mirror of https://github.com/bjornbytes/lovr.git
Allow custom values when clearing color, depth, and stencil buffers;
This commit is contained in:
parent
c538474339
commit
3fd6f27768
|
@ -290,10 +290,44 @@ int l_lovrGraphicsReset(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_lovrGraphicsClear(lua_State* L) {
|
||||
bool color = lua_gettop(L) < 1 || lua_toboolean(L, 1);
|
||||
bool depth = lua_gettop(L) < 2 || lua_toboolean(L, 2);
|
||||
bool stencil = lua_gettop(L) < 3 || lua_toboolean(L, 3);
|
||||
lovrGraphicsClear(color, depth, stencil);
|
||||
int index = 1;
|
||||
int top = lua_gettop(L);
|
||||
|
||||
bool clearColor = true;
|
||||
bool clearDepth = true;
|
||||
bool clearStencil = true;
|
||||
Color color = lovrGraphicsGetBackgroundColor();
|
||||
float depth = 1.0;
|
||||
int stencil = 0;
|
||||
|
||||
if (top >= index) {
|
||||
if (lua_type(L, index) == LUA_TNUMBER) {
|
||||
color.r = luaL_checknumber(L, index++);
|
||||
color.g = luaL_checknumber(L, index++);
|
||||
color.b = luaL_checknumber(L, index++);
|
||||
color.a = luaL_optnumber(L, index++, 1.);
|
||||
} else {
|
||||
clearColor = lua_toboolean(L, index++);
|
||||
}
|
||||
}
|
||||
|
||||
if (top >= index) {
|
||||
if (lua_type(L, index) == LUA_TNUMBER) {
|
||||
depth = luaL_checknumber(L, index++);
|
||||
} else {
|
||||
clearDepth = lua_toboolean(L, index++);
|
||||
}
|
||||
}
|
||||
|
||||
if (top >= index) {
|
||||
if (lua_type(L, index) == LUA_TNUMBER) {
|
||||
stencil = luaL_checkinteger(L, index++);
|
||||
} else {
|
||||
clearStencil = lua_toboolean(L, index++);
|
||||
}
|
||||
}
|
||||
|
||||
lovrGraphicsClear(clearColor, clearDepth, clearStencil, color, depth, stencil);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -787,7 +821,8 @@ int l_lovrGraphicsStencil(lua_State* L) {
|
|||
int replaceValue = luaL_optinteger(L, 3, 1);
|
||||
bool keepValues = lua_toboolean(L, 4);
|
||||
if (!keepValues) {
|
||||
lovrGraphicsClear(false, false, true);
|
||||
int clearTo = lua_isnumber(L, 4) ? lua_tonumber(L, 4) : 0;
|
||||
lovrGraphicsClear(false, false, true, (Color) { 0, 0, 0, 0 }, 0, clearTo);
|
||||
}
|
||||
lua_settop(L, 1);
|
||||
lovrGraphicsStencil(action, replaceValue, stencilCallback, L);
|
||||
|
|
|
@ -78,7 +78,7 @@ Canvas* lovrCanvasCreate(int width, int height, TextureFormat format, CanvasType
|
|||
}
|
||||
|
||||
lovrAssert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE, "Error creating Canvas");
|
||||
lovrGraphicsClear(true, true, true);
|
||||
lovrGraphicsClear(true, true, true, (Color) { 0, 0, 0, 0 }, 1., 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
return canvas;
|
||||
|
|
|
@ -81,9 +81,19 @@ void lovrGraphicsReset() {
|
|||
lovrGraphicsOrigin();
|
||||
}
|
||||
|
||||
void lovrGraphicsClear(bool color, bool depth, bool stencil) {
|
||||
if (!color && !depth && !stencil) return;
|
||||
glClear((color ? GL_COLOR_BUFFER_BIT : 0) | (depth ? GL_DEPTH_BUFFER_BIT : 0) | (stencil ? GL_STENCIL_BUFFER_BIT : 0));
|
||||
void lovrGraphicsClear(bool clearColor, bool clearDepth, bool clearStencil, Color color, float depth, int stencil) {
|
||||
if (clearColor) {
|
||||
float c[4] = { color.r, color.g, color.b, color.a };
|
||||
glClearBufferfv(GL_COLOR, 0, c);
|
||||
}
|
||||
|
||||
if (clearDepth) {
|
||||
glClearBufferfv(GL_DEPTH, 0, &depth);
|
||||
}
|
||||
|
||||
if (clearStencil) {
|
||||
glClearBufferiv(GL_STENCIL, 0, &stencil);
|
||||
}
|
||||
}
|
||||
|
||||
void lovrGraphicsPresent() {
|
||||
|
|
|
@ -139,7 +139,7 @@ typedef struct {
|
|||
void lovrGraphicsInit();
|
||||
void lovrGraphicsDestroy();
|
||||
void lovrGraphicsReset();
|
||||
void lovrGraphicsClear(bool color, bool depth, bool stencil);
|
||||
void lovrGraphicsClear(bool clearColor, bool clearDepth, bool clearStencil, Color color, float depth, int stencil);
|
||||
void lovrGraphicsPresent();
|
||||
void lovrGraphicsPrepare(Material* material, float* pose);
|
||||
void lovrGraphicsCreateWindow(int w, int h, bool fullscreen, int msaa, const char* title, const char* icon);
|
||||
|
|
|
@ -348,7 +348,7 @@ static void fakeRenderTo(headsetRenderCallback callback, void* userdata) {
|
|||
lovrGraphicsMatrixTransform(MATRIX_VIEW, inv);
|
||||
|
||||
lovrGraphicsSetProjection(state.projection);
|
||||
lovrGraphicsClear(true, true, true);
|
||||
lovrGraphicsClear(true, true, true, lovrGraphicsGetBackgroundColor(), 1., 0);
|
||||
callback(EYE_LEFT, userdata);
|
||||
lovrGraphicsPop();
|
||||
}
|
||||
|
|
|
@ -756,7 +756,7 @@ static void openvrRenderTo(headsetRenderCallback callback, void* userdata) {
|
|||
lovrGraphicsPush();
|
||||
lovrGraphicsMatrixTransform(MATRIX_VIEW, transform);
|
||||
lovrGraphicsSetProjection(projection);
|
||||
lovrGraphicsClear(true, true, false);
|
||||
lovrGraphicsClear(true, true, false, (Color) { 0, 0, 0, 0 }, 1., 0);
|
||||
callback(eye, userdata);
|
||||
lovrGraphicsPop();
|
||||
lovrCanvasResolveMSAA(state.canvas);
|
||||
|
|
Loading…
Reference in New Issue