mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
Merged love-experiments/love.graphics.setColorMask into default
This commit is contained in:
@@ -87,6 +87,9 @@ DisplayState Graphics::saveState()
|
|||||||
if (s.scissor)
|
if (s.scissor)
|
||||||
glGetIntegerv(GL_SCISSOR_BOX, s.scissorBox);
|
glGetIntegerv(GL_SCISSOR_BOX, s.scissorBox);
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
s.colorMask[i] = colorMask[i];
|
||||||
|
|
||||||
return s;
|
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]);
|
setScissor(s.scissorBox[0], s.scissorBox[1], s.scissorBox[2], s.scissorBox[3]);
|
||||||
else
|
else
|
||||||
setScissor();
|
setScissor();
|
||||||
|
setColorMask(s.colorMask[0], s.colorMask[1], s.colorMask[2], s.colorMask[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Graphics::setMode(int width, int height, WindowFlags *flags)
|
bool Graphics::setMode(int width, int height, WindowFlags *flags)
|
||||||
@@ -135,6 +139,9 @@ bool Graphics::setMode(int width, int height, WindowFlags *flags)
|
|||||||
// "Normal" blending
|
// "Normal" blending
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
// Enable all color component writes.
|
||||||
|
setColorMask(true, true, true, true);
|
||||||
|
|
||||||
// Enable line/point smoothing.
|
// Enable line/point smoothing.
|
||||||
setLineStyle(LINE_SMOOTH);
|
setLineStyle(LINE_SMOOTH);
|
||||||
glEnable(GL_POINT_SMOOTH);
|
glEnable(GL_POINT_SMOOTH);
|
||||||
@@ -338,12 +345,12 @@ void Graphics::useStencil(bool invert)
|
|||||||
{
|
{
|
||||||
glStencilFunc(GL_EQUAL, (int)(!invert), 1); // invert ? 0 : 1
|
glStencilFunc(GL_EQUAL, (int)(!invert), 1); // invert ? 0 : 1
|
||||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
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()
|
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);
|
glDisable(GL_STENCIL_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -507,6 +514,21 @@ Font *Graphics::getFont() const
|
|||||||
return currentFont;
|
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)
|
void Graphics::setBlendMode(Graphics::BlendMode mode)
|
||||||
{
|
{
|
||||||
const int gl_1_4 = GLEE_VERSION_1_4;
|
const int gl_1_4 = GLEE_VERSION_1_4;
|
||||||
|
|||||||
@@ -77,6 +77,9 @@ struct DisplayState
|
|||||||
bool scissor;
|
bool scissor;
|
||||||
GLint scissorBox[4];
|
GLint scissorBox[4];
|
||||||
|
|
||||||
|
// Color mask.
|
||||||
|
bool colorMask[4];
|
||||||
|
|
||||||
// Window info.
|
// Window info.
|
||||||
std::string caption;
|
std::string caption;
|
||||||
bool mouseVisible;
|
bool mouseVisible;
|
||||||
@@ -94,6 +97,7 @@ struct DisplayState
|
|||||||
pointSize = 1.0f;
|
pointSize = 1.0f;
|
||||||
pointStyle = Graphics::POINT_SMOOTH;
|
pointStyle = Graphics::POINT_SMOOTH;
|
||||||
scissor = false;
|
scissor = false;
|
||||||
|
colorMask[0] = colorMask[1] = colorMask[2] = colorMask[3] = true;
|
||||||
caption = "";
|
caption = "";
|
||||||
mouseVisible = true;
|
mouseVisible = true;
|
||||||
}
|
}
|
||||||
@@ -299,6 +303,17 @@ public:
|
|||||||
**/
|
**/
|
||||||
Font *getFont() const;
|
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.
|
* Sets the current blend mode.
|
||||||
**/
|
**/
|
||||||
@@ -495,6 +510,7 @@ private:
|
|||||||
float lineWidth;
|
float lineWidth;
|
||||||
GLint matrixLimit;
|
GLint matrixLimit;
|
||||||
GLint userMatrices;
|
GLint userMatrices;
|
||||||
|
bool colorMask[4];
|
||||||
|
|
||||||
int getRenderWidth() const;
|
int getRenderWidth() const;
|
||||||
int getRenderHeight() const;
|
int getRenderHeight() const;
|
||||||
|
|||||||
@@ -701,6 +701,28 @@ int w_getFont(lua_State *L)
|
|||||||
return 1;
|
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)
|
int w_setBlendMode(lua_State *L)
|
||||||
{
|
{
|
||||||
Graphics::BlendMode mode;
|
Graphics::BlendMode mode;
|
||||||
@@ -1483,6 +1505,8 @@ static const luaL_Reg functions[] =
|
|||||||
{ "setFont", w_setFont },
|
{ "setFont", w_setFont },
|
||||||
{ "getFont", w_getFont },
|
{ "getFont", w_getFont },
|
||||||
|
|
||||||
|
{ "setColorMask", w_setColorMask },
|
||||||
|
{ "getColorMask", w_getColorMask },
|
||||||
{ "setBlendMode", w_setBlendMode },
|
{ "setBlendMode", w_setBlendMode },
|
||||||
{ "getBlendMode", w_getBlendMode },
|
{ "getBlendMode", w_getBlendMode },
|
||||||
{ "setDefaultFilter", w_setDefaultFilter },
|
{ "setDefaultFilter", w_setDefaultFilter },
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ int w_setBackgroundColor(lua_State *L);
|
|||||||
int w_getBackgroundColor(lua_State *L);
|
int w_getBackgroundColor(lua_State *L);
|
||||||
int w_setFont(lua_State *L);
|
int w_setFont(lua_State *L);
|
||||||
int w_getFont(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_setBlendMode(lua_State *L);
|
||||||
int w_getBlendMode(lua_State *L);
|
int w_getBlendMode(lua_State *L);
|
||||||
int w_setDefaultFilter(lua_State *L);
|
int w_setDefaultFilter(lua_State *L);
|
||||||
|
|||||||
Reference in New Issue
Block a user