diff options
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r-- | src/mbgl/gl/context.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/gl/context.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/gl/depth_mode.cpp | 18 | ||||
-rw-r--r-- | src/mbgl/gl/depth_mode.hpp | 36 | ||||
-rw-r--r-- | src/mbgl/gl/enum.cpp | 54 | ||||
-rw-r--r-- | src/mbgl/gl/enum.hpp | 9 | ||||
-rw-r--r-- | src/mbgl/gl/program.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/gl/value.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/gl/value.hpp | 10 |
9 files changed, 61 insertions, 80 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index a7b40b6448..1be6a32f2b 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -698,8 +698,8 @@ void Context::setDrawMode(const gfx::Triangles&) { void Context::setDrawMode(const gfx::TriangleStrip&) { } -void Context::setDepthMode(const DepthMode& depth) { - if (depth.func == DepthMode::Always && !depth.mask) { +void Context::setDepthMode(const gfx::DepthMode& depth) { + if (depth.func == gfx::DepthFunctionType::Always && depth.mask != gfx::DepthMaskType::ReadWrite) { depthTest = false; // Workaround for rendering errors on Adreno 2xx GPUs. Depth-related state should diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index ceab6aadf1..e296e81452 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -12,7 +12,7 @@ #include <mbgl/gl/vertex_array.hpp> #include <mbgl/gl/types.hpp> #include <mbgl/gfx/draw_mode.hpp> -#include <mbgl/gl/depth_mode.hpp> +#include <mbgl/gfx/depth_mode.hpp> #include <mbgl/gl/stencil_mode.hpp> #include <mbgl/gfx/color_mode.hpp> #include <mbgl/platform/gl_functions.hpp> @@ -170,7 +170,7 @@ public: void setDrawMode(const gfx::Triangles&); void setDrawMode(const gfx::TriangleStrip&); - void setDepthMode(const DepthMode&); + void setDepthMode(const gfx::DepthMode&); void setStencilMode(const StencilMode&); void setColorMode(const gfx::ColorMode&); void setCullFaceMode(const CullFaceMode&); diff --git a/src/mbgl/gl/depth_mode.cpp b/src/mbgl/gl/depth_mode.cpp deleted file mode 100644 index fdd9cf31d1..0000000000 --- a/src/mbgl/gl/depth_mode.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include <mbgl/gl/depth_mode.hpp> -#include <mbgl/gl/defines.hpp> -#include <mbgl/util/traits.hpp> - -namespace mbgl { -namespace gl { - -static_assert(underlying_type(DepthMode::Never) == GL_NEVER, "OpenGL enum mismatch"); -static_assert(underlying_type(DepthMode::Less) == GL_LESS, "OpenGL enum mismatch"); -static_assert(underlying_type(DepthMode::Equal) == GL_EQUAL, "OpenGL enum mismatch"); -static_assert(underlying_type(DepthMode::LessEqual) == GL_LEQUAL, "OpenGL enum mismatch"); -static_assert(underlying_type(DepthMode::Greater) == GL_GREATER, "OpenGL enum mismatch"); -static_assert(underlying_type(DepthMode::NotEqual) == GL_NOTEQUAL, "OpenGL enum mismatch"); -static_assert(underlying_type(DepthMode::GreaterEqual) == GL_GEQUAL, "OpenGL enum mismatch"); -static_assert(underlying_type(DepthMode::Always) == GL_ALWAYS, "OpenGL enum mismatch"); - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/gl/depth_mode.hpp b/src/mbgl/gl/depth_mode.hpp deleted file mode 100644 index 37617e3c34..0000000000 --- a/src/mbgl/gl/depth_mode.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include <mbgl/util/range.hpp> - -namespace mbgl { -namespace gl { - -class DepthMode { -public: - enum Function { - Never = 0x0200, - Less = 0x0201, - Equal = 0x0202, - LessEqual = 0x0203, - Greater = 0x0204, - NotEqual = 0x0205, - GreaterEqual = 0x0206, - Always = 0x0207 - }; - - enum Mask : bool { - ReadOnly = false, - ReadWrite = true - }; - - Function func; - Mask mask; - Range<float> range; - - static DepthMode disabled() { - return DepthMode { Always, ReadOnly, { 0.0, 1.0 } }; - } -}; - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/gl/enum.cpp b/src/mbgl/gl/enum.cpp index 87b3a96284..a6f251a438 100644 --- a/src/mbgl/gl/enum.cpp +++ b/src/mbgl/gl/enum.cpp @@ -5,16 +5,6 @@ namespace mbgl { namespace gl { -// template <> -// gfx::PrimitiveType Enum::from(const platform::GLint value) { - -// } - -// template <> -// platform::GLenum Enum::to(const gfx::PrimitiveType value) { - -// } - template <> platform::GLenum Enum<gfx::PrimitiveType>::to(const gfx::PrimitiveType value) { switch (value) { @@ -50,8 +40,8 @@ platform::GLenum Enum<gfx::ColorBlendEquationType>::to(const gfx::ColorBlendEqua } template <> -gfx::ColorBlendFactorType Enum<gfx::ColorBlendFactorType>::from(const platform::GLint blendFactor) { - switch (blendFactor) { +gfx::ColorBlendFactorType Enum<gfx::ColorBlendFactorType>::from(const platform::GLint value) { + switch (value) { case GL_ZERO: return gfx::ColorBlendFactorType::Zero; case GL_ONE: return gfx::ColorBlendFactorType::One; case GL_SRC_COLOR: return gfx::ColorBlendFactorType::SrcColor; @@ -93,5 +83,45 @@ platform::GLenum Enum<gfx::ColorBlendFactorType>::to(const gfx::ColorBlendFactor return GL_INVALID_ENUM; } +template <> +gfx::DepthFunctionType Enum<gfx::DepthFunctionType>::from(const platform::GLint value) { + switch (value) { + case GL_NEVER: return gfx::DepthFunctionType::Never; + case GL_LESS: return gfx::DepthFunctionType::Less; + case GL_EQUAL: return gfx::DepthFunctionType::Equal; + case GL_LEQUAL: return gfx::DepthFunctionType::LessEqual; + case GL_GREATER: return gfx::DepthFunctionType::Greater; + case GL_NOTEQUAL: return gfx::DepthFunctionType::NotEqual; + case GL_GEQUAL: return gfx::DepthFunctionType::GreaterEqual; + case GL_ALWAYS: return gfx::DepthFunctionType::Always; + } + return {}; +} + +template <> +platform::GLenum Enum<gfx::DepthFunctionType>::to(const gfx::DepthFunctionType value) { + switch (value) { + case gfx::DepthFunctionType::Never: return GL_NEVER; + case gfx::DepthFunctionType::Less: return GL_LESS; + case gfx::DepthFunctionType::Equal: return GL_EQUAL; + case gfx::DepthFunctionType::LessEqual: return GL_LEQUAL; + case gfx::DepthFunctionType::Greater: return GL_GREATER; + case gfx::DepthFunctionType::NotEqual: return GL_NOTEQUAL; + case gfx::DepthFunctionType::GreaterEqual: return GL_GEQUAL; + case gfx::DepthFunctionType::Always: return GL_ALWAYS; + } + return GL_INVALID_ENUM; +} + +template <> +gfx::DepthMaskType Enum<gfx::DepthMaskType>::from(const platform::GLboolean value) { + return value ? gfx::DepthMaskType::ReadWrite : gfx::DepthMaskType::ReadOnly; +} + +template <> +platform::GLboolean Enum<gfx::DepthMaskType>::to(const gfx::DepthMaskType value) { + return value == gfx::DepthMaskType::ReadWrite ? GL_TRUE : GL_FALSE; +} + } // namespace gl } // namespace mbgl diff --git a/src/mbgl/gl/enum.hpp b/src/mbgl/gl/enum.hpp index aaed3a962b..6aa29efdb1 100644 --- a/src/mbgl/gl/enum.hpp +++ b/src/mbgl/gl/enum.hpp @@ -2,14 +2,19 @@ #include <mbgl/platform/gl_functions.hpp> +#include <type_traits> + namespace mbgl { namespace gl { template <typename T> class Enum { public: - static T from(const platform::GLint); - static platform::GLenum to(T); + using InType = std::conditional_t<std::is_same<std::underlying_type_t<T>, bool>::value, platform::GLboolean, platform::GLint>; + using OutType = std::conditional_t<std::is_same<std::underlying_type_t<T>, bool>::value, platform::GLboolean, platform::GLenum>; + + static T from(const InType); + static OutType to(T); }; } // namespace gl diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp index 83dd9a86f6..de51e8dcb6 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -115,7 +115,7 @@ public: template <class DrawMode> void draw(Context& context, DrawMode drawMode, - DepthMode depthMode, + gfx::DepthMode depthMode, StencilMode stencilMode, gfx::ColorMode colorMode, CullFaceMode cullFaceMode, diff --git a/src/mbgl/gl/value.cpp b/src/mbgl/gl/value.cpp index d17ffb6714..800c39a9d6 100644 --- a/src/mbgl/gl/value.cpp +++ b/src/mbgl/gl/value.cpp @@ -60,13 +60,13 @@ StencilMask::Type StencilMask::Get() { const constexpr DepthMask::Type DepthMask::Default; void DepthMask::Set(const Type& value) { - MBGL_CHECK_ERROR(glDepthMask(value)); + MBGL_CHECK_ERROR(glDepthMask(Enum<gfx::DepthMaskType>::to(value))); } DepthMask::Type DepthMask::Get() { GLboolean depthMask; MBGL_CHECK_ERROR(glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask)); - return depthMask; + return Enum<gfx::DepthMaskType>::from(depthMask); } const constexpr ColorMask::Type ColorMask::Default; diff --git a/src/mbgl/gl/value.hpp b/src/mbgl/gl/value.hpp index b284ada51b..d7a8ddf6fe 100644 --- a/src/mbgl/gl/value.hpp +++ b/src/mbgl/gl/value.hpp @@ -1,7 +1,7 @@ #pragma once #include <mbgl/gl/types.hpp> -#include <mbgl/gl/depth_mode.hpp> +#include <mbgl/gfx/depth_mode.hpp> #include <mbgl/gl/stencil_mode.hpp> #include <mbgl/gfx/color_mode.hpp> #include <mbgl/gl/cull_face_mode.hpp> @@ -47,8 +47,8 @@ struct StencilMask { }; struct DepthMask { - using Type = bool; - static const constexpr Type Default = true; + using Type = gfx::DepthMaskType; + static const constexpr Type Default = gfx::DepthMaskType::ReadWrite; static void Set(const Type&); static Type Get(); }; @@ -112,8 +112,8 @@ struct DepthTest { }; struct DepthFunc { - using Type = DepthMode::Function; - static const constexpr Type Default = DepthMode::Less; + using Type = gfx::DepthFunctionType; + static const constexpr Type Default = gfx::DepthFunctionType::Less; static void Set(const Type&); static Type Get(); }; |