diff options
author | Sven Gothel <[email protected]> | 2011-04-08 14:51:22 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-04-08 14:51:22 +0200 |
commit | ab48dac3f4419ceac51fdf059f310f0f0499c4d7 (patch) | |
tree | a255186720c566af8a14281ff99dfde3434075cc /src | |
parent | a140ed4798896ed5d786fbe63e7241309a4b4a91 (diff) |
FIX: Refactor GLArrayData and all it's implementations/sub-interfaces (VBO target, comments, names)
VBO target: Allowing ELEMENT_VERTEX_ARRAY w/o corresponding GLSL/Fixed attribute
Names: Clarified method named.
Comments: Added and fixed comments
Diffstat (limited to 'src')
12 files changed, 404 insertions, 174 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java index 4586d1df5..221385cc6 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java @@ -28,16 +28,26 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData }) != null; /** + * Create a client side buffer object, using a predefined fixed function array index + * and starting with a new created Buffer object with initialSize size + * + * On profiles GL2 and ES1 the fixed function pipeline behavior is as expected. + * On profile ES2 the fixed function emulation will transform these calls to + * EnableVertexAttribArray and VertexAttribPointer calls, + * and a predefined vertex attribute variable name will be chosen. + * + * @param gl the current GL instance * @param index The GL array index * @param name The optional custom name for the GL array index, maybe null. * If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'. * This name might be used as the shader attribute name. * @param comps The array component number * @param dataType The array index GL data type - * @param normalized Wheather the data shall be normalized + * @param normalized Whether the data shall be normalized + * @param initialSize * * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int) - */ + */ public static GLArrayDataClient createFixed(GL gl, int index, String name, int comps, int dataType, boolean normalized, int initialSize) throws GLException @@ -45,10 +55,32 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true); GLArrayDataClient adc = new GLArrayDataClient(); GLArrayHandler glArrayHandler = new GLFixedArrayHandler(adc); - adc.init(name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler, 0, 0); + adc.init(name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler, -1, -1, -1, -1); return adc; } + /** + * Create a client side buffer object, using a predefined fixed function array index + * and starting with a given Buffer object incl it's stride + * + * On profiles GL2 and ES1 the fixed function pipeline behavior is as expected. + * On profile ES2 the fixed function emulation will transform these calls to + * EnableVertexAttribArray and VertexAttribPointer calls, + * and a predefined vertex attribute variable name will be chosen. + * + * @param gl the current GL instance + * @param index The GL array index + * @param name The optional custom name for the GL array index, maybe null. + * If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'. + * This name might be used as the shader attribute name. + * @param comps The array component number + * @param dataType The array index GL data type + * @param normalized Whether the data shall be normalized + * @param stride + * @param buffer the user define data + * + * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int) + */ public static GLArrayDataClient createFixed(GL gl, int index, String name, int comps, int dataType, boolean normalized, int stride, Buffer buffer) throws GLException @@ -56,10 +88,21 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true); GLArrayDataClient adc = new GLArrayDataClient(); GLArrayHandler glArrayHandler = new GLFixedArrayHandler(adc); - adc.init(name, index, comps, dataType, normalized, stride, buffer, comps*comps, false, glArrayHandler, 0, 0); + adc.init(name, index, comps, dataType, normalized, stride, buffer, comps*comps, false, glArrayHandler, -1, -1, -1, -1); return adc; } + /** + * Create a client side buffer object, using a custom GLSL array attribute name + * and starting with a new created Buffer object with initialSize size + * + * @param gl the current GL instance + * @param name The custom name for the GL attribute. + * @param comps The array component number + * @param dataType The array index GL data type + * @param normalized Whether the data shall be normalized + * @param initialSize + */ public static GLArrayDataClient createGLSL(GL gl, String name, int comps, int dataType, boolean normalized, int initialSize) throws GLException @@ -71,10 +114,22 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData GLArrayDataClient adc = new GLArrayDataClient(); GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc); - adc.init(name, -1, comps, dataType, normalized, 0, null, initialSize, true, glArrayHandler, 0, 0); + adc.init(name, -1, comps, dataType, normalized, 0, null, initialSize, true, glArrayHandler, -1, -1, -1, -1); return adc; } + /** + * Create a client side buffer object, using a custom GLSL array attribute name + * and starting with a given Buffer object incl it's stride + * + * @param gl the current GL instance + * @param name The custom name for the GL attribute. + * @param comps The array component number + * @param dataType The array index GL data type + * @param normalized Whether the data shall be normalized + * @param stride + * @param buffer the user define data + */ public static GLArrayDataClient createGLSL(GL gl, String name, int comps, int dataType, boolean normalized, int stride, Buffer buffer) throws GLException @@ -86,7 +141,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData GLArrayDataClient adc = new GLArrayDataClient(); GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc); - adc.init(name, -1, comps, dataType, normalized, stride, buffer, comps*comps, true, glArrayHandler, 0, 0); + adc.init(name, -1, comps, dataType, normalized, stride, buffer, comps*comps, true, glArrayHandler, -1, -1, -1, -1); return adc; } @@ -94,21 +149,20 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData // Data read access // - public final boolean isBufferWritten() { return bufferWritten; } + public final boolean isVBOWritten() { return bufferWritten; } public final boolean sealed() { return sealed; } - public int getBufferUsage() { return -1; } - // // Data and GL state modification .. // - public final void setBufferWritten(boolean written) { bufferWritten=written; } + public final void setVBOWritten(boolean written) { bufferWritten=written; } public void destroy(GL gl) { reset(gl); buffer=null; + valid=false; } public void reset(GL gl) { @@ -131,10 +185,8 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData } public void enableBuffer(GL gl, boolean enable) { - if(enableBufferAlways && enable) { - bufferEnabled = false; - } - if( bufferEnabled != enable && components>0 ) { + if( enableBufferAlways || bufferEnabled != enable || + getVBOName() != gl.glGetBoundBuffer(getVBOTarget()) ) { if(enable) { checkSeal(true); if(null!=buffer) { @@ -252,7 +304,8 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData ", sealed "+sealed+ ", bufferEnabled "+bufferEnabled+ ", bufferWritten "+bufferWritten+ - ", buffer "+buffer+ + ", buffer "+buffer+ + ", valid "+valid+ "]"; } @@ -260,55 +313,58 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData protected final boolean growBufferIfNecessary(int spare) { if(buffer==null || buffer.remaining()<spare) { - growBuffer(initialSize); + growBuffer(Math.max(initialSize, spare)); return true; } return false; } - protected final void growBuffer(int additional) { - if(sealed || 0==additional || 0==components) return; + protected final void growBuffer(int additional) { + if(!valid || sealed) { + throw new GLException("Invalid state: "+this); + } // add the stride delta additional += (additional/components)*(strideL-components); - if(components>0) { - int osize = (buffer!=null)?buffer.capacity():0; - if(clazz==ByteBuffer.class) { - ByteBuffer newBBuffer = Buffers.newDirectByteBuffer( (osize+additional) * components ); - if(buffer!=null) { - buffer.flip(); - newBBuffer.put((ByteBuffer)buffer); - } - buffer = newBBuffer; - } else if(clazz==ShortBuffer.class) { - ShortBuffer newSBuffer = Buffers.newDirectShortBuffer( (osize+additional) * components ); - if(buffer!=null) { - buffer.flip(); - newSBuffer.put((ShortBuffer)buffer); - } - buffer = newSBuffer; - } else if(clazz==IntBuffer.class) { - IntBuffer newIBuffer = Buffers.newDirectIntBuffer( (osize+additional) * components ); - if(buffer!=null) { - buffer.flip(); - newIBuffer.put((IntBuffer)buffer); - } - buffer = newIBuffer; - } else if(clazz==FloatBuffer.class) { - FloatBuffer newFBuffer = Buffers.newDirectFloatBuffer( (osize+additional) * components ); - if(buffer!=null) { - buffer.flip(); - newFBuffer.put((FloatBuffer)buffer); - } - buffer = newFBuffer; - } else { - throw new GLException("Given Buffer Class not supported: "+clazz+":\n\t"+this); + int osize = (buffer!=null)?buffer.capacity():0; + if(clazz==ByteBuffer.class) { + ByteBuffer newBBuffer = Buffers.newDirectByteBuffer( (osize+additional) * components ); + if(buffer!=null) { + buffer.flip(); + newBBuffer.put((ByteBuffer)buffer); + } + buffer = newBBuffer; + } else if(clazz==ShortBuffer.class) { + ShortBuffer newSBuffer = Buffers.newDirectShortBuffer( (osize+additional) * components ); + if(buffer!=null) { + buffer.flip(); + newSBuffer.put((ShortBuffer)buffer); } + buffer = newSBuffer; + } else if(clazz==IntBuffer.class) { + IntBuffer newIBuffer = Buffers.newDirectIntBuffer( (osize+additional) * components ); + if(buffer!=null) { + buffer.flip(); + newIBuffer.put((IntBuffer)buffer); + } + buffer = newIBuffer; + } else if(clazz==FloatBuffer.class) { + FloatBuffer newFBuffer = Buffers.newDirectFloatBuffer( (osize+additional) * components ); + if(buffer!=null) { + buffer.flip(); + newFBuffer.put((FloatBuffer)buffer); + } + buffer = newFBuffer; + } else { + throw new GLException("Given Buffer Class not supported: "+clazz+":\n\t"+this); } } protected final void checkSeal(boolean test) throws GLException { + if(!valid) { + throw new GLException("Invalid state: "+this); + } if(sealed!=test) { if(test) { throw new GLException("Not Sealed yet, seal first:\n\t"+this); @@ -320,11 +376,11 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData protected void init(String name, int index, int comps, int dataType, boolean normalized, int stride, Buffer data, int initialSize, boolean isVertexAttribute, GLArrayHandler handler, - int vboName, long bufferOffset) + int vboName, long vboOffset, int vboUsage, int vboTarget) throws GLException { super.init(name, index, comps, dataType, normalized, stride, data, isVertexAttribute, - vboName, bufferOffset); + vboName, vboOffset, vboUsage, vboTarget); this.initialSize = initialSize; this.glArrayHandler = handler; @@ -333,7 +389,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData this.bufferEnabled=false; this.enableBufferAlways=false; this.bufferWritten=false; - if(null==buffer) { + if(null==buffer && initialSize>0) { growBuffer(initialSize); } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java index 0f8ed27be..32fc5a2a2 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java @@ -16,19 +16,14 @@ public interface GLArrayDataEditable extends GLArrayData { public boolean sealed(); /** - * The VBO buffer usage, if it's an VBO, otherwise -1 + * Is the buffer written to the VBO ? */ - public int getBufferUsage(); + public boolean isVBOWritten(); /** - * Is the buffer written to the GPU ? + * Marks the buffer written to the VBO */ - public boolean isBufferWritten(); - - /** - * Marks the buffer written to the GPU - */ - public void setBufferWritten(boolean written); + public void setVBOWritten(boolean written); // // Data and GL state modification .. diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java index c061e212a..8504aeae3 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java @@ -2,6 +2,7 @@ package com.jogamp.opengl.util; import javax.media.opengl.*; + import java.nio.*; import com.jogamp.opengl.util.glsl.*; @@ -13,26 +14,31 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE // /** - * Create a VBOBuffer object, using a predefined fixed function array index + * Create a VBO, using a predefined fixed function array index * and starting with a given Buffer object incl it's stride * * On profiles GL2 and ES1 the fixed function pipeline behavior is as expected. * On profile ES2 the fixed function emulation will transform these calls to * EnableVertexAttribArray and VertexAttribPointer calls, - * and a predefined vertex attribute variable name will be choosen. + * and a predefined vertex attribute variable name will be chosen. * + * @param gl the current GL instance * @param index The GL array index * @param name The optional custom name for the GL array index, maybe null. * If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'. * This name might be used as the shader attribute name. * @param comps The array component number * @param dataType The array index GL data type - * @param normalized Wheather the data shall be normalized + * @param normalized Whether the data shall be normalized + * @param stride + * @param buffer the user define data + * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW} + * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER} * * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int) */ public static GLArrayDataServer createFixed(GL gl, int index, String name, int comps, int dataType, boolean normalized, - int stride, Buffer buffer, int vboBufferUsage) + int stride, Buffer buffer, int vboUsage, int vboTarget) throws GLException { gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true); @@ -40,23 +46,35 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE GLArrayDataServer ads = new GLArrayDataServer(); GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads); ads.init(gl, name, index, comps, dataType, normalized, stride, buffer, buffer.limit(), false, glArrayHandler, - 0, 0, vboBufferUsage); + 0, 0, vboUsage, vboTarget); return ads; } /** - * Create a VBOBuffer object, using a predefined fixed function array index + * Create a VBO, using a predefined fixed function array index * and starting with a new created Buffer object with initialSize size * * On profiles GL2 and ES1 the fixed function pipeline behavior is as expected. * On profile ES2 the fixed function emulation will transform these calls to * EnableVertexAttribArray and VertexAttribPointer calls, - * and a predefined vertex attribute variable name will be choosen. + * and a predefined vertex attribute variable name will be chosen. + * + * @param gl the current GL instance + * @param index The GL array index + * @param name The optional custom name for the GL array index, maybe null. + * If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'. + * This name might be used as the shader attribute name. + * @param comps The array component number + * @param dataType The array index GL data type + * @param normalized Whether the data shall be normalized + * @param initialSize + * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW} + * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER} * * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int) */ public static GLArrayDataServer createFixed(GL gl, int index, String name, int comps, int dataType, boolean normalized, - int initialSize, int vboBufferUsage) + int initialSize, int vboUsage, int vboTarget) throws GLException { gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true); @@ -64,18 +82,25 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE GLArrayDataServer ads = new GLArrayDataServer(); GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads); ads.init(gl, name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler, - 0, 0, vboBufferUsage); + 0, 0, vboUsage, vboTarget); return ads; } /** - * Create a VBOBuffer object, using a custom GLSL array attribute name + * Create a VBO, using a custom GLSL array attribute name * and starting with a new created Buffer object with initialSize size * - * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int) + * @param gl the current GL instance + * @param name The custom name for the GL attribute, maybe null if gpuBufferTarget is {@link GL#GL_ELEMENT_ARRAY_BUFFER} + * @param comps The array component number + * @param dataType The array index GL data type + * @param normalized Whether the data shall be normalized + * @param initialSize + * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW} + * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER} */ public static GLArrayDataServer createGLSL(GL gl, String name, int comps, int dataType, boolean normalized, - int initialSize, int vboBufferUsage) + int initialSize, int vboUsage, int vboTarget) throws GLException { if(!gl.hasGLSL()) { @@ -84,20 +109,33 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE gl.getGLProfile().isValidArrayDataType(-1, comps, dataType, true, true); GLArrayDataServer ads = new GLArrayDataServer(); - GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads); + GLArrayHandler glArrayHandler; + if( GL.GL_ELEMENT_ARRAY_BUFFER == vboTarget ) { + glArrayHandler = new GLDataArrayHandler(ads); + } else { + glArrayHandler = new GLSLArrayHandler(ads); + } ads.init(gl, name, -1, comps, dataType, normalized, 0, null, initialSize, true, glArrayHandler, - 0, 0, vboBufferUsage); + 0, 0, vboUsage, vboTarget); return ads; } /** - * Create a VBOBuffer object, using a custom GLSL array attribute name + * Create a VBO, using a custom GLSL array attribute name * and starting with a given Buffer object incl it's stride * - * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int) + * @param gl the current GL instance + * @param name The custom name for the GL attribute, maybe null if gpuBufferTarget is {@link GL#GL_ELEMENT_ARRAY_BUFFER} + * @param comps The array component number + * @param dataType The array index GL data type + * @param normalized Whether the data shall be normalized + * @param stride + * @param buffer the user define data + * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW} + * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER} */ public static GLArrayDataServer createGLSL(GL gl, String name, int comps, int dataType, boolean normalized, - int stride, Buffer buffer, int vboBufferUsage) + int stride, Buffer buffer, int vboUsage, int vboTarget) throws GLException { if(!gl.hasGLSL()) { @@ -106,9 +144,14 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE gl.getGLProfile().isValidArrayDataType(-1, comps, dataType, true, true); GLArrayDataServer ads = new GLArrayDataServer(); - GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads); + GLArrayHandler glArrayHandler; + if( GL.GL_ELEMENT_ARRAY_BUFFER == vboTarget ) { + glArrayHandler = new GLDataArrayHandler(ads); + } else { + glArrayHandler = new GLSLArrayHandler(ads); + } ads.init(gl, name, -1, comps, dataType, normalized, stride, buffer, buffer.limit(), true, glArrayHandler, - 0, 0, vboBufferUsage); + 0, 0, vboUsage, vboTarget); return ads; } @@ -116,8 +159,6 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE // Data matters GLArrayData // - public int getBufferUsage() { return vboBufferUsage; } - // // Data and GL state modification .. // @@ -141,9 +182,9 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE * switch to client side data one * Only possible if buffer is defined. */ - public void setVBOUsage(boolean vboUsage) { + public void setVBOEnabled(boolean vboUsage) { checkSeal(false); - super.setVBOUsage(vboUsage); + super.setVBOEnabled(vboUsage); } public String toString() { @@ -157,14 +198,16 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE ", components "+components+ ", stride "+stride+"u "+strideB+"b "+strideL+"c"+ ", initialSize "+initialSize+ - ", vboBufferUsage "+vboBufferUsage+ - ", vboUsage "+vboUsage+ + ", vboUsage 0x"+Integer.toHexString(vboUsage)+ + ", vboTarget 0x"+Integer.toHexString(vboTarget)+ + ", vboEnabled "+vboEnabled+ ", vboName "+vboName+ ", sealed "+sealed+ ", bufferEnabled "+bufferEnabled+ ", bufferWritten "+bufferWritten+ ", buffer "+buffer+ - ", offset "+bufferOffset+ + ", offset "+vboOffset+ + ", valid "+valid+ "]"; } @@ -175,35 +218,21 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE protected void init(GL gl, String name, int index, int comps, int dataType, boolean normalized, int stride, Buffer data, int initialSize, boolean isVertexAttribute, GLArrayHandler glArrayHandler, - int vboName, long bufferOffset, int vboBufferUsage) + int vboName, long vboOffset, int vboUsage, int vboTarget) throws GLException { super.init(name, index, comps, dataType, normalized, stride, data, initialSize, isVertexAttribute, glArrayHandler, - vboName, bufferOffset); - - vboUsage=true; - - if( ! (gl.isGL2ES2() && vboBufferUsage==GL2ES2.GL_STREAM_DRAW) ) { - switch(vboBufferUsage) { - case -1: // nop - case GL.GL_STATIC_DRAW: - case GL.GL_DYNAMIC_DRAW: - break; - default: - throw new GLException("invalid vboBufferUsage: "+vboBufferUsage+":\n\t"+this); - } - } - this.vboBufferUsage=vboBufferUsage; + vboName, vboOffset, vboUsage, vboTarget); + + vboEnabled=true; } protected void init_vbo(GL gl) { - if(vboUsage && vboName==0) { + if(vboEnabled && vboName==0) { int[] tmp = new int[1]; gl.glGenBuffers(1, tmp, 0); vboName = tmp[0]; } } - - protected int vboBufferUsage; } diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java index 88a8603f9..f2694d39c 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java @@ -9,21 +9,55 @@ import java.nio.*; public class GLArrayDataWrapper implements GLArrayData { + /** + * Create a VBO, using a predefined fixed function array index, wrapping the given data. + * + * @param gl the current GL instance + * @param index The GL array index + * @param comps The array component number + * @param dataType The array index GL data type + * @param normalized Whether the data shall be normalized + * @param stride + * @param buffer the user define data + * @param vboName + * @param vboOffset + * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW} + * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER} + * @return the new create instance + * @throws GLException + */ public static GLArrayDataWrapper createFixed(GL gl, int index, int comps, int dataType, boolean normalized, int stride, Buffer buffer, - int vboName, long bufferOffset) + int vboName, long vboOffset, int vboUsage, int vboTarget) throws GLException { gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true); GLArrayDataWrapper adc = new GLArrayDataWrapper(); adc.init(null, index, comps, dataType, normalized, stride, buffer, false, - vboName, bufferOffset); + vboName, vboOffset, vboUsage, vboTarget); return adc; } + /** + * Create a VBO, using a custom GLSL array attribute name, wrapping the given data. + * + * @param gl the current GL instance + * @param name The custom name for the GL attribute, maybe null if gpuBufferTarget is {@link GL#GL_ELEMENT_ARRAY_BUFFER} + * @param comps The array component number + * @param dataType The array index GL data type + * @param normalized Whether the data shall be normalized + * @param stride + * @param buffer the user define data + * @param vboName + * @param vboOffset + * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW} + * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER} + * @return the new create instance + * @throws GLException + */ public static GLArrayDataWrapper createGLSL(GL gl, String name, int comps, int dataType, boolean normalized, - int stride, Buffer buffer, - int vboName, long bufferOffset) + int stride, Buffer buffer, + int vboName, long vboOffset, int vboUsage, int vboTarget) throws GLException { if(!gl.hasGLSL()) { @@ -33,7 +67,7 @@ public class GLArrayDataWrapper implements GLArrayData { GLArrayDataWrapper adc = new GLArrayDataWrapper(); adc.init(name, -1, comps, dataType, normalized, stride, buffer, true, - vboName, bufferOffset); + vboName, vboOffset, vboUsage, vboTarget); return adc; } @@ -51,12 +85,16 @@ public class GLArrayDataWrapper implements GLArrayData { public final String getName() { return name; } - public final long getOffset() { return vboUsage?bufferOffset:-1; } + public final long getVBOOffset() { return vboEnabled?vboOffset:-1; } - public final int getVBOName() { return vboUsage?vboName:-1; } + public final int getVBOName() { return vboEnabled?vboName:-1; } - public final boolean isVBO() { return vboUsage; } + public final boolean isVBO() { return vboEnabled; } + public final int getVBOUsage() { return vboEnabled?vboUsage:-1; } + + public final int getVBOTarget() { return vboEnabled?vboTarget:-1; } + public final Buffer getBuffer() { return buffer; } public final int getComponentNumber() { return components; } @@ -91,14 +129,11 @@ public class GLArrayDataWrapper implements GLArrayData { public final Class getBufferClass() { return clazz; } public void destroy(GL gl) { - this.buffer = null; - this.components = 0; - this.stride=0; - this.strideB=0; - this.strideL=0; - this.vboName=0; - this.vboUsage=false; - this.bufferOffset=0; + buffer = null; + vboName=0; + vboEnabled=false; + vboOffset=-1; + valid = false; } public String toString() { @@ -112,9 +147,12 @@ public class GLArrayDataWrapper implements GLArrayData { ", components "+components+ ", stride "+stride+"u "+strideB+"b "+strideL+"c"+ ", buffer "+buffer+ - ", offset "+bufferOffset+ - ", vboUsage "+vboUsage+ + ", offset "+vboOffset+ + ", vboUsage 0x"+Integer.toHexString(vboUsage)+ + ", vboTarget 0x"+Integer.toHexString(vboTarget)+ + ", vboEnabled "+vboEnabled+ ", vboName "+vboName+ + ", valid "+valid+ "]"; } @@ -140,28 +178,60 @@ public class GLArrayDataWrapper implements GLArrayData { name = newName; } - public void setVBOUsage(boolean vboUsage) { - this.vboUsage=vboUsage; + /** + * Enable or disable use of VBO. + * Only possible if a VBO buffer name is defined. + * @see #setVBOName(int) + */ + public void setVBOEnabled(boolean vboEnabled) { + this.vboEnabled=vboEnabled; } + /** + * Set the VBO buffer name, if valid (>0) enable use of VBO + * @see #setVBOEnabled(boolean) + */ public void setVBOName(int vboName) { this.vboName=vboName; - setVBOUsage(vboName>0); + setVBOEnabled(vboName>0); + } + + /** + * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW} + */ + public void setVBOUsage(int vboUsage) { + this.vboUsage = vboUsage; } + + /** + * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER} + */ + public void setVBOTarget(int vboTarget) { + this.vboTarget = vboTarget; + } protected void init(String name, int index, int comps, int dataType, boolean normalized, int stride, Buffer data, boolean isVertexAttribute, - int vboName, long bufferOffset) + int vboName, long vboOffset, int vboUsage, int vboTarget) throws GLException { this.isVertexAttribute = isVertexAttribute; this.index = index; this.location = -1; // We can't have any dependence on the FixedFuncUtil class here for build bootstrapping reasons - this.name = (null==name)?FixedFuncPipeline.getPredefinedArrayIndexName(index):name; - if(null==this.name) { - throw new GLException("Not a valid GL array index: "+index); + + if( GL.GL_ELEMENT_ARRAY_BUFFER == vboTarget ) { + // ok .. + } else if( GL.GL_ARRAY_BUFFER == vboTarget ) { + // check name .. + this.name = ( null == name ) ? FixedFuncPipeline.getPredefinedArrayIndexName(index) : name ; + if(null == this.name ) { + throw new GLException("Not a valid array buffer index: "+index); + } + } else if( 0 <= vboTarget ) { + throw new GLException("Invalid GPUBuffer target: 0x"+Integer.toHexString(vboTarget)); } + this.dataType = dataType; this.clazz = getBufferClass(dataType); switch(dataType) { @@ -184,17 +254,42 @@ public class GLArrayDataWrapper implements GLArrayData { throw new GLException("stride ("+stride+") not a multiple of bpc "+bpc); } this.buffer = data; + if(0 >= comps) { + throw new GLException("Invalid number of components: " + comps); + } this.components = comps; this.stride=stride; this.strideB=(0==stride)?comps*bpc:stride; this.strideL=(0==stride)?comps:strideB/bpc; this.vboName=vboName; - this.vboUsage=vboName>0; - this.bufferOffset=bufferOffset; + this.vboEnabled=vboName>0; + this.vboOffset=vboOffset; + + switch(vboUsage) { + case -1: // nop + case GL.GL_STATIC_DRAW: + case GL.GL_DYNAMIC_DRAW: + case GL2ES2.GL_STREAM_DRAW: + break; + default: + throw new GLException("invalid gpuBufferUsage: "+vboUsage+":\n\t"+this); + } + switch(vboTarget) { + case -1: // nop + case GL.GL_ARRAY_BUFFER: + case GL.GL_ELEMENT_ARRAY_BUFFER: + break; + default: + throw new GLException("invalid gpuBufferTarget: "+vboTarget+":\n\t"+this); + } + this.vboUsage=vboUsage; + this.vboTarget=vboTarget; + this.valid=true; } protected GLArrayDataWrapper() { } + protected boolean valid; protected int index; protected int location; protected String name; @@ -208,8 +303,10 @@ public class GLArrayDataWrapper implements GLArrayData { protected Buffer buffer; protected boolean isVertexAttribute; - protected long bufferOffset; + protected long vboOffset; protected int vboName; - protected boolean vboUsage; + protected boolean vboEnabled; + protected int vboUsage; + protected int vboTarget; } diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java new file mode 100644 index 000000000..74d49aa6c --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java @@ -0,0 +1,41 @@ + +package com.jogamp.opengl.util; + +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.*; +import com.jogamp.opengl.util.*; +import java.nio.*; + +public class GLDataArrayHandler implements GLArrayHandler { + private GLArrayDataEditable ad; + + public GLDataArrayHandler(GLArrayDataEditable ad) { + this.ad = ad; + } + + public void enableBuffer(GL gl, boolean enable) { + GLPointerFunc glp = gl.getGL2ES1(); + if(enable) { + 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 + gl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); + if(!ad.isVBOWritten()) { + if(null!=buffer) { + gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSize(), buffer, ad.getVBOUsage()); + } + ad.setVBOWritten(true); + } + } else if(null!=buffer) { + ad.setVBOWritten(true); + } + } else { + if(ad.isVBO()) { + gl.glBindBuffer(ad.getVBOTarget(), 0); + } + } + } +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java index f0f5ea896..a825ca690 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java @@ -13,7 +13,7 @@ public class GLFixedArrayHandler implements GLArrayHandler { this.ad = ad; } - protected final void passArrayPointer(GLPointerFunc gl) { + private final void passArrayPointer(GLPointerFunc gl) { switch(ad.getIndex()) { case GLPointerFunc.GL_VERTEX_ARRAY: gl.glVertexPointer(ad); @@ -42,21 +42,21 @@ public class GLFixedArrayHandler implements GLArrayHandler { if(ad.isVBO()) { // always bind and refresh the VBO mgr, // in case more than one gl*Pointer objects are in use - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, ad.getVBOName()); - if(!ad.isBufferWritten()) { + gl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); + if(!ad.isVBOWritten()) { if(null!=buffer) { - gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * ad.getComponentSize(), buffer, ad.getBufferUsage()); + gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSize(), buffer, ad.getVBOUsage()); } - ad.setBufferWritten(true); + ad.setVBOWritten(true); } passArrayPointer(glp); } else if(null!=buffer) { passArrayPointer(glp); - ad.setBufferWritten(true); + ad.setVBOWritten(true); } } else { if(ad.isVBO()) { - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + gl.glBindBuffer(ad.getVBOTarget(), 0); } glp.glDisableClientState(ad.getIndex()); } diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java index d9fce6e6a..be15dfb59 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java +++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java @@ -861,25 +861,25 @@ public class ImmModeSink { if(vComps>0) { vArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, vComps, vDataType, false, - 0, vertexArray, 0, vOffset); + 0, vertexArray, 0, vOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); } else { vArrayData = null; } if(cComps>0) { cArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_COLOR_ARRAY, cComps, cDataType, false, - 0, colorArray, 0, cOffset); + 0, colorArray, 0, cOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); } else { cArrayData = null; } if(nComps>0) { nArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_NORMAL_ARRAY, nComps, nDataType, false, - 0, normalArray, 0, nOffset); + 0, normalArray, 0, nOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); } else { nArrayData = null; } if(tComps>0) { tArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_TEXTURE_COORD_ARRAY, tComps, tDataType, false, - 0, textCoordArray, 0, tOffset); + 0, textCoordArray, 0, tOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); } else { tArrayData = null; } 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 95a550ab6..1ce39d557 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java @@ -39,7 +39,7 @@ public class GLSLArrayHandler implements GLArrayHandler { this.ad = ad; } - protected final void passVertexAttribPointer(GL2ES2 gl, ShaderState st) { + private final void passVertexAttribPointer(GL2ES2 gl, ShaderState st) { st.glVertexAttribPointer(gl, ad); } @@ -61,21 +61,21 @@ public class GLSLArrayHandler implements GLArrayHandler { if(ad.isVBO()) { // always bind and refresh the VBO mgr, // in case more than one gl*Pointer objects are in use - glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, ad.getVBOName()); - if(!ad.isBufferWritten()) { + glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); + if(!ad.isVBOWritten()) { if(null!=buffer) { - glsl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * ad.getComponentSize(), buffer, ad.getBufferUsage()); + glsl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSize(), buffer, ad.getVBOUsage()); } - ad.setBufferWritten(true); + ad.setVBOWritten(true); } passVertexAttribPointer(glsl, st); } else if(null!=buffer) { passVertexAttribPointer(glsl, st); - ad.setBufferWritten(true); + ad.setVBOWritten(true); } } else { if(ad.isVBO()) { - glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + glsl.glBindBuffer(ad.getVBOTarget(), 0); } st.glDisableVertexAttribArray(glsl, ad.getName()); } diff --git a/src/jogl/classes/javax/media/opengl/GLArrayData.java b/src/jogl/classes/javax/media/opengl/GLArrayData.java index 6c8122f27..b449ce232 100644 --- a/src/jogl/classes/javax/media/opengl/GLArrayData.java +++ b/src/jogl/classes/javax/media/opengl/GLArrayData.java @@ -37,7 +37,6 @@ import java.nio.*; * */ public interface GLArrayData { - /** * Returns true if this data set is intended for a GLSL vertex shader attribute, * otherwise false, ie intended for fixed function vertex pointer @@ -81,23 +80,36 @@ public interface GLArrayData { public void setLocation(int v); /** - * Determines wheather the data is server side (VBO), + * Determines whether the data is server side (VBO) and enabled, * or a client side array (false). */ public boolean isVBO(); /** - * The offset, if it's an VBO, otherwise -1 + * The VBO buffer offset or -1 if not a VBO */ - public long getOffset(); + public long getVBOOffset(); /** - * The VBO name, if it's an VBO, otherwise -1 + * The VBO name or -1 if not a VBO */ public int getVBOName(); /** - * The Buffer holding the data, may be null in case of VBO + * The VBO usage or -1 if not a VBO + * @return -1 if not a GPU buffer, otherwise {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW} + */ + public int getVBOUsage(); + + /** + * The VBO target or -1 if not a VBO + * @return -1 if not a GPU buffer, otherwise {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER} + */ + public int getVBOTarget(); + + + /** + * The Buffer holding the data, may be null if a GPU buffer without client bound data */ public Buffer getBuffer(); diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java index 4e5afc683..d0f8543a3 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java @@ -214,7 +214,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun } public void glVertexPointer(int size, int type, int stride, java.nio.Buffer pointer) { - glVertexPointer(GLArrayDataWrapper.createFixed(gl, GL_VERTEX_ARRAY, size, type, false, stride, pointer, 0, 0)); + glVertexPointer(GLArrayDataWrapper.createFixed(gl, GL_VERTEX_ARRAY, size, type, false, stride, pointer, -1, -1, -1, -1)); } public void glVertexPointer(int size, int type, int stride, long pointer_buffer_offset) { int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); @@ -222,7 +222,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun throw new GLException("no GL_ARRAY_BUFFER VBO bound"); } glVertexPointer(GLArrayDataWrapper.createFixed(gl, GL_VERTEX_ARRAY, size, type, false, - stride, null, vboName, pointer_buffer_offset)); + stride, null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER)); } public void glColorPointer(GLArrayData array) { @@ -242,7 +242,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun } public void glColorPointer(int size, int type, int stride, java.nio.Buffer pointer) { glColorPointer(GLArrayDataWrapper.createFixed(gl, GL_COLOR_ARRAY, size, type, false, - stride, pointer, 0, 0)); + stride, pointer, -1, -1, -1, -1)); } public void glColorPointer(int size, int type, int stride, long pointer_buffer_offset) { int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); @@ -250,7 +250,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun throw new GLException("no GL_ARRAY_BUFFER VBO bound"); } glColorPointer(GLArrayDataWrapper.createFixed(gl, GL_COLOR_ARRAY, size, type, false, - stride, null, vboName, pointer_buffer_offset)); + stride, null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER)); } public void glNormalPointer(GLArrayData array) { @@ -273,7 +273,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun } public void glNormalPointer(int type, int stride, java.nio.Buffer pointer) { glNormalPointer(GLArrayDataWrapper.createFixed(gl, GL_NORMAL_ARRAY, 3, type, false, - stride, pointer, 0, 0)); + stride, pointer, -1, -1, -1, -1)); } public void glNormalPointer(int type, int stride, long pointer_buffer_offset) { int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); @@ -281,7 +281,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun throw new GLException("no GL_ARRAY_BUFFER VBO bound"); } glNormalPointer(GLArrayDataWrapper.createFixed(gl, GL_NORMAL_ARRAY, 3, type, false, - stride, null, vboName, pointer_buffer_offset)); + stride, null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER)); } public void glTexCoordPointer(GLArrayData array) { @@ -301,7 +301,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun } public void glTexCoordPointer(int size, int type, int stride, java.nio.Buffer pointer) { glTexCoordPointer( - GLArrayDataWrapper.createFixed(gl, GL_TEXTURE_COORD_ARRAY, size, type, false, stride, pointer, 0,0)); + GLArrayDataWrapper.createFixed(gl, GL_TEXTURE_COORD_ARRAY, size, type, false, stride, pointer, -1, -1, -1, -1)); } public void glTexCoordPointer(int size, int type, int stride, long pointer_buffer_offset) { int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); @@ -310,7 +310,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun } glTexCoordPointer( GLArrayDataWrapper.createFixed(gl, GL_TEXTURE_COORD_ARRAY, size, type, false, - stride, null, vboName, pointer_buffer_offset) ); + stride, null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER) ); } public final String toString() { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java index f062a7375..9ae317537 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java @@ -82,7 +82,7 @@ public class RedSquare0 implements GLEventListener { Assert.assertTrue(0 <= mgl_Vertex); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); FloatBuffer buffer = Buffers.newDirectFloatBuffer(numElements * components); - GLArrayDataWrapper vertices = GLArrayDataWrapper.createGLSL(gl, "mgl_Vertex", 3, gl.GL_FLOAT, false, 0, buffer, -1, 0); + GLArrayDataWrapper vertices = GLArrayDataWrapper.createGLSL(gl, "mgl_Vertex", 3, gl.GL_FLOAT, false, 0, buffer, -1, 0, 0, 0); { // Fill them up FloatBuffer verticeb = (FloatBuffer) vertices.getBuffer(); @@ -111,7 +111,7 @@ public class RedSquare0 implements GLEventListener { Assert.assertTrue(0 <= mgl_Color); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); buffer = Buffers.newDirectFloatBuffer(numElements * components); - GLArrayDataWrapper colors = GLArrayDataWrapper.createGLSL(gl, "mgl_Color", 4, gl.GL_FLOAT, false, 0, buffer, -1, 0); + GLArrayDataWrapper colors = GLArrayDataWrapper.createGLSL(gl, "mgl_Color", 4, gl.GL_FLOAT, false, 0, buffer, -1, 0, 0, 0); { // Fill them up FloatBuffer colorb = (FloatBuffer) colors.getBuffer(); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java index 96a830a53..67e400f29 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java @@ -63,9 +63,9 @@ public class ReadBuffer2Screen extends ReadBufferBase { //readTextureVertices = GLArrayDataClient.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, "mgl_Vertex", // 2, GL.GL_FLOAT, true, 4); readTextureVertices = GLArrayDataServer.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, "mgl_Vertex", - 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); + 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); readTextureVertices.setEnableAlways(enableBufferAlways); - readTextureVertices.setVBOUsage(enableBufferVBO); + readTextureVertices.setVBOEnabled(enableBufferVBO); { FloatBuffer vb = (FloatBuffer)readTextureVertices.getBuffer(); vb.put(-f_edge); vb.put(-f_edge); @@ -155,9 +155,9 @@ public class ReadBuffer2Screen extends ReadBufferBase { void updateTextureCoords(GL gl, boolean force) { if(force || null==readTextureCoords) { readTextureCoords = GLArrayDataServer.createFixed(gl, GLPointerFunc.GL_TEXTURE_COORD_ARRAY, "mgl_MultiTexCoord0", - 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); + 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); readTextureCoords.setEnableAlways(enableBufferAlways); - readTextureCoords.setVBOUsage(enableBufferVBO); + readTextureCoords.setVBOEnabled(enableBufferVBO); { TextureCoords coords = readBufferUtil.getTexture().getImageTexCoords(); FloatBuffer cb = (FloatBuffer)readTextureCoords.getBuffer(); |