summaryrefslogtreecommitdiff
path: root/src/mbgl/gl
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-09-29 15:32:48 +0200
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-09-29 10:17:47 -0700
commitcc78b74098e02311cc646fe5b82c13641ff705fa (patch)
treeaf0219d5611f0984bf3b244a336fbc6074a44cb4 /src/mbgl/gl
parent15aece8a30dcc1f1f97e28180edda46d05641a2d (diff)
downloadqtlocation-mapboxgl-cc78b74098e02311cc646fe5b82c13641ff705fa.tar.gz
[core] remove dependence on gl.h types
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r--src/mbgl/gl/context.cpp112
-rw-r--r--src/mbgl/gl/context.hpp58
-rw-r--r--src/mbgl/gl/types.hpp82
-rw-r--r--src/mbgl/gl/value.cpp337
-rw-r--r--src/mbgl/gl/value.hpp396
5 files changed, 672 insertions, 313 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index 0d67164870..3c1b5e45ae 100644
--- a/src/mbgl/gl/context.cpp
+++ b/src/mbgl/gl/context.cpp
@@ -1,4 +1,6 @@
#include <mbgl/gl/context.hpp>
+#include <mbgl/gl/gl.hpp>
+#include <mbgl/util/traits.hpp>
namespace mbgl {
namespace gl {
@@ -11,10 +13,116 @@ static_assert(std::is_same<VertexArrayID, GLuint>::value, "OpenGL type mismatch"
static_assert(std::is_same<FramebufferID, GLuint>::value, "OpenGL type mismatch");
static_assert(std::is_same<RenderbufferID, GLuint>::value, "OpenGL type mismatch");
+static_assert(std::is_same<StencilValue, GLint>::value, "OpenGL type mismatch");
+static_assert(std::is_same<StencilMaskValue, GLuint>::value, "OpenGL type mismatch");
+
+static_assert(underlying_type(StencilTestFunction::Never) == GL_NEVER, "OpenGL enum mismatch");
+static_assert(underlying_type(StencilTestFunction::Less) == GL_LESS, "OpenGL enum mismatch");
+static_assert(underlying_type(StencilTestFunction::Equal) == GL_EQUAL, "OpenGL enum mismatch");
+static_assert(underlying_type(StencilTestFunction::LessEqual) == GL_LEQUAL, "OpenGL enum mismatch");
+static_assert(underlying_type(StencilTestFunction::Greater) == GL_GREATER, "OpenGL enum mismatch");
+static_assert(underlying_type(StencilTestFunction::NotEqual) == GL_NOTEQUAL, "OpenGL enum mismatch");
+static_assert(underlying_type(StencilTestFunction::GreaterEqual) == GL_GEQUAL, "OpenGL enum mismatch");
+static_assert(underlying_type(StencilTestFunction::Always) == GL_ALWAYS, "OpenGL enum mismatch");
+
+static_assert(underlying_type(StencilTestOperation::Keep) == GL_KEEP, "OpenGL enum mismatch");
+static_assert(underlying_type(StencilTestOperation::Zero) == GL_ZERO, "OpenGL enum mismatch");
+static_assert(underlying_type(StencilTestOperation::Replace) == GL_REPLACE, "OpenGL enum mismatch");
+static_assert(underlying_type(StencilTestOperation::Increment) == GL_INCR, "OpenGL enum mismatch");
+static_assert(underlying_type(StencilTestOperation::IncrementWrap) == GL_INCR_WRAP, "OpenGL enum mismatch");
+static_assert(underlying_type(StencilTestOperation::Decrement) == GL_DECR, "OpenGL enum mismatch");
+static_assert(underlying_type(StencilTestOperation::DecrementWrap) == GL_DECR_WRAP, "OpenGL enum mismatch");
+static_assert(underlying_type(StencilTestOperation::Invert) == GL_INVERT, "OpenGL enum mismatch");
+
+static_assert(underlying_type(DepthTestFunction::Never) == GL_NEVER, "OpenGL enum mismatch");
+static_assert(underlying_type(DepthTestFunction::Less) == GL_LESS, "OpenGL enum mismatch");
+static_assert(underlying_type(DepthTestFunction::Equal) == GL_EQUAL, "OpenGL enum mismatch");
+static_assert(underlying_type(DepthTestFunction::LessEqual) == GL_LEQUAL, "OpenGL enum mismatch");
+static_assert(underlying_type(DepthTestFunction::Greater) == GL_GREATER, "OpenGL enum mismatch");
+static_assert(underlying_type(DepthTestFunction::NotEqual) == GL_NOTEQUAL, "OpenGL enum mismatch");
+static_assert(underlying_type(DepthTestFunction::GreaterEqual) == GL_GEQUAL, "OpenGL enum mismatch");
+static_assert(underlying_type(DepthTestFunction::Always) == GL_ALWAYS, "OpenGL enum mismatch");
+
+static_assert(underlying_type(BlendSourceFactor::Zero) == GL_ZERO, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendSourceFactor::One) == GL_ONE, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendSourceFactor::SrcColor) == GL_SRC_COLOR, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendSourceFactor::OneMinusSrcColor) == GL_ONE_MINUS_SRC_COLOR, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendSourceFactor::DstColor) == GL_DST_COLOR, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendSourceFactor::OneMinusDstColor) == GL_ONE_MINUS_DST_COLOR, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendSourceFactor::SrcAlpha) == GL_SRC_ALPHA, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendSourceFactor::OneMinusSrcAlpha) == GL_ONE_MINUS_SRC_ALPHA, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendSourceFactor::DstAlpha) == GL_DST_ALPHA, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendSourceFactor::OneMinusDstAlpha) == GL_ONE_MINUS_DST_ALPHA, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendSourceFactor::ConstantColor) == GL_CONSTANT_COLOR, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendSourceFactor::OneMinusConstantColor) == GL_ONE_MINUS_CONSTANT_COLOR, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendSourceFactor::ConstantAlpha) == GL_CONSTANT_ALPHA, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendSourceFactor::OneMinusConstantAlpha) == GL_ONE_MINUS_CONSTANT_ALPHA, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendSourceFactor::SrcAlphaSaturate) == GL_SRC_ALPHA_SATURATE, "OpenGL enum mismatch");
+
+static_assert(underlying_type(BlendDestinationFactor::Zero) == GL_ZERO, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendDestinationFactor::One) == GL_ONE, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendDestinationFactor::SrcColor) == GL_SRC_COLOR, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendDestinationFactor::OneMinusSrcColor) == GL_ONE_MINUS_SRC_COLOR, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendDestinationFactor::DstColor) == GL_DST_COLOR, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendDestinationFactor::OneMinusDstColor) == GL_ONE_MINUS_DST_COLOR, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendDestinationFactor::SrcAlpha) == GL_SRC_ALPHA, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendDestinationFactor::OneMinusSrcAlpha) == GL_ONE_MINUS_SRC_ALPHA, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendDestinationFactor::DstAlpha) == GL_DST_ALPHA, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendDestinationFactor::OneMinusDstAlpha) == GL_ONE_MINUS_DST_ALPHA, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendDestinationFactor::ConstantColor) == GL_CONSTANT_COLOR, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendDestinationFactor::OneMinusConstantColor) == GL_ONE_MINUS_CONSTANT_COLOR, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendDestinationFactor::ConstantAlpha) == GL_CONSTANT_ALPHA, "OpenGL enum mismatch");
+static_assert(underlying_type(BlendDestinationFactor::OneMinusConstantAlpha) == GL_ONE_MINUS_CONSTANT_ALPHA, "OpenGL enum mismatch");
+
Context::~Context() {
reset();
}
+UniqueProgram Context::createProgram() {
+ return UniqueProgram{ MBGL_CHECK_ERROR(glCreateProgram()), { this } };
+}
+
+UniqueShader Context::createVertexShader() {
+ return UniqueShader{ MBGL_CHECK_ERROR(glCreateShader(GL_VERTEX_SHADER)), { this } };
+}
+
+UniqueShader Context::createFragmentShader() {
+ return UniqueShader{ MBGL_CHECK_ERROR(glCreateShader(GL_FRAGMENT_SHADER)), { this } };
+}
+
+UniqueBuffer Context::createBuffer() {
+ BufferID id = 0;
+ MBGL_CHECK_ERROR(glGenBuffers(1, &id));
+ return UniqueBuffer{ std::move(id), { this } };
+}
+
+UniqueTexture Context::createTexture() {
+ if (pooledTextures.empty()) {
+ pooledTextures.resize(TextureMax);
+ MBGL_CHECK_ERROR(glGenTextures(TextureMax, pooledTextures.data()));
+ }
+
+ TextureID id = pooledTextures.back();
+ pooledTextures.pop_back();
+ return UniqueTexture{ std::move(id), { this } };
+}
+
+UniqueVertexArray Context::createVertexArray() {
+ VertexArrayID id = 0;
+ MBGL_CHECK_ERROR(gl::GenVertexArrays(1, &id));
+ return UniqueVertexArray{ std::move(id), { this } };
+}
+
+UniqueFramebuffer Context::createFramebuffer() {
+ FramebufferID id = 0;
+ MBGL_CHECK_ERROR(glGenFramebuffers(1, &id));
+ return UniqueFramebuffer{ std::move(id), { this } };
+}
+
+void Context::uploadBuffer(BufferType type, size_t size, void* data) {
+ MBGL_CHECK_ERROR(glBufferData(static_cast<GLenum>(type), size, data, GL_STATIC_DRAW));
+}
+
void Context::reset() {
std::copy(pooledTextures.begin(), pooledTextures.end(), std::back_inserter(abandonedTextures));
pooledTextures.resize(0);
@@ -45,10 +153,10 @@ void applyStateFunction(Context& context, Fn&& fn) {
fn(context.activeTexture);
fn(context.bindFramebuffer);
fn(context.viewport);
-#ifndef GL_ES_VERSION_2_0
+#if not MBGL_USE_GLES2
fn(context.pixelZoom);
fn(context.rasterPos);
-#endif // GL_ES_VERSION_2_0
+#endif // MBGL_USE_GLES2
for (auto& tex : context.texture) {
fn(tex);
}
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp
index 133a56b6f8..04089c2000 100644
--- a/src/mbgl/gl/context.hpp
+++ b/src/mbgl/gl/context.hpp
@@ -7,56 +7,26 @@
#include <memory>
#include <vector>
+#include <array>
namespace mbgl {
namespace gl {
-constexpr GLsizei TextureMax = 64;
+constexpr size_t TextureMax = 64;
class Context : private util::noncopyable {
public:
~Context();
- UniqueProgram createProgram() {
- return UniqueProgram { MBGL_CHECK_ERROR(glCreateProgram()), { this } };
- }
-
- UniqueShader createVertexShader() {
- return UniqueShader { MBGL_CHECK_ERROR(glCreateShader(GL_VERTEX_SHADER)), { this } };
- }
-
- UniqueShader createFragmentShader() {
- return UniqueShader { MBGL_CHECK_ERROR(glCreateShader(GL_FRAGMENT_SHADER)), { this } };
- }
-
- UniqueBuffer createBuffer() {
- BufferID id = 0;
- MBGL_CHECK_ERROR(glGenBuffers(1, &id));
- return UniqueBuffer { std::move(id), { this } };
- }
+ UniqueProgram createProgram();
+ UniqueShader createVertexShader();
+ UniqueShader createFragmentShader();
+ UniqueBuffer createBuffer();
+ UniqueTexture createTexture();
+ UniqueVertexArray createVertexArray();
+ UniqueFramebuffer createFramebuffer();
- UniqueTexture createTexture() {
- if (pooledTextures.empty()) {
- pooledTextures.resize(TextureMax);
- MBGL_CHECK_ERROR(glGenTextures(TextureMax, pooledTextures.data()));
- }
-
- TextureID id = pooledTextures.back();
- pooledTextures.pop_back();
- return UniqueTexture { std::move(id), { this } };
- }
-
- UniqueVertexArray createVertexArray() {
- VertexArrayID id = 0;
- MBGL_CHECK_ERROR(gl::GenVertexArrays(1, &id));
- return UniqueVertexArray { std::move(id), { this } };
- }
-
- UniqueFramebuffer createFramebuffer() {
- FramebufferID id = 0;
- MBGL_CHECK_ERROR(glGenFramebuffers(1, &id));
- return UniqueFramebuffer { std::move(id), { this } };
- }
+ void uploadBuffer(BufferType, size_t, void*);
// Actually remove the objects we marked as abandoned with the above methods.
// Only call this while the OpenGL context is exclusive to this thread.
@@ -100,13 +70,13 @@ public:
State<value::ActiveTexture> activeTexture;
State<value::BindFramebuffer> bindFramebuffer;
State<value::Viewport> viewport;
-#ifndef GL_ES_VERSION_2_0
+#if not MBGL_USE_GLES2
State<value::PixelZoom> pixelZoom;
State<value::RasterPos> rasterPos;
-#endif // GL_ES_VERSION_2_0
+#endif // MBGL_USE_GLES2
std::array<State<value::BindTexture>, 2> texture;
- State<value::BindBuffer<GL_ARRAY_BUFFER>> vertexBuffer;
- State<value::BindBuffer<GL_ELEMENT_ARRAY_BUFFER>> elementBuffer;
+ State<value::BindVertexBuffer> vertexBuffer;
+ State<value::BindElementBuffer> elementBuffer;
State<value::BindVertexArray> vertexArrayObject;
private:
diff --git a/src/mbgl/gl/types.hpp b/src/mbgl/gl/types.hpp
index 94426f5e36..8578a11f66 100644
--- a/src/mbgl/gl/types.hpp
+++ b/src/mbgl/gl/types.hpp
@@ -5,6 +5,7 @@
namespace mbgl {
namespace gl {
+// Mapping based on https://www.opengl.org/wiki/OpenGL_Type
using ProgramID = uint32_t;
using ShaderID = uint32_t;
using BufferID = uint32_t;
@@ -13,5 +14,86 @@ using VertexArrayID = uint32_t;
using FramebufferID = uint32_t;
using RenderbufferID = uint32_t;
+using AttributeLocation = int32_t;
+using UniformLocation = int32_t;
+using TextureUnit = uint8_t;
+
+using DepthValue = double;
+using StencilValue = int32_t;
+using StencilMaskValue = uint32_t;
+
+enum class BufferType : uint32_t {
+ Vertex = 0x8892,
+ Element = 0x8893
+};
+
+enum class StencilTestFunction : uint32_t {
+ Never = 0x0200,
+ Less = 0x0201,
+ Equal = 0x0202,
+ LessEqual = 0x0203,
+ Greater = 0x0204,
+ NotEqual = 0x0205,
+ GreaterEqual = 0x0206,
+ Always = 0x0207,
+};
+
+enum class StencilTestOperation : uint32_t {
+ Keep = 0x1E00,
+ Zero = 0x0000,
+ Replace = 0x1E01,
+ Increment = 0x1E02,
+ IncrementWrap = 0x8507,
+ Decrement = 0x1E03,
+ DecrementWrap = 0x8508,
+ Invert = 0x150A,
+};
+
+enum class DepthTestFunction : uint32_t {
+ Never = 0x0200,
+ Less = 0x0201,
+ Equal = 0x0202,
+ LessEqual = 0x0203,
+ Greater = 0x0204,
+ NotEqual = 0x0205,
+ GreaterEqual = 0x0206,
+ Always = 0x0207,
+};
+
+enum class BlendSourceFactor : uint32_t {
+ Zero = 0x0000,
+ One = 0x0001,
+ SrcColor = 0x0300,
+ OneMinusSrcColor = 0x0301,
+ DstColor = 0x0306,
+ OneMinusDstColor = 0x0307,
+ SrcAlpha = 0x0302,
+ OneMinusSrcAlpha = 0x0303,
+ DstAlpha = 0x0304,
+ OneMinusDstAlpha = 0x0305,
+ ConstantColor = 0x8001,
+ OneMinusConstantColor = 0x8002,
+ ConstantAlpha = 0x8003,
+ OneMinusConstantAlpha = 0x8004,
+ SrcAlphaSaturate = 0x0308,
+};
+
+enum class BlendDestinationFactor : uint32_t {
+ Zero = 0x0000,
+ One = 0x0001,
+ SrcColor = 0x0300,
+ OneMinusSrcColor = 0x0301,
+ DstColor = 0x0306,
+ OneMinusDstColor = 0x0307,
+ SrcAlpha = 0x0302,
+ OneMinusSrcAlpha = 0x0303,
+ DstAlpha = 0x0304,
+ OneMinusDstAlpha = 0x0305,
+ ConstantColor = 0x8001,
+ OneMinusConstantColor = 0x8002,
+ ConstantAlpha = 0x8003,
+ OneMinusConstantAlpha = 0x8004,
+};
+
} // namespace gl
} // namespace mbgl
diff --git a/src/mbgl/gl/value.cpp b/src/mbgl/gl/value.cpp
index af316786ff..ae7d648a45 100644
--- a/src/mbgl/gl/value.cpp
+++ b/src/mbgl/gl/value.cpp
@@ -1,34 +1,355 @@
#include <mbgl/gl/value.hpp>
+#include <mbgl/gl/gl.hpp>
namespace mbgl {
namespace gl {
namespace value {
-const constexpr StencilFunc::Type StencilFunc::Default;
+const constexpr ClearDepth::Type ClearDepth::Default;
+
+void ClearDepth::Set(const Type& value) {
+#if MBGL_USE_GLES2
+ MBGL_CHECK_ERROR(glClearDepthf(value));
+#else
+ MBGL_CHECK_ERROR(glClearDepth(value));
+#endif
+}
+
+ClearDepth::Type ClearDepth::Get() {
+ GLfloat clearDepth;
+ MBGL_CHECK_ERROR(glGetFloatv(GL_DEPTH_CLEAR_VALUE, &clearDepth));
+ return clearDepth;
+}
+
+const constexpr ClearColor::Type ClearColor::Default;
+
+void ClearColor::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glClearColor(value.r, value.g, value.b, value.a));
+}
+
+ClearColor::Type ClearColor::Get() {
+ GLfloat clearColor[4];
+ MBGL_CHECK_ERROR(glGetFloatv(GL_COLOR_CLEAR_VALUE, clearColor));
+ return { clearColor[0], clearColor[1], clearColor[2], clearColor[3] };
+}
+
+const constexpr ClearStencil::Type ClearStencil::Default;
+
+void ClearStencil::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glClearStencil(value));
+}
+
+ClearStencil::Type ClearStencil::Get() {
+ GLint clearStencil;
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &clearStencil));
+ return clearStencil;
+}
+
const constexpr StencilMask::Type StencilMask::Default;
+
+void StencilMask::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glStencilMask(value));
+}
+
+StencilMask::Type StencilMask::Get() {
+ GLint stencilMask;
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_WRITEMASK, &stencilMask));
+ return stencilMask;
+}
+
+const constexpr DepthMask::Type DepthMask::Default;
+
+void DepthMask::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glDepthMask(value));
+}
+
+DepthMask::Type DepthMask::Get() {
+ GLboolean depthMask;
+ MBGL_CHECK_ERROR(glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask));
+ return depthMask;
+}
+
+const constexpr ColorMask::Type ColorMask::Default;
+
+void ColorMask::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glColorMask(value.r, value.g, value.b, value.a));
+}
+
+ColorMask::Type ColorMask::Get() {
+ GLboolean bools[4];
+ MBGL_CHECK_ERROR(glGetBooleanv(GL_COLOR_WRITEMASK, bools));
+ return { static_cast<bool>(bools[0]), static_cast<bool>(bools[1]), static_cast<bool>(bools[2]),
+ static_cast<bool>(bools[3]) };
+}
+
+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));
+}
+
+StencilFunc::Type StencilFunc::Get() {
+ GLint func, ref, mask;
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_FUNC, &func));
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_REF, &ref));
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_VALUE_MASK, &mask));
+ return { static_cast<StencilTestFunction>(func), ref, static_cast<StencilMaskValue>(mask) };
+}
+
const constexpr StencilTest::Type StencilTest::Default;
+
+void StencilTest::Set(const Type& value) {
+ MBGL_CHECK_ERROR(value ? glEnable(GL_STENCIL_TEST) : glDisable(GL_STENCIL_TEST));
+}
+
+StencilTest::Type StencilTest::Get() {
+ Type stencilTest;
+ MBGL_CHECK_ERROR(stencilTest = glIsEnabled(GL_STENCIL_TEST));
+ return stencilTest;
+}
+
const constexpr StencilOp::Type StencilOp::Default;
+
+void StencilOp::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glStencilOp(static_cast<GLenum>(value.sfail),
+ static_cast<GLenum>(value.dpfail),
+ static_cast<GLenum>(value.dppass)));
+}
+
+StencilOp::Type StencilOp::Get() {
+ GLint sfail, dpfail, dppass;
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_FAIL, &sfail));
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, &dpfail));
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, &dppass));
+ return { static_cast<StencilTestOperation>(sfail), static_cast<StencilTestOperation>(dpfail),
+ static_cast<StencilTestOperation>(dppass) };
+}
+
const constexpr DepthRange::Type DepthRange::Default;
-const constexpr DepthMask::Type DepthMask::Default;
+
+void DepthRange::Set(const Type& value) {
+#if MBGL_USE_GLES2
+ MBGL_CHECK_ERROR(glDepthRangef(value.near, value.far));
+#else
+ MBGL_CHECK_ERROR(glDepthRange(value.near, value.far));
+#endif
+}
+
+DepthRange::Type DepthRange::Get() {
+ GLfloat floats[2];
+ MBGL_CHECK_ERROR(glGetFloatv(GL_DEPTH_RANGE, floats));
+ return { floats[0], floats[1] };
+}
+
const constexpr DepthTest::Type DepthTest::Default;
+
+void DepthTest::Set(const Type& value) {
+ MBGL_CHECK_ERROR(value ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST));
+}
+
+DepthTest::Type DepthTest::Get() {
+ Type depthTest;
+ MBGL_CHECK_ERROR(depthTest = glIsEnabled(GL_DEPTH_TEST));
+ return depthTest;
+}
+
const constexpr DepthFunc::Type DepthFunc::Default;
+
+void DepthFunc::Set(const DepthFunc::Type& value) {
+ MBGL_CHECK_ERROR(glDepthFunc(static_cast<GLenum>(value)));
+}
+
+DepthFunc::Type DepthFunc::Get() {
+ GLint depthFunc;
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_DEPTH_FUNC, &depthFunc));
+ return static_cast<Type>(depthFunc);
+}
+
const constexpr Blend::Type Blend::Default;
+
+void Blend::Set(const Type& value) {
+ MBGL_CHECK_ERROR(value ? glEnable(GL_BLEND) : glDisable(GL_BLEND));
+}
+
+Blend::Type Blend::Get() {
+ Type blend;
+ MBGL_CHECK_ERROR(blend = glIsEnabled(GL_BLEND));
+ return blend;
+}
+
const constexpr BlendFunc::Type BlendFunc::Default;
+
+void BlendFunc::Set(const Type& value) {
+ MBGL_CHECK_ERROR(
+ glBlendFunc(static_cast<GLenum>(value.sfactor), static_cast<GLenum>(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 { static_cast<BlendSourceFactor>(sfactor),
+ static_cast<BlendDestinationFactor>(dfactor) };
+}
+
const constexpr BlendColor::Type BlendColor::Default;
-const constexpr ColorMask::Type ColorMask::Default;
-const constexpr ClearDepth::Type ClearDepth::Default;
-const constexpr ClearColor::Type ClearColor::Default;
-const constexpr ClearStencil::Type ClearStencil::Default;
+
+void BlendColor::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glBlendColor(value.r, value.g, value.b, value.a));
+}
+
+BlendColor::Type BlendColor::Get() {
+ GLfloat floats[4];
+ MBGL_CHECK_ERROR(glGetFloatv(GL_BLEND_COLOR, floats));
+ return { floats[0], floats[1], floats[2], floats[3] };
+}
+
const constexpr Program::Type Program::Default;
+
+void Program::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glUseProgram(value));
+}
+
+Program::Type Program::Get() {
+ GLint program;
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_CURRENT_PROGRAM, &program));
+ return program;
+}
+
const constexpr LineWidth::Type LineWidth::Default;
+
+void LineWidth::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glLineWidth(value));
+}
+
+LineWidth::Type LineWidth::Get() {
+ GLfloat lineWidth;
+ MBGL_CHECK_ERROR(glGetFloatv(GL_LINE_WIDTH, &lineWidth));
+ return lineWidth;
+}
+
const constexpr ActiveTexture::Type ActiveTexture::Default;
+
+void ActiveTexture::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glActiveTexture(GL_TEXTURE0 + value));
+}
+
+ActiveTexture::Type ActiveTexture::Get() {
+ GLint activeTexture;
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTexture));
+ return static_cast<Type>(activeTexture - GL_TEXTURE0);
+}
+
+void Viewport::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glViewport(value.x, value.y, value.width, value.height));
+}
+
+Viewport::Type Viewport::Get() {
+ GLint viewport[4];
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_VIEWPORT, viewport));
+ return { static_cast<int32_t>(viewport[0]), static_cast<int32_t>(viewport[1]),
+ static_cast<uint16_t>(viewport[2]), static_cast<uint16_t>(viewport[3]) };
+}
+
+void BindFramebuffer::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, value));
+}
+
+BindFramebuffer::Type BindFramebuffer::Get() {
+ GLint binding;
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_FRAMEBUFFER_BINDING, &binding));
+ return binding;
+}
+
const constexpr BindTexture::Type BindTexture::Default;
+
+void BindTexture::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, value));
+}
+
+BindTexture::Type BindTexture::Get() {
+ GLint binding;
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_TEXTURE_BINDING_2D, &binding));
+ return binding;
+}
+
+const constexpr BindVertexBuffer::Type BindVertexBuffer::Default;
+
+void BindVertexBuffer::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, value));
+}
+
+BindVertexBuffer::Type BindVertexBuffer::Get() {
+ GLint binding;
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &binding));
+ return binding;
+}
+
+const constexpr BindElementBuffer::Type BindElementBuffer::Default;
+
+void BindElementBuffer::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, value));
+}
+
+BindElementBuffer::Type BindElementBuffer::Get() {
+ GLint binding;
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &binding));
+ return binding;
+}
+
const constexpr BindVertexArray::Type BindVertexArray::Default;
-#ifndef GL_ES_VERSION_2_0
+void BindVertexArray::Set(const Type& value) {
+ if (gl::BindVertexArray) {
+ MBGL_CHECK_ERROR(gl::BindVertexArray(value));
+ }
+}
+
+BindVertexArray::Type BindVertexArray::Get() {
+ GLint binding = 0;
+ if (gl::BindVertexArray) {
+#ifdef GL_VERTEX_ARRAY_BINDING
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &binding));
+#elif GL_VERTEX_ARRAY_BINDING_OES
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_VERTEX_ARRAY_BINDING_OES, &binding));
+#elif GL_VERTEX_ARRAY_BINDING_ARB
+ MBGL_CHECK_ERROR(glGetIntegerv(GL_VERTEX_ARRAY_BINDING_ARB, &binding));
+#elif GLVERTEX_ARRAY_BINDING_APPLE
+ MBGL_CHECK_ERROR(glGetIntegerv(GLVERTEX_ARRAY_BINDING_APPLE, &binding));
+#endif
+ }
+ return binding;
+}
+
+#if not MBGL_USE_GLES2
+
const constexpr PixelZoom::Type PixelZoom::Default;
+
+void PixelZoom::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glPixelZoom(value.xfactor, value.yfactor));
+}
+
+PixelZoom::Type PixelZoom::Get() {
+ GLfloat xfactor, yfactor;
+ MBGL_CHECK_ERROR(glGetFloatv(GL_ZOOM_X, &xfactor));
+ MBGL_CHECK_ERROR(glGetFloatv(GL_ZOOM_Y, &yfactor));
+ return { xfactor, yfactor };
+}
+
const constexpr RasterPos::Type RasterPos::Default;
-#endif // GL_ES_VERSION_2_0
+
+void RasterPos::Set(const Type& value) {
+ MBGL_CHECK_ERROR(glRasterPos4d(value.x, value.y, value.z, value.w));
+}
+
+RasterPos::Type RasterPos::Get() {
+ GLdouble pos[4];
+ MBGL_CHECK_ERROR(glGetDoublev(GL_CURRENT_RASTER_POSITION, pos));
+ return { pos[0], pos[1], pos[2], pos[3] };
+}
+
+#endif // MBGL_USE_GLES2
+
} // namespace value
} // namespace gl
diff --git a/src/mbgl/gl/value.hpp b/src/mbgl/gl/value.hpp
index 1250945ba8..9110b33a16 100644
--- a/src/mbgl/gl/value.hpp
+++ b/src/mbgl/gl/value.hpp
@@ -1,11 +1,5 @@
#pragma once
-#include <cstdint>
-#include <tuple>
-#include <array>
-#include <cassert>
-
-#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/types.hpp>
#include <mbgl/util/color.hpp>
@@ -14,82 +8,50 @@ namespace gl {
namespace value {
struct ClearDepth {
- using Type = GLfloat;
+ using Type = float;
static const constexpr Type Default = 1;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glClearDepth(value));
- }
- static Type Get() {
- Type clearDepth;
- MBGL_CHECK_ERROR(glGetFloatv(GL_DEPTH_CLEAR_VALUE, &clearDepth));
- return clearDepth;
- }
+ static void Set(const Type&);
+ static Type Get();
};
struct ClearColor {
using Type = Color;
static const constexpr Type Default = { 0, 0, 0, 0 };
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glClearColor(value.r, value.g, value.b, value.a));
- }
- static Type Get() {
- GLfloat floats[4];
- MBGL_CHECK_ERROR(glGetFloatv(GL_COLOR_CLEAR_VALUE, floats));
- return { floats[0], floats[1], floats[2], floats[3] };
- }
+ static void Set(const Type&);
+ static Type Get();
};
struct ClearStencil {
- using Type = GLint;
+ using Type = StencilValue;
static const constexpr Type Default = 0;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glClearStencil(value));
- }
- static Type Get() {
- Type clearStencil;
- MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &clearStencil));
- return clearStencil;
- }
+ static void Set(const Type&);
+ static Type Get();
};
struct StencilMask {
- using Type = GLuint;
+ using Type = StencilMaskValue;
static const constexpr Type Default = ~0u;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glStencilMask(value));
- }
- static Type Get() {
- GLint stencilMask;
- MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_WRITEMASK, &stencilMask));
- return stencilMask;
- }
+ static void Set(const Type&);
+ static Type Get();
};
struct DepthMask {
- using Type = GLboolean;
- static const constexpr Type Default = GL_TRUE;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glDepthMask(value));
- }
- static Type Get() {
- Type depthMask;
- MBGL_CHECK_ERROR(glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask));
- return depthMask;
- }
+ using Type = bool;
+ static const constexpr Type Default = true;
+ static void Set(const Type&);
+ static Type Get();
};
struct ColorMask {
- struct Type { bool r, g, b, a; };
- static const constexpr Type Default = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE };
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glColorMask(value.r, value.g, value.b, value.a));
- }
- static Type Get() {
- GLboolean bools[4];
- MBGL_CHECK_ERROR(glGetBooleanv(GL_COLOR_WRITEMASK, bools));
- return { static_cast<bool>(bools[0]), static_cast<bool>(bools[1]),
- static_cast<bool>(bools[2]), static_cast<bool>(bools[3]) };
- }
+ struct Type {
+ bool r;
+ bool g;
+ bool b;
+ bool a;
+ };
+ static const constexpr Type Default = { true, true, true, true };
+ static void Set(const Type&);
+ static Type Get();
};
constexpr bool operator!=(const ColorMask::Type& a, const ColorMask::Type& b) {
@@ -97,18 +59,14 @@ constexpr bool operator!=(const ColorMask::Type& a, const ColorMask::Type& b) {
}
struct StencilFunc {
- struct Type { GLenum func; GLint ref; GLuint mask; };
- static const constexpr Type Default = { GL_ALWAYS, 0, ~0u };
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glStencilFunc(value.func, value.ref, value.mask));
- }
- static Type Get() {
- GLint func, ref, mask;
- MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_FUNC, &func));
- MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_REF, &ref));
- MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_VALUE_MASK, &mask));
- return { static_cast<GLenum>(func), ref, static_cast<GLuint>(mask) };
- }
+ struct Type {
+ StencilTestFunction func;
+ StencilValue ref;
+ StencilMaskValue mask;
+ };
+ static const constexpr Type Default = { StencilTestFunction::Always, 0, ~0u };
+ static void Set(const Type&);
+ static Type Get();
};
constexpr bool operator!=(const StencilFunc::Type& a, const StencilFunc::Type& b) {
@@ -117,30 +75,21 @@ constexpr bool operator!=(const StencilFunc::Type& a, const StencilFunc::Type& b
struct StencilTest {
using Type = bool;
- static const constexpr Type Default = GL_FALSE;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(value ? glEnable(GL_STENCIL_TEST) : glDisable(GL_STENCIL_TEST));
- }
- static Type Get() {
- Type stencilTest;
- MBGL_CHECK_ERROR(stencilTest = glIsEnabled(GL_STENCIL_TEST));
- return stencilTest;
- }
+ static const constexpr Type Default = false;
+ static void Set(const Type&);
+ static Type Get();
};
struct StencilOp {
- struct Type { GLenum sfail, dpfail, dppass; };
- static const constexpr Type Default = { GL_KEEP, GL_KEEP, GL_REPLACE };
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glStencilOp(value.sfail, value.dpfail, value.dppass));
- }
- static Type Get() {
- GLint sfail, dpfail, dppass;
- MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_FAIL, &sfail));
- MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, &dpfail));
- MBGL_CHECK_ERROR(glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, &dppass));
- return { static_cast<GLenum>(sfail), static_cast<GLenum>(dpfail), static_cast<GLuint>(dppass) };
- }
+ struct Type {
+ StencilTestOperation sfail;
+ StencilTestOperation dpfail;
+ StencilTestOperation dppass;
+ };
+ static const constexpr Type Default = { StencilTestOperation::Keep, StencilTestOperation::Keep,
+ StencilTestOperation::Keep };
+ static void Set(const Type&);
+ static Type Get();
};
constexpr bool operator!=(const StencilOp::Type& a, const StencilOp::Type& b) {
@@ -148,16 +97,13 @@ constexpr bool operator!=(const StencilOp::Type& a, const StencilOp::Type& b) {
}
struct DepthRange {
- struct Type { GLfloat near, far; };
+ struct Type {
+ float near;
+ float far;
+ };
static const constexpr Type Default = { 0, 1 };
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glDepthRange(value.near, value.far));
- }
- static Type Get() {
- GLfloat floats[2];
- MBGL_CHECK_ERROR(glGetFloatv(GL_DEPTH_RANGE, floats));
- return { floats[0], floats[1] };
- }
+ static void Set(const Type&);
+ static Type Get();
};
constexpr bool operator!=(const DepthRange::Type& a, const DepthRange::Type& b) {
@@ -166,55 +112,33 @@ constexpr bool operator!=(const DepthRange::Type& a, const DepthRange::Type& b)
struct DepthTest {
using Type = bool;
- static const constexpr Type Default = GL_FALSE;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(value ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST));
- }
- static Type Get() {
- Type depthTest;
- MBGL_CHECK_ERROR(depthTest = glIsEnabled(GL_DEPTH_TEST));
- return depthTest;
- }
+ static const constexpr Type Default = false;
+ static void Set(const Type&);
+ static Type Get();
};
struct DepthFunc {
- using Type = GLenum;
- static const constexpr Type Default = GL_LEQUAL;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glDepthFunc(value));
- }
- static Type Get() {
- GLint depthFunc;
- MBGL_CHECK_ERROR(glGetIntegerv(GL_DEPTH_FUNC, &depthFunc));
- return depthFunc;
- }
+ using Type = DepthTestFunction;
+ static const constexpr Type Default = DepthTestFunction::Less;
+ static void Set(const Type&);
+ static Type Get();
};
struct Blend {
using Type = bool;
- static const constexpr Type Default = GL_TRUE;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(value ? glEnable(GL_BLEND) : glDisable(GL_BLEND));
- }
- static Type Get() {
- Type blend;
- MBGL_CHECK_ERROR(blend = glIsEnabled(GL_BLEND));
- return blend;
- }
+ static const constexpr Type Default = true;
+ static void Set(const Type&);
+ static Type Get();
};
struct BlendFunc {
- struct Type { GLenum sfactor, dfactor; };
- static const constexpr Type Default = { GL_ONE, GL_ONE_MINUS_SRC_ALPHA };
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glBlendFunc(value.sfactor, value.dfactor));
- }
- static Type Get() {
- GLint sfactor, dfactor;
- MBGL_CHECK_ERROR(glGetIntegerv(GL_BLEND_SRC_ALPHA, &sfactor));
- MBGL_CHECK_ERROR(glGetIntegerv(GL_BLEND_DST_ALPHA, &dfactor));
- return { static_cast<GLenum>(sfactor), static_cast<GLenum>(dfactor) };
- }
+ struct Type {
+ BlendSourceFactor sfactor;
+ BlendDestinationFactor dfactor;
+ };
+ static const constexpr Type Default = { BlendSourceFactor::One, BlendDestinationFactor::Zero };
+ static void Set(const Type&);
+ static Type Get();
};
constexpr bool operator!=(const BlendFunc::Type& a, const BlendFunc::Type& b) {
@@ -224,159 +148,113 @@ constexpr bool operator!=(const BlendFunc::Type& a, const BlendFunc::Type& b) {
struct BlendColor {
using Type = Color;
static const constexpr Type Default = { 0, 0, 0, 0 };
- inline static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glBlendColor(value.r, value.g, value.b, value.a));
- }
- inline static Type Get() {
- GLfloat floats[4];
- MBGL_CHECK_ERROR(glGetFloatv(GL_BLEND_COLOR, floats));
- return { floats[0], floats[1], floats[2], floats[3] };
- }
+ static void Set(const Type&);
+ static Type Get();
};
struct Program {
using Type = gl::ProgramID;
static const constexpr Type Default = 0;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glUseProgram(value));
- }
- static Type Get() {
- GLint program;
- MBGL_CHECK_ERROR(glGetIntegerv(GL_CURRENT_PROGRAM, &program));
- return program;
- }
+ static void Set(const Type&);
+ static Type Get();
};
struct LineWidth {
- using Type = GLfloat;
+ using Type = float;
static const constexpr Type Default = 1;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glLineWidth(value));
- }
- static Type Get() {
- Type lineWidth;
- MBGL_CHECK_ERROR(glGetFloatv(GL_LINE_WIDTH, &lineWidth));
- return lineWidth;
- }
+ static void Set(const Type&);
+ static Type Get();
};
struct ActiveTexture {
- using Type = uint8_t;
+ using Type = TextureUnit;
static const constexpr Type Default = 0;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glActiveTexture(GL_TEXTURE0 + value));
- }
- static Type Get() {
- GLint activeTexture;
- MBGL_CHECK_ERROR(glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTexture));
- return activeTexture - GL_TEXTURE0;
- }
-};
-
-struct BindFramebuffer {
- using Type = GLint;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, value));
- }
- static Type Get() {
- Type activeFramebuffer;
- MBGL_CHECK_ERROR(glGetIntegerv(GL_FRAMEBUFFER_BINDING, &activeFramebuffer));
- return activeFramebuffer;
- }
+ static void Set(const Type&);
+ static Type Get();
};
struct Viewport {
- using Type = std::array<GLint, 4>;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glViewport(value[0], value[1], value[2], value[3]));
- }
- static Type Get() {
- Type pos;
- MBGL_CHECK_ERROR(glGetIntegerv(GL_VIEWPORT, pos.data()));
- return pos;
- }
+ struct Type {
+ int32_t x;
+ int32_t y;
+ uint16_t width;
+ uint16_t height;
+ };
+ static void Set(const Type&);
+ static Type Get();
};
-
-#ifndef GL_ES_VERSION_2_0
-
-struct PixelZoom {
- struct Type { GLfloat xfactor; GLfloat yfactor; };
- static const constexpr Type Default = { 1, 1 };
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glPixelZoom(value.xfactor, value.yfactor));
- }
- static Type Get() {
- Type value;
- MBGL_CHECK_ERROR(glGetFloatv(GL_ZOOM_X, &value.xfactor));
- MBGL_CHECK_ERROR(glGetFloatv(GL_ZOOM_Y, &value.yfactor));
- return value;
- }
-};
-
-constexpr bool operator!=(const PixelZoom::Type& a, const PixelZoom::Type& b) {
- return a.xfactor != b.xfactor || a.yfactor != b.yfactor;
+constexpr bool operator!=(const Viewport::Type& a, const Viewport::Type& b) {
+ return a.x != b.x || a.y != b.y || a.width != b.width || a.height != b.height;
}
-struct RasterPos {
- using Type = std::array<GLdouble, 4>;
- static const constexpr Type Default = {{ 0, 0, 0, 0 }};
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glRasterPos4d(value[0], value[1], value[2], value[3]));
- }
- static Type Get() {
- Type pos;
- MBGL_CHECK_ERROR(glGetDoublev(GL_CURRENT_RASTER_POSITION, pos.data()));
- return pos;
- }
+struct BindFramebuffer {
+ using Type = FramebufferID;
+ static void Set(const Type&);
+ static Type Get();
};
-#endif // GL_ES_VERSION_2_0
-
struct BindTexture {
using Type = gl::TextureID;
static const constexpr Type Default = 0;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, value));
- }
- static Type Get() {
- GLint texture;
- MBGL_CHECK_ERROR(glGetIntegerv(GL_TEXTURE_BINDING_2D, &texture));
- return static_cast<Type>(texture);
- }
+ static void Set(const Type&);
+ static Type Get();
};
-template <GLenum target>
-struct BindBuffer {
- static_assert(target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER,
- "target must be one of GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER");
+struct BindVertexBuffer {
using Type = gl::BufferID;
static const constexpr Type Default = 0;
- static void Set(const Type& value) {
- MBGL_CHECK_ERROR(glBindBuffer(target, value));
- }
- static Type Get() {
- GLint binding;
- MBGL_CHECK_ERROR(glGetIntegerv(target == GL_ARRAY_BUFFER ? GL_ARRAY_BUFFER_BINDING
- : GL_ELEMENT_ARRAY_BUFFER_BINDING,
- &binding));
- return static_cast<Type>(binding);
- }
+ static void Set(const Type&);
+ static Type Get();
};
-template <GLenum target>
-const typename BindBuffer<target>::Type BindBuffer<target>::Default;
+struct BindElementBuffer {
+ using Type = gl::BufferID;
+ static const constexpr Type Default = 0;
+ static void Set(const Type&);
+ static Type Get();
+};
struct BindVertexArray {
using Type = gl::VertexArrayID;
static const constexpr Type Default = 0;
- static void Set(const Type& value) {
- if (gl::BindVertexArray) {
- MBGL_CHECK_ERROR(gl::BindVertexArray(value));
- }
- }
+ static void Set(const Type&);
+ static Type Get();
};
+#if not MBGL_USE_GLES2
+
+struct PixelZoom {
+ struct Type {
+ float xfactor;
+ float yfactor;
+ };
+ static const constexpr Type Default = { 1, 1 };
+ static void Set(const Type&);
+ static Type Get();
+};
+
+constexpr bool operator!=(const PixelZoom::Type& a, const PixelZoom::Type& b) {
+ return a.xfactor != b.xfactor || a.yfactor != b.yfactor;
+}
+
+struct RasterPos {
+ struct Type {
+ double x;
+ double y;
+ double z;
+ double w;
+ };
+ static const constexpr Type Default = { 0, 0, 0, 0 };
+ static void Set(const Type&);
+ static Type Get();
+};
+
+constexpr bool operator!=(const RasterPos::Type& a, const RasterPos::Type& b) {
+ return a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w;
+}
+
+#endif // MBGL_USE_GLES2
} // namespace value
} // namespace gl