diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index f9cd1c7d1..6790007c9 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -86,6 +86,9 @@ DisplayState Graphics::saveState() if (s.scissor) glGetIntegerv(GL_SCISSOR_BOX, s.scissorBox); + for (int i = 0; i < 4; i++) + s.colorMask[i] = colorMask[i]; + return s; } @@ -101,6 +104,7 @@ void Graphics::restoreState(const DisplayState &s) setScissor(s.scissorBox[0], s.scissorBox[1], s.scissorBox[2], s.scissorBox[3]); else setScissor(); + setColorMask(s.colorMask[0], s.colorMask[1], s.colorMask[2], s.colorMask[3]); } bool Graphics::setMode(int width, int height, bool fullscreen, bool vsync, int fsaa) @@ -136,6 +140,9 @@ bool Graphics::setMode(int width, int height, bool fullscreen, bool vsync, int f // "Normal" blending glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + // Enable all color component writes. + setColorMask(true, true, true, true); + // Enable line/point smoothing. setLineStyle(LINE_SMOOTH); glEnable(GL_POINT_SMOOTH); @@ -331,12 +338,12 @@ void Graphics::useStencil(bool invert) { glStencilFunc(GL_EQUAL, (int)(!invert), 1); // invert ? 0 : 1 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + setColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]); } void Graphics::discardStencil() { - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + setColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]); glDisable(GL_STENCIL_TEST); } @@ -500,6 +507,21 @@ Font *Graphics::getFont() const return currentFont; } +void Graphics::setColorMask(bool r, bool g, bool b, bool a) +{ + colorMask[0] = r; + colorMask[1] = g; + colorMask[2] = b; + colorMask[3] = a; + + glColorMask((GLboolean) r, (GLboolean) g, (GLboolean) b, (GLboolean) a); +} + +const bool *Graphics::getColorMask() const +{ + return colorMask; +} + void Graphics::setBlendMode(Graphics::BlendMode mode) { if (GLEE_VERSION_1_4 || GLEE_ARB_imaging) diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 2799a77cf..2a55010b8 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -76,6 +76,9 @@ struct DisplayState bool scissor; GLint scissorBox[4]; + // Color mask. + bool colorMask[4]; + // Window info. std::string caption; bool mouseVisible; @@ -94,6 +97,7 @@ struct DisplayState pointSize = 1.0f; pointStyle = Graphics::POINT_SMOOTH; scissor = false; + colorMask[0] = colorMask[1] = colorMask[2] = colorMask[3] = true; caption = ""; mouseVisible = true; } @@ -303,6 +307,17 @@ public: **/ Font *getFont() const; + /** + * Sets the enabled color components when rendering. + **/ + void setColorMask(bool r, bool g, bool b, bool a); + + /** + * Gets the current color mask. + * Returns an array of 4 booleans representing the mask. + **/ + const bool *getColorMask() const; + /** * Sets the current blend mode. **/ @@ -521,6 +536,7 @@ private: float lineWidth; GLint matrixLimit; GLint userMatrices; + bool colorMask[4]; int getRenderHeight() const; }; // Graphics diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index a5aa755e4..35fc8f4ed 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -589,6 +589,28 @@ int w_getFont(lua_State *L) return 1; } +int w_setColorMask(lua_State *L) +{ + bool mask[4]; + for (int i = 0; i < 4; i++) + mask[i] = luax_toboolean(L, i + 1); + + // r, g, b, a + instance->setColorMask(mask[0], mask[1], mask[2], mask[3]); + + return 0; +} + +int w_getColorMask(lua_State *L) +{ + const bool *mask = instance->getColorMask(); + + for (int i = 0; i < 4; i++) + luax_pushboolean(L, mask[i]); + + return 4; +} + int w_setBlendMode(lua_State *L) { Graphics::BlendMode mode; @@ -1285,6 +1307,8 @@ static const luaL_Reg functions[] = { "setFont", w_setFont }, { "getFont", w_getFont }, + { "setColorMask", w_setColorMask }, + { "getColorMask", w_getColorMask }, { "setBlendMode", w_setBlendMode }, { "setColorMode", w_setColorMode }, { "setDefaultImageFilter", w_setDefaultImageFilter }, diff --git a/src/modules/graphics/opengl/wrap_Graphics.h b/src/modules/graphics/opengl/wrap_Graphics.h index d11ac1552..8558486f7 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.h +++ b/src/modules/graphics/opengl/wrap_Graphics.h @@ -70,6 +70,8 @@ int w_setBackgroundColor(lua_State *L); int w_getBackgroundColor(lua_State *L); int w_setFont(lua_State *L); int w_getFont(lua_State *L); +int w_setColorMask(lua_State *L); +int w_getColorMask(lua_State *L); int w_setBlendMode(lua_State *L); int w_setColorMode(lua_State *L); int w_setDefaultImageFilter(lua_State *L);