diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-03-06 10:08:43 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-03-06 16:12:51 +0100 |
commit | ec42b2a5a409d767655a61228f951e1f37835d44 (patch) | |
tree | 6475348f95c7bacfe6257b631faf2c88a7065be8 /src/mbgl | |
parent | 458bb6551009dae199fa57df8461f0b1878d7d06 (diff) | |
download | qtlocation-mapboxgl-ec42b2a5a409d767655a61228f951e1f37835d44.tar.gz |
[core] move BufferUsage enum to gfx namespace
Diffstat (limited to 'src/mbgl')
-rw-r--r-- | src/mbgl/gfx/types.hpp | 6 | ||||
-rw-r--r-- | src/mbgl/gl/context.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/gl/context.hpp | 8 | ||||
-rw-r--r-- | src/mbgl/gl/enum.cpp | 20 | ||||
-rw-r--r-- | src/mbgl/gl/types.hpp | 6 | ||||
-rw-r--r-- | src/mbgl/renderer/buckets/symbol_bucket.cpp | 16 |
6 files changed, 42 insertions, 26 deletions
diff --git a/src/mbgl/gfx/types.hpp b/src/mbgl/gfx/types.hpp index a9cb4e1ece..6082d99017 100644 --- a/src/mbgl/gfx/types.hpp +++ b/src/mbgl/gfx/types.hpp @@ -127,5 +127,11 @@ enum CullFaceWindingType : uint8_t { CounterClockwise, }; +enum class BufferUsageType : uint8_t { + StreamDraw, + StaticDraw, + DynamicDraw, +}; + } // namespace gfx } // namespace mbgl diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 4f4357b749..514bc0115e 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -75,10 +75,6 @@ static_assert(underlying_type(UniformDataType::FloatMat4) == GL_FLOAT_MAT4, "Ope static_assert(underlying_type(UniformDataType::Sampler2D) == GL_SAMPLER_2D, "OpenGL type mismatch"); static_assert(underlying_type(UniformDataType::SamplerCube) == GL_SAMPLER_CUBE, "OpenGL type mismatch"); -static_assert(underlying_type(BufferUsage::StreamDraw) == GL_STREAM_DRAW, "OpenGL type mismatch"); -static_assert(underlying_type(BufferUsage::StaticDraw) == GL_STATIC_DRAW, "OpenGL type mismatch"); -static_assert(underlying_type(BufferUsage::DynamicDraw) == GL_DYNAMIC_DRAW, "OpenGL type mismatch"); - static_assert(std::is_same<BinaryProgramFormat, GLenum>::value, "OpenGL type mismatch"); Context::Context() @@ -250,12 +246,12 @@ void Context::verifyProgramLinkage(ProgramID program_) { } std::unique_ptr<const gfx::VertexBufferResource> -Context::createVertexBuffer(const void* data, std::size_t size, const BufferUsage usage) { +Context::createVertexBuffer(const void* data, std::size_t size, const gfx::BufferUsageType usage) { BufferID id = 0; MBGL_CHECK_ERROR(glGenBuffers(1, &id)); UniqueBuffer result { std::move(id), { this } }; vertexBuffer = result; - MBGL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, size, data, static_cast<GLenum>(usage))); + MBGL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, size, data, Enum<gfx::BufferUsageType>::to(usage))); return std::make_unique<gl::VertexBufferResource>(std::move(result)); } @@ -265,13 +261,13 @@ void Context::updateVertexBuffer(const gfx::VertexBufferResource& resource, cons } std::unique_ptr<const gfx::IndexBufferResource> -Context::createIndexBuffer(const void* data, std::size_t size, const BufferUsage usage) { +Context::createIndexBuffer(const void* data, std::size_t size, const gfx::BufferUsageType usage) { BufferID id = 0; MBGL_CHECK_ERROR(glGenBuffers(1, &id)); UniqueBuffer result { std::move(id), { this } }; bindVertexArray = 0; globalVertexArrayState.indexBuffer = result; - MBGL_CHECK_ERROR(glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data, static_cast<GLenum>(usage))); + MBGL_CHECK_ERROR(glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data, Enum<gfx::BufferUsageType>::to(usage))); return std::make_unique<gl::IndexBufferResource>(std::move(result)); } diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index 4d4a538234..585ee286c4 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -66,7 +66,7 @@ public: optional<std::pair<BinaryProgramFormat, std::string>> getBinaryProgram(ProgramID) const; template <class Vertex> - gfx::VertexBuffer<Vertex> createVertexBuffer(gfx::VertexVector<Vertex>&& v, const BufferUsage usage = BufferUsage::StaticDraw) { + gfx::VertexBuffer<Vertex> createVertexBuffer(gfx::VertexVector<Vertex>&& v, const gfx::BufferUsageType usage = gfx::BufferUsageType::StaticDraw) { return { v.elements(), createVertexBuffer(v.data(), v.bytes(), usage) @@ -80,7 +80,7 @@ public: } template <class DrawMode> - gfx::IndexBuffer createIndexBuffer(gfx::IndexVector<DrawMode>&& v, const BufferUsage usage = BufferUsage::StaticDraw) { + gfx::IndexBuffer createIndexBuffer(gfx::IndexVector<DrawMode>&& v, const gfx::BufferUsageType usage = gfx::BufferUsageType::StaticDraw) { return { v.elements(), createIndexBuffer(v.data(), v.bytes(), usage) @@ -274,9 +274,9 @@ private: State<value::PointSize> pointSize; #endif // MBGL_USE_GLES2 - std::unique_ptr<const gfx::VertexBufferResource> createVertexBuffer(const void* data, std::size_t size, const BufferUsage usage); + std::unique_ptr<const gfx::VertexBufferResource> createVertexBuffer(const void* data, std::size_t size, const gfx::BufferUsageType usage); void updateVertexBuffer(const gfx::VertexBufferResource&, const void* data, std::size_t size); - std::unique_ptr<const gfx::IndexBufferResource> createIndexBuffer(const void* data, std::size_t size, const BufferUsage usage); + std::unique_ptr<const gfx::IndexBufferResource> createIndexBuffer(const void* data, std::size_t size, const gfx::BufferUsageType usage); void updateIndexBuffer(const gfx::IndexBufferResource&, const void* data, std::size_t size); UniqueTexture createTexture(Size size, const void* data, TextureFormat, TextureUnit, TextureType); void updateTexture(TextureID, Size size, const void* data, TextureFormat, TextureUnit, TextureType); diff --git a/src/mbgl/gl/enum.cpp b/src/mbgl/gl/enum.cpp index da536692d1..81561360e9 100644 --- a/src/mbgl/gl/enum.cpp +++ b/src/mbgl/gl/enum.cpp @@ -221,5 +221,25 @@ platform::GLenum Enum<gfx::CullFaceWindingType>::to(const gfx::CullFaceWindingTy return GL_INVALID_ENUM; } +template <> +gfx::BufferUsageType Enum<gfx::BufferUsageType>::from(const platform::GLint value) { + switch (value) { + case GL_STREAM_DRAW: return gfx::BufferUsageType::StreamDraw; + case GL_STATIC_DRAW: return gfx::BufferUsageType::StaticDraw; + case GL_DYNAMIC_DRAW: return gfx::BufferUsageType::DynamicDraw; + } + return {}; +} + +template <> +platform::GLenum Enum<gfx::BufferUsageType>::to(const gfx::BufferUsageType value) { + switch (value) { + case gfx::BufferUsageType::StreamDraw: return GL_STREAM_DRAW; + case gfx::BufferUsageType::StaticDraw: return GL_STATIC_DRAW; + case gfx::BufferUsageType::DynamicDraw: return GL_DYNAMIC_DRAW; + } + return GL_INVALID_ENUM; +} + } // namespace gl } // namespace mbgl diff --git a/src/mbgl/gl/types.hpp b/src/mbgl/gl/types.hpp index 22b7098100..310960b970 100644 --- a/src/mbgl/gl/types.hpp +++ b/src/mbgl/gl/types.hpp @@ -93,11 +93,5 @@ enum class UniformDataType : uint32_t { SamplerCube = 0x8B60, }; -enum class BufferUsage : uint32_t { - StreamDraw = 0x88E0, - StaticDraw = 0x88E4, - DynamicDraw = 0x88E8, -}; - } // namespace gl } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/symbol_bucket.cpp b/src/mbgl/renderer/buckets/symbol_bucket.cpp index cea46a54eb..fafc9816fa 100644 --- a/src/mbgl/renderer/buckets/symbol_bucket.cpp +++ b/src/mbgl/renderer/buckets/symbol_bucket.cpp @@ -44,18 +44,18 @@ SymbolBucket::~SymbolBucket() = default; void SymbolBucket::upload(gl::Context& context) { if (hasTextData()) { if (!staticUploaded) { - text.indexBuffer = context.createIndexBuffer(std::move(text.triangles), sortFeaturesByY ? gl::BufferUsage::StreamDraw : gl::BufferUsage::StaticDraw); + text.indexBuffer = context.createIndexBuffer(std::move(text.triangles), sortFeaturesByY ? gfx::BufferUsageType::StreamDraw : gfx::BufferUsageType::StaticDraw); text.vertexBuffer = context.createVertexBuffer(std::move(text.vertices)); } else if (!sortUploaded) { context.updateIndexBuffer(*text.indexBuffer, std::move(text.triangles)); } if (!dynamicUploaded) { - text.dynamicVertexBuffer = context.createVertexBuffer(std::move(text.dynamicVertices), gl::BufferUsage::StreamDraw); + text.dynamicVertexBuffer = context.createVertexBuffer(std::move(text.dynamicVertices), gfx::BufferUsageType::StreamDraw); } if (!placementChangesUploaded) { if (!text.opacityVertexBuffer) { - text.opacityVertexBuffer = context.createVertexBuffer(std::move(text.opacityVertices), gl::BufferUsage::StreamDraw); + text.opacityVertexBuffer = context.createVertexBuffer(std::move(text.opacityVertices), gfx::BufferUsageType::StreamDraw); } else { context.updateVertexBuffer(*text.opacityVertexBuffer, std::move(text.opacityVertices)); } @@ -64,17 +64,17 @@ void SymbolBucket::upload(gl::Context& context) { if (hasIconData()) { if (!staticUploaded) { - icon.indexBuffer = context.createIndexBuffer(std::move(icon.triangles), sortFeaturesByY ? gl::BufferUsage::StreamDraw : gl::BufferUsage::StaticDraw); + icon.indexBuffer = context.createIndexBuffer(std::move(icon.triangles), sortFeaturesByY ? gfx::BufferUsageType::StreamDraw : gfx::BufferUsageType::StaticDraw); icon.vertexBuffer = context.createVertexBuffer(std::move(icon.vertices)); } else if (!sortUploaded) { context.updateIndexBuffer(*icon.indexBuffer, std::move(icon.triangles)); } if (!dynamicUploaded) { - icon.dynamicVertexBuffer = context.createVertexBuffer(std::move(icon.dynamicVertices), gl::BufferUsage::StreamDraw); + icon.dynamicVertexBuffer = context.createVertexBuffer(std::move(icon.dynamicVertices), gfx::BufferUsageType::StreamDraw); } if (!placementChangesUploaded) { if (!icon.opacityVertexBuffer) { - icon.opacityVertexBuffer = context.createVertexBuffer(std::move(icon.opacityVertices), gl::BufferUsage::StreamDraw); + icon.opacityVertexBuffer = context.createVertexBuffer(std::move(icon.opacityVertices), gfx::BufferUsageType::StreamDraw); } else { context.updateVertexBuffer(*icon.opacityVertexBuffer, std::move(icon.opacityVertices)); } @@ -88,7 +88,7 @@ void SymbolBucket::upload(gl::Context& context) { } if (!placementChangesUploaded) { if (!collisionBox.dynamicVertexBuffer) { - collisionBox.dynamicVertexBuffer = context.createVertexBuffer(std::move(collisionBox.dynamicVertices), gl::BufferUsage::StreamDraw); + collisionBox.dynamicVertexBuffer = context.createVertexBuffer(std::move(collisionBox.dynamicVertices), gfx::BufferUsageType::StreamDraw); } else { context.updateVertexBuffer(*collisionBox.dynamicVertexBuffer, std::move(collisionBox.dynamicVertices)); } @@ -102,7 +102,7 @@ void SymbolBucket::upload(gl::Context& context) { } if (!placementChangesUploaded) { if (!collisionCircle.dynamicVertexBuffer) { - collisionCircle.dynamicVertexBuffer = context.createVertexBuffer(std::move(collisionCircle.dynamicVertices), gl::BufferUsage::StreamDraw); + collisionCircle.dynamicVertexBuffer = context.createVertexBuffer(std::move(collisionCircle.dynamicVertices), gfx::BufferUsageType::StreamDraw); } else { context.updateVertexBuffer(*collisionCircle.dynamicVertexBuffer, std::move(collisionCircle.dynamicVertices)); } |