[core] move CullFaceMode to gfx namespace

This commit is contained in:
Konstantin Käfer
2019-02-28 12:31:54 +01:00
parent 4372ce2b90
commit 67a9dc35bf
27 changed files with 126 additions and 110 deletions

View File

@@ -18,7 +18,6 @@
"src/mbgl/geometry/line_atlas.cpp",
"src/mbgl/gl/attribute.cpp",
"src/mbgl/gl/context.cpp",
"src/mbgl/gl/cull_face_mode.cpp",
"src/mbgl/gl/debugging.cpp",
"src/mbgl/gl/debugging_extension.cpp",
"src/mbgl/gl/enum.cpp",
@@ -498,6 +497,7 @@
"mbgl/geometry/line_atlas.hpp": "src/mbgl/geometry/line_atlas.hpp",
"mbgl/gfx/attribute.hpp": "src/mbgl/gfx/attribute.hpp",
"mbgl/gfx/color_mode.hpp": "src/mbgl/gfx/color_mode.hpp",
"mbgl/gfx/cull_face_mode.hpp": "src/mbgl/gfx/cull_face_mode.hpp",
"mbgl/gfx/depth_mode.hpp": "src/mbgl/gfx/depth_mode.hpp",
"mbgl/gfx/draw_mode.hpp": "src/mbgl/gfx/draw_mode.hpp",
"mbgl/gfx/primitives.hpp": "src/mbgl/gfx/primitives.hpp",
@@ -506,7 +506,6 @@
"mbgl/gfx/uniform.hpp": "src/mbgl/gfx/uniform.hpp",
"mbgl/gl/attribute.hpp": "src/mbgl/gl/attribute.hpp",
"mbgl/gl/context.hpp": "src/mbgl/gl/context.hpp",
"mbgl/gl/cull_face_mode.hpp": "src/mbgl/gl/cull_face_mode.hpp",
"mbgl/gl/debugging.hpp": "src/mbgl/gl/debugging.hpp",
"mbgl/gl/debugging_extension.hpp": "src/mbgl/gl/debugging_extension.hpp",
"mbgl/gl/defines.hpp": "src/mbgl/gl/defines.hpp",

View File

@@ -0,0 +1,24 @@
#pragma once
#include <mbgl/gfx/types.hpp>
namespace mbgl {
namespace gfx {
class CullFaceMode {
public:
bool enabled;
CullFaceSideType side;
CullFaceWindingType winding;
static CullFaceMode disabled() {
return { false, CullFaceSideType::Back, CullFaceWindingType::CounterClockwise };
}
static CullFaceMode backCCW() {
return { true, CullFaceSideType::Back, CullFaceWindingType::CounterClockwise };
}
};
} // namespace gfx
} // namespace mbgl

View File

@@ -77,5 +77,16 @@ enum class StencilOpType : uint8_t {
DecrementWrap,
};
enum CullFaceSideType : uint8_t {
Front,
Back,
FrontAndBack,
};
enum CullFaceWindingType : uint8_t {
Clockwise,
CounterClockwise,
};
} // namespace gfx
} // namespace mbgl

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -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;

View File

@@ -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();
};

View File

@@ -61,7 +61,7 @@ public:
gfx::DepthMode depthMode,
gfx::StencilMode stencilMode,
gfx::ColorMode colorMode,
gl::CullFaceMode cullFaceMode,
gfx::CullFaceMode cullFaceMode,
const UniformValues& uniformValues,
const gl::VertexBuffer<gfx::Vertex<CollisionBoxLayoutAttributes>>& layoutVertexBuffer,
const gl::VertexBuffer<gfx::Vertex<CollisionBoxDynamicAttributes>>& dynamicVertexBuffer,
@@ -142,7 +142,7 @@ public:
gfx::DepthMode depthMode,
gfx::StencilMode stencilMode,
gfx::ColorMode colorMode,
gl::CullFaceMode cullFaceMode,
gfx::CullFaceMode cullFaceMode,
const UniformValues& uniformValues,
const gl::VertexBuffer<gfx::Vertex<CollisionBoxLayoutAttributes>>& layoutVertexBuffer,
const gl::VertexBuffer<gfx::Vertex<CollisionBoxDynamicAttributes>>& dynamicVertexBuffer,

