#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)) {} 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}; } void LayerTweaker::setPropertiesAsUniforms(std::vector props) { if (props != propertiesAsUniforms) { propertiesAsUniforms = std::move(props); propertiesChanged = true; } } bool LayerTweaker::hasPropertyAsUniform(const std::string_view attrName) const { // `attrName` is expected to have the "a_" prefix, while the values in `propertiesAsUniforms` // do not. Search for the former within the latter without allocating temporary strings. return propertiesAsUniforms.end() != std::find_if(propertiesAsUniforms.begin(), propertiesAsUniforms.end(), [&](const auto& name) { return name.size() + 2 == attrName.size() && 0 == std::strcmp(name.data(), attrName.data() + 2); }); } #endif // MLN_RENDER_BACKEND_METAL void LayerTweaker::enableOverdrawInspector(bool value) { if (overdrawInspector != value) { overdrawInspector = value; propertiesChanged = true; } } } // namespace mbgl