diff options
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java | 124 |
1 files changed, 52 insertions, 72 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java index 221385cc6..d80d398aa 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java @@ -35,8 +35,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData * 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)'. @@ -48,11 +47,9 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData * * @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) + public static GLArrayDataClient createFixed(int index, String name, int comps, int dataType, boolean normalized, int initialSize) throws GLException { - 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, -1, -1, -1, -1); @@ -67,8 +64,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData * 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)'. @@ -81,11 +77,10 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData * * @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) + public static GLArrayDataClient createFixed(int index, String name, int comps, int dataType, boolean normalized, int stride, + Buffer buffer) throws GLException { - 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, -1, -1, -1, -1); @@ -95,25 +90,20 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData /** * 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 st The ShaderState managing the state of the used shader program, vertex attributes and uniforms * @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) + public static GLArrayDataClient createGLSL(ShaderState st, String name, + int comps, int dataType, boolean normalized, int initialSize) throws GLException { - if(!gl.hasGLSL()) { - throw new GLException("GLArrayDataClient.GLSL not supported: "+gl); - } - gl.getGLProfile().isValidArrayDataType(-1, comps, dataType, true, true); - GLArrayDataClient adc = new GLArrayDataClient(); - GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc); + GLArrayHandler glArrayHandler = new GLSLArrayHandler(st, adc); adc.init(name, -1, comps, dataType, normalized, 0, null, initialSize, true, glArrayHandler, -1, -1, -1, -1); return adc; } @@ -121,8 +111,8 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData /** * 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 st The ShaderState managing the state of the used shader program, vertex attributes and uniforms * @param name The custom name for the GL attribute. * @param comps The array component number * @param dataType The array index GL data type @@ -130,17 +120,13 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData * @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) + public static GLArrayDataClient createGLSL(ShaderState st, String name, + int comps, int dataType, boolean normalized, int stride, + Buffer buffer) throws GLException { - if(!gl.hasGLSL()) { - throw new GLException("GLArrayDataClient.GLSL not supported: "+gl); - } - gl.getGLProfile().isValidArrayDataType(-1, comps, dataType, true, true); - GLArrayDataClient adc = new GLArrayDataClient(); - GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc); + GLArrayHandler glArrayHandler = new GLSLArrayHandler(st, adc); adc.init(name, -1, comps, dataType, normalized, stride, buffer, comps*comps, true, glArrayHandler, -1, -1, -1, -1); return adc; } @@ -152,6 +138,8 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData public final boolean isVBOWritten() { return bufferWritten; } public final boolean sealed() { return sealed; } + + public final boolean enabled() { return bufferEnabled; } // // Data and GL state modification .. @@ -161,8 +149,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData public void destroy(GL gl) { reset(gl); - buffer=null; - valid=false; + super.destroy(gl); } public void reset(GL gl) { @@ -170,28 +157,17 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData reset(); } - public void seal(GL gl, boolean seal) - { + public void seal(GL gl, boolean seal) { seal(seal); - if(sealedGL==seal) return; - sealedGL = seal; - if(seal) { - init_vbo(gl); - - enableBuffer(gl, true); - } else { - enableBuffer(gl, false); - } + enableBuffer(gl, seal); } public void enableBuffer(GL gl, boolean enable) { - if( enableBufferAlways || bufferEnabled != enable || - getVBOName() != gl.glGetBoundBuffer(getVBOTarget()) ) { + if( enableBufferAlways || bufferEnabled != enable ) { if(enable) { checkSeal(true); - if(null!=buffer) { - buffer.rewind(); - } + // init/generate VBO name if not done yet + init_vbo(gl); } glArrayHandler.enableBuffer(gl, enable); bufferEnabled = enable; @@ -219,16 +195,14 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData { if(sealed==seal) return; sealed = seal; + bufferWritten=false; if(seal) { - bufferWritten=false; if (null!=buffer) { buffer.flip(); } - } else { - if (null!=buffer) { - buffer.position(buffer.limit()); - buffer.limit(buffer.capacity()); - } + } else if (null!=buffer) { + buffer.position(buffer.limit()); + buffer.limit(buffer.capacity()); } } @@ -254,7 +228,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData * The arguments remaining elements must be a multiple of this arrays element stride. */ public void put(Buffer v) { - if ( buffer==null || sealed ) return; + if ( sealed ) return; if(0!=(v.remaining() % strideL)) { throw new GLException("Buffer length ("+v.remaining()+") is not a multiple of component-stride:\n\t"+this); } @@ -263,19 +237,19 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData } public void putb(byte v) { - if ( buffer==null || sealed ) return; + if ( sealed ) return; growBufferIfNecessary(1); Buffers.putb(buffer, v); } public void puts(short v) { - if ( buffer==null || sealed ) return; + if ( sealed ) return; growBufferIfNecessary(1); Buffers.puts(buffer, v); } public void puti(int v) { - if ( buffer==null || sealed ) return; + if ( sealed ) return; growBufferIfNecessary(1); Buffers.puti(buffer, v); } @@ -285,7 +259,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData } public void putf(float v) { - if ( buffer==null || sealed ) return; + if ( sealed ) return; growBufferIfNecessary(1); Buffers.putf(buffer, v); } @@ -295,8 +269,8 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData ", index "+index+ ", location "+location+ ", isVertexAttribute "+isVertexAttribute+ - ", dataType "+dataType+ - ", bufferClazz "+clazz+ + ", dataType "+componentType+ + ", bufferClazz "+componentClazz+ ", elements "+getElementNumber()+ ", components "+components+ ", stride "+stride+"u "+strideB+"b "+strideL+"c"+ @@ -305,7 +279,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData ", bufferEnabled "+bufferEnabled+ ", bufferWritten "+bufferWritten+ ", buffer "+buffer+ - ", valid "+valid+ + ", alive "+alive+ "]"; } @@ -320,7 +294,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData } protected final void growBuffer(int additional) { - if(!valid || sealed) { + if(!alive || sealed) { throw new GLException("Invalid state: "+this); } @@ -328,28 +302,28 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData additional += (additional/components)*(strideL-components); int osize = (buffer!=null)?buffer.capacity():0; - if(clazz==ByteBuffer.class) { + if(componentClazz==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) { + } else if(componentClazz==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) { + } else if(componentClazz==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) { + } else if(componentClazz==FloatBuffer.class) { FloatBuffer newFBuffer = Buffers.newDirectFloatBuffer( (osize+additional) * components ); if(buffer!=null) { buffer.flip(); @@ -357,12 +331,12 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData } buffer = newFBuffer; } else { - throw new GLException("Given Buffer Class not supported: "+clazz+":\n\t"+this); + throw new GLException("Given Buffer Class not supported: "+componentClazz+":\n\t"+this); } } protected final void checkSeal(boolean test) throws GLException { - if(!valid) { + if(!alive) { throw new GLException("Invalid state: "+this); } if(sealed!=test) { @@ -385,7 +359,6 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData this.initialSize = initialSize; this.glArrayHandler = handler; this.sealed=false; - this.sealedGL=false; this.bufferEnabled=false; this.enableBufferAlways=false; this.bufferWritten=false; @@ -394,11 +367,18 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData } } - protected void init_vbo(GL gl) {} + private boolean isValidated = false; + + protected void init_vbo(GL gl) { + if(!isValidated ) { + isValidated = true; + validate(gl.getGLProfile(), true); + } + } protected GLArrayDataClient() { } - protected boolean sealed, sealedGL; + protected boolean sealed; protected boolean bufferEnabled; protected boolean bufferWritten; protected boolean enableBufferAlways; |