#pragma once #include #include #include #include #include #include #include #include namespace mbgl { using CollisionBoxLayoutAttributes = gl::Attributes< attributes::a_pos, attributes::a_anchor_pos, attributes::a_extrude>; struct CollisionBoxDynamicAttributes : gl::Attributes { static Vertex vertex(bool placed, bool notUsed) { return Vertex { {{ static_cast(placed), static_cast(notUsed) }} }; } }; class CollisionBoxProgram : public Program< shaders::collision_box, gl::Line, gl::ConcatenateAttributes, gl::Uniforms< uniforms::u_matrix, uniforms::u_extrude_scale, uniforms::u_camera_to_center_distance>, style::Properties<>> { public: using Program::Program; static CollisionBoxLayoutAttributes::Vertex vertex(Point a, Point anchor, Point o) { return CollisionBoxLayoutAttributes::Vertex { {{ static_cast(a.x), static_cast(a.y) }}, {{ static_cast(anchor.x), static_cast(anchor.y) }}, {{ static_cast(::round(o.x)), static_cast(::round(o.y)) }} }; } template void draw(gl::Context& context, DrawMode drawMode, gl::DepthMode depthMode, gl::StencilMode stencilMode, gl::ColorMode colorMode, const UniformValues& uniformValues, const gl::VertexBuffer& layoutVertexBuffer, const gl::VertexBuffer& dynamicVertexBuffer, const gl::IndexBuffer& indexBuffer, const SegmentVector& segments, const PaintPropertyBinders& paintPropertyBinders, const typename PaintProperties::PossiblyEvaluated& currentProperties, float currentZoom, const std::string& layerID) { typename AllUniforms::Values allUniformValues = uniformValues .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)); typename Attributes::Bindings allAttributeBindings = CollisionBoxLayoutAttributes::bindings(layoutVertexBuffer) .concat(CollisionBoxDynamicAttributes::bindings(dynamicVertexBuffer)) .concat(paintPropertyBinders.attributeBindings(currentProperties)); assert(layoutVertexBuffer.vertexCount == dynamicVertexBuffer.vertexCount); for (auto& segment : segments) { auto vertexArrayIt = segment.vertexArrays.find(layerID); if (vertexArrayIt == segment.vertexArrays.end()) { vertexArrayIt = segment.vertexArrays.emplace(layerID, context.createVertexArray()).first; } program.draw( context, std::move(drawMode), std::move(depthMode), std::move(stencilMode), std::move(colorMode), allUniformValues, vertexArrayIt->second, Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset), indexBuffer, segment.indexOffset, segment.indexLength); } } }; class CollisionCircleProgram : public Program< shaders::collision_circle, gl::Triangle, gl::ConcatenateAttributes, gl::Uniforms< uniforms::u_matrix, uniforms::u_extrude_scale, uniforms::u_camera_to_center_distance>, style::Properties<>> { public: using Program::Program; static CollisionBoxLayoutAttributes::Vertex vertex(Point a, Point anchor, Point o) { return CollisionBoxLayoutAttributes::Vertex { {{ static_cast(a.x), static_cast(a.y) }}, {{ static_cast(anchor.x), static_cast(anchor.y) }}, {{ static_cast(::round(o.x)), static_cast(::round(o.y)) }} }; } template void draw(gl::Context& context, DrawMode drawMode, gl::DepthMode depthMode, gl::StencilMode stencilMode, gl::ColorMode colorMode, const UniformValues& uniformValues, const gl::VertexBuffer& layoutVertexBuffer, const gl::VertexBuffer& dynamicVertexBuffer, const gl::IndexBuffer& indexBuffer, const SegmentVector& segments, const PaintPropertyBinders& paintPropertyBinders, const typename PaintProperties::PossiblyEvaluated& currentProperties, float currentZoom, const std::string& layerID) { typename AllUniforms::Values allUniformValues = uniformValues .concat(paintPropertyBinders.uniformValues(currentZoom, currentProperties)); typename Attributes::Bindings allAttributeBindings = CollisionBoxLayoutAttributes::bindings(layoutVertexBuffer) .concat(CollisionBoxDynamicAttributes::bindings(dynamicVertexBuffer)) .concat(paintPropertyBinders.attributeBindings(currentProperties)); for (auto& segment : segments) { auto vertexArrayIt = segment.vertexArrays.find(layerID); if (vertexArrayIt == segment.vertexArrays.end()) { vertexArrayIt = segment.vertexArrays.emplace(layerID, context.createVertexArray()).first; } program.draw( context, std::move(drawMode), std::move(depthMode), std::move(stencilMode), std::move(colorMode), allUniformValues, vertexArrayIt->second, Attributes::offsetBindings(allAttributeBindings, segment.vertexOffset), indexBuffer, segment.indexOffset, segment.indexLength); } } }; using CollisionBoxVertex = CollisionBoxProgram::LayoutVertex; } // namespace mbgl