diff options
-rw-r--r-- | make/gl-if-CustomJavaCode-gl.java | 1 | ||||
-rw-r--r-- | make/gl-ignore-gl2_es12-special.cfg | 2 | ||||
-rw-r--r-- | make/gl-impl-CustomJavaCode-gl2.java | 22 | ||||
-rw-r--r-- | make/gl-impl-CustomJavaCode-gl2_es2.java | 5 | ||||
-rw-r--r-- | make/gl-impl-CustomJavaCode-gl2es12.java | 22 | ||||
-rwxr-xr-x | make/gl-impl-CustomJavaCode-gles1.java | 22 | ||||
-rwxr-xr-x | make/gl-impl-CustomJavaCode-gles2.java | 30 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/glsl/GLSLArrayDataServer.java | 23 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/glsl/fixed/FixedFuncPipeline.java | 10 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLArrayData.java | 44 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLArrayDataClient.java | 134 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLArrayDataServer.java | 54 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/glsl/ShaderState.java | 17 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/util/ImmModeSink.java | 80 |
14 files changed, 259 insertions, 207 deletions
diff --git a/make/gl-if-CustomJavaCode-gl.java b/make/gl-if-CustomJavaCode-gl.java index 2e1ee6b11..20cfe864c 100644 --- a/make/gl-if-CustomJavaCode-gl.java +++ b/make/gl-if-CustomJavaCode-gl.java @@ -115,6 +115,7 @@ public void glLightfv(int light, int pname, java.nio.FloatBuffer params); public void glLightfv(int light, int pname, float[] params, int params_offset); + public void glMaterialf(int face, int pname, float param); public void glMaterialfv(int face, int pname, java.nio.FloatBuffer params); public void glMaterialfv(int face, int pname, float[] params, int params_offset); diff --git a/make/gl-ignore-gl2_es12-special.cfg b/make/gl-ignore-gl2_es12-special.cfg index af200cd75..4849b0207 100644 --- a/make/gl-ignore-gl2_es12-special.cfg +++ b/make/gl-ignore-gl2_es12-special.cfg @@ -446,7 +446,7 @@ Ignore glLinkProgram #Ignore glLoadIdentity #Ignore glLoadMatrixf Ignore glLogicOp -Ignore glMaterialf +#Ignore glMaterialf #Ignore glMaterialfv Ignore glMaterialxv Ignore glMaterialxvOES diff --git a/make/gl-impl-CustomJavaCode-gl2.java b/make/gl-impl-CustomJavaCode-gl2.java index 71e3236b7..d9111f6b1 100644 --- a/make/gl-impl-CustomJavaCode-gl2.java +++ b/make/gl-impl-CustomJavaCode-gl2.java @@ -423,35 +423,39 @@ native private long dispatch_glMapBuffer(int target, int access, long glProcAddr } public void glVertexPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; if(array.isVBO()) { - glVertexPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getOffset()); + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); } else { - glVertexPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getBuffer()); + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); } } public void glColorPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; if(array.isVBO()) { - glColorPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getOffset()); + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); } else { - glColorPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getBuffer()); + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); } } public void glNormalPointer(GLArrayData array) { - if(array.getComponents()!=3) { + if(array.getComponentNumber()==0) return; + if(array.getComponentNumber()!=3) { throw new GLException("Only 3 components per normal allowed"); } if(array.isVBO()) { - glNormalPointer(array.getDataType(), array.getStride(), array.getOffset()); + glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); } else { - glNormalPointer(array.getDataType(), array.getStride(), array.getBuffer()); + glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); } } public void glTexCoordPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; if(array.isVBO()) { - glTexCoordPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getOffset()); + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); } else { - glTexCoordPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getBuffer()); + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); } } diff --git a/make/gl-impl-CustomJavaCode-gl2_es2.java b/make/gl-impl-CustomJavaCode-gl2_es2.java index aef836468..ff1360aeb 100644 --- a/make/gl-impl-CustomJavaCode-gl2_es2.java +++ b/make/gl-impl-CustomJavaCode-gl2_es2.java @@ -261,11 +261,12 @@ } public void glVertexAttribPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; if(array.isVBO()) { - glVertexAttribPointer(array.getLocation(), array.getComponents(), array.getDataType(), + glVertexAttribPointer(array.getLocation(), array.getComponentNumber(), array.getComponentType(), array.getNormalized(), array.getStride(), array.getOffset()); } else { - glVertexAttribPointer(array.getLocation(), array.getComponents(), array.getDataType(), + glVertexAttribPointer(array.getLocation(), array.getComponentNumber(), array.getComponentType(), array.getNormalized(), array.getStride(), array.getBuffer()); } } diff --git a/make/gl-impl-CustomJavaCode-gl2es12.java b/make/gl-impl-CustomJavaCode-gl2es12.java index eaea3afd6..643443b91 100644 --- a/make/gl-impl-CustomJavaCode-gl2es12.java +++ b/make/gl-impl-CustomJavaCode-gl2es12.java @@ -395,34 +395,38 @@ native private long dispatch_glMapBuffer(int target, int access, long glProcAddr } public void glVertexPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; if(array.isVBO()) { - glVertexPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getOffset()); + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); } else { - glVertexPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getBuffer()); + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); } } public void glColorPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; if(array.isVBO()) { - glColorPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getOffset()); + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); } else { - glColorPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getBuffer()); + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); } } public void glNormalPointer(GLArrayData array) { - if(array.getComponents()!=3) { + if(array.getComponentNumber()==0) return; + if(array.getComponentNumber()!=3) { throw new GLException("Only 3 components per normal allowed"); } if(array.isVBO()) { - glNormalPointer(array.getDataType(), array.getStride(), array.getOffset()); + glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); } else { - glNormalPointer(array.getDataType(), array.getStride(), array.getBuffer()); + glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); } } public void glTexCoordPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; if(array.isVBO()) { - glTexCoordPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getOffset()); + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); } else { - glTexCoordPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getBuffer()); + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); } } diff --git a/make/gl-impl-CustomJavaCode-gles1.java b/make/gl-impl-CustomJavaCode-gles1.java index f42ede8b3..b2c078518 100755 --- a/make/gl-impl-CustomJavaCode-gles1.java +++ b/make/gl-impl-CustomJavaCode-gles1.java @@ -316,35 +316,39 @@ native private long dispatch_glMapBuffer(int target, int access, long glProcAddr } public void glVertexPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; if(array.isVBO()) { - glVertexPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getOffset()); + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); } else { - glVertexPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getBuffer()); + glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); } } public void glColorPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; if(array.isVBO()) { - glColorPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getOffset()); + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); } else { - glColorPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getBuffer()); + glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); } } public void glNormalPointer(GLArrayData array) { - if(array.getComponents()!=3) { + if(array.getComponentNumber()==0) return; + if(array.getComponentNumber()!=3) { throw new GLException("Only 3 components per normal allowed"); } if(array.isVBO()) { - glNormalPointer(array.getDataType(), array.getStride(), array.getOffset()); + glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset()); } else { - glNormalPointer(array.getDataType(), array.getStride(), array.getBuffer()); + glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer()); } } public void glTexCoordPointer(GLArrayData array) { + if(array.getComponentNumber()==0) return; if(array.isVBO()) { - glTexCoordPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getOffset()); + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset()); } else { - glTexCoordPointer(array.getComponents(), array.getDataType(), array.getStride(), array.getBuffer()); + glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer()); } } diff --git a/make/gl-impl-CustomJavaCode-gles2.java b/make/gl-impl-CustomJavaCode-gles2.java index a3c274f9a..895d6865e 100755 --- a/make/gl-impl-CustomJavaCode-gles2.java +++ b/make/gl-impl-CustomJavaCode-gles2.java @@ -526,6 +526,9 @@ public void glMaterialfv(int face, int pname, java.nio.FloatBuffer params) { public void glMaterialfv(int face, int pname, float[] params, int params_offset) { glMaterialfv(face, pname, BufferUtil.newFloatBuffer(params, params_offset)); } +public void glMaterialf(int face, int pname, float param) { + glMaterialfv(face, pname, BufferUtil.newFloatBuffer(new float[] { param })); +} public void glShadeModel(int mode) { if(!fixedFunctionShaderActive) { throw new GLUnsupportedException("not enabled"); @@ -592,7 +595,11 @@ public void glVertexPointer(int size, int type, int stride, java.nio.Buffer poin glVertexPointer(GLArrayDataClient.createFixed(GL.GL_VERTEX_ARRAY, null, size, type, false, stride, pointer)); } public void glVertexPointer(int size, int type, int stride, long pointer_buffer_offset) { - glVertexPointer(GLArrayDataServer.createFixed(GL.GL_VERTEX_ARRAY, null, size, type, false, stride, pointer_buffer_offset)); + int vboName = bufferStateTracker.getBoundBufferObject(GL.GL_ARRAY_BUFFER, this); + if(vboName==0) { + throw new GLException("no GL_ARRAY_BUFFER VBO bound"); + } + glVertexPointer(GLArrayDataServer.createFixed(GL.GL_VERTEX_ARRAY, null, size, type, false, stride, pointer_buffer_offset, vboName)); } public void glColorPointer(GLArrayData array) { @@ -613,14 +620,18 @@ public void glColorPointer(int size, int type, int stride, java.nio.Buffer point glColorPointer(GLArrayDataClient.createFixed(GL.GL_COLOR_ARRAY, null, size, type, false, stride, pointer)); } public void glColorPointer(int size, int type, int stride, long pointer_buffer_offset) { - glColorPointer(GLArrayDataServer.createFixed(GL.GL_COLOR_ARRAY, null, size, type, false, stride, pointer_buffer_offset)); + int vboName = bufferStateTracker.getBoundBufferObject(GL.GL_ARRAY_BUFFER, this); + if(vboName==0) { + throw new GLException("no GL_ARRAY_BUFFER VBO bound"); + } + glColorPointer(GLArrayDataServer.createFixed(GL.GL_COLOR_ARRAY, null, size, type, false, stride, pointer_buffer_offset, vboName)); } public void glNormalPointer(GLArrayData array) { if(!fixedFunctionShaderActive) { throw new GLUnsupportedException("Fixed function not enabled"); } - if(array.getComponents()!=3) { + if(array.getComponentNumber()!=3) { throw new GLException("Only 3 components per normal allowed"); } if(array.isVBO()) { @@ -637,7 +648,11 @@ public void glNormalPointer(int type, int stride, java.nio.Buffer pointer) { glNormalPointer(GLArrayDataClient.createFixed(GL.GL_NORMAL_ARRAY, null, 3, type, false, stride, pointer)); } public void glNormalPointer(int type, int stride, long pointer_buffer_offset) { - glNormalPointer(GLArrayDataServer.createFixed(GL.GL_NORMAL_ARRAY, null, 3, type, false, stride, pointer_buffer_offset)); + int vboName = bufferStateTracker.getBoundBufferObject(GL.GL_ARRAY_BUFFER, this); + if(vboName==0) { + throw new GLException("no GL_ARRAY_BUFFER VBO bound"); + } + glNormalPointer(GLArrayDataServer.createFixed(GL.GL_NORMAL_ARRAY, null, 3, type, false, stride, pointer_buffer_offset, vboName)); } public void glTexCoordPointer(GLArrayData array) { @@ -659,10 +674,11 @@ public void glTexCoordPointer(int size, int type, int stride, java.nio.Buffer po GLArrayDataClient.createFixed(GL.GL_TEXTURE_COORD_ARRAY, null, size, type, false, stride, pointer)); } public void glTexCoordPointer(int size, int type, int stride, long pointer_buffer_offset) { - if(!fixedFunctionShaderActive) { - throw new GLUnsupportedException("Fixed function not enabled"); + int vboName = bufferStateTracker.getBoundBufferObject(GL.GL_ARRAY_BUFFER, this); + if(vboName==0) { + throw new GLException("no GL_ARRAY_BUFFER VBO bound"); } glTexCoordPointer( - GLArrayDataServer.createFixed(GL.GL_TEXTURE_COORD_ARRAY, null, size, type, false, stride, pointer_buffer_offset) ); + GLArrayDataServer.createFixed(GL.GL_TEXTURE_COORD_ARRAY, null, size, type, false, stride, pointer_buffer_offset, vboName) ); } diff --git a/src/classes/com/sun/opengl/impl/glsl/GLSLArrayDataServer.java b/src/classes/com/sun/opengl/impl/glsl/GLSLArrayDataServer.java index b56c2dc92..14613227e 100644 --- a/src/classes/com/sun/opengl/impl/glsl/GLSLArrayDataServer.java +++ b/src/classes/com/sun/opengl/impl/glsl/GLSLArrayDataServer.java @@ -22,6 +22,11 @@ public class GLSLArrayDataServer extends GLArrayDataServer { init(name, -1, comps, dataType, normalized, 0, null, 0, initialSize, glBufferUsage, true); } + protected final void passVertexAttribPointer(GL2ES2 gl, ShaderState st) { + if ( ! st.glVertexAttribPointer(gl, this) ) { + throw new RuntimeException("Internal Error"); + } + } protected void enableBufferGLImpl(GL gl, boolean enable) { GL2ES2 glsl = gl.getGL2ES2(); @@ -34,23 +39,27 @@ public class GLSLArrayDataServer extends GLArrayDataServer { if(!st.glEnableVertexAttribArray(glsl, name)) { throw new RuntimeException("Internal Error"); } - bufferEnabled = true; if(vboUsage) { gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName); if(!bufferWritten) { - gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * getBufferCompSize(), buffer, glBufferUsage); + if(null!=buffer) { + gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * getComponentSize(), buffer, glBufferUsage); + } + bufferWritten=true; } + passVertexAttribPointer(glsl, st); + } else if(null!=buffer) { + passVertexAttribPointer(glsl, st); + bufferWritten=true; } - if ( ! st.glVertexAttribPointer(glsl, this) ) { - throw new RuntimeException("Internal Error"); - } - bufferWritten=true; } else { + if(vboUsage) { + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + } if(!st.glDisableVertexAttribArray(glsl, name)) { throw new RuntimeException("Internal Error"); } - bufferEnabled = false; } } diff --git a/src/classes/com/sun/opengl/impl/glsl/fixed/FixedFuncPipeline.java b/src/classes/com/sun/opengl/impl/glsl/fixed/FixedFuncPipeline.java index f9798f48a..27b3aeeac 100644 --- a/src/classes/com/sun/opengl/impl/glsl/fixed/FixedFuncPipeline.java +++ b/src/classes/com/sun/opengl/impl/glsl/fixed/FixedFuncPipeline.java @@ -26,14 +26,6 @@ public class FixedFuncPipeline { return shaderState; } - public void enableLighting(boolean enable) { - lightingEnabled=enable; - } - - public boolean lightingEnabled() { - return lightingEnabled; - } - public int getActiveTextureUnit() { return activeTextureUnit; } @@ -318,7 +310,7 @@ public class FixedFuncPipeline { } else { shaderState.attachShaderProgram(gl, shaderProgramColor); } - } + } if(DEBUG) { System.out.println("validate: "+this); } diff --git a/src/classes/javax/media/opengl/GLArrayData.java b/src/classes/javax/media/opengl/GLArrayData.java index b13b0752b..8fe5194d1 100644 --- a/src/classes/javax/media/opengl/GLArrayData.java +++ b/src/classes/javax/media/opengl/GLArrayData.java @@ -3,6 +3,12 @@ package javax.media.opengl; import java.nio.*; +/** + * + * The total number of bytes hold by the referenced buffer is: + * getComponentSize()* getComponentNumber() * getElementNumber() + * + */ public interface GLArrayData { /** @@ -51,30 +57,50 @@ public interface GLArrayData { public boolean sealed(); /** + * Determines wheather the data is server side (VBO), + * or a client side array (false). + */ + public boolean isVBO(); + + /** * The offset, if it's an VBO, otherwise -1 */ public long getOffset(); /** + * The VBO name, if it's an VBO, otherwise -1 + */ + public int getVBOName(); + + /** + * The VBO buffer usage, if it's an VBO, otherwise -1 + */ + public int getBufferUsage(); + + /** * The Buffer holding the data, may be null in case of VBO */ public Buffer getBuffer(); /** - * Determines wheather the data is server side (VBO), - * or a client side array (false). + * The number of components per element */ - public boolean isVBO(); + public int getComponentNumber(); /** - * The number of components per element + * The component's GL data type, ie. GL_FLOAT */ - public int getComponents(); + public int getComponentType(); /** - * The GL data type of the components, ie. GL_FLOAT + * The components size in bytes */ - public int getDataType(); + public int getComponentSize(); + + /** + * Return the number of elements. + */ + public int getElementNumber(); /** * True, if GL shall normalize fixed point data while converting @@ -88,10 +114,6 @@ public interface GLArrayData { */ public int getStride(); - public int getVerticeNumber(); - - public int getBufferCompSize(); - public String toString(); // diff --git a/src/classes/javax/media/opengl/GLArrayDataClient.java b/src/classes/javax/media/opengl/GLArrayDataClient.java index 5048e15c3..d1dec974c 100644 --- a/src/classes/javax/media/opengl/GLArrayDataClient.java +++ b/src/classes/javax/media/opengl/GLArrayDataClient.java @@ -63,40 +63,59 @@ public class GLArrayDataClient implements GLArrayData { // Data read access // - public boolean isVertexAttribute() { return isVertexAttribute; } + public final boolean isVertexAttribute() { return isVertexAttribute; } - public int getIndex() { return index; } + public final int getIndex() { return index; } - public int getLocation() { return location; } + public final int getLocation() { return location; } - public void setLocation(int v) { location = v; } + public final void setLocation(int v) { location = v; } - public String getName() { return name; } + public final String getName() { return name; } public long getOffset() { return -1; } - public Buffer getBuffer() { return buffer; } + public final Buffer getBuffer() { return buffer; } public boolean isVBO() { return false; } - public int getComponents() { return components; } + public int getVBOName() { return -1; } - public int getDataType() { return dataType; } + public int getBufferUsage() { return -1; } - public boolean getNormalized() { return normalized; } + public final int getComponentNumber() { return components; } - public int getStride() { return stride; } + public final int getComponentType() { return dataType; } - public boolean sealed() { return sealed; } - - public Class getBufferClass() { - return clazz; + public final int getComponentSize() { + if(clazz==ByteBuffer.class) { + return BufferUtil.SIZEOF_BYTE; + } + if(clazz==ShortBuffer.class) { + return BufferUtil.SIZEOF_SHORT; + } + if(clazz==IntBuffer.class) { + return BufferUtil.SIZEOF_INT; + } + if(clazz==FloatBuffer.class) { + return BufferUtil.SIZEOF_FLOAT; + } + throw new GLException("Given Buffer Class not supported: "+clazz+":\n\t"+this); } - public int getVerticeNumber() { - return ( buffer!=null ) ? ( buffer.limit() / components ) : 0 ; + public final int getElementNumber() { + if(null==buffer) return 0; + return ( sealed ) ? ( buffer.limit() / components ) : ( buffer.position() / components ) ; } + public final boolean getNormalized() { return normalized; } + + public final int getStride() { return stride; } + + public final boolean sealed() { return sealed; } + + public final Class getBufferClass() { return clazz; } + // // Data and GL state modification .. // @@ -133,12 +152,13 @@ public class GLArrayDataClient implements GLArrayData { { if(enable) { checkSeal(true); - if(!bufferEnabled && null!=buffer) { + if(null!=buffer) { buffer.rewind(); - enableBufferGLImpl(gl, true); } - } else if(bufferEnabled) { - enableBufferGLImpl(gl, false); + } + if(bufferEnabled != enable && components>0) { + enableBufferGLImpl(gl, enable); + bufferEnabled = enable; } } @@ -293,7 +313,7 @@ public class GLArrayDataClient implements GLArrayData { ", isVertexAttribute "+isVertexAttribute+ ", dataType "+dataType+ ", bufferClazz "+clazz+ - ", vertices "+getVerticeNumber()+ + ", elements "+getElementNumber()+ ", components "+components+ ", stride "+stride+"u "+strideB+"b "+strideL+"c"+ ", initialSize "+initialSize+ @@ -321,22 +341,6 @@ public class GLArrayDataClient implements GLArrayData { } } - public final int getBufferCompSize() { - if(clazz==ByteBuffer.class) { - return BufferUtil.SIZEOF_BYTE; - } - if(clazz==ShortBuffer.class) { - return BufferUtil.SIZEOF_SHORT; - } - if(clazz==IntBuffer.class) { - return BufferUtil.SIZEOF_INT; - } - if(clazz==FloatBuffer.class) { - return BufferUtil.SIZEOF_FLOAT; - } - throw new GLException("Given Buffer Class not supported: "+clazz+":\n\t"+this); - } - // non public matters protected final boolean growBufferIfNecessary(int spare) { @@ -424,7 +428,7 @@ public class GLArrayDataClient implements GLArrayData { this.normalized = false; } - int bpc = getBufferCompSize(); + int bpc = getComponentSize(); if(0<stride && stride<comps*bpc) { throw new GLException("stride ("+stride+") lower than component bytes, "+comps+" * "+bpc); } @@ -446,31 +450,47 @@ public class GLArrayDataClient implements GLArrayData { } } + protected final void passArrayPointer(GL gl) { + switch(index) { + case GL.GL_VERTEX_ARRAY: + gl.glVertexPointer(this); + break; + case GL.GL_NORMAL_ARRAY: + gl.glNormalPointer(this); + break; + case GL.GL_COLOR_ARRAY: + gl.glColorPointer(this); + break; + case GL.GL_TEXTURE_COORD_ARRAY: + gl.glTexCoordPointer(this); + break; + default: + throw new GLException("invalid glArrayIndex: "+index+":\n\t"+this); + } + } + protected void enableBufferGLImpl(GL gl, boolean enable) { if(enable) { gl.glEnableClientState(index); - bufferEnabled = true; - - switch(index) { - case GL.GL_VERTEX_ARRAY: - gl.glVertexPointer(this); - break; - case GL.GL_NORMAL_ARRAY: - gl.glNormalPointer(this); - break; - case GL.GL_COLOR_ARRAY: - gl.glColorPointer(this); - break; - case GL.GL_TEXTURE_COORD_ARRAY: - gl.glTexCoordPointer(this); - break; - default: - throw new GLException("invalid glArrayIndex: "+index+":\n\t"+this); + + if(isVBO()) { + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, getVBOName()); + if(!bufferWritten) { + if(null!=buffer) { + gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * getComponentSize(), buffer, getBufferUsage()); + } + bufferWritten=true; + } + passArrayPointer(gl); + } else if(null!=buffer) { + passArrayPointer(gl); + bufferWritten=true; } - bufferWritten=true; } else { + if(isVBO()) { + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + } gl.glDisableClientState(index); - bufferEnabled = false; } } diff --git a/src/classes/javax/media/opengl/GLArrayDataServer.java b/src/classes/javax/media/opengl/GLArrayDataServer.java index d4f2604fd..44d4a2ff7 100644 --- a/src/classes/javax/media/opengl/GLArrayDataServer.java +++ b/src/classes/javax/media/opengl/GLArrayDataServer.java @@ -67,20 +67,25 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData * Create a VBOBuffer object, using a predefined fixed function array index * and starting with a given Buffer offset incl it's stride * - * This object can neither be enabled, nor rendered, since no knowledge of the buffer - * itself is available. This object is only a VBO variant of GLArrayData - * and cannot being drawn. + * The object will be created in a sealed state, + * where the data has been written (previously). + * + * This object can be enabled, but since no knowledge of the orginal client data is available, + * we cannot send it down again. * * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int) */ public static GLArrayDataServer createFixed(int index, String name, int comps, int dataType, boolean normalized, - int stride, long bufferOffset) + int stride, long bufferOffset, int vboName) throws GLException { GLProfile.isValidateArrayDataType(index, comps, dataType, false, true); GLArrayDataServer ads = new GLArrayDataServer(); ads.init(name, index, comps, dataType, normalized, stride, null, bufferOffset, 0, -1, false); + ads.vboName = vboName; + ads.bufferWritten = true; + ads.sealed = true; return ads; } @@ -130,9 +135,11 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData // Data matters GLArrayData // - public long getOffset() { return vboUsage?bufferOffset:-1; } + public final long getOffset() { return vboUsage?bufferOffset:-1; } + + public final int getVBOName() { return vboUsage?vboName:-1; } - public boolean isVBO() { return vboUsage; } + public final boolean isVBO() { return vboUsage; } // // Data and GL state modification .. @@ -173,7 +180,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData ", isVertexAttribute "+isVertexAttribute+ ", dataType "+dataType+ ", bufferClazz "+clazz+ - ", vertices "+getVerticeNumber()+ + ", elements "+getElementNumber()+ ", components "+components+ ", stride "+stride+"u "+strideB+"b "+strideL+"c"+ ", initialSize "+initialSize+ @@ -215,39 +222,6 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData this.vboName = 0; } - protected void enableBufferGLImpl(GL gl, boolean enable) { - if(enable) { - gl.glEnableClientState(index); - bufferEnabled = true; - - if(vboUsage) { - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName); - if(!bufferWritten) { - gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * getBufferCompSize(), buffer, glBufferUsage); - } - } - switch(index) { - case GL.GL_VERTEX_ARRAY: - gl.glVertexPointer(this); - break; - case GL.GL_NORMAL_ARRAY: - gl.glNormalPointer(this); - break; - case GL.GL_COLOR_ARRAY: - gl.glColorPointer(this); - break; - case GL.GL_TEXTURE_COORD_ARRAY: - gl.glTexCoordPointer(this); - break; - default: - throw new GLException("invalid glArrayIndex: "+index+":\n\t"+this); - } - bufferWritten=true; - } else { - gl.glDisableClientState(index); - bufferEnabled = false; - } - } protected void init_vbo(GL gl) { if(vboUsage && vboName==0) { int[] tmp = new int[1]; diff --git a/src/classes/javax/media/opengl/glsl/ShaderState.java b/src/classes/javax/media/opengl/glsl/ShaderState.java index f17e844e8..3d4983152 100644 --- a/src/classes/javax/media/opengl/glsl/ShaderState.java +++ b/src/classes/javax/media/opengl/glsl/ShaderState.java @@ -412,7 +412,7 @@ public class ShaderState { } /** - * Reset all previously mapped vertex attribute data, + * Reset all previously enabled mapped vertex attribute data, * incl enabling them * * @throws GLException is the program is not in use @@ -430,11 +430,16 @@ public class ShaderState { attribMap2Idx.clear(); for(Iterator iter = enabledVertexAttribArraySet.iterator(); iter.hasNext(); ) { - glEnableVertexAttribArray(gl, (String) iter.next()); - } - - for(Iterator iter = vertexAttribMap2Data.values().iterator(); iter.hasNext(); ) { - glVertexAttribPointer(gl, (GLArrayData) iter.next()); + String name = (String) iter.next(); + glEnableVertexAttribArray(gl, name); + GLArrayData data = getVertexAttribPointer(name); + + if( data.isVBO() && data.getBuffer()==null ) { + // make sure the VBO is bound again + // in case this is only a VBO wrapped object (no buffer) + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, data.getVBOName()); + } + glVertexAttribPointer(gl, data); } } diff --git a/src/classes/javax/media/opengl/util/ImmModeSink.java b/src/classes/javax/media/opengl/util/ImmModeSink.java index df74db5cc..04173cb6f 100644 --- a/src/classes/javax/media/opengl/util/ImmModeSink.java +++ b/src/classes/javax/media/opengl/util/ImmModeSink.java @@ -406,7 +406,7 @@ public class ImmModeSink { if (vertexVBO.getBuffer()!=null) { if(null==indices) { - gl.glDrawArrays(mode, 0, vertexVBO.getVerticeNumber()); + gl.glDrawArrays(mode, 0, vertexVBO.getElementNumber()); } else { Class clazz = indices.getClass(); int type=-1; @@ -437,16 +437,16 @@ public class ImmModeSink { protected void glVertex2f(float x, float y) { checkSeal(false); vertexVBO.putf(x); - if(vertexVBO.getComponents()>1) + if(vertexVBO.getComponentNumber()>1) vertexVBO.putf(y); vertexVBO.padding(2); } protected void glVertex3f(float x, float y, float z) { checkSeal(false); vertexVBO.putf(x); - if(vertexVBO.getComponents()>1) + if(vertexVBO.getComponentNumber()>1) vertexVBO.putf(y); - if(vertexVBO.getComponents()>2) + if(vertexVBO.getComponentNumber()>2) vertexVBO.putf(z); vertexVBO.padding(3); } @@ -458,9 +458,9 @@ public class ImmModeSink { protected void glNormal3f(float x, float y, float z) { checkSeal(false); normalVBO.putf(x); - if(normalVBO.getComponents()>1) + if(normalVBO.getComponentNumber()>1) normalVBO.putf(y); - if(normalVBO.getComponents()>2) + if(normalVBO.getComponentNumber()>2) normalVBO.putf(z); normalVBO.padding(3); } @@ -472,20 +472,20 @@ public class ImmModeSink { protected void glColor3f(float x, float y, float z) { checkSeal(false); colorVBO.putf(x); - if(colorVBO.getComponents()>1) + if(colorVBO.getComponentNumber()>1) colorVBO.putf(y); - if(colorVBO.getComponents()>2) + if(colorVBO.getComponentNumber()>2) colorVBO.putf(z); colorVBO.padding(3); } protected void glColor4f(float x, float y, float z, float a) { checkSeal(false); colorVBO.putf(x); - if(colorVBO.getComponents()>1) + if(colorVBO.getComponentNumber()>1) colorVBO.putf(y); - if(colorVBO.getComponents()>2) + if(colorVBO.getComponentNumber()>2) colorVBO.putf(z); - if(colorVBO.getComponents()>3) + if(colorVBO.getComponentNumber()>3) colorVBO.putf(a); colorVBO.padding(4); } @@ -497,16 +497,16 @@ public class ImmModeSink { protected void glTexCoord2f(float x, float y) { checkSeal(false); texcoordVBO.putf(x); - if(texcoordVBO.getComponents()>1) + if(texcoordVBO.getComponentNumber()>1) texcoordVBO.putf(y); texcoordVBO.padding(2); } protected void glTexCoord3f(float x, float y, float z) { checkSeal(false); texcoordVBO.putf(x); - if(texcoordVBO.getComponents()>1) + if(texcoordVBO.getComponentNumber()>1) texcoordVBO.putf(y); - if(texcoordVBO.getComponents()>2) + if(texcoordVBO.getComponentNumber()>2) texcoordVBO.putf(z); texcoordVBO.padding(3); } @@ -514,16 +514,16 @@ public class ImmModeSink { protected void glVertex2s(short x, short y) { checkSeal(false); vertexVBO.puts(x); - if(vertexVBO.getComponents()>1) + if(vertexVBO.getComponentNumber()>1) vertexVBO.puts(y); vertexVBO.padding(2); } protected void glVertex3s(short x, short y, short z) { checkSeal(false); vertexVBO.puts(x); - if(vertexVBO.getComponents()>1) + if(vertexVBO.getComponentNumber()>1) vertexVBO.puts(y); - if(vertexVBO.getComponents()>2) + if(vertexVBO.getComponentNumber()>2) vertexVBO.puts(z); vertexVBO.padding(3); } @@ -531,9 +531,9 @@ public class ImmModeSink { protected void glNormal3s(short x, short y, short z) { checkSeal(false); normalVBO.puts(x); - if(normalVBO.getComponents()>1) + if(normalVBO.getComponentNumber()>1) normalVBO.puts(y); - if(normalVBO.getComponents()>2) + if(normalVBO.getComponentNumber()>2) normalVBO.puts(z); normalVBO.padding(3); } @@ -541,20 +541,20 @@ public class ImmModeSink { protected void glColor3s(short x, short y, short z) { checkSeal(false); colorVBO.puts(x); - if(colorVBO.getComponents()>1) + if(colorVBO.getComponentNumber()>1) colorVBO.puts(y); - if(colorVBO.getComponents()>2) + if(colorVBO.getComponentNumber()>2) colorVBO.puts(z); colorVBO.padding(3); } protected void glColor4s(short x, short y, short z, short a) { checkSeal(false); colorVBO.puts(x); - if(colorVBO.getComponents()>1) + if(colorVBO.getComponentNumber()>1) colorVBO.puts(y); - if(colorVBO.getComponents()>2) + if(colorVBO.getComponentNumber()>2) colorVBO.puts(z); - if(colorVBO.getComponents()>3) + if(colorVBO.getComponentNumber()>3) colorVBO.puts(a); colorVBO.padding(4); } @@ -562,16 +562,16 @@ public class ImmModeSink { protected void glTexCoord2s(short x, short y) { checkSeal(false); texcoordVBO.puts(x); - if(texcoordVBO.getComponents()>1) + if(texcoordVBO.getComponentNumber()>1) texcoordVBO.puts(y); texcoordVBO.padding(2); } protected void glTexCoord3s(short x, short y, short z) { checkSeal(false); texcoordVBO.puts(x); - if(texcoordVBO.getComponents()>1) + if(texcoordVBO.getComponentNumber()>1) texcoordVBO.puts(y); - if(texcoordVBO.getComponents()>2) + if(texcoordVBO.getComponentNumber()>2) texcoordVBO.puts(z); texcoordVBO.padding(3); } @@ -579,16 +579,16 @@ public class ImmModeSink { protected void glVertex2b(byte x, byte y) { checkSeal(false); vertexVBO.putb(x); - if(vertexVBO.getComponents()>1) + if(vertexVBO.getComponentNumber()>1) vertexVBO.putb(y); vertexVBO.padding(2); } protected void glVertex3b(byte x, byte y, byte z) { checkSeal(false); vertexVBO.putb(x); - if(vertexVBO.getComponents()>1) + if(vertexVBO.getComponentNumber()>1) vertexVBO.putb(y); - if(vertexVBO.getComponents()>2) + if(vertexVBO.getComponentNumber()>2) vertexVBO.putb(z); vertexVBO.padding(3); } @@ -596,9 +596,9 @@ public class ImmModeSink { protected void glNormal3b(byte x, byte y, byte z) { checkSeal(false); normalVBO.putb(x); - if(normalVBO.getComponents()>1) + if(normalVBO.getComponentNumber()>1) normalVBO.putb(y); - if(normalVBO.getComponents()>2) + if(normalVBO.getComponentNumber()>2) normalVBO.putb(z); normalVBO.padding(3); } @@ -606,27 +606,27 @@ public class ImmModeSink { protected void glColor3b(byte x, byte y, byte z) { checkSeal(false); colorVBO.putb(x); - if(colorVBO.getComponents()>1) + if(colorVBO.getComponentNumber()>1) colorVBO.putb(y); - if(colorVBO.getComponents()>2) + if(colorVBO.getComponentNumber()>2) colorVBO.putb(z); colorVBO.padding(3); } protected void glColor4b(byte x, byte y, byte z, byte a) { checkSeal(false); colorVBO.putb(x); - if(colorVBO.getComponents()>1) + if(colorVBO.getComponentNumber()>1) colorVBO.putb(y); - if(colorVBO.getComponents()>2) + if(colorVBO.getComponentNumber()>2) colorVBO.putb(z); - if(colorVBO.getComponents()>3) + if(colorVBO.getComponentNumber()>3) colorVBO.putb(a); colorVBO.padding(4); } protected void glTexCoord2b(byte x, byte y) { checkSeal(false); texcoordVBO.putb(x); - if(texcoordVBO.getComponents()>1) + if(texcoordVBO.getComponentNumber()>1) texcoordVBO.putb(y); texcoordVBO.padding(2); } @@ -634,9 +634,9 @@ public class ImmModeSink { protected void glTexCoord3b(byte x, byte y, byte z) { checkSeal(false); texcoordVBO.putb(x); - if(texcoordVBO.getComponents()>1) + if(texcoordVBO.getComponentNumber()>1) texcoordVBO.putb(y); - if(texcoordVBO.getComponents()>2) + if(texcoordVBO.getComponentNumber()>2) texcoordVBO.putb(z); texcoordVBO.padding(3); } |