diff options
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r-- | src/mbgl/gl/context.cpp | 18 | ||||
-rw-r--r-- | src/mbgl/gl/enum.cpp | 97 | ||||
-rw-r--r-- | src/mbgl/gl/enum.hpp | 16 | ||||
-rw-r--r-- | src/mbgl/gl/value.cpp | 78 | ||||
-rw-r--r-- | src/mbgl/gl/value.hpp | 10 |
5 files changed, 128 insertions, 91 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index ee82fa76ae..a7b40b6448 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -1,4 +1,5 @@ #include <mbgl/gl/context.hpp> +#include <mbgl/gl/enum.hpp> #include <mbgl/gl/debugging_extension.hpp> #include <mbgl/gl/vertex_array_extension.hpp> #include <mbgl/gl/program_binary_extension.hpp> @@ -735,7 +736,7 @@ void Context::setColorMode(const gfx::ColorMode& color) { blend = true; blendColor = color.blendColor; apply_visitor([&] (const auto& blendFunction) { - blendEquation = gfx::ColorMode::BlendEquation(blendFunction.equation); + blendEquation = gfx::ColorBlendEquationType(blendFunction.equation); blendFunc = { blendFunction.srcFactor, blendFunction.dstFactor }; }, color.blendFunction); } @@ -743,24 +744,11 @@ void Context::setColorMode(const gfx::ColorMode& color) { colorMask = color.mask; } -GLenum toGLenum(const gfx::PrimitiveType primitiveType) { - switch (primitiveType) { - case gfx::PrimitiveType::Points: return GL_POINTS; - case gfx::PrimitiveType::Lines: return GL_LINES; - case gfx::PrimitiveType::LineLoop: return GL_LINE_LOOP; - case gfx::PrimitiveType::LineStrip: return GL_LINE_STRIP; - case gfx::PrimitiveType::Triangles: return GL_TRIANGLES; - case gfx::PrimitiveType::TriangleStrip: return GL_TRIANGLE_STRIP; - case gfx::PrimitiveType::TriangleFan: return GL_TRIANGLE_FAN; - } - return GL_INVALID_ENUM; -} - void Context::draw(gfx::PrimitiveType primitiveType, std::size_t indexOffset, std::size_t indexLength) { MBGL_CHECK_ERROR(glDrawElements( - toGLenum(primitiveType), + Enum<gfx::PrimitiveType>::to(primitiveType), static_cast<GLsizei>(indexLength), GL_UNSIGNED_SHORT, reinterpret_cast<GLvoid*>(sizeof(uint16_t) * indexOffset))); diff --git a/src/mbgl/gl/enum.cpp b/src/mbgl/gl/enum.cpp new file mode 100644 index 0000000000..87b3a96284 --- /dev/null +++ b/src/mbgl/gl/enum.cpp @@ -0,0 +1,97 @@ +#include <mbgl/gl/enum.hpp> +#include <mbgl/gfx/types.hpp> +#include <mbgl/gl/defines.hpp> + +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) { + case gfx::PrimitiveType::Points: return GL_POINTS; + case gfx::PrimitiveType::Lines: return GL_LINES; + case gfx::PrimitiveType::LineLoop: return GL_LINE_LOOP; + case gfx::PrimitiveType::LineStrip: return GL_LINE_STRIP; + case gfx::PrimitiveType::Triangles: return GL_TRIANGLES; + case gfx::PrimitiveType::TriangleStrip: return GL_TRIANGLE_STRIP; + case gfx::PrimitiveType::TriangleFan: return GL_TRIANGLE_FAN; + } + return GL_INVALID_ENUM; +} + +template <> +gfx::ColorBlendEquationType Enum<gfx::ColorBlendEquationType>::from(const platform::GLint value) { + switch (value) { + case GL_FUNC_ADD: return gfx::ColorBlendEquationType::Add; + case GL_FUNC_SUBTRACT: return gfx::ColorBlendEquationType::Subtract; + case GL_FUNC_REVERSE_SUBTRACT: return gfx::ColorBlendEquationType::ReverseSubtract; + } + return {}; +} + +template <> +platform::GLenum Enum<gfx::ColorBlendEquationType>::to(const gfx::ColorBlendEquationType value) { + switch (value) { + case gfx::ColorBlendEquationType::Add: return GL_FUNC_ADD; + case gfx::ColorBlendEquationType::Subtract: return GL_FUNC_SUBTRACT; + case gfx::ColorBlendEquationType::ReverseSubtract: return GL_FUNC_REVERSE_SUBTRACT; + } + return GL_INVALID_ENUM; +} + +template <> +gfx::ColorBlendFactorType Enum<gfx::ColorBlendFactorType>::from(const platform::GLint blendFactor) { + switch (blendFactor) { + case GL_ZERO: return gfx::ColorBlendFactorType::Zero; + case GL_ONE: return gfx::ColorBlendFactorType::One; + case GL_SRC_COLOR: return gfx::ColorBlendFactorType::SrcColor; + case GL_ONE_MINUS_SRC_COLOR: return gfx::ColorBlendFactorType::OneMinusSrcColor; + case GL_DST_COLOR: return gfx::ColorBlendFactorType::DstColor; + case GL_ONE_MINUS_DST_COLOR: return gfx::ColorBlendFactorType::OneMinusDstColor; + case GL_SRC_ALPHA: return gfx::ColorBlendFactorType::SrcAlpha; + case GL_ONE_MINUS_SRC_ALPHA: return gfx::ColorBlendFactorType::OneMinusSrcAlpha; + case GL_DST_ALPHA: return gfx::ColorBlendFactorType::DstAlpha; + case GL_ONE_MINUS_DST_ALPHA: return gfx::ColorBlendFactorType::OneMinusDstAlpha; + case GL_CONSTANT_COLOR: return gfx::ColorBlendFactorType::ConstantColor; + case GL_ONE_MINUS_CONSTANT_COLOR: return gfx::ColorBlendFactorType::OneMinusConstantColor; + case GL_CONSTANT_ALPHA: return gfx::ColorBlendFactorType::ConstantAlpha; + case GL_ONE_MINUS_CONSTANT_ALPHA: return gfx::ColorBlendFactorType::OneMinusConstantAlpha; + case GL_SRC_ALPHA_SATURATE: return gfx::ColorBlendFactorType::SrcAlphaSaturate; + } + return {}; +} + +template <> +platform::GLenum Enum<gfx::ColorBlendFactorType>::to(const gfx::ColorBlendFactorType value) { + switch (value) { + case gfx::ColorBlendFactorType::Zero: return GL_ZERO; + case gfx::ColorBlendFactorType::One: return GL_ONE; + case gfx::ColorBlendFactorType::SrcColor: return GL_SRC_COLOR; + case gfx::ColorBlendFactorType::OneMinusSrcColor: return GL_ONE_MINUS_SRC_COLOR; + case gfx::ColorBlendFactorType::DstColor: return GL_DST_COLOR; + case gfx::ColorBlendFactorType::OneMinusDstColor: return GL_ONE_MINUS_DST_COLOR; + case gfx::ColorBlendFactorType::SrcAlpha: return GL_SRC_ALPHA; + case gfx::ColorBlendFactorType::OneMinusSrcAlpha: return GL_ONE_MINUS_SRC_ALPHA; + case gfx::ColorBlendFactorType::DstAlpha: return GL_DST_ALPHA; + case gfx::ColorBlendFactorType::OneMinusDstAlpha: return GL_ONE_MINUS_DST_ALPHA; + case gfx::ColorBlendFactorType::ConstantColor: return GL_CONSTANT_COLOR; + case gfx::ColorBlendFactorType::OneMinusConstantColor: return GL_ONE_MINUS_CONSTANT_COLOR; + case gfx::ColorBlendFactorType::ConstantAlpha: return GL_CONSTANT_ALPHA; + case gfx::ColorBlendFactorType::OneMinusConstantAlpha: return GL_ONE_MINUS_CONSTANT_ALPHA; + case gfx::ColorBlendFactorType::SrcAlphaSaturate: return GL_SRC_ALPHA_SATURATE; + } + return GL_INVALID_ENUM; +} + +} // namespace gl +} // namespace mbgl diff --git a/src/mbgl/gl/enum.hpp b/src/mbgl/gl/enum.hpp new file mode 100644 index 0000000000..aaed3a962b --- /dev/null +++ b/src/mbgl/gl/enum.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include <mbgl/platform/gl_functions.hpp> + +namespace mbgl { +namespace gl { + +template <typename T> +class Enum { +public: + static T from(const platform::GLint); + static platform::GLenum to(T); +}; + +} // namespace gl +} // namespace mbgl diff --git a/src/mbgl/gl/value.cpp b/src/mbgl/gl/value.cpp index b926f599ee..d17ffb6714 100644 --- a/src/mbgl/gl/value.cpp +++ b/src/mbgl/gl/value.cpp @@ -1,6 +1,7 @@ #include <mbgl/gl/value.hpp> #include <mbgl/gl/context.hpp> #include <mbgl/gl/vertex_array_extension.hpp> +#include <mbgl/gl/enum.hpp> namespace mbgl { namespace gl { @@ -8,9 +9,6 @@ namespace value { using namespace platform; -template <class T> -T fromGLenum(const GLint); - const constexpr ClearDepth::Type ClearDepth::Default; void ClearDepth::Set(const Type& value) { @@ -177,91 +175,29 @@ Blend::Type Blend::Get() { const constexpr BlendEquation::Type BlendEquation::Default; -GLenum toGLenum(const gfx::ColorMode::BlendEquation blendEquation) { - switch (blendEquation) { - case gfx::ColorMode::BlendEquation::Add: return GL_FUNC_ADD; - case gfx::ColorMode::BlendEquation::Subtract: return GL_FUNC_SUBTRACT; - case gfx::ColorMode::BlendEquation::ReverseSubtract: return GL_FUNC_REVERSE_SUBTRACT; - } - return GL_INVALID_ENUM; -} - void BlendEquation::Set(const Type& value) { - MBGL_CHECK_ERROR(glBlendEquation(toGLenum(value))); -} - -template <> -gfx::ColorMode::BlendEquation fromGLenum<gfx::ColorMode::BlendEquation>(const GLint blendEquation) { - switch (blendEquation) { - case GL_FUNC_ADD: return gfx::ColorMode::BlendEquation::Add; - case GL_FUNC_SUBTRACT: return gfx::ColorMode::BlendEquation::Subtract; - case GL_FUNC_REVERSE_SUBTRACT: return gfx::ColorMode::BlendEquation::ReverseSubtract; - } - return {}; + MBGL_CHECK_ERROR(glBlendEquation(Enum<gfx::ColorBlendEquationType>::to(value))); } BlendEquation::Type BlendEquation::Get() { GLint blend; MBGL_CHECK_ERROR(glGetIntegerv(GL_BLEND_EQUATION_RGB, &blend)); - return fromGLenum<gfx::ColorMode::BlendEquation>(blend); + return Enum<gfx::ColorBlendEquationType>::from(blend); } const constexpr BlendFunc::Type BlendFunc::Default; -GLenum toGLenum(const gfx::ColorMode::BlendFactor blendFactor) { - switch (blendFactor) { - case gfx::ColorMode::BlendFactor::Zero: return GL_ZERO; - case gfx::ColorMode::BlendFactor::One: return GL_ONE; - case gfx::ColorMode::BlendFactor::SrcColor: return GL_SRC_COLOR; - case gfx::ColorMode::BlendFactor::OneMinusSrcColor: return GL_ONE_MINUS_SRC_COLOR; - case gfx::ColorMode::BlendFactor::DstColor: return GL_DST_COLOR; - case gfx::ColorMode::BlendFactor::OneMinusDstColor: return GL_ONE_MINUS_DST_COLOR; - case gfx::ColorMode::BlendFactor::SrcAlpha: return GL_SRC_ALPHA; - case gfx::ColorMode::BlendFactor::OneMinusSrcAlpha: return GL_ONE_MINUS_SRC_ALPHA; - case gfx::ColorMode::BlendFactor::DstAlpha: return GL_DST_ALPHA; - case gfx::ColorMode::BlendFactor::OneMinusDstAlpha: return GL_ONE_MINUS_DST_ALPHA; - case gfx::ColorMode::BlendFactor::ConstantColor: return GL_CONSTANT_COLOR; - case gfx::ColorMode::BlendFactor::OneMinusConstantColor: return GL_ONE_MINUS_CONSTANT_COLOR; - case gfx::ColorMode::BlendFactor::ConstantAlpha: return GL_CONSTANT_ALPHA; - case gfx::ColorMode::BlendFactor::OneMinusConstantAlpha: return GL_ONE_MINUS_CONSTANT_ALPHA; - case gfx::ColorMode::BlendFactor::SrcAlphaSaturate: return GL_SRC_ALPHA_SATURATE; - } - return GL_INVALID_ENUM; -} - void BlendFunc::Set(const Type& value) { - MBGL_CHECK_ERROR( - glBlendFunc(toGLenum(value.sfactor), toGLenum(value.dfactor))); -} - -template <> -gfx::ColorMode::BlendFactor fromGLenum<gfx::ColorMode::BlendFactor>(const GLint blendFactor) { - switch (blendFactor) { - case GL_ZERO: return gfx::ColorMode::BlendFactor::Zero; - case GL_ONE: return gfx::ColorMode::BlendFactor::One; - case GL_SRC_COLOR: return gfx::ColorMode::BlendFactor::SrcColor; - case GL_ONE_MINUS_SRC_COLOR: return gfx::ColorMode::BlendFactor::OneMinusSrcColor; - case GL_DST_COLOR: return gfx::ColorMode::BlendFactor::DstColor; - case GL_ONE_MINUS_DST_COLOR: return gfx::ColorMode::BlendFactor::OneMinusDstColor; - case GL_SRC_ALPHA: return gfx::ColorMode::BlendFactor::SrcAlpha; - case GL_ONE_MINUS_SRC_ALPHA: return gfx::ColorMode::BlendFactor::OneMinusSrcAlpha; - case GL_DST_ALPHA: return gfx::ColorMode::BlendFactor::DstAlpha; - case GL_ONE_MINUS_DST_ALPHA: return gfx::ColorMode::BlendFactor::OneMinusDstAlpha; - case GL_CONSTANT_COLOR: return gfx::ColorMode::BlendFactor::ConstantColor; - case GL_ONE_MINUS_CONSTANT_COLOR: return gfx::ColorMode::BlendFactor::OneMinusConstantColor; - case GL_CONSTANT_ALPHA: return gfx::ColorMode::BlendFactor::ConstantAlpha; - case GL_ONE_MINUS_CONSTANT_ALPHA: return gfx::ColorMode::BlendFactor::OneMinusConstantAlpha; - case GL_SRC_ALPHA_SATURATE: return gfx::ColorMode::BlendFactor::SrcAlphaSaturate; - } - return {}; + MBGL_CHECK_ERROR(glBlendFunc(Enum<gfx::ColorBlendFactorType>::to(value.sfactor), + Enum<gfx::ColorBlendFactorType>::to(value.dfactor))); } BlendFunc::Type BlendFunc::Get() { GLint sfactor, dfactor; MBGL_CHECK_ERROR(glGetIntegerv(GL_BLEND_SRC_ALPHA, &sfactor)); MBGL_CHECK_ERROR(glGetIntegerv(GL_BLEND_DST_ALPHA, &dfactor)); - return { fromGLenum<gfx::ColorMode::BlendFactor>(sfactor), - fromGLenum<gfx::ColorMode::BlendFactor>(dfactor) }; + return { Enum<gfx::ColorBlendFactorType>::from(sfactor), + Enum<gfx::ColorBlendFactorType>::from(dfactor) }; } const BlendColor::Type BlendColor::Default { 0, 0, 0, 0 }; diff --git a/src/mbgl/gl/value.hpp b/src/mbgl/gl/value.hpp index 8bc5c624bf..b284ada51b 100644 --- a/src/mbgl/gl/value.hpp +++ b/src/mbgl/gl/value.hpp @@ -126,18 +126,18 @@ struct Blend { }; struct BlendEquation { - using Type = gfx::ColorMode::BlendEquation; - static const constexpr Type Default = gfx::ColorMode::BlendEquation::Add; + using Type = gfx::ColorBlendEquationType; + static const constexpr Type Default = gfx::ColorBlendEquationType::Add; static void Set(const Type&); static Type Get(); }; struct BlendFunc { struct Type { - gfx::ColorMode::BlendFactor sfactor; - gfx::ColorMode::BlendFactor dfactor; + gfx::ColorBlendFactorType sfactor; + gfx::ColorBlendFactorType dfactor; }; - static const constexpr Type Default = { gfx::ColorMode::BlendFactor::One, gfx::ColorMode::BlendFactor::Zero }; + static const constexpr Type Default = { gfx::ColorBlendFactorType::One, gfx::ColorBlendFactorType::Zero }; static void Set(const Type&); static Type Get(); }; |