GLState: keep track of clear color

This commit is contained in:
Hannes Janetzek 2014-04-03 22:53:37 +02:00
parent 2833d0f5c2
commit 15023432cc
3 changed files with 17 additions and 13 deletions

View File

@ -30,6 +30,7 @@ public class GLState {
private static boolean depth = false; private static boolean depth = false;
private static boolean stencil = false; private static boolean stencil = false;
private static int shader; private static int shader;
private static float[] clearColor;
private static int currentTexId; private static int currentTexId;
@ -43,6 +44,7 @@ public class GLState {
stencil = false; stencil = false;
shader = -1; shader = -1;
currentTexId = -1; currentTexId = -1;
clearColor = null;
GL.glDisable(GL20.GL_STENCIL_TEST); GL.glDisable(GL20.GL_STENCIL_TEST);
GL.glDisable(GL20.GL_DEPTH_TEST); GL.glDisable(GL20.GL_DEPTH_TEST);
@ -131,4 +133,16 @@ public class GLState {
currentTexId = id; currentTexId = id;
} }
} }
public static void setClearColor(float[] color) {
if (clearColor != null &&
color[0] == clearColor[0] &&
color[1] == clearColor[1] &&
color[2] == clearColor[2] &&
color[3] == clearColor[3])
return;
clearColor = color;
GL.glClearColor(color[0], color[1], color[2], color[3]);
}
} }

View File

@ -50,8 +50,6 @@ public class MapRenderer {
private static int mQuadVerticesID; private static int mQuadVerticesID;
public final static int maxQuads = 64; public final static int maxQuads = 64;
private static boolean mUpdateColor;
public static long frametime; public static long frametime;
private static boolean rerender; private static boolean rerender;
@ -116,7 +114,6 @@ public class MapRenderer {
public static void setBackgroundColor(int color) { public static void setBackgroundColor(int color) {
mClearColor = GLUtils.colorToFloat(color); mClearColor = GLUtils.colorToFloat(color);
mUpdateColor = true;
} }
static class BufferItem extends Inlist<BufferItem> { static class BufferItem extends Inlist<BufferItem> {
@ -179,12 +176,7 @@ public class MapRenderer {
} }
private void draw() { private void draw() {
GLState.setClearColor(mClearColor);
//if (mUpdateColor) {
float cc[] = mClearColor;
GL.glClearColor(cc[0], cc[1], cc[2], cc[3]);
mUpdateColor = false;
//}
GL.glDepthMask(true); GL.glDepthMask(true);
GL.glStencilMask(0xFF); GL.glStencilMask(0xFF);
@ -307,9 +299,6 @@ public class MapRenderer {
quad.length * 4, floatBuffer, GL20.GL_STATIC_DRAW); quad.length * 4, floatBuffer, GL20.GL_STATIC_DRAW);
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0); GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
if (mClearColor != null)
mUpdateColor = true;
GLState.init(GL); GLState.init(GL);
mMap.updateMap(true); mMap.updateMap(true);

View File

@ -17,6 +17,7 @@ public class OffscreenRenderer extends LayerRenderer {
int texH = -1; int texH = -1;
boolean initialized; boolean initialized;
private float[] mClearColor = { 0, 0, 0, 0 };
private boolean useDepthTexture = false; private boolean useDepthTexture = false;
@ -160,7 +161,7 @@ public class OffscreenRenderer extends LayerRenderer {
GL.glBindFramebuffer(GL20.GL_FRAMEBUFFER, fb); GL.glBindFramebuffer(GL20.GL_FRAMEBUFFER, fb);
GL.glViewport(0, 0, texW, texH); GL.glViewport(0, 0, texW, texH);
GL.glDepthMask(true); GL.glDepthMask(true);
GL.glClearColor(0, 0, 0, 0); GLState.setClearColor(mClearColor);
GL.glClear(GL20.GL_DEPTH_BUFFER_BIT | GL20.GL_COLOR_BUFFER_BIT); GL.glClear(GL20.GL_DEPTH_BUFFER_BIT | GL20.GL_COLOR_BUFFER_BIT);
mRenderer.render(viewport); mRenderer.render(viewport);