diff options
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r-- | src/mbgl/gl/context.cpp | 13 | ||||
-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/program.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/gl/value.cpp | 36 | ||||
-rw-r--r-- | src/mbgl/gl/value.hpp | 22 |
7 files changed, 133 insertions, 0 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 4afbe5af1e..22b22b549d 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -617,6 +617,9 @@ void Context::setDirtyState() { clearDepth.setDirty(); clearColor.setDirty(); clearStencil.setDirty(); + cullFace.setDirty(); + cullFaceSide.setDirty(); + frontFace.setDirty(); program.setDirty(); lineWidth.setDirty(); activeTextureUnit.setDirty(); @@ -663,6 +666,16 @@ void Context::clear(optional<mbgl::Color> color, MBGL_CHECK_ERROR(glClear(mask)); } +void Context::setCullFaceMode(const CullFaceMode& mode) { + cullFace = mode.cullFace; + + // 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; +} + #if not MBGL_USE_GLES2 void Context::setDrawMode(const Points& points) { pointSize = points.pointSize; diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index c8181d7e80..f8cb546585 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -172,6 +172,7 @@ public: void setDepthMode(const DepthMode&); void setStencilMode(const StencilMode&); void setColorMode(const ColorMode&); + void setCullFaceMode(const CullFaceMode&); void draw(PrimitiveType, std::size_t indexOffset, @@ -263,6 +264,9 @@ private: State<value::ClearStencil> clearStencil; State<value::LineWidth> lineWidth; State<value::BindRenderbuffer> bindRenderbuffer; + State<value::CullFace> cullFace; + State<value::CullFaceSide> cullFaceSide; + State<value::FrontFace> frontFace; #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 new file mode 100644 index 0000000000..42729aeea7 --- /dev/null +++ b/src/mbgl/gl/cull_face_mode.cpp @@ -0,0 +1,16 @@ +#include <mbgl/gl/cull_face_mode.hpp> +#include <mbgl/gl/gl.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 new file mode 100644 index 0000000000..a408d7a88c --- /dev/null +++ b/src/mbgl/gl/cull_face_mode.hpp @@ -0,0 +1,40 @@ +#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/program.hpp b/src/mbgl/gl/program.hpp index f33501cd11..3ef7955949 100644 --- a/src/mbgl/gl/program.hpp +++ b/src/mbgl/gl/program.hpp @@ -118,6 +118,7 @@ public: DepthMode depthMode, StencilMode stencilMode, ColorMode colorMode, + CullFaceMode cullFaceMode, const UniformValues& uniformValues, VertexArray& vertexArray, const AttributeBindings& attributeBindings, @@ -130,6 +131,7 @@ public: context.setDepthMode(depthMode); context.setStencilMode(stencilMode); context.setColorMode(colorMode); + context.setCullFaceMode(cullFaceMode); context.program = program; diff --git a/src/mbgl/gl/value.cpp b/src/mbgl/gl/value.cpp index 092403af0d..581acd0358 100644 --- a/src/mbgl/gl/value.cpp +++ b/src/mbgl/gl/value.cpp @@ -303,6 +303,42 @@ BindRenderbuffer::Type BindRenderbuffer::Get() { return binding; } +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)); +} + +CullFace::Type CullFace::Get() { + GLboolean cullFace; + MBGL_CHECK_ERROR(cullFace = glIsEnabled(GL_CULL_FACE)); + return cullFace ? CullFaceMode::Enable : CullFaceMode::Disable; +} + +const constexpr CullFaceSide::Type CullFaceSide::Default; + +void CullFaceSide::Set(const Type& value) { + MBGL_CHECK_ERROR(glCullFace(static_cast<GLenum>(value))); +} + +CullFaceSide::Type CullFaceSide::Get() { + GLint cullFaceMode; + MBGL_CHECK_ERROR(glGetIntegerv(GL_CULL_FACE_MODE, &cullFaceMode)); + return static_cast<Type>(cullFaceMode); +} + +const constexpr FrontFace::Type FrontFace::Default; + +void FrontFace::Set(const Type& value) { + MBGL_CHECK_ERROR(glFrontFace(static_cast<GLenum>(value))); +} + +FrontFace::Type FrontFace::Get() { + GLint frontFace; + MBGL_CHECK_ERROR(glGetIntegerv(GL_FRONT_FACE, &frontFace)); + return static_cast<Type>(frontFace); +} + const constexpr BindTexture::Type BindTexture::Default; void BindTexture::Set(const Type& value) { diff --git a/src/mbgl/gl/value.hpp b/src/mbgl/gl/value.hpp index 7b85a5ff4b..25f22aa038 100644 --- a/src/mbgl/gl/value.hpp +++ b/src/mbgl/gl/value.hpp @@ -4,6 +4,7 @@ #include <mbgl/gl/depth_mode.hpp> #include <mbgl/gl/stencil_mode.hpp> #include <mbgl/gl/color_mode.hpp> +#include <mbgl/gl/cull_face_mode.hpp> #include <mbgl/gl/attribute.hpp> #include <mbgl/util/color.hpp> #include <mbgl/util/size.hpp> @@ -212,6 +213,27 @@ struct BindRenderbuffer { static Type Get(); }; +struct CullFace { + using Type = CullFaceMode::CullFace; + static const constexpr Type Default = CullFaceMode::Disable; + static void Set(const Type&); + static Type Get(); +}; + +struct CullFaceSide { + using Type = CullFaceMode::CullFaceSide; + static const constexpr Type Default = CullFaceMode::Back; + static void Set(const Type&); + static Type Get(); +}; + +struct FrontFace { + using Type = CullFaceMode::FrontFace; + static const constexpr Type Default = CullFaceMode::CounterClockwise; + static void Set(const Type&); + static Type Get(); +}; + struct BindTexture { using Type = gl::TextureID; static const constexpr Type Default = 0; |