aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp
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/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp
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/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp')
-rwxr-xr-xsrc/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp135
1 files changed, 135 insertions, 0 deletions
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
//