aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-09-02 02:38:58 +0200
committerSven Gothel <[email protected]>2011-09-02 02:38:58 +0200
commit7f670735a6ca5945ab18769c597b80a1d5c86bb6 (patch)
tree012df9442ff6b1a179796816ffdf9a0322313b34 /src/test/com/jogamp
parentb4b9041daf6004d041d789cb564b839fac0fb149 (diff)
Gears/RedSquare ES1/ES2: Add proper destroy/init lifecycle incl. assertion checks; Use swapInterval ; RedSquareES2 use VBO
RedSquareES2 use VBO. - On Windows/NV we had to re-issue (pass down to GPU) the vertex attribute data (vertex/color), otherwise glDrawArrays crashes .. Probably a GL impl. bug. Hence we use VBO to minimize the data upload.
Diffstat (limited to 'src/test/com/jogamp')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/GearsObject.java34
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java25
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquareES1.java74
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java37
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java159
5 files changed, 200 insertions, 129 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/GearsObject.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/GearsObject.java
index 1bfa137a7..d73c7f735 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/GearsObject.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/GearsObject.java
@@ -37,18 +37,38 @@ public abstract class GearsObject {
public static final FloatBuffer blue = Buffers.newDirectFloatBuffer( new float[] { 0.2f, 0.2f, 1.0f, 0.7f } );
public static final float M_PI = (float)Math.PI;
- public final GLArrayDataServer frontFace;
- public final GLArrayDataServer frontSide;
- public final GLArrayDataServer backFace;
- public final GLArrayDataServer backSide;
- public final GLArrayDataServer outwardFace;
- public final GLArrayDataServer insideRadiusCyl;
+ public GLArrayDataServer frontFace;
+ public GLArrayDataServer frontSide;
+ public GLArrayDataServer backFace;
+ public GLArrayDataServer backSide;
+ public GLArrayDataServer outwardFace;
+ public GLArrayDataServer insideRadiusCyl;
+ public boolean isShared;
public abstract GLArrayDataServer createInterleaved(int comps, int dataType, boolean normalized, int initialSize, int vboUsage);
public abstract void addInterleavedVertexAndNormalArrays(GLArrayDataServer array, int components);
public abstract void draw(GL gl, float x, float y, float angle, FloatBuffer color);
+ public void destroy(GL gl) {
+ if(!isShared) {
+ frontFace.destroy(gl);
+ frontSide.destroy(gl);
+ backFace.destroy(gl);
+ backSide.destroy(gl);
+ outwardFace.destroy(gl);
+ insideRadiusCyl.destroy(gl);
+ }
+ frontFace=null;
+ frontSide=null;
+ backFace=null;
+ backSide=null;
+ outwardFace=null;
+ insideRadiusCyl=null;
+ isShared = false;
+ }
+
public GearsObject ( GearsObject shared ) {
+ isShared = true;
frontFace = shared.frontFace;
frontSide = shared.frontSide;
backFace = shared.backFace;
@@ -74,6 +94,8 @@ public abstract class GearsObject {
float normal[] = new float[3];
// final int tris_per_tooth = 32;
+ isShared = false;
+
r0 = inner_radius;
r1 = outer_radius - tooth_depth / 2.0f;
r2 = outer_radius + tooth_depth / 2.0f;
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java
index bf797924c..bcbb9f57c 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java
@@ -25,8 +25,11 @@ import javax.media.opengl.GL;
import javax.media.opengl.GL2ES1;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLException;
import javax.media.opengl.GLProfile;
+import org.junit.Assert;
+
import com.jogamp.newt.Window;
import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
@@ -80,7 +83,9 @@ public class GearsES1 implements GLEventListener {
public GearsObject getGear3() { return gear3; }
public void init(GLAutoDrawable drawable) {
- System.err.println("Gears: Init: "+drawable);
+ System.err.println(Thread.currentThread()+" GearsES1.init ...");
+ Assert.assertNull("Gear1 object is not null -> already init", gear1);
+
// Use debug pipeline
// drawable.setGL(new DebugGL(drawable.getGL()));
@@ -137,10 +142,12 @@ public class GearsES1 implements GLEventListener {
new com.jogamp.newt.event.awt.AWTMouseAdapter(gearsMouse).addTo(comp);
new com.jogamp.newt.event.awt.AWTKeyAdapter(gearsKeys).addTo(comp);
}
+ System.err.println(Thread.currentThread()+" GearsES1.init FIN");
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
- System.err.println("Gears: Reshape "+x+"/"+y+" "+width+"x"+height);
+ System.err.println(Thread.currentThread()+" GearsES1.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval);
+ Assert.assertNotNull("Gear1 object is null -> not init or already disposed", gear1);
GL2ES1 gl = drawable.getGL().getGL2ES1();
gl.setSwapInterval(swapInterval);
@@ -154,13 +161,25 @@ public class GearsES1 implements GLEventListener {
gl.glMatrixMode(GL2ES1.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -40.0f);
+ System.err.println(Thread.currentThread()+" GearsES1.reshape FIN");
}
public void dispose(GLAutoDrawable drawable) {
- System.err.println("Gears: Dispose");
+ System.err.println(Thread.currentThread()+" GearsES1.dispose ... ");
+ Assert.assertNotNull("Gear1 object is null -> not init or already disposed", gear1);
+ GL gl = drawable.getGL();
+ gear1.destroy(gl);
+ gear1 = null;
+ gear2.destroy(gl);
+ gear2 = null;
+ gear3.destroy(gl);
+ gear3 = null;
+ System.err.println(Thread.currentThread()+" GearsES1.dispose FIN");
}
public void display(GLAutoDrawable drawable) {
+ Assert.assertNotNull("Gear1 object is null -> not init or already disposed", gear1);
+
// Turn the gears' teeth
angle += 2.0f;
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquareES1.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquareES1.java
index 9c74ddce0..cc2578e9d 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquareES1.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquareES1.java
@@ -2,12 +2,13 @@ package com.jogamp.opengl.test.junit.jogl.demos.es1;
import com.jogamp.common.nio.Buffers;
import java.nio.*;
-import java.util.*;
import javax.media.opengl.*;
+import javax.media.opengl.fixedfunc.GLMatrixFunc;
+import javax.media.opengl.fixedfunc.GLPointerFunc;
import javax.media.opengl.glu.*;
-import javax.media.nativewindow.*;
-import com.jogamp.opengl.util.*;
+import org.junit.Assert;
+
import com.jogamp.opengl.util.glsl.fixedfunc.*;
public class RedSquareES1 implements GLEventListener {
@@ -17,22 +18,21 @@ public class RedSquareES1 implements GLEventListener {
public static boolean glTrace = false ;
public static boolean oneThread = false;
public static boolean useAnimator = false;
- public static int swapInterval = -1;
+ private int swapInterval = 0;
- boolean debug = false;
long startTime = 0;
long curTime = 0;
GLU glu = null;
- public RedSquareES1() {
- this(false);
+ public RedSquareES1(int swapInterval) {
+ this.swapInterval = swapInterval;
}
- public RedSquareES1(boolean debug) {
- this.debug = debug;
+ public RedSquareES1() {
+ this.swapInterval = 1;
}
-
+
// FIXME: we must add storage of the pointers in the GL state to
// the GLImpl classes. The need for this can be seen by making
// these variables method local instead of instance members. The
@@ -44,7 +44,8 @@ public class RedSquareES1 implements GLEventListener {
private FloatBuffer vertices;
public void init(GLAutoDrawable drawable) {
- System.out.println("RedSquare: Init");
+ System.err.println(Thread.currentThread()+" RedSquareES1.init ...");
+ Assert.assertNull("GLU object is not null -> already init", glu);
GL _gl = drawable.getGL();
if(glDebugEmu) {
@@ -62,10 +63,6 @@ public class RedSquareES1 implements GLEventListener {
}
GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(_gl);
- if(swapInterval>=0) {
- gl.setSwapInterval(swapInterval);
- }
-
if(glDebug) {
try {
// Debug ..
@@ -82,16 +79,10 @@ public class RedSquareES1 implements GLEventListener {
glu = GLU.createGLU(gl);
- if(debug) {
- System.err.println(Thread.currentThread()+" Entering initialization");
- System.err.println(Thread.currentThread()+" GL Profile: "+gl.getGLProfile());
- System.err.println(Thread.currentThread()+" GL:" + gl);
- System.err.println(Thread.currentThread()+" GL_VERSION=" + gl.glGetString(gl.GL_VERSION));
- System.err.println(Thread.currentThread()+" GL_EXTENSIONS:");
- System.err.println(Thread.currentThread()+" " + gl.glGetString(gl.GL_EXTENSIONS));
- System.err.println(Thread.currentThread()+" swapInterval: " + swapInterval + " (GL: "+gl.getSwapInterval()+")");
- System.err.println(Thread.currentThread()+" GLU: " + glu);
- }
+ System.err.println(Thread.currentThread()+" GL Profile: "+gl.getGLProfile());
+ System.err.println(Thread.currentThread()+" GL:" + gl);
+ System.err.println(Thread.currentThread()+" GL_VERSION=" + gl.glGetString(GL.GL_VERSION));
+ System.err.println(Thread.currentThread()+" GLU: " + glu);
// Allocate vertex arrays
colors = Buffers.newDirectFloatBuffer(16);
@@ -106,8 +97,6 @@ public class RedSquareES1 implements GLEventListener {
vertices.put(6, -2); vertices.put( 7, -2); vertices.put( 8, 0);
vertices.put(9, 2); vertices.put(10, -2); vertices.put(11, 0);
- gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
- gl.glEnableClientState(gl.GL_COLOR_ARRAY);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertices);
gl.glColorPointer(4, GL.GL_FLOAT, 0, colors);
@@ -117,53 +106,58 @@ public class RedSquareES1 implements GLEventListener {
startTime = System.currentTimeMillis();
curTime = startTime;
+ System.err.println(Thread.currentThread()+" RedSquareES1.init FIN");
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
- System.out.println("RedSquare: Reshape");
+ System.err.println(Thread.currentThread()+" RedSquareES1.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval);
+ Assert.assertNotNull("GLU object is null -> not init or already disposed", glu);
GL2ES1 gl = drawable.getGL().getGL2ES1();
+ gl.setSwapInterval(swapInterval);
+
// Set location in front of camera
- gl.glMatrixMode(gl.GL_PROJECTION);
+ gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, (float)width / (float)height, 1.0f, 100.0f);
//gl.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
//glu.gluLookAt(0, 0, -20, 0, 0, 0, 0, 1, 0);
+ System.err.println(Thread.currentThread()+" RedSquareES1.reshape FIN");
}
public void display(GLAutoDrawable drawable) {
+ Assert.assertNotNull("GLU object is null -> not init or already disposed", glu);
curTime = System.currentTimeMillis();
GL2ES1 gl = drawable.getGL().getGL2ES1();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
// One rotation every four seconds
- gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, -10);
float ang = ((float) (curTime - startTime) * 360.0f) / 4000.0f;
gl.glRotatef(ang, 0, 0, 1);
gl.glRotatef(ang, 0, 1, 0);
-
// Draw a square
+ gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ gl.glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);
+ gl.glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ gl.glDisableClientState(GLPointerFunc.GL_COLOR_ARRAY);
}
public void dispose(GLAutoDrawable drawable) {
- System.out.println("RedSquare: Dispose");
+ System.err.println(Thread.currentThread()+" RedSquareES1.dispose ... ");
+ Assert.assertNotNull("GLU object is null -> not init or already disposed", glu);
GL2ES1 gl = drawable.getGL().getGL2ES1();
- if(debug) {
- System.out.println(Thread.currentThread()+" RedSquare.dispose: "+gl.getContext());
- }
- gl.glDisableClientState(gl.GL_VERTEX_ARRAY);
- gl.glDisableClientState(gl.GL_COLOR_ARRAY);
+ gl.glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ gl.glDisableClientState(GLPointerFunc.GL_COLOR_ARRAY);
glu.destroy();
glu = null;
colors.clear();
colors = null;
vertices.clear();
vertices = null;
- if(debug) {
- System.out.println(Thread.currentThread()+" RedSquare.dispose: FIN");
- }
+ System.err.println(Thread.currentThread()+" RedSquareES1.dispose FIN");
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
index 70daa6852..d9e58dded 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
@@ -38,9 +38,12 @@ import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLException;
import javax.media.opengl.GLProfile;
import javax.media.opengl.GLUniformData;
+import junit.framework.Assert;
+
/**
* GearsES2.java <BR>
* @author Brian Paul (converted to Java by Ron Cemer and Sven Gothel) <P>
@@ -90,7 +93,8 @@ public class GearsES2 implements GLEventListener {
public void init(GLAutoDrawable drawable) {
- System.err.println("Gears: Init: "+drawable);
+ System.err.println(Thread.currentThread()+" GearsES2.init ...");
+ Assert.assertNull("ShaderState object is not null -> already init", st);
GL2ES2 gl = drawable.getGL().getGL2ES2();
System.err.println("Chosen GLCapabilities: " + drawable.getChosenGLCapabilities());
@@ -167,16 +171,20 @@ public class GearsES2 implements GLEventListener {
new com.jogamp.newt.event.awt.AWTMouseAdapter(gearsMouse).addTo(comp);
new com.jogamp.newt.event.awt.AWTKeyAdapter(gearsKeys).addTo(comp);
}
+ st.useProgram(gl, false);
+ System.err.println(Thread.currentThread()+" GearsES2.init FIN");
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
- System.err.println("Gears: Reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval);
+ System.err.println(Thread.currentThread()+" GearsES2.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval);
+ Assert.assertNotNull("ShaderState object is null -> not init or already disposed", st);
GL2ES2 gl = drawable.getGL().getGL2ES2();
gl.setSwapInterval(swapInterval);
float h = (float)height / (float)width;
+ st.useProgram(gl, true);
pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION);
pmvMatrix.glLoadIdentity();
pmvMatrix.glFrustumf(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
@@ -184,16 +192,31 @@ public class GearsES2 implements GLEventListener {
pmvMatrix.glLoadIdentity();
pmvMatrix.glTranslatef(0.0f, 0.0f, -40.0f);
st.uniform(gl, pmvMatrixUniform);
+ st.useProgram(gl, false);
+
+ System.err.println(Thread.currentThread()+" GearsES2.reshape FIN");
}
public void dispose(GLAutoDrawable drawable) {
- System.err.println("Gears: Dispose");
- // GL2ES2 gl = drawable.getGL().getGL2ES2();
- // st.useProgram(gl, false);
- // st.destroy(gl);
+ System.err.println(Thread.currentThread()+" GearsES2.dispose ... ");
+ Assert.assertNotNull("ShaderState object is null -> not init or already disposed", st);
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+ st.useProgram(gl, false);
+ gear1.destroy(gl);
+ gear1 = null;
+ gear2.destroy(gl);
+ gear2 = null;
+ gear3.destroy(gl);
+ gear3 = null;
+ pmvMatrix = null;
+ colorU = null;
+ st.destroy(gl);
+ st = null;
+ System.err.println(Thread.currentThread()+" GearsES2.dispose FIN");
}
public void display(GLAutoDrawable drawable) {
+ Assert.assertNotNull("ShaderState object is null -> not init or already disposed", st);
// Turn the gears' teeth
angle += 2.0f;
@@ -213,6 +236,7 @@ public class GearsES2 implements GLEventListener {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
}
+ st.useProgram(gl, true);
pmvMatrix.glPushMatrix();
pmvMatrix.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
pmvMatrix.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
@@ -222,6 +246,7 @@ public class GearsES2 implements GLEventListener {
gear2.draw(gl, 3.1f, -2.0f, -2f * angle - 9.0f, GearsObject.green);
gear3.draw(gl, -3.1f, 4.2f, -2f * angle - 25.0f, GearsObject.blue);
pmvMatrix.glPopMatrix();
+ st.useProgram(gl, false);
}
class GearsKeyAdapter extends KeyAdapter {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
index bcff745f7..c3dfb8897 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
@@ -27,104 +27,108 @@
*/
package com.jogamp.opengl.test.junit.jogl.demos.es2;
-import com.jogamp.common.nio.Buffers;
-import com.jogamp.opengl.util.GLArrayDataWrapper;
+import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.util.PMVMatrix;
-import com.jogamp.opengl.test.junit.jogl.demos.es2.shader.RedSquareShader;
-import com.jogamp.opengl.test.junit.util.GLSLSimpleProgram;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.nio.FloatBuffer;
+import com.jogamp.opengl.util.glsl.ShaderCode;
+import com.jogamp.opengl.util.glsl.ShaderProgram;
+import com.jogamp.opengl.util.glsl.ShaderState;
import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLException;
import javax.media.opengl.GLUniformData;
import org.junit.Assert;
public class RedSquareES2 implements GLEventListener {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream pbaos = new PrintStream(baos);
- GLSLSimpleProgram myShader;
+ ShaderState st;
PMVMatrix pmvMatrix;
- int mgl_PMVMatrix;
GLUniformData pmvMatrixUniform;
- int mgl_Vertex;
- int mgl_Color;
+ GLArrayDataServer vertices ;
+ GLArrayDataServer colors ;
long t0;
+ private int swapInterval = 0;
+ public RedSquareES2(int swapInterval) {
+ this.swapInterval = swapInterval;
+ }
+
+ public RedSquareES2() {
+ this.swapInterval = 1;
+ }
+
public void init(GLAutoDrawable glad) {
+ System.err.println(Thread.currentThread()+" RedSquareES2.init ...");
+ Assert.assertNull("ShaderState object is not null -> already init", st);
GL2ES2 gl = glad.getGL().getGL2ES2();
- myShader = GLSLSimpleProgram.create(gl, RedSquareShader.VERTEX_SHADER_TEXT, RedSquareShader.FRAGMENT_SHADER_TEXT, true);
- gl.glUseProgram(myShader.getShaderProgram());
- Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+
+ System.err.println(Thread.currentThread()+" GL Profile: "+gl.getGLProfile());
+ System.err.println(Thread.currentThread()+" GL:" + gl);
+ System.err.println(Thread.currentThread()+" GL_VERSION=" + gl.glGetString(GL.GL_VERSION));
+
+ st = new ShaderState();
+ st.setVerbose(true);
+ final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, this.getClass(),
+ "shader", "shader/bin", "RedSquareShader");
+ final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, 1, this.getClass(),
+ "shader", "shader/bin", "RedSquareShader");
+ final ShaderProgram sp0 = new ShaderProgram();
+ sp0.add(gl, vp0, System.err);
+ sp0.add(gl, fp0, System.err);
+ st.attachShaderProgram(gl, sp0);
+ st.useProgram(gl, true);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+
// setup mgl_PMVMatrix
pmvMatrix = new PMVMatrix();
pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION);
pmvMatrix.glLoadIdentity();
pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW);
- pmvMatrix.glLoadIdentity();
- mgl_PMVMatrix = gl.glGetUniformLocation(myShader.getShaderProgram(), "mgl_PMVMatrix");
- Assert.assertTrue(0 <= mgl_PMVMatrix);
- Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());
- pmvMatrixUniform.setLocation(mgl_PMVMatrix);
- gl.glUniform(pmvMatrixUniform);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); // P, Mv
+ st.ownUniform(pmvMatrixUniform);
+ st.uniform(gl, pmvMatrixUniform);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+
// Allocate Vertex Array
- int components = 3;
- int numElements = 4;
- mgl_Vertex = gl.glGetAttribLocation(myShader.getShaderProgram(), "mgl_Vertex");
- Assert.assertTrue(0 <= mgl_Vertex);
- Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- FloatBuffer buffer = Buffers.newDirectFloatBuffer(numElements * components);
- GLArrayDataWrapper vertices = GLArrayDataWrapper.createGLSL("mgl_Vertex", 3, gl.GL_FLOAT, false, 0, buffer, 0, 0, 0, GL.GL_ARRAY_BUFFER);
- {
- // Fill them up
- FloatBuffer verticeb = (FloatBuffer) vertices.getBuffer();
- verticeb.put(-2); verticeb.put( 2); verticeb.put( 0);
- verticeb.put( 2); verticeb.put( 2); verticeb.put( 0);
- verticeb.put(-2); verticeb.put(-2); verticeb.put( 0);
- verticeb.put( 2); verticeb.put(-2); verticeb.put( 0);
- }
- buffer.flip();
- vertices.setLocation(mgl_Vertex);
- gl.glEnableVertexAttribArray(mgl_Vertex);
- gl.glVertexAttribPointer(vertices);
- Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ vertices = GLArrayDataServer.createGLSL("mgl_Vertex", 3, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW);
+ vertices.putf(-2); vertices.putf( 2); vertices.putf( 0);
+ vertices.putf( 2); vertices.putf( 2); vertices.putf( 0);
+ vertices.putf(-2); vertices.putf(-2); vertices.putf( 0);
+ vertices.putf( 2); vertices.putf(-2); vertices.putf( 0);
+ vertices.seal(gl, true);
+ st.ownAttribute(vertices, true);
+ vertices.enableBuffer(gl, false);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+
// Allocate Color Array
- components = 4;
- numElements = 4;
- mgl_Color = gl.glGetAttribLocation(myShader.getShaderProgram(), "mgl_Color");
- Assert.assertTrue(0 <= mgl_Color);
- Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- buffer = Buffers.newDirectFloatBuffer(numElements * components);
- GLArrayDataWrapper colors = GLArrayDataWrapper.createGLSL("mgl_Color", 4, gl.GL_FLOAT, false, 0, buffer, 0, 0, 0, GL.GL_ARRAY_BUFFER);
- {
- // Fill them up
- FloatBuffer colorb = (FloatBuffer) colors.getBuffer();
- colorb.put(1); colorb.put(0); colorb.put(0); colorb.put(1);
- colorb.put(0); colorb.put(0); colorb.put(1); colorb.put(1);
- colorb.put(1); colorb.put(0); colorb.put(0); colorb.put(1);
- colorb.put(1); colorb.put(0); colorb.put(0); colorb.put(1);
- }
- buffer.flip();
- colors.setLocation(mgl_Color);
- gl.glEnableVertexAttribArray(mgl_Color);
- gl.glVertexAttribPointer(colors);
- Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ colors= GLArrayDataServer.createGLSL("mgl_Color", 4, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW);
+ colors.putf(1); colors.putf(0); colors.putf(0); colors.putf(1);
+ colors.putf(0); colors.putf(0); colors.putf(1); colors.putf(1);
+ colors.putf(1); colors.putf(0); colors.putf(0); colors.putf(1);
+ colors.putf(1); colors.putf(0); colors.putf(0); colors.putf(1);
+ colors.seal(gl, true);
+ st.ownAttribute(colors, true);
+ colors.enableBuffer(gl, false);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+
// OpenGL Render Settings
gl.glClearColor(0, 0, 0, 1);
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
- gl.glUseProgram(0);
+ st.useProgram(gl, false);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
t0 = System.currentTimeMillis();
+ System.err.println(Thread.currentThread()+" RedSquareES2.init FIN");
}
public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) {
+ System.err.println(Thread.currentThread()+" RedSquareES2.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval);
+ Assert.assertNotNull("ShaderState object is null -> not init or already disposed", st);
GL2ES2 gl = glad.getGL().getGL2ES2();
- gl.glUseProgram(myShader.getShaderProgram());
+ gl.setSwapInterval(swapInterval);
+
+ st.useProgram(gl, true);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
// Set location in front of camera
pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION);
@@ -133,17 +137,19 @@ public class RedSquareES2 implements GLEventListener {
//pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
gl.glUniform(pmvMatrixUniform);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- gl.glUseProgram(0);
+ st.useProgram(gl, false);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ System.err.println(Thread.currentThread()+" RedSquareES2.reshape FIN");
}
public void display(GLAutoDrawable glad) {
+ Assert.assertNotNull("ShaderState object is null -> not init or already disposed", st);
long t1 = System.currentTimeMillis();
GL2ES2 gl = glad.getGL().getGL2ES2();
- gl.glUseProgram(myShader.getShaderProgram());
+ st.useProgram(gl, true);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
// One rotation every four seconds
pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW);
@@ -155,20 +161,25 @@ public class RedSquareES2 implements GLEventListener {
gl.glUniform(pmvMatrixUniform);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
// Draw a square
- gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4);
+ vertices.enableBuffer(gl, true);
+ colors.enableBuffer(gl, true);
+ gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);
+ vertices.enableBuffer(gl, false);
+ colors.enableBuffer(gl, false);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- gl.glUseProgram(0);
+ st.useProgram(gl, false);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
}
public void dispose(GLAutoDrawable glad) {
+ System.err.println(Thread.currentThread()+" RedSquareES2.dispose ... ");
+ Assert.assertNotNull("ShaderState object is null -> not init or already disposed", st);
GL2ES2 gl = glad.getGL().getGL2ES2();
- gl.glDisableVertexAttribArray(mgl_Vertex);
- gl.glDisableVertexAttribArray(mgl_Color);
- myShader.release(gl);
+ st.destroy(gl);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ st = null;
pmvMatrix.destroy();
pmvMatrix = null;
- System.err.println("dispose done");
+ System.err.println(Thread.currentThread()+" RedSquareES2.dispose FIN");
}
}