From 5c3b01ffcfa6f10473d9eb54bd025a2276744a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 4 Feb 2016 16:30:09 +0100 Subject: [core] move util/gl_helper.hpp to gl/gl_helper.hpp --- include/mbgl/gl/gl_helper.hpp | 90 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 include/mbgl/gl/gl_helper.hpp (limited to 'include/mbgl/gl') diff --git a/include/mbgl/gl/gl_helper.hpp b/include/mbgl/gl/gl_helper.hpp new file mode 100644 index 0000000000..e1fb8c27c5 --- /dev/null +++ b/include/mbgl/gl/gl_helper.hpp @@ -0,0 +1,90 @@ +#ifndef MBGL_GL_GL_HELPER +#define MBGL_GL_GL_HELPER + +#include + +#include + +namespace { + +template +class Preserve { +public: + Preserve() : data(Create()) {} + ~Preserve() { Destroy(data); } + +private: + const T 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 getClearColor() { + std::array color; + MBGL_CHECK_ERROR(glGetFloatv(GL_COLOR_CLEAR_VALUE, color.data())); + return color; +} + +inline void setClearColor(const std::array& color) { + MBGL_CHECK_ERROR(glClearColor(color[0], color[1], color[2], color[3])); +} + + +inline std::array getBlendFunc() { + GLint func[2]; + glGetIntegerv(GL_BLEND_SRC_ALPHA, &func[0]); + glGetIntegerv(GL_BLEND_DST_ALPHA, &func[1]); + return {{ static_cast(func[0]), static_cast(func[1]) }}; +} + +inline void setBlendFunc(const std::array& func) { + MBGL_CHECK_ERROR(glBlendFunc(func[0], func[1])); +} + +#ifndef GL_ES_VERSION_2_0 +inline std::array getPixelZoom() { + std::array zoom; + glGetDoublev(GL_ZOOM_X, &zoom[0]); + glGetDoublev(GL_ZOOM_Y, &zoom[1]); + return zoom; +} + +inline void setPixelZoom(const std::array& func) { + MBGL_CHECK_ERROR(glPixelZoom(func[0], func[1])); +} + + +inline std::array getRasterPos() { + std::array pos; + MBGL_CHECK_ERROR(glGetDoublev(GL_CURRENT_RASTER_POSITION, pos.data())); + return pos; +} + +inline void setRasterPos(const std::array& pos) { + MBGL_CHECK_ERROR(glRasterPos4d(pos[0], pos[1], pos[2], pos[3])); +} +#endif +} // end anonymous namespace + +namespace mbgl { +namespace gl { + +using PreserveBlend = Preserve; +using PreserveClearColor = Preserve, getClearColor, setClearColor>; +using PreserveBlendFunc = Preserve, getBlendFunc, setBlendFunc>; + +#ifndef GL_ES_VERSION_2_0 +using PreservePixelZoom = Preserve, getPixelZoom, setPixelZoom>; +using PreserveRasterPos = Preserve, getRasterPos, setRasterPos>; +#endif + +} // namespace gl +} // namespace mbgl + +#endif -- cgit v1.2.1