Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Enable face culling
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Aug 30, 2018
1 parent d3f62a0 commit 1072d4c
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mapbox-gl-js
Submodule mapbox-gl-js updated 119 files
12 changes: 12 additions & 0 deletions src/mbgl/gl/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@ void Context::setDirtyState() {
clearDepth.setDirty();
clearColor.setDirty();
clearStencil.setDirty();
cullFace.setDirty();
cullFaceMode.setDirty();
frontFace.setDirty();
program.setDirty();
lineWidth.setDirty();
activeTextureUnit.setDirty();
Expand Down Expand Up @@ -663,6 +666,15 @@ void Context::clear(optional<mbgl::Color> color,
MBGL_CHECK_ERROR(glClear(mask));
}

void Context::setCullFace(CullFace cullFace_, optional<CullFaceMode> cullFaceMode_, optional<FrontFace> frontFace_) {
cullFace = 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.
cullFaceMode = cullFaceMode_.value_or(gl::value::CullFaceMode::Default);
frontFace = frontFace_.value_or(gl::value::FrontFace::Default);
}

#if not MBGL_USE_GLES2
void Context::setDrawMode(const Points& points) {
pointSize = points.pointSize;
Expand Down
5 changes: 5 additions & 0 deletions src/mbgl/gl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ class Context {
optional<float> depth,
optional<int32_t> stencil);

void setCullFace(CullFace, optional<CullFaceMode> = CullFaceMode::Back, optional<FrontFace> = FrontFace::CounterClockwise);

void setDrawMode(const Points&);
void setDrawMode(const Lines&);
void setDrawMode(const LineStrip&);
Expand Down Expand Up @@ -263,6 +265,9 @@ class Context {
State<value::ClearStencil> clearStencil;
State<value::LineWidth> lineWidth;
State<value::BindRenderbuffer> bindRenderbuffer;
State<value::CullFace> cullFace;
State<value::CullFaceMode> cullFaceMode;
State<value::FrontFace> frontFace;
#if not MBGL_USE_GLES2
State<value::PointSize> pointSize;
#endif // MBGL_USE_GLES2
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/gl/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class Program {
context.setDepthMode(depthMode);
context.setStencilMode(stencilMode);
context.setColorMode(colorMode);
context.setCullFace(CullFace::Enable, CullFaceMode::Back);

context.program = program;

Expand Down
16 changes: 16 additions & 0 deletions src/mbgl/gl/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,21 @@ enum class BufferUsage : uint32_t {
DynamicDraw = 0x88E8,
};

enum class CullFace : bool {
Disable = false,
Enable = true,
};

enum class CullFaceMode : uint32_t {
Front = 0x0404,
Back = 0x0405,
FrontAndBack = 0x0408,
};

enum class FrontFace : uint32_t {
Clockwise = 0x0900,
CounterClockwise = 0x0901
};

} // namespace gl
} // namespace mbgl
36 changes: 36 additions & 0 deletions src/mbgl/gl/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 == gl::CullFace::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 ? gl::CullFace::Enable : gl::CullFace::Disable;
}

const constexpr CullFaceMode::Type CullFaceMode::Default;

void CullFaceMode::Set(const Type& value) {
MBGL_CHECK_ERROR(glCullFace(static_cast<GLenum>(value)));
}

CullFaceMode::Type CullFaceMode::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) {
Expand Down
21 changes: 21 additions & 0 deletions src/mbgl/gl/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,27 @@ struct BindRenderbuffer {
static Type Get();
};

struct CullFace {
using Type = gl::CullFace;
static const constexpr Type Default = gl::CullFace::Disable;
static void Set(const Type&);
static Type Get();
};

struct CullFaceMode {
using Type = gl::CullFaceMode;
static const constexpr Type Default = gl::CullFaceMode::Back;
static void Set(const Type&);
static Type Get();
};

struct FrontFace {
using Type = gl::FrontFace;
static const constexpr Type Default = gl::FrontFace::CounterClockwise;
static void Set(const Type&);
static Type Get();
};

struct BindTexture {
using Type = gl::TextureID;
static const constexpr Type Default = 0;
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/renderer/layers/render_custom_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void RenderCustomLayer::render(PaintParameters& paintParameters, RenderSource*)
glContext.setDepthMode(paintParameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly));
glContext.setStencilMode(gl::StencilMode::disabled());
glContext.setColorMode(paintParameters.colorModeForRenderPass());
glContext.setCullFace(gl::CullFace::Disable);

CustomLayerRenderParameters parameters;

Expand Down

0 comments on commit 1072d4c

Please sign in to comment.