diff options
Diffstat (limited to 'src/classes/com/sun/opengl')
4 files changed, 137 insertions, 67 deletions
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"); + } + } + } + +} + |