diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-02-27 18:43:48 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-03-01 09:33:37 +0100 |
commit | fde7c20f36ce2ecfdd79d2722fc2f0bee72e7e99 (patch) | |
tree | e47f97900d812d438fb67f811c6e9fb00d2bd52b | |
parent | da6e1390c68e01e02652104586c759d46e04c7fd (diff) | |
download | qtlocation-mapboxgl-fde7c20f36ce2ecfdd79d2722fc2f0bee72e7e99.tar.gz |
[core] move GL enum conversions to separate file
-rw-r--r-- | src/core-files.json | 2 | ||||
-rw-r--r-- | src/mbgl/gfx/color_mode.hpp | 57 | ||||
-rw-r--r-- | src/mbgl/gfx/types.hpp | 24 | ||||
-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 | ||||
-rw-r--r-- | src/mbgl/renderer/paint_parameters.cpp | 4 |
9 files changed, 173 insertions, 133 deletions
diff --git a/src/core-files.json b/src/core-files.json index aa53ec9ede..aced36c2b4 100644 --- a/src/core-files.json +++ b/src/core-files.json @@ -22,6 +22,7 @@ "src/mbgl/gl/debugging.cpp", "src/mbgl/gl/debugging_extension.cpp", "src/mbgl/gl/depth_mode.cpp", + "src/mbgl/gl/enum.cpp", "src/mbgl/gl/object.cpp", "src/mbgl/gl/stencil_mode.cpp", "src/mbgl/gl/uniform.cpp", @@ -510,6 +511,7 @@ "mbgl/gl/debugging_extension.hpp": "src/mbgl/gl/debugging_extension.hpp", "mbgl/gl/defines.hpp": "src/mbgl/gl/defines.hpp", "mbgl/gl/depth_mode.hpp": "src/mbgl/gl/depth_mode.hpp", + "mbgl/gl/enum.hpp": "src/mbgl/gl/enum.hpp", "mbgl/gl/extension.hpp": "src/mbgl/gl/extension.hpp", "mbgl/gl/features.hpp": "src/mbgl/gl/features.hpp", "mbgl/gl/framebuffer.hpp": "src/mbgl/gl/framebuffer.hpp", diff --git a/src/mbgl/gfx/color_mode.hpp b/src/mbgl/gfx/color_mode.hpp index 97bbc24096..077c7771bd 100644 --- a/src/mbgl/gfx/color_mode.hpp +++ b/src/mbgl/gfx/color_mode.hpp @@ -1,5 +1,6 @@ #pragma once +#include <mbgl/gfx/types.hpp> #include <mbgl/util/variant.hpp> #include <mbgl/util/color.hpp> @@ -8,53 +9,29 @@ namespace gfx { class ColorMode { public: - enum class BlendEquation { - Add, - Subtract, - ReverseSubtract - }; - - enum class BlendFactor { - Zero, - One, - SrcColor, - OneMinusSrcColor, - SrcAlpha, - OneMinusSrcAlpha, - DstAlpha, - OneMinusDstAlpha, - DstColor, - OneMinusDstColor, - SrcAlphaSaturate, - ConstantColor, - OneMinusConstantColor, - ConstantAlpha, - OneMinusConstantAlpha - }; - - template <BlendEquation E> + template <ColorBlendEquationType E> struct ConstantBlend { - static constexpr BlendEquation equation = E; - static constexpr BlendFactor srcFactor = BlendFactor::One; - static constexpr BlendFactor dstFactor = BlendFactor::One; + static constexpr ColorBlendEquationType equation = E; + static constexpr ColorBlendFactorType srcFactor = ColorBlendFactorType::One; + static constexpr ColorBlendFactorType dstFactor = ColorBlendFactorType::One; }; - template <BlendEquation E> + template <ColorBlendEquationType E> struct LinearBlend { - static constexpr BlendEquation equation = E; - BlendFactor srcFactor; - BlendFactor dstFactor; + static constexpr ColorBlendEquationType equation = E; + ColorBlendFactorType srcFactor; + ColorBlendFactorType dstFactor; }; struct Replace { - static constexpr BlendEquation equation = BlendEquation::Add; - static constexpr BlendFactor srcFactor = BlendFactor::One; - static constexpr BlendFactor dstFactor = BlendFactor::Zero; + static constexpr ColorBlendEquationType equation = ColorBlendEquationType::Add; + static constexpr ColorBlendFactorType srcFactor = ColorBlendFactorType::One; + static constexpr ColorBlendFactorType dstFactor = ColorBlendFactorType::Zero; }; - using Add = LinearBlend<BlendEquation::Add>; - using Subtract = LinearBlend<BlendEquation::Subtract>; - using ReverseSubtract = LinearBlend<BlendEquation::ReverseSubtract>; + using Add = LinearBlend<ColorBlendEquationType::Add>; + using Subtract = LinearBlend<ColorBlendEquationType::Subtract>; + using ReverseSubtract = LinearBlend<ColorBlendEquationType::ReverseSubtract>; using BlendFunction = variant< Replace, @@ -83,11 +60,11 @@ public: } static ColorMode alphaBlended() { - return { Add{ BlendFactor::One, BlendFactor::OneMinusSrcAlpha }, {}, { true, true, true, true } }; + return { Add{ ColorBlendFactorType::One, ColorBlendFactorType::OneMinusSrcAlpha }, {}, { true, true, true, true } }; } static ColorMode additive() { - return { Add{ BlendFactor::One, BlendFactor::One }, {}, { true, true, true, true } }; + return { Add{ ColorBlendFactorType::One, ColorBlendFactorType::One }, {}, { true, true, true, true } }; } }; diff --git a/src/mbgl/gfx/types.hpp b/src/mbgl/gfx/types.hpp index ea7b2da5dc..adf3395db0 100644 --- a/src/mbgl/gfx/types.hpp +++ b/src/mbgl/gfx/types.hpp @@ -15,5 +15,29 @@ enum class PrimitiveType : uint8_t { TriangleFan }; +enum class ColorBlendEquationType : uint8_t { + Add, + Subtract, + ReverseSubtract +}; + +enum class ColorBlendFactorType : uint8_t { + Zero, + One, + SrcColor, + OneMinusSrcColor, + SrcAlpha, + OneMinusSrcAlpha, + DstAlpha, + OneMinusDstAlpha, + DstColor, + OneMinusDstColor, + SrcAlphaSaturate, + ConstantColor, + OneMinusConstantColor, + ConstantAlpha, + OneMinusConstantAlpha +}; + } // namespace gfx } // namespace mbgl 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(); }; diff --git a/src/mbgl/renderer/paint_parameters.cpp b/src/mbgl/renderer/paint_parameters.cpp index 7ab232731c..bdea5989d4 100644 --- a/src/mbgl/renderer/paint_parameters.cpp +++ b/src/mbgl/renderer/paint_parameters.cpp @@ -84,8 +84,8 @@ gfx::ColorMode PaintParameters::colorModeForRenderPass() const { const float overdraw = 1.0f / 8.0f; return gfx::ColorMode { gfx::ColorMode::Add { - gfx::ColorMode::BlendFactor::ConstantColor, - gfx::ColorMode::BlendFactor::One + gfx::ColorBlendFactorType::ConstantColor, + gfx::ColorBlendFactorType::One }, Color { overdraw, overdraw, overdraw, 0.0f }, gfx::ColorMode::Mask { true, true, true, true } |