mirror of https://github.com/bjornbytes/lovr.git
lovr.graphics.getStencilTest; lovr.graphics.setStencilTest;
This commit is contained in:
parent
662572c4e0
commit
8acd7444af
|
@ -382,8 +382,8 @@ int l_lovrGraphicsSetDepthTest(lua_State* L) {
|
|||
if (lua_isnoneornil(L, 1)) {
|
||||
lovrGraphicsSetDepthTest(COMPARE_NONE);
|
||||
} else {
|
||||
CompareMode* depthTest = (CompareMode*) luax_checkenum(L, 1, &CompareModes, "compare mode");
|
||||
lovrGraphicsSetDepthTest(*depthTest);
|
||||
CompareMode depthTest = *(CompareMode*) luax_checkenum(L, 1, &CompareModes, "compare mode");
|
||||
lovrGraphicsSetDepthTest(depthTest);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -454,6 +454,32 @@ int l_lovrGraphicsSetShader(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrGraphicsGetStencilTest(lua_State* L) {
|
||||
CompareMode mode;
|
||||
int value;
|
||||
lovrGraphicsGetStencilTest(&mode, &value);
|
||||
|
||||
if (mode == COMPARE_NONE) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
luax_pushenum(L, &CompareModes, mode);
|
||||
lua_pushinteger(L, value);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int l_lovrGraphicsSetStencilTest(lua_State* L) {
|
||||
if (lua_isnoneornil(L, 1)) {
|
||||
lovrGraphicsSetStencilTest(COMPARE_NONE, 0);
|
||||
} else {
|
||||
CompareMode mode = *(CompareMode*) luax_checkenum(L, 1, &CompareModes, "compare mode");
|
||||
int value = luaL_checkinteger(L, 2);
|
||||
lovrGraphicsSetStencilTest(mode, value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrGraphicsGetWinding(lua_State* L) {
|
||||
luax_pushenum(L, &Windings, lovrGraphicsGetWinding());
|
||||
return 1;
|
||||
|
@ -1003,6 +1029,8 @@ const luaL_Reg lovrGraphics[] = {
|
|||
{ "setPointSize", l_lovrGraphicsSetPointSize },
|
||||
{ "getShader", l_lovrGraphicsGetShader },
|
||||
{ "setShader", l_lovrGraphicsSetShader },
|
||||
{ "getStencilTest", l_lovrGraphicsGetStencilTest },
|
||||
{ "setStencilTest", l_lovrGraphicsSetStencilTest },
|
||||
{ "getWinding", l_lovrGraphicsGetWinding },
|
||||
{ "setWinding", l_lovrGraphicsSetWinding },
|
||||
{ "isWireframe", l_lovrGraphicsIsWireframe },
|
||||
|
|
|
@ -72,6 +72,7 @@ void lovrGraphicsReset() {
|
|||
lovrGraphicsSetLineWidth(1);
|
||||
lovrGraphicsSetPointSize(1);
|
||||
lovrGraphicsSetShader(NULL);
|
||||
lovrGraphicsSetStencilTest(COMPARE_NONE, 0);
|
||||
lovrGraphicsSetWinding(WINDING_COUNTERCLOCKWISE);
|
||||
lovrGraphicsSetWireframe(false);
|
||||
lovrGraphicsSetViewport(0, 0, w, h);
|
||||
|
@ -351,8 +352,8 @@ CompareMode lovrGraphicsGetDepthTest() {
|
|||
void lovrGraphicsSetDepthTest(CompareMode depthTest) {
|
||||
if (state.depthTest != depthTest) {
|
||||
state.depthTest = depthTest;
|
||||
glDepthFunc(depthTest);
|
||||
if (depthTest) {
|
||||
if (depthTest != COMPARE_NONE) {
|
||||
glDepthFunc(depthTest);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
} else {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
@ -444,6 +445,35 @@ void lovrGraphicsSetShader(Shader* shader) {
|
|||
}
|
||||
}
|
||||
|
||||
void lovrGraphicsGetStencilTest(CompareMode* mode, int* value) {
|
||||
*mode = state.stencilMode;
|
||||
*value = state.stencilValue;
|
||||
}
|
||||
|
||||
void lovrGraphicsSetStencilTest(CompareMode mode, int value) {
|
||||
if (mode != state.stencilMode || value != state.stencilValue) {
|
||||
state.stencilMode = mode;
|
||||
state.stencilValue = value;
|
||||
if (mode != COMPARE_NONE) {
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
|
||||
GLenum glMode = mode;
|
||||
switch (mode) {
|
||||
case COMPARE_LESS: glMode = GL_GREATER; break;
|
||||
case COMPARE_LEQUAL: glMode = GL_GEQUAL; break;
|
||||
case COMPARE_GEQUAL: glMode = GL_LEQUAL; break;
|
||||
case COMPARE_GREATER: glMode = GL_LESS; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
glStencilFunc(glMode, value, 0xff);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
} else {
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Winding lovrGraphicsGetWinding() {
|
||||
return state.winding;
|
||||
}
|
||||
|
|
|
@ -103,6 +103,8 @@ typedef struct {
|
|||
float lineWidth;
|
||||
float pointSize;
|
||||
Shader* shader;
|
||||
CompareMode stencilMode;
|
||||
int stencilValue;
|
||||
Winding winding;
|
||||
bool wireframe;
|
||||
uint32_t streamVAO;
|
||||
|
@ -156,6 +158,8 @@ float lovrGraphicsGetPointSize();
|
|||
void lovrGraphicsSetPointSize(float size);
|
||||
Shader* lovrGraphicsGetShader();
|
||||
void lovrGraphicsSetShader(Shader* shader);
|
||||
void lovrGraphicsGetStencilTest(CompareMode* mode, int* value);
|
||||
void lovrGraphicsSetStencilTest(CompareMode mode, int value);
|
||||
Winding lovrGraphicsGetWinding();
|
||||
void lovrGraphicsSetWinding(Winding winding);
|
||||
bool lovrGraphicsIsWireframe();
|
||||
|
|
Loading…
Reference in New Issue