grow ExtrusionLayer compiler buffer if necessary

This commit is contained in:
Hannes Janetzek 2013-03-09 16:30:56 +01:00
parent e05921efdd
commit 65e4845fef
2 changed files with 12 additions and 4 deletions

View File

@ -37,7 +37,6 @@ import android.util.Log;
public class ExtrusionLayer extends Layer {
private final static String TAG = ExtrusionLayer.class.getName();
private static final float S = GLRenderer.COORD_SCALE;
private int mNumVertices = 0;
private final VertexPoolItem mVertices;
private VertexPoolItem mCurVertices;
private final VertexPoolItem mIndices[], mCurIndices[];
@ -47,6 +46,7 @@ public class ExtrusionLayer extends Layer {
// 0. even sides, 1. odd sides, 2. roof, 3. roof outline
public int mIndiceCnt[] = { 0, 0, 0, 0 };
public int mNumIndices = 0;
public int mNumVertices = 0;
public int mIndicesBufferID;
public int mVertexBufferID;
@ -341,7 +341,6 @@ public class ExtrusionLayer extends Layer {
}
mCurVertices.used = v;
mNumVertices += vertexCnt;
return convex;
}

View File

@ -55,7 +55,7 @@ public class ExtrusionOverlay extends RenderOverlay {
private boolean initialized = false;
// FIXME sum up size used while filling layer only up to:
private final int BUFFERSIZE = 65536 * 2;
public int mBufferSize = 65536;
private TileSet mTileSet;
private ShortBuffer mShortBuffer;
private MapTile[] mTiles;
@ -86,7 +86,7 @@ public class ExtrusionOverlay extends RenderOverlay {
hLightPosition[i] = GLES20.glGetAttribLocation(shaderProgram[i], "a_light");
}
ByteBuffer buf = ByteBuffer.allocateDirect(BUFFERSIZE)
ByteBuffer buf = ByteBuffer.allocateDirect(mBufferSize)
.order(ByteOrder.nativeOrder());
mShortBuffer = buf.asShortBuffer();
@ -116,6 +116,15 @@ public class ExtrusionOverlay extends RenderOverlay {
continue;
if (!el.compiled) {
int verticesBytes = el.mNumVertices * 8 * 2;
if (verticesBytes > mBufferSize) {
mBufferSize = verticesBytes;
Log.d(TAG, "realloc extrusion buffer " + verticesBytes);
ByteBuffer buf = ByteBuffer.allocateDirect(verticesBytes)
.order(ByteOrder.nativeOrder());
mShortBuffer = buf.asShortBuffer();
}
el.compile(mShortBuffer);
GlUtils.checkGlError("...");
}