GLState: State DISABLED = -1 (readability).

This commit is contained in:
Gustl22 2018-08-23 22:46:40 +02:00
parent f07de4c910
commit 63cd462109
17 changed files with 41 additions and 31 deletions

View File

@ -86,7 +86,7 @@ public class GdxSpriteBatchTest extends GdxMapApp {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT | (Gdx.graphics.getBufferFormat().coverageSampling ?
GL20.GL_COVERAGE_BUFFER_BIT_NV : 0));
GLState.enableVertexArrays(-1, -1);
GLState.enableVertexArrays(GLState.DISABLED, GLState.DISABLED);
gl.viewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
gl.frontFace(GL.CW);

View File

@ -104,9 +104,9 @@ public class GdxModelRenderer extends LayerRenderer {
// set state that is expected after modelBatch.end();
// modelBatch keeps track of its own state
GLState.enableVertexArrays(-1, -1);
GLState.bindTex2D(-1);
GLState.useProgram(-1);
GLState.enableVertexArrays(GLState.DISABLED, GLState.DISABLED);
GLState.bindTex2D(GLState.DISABLED);
GLState.useProgram(GLState.DISABLED);
GLState.test(false, false);
GLState.blend(false);

View File

@ -105,9 +105,9 @@ public class GdxRenderer3D extends LayerRenderer {
// set state that is expected after modelBatch.end();
// modelBatch keeps track of its own state
GLState.enableVertexArrays(-1, -1);
GLState.bindTex2D(-1);
GLState.useProgram(-1);
GLState.enableVertexArrays(GLState.DISABLED, GLState.DISABLED);
GLState.bindTex2D(GLState.DISABLED);
GLState.useProgram(GLState.DISABLED);
GLState.test(false, false);
GLState.blend(false);

View File

@ -95,9 +95,9 @@ public class GdxRenderer3D2 extends LayerRenderer {
// set state that is expected after modelBatch.end();
// modelBatch keeps track of its own state
GLState.enableVertexArrays(-1, -1);
GLState.bindTex2D(-1);
GLState.useProgram(-1);
GLState.enableVertexArrays(GLState.DISABLED, GLState.DISABLED);
GLState.bindTex2D(GLState.DISABLED);
GLState.useProgram(GLState.DISABLED);
GLState.test(false, false);
GLState.blend(false);

View File

@ -105,7 +105,7 @@ public class CustomRenderer extends LayerRenderer {
//mVertices.position(2);
//GL.vertexAttribPointer(hVertexPosition, 2, GL20.FLOAT, false, 4, mVertices);
GLState.enableVertexArrays(hVertexPosition, -1);
GLState.enableVertexArrays(hVertexPosition, GLState.DISABLED);
/* apply view and projection matrices */
// set mvp (tmp) matrix relative to mMapPosition

View File

@ -119,7 +119,7 @@ public class HexagonRenderTest extends GdxMapApp {
// set VBO vertex layout
gl.vertexAttribPointer(hVertexPosition, 2, GL.FLOAT, false, 0, 0);
GLState.enableVertexArrays(hVertexPosition, -1);
GLState.enableVertexArrays(hVertexPosition, GLState.DISABLED);
/* apply view and projection matrices */
// set mvp (tmp) matrix relative to mMapPosition

View File

@ -112,7 +112,7 @@ public abstract class ExtrusionRenderer extends LayerRenderer {
Shader s = mShader;
s.useProgram();
GLState.enableVertexArrays(s.aPos, -1);
GLState.enableVertexArrays(s.aPos, GLState.DISABLED);
/* only use face-culling when it's unlikely
* that one'moves through the building' */

View File

@ -1,6 +1,7 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 devemux86
* Copyright 2018 Gustl22
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -27,6 +28,8 @@ import static org.oscim.backend.GLAdapter.gl;
public class GLState {
static final Logger log = LoggerFactory.getLogger(GLState.class);
public final static int DISABLED = -1;
private final static boolean[] vertexArray = {false, false};
private static boolean blend = false;
private static boolean depth = false;
@ -44,10 +47,10 @@ public class GLState {
blend = false;
depth = false;
stencil = false;
shader = -1;
currentTexId = -1;
glVertexBuffer = -1;
glIndexBuffer = -1;
shader = DISABLED;
currentTexId = DISABLED;
glVertexBuffer = DISABLED;
glIndexBuffer = DISABLED;
clearColor = null;
gl.disable(GL.STENCIL_TEST);
@ -57,7 +60,7 @@ public class GLState {
public static boolean useProgram(int shaderProgram) {
if (shaderProgram < 0) {
shader = -1;
shader = DISABLED;
} else if (shaderProgram != shader) {
gl.useProgram(shaderProgram);
shader = shaderProgram;
@ -111,6 +114,13 @@ public class GLState {
}
}
/**
* Enable or disable vertex arrays.
* Valid values are
* -1: {@link #DISABLED},
* 0: enable first,
* 1: enable second.
*/
public static void enableVertexArrays(int va1, int va2) {
if (va1 > 1 || va2 > 1)
log.debug("FIXME: enableVertexArrays...");

View File

@ -225,7 +225,7 @@ public class LocationRenderer extends LayerRenderer {
GLState.blend(true);
GLState.test(false, false);
GLState.enableVertexArrays(hVertexPosition, -1);
GLState.enableVertexArrays(hVertexPosition, GLState.DISABLED);
MapRenderer.bindQuadVertexVBO(hVertexPosition/*, true*/);
float radius = CIRCLE_SIZE * mScale;

View File

@ -297,7 +297,7 @@ public class LocationTextureRenderer extends BucketRenderer {
GLState.blend(true);
GLState.test(false, false);
GLState.enableVertexArrays(hVertexPosition, -1);
GLState.enableVertexArrays(hVertexPosition, GLState.DISABLED);
MapRenderer.bindQuadVertexVBO(hVertexPosition/*, true*/);
float radius = 10;

View File

@ -117,10 +117,10 @@ public class MapRenderer {
GLState.test(false, false);
GLState.blend(false);
GLState.bindTex2D(-1);
GLState.useProgram(-1);
GLState.bindElementBuffer(-1);
GLState.bindVertexBuffer(-1);
GLState.bindTex2D(GLState.DISABLED);
GLState.useProgram(GLState.DISABLED);
GLState.bindElementBuffer(GLState.DISABLED);
GLState.bindVertexBuffer(GLState.DISABLED);
mViewport.setFrom(mMap);
@ -269,7 +269,7 @@ public class MapRenderer {
if (location >= 0) {
GLState.bindVertexBuffer(mQuadVerticesID);
GLState.enableVertexArrays(location, -1);
GLState.enableVertexArrays(location, GLState.DISABLED);
gl.vertexAttribPointer(location, 2, GL.FLOAT, false, 0, 0);
}
}

View File

@ -116,7 +116,7 @@ public class CircleBucket extends RenderBucket {
public void set(GLViewport v) {
useProgram();
GLState.enableVertexArrays(aPos, -1);
GLState.enableVertexArrays(aPos, GLState.DISABLED);
v.mvp.setAsUniform(uMVP);
}

View File

@ -118,7 +118,7 @@ public class HairLineBucket extends RenderBucket {
public void set(GLViewport v) {
useProgram();
GLState.enableVertexArrays(aPos, -1);
GLState.enableVertexArrays(aPos, GLState.DISABLED);
v.mvp.setAsUniform(uMVP);

View File

@ -523,7 +523,7 @@ public class LineBucket extends RenderBucket {
@Override
public boolean useProgram() {
if (super.useProgram()) {
GLState.enableVertexArrays(aPos, -1);
GLState.enableVertexArrays(aPos, GLState.DISABLED);
return true;
}
return false;

View File

@ -353,7 +353,7 @@ public final class LineTexBucket extends LineBucket {
GLState.blend(true);
shader.useProgram();
GLState.enableVertexArrays(-1, -1);
GLState.enableVertexArrays(GLState.DISABLED, GLState.DISABLED);
int aLen0 = shader.aLen0;
int aLen1 = shader.aLen1;

View File

@ -174,7 +174,7 @@ public class MeshBucket extends RenderBucket {
Shader s = shader;
s.useProgram();
GLState.enableVertexArrays(s.aPos, -1);
GLState.enableVertexArrays(s.aPos, GLState.DISABLED);
v.mvp.setAsUniform(s.uMVP);

View File

@ -273,7 +273,7 @@ public final class PolygonBucket extends RenderBucket {
private static Shader setShader(Shader shader, GLMatrix mvp, boolean first) {
if (shader.useProgram() || first) {
GLState.enableVertexArrays(shader.aPos, -1);
GLState.enableVertexArrays(shader.aPos, GLState.DISABLED);
gl.vertexAttribPointer(shader.aPos, 2,
GL.SHORT, false, 0, 0);