From 020a4207bb71094849267892e56b678c496a6423 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 16 Sep 2016 20:11:11 -0700 Subject: [PATCH] Improve lovr.graphics.clear; --- src/graphics/graphics.c | 14 ++++++++++++-- src/graphics/graphics.h | 2 +- src/lovr/graphics.c | 4 +++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 5b7ed53a..5af1ab50 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -24,8 +24,18 @@ void lovrGraphicsInit() { map_set(&BufferDrawModes, "fan", GL_TRIANGLE_FAN); } -void lovrGraphicsClear() { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +void lovrGraphicsClear(int color, int depth) { + int bits = 0; + + if (color) { + bits |= GL_COLOR_BUFFER_BIT; + } + + if (depth) { + bits |= GL_DEPTH_BUFFER_BIT; + } + + glClear(bits); } void lovrGraphicsPresent() { diff --git a/src/graphics/graphics.h b/src/graphics/graphics.h index bd41e198..1a557013 100644 --- a/src/graphics/graphics.h +++ b/src/graphics/graphics.h @@ -3,7 +3,7 @@ #include "shader.h" void lovrGraphicsInit(); -void lovrGraphicsClear(); +void lovrGraphicsClear(int color, int depth); void lovrGraphicsPresent(); void lovrGraphicsGetClearColor(float* r, float* g, float* b, float* a); void lovrGraphicsSetClearColor(float r, float g, float b, float a); diff --git a/src/lovr/graphics.c b/src/lovr/graphics.c index fac5256c..56186112 100644 --- a/src/lovr/graphics.c +++ b/src/lovr/graphics.c @@ -28,7 +28,9 @@ int l_lovrGraphicsInit(lua_State* L) { } int l_lovrGraphicsClear(lua_State* L) { - lovrGraphicsClear(); + int color = lua_gettop(L) < 1 || lua_toboolean(L, 1); + int depth = lua_gettop(L) < 2 || lua_toboolean(L, 2); + lovrGraphicsClear(color, depth); return 0; }