View File

@@ -74,7 +74,7 @@ public:
gfx::DepthMode depthMode,
gfx::StencilMode stencilMode,
gfx::ColorMode colorMode,
gl::CullFaceMode cullFaceMode,
gfx::CullFaceMode cullFaceMode,
const gl::IndexBuffer<DrawMode>& indexBuffer,
const SegmentVector<Attributes>& segments,
const typename AllUniforms::Values& allUniformValues,

View File

@@ -309,7 +309,7 @@ public:
gfx::DepthMode depthMode,
gfx::StencilMode stencilMode,
gfx::ColorMode colorMode,
gl::CullFaceMode cullFaceMode,
gfx::CullFaceMode cullFaceMode,
const gl::IndexBuffer<DrawMode>& indexBuffer,
const SegmentVector<Attributes>& segments,
const typename AllUniforms::Values& allUniformValues,

View File

@@ -71,7 +71,7 @@ void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) {
parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly),
gfx::StencilMode::disabled(),
parameters.colorModeForRenderPass(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
parameters.staticData.quadTriangleIndexBuffer,
parameters.staticData.tileTriangleSegments,
allUniformValues,

View File

@@ -102,7 +102,7 @@ void RenderCircleLayer::render(PaintParameters& parameters, RenderSource*) {
? parameters.stencilModeForClipping(tile.clip)
: gfx::StencilMode::disabled(),
parameters.colorModeForRenderPass(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
*bucket.indexBuffer,
bucket.segments,
allUniformValues,

View File

@@ -65,7 +65,7 @@ void RenderCustomLayer::render(PaintParameters& paintParameters, RenderSource*)
glContext.setDepthMode(paintParameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly));
glContext.setStencilMode(gfx::StencilMode::disabled());
glContext.setColorMode(paintParameters.colorModeForRenderPass());
glContext.setCullFaceMode(gl::CullFaceMode::disabled());
glContext.setCullFaceMode(gfx::CullFaceMode::disabled());
CustomLayerRenderParameters parameters;

View File

@@ -96,7 +96,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*
parameters.depthModeFor3D(gfx::DepthMaskType::ReadWrite),
gfx::StencilMode::disabled(),
parameters.colorModeForRenderPass(),
gl::CullFaceMode::backCCW(),
gfx::CullFaceMode::backCCW(),
*tileBucket.indexBuffer,
tileBucket.triangleSegments,
allUniformValues,
@@ -197,7 +197,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*
gfx::DepthMode::disabled(),
gfx::StencilMode::disabled(),
parameters.colorModeForRenderPass(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
parameters.staticData.quadTriangleIndexBuffer,
parameters.staticData.extrusionTextureSegments,
allUniformValues,

View File

@@ -105,7 +105,7 @@ void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) {
depthMode,
parameters.stencilModeForClipping(tile.clip),
parameters.colorModeForRenderPass(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
indexBuffer,
segments,
allUniformValues,
@@ -195,7 +195,7 @@ void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) {
depthMode,
parameters.stencilModeForClipping(tile.clip),
parameters.colorModeForRenderPass(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
indexBuffer,
segments,
allUniformValues,

View File

@@ -123,7 +123,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) {
parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly),
stencilMode,
gfx::ColorMode::additive(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
*bucket.indexBuffer,
bucket.segments,
allUniformValues,
@@ -171,7 +171,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) {
gfx::DepthMode::disabled(),
gfx::StencilMode::disabled(),
parameters.colorModeForRenderPass(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
parameters.staticData.quadTriangleIndexBuffer,
parameters.staticData.extrusionTextureSegments,
allUniformValues,

View File

@@ -100,7 +100,7 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src
parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly),
gfx::StencilMode::disabled(),
parameters.colorModeForRenderPass(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
indexBuffer,
segments,
allUniformValues,
@@ -161,7 +161,7 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src
parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly),
gfx::StencilMode::disabled(),
parameters.colorModeForRenderPass(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
parameters.staticData.quadTriangleIndexBuffer,
parameters.staticData.rasterSegments,
allUniformValues,

View File

@@ -91,7 +91,7 @@ void RenderLineLayer::render(PaintParameters& parameters, RenderSource*) {
parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly),
parameters.stencilModeForClipping(tile.clip),
parameters.colorModeForRenderPass(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
*bucket.indexBuffer,
bucket.segments,
allUniformValues,

View File

@@ -114,7 +114,7 @@ void RenderRasterLayer::render(PaintParameters& parameters, RenderSource* source
parameters.depthModeForSublayer(0, gfx::DepthMaskType::ReadOnly),
gfx::StencilMode::disabled(),
parameters.colorModeForRenderPass(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
indexBuffer,
segments,
allUniformValues,

View File

@@ -122,7 +122,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
: gfx::DepthMode::disabled(),
gfx::StencilMode::disabled(),
parameters.colorModeForRenderPass(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
*buffers.indexBuffer,
buffers.segments,
allUniformValues,
@@ -255,7 +255,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
gfx::DepthMode::disabled(),
gfx::StencilMode::disabled(),
parameters.colorModeForRenderPass(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
CollisionBoxProgram::UniformValues {
uniforms::u_matrix::Value( tile.matrix ),
uniforms::u_extrude_scale::Value( extrudeScale ),
@@ -290,7 +290,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
gfx::DepthMode::disabled(),
gfx::StencilMode::disabled(),
parameters.colorModeForRenderPass(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
CollisionCircleProgram::UniformValues {
uniforms::u_matrix::Value( tile.matrix ),
uniforms::u_extrude_scale::Value( extrudeScale ),

View File

@@ -99,7 +99,7 @@ void RenderTile::finishRender(PaintParameters& parameters) {
gfx::DepthMode::disabled(),
parameters.stencilModeForClipping(clip),
gfx::ColorMode::unblended(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
*tile.debugBucket->indexBuffer,
tile.debugBucket->segments,
program.computeAllUniformValues(
@@ -121,7 +121,7 @@ void RenderTile::finishRender(PaintParameters& parameters) {
gfx::DepthMode::disabled(),
parameters.stencilModeForClipping(clip),
gfx::ColorMode::unblended(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
*tile.debugBucket->indexBuffer,
tile.debugBucket->segments,
program.computeAllUniformValues(
@@ -145,7 +145,7 @@ void RenderTile::finishRender(PaintParameters& parameters) {
gfx::DepthMode::disabled(),
parameters.stencilModeForClipping(clip),
gfx::ColorMode::unblended(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
parameters.staticData.tileBorderIndexBuffer,
parameters.staticData.tileBorderSegments,
program.computeAllUniformValues(

View File

@@ -453,7 +453,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
gfx::StencilOpType::Replace
},
gfx::ColorMode::disabled(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
parameters.staticData.quadTriangleIndexBuffer,
parameters.staticData.tileTriangleSegments,
program.computeAllUniformValues(

View File

@@ -67,7 +67,7 @@ void RenderImageSource::finishRender(PaintParameters& parameters) {
gfx::DepthMode::disabled(),
gfx::StencilMode::disabled(),
gfx::ColorMode::unblended(),
gl::CullFaceMode::disabled(),
gfx::CullFaceMode::disabled(),
parameters.staticData.tileBorderIndexBuffer,
parameters.staticData.tileBorderSegments,
programInstance.computeAllUniformValues(