summaryrefslogtreecommitdiff
path: root/src/mbgl/gl
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-09-29 12:15:36 +0200
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-09-29 10:17:47 -0700
commit15aece8a30dcc1f1f97e28180edda46d05641a2d (patch)
tree51284a75c6aa16614192988641ce71f59c794dd8 /src/mbgl/gl
parentd1a84d9b51a7145f9f7665805cf71050aac7bc63 (diff)
downloadqtlocation-mapboxgl-15aece8a30dcc1f1f97e28180edda46d05641a2d.tar.gz
[core] introduces types for GL objects
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r--src/mbgl/gl/context.cpp12
-rw-r--r--src/mbgl/gl/context.hpp30
-rw-r--r--src/mbgl/gl/object.cpp12
-rw-r--r--src/mbgl/gl/object.hpp26
-rw-r--r--src/mbgl/gl/types.hpp17
-rw-r--r--src/mbgl/gl/value.hpp13
6 files changed, 70 insertions, 40 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index e70affd0b3..0d67164870 100644
--- a/src/mbgl/gl/context.cpp
+++ b/src/mbgl/gl/context.cpp
@@ -3,6 +3,14 @@
namespace mbgl {
namespace gl {
+static_assert(std::is_same<ProgramID, GLuint>::value, "OpenGL type mismatch");
+static_assert(std::is_same<ShaderID, GLuint>::value, "OpenGL type mismatch");
+static_assert(std::is_same<BufferID, GLuint>::value, "OpenGL type mismatch");
+static_assert(std::is_same<TextureID, GLuint>::value, "OpenGL type mismatch");
+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");
+
Context::~Context() {
reset();
}
@@ -60,7 +68,7 @@ void Context::setDirtyState() {
}
void Context::performCleanup() {
- for (GLuint id : abandonedPrograms) {
+ for (auto id : abandonedPrograms) {
if (program == id) {
program.setDirty();
}
@@ -68,7 +76,7 @@ void Context::performCleanup() {
}
abandonedPrograms.clear();
- for (GLuint id : abandonedShaders) {
+ for (auto id : abandonedShaders) {
MBGL_CHECK_ERROR(glDeleteShader(id));
}
abandonedShaders.clear();
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp
index cd42e02fc0..133a56b6f8 100644
--- a/src/mbgl/gl/context.hpp
+++ b/src/mbgl/gl/context.hpp
@@ -21,12 +21,16 @@ public:
return UniqueProgram { MBGL_CHECK_ERROR(glCreateProgram()), { this } };
}
- UniqueShader createShader(GLenum type) {
- return UniqueShader { MBGL_CHECK_ERROR(glCreateShader(type)), { 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() {
- GLuint id = 0;
+ BufferID id = 0;
MBGL_CHECK_ERROR(glGenBuffers(1, &id));
return UniqueBuffer { std::move(id), { this } };
}
@@ -37,19 +41,19 @@ public:
MBGL_CHECK_ERROR(glGenTextures(TextureMax, pooledTextures.data()));
}
- GLuint id = pooledTextures.back();
+ TextureID id = pooledTextures.back();
pooledTextures.pop_back();
return UniqueTexture { std::move(id), { this } };
}
UniqueVertexArray createVertexArray() {
- GLuint id = 0;
+ VertexArrayID id = 0;
MBGL_CHECK_ERROR(gl::GenVertexArrays(1, &id));
return UniqueVertexArray { std::move(id), { this } };
}
UniqueFramebuffer createFramebuffer() {
- GLuint id = 0;
+ FramebufferID id = 0;
MBGL_CHECK_ERROR(glGenFramebuffers(1, &id));
return UniqueFramebuffer { std::move(id), { this } };
}
@@ -113,14 +117,14 @@ private:
friend detail::VertexArrayDeleter;
friend detail::FramebufferDeleter;
- std::vector<GLuint> pooledTextures;
+ std::vector<TextureID> pooledTextures;
- std::vector<GLuint> abandonedPrograms;
- std::vector<GLuint> abandonedShaders;
- std::vector<GLuint> abandonedBuffers;
- std::vector<GLuint> abandonedTextures;
- std::vector<GLuint> abandonedVertexArrays;
- std::vector<GLuint> abandonedFramebuffers;
+ std::vector<ProgramID> abandonedPrograms;
+ std::vector<ShaderID> abandonedShaders;
+ std::vector<BufferID> abandonedBuffers;
+ std::vector<TextureID> abandonedTextures;
+ std::vector<VertexArrayID> abandonedVertexArrays;
+ std::vector<FramebufferID> abandonedFramebuffers;
};
} // namespace gl
diff --git a/src/mbgl/gl/object.cpp b/src/mbgl/gl/object.cpp
index 90451da713..aee87f8836 100644
--- a/src/mbgl/gl/object.cpp
+++ b/src/mbgl/gl/object.cpp
@@ -7,22 +7,22 @@ namespace mbgl {
namespace gl {
namespace detail {
-void ProgramDeleter::operator()(GLuint id) const {
+void ProgramDeleter::operator()(ProgramID id) const {
assert(context);
context->abandonedPrograms.push_back(id);
}
-void ShaderDeleter::operator()(GLuint id) const {
+void ShaderDeleter::operator()(ShaderID id) const {
assert(context);
context->abandonedShaders.push_back(id);
}
-void BufferDeleter::operator()(GLuint id) const {
+void BufferDeleter::operator()(BufferID id) const {
assert(context);
context->abandonedBuffers.push_back(id);
}
-void TextureDeleter::operator()(GLuint id) const {
+void TextureDeleter::operator()(TextureID id) const {
assert(context);
if (context->pooledTextures.size() >= TextureMax) {
context->abandonedTextures.push_back(id);
@@ -31,12 +31,12 @@ void TextureDeleter::operator()(GLuint id) const {
}
}
-void VertexArrayDeleter::operator()(GLuint id) const {
+void VertexArrayDeleter::operator()(VertexArrayID id) const {
assert(context);
context->abandonedVertexArrays.push_back(id);
}
-void FramebufferDeleter::operator()(GLuint id) const {
+void FramebufferDeleter::operator()(FramebufferID id) const {
assert(context);
context->abandonedFramebuffers.push_back(id);
}
diff --git a/src/mbgl/gl/object.hpp b/src/mbgl/gl/object.hpp
index 785e73e8ac..1cc1f04a97 100644
--- a/src/mbgl/gl/object.hpp
+++ b/src/mbgl/gl/object.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/gl/types.hpp>
#include <unique_resource.hpp>
@@ -13,42 +13,42 @@ namespace detail {
struct ProgramDeleter {
Context* context;
- void operator()(GLuint) const;
+ void operator()(ProgramID) const;
};
struct ShaderDeleter {
Context* context;
- void operator()(GLuint) const;
+ void operator()(ShaderID) const;
};
struct BufferDeleter {
Context* context;
- void operator()(GLuint) const;
+ void operator()(BufferID) const;
};
struct TextureDeleter {
Context* context;
- void operator()(GLuint) const;
+ void operator()(TextureID) const;
};
struct VertexArrayDeleter {
Context* context;
- void operator()(GLuint) const;
+ void operator()(VertexArrayID) const;
};
struct FramebufferDeleter {
Context* context;
- void operator()(GLuint) const;
+ void operator()(FramebufferID) const;
};
} // namespace detail
-using UniqueProgram = std_experimental::unique_resource<GLuint, detail::ProgramDeleter>;
-using UniqueShader = std_experimental::unique_resource<GLuint, detail::ShaderDeleter>;
-using UniqueBuffer = std_experimental::unique_resource<GLuint, detail::BufferDeleter>;
-using UniqueTexture = std_experimental::unique_resource<GLuint, detail::TextureDeleter>;
-using UniqueVertexArray = std_experimental::unique_resource<GLuint, detail::VertexArrayDeleter>;
-using UniqueFramebuffer = std_experimental::unique_resource<GLuint, detail::FramebufferDeleter>;
+using UniqueProgram = std_experimental::unique_resource<ProgramID, detail::ProgramDeleter>;
+using UniqueShader = std_experimental::unique_resource<ShaderID, detail::ShaderDeleter>;
+using UniqueBuffer = std_experimental::unique_resource<BufferID, detail::BufferDeleter>;
+using UniqueTexture = std_experimental::unique_resource<TextureID, detail::TextureDeleter>;
+using UniqueVertexArray = std_experimental::unique_resource<VertexArrayID, detail::VertexArrayDeleter>;
+using UniqueFramebuffer = std_experimental::unique_resource<FramebufferID, detail::FramebufferDeleter>;
} // namespace gl
} // namespace mbgl
diff --git a/src/mbgl/gl/types.hpp b/src/mbgl/gl/types.hpp
new file mode 100644
index 0000000000..94426f5e36
--- /dev/null
+++ b/src/mbgl/gl/types.hpp
@@ -0,0 +1,17 @@
+#pragma once
+
+#include <cstdint>
+
+namespace mbgl {
+namespace gl {
+
+using ProgramID = uint32_t;
+using ShaderID = uint32_t;
+using BufferID = uint32_t;
+using TextureID = uint32_t;
+using VertexArrayID = uint32_t;
+using FramebufferID = uint32_t;
+using RenderbufferID = uint32_t;
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/gl/value.hpp b/src/mbgl/gl/value.hpp
index bfa4dce775..1250945ba8 100644
--- a/src/mbgl/gl/value.hpp
+++ b/src/mbgl/gl/value.hpp
@@ -6,6 +6,7 @@
#include <cassert>
#include <mbgl/gl/gl.hpp>
+#include <mbgl/gl/types.hpp>
#include <mbgl/util/color.hpp>
namespace mbgl {
@@ -234,7 +235,7 @@ struct BlendColor {
};
struct Program {
- using Type = GLuint;
+ using Type = gl::ProgramID;
static const constexpr Type Default = 0;
static void Set(const Type& value) {
MBGL_CHECK_ERROR(glUseProgram(value));
@@ -333,7 +334,7 @@ struct RasterPos {
#endif // GL_ES_VERSION_2_0
struct BindTexture {
- using Type = GLuint;
+ using Type = gl::TextureID;
static const constexpr Type Default = 0;
static void Set(const Type& value) {
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, value));
@@ -341,7 +342,7 @@ struct BindTexture {
static Type Get() {
GLint texture;
MBGL_CHECK_ERROR(glGetIntegerv(GL_TEXTURE_BINDING_2D, &texture));
- return texture;
+ return static_cast<Type>(texture);
}
};
@@ -349,7 +350,7 @@ 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");
- using Type = GLuint;
+ using Type = gl::BufferID;
static const constexpr Type Default = 0;
static void Set(const Type& value) {
MBGL_CHECK_ERROR(glBindBuffer(target, value));
@@ -359,7 +360,7 @@ struct BindBuffer {
MBGL_CHECK_ERROR(glGetIntegerv(target == GL_ARRAY_BUFFER ? GL_ARRAY_BUFFER_BINDING
: GL_ELEMENT_ARRAY_BUFFER_BINDING,
&binding));
- return binding;
+ return static_cast<Type>(binding);
}
};
@@ -367,7 +368,7 @@ template <GLenum target>
const typename BindBuffer<target>::Type BindBuffer<target>::Default;
struct BindVertexArray {
- using Type = GLuint;
+ using Type = gl::VertexArrayID;
static const constexpr Type Default = 0;
static void Set(const Type& value) {
if (gl::BindVertexArray) {