v0.4.2: added support for Vertex Buffer Objects

This commit is contained in:
Evan Debenham
2016-08-21 02:37:29 -04:00
committed by Evan Debenham
parent 02166c319b
commit 9663a47958
8 changed files with 220 additions and 44 deletions

View File

@@ -26,6 +26,7 @@ import java.nio.FloatBuffer;
import com.watabou.gltextures.SmartTexture;
import com.watabou.gltextures.TextureCache;
import com.watabou.glwrap.Quad;
import com.watabou.glwrap.Vertexbuffer;
import com.watabou.utils.Rect;
import android.graphics.RectF;
@@ -47,6 +48,7 @@ public class Tilemap extends Visual {
protected short[] bufferPositions;
protected short bufferLength;
protected FloatBuffer quads;
protected Vertexbuffer buffer;
public Rect updated;
@@ -96,7 +98,6 @@ public class Tilemap extends Visual {
float x2 = x1 + cellW;
int pos = i * mapWidth + updated.left;
quads.position( 16 * pos );
for (int j=updated.left; j < updated.right; j++) {
@@ -155,6 +156,15 @@ public class Tilemap extends Visual {
super.draw();
if (!updated.isEmpty()) {
updateVertices();
quads.limit(bufferLength*16);
if (buffer == null)
buffer = new Vertexbuffer(quads);
else
buffer.updateVertices(quads);
}
NoosaScript script = NoosaScript.get();
texture.bind();
@@ -164,17 +174,18 @@ public class Tilemap extends Visual {
rm, gm, bm, am,
ra, ga, ba, aa );
if (!updated.isEmpty()) {
quads.limit(quads.capacity());
updateVertices();
quads.limit(bufferLength);
}
script.camera( camera );
script.drawQuadSet( quads, bufferLength );
script.drawQuadSet( buffer, bufferLength, 0 );
}
@Override
public void destroy() {
super.destroy();
if (buffer != null)
buffer.delete();
}
protected boolean needsRender(int pos){
return true;
}