#ifndef MBGL_RENDERER_GL_CONFIG #define MBGL_RENDERER_GL_CONFIG #include #include #include #include namespace mbgl { namespace gl { template class Value { public: inline void operator=(const typename T::Type& value) { if (current != value) { current = value; MBGL_CHECK_ERROR(T::Set(current)); } } private: typename T::Type current = T::Default; }; struct ClearDepth { using Type = GLfloat; static const Type Default; inline static void Set(const Type& value) { MBGL_CHECK_ERROR(glClearDepth(value)); } }; struct ClearColor { struct Type { float r, g, b, a; }; static const Type Default; inline static void Set(const Type& value) { MBGL_CHECK_ERROR(glClearColor(value.r, value.g, value.b, value.a)); } }; inline bool operator!=(const ClearColor::Type& a, const ClearColor::Type& b) { return a.r != b.r || a.g != b.g || a.b != b.b || a.a != b.a; } struct ClearStencil { using Type = GLint; static const Type Default; inline static void Set(const Type& value) { MBGL_CHECK_ERROR(glClearStencil(value)); } }; struct StencilMask { using Type = GLuint; static const Type Default; inline static void Set(const Type& value) { MBGL_CHECK_ERROR(glStencilMask(value)); } }; struct DepthMask { using Type = GLboolean; static const Type Default; inline static void Set(const Type& value) { MBGL_CHECK_ERROR(glDepthMask(value)); } }; struct ColorMask { struct Type { bool r, g, b, a; }; static const Type Default; inline static void Set(const Type& value) { MBGL_CHECK_ERROR(glColorMask(value.r, value.g, value.b, value.a)); } }; inline bool operator!=(const ColorMask::Type& a, const ColorMask::Type& b) { return a.r != b.r || a.g != b.g || a.b != b.b || a.a != b.a; } struct StencilFunc { struct Type { GLenum func; GLint ref; GLuint mask; }; static const Type Default; inline static void Set(const Type& value) { MBGL_CHECK_ERROR(glStencilFunc(value.func, value.ref, value.mask)); } }; inline bool operator!=(const StencilFunc::Type& a, const StencilFunc::Type& b) { return a.func != b.func || a.ref != b.ref || a.mask != b.mask; } struct StencilTest { using Type = bool; static const Type Default; inline static void Set(const Type& value) { MBGL_CHECK_ERROR(value ? glEnable(GL_STENCIL_TEST) : glDisable(GL_STENCIL_TEST)); } }; struct DepthRange { struct Type { GLfloat near, far; }; static const Type Default; inline static void Set(const Type& value) { MBGL_CHECK_ERROR(glDepthRange(value.near, value.far)); } }; inline bool operator!=(const DepthRange::Type& a, const DepthRange::Type& b) { return a.near != b.near || a.far != b.far; } struct DepthTest { using Type = bool; static const Type Default; inline static void Set(const Type& value) { MBGL_CHECK_ERROR(value ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST)); } }; struct Blend { using Type = bool; static const Type Default; inline static void Set(const Type& value) { MBGL_CHECK_ERROR(value ? glEnable(GL_BLEND) : glDisable(GL_BLEND)); } }; class Config { public: Value stencilFunc; Value stencilMask; Value stencilTest; Value depthRange; Value depthMask; Value depthTest; Value blend; Value colorMask; Value clearDepth; Value clearColor; Value clearStencil; }; } } #endif