diff options
Diffstat (limited to 'src/jogl/classes/jogamp/opengl')
7 files changed, 122 insertions, 89 deletions
diff --git a/src/jogl/classes/jogamp/opengl/util/GLArrayHandler.java b/src/jogl/classes/jogamp/opengl/util/GLArrayHandler.java index 2049f9618..a6314a216 100644 --- a/src/jogl/classes/jogamp/opengl/util/GLArrayHandler.java +++ b/src/jogl/classes/jogamp/opengl/util/GLArrayHandler.java @@ -37,12 +37,28 @@ import javax.media.opengl.*; */ public interface GLArrayHandler { + + /** + * if <code>bind</code> is true and the data uses VBO, + * the latter will be bound and data written to the GPU if required. + * <p> + * If <code>bind</code> is false and the data uses VBO, + * the latter will be unbound. + * </p> + * + * @param gl current GL object + * @param bind true if VBO shall be bound and data written, + * otherwise clear VBO binding. + * @return true if data uses VBO and action was performed, otherwise false + */ + public boolean bindBuffer(GL gl, boolean bind); + /** * Implementation shall enable or disable the array state. * <p> * Before enabling the array state, - * implementation shall associate the data with the array - * and synchronize the data with the GPU. + * implementation shall synchronize the data with the GPU + * and associate the data with the array. * </p> * * @param gl current GL object diff --git a/src/jogl/classes/jogamp/opengl/util/GLArrayHandlerInterleaved.java b/src/jogl/classes/jogamp/opengl/util/GLArrayHandlerInterleaved.java index ab916c329..98f711b8e 100644 --- a/src/jogl/classes/jogamp/opengl/util/GLArrayHandlerInterleaved.java +++ b/src/jogl/classes/jogamp/opengl/util/GLArrayHandlerInterleaved.java @@ -28,8 +28,6 @@ package jogamp.opengl.util; - -import java.nio.Buffer; import java.util.ArrayList; import java.util.List; @@ -41,12 +39,11 @@ import com.jogamp.opengl.util.GLArrayDataEditable; * Interleaved fixed function arrays, i.e. where this buffer data * represents many arrays. */ -public class GLArrayHandlerInterleaved implements GLArrayHandler { - private GLArrayDataEditable ad; +public class GLArrayHandlerInterleaved extends GLVBOArrayHandler implements GLArrayHandler { private List<GLArrayHandlerFlat> subArrays = new ArrayList<GLArrayHandlerFlat>(); public GLArrayHandlerInterleaved(GLArrayDataEditable ad) { - this.ad = ad; + super(ad); } public final void setSubArrayVBOName(int vboName) { @@ -67,24 +64,11 @@ public class GLArrayHandlerInterleaved implements GLArrayHandler { public final void enableState(GL gl, boolean enable, Object ext) { if(enable) { - final Buffer buffer = ad.getBuffer(); - final boolean vboBound = ad.isVBO(); - if(vboBound) { - // always bind and refresh the VBO mgr, - // in case more than one gl*Pointer objects are in use - gl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); - if(!ad.isVBOWritten()) { - if(null!=buffer) { - gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSizeInBytes(), buffer, ad.getVBOUsage()); - } - ad.setVBOWritten(true); - } - } + final boolean vboBound = bindBuffer(gl, true); syncSubData(gl, ext); if(vboBound) { - gl.glBindBuffer(ad.getVBOTarget(), 0); - } - + bindBuffer(gl, false); + } } for(int i=0; i<subArrays.size(); i++) { subArrays.get(i).enableState(gl, enable, ext); diff --git a/src/jogl/classes/jogamp/opengl/util/GLDataArrayHandler.java b/src/jogl/classes/jogamp/opengl/util/GLDataArrayHandler.java index 1e882e080..862d49d1d 100644 --- a/src/jogl/classes/jogamp/opengl/util/GLDataArrayHandler.java +++ b/src/jogl/classes/jogamp/opengl/util/GLDataArrayHandler.java @@ -28,21 +28,20 @@ package jogamp.opengl.util; -import javax.media.opengl.*; +import javax.media.opengl.GL; +import javax.media.opengl.GLException; -import com.jogamp.opengl.util.*; +import com.jogamp.opengl.util.GLArrayDataEditable; -import java.nio.*; /** * Used for pure VBO data arrays, i.e. where the buffer data * does not represents a specific array name. */ -public class GLDataArrayHandler implements GLArrayHandler { - private GLArrayDataEditable ad; +public class GLDataArrayHandler extends GLVBOArrayHandler implements GLArrayHandler { public GLDataArrayHandler(GLArrayDataEditable ad) { - this.ad = ad; + super(ad); } public final void setSubArrayVBOName(int vboName) { @@ -59,19 +58,8 @@ public class GLDataArrayHandler implements GLArrayHandler { // makes no sense otherwise throw new GLException("GLDataArrayHandler can only handle VBOs."); } - Buffer buffer = ad.getBuffer(); - - // always bind and refresh the VBO mgr, - // in case more than one gl*Pointer objects are in use - gl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); - if(!ad.isVBOWritten()) { - if(null!=buffer) { - gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSizeInBytes(), buffer, ad.getVBOUsage()); - } - ad.setVBOWritten(true); - } - gl.glBindBuffer(ad.getVBOTarget(), 0); - + bindBuffer(gl, true); + bindBuffer(gl, false); } // no array association } diff --git a/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandler.java b/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandler.java index 3ed41893a..32bba896f 100644 --- a/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandler.java +++ b/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandler.java @@ -28,22 +28,19 @@ package jogamp.opengl.util; -import javax.media.opengl.*; -import javax.media.opengl.fixedfunc.*; +import javax.media.opengl.GL; +import javax.media.opengl.GLException; +import javax.media.opengl.fixedfunc.GLPointerFunc; import com.jogamp.opengl.util.GLArrayDataEditable; -import java.nio.*; - /** * Used for 1:1 fixed function arrays, i.e. where the buffer data * represents this array only. */ -public class GLFixedArrayHandler implements GLArrayHandler { - private GLArrayDataEditable ad; - +public class GLFixedArrayHandler extends GLVBOArrayHandler implements GLArrayHandler { public GLFixedArrayHandler(GLArrayDataEditable ad) { - this.ad = ad; + super(ad); } public final void setSubArrayVBOName(int vboName) { @@ -57,19 +54,7 @@ public class GLFixedArrayHandler implements GLArrayHandler { public final void enableState(GL gl, boolean enable, Object ext) { final GLPointerFunc glp = gl.getGL2ES1(); if(enable) { - final Buffer buffer = ad.getBuffer(); - final boolean vboBound = ad.isVBO(); - if(vboBound) { - // always bind and refresh the VBO mgr, - // in case more than one gl*Pointer objects are in use - gl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); - if(!ad.isVBOWritten()) { - if(null!=buffer) { - gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSizeInBytes(), buffer, ad.getVBOUsage()); - } - ad.setVBOWritten(true); - } - } + final boolean vboBound = bindBuffer(gl, true); switch(ad.getIndex()) { case GLPointerFunc.GL_VERTEX_ARRAY: glp.glVertexPointer(ad); @@ -86,8 +71,9 @@ public class GLFixedArrayHandler implements GLArrayHandler { default: throw new GLException("invalid glArrayIndex: "+ad.getIndex()+":\n\t"+ad); } - gl.glBindBuffer(ad.getVBOTarget(), 0); - + if(vboBound) { + bindBuffer(gl, false); + } glp.glEnableClientState(ad.getIndex()); } else { glp.glDisableClientState(ad.getIndex()); diff --git a/src/jogl/classes/jogamp/opengl/util/GLVBOArrayHandler.java b/src/jogl/classes/jogamp/opengl/util/GLVBOArrayHandler.java new file mode 100644 index 000000000..ad88a7030 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/GLVBOArrayHandler.java @@ -0,0 +1,73 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.opengl.util; + + +import java.nio.Buffer; +import java.util.ArrayList; +import java.util.List; + +import javax.media.opengl.GL; + +import com.jogamp.opengl.util.GLArrayDataEditable; + +/** + * Interleaved fixed function arrays, i.e. where this buffer data + * represents many arrays. + */ +public abstract class GLVBOArrayHandler implements GLArrayHandler { + protected GLArrayDataEditable ad; + + public GLVBOArrayHandler(GLArrayDataEditable ad) { + this.ad = ad; + } + + public final boolean bindBuffer(GL gl, boolean bind) { + if( !ad.isVBO() ) { + return false; + } + if(bind) { + // always bind and refresh the VBO mgr, + // in case more than one gl*Pointer objects are in use + gl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); + if(!ad.isVBOWritten()) { + final Buffer buffer = ad.getBuffer(); + if(null!=buffer) { + gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSizeInBytes(), buffer, ad.getVBOUsage()); + } + ad.setVBOWritten(true); + } + } else { + gl.glBindBuffer(ad.getVBOTarget(), 0); + } + return true; + } + +} + diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandler.java b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandler.java index d7327a4e8..79bed90c9 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandler.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandler.java @@ -35,6 +35,7 @@ import javax.media.opengl.GL2ES2; import jogamp.opengl.util.GLArrayHandler; import jogamp.opengl.util.GLArrayHandlerFlat; +import jogamp.opengl.util.GLVBOArrayHandler; import com.jogamp.opengl.util.GLArrayDataEditable; import com.jogamp.opengl.util.glsl.ShaderState; @@ -43,11 +44,10 @@ import com.jogamp.opengl.util.glsl.ShaderState; * Used for 1:1 GLSL arrays, i.e. where the buffer data * represents this array only. */ -public class GLSLArrayHandler implements GLArrayHandler { - private GLArrayDataEditable ad; - +public class GLSLArrayHandler extends GLVBOArrayHandler implements GLArrayHandler { + public GLSLArrayHandler(GLArrayDataEditable ad) { - this.ad = ad; + super(ad); } public final void setSubArrayVBOName(int vboName) { @@ -63,7 +63,6 @@ public class GLSLArrayHandler implements GLArrayHandler { final ShaderState st = (ShaderState) ext; if(enable) { - final Buffer buffer = ad.getBuffer(); /* * This would be the non optimized code path: * @@ -78,6 +77,7 @@ public class GLSLArrayHandler implements GLArrayHandler { } st.vertexAttribPointer(glsl, ad); */ + final Buffer buffer = ad.getBuffer(); if(ad.isVBO()) { // bind and refresh the VBO / vertex-attr only if necessary if(!ad.isVBOWritten()) { @@ -108,6 +108,5 @@ public class GLSLArrayHandler implements GLArrayHandler { 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 6c80e31fa..f36693e19 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerInterleaved.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerInterleaved.java @@ -28,7 +28,6 @@ package jogamp.opengl.util.glsl; -import java.nio.Buffer; import java.util.ArrayList; import java.util.List; @@ -36,6 +35,7 @@ import javax.media.opengl.GL; import jogamp.opengl.util.GLArrayHandler; import jogamp.opengl.util.GLArrayHandlerFlat; +import jogamp.opengl.util.GLVBOArrayHandler; import com.jogamp.opengl.util.GLArrayDataEditable; @@ -43,12 +43,11 @@ import com.jogamp.opengl.util.GLArrayDataEditable; * Interleaved fixed function arrays, i.e. where this buffer data * represents many arrays. */ -public class GLSLArrayHandlerInterleaved implements GLArrayHandler { - private GLArrayDataEditable ad; +public class GLSLArrayHandlerInterleaved extends GLVBOArrayHandler implements GLArrayHandler { private List<GLArrayHandlerFlat> subArrays = new ArrayList<GLArrayHandlerFlat>(); public GLSLArrayHandlerInterleaved(GLArrayDataEditable ad) { - this.ad = ad; + super(ad); } public final void setSubArrayVBOName(int vboName) { @@ -72,22 +71,10 @@ public class GLSLArrayHandlerInterleaved implements GLArrayHandler { if(!ad.isVBO()) { throw new InternalError("Interleaved handle is not VBO: "+ad); } - - final Buffer buffer = ad.getBuffer(); - final boolean vboWritten = ad.isVBOWritten(); - - // always bind and refresh the VBO mgr, - // in case more than one gl*Pointer objects are in use - gl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); - if(!vboWritten) { - if(null!=buffer) { - gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSizeInBytes(), buffer, ad.getVBOUsage()); - } - ad.setVBOWritten(true); - } + bindBuffer(gl, true); // sub data will decide weather to update the vertex attrib pointer syncSubData(gl, ext); - gl.glBindBuffer(ad.getVBOTarget(), 0); + bindBuffer(gl, false); } for(int i=0; i<subArrays.size(); i++) { subArrays.get(i).enableState(gl, enable, ext); |