aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/javax
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/javax')
-rw-r--r--src/classes/javax/media/opengl/GLAutoDrawable.java6
-rw-r--r--src/classes/javax/media/opengl/GLContext.java54
-rw-r--r--src/classes/javax/media/opengl/GLProfile.java17
-rw-r--r--src/classes/javax/media/opengl/NativeWindowFactory.java3
-rw-r--r--src/classes/javax/media/opengl/awt/GLCanvas.java4
-rw-r--r--src/classes/javax/media/opengl/awt/GLJPanel.java25
-rw-r--r--src/classes/javax/media/opengl/sub/GLObject.java75
-rw-r--r--src/classes/javax/media/opengl/sub/fixed/GLFixedFuncHookIf.java33
-rw-r--r--src/classes/javax/media/opengl/sub/fixed/GLFixedFuncIf.java18
-rw-r--r--src/classes/javax/media/opengl/sub/fixed/GLFixedFuncUtil.java50
-rw-r--r--src/classes/javax/media/opengl/sub/fixed/GLLightingIf.java50
-rw-r--r--src/classes/javax/media/opengl/sub/fixed/GLMatrixIf.java77
-rw-r--r--src/classes/javax/media/opengl/sub/fixed/GLPointerIf.java39
-rw-r--r--src/classes/javax/media/opengl/util/ImmModeSink.java57
-rwxr-xr-xsrc/classes/javax/media/opengl/util/PMVMatrix.java426
15 files changed, 788 insertions, 146 deletions
diff --git a/src/classes/javax/media/opengl/GLAutoDrawable.java b/src/classes/javax/media/opengl/GLAutoDrawable.java
index d4aff9107..743cbc143 100644
--- a/src/classes/javax/media/opengl/GLAutoDrawable.java
+++ b/src/classes/javax/media/opengl/GLAutoDrawable.java
@@ -56,9 +56,15 @@ public interface GLAutoDrawable extends GLDrawable {
/**
* Returns the context associated with this drawable. The returned
* context will be synchronized.
+ * Don't rely on it's identity, the context may change.
*/
public GLContext getContext();
+ /**
+ * Associate a new context to this drawable.
+ */
+ public void setContext(GLContext context);
+
/** Adds a {@link GLEventListener} to this drawable. If multiple
listeners are added to a given drawable, they are notified of
events in an arbitrary order. */
diff --git a/src/classes/javax/media/opengl/GLContext.java b/src/classes/javax/media/opengl/GLContext.java
index ae9c11786..57569af2a 100644
--- a/src/classes/javax/media/opengl/GLContext.java
+++ b/src/classes/javax/media/opengl/GLContext.java
@@ -39,6 +39,10 @@
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
OpenGL rendering, a context must be "made current" on the current
thread. OpenGL rendering semantics specify that only one context
@@ -53,6 +57,8 @@ package javax.media.opengl;
refer to a given context. */
public abstract class GLContext {
+ protected static final boolean DEBUG = Debug.debug("GLContext");
+
/** Indicates that the context was not made current during the last call to {@link #makeCurrent makeCurrent}. */
public static final int CONTEXT_NOT_CURRENT = 0;
/** Indicates that the context was made current during the last call to {@link #makeCurrent makeCurrent}. */
@@ -62,6 +68,8 @@ public abstract class GLContext {
private static ThreadLocal currentContext = new ThreadLocal();
+ private HashMap/*<int, Object>*/ attachedObjects = new HashMap();
+
/**
* Returns the GLDrawable to which this context may be used to
* draw.
@@ -158,6 +166,11 @@ public abstract class GLContext {
* new GLContext implementations; not for use by end users.
*/
protected static void setCurrent(GLContext cur) {
+ if(DEBUG) {
+ Exception e = new Exception("setCurrent: "+Thread.currentThread()+", "+currentContext.get()+" -> "+cur);
+ e.printStackTrace();
+ }
+
currentContext.set(cur);
}
@@ -188,6 +201,21 @@ public abstract class GLContext {
*/
public abstract void setGL(GL gl);
+ /**
+ * Returns the attached user object for the given name to this GLContext/GL.
+ */
+ public Object getAttachedObject(int name) {
+ return attachedObjects.get(new Integer(name));
+ }
+
+ /**
+ * Sets the attached user object for the given name to this GLContext/GL.
+ * Returns the previous set object or null.
+ */
+ public Object putAttachedObject(int name, Object obj) {
+ return attachedObjects.put(new Integer(name), obj);
+ }
+
public final String toString() {
return "GLContext: "+getClass().getName()+
"(GL: "+getGL().getClass().getName()+","+
@@ -207,28 +235,28 @@ public abstract class GLContext {
* Useful for uniq mapping of canonical array index names as listed.
*
* @see #mgl_Vertex
- * @see javax.media.opengl.GL#GL_VERTEX_ARRAY
+ * @see javax.media.opengl.sub.fixed.GLPointerIf#GL_VERTEX_ARRAY
* @see #mgl_Normal
- * @see javax.media.opengl.GL#GL_NORMAL_ARRAY
+ * @see javax.media.opengl.sub.fixed.GLPointerIf#GL_NORMAL_ARRAY
* @see #mgl_Color
- * @see javax.media.opengl.GL#GL_COLOR_ARRAY
+ * @see javax.media.opengl.sub.fixed.GLPointerIf#GL_COLOR_ARRAY
* @see #mgl_MultiTexCoord
- * @see javax.media.opengl.GL#GL_TEXTURE_COORD_ARRAY
- * @see javax.media.opengl.GL#glEnableClientState
- * @see javax.media.opengl.GL#glVertexPointer
- * @see javax.media.opengl.GL#glColorPointer
- * @see javax.media.opengl.GL#glNormalPointer
- * @see javax.media.opengl.GL#glTexCoordPointer
+ * @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 GL.GL_VERTEX_ARRAY:
+ case GLPointerIf.GL_VERTEX_ARRAY:
return mgl_Vertex;
- case GL.GL_NORMAL_ARRAY:
+ case GLPointerIf.GL_NORMAL_ARRAY:
return mgl_Normal;
- case GL.GL_COLOR_ARRAY:
+ case GLPointerIf.GL_COLOR_ARRAY:
return mgl_Color;
- case GL.GL_TEXTURE_COORD_ARRAY:
+ case GLPointerIf.GL_TEXTURE_COORD_ARRAY:
return mgl_MultiTexCoord;
}
return null;
diff --git a/src/classes/javax/media/opengl/GLProfile.java b/src/classes/javax/media/opengl/GLProfile.java
index 0d1c73d07..a6a51862a 100644
--- a/src/classes/javax/media/opengl/GLProfile.java
+++ b/src/classes/javax/media/opengl/GLProfile.java
@@ -36,6 +36,7 @@
package javax.media.opengl;
+import javax.media.opengl.sub.fixed.*;
import java.lang.reflect.*;
import java.security.*;
import com.sun.opengl.impl.*;
@@ -299,8 +300,8 @@ public class GLProfile {
return false;
}
switch(index) {
- case GL.GL_VERTEX_ARRAY:
- case GL.GL_TEXTURE_COORD_ARRAY:
+ case GLPointerIf.GL_VERTEX_ARRAY:
+ case GLPointerIf.GL_TEXTURE_COORD_ARRAY:
switch(type) {
case GL.GL_BYTE:
case GL.GL_SHORT:
@@ -326,7 +327,7 @@ public class GLProfile {
return false;
}
break;
- case GL.GL_NORMAL_ARRAY:
+ case GLPointerIf.GL_NORMAL_ARRAY:
switch(type) {
case GL.GL_BYTE:
case GL.GL_SHORT:
@@ -350,7 +351,7 @@ public class GLProfile {
return false;
}
break;
- case GL.GL_COLOR_ARRAY:
+ case GLPointerIf.GL_COLOR_ARRAY:
switch(type) {
case GL.GL_UNSIGNED_BYTE:
case GL.GL_FIXED:
@@ -437,7 +438,7 @@ public class GLProfile {
}
} else {
switch(index) {
- case GL.GL_VERTEX_ARRAY:
+ case GLPointerIf.GL_VERTEX_ARRAY:
switch(type) {
case GL.GL_SHORT:
case GL.GL_FLOAT:
@@ -463,7 +464,7 @@ public class GLProfile {
return false;
}
break;
- case GL.GL_NORMAL_ARRAY:
+ case GLPointerIf.GL_NORMAL_ARRAY:
switch(type) {
case GL.GL_BYTE:
case GL.GL_SHORT:
@@ -488,7 +489,7 @@ public class GLProfile {
return false;
}
break;
- case GL.GL_COLOR_ARRAY:
+ case GLPointerIf.GL_COLOR_ARRAY:
switch(type) {
case GL.GL_UNSIGNED_BYTE:
case GL.GL_BYTE:
@@ -517,7 +518,7 @@ public class GLProfile {
return false;
}
break;
- case GL.GL_TEXTURE_COORD_ARRAY:
+ case GLPointerIf.GL_TEXTURE_COORD_ARRAY:
switch(type) {
case GL.GL_SHORT:
case GL.GL_FLOAT:
diff --git a/src/classes/javax/media/opengl/NativeWindowFactory.java b/src/classes/javax/media/opengl/NativeWindowFactory.java
index 18ce61974..b80e239ea 100644
--- a/src/classes/javax/media/opengl/NativeWindowFactory.java
+++ b/src/classes/javax/media/opengl/NativeWindowFactory.java
@@ -85,8 +85,7 @@ public abstract class NativeWindowFactory {
Constructor factoryConstructor =
GLReflection.getConstructor("com.sun.opengl.impl.x11.glx.awt.X11AWTGLXNativeWindowFactory", new Class[] {});
factory = (NativeWindowFactory) factoryConstructor.newInstance(null);
- } catch (Exception e) {
- }
+ } catch (Exception e) { }
}
registerFactory(componentClass, factory);
defaultFactory = factory;
diff --git a/src/classes/javax/media/opengl/awt/GLCanvas.java b/src/classes/javax/media/opengl/awt/GLCanvas.java
index bce58be0f..e0d997dc5 100644
--- a/src/classes/javax/media/opengl/awt/GLCanvas.java
+++ b/src/classes/javax/media/opengl/awt/GLCanvas.java
@@ -373,6 +373,10 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
drawableHelper.removeGLEventListener(listener);
}
+ public void setContext(GLContext ctx) {
+ context=(GLContextImpl)ctx;
+ }
+
public GLContext getContext() {
return context;
}
diff --git a/src/classes/javax/media/opengl/awt/GLJPanel.java b/src/classes/javax/media/opengl/awt/GLJPanel.java
index d5f44ff21..37f1dfa7b 100644
--- a/src/classes/javax/media/opengl/awt/GLJPanel.java
+++ b/src/classes/javax/media/opengl/awt/GLJPanel.java
@@ -324,6 +324,13 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable {
public void setRealized(boolean realized) {
}
+ public void setContext(GLContext ctx) {
+ if (backend == null) {
+ return;
+ }
+ backend.setContext(ctx);
+ }
+
public GLContext getContext() {
if (backend == null) {
return null;
@@ -565,6 +572,9 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable {
// this GLJPanel
public GLContext createContext(GLContext shareWith);
+ // Called to set the current backend's GLContext
+ public void setContext(GLContext ctx);
+
// Called to get the current backend's GLContext
public GLContext getContext();
@@ -797,6 +807,10 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable {
return offscreenDrawable.createContext(shareWith);
}
+ public void setContext(GLContext ctx) {
+ offscreenContext=(GLContextImpl)ctx;
+ }
+
public GLContext getContext() {
return offscreenContext;
}
@@ -873,6 +887,13 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable {
return pbuffer.createContext(shareWith);
}
+ public void setContext(GLContext ctx) {
+ if (pbuffer == null && Beans.isDesignTime()) {
+ return;
+ }
+ pbuffer.setContext(ctx);
+ }
+
public GLContext getContext() {
// Workaround for crashes in NetBeans GUI builder
if (pbuffer == null && Beans.isDesignTime()) {
@@ -1040,6 +1061,10 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable {
throw new GLException("Not yet implemented");
}
+ public void setContext(GLContext ctx) {
+ joglContext=ctx;
+ }
+
public GLContext getContext() {
return joglContext;
}
diff --git a/src/classes/javax/media/opengl/sub/GLObject.java b/src/classes/javax/media/opengl/sub/GLObject.java
new file mode 100644
index 000000000..1426f75d1
--- /dev/null
+++ b/src/classes/javax/media/opengl/sub/GLObject.java
@@ -0,0 +1,75 @@
+/*
+ * 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/classes/javax/media/opengl/sub/fixed/GLFixedFuncHookIf.java b/src/classes/javax/media/opengl/sub/fixed/GLFixedFuncHookIf.java
new file mode 100644
index 000000000..05e0f2ca7
--- /dev/null
+++ b/src/classes/javax/media/opengl/sub/fixed/GLFixedFuncHookIf.java
@@ -0,0 +1,33 @@
+/*
+ * 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.*;
+
+/**
+ * Fixed function implementation hook interface<p>
+ *
+ * An implementation shall implement the below interface methods
+ * and pipeline the call to the underlying GL impl. if necessary. <p>
+ *
+ * An implementation must implement all extended interface methods. <p>
+ */
+public interface GLFixedFuncHookIf extends GLLightingIf, GLMatrixIf, GLPointerIf {
+ public void glDrawArrays(int mode, int first, int count) ;
+ public void glDrawElements(int mode, int count, int type, java.nio.Buffer indices) ;
+ public void glDrawElements(int mode, int count, int type, long indices_buffer_offset) ;
+ public void glActiveTexture(int texture) ;
+ public void glEnable(int cap) ;
+ public void glDisable(int cap) ;
+ public void glCullFace(int faceName) ;
+ public void glGetFloatv(int pname, java.nio.FloatBuffer params) ;
+ public void glGetFloatv(int pname, float[] params, int params_offset) ;
+ public void glGetIntegerv(int pname, IntBuffer params) ;
+ public void glGetIntegerv(int pname, int[] params, int params_offset) ;
+}
+
diff --git a/src/classes/javax/media/opengl/sub/fixed/GLFixedFuncIf.java b/src/classes/javax/media/opengl/sub/fixed/GLFixedFuncIf.java
new file mode 100644
index 000000000..cc3e299e8
--- /dev/null
+++ b/src/classes/javax/media/opengl/sub/fixed/GLFixedFuncIf.java
@@ -0,0 +1,18 @@
+/*
+ * 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.*;
+
+/**
+ * GL Fixed function module interface
+ *
+ */
+public interface GLFixedFuncIf extends GL, GLFixedFuncHookIf, GLLightingIf, GLMatrixIf, GLPointerIf {
+}
+
diff --git a/src/classes/javax/media/opengl/sub/fixed/GLFixedFuncUtil.java b/src/classes/javax/media/opengl/sub/fixed/GLFixedFuncUtil.java
new file mode 100644
index 000000000..4c0d1b87f
--- /dev/null
+++ b/src/classes/javax/media/opengl/sub/fixed/GLFixedFuncUtil.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ */
+
+package javax.media.opengl.sub.fixed;
+
+import javax.media.opengl.*;
+import javax.media.opengl.sub.*;
+
+/**
+ * Contains values to handle the fixed implementation.
+ */
+public class GLFixedFuncUtil {
+
+ /**
+ * @return The current GLContext's GL object cast as GLFixedFuncIf
+ * @throws GLException is this GL Object is not a GLFixedFuncIf implementation,
+ * or no GLContext is current
+ */
+ public static final GLFixedFuncIf getCurrentGLFixedFuncIf() throws GLException {
+ GLContext curContext = GLContext.getCurrent();
+ if (curContext == null) {
+ throw new GLException("No OpenGL context current on this thread");
+ }
+ GL gl = curContext.getGL();
+ if(gl instanceof GLFixedFuncIf) {
+ return (GLFixedFuncIf) gl;
+ }
+ throw new GLException("Not a GLFixedFuncIf implementation");
+ }
+
+ /**
+ * @return true if GL object is a GLFixedFuncIf
+ */
+ public static final boolean isGLFixedFuncIf(GL gl) {
+ return (gl instanceof GLFixedFuncIf) ;
+ }
+
+ /**
+ * @return The object cast as GLFixedFuncIf
+ * @throws GLException is this GL Object is not a GLFixedFuncIf implementation
+ */
+ public static final GLFixedFuncIf getGLFixedFuncIf(GL gl) {
+ if(gl instanceof GLFixedFuncIf) {
+ return (GLFixedFuncIf) gl;
+ }
+ throw new GLException("Not a GLFixedFuncIf implementation");
+ }
+}
+
diff --git a/src/classes/javax/media/opengl/sub/fixed/GLLightingIf.java b/src/classes/javax/media/opengl/sub/fixed/GLLightingIf.java
new file mode 100644
index 000000000..1f3aa9ab7
--- /dev/null
+++ b/src/classes/javax/media/opengl/sub/fixed/GLLightingIf.java
@@ -0,0 +1,50 @@
+/*
+ * 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/classes/javax/media/opengl/sub/fixed/GLMatrixIf.java b/src/classes/javax/media/opengl/sub/fixed/GLMatrixIf.java
new file mode 100644
index 000000000..834731b98
--- /dev/null
+++ b/src/classes/javax/media/opengl/sub/fixed/GLMatrixIf.java
@@ -0,0 +1,77 @@
+/*
+ * 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/classes/javax/media/opengl/sub/fixed/GLPointerIf.java b/src/classes/javax/media/opengl/sub/fixed/GLPointerIf.java
new file mode 100644
index 000000000..2f4cda1aa
--- /dev/null
+++ b/src/classes/javax/media/opengl/sub/fixed/GLPointerIf.java
@@ -0,0 +1,39 @@
+/*
+ * 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/classes/javax/media/opengl/util/ImmModeSink.java b/src/classes/javax/media/opengl/util/ImmModeSink.java
index 526f38dab..9ab899d69 100644
--- a/src/classes/javax/media/opengl/util/ImmModeSink.java
+++ b/src/classes/javax/media/opengl/util/ImmModeSink.java
@@ -2,6 +2,8 @@
package javax.media.opengl.util;
import javax.media.opengl.*;
+import javax.media.opengl.sub.*;
+import javax.media.opengl.sub.fixed.*;
import com.sun.opengl.impl.GLReflection;
import java.nio.*;
import java.util.Iterator;
@@ -332,8 +334,13 @@ public class ImmModeSink {
enableBuffer(gl, true);
if (buffer!=null) {
+ GLFixedFuncIf glf = GLFixedFuncUtil.getGLFixedFuncIf(gl);
+ if(null==glf) {
+ throw new GLException("ImmModeSink.draw: No GLFixedFuncIf available");
+ }
+
if(null==indices) {
- gl.glDrawArrays(mode, 0, count);
+ glf.glDrawArrays(mode, 0, count);
} else {
Class clazz = indices.getClass();
int type=-1;
@@ -345,7 +352,7 @@ public class ImmModeSink {
if(0>type) {
throw new GLException("Given Buffer Class not supported: "+clazz+", should be ubyte or ushort:\n\t"+this);
}
- gl.glDrawElements(mode, indices.remaining(), type, indices);
+ glf.glDrawElements(mode, indices.remaining(), type, indices);
// GL2: gl.glDrawRangeElements(mode, 0, indices.remaining()-1, indices.remaining(), type, indices);
}
}
@@ -643,11 +650,12 @@ public class ImmModeSink {
this.bufferWritten=false;
}
- public void seal(GL gl, boolean seal)
+ public void seal(GL glObj, boolean seal)
{
seal(seal);
if(sealedGL==seal) return;
sealedGL = seal;
+ GL gl = glObj.getGL();
if(seal) {
if(vboUsage && vboName==0) {
int[] tmp = new int[1];
@@ -695,6 +703,11 @@ public class ImmModeSink {
}
public void enableBufferFixed(GL gl, boolean enable) {
+ GLFixedFuncIf glf = GLFixedFuncUtil.getGLFixedFuncIf(gl);
+ if(null==glf) {
+ throw new GLException("ImmModeSink.enableBufferFixed: No GLFixedFuncIf available");
+ }
+
if(enable) {
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName);
@@ -704,35 +717,35 @@ public class ImmModeSink {
}
if(vComps>0) {
- gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
- gl.glVertexPointer(vArrayData);
+ glf.glEnableClientState(glf.GL_VERTEX_ARRAY);
+ glf.glVertexPointer(vArrayData);
}
if(cComps>0) {
- gl.glEnableClientState(gl.GL_COLOR_ARRAY);
- gl.glColorPointer(cArrayData);
+ glf.glEnableClientState(glf.GL_COLOR_ARRAY);
+ glf.glColorPointer(cArrayData);
}
if(nComps>0) {
- gl.glEnableClientState(gl.GL_NORMAL_ARRAY);
- gl.glNormalPointer(nArrayData);
+ glf.glEnableClientState(glf.GL_NORMAL_ARRAY);
+ glf.glNormalPointer(nArrayData);
}
if(tComps>0) {
- gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY);
- gl.glTexCoordPointer(tArrayData);
+ glf.glEnableClientState(glf.GL_TEXTURE_COORD_ARRAY);
+ glf.glTexCoordPointer(tArrayData);
}
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
} else {
if(vComps>0) {
- gl.glDisableClientState(gl.GL_VERTEX_ARRAY);
+ glf.glDisableClientState(glf.GL_VERTEX_ARRAY);
}
if(cComps>0) {
- gl.glDisableClientState(gl.GL_COLOR_ARRAY);
+ glf.glDisableClientState(glf.GL_COLOR_ARRAY);
}
if(nComps>0) {
- gl.glDisableClientState(gl.GL_NORMAL_ARRAY);
+ glf.glDisableClientState(glf.GL_NORMAL_ARRAY);
}
if(tComps>0) {
- gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY);
+ glf.glDisableClientState(glf.GL_TEXTURE_COORD_ARRAY);
}
}
}
@@ -745,10 +758,10 @@ public class ImmModeSink {
}
if(enable) {
- gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName);
+ glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName);
if(!bufferWritten) {
- gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit(), buffer, GL.GL_STATIC_DRAW);
+ glsl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit(), buffer, GL.GL_STATIC_DRAW);
bufferWritten=true;
}
@@ -769,7 +782,7 @@ public class ImmModeSink {
st.glVertexAttribPointer(glsl, tArrayData);
}
- gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+ glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
} else {
if(vComps>0) {
st.glDisableVertexAttribArray(glsl, vArrayData.getName());
@@ -853,25 +866,25 @@ public class ImmModeSink {
buffer.flip();
if(vComps>0) {
- vArrayData = GLArrayDataWrapper.createFixed(GL.GL_VERTEX_ARRAY, vComps, vDataType, false,
+ vArrayData = GLArrayDataWrapper.createFixed(GLPointerIf.GL_VERTEX_ARRAY, vComps, vDataType, false,
0, vertexArray, 0, vOffset);
} else {
vArrayData = null;
}
if(cComps>0) {
- cArrayData = GLArrayDataWrapper.createFixed(GL.GL_COLOR_ARRAY, cComps, cDataType, false,
+ cArrayData = GLArrayDataWrapper.createFixed(GLPointerIf.GL_COLOR_ARRAY, cComps, cDataType, false,
0, colorArray, 0, cOffset);
} else {
cArrayData = null;
}
if(nComps>0) {
- nArrayData = GLArrayDataWrapper.createFixed(GL.GL_NORMAL_ARRAY, nComps, nDataType, false,
+ nArrayData = GLArrayDataWrapper.createFixed(GLPointerIf.GL_NORMAL_ARRAY, nComps, nDataType, false,
0, normalArray, 0, nOffset);
} else {
nArrayData = null;
}
if(tComps>0) {
- tArrayData = GLArrayDataWrapper.createFixed(GL.GL_TEXTURE_COORD_ARRAY, tComps, tDataType, false,
+ tArrayData = GLArrayDataWrapper.createFixed(GLPointerIf.GL_TEXTURE_COORD_ARRAY, tComps, tDataType, false,
0, textCoordArray, 0, tOffset);
} else {
tArrayData = null;
diff --git a/src/classes/javax/media/opengl/util/PMVMatrix.java b/src/classes/javax/media/opengl/util/PMVMatrix.java
index 37472dfe6..5a69b920c 100755
--- a/src/classes/javax/media/opengl/util/PMVMatrix.java
+++ b/src/classes/javax/media/opengl/util/PMVMatrix.java
@@ -1,13 +1,19 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ */
-package javax.media.opengl.util;
+package javax.media.opengl.util;
+
+import com.sun.opengl.impl.ProjectFloat;
-import javax.media.opengl.*;
-import com.sun.opengl.impl.ProjectFloat;
import java.nio.*;
import java.util.ArrayList;
import java.util.List;
-public class PMVMatrix {
+import javax.media.opengl.*;
+import javax.media.opengl.sub.fixed.GLMatrixIf;
+
+public class PMVMatrix implements GLMatrixIf {
public PMVMatrix() {
projectFloat = new ProjectFloat();
@@ -16,14 +22,24 @@ public class PMVMatrix {
projectFloat.gluMakeIdentityf(matrixIdent);
matrixIdent.rewind();
- matrixPMvMviT = BufferUtil.newFloatBuffer(4*16); // grouping P + Mv + Mvi + MviT
- matrixPMvMvi = slice(matrixPMvMviT, 0*16, 3*16); // grouping P + Mv + Mvi
- matrixPMv = slice(matrixPMvMviT, 0*16, 2*16); // grouping P + Mv
- matrixP = slice(matrixPMvMviT, 0*16, 1*16);
- matrixMv = slice(matrixPMvMviT, 1*16, 1*16);
- matrixMvi = slice(matrixPMvMviT, 2*16, 1*16);
- matrixMvit = slice(matrixPMvMviT, 3*16, 1*16);
- matrixPMvMviT.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);
@@ -52,11 +68,13 @@ public class PMVMatrix {
matrixMvStack= new ArrayList();
// default values and mode
- glMatrixMode(GL.GL_PROJECTION);
+ glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glMatrixMode(GL.GL_MODELVIEW);
+ glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
- modified = true;
+ glMatrixMode(GL.GL_TEXTURE);
+ glLoadIdentity();
+ setDirty();
}
private static FloatBuffer slice(FloatBuffer buf, int pos, int len) {
@@ -65,36 +83,121 @@ public class PMVMatrix {
return buf.slice();
}
- public boolean isDirty() {
- return modified;
+ 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 boolean update() {
- boolean res = modified;
- if(res) {
- setMviMvit();
- modified=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 GLUnsupportedException("unsupported matrixName: "+matrixModeName);
}
- return res;
}
- public final int glGetMatrixMode() {
- return matrixMode;
+ 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 GLUnsupportedException("unsupported matrixGetName: "+matrixGetName);
+ }
+ }
+
+ public void setDirty() {
+ modified = DIRTY_MODELVIEW | DIRTY_PROJECTION | DIRTY_TEXTURE ;
+ matrixMode = GL_MODELVIEW;
+ }
+
+ public int getDirtyBits() {
+ return modified;
}
- public void glMatrixMode(int matrixName) {
+ public boolean isDirty(final int matrixName) {
+ boolean res;
switch(matrixName) {
- case GL.GL_MODELVIEW:
- case GL.GL_PROJECTION:
+ 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 GLUnsupportedException("unsupported matrixName: "+matrixName);
}
- matrixMode = matrixName;
+ return res;
}
- public final FloatBuffer glGetPMvMviTMatrixf() {
- return matrixPMvMviT;
+ 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() {
@@ -109,118 +212,256 @@ public class PMVMatrix {
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);
}
- public final FloatBuffer glGetMatrixf(int matrixName) {
- if(matrixName==GL.GL_MODELVIEW) {
+ /**
+ * @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.GL_PROJECTION) {
+ } else if(matrixName==GL_PROJECTION) {
return matrixP;
+ } else if(matrixName==GL.GL_TEXTURE) {
+ return matrixT;
+ } else {
+ throw new GLUnsupportedException("unsupported matrixName: "+matrixName);
}
- return null;
}
- public void glLoadMatrixf(float[] values, int offset) {
+ 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 GLUnsupportedException("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 GLUnsupportedException("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 GLUnsupportedException("unsupported pname: "+pname);
+ }
+ }
+
+ public final void glLoadMatrixf(final float[] values, final int offset) {
int len = values.length-offset;
- if(matrixMode==GL.GL_MODELVIEW) {
+ if(matrixMode==GL_MODELVIEW) {
matrixMv.clear();
matrixMv.put(values, offset, len);
matrixMv.rewind();
- } else if(matrixMode==GL.GL_PROJECTION) {
+ 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 ;
}
- modified = true;
}
- public void glLoadMatrixf(java.nio.FloatBuffer m) {
+ public final void glLoadMatrixf(java.nio.FloatBuffer m) {
int spos = m.position();
- if(matrixMode==GL.GL_MODELVIEW) {
+ if(matrixMode==GL_MODELVIEW) {
matrixMv.clear();
matrixMv.put(m);
matrixMv.rewind();
- } else if(matrixMode==GL.GL_PROJECTION) {
+ 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);
- modified = true;
}
- public void glPopMatrix() {
+ public final void glPopMatrix() {
float[] stackEntry=null;
- if(matrixMode==GL.GL_MODELVIEW) {
+ if(matrixMode==GL_MODELVIEW) {
stackEntry = (float[])matrixMvStack.remove(0);
- } else if(matrixMode==GL.GL_PROJECTION) {
+ } 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 void glPushMatrix() {
+ public final void glPushMatrix() {
float[] stackEntry = new float[1*16];
- if(matrixMode==GL.GL_MODELVIEW) {
+ if(matrixMode==GL_MODELVIEW) {
matrixMv.get(stackEntry);
matrixMv.rewind();
matrixMvStack.add(0, stackEntry);
- } else if(matrixMode==GL.GL_PROJECTION) {
+ } 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 void glLoadIdentity() {
- if(matrixMode==GL.GL_MODELVIEW) {
+ public final void glLoadIdentity() {
+ if(matrixMode==GL_MODELVIEW) {
matrixMv.clear();
matrixMv.put(matrixIdent);
matrixMv.rewind();
matrixIdent.rewind();
- } else if(matrixMode==GL.GL_PROJECTION) {
+ 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 ;
}
- modified = true;
- }
-
- public void glMultMatrixf(FloatBuffer a, 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) );
- }
- // or .. projectFloat.gluMultMatricesf(b, a, p);
}
- public void glMultMatrixf(FloatBuffer m) {
- if(matrixMode==GL.GL_MODELVIEW) {
+ public final void glMultMatrixf(final FloatBuffer m) {
+ if(matrixMode==GL_MODELVIEW) {
glMultMatrixf(matrixMv, m, matrixMult);
matrixMv.clear();
matrixMv.put(matrixMult);
matrixMv.rewind();
- } else if(matrixMode==GL.GL_PROJECTION) {
+ 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();
- modified = true;
}
- public void glTranslatef(float x, float y, float z) {
+ 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
@@ -232,7 +473,7 @@ public class PMVMatrix {
glMultMatrixf(matrixTrans);
}
- public void glRotatef(float angdeg, float x, float y, float z) {
+ 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;
@@ -253,19 +494,6 @@ public class PMVMatrix {
float ys = y*s;
float yz = y*z;
float zs = z*s;
- if(false) {
- 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);
- } else {
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);
@@ -277,12 +505,11 @@ public class PMVMatrix {
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 void glScalef(float x, float y, float z) {
+ public final void glScalef(final float x, final float y, final float z) {
// Scale matrix:
// x 0 0 0
// 0 y 0 0
@@ -295,7 +522,7 @@ public class PMVMatrix {
glMultMatrixf(matrixScale);
}
- public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) {
+ 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
@@ -318,7 +545,7 @@ public class PMVMatrix {
glMultMatrixf(matrixOrtho);
}
- public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) {
+ 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");
}
@@ -352,15 +579,11 @@ public class PMVMatrix {
glMultMatrixf(matrixFrustum);
}
- public void gluPerspective(float fovy, float aspect, float zNear, 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);
- }
+ //
+ // private
+ //
- private void setMviMvit() {
+ private final void setMviMvit() {
if(!projectFloat.gluInvertMatrixf(matrixMv, matrixMvi)) {
throw new GLException("Invalid source Mv matrix, can't compute inverse");
}
@@ -381,15 +604,16 @@ public class PMVMatrix {
}
protected FloatBuffer matrixIdent;
- protected FloatBuffer matrixPMvMviT, matrixPMvMvi, matrixPMv, matrixP, matrixMv, matrixMvi, matrixMvit;
+ protected FloatBuffer matrixTPMvMvitPmv, matrixPMvMvit, matrixPMvMvitPmv, matrixPMvMvi, matrixPMv, matrixP, matrixT, matrixMv, matrixMvi, matrixMvit, matrixPmv;
protected FloatBuffer matrixMvit3;
protected FloatBuffer matrixMult, matrixTrans, matrixRot, matrixScale, matrixOrtho, matrixFrustum;
protected float[] vec3f;
- protected List/*FloatBuffer*/ matrixPStack, matrixMvStack;
- protected int matrixMode = GL.GL_MODELVIEW;
- protected boolean modified = false;
+ 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;
}
-
-