diff options
author | Sven Gothel <[email protected]> | 2008-08-21 14:51:51 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2008-08-21 14:51:51 +0000 |
commit | a971f95b23fd9f8287acdad1afc2eed75a531bc1 (patch) | |
tree | 5f9d5526acab5a7805b0a9b7963be9727217647c /src/classes/com/sun | |
parent | 40d62b2514a8800a9ae0303d67fecdab3d5baada (diff) |
Cleanup GLArrayData*, misc stuff
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1762 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun')
5 files changed, 139 insertions, 69 deletions
diff --git a/src/classes/com/sun/javafx/newt/GLWindow.java b/src/classes/com/sun/javafx/newt/GLWindow.java index baabd25a6..7f7d8d077 100644 --- a/src/classes/com/sun/javafx/newt/GLWindow.java +++ b/src/classes/com/sun/javafx/newt/GLWindow.java @@ -403,8 +403,8 @@ public class GLWindow extends Window implements GLAutoDrawable { dt0 = curTime-lastCheck; if ( dt0 > 5000 ) { dt1 = curTime-startTime; - System.out.println(dt1/1000+"s, 5s: "+ (lastFrames*1000)/dt0 + " fps, "+ - "total: "+ (totalFrames*1000)/dt1 + " fps"); + System.out.println(dt0/1000 +"s: "+ lastFrames + "f, " + (lastFrames*1000)/dt0 + " fps, "+dt0/lastFrames+" ms/f; "+ + "total: "+ dt1/1000+"s, "+(totalFrames*1000)/dt1 + " fps, "+dt1/totalFrames+" ms/f"); lastCheck=curTime; lastFrames=0; } diff --git a/src/classes/com/sun/opengl/impl/GLArrayHandler.java b/src/classes/com/sun/opengl/impl/GLArrayHandler.java new file mode 100644 index 000000000..bba190835 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/GLArrayHandler.java @@ -0,0 +1,11 @@ + +package com.sun.opengl.impl; + +import javax.media.opengl.*; + +public interface GLArrayHandler { + + public void enableBuffer(GL gl, boolean enable); + +} + diff --git a/src/classes/com/sun/opengl/impl/GLFixedArrayHandler.java b/src/classes/com/sun/opengl/impl/GLFixedArrayHandler.java new file mode 100644 index 000000000..9882beb69 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/GLFixedArrayHandler.java @@ -0,0 +1,63 @@ + +package com.sun.opengl.impl; + +import javax.media.opengl.*; +import javax.media.opengl.glsl.ShaderState; +import java.nio.*; + +public class GLFixedArrayHandler implements GLArrayHandler { + private GLArrayData ad; + + public GLFixedArrayHandler(GLArrayData ad) { + this.ad = ad; + } + + protected final void passArrayPointer(GL gl) { + switch(ad.getIndex()) { + case GL.GL_VERTEX_ARRAY: + gl.glVertexPointer(ad); + break; + case GL.GL_NORMAL_ARRAY: + gl.glNormalPointer(ad); + break; + case GL.GL_COLOR_ARRAY: + gl.glColorPointer(ad); + break; + case GL.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) { + if(enable) { + gl.glEnableClientState(ad.getIndex()); + + Buffer buffer = ad.getBuffer(); + + if(ad.isVBO()) { + // always bind and refresh the VBO mgr, + // in case more than one gl*Pointer objects are in use + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, ad.getVBOName()); + if(!ad.isBufferWritten()) { + if(null!=buffer) { + gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * ad.getComponentSize(), buffer, ad.getBufferUsage()); + } + ad.setBufferWritten(true); + } + passArrayPointer(gl); + } else if(null!=buffer) { + passArrayPointer(gl); + ad.setBufferWritten(true); + } + } else { + if(ad.isVBO()) { + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + } + gl.glDisableClientState(ad.getIndex()); + } + } +} + diff --git a/src/classes/com/sun/opengl/impl/glsl/GLSLArrayDataServer.java b/src/classes/com/sun/opengl/impl/glsl/GLSLArrayDataServer.java deleted file mode 100644 index 14613227e..000000000 --- a/src/classes/com/sun/opengl/impl/glsl/GLSLArrayDataServer.java +++ /dev/null @@ -1,67 +0,0 @@ - -package com.sun.opengl.impl.glsl; - -import javax.media.opengl.*; -import javax.media.opengl.glsl.ShaderState; -import java.nio.*; - -public class GLSLArrayDataServer extends GLArrayDataServer { - - public GLSLArrayDataServer(String name, int comps, int dataType, boolean normalized, - int stride, Buffer buffer, int glBufferUsage) { - init(name, -1, comps, dataType, normalized, stride, buffer, 0, buffer.limit(), glBufferUsage, true); - } - - public GLSLArrayDataServer(String name, int comps, int dataType, boolean normalized, - int stride, long bufferOffset) { - init(name, -1, comps, dataType, normalized, stride, null, bufferOffset, 0, -1, true); - } - - public GLSLArrayDataServer(String name, int comps, int dataType, boolean normalized, - int initialSize, int glBufferUsage) { - init(name, -1, comps, dataType, normalized, 0, null, 0, initialSize, glBufferUsage, true); - } - - protected final void passVertexAttribPointer(GL2ES2 gl, ShaderState st) { - if ( ! st.glVertexAttribPointer(gl, this) ) { - throw new RuntimeException("Internal Error"); - } - } - - protected void enableBufferGLImpl(GL gl, boolean enable) { - GL2ES2 glsl = gl.getGL2ES2(); - ShaderState st = ShaderState.getCurrent(); - if(null==st) { - throw new GLException("No ShaderState current"); - } - - if(enable) { - if(!st.glEnableVertexAttribArray(glsl, name)) { - throw new RuntimeException("Internal Error"); - } - - if(vboUsage) { - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName); - if(!bufferWritten) { - if(null!=buffer) { - gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * getComponentSize(), buffer, glBufferUsage); - } - bufferWritten=true; - } - passVertexAttribPointer(glsl, st); - } else if(null!=buffer) { - passVertexAttribPointer(glsl, st); - bufferWritten=true; - } - } else { - if(vboUsage) { - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); - } - if(!st.glDisableVertexAttribArray(glsl, name)) { - throw new RuntimeException("Internal Error"); - } - } - } - -} - diff --git a/src/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java b/src/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java new file mode 100644 index 000000000..2910e67bd --- /dev/null +++ b/src/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java @@ -0,0 +1,63 @@ + +package com.sun.opengl.impl.glsl; + +import com.sun.opengl.impl.*; + +import javax.media.opengl.*; +import javax.media.opengl.glsl.ShaderState; +import java.nio.*; + +public class GLSLArrayHandler implements GLArrayHandler { + private GLArrayData ad; + + public GLSLArrayHandler(GLArrayData ad) { + this.ad = ad; + } + + protected final void passVertexAttribPointer(GL2ES2 gl, ShaderState st) { + if ( ! st.glVertexAttribPointer(gl, ad) ) { + throw new RuntimeException("Internal Error"); + } + } + + public void enableBuffer(GL gl, boolean enable) { + GL2ES2 glsl = gl.getGL2ES2(); + ShaderState st = ShaderState.getCurrent(); + if(null==st) { + throw new GLException("No ShaderState current"); + } + + if(enable) { + if(!st.glEnableVertexAttribArray(glsl, ad.getName())) { + throw new RuntimeException("Internal Error"); + } + + Buffer buffer = ad.getBuffer(); + + if(ad.isVBO()) { + // always bind and refresh the VBO mgr, + // in case more than one gl*Pointer objects are in use + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, ad.getVBOName()); + if(!ad.isBufferWritten()) { + if(null!=buffer) { + gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * ad.getComponentSize(), buffer, ad.getBufferUsage()); + } + ad.setBufferWritten(true); + } + passVertexAttribPointer(glsl, st); + } else if(null!=buffer) { + passVertexAttribPointer(glsl, st); + ad.setBufferWritten(true); + } + } else { + if(ad.isVBO()) { + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + } + if(!st.glDisableVertexAttribArray(glsl, ad.getName())) { + throw new RuntimeException("Internal Error"); + } + } + } + +} + |