mirror of https://github.com/bjornbytes/lovr.git
lovr.graphics.discard;
This commit is contained in:
parent
ee3d9cf235
commit
bfeb3d2d51
|
@ -635,6 +635,15 @@ static int l_lovrGraphicsClear(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrGraphicsDiscard(lua_State* L) {
|
||||
int top = lua_gettop(L);
|
||||
bool color = top >= 1 ? lua_toboolean(L, 1) : true;
|
||||
bool depth = top >= 2 ? lua_toboolean(L, 2) : true;
|
||||
bool stencil = top >= 3 ? lua_toboolean(L, 3) : true;
|
||||
lovrGraphicsDiscard(color, depth, stencil);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrGraphicsPoints(lua_State* L) {
|
||||
uint32_t count = luax_readvertices(L, 1);
|
||||
lovrGraphicsPoints(count);
|
||||
|
@ -1313,6 +1322,7 @@ static const luaL_Reg lovrGraphics[] = {
|
|||
|
||||
// Rendering
|
||||
{ "clear", l_lovrGraphicsClear },
|
||||
{ "discard", l_lovrGraphicsDiscard },
|
||||
{ "points", l_lovrGraphicsPoints },
|
||||
{ "line", l_lovrGraphicsLine },
|
||||
{ "triangle", l_lovrGraphicsTriangle },
|
||||
|
|
|
@ -398,6 +398,12 @@ void lovrGraphicsClear(Color* color, float* depth, int* stencil) {
|
|||
lovrGpuClear(canvas, color, depth, stencil);
|
||||
}
|
||||
|
||||
void lovrGraphicsDiscard(bool color, bool depth, bool stencil) {
|
||||
Pipeline* pipeline = &state.pipelines[state.pipeline];
|
||||
Canvas* canvas = pipeline->canvas ? pipeline->canvas : state.camera.canvas;
|
||||
lovrGpuDiscard(canvas, color, depth, stencil);
|
||||
}
|
||||
|
||||
void lovrGraphicsDraw(DrawCommand* draw) {
|
||||
Mesh* mesh = draw->mesh;
|
||||
if (!mesh) {
|
||||
|
|
|
@ -211,6 +211,7 @@ void lovrGraphicsSetProjection(mat4 projection);
|
|||
// Rendering
|
||||
VertexPointer lovrGraphicsGetVertexPointer(uint32_t capacity);
|
||||
void lovrGraphicsClear(Color* color, float* depth, int* stencil);
|
||||
void lovrGraphicsDiscard(bool color, bool depth, bool stencil);
|
||||
void lovrGraphicsDraw(DrawCommand* draw);
|
||||
void lovrGraphicsPoints(uint32_t count);
|
||||
void lovrGraphicsLine(uint32_t count);
|
||||
|
@ -237,6 +238,7 @@ void lovrGpuDestroy();
|
|||
void lovrGpuBindPipeline(Pipeline* pipeline);
|
||||
void lovrGpuSetViewports(float* viewports, int count);
|
||||
void lovrGpuClear(Canvas* canvas, Color* color, float* depth, int* stencil);
|
||||
void lovrGpuDiscard(Canvas* canvas, bool color, bool depth, bool stencil);
|
||||
void lovrGpuStencil(StencilAction action, int replaceValue, StencilCallback callback, void* userdata);
|
||||
void lovrGpuCompute(Shader* shader, int x, int y, int z);
|
||||
void lovrGpuPresent();
|
||||
|
|
|
@ -859,6 +859,32 @@ void lovrGpuClear(Canvas* canvas, Color* color, float* depth, int* stencil) {
|
|||
}
|
||||
}
|
||||
|
||||
void lovrGpuDiscard(Canvas* canvas, bool color, bool depth, bool stencil) {
|
||||
#if defined(EMSCRIPTEN) || defined(__ANDROID__)
|
||||
lovrCanvasBind(canvas, false);
|
||||
|
||||
GLenum attachments[MAX_CANVAS_ATTACHMENTS + 1] = { 0 };
|
||||
int count = 0;
|
||||
|
||||
if (color) {
|
||||
int n = canvas ? canvas->attachmentCount : 1;
|
||||
for (int i = 0; i < n; i++) {
|
||||
attachments[count++] = GL_COLOR_ATTACHMENT0 + i;
|
||||
}
|
||||
}
|
||||
|
||||
if (depth) {
|
||||
attachments[count++] = GL_DEPTH_ATTACHMENT;
|
||||
}
|
||||
|
||||
if (stencil) {
|
||||
attachments[count++] = GL_STENCIL_ATTACHMENT;
|
||||
}
|
||||
|
||||
glInvalidateFramebuffer(GL_FRAMEBUFFER, count, attachments);
|
||||
#endif
|
||||
}
|
||||
|
||||
void lovrGpuStencil(StencilAction action, int replaceValue, StencilCallback callback, void* userdata) {
|
||||
state.depthWrite = false;
|
||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
|
|
Loading…
Reference in New Issue