use same quad indices in Texture- and LineTexRenderer
This commit is contained in:
parent
2538ed8eb7
commit
b0c02e0c56
@ -74,8 +74,8 @@ public class GLRenderer implements GLSurfaceView.Renderer {
|
||||
// bytes currently loaded in VBOs
|
||||
private static int mBufferMemoryUsage;
|
||||
|
||||
private static float[] mTileCoords = new float[8];
|
||||
//private static float[] mDebugCoords = new float[8];
|
||||
private static float[] mTileCoords;
|
||||
//private static float[] mDebugCoords;
|
||||
|
||||
public class Matrices {
|
||||
public final Matrix4 viewproj = new Matrix4();
|
||||
@ -90,6 +90,10 @@ public class GLRenderer implements GLSurfaceView.Renderer {
|
||||
|
||||
//private
|
||||
static float[] mClearColor = null;
|
||||
|
||||
static int mQuadIndicesID;
|
||||
final static int maxQuads = 64;
|
||||
|
||||
private static boolean mUpdateColor = false;
|
||||
|
||||
// drawlock to synchronize Main- and GL-Thread
|
||||
@ -181,7 +185,9 @@ public class GLRenderer implements GLSurfaceView.Renderer {
|
||||
mMapPosition = new MapPosition();
|
||||
|
||||
mMatrices = new Matrices();
|
||||
mTileCoords = new float[8];
|
||||
|
||||
// tile fill coords
|
||||
short min = 0;
|
||||
short max = (short) ((Tile.TILE_SIZE * COORD_SCALE));
|
||||
mFillCoords = new short[8];
|
||||
@ -193,12 +199,6 @@ public class GLRenderer implements GLSurfaceView.Renderer {
|
||||
mFillCoords[5] = min;
|
||||
mFillCoords[6] = max;
|
||||
mFillCoords[7] = min;
|
||||
|
||||
ByteBuffer bbuf = ByteBuffer.allocateDirect(MB >> 2)
|
||||
.order(ByteOrder.nativeOrder());
|
||||
|
||||
shortBuffer = bbuf.asShortBuffer();
|
||||
shortBuffer.put(mFillCoords, 0, 8);
|
||||
}
|
||||
|
||||
public static void setRenderTheme(RenderTheme t) {
|
||||
@ -606,8 +606,38 @@ public class GLRenderer implements GLSurfaceView.Renderer {
|
||||
mMapView.redrawMap(false);
|
||||
return;
|
||||
}
|
||||
|
||||
mNewSurface = false;
|
||||
|
||||
ByteBuffer bbuf = ByteBuffer.allocateDirect(MB >> 2)
|
||||
.order(ByteOrder.nativeOrder());
|
||||
shortBuffer = bbuf.asShortBuffer();
|
||||
|
||||
// upload quad indices used by Texture- and LineTexRenderer
|
||||
int[] vboIds = new int[1];
|
||||
GLES20.glGenBuffers(1, vboIds, 0);
|
||||
mQuadIndicesID = vboIds[0];
|
||||
int maxIndices = maxQuads * 6;
|
||||
short[] indices = new short[maxIndices];
|
||||
for (int i = 0, j = 0; i < maxIndices; i += 6, j += 4) {
|
||||
indices[i + 0] = (short) (j + 0);
|
||||
indices[i + 1] = (short) (j + 1);
|
||||
indices[i + 2] = (short) (j + 2);
|
||||
|
||||
indices[i + 3] = (short) (j + 2);
|
||||
indices[i + 4] = (short) (j + 1);
|
||||
indices[i + 5] = (short) (j + 3);
|
||||
}
|
||||
|
||||
shortBuffer.put(indices);
|
||||
shortBuffer.flip();
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER,
|
||||
mQuadIndicesID);
|
||||
GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER,
|
||||
indices.length * 2, shortBuffer, GLES20.GL_STATIC_DRAW);
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
|
||||
mBufferMemoryUsage = 0;
|
||||
mDrawTiles = null;
|
||||
|
||||
|
||||
@ -16,7 +16,6 @@ package org.oscim.renderer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.renderer.GLRenderer.Matrices;
|
||||
@ -52,14 +51,8 @@ public class LineTexRenderer {
|
||||
private static int hPatternScale;
|
||||
private static int hPatternWidth;
|
||||
|
||||
private static int mIndicesBufferID;
|
||||
private static int mVertexFlipID;
|
||||
|
||||
// batch up up to 64 quads in one draw call
|
||||
private static int maxQuads = 64;
|
||||
private static int maxIndices = maxQuads * 6;
|
||||
//private static int[] mTexID;
|
||||
|
||||
public static void init() {
|
||||
shader = GlUtils.createProgram(vertexShader, fragmentShader);
|
||||
if (shader == 0) {
|
||||
@ -81,40 +74,18 @@ public class LineTexRenderer {
|
||||
hVertexLength1 = GLES20.glGetAttribLocation(shader, "a_len1");
|
||||
hVertexFlip = GLES20.glGetAttribLocation(shader, "a_flip");
|
||||
|
||||
int[] mVboIds = new int[2];
|
||||
GLES20.glGenBuffers(2, mVboIds, 0);
|
||||
mIndicesBufferID = mVboIds[0];
|
||||
mVertexFlipID = mVboIds[1];
|
||||
|
||||
short[] indices = new short[maxIndices];
|
||||
for (int i = 0, j = 0; i < maxIndices; i += 6, j += 4) {
|
||||
indices[i + 0] = (short) (j + 0);
|
||||
indices[i + 1] = (short) (j + 1);
|
||||
indices[i + 2] = (short) (j + 2);
|
||||
|
||||
indices[i + 3] = (short) (j + 2);
|
||||
indices[i + 4] = (short) (j + 1);
|
||||
indices[i + 5] = (short) (j + 3);
|
||||
}
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(maxIndices * 2)
|
||||
.order(ByteOrder.nativeOrder());
|
||||
|
||||
ShortBuffer sbuf = buf.asShortBuffer();
|
||||
sbuf.put(indices);
|
||||
sbuf.flip();
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER,
|
||||
mIndicesBufferID);
|
||||
GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER,
|
||||
indices.length * 2, sbuf, GLES20.GL_STATIC_DRAW);
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
int[] vboIds = new int[1];
|
||||
GLES20.glGenBuffers(1, vboIds, 0);
|
||||
mVertexFlipID = vboIds[0];
|
||||
|
||||
// 0, 1, 0, 1, 0, ...
|
||||
byte[] flip = new byte[maxQuads * 4];
|
||||
byte[] flip = new byte[GLRenderer.maxQuads * 4];
|
||||
for (int i = 0; i < flip.length; i++)
|
||||
flip[i] = (byte) (i % 2);
|
||||
|
||||
buf.clear();
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(flip.length)
|
||||
.order(ByteOrder.nativeOrder());
|
||||
|
||||
buf.put(flip);
|
||||
buf.flip();
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVertexFlipID);
|
||||
@ -122,6 +93,7 @@ public class LineTexRenderer {
|
||||
GLES20.GL_STATIC_DRAW);
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
|
||||
// mTexID = new int[10];
|
||||
// byte[] stipple = new byte[2];
|
||||
// stipple[0] = 32;
|
||||
@ -146,11 +118,11 @@ public class LineTexRenderer {
|
||||
GLES20.glEnableVertexAttribArray(hVertexLength1);
|
||||
GLES20.glEnableVertexAttribArray(hVertexFlip);
|
||||
|
||||
//GLES20.glUniformMatrix4fv(hMatrix, 1, false, matrix, 0);
|
||||
m.mvp.setAsUniform(hMatrix);
|
||||
|
||||
int maxIndices = GLRenderer.maxQuads * 6;
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER,
|
||||
mIndicesBufferID);
|
||||
GLRenderer.mQuadIndicesID);
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVertexFlipID);
|
||||
GLES20.glVertexAttribPointer(hVertexFlip, 1,
|
||||
|
||||
@ -15,10 +15,6 @@
|
||||
|
||||
package org.oscim.renderer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
import org.oscim.renderer.GLRenderer.Matrices;
|
||||
import org.oscim.renderer.layer.Layer;
|
||||
import org.oscim.renderer.layer.TextureLayer;
|
||||
@ -39,13 +35,10 @@ public final class TextureRenderer {
|
||||
private static int hTextureScale;
|
||||
private static int hTextureScreenScale;
|
||||
private static int hTextureTexCoord;
|
||||
private static int mIndicesVBO;
|
||||
|
||||
public final static int INDICES_PER_SPRITE = 6;
|
||||
final static int VERTICES_PER_SPRITE = 4;
|
||||
final static int SHORTS_PER_VERTICE = 6;
|
||||
// per texture
|
||||
private final static int MAX_ITEMS = 50;
|
||||
|
||||
static void init() {
|
||||
mTextureProgram = GlUtils.createProgram(textVertexShader,
|
||||
@ -57,40 +50,6 @@ public final class TextureRenderer {
|
||||
hTextureScreenScale = GLES20.glGetUniformLocation(mTextureProgram, "u_swidth");
|
||||
hTextureVertex = GLES20.glGetAttribLocation(mTextureProgram, "vertex");
|
||||
hTextureTexCoord = GLES20.glGetAttribLocation(mTextureProgram, "tex_coord");
|
||||
|
||||
int bufferSize = MAX_ITEMS * VERTICES_PER_SPRITE
|
||||
* SHORTS_PER_VERTICE * (Short.SIZE / 8);
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(bufferSize)
|
||||
.order(ByteOrder.nativeOrder());
|
||||
|
||||
ShortBuffer mShortBuffer = buf.asShortBuffer();
|
||||
|
||||
// Setup triangle indices
|
||||
short[] indices = new short[MAX_ITEMS * INDICES_PER_SPRITE];
|
||||
int len = indices.length;
|
||||
short j = 0;
|
||||
for (int i = 0; i < len; i += INDICES_PER_SPRITE, j += VERTICES_PER_SPRITE) {
|
||||
indices[i + 0] = (short) (j + 0);
|
||||
indices[i + 1] = (short) (j + 1);
|
||||
indices[i + 2] = (short) (j + 2);
|
||||
indices[i + 3] = (short) (j + 2);
|
||||
indices[i + 4] = (short) (j + 3);
|
||||
indices[i + 5] = (short) (j + 0);
|
||||
}
|
||||
|
||||
mShortBuffer.clear();
|
||||
mShortBuffer.put(indices, 0, len);
|
||||
mShortBuffer.flip();
|
||||
|
||||
int[] mVboIds = new int[1];
|
||||
GLES20.glGenBuffers(1, mVboIds, 0);
|
||||
mIndicesVBO = mVboIds[0];
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, mIndicesVBO);
|
||||
GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, len * (Short.SIZE / 8),
|
||||
mShortBuffer, GLES20.GL_STATIC_DRAW);
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
public static Layer draw(Layer layer, float scale, Matrices m) {
|
||||
@ -113,16 +72,14 @@ public final class TextureRenderer {
|
||||
m.proj.setAsUniform(hTextureProjMatrix);
|
||||
m.mvp.setAsUniform(hTextureMVMatrix);
|
||||
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, mIndicesVBO);
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, GLRenderer.mQuadIndicesID);
|
||||
|
||||
for (TextureObject to = tl.textures; to != null; to = to.next) {
|
||||
//if (TextureRenderer.debug)
|
||||
// Log.d("...", "draw texture: " + to.id + " " + to.offset + " " + to.vertices);
|
||||
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, to.id);
|
||||
int maxVertices = MAX_ITEMS * INDICES_PER_SPRITE;
|
||||
int maxVertices = GLRenderer.maxQuads * INDICES_PER_SPRITE;
|
||||
|
||||
// can only draw MAX_ITEMS in each iteration
|
||||
// draw up to maxVertices in each iteration
|
||||
for (int i = 0; i < to.vertices; i += maxVertices) {
|
||||
// to.offset * (24(shorts) * 2(short-bytes) / 6(indices) == 8)
|
||||
int off = (to.offset + i) * 8 + tl.offset;
|
||||
|
||||
@ -33,8 +33,8 @@ public final class SymbolLayer extends TextureLayer {
|
||||
|
||||
SymbolItem symbols;
|
||||
|
||||
private Canvas mCanvas;
|
||||
private Rect mRect = new Rect();
|
||||
private final Canvas mCanvas;
|
||||
private final Rect mRect = new Rect();
|
||||
|
||||
public SymbolLayer() {
|
||||
type = Layer.SYMBOL;
|
||||
@ -210,6 +210,13 @@ public final class SymbolLayer extends TextureLayer {
|
||||
buf[pos++] = y1;
|
||||
buf[pos++] = u1;
|
||||
buf[pos++] = v2;
|
||||
// bot-left
|
||||
buf[pos++] = tx;
|
||||
buf[pos++] = ty;
|
||||
buf[pos++] = x1;
|
||||
buf[pos++] = y2;
|
||||
buf[pos++] = u1;
|
||||
buf[pos++] = v1;
|
||||
// top-right
|
||||
buf[pos++] = tx;
|
||||
buf[pos++] = ty;
|
||||
@ -224,13 +231,6 @@ public final class SymbolLayer extends TextureLayer {
|
||||
buf[pos++] = y2;
|
||||
buf[pos++] = u2;
|
||||
buf[pos++] = v1;
|
||||
// bot-left
|
||||
buf[pos++] = tx;
|
||||
buf[pos++] = ty;
|
||||
buf[pos++] = x1;
|
||||
buf[pos++] = y2;
|
||||
buf[pos++] = u1;
|
||||
buf[pos++] = v1;
|
||||
|
||||
// six elements used to draw the four vertices
|
||||
curIndices += TextureRenderer.INDICES_PER_SPRITE;
|
||||
|
||||
@ -246,6 +246,13 @@ public final class TextLayer extends TextureLayer {
|
||||
buf[pos++] = y1;
|
||||
buf[pos++] = u1;
|
||||
buf[pos++] = v2;
|
||||
// bot-left
|
||||
buf[pos++] = tx;
|
||||
buf[pos++] = ty;
|
||||
buf[pos++] = x3;
|
||||
buf[pos++] = y3;
|
||||
buf[pos++] = u1;
|
||||
buf[pos++] = v1;
|
||||
// top-right
|
||||
buf[pos++] = tx;
|
||||
buf[pos++] = ty;
|
||||
@ -260,13 +267,7 @@ public final class TextLayer extends TextureLayer {
|
||||
buf[pos++] = y4;
|
||||
buf[pos++] = u2;
|
||||
buf[pos++] = v1;
|
||||
// bot-left
|
||||
buf[pos++] = tx;
|
||||
buf[pos++] = ty;
|
||||
buf[pos++] = x3;
|
||||
buf[pos++] = y3;
|
||||
buf[pos++] = u1;
|
||||
buf[pos++] = v1;
|
||||
|
||||
|
||||
// six indices to draw the four vertices
|
||||
numIndices += TextureRenderer.INDICES_PER_SPRITE;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user