aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2008-08-21 14:51:51 +0000
committerSven Gothel <[email protected]>2008-08-21 14:51:51 +0000
commita971f95b23fd9f8287acdad1afc2eed75a531bc1 (patch)
tree5f9d5526acab5a7805b0a9b7963be9727217647c /src/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java
parent40d62b2514a8800a9ae0303d67fecdab3d5baada (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/opengl/impl/glsl/GLSLArrayHandler.java')
-rw-r--r--src/classes/com/sun/opengl/impl/glsl/GLSLArrayHandler.java63
1 files changed, 63 insertions, 0 deletions
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");
+ }
+ }
+ }
+
+}
+