#include #include #include #include #include #include #include #if MLN_RENDER_BACKEND_METAL #include #include #include #endif // MLN_RENDER_BACKEND_METAL namespace mbgl { LayerTweaker::LayerTweaker(std::string id_, Immutable properties) : id(std::move(id_)), evaluatedProperties(std::move(properties)) {} bool LayerTweaker::checkTweakDrawable(const gfx::Drawable& drawable) const { // Apply to a drawable if it references us, or if doesn't reference anything. const auto& tweaker = drawable.getLayerTweaker(); return !tweaker || tweaker.get() == this; } mat4 LayerTweaker::getTileMatrix(const UnwrappedTileID& tileID, const RenderTree& renderTree, const TransformState& state, const std::array& translation, style::TranslateAnchorType anchor, bool nearClipped, bool inViewportPixelUnits, bool aligned) { // from RenderTile::prepare mat4 tileMatrix; state.matrixFor(/*out*/ tileMatrix, tileID); const auto& transformParams = renderTree.getParameters().transformParams; // nearClippedMatrix has near plane moved further, to enhance depth buffer precision const auto& projMatrix = aligned ? transformParams.alignedProjMatrix : (nearClipped ? transformParams.nearClippedProjMatrix : transformParams.projMatrix); matrix::multiply(tileMatrix, projMatrix, tileMatrix); return RenderTile::translateVtxMatrix(tileID, tileMatrix, translation, anchor, state, inViewportPixelUnits); } void LayerTweaker::updateProperties(Immutable newProps) { evaluatedProperties = std::move(newProps); propertiesUpdated = true; } #if MLN_RENDER_BACKEND_METAL shaders::ExpressionInputsUBO LayerTweaker::buildExpressionUBO(double zoom, uint64_t frameCount) { const auto time = util::MonotonicTimer::now(); const auto time_ns = std::chrono::duration_cast(time).count(); return {/* .time_lo = */ static_cast(time_ns), /* .time_hi = */ static_cast(time_ns >> 32), /* .frame_lo = */ static_cast(frameCount), /* .frame_hi = */ static_cast(frameCount >> 32), /* .zoom = */ static_cast(zoom), /* .zoom_frac = */ static_cast(zoom - static_cast(zoom)), /* .pad = */ 0, 0}; } bool LayerTweaker::hasPropertyAsUniform(const StringIdentity attrNameID) const { return propertiesAsUniforms.find(attrNameID) != propertiesAsUniforms.end(); } using namespace shaders; AttributeSource LayerTweaker::getAttributeSource(const StringIdentity attribNameID) const { return hasPropertyAsUniform(attribNameID) ? AttributeSource::Constant : AttributeSource::PerVertex; } #endif // MLN_RENDER_BACKEND_METAL void LayerTweaker::setPropertiesAsUniforms([[maybe_unused]] const std::unordered_set& props) { #if MLN_RENDER_BACKEND_METAL if (props != propertiesAsUniforms) { propertiesAsUniforms = props; permutationUpdated = true; } #endif } #if !MLN_RENDER_BACKEND_METAL namespace { const std::unordered_set emptyIDSet; } #endif const std::unordered_set& LayerTweaker::getPropertiesAsUniforms() const { #if MLN_RENDER_BACKEND_METAL return propertiesAsUniforms; #else return emptyIDSet; #endif } void LayerTweaker::enableOverdrawInspector(bool value) { if (overdrawInspector != value) { overdrawInspector = value; permutationUpdated = true; } } } // namespace mbgl