diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-02-28 12:31:54 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-03-01 09:33:37 +0100 |
commit | 67a9dc35bf0c0113d429161be2c125e75981fb5d (patch) | |
tree | 0a11064acec035b62a9d51f8661341719f276ef8 /src/mbgl/gl | |
parent | 4372ce2b90a26d114fafa555227a5200c421878f (diff) | |
download | qtlocation-mapboxgl-67a9dc35bf0c0113d429161be2c125e75981fb5d.tar.gz |
[core] move CullFaceMode to gfx namespace
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r-- | src/mbgl/gl/context.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/gl/context.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/gl/cull_face_mode.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/gl/cull_face_mode.hpp | 40 | ||||
-rw-r--r-- | src/mbgl/gl/enum.cpp | 38 | ||||
-rw-r--r-- | src/mbgl/gl/program.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/gl/value.cpp | 24 | ||||
-rw-r--r-- | src/mbgl/gl/value.hpp | 16 |
8 files changed, 65 insertions, 83 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index abe082f14f..bcbb3ab66c 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -618,7 +618,7 @@ void Context::setDirtyState() { clearStencil.setDirty(); cullFace.setDirty(); cullFaceSide.setDirty(); - frontFace.setDirty(); + cullFaceWinding.setDirty(); program.setDirty(); lineWidth.setDirty(); activeTextureUnit.setDirty(); @@ -665,14 +665,14 @@ void Context::clear(optional<mbgl::Color> color, MBGL_CHECK_ERROR(glClear(mask)); } -void Context::setCullFaceMode(const CullFaceMode& mode) { - cullFace = mode.cullFace; +void Context::setCullFaceMode(const gfx::CullFaceMode& mode) { + cullFace = mode.enabled; // These shouldn't need to be updated when face culling is disabled, but we // might end up having the same isssues with Adreno 2xx GPUs as noted in // Context::setDepthMode. cullFaceSide = mode.side; - frontFace = mode.frontFace; + cullFaceWinding = mode.winding; } #if not MBGL_USE_GLES2 diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index d5e51d0adf..7bc139da36 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -173,7 +173,7 @@ public: void setDepthMode(const gfx::DepthMode&); void setStencilMode(const gfx::StencilMode&); void setColorMode(const gfx::ColorMode&); - void setCullFaceMode(const CullFaceMode&); + void setCullFaceMode(const gfx::CullFaceMode&); void draw(gfx::PrimitiveType, std::size_t indexOffset, @@ -267,7 +267,7 @@ private: State<value::BindRenderbuffer> bindRenderbuffer; State<value::CullFace> cullFace; State<value::CullFaceSide> cullFaceSide; - State<value::FrontFace> frontFace; + State<value::CullFaceWinding> cullFaceWinding; #if not MBGL_USE_GLES2 State<value::PointSize> pointSize; #endif // MBGL_USE_GLES2 diff --git a/src/mbgl/gl/cull_face_mode.cpp b/src/mbgl/gl/cull_face_mode.cpp deleted file mode 100644 index 53dd340204..0000000000 --- a/src/mbgl/gl/cull_face_mode.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include <mbgl/gl/cull_face_mode.hpp> -#include <mbgl/gl/defines.hpp> -#include <mbgl/util/traits.hpp> - -namespace mbgl { -namespace gl { - -static_assert(underlying_type(CullFaceMode::Front) == GL_FRONT, "OpenGL enum mismatch"); -static_assert(underlying_type(CullFaceMode::Back) == GL_BACK, "OpenGL enum mismatch"); -static_assert(underlying_type(CullFaceMode::FrontAndBack) == GL_FRONT_AND_BACK, "OpenGL enum mismatch"); - -static_assert(underlying_type(CullFaceMode::Clockwise) == GL_CW, "OpenGL enum mismatch"); -static_assert(underlying_type(CullFaceMode::CounterClockwise) == GL_CCW, "OpenGL enum mismatch"); - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/gl/cull_face_mode.hpp b/src/mbgl/gl/cull_face_mode.hpp deleted file mode 100644 index a408d7a88c..0000000000 --- a/src/mbgl/gl/cull_face_mode.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include <cstdint> - -namespace mbgl { -namespace gl { - -class CullFaceMode { -public: - enum CullFace : bool { - Disable = false, - Enable = true, - }; - - enum CullFaceSide : uint32_t { - Front = 0x0404, - Back = 0x0405, - FrontAndBack = 0x0408, - }; - - enum FrontFace : uint32_t { - Clockwise = 0x0900, - CounterClockwise = 0x0901 - }; - - CullFace cullFace; - CullFaceSide side; - FrontFace frontFace; - - static CullFaceMode disabled() { - return CullFaceMode { Disable, CullFaceSide::Back, FrontFace::CounterClockwise }; - } - - static CullFaceMode backCCW() { - return CullFaceMode { Enable, CullFaceSide::Back, FrontFace::CounterClockwise }; - } -}; - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/gl/enum.cpp b/src/mbgl/gl/enum.cpp index ea47f2104f..da536692d1 100644 --- a/src/mbgl/gl/enum.cpp +++ b/src/mbgl/gl/enum.cpp @@ -183,5 +183,43 @@ platform::GLenum Enum<gfx::StencilOpType>::to(const gfx::StencilOpType value) { return GL_INVALID_ENUM; } +template <> +gfx::CullFaceSideType Enum<gfx::CullFaceSideType>::from(const platform::GLint value) { + switch (value) { + case GL_FRONT: return gfx::CullFaceSideType::Front; + case GL_BACK: return gfx::CullFaceSideType::Back; + case GL_FRONT_AND_BACK: return gfx::CullFaceSideType::FrontAndBack; + } + return {}; +} + +template <> +platform::GLenum Enum<gfx::CullFaceSideType>::to(const gfx::CullFaceSideType value) { + switch (value) { + case gfx::CullFaceSideType::Front: return GL_FRONT; + case gfx::CullFaceSideType::Back: return GL_BACK; + case gfx::CullFaceSideType::FrontAndBack: return GL_FRONT_AND_BACK; + } + return GL_INVALID_ENUM; +} + +template <> +gfx::CullFaceWindingType Enum<gfx::CullFaceWindingType>::from(const platform::GLint value) { + switch (value) { + case GL_CW: return gfx::CullFaceWindingType::Clockwise; + case GL_CCW: return gfx::CullFaceWindingType::CounterClockwise; + } + return {}; +} + +template <> +platform::GLenum Enum<gfx::CullFaceWindingType>::to(const gfx::CullFaceWindingType value) { + switch (value) { + case gfx::CullFaceWindingType::Clockwise: return GL_CW; + case gfx::CullFaceWindingType::CounterClockwise: return GL_CCW; + } + return GL_INVALID_ENUM; +} + } // namespace gl } // namespace mbgl diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index 5bc7c2075b..7e98a63b8d 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -118,7 +118,7 @@ public: gfx::DepthMode depthMode, gfx::StencilMode stencilMode, gfx::ColorMode colorMode, - CullFaceMode cullFaceMode, + gfx::CullFaceMode cullFaceMode, const UniformValues& uniformValues, VertexArray& vertexArray, const AttributeBindings& attributeBindings, diff --git a/src/mbgl/gl/value.cpp b/src/mbgl/gl/value.cpp index 8b46c1ae35..4e56686103 100644 --- a/src/mbgl/gl/value.cpp +++ b/src/mbgl/gl/value.cpp @@ -85,7 +85,7 @@ ColorMask::Type ColorMask::Get() { const constexpr StencilFunc::Type StencilFunc::Default; void StencilFunc::Set(const Type& value) { - MBGL_CHECK_ERROR(glStencilFunc(static_cast<GLenum>(value.func), value.ref, value.mask)); + MBGL_CHECK_ERROR(glStencilFunc(Enum<gfx::StencilFunctionType>::to(value.func), value.ref, value.mask)); } StencilFunc::Type StencilFunc::Get() { @@ -153,13 +153,13 @@ DepthTest::Type DepthTest::Get() { const constexpr DepthFunc::Type DepthFunc::Default; void DepthFunc::Set(const DepthFunc::Type& value) { - MBGL_CHECK_ERROR(glDepthFunc(static_cast<GLenum>(value))); + MBGL_CHECK_ERROR(glDepthFunc(Enum<gfx::DepthFunctionType>::to(value))); } DepthFunc::Type DepthFunc::Get() { GLint depthFunc; MBGL_CHECK_ERROR(glGetIntegerv(GL_DEPTH_FUNC, &depthFunc)); - return static_cast<Type>(depthFunc); + return Enum<gfx::DepthFunctionType>::from(depthFunc); } const constexpr Blend::Type Blend::Default; @@ -301,37 +301,37 @@ BindRenderbuffer::Type BindRenderbuffer::Get() { const constexpr CullFace::Type CullFace::Default; void CullFace::Set(const Type& value) { - MBGL_CHECK_ERROR(value == CullFaceMode::Enable ? glEnable(GL_CULL_FACE) : glDisable(GL_CULL_FACE)); + MBGL_CHECK_ERROR(value ? glEnable(GL_CULL_FACE) : glDisable(GL_CULL_FACE)); } CullFace::Type CullFace::Get() { GLboolean cullFace; MBGL_CHECK_ERROR(cullFace = glIsEnabled(GL_CULL_FACE)); - return cullFace ? CullFaceMode::Enable : CullFaceMode::Disable; + return cullFace; } const constexpr CullFaceSide::Type CullFaceSide::Default; void CullFaceSide::Set(const Type& value) { - MBGL_CHECK_ERROR(glCullFace(static_cast<GLenum>(value))); + MBGL_CHECK_ERROR(glCullFace(Enum<gfx::CullFaceSideType>::to(value))); } CullFaceSide::Type CullFaceSide::Get() { GLint cullFaceMode; MBGL_CHECK_ERROR(glGetIntegerv(GL_CULL_FACE_MODE, &cullFaceMode)); - return static_cast<Type>(cullFaceMode); + return Enum<gfx::CullFaceSideType>::from(cullFaceMode); } -const constexpr FrontFace::Type FrontFace::Default; +const constexpr CullFaceWinding::Type CullFaceWinding::Default; -void FrontFace::Set(const Type& value) { - MBGL_CHECK_ERROR(glFrontFace(static_cast<GLenum>(value))); +void CullFaceWinding::Set(const Type& value) { + MBGL_CHECK_ERROR(glFrontFace(Enum<gfx::CullFaceWindingType>::to(value))); } -FrontFace::Type FrontFace::Get() { +CullFaceWinding::Type CullFaceWinding::Get() { GLint frontFace; MBGL_CHECK_ERROR(glGetIntegerv(GL_FRONT_FACE, &frontFace)); - return static_cast<Type>(frontFace); + return Enum<gfx::CullFaceWindingType>::from(frontFace); } const constexpr BindTexture::Type BindTexture::Default; diff --git a/src/mbgl/gl/value.hpp b/src/mbgl/gl/value.hpp index 128eff2dce..9c01039b99 100644 --- a/src/mbgl/gl/value.hpp +++ b/src/mbgl/gl/value.hpp @@ -4,7 +4,7 @@ #include <mbgl/gfx/depth_mode.hpp> #include <mbgl/gfx/stencil_mode.hpp> #include <mbgl/gfx/color_mode.hpp> -#include <mbgl/gl/cull_face_mode.hpp> +#include <mbgl/gfx/cull_face_mode.hpp> #include <mbgl/gl/attribute.hpp> #include <mbgl/platform/gl_functions.hpp> #include <mbgl/util/color.hpp> @@ -215,22 +215,22 @@ struct BindRenderbuffer { }; struct CullFace { - using Type = CullFaceMode::CullFace; - static const constexpr Type Default = CullFaceMode::Disable; + using Type = bool; + static const constexpr Type Default = false; static void Set(const Type&); static Type Get(); }; struct CullFaceSide { - using Type = CullFaceMode::CullFaceSide; - static const constexpr Type Default = CullFaceMode::Back; + using Type = gfx::CullFaceSideType; + static const constexpr Type Default = gfx::CullFaceSideType::Back; static void Set(const Type&); static Type Get(); }; -struct FrontFace { - using Type = CullFaceMode::FrontFace; - static const constexpr Type Default = CullFaceMode::CounterClockwise; +struct CullFaceWinding { + using Type = gfx::CullFaceWindingType; + static const constexpr Type Default = gfx::CullFaceWindingType::CounterClockwise; static void Set(const Type&); static Type Get(); }; |