diff options
Diffstat (limited to 'src/jogl/classes/javax/media')
13 files changed, 157 insertions, 1985 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLBase.java b/src/jogl/classes/javax/media/opengl/GLBase.java new file mode 100644 index 000000000..9d88bae58 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLBase.java @@ -0,0 +1,105 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + */ + +package javax.media.opengl; + +import java.nio.*; + +/** + * The base interface from which all GL profiles derive, providing + * checked conversion down to concrete profiles, and access to the + * OpenGL context associated with the GL. + */ +public interface GLBase { + + /** + * Indicates whether this GL object conforms to any of the common GL profiles. + * @return whether this GL object conforms to any of the common GL profiles + */ + public boolean isGL(); + + /** + * Indicates whether this GL object conforms to the GL2 profile. + * @return whether this GL object conforms to the GL2 profile + */ + public boolean isGL2(); + + /** + * Indicates whether this GL object conforms to the GLES1 profile. + * @return whether this GL object conforms to the GLES1 profile + */ + public boolean isGLES1(); + + /** + * Indicates whether this GL object conforms to the GLES2 profile. + * @return whether this GL object conforms to the GLES2 profile + */ + public boolean isGLES2(); + + /** + * Indicates whether this GL object conforms to one of the OpenGL ES profiles. + * @return whether this GL object conforms to one of the OpenGL ES profiles + */ + public boolean isGLES(); + + /** + * Indicates whether this GL object conforms to the GL2ES1 profile. + * @return whether this GL object conforms to the GL2ES1 profile + */ + public boolean isGL2ES1(); + + /** + * Indicates whether this GL object conforms to the GL2ES2 profile. + * @return whether this GL object conforms to the GL2ES2 profile + */ + public boolean isGL2ES2(); + + /** + * Casts this object to the GL interface. + * @return this object cast to the GL interface + * @throws GLException if this GLObject is not a GL implementation + */ + public GL getGL() throws GLException; + + /** + * Casts this object to the GL2 interface. + * @return this object cast to the GL2 interface + * @throws GLException if this GLObject is not a GL2 implementation + */ + public GL2 getGL2() throws GLException; + + /** + * Casts this object to the GLES1 interface. + * @return this object cast to the GLES1 interface + * @throws GLException if this GLObject is not a GLES1 implementation + */ + public GLES1 getGLES1() throws GLException; + + /** + * Casts this object to the GLES2 interface. + * @return this object cast to the GLES2 interface + * @throws GLException if this GLObject is not a GLES2 implementation + */ + public GLES2 getGLES2() throws GLException; + + /** + * Casts this object to the GL2ES1 interface. + * @return this object cast to the GL2ES1 interface + * @throws GLException if this GLObject is not a GL2ES1 implementation + */ + public GL2ES1 getGL2ES1() throws GLException; + + /** + * Casts this object to the GL2ES2 interface. + * @return this object cast to the GL2ES2 interface + * @throws GLException if this GLObject is not a GL2ES2 implementation + */ + public GL2ES2 getGL2ES2() throws GLException; + + /** + * Returns the GLContext with which this GL object is associated. + * @return the GLContext with which this GL object is associated + */ + public GLContext getContext(); +} diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index 78252b4e8..5a4631560 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -40,7 +40,6 @@ package javax.media.opengl; import com.sun.opengl.impl.Debug; -import javax.media.opengl.sub.fixed.*; import java.util.HashMap; /** Abstraction for an OpenGL rendering context. In order to perform @@ -229,63 +228,4 @@ public abstract class GLContext { GLX) extensions. Can only be called while this context is current. */ public abstract String getPlatformExtensionsString(); - - /** - * Mapping fixed function (client) array indices to - * GLSL array attribute names. - * - * Useful for uniq mapping of canonical array index names as listed. - * - * @see #mgl_Vertex - * @see javax.media.opengl.sub.fixed.GLPointerIf#GL_VERTEX_ARRAY - * @see #mgl_Normal - * @see javax.media.opengl.sub.fixed.GLPointerIf#GL_NORMAL_ARRAY - * @see #mgl_Color - * @see javax.media.opengl.sub.fixed.GLPointerIf#GL_COLOR_ARRAY - * @see #mgl_MultiTexCoord - * @see javax.media.opengl.sub.fixed.GLPointerIf#GL_TEXTURE_COORD_ARRAY - * @see javax.media.opengl.sub.fixed.GLPointerIf#glEnableClientState - * @see javax.media.opengl.sub.fixed.GLPointerIf#glVertexPointer - * @see javax.media.opengl.sub.fixed.GLPointerIf#glColorPointer - * @see javax.media.opengl.sub.fixed.GLPointerIf#glNormalPointer - * @see javax.media.opengl.sub.fixed.GLPointerIf#glTexCoordPointer - */ - public static String getPredefinedArrayIndexName(int glArrayIndex) { - switch(glArrayIndex) { - case GLPointerIf.GL_VERTEX_ARRAY: - return mgl_Vertex; - case GLPointerIf.GL_NORMAL_ARRAY: - return mgl_Normal; - case GLPointerIf.GL_COLOR_ARRAY: - return mgl_Color; - case GLPointerIf.GL_TEXTURE_COORD_ARRAY: - return mgl_MultiTexCoord; - } - return null; - } - - /** - * String name for - * @see javax.media.opengl.GL#GL_VERTEX_ARRAY - */ - public static final String mgl_Vertex = "mgl_Vertex"; - - /** - * String name for - * @see javax.media.opengl.GL#GL_NORMAL_ARRAY - */ - public static final String mgl_Normal = "mgl_Normal"; - - /** - * String name for - * @see javax.media.opengl.GL#GL_COLOR_ARRAY - */ - public static final String mgl_Color = "mgl_Color"; - - /** - * String name for - * @see javax.media.opengl.GL#GL_TEXTURE_COORD_ARRAY - */ - public static final String mgl_MultiTexCoord = "mgl_MultiTexCoord" ; - } diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index 54bf63dda..0d20f1a4d 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -36,7 +36,7 @@ package javax.media.opengl; -import javax.media.opengl.sub.fixed.*; +import javax.media.opengl.fixedfunc.*; import java.lang.reflect.*; import java.security.*; import com.sun.opengl.impl.*; @@ -235,7 +235,7 @@ public class GLProfile { } } - public static String getGLTypeName(int type) { + private static String getGLTypeName(int type) { switch (type) { case GL.GL_UNSIGNED_BYTE: return "GL_UNSIGNED_BYTE"; @@ -265,6 +265,20 @@ public class GLProfile { return null; } + private static String getGLArrayName(int array) { + switch(array) { + case GLPointerFunc.GL_VERTEX_ARRAY: + return "GL_VERTEX_ARRAY"; + case GLPointerFunc.GL_NORMAL_ARRAY: + return "GL_NORMAL_ARRAY"; + case GLPointerFunc.GL_COLOR_ARRAY: + return "GL_COLOR_ARRAY"; + case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: + return "GL_TEXTURE_COORD_ARRAY"; + } + return null; + } + /** * General validation if type is a valid GL data type * for the current profile @@ -297,19 +311,19 @@ public class GLProfile { return false; } - public static boolean isValidateArrayDataType(int index, int comps, int type, - boolean isVertexAttribPointer, boolean throwException) { - String indexName = GLContext.getPredefinedArrayIndexName(index); + public static boolean isValidArrayDataType(int index, int comps, int type, + boolean isVertexAttribPointer, boolean throwException) { + String arrayName = getGLArrayName(index); if(GLProfile.isGLES1()) { if(isVertexAttribPointer) { if(throwException) { - throw new GLException("Illegal array type for "+indexName+" on profile GLES1: VertexAttribPointer"); + throw new GLException("Illegal array type for "+arrayName+" on profile GLES1: VertexAttribPointer"); } return false; } switch(index) { - case GLPointerIf.GL_VERTEX_ARRAY: - case GLPointerIf.GL_TEXTURE_COORD_ARRAY: + case GLPointerFunc.GL_VERTEX_ARRAY: + case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: switch(type) { case GL.GL_BYTE: case GL.GL_SHORT: @@ -318,7 +332,7 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal data type for "+indexName+" on profile GLES1: "+type); + throw new GLException("Illegal data type for "+arrayName+" on profile GLES1: "+type); } return false; } @@ -330,12 +344,12 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal component number for "+indexName+" on profile GLES1: "+comps); + throw new GLException("Illegal component number for "+arrayName+" on profile GLES1: "+comps); } return false; } break; - case GLPointerIf.GL_NORMAL_ARRAY: + case GLPointerFunc.GL_NORMAL_ARRAY: switch(type) { case GL.GL_BYTE: case GL.GL_SHORT: @@ -344,7 +358,7 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal data type for "+indexName+" on profile GLES1: "+type); + throw new GLException("Illegal data type for "+arrayName+" on profile GLES1: "+type); } return false; } @@ -354,12 +368,12 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal component number for "+indexName+" on profile GLES1: "+comps); + throw new GLException("Illegal component number for "+arrayName+" on profile GLES1: "+comps); } return false; } break; - case GLPointerIf.GL_COLOR_ARRAY: + case GLPointerFunc.GL_COLOR_ARRAY: switch(type) { case GL.GL_UNSIGNED_BYTE: case GL.GL_FIXED: @@ -367,7 +381,7 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal data type for "+indexName+" on profile GLES1: "+type); + throw new GLException("Illegal data type for "+arrayName+" on profile GLES1: "+type); } return false; } @@ -377,7 +391,7 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal component number for "+indexName+" on profile GLES1: "+comps); + throw new GLException("Illegal component number for "+arrayName+" on profile GLES1: "+comps); } return false; } @@ -396,7 +410,7 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal data type for "+indexName+" on profile GLES2: "+type); + throw new GLException("Illegal data type for "+arrayName+" on profile GLES2: "+type); } return false; } @@ -409,7 +423,7 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal component number for "+indexName+" on profile GLES1: "+comps); + throw new GLException("Illegal component number for "+arrayName+" on profile GLES1: "+comps); } return false; } @@ -427,7 +441,7 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal data type for "+indexName+" on profile GL2: "+type); + throw new GLException("Illegal data type for "+arrayName+" on profile GL2: "+type); } return false; } @@ -440,13 +454,13 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal component number for "+indexName+" on profile GL2: "+comps); + throw new GLException("Illegal component number for "+arrayName+" on profile GL2: "+comps); } return false; } } else { switch(index) { - case GLPointerIf.GL_VERTEX_ARRAY: + case GLPointerFunc.GL_VERTEX_ARRAY: switch(type) { case GL.GL_SHORT: case GL.GL_FLOAT: @@ -455,7 +469,7 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal data type for "+indexName+" on profile GL2: "+type); + throw new GLException("Illegal data type for "+arrayName+" on profile GL2: "+type); } return false; } @@ -467,12 +481,12 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal component number for "+indexName+" on profile GL2: "+comps); + throw new GLException("Illegal component number for "+arrayName+" on profile GL2: "+comps); } return false; } break; - case GLPointerIf.GL_NORMAL_ARRAY: + case GLPointerFunc.GL_NORMAL_ARRAY: switch(type) { case GL.GL_BYTE: case GL.GL_SHORT: @@ -482,7 +496,7 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal data type for "+indexName+" on profile GL2: "+type); + throw new GLException("Illegal data type for "+arrayName+" on profile GL2: "+type); } return false; } @@ -492,12 +506,12 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal component number for "+indexName+" on profile GLES1: "+comps); + throw new GLException("Illegal component number for "+arrayName+" on profile GLES1: "+comps); } return false; } break; - case GLPointerIf.GL_COLOR_ARRAY: + case GLPointerFunc.GL_COLOR_ARRAY: switch(type) { case GL.GL_UNSIGNED_BYTE: case GL.GL_BYTE: @@ -510,7 +524,7 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal data type for "+indexName+" on profile GL2: "+type); + throw new GLException("Illegal data type for "+arrayName+" on profile GL2: "+type); } return false; } @@ -521,12 +535,12 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal component number for "+indexName+" on profile GL2: "+comps); + throw new GLException("Illegal component number for "+arrayName+" on profile GL2: "+comps); } return false; } break; - case GLPointerIf.GL_TEXTURE_COORD_ARRAY: + case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: switch(type) { case GL.GL_SHORT: case GL.GL_FLOAT: @@ -535,7 +549,7 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal data type for "+indexName+" on profile GL2: "+type); + throw new GLException("Illegal data type for "+arrayName+" on profile GL2: "+type); } return false; } @@ -548,7 +562,7 @@ public class GLProfile { break; default: if(throwException) { - throw new GLException("Illegal component number for "+indexName+" on profile GL2: "+comps); + throw new GLException("Illegal component number for "+arrayName+" on profile GL2: "+comps); } return false; } @@ -558,5 +572,4 @@ public class GLProfile { } return true; } - } diff --git a/src/jogl/classes/javax/media/opengl/sub/fixed/GLLightingIf.java b/src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java index 1f3aa9ab7..5563ea9c8 100644 --- a/src/jogl/classes/javax/media/opengl/sub/fixed/GLLightingIf.java +++ b/src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java @@ -2,14 +2,13 @@ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. */ -package javax.media.opengl.sub.fixed; +package javax.media.opengl.fixedfunc; import java.nio.*; import javax.media.opengl.*; -import javax.media.opengl.sub.*; -public interface GLLightingIf { +public interface GLLightingFunc { public static final int GL_LIGHT0 = 0x4000; public static final int GL_LIGHT1 = 0x4001; public static final int GL_LIGHT2 = 0x4002; diff --git a/src/jogl/classes/javax/media/opengl/sub/fixed/GLMatrixIf.java b/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java index 834731b98..61757abde 100644 --- a/src/jogl/classes/javax/media/opengl/sub/fixed/GLMatrixIf.java +++ b/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java @@ -2,14 +2,13 @@ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. */ -package javax.media.opengl.sub.fixed; +package javax.media.opengl.fixedfunc; import java.nio.*; import javax.media.opengl.*; -import javax.media.opengl.sub.*; -public interface GLMatrixIf { +public interface GLMatrixFunc { public static final int GL_MATRIX_MODE = 0x0BA0; public static final int GL_MODELVIEW = 0x1700; diff --git a/src/jogl/classes/javax/media/opengl/sub/fixed/GLPointerIf.java b/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java index 2f4cda1aa..ed7bef5d4 100644 --- a/src/jogl/classes/javax/media/opengl/sub/fixed/GLPointerIf.java +++ b/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java @@ -2,14 +2,13 @@ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. */ -package javax.media.opengl.sub.fixed; +package javax.media.opengl.fixedfunc; import java.nio.*; import javax.media.opengl.*; -import javax.media.opengl.sub.*; -public interface GLPointerIf { +public interface GLPointerFunc { public static final int GL_VERTEX_ARRAY = 0x8074; public static final int GL_NORMAL_ARRAY = 0x8075; public static final int GL_COLOR_ARRAY = 0x8076; diff --git a/src/jogl/classes/javax/media/opengl/sub/GLObject.java b/src/jogl/classes/javax/media/opengl/sub/GLObject.java deleted file mode 100644 index 1426f75d1..000000000 --- a/src/jogl/classes/javax/media/opengl/sub/GLObject.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. - */ - -package javax.media.opengl.sub; - -import java.nio.*; - -import javax.media.opengl.*; - -/** - * GLObject specifies the GL profile related implementations - * and it's composition with GLContext, which is a lifetime one. - */ -public interface GLObject { - - public boolean isGL(); - - public boolean isGL2(); - - public boolean isGLES1(); - - public boolean isGLES2(); - - public boolean isGLES(); - - public boolean isGL2ES1(); - - public boolean isGL2ES2(); - - /** - * @return This object cast to GL - * @throws GLException is this GLObject is not a GL implementation - */ - public GL getGL() throws GLException; - - /** - * @return This object cast to GL2 - * @throws GLException is this GLObject is not a GL2 implementation - */ - public GL2 getGL2() throws GLException; - - /** - * @return This object cast to GLES1 - * @throws GLException is this GLObject is not a GLES1 implementation - */ - public GLES1 getGLES1() throws GLException; - - /** - * @return This object cast to GLES2 - * @throws GLException is this GLObject is not a GLES2 implementation - */ - public GLES2 getGLES2() throws GLException; - - /** - * @return This object cast to GL2ES1 - * @throws GLException is this GLObject is not a GL2ES1 implementation - */ - public GL2ES1 getGL2ES1() throws GLException; - - /** - * @return This object cast to GL2ES2 - * @throws GLException is this GLObject is not a GL2ES2 implementation - */ - public GL2ES2 getGL2ES2() throws GLException; - - public String toString(); - - /** - * @return This GL object's bound GLContext - */ - public GLContext getContext(); - -} - diff --git a/src/jogl/classes/javax/media/opengl/sub/fixed/GLFixedFuncUtil.java b/src/jogl/classes/javax/media/opengl/sub/fixed/GLFixedFuncUtil.java deleted file mode 100644 index 4f6688879..000000000 --- a/src/jogl/classes/javax/media/opengl/sub/fixed/GLFixedFuncUtil.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. - */ - -package javax.media.opengl.sub.fixed; - -import javax.media.opengl.*; -import javax.media.opengl.sub.*; - -import com.sun.nativewindow.impl.NWReflection; -import java.lang.reflect.*; - -/** - * Tool to pipeline GL2ES2 into a fixed function emulation, - * implementing GL2ES1. - * The implementation is retrieved by reflection. - */ -public class GLFixedFuncUtil { - static final Constructor fFuncHookCstr; - static final Constructor fFuncImplCstr; - - static { - if(NWReflection.isClassAvailable("com.sun.opengl.util.glsl.fixed.FixedFuncHook") && - NWReflection.isClassAvailable("com.sun.opengl.util.glsl.fixed.FixedFuncImpl")) { - Class argsHook[] = { javax.media.opengl.GL2ES2.class }; - Class argsImpl[] = { javax.media.opengl.GL2ES2.class, NWReflection.getClass("com.sun.opengl.util.glsl.fixed.FixedFuncHook") }; - fFuncHookCstr = NWReflection.getConstructor("com.sun.opengl.util.glsl.fixed.FixedFuncHook", argsHook); - fFuncImplCstr = NWReflection.getConstructor("com.sun.opengl.util.glsl.fixed.FixedFuncImpl", argsImpl); - } else { - fFuncHookCstr=null; - fFuncImplCstr=null; - } - } - - /** - * @return If gl is a GL2ES1, return the type cast object, - * otherwise create a FixedFuncImpl pipeline with the GL2ES2 impl. - * @throws GLException If this GL Object is neither GL2ES1 nor GL2ES2 - */ - public static final GL2ES1 getFixedFuncImpl(GL gl) { - if(gl instanceof GL2ES1) { - return (GL2ES1)gl; - } else if(gl instanceof GL2ES2) { - if(null!=fFuncImplCstr) { - try { - GL2ES2 es2 = (GL2ES2)gl; - Object fFuncHook = fFuncHookCstr.newInstance( new Object[] { es2 } ); - GL2ES1 fFuncImpl = (GL2ES1) fFuncImplCstr.newInstance( new Object[] { es2, fFuncHook } ); - gl.getContext().setGL(fFuncImpl); - return fFuncImpl; - } catch (Exception e) { - throw new GLException(e); - } - } else { - throw new GLException("GL Object is GL2ES2, but no fixed function impl. available"); - } - } - throw new GLException("GL Object is neither GL2ES1 nor GL2ES2"); - } -} - diff --git a/src/jogl/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp b/src/jogl/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp deleted file mode 100755 index 5cad64d04..000000000 --- a/src/jogl/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp +++ /dev/null @@ -1,453 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -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.nativewindow.impl.NWReflection; - -import java.nio.*; -import java.util.*; - -import java.lang.reflect.*; - -/** Utility routines for dealing with direct buffers. */ - -public class BufferUtil { - public static final int SIZEOF_BYTE = 1; - public static final int SIZEOF_SHORT = 2; - public static final int SIZEOF_INT = 4; - public static final int SIZEOF_FLOAT = 4; - 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; - } - - public static final int sizeOfBufferElem(Buffer buffer) { - if (buffer == null) { - return 0; - } - if (buffer instanceof ByteBuffer) { - return BufferUtil.SIZEOF_BYTE; - } else if (buffer instanceof IntBuffer) { - return BufferUtil.SIZEOF_INT; - } else if (buffer instanceof ShortBuffer) { - return BufferUtil.SIZEOF_SHORT; - } else if (buffer instanceof FloatBuffer) { - return BufferUtil.SIZEOF_FLOAT; - } - throw new RuntimeException("Unexpected buffer type " + - buffer.getClass().getName()); - } - - 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. */ - public static ByteBuffer newByteBuffer(int numElements) { - ByteBuffer bb = ByteBuffer.allocateDirect(numElements); - nativeOrder(bb); - return bb; - } - - public static ByteBuffer newByteBuffer(byte[] values, int offset, int len) { - ByteBuffer bb = newByteBuffer(len); - bb.put(values, offset, len); - bb.rewind(); - return bb; - } - - public static ByteBuffer newByteBuffer(byte[] values, int offset) { - return newByteBuffer(values, offset, values.length-offset); - } - - public static ByteBuffer newByteBuffer(byte[] values) { - return newByteBuffer(values, 0); - } - - /** Allocates a new direct FloatBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static FloatBuffer newFloatBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_FLOAT); - return bb.asFloatBuffer(); - } - - public static FloatBuffer newFloatBuffer(float[] values, int offset, int len) { - FloatBuffer bb = newFloatBuffer(len); - bb.put(values, offset, len); - bb.rewind(); - return bb; - } - - public static FloatBuffer newFloatBuffer(float[] values, int offset) { - return newFloatBuffer(values, 0, values.length-offset); - } - - public static FloatBuffer newFloatBuffer(float[] values) { - return newFloatBuffer(values, 0); - } - - /** Allocates a new direct IntBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static IntBuffer newIntBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT); - return bb.asIntBuffer(); - } - - public static IntBuffer newIntBuffer(int[] values, int offset, int len) { - IntBuffer bb = newIntBuffer(len); - bb.put(values, offset, len); - bb.rewind(); - return bb; - } - - public static IntBuffer newIntBuffer(int[] values, int offset) { - return newIntBuffer(values, 0, values.length-offset); - } - - public static IntBuffer newIntBuffer(int[] values) { - return newIntBuffer(values, 0); - } - - - /** Allocates a new direct ShortBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static ShortBuffer newShortBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_SHORT); - return bb.asShortBuffer(); - } - - public static ShortBuffer newShortBuffer(short[] values, int offset, int len) { - ShortBuffer bb = newShortBuffer(len); - bb.put(values, offset, len); - bb.rewind(); - return bb; - } - - public static ShortBuffer newShortBuffer(short[] values, int offset) { - return newShortBuffer(values, 0, values.length-offset); - } - - public static ShortBuffer newShortBuffer(short[] values) { - return newShortBuffer(values, 0); - } - - - //---------------------------------------------------------------------- - // Copy routines (type-to-type) - // - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed ByteBuffer into - a newly-allocated direct ByteBuffer. The returned buffer will - have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyByteBuffer(ByteBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining()); - dest.put(orig); - dest.rewind(); - return dest; - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed FloatBuffer - into a newly-allocated direct FloatBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static FloatBuffer copyFloatBuffer(FloatBuffer orig) { - return copyFloatBufferAsByteBuffer(orig).asFloatBuffer(); - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed IntBuffer - into a newly-allocated direct IntBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static IntBuffer copyIntBuffer(IntBuffer orig) { - return copyIntBufferAsByteBuffer(orig).asIntBuffer(); - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed ShortBuffer - into a newly-allocated direct ShortBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ShortBuffer copyShortBuffer(ShortBuffer orig) { - return copyShortBufferAsByteBuffer(orig).asShortBuffer(); - } - - //---------------------------------------------------------------------- - // Copy routines (type-to-ByteBuffer) - // - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed FloatBuffer - into a newly-allocated direct ByteBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyFloatBufferAsByteBuffer(FloatBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_FLOAT); - dest.asFloatBuffer().put(orig); - dest.rewind(); - return dest; - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed IntBuffer into - a newly-allocated direct ByteBuffer. The returned buffer will - have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyIntBufferAsByteBuffer(IntBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_INT); - dest.asIntBuffer().put(orig); - dest.rewind(); - return dest; - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed ShortBuffer - into a newly-allocated direct ByteBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyShortBufferAsByteBuffer(ShortBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_SHORT); - dest.asShortBuffer().put(orig); - dest.rewind(); - return dest; - } - - //---------------------------------------------------------------------- - // Conversion routines - // - - public final static float[] getFloatArray(double[] source) { - int i=source.length; - float[] dest = new float[i--]; - while(i>=0) { dest[i]=(float)source[i]; i--; } - return dest; - } - - public static ByteBuffer nativeOrder(ByteBuffer buf) { - if (!isCDCFP) { - try { - if (byteOrderClass == null) { - byteOrderClass = Class.forName("java.nio.ByteOrder"); - orderMethod = ByteBuffer.class.getMethod("order", new Class[] { byteOrderClass }); - Method nativeOrderMethod = byteOrderClass.getMethod("nativeOrder", null); - nativeOrderObject = nativeOrderMethod.invoke(null, null); - } - } catch (Throwable t) { - // Must be running on CDC / FP - isCDCFP = true; - } - - if (!isCDCFP) { - try { - orderMethod.invoke(buf, new Object[] { nativeOrderObject }); - } catch (Throwable t) { - } - } - } - return buf; - } - - //---------------------------------------------------------------------- - // 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(!NWReflection.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 - // - - // NOTE that this work must be done reflectively at the present time - // because this code must compile and run correctly on both CDC/FP and J2SE - private static boolean isCDCFP; - private static Class byteOrderClass; - private static Object nativeOrderObject; - private static Method orderMethod; - -} diff --git a/src/jogl/classes/javax/media/opengl/util/BufferUtil.java.javase b/src/jogl/classes/javax/media/opengl/util/BufferUtil.java.javase deleted file mode 100755 index c3b0a3ab8..000000000 --- a/src/jogl/classes/javax/media/opengl/util/BufferUtil.java.javase +++ /dev/null @@ -1,503 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -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.nativewindow.impl.NWReflection; - -import java.nio.*; -import java.util.*; - -import java.lang.reflect.*; - -/** Utility routines for dealing with direct buffers. */ - -public class BufferUtil { - public static final int SIZEOF_BYTE = 1; - public static final int SIZEOF_SHORT = 2; - public static final int SIZEOF_INT = 4; - public static final int SIZEOF_FLOAT = 4; - 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; - } - - public static final int sizeOfBufferElem(Buffer buffer) { - if (buffer == null) { - return 0; - } - if (buffer instanceof ByteBuffer) { - return BufferUtil.SIZEOF_BYTE; - } else if (buffer instanceof IntBuffer) { - return BufferUtil.SIZEOF_INT; - } else if (buffer instanceof ShortBuffer) { - return BufferUtil.SIZEOF_SHORT; - } else if (buffer instanceof FloatBuffer) { - return BufferUtil.SIZEOF_FLOAT; - } else if (buffer instanceof DoubleBuffer) { - return BufferUtil.SIZEOF_DOUBLE; - } - throw new RuntimeException("Unexpected buffer type " + - buffer.getClass().getName()); - } - - 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. */ - public static ByteBuffer newByteBuffer(int numElements) { - ByteBuffer bb = ByteBuffer.allocateDirect(numElements); - nativeOrder(bb); - return bb; - } - - public static ByteBuffer newByteBuffer(byte[] values, int offset, int len) { - ByteBuffer bb = newByteBuffer(len); - bb.put(values, offset, len); - bb.rewind(); - return bb; - } - - public static ByteBuffer newByteBuffer(byte[] values, int offset) { - return newByteBuffer(values, offset, values.length-offset); - } - - public static ByteBuffer newByteBuffer(byte[] values) { - return newByteBuffer(values, 0); - } - - - /** Allocates a new direct DoubleBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static DoubleBuffer newDoubleBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_DOUBLE); - return bb.asDoubleBuffer(); - } - - public static DoubleBuffer newDoubleBuffer(double[] values, int offset) { - int len = values.length-offset; - DoubleBuffer bb = newDoubleBuffer(len); - bb.put(values, offset, len); - bb.rewind(); - return bb; - } - - public static DoubleBuffer newDoubleBuffer(double[] values) { - return newDoubleBuffer(values, 0); - } - - - /** Allocates a new direct FloatBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static FloatBuffer newFloatBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_FLOAT); - return bb.asFloatBuffer(); - } - - public static FloatBuffer newFloatBuffer(float[] values, int offset, int len) { - FloatBuffer bb = newFloatBuffer(len); - bb.put(values, offset, len); - bb.rewind(); - return bb; - } - - public static FloatBuffer newFloatBuffer(float[] values, int offset) { - return newFloatBuffer(values, 0, values.length-offset); - } - - public static FloatBuffer newFloatBuffer(float[] values) { - return newFloatBuffer(values, 0); - } - - - /** Allocates a new direct IntBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static IntBuffer newIntBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT); - return bb.asIntBuffer(); - } - - public static IntBuffer newIntBuffer(int[] values, int offset, int len) { - IntBuffer bb = newIntBuffer(len); - bb.put(values, offset, len); - bb.rewind(); - return bb; - } - - public static IntBuffer newIntBuffer(int[] values, int offset) { - return newIntBuffer(values, 0, values.length-offset); - } - - public static IntBuffer newIntBuffer(int[] values) { - return newIntBuffer(values, 0); - } - - /** Allocates a new direct LongBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static LongBuffer newLongBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_LONG); - return bb.asLongBuffer(); - } - - /** Allocates a new direct ShortBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static ShortBuffer newShortBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_SHORT); - return bb.asShortBuffer(); - } - - public static ShortBuffer newShortBuffer(short[] values, int offset, int len) { - ShortBuffer bb = newShortBuffer(len); - bb.put(values, offset, len); - bb.rewind(); - return bb; - } - - public static ShortBuffer newShortBuffer(short[] values, int offset) { - return newShortBuffer(values, 0, values.length-offset); - } - - public static ShortBuffer newShortBuffer(short[] values) { - return newShortBuffer(values, 0); - } - - //---------------------------------------------------------------------- - // Copy routines (type-to-type) - // - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed ByteBuffer into - a newly-allocated direct ByteBuffer. The returned buffer will - have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyByteBuffer(ByteBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining()); - dest.put(orig); - dest.rewind(); - return dest; - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed FloatBuffer - into a newly-allocated direct FloatBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static FloatBuffer copyFloatBuffer(FloatBuffer orig) { - return copyFloatBufferAsByteBuffer(orig).asFloatBuffer(); - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed IntBuffer - into a newly-allocated direct IntBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static IntBuffer copyIntBuffer(IntBuffer orig) { - return copyIntBufferAsByteBuffer(orig).asIntBuffer(); - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed ShortBuffer - into a newly-allocated direct ShortBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ShortBuffer copyShortBuffer(ShortBuffer orig) { - return copyShortBufferAsByteBuffer(orig).asShortBuffer(); - } - - //---------------------------------------------------------------------- - // Copy routines (type-to-ByteBuffer) - // - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed FloatBuffer - into a newly-allocated direct ByteBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyFloatBufferAsByteBuffer(FloatBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_FLOAT); - dest.asFloatBuffer().put(orig); - dest.rewind(); - return dest; - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed IntBuffer into - a newly-allocated direct ByteBuffer. The returned buffer will - have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyIntBufferAsByteBuffer(IntBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_INT); - dest.asIntBuffer().put(orig); - dest.rewind(); - return dest; - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed ShortBuffer - into a newly-allocated direct ByteBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyShortBufferAsByteBuffer(ShortBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_SHORT); - dest.asShortBuffer().put(orig); - dest.rewind(); - return dest; - } - - //---------------------------------------------------------------------- - // Conversion routines - // - - public final static float[] getFloatArray(double[] source) { - int i=source.length; - float[] dest = new float[i--]; - while(i>=0) { dest[i]=(float)source[i]; i--; } - return dest; - } - - public final static FloatBuffer getFloatBuffer(DoubleBuffer source) { - source.rewind(); - FloatBuffer dest = BufferUtil.newFloatBuffer(source.limit()); - while(source.hasRemaining()) { dest.put((float)source.get()); } - return dest; - } - - public static ByteBuffer nativeOrder(ByteBuffer buf) { - if (!isCDCFP) { - try { - if (byteOrderClass == null) { - byteOrderClass = Class.forName("java.nio.ByteOrder"); - orderMethod = ByteBuffer.class.getMethod("order", new Class[] { byteOrderClass }); - Method nativeOrderMethod = byteOrderClass.getMethod("nativeOrder", null); - nativeOrderObject = nativeOrderMethod.invoke(null, null); - } - } catch (Throwable t) { - // Must be running on CDC / FP - isCDCFP = true; - } - - if (!isCDCFP) { - try { - orderMethod.invoke(buf, new Object[] { nativeOrderObject }); - } catch (Throwable t) { - } - } - } - return buf; - } - - //---------------------------------------------------------------------- - // 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(!NWReflection.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 - // - - // NOTE that this work must be done reflectively at the present time - // because this code must compile and run correctly on both CDC/FP and J2SE - private static boolean isCDCFP; - private static Class byteOrderClass; - private static Object nativeOrderObject; - private static Method orderMethod; - -} diff --git a/src/jogl/classes/javax/media/opengl/util/FixedPoint.java b/src/jogl/classes/javax/media/opengl/util/FixedPoint.java deleted file mode 100644 index 35e2aaaf4..000000000 --- a/src/jogl/classes/javax/media/opengl/util/FixedPoint.java +++ /dev/null @@ -1,29 +0,0 @@ - -package javax.media.opengl.util; - -public class FixedPoint { - public static final int toFixed(int value) { - if (value < -32768) value = -32768; - if (value > 32767) value = 32767; - return value * 65536; - } - - public static final int toFixed(float value) { - if (value < -32768) value = -32768; - if (value > 32767) value = 32767; - return (int)(value * 65536.0f); - } - - public static final float toFloat(int value) { - return (float)value/65536.0f; - } - - public static final int mult(int x1, int x2) { - return (int) ( ((long)x1*(long)x2)/65536 ); - } - - public static final int div(int x1, int x2) { - return (int) ( (((long)x1)<<16)/x2 ); - } -} - diff --git a/src/jogl/classes/javax/media/opengl/util/Gamma.java b/src/jogl/classes/javax/media/opengl/util/Gamma.java deleted file mode 100755 index ba7bc5a32..000000000 --- a/src/jogl/classes/javax/media/opengl/util/Gamma.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package javax.media.opengl.util; - -import com.sun.opengl.impl.*; - -/** Provides control over the primary display's gamma, brightness and - contrast controls via the hardware gamma ramp tables. Not - supported on all platforms or graphics hardware. <P> - - Thanks to the LWJGL project for illustrating how to access gamma - control on the various platforms. -*/ - -public class Gamma { - private Gamma() {} - - /** - * Sets the gamma, brightness, and contrast of the current main - * display. This functionality is not available on all platforms and - * graphics hardware. Returns true if the settings were successfully - * changed, false if not. This method may return false for some - * values of the incoming arguments even on hardware which does - * support the underlying functionality. <P> - * - * If this method returns true, the display settings will - * automatically be reset to their original values upon JVM exit - * (assuming the JVM does not crash); if the user wishes to change - * the display settings back to normal ahead of time, use {@link - * #resetDisplayGamma resetDisplayGamma}(). It is recommended to - * call {@link #resetDisplayGamma resetDisplayGamma} before calling - * e.g. <code>System.exit()</code> from the application rather than - * rely on the shutdown hook functionality due to inevitable race - * conditions and unspecified behavior during JVM teardown. <P> - * - * This method may be called multiple times during the application's - * execution, but calling {@link #resetDisplayGamma - * resetDisplayGamma} will only reset the settings to the values - * before the first call to this method. <P> - * - * @param gamma The gamma value, typically > 1.0 (default values - * vary, but typically roughly 1.0) - * @param brightness The brightness value between -1.0 and 1.0, - * inclusive (default values vary, but typically 0) - * @param contrast The contrast, greater than 0.0 (default values - * vary, but typically 1) - * @return true if gamma settings were successfully changed, false - * if not - * @throws IllegalArgumentException if any of the parameters were - * out-of-bounds - */ - public static boolean setDisplayGamma(float gamma, float brightness, float contrast) throws IllegalArgumentException { - return GLDrawableFactoryImpl.getFactoryImpl().setDisplayGamma(gamma, brightness, contrast); - } - - /** - * Resets the gamma, brightness and contrast values for the primary - * display to their original values before {@link #setDisplayGamma - * setDisplayGamma} was called the first time. {@link - * #setDisplayGamma setDisplayGamma} must be called before calling - * this method or an unspecified exception will be thrown. While it - * is not explicitly required that this method be called before - * exiting, calling it is recommended because of the inevitable - * unspecified behavior during JVM teardown. - */ - public static void resetDisplayGamma() { - GLDrawableFactoryImpl.getFactoryImpl().resetDisplayGamma(); - } -} diff --git a/src/jogl/classes/javax/media/opengl/util/PMVMatrix.java b/src/jogl/classes/javax/media/opengl/util/PMVMatrix.java deleted file mode 100755 index 4598993f1..000000000 --- a/src/jogl/classes/javax/media/opengl/util/PMVMatrix.java +++ /dev/null @@ -1,656 +0,0 @@ -/* - * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. - */ - -package javax.media.opengl.util; - -import com.sun.opengl.impl.ProjectFloat; - -import java.nio.*; -import java.util.ArrayList; -import java.util.List; - -import javax.media.opengl.*; -import javax.media.opengl.sub.fixed.GLMatrixIf; - -public class PMVMatrix implements GLMatrixIf { - - public PMVMatrix() { - projectFloat = new ProjectFloat(); - - matrixIdent = BufferUtil.newFloatBuffer(1*16); - projectFloat.gluMakeIdentityf(matrixIdent); - matrixIdent.rewind(); - - // T Texture - // P Projection - // Mv ModelView - // Mvi Modelview-Inverse - // Mvit Modelview-Inverse-Transpose - // Pmv P * Mv - matrixTPMvMvitPmv = BufferUtil.newFloatBuffer(6*16); // grouping T + P + Mv + Mvi + Mvit + Pmv - matrixPMvMvitPmv = slice(matrixTPMvMvitPmv, 1*16, 5*16); // grouping P + Mv + Mvi + Mvit + Pmv - matrixT = slice(matrixTPMvMvitPmv, 0*16, 1*16); // T - matrixPMvMvit = slice(matrixTPMvMvitPmv, 1*16, 4*16); // grouping P + Mv + Mvi + Mvit - matrixPMvMvi = slice(matrixTPMvMvitPmv, 1*16, 3*16); // grouping P + Mv + Mvi - matrixPMv = slice(matrixTPMvMvitPmv, 1*16, 2*16); // grouping P + Mv - matrixP = slice(matrixTPMvMvitPmv, 1*16, 1*16); // P - matrixMv = slice(matrixTPMvMvitPmv, 2*16, 1*16); // Mv - matrixMvi = slice(matrixTPMvMvitPmv, 3*16, 1*16); // Mvi - matrixMvit = slice(matrixTPMvMvitPmv, 4*16, 1*16); // Mvit - matrixPmv = slice(matrixTPMvMvitPmv, 5*16, 1*16); // Pmv - matrixTPMvMvitPmv.rewind(); - - matrixMvit3 = BufferUtil.newFloatBuffer(3*3); - - localBuf = BufferUtil.newFloatBuffer(6*16); - - matrixMult=slice(localBuf, 0*16, 16); - - matrixTrans=slice(localBuf, 1*16, 16); - projectFloat.gluMakeIdentityf(matrixTrans); - - matrixRot=slice(localBuf, 2*16, 16); - projectFloat.gluMakeIdentityf(matrixRot); - - matrixScale=slice(localBuf, 3*16, 16); - projectFloat.gluMakeIdentityf(matrixScale); - - matrixOrtho=slice(localBuf, 4*16, 16); - projectFloat.gluMakeIdentityf(matrixOrtho); - - matrixFrustum=slice(localBuf, 5*16, 16); - projectFloat.gluMakeZero(matrixFrustum); - - vec3f=new float[3]; - - matrixPStack = new ArrayList(); - matrixMvStack= new ArrayList(); - - // default values and mode - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glMatrixMode(GL.GL_TEXTURE); - glLoadIdentity(); - setDirty(); - } - - public void destroy() { - if(null!=projectFloat) { - projectFloat.destroy(); projectFloat=null; - } - - if(null!=matrixIdent) { - matrixIdent.clear(); matrixIdent=null; - } - if(null!=matrixTPMvMvitPmv) { - matrixTPMvMvitPmv.clear(); matrixTPMvMvitPmv=null; - } - if(null!=matrixMvit3) { - matrixMvit3.clear(); matrixMvit3=null; - } - if(null!=localBuf) { - localBuf.clear(); localBuf=null; - } - - if(null!=matrixPStack) { - matrixPStack.clear(); matrixPStack=null; - } - vec3f=null; - if(null!=matrixMvStack) { - matrixMvStack.clear(); matrixMvStack=null; - } - if(null!=matrixPStack) { - matrixPStack.clear(); matrixPStack=null; - } - if(null!=matrixTStack) { - matrixTStack.clear(); matrixTStack=null; - } - - matrixTPMvMvitPmv=null; matrixPMvMvit=null; matrixPMvMvitPmv=null; matrixPMvMvi=null; matrixPMv=null; - matrixP=null; matrixT=null; matrixMv=null; matrixMvi=null; matrixMvit=null; matrixPmv=null; - matrixMult=null; matrixTrans=null; matrixRot=null; matrixScale=null; matrixOrtho=null; matrixFrustum=null; - } - - private static FloatBuffer slice(FloatBuffer buf, int pos, int len) { - buf.position(pos); - buf.limit(pos + len); - return buf.slice(); - } - - public static final boolean isMatrixModeName(final int matrixModeName) { - switch(matrixModeName) { - case GL_MODELVIEW_MATRIX: - case GL_PROJECTION_MATRIX: - case GL_TEXTURE_MATRIX: - return true; - } - return false; - } - - public static final int matrixModeName2MatrixGetName(final int matrixModeName) { - switch(matrixModeName) { - case GL_MODELVIEW: - return GL_MODELVIEW_MATRIX; - case GL_PROJECTION: - return GL_PROJECTION_MATRIX; - case GL.GL_TEXTURE: - return GL_TEXTURE_MATRIX; - default: - throw new GLException("unsupported matrixName: "+matrixModeName); - } - } - - public static final boolean isMatrixGetName(final int matrixGetName) { - switch(matrixGetName) { - case GL_MATRIX_MODE: - case GL_MODELVIEW_MATRIX: - case GL_PROJECTION_MATRIX: - case GL_TEXTURE_MATRIX: - return true; - } - return false; - } - - public static final int matrixGetName2MatrixModeName(final int matrixGetName) { - switch(matrixGetName) { - case GL_MODELVIEW_MATRIX: - return GL_MODELVIEW; - case GL_PROJECTION_MATRIX: - return GL_PROJECTION; - case GL_TEXTURE_MATRIX: - return GL.GL_TEXTURE; - default: - throw new GLException("unsupported matrixGetName: "+matrixGetName); - } - } - - public void setDirty() { - modified = DIRTY_MODELVIEW | DIRTY_PROJECTION | DIRTY_TEXTURE ; - matrixMode = GL_MODELVIEW; - } - - public int getDirtyBits() { - return modified; - } - - public boolean isDirty(final int matrixName) { - boolean res; - switch(matrixName) { - case GL_MODELVIEW: - res = (modified&DIRTY_MODELVIEW)!=0 ; - break; - case GL_PROJECTION: - res = (modified&DIRTY_PROJECTION)!=0 ; - break; - case GL.GL_TEXTURE: - res = (modified&DIRTY_TEXTURE)!=0 ; - break; - default: - throw new GLException("unsupported matrixName: "+matrixName); - } - return res; - } - - public boolean isDirty() { - return modified!=0; - } - - public boolean update() { - // if(0==modified) return false; - - // int res = modified; - int res = DIRTY_MODELVIEW | DIRTY_PROJECTION ; - if( (res&DIRTY_MODELVIEW)!=0 ) { - setMviMvit(); - } - if( (res&DIRTY_MODELVIEW)!=0 || (res&DIRTY_PROJECTION)!=0 ) { - glMultMatrixf(matrixP, matrixMv, matrixPmv); - } - modified=0; - return res!=0; - } - - public final int glGetMatrixMode() { - return matrixMode; - } - - public final FloatBuffer glGetTMatrixf() { - return matrixT; - } - - public final FloatBuffer glGetPMatrixf() { - return matrixP; - } - - public final FloatBuffer glGetMvMatrixf() { - return matrixMv; - } - - public final FloatBuffer glGetPMvMvitPmvMatrixf() { - return matrixPMvMvitPmv; - } - - public final FloatBuffer glGetPMvMvitMatrixf() { - return matrixPMvMvit; - } - - public final FloatBuffer glGetPMvMviMatrixf() { - return matrixPMvMvi; - } - - public final FloatBuffer glGetPMvMatrixf() { - return matrixPMv; - } - - public final FloatBuffer glGetMviMatrixf() { - return matrixMvi; - } - - public final FloatBuffer glGetPmvMatrixf() { - return matrixPmv; - } - - public final FloatBuffer glGetNormalMatrixf() { - return matrixMvit3; - } - - /* - * @return the current matrix - */ - public final FloatBuffer glGetMatrixf() { - return glGetMatrixf(matrixMode); - } - - /** - * @param pname GL_MODELVIEW, GL_PROJECTION or GL.GL_TEXTURE - * @return the given matrix - */ - public final FloatBuffer glGetMatrixf(final int matrixName) { - if(matrixName==GL_MODELVIEW) { - return matrixMv; - } else if(matrixName==GL_PROJECTION) { - return matrixP; - } else if(matrixName==GL.GL_TEXTURE) { - return matrixT; - } else { - throw new GLException("unsupported matrixName: "+matrixName); - } - } - - public final void gluPerspective(final float fovy, final float aspect, final float zNear, final float zFar) { - float top=(float)Math.tan(fovy*((float)Math.PI)/360.0f)*zNear; - float bottom=-1.0f*top; - float left=aspect*bottom; - float right=aspect*top; - glFrustumf(left, right, bottom, top, zNear, zFar); - } - - public static final void glMultMatrixf(final FloatBuffer a, final FloatBuffer b, FloatBuffer p) { - for (int i = 0; i < 4; i++) { - final float ai0=a.get(i+0*4), ai1=a.get(i+1*4), ai2=a.get(i+2*4), ai3=a.get(i+3*4); - p.put(i+0*4 , ai0 * b.get(0+0*4) + ai1 * b.get(1+0*4) + ai2 * b.get(2+0*4) + ai3 * b.get(3+0*4) ); - p.put(i+1*4 , ai0 * b.get(0+1*4) + ai1 * b.get(1+1*4) + ai2 * b.get(2+1*4) + ai3 * b.get(3+1*4) ); - p.put(i+2*4 , ai0 * b.get(0+2*4) + ai1 * b.get(1+2*4) + ai2 * b.get(2+2*4) + ai3 * b.get(3+2*4) ); - p.put(i+3*4 , ai0 * b.get(0+3*4) + ai1 * b.get(1+3*4) + ai2 * b.get(2+3*4) + ai3 * b.get(3+3*4) ); - } - } - public static final void glMultMatrixf(final FloatBuffer a, final float[] b, int b_off, FloatBuffer p) { - for (int i = 0; i < 4; i++) { - final float ai0=a.get(i+0*4), ai1=a.get(i+1*4), ai2=a.get(i+2*4), ai3=a.get(i+3*4); - p.put(i+0*4 , ai0 * b[b_off+0+0*4] + ai1 * b[b_off+1+0*4] + ai2 * b[b_off+2+0*4] + ai3 * b[b_off+3+0*4] ); - p.put(i+1*4 , ai0 * b[b_off+0+1*4] + ai1 * b[b_off+1+1*4] + ai2 * b[b_off+2+1*4] + ai3 * b[b_off+3+1*4] ); - p.put(i+2*4 , ai0 * b[b_off+0+2*4] + ai1 * b[b_off+1+2*4] + ai2 * b[b_off+2+2*4] + ai3 * b[b_off+3+2*4] ); - p.put(i+3*4 , ai0 * b[b_off+0+3*4] + ai1 * b[b_off+1+3*4] + ai2 * b[b_off+2+3*4] + ai3 * b[b_off+3+3*4] ); - } - } - - // - // MatrixIf - // - - public void glMatrixMode(final int matrixName) { - switch(matrixName) { - case GL_MODELVIEW: - case GL_PROJECTION: - case GL.GL_TEXTURE: - break; - default: - throw new GLException("unsupported matrixName: "+matrixName); - } - matrixMode = matrixName; - } - - public void glGetFloatv(int matrixGetName, FloatBuffer params) { - int pos = params.position(); - if(matrixGetName==GL_MATRIX_MODE) { - params.put((float)matrixMode); - } else { - FloatBuffer matrix = glGetMatrixf(matrixGetName2MatrixModeName(matrixGetName)); - params.put(matrix); - matrix.rewind(); - } - params.position(pos); - } - public void glGetFloatv(int matrixGetName, float[] params, int params_offset) { - if(matrixGetName==GL_MATRIX_MODE) { - params[params_offset]=(float)matrixMode; - } else { - FloatBuffer matrix = glGetMatrixf(matrixGetName2MatrixModeName(matrixGetName)); - matrix.get(params, params_offset, 16); - matrix.rewind(); - } - } - public void glGetIntegerv(int pname, IntBuffer params) { - int pos = params.position(); - if(pname==GL_MATRIX_MODE) { - params.put(matrixMode); - } else { - throw new GLException("unsupported pname: "+pname); - } - params.position(pos); - } - public void glGetIntegerv(int pname, int[] params, int params_offset) { - if(pname==GL_MATRIX_MODE) { - params[params_offset]=matrixMode; - } else { - throw new GLException("unsupported pname: "+pname); - } - } - - public final void glLoadMatrixf(final float[] values, final int offset) { - int len = values.length-offset; - if(matrixMode==GL_MODELVIEW) { - matrixMv.clear(); - matrixMv.put(values, offset, len); - matrixMv.rewind(); - modified |= DIRTY_MODELVIEW ; - } else if(matrixMode==GL_PROJECTION) { - matrixP.clear(); - matrixP.put(values, offset, len); - matrixP.rewind(); - modified |= DIRTY_PROJECTION ; - } else if(matrixMode==GL.GL_TEXTURE) { - matrixT.clear(); - matrixT.put(values, offset, len); - matrixT.rewind(); - modified |= DIRTY_TEXTURE ; - } - } - - public final void glLoadMatrixf(java.nio.FloatBuffer m) { - int spos = m.position(); - if(matrixMode==GL_MODELVIEW) { - matrixMv.clear(); - matrixMv.put(m); - matrixMv.rewind(); - modified |= DIRTY_MODELVIEW ; - } else if(matrixMode==GL_PROJECTION) { - matrixP.clear(); - matrixP.put(m); - matrixP.rewind(); - modified |= DIRTY_PROJECTION ; - } else if(matrixMode==GL.GL_TEXTURE) { - matrixT.clear(); - matrixT.put(m); - matrixT.rewind(); - modified |= DIRTY_TEXTURE ; - } - m.position(spos); - } - - public final void glPopMatrix() { - float[] stackEntry=null; - if(matrixMode==GL_MODELVIEW) { - stackEntry = (float[])matrixMvStack.remove(0); - } else if(matrixMode==GL_PROJECTION) { - stackEntry = (float[])matrixPStack.remove(0); - } else if(matrixMode==GL.GL_TEXTURE) { - stackEntry = (float[])matrixTStack.remove(0); - } - glLoadMatrixf(stackEntry, 0); - } - - public final void glPushMatrix() { - float[] stackEntry = new float[1*16]; - if(matrixMode==GL_MODELVIEW) { - matrixMv.get(stackEntry); - matrixMv.rewind(); - matrixMvStack.add(0, stackEntry); - } else if(matrixMode==GL_PROJECTION) { - matrixP.get(stackEntry); - matrixP.rewind(); - matrixPStack.add(0, stackEntry); - } else if(matrixMode==GL.GL_TEXTURE) { - matrixT.get(stackEntry); - matrixT.rewind(); - matrixTStack.add(0, stackEntry); - } - } - - public final void glLoadIdentity() { - if(matrixMode==GL_MODELVIEW) { - matrixMv.clear(); - matrixMv.put(matrixIdent); - matrixMv.rewind(); - matrixIdent.rewind(); - modified |= DIRTY_MODELVIEW ; - } else if(matrixMode==GL_PROJECTION) { - matrixP.clear(); - matrixP.put(matrixIdent); - matrixP.rewind(); - matrixIdent.rewind(); - modified |= DIRTY_PROJECTION ; - } else if(matrixMode==GL.GL_TEXTURE) { - matrixT.clear(); - matrixT.put(matrixIdent); - matrixT.rewind(); - matrixIdent.rewind(); - modified |= DIRTY_TEXTURE ; - } - } - - public final void glMultMatrixf(final FloatBuffer m) { - if(matrixMode==GL_MODELVIEW) { - glMultMatrixf(matrixMv, m, matrixMult); - matrixMv.clear(); - matrixMv.put(matrixMult); - matrixMv.rewind(); - modified |= DIRTY_MODELVIEW ; - } else if(matrixMode==GL_PROJECTION) { - glMultMatrixf(matrixP, m, matrixMult); - matrixP.clear(); - matrixP.put(matrixMult); - matrixP.rewind(); - modified |= DIRTY_PROJECTION ; - } else if(matrixMode==GL.GL_TEXTURE) { - glMultMatrixf(matrixT, m, matrixMult); - matrixT.clear(); - matrixT.put(matrixMult); - matrixT.rewind(); - modified |= DIRTY_TEXTURE ; - } - matrixMult.rewind(); - } - - public void glMultMatrixf(float[] m, int m_offset) { - if(matrixMode==GL_MODELVIEW) { - glMultMatrixf(matrixMv, m, m_offset, matrixMult); - matrixMv.clear(); - matrixMv.put(matrixMult); - matrixMv.rewind(); - modified |= DIRTY_MODELVIEW ; - } else if(matrixMode==GL_PROJECTION) { - glMultMatrixf(matrixP, m, m_offset, matrixMult); - matrixP.clear(); - matrixP.put(matrixMult); - matrixP.rewind(); - modified |= DIRTY_PROJECTION ; - } else if(matrixMode==GL.GL_TEXTURE) { - glMultMatrixf(matrixT, m, m_offset, matrixMult); - matrixT.clear(); - matrixT.put(matrixMult); - matrixT.rewind(); - modified |= DIRTY_TEXTURE ; - } - matrixMult.rewind(); - } - - public final void glTranslatef(final float x, final float y, final float z) { - // Translation matrix: - // 1 0 0 x - // 0 1 0 y - // 0 0 1 z - // 0 0 0 1 - matrixTrans.put(0+4*3, x); - matrixTrans.put(1+4*3, y); - matrixTrans.put(2+4*3, z); - glMultMatrixf(matrixTrans); - } - - public final void glRotatef(final float angdeg, float x, float y, float z) { - float angrad = angdeg * (float) Math.PI / 180; - float c = (float)Math.cos(angrad); - float ic= 1.0f - c; - float s = (float)Math.sin(angrad); - - vec3f[0]=x; vec3f[1]=y; vec3f[2]=z; - projectFloat.normalize(vec3f); - x = vec3f[0]; y = vec3f[1]; z = vec3f[2]; - - // Rotation matrix: - // xx(1−c)+c xy(1−c)+zs xz(1−c)-ys 0 - // xy(1−c)-zs yy(1−c)+c yz(1−c)+xs 0 - // xz(1−c)+ys yz(1−c)-xs zz(1−c)+c 0 - // 0 0 0 1 - float xy = x*y; - float xz = x*z; - float xs = x*s; - float ys = y*s; - float yz = y*z; - float zs = z*s; - matrixRot.put(0*4+0, x*x*ic+c); - matrixRot.put(0*4+1, xy*ic+zs); - matrixRot.put(0*4+2, xz*ic-ys); - - matrixRot.put(1*4+0, xy*ic-zs); - matrixRot.put(1*4+1, y*y*ic+c); - matrixRot.put(1*4+2, yz*ic+xs); - - matrixRot.put(2*4+0, xz*ic+ys); - matrixRot.put(2*4+1, yz*ic-xs); - matrixRot.put(2*4+2, z*z*ic+c); - - glMultMatrixf(matrixRot); - } - - public final void glScalef(final float x, final float y, final float z) { - // Scale matrix: - // x 0 0 0 - // 0 y 0 0 - // 0 0 z 0 - // 0 0 0 1 - matrixScale.put(0+4*0, x); - matrixScale.put(1+4*1, y); - matrixScale.put(2+4*2, z); - - glMultMatrixf(matrixScale); - } - - public final void glOrthof(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar) { - // Ortho matrix: - // 2/dx 0 0 tx - // 0 2/dy 0 ty - // 0 0 2/dz tz - // 0 0 0 1 - float dx=right-left; - float dy=top-bottom; - float dz=zFar-zNear; - float tx=-1.0f*(right+left)/dx; - float ty=-1.0f*(top+bottom)/dy; - float tz=-1.0f*(zFar+zNear)/dz; - - matrixOrtho.put(0+4*0, 2.0f/dx); - matrixOrtho.put(1+4*1, 2.0f/dy); - matrixOrtho.put(2+4*2, -2.0f/dz); - matrixOrtho.put(0+4*3, tx); - matrixOrtho.put(1+4*3, ty); - matrixOrtho.put(2+4*3, tz); - - glMultMatrixf(matrixOrtho); - } - - public final void glFrustumf(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar) { - if(zNear<=0.0f||zFar<0.0f) { - throw new GLException("GL_INVALID_VALUE: zNear and zFar must be positive, and zNear>0"); - } - if(left==right || top==bottom) { - throw new GLException("GL_INVALID_VALUE: top,bottom and left,right must not be equal"); - } - // Frustum matrix: - // 2*zNear/dx 0 A 0 - // 0 2*zNear/dy B 0 - // 0 0 C D - // 0 0 −1 0 - float zNear2 = 2.0f*zNear; - float dx=right-left; - float dy=top-bottom; - float dz=zFar-zNear; - float A=(right+left)/dx; - float B=(top+bottom)/dy; - float C=-1.0f*(zFar+zNear)/dz; - float D=-2.0f*(zFar*zNear)/dz; - - matrixFrustum.put(0+4*0, zNear2/dx); - matrixFrustum.put(1+4*1, zNear2/dy); - matrixFrustum.put(2+4*2, C); - - matrixFrustum.put(0+4*2, A); - matrixFrustum.put(1+4*2, B); - - matrixFrustum.put(2+4*3, D); - matrixFrustum.put(3+4*2, -1.0f); - - glMultMatrixf(matrixFrustum); - } - - // - // private - // - - private final void setMviMvit() { - if(!projectFloat.gluInvertMatrixf(matrixMv, matrixMvi)) { - throw new GLException("Invalid source Mv matrix, can't compute inverse"); - } - - // transpose matrix - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - matrixMvit.put(j+i*4, matrixMvi.get(i+j*4)); - } - } - - // fetch 3x3 - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - matrixMvit3.put(i+j*3, matrixMvit.get(i+j*4)); - } - } - } - - protected FloatBuffer matrixIdent; - protected FloatBuffer matrixTPMvMvitPmv, matrixPMvMvit, matrixPMvMvitPmv, matrixPMvMvi, matrixPMv, matrixP, matrixT, matrixMv, matrixMvi, matrixMvit, matrixPmv; - protected FloatBuffer matrixMvit3; - protected FloatBuffer localBuf, matrixMult, matrixTrans, matrixRot, matrixScale, matrixOrtho, matrixFrustum; - protected float[] vec3f; - protected List/*FloatBuffer*/ matrixTStack, matrixPStack, matrixMvStack; - protected int matrixMode = GL_MODELVIEW; - protected int modified = 0; - protected ProjectFloat projectFloat; - - public static final int DIRTY_MODELVIEW = 1 << 0; - public static final int DIRTY_PROJECTION = 1 << 1; - public static final int DIRTY_TEXTURE = 1 << 2; -} |