diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-02-04 16:59:59 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-02-08 12:50:00 +0100 |
commit | e74987b07fac1c2e39ced47e2401436fb01b2a1c (patch) | |
tree | 27abb7086bd510aadd63a4a6327f82fbbcb52a36 /src/mbgl/gl | |
parent | 5c3b01ffcfa6f10473d9eb54bd025a2276744a90 (diff) | |
download | qtlocation-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.
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r-- | src/mbgl/gl/gl_config.cpp | 24 | ||||
-rw-r--r-- | src/mbgl/gl/gl_config.hpp | 100 |
2 files changed, 124 insertions, 0 deletions
diff --git a/src/mbgl/gl/gl_config.cpp b/src/mbgl/gl/gl_config.cpp new file mode 100644 index 0000000000..4160ae100e --- /dev/null +++ b/src/mbgl/gl/gl_config.cpp @@ -0,0 +1,24 @@ +#include "gl_config.hpp" + +namespace mbgl { +namespace gl { + +const StencilFunc::Type StencilFunc::Default = { GL_ALWAYS, 0, ~0u }; +const StencilMask::Type StencilMask::Default = ~0u; +const StencilTest::Type StencilTest::Default = GL_FALSE; +const StencilOp::Type StencilOp::Default = { GL_KEEP, GL_KEEP, GL_REPLACE }; +const DepthRange::Type DepthRange::Default = { 0, 1 }; +const DepthMask::Type DepthMask::Default = GL_TRUE; +const DepthTest::Type DepthTest::Default = GL_FALSE; +const DepthFunc::Type DepthFunc::Default = GL_LEQUAL; +const Blend::Type Blend::Default = GL_TRUE; +const BlendFunc::Type BlendFunc::Default = { GL_ONE, GL_ONE_MINUS_SRC_ALPHA }; +const ColorMask::Type ColorMask::Default = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE }; +const ClearDepth::Type ClearDepth::Default = 1; +const ClearColor::Type ClearColor::Default = { 0, 0, 0, 0 }; +const ClearStencil::Type ClearStencil::Default = 0; +const Program::Type Program::Default = 0; +const LineWidth::Type LineWidth::Default = 1; + +} // namespace gl +} // namespace mbgl 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 |