diff --git a/vtm/src/org/oscim/renderer/MapRenderer.java b/vtm/src/org/oscim/renderer/MapRenderer.java index ea96e375..17373c2d 100644 --- a/vtm/src/org/oscim/renderer/MapRenderer.java +++ b/vtm/src/org/oscim/renderer/MapRenderer.java @@ -25,7 +25,6 @@ import org.oscim.backend.GLAdapter; import org.oscim.backend.canvas.Color; import org.oscim.map.Map; import org.oscim.renderer.bucket.RenderBuckets; -import org.oscim.renderer.bucket.TextureBucket; import org.oscim.renderer.bucket.TextureItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,7 +44,11 @@ public class MapRenderer { private static int mQuadIndicesID; private static int mQuadVerticesID; - public final static int maxQuads = 512; + + /** Number of Quads that can be rendered with bindQuadIndicesVBO() */ + public final static int MAX_QUADS = 512; + /** Number of Indices that can be rendered with bindQuadIndicesVBO() */ + public final static int MAX_INDICES = MAX_QUADS * 6; public static long frametime; private static boolean rerender; @@ -168,9 +171,9 @@ public class MapRenderer { int[] vboIds = GLUtils.glGenBuffers(2); mQuadIndicesID = vboIds[0]; - int maxIndices = maxQuads * TextureBucket.INDICES_PER_SPRITE; - short[] indices = new short[maxIndices]; - for (int i = 0, j = 0; i < maxIndices; i += 6, j += 4) { + + short[] indices = new short[MAX_INDICES]; + for (int i = 0, j = 0; i < MAX_INDICES; i += 6, j += 4) { indices[i + 0] = (short) (j + 0); indices[i + 1] = (short) (j + 1); indices[i + 2] = (short) (j + 2); @@ -253,14 +256,12 @@ public class MapRenderer { } /** - * Bind indices for rendering up to MapRenderer.maxQuads (512) in - * one draw call. Vertex order is 0-1-2 2-1-3 - * - * @param bind - true to activate, false to unbind (dont forget!) - * */ - public static void bindQuadIndicesVBO(boolean bind) { - GLState.bindElementBuffer(bind ? mQuadIndicesID : 0); - + * Bind indices for rendering up to MAX_QUADS (512), + * ie. MAX_INDICES (512*6) in one draw call. + * Vertex order is 0-1-2 2-1-3 + */ + public static void bindQuadIndicesVBO() { + GLState.bindElementBuffer(mQuadIndicesID); } /** diff --git a/vtm/src/org/oscim/renderer/bucket/BitmapBucket.java b/vtm/src/org/oscim/renderer/bucket/BitmapBucket.java index 32136bfb..ee5b5541 100644 --- a/vtm/src/org/oscim/renderer/bucket/BitmapBucket.java +++ b/vtm/src/org/oscim/renderer/bucket/BitmapBucket.java @@ -19,6 +19,8 @@ package org.oscim.renderer.bucket; import static org.oscim.backend.GL20.GL_SHORT; import static org.oscim.backend.GL20.GL_TRIANGLES; import static org.oscim.backend.GL20.GL_UNSIGNED_SHORT; +import static org.oscim.renderer.MapRenderer.MAX_INDICES; +import static org.oscim.renderer.MapRenderer.bindQuadIndicesVBO; import java.nio.ShortBuffer; @@ -207,17 +209,14 @@ public class BitmapBucket extends TextureBucket { GL.glUniform1f(s.uAlpha, alpha); v.mvp.setAsUniform(s.uMVP); - MapRenderer.bindQuadIndicesVBO(true); + bindQuadIndicesVBO(); for (TextureItem t = tb.textures; t != null; t = t.next) { - t.bind(); - int maxIndices = MapRenderer.maxQuads * INDICES_PER_SPRITE; - - // draw up to maxVertices in each iteration */ - for (int i = 0; i < t.indices; i += maxIndices) { - // to.offset * (24(shorts) * 2(short-bytes) / 6(indices) == 8) + for (int i = 0; i < t.indices; i += MAX_INDICES) { + /* to.offset * (24(shorts) * + * 2(short-bytes) / 6(indices) == 8) */ int off = (t.offset + i) * 8 + tb.vertexOffset; GL.glVertexAttribPointer(s.aPos, 2, @@ -227,16 +226,14 @@ public class BitmapBucket extends TextureBucket { GL_SHORT, false, 12, off + 8); int numIndices = t.indices - i; - if (numIndices > maxIndices) - numIndices = maxIndices; + if (numIndices > MAX_INDICES) + numIndices = MAX_INDICES; GL.glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, 0); } } - MapRenderer.bindQuadIndicesVBO(false); - return b.next; } } diff --git a/vtm/src/org/oscim/renderer/bucket/LineTexBucket.java b/vtm/src/org/oscim/renderer/bucket/LineTexBucket.java index 00a74c58..0c6b8e68 100644 --- a/vtm/src/org/oscim/renderer/bucket/LineTexBucket.java +++ b/vtm/src/org/oscim/renderer/bucket/LineTexBucket.java @@ -16,6 +16,9 @@ */ package org.oscim.renderer.bucket; +import static org.oscim.renderer.MapRenderer.MAX_INDICES; +import static org.oscim.renderer.MapRenderer.bindQuadIndicesVBO; + import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.ShortBuffer; @@ -273,7 +276,7 @@ public final class LineTexBucket extends RenderBucket { mVertexFlipID = vboIds[0]; /* bytes: 0, 1, 0, 1, 0, ... */ - byte[] flip = new byte[MapRenderer.maxQuads * 4]; + byte[] flip = new byte[MapRenderer.MAX_QUADS * 4]; for (int i = 0; i < flip.length; i++) flip[i] = (byte) (i % 2); @@ -326,9 +329,7 @@ public final class LineTexBucket extends RenderBucket { v.mvp.setAsUniform(shader.uMVP); - int maxIndices = MapRenderer.maxQuads * 6; - - MapRenderer.bindQuadIndicesVBO(true); + bindQuadIndicesVBO(); GLState.bindVertexBuffer(mVertexFlipID); GL.glVertexAttribPointer(shader.aFlip, 1, @@ -368,10 +369,10 @@ public final class LineTexBucket extends RenderBucket { // TODO interleave 1. and 2. pass to improve vertex cache usage? /* first pass */ int allIndices = (lb.evenQuads * 6); - for (int i = 0; i < allIndices; i += maxIndices) { + for (int i = 0; i < allIndices; i += MAX_INDICES) { int numIndices = allIndices - i; - if (numIndices > maxIndices) - numIndices = maxIndices; + if (numIndices > MAX_INDICES) + numIndices = MAX_INDICES; /* i / 6 * (24 shorts per block * 2 short bytes) */ int add = (b.vertexOffset + i * 8) + vOffset; @@ -394,10 +395,10 @@ public final class LineTexBucket extends RenderBucket { /* second pass */ allIndices = (lb.oddQuads * 6); - for (int i = 0; i < allIndices; i += maxIndices) { + for (int i = 0; i < allIndices; i += MAX_INDICES) { int numIndices = allIndices - i; - if (numIndices > maxIndices) - numIndices = maxIndices; + if (numIndices > MAX_INDICES) + numIndices = MAX_INDICES; /* i / 6 * (24 shorts per block * 2 short bytes) */ int add = (b.vertexOffset + i * 8) + vOffset; diff --git a/vtm/src/org/oscim/renderer/bucket/TextureBucket.java b/vtm/src/org/oscim/renderer/bucket/TextureBucket.java index 333c1fb7..1943c15e 100644 --- a/vtm/src/org/oscim/renderer/bucket/TextureBucket.java +++ b/vtm/src/org/oscim/renderer/bucket/TextureBucket.java @@ -20,6 +20,7 @@ import static org.oscim.backend.GL20.GL_SHORT; import static org.oscim.backend.GL20.GL_TRIANGLES; import static org.oscim.backend.GL20.GL_UNSIGNED_SHORT; import static org.oscim.renderer.MapRenderer.COORD_SCALE; +import static org.oscim.renderer.MapRenderer.MAX_INDICES; import java.nio.ShortBuffer; @@ -123,31 +124,28 @@ public class TextureBucket extends RenderBucket { v.proj.setAsUniform(shader.uProj); v.mvp.setAsUniform(shader.uMV); - MapRenderer.bindQuadIndicesVBO(true); + MapRenderer.bindQuadIndicesVBO(); for (TextureItem t = tb.textures; t != null; t = t.next) { GL.glUniform2f(shader.uTexSize, 1f / (t.width * COORD_SCALE), 1f / (t.height * COORD_SCALE)); t.bind(); - int maxIndices = MapRenderer.maxQuads * INDICES_PER_SPRITE; /* draw up to maxVertices in each iteration */ - for (int i = 0; i < t.indices; i += maxIndices) { + for (int i = 0; i < t.indices; i += MAX_INDICES) { /* to.offset * (24(shorts) * 2(short-bytes) * / 6(indices) == 8) */ int off = (t.offset + i) * 8 + tb.vertexOffset; int numIndices = t.indices - i; - if (numIndices > maxIndices) - numIndices = maxIndices; + if (numIndices > MAX_INDICES) + numIndices = MAX_INDICES; tb.render(off, numIndices); } } - MapRenderer.bindQuadIndicesVBO(false); - return b.next; } }