summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-02-04 16:59:59 +0100
committerKonstantin Käfer <mail@kkaefer.com>2016-02-08 12:50:00 +0100
commite74987b07fac1c2e39ced47e2401436fb01b2a1c (patch)
tree27abb7086bd510aadd63a4a6327f82fbbcb52a36
parent5c3b01ffcfa6f10473d9eb54bd025a2276744a90 (diff)
downloadqtlocation-mapboxgl-e74987b07fac1c2e39ced47e2401436fb01b2a1c.tar.gz
[core] move GL value objects from gl_config.hpp to gl_values.hpp
Also removes duplicate code from gl_helper.hpp by reusing the GL values that we already have anyway.
-rw-r--r--include/mbgl/gl/gl_helper.hpp85
-rw-r--r--include/mbgl/gl/gl_values.hpp (renamed from src/mbgl/renderer/gl_config.hpp)109
-rw-r--r--include/mbgl/platform/default/glfw_view.hpp1
-rw-r--r--platform/default/glfw_view.cpp17
-rw-r--r--src/mbgl/gl/gl_config.cpp (renamed from src/mbgl/renderer/gl_config.cpp)0
-rw-r--r--src/mbgl/gl/gl_config.hpp100
-rw-r--r--src/mbgl/renderer/painter.hpp2
7 files changed, 148 insertions, 166 deletions
diff --git a/include/mbgl/gl/gl_helper.hpp b/include/mbgl/gl/gl_helper.hpp
index e1fb8c27c5..4f3990a434 100644
--- a/include/mbgl/gl/gl_helper.hpp
+++ b/include/mbgl/gl/gl_helper.hpp
@@ -1,89 +1,22 @@
#ifndef MBGL_GL_GL_HELPER
#define MBGL_GL_GL_HELPER
-#include <mbgl/gl/gl.hpp>
-
-#include <array>
-
-namespace {
+namespace mbgl {
+namespace gl {
-template <typename T, T (*Create)(), void (*Destroy)(const T&)>
+template <typename T>
class Preserve {
public:
- Preserve() : data(Create()) {}
- ~Preserve() { Destroy(data); }
+ inline Preserve() : data(T::Get()) {
+ }
+ inline ~Preserve() {
+ T::Set(data);
+ }
private:
- const T data;
+ const typename T::Type data;
};
-inline bool getBlend() {
- return glIsEnabled(GL_BLEND);
-}
-
-inline void setBlend(const bool& enabled) {
- enabled ? MBGL_CHECK_ERROR(glEnable(GL_BLEND)) : MBGL_CHECK_ERROR(glDisable(GL_BLEND));
-}
-
-inline std::array<float, 4> getClearColor() {
- std::array<float, 4> color;
- MBGL_CHECK_ERROR(glGetFloatv(GL_COLOR_CLEAR_VALUE, color.data()));
- return color;
-}
-
-inline void setClearColor(const std::array<float, 4>& color) {
- MBGL_CHECK_ERROR(glClearColor(color[0], color[1], color[2], color[3]));
-}
-
-
-inline std::array<GLenum, 2> getBlendFunc() {
- GLint func[2];
- glGetIntegerv(GL_BLEND_SRC_ALPHA, &func[0]);
- glGetIntegerv(GL_BLEND_DST_ALPHA, &func[1]);
- return {{ static_cast<GLenum>(func[0]), static_cast<GLenum>(func[1]) }};
-}
-
-inline void setBlendFunc(const std::array<GLenum, 2>& func) {
- MBGL_CHECK_ERROR(glBlendFunc(func[0], func[1]));
-}
-
-#ifndef GL_ES_VERSION_2_0
-inline std::array<double, 2> getPixelZoom() {
- std::array<double, 2> zoom;
- glGetDoublev(GL_ZOOM_X, &zoom[0]);
- glGetDoublev(GL_ZOOM_Y, &zoom[1]);
- return zoom;
-}
-
-inline void setPixelZoom(const std::array<double, 2>& func) {
- MBGL_CHECK_ERROR(glPixelZoom(func[0], func[1]));
-}
-
-
-inline std::array<double, 4> getRasterPos() {
- std::array<double, 4> pos;
- MBGL_CHECK_ERROR(glGetDoublev(GL_CURRENT_RASTER_POSITION, pos.data()));
- return pos;
-}
-
-inline void setRasterPos(const std::array<double, 4>& pos) {
- MBGL_CHECK_ERROR(glRasterPos4d(pos[0], pos[1], pos[2], pos[3]));
-}
-#endif
-} // end anonymous namespace
-
-namespace mbgl {
-namespace gl {
-
-using PreserveBlend = Preserve<bool, getBlend, setBlend>;
-using PreserveClearColor = Preserve<std::array<float, 4>, getClearColor, setClearColor>;
-using PreserveBlendFunc = Preserve<std::array<GLenum, 2>, getBlendFunc, setBlendFunc>;
-
-#ifndef GL_ES_VERSION_2_0
-using PreservePixelZoom = Preserve<std::array<double, 2>, getPixelZoom, setPixelZoom>;
-using PreserveRasterPos = Preserve<std::array<double, 4>, getRasterPos, setRasterPos>;
-#endif
-
} // namespace gl
} // namespace mbgl
diff --git a/src/mbgl/renderer/gl_config.hpp b/include/mbgl/gl/gl_values.hpp
index 4ab1dbb268..a5d413f5af 100644
--- a/src/mbgl/renderer/gl_config.hpp
+++ b/include/mbgl/gl/gl_values.hpp
@@ -1,5 +1,5 @@
-#ifndef MBGL_RENDERER_GL_CONFIG
-#define MBGL_RENDERER_GL_CONFIG
+#ifndef MBGL_GL_GL_VALUES
+#define MBGL_GL_GL_VALUES
#include <cstdint>
#include <tuple>
@@ -10,32 +10,6 @@
namespace mbgl {
namespace gl {
-template <typename T>
-class Value {
-public:
- inline void operator=(const typename T::Type& value) {
- if (dirty || current != value) {
- dirty = false;
- current = value;
- T::Set(current);
- }
- }
-
- inline void reset() {
- dirty = true;
- current = T::Default;
- T::Set(current);
- }
-
- inline void setDirty() {
- dirty = true;
- }
-
-private:
- typename T::Type current = T::Default;
- bool dirty = false;
-};
-
struct ClearDepth {
using Type = GLfloat;
static const Type Default;
@@ -266,64 +240,37 @@ struct LineWidth {
}
};
-class Config {
-public:
- void reset() {
- stencilFunc.reset();
- stencilMask.reset();
- stencilTest.reset();
- stencilOp.reset();
- depthRange.reset();
- depthMask.reset();
- depthTest.reset();
- depthFunc.reset();
- blend.reset();
- blendFunc.reset();
- colorMask.reset();
- clearDepth.reset();
- clearColor.reset();
- clearStencil.reset();
- program.reset();
- lineWidth.reset();
- }
+#ifndef GL_ES_VERSION_2_0
- void setDirty() {
- stencilFunc.setDirty();
- stencilMask.setDirty();
- stencilTest.setDirty();
- stencilOp.setDirty();
- depthRange.setDirty();
- depthMask.setDirty();
- depthTest.setDirty();
- depthFunc.setDirty();
- blend.setDirty();
- blendFunc.setDirty();
- colorMask.setDirty();
- clearDepth.setDirty();
- clearColor.setDirty();
- clearStencil.setDirty();
- program.setDirty();
- lineWidth.setDirty();
+struct PixelZoom {
+ struct Type { GLfloat xfactor; GLfloat yfactor; };
+ static const Type Default;
+ inline static void Set(const Type& value) {
+ MBGL_CHECK_ERROR(glPixelZoom(value.xfactor, value.yfactor));
+ }
+ inline 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;
}
+};
- Value<StencilFunc> stencilFunc;
- Value<StencilMask> stencilMask;
- Value<StencilTest> stencilTest;
- Value<StencilOp> stencilOp;
- Value<DepthRange> depthRange;
- Value<DepthMask> depthMask;
- Value<DepthTest> depthTest;
- Value<DepthFunc> depthFunc;
- Value<Blend> blend;
- Value<BlendFunc> blendFunc;
- Value<ColorMask> colorMask;
- Value<ClearDepth> clearDepth;
- Value<ClearColor> clearColor;
- Value<ClearStencil> clearStencil;
- Value<Program> program;
- Value<LineWidth> lineWidth;
+struct RasterPos {
+ using Type = std::array<GLdouble, 4>;
+ static const Type Default;
+ inline static void Set(const Type& value) {
+ MBGL_CHECK_ERROR(glRasterPos4d(value[0], value[1], value[2], value[3]));
+ }
+ inline static Type Get() {
+ Type pos;
+ MBGL_CHECK_ERROR(glGetDoublev(GL_CURRENT_RASTER_POSITION, pos.data()));
+ return pos;
+ }
};
+#endif
+
} // namespace gl
} // namespace mbgl
diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp
index 0e46f7d87e..2f74404201 100644
--- a/include/mbgl/platform/default/glfw_view.hpp
+++ b/include/mbgl/platform/default/glfw_view.hpp
@@ -6,6 +6,7 @@
#ifdef MBGL_USE_GLES2
#define GLFW_INCLUDE_ES2
#endif
+#define GL_GLEXT_PROTOTYPES
#include <GLFW/glfw3.h>
#include <atomic>
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index 375b9fd626..3173bfddee 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -1,8 +1,9 @@
+#include <mbgl/platform/default/glfw_view.hpp>
#include <mbgl/annotation/point_annotation.hpp>
#include <mbgl/annotation/shape_annotation.hpp>
#include <mbgl/sprite/sprite_image.hpp>
-#include <mbgl/platform/default/glfw_view.hpp>
#include <mbgl/gl/gl.hpp>
+#include <mbgl/gl/gl_values.hpp>
#include <mbgl/gl/gl_helper.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/util/string.hpp>
@@ -496,8 +497,8 @@ void showDebugImage(std::string name, const char *data, size_t width, size_t hei
float scale = static_cast<float>(fbWidth) / static_cast<float>(width);
{
- gl::PreservePixelZoom pixelZoom;
- gl::PreserveRasterPos rasterPos;
+ gl::Preserve<gl::PixelZoom> pixelZoom;
+ gl::Preserve<gl::RasterPos> rasterPos;
MBGL_CHECK_ERROR(glPixelZoom(scale, -scale));
MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f));
@@ -533,11 +534,11 @@ void showColorDebugImage(std::string name, const char *data, size_t logicalWidth
float yScale = static_cast<float>(fbHeight) / static_cast<float>(height);
{
- gl::PreserveClearColor clearColor;
- gl::PreserveBlend blend;
- gl::PreserveBlendFunc blendFunc;
- gl::PreservePixelZoom pixelZoom;
- gl::PreserveRasterPos rasterPos;
+ gl::Preserve<gl::ClearColor> clearColor;
+ gl::Preserve<gl::Blend> blend;
+ gl::Preserve<gl::BlendFunc> blendFunc;
+ gl::Preserve<gl::PixelZoom> pixelZoom;
+ gl::Preserve<gl::RasterPos> rasterPos;
MBGL_CHECK_ERROR(glClearColor(0.8, 0.8, 0.8, 1));
MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT));
diff --git a/src/mbgl/renderer/gl_config.cpp b/src/mbgl/gl/gl_config.cpp
index 4160ae100e..4160ae100e 100644
--- a/src/mbgl/renderer/gl_config.cpp
+++ b/src/mbgl/gl/gl_config.cpp
diff --git a/src/mbgl/gl/gl_config.hpp b/src/mbgl/gl/gl_config.hpp
new file mode 100644
index 0000000000..af373fc3f8
--- /dev/null
+++ b/src/mbgl/gl/gl_config.hpp
@@ -0,0 +1,100 @@
+#ifndef MBGL_GL_GL_CONFIG
+#define MBGL_GL_GL_CONFIG
+
+#include <cstdint>
+#include <tuple>
+#include <array>
+
+#include <mbgl/gl/gl_values.hpp>
+
+namespace mbgl {
+namespace gl {
+
+template <typename T>
+class Value {
+public:
+ inline void operator=(const typename T::Type& value) {
+ if (dirty || current != value) {
+ dirty = false;
+ current = value;
+ T::Set(current);
+ }
+ }
+
+ inline void reset() {
+ dirty = true;
+ current = T::Default;
+ T::Set(current);
+ }
+
+ inline void setDirty() {
+ dirty = true;
+ }
+
+private:
+ typename T::Type current = T::Default;
+ bool dirty = false;
+};
+
+class Config {
+public:
+ void reset() {
+ stencilFunc.reset();
+ stencilMask.reset();
+ stencilTest.reset();
+ stencilOp.reset();
+ depthRange.reset();
+ depthMask.reset();
+ depthTest.reset();
+ depthFunc.reset();
+ blend.reset();
+ blendFunc.reset();
+ colorMask.reset();
+ clearDepth.reset();
+ clearColor.reset();
+ clearStencil.reset();
+ program.reset();
+ lineWidth.reset();
+ }
+
+ void setDirty() {
+ stencilFunc.setDirty();
+ stencilMask.setDirty();
+ stencilTest.setDirty();
+ stencilOp.setDirty();
+ depthRange.setDirty();
+ depthMask.setDirty();
+ depthTest.setDirty();
+ depthFunc.setDirty();
+ blend.setDirty();
+ blendFunc.setDirty();
+ colorMask.setDirty();
+ clearDepth.setDirty();
+ clearColor.setDirty();
+ clearStencil.setDirty();
+ program.setDirty();
+ lineWidth.setDirty();
+ }
+
+ Value<StencilFunc> stencilFunc;
+ Value<StencilMask> stencilMask;
+ Value<StencilTest> stencilTest;
+ Value<StencilOp> stencilOp;
+ Value<DepthRange> depthRange;
+ Value<DepthMask> depthMask;
+ Value<DepthTest> depthTest;
+ Value<DepthFunc> depthFunc;
+ Value<Blend> blend;
+ Value<BlendFunc> blendFunc;
+ Value<ColorMask> colorMask;
+ Value<ClearDepth> clearDepth;
+ Value<ClearColor> clearColor;
+ Value<ClearStencil> clearStencil;
+ Value<Program> program;
+ Value<LineWidth> lineWidth;
+};
+
+} // namespace gl
+} // namespace mbgl
+
+#endif // MBGL_RENDERER_GL_CONFIG
diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp
index 3940978835..e2949681cd 100644
--- a/src/mbgl/renderer/painter.hpp
+++ b/src/mbgl/renderer/painter.hpp
@@ -10,7 +10,7 @@
#include <mbgl/geometry/vao.hpp>
#include <mbgl/geometry/static_vertex_buffer.hpp>
-#include <mbgl/renderer/gl_config.hpp>
+#include <mbgl/gl/gl_config.hpp>
#include <mbgl/style/types.hpp>