diff options
author | Sven Gothel <[email protected]> | 2011-08-22 16:38:45 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-08-22 16:38:45 +0200 |
commit | 87ff90fb03216737df70ff83246664b7fba2663e (patch) | |
tree | d62c0a3c95e2f1eabd9fa69a95c814c668c4ff15 /src/jogl/classes/jogamp/opengl/util/glsl | |
parent | 6602d8eb5af13dc317fff8e044db52c3388f99fa (diff) |
Fix regression of commit 6c346d98f04e2355210960fe9ffde47432f04d62, where VBO/attribute binding wasn't updated (VBO data written, shader change/switch attribute on same location) ; Optimized interleaved GLSL VBO binding, hence split up GLArrayHandler syncData/enableState
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/util/glsl')
3 files changed, 76 insertions, 22 deletions
diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandler.java b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandler.java index b4b7b5ace..d2fc52d5c 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandler.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandler.java @@ -32,7 +32,7 @@ import java.nio.Buffer; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLException; + import com.jogamp.opengl.util.GLArrayDataEditable; import com.jogamp.opengl.util.GLArrayHandler; import com.jogamp.opengl.util.glsl.ShaderState; @@ -54,12 +54,25 @@ public class GLSLArrayHandler implements GLArrayHandler { throw new UnsupportedOperationException(); } - public final void enableBuffer(GL gl, boolean enable) { - GL2ES2 glsl = gl.getGL2ES2(); + public final void syncData(GL gl, boolean enable) { + final GL2ES2 glsl = gl.getGL2ES2(); if(enable) { - Buffer buffer = ad.getBuffer(); - + final Buffer buffer = ad.getBuffer(); + /* + * This would be the non optimized code path: + * + if(ad.isVBO()) { + glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); + if(!ad.isVBOWritten()) { + if(null!=buffer) { + glsl.glBufferData(ad.getVBOTarget(), ad.getSizeInBytes(), buffer, ad.getVBOUsage()); + } + ad.setVBOWritten(true); + } + } + st.vertexAttribPointer(glsl, ad); + */ if(ad.isVBO()) { // bind and refresh the VBO / vertex-attr only if necessary if(!ad.isVBOWritten()) { @@ -69,8 +82,9 @@ public class GLSLArrayHandler implements GLArrayHandler { } ad.setVBOWritten(true); st.vertexAttribPointer(glsl, ad); - } else if(ad.getLocation() >= 0) { + } else if(st.getAttribLocation(glsl, ad) >= 0) { // didn't experience a performance hit on this query .. + // (using ShaderState's location query above to validate the location) final int[] qi = new int[1]; glsl.glGetVertexAttribiv(ad.getLocation(), GL2ES2.GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, qi, 0); if(ad.getVBOName() != qi[0]) { @@ -81,12 +95,18 @@ public class GLSLArrayHandler implements GLArrayHandler { } else if(null!=buffer) { st.vertexAttribPointer(glsl, ad); } + } else if(ad.isVBO()) { + glsl.glBindBuffer(ad.getVBOTarget(), 0); + } + } + + public final void enableState(GL gl, boolean enable) { + final GL2ES2 glsl = gl.getGL2ES2(); + + if(enable) { st.enableVertexAttribArray(glsl, ad); } else { st.disableVertexAttribArray(glsl, ad); - if(ad.isVBO()) { - glsl.glBindBuffer(ad.getVBOTarget(), 0); - } } } diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerFlat.java b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerFlat.java index 38379877f..5c4aa718c 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerFlat.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerFlat.java @@ -51,16 +51,20 @@ public class GLSLArrayHandlerFlat implements GLArrayHandler { throw new UnsupportedOperationException(); } - public final void enableBuffer(GL gl, boolean enable) { - GL2ES2 glsl = gl.getGL2ES2(); + public final void syncData(GL gl, boolean enable) { + if(enable) { + st.vertexAttribPointer(gl.getGL2ES2(), ad); + } + } + + public final void enableState(GL gl, boolean enable) { + final GL2ES2 glsl = gl.getGL2ES2(); if(enable) { - st.vertexAttribPointer(glsl, ad); st.enableVertexAttribArray(glsl, ad); } else { st.disableVertexAttribArray(glsl, ad); } - } - + } } diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerInterleaved.java b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerInterleaved.java index ba5814a09..c662c13d2 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerInterleaved.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerInterleaved.java @@ -60,21 +60,22 @@ public class GLSLArrayHandlerInterleaved implements GLArrayHandler { subArrays.add(handler); } - private final void enableSubBuffer(GL gl, boolean enable) { + private final void syncSubData(GL gl, boolean enable) { for(int i=0; i<subArrays.size(); i++) { - subArrays.get(i).enableBuffer(gl, enable); + subArrays.get(i).syncData(gl, enable); } } - public final void enableBuffer(GL gl, boolean enable) { + public final void syncData(GL gl, boolean enable) { GL2ES2 glsl = gl.getGL2ES2(); if(enable) { Buffer buffer = ad.getBuffer(); + /* + * This would be the non optimized code path: + * if(ad.isVBO()) { - // always bind and refresh the VBO mgr, - // in case more than one attributes are in use glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); if(!ad.isVBOWritten()) { if(null!=buffer) { @@ -83,13 +84,42 @@ public class GLSLArrayHandlerInterleaved implements GLArrayHandler { ad.setVBOWritten(true); } } - enableSubBuffer(gl, true); + syncSubData(gl, true); + */ + if(ad.isVBO()) { + // bind and refresh the VBO / vertex-attr only if necessary + if(!ad.isVBOWritten()) { + glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); + if(null!=buffer) { + glsl.glBufferData(ad.getVBOTarget(), ad.getSizeInBytes(), buffer, ad.getVBOUsage()); + } + ad.setVBOWritten(true); + syncSubData(gl, true); + } else if(st.getAttribLocation(glsl, ad) >= 0) { + // didn't experience a performance hit on this query .. + // (using ShaderState's location query above to validate the location) + final int[] qi = new int[1]; + glsl.glGetVertexAttribiv(ad.getLocation(), GL2ES2.GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, qi, 0); + if(ad.getVBOName() != qi[0]) { + glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); + syncSubData(gl, true); + } + } + } else if(null!=buffer) { + syncSubData(gl, true); + } } else { - enableSubBuffer(gl, false); + syncSubData(gl, false); if(ad.isVBO()) { glsl.glBindBuffer(ad.getVBOTarget(), 0); } - } + } + } + + public final void enableState(GL gl, boolean enable) { + for(int i=0; i<subArrays.size(); i++) { + subArrays.get(i).enableState(gl, enable); + } } } |