Merged love-experiments/love.graphics.setColorMask into default

This commit is contained in:
Alex Szpakowski
2013-03-27 19:43:04 -03:00
4 changed files with 66 additions and 2 deletions
+24 -2
View File
@@ -87,6 +87,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, WindowFlags *flags)
@@ -135,6 +139,9 @@ bool Graphics::setMode(int width, int height, WindowFlags *flags)
// "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);
@@ -338,12 +345,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);
}
@@ -507,6 +514,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)
{
const int gl_1_4 = GLEE_VERSION_1_4;
+16
View File
@@ -77,6 +77,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;
}
@@ -299,6 +303,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.
**/
@@ -495,6 +510,7 @@ private:
float lineWidth;
GLint matrixLimit;
GLint userMatrices;
bool colorMask[4];
int getRenderWidth() const;
int getRenderHeight() const;
@@ -701,6 +701,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;
@@ -1483,6 +1505,8 @@ static const luaL_Reg functions[] =
{ "setFont", w_setFont },
{ "getFont", w_getFont },
{ "setColorMask", w_setColorMask },
{ "getColorMask", w_getColorMask },
{ "setBlendMode", w_setBlendMode },
{ "getBlendMode", w_getBlendMode },
{ "setDefaultFilter", w_setDefaultFilter },
@@ -71,6 +71,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_getBlendMode(lua_State *L);
int w_setDefaultFilter(lua_State *L);