aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-04-22 06:03:44 +0200
committerSven Gothel <[email protected]>2011-04-22 06:03:44 +0200
commitbf8a54b502f0fcd930e12a8bbda65f9538e8a2f7 (patch)
tree88ebdb21601f576674ca69fee8aaf5e6847b5fd7 /src/jogl/classes
parentd72745fa32a86a3820e5220643a01153e3f21fe7 (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')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java124
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java50
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java152
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java134
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java44
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java52
-rw-r--r--src/jogl/classes/javax/media/opengl/GLArrayData.java11
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java28
8 files changed, 315 insertions, 280 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;
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java
index 32fc5a2a2..0da7d1171 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java
@@ -14,6 +14,8 @@ import java.nio.*;
public interface GLArrayDataEditable extends GLArrayData {
public boolean sealed();
+
+ public boolean enabled();
/**
* Is the buffer written to the VBO ?
@@ -34,29 +36,27 @@ public interface GLArrayDataEditable extends GLArrayData {
public void reset(GL gl);
/**
- * If seal is true, it
- * disable write operations to the buffer.
- * Calls flip, ie limit:=position and position:=0.
- * Also enables the buffer for OpenGL, and passes the data.
- *
- * If seal is false, it
- * enable write operations continuing
- * at the buffer position, where you left off at seal(true),
- * ie position:=limit and limit:=capacity.
- * Also disables the buffer for OpenGL.
+ * Convenience method calling {@link #seal(boolean)} and {@link #enableBuffer(GL, boolean)}.
*
* @see #seal(boolean)
+ * @see #enableBuffer(GL, boolean)
+ *
*/
public void seal(GL gl, boolean seal);
/**
- * Enables/disables the buffer, which implies
- * the client state, binding the VBO
- * and transfering the data if not done yet.
+ * <p>Enables/disables the buffer,
+ * sets the client state, binds the VBO if used
+ * and transfers the data if necessary.</p>
+ *
+ * <p>The action will only be executed,
+ * if the internal enable state differs,
+ * or 'setEnableAlways' was called with 'true'.</b>
*
- * The above will only be executed,
- * if the buffer is disabled,
- * or 'setEnableAlways' was called with 'true'.
+ * <p>It is up to the user to enable/disable the array properly,
+ * ie in case of multiple data sets for the same vertex attribute (VA).
+ * Meaning in such case usage of one set while expecting another one
+ * to be used for the same VA implies decorating each usage with enable/disable.</p>
*
* @see #setEnableAlways(boolean)
*/
@@ -67,8 +67,9 @@ public interface GLArrayDataEditable extends GLArrayData {
*
* The default is 'false'
*
- * This is usefull when you mix up
- * GLArrayData usage with conventional GL array calls.
+ * This is useful when you mix up
+ * GLArrayData usage with conventional GL array calls
+ * or in case of a buggy GL VBO implementation.
*
* @see #enableBuffer(GL, boolean)
*/
@@ -81,16 +82,17 @@ public interface GLArrayDataEditable extends GLArrayData {
public void reset();
/**
- * If seal is true, it
- * disable write operations to the buffer.
- * Calls flip, ie limit:=position and position:=0.
+ * <p>If <i>seal</i> is true, it
+ * disables write operations to the buffer.
+ * Calls flip, ie limit:=position and position:=0.</p>
*
- * If seal is false, it
+ * <p>If <i>seal</i> is false, it
* enable write operations continuing
* at the buffer position, where you left off at seal(true),
- * ie position:=limit and limit:=capacity.
+ * ie position:=limit and limit:=capacity.</p>
*
- */
+ * @see #seal(boolean)
+ */
public void seal(boolean seal);
public void rewind();
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
index 8504aeae3..23c237909 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
@@ -21,32 +21,28 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
* 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.
+ * 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
* @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 vboUsage, int vboTarget)
+ public static GLArrayDataServer createFixed(int index, String name, int comps, int dataType, boolean normalized, int stride,
+ Buffer buffer, int vboUsage)
throws GLException
{
- gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true);
-
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, vboUsage, vboTarget);
+ ads.init(name, index, comps, dataType, normalized, stride, buffer, buffer.limit(), false, glArrayHandler,
+ 0, 0, vboUsage, GL.GL_ARRAY_BUFFER);
return ads;
}
@@ -58,103 +54,126 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
* 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.
+ * 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 vboUsage, int vboTarget)
+ public static GLArrayDataServer createFixed(int index, String name, int comps, int dataType, boolean normalized, int initialSize,
+ int vboUsage)
throws GLException
{
- gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true);
-
- GLArrayDataServer ads = new GLArrayDataServer();
- GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads);
- ads.init(gl, name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler,
- 0, 0, vboUsage, vboTarget);
+ GLArrayDataServer ads = new GLArrayDataServer();
+ GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads);
+ ads.init(name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler,
+ 0, 0, vboUsage, GL.GL_ARRAY_BUFFER);
return ads;
}
/**
* Create a VBO, 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, 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 vboUsage, int vboTarget)
- throws GLException
+ public static GLArrayDataServer createGLSL(ShaderState st, String name,
+ int comps, int dataType, boolean normalized, int initialSize,
+ int vboUsage)
+ throws GLException
{
- if(!gl.hasGLSL()) {
- throw new GLException("GLArrayDataServer.GLSL not supported: "+gl);
- }
- gl.getGLProfile().isValidArrayDataType(-1, comps, dataType, true, true);
-
GLArrayDataServer ads = new GLArrayDataServer();
- 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, vboUsage, vboTarget);
+ GLArrayHandler glArrayHandler = new GLSLArrayHandler(st, ads);
+ ads.init(name, -1, comps, dataType, normalized, 0, null, initialSize,
+ true, glArrayHandler, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER);
return ads;
- }
-
+ }
+
/**
* Create a VBO, 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, maybe null if gpuBufferTarget is {@link GL#GL_ELEMENT_ARRAY_BUFFER}
+ *
+ * @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, maybe null if gpuBufferTarget is
* @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 vboUsage, int vboTarget)
+ public static GLArrayDataServer createGLSL(ShaderState st, String name,
+ int comps, int dataType, boolean normalized, int stride,
+ Buffer buffer, int vboUsage)
throws GLException
{
- if(!gl.hasGLSL()) {
- throw new GLException("GLArrayDataServer.GLSL not supported: "+gl);
- }
- gl.getGLProfile().isValidArrayDataType(-1, comps, dataType, true, true);
+ GLArrayDataServer ads = new GLArrayDataServer();
+ GLArrayHandler glArrayHandler = new GLSLArrayHandler(st, ads);
+ ads.init(name, -1, comps, dataType, normalized, stride, buffer, buffer.limit(), true, glArrayHandler,
+ 0, 0, vboUsage, GL.GL_ARRAY_BUFFER);
+ return ads;
+ }
+
+ /**
+ * Create a VBO data object for any target w/o render pipeline association, ie {@link GL#GL_ELEMENT_ARRAY_BUFFER}.
+ *
+ * Hence no index, name for a fixed function pipeline nor vertex attribute is given.
+ *
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @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 {@link GL#GL_ELEMENT_ARRAY_BUFFER}, ..
+ * {@link GL#glGenBuffers(int, int[], int)
+ */
+ public static GLArrayDataServer createData(int comps, int dataType, int stride,
+ Buffer buffer, int vboUsage, int vboTarget)
+ throws GLException
+ {
+ GLArrayDataServer ads = new GLArrayDataServer();
+ GLArrayHandler glArrayHandler = new GLDataArrayHandler(ads);
+ ads.init(null, -1, comps, dataType, false, stride, buffer, buffer.limit(), false, glArrayHandler,
+ 0, 0, vboUsage, vboTarget);
+ return ads;
+ }
+ /**
+ * Create a VBO data object for any target w/o render pipeline association, ie {@link GL#GL_ELEMENT_ARRAY_BUFFER}.
+ *
+ * Hence no index, name for a fixed function pipeline nor vertex attribute is given.
+ *
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param initialSize
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ * @param vboTarget {@link GL#GL_ELEMENT_ARRAY_BUFFER}, ..
+ */
+ public static GLArrayDataServer createData(int comps, int dataType, int initialSize,
+ int vboUsage, int vboTarget)
+ throws GLException
+ {
GLArrayDataServer ads = new GLArrayDataServer();
- 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,
+ GLArrayHandler glArrayHandler = new GLDataArrayHandler(ads);
+ ads.init(null, -1, comps, dataType, false, 0, null, initialSize, false, glArrayHandler,
0, 0, vboUsage, vboTarget);
return ads;
}
+
//
// Data matters GLArrayData
//
@@ -192,8 +211,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
", 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"+
@@ -207,7 +226,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
", bufferWritten "+bufferWritten+
", buffer "+buffer+
", offset "+vboOffset+
- ", valid "+valid+
+ ", alive "+alive+
"]";
}
@@ -215,7 +234,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
// non public matters ..
//
- protected void init(GL gl, String name, int index, int comps, int dataType, boolean normalized,
+ protected void init(String name, int index, int comps, int dataType, boolean normalized,
int stride, Buffer data, int initialSize, boolean isVertexAttribute,
GLArrayHandler glArrayHandler,
int vboName, long vboOffset, int vboUsage, int vboTarget)
@@ -228,6 +247,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
}
protected void init_vbo(GL gl) {
+ super.init_vbo(gl);
if(vboEnabled && vboName==0) {
int[] tmp = new int[1];
gl.glGenBuffers(1, tmp, 0);
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java
index f2694d39c..735bd11f7 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java
@@ -12,7 +12,6 @@ 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
@@ -22,26 +21,25 @@ public class GLArrayDataWrapper implements GLArrayData {
* @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 vboOffset, int vboUsage, int vboTarget)
+ public static GLArrayDataWrapper createFixed(int index, int comps, int dataType, boolean normalized, int stride,
+ Buffer buffer, int vboName,
+ long vboOffset, int vboUsage)
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, vboOffset, vboUsage, vboTarget);
+ vboName, vboOffset, vboUsage, GL.GL_ARRAY_BUFFER);
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
@@ -51,26 +49,45 @@ public class GLArrayDataWrapper implements GLArrayData {
* @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 vboOffset, int vboUsage, int vboTarget)
+ public static GLArrayDataWrapper createGLSL(String name, int comps, int dataType, boolean normalized, int stride,
+ Buffer buffer, int vboName,
+ long vboOffset, int vboUsage)
throws GLException
{
- if(!gl.hasGLSL()) {
- throw new GLException("GLArrayDataWrapper.GLSL not supported: "+gl);
- }
- gl.getGLProfile().isValidArrayDataType(-1, comps, dataType, true, true);
-
GLArrayDataWrapper adc = new GLArrayDataWrapper();
adc.init(name, -1, comps, dataType, normalized, stride, buffer, true,
- vboName, vboOffset, vboUsage, vboTarget);
+ vboName, vboOffset, vboUsage, GL.GL_ARRAY_BUFFER);
return adc;
}
+ /**
+ * Validates this instance's parameter. Called automatically by {@link GLArrayDataClient} and {@link GLArrayDataServer}.
+ * {@link GLArrayDataWrapper} does not validate it's instance by itself.
+ *
+ * @param glp the GLProfile to use
+ * @param throwException whether to throw an exception if this instance has invalid parameter or not
+ * @return true if this instance has invalid parameter, otherwise false
+ */
+ public final boolean validate(GLProfile glp, boolean throwException) {
+ if(!alive) {
+ if(throwException) {
+ throw new GLException("Instance !alive "+this);
+ }
+ return false;
+ }
+ if(this.isVertexAttribute() && !glp.hasGLSL()) {
+ if(throwException) {
+ throw new GLException("GLSL not supported on "+glp+", "+this);
+ }
+ return false;
+ }
+ return glp.isValidArrayDataType(getIndex(), getComponentNumber(), getComponentType(), isVertexAttribute(), throwException);
+ }
+
//
// Data read access
//
@@ -99,41 +116,31 @@ public class GLArrayDataWrapper implements GLArrayData {
public final int getComponentNumber() { return components; }
- public final int getComponentType() { return dataType; }
-
- public final int getComponentSize() {
- if(clazz==ByteBuffer.class) {
- return GLBuffers.SIZEOF_BYTE;
- }
- if(clazz==ShortBuffer.class) {
- return GLBuffers.SIZEOF_SHORT;
- }
- if(clazz==IntBuffer.class) {
- return GLBuffers.SIZEOF_INT;
- }
- if(clazz==FloatBuffer.class) {
- return GLBuffers.SIZEOF_FLOAT;
- }
- throw new GLException("Given Buffer Class not supported: "+clazz+":\n\t"+this);
- }
+ public final int getComponentType() { return componentType; }
+ public final int getComponentSize() { return componentSize; }
+
public final int getElementNumber() {
if(null==buffer) return 0;
return ( buffer.position()==0 ) ? ( buffer.limit() / components ) : ( buffer.position() / components ) ;
}
-
+ public final int getByteSize() {
+ if(null==buffer) return 0;
+ return ( buffer.position()==0 ) ? ( buffer.limit() * componentSize ) : ( buffer.position() * componentSize ) ;
+ }
+
public final boolean getNormalized() { return normalized; }
public final int getStride() { return stride; }
- public final Class getBufferClass() { return clazz; }
+ public final Class getBufferClass() { return componentClazz; }
public void destroy(GL gl) {
buffer = null;
vboName=0;
vboEnabled=false;
vboOffset=-1;
- valid = false;
+ alive = false;
}
public String toString() {
@@ -141,8 +148,8 @@ public class 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"+
@@ -152,7 +159,7 @@ public class GLArrayDataWrapper implements GLArrayData {
", vboTarget 0x"+Integer.toHexString(vboTarget)+
", vboEnabled "+vboEnabled+
", vboName "+vboName+
- ", valid "+valid+
+ ", alive "+alive+
"]";
}
@@ -210,7 +217,8 @@ public class GLArrayDataWrapper implements GLArrayData {
this.vboTarget = vboTarget;
}
- protected void init(String name, int index, int comps, int dataType, boolean normalized, int stride, Buffer data,
+ protected void init(String name, int index, int components, int componentType,
+ boolean normalized, int stride, Buffer data,
boolean isVertexAttribute,
int vboName, long vboOffset, int vboUsage, int vboTarget)
throws GLException
@@ -232,35 +240,38 @@ public class GLArrayDataWrapper implements GLArrayData {
throw new GLException("Invalid GPUBuffer target: 0x"+Integer.toHexString(vboTarget));
}
- this.dataType = dataType;
- this.clazz = getBufferClass(dataType);
- switch(dataType) {
+ this.componentType = componentType;
+ componentClazz = getBufferClass(componentType);
+ switch(componentType) {
case GL.GL_BYTE:
case GL.GL_UNSIGNED_BYTE:
case GL.GL_SHORT:
case GL.GL_UNSIGNED_SHORT:
- case GL2ES1.GL_FIXED:
+ case GL.GL_FIXED:
this.normalized = normalized;
break;
default:
this.normalized = false;
}
+ componentSize = GLBuffers.sizeOfGLType(componentType);
+ if(0 > componentSize) {
+ throw new GLException("Given componentType not supported: "+componentType+":\n\t"+this);
+ }
+ if(0 >= components) {
+ throw new GLException("Invalid number of components: " + components);
+ }
+ this.components = components;
- int bpc = getComponentSize();
- if(0<stride && stride<comps*bpc) {
- throw new GLException("stride ("+stride+") lower than component bytes, "+comps+" * "+bpc);
+ if(0<stride && stride<components*componentSize) {
+ throw new GLException("stride ("+stride+") lower than component bytes, "+components+" * "+componentSize);
}
- if(0<stride && stride%bpc!=0) {
- throw new GLException("stride ("+stride+") not a multiple of bpc "+bpc);
+ if(0<stride && stride%componentSize!=0) {
+ throw new GLException("stride ("+stride+") not a multiple of bpc "+componentSize);
}
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.strideB=(0==stride)?components*componentSize:stride;
+ this.strideL=(0==stride)?components:strideB/componentSize;
this.vboName=vboName;
this.vboEnabled=vboName>0;
this.vboOffset=vboOffset;
@@ -284,22 +295,23 @@ public class GLArrayDataWrapper implements GLArrayData {
}
this.vboUsage=vboUsage;
this.vboTarget=vboTarget;
- this.valid=true;
+ this.alive=true;
}
protected GLArrayDataWrapper() { }
- protected boolean valid;
+ protected boolean alive;
protected int index;
protected int location;
protected String name;
protected int components;
- protected int dataType;
+ protected int componentType;
+ protected Class componentClazz;
+ protected int componentSize;
protected boolean normalized;
protected int stride; // user given stride
protected int strideB; // stride in bytes
protected int strideL; // stride in logical components
- protected Class clazz;
protected Buffer buffer;
protected boolean isVertexAttribute;
diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
index be15dfb59..cb9e4cce5 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
@@ -2,6 +2,8 @@
package com.jogamp.opengl.util;
import com.jogamp.common.util.*;
+import com.jogamp.opengl.util.glsl.ShaderState;
+
import javax.media.opengl.*;
import javax.media.opengl.fixedfunc.*;
import java.nio.*;
@@ -36,7 +38,7 @@ public class ImmModeSink {
*
* @see #draw(GL, boolean)
* @see com.jogamp.opengl.util.glsl.ShaderState#glUseProgram(GL2ES2, boolean)
- * @see com.jogamp.opengl.util.glsl.ShaderState#getCurrent()
+ * @see com.jogamp.opengl.util.glsl.ShaderState#getCurrentShaderState()
*/
public static ImmModeSink createGLSL(GL gl, int glBufferUsage, int initialSize,
int vComps, int vDataType,
@@ -745,11 +747,11 @@ public class ImmModeSink {
}
public void enableBufferGLSL(GL gl, boolean enable) {
- GL2ES2 glsl = gl.getGL2ES2();
- com.jogamp.opengl.util.glsl.ShaderState st = com.jogamp.opengl.util.glsl.ShaderState.getCurrent();
+ ShaderState st = ShaderState.getShaderState(gl);
if(null==st) {
- throw new GLException("No ShaderState current");
- }
+ throw new GLException("No ShaderState in "+gl);
+ }
+ GL2ES2 glsl = gl.getGL2ES2();
if(enable) {
glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName);
@@ -760,35 +762,35 @@ public class ImmModeSink {
}
if(vComps>0) {
- st.glEnableVertexAttribArray(glsl, vArrayData.getName());
+ st.glEnableVertexAttribArray(glsl, vArrayData);
st.glVertexAttribPointer(glsl, vArrayData);
}
if(cComps>0) {
- st.glEnableVertexAttribArray(glsl, cArrayData.getName());
+ st.glEnableVertexAttribArray(glsl, cArrayData);
st.glVertexAttribPointer(glsl, cArrayData);
}
if(nComps>0) {
- st.glEnableVertexAttribArray(glsl, nArrayData.getName());
+ st.glEnableVertexAttribArray(glsl, nArrayData);
st.glVertexAttribPointer(glsl, nArrayData);
}
if(tComps>0) {
- st.glEnableVertexAttribArray(glsl, tArrayData.getName());
+ st.glEnableVertexAttribArray(glsl, tArrayData);
st.glVertexAttribPointer(glsl, tArrayData);
}
glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
} else {
if(vComps>0) {
- st.glDisableVertexAttribArray(glsl, vArrayData.getName());
+ st.glDisableVertexAttribArray(glsl, vArrayData);
}
if(cComps>0) {
- st.glDisableVertexAttribArray(glsl, cArrayData.getName());
+ st.glDisableVertexAttribArray(glsl, cArrayData);
}
if(nComps>0) {
- st.glDisableVertexAttribArray(glsl, nArrayData.getName());
+ st.glDisableVertexAttribArray(glsl, nArrayData);
}
if(tComps>0) {
- st.glDisableVertexAttribArray(glsl, tArrayData.getName());
+ st.glDisableVertexAttribArray(glsl, tArrayData);
}
}
}
@@ -860,26 +862,26 @@ public class ImmModeSink {
buffer.flip();
if(vComps>0) {
- vArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, vComps, vDataType, false,
- 0, vertexArray, 0, vOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
+ vArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_VERTEX_ARRAY, vComps, vDataType, false, 0,
+ vertexArray, 0, vOffset, GL.GL_STATIC_DRAW);
} else {
vArrayData = null;
}
if(cComps>0) {
- cArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_COLOR_ARRAY, cComps, cDataType, false,
- 0, colorArray, 0, cOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
+ cArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_COLOR_ARRAY, cComps, cDataType, false, 0,
+ colorArray, 0, cOffset, GL.GL_STATIC_DRAW);
} else {
cArrayData = null;
}
if(nComps>0) {
- nArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_NORMAL_ARRAY, nComps, nDataType, false,
- 0, normalArray, 0, nOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
+ nArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_NORMAL_ARRAY, nComps, nDataType, false, 0,
+ normalArray, 0, nOffset, GL.GL_STATIC_DRAW);
} else {
nArrayData = null;
}
if(tComps>0) {
- tArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_TEXTURE_COORD_ARRAY, tComps, tDataType, false,
- 0, textCoordArray, 0, tOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
+ tArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_TEXTURE_COORD_ARRAY, tComps, tDataType, false, 0,
+ textCoordArray, 0, tOffset, GL.GL_STATIC_DRAW);
} 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 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);
}
}
diff --git a/src/jogl/classes/javax/media/opengl/GLArrayData.java b/src/jogl/classes/javax/media/opengl/GLArrayData.java
index b449ce232..f375be623 100644
--- a/src/jogl/classes/javax/media/opengl/GLArrayData.java
+++ b/src/jogl/classes/javax/media/opengl/GLArrayData.java
@@ -124,14 +124,21 @@ public interface GLArrayData {
public int getComponentType();
/**
- * The components size in bytes
+ * The component's size in bytes
*/
public int getComponentSize();
/**
- * Return the number of elements.
+ * The current number of used elements.<br>
+ * In case the buffer's position is 0 (sealed, flipped), it's based on it's limit instead of it's position.
*/
public int getElementNumber();
+
+ /**
+ * The current number of used bytes.<br>
+ * In case the buffer's position is 0 (sealed, flipped), it's based on it's limit instead of it's position.
+ */
+ public int getByteSize();
/**
* True, if GL shall normalize fixed point data while converting
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 d0f8543a3..854d01fa6 100644
--- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java
+++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java
@@ -214,15 +214,15 @@ 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, -1, -1, -1, -1));
+ glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, false, stride, pointer, -1, -1, -1));
}
public void glVertexPointer(int size, int type, int stride, long pointer_buffer_offset) {
int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
if(vboName==0) {
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, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER));
+ glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, false, stride,
+ null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW));
}
public void glColorPointer(GLArrayData array) {
@@ -241,16 +241,16 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
fixedFunction.glColorPointer(gl, array);
}
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, -1, -1, -1, -1));
+ glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, false, stride,
+ pointer, -1, -1, -1));
}
public void glColorPointer(int size, int type, int stride, long pointer_buffer_offset) {
int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
if(vboName==0) {
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, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER));
+ glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, false, stride,
+ null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW));
}
public void glNormalPointer(GLArrayData array) {
@@ -272,16 +272,16 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
fixedFunction.glNormalPointer(gl, array);
}
public void glNormalPointer(int type, int stride, java.nio.Buffer pointer) {
- glNormalPointer(GLArrayDataWrapper.createFixed(gl, GL_NORMAL_ARRAY, 3, type, false,
- stride, pointer, -1, -1, -1, -1));
+ glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, false, stride,
+ pointer, -1, -1, -1));
}
public void glNormalPointer(int type, int stride, long pointer_buffer_offset) {
int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
if(vboName==0) {
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, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER));
+ glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, false, stride,
+ null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW));
}
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, -1, -1, -1, -1));
+ GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, false, stride, pointer, -1, -1, -1));
}
public void glTexCoordPointer(int size, int type, int stride, long pointer_buffer_offset) {
int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
@@ -309,8 +309,8 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
throw new GLException("no GL_ARRAY_BUFFER VBO bound");
}
glTexCoordPointer(
- GLArrayDataWrapper.createFixed(gl, GL_TEXTURE_COORD_ARRAY, size, type, false,
- stride, null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER) );
+ GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, false, stride,
+ null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW) );
}
public final String toString() {