diff options
Diffstat (limited to 'src/classes/javax')
4 files changed, 77 insertions, 80 deletions
diff --git a/src/classes/javax/media/opengl/GLArrayData.java b/src/classes/javax/media/opengl/GLArrayData.java index 096506242..bdffa3c44 100644 --- a/src/classes/javax/media/opengl/GLArrayData.java +++ b/src/classes/javax/media/opengl/GLArrayData.java @@ -83,6 +83,16 @@ public interface GLArrayData { public Buffer getBuffer(); /** + * Is the buffer written to the GPU ? + */ + public boolean isBufferWritten(); + + /** + * Marks the buffer written to the GPU + */ + public void setBufferWritten(boolean written); + + /** * The number of components per element */ public int getComponentNumber(); diff --git a/src/classes/javax/media/opengl/GLArrayDataClient.java b/src/classes/javax/media/opengl/GLArrayDataClient.java index a8da6c0a1..2a5b48506 100644 --- a/src/classes/javax/media/opengl/GLArrayDataClient.java +++ b/src/classes/javax/media/opengl/GLArrayDataClient.java @@ -2,13 +2,23 @@ package javax.media.opengl; import javax.media.opengl.util.*; -import com.sun.opengl.impl.GLReflection; +import com.sun.opengl.impl.*; +import com.sun.opengl.impl.glsl.*; import java.nio.*; public class GLArrayDataClient implements GLArrayData { /** + * The OpenGL ES emulation on the PC probably has a buggy VBO implementation, + * where we have to 'refresh' the VertexPointer or VertexAttribArray after each + * BindBuffer ! + * + * This should not be necessary on proper native implementations. + */ + public static final boolean hasVBOBug = (SystemUtil.getenv("JOGL_VBO_BUG") != null); + + /** * @arg index The GL array index * @arg name The optional custom name for the GL array index, maybe null. * If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'. @@ -25,7 +35,8 @@ public class GLArrayDataClient implements GLArrayData { { GLProfile.isValidateArrayDataType(index, comps, dataType, false, true); GLArrayDataClient adc = new GLArrayDataClient(); - adc.init(name, index, comps, dataType, normalized, 0, null, initialSize, false); + GLArrayHandler glArrayHandler = new GLFixedArrayHandler(adc); + adc.init(name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler); return adc; } @@ -35,27 +46,36 @@ public class GLArrayDataClient implements GLArrayData { { GLProfile.isValidateArrayDataType(index, comps, dataType, false, true); GLArrayDataClient adc = new GLArrayDataClient(); - adc.init(name, index, comps, dataType, normalized, stride, buffer, comps*comps, false); + GLArrayHandler glArrayHandler = new GLFixedArrayHandler(adc); + adc.init(name, index, comps, dataType, normalized, stride, buffer, comps*comps, false, glArrayHandler); return adc; } - public static GLArrayDataClient createGLSL(int index, String name, int comps, int dataType, boolean normalized, + public static GLArrayDataClient createGLSL(String name, int comps, int dataType, boolean normalized, int initialSize) throws GLException { - GLProfile.isValidateArrayDataType(index, comps, dataType, true, true); + if(!GLProfile.isGL2ES2()) { + throw new GLException("GLArrayDataServer not supported for profile: "+GLProfile.getProfile()); + } + GLArrayDataClient adc = new GLArrayDataClient(); - adc.init(name, index, comps, dataType, normalized, 0, null, initialSize, true); + GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc); + adc.init(name, -1, comps, dataType, normalized, 0, null, initialSize, true, glArrayHandler); return adc; } - public static GLArrayDataClient createGLSL(int index, String name, int comps, int dataType, boolean normalized, + public static GLArrayDataClient createGLSL(String name, int comps, int dataType, boolean normalized, int stride, Buffer buffer) throws GLException { - GLProfile.isValidateArrayDataType(index, comps, dataType, true, true); + if(!GLProfile.isGL2ES2()) { + throw new GLException("GLArrayDataServer not supported for profile: "+GLProfile.getProfile()); + } + GLArrayDataClient adc = new GLArrayDataClient(); - adc.init(name, index, comps, dataType, normalized, stride, buffer, comps*comps, true); + GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc); + adc.init(name, -1, comps, dataType, normalized, stride, buffer, comps*comps, true, glArrayHandler); return adc; } @@ -75,7 +95,7 @@ public class GLArrayDataClient implements GLArrayData { public long getOffset() { return -1; } - public final Buffer getBuffer() { return buffer; } + public final boolean isBufferWritten() { return bufferWritten; } public boolean isVBO() { return false; } @@ -120,6 +140,10 @@ public class GLArrayDataClient implements GLArrayData { // Data and GL state modification .. // + public final Buffer getBuffer() { return buffer; } + + public final void setBufferWritten(boolean written) { bufferWritten=written; } + public void setName(String newName) { location = -1; name = newName; @@ -159,7 +183,7 @@ public class GLArrayDataClient implements GLArrayData { buffer.rewind(); } } - enableBufferGLImpl(gl, enable); + glArrayHandler.enableBuffer(gl, enable); bufferEnabled = enable; } } @@ -410,9 +434,10 @@ public class GLArrayDataClient implements GLArrayData { } protected void init(String name, int index, int comps, int dataType, boolean normalized, int stride, Buffer data, - int initialSize, boolean isVertexAttribute) + int initialSize, boolean isVertexAttribute, GLArrayHandler handler) throws GLException { + this.glArrayHandler = handler; this.isVertexAttribute = isVertexAttribute; this.index = index; this.location = -1; @@ -457,50 +482,6 @@ 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); - - 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; - } - } else { - if(isVBO()) { - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); - } - gl.glDisableClientState(index); - } - } - protected void init_vbo(GL gl) {} protected GLArrayDataClient() { } @@ -522,5 +503,7 @@ public class GLArrayDataClient implements GLArrayData { protected boolean bufferEnabled; protected boolean bufferWritten; protected boolean enableBufferAlways; + + protected GLArrayHandler glArrayHandler; } diff --git a/src/classes/javax/media/opengl/GLArrayDataServer.java b/src/classes/javax/media/opengl/GLArrayDataServer.java index 44d4a2ff7..032e0a6f1 100644 --- a/src/classes/javax/media/opengl/GLArrayDataServer.java +++ b/src/classes/javax/media/opengl/GLArrayDataServer.java @@ -4,6 +4,7 @@ package javax.media.opengl; import javax.media.opengl.*; import java.nio.*; import com.sun.opengl.impl.*; +import com.sun.opengl.impl.glsl.*; public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData { @@ -37,7 +38,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData GLProfile.isValidateArrayDataType(index, comps, dataType, false, true); GLArrayDataServer ads = new GLArrayDataServer(); - ads.init(name, index, comps, dataType, normalized, stride, buffer, 0, buffer.limit(), glBufferUsage, false); + GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads); + ads.init(name, index, comps, dataType, normalized, stride, buffer, 0, buffer.limit(), glBufferUsage, false, glArrayHandler); return ads; } @@ -59,7 +61,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData GLProfile.isValidateArrayDataType(index, comps, dataType, false, true); GLArrayDataServer ads = new GLArrayDataServer(); - ads.init(name, index, comps, dataType, normalized, 0, null, 0, initialSize, glBufferUsage, false); + GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads); + ads.init(name, index, comps, dataType, normalized, 0, null, 0, initialSize, glBufferUsage, false, glArrayHandler); return ads; } @@ -82,7 +85,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData GLProfile.isValidateArrayDataType(index, comps, dataType, false, true); GLArrayDataServer ads = new GLArrayDataServer(); - ads.init(name, index, comps, dataType, normalized, stride, null, bufferOffset, 0, -1, false); + GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads); + ads.init(name, index, comps, dataType, normalized, stride, null, bufferOffset, 0, -1, false, glArrayHandler); ads.vboName = vboName; ads.bufferWritten = true; ads.sealed = true; @@ -99,15 +103,14 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData int initialSize, int glBufferUsage) throws GLException { - GLProfile.isValidateArrayDataType(-1, comps, dataType, true, true); - Class[] types = new Class[]{ String.class, int.class, int.class, boolean.class, int.class, int.class }; - Object[] args = new Object[]{ name, new Integer(comps), new Integer(dataType), - new Boolean(normalized), new Integer(initialSize), new Integer(glBufferUsage) } ; - - if(GLProfile.isGL2ES2()) { - return (GLArrayDataServer) GLReflection.createInstance("com.sun.opengl.impl.glsl.GLSLArrayDataServer", types, args); + if(!GLProfile.isGL2ES2()) { + throw new GLException("GLArrayDataServer not supported for profile: "+GLProfile.getProfile()); } - throw new GLException("GLArrayDataServer not supported for profile: "+GLProfile.getProfile()); + + GLArrayDataServer ads = new GLArrayDataServer(); + GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads); + ads.init(name, -1, comps, dataType, normalized, 0, null, 0, initialSize, glBufferUsage, true, glArrayHandler); + return ads; } /** @@ -120,15 +123,14 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData int stride, Buffer buffer, int glBufferUsage) throws GLException { - GLProfile.isValidateArrayDataType(-1, comps, dataType, true, true); - Class[] types = new Class[]{ String.class, int.class, int.class, boolean.class, int.class, Buffer.class, int.class }; - Object[] args = new Object[]{ name, new Integer(comps), new Integer(dataType), - new Boolean(normalized), new Integer(stride), buffer, new Integer(glBufferUsage) } ; - - if(GLProfile.isGL2ES2()) { - return (GLArrayDataServer) GLReflection.createInstance("com.sun.opengl.impl.glsl.GLSLArrayDataServer", types, args); + if(!GLProfile.isGL2ES2()) { + throw new GLException("GLArrayDataServer not supported for profile: "+GLProfile.getProfile()); } - throw new GLException("GLArrayDataServer not supported for profile: "+GLProfile.getProfile()); + + GLArrayDataServer ads = new GLArrayDataServer(); + GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads); + ads.init(name, -1, comps, dataType, normalized, stride, buffer, 0, buffer.limit(), glBufferUsage, true, glArrayHandler); + return ads; } // @@ -200,10 +202,11 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData // protected void init(String name, int index, int comps, int dataType, boolean normalized, - int stride, Buffer data, long offset, int initialSize, int glBufferUsage, boolean isVertexAttribute) + int stride, Buffer data, long offset, int initialSize, int glBufferUsage, boolean isVertexAttribute, + GLArrayHandler glArrayHandler) throws GLException { - super.init(name, index, comps, dataType, normalized, stride, data, initialSize, isVertexAttribute); + super.init(name, index, comps, dataType, normalized, stride, data, initialSize, isVertexAttribute, glArrayHandler); vboUsage=true; diff --git a/src/classes/javax/media/opengl/util/ImmModeSink.java b/src/classes/javax/media/opengl/util/ImmModeSink.java index 04173cb6f..4ef8cacf7 100644 --- a/src/classes/javax/media/opengl/util/ImmModeSink.java +++ b/src/classes/javax/media/opengl/util/ImmModeSink.java @@ -399,10 +399,10 @@ public class ImmModeSink { Exception e = new Exception("ImmModeSink.draw["+i+"](disableBufferAfterDraw: "+disableBufferAfterDraw+"):\n\t"+this); e.printStackTrace(); } - vertexVBO.enableBuffer(gl, true); normalVBO.enableBuffer(gl, true); colorVBO.enableBuffer(gl, true); texcoordVBO.enableBuffer(gl, true); + vertexVBO.enableBuffer(gl, true); if (vertexVBO.getBuffer()!=null) { if(null==indices) { @@ -419,14 +419,15 @@ public class ImmModeSink { throw new GLException("Given Buffer Class not supported: "+clazz+", should be ubyte or ushort:\n\t"+this); } gl.glDrawElements(mode, indices.remaining(), type, indices); + // GL2: gl.glDrawRangeElements(mode, 0, indices.remaining()-1, indices.remaining(), type, indices); } } if(disableBufferAfterDraw) { vertexVBO.enableBuffer(gl, false); - normalVBO.enableBuffer(gl, false); - colorVBO.enableBuffer(gl, false); texcoordVBO.enableBuffer(gl, false); + colorVBO.enableBuffer(gl, false); + normalVBO.enableBuffer(gl, false); } } |