From 8beeca6fcb1b5fe98e7c04a208fc208014f35c1f Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 13 Aug 2008 13:22:21 +0000 Subject: GLArrayData* - cleanup names and enable/disable code - bail out if components==0 in GL* impl. - add passing the VBO name for wrapping VBO server objects from the fixed function calls ShaderState: - reset: - only pass _enabled_ vertex attribute data in case of a reset - enable VBO in case of a wrapped VBO server object Fixed: - Added glMaterialf to GL (enables Angeles demo) - Working: Angeles on ES2 git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1755 232f8b59-042b-4e1e-8c03-345bb8c30851 --- .../sun/opengl/impl/glsl/GLSLArrayDataServer.java | 23 ++-- .../opengl/impl/glsl/fixed/FixedFuncPipeline.java | 10 +- src/classes/javax/media/opengl/GLArrayData.java | 44 +++++-- .../javax/media/opengl/GLArrayDataClient.java | 134 ++++++++++++--------- .../javax/media/opengl/GLArrayDataServer.java | 54 +++------ .../javax/media/opengl/glsl/ShaderState.java | 17 ++- .../javax/media/opengl/util/ImmModeSink.java | 80 ++++++------ 7 files changed, 192 insertions(+), 170 deletions(-) (limited to 'src') 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 { /** @@ -50,31 +56,51 @@ 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(01) + 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); } -- cgit v1.2.3