diff options
author | Sven Gothel <[email protected]> | 2008-08-13 13:22:21 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2008-08-13 13:22:21 +0000 |
commit | 8beeca6fcb1b5fe98e7c04a208fc208014f35c1f (patch) | |
tree | 033fabe8cf8389aae3ba41b31366b50c661ef13a /src/classes/javax/media | |
parent | fc37b49b6890531ed87b45956c7d369b46c4fd88 (diff) |
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
Diffstat (limited to 'src/classes/javax/media')
-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 |
5 files changed, 175 insertions, 154 deletions
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); } |