diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-11-07 12:26:05 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-11-08 08:09:29 -0800 |
commit | 1db2ffbc1b69069eca39f786cacc45dbb02c3052 (patch) | |
tree | 9d6ed2a7302492f41c52ea3fdeadabf6466b0d8d /src/mbgl/gl/context.hpp | |
parent | 66bdbc3b969083b9d647abdf72784be64a125949 (diff) | |
download | qtlocation-mapboxgl-1db2ffbc1b69069eca39f786cacc45dbb02c3052.tar.gz |
[core] Use gl::Program to resolve some rough edges in the GL binding types
* Extract `ignore` util to separate header.
* `Segment` now tracks offset and length of indices, rather than primitives. This is more natural.
* Introduce `VertexVector` and `IndexVector` types. These types carry information about the intended draw mode (`Triangles`, `LineStrip`, etc.), and ensure that elements are always appended in a group size appropriate for that draw mode, for both indexed and unindexed rendering.
* `Program`, rather than `Drawable`, is now the unifying object for draw calls. `Program` is the best place to type check the draw call, because it is typed to carry information about the intended primitive, vertex type, attributes, and uniforms.
* Use the debug shaders for debug tile rendering, like gl-js.
* Fix the draw mode for background. It was drawing triangle strips with a triangles array. Surprised this didn’t cause issues. Now it’s type checked.
Diffstat (limited to 'src/mbgl/gl/context.hpp')
-rw-r--r-- | src/mbgl/gl/context.hpp | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index 2a3fbea33d..154921a1b9 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -8,9 +8,16 @@ #include <mbgl/gl/framebuffer.hpp> #include <mbgl/gl/vertex_buffer.hpp> #include <mbgl/gl/index_buffer.hpp> -#include <mbgl/gl/drawable.hpp> +#include <mbgl/gl/types.hpp> +#include <mbgl/gl/draw_mode.hpp> +#include <mbgl/gl/depth_mode.hpp> +#include <mbgl/gl/stencil_mode.hpp> +#include <mbgl/gl/color_mode.hpp> +#include <mbgl/gl/segment.hpp> #include <mbgl/util/noncopyable.hpp> + +#include <functional> #include <memory> #include <vector> #include <array> @@ -33,18 +40,18 @@ public: UniqueProgram createProgram(ShaderID vertexShader, ShaderID fragmentShader); UniqueTexture createTexture(); - template <class V> - VertexBuffer<V> createVertexBuffer(std::vector<V>&& v) { - return VertexBuffer<V> { - v.size(), - createVertexBuffer(v.data(), v.size() * sizeof(V)) + template <class Vertex, class DrawMode> + VertexBuffer<Vertex, DrawMode> createVertexBuffer(VertexVector<Vertex, DrawMode>&& v) { + return VertexBuffer<Vertex, DrawMode> { + v.vertexSize(), + createVertexBuffer(v.data(), v.byteSize()) }; } - template <class P> - IndexBuffer<P> createIndexBuffer(std::vector<P>&& v) { - return IndexBuffer<P> { - createIndexBuffer(v.data(), v.size() * sizeof(P)) + template <class DrawMode> + IndexBuffer<DrawMode> createIndexBuffer(IndexVector<DrawMode>&& v) { + return IndexBuffer<DrawMode> { + createIndexBuffer(v.data(), v.byteSize()) }; } @@ -111,6 +118,19 @@ public: optional<float> depth, optional<int32_t> stencil); + struct Drawable { + DrawMode drawMode; + DepthMode depthMode; + StencilMode stencilMode; + ColorMode colorMode; + gl::ProgramID program; + gl::BufferID vertexBuffer; + gl::BufferID indexBuffer; + const std::vector<Segment>& segments; + std::function<void ()> bindUniforms; + std::function<void (std::size_t)> bindAttributes; + }; + void draw(const Drawable&); void setDepthMode(const DepthMode&); |