diff options
Diffstat (limited to 'src/jogl/classes')
29 files changed, 937 insertions, 363 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/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; } diff --git a/src/jogl/classes/javax/media/opengl/GLArrayData.java b/src/jogl/classes/javax/media/opengl/GLArrayData.java index 4562c1c0b..26f0f6be2 100644 --- a/src/jogl/classes/javax/media/opengl/GLArrayData.java +++ b/src/jogl/classes/javax/media/opengl/GLArrayData.java @@ -116,7 +116,7 @@ public interface GLArrayData { /** * The number of components per element */ - public int getComponentNumber(); + public int getComponentCount(); /** * The component's GL data type, ie. GL_FLOAT @@ -126,19 +126,19 @@ public interface GLArrayData { /** * The component's size in bytes */ - public int getComponentSize(); + public int getComponentSizeInBytes(); /** * The current number of used elements.<br> * In case the buffer's position is 0 (sealed, flipped), it's based on it's limit instead of it's position. */ - public int getElementNumber(); + public int getElementCount(); /** - * The current number of used bytes.<br> + * The currently used size in bytes.<br> * In case the buffer's position is 0 (sealed, flipped), it's based on it's limit instead of it's position. */ - public int getByteSize(); + public int getSizeInBytes(); /** * True, if GL shall normalize fixed point data while converting @@ -146,10 +146,9 @@ public interface GLArrayData { */ public boolean getNormalized(); - /** - * The distance to the next payload, - * allowing interleaved arrays. - */ + /** + * @return the byte offset between consecutive components + */ public int getStride(); public String toString(); diff --git a/src/jogl/classes/javax/media/opengl/GLUniformData.java b/src/jogl/classes/javax/media/opengl/GLUniformData.java index 9b0d5f151..5c9388be2 100644 --- a/src/jogl/classes/javax/media/opengl/GLUniformData.java +++ b/src/jogl/classes/javax/media/opengl/GLUniformData.java @@ -59,10 +59,10 @@ public class GLUniformData { init(name, rows, columns, data); } - public void setData(int data) { init(new Integer(data)); } - public void setData(float data) { init(new Float(data)); } - public void setData(IntBuffer data) { init(data); } - public void setData(FloatBuffer data) { init(data); } + public GLUniformData setData(int data) { init(new Integer(data)); return this; } + public GLUniformData setData(float data) { init(new Float(data)); return this; } + public GLUniformData setData(IntBuffer data) { init(data); return this; } + public GLUniformData setData(FloatBuffer data) { init(data); return this; } public int intValue() { return ((Integer)data).intValue(); }; public float floatValue() { return ((Float)data).floatValue(); }; @@ -105,8 +105,8 @@ public class GLUniformData { private void init(Object data) { if(data instanceof Buffer) { - int sz = rows*columns; - Buffer buffer = (Buffer)data; + final int sz = rows*columns; + final Buffer buffer = (Buffer)data; if(buffer.limit()<sz || 0!=buffer.limit()%sz) { throw new GLException("data buffer size invalid: new buffer limit: "+buffer.limit()+"\n\t"+this); } @@ -127,7 +127,7 @@ public class GLUniformData { /** * Sets the determined location of the shader uniform. */ - public void setLocation(int location) { this.location=location; } + public GLUniformData setLocation(int location) { this.location=location; return this; } public Object getObject() { return data; diff --git a/src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java b/src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java index 5563ea9c8..001f4f05b 100644 --- a/src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java +++ b/src/jogl/classes/javax/media/opengl/fixedfunc/GLLightingFunc.java @@ -1,13 +1,34 @@ /* * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * 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 javax.media.opengl.fixedfunc; -import java.nio.*; - -import javax.media.opengl.*; - public interface GLLightingFunc { public static final int GL_LIGHT0 = 0x4000; public static final int GL_LIGHT1 = 0x4001; diff --git a/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java b/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java index b899f3c0a..a34d490c0 100644 --- a/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java +++ b/src/jogl/classes/javax/media/opengl/fixedfunc/GLMatrixFunc.java @@ -1,5 +1,30 @@ /* * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * 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 javax.media.opengl.fixedfunc; diff --git a/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java b/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java index ed7bef5d4..786835f4d 100644 --- a/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java +++ b/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFunc.java @@ -1,11 +1,34 @@ /* * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * 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 javax.media.opengl.fixedfunc; -import java.nio.*; - import javax.media.opengl.*; public interface GLPointerFunc { diff --git a/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFuncUtil.java b/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFuncUtil.java new file mode 100644 index 000000000..e52154c7d --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/fixedfunc/GLPointerFuncUtil.java @@ -0,0 +1,55 @@ +/* + * 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 javax.media.opengl.fixedfunc; + +public class GLPointerFuncUtil { + public static final String mgl_Vertex = "mgl_Vertex"; + public static final String mgl_Normal = "mgl_Normal"; + public static final String mgl_Color = "mgl_Color"; + public static final String mgl_MultiTexCoord = "mgl_MultiTexCoord" ; + public static final String mgl_InterleaveArray = "mgl_InterleaveArray" ; // magic name for interleaved arrays w/ sub-arrays + + /** + * @param glArrayIndex the fixed function array index + * @return default fixed function array name + */ + public static String getPredefinedArrayIndexName(int glArrayIndex) { + switch(glArrayIndex) { + case GLPointerFunc.GL_VERTEX_ARRAY: + return mgl_Vertex; + case GLPointerFunc.GL_NORMAL_ARRAY: + return mgl_Normal; + case GLPointerFunc.GL_COLOR_ARRAY: + return mgl_Color; + case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: + return mgl_MultiTexCoord; + } + return null; + } +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java index 6427bcd48..2d13f5ba0 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java @@ -212,7 +212,7 @@ public class VBORegion2PES2 extends GLRegion { texCoordFboAttr.enableBuffer(gl, true); indicesFbo.enableBuffer(gl, true); - gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesFbo.getElementNumber() * indicesFbo.getComponentNumber(), GL2ES2.GL_UNSIGNED_SHORT, 0); + gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesFbo.getElementCount() * indicesFbo.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); verticeFboAttr.enableBuffer(gl, false); texCoordFboAttr.enableBuffer(gl, false); @@ -278,7 +278,7 @@ public class VBORegion2PES2 extends GLRegion { texCoordTxtAttr.enableBuffer(gl, true); indicesTxt.enableBuffer(gl, true); - gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxt.getElementNumber() * indicesTxt.getComponentNumber(), GL2ES2.GL_UNSIGNED_SHORT, 0); + gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxt.getElementCount() * indicesTxt.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); verticeTxtAttr.enableBuffer(gl, false); texCoordTxtAttr.enableBuffer(gl, false); diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java index dc4e3a6e0..83cd6fab9 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java @@ -130,7 +130,7 @@ public class VBORegionSPES2 extends GLRegion { texCoordAttr.enableBuffer(gl, true); indices.enableBuffer(gl, true); - gl.glDrawElements(GL2ES2.GL_TRIANGLES, indices.getElementNumber() * indices.getComponentNumber(), GL2ES2.GL_UNSIGNED_SHORT, 0); + gl.glDrawElements(GL2ES2.GL_TRIANGLES, indices.getElementCount() * indices.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); verticeAttr.enableBuffer(gl, false); texCoordAttr.enableBuffer(gl, false); diff --git a/src/jogl/classes/jogamp/opengl/util/GLDataArrayHandler.java b/src/jogl/classes/jogamp/opengl/util/GLDataArrayHandler.java new file mode 100644 index 000000000..718b63822 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/GLDataArrayHandler.java @@ -0,0 +1,73 @@ +/** + * 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; + +import javax.media.opengl.*; +import com.jogamp.opengl.util.*; + +import java.nio.*; + +/** + * Used for pure VBO data arrays, i.e. where the buffer data + * does not represents a specific array name. + */ +public class GLDataArrayHandler implements GLArrayHandler { + private GLArrayDataEditable ad; + + public GLDataArrayHandler(GLArrayDataEditable ad) { + this.ad = ad; + if(!ad.isVBO()) { + // makes no sense otherwise + throw new GLException("GLDataArrayHandler can only handle VBOs."); + } + } + + public final void addSubHandler(GLArrayHandler handler) { + throw new UnsupportedOperationException(); + } + + public final void enableBuffer(GL gl, boolean enable) { + if(enable) { + Buffer buffer = ad.getBuffer(); + + // 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.getComponentSizeInBytes(), buffer, ad.getVBOUsage()); + } + ad.setVBOWritten(true); + } + } else { + gl.glBindBuffer(ad.getVBOTarget(), 0); + } + } +} + diff --git a/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandler.java b/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandler.java new file mode 100644 index 000000000..e365f0f4b --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandler.java @@ -0,0 +1,99 @@ +/** + * 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; + +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.*; + +import com.jogamp.opengl.util.GLArrayDataEditable; +import com.jogamp.opengl.util.GLArrayHandler; + +import java.nio.*; + +/** + * Used for 1:1 fixed function arrays, i.e. where the buffer data + * represents this array only. + */ +public class GLFixedArrayHandler implements GLArrayHandler { + private GLArrayDataEditable ad; + + public GLFixedArrayHandler(GLArrayDataEditable ad) { + this.ad = ad; + } + + public final void addSubHandler(GLArrayHandler handler) { + throw new UnsupportedOperationException(); + } + + 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 final 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.getComponentSizeInBytes(), buffer, ad.getVBOUsage()); + } + ad.setVBOWritten(true); + } + } + passArrayPointer(glp); + glp.glEnableClientState(ad.getIndex()); + } else { + glp.glDisableClientState(ad.getIndex()); + if(ad.isVBO()) { + gl.glBindBuffer(ad.getVBOTarget(), 0); + } + } + } +} + diff --git a/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandlerFlat.java b/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandlerFlat.java new file mode 100644 index 000000000..e1cf5d572 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandlerFlat.java @@ -0,0 +1,82 @@ +/** + * 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.GL; +import javax.media.opengl.GLArrayData; +import javax.media.opengl.GLException; +import javax.media.opengl.fixedfunc.GLPointerFunc; + +import com.jogamp.opengl.util.GLArrayHandler; + +/** + * 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 GLFixedArrayHandlerFlat(GLArrayData ad) { + this.ad = ad; + } + + public final void addSubHandler(GLArrayHandler handler) { + throw new UnsupportedOperationException(); + } + + 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 final void enableBuffer(GL gl, boolean enable) { + GLPointerFunc glp = gl.getGL2ES1(); + if(enable) { + passArrayPointer(glp); + glp.glEnableClientState(ad.getIndex()); + } else { + glp.glDisableClientState(ad.getIndex()); + } + } +} + diff --git a/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandlerInterleaved.java b/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandlerInterleaved.java new file mode 100644 index 000000000..838032646 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/GLFixedArrayHandlerInterleaved.java @@ -0,0 +1,87 @@ +/** + * 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; + +import javax.media.opengl.*; +import javax.media.opengl.fixedfunc.*; + +import com.jogamp.opengl.util.GLArrayDataEditable; +import com.jogamp.opengl.util.GLArrayHandler; + +import java.nio.*; +import java.util.ArrayList; +import java.util.List; + +/** + * Interleaved fixed function arrays, i.e. where this buffer data + * represents many arrays. + */ +public class GLFixedArrayHandlerInterleaved implements GLArrayHandler { + private GLArrayDataEditable ad; + private List<GLArrayHandler> subArrays = new ArrayList<GLArrayHandler>(); + + public GLFixedArrayHandlerInterleaved(GLArrayDataEditable ad) { + this.ad = ad; + } + + public final void addSubHandler(GLArrayHandler handler) { + subArrays.add(handler); + } + + private final void enableSubBuffer(GL gl, boolean enable) { + for(int i=0; i<subArrays.size(); i++) { + subArrays.get(i).enableBuffer(gl, enable); + } + } + + public final void enableBuffer(GL gl, boolean enable) { + 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.getComponentSizeInBytes(), buffer, ad.getVBOUsage()); + } + ad.setVBOWritten(true); + } + } + enableSubBuffer(gl, true); + } else { + enableSubBuffer(gl, false); + if(ad.isVBO()) { + gl.glBindBuffer(ad.getVBOTarget(), 0); + } + } + } +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandler.java index cc9be681c..b4b7b5ace 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandler.java @@ -26,7 +26,7 @@ * or implied, of JogAmp Community. */ -package com.jogamp.opengl.util.glsl; +package jogamp.opengl.util.glsl; import java.nio.Buffer; @@ -35,9 +35,13 @@ import javax.media.opengl.GL2ES2; import javax.media.opengl.GLException; import com.jogamp.opengl.util.GLArrayDataEditable; import com.jogamp.opengl.util.GLArrayHandler; +import com.jogamp.opengl.util.glsl.ShaderState; +/** + * Used for 1:1 GLSL arrays, i.e. where the buffer data + * represents this array only. + */ public class GLSLArrayHandler implements GLArrayHandler { - private static final boolean DEBUG = ShaderState.DEBUG; private GLArrayDataEditable ad; private ShaderState st; @@ -46,26 +50,22 @@ public class GLSLArrayHandler implements GLArrayHandler { this.ad = ad; } - public void enableBuffer(GL gl, boolean enable) { - if(!gl.isGL2ES2()) { - throw new GLException("GLSLArrayHandler expects a GL2ES2 implementation"); - } + public final void addSubHandler(GLArrayHandler handler) { + throw new UnsupportedOperationException(); + } + + public final void enableBuffer(GL gl, boolean enable) { 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()); + glsl.glBufferData(ad.getVBOTarget(), ad.getSizeInBytes(), buffer, ad.getVBOUsage()); } ad.setVBOWritten(true); st.vertexAttribPointer(glsl, ad); @@ -74,22 +74,19 @@ public class GLSLArrayHandler implements GLArrayHandler { 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); } + st.enableVertexAttribArray(glsl, ad); } else { + st.disableVertexAttribArray(glsl, ad); if(ad.isVBO()) { glsl.glBindBuffer(ad.getVBOTarget(), 0); } - st.disableVertexAttribArray(glsl, ad); } } diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerFlat.java b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerFlat.java new file mode 100644 index 000000000..38379877f --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerFlat.java @@ -0,0 +1,66 @@ +/** + * 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.glsl; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLArrayData; +import com.jogamp.opengl.util.GLArrayHandler; +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 ShaderState st; + private GLArrayData ad; + + public GLSLArrayHandlerFlat(ShaderState st, GLArrayData ad) { + this.st = st; + this.ad = ad; + } + + public final void addSubHandler(GLArrayHandler handler) { + throw new UnsupportedOperationException(); + } + + public final void enableBuffer(GL gl, boolean enable) { + GL2ES2 glsl = gl.getGL2ES2(); + + if(enable) { + st.vertexAttribPointer(glsl, ad); + st.enableVertexAttribArray(glsl, ad); + } else { + st.disableVertexAttribArray(glsl, 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..ba5814a09 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/GLSLArrayHandlerInterleaved.java @@ -0,0 +1,96 @@ +/** + * 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 javax.media.opengl.GL2ES2; +import javax.media.opengl.GLException; + +import jogamp.opengl.util.GLFixedArrayHandlerFlat; + +import com.jogamp.opengl.util.GLArrayDataEditable; +import com.jogamp.opengl.util.GLArrayHandler; +import com.jogamp.opengl.util.glsl.ShaderState; + +/** + * Interleaved GLSL arrays, i.e. where this buffer data + * represents many arrays. + */ +public class GLSLArrayHandlerInterleaved implements GLArrayHandler { + private GLArrayDataEditable ad; + private ShaderState st; + private List<GLArrayHandler> subArrays = new ArrayList<GLArrayHandler>(); + + public GLSLArrayHandlerInterleaved(ShaderState st, GLArrayDataEditable ad) { + this.st = st; + this.ad = ad; + } + + public final void addSubHandler(GLArrayHandler handler) { + subArrays.add(handler); + } + + private final void enableSubBuffer(GL gl, boolean enable) { + for(int i=0; i<subArrays.size(); i++) { + subArrays.get(i).enableBuffer(gl, enable); + } + } + + public final void enableBuffer(GL gl, boolean enable) { + GL2ES2 glsl = gl.getGL2ES2(); + + if(enable) { + Buffer buffer = ad.getBuffer(); + + if(ad.isVBO()) { + // always bind and refresh the VBO mgr, + // in case more than one attributes are in use + glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName()); + if(!ad.isVBOWritten()) { + if(null!=buffer) { + glsl.glBufferData(ad.getVBOTarget(), ad.getSizeInBytes(), buffer, ad.getVBOUsage()); + } + ad.setVBOWritten(true); + } + } + enableSubBuffer(gl, true); + } else { + enableSubBuffer(gl, false); + if(ad.isVBO()) { + glsl.glBindBuffer(ad.getVBOTarget(), 0); + } + } + } + +} + diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java index 984439031..2d18ba248 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java @@ -1,5 +1,30 @@ /* * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * 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.fixedfunc; @@ -254,7 +279,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun } public void glNormalPointer(GLArrayData array) { - if(array.getComponentNumber()!=3) { + if(array.getComponentCount()!=3) { throw new GLException("Only 3 components per normal allowed"); } if(array.isVBO()) { diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java index 2218c2d73..7bc0c5468 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java @@ -1,3 +1,31 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * 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.fixedfunc; @@ -12,26 +40,6 @@ public class FixedFuncPipeline { public static final int MAX_TEXTURE_UNITS = 8; public static final int MAX_LIGHTS = 8; - // We can't have any dependencies on the FixedFuncUtil class for build bootstrapping reasons - public static final String mgl_Vertex = "mgl_Vertex"; - public static final String mgl_Normal = "mgl_Normal"; - public static final String mgl_Color = "mgl_Color"; - public static final String mgl_MultiTexCoord = "mgl_MultiTexCoord" ; - - public static String getPredefinedArrayIndexName(int glArrayIndex) { - switch(glArrayIndex) { - case GLPointerFunc.GL_VERTEX_ARRAY: - return mgl_Vertex; - case GLPointerFunc.GL_NORMAL_ARRAY: - return mgl_Normal; - case GLPointerFunc.GL_COLOR_ARRAY: - return mgl_Color; - case GLPointerFunc.GL_TEXTURE_COORD_ARRAY: - return mgl_MultiTexCoord; - } - return null; - } - public FixedFuncPipeline(GL2ES2 gl, PMVMatrix pmvMatrix) { init(gl, pmvMatrix, FixedFuncPipeline.class, shaderSrcRootDef, shaderBinRootDef, vertexColorFileDef, vertexColorLightFileDef, fragmentColorFileDef, fragmentColorTextureFileDef); @@ -62,7 +70,7 @@ public class FixedFuncPipeline { } public String getArrayIndexName(int glArrayIndex) { - String name = getPredefinedArrayIndexName(glArrayIndex); + String name = GLPointerFuncUtil.getPredefinedArrayIndexName(glArrayIndex); switch(glArrayIndex) { case GLPointerFunc.GL_VERTEX_ARRAY: case GLPointerFunc.GL_NORMAL_ARRAY: @@ -320,15 +328,10 @@ public class FixedFuncPipeline { } else { throw new GLException("Failed to update: mgl_PMVMatrix"); } - ud = shaderState.getUniform(mgl_NormalMatrix); - if(null!=ud) { - // same data object .. - shaderState.uniform(gl, ud); - } } ud = shaderState.getUniform(mgl_ColorEnabled); if(null!=ud) { - int ca = (shaderState.isVertexAttribArrayEnabled(mgl_Color)==true)?1:0; + int ca = (shaderState.isVertexAttribArrayEnabled(GLPointerFuncUtil.mgl_Color)==true)?1:0; if(ca!=ud.intValue()) { ud.setData(ca); shaderState.uniform(gl, ud); @@ -450,13 +453,10 @@ public class FixedFuncPipeline { shaderState.useProgram(gl, true); // mandatory .. - if(!shaderState.uniform(gl, new GLUniformData(mgl_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMviMatrixf()))) { + if(!shaderState.uniform(gl, new GLUniformData(mgl_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMvitMatrixf()))) { throw new GLException("Error setting PMVMatrix in shader: "+this); } - // optional parameter .. - shaderState.uniform(gl, new GLUniformData(mgl_NormalMatrix, 3, 3, pmvMatrix.glGetNormalMatrixf())); - shaderState.uniform(gl, new GLUniformData(mgl_ColorEnabled, 0)); shaderState.uniform(gl, new GLUniformData(mgl_ColorStatic, 4, zero4f)); shaderState.uniform(gl, new GLUniformData(mgl_TexCoordEnabled, 1, textureCoordsEnabled)); @@ -508,8 +508,7 @@ public class FixedFuncPipeline { protected ShaderProgram shaderProgramColorTextureLight; // uniforms .. - protected static final String mgl_PMVMatrix = "mgl_PMVMatrix"; // m4fv[3] - protected static final String mgl_NormalMatrix = "mgl_NormalMatrix"; // m4fv + protected static final String mgl_PMVMatrix = "mgl_PMVMatrix"; // m4fv[4] - P, Mv, Mvi and Mvit protected static final String mgl_ColorEnabled = "mgl_ColorEnabled"; // 1i protected static final String mgl_ColorStatic = "mgl_ColorStatic"; // 4fv diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp index ce203cfb9..7ce1eedcf 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp @@ -19,7 +19,7 @@ void main(void) position = mgl_PMVMatrix[1] * mgl_Vertex; // vertex eye position - normal = normalize(mgl_NormalMatrix * mgl_Normal); + normal = normalize(mgl_PMVMatrix[3] * mgl_Normal).xyz; // cameraPosition: (mgl_PMVMatrix[2] * vec4(0,0,0,1.0)).xyz cameraDir = normalize( (mgl_PMVMatrix[2] * vec4(0,0,0,1.0)).xyz - mgl_Vertex.xyz ); @@ -50,7 +50,7 @@ void main(void) } } } - ambient += mgl_FrontMaterial.ambient; + ambient *= mgl_FrontMaterial.ambient; diffuse *= mgl_FrontMaterial.diffuse; specular *= mgl_FrontMaterial.specular; diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_attribute.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_attribute.glsl index b09bdb05a..09a11ec95 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_attribute.glsl +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_attribute.glsl @@ -5,7 +5,7 @@ #include es_precision.glsl attribute HIGHP vec4 mgl_Vertex; -attribute HIGHP vec3 mgl_Normal; +attribute HIGHP vec4 mgl_Normal; attribute HIGHP vec4 mgl_Color; attribute HIGHP vec4 mgl_MultiTexCoord0; attribute HIGHP vec4 mgl_MultiTexCoord1; diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl index d8b3c7f95..4c4000dfa 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl @@ -6,8 +6,7 @@ #include mgl_const.glsl -uniform HIGHP mat4 mgl_PMVMatrix[3]; // P, Mv, and Mvi -uniform HIGHP mat3 mgl_NormalMatrix; // transpose(inverse(ModelView)).3x3 +uniform HIGHP mat4 mgl_PMVMatrix[4]; // P, Mv, Mvi and Mvit (transpose(inverse(ModelView)) == normalMatrix) uniform LOWP int mgl_ColorEnabled; uniform HIGHP vec4 mgl_ColorStatic; uniform LOWP int mgl_TexCoordEnabled[MAX_TEXTURE_UNITS]; |