diff options
Diffstat (limited to 'src')
24 files changed, 677 insertions, 272 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java index 99500adfb..a61fe0d27 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java @@ -217,11 +217,11 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData } } - public void padding(int done) { + public void padding(int doneInByteSize) { if ( buffer==null || sealed ) return; - while(done<strideL) { + while(doneInByteSize<strideB) { Buffers.putb(buffer, (byte)0); - done++; + doneInByteSize++; } } @@ -233,9 +233,10 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData */ public void put(Buffer v) { if ( sealed ) return; + /** FIXME: isn't true for interleaved arrays ! if(0!=(v.remaining() % strideL)) { throw new GLException("Buffer length ("+v.remaining()+") is not a multiple of component-stride:\n\t"+this); - } + } */ growBufferIfNecessary(v.remaining()); Buffers.put(buffer, v); } diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java index 0da7d1171..bb22a4b7e 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java @@ -96,7 +96,7 @@ public interface GLArrayDataEditable extends GLArrayData { public void seal(boolean seal); public void rewind(); - public void padding(int done); + public void padding(int doneInByteSize); public void put(Buffer v); public void putb(byte v); public void puts(short v); diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java index d3bb2e3fd..8d9d839e2 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java @@ -16,6 +16,7 @@ import jogamp.opengl.util.GLFixedArrayHandler; import jogamp.opengl.util.GLFixedArrayHandlerFlat; import jogamp.opengl.util.glsl.GLSLArrayHandler; import jogamp.opengl.util.glsl.GLSLArrayHandlerFlat; +import jogamp.opengl.util.glsl.GLSLArrayHandlerInterleaved; public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataEditable { @@ -224,15 +225,14 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE if(usesGLSL) { throw new GLException("buffer uses GLSL"); } - GLArrayDataWrapper ad = GLArrayDataWrapper.createFixed( + final GLArrayDataWrapper ad = GLArrayDataWrapper.createFixed( index, comps, getComponentType(), getNormalized(), getStride(), getBuffer(), getVBOName(), interleavedOffset, getVBOUsage(), vboTarget); ad.setVBOEnabled(isVBO()); interleavedOffset += comps * getComponentSizeInBytes(); if(GL.GL_ARRAY_BUFFER == vboTarget) { - GLArrayHandler handler = new GLFixedArrayHandlerFlat(ad); - glArrayHandler.addSubHandler(handler); + glArrayHandler.addSubHandler(new GLFixedArrayHandlerFlat(ad)); } return ad; } @@ -253,7 +253,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE throws GLException { GLArrayDataServer ads = new GLArrayDataServer(); - GLArrayHandler glArrayHandler = new GLArrayHandlerInterleaved(ads); + GLArrayHandler glArrayHandler = new GLSLArrayHandlerInterleaved(ads); ads.init(GLPointerFuncUtil.mgl_InterleaveArray, -1, comps, dataType, false, 0, null, initialSize, false, glArrayHandler, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, true); return ads; @@ -280,15 +280,14 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE if(!usesGLSL) { throw new GLException("buffer uses fixed function"); } - GLArrayDataWrapper ad = GLArrayDataWrapper.createGLSL( + final GLArrayDataWrapper ad = GLArrayDataWrapper.createGLSL( name, comps, getComponentType(), getNormalized(), getStride(), getBuffer(), getVBOName(), interleavedOffset, getVBOUsage(), vboTarget); ad.setVBOEnabled(isVBO()); interleavedOffset += comps * getComponentSizeInBytes(); if(GL.GL_ARRAY_BUFFER == vboTarget) { - GLArrayHandler handler = new GLSLArrayHandlerFlat(ad); - glArrayHandler.addSubHandler(handler); + glArrayHandler.addSubHandler(new GLSLArrayHandlerFlat(ad)); } return ad; } @@ -371,6 +370,9 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE int[] tmp = new int[1]; gl.glGenBuffers(1, tmp, 0); vboName = tmp[0]; + if(0 < interleavedOffset) { + glArrayHandler.setSubArrayVBOName(vboName); + } } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java index aba6c90a7..a86a2f435 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java +++ b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java @@ -45,7 +45,30 @@ import javax.media.opengl.fixedfunc.GLMatrixFunc; public class PMVMatrix implements GLMatrixFunc { + protected final float[] matrixBufferArray; + + /** + * Creates an instance of PMVMatrix {@link #PMVMatrix(boolean) PMVMatrix(boolean useBackingArray)}, + * with <code>useBackingArray = true</code>. + */ public PMVMatrix() { + this(true); + } + + /** + * Creates an instance of PMVMatrix. + * + * @param useBackingArray <code>true</code> for non direct NIO Buffers with guaranteed backing array, + * which allows faster access in Java computation. + * <p><code>false</code> for direct NIO buffers w/o a guaranteed backing array. + * In most Java implementations, direct NIO buffers have no backing array + * and hence the Java computation will be throttled down by direct IO get/put + * operations.</p> + * <p>Depending on the application, ie. weather the Java computation or + * JNI invocation and hence native data transfer part is heavier, + * this flag shall be set to <code>true</code> or <code>false</code></p>. + */ + public PMVMatrix(boolean useBackingArray) { projectFloat = new ProjectFloat(); // I Identity @@ -54,33 +77,43 @@ public class PMVMatrix implements GLMatrixFunc { // Mv ModelView // Mvi Modelview-Inverse // Mvit Modelview-Inverse-Transpose - matrixBuffer = Buffers.newDirectByteBuffer(12*16 * Buffers.SIZEOF_FLOAT); - // I + T + P + Mv + Mvi + Mvit + Local - matrixIdent = slice2Float(matrixBuffer, 0*16, 1*16); // I - matrixTex = slice2Float(matrixBuffer, 1*16, 1*16); // T - matrixPMvMvit = slice2Float(matrixBuffer, 2*16, 4*16); // P + Mv + Mvi + Mvit - matrixPMvMvi = slice2Float(matrixBuffer, 2*16, 3*16); // P + Mv + Mvi - matrixPMv = slice2Float(matrixBuffer, 2*16, 2*16); // P + Mv - matrixP = slice2Float(matrixBuffer, 2*16, 1*16); // P - matrixMv = slice2Float(matrixBuffer, 3*16, 1*16); // Mv - matrixMvi = slice2Float(matrixBuffer, 4*16, 1*16); // Mvi - matrixMvit = slice2Float(matrixBuffer, 5*16, 1*16); // Mvit - matrixMult = slice2Float(matrixBuffer, 6*16, 1*16); - matrixTrans = slice2Float(matrixBuffer, 7*16, 1*16); - matrixRot = slice2Float(matrixBuffer, 8*16, 1*16); - matrixScale = slice2Float(matrixBuffer, 9*16, 1*16); - matrixOrtho = slice2Float(matrixBuffer, 10*16, 1*16); - matrixFrustum = slice2Float(matrixBuffer, 11*16, 1*16); - matrixBuffer.rewind(); + if(useBackingArray) { + matrixBufferArray = new float[6*16]; + matrixBuffer = null; + // matrixBuffer = FloatBuffer.wrap(new float[12*16]); + } else { + matrixBufferArray = null; + matrixBuffer = Buffers.newDirectByteBuffer(6*16 * Buffers.SIZEOF_FLOAT); + matrixBuffer.mark(); + } + matrixIdent = slice2Float(matrixBuffer, matrixBufferArray, 0*16, 1*16); // I + matrixTex = slice2Float(matrixBuffer, matrixBufferArray, 1*16, 1*16); // T + matrixPMvMvit = slice2Float(matrixBuffer, matrixBufferArray, 2*16, 4*16); // P + Mv + Mvi + Mvit + matrixPMvMvi = slice2Float(matrixBuffer, matrixBufferArray, 2*16, 3*16); // P + Mv + Mvi + matrixPMv = slice2Float(matrixBuffer, matrixBufferArray, 2*16, 2*16); // P + Mv + matrixP = slice2Float(matrixBuffer, matrixBufferArray, 2*16, 1*16); // P + matrixMv = slice2Float(matrixBuffer, matrixBufferArray, 3*16, 1*16); // Mv + matrixMvi = slice2Float(matrixBuffer, matrixBufferArray, 4*16, 1*16); // Mvi + matrixMvit = slice2Float(matrixBuffer, matrixBufferArray, 5*16, 1*16); // Mvit + + if(null != matrixBuffer) { + matrixBuffer.reset(); + } ProjectFloat.gluMakeIdentityf(matrixIdent); - ProjectFloat.gluMakeIdentityf(matrixTrans); - ProjectFloat.gluMakeIdentityf(matrixRot); - ProjectFloat.gluMakeIdentityf(matrixScale); - ProjectFloat.gluMakeIdentityf(matrixOrtho); - ProjectFloat.gluMakeZero(matrixFrustum); - - vec3f=new float[3]; + + vec3f = new float[3]; + matrixMult = new float[16]; + matrixTrans = new float[16]; + matrixRot = new float[16]; + matrixScale = new float[16]; + matrixOrtho = new float[16]; + matrixFrustum = new float[16]; + ProjectFloat.gluMakeIdentityf(matrixTrans, 0); + ProjectFloat.gluMakeIdentityf(matrixRot, 0); + ProjectFloat.gluMakeIdentityf(matrixScale, 0); + ProjectFloat.gluMakeIdentityf(matrixOrtho, 0); + ProjectFloat.gluMakeZero(matrixFrustum, 0); matrixPStack = new ArrayList<float[]>(); matrixMvStack= new ArrayList<float[]>(); @@ -101,27 +134,30 @@ public class PMVMatrix implements GLMatrixFunc { projectFloat.destroy(); projectFloat=null; } - if(null!=matrixBuffer) { - matrixBuffer.clear(); matrixBuffer=null; - } - + matrixBuffer=null; + matrixBuffer=null; matrixPMvMvit=null; matrixPMvMvi=null; matrixPMv=null; + matrixP=null; matrixTex=null; matrixMv=null; matrixMvi=null; matrixMvit=null; + + vec3f = null; + matrixMult = null; + matrixTrans = null; + matrixRot = null; + matrixScale = null; + matrixOrtho = null; + matrixFrustum = null; + if(null!=matrixPStack) { matrixPStack.clear(); matrixPStack=null; } - vec3f=null; if(null!=matrixMvStack) { matrixMvStack.clear(); matrixMvStack=null; } if(null!=matrixPStack) { - matrixPStack.clear(); matrixPStack=null; + matrixPStack.clear(); matrixPStack=null; } if(null!=matrixTStack) { matrixTStack.clear(); matrixTStack=null; } - - matrixBuffer=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; } @@ -133,14 +169,33 @@ public class PMVMatrix implements GLMatrixFunc { * This bug is resolved at least in Android 3.2. * * @param buf source ByteBuffer + * @param backing source float array * @param posFloat {@link Buffers#SIZEOF_FLOAT} position * @param lenFloat {@link Buffers#SIZEOF_FLOAT} size * @return FloatBuffer w/ native byte order as given ByteBuffer */ - private static FloatBuffer slice2Float(ByteBuffer buf, int posFloat, int lenFloat) { - buf.position( posFloat * Buffers.SIZEOF_FLOAT ); - buf.limit( (posFloat + lenFloat) * Buffers.SIZEOF_FLOAT ); - return buf.slice().order(buf.order()).asFloatBuffer(); // slice and duplicate may change byte order + private static FloatBuffer slice2Float(Buffer buf, float[] backing, int posFloat, int lenFloat) { + if(buf instanceof ByteBuffer) { + ByteBuffer bb = (ByteBuffer) buf; + bb.position( posFloat * Buffers.SIZEOF_FLOAT ); + bb.limit( (posFloat + lenFloat) * Buffers.SIZEOF_FLOAT ); + FloatBuffer fb = bb.slice().order(bb.order()).asFloatBuffer(); // slice and duplicate may change byte order + fb.mark(); + return fb; + } else if(null != backing) { + FloatBuffer fb = FloatBuffer.wrap(backing, posFloat, lenFloat); + fb.mark(); + return fb; + } else if(buf instanceof FloatBuffer) { + FloatBuffer fb = (FloatBuffer) buf; + fb.position( posFloat ); + fb.limit( posFloat + lenFloat ); + FloatBuffer fb0 = fb.slice(); // slice and duplicate may change byte order + fb0.mark(); + return fb0; + } else { + throw new InternalError("XXX"); + } } public static final boolean isMatrixModeName(final int matrixModeName) { @@ -231,7 +286,6 @@ public class PMVMatrix implements GLMatrixFunc { if(0==modified) return false; final int res = modified; - // int res = DIRTY_MODELVIEW | DIRTY_PROJECTION ; if( (res&DIRTY_MODELVIEW)!=0 ) { setMviMvit(); } @@ -255,11 +309,8 @@ public class PMVMatrix implements GLMatrixFunc { return matrixMv; } - public final FloatBuffer glGetPMvMvitMatrixf() { - return matrixPMvMvit; - } - public final FloatBuffer glGetPMvMviMatrixf() { + usesMviMvit |= 1; return matrixPMvMvi; } @@ -268,9 +319,20 @@ public class PMVMatrix implements GLMatrixFunc { } public final FloatBuffer glGetMviMatrixf() { + usesMviMvit |= 1; return matrixMvi; } + public final FloatBuffer glGetPMvMvitMatrixf() { + usesMviMvit |= 1 | 2; + return matrixPMvMvit; + } + + public final FloatBuffer glGetMvitMatrixf() { + usesMviMvit |= 1 | 2; + return matrixMvit; + } + /* * @return the current matrix */ @@ -302,22 +364,27 @@ public class PMVMatrix implements GLMatrixFunc { glFrustumf(left, right, bottom, top, zNear, zFar); } - public static final void glMultMatrixf(final FloatBuffer a, final FloatBuffer b, FloatBuffer p) { + public static final void glMultMatrixf(final FloatBuffer a, final FloatBuffer b, FloatBuffer d) { + final int aP = a.position(); + final int bP = b.position(); + final int dP = d.position(); 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) ); + final float ai0=a.get(aP+i+0*4), ai1=a.get(aP+i+1*4), ai2=a.get(aP+i+2*4), ai3=a.get(aP+i+3*4); + d.put(dP+i+0*4 , ai0 * b.get(bP+0+0*4) + ai1 * b.get(bP+1+0*4) + ai2 * b.get(bP+2+0*4) + ai3 * b.get(bP+3+0*4) ); + d.put(dP+i+1*4 , ai0 * b.get(bP+0+1*4) + ai1 * b.get(bP+1+1*4) + ai2 * b.get(bP+2+1*4) + ai3 * b.get(bP+3+1*4) ); + d.put(dP+i+2*4 , ai0 * b.get(bP+0+2*4) + ai1 * b.get(bP+1+2*4) + ai2 * b.get(bP+2+2*4) + ai3 * b.get(bP+3+2*4) ); + d.put(dP+i+3*4 , ai0 * b.get(bP+0+3*4) + ai1 * b.get(bP+1+3*4) + ai2 * b.get(bP+2+3*4) + ai3 * b.get(bP+3+3*4) ); } } - public static final void glMultMatrixf(final FloatBuffer a, final float[] b, int b_off, FloatBuffer p) { + public static final void glMultMatrixf(final FloatBuffer a, final float[] b, int b_off, FloatBuffer d) { + final int aP = a.position(); + final int dP = d.position(); 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] ); + final float ai0=a.get(aP+i+0*4), ai1=a.get(aP+i+1*4), ai2=a.get(aP+i+2*4), ai3=a.get(aP+i+3*4); + d.put(dP+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] ); + d.put(dP+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] ); + d.put(dP+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] ); + d.put(dP+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] ); } } @@ -343,8 +410,8 @@ public class PMVMatrix implements GLMatrixFunc { params.put((float)matrixMode); } else { FloatBuffer matrix = glGetMatrixf(matrixGetName2MatrixModeName(matrixGetName)); - params.put(matrix); - matrix.rewind(); + params.put(matrix); // matrix -> params + matrix.reset(); } params.position(pos); } @@ -353,8 +420,8 @@ public class PMVMatrix implements GLMatrixFunc { params[params_offset]=(float)matrixMode; } else { FloatBuffer matrix = glGetMatrixf(matrixGetName2MatrixModeName(matrixGetName)); - matrix.get(params, params_offset, 16); - matrix.rewind(); + matrix.get(params, params_offset, 16); // matrix -> params + matrix.reset(); } } public void glGetIntegerv(int pname, IntBuffer params) { @@ -377,19 +444,16 @@ public class PMVMatrix implements GLMatrixFunc { 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(); + matrixMv.reset(); modified |= DIRTY_MODELVIEW ; } else if(matrixMode==GL_PROJECTION) { - matrixP.clear(); matrixP.put(values, offset, len); - matrixP.rewind(); + matrixP.reset(); modified |= DIRTY_PROJECTION ; } else if(matrixMode==GL.GL_TEXTURE) { - matrixTex.clear(); matrixTex.put(values, offset, len); - matrixTex.rewind(); + matrixTex.reset(); modified |= DIRTY_TEXTURE ; } } @@ -397,19 +461,16 @@ public class PMVMatrix implements GLMatrixFunc { public final void glLoadMatrixf(java.nio.FloatBuffer m) { int spos = m.position(); if(matrixMode==GL_MODELVIEW) { - matrixMv.clear(); matrixMv.put(m); - matrixMv.rewind(); + matrixMv.reset(); modified |= DIRTY_MODELVIEW ; } else if(matrixMode==GL_PROJECTION) { - matrixP.clear(); matrixP.put(m); - matrixP.rewind(); + matrixP.reset(); modified |= DIRTY_PROJECTION ; } else if(matrixMode==GL.GL_TEXTURE) { - matrixTex.clear(); matrixTex.put(m); - matrixTex.rewind(); + matrixTex.reset(); modified |= DIRTY_TEXTURE ; } m.position(spos); @@ -431,85 +492,60 @@ public class PMVMatrix implements GLMatrixFunc { float[] stackEntry = new float[1*16]; if(matrixMode==GL_MODELVIEW) { matrixMv.get(stackEntry); - matrixMv.rewind(); + matrixMv.reset(); matrixMvStack.add(0, stackEntry); } else if(matrixMode==GL_PROJECTION) { matrixP.get(stackEntry); - matrixP.rewind(); + matrixP.reset(); matrixPStack.add(0, stackEntry); } else if(matrixMode==GL.GL_TEXTURE) { matrixTex.get(stackEntry); - matrixTex.rewind(); + matrixTex.reset(); matrixTStack.add(0, stackEntry); } } public final void glLoadIdentity() { if(matrixMode==GL_MODELVIEW) { - matrixMv.clear(); matrixMv.put(matrixIdent); - matrixMv.rewind(); - matrixIdent.rewind(); + matrixMv.reset(); modified |= DIRTY_MODELVIEW ; } else if(matrixMode==GL_PROJECTION) { - matrixP.clear(); matrixP.put(matrixIdent); - matrixP.rewind(); - matrixIdent.rewind(); + matrixP.reset(); modified |= DIRTY_PROJECTION ; } else if(matrixMode==GL.GL_TEXTURE) { - matrixTex.clear(); matrixTex.put(matrixIdent); - matrixTex.rewind(); - matrixIdent.rewind(); + matrixTex.reset(); modified |= DIRTY_TEXTURE ; } + matrixIdent.reset(); } public final void glMultMatrixf(final FloatBuffer m) { if(matrixMode==GL_MODELVIEW) { - glMultMatrixf(matrixMv, m, matrixMult); - matrixMv.clear(); - matrixMv.put(matrixMult); - matrixMv.rewind(); + glMultMatrixf(matrixMv, m, matrixMv); modified |= DIRTY_MODELVIEW ; } else if(matrixMode==GL_PROJECTION) { - glMultMatrixf(matrixP, m, matrixMult); - matrixP.clear(); - matrixP.put(matrixMult); - matrixP.rewind(); + glMultMatrixf(matrixP, m, matrixP); modified |= DIRTY_PROJECTION ; } else if(matrixMode==GL.GL_TEXTURE) { - glMultMatrixf(matrixTex, m, matrixMult); - matrixTex.clear(); - matrixTex.put(matrixMult); - matrixTex.rewind(); + glMultMatrixf(matrixTex, m, matrixTex); 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(); + glMultMatrixf(matrixMv, m, m_offset, matrixMv); modified |= DIRTY_MODELVIEW ; } else if(matrixMode==GL_PROJECTION) { - glMultMatrixf(matrixP, m, m_offset, matrixMult); - matrixP.clear(); - matrixP.put(matrixMult); - matrixP.rewind(); + glMultMatrixf(matrixP, m, m_offset, matrixP); modified |= DIRTY_PROJECTION ; } else if(matrixMode==GL.GL_TEXTURE) { - glMultMatrixf(matrixTex, m, m_offset, matrixMult); - matrixTex.clear(); - matrixTex.put(matrixMult); - matrixTex.rewind(); + glMultMatrixf(matrixTex, m, m_offset, matrixTex); modified |= DIRTY_TEXTURE ; } - matrixMult.rewind(); } public final void glTranslatef(final float x, final float y, final float z) { @@ -518,17 +554,17 @@ public class PMVMatrix implements GLMatrixFunc { // 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); + matrixTrans[0+4*3] = x; + matrixTrans[1+4*3] = y; + matrixTrans[2+4*3] = z; + glMultMatrixf(matrixTrans, 0); } public final void glRotatef(final float angdeg, float x, float y, float z) { - 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); + final float angrad = angdeg * (float) Math.PI / 180.0f; + final float c = (float)Math.cos(angrad); + final float ic= 1.0f - c; + final float s = (float)Math.sin(angrad); vec3f[0]=x; vec3f[1]=y; vec3f[2]=z; ProjectFloat.normalize(vec3f); @@ -539,25 +575,25 @@ public class PMVMatrix implements GLMatrixFunc { // 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); + final float xy = x*y; + final float xz = x*z; + final float xs = x*s; + final float ys = y*s; + final float yz = y*z; + final float zs = z*s; + matrixRot[0*4+0] = x*x*ic+c; + matrixRot[0*4+1] = xy*ic+zs; + matrixRot[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[1*4+0] = xy*ic-zs; + matrixRot[1*4+1] = y*y*ic+c; + matrixRot[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); + matrixRot[2*4+0] = xz*ic+ys; + matrixRot[2*4+1] = yz*ic-xs; + matrixRot[2*4+2] = z*z*ic+c; - glMultMatrixf(matrixRot); + glMultMatrixf(matrixRot, 0); } public final void glScalef(final float x, final float y, final float z) { @@ -566,11 +602,11 @@ public class PMVMatrix implements GLMatrixFunc { // 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); + matrixScale[0+4*0] = x; + matrixScale[1+4*1] = y; + matrixScale[2+4*2] = z; - glMultMatrixf(matrixScale); + glMultMatrixf(matrixScale, 0); } public final void glOrthof(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar) { @@ -579,21 +615,21 @@ public class PMVMatrix implements GLMatrixFunc { // 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; + final float dx=right-left; + final float dy=top-bottom; + final float dz=zFar-zNear; + final float tx=-1.0f*(right+left)/dx; + final float ty=-1.0f*(top+bottom)/dy; + final 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); + matrixOrtho[0+4*0] = 2.0f/dx; + matrixOrtho[1+4*1] = 2.0f/dy; + matrixOrtho[2+4*2] = -2.0f/dz; + matrixOrtho[0+4*3] = tx; + matrixOrtho[1+4*3] = ty; + matrixOrtho[2+4*3] = tz; - glMultMatrixf(matrixOrtho); + glMultMatrixf(matrixOrtho, 0); } public final void glFrustumf(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar) { @@ -608,52 +644,87 @@ public class PMVMatrix implements GLMatrixFunc { // 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; + final float zNear2 = 2.0f*zNear; + final float dx=right-left; + final float dy=top-bottom; + final float dz=zFar-zNear; + final float A=(right+left)/dx; + final float B=(top+bottom)/dy; + final float C=-1.0f*(zFar+zNear)/dz; + final 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[0+4*0] = zNear2/dx; + matrixFrustum[1+4*1] = zNear2/dy; + matrixFrustum[2+4*2] = C; - matrixFrustum.put(0+4*2, A); - matrixFrustum.put(1+4*2, B); + matrixFrustum[0+4*2] = A; + matrixFrustum[1+4*2] = B; - matrixFrustum.put(2+4*3, D); - matrixFrustum.put(3+4*2, -1.0f); + matrixFrustum[2+4*3] = D; + matrixFrustum[3+4*2] = -1.0f; - glMultMatrixf(matrixFrustum); + glMultMatrixf(matrixFrustum, 0); } // // private // + private int nioBackupArraySupported = 0; // -1 not supported, 0 - TBD, 1 - supported + private final String msgCantComputeInverse = "Invalid source Mv matrix, can't compute inverse"; private final void setMviMvit() { - if(!projectFloat.gluInvertMatrixf(matrixMv, matrixMvi)) { - throw new GLException("Invalid source Mv matrix, can't compute inverse"); + if( 0 != (usesMviMvit & 1) ) { + if(nioBackupArraySupported>=0) { + try { + setMviMvitNIOBackupArray(); + nioBackupArraySupported = 1; + return; + } catch(UnsupportedOperationException uoe) { + nioBackupArraySupported = -1; + } + } + setMviMvitNIODirectAccess(); } - - // 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)); + } + private final void setMviMvitNIOBackupArray() { + final float[] _matrixMvi = matrixMvi.array(); + final int _matrixMviOffset = matrixMvi.position(); + if(!projectFloat.gluInvertMatrixf(matrixMv.array(), matrixMv.position(), _matrixMvi, _matrixMviOffset)) { + throw new GLException(msgCantComputeInverse); + } + if( 0 != (usesMviMvit & 2) ) { + // transpose matrix + final float[] _matrixMvit = matrixMvit.array(); + final int _matrixMvitOffset = matrixMvit.position(); + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + _matrixMvit[_matrixMvitOffset+j+i*4] = _matrixMvi[_matrixMviOffset+i+j*4]; + } } + } + } + + private final void setMviMvitNIODirectAccess() { + if(!projectFloat.gluInvertMatrixf(matrixMv, matrixMvi)) { + throw new GLException(msgCantComputeInverse); } + if( 0 != (usesMviMvit & 2) ) { + // 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)); + } + } + } } - protected ByteBuffer matrixBuffer; + protected Buffer matrixBuffer; protected FloatBuffer matrixIdent, matrixPMvMvit, matrixPMvMvi, matrixPMv, matrixP, matrixTex, matrixMv, matrixMvi, matrixMvit; - protected FloatBuffer matrixMult, matrixTrans, matrixRot, matrixScale, matrixOrtho, matrixFrustum; - protected float[] vec3f; + protected float[] matrixMult, matrixTrans, matrixRot, matrixScale, matrixOrtho, matrixFrustum, vec3f; protected List<float[]> matrixTStack, matrixPStack, matrixMvStack; protected int matrixMode = GL_MODELVIEW; protected int modified = 0; + protected int usesMviMvit = 0; // 0 - none, 1 - Mvi, 2 - Mvit, 3 - MviMvit (ofc no Mvit w/o Mvi!) protected ProjectFloat projectFloat; public static final int DIRTY_MODELVIEW = 1 << 0; diff --git a/src/jogl/classes/jogamp/opengl/ProjectFloat.java b/src/jogl/classes/jogamp/opengl/ProjectFloat.java index a6316b242..1c69fa370 100644 --- a/src/jogl/classes/jogamp/opengl/ProjectFloat.java +++ b/src/jogl/classes/jogamp/opengl/ProjectFloat.java @@ -235,9 +235,18 @@ public class ProjectFloat { /** * Make matrix an identity matrix */ - public static void gluMakeIdentityf(float[] m) { + public static void gluMakeIdentityf(float[] m, int offset) { for (int i = 0; i < 16; i++) { - m[i] = IDENTITY_MATRIX[i]; + m[i+offset] = IDENTITY_MATRIX[i]; + } + } + + /** + * Make matrix an zero matrix + */ + public static void gluMakeZero(float[] m, int offset) { + for (int i = 0; i < 16; i++) { + m[i+offset] = 0; } } @@ -280,21 +289,22 @@ public class ProjectFloat { /** * @param src + * @param srcOffset * @param inverse - * + * @param inverseOffset * @return */ - public boolean gluInvertMatrixf(float[] src, float[] inverse) { + public boolean gluInvertMatrixf(float[] src, int srcOffset, float[] inverse, int inverseOffset) { int i, j, k, swap; float t; float[][] temp = tempInvertMatrix; for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { - temp[i][j] = src[i*4+j]; + temp[i][j] = src[i*4+j+srcOffset]; } } - gluMakeIdentityf(inverse); + gluMakeIdentityf(inverse, inverseOffset); for (i = 0; i < 4; i++) { // @@ -316,9 +326,9 @@ public class ProjectFloat { temp[i][k] = temp[swap][k]; temp[swap][k] = t; - t = inverse[i*4+k]; - inverse[i*4+k] = inverse[swap*4+k]; - inverse[swap*4+k] = t; + t = inverse[i*4+k+inverseOffset]; + inverse[i*4+k+inverseOffset] = inverse[swap*4+k+inverseOffset]; + inverse[swap*4+k+inverseOffset] = t; } } @@ -333,14 +343,14 @@ public class ProjectFloat { t = temp[i][i]; for (k = 0; k < 4; k++) { temp[i][k] /= t; - inverse[i*4+k] /= t; + inverse[i*4+k+inverseOffset] /= t; } for (j = 0; j < 4; j++) { if (j != i) { t = temp[j][i]; for (k = 0; k < 4; k++) { temp[j][k] -= temp[i][k] * t; - inverse[j*4+k] -= inverse[i*4+k]*t; + inverse[j*4+k+inverseOffset] -= inverse[i*4+k+inverseOffset]*t; } } } @@ -781,7 +791,7 @@ public class ProjectFloat { gluMultMatricesf(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, matrix); - if (!gluInvertMatrixf(matrix, matrix)) + if (!gluInvertMatrixf(matrix, 0, matrix, 0)) return false; in[0] = winx; @@ -907,7 +917,7 @@ public class ProjectFloat { gluMultMatricesf(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, matrix); - if (!gluInvertMatrixf(matrix, matrix)) + if (!gluInvertMatrixf(matrix, 0, matrix, 0)) return false; in[0] = winx; diff --git a/src/jogl/classes/jogamp/opengl/util/GLArrayHandler.java b/src/jogl/classes/jogamp/opengl/util/GLArrayHandler.java index 4a570d3a7..22690b06d 100644 --- a/src/jogl/classes/jogamp/opengl/util/GLArrayHandler.java +++ b/src/jogl/classes/jogamp/opengl/util/GLArrayHandler.java @@ -63,7 +63,9 @@ public interface GLArrayHandler { * @param handler the sub handler * @throws UnsupportedOperationException if this array handler does not support interleaved arrays */ - public void addSubHandler(GLArrayHandler handler) throws UnsupportedOperationException; + public void addSubHandler(GLArrayHandlerFlat handler) throws UnsupportedOperationException; + public void setSubArrayVBOName(int vboName); + } diff --git a/src/jogl/classes/jogamp/opengl/util/GLArrayHandlerFlat.java b/src/jogl/classes/jogamp/opengl/util/GLArrayHandlerFlat.java new file mode 100644 index 000000000..dca9129ad --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/GLArrayHandlerFlat.java @@ -0,0 +1,61 @@ +/** + * Copyright 2011 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 jogamp.opengl.util; + +import javax.media.opengl.*; + +import com.jogamp.opengl.util.GLArrayDataWrapper; + +/** + * Handles consistency of interleaved array state. + */ +public interface GLArrayHandlerFlat { + + /** + * Implementation shall associate the data with the array + * + * @param gl current GL object + * @param enable true if array data shall be valid, otherwise false. + * @param force true force data association, bypassing optimization + * @param ext extension object allowing passing of an implementation detail + */ + public void syncData(GL gl, boolean enable, boolean force, Object ext); + + /** + * Implementation shall enable or disable the array state. + * + * @param gl current GL object + * @param enable true if array shall be enabled, otherwise false. + * @param ext extension object allowing passing of an implementation detail + */ + public void enableState(GL gl, boolean enable, Object ext); + + public GLArrayDataWrapper getData(); +} + diff --git a/src/jogl/classes/jogamp/opengl/util/GLArrayHandlerInterleaved.java b/src/jogl/classes/jogamp/opengl/util/GLArrayHandlerInterleaved.java index 8e813a79b..d31b41582 100644 --- a/src/jogl/classes/jogamp/opengl/util/GLArrayHandlerInterleaved.java +++ b/src/jogl/classes/jogamp/opengl/util/GLArrayHandlerInterleaved.java @@ -43,19 +43,25 @@ import com.jogamp.opengl.util.GLArrayDataEditable; */ public class GLArrayHandlerInterleaved implements GLArrayHandler { private GLArrayDataEditable ad; - private List<GLArrayHandler> subArrays = new ArrayList<GLArrayHandler>(); + private List<GLArrayHandlerFlat> subArrays = new ArrayList<GLArrayHandlerFlat>(); public GLArrayHandlerInterleaved(GLArrayDataEditable ad) { this.ad = ad; } - public final void addSubHandler(GLArrayHandler handler) { + public final void setSubArrayVBOName(int vboName) { + for(int i=0; i<subArrays.size(); i++) { + subArrays.get(i).getData().setVBOName(vboName); + } + } + + public final void addSubHandler(GLArrayHandlerFlat handler) { subArrays.add(handler); } - private final void syncSubData(GL gl, boolean enable, Object ext) { + private final void syncSubData(GL gl, boolean enable, boolean force, Object ext) { for(int i=0; i<subArrays.size(); i++) { - subArrays.get(i).syncData(gl, enable, ext); + subArrays.get(i).syncData(gl, enable, force, ext); } } @@ -74,9 +80,9 @@ public class GLArrayHandlerInterleaved implements GLArrayHandler { ad.setVBOWritten(true); } } - syncSubData(gl, true, ext); + syncSubData(gl, true, true, ext); } else { - syncSubData(gl, false, ext); + syncSubData(gl, false, true, ext); if(ad.isVBO()) { gl.glBindBuffer(ad.getVBOTarget(), 0); } diff --git a/src/jogl/classes/jogamp/opengl/util/GLDataArrayHandler.java b/src/jogl/classes/jogamp/opengl/util/GLDataArrayHandler.java index c91d6c93e..6c8e2e762 100644 --- a/src/jogl/classes/jogamp/opengl/util/GLDataArrayHandler.java +++ b/src/jogl/classes/jogamp/opengl/util/GLDataArrayHandler.java @@ -45,7 +45,11 @@ public class GLDataArrayHandler implements GLArrayHandler { this.ad = ad; } - public final void addSubHandler(GLArrayHandler handler) { + public final void setSubArrayVBOName(int vboName) { + throw new UnsupportedOperationException(); + } + + public final void addSubHandler(GLArrayHandlerFlat handler) { throw new UnsupportedOperationException(); } diff --git a/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandler.java b/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandler.java index 8963b7985..d8939dc0f 100644 --- a/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandler.java +++ b/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandler.java @@ -45,8 +45,12 @@ public class GLFixedArrayHandler implements GLArrayHandler { public GLFixedArrayHandler(GLArrayDataEditable ad) { this.ad = ad; } - - public final void addSubHandler(GLArrayHandler handler) { + + public final void setSubArrayVBOName(int vboName) { + throw new UnsupportedOperationException(); + } + + public final void addSubHandler(GLArrayHandlerFlat handler) { throw new UnsupportedOperationException(); } diff --git a/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandlerFlat.java b/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandlerFlat.java index 81c782dab..2937cc720 100644 --- a/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandlerFlat.java +++ b/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandlerFlat.java @@ -29,27 +29,27 @@ package jogamp.opengl.util; import javax.media.opengl.GL; -import javax.media.opengl.GLArrayData; import javax.media.opengl.GLException; import javax.media.opengl.fixedfunc.GLPointerFunc; +import com.jogamp.opengl.util.GLArrayDataWrapper; /** * Used for interleaved fixed function arrays, i.e. where the buffer data itself is handled * separately and interleaves many arrays. */ -public class GLFixedArrayHandlerFlat implements GLArrayHandler { - private GLArrayData ad; +public class GLFixedArrayHandlerFlat implements GLArrayHandlerFlat { + private GLArrayDataWrapper ad; - public GLFixedArrayHandlerFlat(GLArrayData ad) { + public GLFixedArrayHandlerFlat(GLArrayDataWrapper ad) { this.ad = ad; } - public final void addSubHandler(GLArrayHandler handler) { - throw new UnsupportedOperationException(); + public GLArrayDataWrapper getData() { + return ad; } - public final void syncData(GL gl, boolean enable, Object ext) { + public final void syncData(GL gl, boolean enable, boolean force, Object ext) { if(enable) { final GLPointerFunc glp = gl.getGL2ES1(); switch(ad.getIndex()) { diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandler.java b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandler.java index 96bb02b19..602d283d6 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandler.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandler.java @@ -34,6 +34,7 @@ import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; import jogamp.opengl.util.GLArrayHandler; +import jogamp.opengl.util.GLArrayHandlerFlat; import com.jogamp.opengl.util.GLArrayDataEditable; import com.jogamp.opengl.util.glsl.ShaderState; @@ -48,8 +49,12 @@ public class GLSLArrayHandler implements GLArrayHandler { public GLSLArrayHandler(GLArrayDataEditable ad) { this.ad = ad; } - - public final void addSubHandler(GLArrayHandler handler) { + + public final void setSubArrayVBOName(int vboName) { + throw new UnsupportedOperationException(); + } + + public final void addSubHandler(GLArrayHandlerFlat handler) { throw new UnsupportedOperationException(); } diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerFlat.java b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerFlat.java index 0d6da7ba4..c4b761b13 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerFlat.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerFlat.java @@ -30,31 +30,48 @@ package jogamp.opengl.util.glsl; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLArrayData; -import jogamp.opengl.util.GLArrayHandler; +import jogamp.opengl.util.GLArrayHandlerFlat; +import com.jogamp.opengl.util.GLArrayDataWrapper; import com.jogamp.opengl.util.glsl.ShaderState; /** * Used for interleaved GLSL arrays, i.e. where the buffer data itself is handled * separately and interleaves many arrays. */ -public class GLSLArrayHandlerFlat implements GLArrayHandler { - private GLArrayData ad; +public class GLSLArrayHandlerFlat implements GLArrayHandlerFlat { + private GLArrayDataWrapper ad; - public GLSLArrayHandlerFlat(GLArrayData ad) { + public GLSLArrayHandlerFlat(GLArrayDataWrapper ad) { this.ad = ad; } - public final void addSubHandler(GLArrayHandler handler) { - throw new UnsupportedOperationException(); + public GLArrayDataWrapper getData() { + return ad; } - - public final void syncData(GL gl, boolean enable, Object ext) { - final ShaderState st = (ShaderState) ext; + + public final void syncData(GL gl, boolean enable, boolean force, Object ext) { if(enable) { - st.vertexAttribPointer(gl.getGL2ES2(), ad); + final GL2ES2 glsl = gl.getGL2ES2(); + final ShaderState st = (ShaderState) ext; + + st.vertexAttribPointer(glsl, ad); + /** + * Due to probable application VBO switching, this might not make any sense .. + * + if(force) { + st.vertexAttribPointer(glsl, ad); + } else if(st.getAttribLocation(glsl, ad) >= 0) { + final int[] qi = new int[1]; + glsl.glGetVertexAttribiv(ad.getLocation(), GL2ES2.GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, qi, 0); + if(ad.getVBOName() != qi[0]) { + System.err.println("XXX1: "+ad.getName()+", vbo ad "+ad.getVBOName()+", gl "+qi[0]+", "+ad); + st.vertexAttribPointer(glsl, ad); + } else { + System.err.println("XXX0: "+ad.getName()+", vbo ad "+ad.getVBOName()+", gl "+qi[0]+", "+ad); + } + }*/ } } diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerInterleaved.java b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerInterleaved.java new file mode 100644 index 000000000..f50429623 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerInterleaved.java @@ -0,0 +1,102 @@ +/** + * 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 jogamp.opengl.util.glsl; + +import java.nio.Buffer; +import java.util.ArrayList; +import java.util.List; + +import javax.media.opengl.GL; + +import jogamp.opengl.util.GLArrayHandler; +import jogamp.opengl.util.GLArrayHandlerFlat; + +import com.jogamp.opengl.util.GLArrayDataEditable; + +/** + * Interleaved fixed function arrays, i.e. where this buffer data + * represents many arrays. + */ +public class GLSLArrayHandlerInterleaved implements GLArrayHandler { + private GLArrayDataEditable ad; + private List<GLArrayHandlerFlat> subArrays = new ArrayList<GLArrayHandlerFlat>(); + + public GLSLArrayHandlerInterleaved(GLArrayDataEditable ad) { + this.ad = ad; + } + + public final void setSubArrayVBOName(int vboName) { + for(int i=0; i<subArrays.size(); i++) { + subArrays.get(i).getData().setVBOName(vboName); + } + } + + public final void addSubHandler(GLArrayHandlerFlat handler) { + subArrays.add(handler); + } + + private final void syncSubData(GL gl, boolean enable, boolean force, Object ext) { + for(int i=0; i<subArrays.size(); i++) { + subArrays.get(i).syncData(gl, enable, force, ext); + } + } + + public final void syncData(GL gl, boolean enable, Object ext) { + if(!ad.isVBO()) { + throw new InternalError("Interleaved handle is not VBO: "+ad); + } + + if(enable) { + final Buffer buffer = ad.getBuffer(); + final boolean vboWritten = ad.isVBOWritten(); + + // 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(!vboWritten) { + if(null!=buffer) { + gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSizeInBytes(), buffer, ad.getVBOUsage()); + } + ad.setVBOWritten(true); + } + // sub data will decide weather to update the vertex attrib pointer + syncSubData(gl, true, !vboWritten, ext); + } else { + // NOP on GLSL: syncSubData(gl, false, ext); + gl.glBindBuffer(ad.getVBOTarget(), 0); + } + } + + public final void enableState(GL gl, boolean enable, Object ext) { + for(int i=0; i<subArrays.size(); i++) { + subArrays.get(i).enableState(gl, enable, ext); + } + } +} + diff --git a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java index cd3cb489f..9cefa8163 100644 --- a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java +++ b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java @@ -205,7 +205,7 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { @Override protected void createNativeImpl() { Log.d(MD.TAG, "createNativeImpl 0 - surfaceHandle 0x"+Long.toHexString(surfaceHandle)+ - ", "+x+"/"+y+" "+width+"x"+height+" - "+Thread.currentThread().getName()); + ", format "+format+", "+x+"/"+y+" "+width+"x"+height+" - "+Thread.currentThread().getName()); Thread.dumpStack(); if(0!=getParentWindowHandle()) { throw new NativeWindowException("Window parenting not supported (yet)"); @@ -331,9 +331,9 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { Log.d(MD.TAG, "surfaceCreated: "+x+"/"+y+" "+width+"x"+height); } - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { - Log.d(MD.TAG, "surfaceChanged: f "+this.format+" -> "+format+", "+width+"x"+height+", current surfaceHandle: 0x"+Long.toHexString(surfaceHandle)); - if(0!=surfaceHandle && this.format != format) { + public void surfaceChanged(SurfaceHolder aHolder, int aFormat, int aWidth, int aHeight) { + Log.d(MD.TAG, "surfaceChanged: f "+format+" -> "+aFormat+", "+aWidth+"x"+aHeight+", current surfaceHandle: 0x"+Long.toHexString(surfaceHandle)); + if(0!=surfaceHandle && format != aFormat) { // re-create Log.d(MD.TAG, "surfaceChanged (destroy old)"); windowDestroyNotify(); @@ -352,24 +352,26 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { } if(0 == surfaceHandle) { - surface = holder.getSurface(); + surface = aHolder.getSurface(); surfaceHandle = getSurfaceHandle0(surface); acquire0(surfaceHandle); format = getSurfaceVisualID0(surfaceHandle); + final int nWidth = getWidth0(surfaceHandle); + final int nHeight = getHeight0(surfaceHandle); capsByFormat = (GLCapabilitiesImmutable) fixCaps(format, getRequestedCapabilities()); - sizeChanged(false, getWidth0(surfaceHandle), getHeight0(surfaceHandle), false); + sizeChanged(false, nWidth, nHeight, false); Log.d(MD.TAG, "surfaceRealized: isValid: "+surface.isValid()+ ", new surfaceHandle 0x"+Long.toHexString(surfaceHandle)+", format: "+format+ - ", "+x+"/"+y+" "+width+"x"+height+", visible: "+isVisible()); + ", "+x+"/"+y+" "+nWidth+"x"+nHeight+", visible: "+isVisible()); if(isVisible()) { setVisible(true); } } else { - sizeChanged(false, width, height, false); + sizeChanged(false, aWidth, aHeight, false); } - windowRepaint(0, 0, width, height); + windowRepaint(0, 0, aWidth, aHeight); Log.d(MD.TAG, "surfaceChanged: X"); } @@ -382,8 +384,7 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { Log.d(MD.TAG, "surfaceRedrawNeeded"); windowRepaint(0, 0, getWidth(), getHeight()); } - - + private MSurfaceView androidView; private android.view.Window androidWindow; private int format; // stored current PixelFormat diff --git a/src/test/com/jogamp/opengl/test/android/NEWTElektronActivity.java b/src/test/com/jogamp/opengl/test/android/NEWTElektronActivity.java index 442400868..21eb8af2d 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTElektronActivity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTElektronActivity.java @@ -52,9 +52,10 @@ public class NEWTElektronActivity extends NewtBaseActivity { // create GLWindow (-> incl. underlying NEWT Display, Screen & Window) GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES2)); - // caps.setAlphaBits(4); - // caps.setNumSamples(4); - // caps.setSampleBuffers(true); + caps.setRedBits(5); + caps.setGreenBits(6); + caps.setBlueBits(5); + caps.setAlphaBits(0); Log.d(TAG, "req caps: "+caps); GLWindow glWindow = GLWindow.create(caps); glWindow.setFullscreen(true); diff --git a/src/test/com/jogamp/opengl/test/android/NEWTGearsES1Activity.java b/src/test/com/jogamp/opengl/test/android/NEWTGearsES1Activity.java index bc4e7d394..337dafc71 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTGearsES1Activity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTGearsES1Activity.java @@ -52,6 +52,11 @@ public class NEWTGearsES1Activity extends NewtBaseActivity { // create GLWindow (-> incl. underlying NEWT Display, Screen & Window) GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES1)); + /* + caps.setRedBits(5); + caps.setGreenBits(6); + caps.setBlueBits(5); + caps.setAlphaBits(0); */ Log.d(TAG, "req caps: "+caps); GLWindow glWindow = GLWindow.create(caps); setContentView(getWindow(), glWindow); diff --git a/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java b/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java index 939bfa210..3e9869c95 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java @@ -52,12 +52,19 @@ public class NEWTGearsES2Activity extends NewtBaseActivity { // create GLWindow (-> incl. underlying NEWT Display, Screen & Window) GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES2)); + /* + caps.setRedBits(5); + caps.setGreenBits(6); + caps.setBlueBits(5); + caps.setAlphaBits(0); */ Log.d(TAG, "req caps: "+caps); GLWindow glWindow = GLWindow.create(caps); glWindow.setFullscreen(true); setContentView(getWindow(), glWindow); - glWindow.addGLEventListener(new GearsES2(1)); + GearsES2 demo = new GearsES2(0); + // demo.enableAndroidTrace(true); + glWindow.addGLEventListener(demo); glWindow.getWindow().getScreen().addScreenModeListener(new ScreenModeListener() { public void screenModeChangeNotify(ScreenMode sm) { } public void screenModeChanged(ScreenMode sm, boolean success) { @@ -67,6 +74,7 @@ public class NEWTGearsES2Activity extends NewtBaseActivity { glWindow.setVisible(true); Animator animator = new Animator(glWindow); animator.setUpdateFPSFrames(60, System.err); + // animator.setRunAsFastAsPossible(true); setAnimator(animator); Log.d(TAG, "onCreate - X"); diff --git a/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES1Activity.java b/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES1Activity.java index 6fc3a46d6..24b4eaf0c 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES1Activity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES1Activity.java @@ -52,6 +52,10 @@ public class NEWTRedSquareES1Activity extends NewtBaseActivity { // create GLWindow (-> incl. underlying NEWT Display, Screen & Window) GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES1)); + caps.setRedBits(5); + caps.setGreenBits(6); + caps.setBlueBits(5); + caps.setAlphaBits(0); Log.d(TAG, "req caps: "+caps); GLWindow glWindow = GLWindow.create(caps); setContentView(getWindow(), glWindow); diff --git a/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES2Activity.java b/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES2Activity.java index e9ef981b8..70d1c382d 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES2Activity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES2Activity.java @@ -52,12 +52,18 @@ public class NEWTRedSquareES2Activity extends NewtBaseActivity { // create GLWindow (-> incl. underlying NEWT Display, Screen & Window) GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES2)); + caps.setRedBits(5); + caps.setGreenBits(6); + caps.setBlueBits(5); + caps.setAlphaBits(0); Log.d(TAG, "req caps: "+caps); GLWindow glWindow = GLWindow.create(caps); glWindow.setFullscreen(true); setContentView(getWindow(), glWindow); - glWindow.addGLEventListener(new RedSquareES2(1)); + final RedSquareES2 demo = new RedSquareES2(0); + // demo.enableAndroidTrace(true); + glWindow.addGLEventListener(demo); glWindow.getWindow().getScreen().addScreenModeListener(new ScreenModeListener() { public void screenModeChangeNotify(ScreenMode sm) { } public void screenModeChanged(ScreenMode sm, boolean success) { @@ -67,6 +73,7 @@ public class NEWTRedSquareES2Activity extends NewtBaseActivity { glWindow.setVisible(true); Animator animator = new Animator(glWindow); animator.setUpdateFPSFrames(60, System.err); + // animator.setRunAsFastAsPossible(true); setAnimator(animator); Log.d(TAG, "onCreate - X"); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java index 9bff38fce..573d92ad9 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java @@ -56,6 +56,7 @@ public class GearsES2 implements GLEventListener { private GearsObjectES2 gear1=null, gear2=null, gear3=null; private float angle = 0.0f; private int swapInterval = 0; + private boolean pmvUseBackingArray = true; // the default for PMVMatrix now, since it's faster // private MouseListener gearsMouse = new TraceMouseAdapter(new GearsMouseAdapter()); private MouseListener gearsMouse = new GearsMouseAdapter(); private KeyListener gearsKeys = new GearsKeyAdapter(); @@ -70,6 +71,10 @@ public class GearsES2 implements GLEventListener { this.swapInterval = 1; } + public void setPMVUseBackingArray(boolean pmvUseBackingArray) { + this.pmvUseBackingArray = pmvUseBackingArray; + } + public void setGears(GearsObjectES2 g1, GearsObjectES2 g2, GearsObjectES2 g3) { gear1 = g1; gear2 = g2; @@ -119,7 +124,7 @@ public class GearsES2 implements GLEventListener { // Use debug pipeline // drawable.setGL(new DebugGL(drawable.getGL())); - pmvMatrix = new PMVMatrix(); + pmvMatrix = new PMVMatrix(pmvUseBackingArray); st.attachObject("pmvMatrix", pmvMatrix); pmvMatrixUniform = new GLUniformData("pmvMatrix", 4, 4, pmvMatrix.glGetPMvMvitMatrixf()); // P, Mv, Mvi and Mvit st.ownUniform(pmvMatrixUniform); @@ -173,6 +178,10 @@ public class GearsES2 implements GLEventListener { System.err.println(Thread.currentThread()+" GearsES2.init FIN"); } + public void enableAndroidTrace(boolean v) { + useAndroidDebug = v; + } + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { System.err.println(Thread.currentThread()+" GearsES2.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval); GL2ES2 gl = drawable.getGL().getGL2ES2(); @@ -189,10 +198,24 @@ public class GearsES2 implements GLEventListener { st.uniform(gl, pmvMatrixUniform); st.useProgram(gl, false); + if(useAndroidDebug) { + try { + android.os.Debug.startMethodTracing("GearsES2.trace"); + // android.os.Debug.startAllocCounting(); + useAndroidDebug = true; + } catch (NoClassDefFoundError e) { useAndroidDebug=false; } + } + System.err.println(Thread.currentThread()+" GearsES2.reshape FIN"); } + private boolean useAndroidDebug = false; public void dispose(GLAutoDrawable drawable) { + if(useAndroidDebug) { + // android.os.Debug.stopAllocCounting(); + android.os.Debug.stopMethodTracing(); + } + System.err.println(Thread.currentThread()+" GearsES2.dispose ... "); if (drawable instanceof Window) { Window window = (Window) drawable; @@ -244,7 +267,7 @@ public class GearsES2 implements GLEventListener { gear2.draw(gl, 3.1f, -2.0f, -2f * angle - 9.0f, GearsObject.green); gear3.draw(gl, -3.1f, 4.2f, -2f * angle - 25.0f, GearsObject.blue); pmvMatrix.glPopMatrix(); - st.useProgram(gl, false); + st.useProgram(gl, false); } class GearsKeyAdapter extends KeyAdapter { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java index d06c6da97..01790de10 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java @@ -131,21 +131,6 @@ public class RedSquareES2 implements GLEventListener { System.err.println(Thread.currentThread()+" RedSquareES2.init FIN"); } - public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { - System.err.println(Thread.currentThread()+" RedSquareES2.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval); - GL2ES2 gl = glad.getGL().getGL2ES2(); - - st.useProgram(gl, true); - // Set location in front of camera - pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); - pmvMatrix.glLoadIdentity(); - pmvMatrix.gluPerspective(45.0F, (float) width / (float) height, 1.0F, 100.0F); - //pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f); - st.uniform(gl, pmvMatrixUniform); - st.useProgram(gl, false); - System.err.println(Thread.currentThread()+" RedSquareES2.reshape FIN"); - } - public void display(GLAutoDrawable glad) { long t1 = System.currentTimeMillis(); @@ -170,7 +155,40 @@ public class RedSquareES2 implements GLEventListener { st.useProgram(gl, false); } + public void enableAndroidTrace(boolean v) { + useAndroidDebug = v; + } + + public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { + System.err.println(Thread.currentThread()+" RedSquareES2.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval); + GL2ES2 gl = glad.getGL().getGL2ES2(); + + st.useProgram(gl, true); + // Set location in front of camera + pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.gluPerspective(45.0F, (float) width / (float) height, 1.0F, 100.0F); + //pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f); + st.uniform(gl, pmvMatrixUniform); + st.useProgram(gl, false); + + if(useAndroidDebug) { + try { + android.os.Debug.startMethodTracing("RedSquareES2.trace"); + // android.os.Debug.startAllocCounting(); + useAndroidDebug = true; + } catch (NoClassDefFoundError e) { useAndroidDebug=false; } + } + + System.err.println(Thread.currentThread()+" RedSquareES2.reshape FIN"); + } + private boolean useAndroidDebug = false; + public void dispose(GLAutoDrawable glad) { + if(useAndroidDebug) { + // android.os.Debug.stopAllocCounting(); + android.os.Debug.stopMethodTracing(); + } System.err.println(Thread.currentThread()+" RedSquareES2.dispose ... "); if (null != glWindow) { glWindow.removeMouseListener(myMouse); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java index df86b83d2..64eb518fb 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java @@ -28,6 +28,10 @@ package com.jogamp.opengl.test.junit.jogl.demos.es2.newt; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.opengl.GLWindow; @@ -38,7 +42,10 @@ import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import javax.media.opengl.GLAnimatorControl; +import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile; import org.junit.Assert; @@ -78,7 +85,29 @@ public class TestGearsES2NEWT extends UITestCase { glWindow.setUndecorated(undecorated); glWindow.setAlwaysOnTop(alwaysOnTop); glWindow.setFullscreen(fullscreen); - glWindow.addGLEventListener(new GearsES2()); + GearsES2 demo = new GearsES2(vsync ? 1 : 0); + demo.setPMVUseBackingArray(pmvUseBackingArray); + glWindow.addGLEventListener(demo); + if(waitForKey) { + glWindow.addGLEventListener(new GLEventListener() { + public void init(GLAutoDrawable drawable) { } + public void dispose(GLAutoDrawable drawable) { } + public void display(GLAutoDrawable drawable) { + GLAnimatorControl actrl = drawable.getAnimator(); + if(waitForKey && actrl.getTotalFPSFrames() == 60*3) { + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + System.err.println("Press enter to continue"); + try { + System.err.println(stdin.readLine()); + } catch (IOException e) { } + actrl.resetFPSCounter(); + waitForKey = false; + } + } + public void reshape(GLAutoDrawable drawable, int x, int y, + int width, int height) { } + }); + } Animator animator = new Animator(glWindow); QuitAdapter quitAdapter = new QuitAdapter(); @@ -128,7 +157,7 @@ public class TestGearsES2NEWT extends UITestCase { System.err.println("size/pos: "+f_glWindow.getX()+"/"+f_glWindow.getY()+" "+f_glWindow.getWidth()+"x"+f_glWindow.getHeight()+", "+f_glWindow.getInsets()); System.err.println("chosen: "+glWindow.getChosenCapabilities()); - animator.setUpdateFPSFrames(1, null); + animator.setUpdateFPSFrames(60, System.err); animator.start(); while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) { @@ -151,8 +180,12 @@ public class TestGearsES2NEWT extends UITestCase { static boolean undecorated = false; static boolean alwaysOnTop = false; static boolean fullscreen = false; + static boolean pmvUseBackingArray = true; + static boolean vsync = false; + static boolean waitForKey = false; - public static void main(String args[]) { + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { i++; @@ -167,8 +200,28 @@ public class TestGearsES2NEWT extends UITestCase { alwaysOnTop = true; } else if(args[i].equals("-fullscreen")) { fullscreen = true; + } else if(args[i].equals("-pmvDirect")) { + pmvUseBackingArray = false; + } else if(args[i].equals("-vsync")) { + vsync = true; + } else if(args[i].equals("-wait")) { + waitForKey = true; } } + System.err.println("translucent "+(!opaque)); + System.err.println("undecorated "+undecorated); + System.err.println("atop "+alwaysOnTop); + System.err.println("fullscreen "+fullscreen); + System.err.println("pmvDirect "+(!pmvUseBackingArray)); + System.err.println("vsync "+vsync); + + if(waitForKey) { + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + System.err.println("Press enter to continue"); + try { + System.err.println(stdin.readLine()); + } catch (IOException e) { } + } org.junit.runner.JUnitCore.main(TestGearsES2NEWT.class.getName()); } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.fp index e8feef2fa..768e23b36 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.fp +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.fp @@ -23,12 +23,12 @@ const vec4 matSpecular = vec4(0.8, 0.8, 0.8, 1.0); const float matShininess = 0.5; void main() -{ - float lambertTerm = dot(normal, lightDir); - +{ vec4 ambient = color * matAmbient; - vec4 diffuse = color * lambertTerm * attenuation * matDiffuse; vec4 specular = vec4(0.0); + + float lambertTerm = dot(normal, lightDir); + vec4 diffuse = color * lambertTerm * attenuation * matDiffuse; if (lambertTerm > 0.0) { float NdotHV; /* |