diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-10-28 16:39:50 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-02 09:44:42 -0800 |
commit | 141e995806576364d185626176c1b993fc519291 (patch) | |
tree | ecdc41fc7699f2a1a9e9456157348451ebe99597 /src/mbgl/gl/program.hpp | |
parent | 6a6bddb4537004cc1bfc506e76772de74d33f3f7 (diff) | |
download | qtlocation-mapboxgl-141e995806576364d185626176c1b993fc519291.tar.gz |
[core] Add support for data-driven styling
Diffstat (limited to 'src/mbgl/gl/program.hpp')
-rw-r--r-- | src/mbgl/gl/program.hpp | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index 33387e9d4e..fa0470796e 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -20,16 +20,14 @@ public: using Attributes = As; using Uniforms = Us; - using Vertex = typename Attributes::Vertex; using UniformValues = typename Uniforms::Values; - - static_assert(std::is_standard_layout<Vertex>::value, "vertex type must use standard layout"); + using AttributeBindings = typename Attributes::Bindings; Program(Context& context, const std::string& vertexSource, const std::string& fragmentSource) : vertexShader(context.createShader(ShaderType::Vertex, vertexSource)), fragmentShader(context.createShader(ShaderType::Fragment, fragmentSource)), program(context.createProgram(vertexShader, fragmentShader)), - attributesState(Attributes::state(program)), + attributeLocations(Attributes::locations(program)), uniformsState((context.linkProgram(program), Uniforms::state(program))) {} template <class DrawMode> @@ -39,22 +37,30 @@ public: StencilMode stencilMode, ColorMode colorMode, UniformValues&& uniformValues, - const VertexBuffer<Vertex>& vertexBuffer, + AttributeBindings&& attributeBindings, const IndexBuffer<DrawMode>& indexBuffer, const SegmentVector<Attributes>& segments) { static_assert(std::is_same<Primitive, typename DrawMode::Primitive>::value, "incompatible draw mode"); - context.draw({ - std::move(drawMode), - std::move(depthMode), - std::move(stencilMode), - std::move(colorMode), - program, - vertexBuffer.buffer, - indexBuffer.buffer, - segments, - Uniforms::binder(uniformsState, std::move(uniformValues)), - Attributes::binder(attributesState) - }); + + context.setDrawMode(drawMode); + context.setDepthMode(depthMode); + context.setStencilMode(stencilMode); + context.setColorMode(colorMode); + + context.program = program; + + Uniforms::bind(uniformsState, std::move(uniformValues)); + + for (const auto& segment : segments) { + segment.bind(context, + indexBuffer.buffer, + attributeLocations, + attributeBindings); + + context.draw(drawMode.primitiveType, + segment.indexOffset, + segment.indexLength); + } } private: @@ -62,7 +68,7 @@ private: UniqueShader fragmentShader; UniqueProgram program; - typename Attributes::State attributesState; + typename Attributes::Locations attributeLocations; typename Uniforms::State uniformsState; }; |