summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-08-22 01:59:00 +0200
committerSven Gothel <[email protected]>2011-08-22 01:59:00 +0200
commit6c346d98f04e2355210960fe9ffde47432f04d62 (patch)
tree938536365abee309d5acf9ada1ac75bc1a49e939 /src/jogl/classes/com
parent47b0d317df3c860b6cf3ea10196dfee82b3b3dc1 (diff)
Misc Rename/Reloc; GLArrayData*/PMVMatrix enhancments; Test fixes/adds (GearsES1/ES2)
rename/reloc: - javax.media.nativewindow.util: DimensionReadOnly -> DimensionImmutable PointReadOnly -> PointImmutable RectangleReadOnly -> RectangleImmutable unified 'immutable' name as used within jogamp already - remove array handler from public API com.jogamp.opengl.util.GL*ArrayHandler -> jogamp.opengl.util.GL*ArrayHandler - GLArrayData: Clarify method names getComponentNumber() -> getComponentCount() getComponentSize() -> getComponentSizeInBytes() getElementNumber() -> getElementCount() getByteSize() -> getSizeInBytes() - FixedFuncPipeline: Moved def. array names to GLPointerFuncUtil enhancement: - GLArrayDataServer: Add support for interleaved arrays/VBO - GLArrayData*.createFixed(..) remove 'name' argument (non sense for fixed function) - PMVMatrix: - one nio buffer - removed 'Pmv' multiplied matrix - removed 2x2 cut down 'Mvi' normal matrix (use 4x4 Mvi) - tests: - RedSquare -> RedSquareES1/RedSquareES2 - Gears ES1 fixed + ES2 added. Both work properly and share common Gears VBO construction - Added TestMapBuffer01NEWT, testing glMapBuffer
Diffstat (limited to 'src/jogl/classes/com')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java55
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java89
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java41
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayHandler.java21
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java41
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java65
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java168
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java97
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java2
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java10
10 files changed, 210 insertions, 379 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
index 4296ebee2..13c61766e 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
@@ -1,33 +1,26 @@
package com.jogamp.opengl.util;
-import com.jogamp.common.nio.Buffers;
-import java.security.*;
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+import java.nio.ShortBuffer;
-import javax.media.opengl.*;
+import javax.media.opengl.GL;
+import javax.media.opengl.GLException;
+import javax.media.opengl.fixedfunc.GLPointerFuncUtil;
-import com.jogamp.opengl.util.glsl.*;
+import jogamp.opengl.util.GLFixedArrayHandler;
+import jogamp.opengl.util.glsl.GLSLArrayHandler;
-import jogamp.opengl.SystemUtil;
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.opengl.util.glsl.ShaderState;
-import java.nio.*;
public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayDataEditable {
/**
- * The OpenGL ES emulation on the PC probably has a buggy VBO implementation,
- * where we have to 'refresh' the VertexPointer or VertexAttribArray after each
- * BindBuffer !
- *
- * This should not be necessary on proper native implementations.
- */
- public static final boolean hasVBOBug = AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- return SystemUtil.getenv("JOGL_VBO_BUG");
- }
- }) != null;
-
- /**
* Create a client side buffer object, using a predefined fixed function array index
* and starting with a new created Buffer object with initialSize size
*
@@ -36,10 +29,10 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
* EnableVertexAttribArray and VertexAttribPointer calls,
* and a predefined vertex attribute variable name will be chosen.
*
+ * The default name mapping will be used,
+ * see {@link GLPointerFuncUtil#getPredefinedArrayIndexName(int)}.
+ *
* @param index The GL array index
- * @param name The optional custom name for the GL array index, maybe null.
- * If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'.
- * This name might be used as the shader attribute name.
* @param comps The array component number
* @param dataType The array index GL data type
* @param normalized Whether the data shall be normalized
@@ -47,12 +40,12 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
*
* @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
*/
- public static GLArrayDataClient createFixed(int index, String name, int comps, int dataType, boolean normalized, int initialSize)
+ public static GLArrayDataClient createFixed(int index, int comps, int dataType, boolean normalized, int initialSize)
throws GLException
{
GLArrayDataClient adc = new GLArrayDataClient();
GLArrayHandler glArrayHandler = new GLFixedArrayHandler(adc);
- adc.init(name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler, 0, 0, 0, 0);
+ adc.init(null, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler, 0, 0, 0, 0);
return adc;
}
@@ -65,10 +58,10 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
* EnableVertexAttribArray and VertexAttribPointer calls,
* and a predefined vertex attribute variable name will be chosen.
*
+ * The default name mapping will be used,
+ * see {@link GLPointerFuncUtil#getPredefinedArrayIndexName(int)}.
+ *
* @param index The GL array index
- * @param name The optional custom name for the GL array index, maybe null.
- * If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'.
- * This name might be used as the shader attribute name.
* @param comps The array component number
* @param dataType The array index GL data type
* @param normalized Whether the data shall be normalized
@@ -77,13 +70,13 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
*
* @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
*/
- public static GLArrayDataClient createFixed(int index, String name, int comps, int dataType, boolean normalized, int stride,
+ public static GLArrayDataClient createFixed(int index, int comps, int dataType, boolean normalized, int stride,
Buffer buffer)
throws GLException
{
GLArrayDataClient adc = new GLArrayDataClient();
GLArrayHandler glArrayHandler = new GLFixedArrayHandler(adc);
- adc.init(name, index, comps, dataType, normalized, stride, buffer, comps*comps, false, glArrayHandler, 0, 0, 0, 0);
+ adc.init(null, index, comps, dataType, normalized, stride, buffer, comps*comps, false, glArrayHandler, 0, 0, 0, 0);
return adc;
}
@@ -271,9 +264,9 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
", isVertexAttribute "+isVertexAttribute+
", dataType "+componentType+
", bufferClazz "+componentClazz+
- ", elements "+getElementNumber()+
+ ", elements "+getElementCount()+
", components "+components+
- ", stride "+stride+"u "+strideB+"b "+strideL+"c"+
+ ", stride "+strideB+"b "+strideL+"c"+
", initialSize "+initialSize+
", sealed "+sealed+
", bufferEnabled "+bufferEnabled+
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
index b244184b0..38207cd2d 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
@@ -1,11 +1,22 @@
package com.jogamp.opengl.util;
-import javax.media.opengl.*;
+import java.nio.Buffer;
-import java.nio.*;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLArrayData;
+import javax.media.opengl.GLException;
+import javax.media.opengl.fixedfunc.GLPointerFuncUtil;
-import com.jogamp.opengl.util.glsl.*;
+import jogamp.opengl.util.GLDataArrayHandler;
+import jogamp.opengl.util.GLFixedArrayHandler;
+import jogamp.opengl.util.GLFixedArrayHandlerFlat;
+import jogamp.opengl.util.GLFixedArrayHandlerInterleaved;
+import jogamp.opengl.util.glsl.GLSLArrayHandler;
+import jogamp.opengl.util.glsl.GLSLArrayHandlerFlat;
+
+import com.jogamp.opengl.util.glsl.ShaderState;
public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataEditable {
@@ -22,6 +33,9 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
* EnableVertexAttribArray and VertexAttribPointer calls,
* and a predefined vertex attribute variable name will be chosen.
*
+ * The default name mapping will be used,
+ * see {@link GLPointerFuncUtil#getPredefinedArrayIndexName(int)}.
+ *
* @param index The GL array index
* @param name The optional custom name for the GL array index, maybe null.
* If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'.
@@ -35,13 +49,13 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
*
* @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
*/
- public static GLArrayDataServer createFixed(int index, String name, int comps, int dataType, boolean normalized, int stride,
+ public static GLArrayDataServer createFixed(int index, int comps, int dataType, boolean normalized, int stride,
Buffer buffer, int vboUsage)
throws GLException
{
GLArrayDataServer ads = new GLArrayDataServer();
GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads);
- ads.init(name, index, comps, dataType, normalized, stride, buffer, buffer.limit(), false, glArrayHandler,
+ ads.init(null, index, comps, dataType, normalized, stride, buffer, buffer.limit(), false, glArrayHandler,
0, 0, vboUsage, GL.GL_ARRAY_BUFFER);
return ads;
}
@@ -55,10 +69,10 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
* EnableVertexAttribArray and VertexAttribPointer calls,
* and a predefined vertex attribute variable name will be chosen.
*
+ * The default name mapping will be used,
+ * see {@link GLPointerFuncUtil#getPredefinedArrayIndexName(int)}.
+ *
* @param index The GL array index
- * @param name The optional custom name for the GL array index, maybe null.
- * If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'.
- * This name might be used as the shader attribute name.
* @param comps The array component number
* @param dataType The array index GL data type
* @param normalized Whether the data shall be normalized
@@ -67,14 +81,14 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
*
* @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
*/
- public static GLArrayDataServer createFixed(int index, String name, int comps, int dataType, boolean normalized, int initialSize,
+ public static GLArrayDataServer createFixed(int index, int comps, int dataType, boolean normalized, int initialSize,
int vboUsage)
throws GLException
{
- GLArrayDataServer ads = new GLArrayDataServer();
- GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads);
- ads.init(name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler,
- 0, 0, vboUsage, GL.GL_ARRAY_BUFFER);
+ GLArrayDataServer ads = new GLArrayDataServer();
+ GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads);
+ ads.init(null, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler,
+ 0, 0, vboUsage, GL.GL_ARRAY_BUFFER);
return ads;
}
@@ -174,6 +188,51 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
}
+ public static GLArrayDataServer createInterleaved(int comps, int dataType, boolean normalized, int initialSize,
+ int vboUsage)
+ throws GLException
+ {
+ GLArrayDataServer ads = new GLArrayDataServer();
+ GLArrayHandler glArrayHandler = new GLFixedArrayHandlerInterleaved(ads);
+ ads.init(GLPointerFuncUtil.mgl_InterleaveArray, -1, comps, dataType, false, 0, null, initialSize, false, glArrayHandler,
+ 0, 0, vboUsage, GL.GL_ARRAY_BUFFER);
+ return ads;
+ }
+
+ int interleavedOffset = 0;
+
+ public GLArrayData addFixedSubArray(int index, int comps) {
+ if(interleavedOffset >= getComponentCount() * getComponentSizeInBytes()) {
+ final int iOffC = interleavedOffset / getComponentSizeInBytes();
+ throw new GLException("Interleaved offset > total components ("+iOffC+" > "+getComponentCount()+")");
+ }
+ GLArrayDataWrapper ad = GLArrayDataWrapper.createFixed(
+ index, comps, getComponentType(),
+ getNormalized(), getStride(), getBuffer(),
+ getVBOName(), interleavedOffset, getVBOUsage());
+ ad.setVBOEnabled(isVBO());
+ interleavedOffset += comps * getComponentSizeInBytes();
+ GLArrayHandler handler = new GLFixedArrayHandlerFlat(ad);
+ glArrayHandler.addSubHandler(handler);
+ return ad;
+ }
+
+ public GLArrayData addGLSLSubArray(ShaderState st, String name, int comps) {
+ if(interleavedOffset >= getComponentCount() * getComponentSizeInBytes()) {
+ final int iOffC = interleavedOffset / getComponentSizeInBytes();
+ throw new GLException("Interleaved offset > total components ("+iOffC+" > "+getComponentCount()+")");
+ }
+ GLArrayDataWrapper ad = GLArrayDataWrapper.createGLSL(
+ name, comps, getComponentType(),
+ getNormalized(), getStride(), getBuffer(),
+ getVBOName(), interleavedOffset, getVBOUsage());
+ ad.setVBOEnabled(isVBO());
+ interleavedOffset += comps * getComponentSizeInBytes();
+ GLArrayHandler handler = new GLSLArrayHandlerFlat(st, ad);
+ glArrayHandler.addSubHandler(handler);
+ return ad;
+ }
+
//
// Data matters GLArrayData
//
@@ -213,9 +272,9 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
", isVertexAttribute "+isVertexAttribute+
", dataType "+componentType+
", bufferClazz "+componentClazz+
- ", elements "+getElementNumber()+
+ ", elements "+getElementCount()+
", components "+components+
- ", stride "+stride+"u "+strideB+"b "+strideL+"c"+
+ ", stride "+strideB+"b "+strideL+"c"+
", initialSize "+initialSize+
", vboEnabled "+vboEnabled+
", vboName "+vboName+
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java
index e3b250934..da841afca 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java
@@ -2,6 +2,7 @@
package com.jogamp.opengl.util;
import javax.media.opengl.*;
+import javax.media.opengl.fixedfunc.GLPointerFuncUtil;
import jogamp.opengl.util.glsl.fixedfunc.*;
@@ -85,7 +86,7 @@ public class GLArrayDataWrapper implements GLArrayData {
}
return false;
}
- return glp.isValidArrayDataType(getIndex(), getComponentNumber(), getComponentType(), isVertexAttribute(), throwException);
+ return glp.isValidArrayDataType(getIndex(), getComponentCount(), getComponentType(), isVertexAttribute(), throwException);
}
//
@@ -114,24 +115,24 @@ public class GLArrayDataWrapper implements GLArrayData {
public final Buffer getBuffer() { return buffer; }
- public final int getComponentNumber() { return components; }
+ public final int getComponentCount() { return components; }
public final int getComponentType() { return componentType; }
- public final int getComponentSize() { return componentSize; }
+ public final int getComponentSizeInBytes() { return componentByteSize; }
- public final int getElementNumber() {
+ public final int getElementCount() {
if(null==buffer) return 0;
return ( buffer.position()==0 ) ? ( buffer.limit() / components ) : ( buffer.position() / components ) ;
}
- public final int getByteSize() {
+ public final int getSizeInBytes() {
if(null==buffer) return 0;
- return ( buffer.position()==0 ) ? ( buffer.limit() * componentSize ) : ( buffer.position() * componentSize ) ;
+ return ( buffer.position()==0 ) ? ( buffer.limit() * componentByteSize ) : ( buffer.position() * componentByteSize ) ;
}
public final boolean getNormalized() { return normalized; }
- public final int getStride() { return stride; }
+ public final int getStride() { return strideB; }
public final Class getBufferClass() { return componentClazz; }
@@ -150,9 +151,9 @@ public class GLArrayDataWrapper implements GLArrayData {
", isVertexAttribute "+isVertexAttribute+
", dataType "+componentType+
", bufferClazz "+componentClazz+
- ", elements "+getElementNumber()+
+ ", elements "+getElementCount()+
", components "+components+
- ", stride "+stride+"u "+strideB+"b "+strideL+"c"+
+ ", stride "+strideB+"b "+strideL+"c"+
", buffer "+buffer+
", vboEnabled "+vboEnabled+
", vboName "+vboName+
@@ -234,7 +235,7 @@ public class GLArrayDataWrapper implements GLArrayData {
// ok ..
} else if( GL.GL_ARRAY_BUFFER == vboTarget ) {
// check name ..
- this.name = ( null == name ) ? FixedFuncPipeline.getPredefinedArrayIndexName(index) : name ;
+ this.name = ( null == name ) ? GLPointerFuncUtil.getPredefinedArrayIndexName(index) : name ;
if(null == this.name ) {
throw new GLException("Not a valid array buffer index: "+index);
}
@@ -255,8 +256,8 @@ public class GLArrayDataWrapper implements GLArrayData {
default:
this.normalized = false;
}
- componentSize = GLBuffers.sizeOfGLType(componentType);
- if(0 > componentSize) {
+ componentByteSize = GLBuffers.sizeOfGLType(componentType);
+ if(0 > componentByteSize) {
throw new GLException("Given componentType not supported: "+componentType+":\n\t"+this);
}
if(0 >= components) {
@@ -264,16 +265,15 @@ public class GLArrayDataWrapper implements GLArrayData {
}
this.components = components;
- if(0<stride && stride<components*componentSize) {
- throw new GLException("stride ("+stride+") lower than component bytes, "+components+" * "+componentSize);
+ if(0<stride && stride<components*componentByteSize) {
+ throw new GLException("stride ("+stride+") lower than component bytes, "+components+" * "+componentByteSize);
}
- if(0<stride && stride%componentSize!=0) {
- throw new GLException("stride ("+stride+") not a multiple of bpc "+componentSize);
+ if(0<stride && stride%componentByteSize!=0) {
+ throw new GLException("stride ("+stride+") not a multiple of bpc "+componentByteSize);
}
this.buffer = data;
- this.stride=stride;
- this.strideB=(0==stride)?components*componentSize:stride;
- this.strideL=(0==stride)?components:strideB/componentSize;
+ this.strideB=(0==stride)?components*componentByteSize:stride;
+ this.strideL=strideB/componentByteSize;
this.vboName= vboName;
this.vboEnabled= 0 != vboName ;
this.vboOffset=vboOffset;
@@ -309,9 +309,8 @@ public class GLArrayDataWrapper implements GLArrayData {
protected int components;
protected int componentType;
protected Class componentClazz;
- protected int componentSize;
+ protected int componentByteSize;
protected boolean normalized;
- protected int stride; // user given stride
protected int strideB; // stride in bytes
protected int strideL; // stride in logical components
protected Buffer buffer;
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayHandler.java
index bfabb5b01..ee80c4299 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayHandler.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayHandler.java
@@ -3,9 +3,30 @@ package com.jogamp.opengl.util;
import javax.media.opengl.*;
+/**
+ * Handles consistency of buffer data and array state.
+ * Implementations shall consider buffer types (VBO, ..), interleaved, etc.
+ * They also need to consider array state types, i.e. fixed function or GLSL.
+ */
public interface GLArrayHandler {
+ /**
+ * Implementation shall ensure the buffers data is synchronized to the GPU
+ * and the array state is enabled.
+ *
+ * @param gl current GL object
+ * @param enable true if array shall be enabled, otherwise false.
+ */
public void enableBuffer(GL gl, boolean enable);
+
+ /**
+ * Supporting interleaved arrays, where sub handlers may handle
+ * the array state and the <i>master</i> handler the buffer consistency.
+ *
+ * @param handler the sub handler
+ * @throws UnsupportedOperationException if this array handler does not support interleaved arrays
+ */
+ public void addSubHandler(GLArrayHandler handler) throws UnsupportedOperationException;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java
deleted file mode 100644
index 74d49aa6c..000000000
--- a/src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java
+++ /dev/null
@@ -1,41 +0,0 @@
-
-package com.jogamp.opengl.util;
-
-import javax.media.opengl.*;
-import javax.media.opengl.fixedfunc.*;
-import com.jogamp.opengl.util.*;
-import java.nio.*;
-
-public class GLDataArrayHandler implements GLArrayHandler {
- private GLArrayDataEditable ad;
-
- public GLDataArrayHandler(GLArrayDataEditable ad) {
- this.ad = ad;
- }
-
- public void enableBuffer(GL gl, boolean enable) {
- GLPointerFunc glp = gl.getGL2ES1();
- if(enable) {
- 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(ad.getVBOTarget(), ad.getVBOName());
- if(!ad.isVBOWritten()) {
- if(null!=buffer) {
- gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSize(), buffer, ad.getVBOUsage());
- }
- ad.setVBOWritten(true);
- }
- } else if(null!=buffer) {
- ad.setVBOWritten(true);
- }
- } else {
- if(ad.isVBO()) {
- gl.glBindBuffer(ad.getVBOTarget(), 0);
- }
- }
- }
-}
-
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java
deleted file mode 100644
index a825ca690..000000000
--- a/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java
+++ /dev/null
@@ -1,65 +0,0 @@
-
-package com.jogamp.opengl.util;
-
-import javax.media.opengl.*;
-import javax.media.opengl.fixedfunc.*;
-import com.jogamp.opengl.util.*;
-import java.nio.*;
-
-public class GLFixedArrayHandler implements GLArrayHandler {
- private GLArrayDataEditable ad;
-
- public GLFixedArrayHandler(GLArrayDataEditable ad) {
- this.ad = ad;
- }
-
- private 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(ad.getVBOTarget(), ad.getVBOName());
- if(!ad.isVBOWritten()) {
- if(null!=buffer) {
- gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSize(), buffer, ad.getVBOUsage());
- }
- ad.setVBOWritten(true);
- }
- passArrayPointer(glp);
- } else if(null!=buffer) {
- passArrayPointer(glp);
- ad.setVBOWritten(true);
- }
- } else {
- if(ad.isVBO()) {
- gl.glBindBuffer(ad.getVBOTarget(), 0);
- }
- glp.glDisableClientState(ad.getIndex());
- }
- }
-}
-
diff --git a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java
index 0e1b7926e..bf6e8c025 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java
@@ -48,49 +48,36 @@ public class PMVMatrix implements GLMatrixFunc {
public PMVMatrix() {
projectFloat = new ProjectFloat();
- matrixIdent = Buffers.newDirectFloatBuffer(1*16);
- projectFloat.gluMakeIdentityf(matrixIdent);
- matrixIdent.rewind();
-
+ // I Identity
// T Texture
// P Projection
// Mv ModelView
// Mvi Modelview-Inverse
// Mvit Modelview-Inverse-Transpose
- // Pmv P * Mv
- matrixTPMvMvitPmv = Buffers.newDirectFloatBuffer(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 = Buffers.newDirectFloatBuffer(3*3);
-
- localBuf = Buffers.newDirectFloatBuffer(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);
+ matrixITPMvMvitL = Buffers.newDirectFloatBuffer(12*16); // I + T + P + Mv + Mvi + Mvit + Local
+ matrixIdent = slice(matrixITPMvMvitL, 0*16, 1*16); // I
+ matrixTex = slice(matrixITPMvMvitL, 1*16, 1*16); // T
+ matrixPMvMvit = slice(matrixITPMvMvitL, 2*16, 4*16); // P + Mv + Mvi + Mvit
+ matrixPMvMvi = slice(matrixITPMvMvitL, 2*16, 3*16); // P + Mv + Mvi
+ matrixPMv = slice(matrixITPMvMvitL, 2*16, 2*16); // P + Mv
+ matrixP = slice(matrixITPMvMvitL, 2*16, 1*16); // P
+ matrixMv = slice(matrixITPMvMvitL, 3*16, 1*16); // Mv
+ matrixMvi = slice(matrixITPMvMvitL, 4*16, 1*16); // Mvi
+ matrixMvit = slice(matrixITPMvMvitL, 5*16, 1*16); // Mvit
+ matrixMult = slice(matrixITPMvMvitL, 6*16, 1*16);
+ matrixTrans = slice(matrixITPMvMvitL, 7*16, 1*16);
+ matrixRot = slice(matrixITPMvMvitL, 8*16, 1*16);
+ matrixScale = slice(matrixITPMvMvitL, 9*16, 1*16);
+ matrixOrtho = slice(matrixITPMvMvitL, 10*16, 1*16);
+ matrixFrustum = slice(matrixITPMvMvitL, 11*16, 1*16);
+ matrixITPMvMvitL.rewind();
+
+ ProjectFloat.gluMakeIdentityf(matrixIdent);
+ ProjectFloat.gluMakeIdentityf(matrixTrans);
+ ProjectFloat.gluMakeIdentityf(matrixRot);
+ ProjectFloat.gluMakeIdentityf(matrixScale);
+ ProjectFloat.gluMakeIdentityf(matrixOrtho);
+ ProjectFloat.gluMakeZero(matrixFrustum);
vec3f=new float[3];
@@ -105,6 +92,7 @@ public class PMVMatrix implements GLMatrixFunc {
glMatrixMode(GL.GL_TEXTURE);
glLoadIdentity();
setDirty();
+ update();
}
public void destroy() {
@@ -112,17 +100,8 @@ public class PMVMatrix implements GLMatrixFunc {
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!=matrixITPMvMvitL) {
+ matrixITPMvMvitL.clear(); matrixITPMvMvitL=null;
}
if(null!=matrixPStack) {
@@ -139,8 +118,8 @@ public class PMVMatrix implements GLMatrixFunc {
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;
+ matrixITPMvMvitL=null; matrixPMvMvit=null; matrixPMvMvi=null; matrixPMv=null;
+ matrixP=null; matrixTex=null; matrixMv=null; matrixMvi=null; matrixMvit=null;
matrixMult=null; matrixTrans=null; matrixRot=null; matrixScale=null; matrixOrtho=null; matrixFrustum=null;
}
@@ -228,17 +207,20 @@ public class PMVMatrix implements GLMatrixFunc {
return modified!=0;
}
+ /**
+ * Update the derived Mvi, Mvit and Pmv matrices
+ * in case Mv or P has changed.
+ *
+ * @return
+ */
public boolean update() {
- // if(0==modified) return false;
+ if(0==modified) return false;
- // int res = modified;
- int res = DIRTY_MODELVIEW | DIRTY_PROJECTION ;
+ final 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;
}
@@ -248,7 +230,7 @@ public class PMVMatrix implements GLMatrixFunc {
}
public final FloatBuffer glGetTMatrixf() {
- return matrixT;
+ return matrixTex;
}
public final FloatBuffer glGetPMatrixf() {
@@ -259,10 +241,6 @@ public class PMVMatrix implements GLMatrixFunc {
return matrixMv;
}
- public final FloatBuffer glGetPMvMvitPmvMatrixf() {
- return matrixPMvMvitPmv;
- }
-
public final FloatBuffer glGetPMvMvitMatrixf() {
return matrixPMvMvit;
}
@@ -279,14 +257,6 @@ public class PMVMatrix implements GLMatrixFunc {
return matrixMvi;
}
- public final FloatBuffer glGetPmvMatrixf() {
- return matrixPmv;
- }
-
- public final FloatBuffer glGetNormalMatrixf() {
- return matrixMvit3;
- }
-
/*
* @return the current matrix
*/
@@ -304,7 +274,7 @@ public class PMVMatrix implements GLMatrixFunc {
} else if(matrixName==GL_PROJECTION) {
return matrixP;
} else if(matrixName==GL.GL_TEXTURE) {
- return matrixT;
+ return matrixTex;
} else {
throw new GLException("unsupported matrixName: "+matrixName);
}
@@ -403,9 +373,9 @@ public class PMVMatrix implements GLMatrixFunc {
matrixP.rewind();
modified |= DIRTY_PROJECTION ;
} else if(matrixMode==GL.GL_TEXTURE) {
- matrixT.clear();
- matrixT.put(values, offset, len);
- matrixT.rewind();
+ matrixTex.clear();
+ matrixTex.put(values, offset, len);
+ matrixTex.rewind();
modified |= DIRTY_TEXTURE ;
}
}
@@ -423,9 +393,9 @@ public class PMVMatrix implements GLMatrixFunc {
matrixP.rewind();
modified |= DIRTY_PROJECTION ;
} else if(matrixMode==GL.GL_TEXTURE) {
- matrixT.clear();
- matrixT.put(m);
- matrixT.rewind();
+ matrixTex.clear();
+ matrixTex.put(m);
+ matrixTex.rewind();
modified |= DIRTY_TEXTURE ;
}
m.position(spos);
@@ -454,8 +424,8 @@ public class PMVMatrix implements GLMatrixFunc {
matrixP.rewind();
matrixPStack.add(0, stackEntry);
} else if(matrixMode==GL.GL_TEXTURE) {
- matrixT.get(stackEntry);
- matrixT.rewind();
+ matrixTex.get(stackEntry);
+ matrixTex.rewind();
matrixTStack.add(0, stackEntry);
}
}
@@ -474,9 +444,9 @@ public class PMVMatrix implements GLMatrixFunc {
matrixIdent.rewind();
modified |= DIRTY_PROJECTION ;
} else if(matrixMode==GL.GL_TEXTURE) {
- matrixT.clear();
- matrixT.put(matrixIdent);
- matrixT.rewind();
+ matrixTex.clear();
+ matrixTex.put(matrixIdent);
+ matrixTex.rewind();
matrixIdent.rewind();
modified |= DIRTY_TEXTURE ;
}
@@ -496,10 +466,10 @@ public class PMVMatrix implements GLMatrixFunc {
matrixP.rewind();
modified |= DIRTY_PROJECTION ;
} else if(matrixMode==GL.GL_TEXTURE) {
- glMultMatrixf(matrixT, m, matrixMult);
- matrixT.clear();
- matrixT.put(matrixMult);
- matrixT.rewind();
+ glMultMatrixf(matrixTex, m, matrixMult);
+ matrixTex.clear();
+ matrixTex.put(matrixMult);
+ matrixTex.rewind();
modified |= DIRTY_TEXTURE ;
}
matrixMult.rewind();
@@ -519,10 +489,10 @@ public class PMVMatrix implements GLMatrixFunc {
matrixP.rewind();
modified |= DIRTY_PROJECTION ;
} else if(matrixMode==GL.GL_TEXTURE) {
- glMultMatrixf(matrixT, m, m_offset, matrixMult);
- matrixT.clear();
- matrixT.put(matrixMult);
- matrixT.rewind();
+ glMultMatrixf(matrixTex, m, m_offset, matrixMult);
+ matrixTex.clear();
+ matrixTex.put(matrixMult);
+ matrixTex.rewind();
modified |= DIRTY_TEXTURE ;
}
matrixMult.rewind();
@@ -541,13 +511,13 @@ public class PMVMatrix implements GLMatrixFunc {
}
public final void glRotatef(final float angdeg, float x, float y, float z) {
- float angrad = angdeg * (float) Math.PI / 180;
+ float angrad = angdeg * (float) Math.PI / 180.0f;
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);
+ ProjectFloat.normalize(vec3f);
x = vec3f[0]; y = vec3f[1]; z = vec3f[2];
// Rotation matrix:
@@ -661,19 +631,11 @@ public class PMVMatrix implements GLMatrixFunc {
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 FloatBuffer matrixITPMvMvitL;
+ protected FloatBuffer matrixIdent, matrixPMvMvit, matrixPMvMvi, matrixPMv, matrixP, matrixTex, matrixMv, matrixMvi, matrixMvit;
+ protected FloatBuffer matrixMult, matrixTrans, matrixRot, matrixScale, matrixOrtho, matrixFrustum;
protected float[] vec3f;
protected List/*FloatBuffer*/ matrixTStack, matrixPStack, matrixMvStack;
protected int matrixMode = GL_MODELVIEW;
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java
deleted file mode 100644
index cc9be681c..000000000
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions 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.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-
-package com.jogamp.opengl.util.glsl;
-
-import java.nio.Buffer;
-
-import javax.media.opengl.GL;
-import javax.media.opengl.GL2ES2;
-import javax.media.opengl.GLException;
-import com.jogamp.opengl.util.GLArrayDataEditable;
-import com.jogamp.opengl.util.GLArrayHandler;
-
-public class GLSLArrayHandler implements GLArrayHandler {
- private static final boolean DEBUG = ShaderState.DEBUG;
- private GLArrayDataEditable ad;
- private ShaderState st;
-
- public GLSLArrayHandler(ShaderState st, GLArrayDataEditable ad) {
- this.st = st;
- this.ad = ad;
- }
-
- public void enableBuffer(GL gl, boolean enable) {
- if(!gl.isGL2ES2()) {
- throw new GLException("GLSLArrayHandler expects a GL2ES2 implementation");
- }
- GL2ES2 glsl = gl.getGL2ES2();
-
- if(enable) {
- st.enableVertexAttribArray(glsl, ad);
-
- Buffer buffer = ad.getBuffer();
-
- if(ad.isVBO()) {
- // bind and refresh the VBO / vertex-attr only if necessary
- if(!ad.isVBOWritten()) {
- if(DEBUG) {
- System.err.println("XXX VA "+ad.getName()+" VBO write: "+ad.getVBOName());
- }
- glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName());
- if(null!=buffer) {
- glsl.glBufferData(ad.getVBOTarget(), ad.getByteSize(), buffer, ad.getVBOUsage());
- }
- ad.setVBOWritten(true);
- st.vertexAttribPointer(glsl, ad);
- } else if(ad.getLocation() >= 0) {
- // didn't experience a performance hit on this query ..
- final int[] qi = new int[1];
- glsl.glGetVertexAttribiv(ad.getLocation(), GL2ES2.GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, qi, 0);
- if(ad.getVBOName() != qi[0]) {
- if(DEBUG) {
- System.err.println("XXX VA "+ad.getName()+" VBO rebind: "+qi[0]+" -> "+ad.getVBOName());
- }
- glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName());
- st.vertexAttribPointer(glsl, ad);
- }
- }
- } else if(null!=buffer) {
- st.vertexAttribPointer(glsl, ad);
- ad.setVBOWritten(true);
- }
- } else {
- if(ad.isVBO()) {
- glsl.glBindBuffer(ad.getVBOTarget(), 0);
- }
- st.disableVertexAttribArray(glsl, ad);
- }
- }
-
-}
-
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java
index 565b5ab1c..8dd09ffab 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java
@@ -229,7 +229,7 @@ public class ShaderProgram {
*
* @param gl
* @param verboseOut
- * @return
+ * @return true if program was successfully linked and is valid, otherwise false
*
* @see #init(GL2ES2)
*/
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java
index c2b3308db..d92a7aa22 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/FixedFuncUtil.java
@@ -63,30 +63,30 @@ public class FixedFuncUtil {
* @see javax.media.opengl.fixedfunc.GLPointerFunc#glTexCoordPointer
*/
public static String getPredefinedArrayIndexName(int glArrayIndex) {
- return FixedFuncPipeline.getPredefinedArrayIndexName(glArrayIndex);
+ return GLPointerFuncUtil.getPredefinedArrayIndexName(glArrayIndex);
}
/**
* String name for
* @see javax.media.opengl.GL2#GL_VERTEX_ARRAY
*/
- public static final String mgl_Vertex = FixedFuncPipeline.mgl_Vertex;
+ public static final String mgl_Vertex = GLPointerFuncUtil.mgl_Vertex;
/**
* String name for
* @see javax.media.opengl.GL2#GL_NORMAL_ARRAY
*/
- public static final String mgl_Normal = FixedFuncPipeline.mgl_Normal;
+ public static final String mgl_Normal = GLPointerFuncUtil.mgl_Normal;
/**
* String name for
* @see javax.media.opengl.GL2#GL_COLOR_ARRAY
*/
- public static final String mgl_Color = FixedFuncPipeline.mgl_Color;
+ public static final String mgl_Color = GLPointerFuncUtil.mgl_Color;
/**
* String name for
* @see javax.media.opengl.GL2#GL_TEXTURE_COORD_ARRAY
*/
- public static final String mgl_MultiTexCoord = FixedFuncPipeline.mgl_MultiTexCoord;
+ public static final String mgl_MultiTexCoord = GLPointerFuncUtil.mgl_MultiTexCoord;
}