141 lines
5.7 KiB
C++
141 lines
5.7 KiB
C++
#include <mbgl/renderer/layers/render_background_layer.hpp>
|
|
#include <mbgl/style/layers/background_layer_impl.hpp>
|
|
#include <mbgl/renderer/bucket.hpp>
|
|
#include <mbgl/renderer/paint_parameters.hpp>
|
|
#include <mbgl/renderer/image_manager.hpp>
|
|
#include <mbgl/renderer/render_static_data.hpp>
|
|
#include <mbgl/programs/programs.hpp>
|
|
#include <mbgl/programs/background_program.hpp>
|
|
#include <mbgl/util/tile_cover.hpp>
|
|
#include <mbgl/map/transform_state.hpp>
|
|
#include <mbgl/gfx/cull_face_mode.hpp>
|
|
|
|
namespace mbgl {
|
|
|
|
using namespace style;
|
|
|
|
inline const BackgroundLayer::Impl& impl(const Immutable<style::Layer::Impl>& impl) {
|
|
return static_cast<const style::BackgroundLayer::Impl&>(*impl);
|
|
}
|
|
|
|
RenderBackgroundLayer::RenderBackgroundLayer(Immutable<style::BackgroundLayer::Impl> _impl)
|
|
: RenderLayer(makeMutable<BackgroundLayerProperties>(std::move(_impl))),
|
|
unevaluated(impl(baseImpl).paint.untransitioned()) {
|
|
}
|
|
|
|
RenderBackgroundLayer::~RenderBackgroundLayer() = default;
|
|
|
|
void RenderBackgroundLayer::transition(const TransitionParameters ¶meters) {
|
|
unevaluated = impl(baseImpl).paint.transitioned(parameters, std::move(unevaluated));
|
|
}
|
|
|
|
void RenderBackgroundLayer::evaluate(const PropertyEvaluationParameters ¶meters) {
|
|
auto properties = makeMutable<BackgroundLayerProperties>(
|
|
staticImmutableCast<BackgroundLayer::Impl>(baseImpl),
|
|
parameters.getCrossfadeParameters(),
|
|
unevaluated.evaluate(parameters));
|
|
|
|
passes = properties->evaluated.get<style::BackgroundOpacity>() > 0 ? RenderPass::Translucent
|
|
: RenderPass::None;
|
|
evaluatedProperties = std::move(properties);
|
|
}
|
|
|
|
bool RenderBackgroundLayer::hasTransition() const {
|
|
return unevaluated.hasTransition();
|
|
}
|
|
|
|
bool RenderBackgroundLayer::hasCrossfade() const {
|
|
return static_cast<const BackgroundLayerProperties&>(*evaluatedProperties).crossfade.t != 1;
|
|
}
|
|
|
|
void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) {
|
|
// Note that for bottommost layers without a pattern, the background color is drawn with
|
|
// glClear rather than this method.
|
|
|
|
const Properties<>::PossiblyEvaluated properties;
|
|
const BackgroundProgram::Binders paintAttributeData(properties, 0);
|
|
|
|
auto draw = [&](auto& program, auto&& uniformValues, const auto& textureBindings) {
|
|
const auto allUniformValues = program.computeAllUniformValues(
|
|
std::move(uniformValues),
|
|
paintAttributeData,
|
|
properties,
|
|
parameters.state.getZoom()
|
|
);
|
|
const auto allAttributeBindings = program.computeAllAttributeBindings(
|
|
parameters.staticData.tileVertexBuffer,
|
|
paintAttributeData,
|
|
properties
|
|
);
|
|
|
|
checkRenderability(parameters, program.activeBindingCount(allAttributeBindings));
|
|
|
|
program.draw(
|
|
parameters.context,
|
|
*parameters.renderPass,
|
|
gfx::Triangles(),
|
|
parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly),
|
|
gfx::StencilMode::disabled(),
|
|
parameters.colorModeForRenderPass(),
|
|
gfx::CullFaceMode::disabled(),
|
|
parameters.staticData.quadTriangleIndexBuffer,
|
|
parameters.staticData.tileTriangleSegments,
|
|
allUniformValues,
|
|
allAttributeBindings,
|
|
textureBindings,
|
|
getID()
|
|
);
|
|
};
|
|
const auto& evaluated = static_cast<const BackgroundLayerProperties&>(*evaluatedProperties).evaluated;
|
|
const auto& crossfade = static_cast<const BackgroundLayerProperties&>(*evaluatedProperties).crossfade;
|
|
if (!evaluated.get<BackgroundPattern>().to.empty()) {
|
|
optional<ImagePosition> imagePosA = parameters.imageManager.getPattern(evaluated.get<BackgroundPattern>().from);
|
|
optional<ImagePosition> imagePosB = parameters.imageManager.getPattern(evaluated.get<BackgroundPattern>().to);
|
|
|
|
if (!imagePosA || !imagePosB)
|
|
return;
|
|
|
|
for (const auto& tileID : util::tileCover(parameters.state, parameters.state.getIntegerZoom())) {
|
|
draw(
|
|
parameters.programs.getBackgroundLayerPrograms().backgroundPattern,
|
|
BackgroundPatternProgram::layoutUniformValues(
|
|
parameters.matrixForTile(tileID),
|
|
evaluated.get<BackgroundOpacity>(),
|
|
parameters.imageManager.getPixelSize(),
|
|
*imagePosA,
|
|
*imagePosB,
|
|
crossfade,
|
|
tileID,
|
|
parameters.state
|
|
),
|
|
BackgroundPatternProgram::TextureBindings{
|
|
textures::image::Value{ parameters.imageManager.textureBinding(parameters.context) },
|
|
}
|
|
);
|
|
}
|
|
} else {
|
|
for (const auto& tileID : util::tileCover(parameters.state, parameters.state.getIntegerZoom())) {
|
|
draw(
|
|
parameters.programs.getBackgroundLayerPrograms().background,
|
|
BackgroundProgram::LayoutUniformValues {
|
|
uniforms::matrix::Value( parameters.matrixForTile(tileID) ),
|
|
uniforms::color::Value( evaluated.get<BackgroundColor>() ),
|
|
uniforms::opacity::Value( evaluated.get<BackgroundOpacity>() ),
|
|
},
|
|
BackgroundProgram::TextureBindings{}
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
optional<Color> RenderBackgroundLayer::getSolidBackground() const {
|
|
const auto& evaluated = static_cast<const BackgroundLayerProperties&>(*evaluatedProperties).evaluated;
|
|
if (!evaluated.get<BackgroundPattern>().from.empty()) {
|
|
return nullopt;
|
|
}
|
|
|
|
return { evaluated.get<BackgroundColor>() * evaluated.get<BackgroundOpacity>() };
|
|
}
|
|
|
|
} // namespace mbgl
|