aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2008-08-29 08:49:29 +0000
committerSven Gothel <[email protected]>2008-08-29 08:49:29 +0000
commit4667ad39359ac0f096ad8257bc3e29740493028a (patch)
treeea6efe460ddc8c88adca1546837e4624d703640d /src
parentc91152ffe6a86e29c4e6c896eec7af5a40bc7be0 (diff)
BufferUtil:
- new GL type tools - new put methods ImmModeSink: - using 1 VBO array for 1-4 attributes GLArrayData - split into GLArrayData and GLArrayDataEditable, the latter of modifying purposes only - GLArrayDataWrapper implements a container only git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1764 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src')
-rw-r--r--src/classes/com/sun/opengl/impl/GLFixedArrayHandler.java4
-rw-r--r--src/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java16
-rw-r--r--src/classes/javax/media/opengl/GLArrayData.java96
-rw-r--r--src/classes/javax/media/opengl/GLArrayDataClient.java206
-rw-r--r--src/classes/javax/media/opengl/GLArrayDataEditable.java108
-rw-r--r--src/classes/javax/media/opengl/GLArrayDataServer.java87
-rw-r--r--src/classes/javax/media/opengl/GLArrayDataWrapper.java203
-rw-r--r--src/classes/javax/media/opengl/GLProfile.java30
-rw-r--r--src/classes/javax/media/opengl/glsl/ShaderState.java1
-rwxr-xr-xsrc/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp135
-rwxr-xr-xsrc/classes/javax/media/opengl/util/BufferUtil.java.javase147
-rw-r--r--src/classes/javax/media/opengl/util/ImmModeSink.java867
12 files changed, 1264 insertions, 636 deletions
diff --git a/src/classes/com/sun/opengl/impl/GLFixedArrayHandler.java b/src/classes/com/sun/opengl/impl/GLFixedArrayHandler.java
index 9882beb69..333a75aa0 100644
--- a/src/classes/com/sun/opengl/impl/GLFixedArrayHandler.java
+++ b/src/classes/com/sun/opengl/impl/GLFixedArrayHandler.java
@@ -6,9 +6,9 @@ import javax.media.opengl.glsl.ShaderState;
import java.nio.*;
public class GLFixedArrayHandler implements GLArrayHandler {
- private GLArrayData ad;
+ private GLArrayDataEditable ad;
- public GLFixedArrayHandler(GLArrayData ad) {
+ public GLFixedArrayHandler(GLArrayDataEditable ad) {
this.ad = ad;
}
diff --git a/src/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java b/src/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java
index 2910e67bd..3d48f2014 100644
--- a/src/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java
+++ b/src/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java
@@ -8,16 +8,14 @@ import javax.media.opengl.glsl.ShaderState;
import java.nio.*;
public class GLSLArrayHandler implements GLArrayHandler {
- private GLArrayData ad;
+ private GLArrayDataEditable ad;
- public GLSLArrayHandler(GLArrayData ad) {
+ public GLSLArrayHandler(GLArrayDataEditable ad) {
this.ad = ad;
}
protected final void passVertexAttribPointer(GL2ES2 gl, ShaderState st) {
- if ( ! st.glVertexAttribPointer(gl, ad) ) {
- throw new RuntimeException("Internal Error");
- }
+ st.glVertexAttribPointer(gl, ad);
}
public void enableBuffer(GL gl, boolean enable) {
@@ -28,9 +26,7 @@ public class GLSLArrayHandler implements GLArrayHandler {
}
if(enable) {
- if(!st.glEnableVertexAttribArray(glsl, ad.getName())) {
- throw new RuntimeException("Internal Error");
- }
+ st.glEnableVertexAttribArray(glsl, ad.getName());
Buffer buffer = ad.getBuffer();
@@ -53,9 +49,7 @@ public class GLSLArrayHandler implements GLArrayHandler {
if(ad.isVBO()) {
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
}
- if(!st.glDisableVertexAttribArray(glsl, ad.getName())) {
- throw new RuntimeException("Internal Error");
- }
+ st.glDisableVertexAttribArray(glsl, ad.getName());
}
}
diff --git a/src/classes/javax/media/opengl/GLArrayData.java b/src/classes/javax/media/opengl/GLArrayData.java
index bdffa3c44..a51229cd6 100644
--- a/src/classes/javax/media/opengl/GLArrayData.java
+++ b/src/classes/javax/media/opengl/GLArrayData.java
@@ -53,9 +53,6 @@ public interface GLArrayData {
*/
public void setLocation(int v);
-
- public boolean sealed();
-
/**
* Determines wheather the data is server side (VBO),
* or a client side array (false).
@@ -73,26 +70,11 @@ public interface GLArrayData {
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();
/**
- * 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();
@@ -126,83 +108,5 @@ public interface GLArrayData {
public String toString();
- //
- // Data and GL state modification ..
- //
-
- public void destroy(GL gl);
-
- 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.
- *
- * @see #seal(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.
- *
- * The above will only be executed,
- * if the buffer is disabled,
- * or 'setEnableAlways' was called with 'true'.
- *
- * @see #setEnableAlways(boolean)
- */
- public void enableBuffer(GL gl, boolean enable);
-
- /**
- * Affects the behavior of 'enableBuffer'.
- *
- * The default is 'false'
- *
- * This is usefull when you mix up
- * GLArrayData usage with conventional GL array calls.
- *
- * @see #enableBuffer(GL, boolean)
- */
- public void setEnableAlways(boolean always);
-
- //
- // Data modification ..
- //
-
- public void reset();
-
- /**
- * If seal is true, it
- * disable write operations to the buffer.
- * Calls flip, ie limit:=position and position:=0.
- *
- * 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.
- *
- */
- public void seal(boolean seal);
-
- public void rewind();
- public void padding(int done);
- public void put(Buffer v);
- public void putb(byte v);
- public void puts(short v);
- public void puti(int v);
- public void putx(int v);
- public void putf(float v);
- public void putd(double v);
-
}
diff --git a/src/classes/javax/media/opengl/GLArrayDataClient.java b/src/classes/javax/media/opengl/GLArrayDataClient.java
index a4b4cae19..4819e9067 100644
--- a/src/classes/javax/media/opengl/GLArrayDataClient.java
+++ b/src/classes/javax/media/opengl/GLArrayDataClient.java
@@ -7,7 +7,7 @@ import com.sun.opengl.impl.glsl.*;
import java.nio.*;
-public class GLArrayDataClient implements GLArrayData {
+public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayDataEditable {
/**
* The OpenGL ES emulation on the PC probably has a buggy VBO implementation,
@@ -36,7 +36,7 @@ public class GLArrayDataClient implements GLArrayData {
GLProfile.isValidateArrayDataType(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);
+ adc.init(name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler, 0, 0);
return adc;
}
@@ -47,7 +47,7 @@ public class GLArrayDataClient implements GLArrayData {
GLProfile.isValidateArrayDataType(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);
+ adc.init(name, index, comps, dataType, normalized, stride, buffer, comps*comps, false, glArrayHandler, 0, 0);
return adc;
}
@@ -62,7 +62,7 @@ public class GLArrayDataClient implements GLArrayData {
GLArrayDataClient adc = new GLArrayDataClient();
GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc);
- adc.init(name, -1, comps, dataType, normalized, 0, null, initialSize, true, glArrayHandler);
+ adc.init(name, -1, comps, dataType, normalized, 0, null, initialSize, true, glArrayHandler, 0, 0);
return adc;
}
@@ -77,7 +77,7 @@ public class GLArrayDataClient implements GLArrayData {
GLArrayDataClient adc = new GLArrayDataClient();
GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc);
- adc.init(name, -1, comps, dataType, normalized, stride, buffer, comps*comps, true, glArrayHandler);
+ adc.init(name, -1, comps, dataType, normalized, stride, buffer, comps*comps, true, glArrayHandler, 0, 0);
return adc;
}
@@ -85,74 +85,21 @@ public class GLArrayDataClient implements GLArrayData {
// Data read access
//
- public final boolean isVertexAttribute() { return isVertexAttribute; }
-
- public final int getIndex() { return index; }
-
- public final int getLocation() { return location; }
-
- public final void setLocation(int v) { location = v; }
-
- public final String getName() { return name; }
-
- public long getOffset() { return -1; }
-
public final boolean isBufferWritten() { return bufferWritten; }
- public boolean isVBO() { return false; }
-
- public int getVBOName() { return -1; }
-
- public int getBufferUsage() { return -1; }
-
- public final int getComponentNumber() { return components; }
-
- public final int getComponentType() { return dataType; }
-
- 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 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; }
+ public int getBufferUsage() { return -1; }
//
// 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;
- }
-
public void destroy(GL gl) {
reset(gl);
+ buffer=null;
}
public void reset(GL gl) {
@@ -234,17 +181,7 @@ public class GLArrayDataClient implements GLArrayData {
public void padding(int done) {
if ( buffer==null || sealed ) return;
while(done<strideL) {
- if(clazz==ByteBuffer.class) {
- ((ByteBuffer)buffer).put((byte)0);
- } else if(clazz==ShortBuffer.class) {
- ((ShortBuffer)buffer).put((short)0);
- } else if(clazz==IntBuffer.class) {
- ((IntBuffer)buffer).put(0);
- } else if(clazz==FloatBuffer.class) {
- ((FloatBuffer)buffer).put(0f);
- } else {
- throw new GLException("Given Buffer Class not supported: "+clazz+" :\n\t"+this);
- }
+ BufferUtil.putb(buffer, (byte)0);
done++;
}
}
@@ -260,56 +197,26 @@ public class GLArrayDataClient implements GLArrayData {
if(0!=(v.remaining() % strideL)) {
throw new GLException("Buffer length ("+v.remaining()+") is not a multiple of component-stride:\n\t"+this);
}
- Class vClazz = v.getClass();
- if(!GLReflection.instanceOf(vClazz, clazz.getName())) {
- throw new GLException("This array's buffer class "+clazz+" doesn't match the argument's Class: "+vClazz+" :\n\t"+this);
- }
growBufferIfNecessary(v.remaining());
- if(clazz==ByteBuffer.class) {
- ((ByteBuffer)buffer).put((ByteBuffer)v);
- } else if(clazz==ShortBuffer.class) {
- ((ShortBuffer)buffer).put((ShortBuffer)v);
- } else if(clazz==IntBuffer.class) {
- ((IntBuffer)buffer).put((IntBuffer)v);
- } else if(clazz==FloatBuffer.class) {
- ((FloatBuffer)buffer).put((FloatBuffer)v);
- }
+ BufferUtil.put(buffer, v);
}
public void putb(byte v) {
if ( buffer==null || sealed ) return;
growBufferIfNecessary(1);
- if(clazz==ByteBuffer.class) {
- ((ByteBuffer)buffer).put(v);
- } else if(clazz==ShortBuffer.class) {
- ((ShortBuffer)buffer).put((short)v);
- } else if(clazz==IntBuffer.class) {
- ((IntBuffer)buffer).put((int)v);
- } else {
- throw new GLException("Byte doesn't match Buffer Class: "+clazz+" :\n\t"+this);
- }
+ BufferUtil.putb(buffer, v);
}
public void puts(short v) {
if ( buffer==null || sealed ) return;
growBufferIfNecessary(1);
- if(clazz==ShortBuffer.class) {
- ((ShortBuffer)buffer).put(v);
- } else if(clazz==IntBuffer.class) {
- ((IntBuffer)buffer).put((int)v);
- } else {
- throw new GLException("Short doesn't match Buffer Class: "+clazz+" :\n\t"+this);
- }
+ BufferUtil.puts(buffer, v);
}
public void puti(int v) {
if ( buffer==null || sealed ) return;
growBufferIfNecessary(1);
- if(clazz==IntBuffer.class) {
- ((IntBuffer)buffer).put(v);
- } else {
- throw new GLException("Integer doesn't match Buffer Class: "+clazz+" :\n\t"+this);
- }
+ BufferUtil.puti(buffer, v);
}
public void putx(int v) {
@@ -319,23 +226,7 @@ public class GLArrayDataClient implements GLArrayData {
public void putf(float v) {
if ( buffer==null || sealed ) return;
growBufferIfNecessary(1);
- if(clazz==FloatBuffer.class) {
- ((FloatBuffer)buffer).put(v);
- } else if(clazz==IntBuffer.class) {
- ((IntBuffer)buffer).put(FixedPoint.toFixed(v));
- } else {
- throw new GLException("Float doesn't match Buffer Class: "+clazz+" :\n\t"+this);
- }
- }
-
- public void putd(double v) {
- if ( buffer==null || sealed ) return;
- growBufferIfNecessary(1);
- if(clazz==FloatBuffer.class) {
- ((FloatBuffer)buffer).put((float)v);
- } else {
- throw new GLException("Double doesn't match Buffer Class: "+clazz+" :\n\t"+this);
- }
+ BufferUtil.putf(buffer, v);
}
public String toString() {
@@ -356,23 +247,6 @@ public class GLArrayDataClient implements GLArrayData {
"]";
}
- public static final Class getBufferClass(int dataType) {
- switch(dataType) {
- case GL.GL_BYTE:
- case GL.GL_UNSIGNED_BYTE:
- return ByteBuffer.class;
- case GL.GL_SHORT:
- case GL.GL_UNSIGNED_SHORT:
- return ShortBuffer.class;
- case GL2ES1.GL_FIXED:
- return IntBuffer.class;
- case GL.GL_FLOAT:
- return FloatBuffer.class;
- default:
- throw new GLException("Given OpenGL data type not supported: "+dataType);
- }
- }
-
// non public matters
protected final boolean growBufferIfNecessary(int spare) {
@@ -436,44 +310,15 @@ 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, GLArrayHandler handler)
+ int initialSize, boolean isVertexAttribute, GLArrayHandler handler,
+ int vboName, long bufferOffset)
throws GLException
{
- this.glArrayHandler = handler;
- this.isVertexAttribute = isVertexAttribute;
- this.index = index;
- this.location = -1;
- this.name = (null==name)?GLContext.getPredefinedArrayIndexName(index):name;
- if(null==this.name) {
- throw new GLException("Not a valid GL array index: "+index);
- }
- this.dataType = dataType;
- this.clazz = getBufferClass(dataType);
- switch(dataType) {
- case GL.GL_BYTE:
- case GL.GL_UNSIGNED_BYTE:
- case GL.GL_SHORT:
- case GL.GL_UNSIGNED_SHORT:
- case GL2ES1.GL_FIXED:
- this.normalized = normalized;
- break;
- default:
- this.normalized = false;
- }
+ super.init(name, index, comps, dataType, normalized, stride, data, isVertexAttribute,
+ vboName, bufferOffset);
- int bpc = getComponentSize();
- if(0<stride && stride<comps*bpc) {
- throw new GLException("stride ("+stride+") lower than component bytes, "+comps+" * "+bpc);
- }
- if(0<stride && stride%bpc!=0) {
- throw new GLException("stride ("+stride+") not a multiple of bpc "+bpc);
- }
- this.buffer = data;
- this.components = comps;
- this.stride=stride;
- this.strideB=(0==stride)?comps*bpc:stride;
- this.strideL=(0==stride)?comps:strideB/bpc;
this.initialSize = initialSize;
+ this.glArrayHandler = handler;
this.sealed=false;
this.sealedGL=false;
this.bufferEnabled=false;
@@ -488,24 +333,13 @@ public class GLArrayDataClient implements GLArrayData {
protected GLArrayDataClient() { }
- protected int index;
- protected int location;
- protected String name;
- protected int components;
- protected int dataType;
- 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 int initialSize;
- protected boolean isVertexAttribute;
protected boolean sealed, sealedGL;
protected boolean bufferEnabled;
protected boolean bufferWritten;
protected boolean enableBufferAlways;
+ protected int initialSize;
+
protected GLArrayHandler glArrayHandler;
}
diff --git a/src/classes/javax/media/opengl/GLArrayDataEditable.java b/src/classes/javax/media/opengl/GLArrayDataEditable.java
new file mode 100644
index 000000000..7cf58e2ae
--- /dev/null
+++ b/src/classes/javax/media/opengl/GLArrayDataEditable.java
@@ -0,0 +1,108 @@
+
+package javax.media.opengl;
+
+import java.nio.*;
+
+/**
+ *
+ * The total number of bytes hold by the referenced buffer is:
+ * getComponentSize()* getComponentNumber() * getElementNumber()
+ *
+ */
+public interface GLArrayDataEditable extends GLArrayData {
+
+ public boolean sealed();
+
+ /**
+ * The VBO buffer usage, if it's an VBO, otherwise -1
+ */
+ public int getBufferUsage();
+
+ /**
+ * Is the buffer written to the GPU ?
+ */
+ public boolean isBufferWritten();
+
+ /**
+ * Marks the buffer written to the GPU
+ */
+ public void setBufferWritten(boolean written);
+
+ //
+ // Data and GL state modification ..
+ //
+
+ public void destroy(GL gl);
+
+ 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.
+ *
+ * @see #seal(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.
+ *
+ * The above will only be executed,
+ * if the buffer is disabled,
+ * or 'setEnableAlways' was called with 'true'.
+ *
+ * @see #setEnableAlways(boolean)
+ */
+ public void enableBuffer(GL gl, boolean enable);
+
+ /**
+ * Affects the behavior of 'enableBuffer'.
+ *
+ * The default is 'false'
+ *
+ * This is usefull when you mix up
+ * GLArrayData usage with conventional GL array calls.
+ *
+ * @see #enableBuffer(GL, boolean)
+ */
+ public void setEnableAlways(boolean always);
+
+ //
+ // Data modification ..
+ //
+
+ public void reset();
+
+ /**
+ * If seal is true, it
+ * disable write operations to the buffer.
+ * Calls flip, ie limit:=position and position:=0.
+ *
+ * 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.
+ *
+ */
+ public void seal(boolean seal);
+
+ public void rewind();
+ public void padding(int done);
+ public void put(Buffer v);
+ public void putb(byte v);
+ public void puts(short v);
+ public void puti(int v);
+ public void putx(int v);
+ public void putf(float v);
+}
+
diff --git a/src/classes/javax/media/opengl/GLArrayDataServer.java b/src/classes/javax/media/opengl/GLArrayDataServer.java
index 6fcb03a90..53b5b896a 100644
--- a/src/classes/javax/media/opengl/GLArrayDataServer.java
+++ b/src/classes/javax/media/opengl/GLArrayDataServer.java
@@ -6,7 +6,7 @@ import java.nio.*;
import com.sun.opengl.impl.*;
import com.sun.opengl.impl.glsl.*;
-public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData {
+public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataEditable {
//
// lifetime matters
@@ -32,14 +32,15 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData
* @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
*/
public static GLArrayDataServer createFixed(int index, String name, int comps, int dataType, boolean normalized,
- int stride, Buffer buffer, int glBufferUsage)
+ int stride, Buffer buffer, int vboBufferUsage)
throws GLException
{
GLProfile.isValidateArrayDataType(index, comps, dataType, false, true);
GLArrayDataServer ads = new GLArrayDataServer();
GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads);
- ads.init(name, index, comps, dataType, normalized, stride, buffer, 0, buffer.limit(), glBufferUsage, false, glArrayHandler);
+ ads.init(name, index, comps, dataType, normalized, stride, buffer, buffer.limit(), false, glArrayHandler,
+ 0, 0, vboBufferUsage);
return ads;
}
@@ -55,41 +56,15 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData
* @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
*/
public static GLArrayDataServer createFixed(int index, String name, int comps, int dataType, boolean normalized,
- int initialSize, int glBufferUsage)
+ int initialSize, int vboBufferUsage)
throws GLException
{
GLProfile.isValidateArrayDataType(index, comps, dataType, false, true);
GLArrayDataServer ads = new GLArrayDataServer();
GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads);
- ads.init(name, index, comps, dataType, normalized, 0, null, 0, initialSize, glBufferUsage, false, glArrayHandler);
- return ads;
- }
-
- /**
- * Create a VBOBuffer object, using a predefined fixed function array index
- * and starting with a given Buffer offset incl it's stride
- *
- * 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 vboName)
- throws GLException
- {
- GLProfile.isValidateArrayDataType(index, comps, dataType, false, true);
-
- GLArrayDataServer ads = new GLArrayDataServer();
- 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;
+ ads.init(name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler,
+ 0, 0, vboBufferUsage);
return ads;
}
@@ -100,7 +75,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData
* @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
*/
public static GLArrayDataServer createGLSL(String name, int comps, int dataType, boolean normalized,
- int initialSize, int glBufferUsage)
+ int initialSize, int vboBufferUsage)
throws GLException
{
if(!GLProfile.isGL2ES2()) {
@@ -110,7 +85,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData
GLArrayDataServer ads = new GLArrayDataServer();
GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads);
- ads.init(name, -1, comps, dataType, normalized, 0, null, 0, initialSize, glBufferUsage, true, glArrayHandler);
+ ads.init(name, -1, comps, dataType, normalized, 0, null, initialSize, true, glArrayHandler,
+ 0, 0, vboBufferUsage);
return ads;
}
@@ -121,7 +97,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData
* @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
*/
public static GLArrayDataServer createGLSL(String name, int comps, int dataType, boolean normalized,
- int stride, Buffer buffer, int glBufferUsage)
+ int stride, Buffer buffer, int vboBufferUsage)
throws GLException
{
if(!GLProfile.isGL2ES2()) {
@@ -131,7 +107,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData
GLArrayDataServer ads = new GLArrayDataServer();
GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads);
- ads.init(name, -1, comps, dataType, normalized, stride, buffer, 0, buffer.limit(), glBufferUsage, true, glArrayHandler);
+ ads.init(name, -1, comps, dataType, normalized, stride, buffer, buffer.limit(), true, glArrayHandler,
+ 0, 0, vboBufferUsage);
return ads;
}
@@ -139,11 +116,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData
// Data matters GLArrayData
//
- public final long getOffset() { return vboUsage?bufferOffset:-1; }
-
- public final int getVBOName() { return vboUsage?vboName:-1; }
-
- public final boolean isVBO() { return vboUsage; }
+ public int getBufferUsage() { return vboBufferUsage; }
//
// Data and GL state modification ..
@@ -170,11 +143,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData
*/
public void setVBOUsage(boolean vboUsage) {
checkSeal(false);
- this.vboUsage=(null!=buffer)?vboUsage:true;
- }
-
- public int getBufferUsage() {
- return glBufferUsage;
+ super.setVBOUsage(vboUsage);
}
public String toString() {
@@ -188,7 +157,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData
", components "+components+
", stride "+stride+"u "+strideB+"b "+strideL+"c"+
", initialSize "+initialSize+
- ", glBufferUsage "+glBufferUsage+
+ ", vboBufferUsage "+vboBufferUsage+
", vboUsage "+vboUsage+
", vboName "+vboName+
", sealed "+sealed+
@@ -204,27 +173,27 @@ 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,
- GLArrayHandler glArrayHandler)
+ int stride, Buffer data, int initialSize, boolean isVertexAttribute,
+ GLArrayHandler glArrayHandler,
+ int vboName, long bufferOffset, int vboBufferUsage)
throws GLException
{
- super.init(name, index, comps, dataType, normalized, stride, data, initialSize, isVertexAttribute, glArrayHandler);
+ super.init(name, index, comps, dataType, normalized, stride, data, initialSize, isVertexAttribute, glArrayHandler,
+ vboName, bufferOffset);
vboUsage=true;
- if( ! (GLProfile.isGL2ES2() && glBufferUsage==GL2ES2.GL_STREAM_DRAW) ) {
- switch(glBufferUsage) {
+ if( ! (GLProfile.isGL2ES2() && vboBufferUsage==GL2ES2.GL_STREAM_DRAW) ) {
+ switch(vboBufferUsage) {
case -1: // nop
case GL2ES1.GL_STATIC_DRAW:
case GL2ES1.GL_DYNAMIC_DRAW:
break;
default:
- throw new GLException("invalid glBufferUsage: "+glBufferUsage+":\n\t"+this);
+ throw new GLException("invalid vboBufferUsage: "+vboBufferUsage+":\n\t"+this);
}
}
- this.bufferOffset=offset;
- this.glBufferUsage = glBufferUsage;
- this.vboName = 0;
+ this.vboBufferUsage=vboBufferUsage;
}
protected void init_vbo(GL gl) {
@@ -235,10 +204,6 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayData
}
}
- protected long bufferOffset;
- protected int glBufferUsage;
- protected int vboName;
- protected boolean vboUsage;
-
+ protected int vboBufferUsage;
}
diff --git a/src/classes/javax/media/opengl/GLArrayDataWrapper.java b/src/classes/javax/media/opengl/GLArrayDataWrapper.java
new file mode 100644
index 000000000..f5b5be6c6
--- /dev/null
+++ b/src/classes/javax/media/opengl/GLArrayDataWrapper.java
@@ -0,0 +1,203 @@
+
+package javax.media.opengl;
+
+import javax.media.opengl.util.*;
+import com.sun.opengl.impl.*;
+import com.sun.opengl.impl.glsl.*;
+
+import java.nio.*;
+
+public class GLArrayDataWrapper implements GLArrayData {
+
+ public static GLArrayDataWrapper createFixed(int index, int comps, int dataType, boolean normalized,
+ int stride, Buffer buffer,
+ int vboName, long bufferOffset)
+ throws GLException
+ {
+ GLProfile.isValidateArrayDataType(index, comps, dataType, false, true);
+ GLArrayDataWrapper adc = new GLArrayDataWrapper();
+ adc.init(null, index, comps, dataType, normalized, stride, buffer, false,
+ vboName, bufferOffset);
+ return adc;
+ }
+
+ public static GLArrayDataWrapper createGLSL(String name, int comps, int dataType, boolean normalized,
+ int stride, Buffer buffer,
+ int vboName, long bufferOffset)
+ throws GLException
+ {
+ if(!GLProfile.isGL2ES2()) {
+ throw new GLException("GLArrayDataServer not supported for profile: "+GLProfile.getProfile());
+ }
+ GLProfile.isValidateArrayDataType(-1, comps, dataType, true, true);
+
+ GLArrayDataWrapper adc = new GLArrayDataWrapper();
+ adc.init(name, -1, comps, dataType, normalized, stride, buffer, true,
+ vboName, bufferOffset);
+ return adc;
+ }
+
+ //
+ // Data read access
+ //
+
+ public final boolean isVertexAttribute() { return isVertexAttribute; }
+
+ public final int getIndex() { return index; }
+
+ public final int getLocation() { return location; }
+
+ public final void setLocation(int v) { location = v; }
+
+ public final String getName() { return name; }
+
+ public final long getOffset() { return vboUsage?bufferOffset:-1; }
+
+ public final int getVBOName() { return vboUsage?vboName:-1; }
+
+ public final boolean isVBO() { return vboUsage; }
+
+ public final Buffer getBuffer() { return buffer; }
+
+ public final int getComponentNumber() { return components; }
+
+ public final int getComponentType() { return dataType; }
+
+ 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 final int getElementNumber() {
+ if(null==buffer) return 0;
+ return ( buffer.position()==0 ) ? ( buffer.limit() / components ) : ( buffer.position() / components ) ;
+ }
+
+ public final boolean getNormalized() { return normalized; }
+
+ public final int getStride() { return stride; }
+
+ public final Class getBufferClass() { return clazz; }
+
+ public String toString() {
+ return "GLArrayDataWrapper["+name+
+ ", index "+index+
+ ", location "+location+
+ ", isVertexAttribute "+isVertexAttribute+
+ ", dataType "+dataType+
+ ", bufferClazz "+clazz+
+ ", elements "+getElementNumber()+
+ ", components "+components+
+ ", stride "+stride+"u "+strideB+"b "+strideL+"c"+
+ ", buffer "+buffer+
+ ", offset "+bufferOffset+
+ ", vboUsage "+vboUsage+
+ ", vboName "+vboName+
+ "]";
+ }
+
+ public static final Class getBufferClass(int dataType) {
+ switch(dataType) {
+ case GL.GL_BYTE:
+ case GL.GL_UNSIGNED_BYTE:
+ return ByteBuffer.class;
+ case GL.GL_SHORT:
+ case GL.GL_UNSIGNED_SHORT:
+ return ShortBuffer.class;
+ case GL2ES1.GL_FIXED:
+ return IntBuffer.class;
+ case GL.GL_FLOAT:
+ return FloatBuffer.class;
+ default:
+ throw new GLException("Given OpenGL data type not supported: "+dataType);
+ }
+ }
+
+ public void setName(String newName) {
+ location = -1;
+ name = newName;
+ }
+
+ public void setVBOUsage(boolean vboUsage) {
+ this.vboUsage=vboUsage;
+ }
+
+ public void setVBOName(int vboName) {
+ this.vboName=vboName;
+ setVBOUsage(vboName>0);
+ }
+
+ protected void init(String name, int index, int comps, int dataType, boolean normalized, int stride, Buffer data,
+ boolean isVertexAttribute,
+ int vboName, long bufferOffset)
+ throws GLException
+ {
+ this.isVertexAttribute = isVertexAttribute;
+ this.index = index;
+ this.location = -1;
+ this.name = (null==name)?GLContext.getPredefinedArrayIndexName(index):name;
+ if(null==this.name) {
+ throw new GLException("Not a valid GL array index: "+index);
+ }
+ this.dataType = dataType;
+ this.clazz = getBufferClass(dataType);
+ switch(dataType) {
+ case GL.GL_BYTE:
+ case GL.GL_UNSIGNED_BYTE:
+ case GL.GL_SHORT:
+ case GL.GL_UNSIGNED_SHORT:
+ case GL2ES1.GL_FIXED:
+ this.normalized = normalized;
+ break;
+ default:
+ this.normalized = false;
+ }
+
+ int bpc = getComponentSize();
+ if(0<stride && stride<comps*bpc) {
+ throw new GLException("stride ("+stride+") lower than component bytes, "+comps+" * "+bpc);
+ }
+ if(0<stride && stride%bpc!=0) {
+ throw new GLException("stride ("+stride+") not a multiple of bpc "+bpc);
+ }
+ this.buffer = data;
+ this.components = comps;
+ this.stride=stride;
+ this.strideB=(0==stride)?comps*bpc:stride;
+ this.strideL=(0==stride)?comps:strideB/bpc;
+ this.vboName=vboName;
+ this.vboUsage=vboName>0;
+ this.bufferOffset=bufferOffset;
+ }
+
+ protected GLArrayDataWrapper() { }
+
+ protected int index;
+ protected int location;
+ protected String name;
+ protected int components;
+ protected int dataType;
+ 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;
+
+ protected long bufferOffset;
+ protected int vboName;
+ protected boolean vboUsage;
+}
+
diff --git a/src/classes/javax/media/opengl/GLProfile.java b/src/classes/javax/media/opengl/GLProfile.java
index ac37305b2..14a57cc8c 100644
--- a/src/classes/javax/media/opengl/GLProfile.java
+++ b/src/classes/javax/media/opengl/GLProfile.java
@@ -223,6 +223,36 @@ public class GLProfile {
}
}
+ public static String getGLTypeName(int type) {
+ switch (type) {
+ case GL.GL_UNSIGNED_BYTE:
+ return "GL_UNSIGNED_BYTE";
+ case GL.GL_BYTE:
+ return "GL_BYTE";
+ case GL.GL_UNSIGNED_SHORT:
+ return "GL_UNSIGNED_SHORT";
+ case GL.GL_SHORT:
+ return "GL_SHORT";
+ case GL.GL_FLOAT:
+ return "GL_FLOAT";
+ case GL.GL_FIXED:
+ return "GL_FIXED";
+ case javax.media.opengl.GL2ES2.GL_INT:
+ return "GL_INT";
+ case javax.media.opengl.GL2ES2.GL_UNSIGNED_INT:
+ return "GL_UNSIGNED_INT";
+ case javax.media.opengl.GL2.GL_DOUBLE:
+ return "GL_DOUBLE";
+ case javax.media.opengl.GL2.GL_2_BYTES:
+ return "GL_2_BYTES";
+ case javax.media.opengl.GL2.GL_3_BYTES:
+ return "GL_3_BYTES";
+ case javax.media.opengl.GL2.GL_4_BYTES:
+ return "GL_4_BYTES";
+ }
+ return null;
+ }
+
/**
* General validation if type is a valid GL data type
* for the current profile
diff --git a/src/classes/javax/media/opengl/glsl/ShaderState.java b/src/classes/javax/media/opengl/glsl/ShaderState.java
index c6c1f2152..6419402fd 100644
--- a/src/classes/javax/media/opengl/glsl/ShaderState.java
+++ b/src/classes/javax/media/opengl/glsl/ShaderState.java
@@ -459,7 +459,6 @@ public class ShaderState {
if(0>loc) {
// not used in shader
- System.err.println("*** skip: "+name);
continue;
}
diff --git a/src/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp b/src/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp
index 425756c07..2496950be 100755
--- a/src/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp
+++ b/src/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp
@@ -39,6 +39,13 @@
package javax.media.opengl.util;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLException;
+import javax.media.opengl.GLProfile;
+import com.sun.opengl.impl.GLReflection;
+
import java.nio.*;
import java.util.*;
@@ -54,12 +61,76 @@ public class BufferUtil {
public static final int SIZEOF_LONG = -1; // not supported
public static final int SIZEOF_DOUBLE = -1; // not supported
+ public static final int sizeOfGLType(int glType) {
+ switch (glType) {
+ case GL.GL_UNSIGNED_BYTE:
+ return SIZEOF_BYTE;
+ case GL.GL_BYTE:
+ return SIZEOF_BYTE;
+ case GL.GL_UNSIGNED_SHORT:
+ return SIZEOF_SHORT;
+ case GL.GL_SHORT:
+ return SIZEOF_SHORT;
+ case GL.GL_FLOAT:
+ return SIZEOF_FLOAT;
+ case GL.GL_FIXED:
+ return SIZEOF_INT;
+ case GL2ES2.GL_INT:
+ return SIZEOF_INT;
+ case GL2ES2.GL_UNSIGNED_INT:
+ return SIZEOF_INT;
+ case GL2.GL_DOUBLE:
+ return SIZEOF_DOUBLE;
+ }
+ return -1;
+ }
+
private BufferUtil() {}
//----------------------------------------------------------------------
// Allocation routines
//
+ public static final Buffer newGLBuffer(int glType, int numElements) {
+ switch (glType) {
+ case GL.GL_UNSIGNED_BYTE:
+ case GL.GL_BYTE:
+ return newByteBuffer(numElements);
+ case GL.GL_UNSIGNED_SHORT:
+ case GL.GL_SHORT:
+ return newShortBuffer(numElements);
+ case GL.GL_FLOAT:
+ return newFloatBuffer(numElements);
+ case GL.GL_FIXED:
+ case GL2ES2.GL_INT:
+ case GL2ES2.GL_UNSIGNED_INT:
+ return newIntBuffer(numElements);
+ }
+ return null;
+ }
+
+ public static final Buffer sliceGLBuffer(ByteBuffer parent, int bytePos, int byteLen, int glType) {
+ if(parent==null || byteLen==0) return null;
+ parent.position(bytePos);
+ parent.limit(bytePos + byteLen);
+
+ switch (glType) {
+ case GL.GL_UNSIGNED_BYTE:
+ case GL.GL_BYTE:
+ return parent.slice();
+ case GL.GL_UNSIGNED_SHORT:
+ case GL.GL_SHORT:
+ return parent.asShortBuffer();
+ case GL.GL_FLOAT:
+ return parent.asFloatBuffer();
+ case GL.GL_FIXED:
+ case GL2ES2.GL_INT:
+ case GL2ES2.GL_UNSIGNED_INT:
+ return parent.asIntBuffer();
+ }
+ return null;
+ }
+
/** Allocates a new direct ByteBuffer with the specified number of
elements. The returned buffer will have its byte order set to
the host platform's native byte order. */
@@ -288,6 +359,70 @@ public class BufferUtil {
}
//----------------------------------------------------------------------
+ // Convenient GL put methods with generic target Buffer
+ //
+ public static void put(Buffer dest, Buffer v) {
+ Class dClazz = dest.getClass();
+ Class vClazz = v.getClass();
+ if(!GLReflection.instanceOf(vClazz, dClazz.getName())) {
+ throw new GLException("This array's dest class "+dClazz+" doesn't match the argument's Class: "+vClazz);
+ }
+ if(dest instanceof ByteBuffer) {
+ ((ByteBuffer)dest).put((ByteBuffer)v);
+ } else if(dest instanceof ShortBuffer) {
+ ((ShortBuffer)dest).put((ShortBuffer)v);
+ } else if(dest instanceof IntBuffer) {
+ ((IntBuffer)dest).put((IntBuffer)v);
+ } else if(dest instanceof FloatBuffer) {
+ ((FloatBuffer)dest).put((FloatBuffer)v);
+ }
+ }
+
+ public static void putb(Buffer dest, byte v) {
+ if(dest instanceof ByteBuffer) {
+ ((ByteBuffer)dest).put(v);
+ } else if(dest instanceof ShortBuffer) {
+ ((ShortBuffer)dest).put((short)v);
+ } else if(dest instanceof IntBuffer) {
+ ((IntBuffer)dest).put((int)v);
+ } else {
+ throw new GLException("Byte doesn't match Buffer Class: "+dest);
+ }
+ }
+
+ public static void puts(Buffer dest, short v) {
+ if(dest instanceof ShortBuffer) {
+ ((ShortBuffer)dest).put(v);
+ } else if(dest instanceof IntBuffer) {
+ ((IntBuffer)dest).put((int)v);
+ } else {
+ throw new GLException("Short doesn't match Buffer Class: "+dest);
+ }
+ }
+
+ public static void puti(Buffer dest, int v) {
+ if(dest instanceof IntBuffer) {
+ ((IntBuffer)dest).put(v);
+ } else {
+ throw new GLException("Integer doesn't match Buffer Class: "+dest);
+ }
+ }
+
+ public static void putx(Buffer dest, int v) {
+ puti(dest, v);
+ }
+
+ public static void putf(Buffer dest, float v) {
+ if(dest instanceof FloatBuffer) {
+ ((FloatBuffer)dest).put(v);
+ } else if(dest instanceof IntBuffer) {
+ ((IntBuffer)dest).put(FixedPoint.toFixed(v));
+ } else {
+ throw new GLException("Float doesn't match Buffer Class: "+dest);
+ }
+ }
+
+ //----------------------------------------------------------------------
// Internals only below this point
//
diff --git a/src/classes/javax/media/opengl/util/BufferUtil.java.javase b/src/classes/javax/media/opengl/util/BufferUtil.java.javase
index 6ea6fe2c7..f9f6a5d24 100755
--- a/src/classes/javax/media/opengl/util/BufferUtil.java.javase
+++ b/src/classes/javax/media/opengl/util/BufferUtil.java.javase
@@ -39,6 +39,13 @@
package javax.media.opengl.util;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLException;
+import javax.media.opengl.GLProfile;
+import com.sun.opengl.impl.GLReflection;
+
import java.nio.*;
import java.util.*;
@@ -54,12 +61,80 @@ public class BufferUtil {
public static final int SIZEOF_LONG = 8;
public static final int SIZEOF_DOUBLE = 8;
+ public static final int sizeOfGLType(int glType) {
+ switch (glType) {
+ case GL.GL_UNSIGNED_BYTE:
+ return SIZEOF_BYTE;
+ case GL.GL_BYTE:
+ return SIZEOF_BYTE;
+ case GL.GL_UNSIGNED_SHORT:
+ return SIZEOF_SHORT;
+ case GL.GL_SHORT:
+ return SIZEOF_SHORT;
+ case GL.GL_FLOAT:
+ return SIZEOF_FLOAT;
+ case GL.GL_FIXED:
+ return SIZEOF_INT;
+ case GL2ES2.GL_INT:
+ return SIZEOF_INT;
+ case GL2ES2.GL_UNSIGNED_INT:
+ return SIZEOF_INT;
+ case GL2.GL_DOUBLE:
+ return SIZEOF_DOUBLE;
+ }
+ return -1;
+ }
+
private BufferUtil() {}
//----------------------------------------------------------------------
// Allocation routines
//
+ public static final Buffer newGLBuffer(int glType, int numElements) {
+ switch (glType) {
+ case GL.GL_UNSIGNED_BYTE:
+ case GL.GL_BYTE:
+ return newByteBuffer(numElements);
+ case GL.GL_UNSIGNED_SHORT:
+ case GL.GL_SHORT:
+ return newShortBuffer(numElements);
+ case GL.GL_FLOAT:
+ return newFloatBuffer(numElements);
+ case GL.GL_FIXED:
+ case GL2ES2.GL_INT:
+ case GL2ES2.GL_UNSIGNED_INT:
+ return newIntBuffer(numElements);
+ case GL2.GL_DOUBLE:
+ return newDoubleBuffer(numElements);
+ }
+ return null;
+ }
+
+ public static final Buffer sliceGLBuffer(ByteBuffer parent, int bytePos, int byteLen, int glType) {
+ if(parent==null || byteLen==0) return null;
+ parent.position(bytePos);
+ parent.limit(bytePos + byteLen);
+
+ switch (glType) {
+ case GL.GL_UNSIGNED_BYTE:
+ case GL.GL_BYTE:
+ return parent.slice();
+ case GL.GL_UNSIGNED_SHORT:
+ case GL.GL_SHORT:
+ return parent.asShortBuffer();
+ case GL.GL_FLOAT:
+ return parent.asFloatBuffer();
+ case GL.GL_FIXED:
+ case GL2ES2.GL_INT:
+ case GL2ES2.GL_UNSIGNED_INT:
+ return parent.asIntBuffer();
+ case GL2.GL_DOUBLE:
+ return parent.asDoubleBuffer();
+ }
+ return null;
+ }
+
/** Allocates a new direct ByteBuffer with the specified number of
elements. The returned buffer will have its byte order set to
the host platform's native byte order. */
@@ -324,6 +399,78 @@ public class BufferUtil {
}
//----------------------------------------------------------------------
+ // Convenient GL put methods with generic target Buffer
+ //
+ public static void put(Buffer dest, Buffer v) {
+ Class dClazz = dest.getClass();
+ Class vClazz = v.getClass();
+ if(!GLReflection.instanceOf(vClazz, dClazz.getName())) {
+ throw new GLException("This array's dest class "+dClazz+" doesn't match the argument's Class: "+vClazz);
+ }
+ if(dest instanceof ByteBuffer) {
+ ((ByteBuffer)dest).put((ByteBuffer)v);
+ } else if(dest instanceof ShortBuffer) {
+ ((ShortBuffer)dest).put((ShortBuffer)v);
+ } else if(dest instanceof IntBuffer) {
+ ((IntBuffer)dest).put((IntBuffer)v);
+ } else if(dest instanceof FloatBuffer) {
+ ((FloatBuffer)dest).put((FloatBuffer)v);
+ }
+ }
+
+ public static void putb(Buffer dest, byte v) {
+ if(dest instanceof ByteBuffer) {
+ ((ByteBuffer)dest).put(v);
+ } else if(dest instanceof ShortBuffer) {
+ ((ShortBuffer)dest).put((short)v);
+ } else if(dest instanceof IntBuffer) {
+ ((IntBuffer)dest).put((int)v);
+ } else {
+ throw new GLException("Byte doesn't match Buffer Class: "+dest);
+ }
+ }
+
+ public static void puts(Buffer dest, short v) {
+ if(dest instanceof ShortBuffer) {
+ ((ShortBuffer)dest).put(v);
+ } else if(dest instanceof IntBuffer) {
+ ((IntBuffer)dest).put((int)v);
+ } else {
+ throw new GLException("Short doesn't match Buffer Class: "+dest);
+ }
+ }
+
+ public static void puti(Buffer dest, int v) {
+ if(dest instanceof IntBuffer) {
+ ((IntBuffer)dest).put(v);
+ } else {
+ throw new GLException("Integer doesn't match Buffer Class: "+dest);
+ }
+ }
+
+ public static void putx(Buffer dest, int v) {
+ puti(dest, v);
+ }
+
+ public static void putf(Buffer dest, float v) {
+ if(dest instanceof FloatBuffer) {
+ ((FloatBuffer)dest).put(v);
+ } else if(dest instanceof IntBuffer) {
+ ((IntBuffer)dest).put(FixedPoint.toFixed(v));
+ } else {
+ throw new GLException("Float doesn't match Buffer Class: "+dest);
+ }
+ }
+
+ public static void putd(Buffer dest, double v) {
+ if(dest instanceof FloatBuffer) {
+ ((FloatBuffer)dest).put((float)v);
+ } else {
+ throw new GLException("Double doesn't match Buffer Class: "+dest);
+ }
+ }
+
+ //----------------------------------------------------------------------
// Internals only below this point
//
diff --git a/src/classes/javax/media/opengl/util/ImmModeSink.java b/src/classes/javax/media/opengl/util/ImmModeSink.java
index 4ef8cacf7..16b030e69 100644
--- a/src/classes/javax/media/opengl/util/ImmModeSink.java
+++ b/src/classes/javax/media/opengl/util/ImmModeSink.java
@@ -144,11 +144,12 @@ public class ImmModeSink {
e.printStackTrace();
}
if(immediateDraw) {
- vboSet.seal(gl, false);
+ vboSet.seal(gl, true);
vboSet.draw(gl, indices, true, -1);
reset(gl);
} else {
vboSet.seal(gl, true);
+ vboSet.enableBuffer(gl, false);
vboSetList.add(vboSet);
vboSet = vboSet.regenerate();
}
@@ -157,6 +158,16 @@ public class ImmModeSink {
public void glVertexv(Buffer v) {
vboSet.glVertexv(v);
}
+ public void glNormalv(Buffer v) {
+ vboSet.glNormalv(v);
+ }
+ public void glColorv(Buffer v) {
+ vboSet.glColorv(v);
+ }
+ public void glTexCoordv(Buffer v) {
+ vboSet.glTexCoordv(v);
+ }
+
public final void glVertex2f(float x, float y) {
vboSet.glVertex2f(x,y);
}
@@ -165,16 +176,10 @@ public class ImmModeSink {
vboSet.glVertex3f(x,y,z);
}
- public void glNormalv(Buffer v) {
- vboSet.glNormalv(v);
- }
public final void glNormal3f(float x, float y, float z) {
vboSet.glNormal3f(x,y,z);
}
- public void glColorv(Buffer v) {
- vboSet.glColorv(v);
- }
public final void glColor3f(float x, float y, float z) {
vboSet.glColor3f(x,y,z);
}
@@ -183,9 +188,6 @@ public class ImmModeSink {
vboSet.glColor4f(x,y,z, a);
}
- public void glTexCoordv(Buffer v) {
- vboSet.glTexCoordv(v);
- }
public final void glTexCoord2f(float x, float y) {
vboSet.glTexCoord2f(x,y);
}
@@ -292,27 +294,15 @@ public class ImmModeSink {
this.tComps=tComps;
this.useGLSL=useGLSL;
- if(!useGLSL) {
- this.vertexVBO = GLArrayDataServer.createFixed(GL.GL_VERTEX_ARRAY, null, vComps, vDataType, false, initialSize, glBufferUsage);
- this.colorVBO = GLArrayDataServer.createFixed(GL.GL_COLOR_ARRAY, null, cComps, cDataType, false, initialSize, glBufferUsage);
- this.normalVBO = GLArrayDataServer.createFixed(GL.GL_NORMAL_ARRAY, null, nComps, nDataType, false, initialSize, glBufferUsage);
- this.texcoordVBO = GLArrayDataServer.createFixed(GL.GL_TEXTURE_COORD_ARRAY, null, tComps, tDataType, false, initialSize, glBufferUsage);
- } else {
- this.vertexVBO = GLArrayDataServer.createGLSL(GLContext.mgl_Vertex, vComps, vDataType, false, initialSize, glBufferUsage);
- this.colorVBO = GLArrayDataServer.createGLSL(GLContext.mgl_Color, cComps, cDataType, false, initialSize, glBufferUsage);
- this.normalVBO = GLArrayDataServer.createGLSL(GLContext.mgl_Normal, nComps, nDataType, false, initialSize, glBufferUsage);
- this.texcoordVBO = GLArrayDataServer.createGLSL(GLContext.mgl_MultiTexCoord, tComps, tDataType, false, initialSize, glBufferUsage);
- }
- if(!vboUsage) {
- this.vertexVBO.setVBOUsage(vboUsage);
- this.colorVBO.setVBOUsage(vboUsage);
- this.normalVBO.setVBOUsage(vboUsage);
- this.texcoordVBO.setVBOUsage(vboUsage);
- }
+ allocateBuffer(initialSize);
+ rewind();
this.sealed=false;
+ this.sealedGL=false;
this.mode = -1;
this.modeOrig = -1;
+ this.bufferEnabled=false;
+ this.bufferWritten=false;
}
protected final VBOSet regenerate() {
@@ -320,39 +310,6 @@ public class ImmModeSink {
vComps, vDataType, cComps, cDataType, nComps, nDataType, tComps, tDataType, useGLSL);
}
- protected void destroy(GL gl) {
- vertexVBO.destroy(gl);
- normalVBO.destroy(gl);
- colorVBO.destroy(gl);
- texcoordVBO.destroy(gl);
-
- this.mode = -1;
- this.modeOrig = -1;
- this.sealed=false;
- }
-
- protected void reset(GL gl) {
- vertexVBO.reset(gl);
- normalVBO.reset(gl);
- colorVBO.reset(gl);
- texcoordVBO.reset(gl);
-
- this.mode = -1;
- this.modeOrig = -1;
- this.sealed=false;
- }
-
- public String toString() {
- return "VBOSet[mode "+mode+
- ", modeOrig "+modeOrig+
- ", sealed "+sealed+
- ",\n\t"+vertexVBO+
- ",\n\t"+normalVBO+
- ",\n\t"+colorVBO+
- ",\n\t"+texcoordVBO+
- "]";
- }
-
protected void checkSeal(boolean test) throws GLException {
if(mode<0) {
throw new GLException("No mode set yet, call glBegin(mode) first:\n\t"+this);
@@ -366,47 +323,17 @@ public class ImmModeSink {
}
}
- protected void rewind() {
- checkSeal(true);
-
- vertexVBO.rewind();
- normalVBO.rewind();
- colorVBO.rewind();
- texcoordVBO.rewind();
- }
-
- protected void seal(GL gl, boolean disableBufferAfterSeal)
- {
- checkSeal(false);
- sealed = true;
-
- vertexVBO.seal(gl, true);
- normalVBO.seal(gl, true);
- colorVBO.seal(gl, true);
- texcoordVBO.seal(gl, true);
-
- if(disableBufferAfterSeal) {
- vertexVBO.enableBuffer(gl, false);
- normalVBO.enableBuffer(gl, false);
- colorVBO.enableBuffer(gl, false);
- texcoordVBO.enableBuffer(gl, false);
- }
- }
-
protected void draw(GL gl, Buffer indices, boolean disableBufferAfterDraw, int i)
{
if(DEBUG_DRAW) {
Exception e = new Exception("ImmModeSink.draw["+i+"](disableBufferAfterDraw: "+disableBufferAfterDraw+"):\n\t"+this);
e.printStackTrace();
}
- normalVBO.enableBuffer(gl, true);
- colorVBO.enableBuffer(gl, true);
- texcoordVBO.enableBuffer(gl, true);
- vertexVBO.enableBuffer(gl, true);
+ enableBuffer(gl, true);
- if (vertexVBO.getBuffer()!=null) {
+ if (buffer!=null) {
if(null==indices) {
- gl.glDrawArrays(mode, 0, vertexVBO.getElementNumber());
+ gl.glDrawArrays(mode, 0, count);
} else {
Class clazz = indices.getClass();
int type=-1;
@@ -424,233 +351,615 @@ public class ImmModeSink {
}
if(disableBufferAfterDraw) {
- vertexVBO.enableBuffer(gl, false);
- texcoordVBO.enableBuffer(gl, false);
- colorVBO.enableBuffer(gl, false);
- normalVBO.enableBuffer(gl, false);
+ enableBuffer(gl, false);
}
}
- protected void glVertexv(Buffer v) {
+ public void glVertexv(Buffer v) {
checkSeal(false);
- vertexVBO.put(v);
+ BufferUtil.put(vertexArray, v);
}
- protected void glVertex2f(float x, float y) {
+ public void glNormalv(Buffer v) {
checkSeal(false);
- vertexVBO.putf(x);
- if(vertexVBO.getComponentNumber()>1)
- vertexVBO.putf(y);
- vertexVBO.padding(2);
+ BufferUtil.put(normalArray, v);
}
- protected void glVertex3f(float x, float y, float z) {
+ public void glColorv(Buffer v) {
checkSeal(false);
- vertexVBO.putf(x);
- if(vertexVBO.getComponentNumber()>1)
- vertexVBO.putf(y);
- if(vertexVBO.getComponentNumber()>2)
- vertexVBO.putf(z);
- vertexVBO.padding(3);
+ BufferUtil.put(colorArray, v);
}
-
- protected void glNormalv(Buffer v) {
+ public void glTexCoordv(Buffer v) {
checkSeal(false);
- normalVBO.put(v);
+ BufferUtil.put(textCoordArray, v);
}
- protected void glNormal3f(float x, float y, float z) {
+
+ public void glVertex2b(byte x, byte y) {
checkSeal(false);
- normalVBO.putf(x);
- if(normalVBO.getComponentNumber()>1)
- normalVBO.putf(y);
- if(normalVBO.getComponentNumber()>2)
- normalVBO.putf(z);
- normalVBO.padding(3);
+ growBufferIfNecessary(VERTEX, 2);
+ if(vComps>0)
+ BufferUtil.putb(vertexArray, x);
+ if(vComps>1)
+ BufferUtil.putb(vertexArray, y);
+ padding(VERTEX, vComps-2);
+ }
+ public void glVertex3b(byte x, byte y, byte z) {
+ checkSeal(false);
+ growBufferIfNecessary(VERTEX, 3);
+ if(vComps>0)
+ BufferUtil.putb(vertexArray, x);
+ if(vComps>1)
+ BufferUtil.putb(vertexArray, y);
+ if(vComps>2)
+ BufferUtil.putb(vertexArray, z);
+ padding(VERTEX, vComps-3);
+ }
+ public void glVertex2s(short x, short y) {
+ checkSeal(false);
+ growBufferIfNecessary(VERTEX, 2);
+ if(vComps>0)
+ BufferUtil.puts(vertexArray, x);
+ if(vComps>1)
+ BufferUtil.puts(vertexArray, y);
+ padding(VERTEX, vComps-2);
+ }
+ public void glVertex3s(short x, short y, short z) {
+ checkSeal(false);
+ growBufferIfNecessary(VERTEX, 3);
+ if(vComps>0)
+ BufferUtil.puts(vertexArray, x);
+ if(vComps>1)
+ BufferUtil.puts(vertexArray, y);
+ if(vComps>2)
+ BufferUtil.puts(vertexArray, z);
+ padding(VERTEX, vComps-3);
+ }
+ public void glVertex2f(float x, float y) {
+ checkSeal(false);
+ growBufferIfNecessary(VERTEX, 2);
+ if(vComps>0)
+ BufferUtil.putf(vertexArray, x);
+ if(vComps>1)
+ BufferUtil.putf(vertexArray, y);
+ padding(VERTEX, vComps-2);
+ }
+ public void glVertex3f(float x, float y, float z) {
+ checkSeal(false);
+ growBufferIfNecessary(VERTEX, 3);
+ if(vComps>0)
+ BufferUtil.putf(vertexArray, x);
+ if(vComps>1)
+ BufferUtil.putf(vertexArray, y);
+ if(vComps>2)
+ BufferUtil.putf(vertexArray, z);
+ padding(VERTEX, vComps-3);
}
- protected void glColorv(Buffer v) {
+ public void glNormal3b(byte x, byte y, byte z) {
checkSeal(false);
- colorVBO.put(v);
- }
- protected void glColor3f(float x, float y, float z) {
+ growBufferIfNecessary(NORMAL, 3);
+ if(nComps>0)
+ BufferUtil.putb(normalArray, x);
+ if(nComps>1)
+ BufferUtil.putb(normalArray, y);
+ if(nComps>2)
+ BufferUtil.putb(normalArray, z);
+ padding(NORMAL, nComps-3);
+ }
+ public void glNormal3s(short x, short y, short z) {
checkSeal(false);
- colorVBO.putf(x);
- if(colorVBO.getComponentNumber()>1)
- colorVBO.putf(y);
- if(colorVBO.getComponentNumber()>2)
- colorVBO.putf(z);
- colorVBO.padding(3);
- }
- protected void glColor4f(float x, float y, float z, float a) {
+ growBufferIfNecessary(NORMAL, 3);
+ if(nComps>0)
+ BufferUtil.puts(normalArray, x);
+ if(nComps>1)
+ BufferUtil.puts(normalArray, y);
+ if(nComps>2)
+ BufferUtil.puts(normalArray, z);
+ padding(NORMAL, nComps-3);
+ }
+ public void glNormal3f(float x, float y, float z) {
checkSeal(false);
- colorVBO.putf(x);
- if(colorVBO.getComponentNumber()>1)
- colorVBO.putf(y);
- if(colorVBO.getComponentNumber()>2)
- colorVBO.putf(z);
- if(colorVBO.getComponentNumber()>3)
- colorVBO.putf(a);
- colorVBO.padding(4);
+ growBufferIfNecessary(NORMAL, 3);
+ if(nComps>0)
+ BufferUtil.putf(normalArray, x);
+ if(nComps>1)
+ BufferUtil.putf(normalArray, y);
+ if(nComps>2)
+ BufferUtil.putf(normalArray, z);
+ padding(NORMAL, nComps-3);
}
- protected void glTexCoordv(Buffer v) {
+ public void glColor3b(byte r, byte g, byte b) {
checkSeal(false);
- texcoordVBO.put(v);
- }
- protected void glTexCoord2f(float x, float y) {
+ growBufferIfNecessary(COLOR, 3);
+ if(cComps>0)
+ BufferUtil.putb(colorArray, r);
+ if(cComps>1)
+ BufferUtil.putb(colorArray, g);
+ if(cComps>2)
+ BufferUtil.putb(colorArray, b);
+ padding(COLOR, cComps-3);
+ }
+ public void glColor4b(byte r, byte g, byte b, byte a) {
checkSeal(false);
- texcoordVBO.putf(x);
- if(texcoordVBO.getComponentNumber()>1)
- texcoordVBO.putf(y);
- texcoordVBO.padding(2);
- }
- protected void glTexCoord3f(float x, float y, float z) {
+ growBufferIfNecessary(COLOR, 4);
+ if(cComps>0)
+ BufferUtil.putb(colorArray, r);
+ if(cComps>1)
+ BufferUtil.putb(colorArray, g);
+ if(cComps>2)
+ BufferUtil.putb(colorArray, b);
+ if(cComps>3)
+ BufferUtil.putb(colorArray, a);
+ padding(COLOR, cComps-4);
+ }
+ public void glColor3s(short r, short g, short b) {
+ checkSeal(false);
+ growBufferIfNecessary(COLOR, 3);
+ if(cComps>0)
+ BufferUtil.puts(colorArray, r);
+ if(cComps>1)
+ BufferUtil.puts(colorArray, g);
+ if(cComps>2)
+ BufferUtil.puts(colorArray, b);
+ padding(COLOR, cComps-3);
+ }
+ public void glColor4s(short r, short g, short b, short a) {
+ checkSeal(false);
+ growBufferIfNecessary(COLOR, 4);
+ if(cComps>0)
+ BufferUtil.puts(colorArray, r);
+ if(cComps>1)
+ BufferUtil.puts(colorArray, g);
+ if(cComps>2)
+ BufferUtil.puts(colorArray, b);
+ if(cComps>3)
+ BufferUtil.puts(colorArray, a);
+ padding(COLOR, cComps-4);
+ }
+ public void glColor3f(float r, float g, float b) {
+ checkSeal(false);
+ growBufferIfNecessary(COLOR, 3);
+ if(cComps>0)
+ BufferUtil.putf(colorArray, r);
+ if(cComps>1)
+ BufferUtil.putf(colorArray, g);
+ if(cComps>2)
+ BufferUtil.putf(colorArray, b);
+ padding(COLOR, cComps-3);
+ }
+ public void glColor4f(float r, float g, float b, float a) {
+ checkSeal(false);
+ growBufferIfNecessary(COLOR, 4);
+ if(cComps>0)
+ BufferUtil.putf(colorArray, r);
+ if(cComps>1)
+ BufferUtil.putf(colorArray, g);
+ if(cComps>2)
+ BufferUtil.putf(colorArray, b);
+ if(cComps>3)
+ BufferUtil.putf(colorArray, a);
+ padding(COLOR, cComps-4);
+ }
+
+ public void glTexCoord2b(byte x, byte y) {
checkSeal(false);
- texcoordVBO.putf(x);
- if(texcoordVBO.getComponentNumber()>1)
- texcoordVBO.putf(y);
- if(texcoordVBO.getComponentNumber()>2)
- texcoordVBO.putf(z);
- texcoordVBO.padding(3);
+ growBufferIfNecessary(TEXTCOORD, 2);
+ if(tComps>0)
+ BufferUtil.putb(textCoordArray, x);
+ if(tComps>1)
+ BufferUtil.putb(textCoordArray, y);
+ padding(TEXTCOORD, tComps-2);
+ }
+ public void glTexCoord3b(byte x, byte y, byte z) {
+ checkSeal(false);
+ growBufferIfNecessary(TEXTCOORD, 3);
+ if(tComps>0)
+ BufferUtil.putb(textCoordArray, x);
+ if(tComps>1)
+ BufferUtil.putb(textCoordArray, y);
+ if(tComps>2)
+ BufferUtil.putb(textCoordArray, z);
+ padding(TEXTCOORD, tComps-3);
+ }
+ public void glTexCoord2s(short x, short y) {
+ checkSeal(false);
+ growBufferIfNecessary(TEXTCOORD, 2);
+ if(tComps>0)
+ BufferUtil.puts(textCoordArray, x);
+ if(tComps>1)
+ BufferUtil.puts(textCoordArray, y);
+ padding(TEXTCOORD, tComps-2);
+ }
+ public void glTexCoord3s(short x, short y, short z) {
+ checkSeal(false);
+ growBufferIfNecessary(TEXTCOORD, 3);
+ if(tComps>0)
+ BufferUtil.puts(textCoordArray, x);
+ if(tComps>1)
+ BufferUtil.puts(textCoordArray, y);
+ if(tComps>2)
+ BufferUtil.puts(textCoordArray, z);
+ padding(TEXTCOORD, tComps-3);
+ }
+ public void glTexCoord2f(float x, float y) {
+ checkSeal(false);
+ growBufferIfNecessary(TEXTCOORD, 2);
+ if(tComps>0)
+ BufferUtil.putf(textCoordArray, x);
+ if(tComps>1)
+ BufferUtil.putf(textCoordArray, y);
+ padding(TEXTCOORD, tComps-2);
+ }
+ public void glTexCoord3f(float x, float y, float z) {
+ checkSeal(false);
+ growBufferIfNecessary(TEXTCOORD, 3);
+ if(tComps>0)
+ BufferUtil.putf(textCoordArray, x);
+ if(tComps>1)
+ BufferUtil.putf(textCoordArray, y);
+ if(tComps>2)
+ BufferUtil.putf(textCoordArray, z);
+ padding(TEXTCOORD, tComps-3);
+ }
+
+ public void rewind() {
+ if(null!=vertexArray) {
+ vertexArray.rewind();
+ }
+ if(null!=colorArray) {
+ colorArray.rewind();
+ }
+ if(null!=normalArray) {
+ normalArray.rewind();
+ }
+ if(null!=textCoordArray) {
+ textCoordArray.rewind();
+ }
}
- protected void glVertex2s(short x, short y) {
- checkSeal(false);
- vertexVBO.puts(x);
- if(vertexVBO.getComponentNumber()>1)
- vertexVBO.puts(y);
- vertexVBO.padding(2);
+ public void destroy(GL gl) {
+ reset(gl);
+
+ vertexArray=null; colorArray=null; normalArray=null; textCoordArray=null;
+ vArrayData=null; cArrayData=null; nArrayData=null; tArrayData=null;
+ buffer=null;
+ bSize=0; count=0;
}
- protected void glVertex3s(short x, short y, short z) {
- checkSeal(false);
- vertexVBO.puts(x);
- if(vertexVBO.getComponentNumber()>1)
- vertexVBO.puts(y);
- if(vertexVBO.getComponentNumber()>2)
- vertexVBO.puts(z);
- vertexVBO.padding(3);
+
+ public void reset(GL gl) {
+ enableBuffer(gl, false);
+ reset();
}
- protected void glNormal3s(short x, short y, short z) {
- checkSeal(false);
- normalVBO.puts(x);
- if(normalVBO.getComponentNumber()>1)
- normalVBO.puts(y);
- if(normalVBO.getComponentNumber()>2)
- normalVBO.puts(z);
- normalVBO.padding(3);
+ public void reset() {
+ if(buffer!=null) {
+ buffer.clear();
+ }
+ rewind();
+
+ this.mode = -1;
+ this.modeOrig = -1;
+ this.sealed=false;
+ this.bufferEnabled=false;
+ this.bufferWritten=false;
}
- protected void glColor3s(short x, short y, short z) {
- checkSeal(false);
- colorVBO.puts(x);
- if(colorVBO.getComponentNumber()>1)
- colorVBO.puts(y);
- 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.getComponentNumber()>1)
- colorVBO.puts(y);
- if(colorVBO.getComponentNumber()>2)
- colorVBO.puts(z);
- if(colorVBO.getComponentNumber()>3)
- colorVBO.puts(a);
- colorVBO.padding(4);
+ public void seal(GL gl, boolean seal)
+ {
+ seal(seal);
+ if(sealedGL==seal) return;
+ sealedGL = seal;
+ if(seal) {
+ if(vboUsage && vboName==0) {
+ int[] tmp = new int[1];
+ gl.glGenBuffers(1, tmp, 0);
+ vboName = tmp[0];
+ }
+ if(null!=vArrayData)
+ vArrayData.setVBOName(vboName);
+ if(null!=cArrayData)
+ cArrayData.setVBOName(vboName);
+ if(null!=nArrayData)
+ nArrayData.setVBOName(vboName);
+ if(null!=tArrayData)
+ tArrayData.setVBOName(vboName);
+ enableBuffer(gl, true);
+ } else {
+ enableBuffer(gl, false);
+ }
}
- protected void glTexCoord2s(short x, short y) {
- checkSeal(false);
- texcoordVBO.puts(x);
- if(texcoordVBO.getComponentNumber()>1)
- texcoordVBO.puts(y);
- texcoordVBO.padding(2);
+ public void seal(boolean seal)
+ {
+ if(sealed==seal) return;
+ sealed = seal;
+ if(seal) {
+ bufferWritten=false;
+ }
}
- protected void glTexCoord3s(short x, short y, short z) {
- checkSeal(false);
- texcoordVBO.puts(x);
- if(texcoordVBO.getComponentNumber()>1)
- texcoordVBO.puts(y);
- if(texcoordVBO.getComponentNumber()>2)
- texcoordVBO.puts(z);
- texcoordVBO.padding(3);
+
+ public void enableBuffer(GL gl, boolean enable) {
+ /* if(enableBufferAlways && enable) {
+ bufferEnabled = false;
+ } */
+ if( bufferEnabled != enable && count>0 ) {
+ if(enable) {
+ checkSeal(true);
+ }
+ if(useGLSL) {
+ enableBufferGLSL(gl, enable);
+ } else {
+ enableBufferFixed(gl, enable);
+ }
+ bufferEnabled = enable;
}
+ }
- protected void glVertex2b(byte x, byte y) {
- checkSeal(false);
- vertexVBO.putb(x);
- if(vertexVBO.getComponentNumber()>1)
- vertexVBO.putb(y);
- vertexVBO.padding(2);
+ public void enableBufferFixed(GL gl, boolean enable) {
+ if(enable) {
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName);
+
+ if(!bufferWritten) {
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit(), buffer, GL.GL_STATIC_DRAW);
+ bufferWritten=true;
+ }
+
+ if(vComps>0) {
+ gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
+ gl.glVertexPointer(vArrayData);
+ }
+ if(cComps>0) {
+ gl.glEnableClientState(gl.GL_COLOR_ARRAY);
+ gl.glColorPointer(cArrayData);
+ }
+ if(nComps>0) {
+ gl.glEnableClientState(gl.GL_NORMAL_ARRAY);
+ gl.glNormalPointer(nArrayData);
+ }
+ if(tComps>0) {
+ gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY);
+ gl.glTexCoordPointer(tArrayData);
+ }
+
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+ } else {
+ if(vComps>0) {
+ gl.glDisableClientState(gl.GL_VERTEX_ARRAY);
+ }
+ if(cComps>0) {
+ gl.glDisableClientState(gl.GL_COLOR_ARRAY);
+ }
+ if(nComps>0) {
+ gl.glDisableClientState(gl.GL_NORMAL_ARRAY);
+ }
+ if(tComps>0) {
+ gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY);
+ }
}
- protected void glVertex3b(byte x, byte y, byte z) {
- checkSeal(false);
- vertexVBO.putb(x);
- if(vertexVBO.getComponentNumber()>1)
- vertexVBO.putb(y);
- if(vertexVBO.getComponentNumber()>2)
- vertexVBO.putb(z);
- vertexVBO.padding(3);
+ }
+
+ public void enableBufferGLSL(GL gl, boolean enable) {
+ GL2ES2 glsl = gl.getGL2ES2();
+ javax.media.opengl.glsl.ShaderState st = javax.media.opengl.glsl.ShaderState.getCurrent();
+ if(null==st) {
+ throw new GLException("No ShaderState current");
}
+
+ if(enable) {
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName);
- protected void glNormal3b(byte x, byte y, byte z) {
- checkSeal(false);
- normalVBO.putb(x);
- if(normalVBO.getComponentNumber()>1)
- normalVBO.putb(y);
- if(normalVBO.getComponentNumber()>2)
- normalVBO.putb(z);
- normalVBO.padding(3);
+ if(!bufferWritten) {
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit(), buffer, GL.GL_STATIC_DRAW);
+ bufferWritten=true;
+ }
+
+ if(vComps>0) {
+ st.glEnableVertexAttribArray(glsl, vArrayData.getName());
+ st.glVertexAttribPointer(glsl, vArrayData);
+ }
+ if(cComps>0) {
+ st.glEnableVertexAttribArray(glsl, cArrayData.getName());
+ st.glVertexAttribPointer(glsl, cArrayData);
+ }
+ if(nComps>0) {
+ st.glEnableVertexAttribArray(glsl, nArrayData.getName());
+ st.glVertexAttribPointer(glsl, nArrayData);
+ }
+ if(tComps>0) {
+ st.glEnableVertexAttribArray(glsl, tArrayData.getName());
+ st.glVertexAttribPointer(glsl, tArrayData);
+ }
+
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+ } else {
+ if(vComps>0) {
+ st.glDisableVertexAttribArray(glsl, vArrayData.getName());
+ }
+ if(cComps>0) {
+ st.glDisableVertexAttribArray(glsl, cArrayData.getName());
+ }
+ if(nComps>0) {
+ st.glDisableVertexAttribArray(glsl, nArrayData.getName());
+ }
+ if(tComps>0) {
+ st.glDisableVertexAttribArray(glsl, tArrayData.getName());
+ }
}
+ }
- protected void glColor3b(byte x, byte y, byte z) {
- checkSeal(false);
- colorVBO.putb(x);
- if(colorVBO.getComponentNumber()>1)
- colorVBO.putb(y);
- 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.getComponentNumber()>1)
- colorVBO.putb(y);
- if(colorVBO.getComponentNumber()>2)
- colorVBO.putb(z);
- if(colorVBO.getComponentNumber()>3)
- colorVBO.putb(a);
- colorVBO.padding(4);
- }
- protected void glTexCoord2b(byte x, byte y) {
- checkSeal(false);
- texcoordVBO.putb(x);
- if(texcoordVBO.getComponentNumber()>1)
- texcoordVBO.putb(y);
- texcoordVBO.padding(2);
+ public String toString() {
+ return "VBOSet[mode "+mode+
+ ", modeOrig "+modeOrig+
+ ", sealed "+sealed+
+ ", bufferEnabled "+bufferEnabled+
+ ", bufferWritten "+bufferWritten+
+ ",\n\t"+vArrayData+
+ ",\n\t"+cArrayData+
+ ",\n\t"+nArrayData+
+ ",\n\t"+tArrayData+
+ "]";
}
- protected void glTexCoord3b(byte x, byte y, byte z) {
- checkSeal(false);
- texcoordVBO.putb(x);
- if(texcoordVBO.getComponentNumber()>1)
- texcoordVBO.putb(y);
- if(texcoordVBO.getComponentNumber()>2)
- texcoordVBO.putb(z);
- texcoordVBO.padding(3);
- }
-
- GLArrayDataServer vertexVBO;
- GLArrayDataServer normalVBO;
- GLArrayDataServer colorVBO;
- GLArrayDataServer texcoordVBO;
- int mode, modeOrig;
- int glBufferUsage, initialSize;
- int vComps, cComps, nComps, tComps;
- int vDataType, cDataType, nDataType, tDataType;
- boolean sealed, useGLSL;
+ // non public matters
+
+ protected void allocateBuffer(int elements) {
+ int vWidth = vComps * BufferUtil.sizeOfGLType(vDataType);
+ int cWidth = cComps * BufferUtil.sizeOfGLType(cDataType);
+ int nWidth = nComps * BufferUtil.sizeOfGLType(nDataType);
+ int tWidth = tComps * BufferUtil.sizeOfGLType(tDataType);
+
+ count = elements;
+ bSize = count * ( vWidth + cWidth + nWidth + tWidth ) ;
+
+ buffer = BufferUtil.newByteBuffer(bSize);
+
+ int pos = 0;
+ int size= count * vWidth ;
+ if(size>0) {
+ vertexArray = BufferUtil.sliceGLBuffer(buffer, pos, size, vDataType);
+ } else {
+ vertexArray = null;
+ }
+ vOffset = pos;
+ pos+=size;
+
+ size= count * cWidth ;
+ if(size>0) {
+ colorArray = BufferUtil.sliceGLBuffer(buffer, pos, size, cDataType);
+ } else {
+ colorArray = null;
+ }
+ cOffset = pos;
+ pos+=size;
+
+ size= count * nWidth ;
+ if(size>0) {
+ normalArray = BufferUtil.sliceGLBuffer(buffer, pos, size, nDataType);
+ } else {
+ normalArray = null;
+ }
+ nOffset = pos;
+ pos+=size;
+
+ size= count * tWidth ;
+ if(size>0) {
+ textCoordArray = BufferUtil.sliceGLBuffer(buffer, pos, size, tDataType);
+ } else {
+ textCoordArray = null;
+ }
+ tOffset = pos;
+ pos+=size;
+
+ buffer.position(pos);
+ buffer.flip();
+
+ if(vComps>0) {
+ vArrayData = GLArrayDataWrapper.createFixed(GL.GL_VERTEX_ARRAY, vComps, vDataType, false,
+ 0, vertexArray, 0, vOffset);
+ } else {
+ vArrayData = null;
+ }
+ if(cComps>0) {
+ cArrayData = GLArrayDataWrapper.createFixed(GL.GL_COLOR_ARRAY, cComps, cDataType, false,
+ 0, colorArray, 0, cOffset);
+ } else {
+ cArrayData = null;
+ }
+ if(nComps>0) {
+ nArrayData = GLArrayDataWrapper.createFixed(GL.GL_NORMAL_ARRAY, nComps, nDataType, false,
+ 0, normalArray, 0, nOffset);
+ } else {
+ nArrayData = null;
+ }
+ if(tComps>0) {
+ tArrayData = GLArrayDataWrapper.createFixed(GL.GL_TEXTURE_COORD_ARRAY, tComps, tDataType, false,
+ 0, textCoordArray, 0, tOffset);
+ } else {
+ tArrayData = null;
+ }
+
+ }
+
+ protected final boolean growBufferIfNecessary(int type, int spare) {
+ if(buffer==null || count < spare) {
+ growBuffer(type, initialSize);
+ return true;
+ }
+ return false;
+ }
+
+ protected final void growBuffer(int type, int additional) {
+ if(sealed || 0==additional) return;
+
+ // save olde values ..
+ Buffer _vertexArray=vertexArray, _colorArray=colorArray, _normalArray=normalArray, _textCoordArray=textCoordArray;
+ ByteBuffer _buffer = buffer;
+
+ allocateBuffer(count+additional);
+
+ if(null!=_vertexArray) {
+ _vertexArray.flip();
+ BufferUtil.put(vertexArray, _vertexArray);
+ }
+ if(null!=_colorArray) {
+ _colorArray.flip();
+ BufferUtil.put(colorArray, _colorArray);
+ }
+ if(null!=_normalArray) {
+ _normalArray.flip();
+ BufferUtil.put(normalArray, _normalArray);
+ }
+ if(null!=_textCoordArray) {
+ _textCoordArray.flip();
+ BufferUtil.put(textCoordArray, _textCoordArray);
+ }
+ }
+
+ protected void padding(int type, int fill) {
+ if ( sealed ) return;
+
+ Buffer dest = null;
+
+ switch (type) {
+ case VERTEX:
+ dest = vertexArray;
+ break;
+ case COLOR:
+ dest = colorArray;
+ break;
+ case NORMAL:
+ dest = normalArray;
+ break;
+ case TEXTCOORD:
+ dest = textCoordArray;
+ break;
+ }
+
+ if ( null==dest ) return;
+
+ while((fill--)>0) {
+ BufferUtil.putb(dest, (byte)0);
+ }
+ }
+
+ protected int mode, modeOrig;
+ protected int glBufferUsage, initialSize;
+
+ protected ByteBuffer buffer;
+ protected int bSize, count, vboName;
+
+ public static final int VERTEX = 0;
+ public static final int COLOR = 1;
+ public static final int NORMAL = 2;
+ public static final int TEXTCOORD = 3;
+
+ protected int vOffset, cOffset, nOffset, tOffset;
+ protected int vComps, cComps, nComps, tComps;
+ protected int vDataType, cDataType, nDataType, tDataType;
+ protected Buffer vertexArray, colorArray, normalArray, textCoordArray;
+ protected GLArrayDataWrapper vArrayData, cArrayData, nArrayData, tArrayData;
+
+ protected boolean sealed, sealedGL, useGLSL;
+ protected boolean bufferEnabled, bufferWritten;
}
}