From 45eac4e00b9b9dd935265c2ab25a61a2cf3cbf63 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Thu, 19 Mar 2009 06:39:36 +0000 Subject: Moved remaining portions of fixed function emulation out of core JOGL public and implementation packages and into com.sun.opengl.util.glsl.fixed.* and other subpackages of com.sun.opengl.util. Renamed javax.media.opengl.sub.GLObject to javax.media.opengl.GLBase. Moved interfaces in javax.media.opengl.sub.fixed to javax.media.opengl.fixedfunc and changed naming convention. Moved all classes in javax.media.opengl.util to com.sun.opengl.util. Moved com.sun.opengl.impl.packrect to com.sun.opengl.util.packrect. Renamed InternalBufferUtils to InternalBufferUtil to match naming convention and copied in needed routines for GLU and other classes. Fixed build breakage when specifying rootrel.build property; reintroduced build-temp directory. Updated demos. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1886 232f8b59-042b-4e1e-8c03-345bb8c30851 --- .../com/sun/opengl/impl/GLArrayHandler.java | 12 - .../com/sun/opengl/impl/GLFixedArrayHandler.java | 66 -- .../impl/InternalBufferUtil.java.javame_cdc_fp | 113 ++++ .../sun/opengl/impl/InternalBufferUtil.java.javase | 195 ++++++ .../com/sun/opengl/impl/InternalBufferUtils.java | 55 -- .../classes/com/sun/opengl/impl/ProjectFloat.java | 15 +- .../sun/opengl/impl/egl/EGLDrawableFactory.java | 2 +- .../com/sun/opengl/impl/gl2/ProjectDouble.java | 3 +- .../com/sun/opengl/impl/glsl/GLSLArrayHandler.java | 62 -- .../opengl/impl/glsl/fixed/FixedFuncPipeline.java | 533 ---------------- .../impl/glsl/fixed/shader/FixedFuncColor.fp | 16 - .../impl/glsl/fixed/shader/FixedFuncColor.vp | 22 - .../impl/glsl/fixed/shader/FixedFuncColorLight.vp | 70 --- .../glsl/fixed/shader/FixedFuncColorTexture.fp | 47 -- .../fixed/shader/bin/nvidia/FixedFuncColor.bfp | Bin 1108 -> 0 bytes .../fixed/shader/bin/nvidia/FixedFuncColor.bvp | Bin 2344 -> 0 bytes .../shader/bin/nvidia/FixedFuncColorLight.bvp | Bin 8787 -> 0 bytes .../shader/bin/nvidia/FixedFuncColorTexture.bfp | Bin 2392 -> 0 bytes .../impl/glsl/fixed/shader/es_precision.glsl | 14 - .../impl/glsl/fixed/shader/mgl_attribute.glsl | 19 - .../opengl/impl/glsl/fixed/shader/mgl_const.glsl | 10 - .../impl/glsl/fixed/shader/mgl_lightdef.glsl | 26 - .../impl/glsl/fixed/shader/mgl_settexcoord.vp | 35 -- .../opengl/impl/glsl/fixed/shader/mgl_uniform.glsl | 18 - .../impl/glsl/fixed/shader/mgl_uniform_light.glsl | 15 - .../opengl/impl/glsl/fixed/shader/mgl_varying.glsl | 12 - .../fixed/shader/scripts/nvidia-apx/glslc-ff.bat | 9 - .../glsl/fixed/shader/scripts/nvidia-apx/glslc.bat | 9 - .../com/sun/opengl/impl/glu/GLUquadricImpl.java | 1 - .../sun/opengl/impl/glu/mipmap/BuildMipmap.java | 30 +- .../com/sun/opengl/impl/glu/mipmap/Mipmap.java | 6 +- .../sun/opengl/impl/glu/mipmap/ScaleInternal.java | 6 +- .../classes/com/sun/opengl/impl/io/Locator.java | 106 ---- .../opengl/impl/packrect/BackingStoreManager.java | 99 --- .../com/sun/opengl/impl/packrect/Level.java | 275 --------- .../com/sun/opengl/impl/packrect/LevelSet.java | 213 ------- .../classes/com/sun/opengl/impl/packrect/Rect.java | 170 ----- .../com/sun/opengl/impl/packrect/RectVisitor.java | 47 -- .../sun/opengl/impl/packrect/RectanglePacker.java | 306 --------- .../com/sun/opengl/impl/packrect/package.html | 7 - .../windows/wgl/WindowsWGLDrawableFactory.java | 1 - .../sun/opengl/util/BufferUtil.java.javame_cdc_fp | 449 ++++++++++++++ .../com/sun/opengl/util/BufferUtil.java.javase | 499 +++++++++++++++ .../classes/com/sun/opengl/util/FixedPoint.java | 61 ++ .../com/sun/opengl/util/GLArrayDataClient.java | 22 +- .../com/sun/opengl/util/GLArrayDataServer.java | 12 +- .../com/sun/opengl/util/GLArrayDataWrapper.java | 10 +- .../com/sun/opengl/util/GLArrayHandler.java | 11 + .../com/sun/opengl/util/GLFixedArrayHandler.java | 65 ++ src/jogl/classes/com/sun/opengl/util/Gamma.java | 106 ++++ .../classes/com/sun/opengl/util/ImmModeSink.java | 11 +- src/jogl/classes/com/sun/opengl/util/Locator.java | 137 +++++ .../classes/com/sun/opengl/util/PMVMatrix.java | 685 +++++++++++++++++++++ .../com/sun/opengl/util/awt/TextRenderer.java | 5 +- .../com/sun/opengl/util/glsl/GLSLArrayHandler.java | 60 ++ .../com/sun/opengl/util/glsl/ShaderCode.java | 4 +- .../sun/opengl/util/glsl/fixed/FixedFuncHook.java | 334 ---------- .../opengl/util/glsl/fixedfunc/FixedFuncUtil.java | 81 +++ .../util/glsl/fixedfunc/impl/FixedFuncHook.java | 332 ++++++++++ .../glsl/fixedfunc/impl/FixedFuncPipeline.java | 554 +++++++++++++++++ .../glsl/fixedfunc/impl/shaders/FixedFuncColor.fp | 16 + .../glsl/fixedfunc/impl/shaders/FixedFuncColor.vp | 22 + .../fixedfunc/impl/shaders/FixedFuncColorLight.vp | 70 +++ .../impl/shaders/FixedFuncColorTexture.fp | 47 ++ .../impl/shaders/bin/nvidia/FixedFuncColor.bfp | Bin 0 -> 1108 bytes .../impl/shaders/bin/nvidia/FixedFuncColor.bvp | Bin 0 -> 2344 bytes .../shaders/bin/nvidia/FixedFuncColorLight.bvp | Bin 0 -> 8787 bytes .../shaders/bin/nvidia/FixedFuncColorTexture.bfp | Bin 0 -> 2392 bytes .../glsl/fixedfunc/impl/shaders/es_precision.glsl | 14 + .../glsl/fixedfunc/impl/shaders/mgl_attribute.glsl | 19 + .../glsl/fixedfunc/impl/shaders/mgl_const.glsl | 10 + .../glsl/fixedfunc/impl/shaders/mgl_lightdef.glsl | 26 + .../glsl/fixedfunc/impl/shaders/mgl_settexcoord.vp | 35 ++ .../glsl/fixedfunc/impl/shaders/mgl_uniform.glsl | 18 + .../fixedfunc/impl/shaders/mgl_uniform_light.glsl | 15 + .../glsl/fixedfunc/impl/shaders/mgl_varying.glsl | 12 + .../impl/shaders/scripts/nvidia-apx/glslc-ff.bat | 9 + .../impl/shaders/scripts/nvidia-apx/glslc.bat | 9 + .../sun/opengl/util/glsl/sdk/CompileShader.java | 2 +- .../opengl/util/packrect/BackingStoreManager.java | 99 +++ .../com/sun/opengl/util/packrect/Level.java | 275 +++++++++ .../com/sun/opengl/util/packrect/LevelSet.java | 213 +++++++ .../classes/com/sun/opengl/util/packrect/Rect.java | 170 +++++ .../com/sun/opengl/util/packrect/RectVisitor.java | 47 ++ .../sun/opengl/util/packrect/RectanglePacker.java | 306 +++++++++ .../com/sun/opengl/util/packrect/package.html | 7 + .../opengl/util/texture/spi/DDSImage.java.javase | 2 +- src/jogl/classes/javax/media/opengl/GLBase.java | 105 ++++ src/jogl/classes/javax/media/opengl/GLContext.java | 60 -- src/jogl/classes/javax/media/opengl/GLProfile.java | 79 ++- .../media/opengl/fixedfunc/GLLightingFunc.java | 49 ++ .../javax/media/opengl/fixedfunc/GLMatrixFunc.java | 76 +++ .../media/opengl/fixedfunc/GLPointerFunc.java | 38 ++ .../classes/javax/media/opengl/sub/GLObject.java | 75 --- .../media/opengl/sub/fixed/GLFixedFuncUtil.java | 61 -- .../javax/media/opengl/sub/fixed/GLLightingIf.java | 50 -- .../javax/media/opengl/sub/fixed/GLMatrixIf.java | 77 --- .../javax/media/opengl/sub/fixed/GLPointerIf.java | 39 -- .../opengl/util/BufferUtil.java.javame_cdc_fp | 453 -------------- .../javax/media/opengl/util/BufferUtil.java.javase | 503 --------------- .../javax/media/opengl/util/FixedPoint.java | 29 - .../classes/javax/media/opengl/util/Gamma.java | 106 ---- .../classes/javax/media/opengl/util/PMVMatrix.java | 656 -------------------- src/jogl/native/GLXGetProcAddressARB.c | 53 ++ src/jogl/native/InternalBufferUtils.c | 78 --- 105 files changed, 5221 insertions(+), 4892 deletions(-) delete mode 100644 src/jogl/classes/com/sun/opengl/impl/GLArrayHandler.java delete mode 100644 src/jogl/classes/com/sun/opengl/impl/GLFixedArrayHandler.java create mode 100644 src/jogl/classes/com/sun/opengl/impl/InternalBufferUtil.java.javame_cdc_fp create mode 100644 src/jogl/classes/com/sun/opengl/impl/InternalBufferUtil.java.javase delete mode 100644 src/jogl/classes/com/sun/opengl/impl/InternalBufferUtils.java delete mode 100644 src/jogl/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java delete mode 100644 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/FixedFuncPipeline.java delete mode 100644 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/FixedFuncColor.fp delete mode 100644 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/FixedFuncColor.vp delete mode 100644 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/FixedFuncColorLight.vp delete mode 100644 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/FixedFuncColorTexture.fp delete mode 100755 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColor.bfp delete mode 100755 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColor.bvp delete mode 100755 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColorLight.bvp delete mode 100755 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColorTexture.bfp delete mode 100644 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/es_precision.glsl delete mode 100644 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_attribute.glsl delete mode 100644 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_const.glsl delete mode 100644 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_lightdef.glsl delete mode 100644 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_settexcoord.vp delete mode 100644 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_uniform.glsl delete mode 100644 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_uniform_light.glsl delete mode 100644 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_varying.glsl delete mode 100755 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/scripts/nvidia-apx/glslc-ff.bat delete mode 100755 src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/scripts/nvidia-apx/glslc.bat delete mode 100644 src/jogl/classes/com/sun/opengl/impl/io/Locator.java delete mode 100755 src/jogl/classes/com/sun/opengl/impl/packrect/BackingStoreManager.java delete mode 100755 src/jogl/classes/com/sun/opengl/impl/packrect/Level.java delete mode 100755 src/jogl/classes/com/sun/opengl/impl/packrect/LevelSet.java delete mode 100755 src/jogl/classes/com/sun/opengl/impl/packrect/Rect.java delete mode 100755 src/jogl/classes/com/sun/opengl/impl/packrect/RectVisitor.java delete mode 100755 src/jogl/classes/com/sun/opengl/impl/packrect/RectanglePacker.java delete mode 100755 src/jogl/classes/com/sun/opengl/impl/packrect/package.html create mode 100755 src/jogl/classes/com/sun/opengl/util/BufferUtil.java.javame_cdc_fp create mode 100755 src/jogl/classes/com/sun/opengl/util/BufferUtil.java.javase create mode 100644 src/jogl/classes/com/sun/opengl/util/FixedPoint.java create mode 100644 src/jogl/classes/com/sun/opengl/util/GLArrayHandler.java create mode 100644 src/jogl/classes/com/sun/opengl/util/GLFixedArrayHandler.java create mode 100755 src/jogl/classes/com/sun/opengl/util/Gamma.java create mode 100644 src/jogl/classes/com/sun/opengl/util/Locator.java create mode 100755 src/jogl/classes/com/sun/opengl/util/PMVMatrix.java create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/GLSLArrayHandler.java delete mode 100755 src/jogl/classes/com/sun/opengl/util/glsl/fixed/FixedFuncHook.java create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/FixedFuncUtil.java create mode 100755 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncHook.java create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncPipeline.java create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColor.fp create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColor.vp create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorLight.vp create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorTexture.fp create mode 100755 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bfp create mode 100755 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bvp create mode 100755 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorLight.bvp create mode 100755 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorTexture.bfp create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/es_precision.glsl create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_attribute.glsl create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_const.glsl create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_lightdef.glsl create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_settexcoord.vp create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform.glsl create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform_light.glsl create mode 100644 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_varying.glsl create mode 100755 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc-ff.bat create mode 100755 src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc.bat create mode 100755 src/jogl/classes/com/sun/opengl/util/packrect/BackingStoreManager.java create mode 100755 src/jogl/classes/com/sun/opengl/util/packrect/Level.java create mode 100755 src/jogl/classes/com/sun/opengl/util/packrect/LevelSet.java create mode 100755 src/jogl/classes/com/sun/opengl/util/packrect/Rect.java create mode 100755 src/jogl/classes/com/sun/opengl/util/packrect/RectVisitor.java create mode 100755 src/jogl/classes/com/sun/opengl/util/packrect/RectanglePacker.java create mode 100755 src/jogl/classes/com/sun/opengl/util/packrect/package.html create mode 100644 src/jogl/classes/javax/media/opengl/GLBase.java create mode 100644 src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java create mode 100644 src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java create mode 100644 src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java delete mode 100644 src/jogl/classes/javax/media/opengl/sub/GLObject.java delete mode 100644 src/jogl/classes/javax/media/opengl/sub/fixed/GLFixedFuncUtil.java delete mode 100644 src/jogl/classes/javax/media/opengl/sub/fixed/GLLightingIf.java delete mode 100644 src/jogl/classes/javax/media/opengl/sub/fixed/GLMatrixIf.java delete mode 100644 src/jogl/classes/javax/media/opengl/sub/fixed/GLPointerIf.java delete mode 100755 src/jogl/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp delete mode 100755 src/jogl/classes/javax/media/opengl/util/BufferUtil.java.javase delete mode 100644 src/jogl/classes/javax/media/opengl/util/FixedPoint.java delete mode 100755 src/jogl/classes/javax/media/opengl/util/Gamma.java delete mode 100755 src/jogl/classes/javax/media/opengl/util/PMVMatrix.java create mode 100644 src/jogl/native/GLXGetProcAddressARB.c delete mode 100644 src/jogl/native/InternalBufferUtils.c (limited to 'src/jogl') diff --git a/src/jogl/classes/com/sun/opengl/impl/GLArrayHandler.java b/src/jogl/classes/com/sun/opengl/impl/GLArrayHandler.java deleted file mode 100644 index d34e04b10..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/GLArrayHandler.java +++ /dev/null @@ -1,12 +0,0 @@ - -package com.sun.opengl.impl; - -import javax.media.opengl.*; -import javax.media.opengl.sub.*; - -public interface GLArrayHandler { - - public void enableBuffer(GL gl, boolean enable); - -} - diff --git a/src/jogl/classes/com/sun/opengl/impl/GLFixedArrayHandler.java b/src/jogl/classes/com/sun/opengl/impl/GLFixedArrayHandler.java deleted file mode 100644 index 86ae92754..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/GLFixedArrayHandler.java +++ /dev/null @@ -1,66 +0,0 @@ - -package com.sun.opengl.impl; - -import javax.media.opengl.*; -import javax.media.opengl.sub.*; -import javax.media.opengl.sub.fixed.*; -import com.sun.opengl.util.*; -import java.nio.*; - -public class GLFixedArrayHandler implements GLArrayHandler { - private GLArrayDataEditable ad; - - public GLFixedArrayHandler(GLArrayDataEditable ad) { - this.ad = ad; - } - - protected final void passArrayPointer(GLPointerIf gl) { - switch(ad.getIndex()) { - case GLPointerIf.GL_VERTEX_ARRAY: - gl.glVertexPointer(ad); - break; - case GLPointerIf.GL_NORMAL_ARRAY: - gl.glNormalPointer(ad); - break; - case GLPointerIf.GL_COLOR_ARRAY: - gl.glColorPointer(ad); - break; - case GLPointerIf.GL_TEXTURE_COORD_ARRAY: - gl.glTexCoordPointer(ad); - break; - default: - throw new GLException("invalid glArrayIndex: "+ad.getIndex()+":\n\t"+ad); - } - } - - public void enableBuffer(GL gl, boolean enable) { - GLPointerIf glp = gl.getGL2ES1(); - if(enable) { - glp.glEnableClientState(ad.getIndex()); - - Buffer buffer = ad.getBuffer(); - - if(ad.isVBO()) { - // always bind and refresh the VBO mgr, - // in case more than one gl*Pointer objects are in use - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, ad.getVBOName()); - if(!ad.isBufferWritten()) { - if(null!=buffer) { - gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * ad.getComponentSize(), buffer, ad.getBufferUsage()); - } - ad.setBufferWritten(true); - } - passArrayPointer(glp); - } else if(null!=buffer) { - passArrayPointer(glp); - ad.setBufferWritten(true); - } - } else { - if(ad.isVBO()) { - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); - } - glp.glDisableClientState(ad.getIndex()); - } - } -} - diff --git a/src/jogl/classes/com/sun/opengl/impl/InternalBufferUtil.java.javame_cdc_fp b/src/jogl/classes/com/sun/opengl/impl/InternalBufferUtil.java.javame_cdc_fp new file mode 100644 index 000000000..1b989dc37 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/impl/InternalBufferUtil.java.javame_cdc_fp @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2009 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. + * + */ + +package com.sun.opengl.impl; + +import java.lang.reflect.*; +import java.nio.*; + +/** Internal copy of selected routines from BufferUtil to avoid + outward dependencies on com.sun.opengl.util package. */ +public class InternalBufferUtil { + 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; + + //---------------------------------------------------------------------- + // Allocation routines + // + + /** 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; + } + + /** 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(); + } + + //---------------------------------------------------------------------- + // Conversion routines + // + + public 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; + } + + //---------------------------------------------------------------------- + // 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/com/sun/opengl/impl/InternalBufferUtil.java.javase b/src/jogl/classes/com/sun/opengl/impl/InternalBufferUtil.java.javase new file mode 100644 index 000000000..f9f443e13 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/impl/InternalBufferUtil.java.javase @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2009 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. + * + */ + +package com.sun.opengl.impl; + +import java.lang.reflect.*; +import java.nio.*; + +/** Internal copy of selected routines from BufferUtil to avoid + outward dependencies on com.sun.opengl.util package. */ +public class InternalBufferUtil { + 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; + + //---------------------------------------------------------------------- + // Allocation routines + // + + /** 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; + } + + /** 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(); + } + + /** 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(); + } + + /** 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(); + } + + //---------------------------------------------------------------------- + // Copy routines (type-to-type) + // + + /** Copies the remaining elements (as defined by + limit() - position()) 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; + } + + //---------------------------------------------------------------------- + // Copy routines (type-to-ByteBuffer) + // + + /** Copies the remaining elements (as defined by + limit() - position()) 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 remaining elements (as defined by + limit() - position()) 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 remaining elements (as defined by + limit() - position()) 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 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; + } + + //---------------------------------------------------------------------- + // 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/com/sun/opengl/impl/InternalBufferUtils.java b/src/jogl/classes/com/sun/opengl/impl/InternalBufferUtils.java deleted file mode 100644 index 89639c493..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/InternalBufferUtils.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2003 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 com.sun.opengl.impl; - -import java.nio.*; - -/** Utility routines available only to the JOGL implementation. */ - -public class InternalBufferUtils { - /** Allocates a new direct byte buffer at the given address with the - given capacity. This is exposed only because of glMapBufferARB - and its semantics; it is undesirable to allocate a new buffer - every frame because (a) ByteBuffers are finalizable and (b) the - application would typically need to re-slice the buffer every - frame. Instead we cache these ByteBuffer objects up in Java and - look them up in a HashMap by base address and capacity. */ - public static native ByteBuffer newDirectByteBuffer(long address, int capacity); -} diff --git a/src/jogl/classes/com/sun/opengl/impl/ProjectFloat.java b/src/jogl/classes/com/sun/opengl/impl/ProjectFloat.java index 5788bbc9b..cc8ba639f 100755 --- a/src/jogl/classes/com/sun/opengl/impl/ProjectFloat.java +++ b/src/jogl/classes/com/sun/opengl/impl/ProjectFloat.java @@ -117,8 +117,7 @@ package com.sun.opengl.impl; import java.nio.*; import javax.media.opengl.*; -import javax.media.opengl.util.*; -import javax.media.opengl.sub.fixed.GLMatrixIf; +import javax.media.opengl.fixedfunc.GLMatrixFunc; /** * ProjectFloat.java @@ -181,7 +180,7 @@ public class ProjectFloat { // Slice up one big buffer because some NIO implementations // allocate a huge amount of memory to back even the smallest of // buffers. - locbuf = BufferUtil.newFloatBuffer(2*16+2*4+3*3); + locbuf = InternalBufferUtil.newFloatBuffer(2*16+2*4+3*3); int pos = 0; int sz = 16; matrixBuf = slice(locbuf, pos, sz); @@ -547,7 +546,7 @@ public class ProjectFloat { * @param bottom * @param top */ - public void gluOrtho2D(GLMatrixIf gl, float left, float right, float bottom, float top) { + public void gluOrtho2D(GLMatrixFunc gl, float left, float right, float bottom, float top) { gl.glOrthof(left, right, bottom, top, -1, 1); } @@ -559,7 +558,7 @@ public class ProjectFloat { * @param zNear * @param zFar */ - public void gluPerspective(GLMatrixIf gl, float fovy, float aspect, float zNear, float zFar) { + public void gluPerspective(GLMatrixFunc gl, float fovy, float aspect, float zNear, float zFar) { float sine, cotangent, deltaZ; float radians = fovy / 2 * (float) Math.PI / 180; @@ -597,7 +596,7 @@ public class ProjectFloat { * @param upy * @param upz */ - public void gluLookAt(GLMatrixIf gl, + public void gluLookAt(GLMatrixFunc gl, float eyex, float eyey, float eyez, @@ -1010,7 +1009,7 @@ public class ProjectFloat { * @param deltaY * @param viewport */ - public void gluPickMatrix(GLMatrixIf gl, + public void gluPickMatrix(GLMatrixFunc gl, float x, float y, float deltaX, @@ -1038,7 +1037,7 @@ public class ProjectFloat { * @param viewport * @param viewport_offset */ - public void gluPickMatrix(GLMatrixIf gl, + public void gluPickMatrix(GLMatrixFunc gl, float x, float y, float deltaX, diff --git a/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java b/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java index b73cfbd3e..a5f1d2ca3 100755 --- a/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java @@ -348,7 +348,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { public native void shutdown(); public void testGetDirectBufferAddress() { - java.nio.FloatBuffer buf = com.sun.opengl.util.BufferUtil.newFloatBuffer(12); + java.nio.FloatBuffer buf = com.sun.opengl.impl.InternalBufferUtil.newFloatBuffer(12); int addr = getDirectBufferAddress(buf); System.out.println("Direct FloatBuffer's address: 0x" + Integer.toHexString(addr)); } diff --git a/src/jogl/classes/com/sun/opengl/impl/gl2/ProjectDouble.java b/src/jogl/classes/com/sun/opengl/impl/gl2/ProjectDouble.java index 619c0bee3..5b7b679ad 100755 --- a/src/jogl/classes/com/sun/opengl/impl/gl2/ProjectDouble.java +++ b/src/jogl/classes/com/sun/opengl/impl/gl2/ProjectDouble.java @@ -117,7 +117,6 @@ package com.sun.opengl.impl.gl2; import java.nio.*; import javax.media.opengl.*; -import javax.media.opengl.util.*; import com.sun.opengl.impl.*; /** @@ -174,7 +173,7 @@ public class ProjectDouble { // Slice up one big buffer because some NIO implementations // allocate a huge amount of memory to back even the smallest of // buffers. - DoubleBuffer locbuf = BufferUtil.newDoubleBuffer(128); + DoubleBuffer locbuf = InternalBufferUtil.newDoubleBuffer(128); int pos = 0; int sz = 16; matrixBuf = slice(locbuf, pos, sz); diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java b/src/jogl/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java deleted file mode 100644 index 30c4a0190..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java +++ /dev/null @@ -1,62 +0,0 @@ - -package com.sun.opengl.impl.glsl; - -import com.sun.opengl.impl.*; - -import javax.media.opengl.*; -import javax.media.opengl.sub.*; -import com.sun.opengl.util.*; -import com.sun.opengl.util.glsl.ShaderState; -import java.nio.*; - -public class GLSLArrayHandler implements GLArrayHandler { - private GLArrayDataEditable ad; - - public GLSLArrayHandler(GLArrayDataEditable ad) { - this.ad = ad; - } - - protected final void passVertexAttribPointer(GL2ES2 gl, ShaderState st) { - st.glVertexAttribPointer(gl, ad); - } - - public void enableBuffer(GL gl, boolean enable) { - if(!gl.isGL2ES2()) { - throw new GLException("GLSLArrayHandler expects a GL2ES2 implementation"); - } - GL2ES2 glsl = gl.getGL2ES2(); - ShaderState st = ShaderState.getCurrent(); - if(null==st) { - throw new GLException("No ShaderState current"); - } - - if(enable) { - st.glEnableVertexAttribArray(glsl, ad.getName()); - - Buffer buffer = ad.getBuffer(); - - if(ad.isVBO()) { - // always bind and refresh the VBO mgr, - // in case more than one gl*Pointer objects are in use - glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, ad.getVBOName()); - if(!ad.isBufferWritten()) { - if(null!=buffer) { - glsl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * ad.getComponentSize(), buffer, ad.getBufferUsage()); - } - ad.setBufferWritten(true); - } - passVertexAttribPointer(glsl, st); - } else if(null!=buffer) { - passVertexAttribPointer(glsl, st); - ad.setBufferWritten(true); - } - } else { - if(ad.isVBO()) { - glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); - } - st.glDisableVertexAttribArray(glsl, ad.getName()); - } - } - -} - diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/FixedFuncPipeline.java b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/FixedFuncPipeline.java deleted file mode 100644 index 1d33254c0..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/FixedFuncPipeline.java +++ /dev/null @@ -1,533 +0,0 @@ - -package com.sun.opengl.impl.glsl.fixed; - -import javax.media.opengl.*; -import javax.media.opengl.util.*; -import javax.media.opengl.sub.fixed.*; -import com.sun.opengl.util.glsl.*; -import java.nio.*; - -public class FixedFuncPipeline { - public static final int MAX_TEXTURE_UNITS = 8; - public static final int MAX_LIGHTS = 8; - - public FixedFuncPipeline(GL2ES2 gl, PMVMatrix pmvMatrix) { - init(gl, pmvMatrix, FixedFuncPipeline.class, shaderSrcRootDef, shaderBinRootDef, - vertexColorFileDef, vertexColorLightFileDef, fragmentColorFileDef, fragmentColorTextureFileDef); - } - public FixedFuncPipeline(GL2ES2 gl, PMVMatrix pmvMatrix, Class shaderRootClass, String shaderSrcRoot, String shaderBinRoot, - String vertexColorFile, - String vertexColorLightFile, - String fragmentColorFile, - String fragmentColorTextureFile) { - init(gl, pmvMatrix, shaderRootClass, shaderSrcRoot, shaderBinRoot, - vertexColorFile, vertexColorLightFile, fragmentColorFile, fragmentColorTextureFile); - } - - public boolean verbose() { return verbose; } - - public void setVerbose(boolean v) { verbose=v; } - - public boolean isValid() { - return shaderState.linked(); - } - - public ShaderState getShaderState() { - return shaderState; - } - - public int getActiveTextureUnit() { - return activeTextureUnit; - } - - public String getArrayIndexName(int glArrayIndex) { - String name = GLContext.getPredefinedArrayIndexName(glArrayIndex); - switch(glArrayIndex) { - case GLPointerIf.GL_VERTEX_ARRAY: - case GLPointerIf.GL_NORMAL_ARRAY: - case GLPointerIf.GL_COLOR_ARRAY: - break; - case GLPointerIf.GL_TEXTURE_COORD_ARRAY: - name = name + activeTextureUnit; - } - return name; - } - - public void destroy(GL2ES2 gl) { - shaderProgramColor.release(gl, true); - shaderProgramColorLight.release(gl, true); - shaderProgramColorTexture.release(gl, true); - shaderProgramColorTextureLight.release(gl, true); - shaderState.destroy(gl); - } - - public void glEnableClientState(GL2ES2 gl, int glArrayIndex) { - shaderState.glUseProgram(gl, true); - - shaderState.glEnableVertexAttribArray(gl, getArrayIndexName(glArrayIndex)); - // textureCoordsEnabled |= (1 << activeTextureUnit); - if ( textureCoordsEnabled.get(activeTextureUnit) != 1 ) { - textureCoordsEnabled.put(activeTextureUnit, 1); - textureCoordsEnabledDirty = true; - } - } - - public void glDisableClientState(GL2ES2 gl, int glArrayIndex) { - shaderState.glUseProgram(gl, true); - - shaderState.glDisableVertexAttribArray(gl, getArrayIndexName(glArrayIndex)); - // textureCoordsEnabled &= ~(1 << activeTextureUnit); - if ( textureCoordsEnabled.get(activeTextureUnit) != 0 ) { - textureCoordsEnabled.put(activeTextureUnit, 0); - textureCoordsEnabledDirty = true; - } - } - - public void glVertexPointer(GL2ES2 gl, GLArrayData data) { - shaderState.glUseProgram(gl, true); - shaderState.glVertexAttribPointer(gl, data); - } - - public void glColorPointer(GL2ES2 gl, GLArrayData data) { - shaderState.glUseProgram(gl, true); - shaderState.glVertexAttribPointer(gl, data); - } - - public void glColor4fv(GL2ES2 gl, FloatBuffer data ) { - shaderState.glUseProgram(gl, true); - GLUniformData ud = shaderState.getUniform(mgl_ColorStatic); - if(null!=ud) { - ud.setData(data); - shaderState.glUniform(gl, ud); - } - } - - public void glNormalPointer(GL2ES2 gl, GLArrayData data) { - shaderState.glUseProgram(gl, true); - shaderState.glVertexAttribPointer(gl, data); - } - - public void glTexCoordPointer(GL2ES2 gl, GLArrayData data) { - shaderState.glUseProgram(gl, true); - data.setName( getArrayIndexName(data.getIndex()) ); - shaderState.glVertexAttribPointer(gl, data); - } - - public void glLightfv(GL2ES2 gl, int light, int pname, java.nio.FloatBuffer params) { - shaderState.glUseProgram(gl, true); - light -=GLLightingIf.GL_LIGHT0; - if(0 <= light && light < MAX_LIGHTS) { - GLUniformData ud = null; - switch(pname) { - case GLLightingIf.GL_AMBIENT: - ud = shaderState.getUniform(mgl_LightSource+"["+light+"].ambient"); - break; - case GLLightingIf.GL_DIFFUSE: - ud = shaderState.getUniform(mgl_LightSource+"["+light+"].diffuse"); - break; - case GLLightingIf.GL_SPECULAR: - ud = shaderState.getUniform(mgl_LightSource+"["+light+"].specular"); - break; - case GLLightingIf.GL_POSITION: - ud = shaderState.getUniform(mgl_LightSource+"["+light+"].position"); - break; - case GLLightingIf.GL_SPOT_DIRECTION: - ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotDirection"); - break; - case GLLightingIf.GL_SPOT_EXPONENT: - ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotExponent"); - break; - case GLLightingIf.GL_SPOT_CUTOFF: - ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotCutoff"); - break; - case GLLightingIf.GL_CONSTANT_ATTENUATION: - ud = shaderState.getUniform(mgl_LightSource+"["+light+"].constantAttenuation"); - break; - case GLLightingIf.GL_LINEAR_ATTENUATION: - ud = shaderState.getUniform(mgl_LightSource+"["+light+"].linearAttenuation"); - break; - case GLLightingIf.GL_QUADRATIC_ATTENUATION: - ud = shaderState.getUniform(mgl_LightSource+"["+light+"].quadraticAttenuation"); - break; - default: - if(verbose) { - System.err.println("glLightfv pname not within [GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_POSITION GL_SPOT_DIRECTION]: "+pname); - } - return; - } - if(null!=ud) { - ud.setData(params); - shaderState.glUniform(gl, ud); - } - } else if(verbose) { - System.err.println("glLightfv light not within [0.."+MAX_LIGHTS+"]: "+light); - } - } - - public void glMaterialfv(GL2ES2 gl, int face, int pname, java.nio.FloatBuffer params) { - shaderState.glUseProgram(gl, true); - - switch (face) { - case GL.GL_FRONT: - case GL.GL_FRONT_AND_BACK: - break; - case GL.GL_BACK: - if(verbose) { - System.err.println("glMaterialfv face GL_BACK currently not supported"); - } - break; - default: - } - - GLUniformData ud = null; - switch(pname) { - case GLLightingIf.GL_AMBIENT: - ud = shaderState.getUniform(mgl_FrontMaterial+".ambient"); - break; - case GLLightingIf.GL_AMBIENT_AND_DIFFUSE: - glMaterialfv(gl, face, GLLightingIf.GL_AMBIENT, params); - // fall through intended .. - case GLLightingIf.GL_DIFFUSE: - ud = shaderState.getUniform(mgl_FrontMaterial+".diffuse"); - break; - case GLLightingIf.GL_SPECULAR: - ud = shaderState.getUniform(mgl_FrontMaterial+".specular"); - break; - case GLLightingIf.GL_EMISSION: - ud = shaderState.getUniform(mgl_FrontMaterial+".emission"); - break; - case GLLightingIf.GL_SHININESS: - ud = shaderState.getUniform(mgl_FrontMaterial+".shininess"); - break; - default: - if(verbose) { - System.err.println("glMaterialfv pname not within [GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_EMISSION GL_SHININESS]: "+pname); - } - return; - } - if(null!=ud) { - ud.setData(params); - shaderState.glUniform(gl, ud); - } - } - - public void glShadeModel(GL2ES2 gl, int mode) { - shaderState.glUseProgram(gl, true); - GLUniformData ud = shaderState.getUniform(mgl_ShadeModel); - if(null!=ud) { - ud.setData(mode); - shaderState.glUniform(gl, ud); - } - } - - public void glActiveTexture(GL2ES2 gl, int textureUnit) { - textureUnit -= GL.GL_TEXTURE0; - if(0 <= textureUnit && textureUnitcullFace) { - faceName *= -1; - } - cullFace = faceName; - } - - public void validate(GL2ES2 gl) { - shaderState.glUseProgram(gl, true); - GLUniformData ud; - if(pmvMatrix.update()) { - ud = shaderState.getUniform(mgl_PMVMatrix); - if(null!=ud) { - // same data object .. - shaderState.glUniform(gl, ud); - } else { - throw new GLException("Failed to update: mgl_PMVMatrix"); - } - ud = shaderState.getUniform(mgl_NormalMatrix); - if(null!=ud) { - // same data object .. - shaderState.glUniform(gl, ud); - } - } - ud = shaderState.getUniform(mgl_ColorEnabled); - if(null!=ud) { - int ca = (shaderState.isVertexAttribArrayEnabled(GLContext.mgl_Color)==true)?1:0; - if(ca!=ud.intValue()) { - ud.setData(ca); - shaderState.glUniform(gl, ud); - } - } - ud = shaderState.getUniform(mgl_CullFace); - if(null!=ud) { - if(cullFace!=ud.intValue()) { - ud.setData(cullFace); - shaderState.glUniform(gl, ud); - } - } - - if(lightsEnabledDirty) { - ud = shaderState.getUniform(mgl_LightsEnabled); - if(null!=ud) { - // same data object - shaderState.glUniform(gl, ud); - } - lightsEnabledDirty=false; - } - - if(textureCoordsEnabledDirty) { - ud = shaderState.getUniform(mgl_TexCoordEnabled); - if(null!=ud) { - // same data object - shaderState.glUniform(gl, ud); - } - textureCoordsEnabledDirty=false; - } - - if(textureEnabled) { - if(lightingEnabled) { - shaderState.attachShaderProgram(gl, shaderProgramColorTextureLight); - } else { - shaderState.attachShaderProgram(gl, shaderProgramColorTexture); - } - } else { - if(lightingEnabled) { - shaderState.attachShaderProgram(gl, shaderProgramColorLight); - } else { - shaderState.attachShaderProgram(gl, shaderProgramColor); - } - } - if(DEBUG) { - System.err.println("validate: "+this); - } - } - - public String toString() { - return "FixedFuncPipeline[pmv: "+pmvMatrix+ - ", textureEnabled: "+textureEnabled+ - ", textureCoordsEnabled: "+textureCoordsEnabled+ - ", lightingEnabled: "+lightingEnabled+ - ", lightsEnabled: "+lightsEnabled+ - "\n\t, shaderProgramColor: "+shaderProgramColor+ - "\n\t, shaderProgramColorTexture: "+shaderProgramColorTexture+ - "\n\t, shaderProgramColorLight: "+shaderProgramColorLight+ - "\n\t, shaderProgramColorTextureLight: "+shaderProgramColorTextureLight+ - "\n\t, ShaderState: "+shaderState+ - "]"; - } - - protected void init(GL2ES2 gl, PMVMatrix pmvMatrix, Class shaderRootClass, String shaderSrcRoot, String shaderBinRoot, - String vertexColorFile, - String vertexColorLightFile, - String fragmentColorFile, - String fragmentColorTextureFile) - { - if(null==pmvMatrix) { - throw new GLException("PMVMatrix is null"); - } - this.pmvMatrix=pmvMatrix; - this.shaderState=new ShaderState(); - this.shaderState.setVerbose(verbose); - ShaderCode vertexColor, vertexColorLight, fragmentColor, fragmentColorTexture; - - vertexColor = ShaderCode.create( gl, gl.GL_VERTEX_SHADER, 1, shaderRootClass, - shaderSrcRoot, shaderBinRoot, vertexColorFile); - - vertexColorLight = ShaderCode.create( gl, gl.GL_VERTEX_SHADER, 1, shaderRootClass, - shaderSrcRoot, shaderBinRoot, vertexColorLightFile); - - fragmentColor = ShaderCode.create( gl, gl.GL_FRAGMENT_SHADER, 1, shaderRootClass, - shaderSrcRoot, shaderBinRoot, fragmentColorFile); - - fragmentColorTexture = ShaderCode.create( gl, gl.GL_FRAGMENT_SHADER, 1, shaderRootClass, - shaderSrcRoot, shaderBinRoot, fragmentColorTextureFile); - - shaderProgramColor = new ShaderProgram(); - shaderProgramColor.add(vertexColor); - shaderProgramColor.add(fragmentColor); - if(!shaderProgramColor.link(gl, System.err)) { - throw new GLException("Couldn't link VertexColor program: "+shaderProgramColor); - } - - shaderProgramColorTexture = new ShaderProgram(); - shaderProgramColorTexture.add(vertexColor); - shaderProgramColorTexture.add(fragmentColorTexture); - if(!shaderProgramColorTexture.link(gl, System.err)) { - throw new GLException("Couldn't link VertexColorTexture program: "+shaderProgramColorTexture); - } - - shaderProgramColorLight = new ShaderProgram(); - shaderProgramColorLight.add(vertexColorLight); - shaderProgramColorLight.add(fragmentColor); - if(!shaderProgramColorLight.link(gl, System.err)) { - throw new GLException("Couldn't link VertexColorLight program: "+shaderProgramColorLight); - } - - shaderProgramColorTextureLight = new ShaderProgram(); - shaderProgramColorTextureLight.add(vertexColorLight); - shaderProgramColorTextureLight.add(fragmentColorTexture); - if(!shaderProgramColorTextureLight.link(gl, System.err)) { - throw new GLException("Couldn't link VertexColorLight program: "+shaderProgramColorTextureLight); - } - - shaderState.attachShaderProgram(gl, shaderProgramColor); - shaderState.glUseProgram(gl, true); - - // mandatory .. - if(!shaderState.glUniform(gl, new GLUniformData(mgl_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMviMatrixf()))) { - throw new GLException("Error setting PMVMatrix in shader: "+this); - } - - // optional parameter .. - shaderState.glUniform(gl, new GLUniformData(mgl_NormalMatrix, 3, 3, pmvMatrix.glGetNormalMatrixf())); - - shaderState.glUniform(gl, new GLUniformData(mgl_ColorEnabled, 0)); - shaderState.glUniform(gl, new GLUniformData(mgl_ColorStatic, 4, zero4f)); - shaderState.glUniform(gl, new GLUniformData(mgl_TexCoordEnabled, 1, textureCoordsEnabled)); - shaderState.glUniform(gl, new GLUniformData(mgl_ActiveTexture, activeTextureUnit)); - shaderState.glUniform(gl, new GLUniformData(mgl_ActiveTextureIdx, activeTextureUnit)); - shaderState.glUniform(gl, new GLUniformData(mgl_ShadeModel, 0)); - shaderState.glUniform(gl, new GLUniformData(mgl_CullFace, cullFace)); - for(int i=0; i 0 && - ( ( mgl_CullFace == 1 && gl_FrontFacing ) || - ( mgl_CullFace == 2 && !gl_FrontFacing ) || - ( mgl_CullFace == 3 ) ) ) { - discard; - } - gl_FragColor = frontColor; -} - diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/FixedFuncColor.vp b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/FixedFuncColor.vp deleted file mode 100644 index 346e40196..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/FixedFuncColor.vp +++ /dev/null @@ -1,22 +0,0 @@ -#include es_precision.glsl - -#include mgl_const.glsl -#include mgl_uniform.glsl -#include mgl_attribute.glsl -#include mgl_varying.glsl - -#include mgl_settexcoord.vp - -void main(void) -{ - if(mgl_ColorEnabled>0) { - frontColor=mgl_Color; - } else { - frontColor=mgl_ColorStatic; - } - - gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex; - - setTexCoord(gl_Position); -} - diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/FixedFuncColorLight.vp b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/FixedFuncColorLight.vp deleted file mode 100644 index ce203cfb9..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/FixedFuncColorLight.vp +++ /dev/null @@ -1,70 +0,0 @@ -#include es_precision.glsl -#include mgl_lightdef.glsl - -#include mgl_const.glsl -#include mgl_uniform.glsl -#include mgl_uniform_light.glsl -#include mgl_attribute.glsl -#include mgl_varying.glsl - -#include mgl_settexcoord.vp - -void main(void) -{ - vec4 position; - vec3 normal, lightDir, cameraDir, halfDir; - vec4 ambient, diffuse, specular; - float NdotL, NdotHV, dist, attenuation; - int i; - - position = mgl_PMVMatrix[1] * mgl_Vertex; // vertex eye position - - normal = normalize(mgl_NormalMatrix * mgl_Normal); - // cameraPosition: (mgl_PMVMatrix[2] * vec4(0,0,0,1.0)).xyz - cameraDir = normalize( (mgl_PMVMatrix[2] * vec4(0,0,0,1.0)).xyz - mgl_Vertex.xyz ); - - ambient = vec4(0,0,0,0); - diffuse = vec4(0,0,0,0); - specular = vec4(0,0,0,0); - - bool lightEnabled = false; - - for(i=0; i0) { - frontColor=mgl_Color; - } else { - frontColor=mgl_ColorStatic; - } - if( lightEnabled ) { - frontColor *= ambient + diffuse + specular; - } - - gl_Position = mgl_PMVMatrix[0] * position; - - setTexCoord(gl_Position); -} - diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/FixedFuncColorTexture.fp b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/FixedFuncColorTexture.fp deleted file mode 100644 index 86e6ace73..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/FixedFuncColorTexture.fp +++ /dev/null @@ -1,47 +0,0 @@ - -#include es_precision.glsl -#include mgl_lightdef.glsl - -#include mgl_const.glsl -#include mgl_uniform.glsl -#include mgl_varying.glsl - -vec4 getTexColor(in sampler2D tex, in int idx) { - vec4 coord; - if(idx==0) { - coord= mgl_TexCoords[0]; - } else if(idx==1) { - coord= mgl_TexCoords[1]; - } else if(idx==2) { - coord= mgl_TexCoords[2]; - } else if(idx==3) { - coord= mgl_TexCoords[3]; - } else if(idx==4) { - coord= mgl_TexCoords[4]; - } else if(idx==5) { - coord= mgl_TexCoords[5]; - } else if(idx==6) { - coord= mgl_TexCoords[6]; - } else { - coord= mgl_TexCoords[7]; - } - return texture2D(tex, coord.st); -} - -void main (void) -{ - if( mgl_CullFace > 0 && - ( ( mgl_CullFace == 1 && gl_FrontFacing ) || - ( mgl_CullFace == 2 && !gl_FrontFacing ) || - ( mgl_CullFace == 3 ) ) ) { - discard; - } - - vec4 texColor = getTexColor(mgl_ActiveTexture,mgl_ActiveTextureIdx); - - if(length(texColor.rgb)>0.0) { - gl_FragColor = vec4(frontColor.rgb*texColor.rgb, frontColor.a) ; - } else { - gl_FragColor = frontColor; - } -} diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColor.bfp b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColor.bfp deleted file mode 100755 index 3ebaaee1d..000000000 Binary files a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColor.bfp and /dev/null differ diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColor.bvp b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColor.bvp deleted file mode 100755 index 279ef72c7..000000000 Binary files a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColor.bvp and /dev/null differ diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColorLight.bvp b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColorLight.bvp deleted file mode 100755 index 5a9deea71..000000000 Binary files a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColorLight.bvp and /dev/null differ diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColorTexture.bfp b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColorTexture.bfp deleted file mode 100755 index ce1397fe1..000000000 Binary files a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/FixedFuncColorTexture.bfp and /dev/null differ diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/es_precision.glsl b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/es_precision.glsl deleted file mode 100644 index fd6abe54e..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/es_precision.glsl +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef es_precision_glsl -#define es_precision_glsl - -#ifdef GL_ES - #define MEDIUMP mediump - #define HIGHP highp - #define LOWP lowp -#else - #define MEDIUMP - #define HIGHP - #define LOWP -#endif - -#endif // es_precision_glsl diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_attribute.glsl b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_attribute.glsl deleted file mode 100644 index b09bdb05a..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_attribute.glsl +++ /dev/null @@ -1,19 +0,0 @@ - -#ifndef mgl_attribute_glsl -#define mgl_attribute_glsl - -#include es_precision.glsl - -attribute HIGHP vec4 mgl_Vertex; -attribute HIGHP vec3 mgl_Normal; -attribute HIGHP vec4 mgl_Color; -attribute HIGHP vec4 mgl_MultiTexCoord0; -attribute HIGHP vec4 mgl_MultiTexCoord1; -attribute HIGHP vec4 mgl_MultiTexCoord2; -attribute HIGHP vec4 mgl_MultiTexCoord3; -attribute HIGHP vec4 mgl_MultiTexCoord4; -attribute HIGHP vec4 mgl_MultiTexCoord5; -attribute HIGHP vec4 mgl_MultiTexCoord6; -attribute HIGHP vec4 mgl_MultiTexCoord7; - -#endif // mgl_attribute_glsl diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_const.glsl b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_const.glsl deleted file mode 100644 index 1a464a1cb..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_const.glsl +++ /dev/null @@ -1,10 +0,0 @@ - -#ifndef mgl_const_glsl -#define mgl_const_glsl - -#include es_precision.glsl - -const LOWP int MAX_TEXTURE_UNITS = 8; // <=gl_MaxTextureImageUnits -const LOWP int MAX_LIGHTS = 8; - -#endif // mgl_const_glsl diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_lightdef.glsl b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_lightdef.glsl deleted file mode 100644 index 98e214139..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_lightdef.glsl +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef mgl_lightdef_glsl -#define mgl_lightdef_glsl - -struct mgl_LightSourceParameters { - vec4 ambient; - vec4 diffuse; - vec4 specular; - vec4 position; - // vec4 halfVector; // is computed here - vec3 spotDirection; - float spotExponent; - float spotCutoff; // (range: [0.0,90.0], 180.0) - //float spotCosCutoff; // (range: [1.0,0.0],-1.0) - float constantAttenuation; - float linearAttenuation; - float quadraticAttenuation; -}; -struct mgl_MaterialParameters { - vec4 ambient; - vec4 diffuse; - vec4 specular; - vec4 emission; - float shininess; -}; - -#endif // mgl_lightdef_glsl diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_settexcoord.vp b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_settexcoord.vp deleted file mode 100644 index 1efe328d0..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_settexcoord.vp +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef mgl_settexcoord_vp -#define mgl_settexcoord_vp - -#include es_precision.glsl - -#include mgl_const.glsl -#include mgl_uniform.glsl -#include mgl_attribute.glsl -#include mgl_varying.glsl - -void setTexCoord(in vec4 defpos) { - /** - * bitwise operator not supported on APX 2500 ES 2.0 - * - mgl_TexCoords[0] = ( 0 != (mgl_TexCoordEnabled & 1) ) ? mgl_MultiTexCoord0 : defpos; - mgl_TexCoords[1] = ( 0 != (mgl_TexCoordEnabled & 2) ) ? mgl_MultiTexCoord1 : defpos; - mgl_TexCoords[2] = ( 0 != (mgl_TexCoordEnabled & 4) ) ? mgl_MultiTexCoord2 : defpos; - mgl_TexCoords[3] = ( 0 != (mgl_TexCoordEnabled & 8) ) ? mgl_MultiTexCoord3 : defpos; - mgl_TexCoords[4] = ( 0 != (mgl_TexCoordEnabled & 16) ) ? mgl_MultiTexCoord4 : defpos; - mgl_TexCoords[5] = ( 0 != (mgl_TexCoordEnabled & 32) ) ? mgl_MultiTexCoord5 : defpos; - mgl_TexCoords[6] = ( 0 != (mgl_TexCoordEnabled & 64) ) ? mgl_MultiTexCoord6 : defpos; - mgl_TexCoords[7] = ( 0 != (mgl_TexCoordEnabled & 128) ) ? mgl_MultiTexCoord7 : defpos; - */ - - mgl_TexCoords[0] = ( 0 != mgl_TexCoordEnabled[0] ) ? mgl_MultiTexCoord0 : defpos; - mgl_TexCoords[1] = ( 0 != mgl_TexCoordEnabled[1] ) ? mgl_MultiTexCoord1 : defpos; - mgl_TexCoords[2] = ( 0 != mgl_TexCoordEnabled[2] ) ? mgl_MultiTexCoord2 : defpos; - mgl_TexCoords[3] = ( 0 != mgl_TexCoordEnabled[3] ) ? mgl_MultiTexCoord3 : defpos; - mgl_TexCoords[4] = ( 0 != mgl_TexCoordEnabled[4] ) ? mgl_MultiTexCoord4 : defpos; - mgl_TexCoords[5] = ( 0 != mgl_TexCoordEnabled[5] ) ? mgl_MultiTexCoord5 : defpos; - mgl_TexCoords[6] = ( 0 != mgl_TexCoordEnabled[6] ) ? mgl_MultiTexCoord6 : defpos; - mgl_TexCoords[7] = ( 0 != mgl_TexCoordEnabled[7] ) ? mgl_MultiTexCoord7 : defpos; -} - -#endif // mgl_settexcoord_vp diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_uniform.glsl b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_uniform.glsl deleted file mode 100644 index d8b3c7f95..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_uniform.glsl +++ /dev/null @@ -1,18 +0,0 @@ - -#ifndef mgl_uniform_glsl -#define mgl_uniform_glsl - -#include es_precision.glsl - -#include mgl_const.glsl - -uniform HIGHP mat4 mgl_PMVMatrix[3]; // P, Mv, and Mvi -uniform HIGHP mat3 mgl_NormalMatrix; // transpose(inverse(ModelView)).3x3 -uniform LOWP int mgl_ColorEnabled; -uniform HIGHP vec4 mgl_ColorStatic; -uniform LOWP int mgl_TexCoordEnabled[MAX_TEXTURE_UNITS]; -uniform sampler2D mgl_ActiveTexture; -uniform LOWP int mgl_ActiveTextureIdx; -uniform LOWP int mgl_CullFace; - -#endif // mgl_uniform_glsl diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_uniform_light.glsl b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_uniform_light.glsl deleted file mode 100644 index 0dedb5d5d..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_uniform_light.glsl +++ /dev/null @@ -1,15 +0,0 @@ - -#ifndef mgl_uniform_light_glsl -#define mgl_uniform_light_glsl - -#include es_precision.glsl - -#include mgl_const.glsl -#include mgl_lightdef.glsl - -uniform LOWP int mgl_LightsEnabled[MAX_LIGHTS]; - -uniform mgl_LightSourceParameters mgl_LightSource[MAX_LIGHTS]; -uniform mgl_MaterialParameters mgl_FrontMaterial; - -#endif // mgl_uniform_light_glsl diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_varying.glsl b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_varying.glsl deleted file mode 100644 index fc9f735d1..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/mgl_varying.glsl +++ /dev/null @@ -1,12 +0,0 @@ - -#ifndef mgl_varying_glsl -#define mgl_varying_glsl - -#include es_precision.glsl - -#include mgl_const.glsl - -varying vec4 frontColor; -varying vec4 mgl_TexCoords[MAX_TEXTURE_UNITS]; - -#endif // mgl_varying_glsl diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/scripts/nvidia-apx/glslc-ff.bat b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/scripts/nvidia-apx/glslc-ff.bat deleted file mode 100755 index 21fba2fc3..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/scripts/nvidia-apx/glslc-ff.bat +++ /dev/null @@ -1,9 +0,0 @@ -REM -REM You have to call it from the 'shader' directory, e.g.: -REM scripts\nvidia-apx\glslc-ff.bat -REM -IF !"%JOGLDIR%"==""! GOTO YESPATH -set JOGLDIR=..\lib -:YESPATH - -java -cp %JOGLDIR%\jogl.core.jar;%JOGLDIR%\jogl.gles2.jar;%JOGLDIR%\jogl.fixed.jar;%JOGLDIR%\jogl.sdk.jar javax.media.opengl.sdk.glsl.CompileShaderNVidia FixedFuncColor.fp FixedFuncColorTexture.fp FixedFuncColorLight.vp FixedFuncColor.vp diff --git a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/scripts/nvidia-apx/glslc.bat b/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/scripts/nvidia-apx/glslc.bat deleted file mode 100755 index 28f3cf822..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/glsl/fixed/shader/scripts/nvidia-apx/glslc.bat +++ /dev/null @@ -1,9 +0,0 @@ -REM -REM You have to call it from the 'shader' directory, e.g.: -REM scripts\nvidia-apx\glslc.bat -REM -IF !"%JOGLDIR%"==""! GOTO YESPATH -set JOGLDIR=..\lib -:YESPATH - -java -cp %JOGLDIR%\jogl.core.jar;%JOGLDIR%\jogl.gles2.jar;%JOGLDIR%\jogl.fixed.jar;%JOGLDIR%\jogl.sdk.jar javax.media.opengl.sdk.glsl.CompileShaderNVidia %1 diff --git a/src/jogl/classes/com/sun/opengl/impl/glu/GLUquadricImpl.java b/src/jogl/classes/com/sun/opengl/impl/glu/GLUquadricImpl.java index 2d6e41126..bb1decf42 100644 --- a/src/jogl/classes/com/sun/opengl/impl/glu/GLUquadricImpl.java +++ b/src/jogl/classes/com/sun/opengl/impl/glu/GLUquadricImpl.java @@ -116,7 +116,6 @@ package com.sun.opengl.impl.glu; import javax.media.opengl.*; -import javax.media.opengl.sub.*; import javax.media.opengl.glu.*; import com.sun.opengl.util.ImmModeSink; import java.nio.*; diff --git a/src/jogl/classes/com/sun/opengl/impl/glu/mipmap/BuildMipmap.java b/src/jogl/classes/com/sun/opengl/impl/glu/mipmap/BuildMipmap.java index c30f83d20..f77f76fc8 100644 --- a/src/jogl/classes/com/sun/opengl/impl/glu/mipmap/BuildMipmap.java +++ b/src/jogl/classes/com/sun/opengl/impl/glu/mipmap/BuildMipmap.java @@ -47,8 +47,8 @@ package com.sun.opengl.impl.glu.mipmap; import javax.media.opengl.GL; import javax.media.opengl.GL2; import javax.media.opengl.glu.GLU; -import javax.media.opengl.util.BufferUtil; import com.sun.opengl.impl.Debug; +import com.sun.opengl.impl.InternalBufferUtil; import java.nio.*; import java.io.*; @@ -89,7 +89,7 @@ public class BuildMipmap { Mipmap.retrieveStoreModes( gl, psm ); try { - newImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.image_size( width, 1, format, + newImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.image_size( width, 1, format, GL2.GL_UNSIGNED_SHORT ) )).asShortBuffer(); } catch( OutOfMemoryError ome ) { return( GLU.GLU_OUT_OF_MEMORY ); @@ -117,7 +117,7 @@ public class BuildMipmap { if( otherImage == null ) { memReq = Mipmap.image_size( newwidth, 1, format, GL2.GL_UNSIGNED_SHORT ); try { - otherImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )).asShortBuffer(); + otherImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )).asShortBuffer(); } catch( OutOfMemoryError ome ) { gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); @@ -178,7 +178,7 @@ public class BuildMipmap { } try { - newImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.image_size( width, height, + newImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.image_size( width, height, format, GL2.GL_UNSIGNED_SHORT ) )).asShortBuffer(); } catch( OutOfMemoryError ome ) { return( GLU.GLU_OUT_OF_MEMORY ); @@ -206,7 +206,7 @@ public class BuildMipmap { if( otherImage == null ) { memReq = Mipmap.image_size( newwidth[0], newheight[0], format, GL2.GL_UNSIGNED_SHORT ); try { - otherImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )).asShortBuffer(); + otherImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )).asShortBuffer(); } catch( OutOfMemoryError ome ) { gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); @@ -364,7 +364,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); + dstImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -481,7 +481,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); + dstImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -519,7 +519,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); + dstImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -653,7 +653,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); + dstImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -880,7 +880,7 @@ public class BuildMipmap { int i, j; try { - newImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.image_size( + newImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.image_size( width, height, format, GL2.GL_UNSIGNED_BYTE ) )); } catch( OutOfMemoryError err ) { return( GLU.GLU_OUT_OF_MEMORY ); @@ -924,7 +924,7 @@ public class BuildMipmap { if( otherImage == null ) { memReq = Mipmap.image_size( newwidth[0], newheight[0], format, GL2.GL_UNSIGNED_BYTE ); try { - otherImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); + otherImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); } catch( OutOfMemoryError err ) { gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); @@ -1102,7 +1102,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); + dstImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -1288,7 +1288,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); + dstImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -1329,7 +1329,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); + dstImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -1391,7 +1391,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); + dstImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); diff --git a/src/jogl/classes/com/sun/opengl/impl/glu/mipmap/Mipmap.java b/src/jogl/classes/com/sun/opengl/impl/glu/mipmap/Mipmap.java index b048bf1f5..aa33550ca 100644 --- a/src/jogl/classes/com/sun/opengl/impl/glu/mipmap/Mipmap.java +++ b/src/jogl/classes/com/sun/opengl/impl/glu/mipmap/Mipmap.java @@ -47,9 +47,9 @@ package com.sun.opengl.impl.glu.mipmap; import javax.media.opengl.GL; import javax.media.opengl.GL2; import javax.media.opengl.glu.GLU; -import javax.media.opengl.util.BufferUtil; import javax.media.opengl.GLException; import java.nio.*; +import com.sun.opengl.impl.InternalBufferUtil; /** * @@ -574,8 +574,8 @@ public class Mipmap { if( !isLegalFormatForPackedPixelType( format, typeout ) ) { return( GLU.GLU_INVALID_OPERATION ); } - beforeimage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( image_size( widthin, heightin, format, GL2.GL_UNSIGNED_SHORT ) )); - afterimage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( image_size( widthout, heightout, format, GL2.GL_UNSIGNED_SHORT ) )); + beforeimage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( image_size( widthin, heightin, format, GL2.GL_UNSIGNED_SHORT ) )); + afterimage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( image_size( widthout, heightout, format, GL2.GL_UNSIGNED_SHORT ) )); if( beforeimage == null || afterimage == null ) { return( GLU.GLU_OUT_OF_MEMORY ); } diff --git a/src/jogl/classes/com/sun/opengl/impl/glu/mipmap/ScaleInternal.java b/src/jogl/classes/com/sun/opengl/impl/glu/mipmap/ScaleInternal.java index 70ddab880..f51c72ea6 100644 --- a/src/jogl/classes/com/sun/opengl/impl/glu/mipmap/ScaleInternal.java +++ b/src/jogl/classes/com/sun/opengl/impl/glu/mipmap/ScaleInternal.java @@ -47,8 +47,8 @@ package com.sun.opengl.impl.glu.mipmap; import javax.media.opengl.GL; import javax.media.opengl.GL2; import javax.media.opengl.glu.GLU; -import javax.media.opengl.util.BufferUtil; import java.nio.*; +import com.sun.opengl.impl.InternalBufferUtil; /** * @@ -2425,9 +2425,9 @@ public class ScaleInternal { } try { - beforeImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.imageSize3D( widthIn, + beforeImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.imageSize3D( widthIn, heightIn, depthIn, format, GL2.GL_UNSIGNED_SHORT ) )).asShortBuffer(); - afterImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.imageSize3D( widthIn, + afterImage = InternalBufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.imageSize3D( widthIn, heightIn, depthIn, format, GL2.GL_UNSIGNED_SHORT ) )).asShortBuffer(); } catch( OutOfMemoryError err ) { return( GLU.GLU_OUT_OF_MEMORY ); diff --git a/src/jogl/classes/com/sun/opengl/impl/io/Locator.java b/src/jogl/classes/com/sun/opengl/impl/io/Locator.java deleted file mode 100644 index 863829960..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/io/Locator.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.sun.opengl.impl.io; - -import javax.media.opengl.util.*; - -import java.util.*; -import java.nio.*; -import java.io.*; -import java.net.*; - -/** Utilities for dealing with streams. */ - -public class Locator { - private Locator() {} - - /** - * Locates the resource using 'getResource(String path, ClassLoader cl)', - * with this context ClassLoader and the path as is, - * as well with the context's package name path plus the path. - * - * @see #getResource(String, ClassLoader) - */ - public static URL getResource(Class context, String path) { - ClassLoader contextCL = (null!=context)?context.getClassLoader():null; - URL url = getResource(path, contextCL); - if (url == null && null!=context) { - // Try again by scoping the path within the class's package - String className = context.getName().replace('.', '/'); - int lastSlash = className.lastIndexOf('/'); - if (lastSlash >= 0) { - String tmpPath = className.substring(0, lastSlash + 1) + path; - url = getResource(tmpPath, contextCL); - } - } - return url; - } - - /** - * Locates the resource using the ClassLoader's facility, - * the absolute URL and absolute file. - * - * @see ClassLoader#getResource(String) - * @see ClassLoader#getSystemResource(String) - * @see URL#URL(String) - * @see File#File(String) - */ - public static URL getResource(String path, ClassLoader cl) { - URL url = null; - if (cl != null) { - url = cl.getResource(path); - } else { - url = ClassLoader.getSystemResource(path); - } - if(!urlExists(url)) { - url = null; - try { - url = new URL(path); - } catch (MalformedURLException e) { } - } - if(!urlExists(url)) { - url = null; - try { - File file = new File(path); - if(file.exists()) { - url = file.toURL(); - } - } catch (MalformedURLException e) {} - } - return url; - } - - /** - * Generates a path for the 'relativeFile' relative to the 'absoluteFileLocation' - */ - public static String getRelativeOf(String absoluteFileLocation, String relativeFile) { - File file = new File(absoluteFileLocation); - file = file.getParentFile(); - while (file != null && relativeFile.startsWith("../")) { - file = file.getParentFile(); - relativeFile = relativeFile.substring(3); - } - if (file != null) { - String res = new File(file, relativeFile).getPath(); - // Handle things on Windows - return res.replace('\\', '/'); - } else { - return relativeFile; - } - } - - /** - * Returns true, if the url exists, - * trying to open a connection. - */ - public static boolean urlExists(URL url) { - boolean v = false; - if(null!=url) { - try { - URLConnection uc = url.openConnection(); - v = true; - } catch (IOException ioe) { } - } - return v; - } - -} - diff --git a/src/jogl/classes/com/sun/opengl/impl/packrect/BackingStoreManager.java b/src/jogl/classes/com/sun/opengl/impl/packrect/BackingStoreManager.java deleted file mode 100755 index 2ca5a5a7b..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/packrect/BackingStoreManager.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2006 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 com.sun.opengl.impl.packrect; - -/** This interface must be implemented by the end user and is called - in response to events like addition of rectangles into the - RectanglePacker. It is used both when a full re-layout must be - done as well as when the data in the backing store must be copied - to a new one. */ - -public interface BackingStoreManager { - public Object allocateBackingStore(int w, int h); - public void deleteBackingStore(Object backingStore); - - /** Indication whether this BackingStoreManager supports compaction; - in other words, the allocation of a new backing store and - movement of the contents of the backing store from the old to - the new one. If it does not, then RectanglePacker.add() may - throw an exception if additionFailed() can not make enough room - available. If an implementation returns false, this also implies - that the backing store can not grow, so that preExpand() will - never be called. */ - public boolean canCompact(); - - /** Notification that expansion of the backing store is about to be - done due to addition of the given rectangle. Gives the manager a - chance to do some compaction and potentially remove old entries - from the backing store, if it acts like a least-recently-used - cache. This method receives as argument the number of attempts - so far to add the given rectangle. Manager should return true if - the RectanglePacker should retry the addition (which may result - in this method being called again, with an increased attempt - number) or false if the RectanglePacker should just expand the - backing store. The caller should not call RectanglePacker.add() - in its preExpand() method. */ - public boolean preExpand(Rect cause, int attemptNumber); - - /** Notification that addition of the given Rect failed because a - maximum size was set in the RectanglePacker and the backing - store could not be expanded, or because compaction (and, - therefore, implicitly expansion) was not supported. Should - return false if the manager can do nothing more to handle the - failed addition, which will cause a RuntimeException to be - thrown from the RectanglePacker. */ - public boolean additionFailed(Rect cause, int attemptNumber); - - /** Notification that movement is starting. */ - public void beginMovement(Object oldBackingStore, Object newBackingStore); - - /** Tells the manager to move the contents of the given rect from - the old location on the old backing store to the new location on - the new backing store. The backing stores can be identical in - the case of compacting the existing backing store instead of - reallocating it. */ - public void move(Object oldBackingStore, - Rect oldLocation, - Object newBackingStore, - Rect newLocation); - - /** Notification that movement is ending. */ - public void endMovement(Object oldBackingStore, Object newBackingStore); -} diff --git a/src/jogl/classes/com/sun/opengl/impl/packrect/Level.java b/src/jogl/classes/com/sun/opengl/impl/packrect/Level.java deleted file mode 100755 index 12a09cd9a..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/packrect/Level.java +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright (c) 2006 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 com.sun.opengl.impl.packrect; - -import java.util.*; - -public class Level { - private int width; - private int height; - private int yPos; - private LevelSet holder; - - private List/**/ rects = new ArrayList/**/(); - private List/**/ freeList; - private int nextAddX; - - static class RectXComparator implements Comparator { - public int compare(Object o1, Object o2) { - Rect r1 = (Rect) o1; - Rect r2 = (Rect) o2; - return r1.x() - r2.x(); - } - - public boolean equals(Object obj) { - return this == obj; - } - } - private static final Comparator rectXComparator = new RectXComparator(); - - public Level(int width, int height, int yPos, LevelSet holder) { - this.width = width; - this.height = height; - this.yPos = yPos; - this.holder = holder; - } - - public int w() { return width; } - public int h() { return height; } - public int yPos() { return yPos; } - - /** Tries to add the given rectangle to this level only allowing - non-disruptive changes like trivial expansion of the last level - in the RectanglePacker and allocation from the free list. More - disruptive changes like compaction of the level must be - requested explicitly. */ - public boolean add(Rect rect) { - if (rect.h() > height) { - // See whether it's worth trying to expand vertically - if (nextAddX + rect.w() > width) { - return false; - } - - // See whether we're the last level and can expand - if (!holder.canExpand(this, rect.h())) { - return false; - } - - // Trivially expand and try the allocation - holder.expand(this, height, rect.h()); - height = rect.h(); - } - - // See whether we can add at the end - if (nextAddX + rect.w() <= width) { - rect.setPosition(nextAddX, yPos); - rects.add(rect); - nextAddX += rect.w(); - return true; - } - - // See whether we can add from the free list - if (freeList != null) { - Rect candidate = null; - for (Iterator iter = freeList.iterator(); iter.hasNext(); ) { - Rect cur = (Rect) iter.next(); - if (cur.canContain(rect)) { - candidate = cur; - break; - } - } - - if (candidate != null) { - // Remove the candidate from the free list - freeList.remove(candidate); - // Set up and add the real rect - rect.setPosition(candidate.x(), candidate.y()); - rects.add(rect); - // Re-add any remaining free space - if (candidate.w() > rect.w()) { - candidate.setPosition(candidate.x() + rect.w(), candidate.y()); - candidate.setSize(candidate.w() - rect.w(), height); - freeList.add(candidate); - } - - coalesceFreeList(); - - return true; - } - } - - return false; - } - - /** Removes the given Rect from this Level. */ - public boolean remove(Rect rect) { - if (!rects.remove(rect)) - return false; - - // If this is the rightmost rectangle, instead of adding its space - // to the free list, we can just decrease the nextAddX - if (rect.maxX() + 1 == nextAddX) { - nextAddX -= rect.w(); - } else { - if (freeList == null) { - freeList = new ArrayList/**/(); - } - freeList.add(new Rect(rect.x(), rect.y(), rect.w(), height, null)); - coalesceFreeList(); - } - - return true; - } - - /** Indicates whether this Level contains no rectangles. */ - public boolean isEmpty() { - return rects.isEmpty(); - } - - /** Indicates whether this Level could satisfy an allocation request - if it were compacted. */ - public boolean couldAllocateIfCompacted(Rect rect) { - if (rect.h() > height) - return false; - if (freeList == null) - return false; - int freeListWidth = 0; - for (Iterator iter = freeList.iterator(); iter.hasNext(); ) { - Rect cur = (Rect) iter.next(); - freeListWidth += cur.w(); - } - // Add on the remaining space at the end - freeListWidth += (width - nextAddX); - return (freeListWidth >= rect.w()); - } - - public void compact(Object backingStore, BackingStoreManager manager) { - Collections.sort(rects, rectXComparator); - int nextCompactionDest = 0; - manager.beginMovement(backingStore, backingStore); - for (Iterator iter = rects.iterator(); iter.hasNext(); ) { - Rect cur = (Rect) iter.next(); - if (cur.x() != nextCompactionDest) { - manager.move(backingStore, cur, - backingStore, new Rect(nextCompactionDest, cur.y(), cur.w(), cur.h(), null)); - cur.setPosition(nextCompactionDest, cur.y()); - } - nextCompactionDest += cur.w(); - } - nextAddX = nextCompactionDest; - freeList.clear(); - manager.endMovement(backingStore, backingStore); - } - - public Iterator iterator() { - return rects.iterator(); - } - - /** Visits all Rects contained in this Level. */ - public void visit(RectVisitor visitor) { - for (Iterator iter = rects.iterator(); iter.hasNext(); ) { - Rect rect = (Rect) iter.next(); - visitor.visit(rect); - } - } - - /** Updates the references to the Rect objects in this Level with - the "next locations" of those Rects. This is actually used to - update the new Rects in a newly laid-out LevelSet with the - original Rects. */ - public void updateRectangleReferences() { - for (int i = 0; i < rects.size(); i++) { - Rect cur = (Rect) rects.get(i); - Rect next = cur.getNextLocation(); - next.setPosition(cur.x(), cur.y()); - if (cur.w() != next.w() || cur.h() != next.h()) - throw new RuntimeException("Unexpected disparity in rectangle sizes during updateRectangleReferences"); - rects.set(i, next); - } - } - - private void coalesceFreeList() { - if (freeList == null) - return; - if (freeList.isEmpty()) - return; - - // Try to coalesce adjacent free blocks in the free list - Collections.sort(freeList, rectXComparator); - int i = 0; - while (i < freeList.size() - 1) { - Rect r1 = (Rect) freeList.get(i); - Rect r2 = (Rect) freeList.get(i+1); - if (r1.maxX() + 1 == r2.x()) { - // Coalesce r1 and r2 into one block - freeList.remove(i+1); - r1.setSize(r1.w() + r2.w(), r1.h()); - } else { - ++i; - } - } - // See whether the last block bumps up against the addition point - Rect last = (Rect) freeList.get(freeList.size() - 1); - if (last.maxX() + 1 == nextAddX) { - nextAddX -= last.w(); - freeList.remove(freeList.size() - 1); - } - if (freeList.isEmpty()) { - freeList = null; - } - } - - //---------------------------------------------------------------------- - // Debugging functionality - // - - public void dumpFreeSpace() { - int freeListWidth = 0; - for (Iterator iter = freeList.iterator(); iter.hasNext(); ) { - Rect cur = (Rect) iter.next(); - System.err.println(" Free rectangle at " + cur); - freeListWidth += cur.w(); - } - // Add on the remaining space at the end - System.err.println(" Remaining free space " + (width - nextAddX)); - freeListWidth += (width - nextAddX); - System.err.println(" Total free space " + freeListWidth); - } -} diff --git a/src/jogl/classes/com/sun/opengl/impl/packrect/LevelSet.java b/src/jogl/classes/com/sun/opengl/impl/packrect/LevelSet.java deleted file mode 100755 index 97a1f2e74..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/packrect/LevelSet.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (c) 2006 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 com.sun.opengl.impl.packrect; - -import java.util.*; - -/** Manages a list of Levels; this is the core data structure - contained within the RectanglePacker and encompasses the storage - algorithm for the contained Rects. */ - -public class LevelSet { - // Maintained in sorted order by increasing Y coordinate - private List/**/ levels = new ArrayList/**/(); - private int nextAddY; - private int w; - private int h; - - /** A LevelSet manages all of the backing store for a region of a - specified width and height. */ - public LevelSet(int w, int h) { - this.w = w; - this.h = h; - } - - public int w() { return w; } - public int h() { return h; } - - /** Returns true if the given rectangle was successfully added to - the LevelSet given its current dimensions, false if not. Caller - is responsible for performing compaction, expansion, etc. as a - consequence. */ - public boolean add(Rect rect) { - if (rect.w() > w) - return false; - - // Go in reverse order through the levels seeing whether we can - // trivially satisfy the allocation request - for (int i = levels.size() - 1; i >= 0; --i) { - Level level = (Level) levels.get(i); - if (level.add(rect)) - return true; - } - - // See whether compaction could satisfy this allocation. This - // increases the computational complexity of the addition process, - // but prevents us from expanding unnecessarily. - for (int i = levels.size() - 1; i >= 0; --i) { - Level level = (Level) levels.get(i); - if (level.couldAllocateIfCompacted(rect)) - return false; - } - - // OK, we need to either add a new Level or expand the backing - // store. Try to add a new Level. - if (nextAddY + rect.h() > h) - return false; - - Level newLevel = new Level(w, rect.h(), nextAddY, this); - levels.add(newLevel); - nextAddY += rect.h(); - boolean res = newLevel.add(rect); - if (!res) - throw new RuntimeException("Unexpected failure in addition to new Level"); - return true; - } - - /** Removes the given Rect from this LevelSet. */ - public boolean remove(Rect rect) { - for (int i = levels.size() - 1; i >= 0; --i) { - Level level = (Level) levels.get(i); - if (level.remove(rect)) - return true; - } - - return false; - } - - /** Allocates the given Rectangle, performing compaction of a Level - if necessary. This is the correct fallback path to {@link - #add(Rect)} above. Returns true if allocated successfully, false - otherwise (indicating the need to expand the backing store). */ - public boolean compactAndAdd(Rect rect, - Object backingStore, - BackingStoreManager manager) { - for (int i = levels.size() - 1; i >= 0; --i) { - Level level = (Level) levels.get(i); - if (level.couldAllocateIfCompacted(rect)) { - level.compact(backingStore, manager); - boolean res = level.add(rect); - if (!res) - throw new RuntimeException("Unexpected failure to add after compaction"); - return true; - } - } - - return false; - } - - /** Indicates whether it's legal to trivially increase the height of - the given Level. This is only possible if it's the last Level - added and there's enough room in the backing store. */ - public boolean canExpand(Level level, int height) { - if (levels.isEmpty()) - return false; // Should not happen - if (levels.get(levels.size() - 1) == level && - (h - nextAddY >= height - level.h())) - return true; - return false; - } - - public void expand(Level level, int oldHeight, int newHeight) { - nextAddY += (newHeight - oldHeight); - } - - /** Gets the used height of the levels in this LevelSet. */ - public int getUsedHeight() { - return nextAddY; - } - - /** Sets the height of this LevelSet. It is only legal to reduce the - height to greater than or equal to the currently used height. */ - public void setHeight(int height) throws IllegalArgumentException { - if (height < getUsedHeight()) { - throw new IllegalArgumentException("May not reduce height below currently used height"); - } - h = height; - } - - /** Returns the vertical fragmentation ratio of this LevelSet. This - is defined as the ratio of the sum of the heights of all - completely empty Levels divided by the overall used height of - the LevelSet. A high vertical fragmentation ratio indicates that - it may be profitable to perform a compaction. */ - public float verticalFragmentationRatio() { - int freeHeight = 0; - int usedHeight = getUsedHeight(); - if (usedHeight == 0) - return 0.0f; - for (Iterator iter = iterator(); iter.hasNext(); ) { - Level level = (Level) iter.next(); - if (level.isEmpty()) { - freeHeight += level.h(); - } - } - return (float) freeHeight / (float) usedHeight; - } - - public Iterator iterator() { - return levels.iterator(); - } - - /** Visits all Rects contained in this LevelSet. */ - public void visit(RectVisitor visitor) { - for (Iterator iter = levels.iterator(); iter.hasNext(); ) { - Level level = (Level) iter.next(); - level.visit(visitor); - } - } - - /** Updates the references to the Rect objects in this LevelSet with - the "next locations" of those Rects. This is actually used to - update the new Rects in a newly laid-out LevelSet with the - original Rects. */ - public void updateRectangleReferences() { - for (Iterator iter = levels.iterator(); iter.hasNext(); ) { - Level level = (Level) iter.next(); - level.updateRectangleReferences(); - } - } - - /** Clears out all Levels stored in this LevelSet. */ - public void clear() { - levels.clear(); - nextAddY = 0; - } -} diff --git a/src/jogl/classes/com/sun/opengl/impl/packrect/Rect.java b/src/jogl/classes/com/sun/opengl/impl/packrect/Rect.java deleted file mode 100755 index f47660e94..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/packrect/Rect.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2006 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 com.sun.opengl.impl.packrect; - -/** Represents a rectangular region on the backing store. The edges of - the rectangle are the infinitely thin region between adjacent - pixels on the screen. The origin of the rectangle is its - upper-left corner. It is inclusive of the pixels on the top and - left edges and exclusive of the pixels on the bottom and right - edges. For example, a rect at position (0, 0) and of size (1, 1) - would include only the pixel at (0, 0).

- - Negative coordinates and sizes are not supported, since they make - no sense in the context of the packer, which deals only with - positively sized regions.

- - This class contains a user data field for efficient hookup to - external data structures as well as enough other hooks to - efficiently plug into the rectangle packer. */ - -public class Rect { - private int x; - private int y; - private int w; - private int h; - - // The level we're currently installed in in the parent - // RectanglePacker, or null if not hooked in to the table yet - private Level level; - - // The user's object this rectangle represents. - private Object userData; - - // Used transiently during re-layout of the backing store (when - // there is no room left due either to fragmentation or just being - // out of space) - private Rect nextLocation; - - public Rect() { - this(null); - } - - public Rect(Object userData) { - this(0, 0, 0, 0, userData); - } - - public Rect(int x, int y, int w, int h, Object userData) { - setPosition(x, y); - setSize(w, h); - setUserData(userData); - } - - public int x() { return x; } - public int y() { return y; } - public int w() { return w; } - public int h() { return h; } - public Object getUserData() { return userData; } - public Rect getNextLocation() { return nextLocation; } - - public void setPosition(int x, int y) { - if (x < 0) - throw new IllegalArgumentException("Negative x"); - if (y < 0) - throw new IllegalArgumentException("Negative y"); - this.x = x; - this.y = y; - } - - public void setSize(int w, int h) throws IllegalArgumentException { - if (w < 0) - throw new IllegalArgumentException("Negative width"); - if (h < 0) - throw new IllegalArgumentException("Negative height"); - this.w = w; - this.h = h; - } - - public void setUserData(Object obj) { userData = obj; } - public void setNextLocation(Rect nextLocation) { this.nextLocation = nextLocation; } - - // Helpers for computations. - - /** Returns the maximum x-coordinate contained within this - rectangle. Note that this returns a different result than Java - 2D's rectangles; for a rectangle of position (0, 0) and size (1, - 1) this will return 0, not 1. Returns -1 if the width of this - rectangle is 0. */ - public int maxX() { - if (w() < 1) - return -1; - return x() + w() - 1; - } - - /** Returns the maximum y-coordinate contained within this - rectangle. Note that this returns a different result than Java - 2D's rectangles; for a rectangle of position (0, 0) and size (1, - 1) this will return 0, not 1. Returns -1 if the height of this - rectangle is 0. */ - public int maxY() { - if (h() < 1) - return -1; - return y() + h() - 1; - } - - public boolean canContain(Rect other) { - return (w() >= other.w() && - h() >= other.h()); - } - - public String toString() { - return "[Rect x: " + x() + " y: " + y() + " w: " + w() + " h: " + h() + "]"; - } - - // Unclear whether it's a good idea to override hashCode and equals - // for these objects - /* - public boolean equals(Object other) { - if (other == null || (!(other instanceof Rect))) { - return false; - } - - Rect r = (Rect) other; - return (this.x() == r.x() && - this.y() == r.y() && - this.w() == r.w() && - this.h() == r.h()); - } - - public int hashCode() { - return (x + y * 13 + w * 17 + h * 23); - } - */ -} diff --git a/src/jogl/classes/com/sun/opengl/impl/packrect/RectVisitor.java b/src/jogl/classes/com/sun/opengl/impl/packrect/RectVisitor.java deleted file mode 100755 index 6474f204e..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/packrect/RectVisitor.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2006 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 com.sun.opengl.impl.packrect; - -/** Iteration construct without exposing the internals of the - RectanglePacker and without implementing a complex Iterator. */ - -public interface RectVisitor { - public void visit(Rect rect); -} diff --git a/src/jogl/classes/com/sun/opengl/impl/packrect/RectanglePacker.java b/src/jogl/classes/com/sun/opengl/impl/packrect/RectanglePacker.java deleted file mode 100755 index 8520484cf..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/packrect/RectanglePacker.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Copyright (c) 2006 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 com.sun.opengl.impl.packrect; - -import java.util.*; - -/** Packs rectangles supplied by the user (typically representing - image regions) into a larger backing store rectangle (typically - representing a large texture). Supports automatic compaction of - the space on the backing store, and automatic expansion of the - backing store, when necessary. */ - -public class RectanglePacker { - private BackingStoreManager manager; - private Object backingStore; - private LevelSet levels; - private float EXPANSION_FACTOR = 0.5f; - private float SHRINK_FACTOR = 0.3f; - - private int initialWidth; - private int initialHeight; - - private int maxWidth = -1; - private int maxHeight = -1; - - static class RectHComparator implements Comparator { - public int compare(Object o1, Object o2) { - Rect r1 = (Rect) o1; - Rect r2 = (Rect) o2; - return r2.h() - r1.h(); - } - - public boolean equals(Object obj) { - return this == obj; - } - } - private static final Comparator rectHComparator = new RectHComparator(); - - public RectanglePacker(BackingStoreManager manager, - int initialWidth, - int initialHeight) { - this.manager = manager; - levels = new LevelSet(initialWidth, initialHeight); - this.initialWidth = initialWidth; - this.initialHeight = initialHeight; - } - - public Object getBackingStore() { - if (backingStore == null) { - backingStore = manager.allocateBackingStore(levels.w(), levels.h()); - } - - return backingStore; - } - - /** Sets up a maximum width and height for the backing store. These - are optional and if not specified the backing store will grow as - necessary. Setting up a maximum width and height introduces the - possibility that additions will fail; these are handled with the - BackingStoreManager's allocationFailed notification. */ - public void setMaxSize(int maxWidth, int maxHeight) { - this.maxWidth = maxWidth; - this.maxHeight = maxHeight; - } - - /** Decides upon an (x, y) position for the given rectangle (leaving - its width and height unchanged) and places it on the backing - store. May provoke re-layout of other Rects already added. If - the BackingStoreManager does not support compaction, and {@link - BackingStoreManager#preExpand BackingStoreManager.preExpand} - does not clear enough space for the incoming rectangle, then - this method will throw a RuntimeException. */ - public void add(Rect rect) throws RuntimeException { - // Allocate backing store if we don't have any yet - if (backingStore == null) - backingStore = manager.allocateBackingStore(levels.w(), levels.h()); - - int attemptNumber = 0; - boolean tryAgain = false; - - do { - // Try to allocate - if (levels.add(rect)) - return; - - if (manager.canCompact()) { - // Try to allocate with horizontal compaction - if (levels.compactAndAdd(rect, backingStore, manager)) - return; - // Let the manager have a chance at potentially evicting some entries - tryAgain = manager.preExpand(rect, attemptNumber++); - } else { - tryAgain = manager.additionFailed(rect, attemptNumber++); - } - } while (tryAgain); - - if (!manager.canCompact()) { - throw new RuntimeException("BackingStoreManager does not support compaction or expansion, and didn't clear space for new rectangle"); - } - - compactImpl(rect); - - // Retry the addition of the incoming rectangle - add(rect); - // Done - } - - /** Removes the given rectangle from this RectanglePacker. */ - public void remove(Rect rect) { - levels.remove(rect); - } - - /** Visits all Rects contained in this RectanglePacker. */ - public void visit(RectVisitor visitor) { - levels.visit(visitor); - } - - /** Returns the vertical fragmentation ratio of this - RectanglePacker. This is defined as the ratio of the sum of the - heights of all completely empty Levels divided by the overall - used height of the LevelSet. A high vertical fragmentation ratio - indicates that it may be profitable to perform a compaction. */ - public float verticalFragmentationRatio() { - return levels.verticalFragmentationRatio(); - } - - /** Forces a compaction cycle, which typically results in allocating - a new backing store and copying all entries to it. */ - public void compact() { - compactImpl(null); - } - - // The "cause" rect may be null - private void compactImpl(Rect cause) { - // Have to either expand, compact or both. Need to figure out what - // direction to go. Prefer to expand vertically. Expand - // horizontally only if rectangle being added is too wide. FIXME: - // may want to consider rebalancing the width and height to be - // more equal if it turns out we keep expanding in the vertical - // direction. - boolean done = false; - int newWidth = levels.w(); - int newHeight = levels.h(); - LevelSet nextLevelSet = null; - int attemptNumber = 0; - boolean needAdditionFailureNotification = false; - - while (!done) { - if (cause != null) { - if (cause.w() > newWidth) { - newWidth = cause.w(); - } else { - newHeight = (int) (newHeight * (1.0f + EXPANSION_FACTOR)); - } - } - - // Clamp to maximum values - needAdditionFailureNotification = false; - if (maxWidth > 0 && newWidth > maxWidth) { - newWidth = maxWidth; - needAdditionFailureNotification = true; - } - if (maxHeight > 0 && newHeight > maxHeight) { - newHeight = maxHeight; - needAdditionFailureNotification = true; - } - - nextLevelSet = new LevelSet(newWidth, newHeight); - - // Make copies of all existing rectangles - List/**/ newRects = new ArrayList/**/(); - for (Iterator i1 = levels.iterator(); i1.hasNext(); ) { - Level level = (Level) i1.next(); - for (Iterator i2 = level.iterator(); i2.hasNext(); ) { - Rect cur = (Rect) i2.next(); - Rect newRect = new Rect(0, 0, cur.w(), cur.h(), null); - cur.setNextLocation(newRect); - // Hook up the reverse mapping too for easier replacement - newRect.setNextLocation(cur); - newRects.add(newRect); - } - } - // Sort them by decreasing height (note: this isn't really - // guaranteed to improve the chances of a successful layout) - Collections.sort(newRects, rectHComparator); - // Try putting all of these rectangles into the new level set - done = true; - for (Iterator iter = newRects.iterator(); iter.hasNext(); ) { - if (!nextLevelSet.add((Rect) iter.next())) { - done = false; - break; - } - } - - if (done && cause != null) { - // Try to add the new rectangle as well - if (nextLevelSet.add(cause)) { - // We're OK - } else { - done = false; - } - } - - // Don't send addition failure notifications if we're only doing - // a compaction - if (!done && needAdditionFailureNotification && cause != null) { - manager.additionFailed(cause, attemptNumber); - } - ++attemptNumber; - } - - // See whether the implicit compaction that just occurred has - // yielded excess empty space. - if (nextLevelSet.getUsedHeight() > 0 && - nextLevelSet.getUsedHeight() < nextLevelSet.h() * SHRINK_FACTOR) { - int shrunkHeight = Math.max(initialHeight, - (int) (nextLevelSet.getUsedHeight() * (1.0f + EXPANSION_FACTOR))); - if (maxHeight > 0 && shrunkHeight > maxHeight) { - shrunkHeight = maxHeight; - } - nextLevelSet.setHeight(shrunkHeight); - } - - // If we temporarily added the new rectangle to the new LevelSet, - // take it out since we don't "really" add it here but in add(), above - if (cause != null) { - nextLevelSet.remove(cause); - } - - // OK, now we have a new layout and a mapping from the old to the - // new locations of rectangles on the backing store. Allocate a - // new backing store, move the contents over and deallocate the - // old one. - Object newBackingStore = manager.allocateBackingStore(nextLevelSet.w(), - nextLevelSet.h()); - manager.beginMovement(backingStore, newBackingStore); - for (Iterator i1 = levels.iterator(); i1.hasNext(); ) { - Level level = (Level) i1.next(); - for (Iterator i2 = level.iterator(); i2.hasNext(); ) { - Rect cur = (Rect) i2.next(); - manager.move(backingStore, cur, - newBackingStore, cur.getNextLocation()); - } - } - // Replace references to temporary rectangles with original ones - nextLevelSet.updateRectangleReferences(); - manager.endMovement(backingStore, newBackingStore); - // Now delete the old backing store - manager.deleteBackingStore(backingStore); - // Update to new versions of backing store and LevelSet - backingStore = newBackingStore; - levels = nextLevelSet; - } - - /** Clears all Rects contained in this RectanglePacker. */ - public void clear() { - levels.clear(); - } - - /** Disposes the backing store allocated by the - BackingStoreManager. This RectanglePacker may no longer be used - after calling this method. */ - public void dispose() { - if (backingStore != null) - manager.deleteBackingStore(backingStore); - backingStore = null; - levels = null; - } -} diff --git a/src/jogl/classes/com/sun/opengl/impl/packrect/package.html b/src/jogl/classes/com/sun/opengl/impl/packrect/package.html deleted file mode 100755 index 7f2522244..000000000 --- a/src/jogl/classes/com/sun/opengl/impl/packrect/package.html +++ /dev/null @@ -1,7 +0,0 @@ -This package implements a rectangle packing algorithm suitable for -tracking the placement of multiple rectangles inside a larger one. It -is useful for cases such as placing the contents of multiple windows -on a larger backing store texture for a compositing window manager; -placing multiple rasterized strings in a texture map for quick -rendering to the screen; and many other situations where it is useful -to carve up a larger texture into smaller pieces dynamically.

diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index 10d7c5a22..3380de742 100644 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -44,7 +44,6 @@ import java.util.*; import javax.media.nativewindow.*; import javax.media.opengl.*; import com.sun.opengl.impl.*; -import javax.media.opengl.util.BufferUtil; public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { private static final boolean DEBUG = Debug.debug("WindowsWGLDrawableFactory"); diff --git a/src/jogl/classes/com/sun/opengl/util/BufferUtil.java.javame_cdc_fp b/src/jogl/classes/com/sun/opengl/util/BufferUtil.java.javame_cdc_fp new file mode 100755 index 000000000..40f035514 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/BufferUtil.java.javame_cdc_fp @@ -0,0 +1,449 @@ +/* + * 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 com.sun.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 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 remaining elements (as defined by + limit() - position()) 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 remaining elements (as defined by + limit() - position()) 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 remaining elements (as defined by + limit() - position()) 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 remaining elements (as defined by + limit() - position()) 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 remaining elements (as defined by + limit() - position()) 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 remaining elements (as defined by + limit() - position()) 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 remaining elements (as defined by + limit() - position()) 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) { + if((dest instanceof ByteBuffer) && (v instanceof ByteBuffer)) { + ((ByteBuffer)dest).put((ByteBuffer)v); + } else if((dest instanceof ShortBuffer) && (v instanceof ShortBuffer)) { + ((ShortBuffer)dest).put((ShortBuffer)v); + } else if((dest instanceof IntBuffer) && (v instanceof IntBuffer)) { + ((IntBuffer)dest).put((IntBuffer)v); + } else if((dest instanceof FloatBuffer) && (v instanceof FloatBuffer)) { + ((FloatBuffer)dest).put((FloatBuffer)v); + } else { + throw new GLException("Incompatible Buffer classes: dest = "+dest.getClass().getName() + ", src = " + v.getClass().getName()); + } + } + + 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/com/sun/opengl/util/BufferUtil.java.javase b/src/jogl/classes/com/sun/opengl/util/BufferUtil.java.javase new file mode 100755 index 000000000..d02f3d15f --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/BufferUtil.java.javase @@ -0,0 +1,499 @@ +/* + * 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 com.sun.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 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 remaining elements (as defined by + limit() - position()) 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 remaining elements (as defined by + limit() - position()) 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 remaining elements (as defined by + limit() - position()) 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 remaining elements (as defined by + limit() - position()) 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 remaining elements (as defined by + limit() - position()) 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 remaining elements (as defined by + limit() - position()) 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 remaining elements (as defined by + limit() - position()) 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) { + if((dest instanceof ByteBuffer) && (v instanceof ByteBuffer)) { + ((ByteBuffer)dest).put((ByteBuffer)v); + } else if((dest instanceof ShortBuffer) && (v instanceof ShortBuffer)) { + ((ShortBuffer)dest).put((ShortBuffer)v); + } else if((dest instanceof IntBuffer) && (v instanceof IntBuffer)) { + ((IntBuffer)dest).put((IntBuffer)v); + } else if((dest instanceof FloatBuffer) && (v instanceof FloatBuffer)) { + ((FloatBuffer)dest).put((FloatBuffer)v); + } else { + throw new GLException("Incompatible Buffer classes: dest = "+dest.getClass().getName() + ", src = " + v.getClass().getName()); + } + } + + 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/com/sun/opengl/util/FixedPoint.java b/src/jogl/classes/com/sun/opengl/util/FixedPoint.java new file mode 100644 index 000000000..e9bdae0e9 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/FixedPoint.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2009 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. + * + */ + +package com.sun.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/com/sun/opengl/util/GLArrayDataClient.java b/src/jogl/classes/com/sun/opengl/util/GLArrayDataClient.java index efee49a16..3dc8159b9 100644 --- a/src/jogl/classes/com/sun/opengl/util/GLArrayDataClient.java +++ b/src/jogl/classes/com/sun/opengl/util/GLArrayDataClient.java @@ -1,10 +1,14 @@ package com.sun.opengl.util; +import java.security.*; + import javax.media.opengl.*; import javax.media.opengl.util.*; -import com.sun.opengl.impl.*; -import com.sun.opengl.impl.glsl.*; + +import com.sun.opengl.util.glsl.*; + +import com.sun.opengl.impl.SystemUtil; import java.nio.*; @@ -17,7 +21,11 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData * * This should not be necessary on proper native implementations. */ - public static final boolean hasVBOBug = (SystemUtil.getenv("JOGL_VBO_BUG") != null); + public static final boolean hasVBOBug = AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return SystemUtil.getenv("JOGL_VBO_BUG"); + } + }) != null; /** * @arg index The GL array index @@ -34,7 +42,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData int initialSize) throws GLException { - GLProfile.isValidateArrayDataType(index, comps, dataType, false, true); + GLProfile.isValidArrayDataType(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, 0, 0); @@ -45,7 +53,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData int stride, Buffer buffer) throws GLException { - GLProfile.isValidateArrayDataType(index, comps, dataType, false, true); + GLProfile.isValidArrayDataType(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, 0, 0); @@ -59,7 +67,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData if(!GLProfile.isGL2ES2()) { throw new GLException("GLArrayDataServer not supported for profile: "+GLProfile.getProfile()); } - GLProfile.isValidateArrayDataType(-1, comps, dataType, true, true); + GLProfile.isValidArrayDataType(-1, comps, dataType, true, true); GLArrayDataClient adc = new GLArrayDataClient(); GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc); @@ -74,7 +82,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData if(!GLProfile.isGL2ES2()) { throw new GLException("GLArrayDataServer not supported for profile: "+GLProfile.getProfile()); } - GLProfile.isValidateArrayDataType(-1, comps, dataType, true, true); + GLProfile.isValidArrayDataType(-1, comps, dataType, true, true); GLArrayDataClient adc = new GLArrayDataClient(); GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc); diff --git a/src/jogl/classes/com/sun/opengl/util/GLArrayDataServer.java b/src/jogl/classes/com/sun/opengl/util/GLArrayDataServer.java index 59024dec7..caf6efe12 100644 --- a/src/jogl/classes/com/sun/opengl/util/GLArrayDataServer.java +++ b/src/jogl/classes/com/sun/opengl/util/GLArrayDataServer.java @@ -3,8 +3,8 @@ package com.sun.opengl.util; import javax.media.opengl.*; import java.nio.*; -import com.sun.opengl.impl.*; -import com.sun.opengl.impl.glsl.*; + +import com.sun.opengl.util.glsl.*; public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataEditable { @@ -35,7 +35,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE int stride, Buffer buffer, int vboBufferUsage) throws GLException { - GLProfile.isValidateArrayDataType(index, comps, dataType, false, true); + GLProfile.isValidArrayDataType(index, comps, dataType, false, true); GLArrayDataServer ads = new GLArrayDataServer(); GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads); @@ -59,7 +59,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE int initialSize, int vboBufferUsage) throws GLException { - GLProfile.isValidateArrayDataType(index, comps, dataType, false, true); + GLProfile.isValidArrayDataType(index, comps, dataType, false, true); GLArrayDataServer ads = new GLArrayDataServer(); GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads); @@ -81,7 +81,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE if(!GLProfile.isGL2ES2()) { throw new GLException("GLArrayDataServer not supported for profile: "+GLProfile.getProfile()); } - GLProfile.isValidateArrayDataType(-1, comps, dataType, true, true); + GLProfile.isValidArrayDataType(-1, comps, dataType, true, true); GLArrayDataServer ads = new GLArrayDataServer(); GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads); @@ -103,7 +103,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE if(!GLProfile.isGL2ES2()) { throw new GLException("GLArrayDataServer not supported for profile: "+GLProfile.getProfile()); } - GLProfile.isValidateArrayDataType(-1, comps, dataType, true, true); + GLProfile.isValidArrayDataType(-1, comps, dataType, true, true); GLArrayDataServer ads = new GLArrayDataServer(); GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads); diff --git a/src/jogl/classes/com/sun/opengl/util/GLArrayDataWrapper.java b/src/jogl/classes/com/sun/opengl/util/GLArrayDataWrapper.java index 808848b22..cacc285d1 100644 --- a/src/jogl/classes/com/sun/opengl/util/GLArrayDataWrapper.java +++ b/src/jogl/classes/com/sun/opengl/util/GLArrayDataWrapper.java @@ -3,7 +3,8 @@ package com.sun.opengl.util; import javax.media.opengl.*; import javax.media.opengl.util.*; -import com.sun.opengl.impl.*; + +import com.sun.opengl.util.glsl.fixedfunc.impl.*; import java.nio.*; @@ -14,7 +15,7 @@ public class GLArrayDataWrapper implements GLArrayData { int vboName, long bufferOffset) throws GLException { - GLProfile.isValidateArrayDataType(index, comps, dataType, false, true); + GLProfile.isValidArrayDataType(index, comps, dataType, false, true); GLArrayDataWrapper adc = new GLArrayDataWrapper(); adc.init(null, index, comps, dataType, normalized, stride, buffer, false, vboName, bufferOffset); @@ -29,7 +30,7 @@ public class GLArrayDataWrapper implements GLArrayData { if(!GLProfile.isGL2ES2()) { throw new GLException("GLArrayDataServer not supported for profile: "+GLProfile.getProfile()); } - GLProfile.isValidateArrayDataType(-1, comps, dataType, true, true); + GLProfile.isValidArrayDataType(-1, comps, dataType, true, true); GLArrayDataWrapper adc = new GLArrayDataWrapper(); adc.init(name, -1, comps, dataType, normalized, stride, buffer, true, @@ -157,7 +158,8 @@ public class GLArrayDataWrapper implements GLArrayData { this.isVertexAttribute = isVertexAttribute; this.index = index; this.location = -1; - this.name = (null==name)?GLContext.getPredefinedArrayIndexName(index):name; + // We can't have any dependence on the FixedFuncUtil class here for build bootstrapping reasons + this.name = (null==name)?FixedFuncPipeline.getPredefinedArrayIndexName(index):name; if(null==this.name) { throw new GLException("Not a valid GL array index: "+index); } diff --git a/src/jogl/classes/com/sun/opengl/util/GLArrayHandler.java b/src/jogl/classes/com/sun/opengl/util/GLArrayHandler.java new file mode 100644 index 000000000..9443ad6ed --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/GLArrayHandler.java @@ -0,0 +1,11 @@ + +package com.sun.opengl.util; + +import javax.media.opengl.*; + +public interface GLArrayHandler { + + public void enableBuffer(GL gl, boolean enable); + +} + diff --git a/src/jogl/classes/com/sun/opengl/util/GLFixedArrayHandler.java b/src/jogl/classes/com/sun/opengl/util/GLFixedArrayHandler.java new file mode 100644 index 000000000..f1e2502be --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/GLFixedArrayHandler.java @@ -0,0 +1,65 @@ + +package com.sun.opengl.util; + +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.*; +import com.sun.opengl.util.*; +import java.nio.*; + +public class GLFixedArrayHandler implements GLArrayHandler { + private GLArrayDataEditable ad; + + public GLFixedArrayHandler(GLArrayDataEditable ad) { + this.ad = ad; + } + + protected final void passArrayPointer(GLPointerFunc gl) { + switch(ad.getIndex()) { + case GLPointerFunc.GL_VERTEX_ARRAY: + gl.glVertexPointer(ad); + break; + case GLPointerFunc.GL_NORMAL_ARRAY: + gl.glNormalPointer(ad); + break; + case GLPointerFunc.GL_COLOR_ARRAY: + gl.glColorPointer(ad); + break; + case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: + gl.glTexCoordPointer(ad); + break; + default: + throw new GLException("invalid glArrayIndex: "+ad.getIndex()+":\n\t"+ad); + } + } + + public void enableBuffer(GL gl, boolean enable) { + GLPointerFunc glp = gl.getGL2ES1(); + if(enable) { + glp.glEnableClientState(ad.getIndex()); + + Buffer buffer = ad.getBuffer(); + + if(ad.isVBO()) { + // always bind and refresh the VBO mgr, + // in case more than one gl*Pointer objects are in use + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, ad.getVBOName()); + if(!ad.isBufferWritten()) { + if(null!=buffer) { + gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * ad.getComponentSize(), buffer, ad.getBufferUsage()); + } + ad.setBufferWritten(true); + } + passArrayPointer(glp); + } else if(null!=buffer) { + passArrayPointer(glp); + ad.setBufferWritten(true); + } + } else { + if(ad.isVBO()) { + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + } + glp.glDisableClientState(ad.getIndex()); + } + } +} + diff --git a/src/jogl/classes/com/sun/opengl/util/Gamma.java b/src/jogl/classes/com/sun/opengl/util/Gamma.java new file mode 100755 index 000000000..8be4f4edf --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/Gamma.java @@ -0,0 +1,106 @@ +/* + * 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 com.sun.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.

+ + 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.

+ * + * 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. System.exit() from the application rather than + * rely on the shutdown hook functionality due to inevitable race + * conditions and unspecified behavior during JVM teardown.

+ * + * 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.

+ * + * @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/com/sun/opengl/util/ImmModeSink.java b/src/jogl/classes/com/sun/opengl/util/ImmModeSink.java index 4f30cd7b1..d3b61d7c5 100644 --- a/src/jogl/classes/com/sun/opengl/util/ImmModeSink.java +++ b/src/jogl/classes/com/sun/opengl/util/ImmModeSink.java @@ -3,8 +3,7 @@ package com.sun.opengl.util; import javax.media.opengl.*; import javax.media.opengl.util.*; -import javax.media.opengl.sub.*; -import javax.media.opengl.sub.fixed.*; +import javax.media.opengl.fixedfunc.*; import com.sun.nativewindow.impl.NWReflection; import java.nio.*; import java.util.Iterator; @@ -861,25 +860,25 @@ public class ImmModeSink { buffer.flip(); if(vComps>0) { - vArrayData = GLArrayDataWrapper.createFixed(GLPointerIf.GL_VERTEX_ARRAY, vComps, vDataType, false, + vArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_VERTEX_ARRAY, vComps, vDataType, false, 0, vertexArray, 0, vOffset); } else { vArrayData = null; } if(cComps>0) { - cArrayData = GLArrayDataWrapper.createFixed(GLPointerIf.GL_COLOR_ARRAY, cComps, cDataType, false, + cArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_COLOR_ARRAY, cComps, cDataType, false, 0, colorArray, 0, cOffset); } else { cArrayData = null; } if(nComps>0) { - nArrayData = GLArrayDataWrapper.createFixed(GLPointerIf.GL_NORMAL_ARRAY, nComps, nDataType, false, + nArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_NORMAL_ARRAY, nComps, nDataType, false, 0, normalArray, 0, nOffset); } else { nArrayData = null; } if(tComps>0) { - tArrayData = GLArrayDataWrapper.createFixed(GLPointerIf.GL_TEXTURE_COORD_ARRAY, tComps, tDataType, false, + tArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_TEXTURE_COORD_ARRAY, tComps, tDataType, false, 0, textCoordArray, 0, tOffset); } else { tArrayData = null; diff --git a/src/jogl/classes/com/sun/opengl/util/Locator.java b/src/jogl/classes/com/sun/opengl/util/Locator.java new file mode 100644 index 000000000..06cd50ce8 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/Locator.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2009 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. + * + */ + +package com.sun.opengl.util; + +import java.util.*; +import java.nio.*; +import java.io.*; +import java.net.*; + +/** Utilities for dealing with resources. */ + +public class Locator { + private Locator() {} + + /** + * Locates the resource using 'getResource(String path, ClassLoader cl)', + * with this context ClassLoader and the path as is, + * as well with the context's package name path plus the path. + * + * @see #getResource(String, ClassLoader) + */ + public static URL getResource(Class context, String path) { + ClassLoader contextCL = (null!=context)?context.getClassLoader():null; + URL url = getResource(path, contextCL); + if (url == null && null!=context) { + // Try again by scoping the path within the class's package + String className = context.getName().replace('.', '/'); + int lastSlash = className.lastIndexOf('/'); + if (lastSlash >= 0) { + String tmpPath = className.substring(0, lastSlash + 1) + path; + url = getResource(tmpPath, contextCL); + } + } + return url; + } + + /** + * Locates the resource using the ClassLoader's facility, + * the absolute URL and absolute file. + * + * @see ClassLoader#getResource(String) + * @see ClassLoader#getSystemResource(String) + * @see URL#URL(String) + * @see File#File(String) + */ + public static URL getResource(String path, ClassLoader cl) { + URL url = null; + if (cl != null) { + url = cl.getResource(path); + } else { + url = ClassLoader.getSystemResource(path); + } + if(!urlExists(url)) { + url = null; + try { + url = new URL(path); + } catch (MalformedURLException e) { } + } + if(!urlExists(url)) { + url = null; + try { + File file = new File(path); + if(file.exists()) { + url = file.toURL(); + } + } catch (MalformedURLException e) {} + } + return url; + } + + /** + * Generates a path for the 'relativeFile' relative to the 'absoluteFileLocation' + */ + public static String getRelativeOf(String absoluteFileLocation, String relativeFile) { + File file = new File(absoluteFileLocation); + file = file.getParentFile(); + while (file != null && relativeFile.startsWith("../")) { + file = file.getParentFile(); + relativeFile = relativeFile.substring(3); + } + if (file != null) { + String res = new File(file, relativeFile).getPath(); + // Handle things on Windows + return res.replace('\\', '/'); + } else { + return relativeFile; + } + } + + /** + * Returns true, if the url exists, + * trying to open a connection. + */ + public static boolean urlExists(URL url) { + boolean v = false; + if(null!=url) { + try { + URLConnection uc = url.openConnection(); + v = true; + } catch (IOException ioe) { } + } + return v; + } + +} + diff --git a/src/jogl/classes/com/sun/opengl/util/PMVMatrix.java b/src/jogl/classes/com/sun/opengl/util/PMVMatrix.java new file mode 100755 index 000000000..4211e893b --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/PMVMatrix.java @@ -0,0 +1,685 @@ +/* + * Copyright (c) 2009 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. + * + */ + +package com.sun.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.fixedfunc.GLMatrixFunc; + +public class PMVMatrix implements GLMatrixFunc { + + 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; +} diff --git a/src/jogl/classes/com/sun/opengl/util/awt/TextRenderer.java b/src/jogl/classes/com/sun/opengl/util/awt/TextRenderer.java index d40339264..6e668b84a 100755 --- a/src/jogl/classes/com/sun/opengl/util/awt/TextRenderer.java +++ b/src/jogl/classes/com/sun/opengl/util/awt/TextRenderer.java @@ -38,9 +38,9 @@ */ package com.sun.opengl.util.awt; -import com.sun.opengl.impl.*; -import com.sun.opengl.impl.packrect.*; +import com.sun.opengl.impl.Debug; import com.sun.opengl.util.*; +import com.sun.opengl.util.packrect.*; import com.sun.opengl.util.texture.*; import com.sun.opengl.util.texture.awt.*; @@ -70,7 +70,6 @@ import javax.media.opengl.*; import javax.media.opengl.glu.*; import javax.media.opengl.glu.gl2.*; import javax.media.opengl.awt.*; -import javax.media.opengl.util.*; /** Renders bitmapped Java 2D text into an OpenGL window with high diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/GLSLArrayHandler.java b/src/jogl/classes/com/sun/opengl/util/glsl/GLSLArrayHandler.java new file mode 100644 index 000000000..1ef9874e4 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/GLSLArrayHandler.java @@ -0,0 +1,60 @@ + +package com.sun.opengl.util.glsl; + +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.*; +import com.sun.opengl.util.*; +import com.sun.opengl.util.glsl.ShaderState; +import java.nio.*; + +public class GLSLArrayHandler implements GLArrayHandler { + private GLArrayDataEditable ad; + + public GLSLArrayHandler(GLArrayDataEditable ad) { + this.ad = ad; + } + + protected final void passVertexAttribPointer(GL2ES2 gl, ShaderState st) { + st.glVertexAttribPointer(gl, ad); + } + + public void enableBuffer(GL gl, boolean enable) { + if(!gl.isGL2ES2()) { + throw new GLException("GLSLArrayHandler expects a GL2ES2 implementation"); + } + GL2ES2 glsl = gl.getGL2ES2(); + ShaderState st = ShaderState.getCurrent(); + if(null==st) { + throw new GLException("No ShaderState current"); + } + + if(enable) { + st.glEnableVertexAttribArray(glsl, ad.getName()); + + Buffer buffer = ad.getBuffer(); + + if(ad.isVBO()) { + // always bind and refresh the VBO mgr, + // in case more than one gl*Pointer objects are in use + glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, ad.getVBOName()); + if(!ad.isBufferWritten()) { + if(null!=buffer) { + glsl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * ad.getComponentSize(), buffer, ad.getBufferUsage()); + } + ad.setBufferWritten(true); + } + passVertexAttribPointer(glsl, st); + } else if(null!=buffer) { + passVertexAttribPointer(glsl, st); + ad.setBufferWritten(true); + } + } else { + if(ad.isVBO()) { + glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + } + st.glDisableVertexAttribArray(glsl, ad.getName()); + } + } + +} + diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderCode.java b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderCode.java index f5ed88ff0..cba5f91b3 100644 --- a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderCode.java +++ b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderCode.java @@ -2,9 +2,7 @@ package com.sun.opengl.util.glsl; import javax.media.opengl.*; -import javax.media.opengl.util.*; -import com.sun.opengl.util.StreamUtil; -import com.sun.opengl.impl.io.Locator; +import com.sun.opengl.util.*; import java.util.*; import java.nio.*; diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixed/FixedFuncHook.java b/src/jogl/classes/com/sun/opengl/util/glsl/fixed/FixedFuncHook.java deleted file mode 100755 index cb80cdcf9..000000000 --- a/src/jogl/classes/com/sun/opengl/util/glsl/fixed/FixedFuncHook.java +++ /dev/null @@ -1,334 +0,0 @@ -/* - * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. - */ - -package com.sun.opengl.util.glsl.fixed; - -import javax.media.opengl.*; -import javax.media.opengl.sub.*; -import javax.media.opengl.sub.fixed.*; -import javax.media.opengl.util.*; -import javax.media.opengl.glu.*; -import com.sun.gluegen.runtime.BufferFactory; -import com.sun.opengl.util.*; -import com.sun.opengl.util.glsl.*; -import com.sun.opengl.impl.glsl.fixed.*; -import java.nio.*; - -public class FixedFuncHook implements GLLightingIf, GLMatrixIf, GLPointerIf { - public static final int MAX_TEXTURE_UNITS = 8; - - protected FixedFuncPipeline fixedFunction=null; - protected PMVMatrix pmvMatrix=null; - protected GL2ES2 gl=null; - - public FixedFuncHook (GL2ES2 gl) { - this(gl, null); - } - - public FixedFuncHook (GL2ES2 gl, PMVMatrix matrix) { - this.gl = gl; - pmvMatrix = (null!=matrix)?matrix:new PMVMatrix(); - - fixedFunction = new FixedFuncPipeline(gl, pmvMatrix); - } - - public FixedFuncHook(GL2ES2 gl, PMVMatrix matrix, - Class shaderRootClass, String shaderSrcRoot, String shaderBinRoot, - String vertexColorFile, - String vertexColorLightFile, - String fragmentColorFile, - String fragmentColorTextureFile) { - this.gl = gl; - pmvMatrix = matrix; - - fixedFunction = new FixedFuncPipeline(gl, pmvMatrix, - shaderRootClass, shaderSrcRoot, shaderBinRoot, - vertexColorFile, vertexColorLightFile, fragmentColorFile, fragmentColorTextureFile); - } - - public void destroy() { - fixedFunction.destroy(gl); - fixedFunction = null; - } - - public PMVMatrix getMatrix() { return pmvMatrix; } - - // - // FixedFuncHookIf - hooks - // - public void glDrawArrays(int mode, int first, int count) { - fixedFunction.validate(gl); - gl.glDrawArrays(mode, first, count); - } - public void glDrawElements(int mode, int count, int type, java.nio.Buffer indices) { - fixedFunction.validate(gl); - gl.glDrawElements(mode, count, type, indices); - } - public void glDrawElements(int mode, int count, int type, long indices_buffer_offset) { - fixedFunction.validate(gl); - gl.glDrawElements(mode, count, type, indices_buffer_offset); - } - - public void glActiveTexture(int texture) { - fixedFunction.glActiveTexture(gl, texture); - gl.glActiveTexture(texture); - } - public void glEnable(int cap) { - if(fixedFunction.glEnable(gl, cap, true)) { - gl.glEnable(cap); - } - } - public void glDisable(int cap) { - if(fixedFunction.glEnable(gl, cap, false)) { - gl.glDisable(cap); - } - } - public void glCullFace(int faceName) { - fixedFunction.glCullFace(gl, faceName); - gl.glCullFace(faceName); - } - - public void glGetFloatv(int pname, java.nio.FloatBuffer params) { - if(pmvMatrix.isMatrixGetName(pname)) { - pmvMatrix.glGetFloatv(pname, params); - return; - } - gl.glGetFloatv(pname, params); - } - public void glGetFloatv(int pname, float[] params, int params_offset) { - if(pmvMatrix.isMatrixGetName(pname)) { - pmvMatrix.glGetFloatv(pname, params, params_offset); - return; - } - gl.glGetFloatv(pname, params, params_offset); - } - public void glGetIntegerv(int pname, IntBuffer params) { - if(pmvMatrix.isMatrixGetName(pname)) { - pmvMatrix.glGetIntegerv(pname, params); - return; - } - gl.glGetIntegerv(pname, params); - } - public void glGetIntegerv(int pname, int[] params, int params_offset) { - if(pmvMatrix.isMatrixGetName(pname)) { - pmvMatrix.glGetIntegerv(pname, params, params_offset); - return; - } - gl.glGetIntegerv(pname, params, params_offset); - } - - // - // MatrixIf - // - public int glGetMatrixMode() { - return pmvMatrix.glGetMatrixMode(); - } - public void glMatrixMode(int mode) { - pmvMatrix.glMatrixMode(mode); - } - public void glLoadMatrixf(java.nio.FloatBuffer m) { - pmvMatrix.glLoadMatrixf(m); - } - public void glLoadMatrixf(float[] m, int m_offset) { - glLoadMatrixf(BufferUtil.newFloatBuffer(m, m_offset)); - } - public void glPopMatrix() { - pmvMatrix.glPopMatrix(); - } - public void glPushMatrix() { - pmvMatrix.glPushMatrix(); - } - public void glLoadIdentity() { - pmvMatrix.glLoadIdentity(); - } - public void glMultMatrixf(java.nio.FloatBuffer m) { - pmvMatrix.glMultMatrixf(m); - } - public void glMultMatrixf(float[] m, int m_offset) { - glMultMatrixf(BufferUtil.newFloatBuffer(m, m_offset)); - } - public void glTranslatef(float x, float y, float z) { - pmvMatrix.glTranslatef(x, y, z); - } - public void glRotatef(float angdeg, float x, float y, float z) { - pmvMatrix.glRotatef(angdeg, x, y, z); - } - public void glScalef(float x, float y, float z) { - pmvMatrix.glScalef(x, y, z); - } - public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) { - pmvMatrix.glOrthof(left, right, bottom, top, zNear, zFar); - } - public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) { - pmvMatrix.glFrustumf(left, right, bottom, top, zNear, zFar); - } - - // - // LightingIf - // - public void glColor4f(float red, float green, float blue, float alpha) { - fixedFunction.glColor4fv(gl, BufferUtil.newFloatBuffer(new float[] { red, green, blue, alpha })); - } - - public void glLightfv(int light, int pname, java.nio.FloatBuffer params) { - fixedFunction.glLightfv(gl, light, pname, params); - } - public void glLightfv(int light, int pname, float[] params, int params_offset) { - glLightfv(light, pname, BufferUtil.newFloatBuffer(params, params_offset)); - } - public void glMaterialfv(int face, int pname, java.nio.FloatBuffer params) { - fixedFunction.glMaterialfv(gl, face, pname, params); - } - public void glMaterialfv(int face, int pname, float[] params, int params_offset) { - glMaterialfv(face, pname, BufferUtil.newFloatBuffer(params, params_offset)); - } - public void glMaterialf(int face, int pname, float param) { - glMaterialfv(face, pname, BufferUtil.newFloatBuffer(new float[] { param })); - } - public void glShadeModel(int mode) { - fixedFunction.glShadeModel(gl, mode); - } - - // - // PointerIf - // - public void glEnableClientState(int glArrayIndex) { - fixedFunction.glEnableClientState(gl, glArrayIndex); - } - public void glDisableClientState(int glArrayIndex) { - fixedFunction.glDisableClientState(gl, glArrayIndex); - } - - public void glVertexPointer(GLArrayData array) { - if(array.isVBO()) { - if(!gl.glIsVBOArrayEnabled()) { - throw new GLException("VBO array is not enabled: "+array); - } - } else { - if(gl.glIsVBOArrayEnabled()) { - throw new GLException("VBO array is not disabled: "+array); - } - BufferFactory.rangeCheck(array.getBuffer(), 1); - if (!BufferFactory.isDirect(array.getBuffer())) { - throw new GLException("Argument \"pointer\" was not a direct buffer"); } - } - fixedFunction.glVertexPointer(gl, array); - } - - public void glVertexPointer(int size, int type, int stride, java.nio.Buffer pointer) { - glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, false, stride, pointer, 0, 0)); - } - public void glVertexPointer(int size, int type, int stride, long pointer_buffer_offset) { - int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); - if(vboName==0) { - throw new GLException("no GL_ARRAY_BUFFER VBO bound"); - } - glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, false, - stride, null, vboName, pointer_buffer_offset)); - } - - public void glColorPointer(GLArrayData array) { - if(array.isVBO()) { - if(!gl.glIsVBOArrayEnabled()) { - throw new GLException("VBO array is not enabled: "+array); - } - } else { - if(gl.glIsVBOArrayEnabled()) { - throw new GLException("VBO array is not disabled: "+array); - } - BufferFactory.rangeCheck(array.getBuffer(), 1); - if (!BufferFactory.isDirect(array.getBuffer())) { - throw new GLException("Argument \"pointer\" was not a direct buffer"); } - } - fixedFunction.glColorPointer(gl, array); - } - public void glColorPointer(int size, int type, int stride, java.nio.Buffer pointer) { - glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, false, - stride, pointer, 0, 0)); - } - public void glColorPointer(int size, int type, int stride, long pointer_buffer_offset) { - int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); - if(vboName==0) { - throw new GLException("no GL_ARRAY_BUFFER VBO bound"); - } - glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, false, - stride, null, vboName, pointer_buffer_offset)); - } - - public void glNormalPointer(GLArrayData array) { - if(array.getComponentNumber()!=3) { - throw new GLException("Only 3 components per normal allowed"); - } - if(array.isVBO()) { - if(!gl.glIsVBOArrayEnabled()) { - throw new GLException("VBO array is not enabled: "+array); - } - } else { - if(gl.glIsVBOArrayEnabled()) { - throw new GLException("VBO array is not disabled: "+array); - } - BufferFactory.rangeCheck(array.getBuffer(), 1); - if (!BufferFactory.isDirect(array.getBuffer())) { - throw new GLException("Argument \"pointer\" was not a direct buffer"); } - } - fixedFunction.glNormalPointer(gl, array); - } - public void glNormalPointer(int type, int stride, java.nio.Buffer pointer) { - glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, false, - stride, pointer, 0, 0)); - } - public void glNormalPointer(int type, int stride, long pointer_buffer_offset) { - int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); - if(vboName==0) { - throw new GLException("no GL_ARRAY_BUFFER VBO bound"); - } - glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, false, - stride, null, vboName, pointer_buffer_offset)); - } - - public void glTexCoordPointer(GLArrayData array) { - if(array.isVBO()) { - if(!gl.glIsVBOArrayEnabled()) { - throw new GLException("VBO array is not enabled: "+array); - } - } else { - if(gl.glIsVBOArrayEnabled()) { - throw new GLException("VBO array is not disabled: "+array); - } - BufferFactory.rangeCheck(array.getBuffer(), 1); - if (!BufferFactory.isDirect(array.getBuffer())) { - throw new GLException("Argument \"pointer\" was not a direct buffer"); } - } - fixedFunction.glTexCoordPointer(gl, array); - } - public void glTexCoordPointer(int size, int type, int stride, java.nio.Buffer pointer) { - glTexCoordPointer( - GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, false, stride, pointer, 0,0)); - } - public void glTexCoordPointer(int size, int type, int stride, long pointer_buffer_offset) { - int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); - if(vboName==0) { - throw new GLException("no GL_ARRAY_BUFFER VBO bound"); - } - glTexCoordPointer( - GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, false, - stride, null, vboName, pointer_buffer_offset) ); - } - - public final String toString() { - StringBuffer buf = new StringBuffer(); - buf.append(getClass().getName()+" ("); - if(null!=pmvMatrix) { - buf.append(", matrixDirty: "+pmvMatrix.isDirty()); - } - buf.append("\n\t, FixedFunction: "+fixedFunction); - buf.append(gl); - buf.append(" )"); - - return buf.toString(); - } - -} - - diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/FixedFuncUtil.java b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/FixedFuncUtil.java new file mode 100644 index 000000000..02d6ec92e --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/FixedFuncUtil.java @@ -0,0 +1,81 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + */ + +package com.sun.opengl.util.glsl.fixedfunc; + +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.*; + +import com.sun.opengl.util.glsl.fixedfunc.impl.*; + +/** + * Tool to pipeline GL2ES2 into a fixed function emulation implementing GL2ES1. + */ +public class FixedFuncUtil { + /** + * @return If gl is a GL2ES1, return the type cast object, + * otherwise create a fixed function emulation pipeline with the GL2ES2 impl. + * @throws GLException if the GL object is neither GL2ES1 nor GL2ES2 + */ + public static final GL2ES1 getFixedFuncImpl(GL gl) { + if(gl.isGL2ES1()) { + return gl.getGL2ES1(); + } else if(gl.isGL2ES2()) { + GL2ES2 es2 = (GL2ES2)gl; + FixedFuncHook hook = new FixedFuncHook(es2); + FixedFuncImpl impl = new FixedFuncImpl(es2, hook); + gl.getContext().setGL(impl); + return impl; + } + throw new GLException("GL Object is neither GL2ES1 nor GL2ES2"); + } + + /** + * 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.fixedfunc.GLPointerFunc#GL_VERTEX_ARRAY + * @see #mgl_Normal + * @see javax.media.opengl.fixedfunc.GLPointerFunc#GL_NORMAL_ARRAY + * @see #mgl_Color + * @see javax.media.opengl.fixedfunc.GLPointerFunc#GL_COLOR_ARRAY + * @see #mgl_MultiTexCoord + * @see javax.media.opengl.fixedfunc.GLPointerFunc#GL_TEXTURE_COORD_ARRAY + * @see javax.media.opengl.fixedfunc.GLPointerFunc#glEnableClientState + * @see javax.media.opengl.fixedfunc.GLPointerFunc#glVertexPointer + * @see javax.media.opengl.fixedfunc.GLPointerFunc#glColorPointer + * @see javax.media.opengl.fixedfunc.GLPointerFunc#glNormalPointer + * @see javax.media.opengl.fixedfunc.GLPointerFunc#glTexCoordPointer + */ + public static String getPredefinedArrayIndexName(int glArrayIndex) { + return FixedFuncPipeline.getPredefinedArrayIndexName(glArrayIndex); + } + + /** + * String name for + * @see javax.media.opengl.GL#GL_VERTEX_ARRAY + */ + public static final String mgl_Vertex = FixedFuncPipeline.mgl_Vertex; + + /** + * String name for + * @see javax.media.opengl.GL#GL_NORMAL_ARRAY + */ + public static final String mgl_Normal = FixedFuncPipeline.mgl_Normal; + + /** + * String name for + * @see javax.media.opengl.GL#GL_COLOR_ARRAY + */ + public static final String mgl_Color = FixedFuncPipeline.mgl_Color; + + /** + * String name for + * @see javax.media.opengl.GL#GL_TEXTURE_COORD_ARRAY + */ + public static final String mgl_MultiTexCoord = FixedFuncPipeline.mgl_MultiTexCoord; +} diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncHook.java b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncHook.java new file mode 100755 index 000000000..626f3fdaa --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncHook.java @@ -0,0 +1,332 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + */ + +package com.sun.opengl.util.glsl.fixedfunc.impl; + +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.*; +import javax.media.opengl.util.*; +import javax.media.opengl.glu.*; +import com.sun.gluegen.runtime.BufferFactory; +import com.sun.opengl.util.*; +import com.sun.opengl.util.glsl.*; +import java.nio.*; + +public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFunc { + public static final int MAX_TEXTURE_UNITS = 8; + + protected FixedFuncPipeline fixedFunction=null; + protected PMVMatrix pmvMatrix=null; + protected GL2ES2 gl=null; + + public FixedFuncHook (GL2ES2 gl) { + this(gl, null); + } + + public FixedFuncHook (GL2ES2 gl, PMVMatrix matrix) { + this.gl = gl; + pmvMatrix = (null!=matrix)?matrix:new PMVMatrix(); + + fixedFunction = new FixedFuncPipeline(gl, pmvMatrix); + } + + public FixedFuncHook(GL2ES2 gl, PMVMatrix matrix, + Class shaderRootClass, String shaderSrcRoot, String shaderBinRoot, + String vertexColorFile, + String vertexColorLightFile, + String fragmentColorFile, + String fragmentColorTextureFile) { + this.gl = gl; + pmvMatrix = matrix; + + fixedFunction = new FixedFuncPipeline(gl, pmvMatrix, + shaderRootClass, shaderSrcRoot, shaderBinRoot, + vertexColorFile, vertexColorLightFile, fragmentColorFile, fragmentColorTextureFile); + } + + public void destroy() { + fixedFunction.destroy(gl); + fixedFunction = null; + } + + public PMVMatrix getMatrix() { return pmvMatrix; } + + // + // FixedFuncHookIf - hooks + // + public void glDrawArrays(int mode, int first, int count) { + fixedFunction.validate(gl); + gl.glDrawArrays(mode, first, count); + } + public void glDrawElements(int mode, int count, int type, java.nio.Buffer indices) { + fixedFunction.validate(gl); + gl.glDrawElements(mode, count, type, indices); + } + public void glDrawElements(int mode, int count, int type, long indices_buffer_offset) { + fixedFunction.validate(gl); + gl.glDrawElements(mode, count, type, indices_buffer_offset); + } + + public void glActiveTexture(int texture) { + fixedFunction.glActiveTexture(gl, texture); + gl.glActiveTexture(texture); + } + public void glEnable(int cap) { + if(fixedFunction.glEnable(gl, cap, true)) { + gl.glEnable(cap); + } + } + public void glDisable(int cap) { + if(fixedFunction.glEnable(gl, cap, false)) { + gl.glDisable(cap); + } + } + public void glCullFace(int faceName) { + fixedFunction.glCullFace(gl, faceName); + gl.glCullFace(faceName); + } + + public void glGetFloatv(int pname, java.nio.FloatBuffer params) { + if(pmvMatrix.isMatrixGetName(pname)) { + pmvMatrix.glGetFloatv(pname, params); + return; + } + gl.glGetFloatv(pname, params); + } + public void glGetFloatv(int pname, float[] params, int params_offset) { + if(pmvMatrix.isMatrixGetName(pname)) { + pmvMatrix.glGetFloatv(pname, params, params_offset); + return; + } + gl.glGetFloatv(pname, params, params_offset); + } + public void glGetIntegerv(int pname, IntBuffer params) { + if(pmvMatrix.isMatrixGetName(pname)) { + pmvMatrix.glGetIntegerv(pname, params); + return; + } + gl.glGetIntegerv(pname, params); + } + public void glGetIntegerv(int pname, int[] params, int params_offset) { + if(pmvMatrix.isMatrixGetName(pname)) { + pmvMatrix.glGetIntegerv(pname, params, params_offset); + return; + } + gl.glGetIntegerv(pname, params, params_offset); + } + + // + // MatrixIf + // + public int glGetMatrixMode() { + return pmvMatrix.glGetMatrixMode(); + } + public void glMatrixMode(int mode) { + pmvMatrix.glMatrixMode(mode); + } + public void glLoadMatrixf(java.nio.FloatBuffer m) { + pmvMatrix.glLoadMatrixf(m); + } + public void glLoadMatrixf(float[] m, int m_offset) { + glLoadMatrixf(BufferUtil.newFloatBuffer(m, m_offset)); + } + public void glPopMatrix() { + pmvMatrix.glPopMatrix(); + } + public void glPushMatrix() { + pmvMatrix.glPushMatrix(); + } + public void glLoadIdentity() { + pmvMatrix.glLoadIdentity(); + } + public void glMultMatrixf(java.nio.FloatBuffer m) { + pmvMatrix.glMultMatrixf(m); + } + public void glMultMatrixf(float[] m, int m_offset) { + glMultMatrixf(BufferUtil.newFloatBuffer(m, m_offset)); + } + public void glTranslatef(float x, float y, float z) { + pmvMatrix.glTranslatef(x, y, z); + } + public void glRotatef(float angdeg, float x, float y, float z) { + pmvMatrix.glRotatef(angdeg, x, y, z); + } + public void glScalef(float x, float y, float z) { + pmvMatrix.glScalef(x, y, z); + } + public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) { + pmvMatrix.glOrthof(left, right, bottom, top, zNear, zFar); + } + public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) { + pmvMatrix.glFrustumf(left, right, bottom, top, zNear, zFar); + } + + // + // LightingIf + // + public void glColor4f(float red, float green, float blue, float alpha) { + fixedFunction.glColor4fv(gl, BufferUtil.newFloatBuffer(new float[] { red, green, blue, alpha })); + } + + public void glLightfv(int light, int pname, java.nio.FloatBuffer params) { + fixedFunction.glLightfv(gl, light, pname, params); + } + public void glLightfv(int light, int pname, float[] params, int params_offset) { + glLightfv(light, pname, BufferUtil.newFloatBuffer(params, params_offset)); + } + public void glMaterialfv(int face, int pname, java.nio.FloatBuffer params) { + fixedFunction.glMaterialfv(gl, face, pname, params); + } + public void glMaterialfv(int face, int pname, float[] params, int params_offset) { + glMaterialfv(face, pname, BufferUtil.newFloatBuffer(params, params_offset)); + } + public void glMaterialf(int face, int pname, float param) { + glMaterialfv(face, pname, BufferUtil.newFloatBuffer(new float[] { param })); + } + public void glShadeModel(int mode) { + fixedFunction.glShadeModel(gl, mode); + } + + // + // PointerIf + // + public void glEnableClientState(int glArrayIndex) { + fixedFunction.glEnableClientState(gl, glArrayIndex); + } + public void glDisableClientState(int glArrayIndex) { + fixedFunction.glDisableClientState(gl, glArrayIndex); + } + + public void glVertexPointer(GLArrayData array) { + if(array.isVBO()) { + if(!gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not enabled: "+array); + } + } else { + if(gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not disabled: "+array); + } + BufferFactory.rangeCheck(array.getBuffer(), 1); + if (!BufferFactory.isDirect(array.getBuffer())) { + throw new GLException("Argument \"pointer\" was not a direct buffer"); } + } + fixedFunction.glVertexPointer(gl, array); + } + + public void glVertexPointer(int size, int type, int stride, java.nio.Buffer pointer) { + glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, false, stride, pointer, 0, 0)); + } + public void glVertexPointer(int size, int type, int stride, long pointer_buffer_offset) { + int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); + if(vboName==0) { + throw new GLException("no GL_ARRAY_BUFFER VBO bound"); + } + glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, false, + stride, null, vboName, pointer_buffer_offset)); + } + + public void glColorPointer(GLArrayData array) { + if(array.isVBO()) { + if(!gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not enabled: "+array); + } + } else { + if(gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not disabled: "+array); + } + BufferFactory.rangeCheck(array.getBuffer(), 1); + if (!BufferFactory.isDirect(array.getBuffer())) { + throw new GLException("Argument \"pointer\" was not a direct buffer"); } + } + fixedFunction.glColorPointer(gl, array); + } + public void glColorPointer(int size, int type, int stride, java.nio.Buffer pointer) { + glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, false, + stride, pointer, 0, 0)); + } + public void glColorPointer(int size, int type, int stride, long pointer_buffer_offset) { + int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); + if(vboName==0) { + throw new GLException("no GL_ARRAY_BUFFER VBO bound"); + } + glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, false, + stride, null, vboName, pointer_buffer_offset)); + } + + public void glNormalPointer(GLArrayData array) { + if(array.getComponentNumber()!=3) { + throw new GLException("Only 3 components per normal allowed"); + } + if(array.isVBO()) { + if(!gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not enabled: "+array); + } + } else { + if(gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not disabled: "+array); + } + BufferFactory.rangeCheck(array.getBuffer(), 1); + if (!BufferFactory.isDirect(array.getBuffer())) { + throw new GLException("Argument \"pointer\" was not a direct buffer"); } + } + fixedFunction.glNormalPointer(gl, array); + } + public void glNormalPointer(int type, int stride, java.nio.Buffer pointer) { + glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, false, + stride, pointer, 0, 0)); + } + public void glNormalPointer(int type, int stride, long pointer_buffer_offset) { + int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); + if(vboName==0) { + throw new GLException("no GL_ARRAY_BUFFER VBO bound"); + } + glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, false, + stride, null, vboName, pointer_buffer_offset)); + } + + public void glTexCoordPointer(GLArrayData array) { + if(array.isVBO()) { + if(!gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not enabled: "+array); + } + } else { + if(gl.glIsVBOArrayEnabled()) { + throw new GLException("VBO array is not disabled: "+array); + } + BufferFactory.rangeCheck(array.getBuffer(), 1); + if (!BufferFactory.isDirect(array.getBuffer())) { + throw new GLException("Argument \"pointer\" was not a direct buffer"); } + } + fixedFunction.glTexCoordPointer(gl, array); + } + public void glTexCoordPointer(int size, int type, int stride, java.nio.Buffer pointer) { + glTexCoordPointer( + GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, false, stride, pointer, 0,0)); + } + public void glTexCoordPointer(int size, int type, int stride, long pointer_buffer_offset) { + int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); + if(vboName==0) { + throw new GLException("no GL_ARRAY_BUFFER VBO bound"); + } + glTexCoordPointer( + GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, false, + stride, null, vboName, pointer_buffer_offset) ); + } + + public final String toString() { + StringBuffer buf = new StringBuffer(); + buf.append(getClass().getName()+" ("); + if(null!=pmvMatrix) { + buf.append(", matrixDirty: "+pmvMatrix.isDirty()); + } + buf.append("\n\t, FixedFunction: "+fixedFunction); + buf.append(gl); + buf.append(" )"); + + return buf.toString(); + } + +} + + diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncPipeline.java b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncPipeline.java new file mode 100644 index 000000000..1b8dd1f11 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncPipeline.java @@ -0,0 +1,554 @@ + +package com.sun.opengl.util.glsl.fixedfunc.impl; + +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.*; +import com.sun.opengl.util.*; +import com.sun.opengl.util.glsl.*; +import com.sun.opengl.util.glsl.fixedfunc.*; +import java.nio.*; + +public class FixedFuncPipeline { + public static final int MAX_TEXTURE_UNITS = 8; + public static final int MAX_LIGHTS = 8; + + // We can't have any dependencies on the FixedFuncUtil class for build bootstrapping reasons + public static final String mgl_Vertex = "mgl_Vertex"; + public static final String mgl_Normal = "mgl_Normal"; + public static final String mgl_Color = "mgl_Color"; + public static final String mgl_MultiTexCoord = "mgl_MultiTexCoord" ; + + public static String getPredefinedArrayIndexName(int glArrayIndex) { + switch(glArrayIndex) { + case GLPointerFunc.GL_VERTEX_ARRAY: + return mgl_Vertex; + case GLPointerFunc.GL_NORMAL_ARRAY: + return mgl_Normal; + case GLPointerFunc.GL_COLOR_ARRAY: + return mgl_Color; + case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: + return mgl_MultiTexCoord; + } + return null; + } + + public FixedFuncPipeline(GL2ES2 gl, PMVMatrix pmvMatrix) { + init(gl, pmvMatrix, FixedFuncPipeline.class, shaderSrcRootDef, shaderBinRootDef, + vertexColorFileDef, vertexColorLightFileDef, fragmentColorFileDef, fragmentColorTextureFileDef); + } + public FixedFuncPipeline(GL2ES2 gl, PMVMatrix pmvMatrix, Class shaderRootClass, String shaderSrcRoot, String shaderBinRoot, + String vertexColorFile, + String vertexColorLightFile, + String fragmentColorFile, + String fragmentColorTextureFile) { + init(gl, pmvMatrix, shaderRootClass, shaderSrcRoot, shaderBinRoot, + vertexColorFile, vertexColorLightFile, fragmentColorFile, fragmentColorTextureFile); + } + + public boolean verbose() { return verbose; } + + public void setVerbose(boolean v) { verbose=v; } + + public boolean isValid() { + return shaderState.linked(); + } + + public ShaderState getShaderState() { + return shaderState; + } + + public int getActiveTextureUnit() { + return activeTextureUnit; + } + + public String getArrayIndexName(int glArrayIndex) { + String name = getPredefinedArrayIndexName(glArrayIndex); + switch(glArrayIndex) { + case GLPointerFunc.GL_VERTEX_ARRAY: + case GLPointerFunc.GL_NORMAL_ARRAY: + case GLPointerFunc.GL_COLOR_ARRAY: + break; + case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: + name = name + activeTextureUnit; + } + return name; + } + + public void destroy(GL2ES2 gl) { + shaderProgramColor.release(gl, true); + shaderProgramColorLight.release(gl, true); + shaderProgramColorTexture.release(gl, true); + shaderProgramColorTextureLight.release(gl, true); + shaderState.destroy(gl); + } + + public void glEnableClientState(GL2ES2 gl, int glArrayIndex) { + shaderState.glUseProgram(gl, true); + + shaderState.glEnableVertexAttribArray(gl, getArrayIndexName(glArrayIndex)); + // textureCoordsEnabled |= (1 << activeTextureUnit); + if ( textureCoordsEnabled.get(activeTextureUnit) != 1 ) { + textureCoordsEnabled.put(activeTextureUnit, 1); + textureCoordsEnabledDirty = true; + } + } + + public void glDisableClientState(GL2ES2 gl, int glArrayIndex) { + shaderState.glUseProgram(gl, true); + + shaderState.glDisableVertexAttribArray(gl, getArrayIndexName(glArrayIndex)); + // textureCoordsEnabled &= ~(1 << activeTextureUnit); + if ( textureCoordsEnabled.get(activeTextureUnit) != 0 ) { + textureCoordsEnabled.put(activeTextureUnit, 0); + textureCoordsEnabledDirty = true; + } + } + + public void glVertexPointer(GL2ES2 gl, GLArrayData data) { + shaderState.glUseProgram(gl, true); + shaderState.glVertexAttribPointer(gl, data); + } + + public void glColorPointer(GL2ES2 gl, GLArrayData data) { + shaderState.glUseProgram(gl, true); + shaderState.glVertexAttribPointer(gl, data); + } + + public void glColor4fv(GL2ES2 gl, FloatBuffer data ) { + shaderState.glUseProgram(gl, true); + GLUniformData ud = shaderState.getUniform(mgl_ColorStatic); + if(null!=ud) { + ud.setData(data); + shaderState.glUniform(gl, ud); + } + } + + public void glNormalPointer(GL2ES2 gl, GLArrayData data) { + shaderState.glUseProgram(gl, true); + shaderState.glVertexAttribPointer(gl, data); + } + + public void glTexCoordPointer(GL2ES2 gl, GLArrayData data) { + shaderState.glUseProgram(gl, true); + data.setName( getArrayIndexName(data.getIndex()) ); + shaderState.glVertexAttribPointer(gl, data); + } + + public void glLightfv(GL2ES2 gl, int light, int pname, java.nio.FloatBuffer params) { + shaderState.glUseProgram(gl, true); + light -=GLLightingFunc.GL_LIGHT0; + if(0 <= light && light < MAX_LIGHTS) { + GLUniformData ud = null; + switch(pname) { + case GLLightingFunc.GL_AMBIENT: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].ambient"); + break; + case GLLightingFunc.GL_DIFFUSE: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].diffuse"); + break; + case GLLightingFunc.GL_SPECULAR: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].specular"); + break; + case GLLightingFunc.GL_POSITION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].position"); + break; + case GLLightingFunc.GL_SPOT_DIRECTION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotDirection"); + break; + case GLLightingFunc.GL_SPOT_EXPONENT: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotExponent"); + break; + case GLLightingFunc.GL_SPOT_CUTOFF: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotCutoff"); + break; + case GLLightingFunc.GL_CONSTANT_ATTENUATION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].constantAttenuation"); + break; + case GLLightingFunc.GL_LINEAR_ATTENUATION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].linearAttenuation"); + break; + case GLLightingFunc.GL_QUADRATIC_ATTENUATION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].quadraticAttenuation"); + break; + default: + if(verbose) { + System.err.println("glLightfv pname not within [GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_POSITION GL_SPOT_DIRECTION]: "+pname); + } + return; + } + if(null!=ud) { + ud.setData(params); + shaderState.glUniform(gl, ud); + } + } else if(verbose) { + System.err.println("glLightfv light not within [0.."+MAX_LIGHTS+"]: "+light); + } + } + + public void glMaterialfv(GL2ES2 gl, int face, int pname, java.nio.FloatBuffer params) { + shaderState.glUseProgram(gl, true); + + switch (face) { + case GL.GL_FRONT: + case GL.GL_FRONT_AND_BACK: + break; + case GL.GL_BACK: + if(verbose) { + System.err.println("glMaterialfv face GL_BACK currently not supported"); + } + break; + default: + } + + GLUniformData ud = null; + switch(pname) { + case GLLightingFunc.GL_AMBIENT: + ud = shaderState.getUniform(mgl_FrontMaterial+".ambient"); + break; + case GLLightingFunc.GL_AMBIENT_AND_DIFFUSE: + glMaterialfv(gl, face, GLLightingFunc.GL_AMBIENT, params); + // fall through intended .. + case GLLightingFunc.GL_DIFFUSE: + ud = shaderState.getUniform(mgl_FrontMaterial+".diffuse"); + break; + case GLLightingFunc.GL_SPECULAR: + ud = shaderState.getUniform(mgl_FrontMaterial+".specular"); + break; + case GLLightingFunc.GL_EMISSION: + ud = shaderState.getUniform(mgl_FrontMaterial+".emission"); + break; + case GLLightingFunc.GL_SHININESS: + ud = shaderState.getUniform(mgl_FrontMaterial+".shininess"); + break; + default: + if(verbose) { + System.err.println("glMaterialfv pname not within [GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_EMISSION GL_SHININESS]: "+pname); + } + return; + } + if(null!=ud) { + ud.setData(params); + shaderState.glUniform(gl, ud); + } + } + + public void glShadeModel(GL2ES2 gl, int mode) { + shaderState.glUseProgram(gl, true); + GLUniformData ud = shaderState.getUniform(mgl_ShadeModel); + if(null!=ud) { + ud.setData(mode); + shaderState.glUniform(gl, ud); + } + } + + public void glActiveTexture(GL2ES2 gl, int textureUnit) { + textureUnit -= GL.GL_TEXTURE0; + if(0 <= textureUnit && textureUnitcullFace) { + faceName *= -1; + } + cullFace = faceName; + } + + public void validate(GL2ES2 gl) { + shaderState.glUseProgram(gl, true); + GLUniformData ud; + if(pmvMatrix.update()) { + ud = shaderState.getUniform(mgl_PMVMatrix); + if(null!=ud) { + // same data object .. + shaderState.glUniform(gl, ud); + } else { + throw new GLException("Failed to update: mgl_PMVMatrix"); + } + ud = shaderState.getUniform(mgl_NormalMatrix); + if(null!=ud) { + // same data object .. + shaderState.glUniform(gl, ud); + } + } + ud = shaderState.getUniform(mgl_ColorEnabled); + if(null!=ud) { + int ca = (shaderState.isVertexAttribArrayEnabled(mgl_Color)==true)?1:0; + if(ca!=ud.intValue()) { + ud.setData(ca); + shaderState.glUniform(gl, ud); + } + } + ud = shaderState.getUniform(mgl_CullFace); + if(null!=ud) { + if(cullFace!=ud.intValue()) { + ud.setData(cullFace); + shaderState.glUniform(gl, ud); + } + } + + if(lightsEnabledDirty) { + ud = shaderState.getUniform(mgl_LightsEnabled); + if(null!=ud) { + // same data object + shaderState.glUniform(gl, ud); + } + lightsEnabledDirty=false; + } + + if(textureCoordsEnabledDirty) { + ud = shaderState.getUniform(mgl_TexCoordEnabled); + if(null!=ud) { + // same data object + shaderState.glUniform(gl, ud); + } + textureCoordsEnabledDirty=false; + } + + if(textureEnabled) { + if(lightingEnabled) { + shaderState.attachShaderProgram(gl, shaderProgramColorTextureLight); + } else { + shaderState.attachShaderProgram(gl, shaderProgramColorTexture); + } + } else { + if(lightingEnabled) { + shaderState.attachShaderProgram(gl, shaderProgramColorLight); + } else { + shaderState.attachShaderProgram(gl, shaderProgramColor); + } + } + if(DEBUG) { + System.err.println("validate: "+this); + } + } + + public String toString() { + return "FixedFuncPipeline[pmv: "+pmvMatrix+ + ", textureEnabled: "+textureEnabled+ + ", textureCoordsEnabled: "+textureCoordsEnabled+ + ", lightingEnabled: "+lightingEnabled+ + ", lightsEnabled: "+lightsEnabled+ + "\n\t, shaderProgramColor: "+shaderProgramColor+ + "\n\t, shaderProgramColorTexture: "+shaderProgramColorTexture+ + "\n\t, shaderProgramColorLight: "+shaderProgramColorLight+ + "\n\t, shaderProgramColorTextureLight: "+shaderProgramColorTextureLight+ + "\n\t, ShaderState: "+shaderState+ + "]"; + } + + protected void init(GL2ES2 gl, PMVMatrix pmvMatrix, Class shaderRootClass, String shaderSrcRoot, String shaderBinRoot, + String vertexColorFile, + String vertexColorLightFile, + String fragmentColorFile, + String fragmentColorTextureFile) + { + if(null==pmvMatrix) { + throw new GLException("PMVMatrix is null"); + } + this.pmvMatrix=pmvMatrix; + this.shaderState=new ShaderState(); + this.shaderState.setVerbose(verbose); + ShaderCode vertexColor, vertexColorLight, fragmentColor, fragmentColorTexture; + + vertexColor = ShaderCode.create( gl, gl.GL_VERTEX_SHADER, 1, shaderRootClass, + shaderSrcRoot, shaderBinRoot, vertexColorFile); + + vertexColorLight = ShaderCode.create( gl, gl.GL_VERTEX_SHADER, 1, shaderRootClass, + shaderSrcRoot, shaderBinRoot, vertexColorLightFile); + + fragmentColor = ShaderCode.create( gl, gl.GL_FRAGMENT_SHADER, 1, shaderRootClass, + shaderSrcRoot, shaderBinRoot, fragmentColorFile); + + fragmentColorTexture = ShaderCode.create( gl, gl.GL_FRAGMENT_SHADER, 1, shaderRootClass, + shaderSrcRoot, shaderBinRoot, fragmentColorTextureFile); + + shaderProgramColor = new ShaderProgram(); + shaderProgramColor.add(vertexColor); + shaderProgramColor.add(fragmentColor); + if(!shaderProgramColor.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColor program: "+shaderProgramColor); + } + + shaderProgramColorTexture = new ShaderProgram(); + shaderProgramColorTexture.add(vertexColor); + shaderProgramColorTexture.add(fragmentColorTexture); + if(!shaderProgramColorTexture.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColorTexture program: "+shaderProgramColorTexture); + } + + shaderProgramColorLight = new ShaderProgram(); + shaderProgramColorLight.add(vertexColorLight); + shaderProgramColorLight.add(fragmentColor); + if(!shaderProgramColorLight.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColorLight program: "+shaderProgramColorLight); + } + + shaderProgramColorTextureLight = new ShaderProgram(); + shaderProgramColorTextureLight.add(vertexColorLight); + shaderProgramColorTextureLight.add(fragmentColorTexture); + if(!shaderProgramColorTextureLight.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColorLight program: "+shaderProgramColorTextureLight); + } + + shaderState.attachShaderProgram(gl, shaderProgramColor); + shaderState.glUseProgram(gl, true); + + // mandatory .. + if(!shaderState.glUniform(gl, new GLUniformData(mgl_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMviMatrixf()))) { + throw new GLException("Error setting PMVMatrix in shader: "+this); + } + + // optional parameter .. + shaderState.glUniform(gl, new GLUniformData(mgl_NormalMatrix, 3, 3, pmvMatrix.glGetNormalMatrixf())); + + shaderState.glUniform(gl, new GLUniformData(mgl_ColorEnabled, 0)); + shaderState.glUniform(gl, new GLUniformData(mgl_ColorStatic, 4, zero4f)); + shaderState.glUniform(gl, new GLUniformData(mgl_TexCoordEnabled, 1, textureCoordsEnabled)); + shaderState.glUniform(gl, new GLUniformData(mgl_ActiveTexture, activeTextureUnit)); + shaderState.glUniform(gl, new GLUniformData(mgl_ActiveTextureIdx, activeTextureUnit)); + shaderState.glUniform(gl, new GLUniformData(mgl_ShadeModel, 0)); + shaderState.glUniform(gl, new GLUniformData(mgl_CullFace, cullFace)); + for(int i=0; i 0 && + ( ( mgl_CullFace == 1 && gl_FrontFacing ) || + ( mgl_CullFace == 2 && !gl_FrontFacing ) || + ( mgl_CullFace == 3 ) ) ) { + discard; + } + gl_FragColor = frontColor; +} + diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColor.vp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColor.vp new file mode 100644 index 000000000..346e40196 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColor.vp @@ -0,0 +1,22 @@ +#include es_precision.glsl + +#include mgl_const.glsl +#include mgl_uniform.glsl +#include mgl_attribute.glsl +#include mgl_varying.glsl + +#include mgl_settexcoord.vp + +void main(void) +{ + if(mgl_ColorEnabled>0) { + frontColor=mgl_Color; + } else { + frontColor=mgl_ColorStatic; + } + + gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex; + + setTexCoord(gl_Position); +} + diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorLight.vp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorLight.vp new file mode 100644 index 000000000..ce203cfb9 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorLight.vp @@ -0,0 +1,70 @@ +#include es_precision.glsl +#include mgl_lightdef.glsl + +#include mgl_const.glsl +#include mgl_uniform.glsl +#include mgl_uniform_light.glsl +#include mgl_attribute.glsl +#include mgl_varying.glsl + +#include mgl_settexcoord.vp + +void main(void) +{ + vec4 position; + vec3 normal, lightDir, cameraDir, halfDir; + vec4 ambient, diffuse, specular; + float NdotL, NdotHV, dist, attenuation; + int i; + + position = mgl_PMVMatrix[1] * mgl_Vertex; // vertex eye position + + normal = normalize(mgl_NormalMatrix * mgl_Normal); + // cameraPosition: (mgl_PMVMatrix[2] * vec4(0,0,0,1.0)).xyz + cameraDir = normalize( (mgl_PMVMatrix[2] * vec4(0,0,0,1.0)).xyz - mgl_Vertex.xyz ); + + ambient = vec4(0,0,0,0); + diffuse = vec4(0,0,0,0); + specular = vec4(0,0,0,0); + + bool lightEnabled = false; + + for(i=0; i0) { + frontColor=mgl_Color; + } else { + frontColor=mgl_ColorStatic; + } + if( lightEnabled ) { + frontColor *= ambient + diffuse + specular; + } + + gl_Position = mgl_PMVMatrix[0] * position; + + setTexCoord(gl_Position); +} + diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorTexture.fp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorTexture.fp new file mode 100644 index 000000000..86e6ace73 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorTexture.fp @@ -0,0 +1,47 @@ + +#include es_precision.glsl +#include mgl_lightdef.glsl + +#include mgl_const.glsl +#include mgl_uniform.glsl +#include mgl_varying.glsl + +vec4 getTexColor(in sampler2D tex, in int idx) { + vec4 coord; + if(idx==0) { + coord= mgl_TexCoords[0]; + } else if(idx==1) { + coord= mgl_TexCoords[1]; + } else if(idx==2) { + coord= mgl_TexCoords[2]; + } else if(idx==3) { + coord= mgl_TexCoords[3]; + } else if(idx==4) { + coord= mgl_TexCoords[4]; + } else if(idx==5) { + coord= mgl_TexCoords[5]; + } else if(idx==6) { + coord= mgl_TexCoords[6]; + } else { + coord= mgl_TexCoords[7]; + } + return texture2D(tex, coord.st); +} + +void main (void) +{ + if( mgl_CullFace > 0 && + ( ( mgl_CullFace == 1 && gl_FrontFacing ) || + ( mgl_CullFace == 2 && !gl_FrontFacing ) || + ( mgl_CullFace == 3 ) ) ) { + discard; + } + + vec4 texColor = getTexColor(mgl_ActiveTexture,mgl_ActiveTextureIdx); + + if(length(texColor.rgb)>0.0) { + gl_FragColor = vec4(frontColor.rgb*texColor.rgb, frontColor.a) ; + } else { + gl_FragColor = frontColor; + } +} diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bfp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bfp new file mode 100755 index 000000000..3ebaaee1d Binary files /dev/null and b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bfp differ diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bvp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bvp new file mode 100755 index 000000000..279ef72c7 Binary files /dev/null and b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bvp differ diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorLight.bvp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorLight.bvp new file mode 100755 index 000000000..5a9deea71 Binary files /dev/null and b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorLight.bvp differ diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorTexture.bfp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorTexture.bfp new file mode 100755 index 000000000..ce1397fe1 Binary files /dev/null and b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorTexture.bfp differ diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/es_precision.glsl b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/es_precision.glsl new file mode 100644 index 000000000..fd6abe54e --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/es_precision.glsl @@ -0,0 +1,14 @@ +#ifndef es_precision_glsl +#define es_precision_glsl + +#ifdef GL_ES + #define MEDIUMP mediump + #define HIGHP highp + #define LOWP lowp +#else + #define MEDIUMP + #define HIGHP + #define LOWP +#endif + +#endif // es_precision_glsl diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_attribute.glsl b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_attribute.glsl new file mode 100644 index 000000000..b09bdb05a --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_attribute.glsl @@ -0,0 +1,19 @@ + +#ifndef mgl_attribute_glsl +#define mgl_attribute_glsl + +#include es_precision.glsl + +attribute HIGHP vec4 mgl_Vertex; +attribute HIGHP vec3 mgl_Normal; +attribute HIGHP vec4 mgl_Color; +attribute HIGHP vec4 mgl_MultiTexCoord0; +attribute HIGHP vec4 mgl_MultiTexCoord1; +attribute HIGHP vec4 mgl_MultiTexCoord2; +attribute HIGHP vec4 mgl_MultiTexCoord3; +attribute HIGHP vec4 mgl_MultiTexCoord4; +attribute HIGHP vec4 mgl_MultiTexCoord5; +attribute HIGHP vec4 mgl_MultiTexCoord6; +attribute HIGHP vec4 mgl_MultiTexCoord7; + +#endif // mgl_attribute_glsl diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_const.glsl b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_const.glsl new file mode 100644 index 000000000..1a464a1cb --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_const.glsl @@ -0,0 +1,10 @@ + +#ifndef mgl_const_glsl +#define mgl_const_glsl + +#include es_precision.glsl + +const LOWP int MAX_TEXTURE_UNITS = 8; // <=gl_MaxTextureImageUnits +const LOWP int MAX_LIGHTS = 8; + +#endif // mgl_const_glsl diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_lightdef.glsl b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_lightdef.glsl new file mode 100644 index 000000000..98e214139 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_lightdef.glsl @@ -0,0 +1,26 @@ +#ifndef mgl_lightdef_glsl +#define mgl_lightdef_glsl + +struct mgl_LightSourceParameters { + vec4 ambient; + vec4 diffuse; + vec4 specular; + vec4 position; + // vec4 halfVector; // is computed here + vec3 spotDirection; + float spotExponent; + float spotCutoff; // (range: [0.0,90.0], 180.0) + //float spotCosCutoff; // (range: [1.0,0.0],-1.0) + float constantAttenuation; + float linearAttenuation; + float quadraticAttenuation; +}; +struct mgl_MaterialParameters { + vec4 ambient; + vec4 diffuse; + vec4 specular; + vec4 emission; + float shininess; +}; + +#endif // mgl_lightdef_glsl diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_settexcoord.vp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_settexcoord.vp new file mode 100644 index 000000000..1efe328d0 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_settexcoord.vp @@ -0,0 +1,35 @@ +#ifndef mgl_settexcoord_vp +#define mgl_settexcoord_vp + +#include es_precision.glsl + +#include mgl_const.glsl +#include mgl_uniform.glsl +#include mgl_attribute.glsl +#include mgl_varying.glsl + +void setTexCoord(in vec4 defpos) { + /** + * bitwise operator not supported on APX 2500 ES 2.0 + * + mgl_TexCoords[0] = ( 0 != (mgl_TexCoordEnabled & 1) ) ? mgl_MultiTexCoord0 : defpos; + mgl_TexCoords[1] = ( 0 != (mgl_TexCoordEnabled & 2) ) ? mgl_MultiTexCoord1 : defpos; + mgl_TexCoords[2] = ( 0 != (mgl_TexCoordEnabled & 4) ) ? mgl_MultiTexCoord2 : defpos; + mgl_TexCoords[3] = ( 0 != (mgl_TexCoordEnabled & 8) ) ? mgl_MultiTexCoord3 : defpos; + mgl_TexCoords[4] = ( 0 != (mgl_TexCoordEnabled & 16) ) ? mgl_MultiTexCoord4 : defpos; + mgl_TexCoords[5] = ( 0 != (mgl_TexCoordEnabled & 32) ) ? mgl_MultiTexCoord5 : defpos; + mgl_TexCoords[6] = ( 0 != (mgl_TexCoordEnabled & 64) ) ? mgl_MultiTexCoord6 : defpos; + mgl_TexCoords[7] = ( 0 != (mgl_TexCoordEnabled & 128) ) ? mgl_MultiTexCoord7 : defpos; + */ + + mgl_TexCoords[0] = ( 0 != mgl_TexCoordEnabled[0] ) ? mgl_MultiTexCoord0 : defpos; + mgl_TexCoords[1] = ( 0 != mgl_TexCoordEnabled[1] ) ? mgl_MultiTexCoord1 : defpos; + mgl_TexCoords[2] = ( 0 != mgl_TexCoordEnabled[2] ) ? mgl_MultiTexCoord2 : defpos; + mgl_TexCoords[3] = ( 0 != mgl_TexCoordEnabled[3] ) ? mgl_MultiTexCoord3 : defpos; + mgl_TexCoords[4] = ( 0 != mgl_TexCoordEnabled[4] ) ? mgl_MultiTexCoord4 : defpos; + mgl_TexCoords[5] = ( 0 != mgl_TexCoordEnabled[5] ) ? mgl_MultiTexCoord5 : defpos; + mgl_TexCoords[6] = ( 0 != mgl_TexCoordEnabled[6] ) ? mgl_MultiTexCoord6 : defpos; + mgl_TexCoords[7] = ( 0 != mgl_TexCoordEnabled[7] ) ? mgl_MultiTexCoord7 : defpos; +} + +#endif // mgl_settexcoord_vp diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform.glsl b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform.glsl new file mode 100644 index 000000000..d8b3c7f95 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform.glsl @@ -0,0 +1,18 @@ + +#ifndef mgl_uniform_glsl +#define mgl_uniform_glsl + +#include es_precision.glsl + +#include mgl_const.glsl + +uniform HIGHP mat4 mgl_PMVMatrix[3]; // P, Mv, and Mvi +uniform HIGHP mat3 mgl_NormalMatrix; // transpose(inverse(ModelView)).3x3 +uniform LOWP int mgl_ColorEnabled; +uniform HIGHP vec4 mgl_ColorStatic; +uniform LOWP int mgl_TexCoordEnabled[MAX_TEXTURE_UNITS]; +uniform sampler2D mgl_ActiveTexture; +uniform LOWP int mgl_ActiveTextureIdx; +uniform LOWP int mgl_CullFace; + +#endif // mgl_uniform_glsl diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform_light.glsl b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform_light.glsl new file mode 100644 index 000000000..0dedb5d5d --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform_light.glsl @@ -0,0 +1,15 @@ + +#ifndef mgl_uniform_light_glsl +#define mgl_uniform_light_glsl + +#include es_precision.glsl + +#include mgl_const.glsl +#include mgl_lightdef.glsl + +uniform LOWP int mgl_LightsEnabled[MAX_LIGHTS]; + +uniform mgl_LightSourceParameters mgl_LightSource[MAX_LIGHTS]; +uniform mgl_MaterialParameters mgl_FrontMaterial; + +#endif // mgl_uniform_light_glsl diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_varying.glsl b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_varying.glsl new file mode 100644 index 000000000..fc9f735d1 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_varying.glsl @@ -0,0 +1,12 @@ + +#ifndef mgl_varying_glsl +#define mgl_varying_glsl + +#include es_precision.glsl + +#include mgl_const.glsl + +varying vec4 frontColor; +varying vec4 mgl_TexCoords[MAX_TEXTURE_UNITS]; + +#endif // mgl_varying_glsl diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc-ff.bat b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc-ff.bat new file mode 100755 index 000000000..002dca8ef --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc-ff.bat @@ -0,0 +1,9 @@ +REM +REM You have to call it from the 'shaders' directory, e.g.: +REM scripts\nvidia-apx\glslc-ff.bat +REM +IF !"%JOGLDIR%"==""! GOTO YESPATH +set JOGLDIR=..\lib +:YESPATH + +java -cp %JOGLDIR%\jogl.core.jar;%JOGLDIR%\jogl.gles2.jar;%JOGLDIR%\jogl.fixed.jar;%JOGLDIR%\jogl.sdk.jar com.sun.opengl.util.glsl.sdk.CompileShaderNVidia FixedFuncColor.fp FixedFuncColorTexture.fp FixedFuncColorLight.vp FixedFuncColor.vp diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc.bat b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc.bat new file mode 100755 index 000000000..9b5a4b39c --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc.bat @@ -0,0 +1,9 @@ +REM +REM You have to call it from the 'shaders' directory, e.g.: +REM scripts\nvidia-apx\glslc.bat +REM +IF !"%JOGLDIR%"==""! GOTO YESPATH +set JOGLDIR=..\lib +:YESPATH + +java -cp %JOGLDIR%\jogl.core.jar;%JOGLDIR%\jogl.gles2.jar;%JOGLDIR%\jogl.fixed.jar;%JOGLDIR%\jogl.sdk.jar com.sun.opengl.util.glsl.sdk.CompileShaderNVidia %1 diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/sdk/CompileShader.java b/src/jogl/classes/com/sun/opengl/util/glsl/sdk/CompileShader.java index 9b3a48780..f18005feb 100755 --- a/src/jogl/classes/com/sun/opengl/util/glsl/sdk/CompileShader.java +++ b/src/jogl/classes/com/sun/opengl/util/glsl/sdk/CompileShader.java @@ -1,7 +1,7 @@ package com.sun.opengl.util.glsl.sdk; import javax.media.opengl.*; -import com.sun.opengl.impl.io.Locator; +import com.sun.opengl.util.*; import com.sun.opengl.util.glsl.*; import java.io.*; diff --git a/src/jogl/classes/com/sun/opengl/util/packrect/BackingStoreManager.java b/src/jogl/classes/com/sun/opengl/util/packrect/BackingStoreManager.java new file mode 100755 index 000000000..754ba2757 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/packrect/BackingStoreManager.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2006 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 com.sun.opengl.util.packrect; + +/** This interface must be implemented by the end user and is called + in response to events like addition of rectangles into the + RectanglePacker. It is used both when a full re-layout must be + done as well as when the data in the backing store must be copied + to a new one. */ + +public interface BackingStoreManager { + public Object allocateBackingStore(int w, int h); + public void deleteBackingStore(Object backingStore); + + /** Indication whether this BackingStoreManager supports compaction; + in other words, the allocation of a new backing store and + movement of the contents of the backing store from the old to + the new one. If it does not, then RectanglePacker.add() may + throw an exception if additionFailed() can not make enough room + available. If an implementation returns false, this also implies + that the backing store can not grow, so that preExpand() will + never be called. */ + public boolean canCompact(); + + /** Notification that expansion of the backing store is about to be + done due to addition of the given rectangle. Gives the manager a + chance to do some compaction and potentially remove old entries + from the backing store, if it acts like a least-recently-used + cache. This method receives as argument the number of attempts + so far to add the given rectangle. Manager should return true if + the RectanglePacker should retry the addition (which may result + in this method being called again, with an increased attempt + number) or false if the RectanglePacker should just expand the + backing store. The caller should not call RectanglePacker.add() + in its preExpand() method. */ + public boolean preExpand(Rect cause, int attemptNumber); + + /** Notification that addition of the given Rect failed because a + maximum size was set in the RectanglePacker and the backing + store could not be expanded, or because compaction (and, + therefore, implicitly expansion) was not supported. Should + return false if the manager can do nothing more to handle the + failed addition, which will cause a RuntimeException to be + thrown from the RectanglePacker. */ + public boolean additionFailed(Rect cause, int attemptNumber); + + /** Notification that movement is starting. */ + public void beginMovement(Object oldBackingStore, Object newBackingStore); + + /** Tells the manager to move the contents of the given rect from + the old location on the old backing store to the new location on + the new backing store. The backing stores can be identical in + the case of compacting the existing backing store instead of + reallocating it. */ + public void move(Object oldBackingStore, + Rect oldLocation, + Object newBackingStore, + Rect newLocation); + + /** Notification that movement is ending. */ + public void endMovement(Object oldBackingStore, Object newBackingStore); +} diff --git a/src/jogl/classes/com/sun/opengl/util/packrect/Level.java b/src/jogl/classes/com/sun/opengl/util/packrect/Level.java new file mode 100755 index 000000000..3dae4301d --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/packrect/Level.java @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2006 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 com.sun.opengl.util.packrect; + +import java.util.*; + +public class Level { + private int width; + private int height; + private int yPos; + private LevelSet holder; + + private List/**/ rects = new ArrayList/**/(); + private List/**/ freeList; + private int nextAddX; + + static class RectXComparator implements Comparator { + public int compare(Object o1, Object o2) { + Rect r1 = (Rect) o1; + Rect r2 = (Rect) o2; + return r1.x() - r2.x(); + } + + public boolean equals(Object obj) { + return this == obj; + } + } + private static final Comparator rectXComparator = new RectXComparator(); + + public Level(int width, int height, int yPos, LevelSet holder) { + this.width = width; + this.height = height; + this.yPos = yPos; + this.holder = holder; + } + + public int w() { return width; } + public int h() { return height; } + public int yPos() { return yPos; } + + /** Tries to add the given rectangle to this level only allowing + non-disruptive changes like trivial expansion of the last level + in the RectanglePacker and allocation from the free list. More + disruptive changes like compaction of the level must be + requested explicitly. */ + public boolean add(Rect rect) { + if (rect.h() > height) { + // See whether it's worth trying to expand vertically + if (nextAddX + rect.w() > width) { + return false; + } + + // See whether we're the last level and can expand + if (!holder.canExpand(this, rect.h())) { + return false; + } + + // Trivially expand and try the allocation + holder.expand(this, height, rect.h()); + height = rect.h(); + } + + // See whether we can add at the end + if (nextAddX + rect.w() <= width) { + rect.setPosition(nextAddX, yPos); + rects.add(rect); + nextAddX += rect.w(); + return true; + } + + // See whether we can add from the free list + if (freeList != null) { + Rect candidate = null; + for (Iterator iter = freeList.iterator(); iter.hasNext(); ) { + Rect cur = (Rect) iter.next(); + if (cur.canContain(rect)) { + candidate = cur; + break; + } + } + + if (candidate != null) { + // Remove the candidate from the free list + freeList.remove(candidate); + // Set up and add the real rect + rect.setPosition(candidate.x(), candidate.y()); + rects.add(rect); + // Re-add any remaining free space + if (candidate.w() > rect.w()) { + candidate.setPosition(candidate.x() + rect.w(), candidate.y()); + candidate.setSize(candidate.w() - rect.w(), height); + freeList.add(candidate); + } + + coalesceFreeList(); + + return true; + } + } + + return false; + } + + /** Removes the given Rect from this Level. */ + public boolean remove(Rect rect) { + if (!rects.remove(rect)) + return false; + + // If this is the rightmost rectangle, instead of adding its space + // to the free list, we can just decrease the nextAddX + if (rect.maxX() + 1 == nextAddX) { + nextAddX -= rect.w(); + } else { + if (freeList == null) { + freeList = new ArrayList/**/(); + } + freeList.add(new Rect(rect.x(), rect.y(), rect.w(), height, null)); + coalesceFreeList(); + } + + return true; + } + + /** Indicates whether this Level contains no rectangles. */ + public boolean isEmpty() { + return rects.isEmpty(); + } + + /** Indicates whether this Level could satisfy an allocation request + if it were compacted. */ + public boolean couldAllocateIfCompacted(Rect rect) { + if (rect.h() > height) + return false; + if (freeList == null) + return false; + int freeListWidth = 0; + for (Iterator iter = freeList.iterator(); iter.hasNext(); ) { + Rect cur = (Rect) iter.next(); + freeListWidth += cur.w(); + } + // Add on the remaining space at the end + freeListWidth += (width - nextAddX); + return (freeListWidth >= rect.w()); + } + + public void compact(Object backingStore, BackingStoreManager manager) { + Collections.sort(rects, rectXComparator); + int nextCompactionDest = 0; + manager.beginMovement(backingStore, backingStore); + for (Iterator iter = rects.iterator(); iter.hasNext(); ) { + Rect cur = (Rect) iter.next(); + if (cur.x() != nextCompactionDest) { + manager.move(backingStore, cur, + backingStore, new Rect(nextCompactionDest, cur.y(), cur.w(), cur.h(), null)); + cur.setPosition(nextCompactionDest, cur.y()); + } + nextCompactionDest += cur.w(); + } + nextAddX = nextCompactionDest; + freeList.clear(); + manager.endMovement(backingStore, backingStore); + } + + public Iterator iterator() { + return rects.iterator(); + } + + /** Visits all Rects contained in this Level. */ + public void visit(RectVisitor visitor) { + for (Iterator iter = rects.iterator(); iter.hasNext(); ) { + Rect rect = (Rect) iter.next(); + visitor.visit(rect); + } + } + + /** Updates the references to the Rect objects in this Level with + the "next locations" of those Rects. This is actually used to + update the new Rects in a newly laid-out LevelSet with the + original Rects. */ + public void updateRectangleReferences() { + for (int i = 0; i < rects.size(); i++) { + Rect cur = (Rect) rects.get(i); + Rect next = cur.getNextLocation(); + next.setPosition(cur.x(), cur.y()); + if (cur.w() != next.w() || cur.h() != next.h()) + throw new RuntimeException("Unexpected disparity in rectangle sizes during updateRectangleReferences"); + rects.set(i, next); + } + } + + private void coalesceFreeList() { + if (freeList == null) + return; + if (freeList.isEmpty()) + return; + + // Try to coalesce adjacent free blocks in the free list + Collections.sort(freeList, rectXComparator); + int i = 0; + while (i < freeList.size() - 1) { + Rect r1 = (Rect) freeList.get(i); + Rect r2 = (Rect) freeList.get(i+1); + if (r1.maxX() + 1 == r2.x()) { + // Coalesce r1 and r2 into one block + freeList.remove(i+1); + r1.setSize(r1.w() + r2.w(), r1.h()); + } else { + ++i; + } + } + // See whether the last block bumps up against the addition point + Rect last = (Rect) freeList.get(freeList.size() - 1); + if (last.maxX() + 1 == nextAddX) { + nextAddX -= last.w(); + freeList.remove(freeList.size() - 1); + } + if (freeList.isEmpty()) { + freeList = null; + } + } + + //---------------------------------------------------------------------- + // Debugging functionality + // + + public void dumpFreeSpace() { + int freeListWidth = 0; + for (Iterator iter = freeList.iterator(); iter.hasNext(); ) { + Rect cur = (Rect) iter.next(); + System.err.println(" Free rectangle at " + cur); + freeListWidth += cur.w(); + } + // Add on the remaining space at the end + System.err.println(" Remaining free space " + (width - nextAddX)); + freeListWidth += (width - nextAddX); + System.err.println(" Total free space " + freeListWidth); + } +} diff --git a/src/jogl/classes/com/sun/opengl/util/packrect/LevelSet.java b/src/jogl/classes/com/sun/opengl/util/packrect/LevelSet.java new file mode 100755 index 000000000..973980fdc --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/packrect/LevelSet.java @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2006 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 com.sun.opengl.util.packrect; + +import java.util.*; + +/** Manages a list of Levels; this is the core data structure + contained within the RectanglePacker and encompasses the storage + algorithm for the contained Rects. */ + +public class LevelSet { + // Maintained in sorted order by increasing Y coordinate + private List/**/ levels = new ArrayList/**/(); + private int nextAddY; + private int w; + private int h; + + /** A LevelSet manages all of the backing store for a region of a + specified width and height. */ + public LevelSet(int w, int h) { + this.w = w; + this.h = h; + } + + public int w() { return w; } + public int h() { return h; } + + /** Returns true if the given rectangle was successfully added to + the LevelSet given its current dimensions, false if not. Caller + is responsible for performing compaction, expansion, etc. as a + consequence. */ + public boolean add(Rect rect) { + if (rect.w() > w) + return false; + + // Go in reverse order through the levels seeing whether we can + // trivially satisfy the allocation request + for (int i = levels.size() - 1; i >= 0; --i) { + Level level = (Level) levels.get(i); + if (level.add(rect)) + return true; + } + + // See whether compaction could satisfy this allocation. This + // increases the computational complexity of the addition process, + // but prevents us from expanding unnecessarily. + for (int i = levels.size() - 1; i >= 0; --i) { + Level level = (Level) levels.get(i); + if (level.couldAllocateIfCompacted(rect)) + return false; + } + + // OK, we need to either add a new Level or expand the backing + // store. Try to add a new Level. + if (nextAddY + rect.h() > h) + return false; + + Level newLevel = new Level(w, rect.h(), nextAddY, this); + levels.add(newLevel); + nextAddY += rect.h(); + boolean res = newLevel.add(rect); + if (!res) + throw new RuntimeException("Unexpected failure in addition to new Level"); + return true; + } + + /** Removes the given Rect from this LevelSet. */ + public boolean remove(Rect rect) { + for (int i = levels.size() - 1; i >= 0; --i) { + Level level = (Level) levels.get(i); + if (level.remove(rect)) + return true; + } + + return false; + } + + /** Allocates the given Rectangle, performing compaction of a Level + if necessary. This is the correct fallback path to {@link + #add(Rect)} above. Returns true if allocated successfully, false + otherwise (indicating the need to expand the backing store). */ + public boolean compactAndAdd(Rect rect, + Object backingStore, + BackingStoreManager manager) { + for (int i = levels.size() - 1; i >= 0; --i) { + Level level = (Level) levels.get(i); + if (level.couldAllocateIfCompacted(rect)) { + level.compact(backingStore, manager); + boolean res = level.add(rect); + if (!res) + throw new RuntimeException("Unexpected failure to add after compaction"); + return true; + } + } + + return false; + } + + /** Indicates whether it's legal to trivially increase the height of + the given Level. This is only possible if it's the last Level + added and there's enough room in the backing store. */ + public boolean canExpand(Level level, int height) { + if (levels.isEmpty()) + return false; // Should not happen + if (levels.get(levels.size() - 1) == level && + (h - nextAddY >= height - level.h())) + return true; + return false; + } + + public void expand(Level level, int oldHeight, int newHeight) { + nextAddY += (newHeight - oldHeight); + } + + /** Gets the used height of the levels in this LevelSet. */ + public int getUsedHeight() { + return nextAddY; + } + + /** Sets the height of this LevelSet. It is only legal to reduce the + height to greater than or equal to the currently used height. */ + public void setHeight(int height) throws IllegalArgumentException { + if (height < getUsedHeight()) { + throw new IllegalArgumentException("May not reduce height below currently used height"); + } + h = height; + } + + /** Returns the vertical fragmentation ratio of this LevelSet. This + is defined as the ratio of the sum of the heights of all + completely empty Levels divided by the overall used height of + the LevelSet. A high vertical fragmentation ratio indicates that + it may be profitable to perform a compaction. */ + public float verticalFragmentationRatio() { + int freeHeight = 0; + int usedHeight = getUsedHeight(); + if (usedHeight == 0) + return 0.0f; + for (Iterator iter = iterator(); iter.hasNext(); ) { + Level level = (Level) iter.next(); + if (level.isEmpty()) { + freeHeight += level.h(); + } + } + return (float) freeHeight / (float) usedHeight; + } + + public Iterator iterator() { + return levels.iterator(); + } + + /** Visits all Rects contained in this LevelSet. */ + public void visit(RectVisitor visitor) { + for (Iterator iter = levels.iterator(); iter.hasNext(); ) { + Level level = (Level) iter.next(); + level.visit(visitor); + } + } + + /** Updates the references to the Rect objects in this LevelSet with + the "next locations" of those Rects. This is actually used to + update the new Rects in a newly laid-out LevelSet with the + original Rects. */ + public void updateRectangleReferences() { + for (Iterator iter = levels.iterator(); iter.hasNext(); ) { + Level level = (Level) iter.next(); + level.updateRectangleReferences(); + } + } + + /** Clears out all Levels stored in this LevelSet. */ + public void clear() { + levels.clear(); + nextAddY = 0; + } +} diff --git a/src/jogl/classes/com/sun/opengl/util/packrect/Rect.java b/src/jogl/classes/com/sun/opengl/util/packrect/Rect.java new file mode 100755 index 000000000..2f12981a6 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/packrect/Rect.java @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2006 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 com.sun.opengl.util.packrect; + +/** Represents a rectangular region on the backing store. The edges of + the rectangle are the infinitely thin region between adjacent + pixels on the screen. The origin of the rectangle is its + upper-left corner. It is inclusive of the pixels on the top and + left edges and exclusive of the pixels on the bottom and right + edges. For example, a rect at position (0, 0) and of size (1, 1) + would include only the pixel at (0, 0).

+ + Negative coordinates and sizes are not supported, since they make + no sense in the context of the packer, which deals only with + positively sized regions.

+ + This class contains a user data field for efficient hookup to + external data structures as well as enough other hooks to + efficiently plug into the rectangle packer. */ + +public class Rect { + private int x; + private int y; + private int w; + private int h; + + // The level we're currently installed in in the parent + // RectanglePacker, or null if not hooked in to the table yet + private Level level; + + // The user's object this rectangle represents. + private Object userData; + + // Used transiently during re-layout of the backing store (when + // there is no room left due either to fragmentation or just being + // out of space) + private Rect nextLocation; + + public Rect() { + this(null); + } + + public Rect(Object userData) { + this(0, 0, 0, 0, userData); + } + + public Rect(int x, int y, int w, int h, Object userData) { + setPosition(x, y); + setSize(w, h); + setUserData(userData); + } + + public int x() { return x; } + public int y() { return y; } + public int w() { return w; } + public int h() { return h; } + public Object getUserData() { return userData; } + public Rect getNextLocation() { return nextLocation; } + + public void setPosition(int x, int y) { + if (x < 0) + throw new IllegalArgumentException("Negative x"); + if (y < 0) + throw new IllegalArgumentException("Negative y"); + this.x = x; + this.y = y; + } + + public void setSize(int w, int h) throws IllegalArgumentException { + if (w < 0) + throw new IllegalArgumentException("Negative width"); + if (h < 0) + throw new IllegalArgumentException("Negative height"); + this.w = w; + this.h = h; + } + + public void setUserData(Object obj) { userData = obj; } + public void setNextLocation(Rect nextLocation) { this.nextLocation = nextLocation; } + + // Helpers for computations. + + /** Returns the maximum x-coordinate contained within this + rectangle. Note that this returns a different result than Java + 2D's rectangles; for a rectangle of position (0, 0) and size (1, + 1) this will return 0, not 1. Returns -1 if the width of this + rectangle is 0. */ + public int maxX() { + if (w() < 1) + return -1; + return x() + w() - 1; + } + + /** Returns the maximum y-coordinate contained within this + rectangle. Note that this returns a different result than Java + 2D's rectangles; for a rectangle of position (0, 0) and size (1, + 1) this will return 0, not 1. Returns -1 if the height of this + rectangle is 0. */ + public int maxY() { + if (h() < 1) + return -1; + return y() + h() - 1; + } + + public boolean canContain(Rect other) { + return (w() >= other.w() && + h() >= other.h()); + } + + public String toString() { + return "[Rect x: " + x() + " y: " + y() + " w: " + w() + " h: " + h() + "]"; + } + + // Unclear whether it's a good idea to override hashCode and equals + // for these objects + /* + public boolean equals(Object other) { + if (other == null || (!(other instanceof Rect))) { + return false; + } + + Rect r = (Rect) other; + return (this.x() == r.x() && + this.y() == r.y() && + this.w() == r.w() && + this.h() == r.h()); + } + + public int hashCode() { + return (x + y * 13 + w * 17 + h * 23); + } + */ +} diff --git a/src/jogl/classes/com/sun/opengl/util/packrect/RectVisitor.java b/src/jogl/classes/com/sun/opengl/util/packrect/RectVisitor.java new file mode 100755 index 000000000..8f395ed99 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/packrect/RectVisitor.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2006 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 com.sun.opengl.util.packrect; + +/** Iteration construct without exposing the internals of the + RectanglePacker and without implementing a complex Iterator. */ + +public interface RectVisitor { + public void visit(Rect rect); +} diff --git a/src/jogl/classes/com/sun/opengl/util/packrect/RectanglePacker.java b/src/jogl/classes/com/sun/opengl/util/packrect/RectanglePacker.java new file mode 100755 index 000000000..51e6842c0 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/packrect/RectanglePacker.java @@ -0,0 +1,306 @@ +/* + * Copyright (c) 2006 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 com.sun.opengl.util.packrect; + +import java.util.*; + +/** Packs rectangles supplied by the user (typically representing + image regions) into a larger backing store rectangle (typically + representing a large texture). Supports automatic compaction of + the space on the backing store, and automatic expansion of the + backing store, when necessary. */ + +public class RectanglePacker { + private BackingStoreManager manager; + private Object backingStore; + private LevelSet levels; + private float EXPANSION_FACTOR = 0.5f; + private float SHRINK_FACTOR = 0.3f; + + private int initialWidth; + private int initialHeight; + + private int maxWidth = -1; + private int maxHeight = -1; + + static class RectHComparator implements Comparator { + public int compare(Object o1, Object o2) { + Rect r1 = (Rect) o1; + Rect r2 = (Rect) o2; + return r2.h() - r1.h(); + } + + public boolean equals(Object obj) { + return this == obj; + } + } + private static final Comparator rectHComparator = new RectHComparator(); + + public RectanglePacker(BackingStoreManager manager, + int initialWidth, + int initialHeight) { + this.manager = manager; + levels = new LevelSet(initialWidth, initialHeight); + this.initialWidth = initialWidth; + this.initialHeight = initialHeight; + } + + public Object getBackingStore() { + if (backingStore == null) { + backingStore = manager.allocateBackingStore(levels.w(), levels.h()); + } + + return backingStore; + } + + /** Sets up a maximum width and height for the backing store. These + are optional and if not specified the backing store will grow as + necessary. Setting up a maximum width and height introduces the + possibility that additions will fail; these are handled with the + BackingStoreManager's allocationFailed notification. */ + public void setMaxSize(int maxWidth, int maxHeight) { + this.maxWidth = maxWidth; + this.maxHeight = maxHeight; + } + + /** Decides upon an (x, y) position for the given rectangle (leaving + its width and height unchanged) and places it on the backing + store. May provoke re-layout of other Rects already added. If + the BackingStoreManager does not support compaction, and {@link + BackingStoreManager#preExpand BackingStoreManager.preExpand} + does not clear enough space for the incoming rectangle, then + this method will throw a RuntimeException. */ + public void add(Rect rect) throws RuntimeException { + // Allocate backing store if we don't have any yet + if (backingStore == null) + backingStore = manager.allocateBackingStore(levels.w(), levels.h()); + + int attemptNumber = 0; + boolean tryAgain = false; + + do { + // Try to allocate + if (levels.add(rect)) + return; + + if (manager.canCompact()) { + // Try to allocate with horizontal compaction + if (levels.compactAndAdd(rect, backingStore, manager)) + return; + // Let the manager have a chance at potentially evicting some entries + tryAgain = manager.preExpand(rect, attemptNumber++); + } else { + tryAgain = manager.additionFailed(rect, attemptNumber++); + } + } while (tryAgain); + + if (!manager.canCompact()) { + throw new RuntimeException("BackingStoreManager does not support compaction or expansion, and didn't clear space for new rectangle"); + } + + compactImpl(rect); + + // Retry the addition of the incoming rectangle + add(rect); + // Done + } + + /** Removes the given rectangle from this RectanglePacker. */ + public void remove(Rect rect) { + levels.remove(rect); + } + + /** Visits all Rects contained in this RectanglePacker. */ + public void visit(RectVisitor visitor) { + levels.visit(visitor); + } + + /** Returns the vertical fragmentation ratio of this + RectanglePacker. This is defined as the ratio of the sum of the + heights of all completely empty Levels divided by the overall + used height of the LevelSet. A high vertical fragmentation ratio + indicates that it may be profitable to perform a compaction. */ + public float verticalFragmentationRatio() { + return levels.verticalFragmentationRatio(); + } + + /** Forces a compaction cycle, which typically results in allocating + a new backing store and copying all entries to it. */ + public void compact() { + compactImpl(null); + } + + // The "cause" rect may be null + private void compactImpl(Rect cause) { + // Have to either expand, compact or both. Need to figure out what + // direction to go. Prefer to expand vertically. Expand + // horizontally only if rectangle being added is too wide. FIXME: + // may want to consider rebalancing the width and height to be + // more equal if it turns out we keep expanding in the vertical + // direction. + boolean done = false; + int newWidth = levels.w(); + int newHeight = levels.h(); + LevelSet nextLevelSet = null; + int attemptNumber = 0; + boolean needAdditionFailureNotification = false; + + while (!done) { + if (cause != null) { + if (cause.w() > newWidth) { + newWidth = cause.w(); + } else { + newHeight = (int) (newHeight * (1.0f + EXPANSION_FACTOR)); + } + } + + // Clamp to maximum values + needAdditionFailureNotification = false; + if (maxWidth > 0 && newWidth > maxWidth) { + newWidth = maxWidth; + needAdditionFailureNotification = true; + } + if (maxHeight > 0 && newHeight > maxHeight) { + newHeight = maxHeight; + needAdditionFailureNotification = true; + } + + nextLevelSet = new LevelSet(newWidth, newHeight); + + // Make copies of all existing rectangles + List/**/ newRects = new ArrayList/**/(); + for (Iterator i1 = levels.iterator(); i1.hasNext(); ) { + Level level = (Level) i1.next(); + for (Iterator i2 = level.iterator(); i2.hasNext(); ) { + Rect cur = (Rect) i2.next(); + Rect newRect = new Rect(0, 0, cur.w(), cur.h(), null); + cur.setNextLocation(newRect); + // Hook up the reverse mapping too for easier replacement + newRect.setNextLocation(cur); + newRects.add(newRect); + } + } + // Sort them by decreasing height (note: this isn't really + // guaranteed to improve the chances of a successful layout) + Collections.sort(newRects, rectHComparator); + // Try putting all of these rectangles into the new level set + done = true; + for (Iterator iter = newRects.iterator(); iter.hasNext(); ) { + if (!nextLevelSet.add((Rect) iter.next())) { + done = false; + break; + } + } + + if (done && cause != null) { + // Try to add the new rectangle as well + if (nextLevelSet.add(cause)) { + // We're OK + } else { + done = false; + } + } + + // Don't send addition failure notifications if we're only doing + // a compaction + if (!done && needAdditionFailureNotification && cause != null) { + manager.additionFailed(cause, attemptNumber); + } + ++attemptNumber; + } + + // See whether the implicit compaction that just occurred has + // yielded excess empty space. + if (nextLevelSet.getUsedHeight() > 0 && + nextLevelSet.getUsedHeight() < nextLevelSet.h() * SHRINK_FACTOR) { + int shrunkHeight = Math.max(initialHeight, + (int) (nextLevelSet.getUsedHeight() * (1.0f + EXPANSION_FACTOR))); + if (maxHeight > 0 && shrunkHeight > maxHeight) { + shrunkHeight = maxHeight; + } + nextLevelSet.setHeight(shrunkHeight); + } + + // If we temporarily added the new rectangle to the new LevelSet, + // take it out since we don't "really" add it here but in add(), above + if (cause != null) { + nextLevelSet.remove(cause); + } + + // OK, now we have a new layout and a mapping from the old to the + // new locations of rectangles on the backing store. Allocate a + // new backing store, move the contents over and deallocate the + // old one. + Object newBackingStore = manager.allocateBackingStore(nextLevelSet.w(), + nextLevelSet.h()); + manager.beginMovement(backingStore, newBackingStore); + for (Iterator i1 = levels.iterator(); i1.hasNext(); ) { + Level level = (Level) i1.next(); + for (Iterator i2 = level.iterator(); i2.hasNext(); ) { + Rect cur = (Rect) i2.next(); + manager.move(backingStore, cur, + newBackingStore, cur.getNextLocation()); + } + } + // Replace references to temporary rectangles with original ones + nextLevelSet.updateRectangleReferences(); + manager.endMovement(backingStore, newBackingStore); + // Now delete the old backing store + manager.deleteBackingStore(backingStore); + // Update to new versions of backing store and LevelSet + backingStore = newBackingStore; + levels = nextLevelSet; + } + + /** Clears all Rects contained in this RectanglePacker. */ + public void clear() { + levels.clear(); + } + + /** Disposes the backing store allocated by the + BackingStoreManager. This RectanglePacker may no longer be used + after calling this method. */ + public void dispose() { + if (backingStore != null) + manager.deleteBackingStore(backingStore); + backingStore = null; + levels = null; + } +} diff --git a/src/jogl/classes/com/sun/opengl/util/packrect/package.html b/src/jogl/classes/com/sun/opengl/util/packrect/package.html new file mode 100755 index 000000000..7f2522244 --- /dev/null +++ b/src/jogl/classes/com/sun/opengl/util/packrect/package.html @@ -0,0 +1,7 @@ +This package implements a rectangle packing algorithm suitable for +tracking the placement of multiple rectangles inside a larger one. It +is useful for cases such as placing the contents of multiple windows +on a larger backing store texture for a compositing window manager; +placing multiple rasterized strings in a texture map for quick +rendering to the screen; and many other situations where it is useful +to carve up a larger texture into smaller pieces dynamically.

diff --git a/src/jogl/classes/com/sun/opengl/util/texture/spi/DDSImage.java.javase b/src/jogl/classes/com/sun/opengl/util/texture/spi/DDSImage.java.javase index cca8dbd2b..8a3e1c4be 100755 --- a/src/jogl/classes/com/sun/opengl/util/texture/spi/DDSImage.java.javase +++ b/src/jogl/classes/com/sun/opengl/util/texture/spi/DDSImage.java.javase @@ -44,7 +44,7 @@ import java.nio.*; import java.nio.channels.*; import javax.media.opengl.*; -import javax.media.opengl.util.*; +import com.sun.opengl.util.*; import com.sun.opengl.util.texture.*; /** A reader and writer for DirectDraw Surface (.dds) files, which are 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/fixedfunc/GLLightingFunc.java b/src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java new file mode 100644 index 000000000..5563ea9c8 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java @@ -0,0 +1,49 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + */ + +package javax.media.opengl.fixedfunc; + +import java.nio.*; + +import javax.media.opengl.*; + +public interface GLLightingFunc { + public static final int GL_LIGHT0 = 0x4000; + public static final int GL_LIGHT1 = 0x4001; + public static final int GL_LIGHT2 = 0x4002; + public static final int GL_LIGHT3 = 0x4003; + public static final int GL_LIGHT4 = 0x4004; + public static final int GL_LIGHT5 = 0x4005; + public static final int GL_LIGHT6 = 0x4006; + public static final int GL_LIGHT7 = 0x4007; + public static final int GL_LIGHTING = 0xB50; + public static final int GL_AMBIENT = 0x1200; + public static final int GL_DIFFUSE = 0x1201; + public static final int GL_SPECULAR = 0x1202; + public static final int GL_POSITION = 0x1203; + public static final int GL_SPOT_DIRECTION = 0x1204; + public static final int GL_SPOT_EXPONENT = 0x1205; + public static final int GL_SPOT_CUTOFF = 0x1206; + public static final int GL_CONSTANT_ATTENUATION = 0x1207; + public static final int GL_LINEAR_ATTENUATION = 0x1208; + public static final int GL_QUADRATIC_ATTENUATION = 0x1209; + public static final int GL_EMISSION = 0x1600; + public static final int GL_SHININESS = 0x1601; + public static final int GL_AMBIENT_AND_DIFFUSE = 0x1602; + public static final int GL_COLOR_MATERIAL = 0xB57; + public static final int GL_NORMALIZE = 0xBA1; + + public static final int GL_FLAT = 0x1D00; + public static final int GL_SMOOTH = 0x1D01; + + public void glLightfv(int light, int pname, java.nio.FloatBuffer params); + public void glLightfv(int light, int pname, float[] params, int params_offset); + public void glMaterialf(int face, int pname, float param); + public void glMaterialfv(int face, int pname, java.nio.FloatBuffer params); + public void glMaterialfv(int face, int pname, float[] params, int params_offset); + public void glColor4f(float red, float green, float blue, float alpha); + public void glShadeModel(int mode); + +} + diff --git a/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java b/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java new file mode 100644 index 000000000..61757abde --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java @@ -0,0 +1,76 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + */ + +package javax.media.opengl.fixedfunc; + +import java.nio.*; + +import javax.media.opengl.*; + +public interface GLMatrixFunc { + + public static final int GL_MATRIX_MODE = 0x0BA0; + public static final int GL_MODELVIEW = 0x1700; + public static final int GL_PROJECTION = 0x1701; + // public static final int GL_TEXTURE = 0x1702; // Use GL.GL_TEXTURE due to ambiguous GL usage + public static final int GL_MODELVIEW_MATRIX = 0x0BA6; + public static final int GL_PROJECTION_MATRIX = 0x0BA7; + public static final int GL_TEXTURE_MATRIX = 0x0BA8; + + /** + * glGetFloatv + * @param pname GL_MODELVIEW_MATRIX, GL_PROJECTION_MATRIX or GL_TEXTURE_MATRIX + * @param params the FloatBuffer's position remains unchanged, + * which is the same behavior than the native JOGL GL impl + */ + public void glGetFloatv(int pname, java.nio.FloatBuffer params); + public void glGetFloatv(int pname, float[] params, int params_offset); + /** + * glGetIntegerv + * @param pname GL_MATRIX_MODE + * @param params the FloatBuffer's position remains unchanged + * which is the same behavior than the native JOGL GL impl + */ + public void glGetIntegerv(int pname, IntBuffer params); + public void glGetIntegerv(int pname, int[] params, int params_offset); + + /** + * sets the current matrix + * @param pname GL_MODELVIEW, GL_PROJECTION or GL.GL_TEXTURE + */ + public void glMatrixMode(int mode) ; + + public void glPushMatrix(); + public void glPopMatrix(); + + public void glLoadIdentity() ; + + /** + * glLoadMatrixf + * @param params the FloatBuffer's position remains unchanged, + * which is the same behavior than the native JOGL GL impl + */ + public void glLoadMatrixf(java.nio.FloatBuffer m) ; + public void glLoadMatrixf(float[] m, int m_offset); + + /** + * glMultMatrixf + * @param params the FloatBuffer's position remains unchanged, + * which is the same behavior than the native JOGL GL impl + */ + public void glMultMatrixf(java.nio.FloatBuffer m) ; + public void glMultMatrixf(float[] m, int m_offset); + + public void glTranslatef(float x, float y, float z) ; + + public void glRotatef(float angle, float x, float y, float z); + + public void glScalef(float x, float y, float z) ; + + public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) ; + + public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar); + +} + diff --git a/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java b/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java new file mode 100644 index 000000000..ed7bef5d4 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java @@ -0,0 +1,38 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + */ + +package javax.media.opengl.fixedfunc; + +import java.nio.*; + +import javax.media.opengl.*; + +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; + public static final int GL_TEXTURE_COORD_ARRAY = 0x8078; + + public void glEnableClientState(int arrayName); + public void glDisableClientState(int arrayName); + + public void glVertexPointer(GLArrayData array); + public void glVertexPointer(int size, int type, int stride, java.nio.Buffer pointer); + public void glVertexPointer(int size, int type, int stride, long pointer_buffer_offset); + + public void glColorPointer(GLArrayData array); + public void glColorPointer(int size, int type, int stride, java.nio.Buffer pointer); + public void glColorPointer(int size, int type, int stride, long pointer_buffer_offset); + public void glColor4f(float red, float green, float blue, float alpha); + + public void glNormalPointer(GLArrayData array); + public void glNormalPointer(int type, int stride, java.nio.Buffer pointer); + public void glNormalPointer(int type, int stride, long pointer_buffer_offset); + + public void glTexCoordPointer(GLArrayData array); + public void glTexCoordPointer(int size, int type, int stride, java.nio.Buffer pointer); + public void glTexCoordPointer(int size, int type, int stride, long pointer_buffer_offset); + +} + 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/sub/fixed/GLLightingIf.java b/src/jogl/classes/javax/media/opengl/sub/fixed/GLLightingIf.java deleted file mode 100644 index 1f3aa9ab7..000000000 --- a/src/jogl/classes/javax/media/opengl/sub/fixed/GLLightingIf.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. - */ - -package javax.media.opengl.sub.fixed; - -import java.nio.*; - -import javax.media.opengl.*; -import javax.media.opengl.sub.*; - -public interface GLLightingIf { - public static final int GL_LIGHT0 = 0x4000; - public static final int GL_LIGHT1 = 0x4001; - public static final int GL_LIGHT2 = 0x4002; - public static final int GL_LIGHT3 = 0x4003; - public static final int GL_LIGHT4 = 0x4004; - public static final int GL_LIGHT5 = 0x4005; - public static final int GL_LIGHT6 = 0x4006; - public static final int GL_LIGHT7 = 0x4007; - public static final int GL_LIGHTING = 0xB50; - public static final int GL_AMBIENT = 0x1200; - public static final int GL_DIFFUSE = 0x1201; - public static final int GL_SPECULAR = 0x1202; - public static final int GL_POSITION = 0x1203; - public static final int GL_SPOT_DIRECTION = 0x1204; - public static final int GL_SPOT_EXPONENT = 0x1205; - public static final int GL_SPOT_CUTOFF = 0x1206; - public static final int GL_CONSTANT_ATTENUATION = 0x1207; - public static final int GL_LINEAR_ATTENUATION = 0x1208; - public static final int GL_QUADRATIC_ATTENUATION = 0x1209; - public static final int GL_EMISSION = 0x1600; - public static final int GL_SHININESS = 0x1601; - public static final int GL_AMBIENT_AND_DIFFUSE = 0x1602; - public static final int GL_COLOR_MATERIAL = 0xB57; - public static final int GL_NORMALIZE = 0xBA1; - - public static final int GL_FLAT = 0x1D00; - public static final int GL_SMOOTH = 0x1D01; - - public void glLightfv(int light, int pname, java.nio.FloatBuffer params); - public void glLightfv(int light, int pname, float[] params, int params_offset); - public void glMaterialf(int face, int pname, float param); - public void glMaterialfv(int face, int pname, java.nio.FloatBuffer params); - public void glMaterialfv(int face, int pname, float[] params, int params_offset); - public void glColor4f(float red, float green, float blue, float alpha); - public void glShadeModel(int mode); - -} - diff --git a/src/jogl/classes/javax/media/opengl/sub/fixed/GLMatrixIf.java b/src/jogl/classes/javax/media/opengl/sub/fixed/GLMatrixIf.java deleted file mode 100644 index 834731b98..000000000 --- a/src/jogl/classes/javax/media/opengl/sub/fixed/GLMatrixIf.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. - */ - -package javax.media.opengl.sub.fixed; - -import java.nio.*; - -import javax.media.opengl.*; -import javax.media.opengl.sub.*; - -public interface GLMatrixIf { - - public static final int GL_MATRIX_MODE = 0x0BA0; - public static final int GL_MODELVIEW = 0x1700; - public static final int GL_PROJECTION = 0x1701; - // public static final int GL_TEXTURE = 0x1702; // Use GL.GL_TEXTURE due to ambiguous GL usage - public static final int GL_MODELVIEW_MATRIX = 0x0BA6; - public static final int GL_PROJECTION_MATRIX = 0x0BA7; - public static final int GL_TEXTURE_MATRIX = 0x0BA8; - - /** - * glGetFloatv - * @param pname GL_MODELVIEW_MATRIX, GL_PROJECTION_MATRIX or GL_TEXTURE_MATRIX - * @param params the FloatBuffer's position remains unchanged, - * which is the same behavior than the native JOGL GL impl - */ - public void glGetFloatv(int pname, java.nio.FloatBuffer params); - public void glGetFloatv(int pname, float[] params, int params_offset); - /** - * glGetIntegerv - * @param pname GL_MATRIX_MODE - * @param params the FloatBuffer's position remains unchanged - * which is the same behavior than the native JOGL GL impl - */ - public void glGetIntegerv(int pname, IntBuffer params); - public void glGetIntegerv(int pname, int[] params, int params_offset); - - /** - * sets the current matrix - * @param pname GL_MODELVIEW, GL_PROJECTION or GL.GL_TEXTURE - */ - public void glMatrixMode(int mode) ; - - public void glPushMatrix(); - public void glPopMatrix(); - - public void glLoadIdentity() ; - - /** - * glLoadMatrixf - * @param params the FloatBuffer's position remains unchanged, - * which is the same behavior than the native JOGL GL impl - */ - public void glLoadMatrixf(java.nio.FloatBuffer m) ; - public void glLoadMatrixf(float[] m, int m_offset); - - /** - * glMultMatrixf - * @param params the FloatBuffer's position remains unchanged, - * which is the same behavior than the native JOGL GL impl - */ - public void glMultMatrixf(java.nio.FloatBuffer m) ; - public void glMultMatrixf(float[] m, int m_offset); - - public void glTranslatef(float x, float y, float z) ; - - public void glRotatef(float angle, float x, float y, float z); - - public void glScalef(float x, float y, float z) ; - - public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) ; - - public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar); - -} - diff --git a/src/jogl/classes/javax/media/opengl/sub/fixed/GLPointerIf.java b/src/jogl/classes/javax/media/opengl/sub/fixed/GLPointerIf.java deleted file mode 100644 index 2f4cda1aa..000000000 --- a/src/jogl/classes/javax/media/opengl/sub/fixed/GLPointerIf.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. - */ - -package javax.media.opengl.sub.fixed; - -import java.nio.*; - -import javax.media.opengl.*; -import javax.media.opengl.sub.*; - -public interface GLPointerIf { - public static final int GL_VERTEX_ARRAY = 0x8074; - public static final int GL_NORMAL_ARRAY = 0x8075; - public static final int GL_COLOR_ARRAY = 0x8076; - public static final int GL_TEXTURE_COORD_ARRAY = 0x8078; - - public void glEnableClientState(int arrayName); - public void glDisableClientState(int arrayName); - - public void glVertexPointer(GLArrayData array); - public void glVertexPointer(int size, int type, int stride, java.nio.Buffer pointer); - public void glVertexPointer(int size, int type, int stride, long pointer_buffer_offset); - - public void glColorPointer(GLArrayData array); - public void glColorPointer(int size, int type, int stride, java.nio.Buffer pointer); - public void glColorPointer(int size, int type, int stride, long pointer_buffer_offset); - public void glColor4f(float red, float green, float blue, float alpha); - - public void glNormalPointer(GLArrayData array); - public void glNormalPointer(int type, int stride, java.nio.Buffer pointer); - public void glNormalPointer(int type, int stride, long pointer_buffer_offset); - - public void glTexCoordPointer(GLArrayData array); - public void glTexCoordPointer(int size, int type, int stride, java.nio.Buffer pointer); - public void glTexCoordPointer(int size, int type, int stride, long pointer_buffer_offset); - -} - 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 remaining elements (as defined by - limit() - position()) 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 remaining elements (as defined by - limit() - position()) 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 remaining elements (as defined by - limit() - position()) 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 remaining elements (as defined by - limit() - position()) 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 remaining elements (as defined by - limit() - position()) 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 remaining elements (as defined by - limit() - position()) 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 remaining elements (as defined by - limit() - position()) 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 remaining elements (as defined by - limit() - position()) 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 remaining elements (as defined by - limit() - position()) 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 remaining elements (as defined by - limit() - position()) 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 remaining elements (as defined by - limit() - position()) 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 remaining elements (as defined by - limit() - position()) 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 remaining elements (as defined by - limit() - position()) 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 remaining elements (as defined by - limit() - position()) 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.

- - 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.

- * - * 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. System.exit() from the application rather than - * rely on the shutdown hook functionality due to inevitable race - * conditions and unspecified behavior during JVM teardown.

- * - * 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.

- * - * @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; -} diff --git a/src/jogl/native/GLXGetProcAddressARB.c b/src/jogl/native/GLXGetProcAddressARB.c new file mode 100644 index 000000000..6e9f6c3c2 --- /dev/null +++ b/src/jogl/native/GLXGetProcAddressARB.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2003-2009 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 + * MIDROSYSTEMS, 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. + */ + +#if defined(__sun) || defined(_HPUX) +#include + +/* HP-UX doesn't define RTLD_DEFAULT. */ +#if defined(_HPUX) && !defined(RTLD_DEFAULT) +#define RTLD_DEFAULT NULL +#endif + +/* Sun's GLX implementation doesn't have glXGetProcAddressARB (or + glXGetProcAddress) so we implement it here */ +void (*glXGetProcAddressARB(const char *procname))() { + return (void (*)()) dlsym(RTLD_DEFAULT, procname); +} +#endif /* __ sun || _HPUX */ diff --git a/src/jogl/native/InternalBufferUtils.c b/src/jogl/native/InternalBufferUtils.c deleted file mode 100644 index 4b2001a34..000000000 --- a/src/jogl/native/InternalBufferUtils.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2003 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 - * MIDROSYSTEMS, 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. - */ - -#include - -#ifdef _WIN32 - #ifdef _MSC_VER - /* This typedef is apparently needed for Microsoft compilers before VC8, - and on Windows CE */ - #if (_MSC_VER < 1400) || defined(UNDER_CE) - #ifdef _WIN64 - typedef long long intptr_t; - #else - typedef int intptr_t; - #endif - #endif - #else - #include - #endif -#else - #include -#endif - -JNIEXPORT jobject JNICALL -Java_com_sun_opengl_impl_InternalBufferUtils_newDirectByteBuffer(JNIEnv* env, jclass unused, jlong address, jint capacity) { - return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) address, capacity); -} - -#if defined(__sun) || defined(_HPUX) -#include - -/* HP-UX doesn't define RTLD_DEFAULT. */ -#if defined(_HPUX) && !defined(RTLD_DEFAULT) -#define RTLD_DEFAULT NULL -#endif - -/* Sun's GLX implementation doesn't have glXGetProcAddressARB (or - glXGetProcAddress) so we implement it here */ -void (*glXGetProcAddressARB(const char *procname))() { - return (void (*)()) dlsym(RTLD_DEFAULT, procname); -} -#endif /* __ sun || _HPUX */ -- cgit v1.2.3