diff --git a/drape/glconstants.cpp b/drape/glconstants.cpp index c25e7ffbbe..8b232488d2 100644 --- a/drape/glconstants.cpp +++ b/drape/glconstants.cpp @@ -82,26 +82,42 @@ namespace GLConst const glConst GLFloatType = GL_FLOAT; const glConst GLDoubleType = GL_DOUBLE; - const glConst GLFloatVec2 = GL_FLOAT_VEC2; - const glConst GLFloatVec3 = GL_FLOAT_VEC3; - const glConst GLFloatVec4 = GL_FLOAT_VEC4; + const glConst GLFloatVec2 = GL_FLOAT_VEC2; + const glConst GLFloatVec3 = GL_FLOAT_VEC3; + const glConst GLFloatVec4 = GL_FLOAT_VEC4; - const glConst GLIntVec2 = GL_INT_VEC2; - const glConst GLIntVec3 = GL_INT_VEC3; - const glConst GLIntVec4 = GL_INT_VEC4; + const glConst GLIntVec2 = GL_INT_VEC2; + const glConst GLIntVec3 = GL_INT_VEC3; + const glConst GLIntVec4 = GL_INT_VEC4; - const glConst GLFloatMat4 = GL_FLOAT_MAT4; + const glConst GLFloatMat4 = GL_FLOAT_MAT4; - const glConst GLDepthTest = GL_DEPTH_TEST; + const glConst GLAddBlend = GL_FUNC_ADD; + const glConst GLSubstractBlend = GL_FUNC_SUBTRACT; + const glConst GLReverseSubstrBlend = GL_FUNC_REVERSE_SUBTRACT; - const glConst GLNever = GL_NEVER; - const glConst GLLess = GL_LESS; - const glConst GLEqual = GL_EQUAL; - const glConst GLLessOrEqual = GL_LEQUAL; - const glConst GLGreat = GL_GREATER; - const glConst GLNotEqual = GL_NOTEQUAL; - const glConst GLGreatOrEqual = GL_GEQUAL; - const glConst GLAlways = GL_ALWAYS; + const glConst GLZero = GL_ZERO; + const glConst GLOne = GL_ONE; + const glConst GLSrcColor = GL_SRC_COLOR; + const glConst GLOneMinusSrcColor = GL_ONE_MINUS_SRC_COLOR; + const glConst GLDstColor = GL_DST_COLOR; + const glConst GLOneMinusDstColor = GL_ONE_MINUS_DST_COLOR; + const glConst GLSrcAlfa = GL_SRC_ALPHA; + const glConst GLOneMinusSrcAlfa = GL_ONE_MINUS_SRC_ALPHA; + const glConst GLDstAlfa = GL_DST_ALPHA; + const glConst GLOneMinusDstAlfa = GL_ONE_MINUS_DST_ALPHA; + + const glConst GLDepthTest = GL_DEPTH_TEST; + const glConst GLBlending = GL_BLEND; + + const glConst GLNever = GL_NEVER; + const glConst GLLess = GL_LESS; + const glConst GLEqual = GL_EQUAL; + const glConst GLLessOrEqual = GL_LEQUAL; + const glConst GLGreat = GL_GREATER; + const glConst GLNotEqual = GL_NOTEQUAL; + const glConst GLGreatOrEqual = GL_GEQUAL; + const glConst GLAlways = GL_ALWAYS; const glConst GLActiveUniforms = GL_ACTIVE_UNIFORMS; } diff --git a/drape/glconstants.hpp b/drape/glconstants.hpp index b4980a13bd..c7dcb58812 100644 --- a/drape/glconstants.hpp +++ b/drape/glconstants.hpp @@ -84,9 +84,26 @@ namespace GLConst extern const glConst GLFloatMat4; + /// Blend Functions + extern const glConst GLAddBlend; + extern const glConst GLSubstractBlend; + extern const glConst GLReverseSubstrBlend; + + /// Blend Factors + extern const glConst GLZero; + extern const glConst GLOne; + extern const glConst GLSrcColor; + extern const glConst GLOneMinusSrcColor; + extern const glConst GLDstColor; + extern const glConst GLOneMinusDstColor; + extern const glConst GLSrcAlfa; + extern const glConst GLOneMinusSrcAlfa; + extern const glConst GLDstAlfa; + extern const glConst GLOneMinusDstAlfa; /// OpenGL states extern const glConst GLDepthTest; + extern const glConst GLBlending; /// OpenGL depth functions extern const glConst GLNever; diff --git a/drape/glfunctions.cpp b/drape/glfunctions.cpp index 2d2132342b..a1e39f2bde 100644 --- a/drape/glfunctions.cpp +++ b/drape/glfunctions.cpp @@ -211,27 +211,37 @@ int32_t GLFunctions::glGetInteger(glConst pname) void GLFunctions::glEnable(glConst mode) { - ::glEnable(mode); + GLCHECK(::glEnable(mode)); } void GLFunctions::glDisable(glConst mode) { - ::glDisable(mode); + GLCHECK(::glDisable(mode)); } void GLFunctions::glClearDepth(double depth) { - ::glClearDepth(depth); + GLCHECK(::glClearDepth(depth)); } void GLFunctions::glDepthMask(bool needWriteToDepthBuffer) { - ::glDepthMask(convert(needWriteToDepthBuffer)); + GLCHECK(::glDepthMask(convert(needWriteToDepthBuffer))); } void GLFunctions::glDepthFunc(glConst depthFunc) { - ::glDepthFunc(depthFunc); + GLCHECK(::glDepthFunc(depthFunc)); +} + +void GLFunctions::glBlendEquation(glConst function) +{ + GLCHECK(::glBlendEquation(function)); +} + +void GLFunctions::glBlendFunc(glConst srcFactor, glConst dstFactor) +{ + GLCHECK(::glBlendFunc(srcFactor, dstFactor)); } void GLFunctions::glBindFramebuffer(glConst target, uint32_t id) diff --git a/drape/glfunctions.hpp b/drape/glfunctions.hpp index 78a54a9221..3688bf2084 100644 --- a/drape/glfunctions.hpp +++ b/drape/glfunctions.hpp @@ -21,6 +21,8 @@ public: static void glClearDepth(double depth); static void glDepthMask(bool needWriteToDepthBuffer); static void glDepthFunc(glConst depthFunc); + static void glBlendEquation(glConst function); + static void glBlendFunc(glConst srcFactor, glConst dstFactor); static void glBindFramebuffer(glConst target, uint32_t id); diff --git a/drape/glstate.cpp b/drape/glstate.cpp index 482799f32a..751f2dbd55 100644 --- a/drape/glstate.cpp +++ b/drape/glstate.cpp @@ -7,6 +7,46 @@ #define COLOR_BIT 0x1 #define TEXTURE_BIT 0x2 +Blending::Blending(bool isEnabled) + : m_isEnabled(isEnabled) + , m_blendFunction(GLConst::GLAddBlend) + , m_blendSrcFactor(GLConst::GLSrcAlfa) + , m_blendDstFactor(GLConst::GLOneMinusSrcAlfa) +{ +} + +void Blending::Apply() const +{ + if (m_isEnabled) + { + GLFunctions::glEnable(GLConst::GLBlending); + GLFunctions::glBlendEquation(m_blendFunction); + GLFunctions::glBlendFunc(m_blendSrcFactor, m_blendDstFactor); + } + else + GLFunctions::glDisable(GLConst::GLBlending); +} + +bool Blending::operator < (const Blending & other) const +{ + if (m_isEnabled != other.m_isEnabled) + return m_isEnabled < other.m_isEnabled; + if (m_blendFunction != other.m_blendFunction) + return m_blendFunction < other.m_blendFunction; + if (m_blendSrcFactor != other.m_blendSrcFactor) + return m_blendSrcFactor < other.m_blendSrcFactor; + + return m_blendDstFactor < other.m_blendDstFactor; +} + +bool Blending::operator == (const Blending & other) const +{ + return m_isEnabled == other.m_isEnabled && + m_blendFunction == other.m_blendFunction && + m_blendSrcFactor == other.m_blendSrcFactor && + m_blendDstFactor == other.m_blendDstFactor; +} + GLState::GLState(uint32_t gpuProgramIndex, int16_t depthLayer) : m_gpuProgramIndex(gpuProgramIndex) , m_depthLayer(depthLayer) @@ -48,6 +88,16 @@ bool GLState::HasColor() const return (m_mask & COLOR_BIT) != 0; } +void GLState::SetBlending(const Blending & blending) +{ + m_blending = blending; +} + +const Blending & GLState::GetBlending() const +{ + return m_blending; +} + int GLState::GetProgramIndex() const { return m_gpuProgramIndex; @@ -105,4 +155,6 @@ void ApplyState(GLState state, RefPointer program, int8_t location = program->GetUniformLocation("u_textures"); GLFunctions::glUniformValueiv(location, ids.data(), count); } + + state.GetBlending().Apply(); } diff --git a/drape/glstate.hpp b/drape/glstate.hpp index 6aeec9c724..967a4d0fa1 100644 --- a/drape/glstate.hpp +++ b/drape/glstate.hpp @@ -5,6 +5,21 @@ #include "texture_set_controller.hpp" #include "color.hpp" +struct Blending +{ + Blending(bool isEnabled = false); + + void Apply() const; + + bool operator < (Blending const & other) const; + bool operator == (Blending const & other) const; + + bool m_isEnabled; + glConst m_blendFunction; + glConst m_blendSrcFactor; + glConst m_blendDstFactor; +}; + class GLState { public: @@ -18,6 +33,9 @@ public: Color const & GetColor() const; bool HasColor() const; + void SetBlending(Blending const & blending); + const Blending & GetBlending() const; + int GetProgramIndex() const; bool operator<(const GLState & other) const; @@ -26,6 +44,7 @@ private: uint32_t m_gpuProgramIndex; uint16_t m_depthLayer; int32_t m_textureSet; + Blending m_blending; Color m_color; uint32_t m_mask;