diff options
author | Sven Gothel <[email protected]> | 2011-04-22 06:03:44 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-04-22 06:03:44 +0200 |
commit | bf8a54b502f0fcd930e12a8bbda65f9538e8a2f7 (patch) | |
tree | 88ebdb21601f576674ca69fee8aaf5e6847b5fd7 /src/jogl/classes/com/jogamp/opengl/util/glsl | |
parent | d72745fa32a86a3820e5220643a01153e3f21fe7 (diff) |
GLArrayData API and impl. changes
+++
Remove GL parameter for
- createFixed(..)
- createGLSL(..)
validation at client/server array data happens at 1st enableBuffer() call,
no current context or profile required at creation time.
Added ShaderState for createGLSL(..) clarifying dependency to the ShaderState,
passing it down to the GLSLArrayHandler, which also removes the TLS GLContext.getCurrent() call.
+++
Partially reverted ab48dac3f4419ceac51fdf059f310f0f0499c4d7 factory methods:
removed added vboTarget parameter, since all createFixed and createGLSL are GL_ARRAY_BUFFER (VBO).
Adding createData(..) factory method in GLArrayDataServer allowing diff vbo targets,
ie GL_ELEMENT_ARRAY_BUFFER .. or none.
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/glsl')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java index 1ce39d557..f771ea019 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java @@ -28,56 +28,68 @@ package com.jogamp.opengl.util.glsl; -import javax.media.opengl.*; -import com.jogamp.opengl.util.*; -import java.nio.*; +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; public class GLSLArrayHandler implements GLArrayHandler { + private static final boolean DEBUG = ShaderState.DEBUG; private GLArrayDataEditable ad; + private ShaderState st; - public GLSLArrayHandler(GLArrayDataEditable ad) { + public GLSLArrayHandler(ShaderState st, GLArrayDataEditable ad) { + this.st = st; this.ad = ad; } - private final void passVertexAttribPointer(GL2ES2 gl, ShaderState st) { - st.glVertexAttribPointer(gl, ad); - } - public void enableBuffer(GL gl, boolean enable) { if(!gl.isGL2ES2()) { throw new GLException("GLSLArrayHandler expects a GL2ES2 implementation"); } GL2ES2 glsl = gl.getGL2ES2(); - ShaderState st = ShaderState.getCurrent(); - if(null==st) { - throw new GLException("No ShaderState current"); - } if(enable) { - st.glEnableVertexAttribArray(glsl, ad.getName()); + st.glEnableVertexAttribArray(glsl, ad); Buffer buffer = ad.getBuffer(); if(ad.isVBO()) { - // always bind and refresh the VBO mgr, - // in case more than one gl*Pointer objects are in use - glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); + // bind and refresh the VBO / vertex-attr only if necessary if(!ad.isVBOWritten()) { + if(DEBUG) { + System.err.println("XXX VA "+ad.getName()+" VBO write: "+ad.getVBOName()); + } + glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); if(null!=buffer) { - glsl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSize(), buffer, ad.getVBOUsage()); + glsl.glBufferData(ad.getVBOTarget(), ad.getByteSize(), buffer, ad.getVBOUsage()); } ad.setVBOWritten(true); + st.glVertexAttribPointer(glsl, ad); + } else { + // didn't experience a performance hit on this query .. + int[] qi = new int[1]; + glsl.glGetVertexAttribiv(ad.getLocation(), GL2ES2.GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, qi, 0); + if(ad.getVBOName() != qi[0]) { + if(DEBUG) { + System.err.println("XXX VA "+ad.getName()+" VBO rebind: "+qi[0]+" -> "+ad.getVBOName()); + } + glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); + st.glVertexAttribPointer(glsl, ad); + } } - passVertexAttribPointer(glsl, st); } else if(null!=buffer) { - passVertexAttribPointer(glsl, st); + st.glVertexAttribPointer(glsl, ad); ad.setVBOWritten(true); } } else { if(ad.isVBO()) { glsl.glBindBuffer(ad.getVBOTarget(), 0); } - st.glDisableVertexAttribArray(glsl, ad.getName()); + st.glDisableVertexAttribArray(glsl, ad); } } |