v0.4.2: vertex buffers now support selective updating
This commit is contained in:
parent
1461003683
commit
7a2e6c63c1
|
@ -30,7 +30,7 @@ public class Vertexbuffer {
|
|||
|
||||
private int id;
|
||||
private FloatBuffer vertices;
|
||||
private boolean needsUpdate;
|
||||
private int updateStart, updateEnd;
|
||||
|
||||
private static ArrayList<Vertexbuffer> buffers = new ArrayList<>();
|
||||
|
||||
|
@ -42,24 +42,49 @@ public class Vertexbuffer {
|
|||
this.vertices = vertices;
|
||||
buffers.add(this);
|
||||
|
||||
//forces an update so the GL data isn't blank
|
||||
needsUpdate = true;
|
||||
updateGLData();
|
||||
updateStart = 0;
|
||||
updateEnd = vertices.limit();
|
||||
}
|
||||
|
||||
//For flagging the buffer for a full update without changing anything
|
||||
public void updateVertices(){
|
||||
updateVertices(vertices);
|
||||
}
|
||||
|
||||
//For flagging an update with a full set of new data
|
||||
public void updateVertices( FloatBuffer vertices ){
|
||||
updateVertices(vertices, 0, vertices.limit());
|
||||
}
|
||||
|
||||
//For flagging an update with a subset of data changed
|
||||
public void updateVertices( FloatBuffer vertices, int start, int end){
|
||||
this.vertices = vertices;
|
||||
needsUpdate = true;
|
||||
|
||||
if (updateStart == -1)
|
||||
updateStart = start;
|
||||
else
|
||||
updateStart = Math.min(start, updateStart);
|
||||
|
||||
if (updateEnd == -1)
|
||||
updateEnd = end;
|
||||
else
|
||||
updateEnd = Math.max(end, updateEnd);
|
||||
}
|
||||
|
||||
public void updateGLData(){
|
||||
if (!needsUpdate) return;
|
||||
if (updateStart == -1) return;
|
||||
|
||||
vertices.position(0);
|
||||
vertices.position(updateStart);
|
||||
bind();
|
||||
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, (vertices.limit()*4), vertices, GLES20.GL_DYNAMIC_DRAW);
|
||||
|
||||
if (updateStart == 0 && updateEnd == vertices.limit()){
|
||||
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, vertices.limit()*4, vertices, GLES20.GL_DYNAMIC_DRAW);
|
||||
} else {
|
||||
GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, updateStart*4, (updateEnd - updateStart)*4, vertices);
|
||||
}
|
||||
|
||||
release();
|
||||
needsUpdate = false;
|
||||
updateStart = updateEnd = -1;
|
||||
}
|
||||
|
||||
public void bind(){
|
||||
|
@ -77,7 +102,7 @@ public class Vertexbuffer {
|
|||
|
||||
public static void refreshAllBuffers(){
|
||||
for (Vertexbuffer buf : buffers) {
|
||||
buf.needsUpdate = true;
|
||||
buf.updateVertices();
|
||||
buf.updateGLData();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user