diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-02-28 17:41:38 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-03-01 09:33:37 +0100 |
commit | fd37d9065029c732d97e6fa59bc0a0d27ecd3c72 (patch) | |
tree | 32111ffa986b6338f2aa4311b2974c90ec09baff /src/mbgl/gl | |
parent | c53cbe52461e3c1f6f4e1bb6383a6a2e3e5a2cae (diff) | |
download | qtlocation-mapboxgl-fd37d9065029c732d97e6fa59bc0a0d27ecd3c72.tar.gz |
[core] move draw mode and primitives to gfx namespace
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r-- | src/mbgl/gl/context.cpp | 38 | ||||
-rw-r--r-- | src/mbgl/gl/context.hpp | 14 | ||||
-rw-r--r-- | src/mbgl/gl/draw_mode.hpp | 72 | ||||
-rw-r--r-- | src/mbgl/gl/index_buffer.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/gl/primitives.hpp | 24 | ||||
-rw-r--r-- | src/mbgl/gl/types.hpp | 10 | ||||
-rw-r--r-- | src/mbgl/gl/vertex_buffer.hpp | 4 |
7 files changed, 31 insertions, 133 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 2463993cf0..64365a1018 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -40,15 +40,6 @@ static_assert(underlying_type(RenderbufferType::DepthComponent) == GL_DEPTH_COMP static_assert(underlying_type(RenderbufferType::DepthComponent) == GL_DEPTH_COMPONENT16, "OpenGL type mismatch"); #endif // MBGL_USE_GLES2 - -static_assert(underlying_type(PrimitiveType::Points) == GL_POINTS, "OpenGL type mismatch"); -static_assert(underlying_type(PrimitiveType::Lines) == GL_LINES, "OpenGL type mismatch"); -static_assert(underlying_type(PrimitiveType::LineLoop) == GL_LINE_LOOP, "OpenGL type mismatch"); -static_assert(underlying_type(PrimitiveType::LineStrip) == GL_LINE_STRIP, "OpenGL type mismatch"); -static_assert(underlying_type(PrimitiveType::Triangles) == GL_TRIANGLES, "OpenGL type mismatch"); -static_assert(underlying_type(PrimitiveType::TriangleStrip) == GL_TRIANGLE_STRIP, "OpenGL type mismatch"); -static_assert(underlying_type(PrimitiveType::TriangleFan) == GL_TRIANGLE_FAN, "OpenGL type mismatch"); - static_assert(std::is_same<ProgramID, GLuint>::value, "OpenGL type mismatch"); static_assert(std::is_same<ShaderID, GLuint>::value, "OpenGL type mismatch"); static_assert(std::is_same<BufferID, GLuint>::value, "OpenGL type mismatch"); @@ -684,26 +675,26 @@ void Context::setCullFaceMode(const CullFaceMode& mode) { } #if not MBGL_USE_GLES2 -void Context::setDrawMode(const Points& points) { +void Context::setDrawMode(const gfx::Points& points) { pointSize = points.pointSize; } #else -void Context::setDrawMode(const Points&) { +void Context::setDrawMode(const gfx::Points&) { } #endif // MBGL_USE_GLES2 -void Context::setDrawMode(const Lines& lines) { +void Context::setDrawMode(const gfx::Lines& lines) { lineWidth = lines.lineWidth; } -void Context::setDrawMode(const LineStrip& lineStrip) { +void Context::setDrawMode(const gfx::LineStrip& lineStrip) { lineWidth = lineStrip.lineWidth; } -void Context::setDrawMode(const Triangles&) { +void Context::setDrawMode(const gfx::Triangles&) { } -void Context::setDrawMode(const TriangleStrip&) { +void Context::setDrawMode(const gfx::TriangleStrip&) { } void Context::setDepthMode(const DepthMode& depth) { @@ -752,11 +743,24 @@ void Context::setColorMode(const ColorMode& color) { colorMask = color.mask; } -void Context::draw(PrimitiveType primitiveType, +GLenum toGLenum(const gfx::PrimitiveType primitiveType) { + switch (primitiveType) { + case gfx::PrimitiveType::Points: return GL_POINTS; + case gfx::PrimitiveType::Lines: return GL_LINES; + case gfx::PrimitiveType::LineLoop: return GL_LINE_LOOP; + case gfx::PrimitiveType::LineStrip: return GL_LINE_STRIP; + case gfx::PrimitiveType::Triangles: return GL_TRIANGLES; + case gfx::PrimitiveType::TriangleStrip: return GL_TRIANGLE_STRIP; + case gfx::PrimitiveType::TriangleFan: return GL_TRIANGLE_FAN; + } + return GL_INVALID_ENUM; +} + +void Context::draw(gfx::PrimitiveType primitiveType, std::size_t indexOffset, std::size_t indexLength) { MBGL_CHECK_ERROR(glDrawElements( - static_cast<GLenum>(primitiveType), + toGLenum(primitiveType), static_cast<GLsizei>(indexLength), GL_UNSIGNED_SHORT, reinterpret_cast<GLvoid*>(sizeof(uint16_t) * indexOffset))); diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index a10b49da48..b09c64de5a 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -11,7 +11,7 @@ #include <mbgl/gl/index_buffer.hpp> #include <mbgl/gl/vertex_array.hpp> #include <mbgl/gl/types.hpp> -#include <mbgl/gl/draw_mode.hpp> +#include <mbgl/gfx/draw_mode.hpp> #include <mbgl/gl/depth_mode.hpp> #include <mbgl/gl/stencil_mode.hpp> #include <mbgl/gl/color_mode.hpp> @@ -164,18 +164,18 @@ public: optional<float> depth, optional<int32_t> stencil); - void setDrawMode(const Points&); - void setDrawMode(const Lines&); - void setDrawMode(const LineStrip&); - void setDrawMode(const Triangles&); - void setDrawMode(const TriangleStrip&); + void setDrawMode(const gfx::Points&); + void setDrawMode(const gfx::Lines&); + void setDrawMode(const gfx::LineStrip&); + void setDrawMode(const gfx::Triangles&); + void setDrawMode(const gfx::TriangleStrip&); void setDepthMode(const DepthMode&); void setStencilMode(const StencilMode&); void setColorMode(const ColorMode&); void setCullFaceMode(const CullFaceMode&); - void draw(PrimitiveType, + void draw(gfx::PrimitiveType, std::size_t indexOffset, std::size_t indexLength); diff --git a/src/mbgl/gl/draw_mode.hpp b/src/mbgl/gl/draw_mode.hpp deleted file mode 100644 index 6f0c5ea4a4..0000000000 --- a/src/mbgl/gl/draw_mode.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include <mbgl/gl/types.hpp> -#include <mbgl/gl/primitives.hpp> - -#include <cassert> - -namespace mbgl { -namespace gl { - -class Points { -public: - using Primitive = Point; - - static constexpr std::size_t bufferGroupSize = 1; - static constexpr PrimitiveType primitiveType = PrimitiveType::Points; - - explicit Points(float pointSize_) : pointSize(pointSize_) {} - - float pointSize; -}; - -class Lines { -public: - using Primitive = Line; - - static constexpr std::size_t bufferGroupSize = 2; - static constexpr PrimitiveType primitiveType = PrimitiveType::Lines; - - explicit Lines(float lineWidth_) : lineWidth(lineWidth_) { - assert(lineWidth > 0); - } - - float lineWidth; -}; - -class LineStrip { -public: - // LineStrip is a form of "Line" rendering, but the element buffer - // cannot be grouped into logical elements beyond a single Point. - using Primitive = Line; - - static constexpr std::size_t bufferGroupSize = 1; - static constexpr PrimitiveType primitiveType = PrimitiveType::LineStrip; - - explicit LineStrip(float lineWidth_) : lineWidth(lineWidth_) { - assert(lineWidth > 0); - } - - float lineWidth; -}; - -class Triangles { -public: - using Primitive = Triangle; - - static constexpr std::size_t bufferGroupSize = 3; - static constexpr PrimitiveType primitiveType = PrimitiveType::Triangles; -}; - -class TriangleStrip { -public: - // TriangleStrip is a form of "Triangle" rendering, but the element buffer - // cannot be grouped into logical elements beyond a single Point. - using Primitive = Triangle; - - static constexpr std::size_t bufferGroupSize = 1; - static constexpr PrimitiveType primitiveType = PrimitiveType::TriangleStrip; -}; - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/gl/index_buffer.hpp b/src/mbgl/gl/index_buffer.hpp index 87bfb6068f..14bdcf09e7 100644 --- a/src/mbgl/gl/index_buffer.hpp +++ b/src/mbgl/gl/index_buffer.hpp @@ -1,7 +1,7 @@ #pragma once #include <mbgl/gl/object.hpp> -#include <mbgl/gl/draw_mode.hpp> +#include <mbgl/gfx/draw_mode.hpp> #include <mbgl/util/ignore.hpp> #include <vector> diff --git a/src/mbgl/gl/primitives.hpp b/src/mbgl/gl/primitives.hpp deleted file mode 100644 index a101694643..0000000000 --- a/src/mbgl/gl/primitives.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include <cstddef> - -namespace mbgl { -namespace gl { - -class Point { -public: - static constexpr std::size_t vertexCount = 1; -}; - -class Line { -public: - static constexpr std::size_t vertexCount = 2; -}; - -class Triangle { -public: - static constexpr std::size_t vertexCount = 3; -}; - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/gl/types.hpp b/src/mbgl/gl/types.hpp index 376a784a0c..4c3033454f 100644 --- a/src/mbgl/gl/types.hpp +++ b/src/mbgl/gl/types.hpp @@ -73,16 +73,6 @@ enum class TextureType : uint32_t { #endif // MBGL_USE_GLES2 }; -enum class PrimitiveType { - Points = 0x0000, - Lines = 0x0001, - LineLoop = 0x0002, - LineStrip = 0x0003, - Triangles = 0x0004, - TriangleStrip = 0x0005, - TriangleFan = 0x0006 -}; - struct PixelStorageType { int32_t alignment; }; diff --git a/src/mbgl/gl/vertex_buffer.hpp b/src/mbgl/gl/vertex_buffer.hpp index 29eba2e979..0e2db2608f 100644 --- a/src/mbgl/gl/vertex_buffer.hpp +++ b/src/mbgl/gl/vertex_buffer.hpp @@ -1,8 +1,8 @@ #pragma once #include <mbgl/gl/object.hpp> -#include <mbgl/gl/primitives.hpp> -#include <mbgl/gl/draw_mode.hpp> +#include <mbgl/gfx/primitives.hpp> +#include <mbgl/gfx/draw_mode.hpp> #include <mbgl/util/ignore.hpp> #include <vector> |