summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2008-08-21 17:40:54 +0000
committerSven Gothel <[email protected]>2008-08-21 17:40:54 +0000
commit0b657e84188652ea4e400861f778bdebcd35d6b3 (patch)
treedbac158f594cfcdb01962678fbc54b212a256460 /src
parent53b839d9c65114998b561a9a9f9309dff9636f77 (diff)
ES2 performance test: 1st draft
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/branches/JOGL_2_SANDBOX@277 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src')
-rw-r--r--src/demos/es1/cube/Cube.java36
-rw-r--r--src/demos/es1/cube/CubeImmModeSink.java7
-rwxr-xr-xsrc/demos/es1/cubefbo/Main.java2
-rwxr-xr-xsrc/demos/es2/RedSquare.java11
-rw-r--r--src/demos/es2/perftst/PerfModule.java94
-rwxr-xr-xsrc/demos/es2/perftst/PerfUniLoad.java180
-rwxr-xr-xsrc/demos/es2/perftst/PerfVBOLoad.java190
-rwxr-xr-xsrc/demos/es2/perftst/Perftst.java171
-rwxr-xr-xsrc/demos/es2/perftst/shader/bin/nvidia/fcolor.bfpbin0 -> 524 bytes
-rwxr-xr-xsrc/demos/es2/perftst/shader/bin/nvidia/uni-vert-col.bvpbin0 -> 8148 bytes
-rwxr-xr-xsrc/demos/es2/perftst/shader/bin/nvidia/vbo-vert-col.bvpbin0 -> 864 bytes
-rw-r--r--src/demos/es2/perftst/shader/fcolor.fp16
-rwxr-xr-xsrc/demos/es2/perftst/shader/scripts/nvidia-apx/glslc-ff.bat9
-rw-r--r--src/demos/es2/perftst/shader/uni-vert-col.vp57
-rw-r--r--src/demos/es2/perftst/shader/vbo-vert-col.vp19
15 files changed, 769 insertions, 23 deletions
diff --git a/src/demos/es1/cube/Cube.java b/src/demos/es1/cube/Cube.java
index d46e87d..48e1b6b 100644
--- a/src/demos/es1/cube/Cube.java
+++ b/src/demos/es1/cube/Cube.java
@@ -77,6 +77,9 @@ public class Cube implements GLEventListener {
gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLORTEXTURE);
System.err.println("Cubes Fixed emu: FIXED_EMULATION_VERTEXCOLORTEXTURE");
}
+
+ gl.glGenBuffers(4, vboNames, 0);
+
if(!innerCube) {
System.err.println("Entering initialization");
System.err.println("GL Profile: "+GLProfile.getProfile());
@@ -133,13 +136,32 @@ public class Cube implements GLEventListener {
}
gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboNames[0]);
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, cubeVertices.limit() * BufferUtil.SIZEOF_SHORT, cubeVertices, GL.GL_STATIC_DRAW);
+ gl.glVertexPointer(3, gl.GL_SHORT, 0, 0);
+
gl.glEnableClientState(gl.GL_NORMAL_ARRAY);
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboNames[1]);
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, cubeNormals.limit() * BufferUtil.SIZEOF_BYTE, cubeNormals, GL.GL_STATIC_DRAW);
+ gl.glNormalPointer(gl.GL_BYTE, 0, 0);
+
gl.glEnableClientState(gl.GL_COLOR_ARRAY);
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboNames[2]);
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, cubeColors.limit() * BufferUtil.SIZEOF_FLOAT, cubeColors, GL.GL_STATIC_DRAW);
+ gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
+
if (cubeTexCoords != null) {
gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY);
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboNames[3]);
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, cubeTexCoords.limit() * BufferUtil.SIZEOF_SHORT, cubeTexCoords, GL.GL_STATIC_DRAW);
+ gl.glTexCoordPointer(2, gl.GL_SHORT, 0, 0);
+ if(null!=glF) {
+ glF.glTexEnvi(glF.GL_TEXTURE_ENV, glF.GL_TEXTURE_ENV_MODE, glF.GL_INCR);
+ }
} else {
gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY);
}
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
if(null!=glF) {
glF.glHint(glF.GL_PERSPECTIVE_CORRECTION_HINT, glF.GL_FASTEST);
@@ -172,17 +194,6 @@ public class Cube implements GLEventListener {
gl.glRotatef((float)(time * 29.77f), 1.0f, 2.0f, 0.0f);
gl.glRotatef((float)(time * 22.311f), -0.1f, 0.0f, -5.0f);
- gl.glVertexPointer(3, gl.GL_SHORT, 0, cubeVertices);
- gl.glColorPointer(4, gl.GL_FLOAT, 0, cubeColors);
- gl.glNormalPointer(gl.GL_BYTE, 0, cubeNormals);
- if (cubeTexCoords != null) {
- gl.glTexCoordPointer(2, gl.GL_SHORT, 0, cubeTexCoords);
- if(null!=glF) {
- glF.glTexEnvi(glF.GL_TEXTURE_ENV, glF.GL_TEXTURE_ENV_MODE, glF.GL_INCR);
- }
- }
-
-
gl.glDrawElements(gl.GL_TRIANGLES, 6 * 6, gl.GL_UNSIGNED_BYTE, cubeIndices);
// gl.glFinish();
// System.err.println(gl);
@@ -199,6 +210,7 @@ public class Cube implements GLEventListener {
static final float[] material_spec = { 1.0f, 1.0f, 1.0f, 0.f };
static final float[] zero_vec4 = { 0.0f, 0.0f, 0.0f, 0.f };
+ int[] vboNames = new int[4];
boolean innerCube;
boolean initialized = false;
float time = 0.0f;
@@ -311,7 +323,7 @@ public class Cube implements GLEventListener {
window.setFullscreen(true);
window.setVisible(true);
- while (window.getDuration() < 20000) {
+ while (window.getDuration() < 31000) {
window.display();
}
diff --git a/src/demos/es1/cube/CubeImmModeSink.java b/src/demos/es1/cube/CubeImmModeSink.java
index 219e5fd..c0ad4aa 100644
--- a/src/demos/es1/cube/CubeImmModeSink.java
+++ b/src/demos/es1/cube/CubeImmModeSink.java
@@ -43,6 +43,7 @@ public class CubeImmModeSink implements GLEventListener {
this(false, false);
}
+ private static boolean VBO_CACHE = true;
ByteBuffer cubeIndices=null;
ImmModeSink vboCubeF = null;
@@ -78,7 +79,6 @@ public class CubeImmModeSink implements GLEventListener {
if(null!=vboCubeF) {
vboCubeF.draw(gl, cubeIndices, true);
}
- System.err.println("VBO Cube fin");
}
private GLUquadric sphere=null;
@@ -86,6 +86,7 @@ public class CubeImmModeSink implements GLEventListener {
public void drawSphere(GL gl, float radius, int slices, int stacks) {
if(sphere==null) {
sphere = glu.gluNewQuadric();
+ sphere.enableImmModeSink(true);
sphere.setImmMode((VBO_CACHE)?false:true);
}
ImmModeSink vbo = vboSphere;
@@ -105,12 +106,12 @@ public class CubeImmModeSink implements GLEventListener {
}
- private static boolean VBO_CACHE = true;
private GLUquadric cylinder=null;
private ImmModeSink vboCylinder=null;
public void drawCylinder(GL gl, float radius, float halfHeight, int upAxis) {
if(cylinder==null) {
cylinder = glu.gluNewQuadric();
+ cylinder.enableImmModeSink(true);
cylinder.setImmMode((VBO_CACHE)?false:true);
}
@@ -409,7 +410,7 @@ public class CubeImmModeSink implements GLEventListener {
long curTime;
long startTime = System.currentTimeMillis();
- while (((curTime = System.currentTimeMillis()) - startTime) < 20000) {
+ while (((curTime = System.currentTimeMillis()) - startTime) < 31000) {
window.display();
}
diff --git a/src/demos/es1/cubefbo/Main.java b/src/demos/es1/cubefbo/Main.java
index b23b221..cc43ebf 100755
--- a/src/demos/es1/cubefbo/Main.java
+++ b/src/demos/es1/cubefbo/Main.java
@@ -67,7 +67,7 @@ public class Main implements MouseListener {
FBCubes cubes = new FBCubes();
window.addGLEventListener(cubes);
- while ( !quit && window.getDuration() < 215000) {
+ while ( !quit && window.getDuration() < 31000) {
window.display();
}
diff --git a/src/demos/es2/RedSquare.java b/src/demos/es2/RedSquare.java
index 089ebfe..ce1d0c2 100755
--- a/src/demos/es2/RedSquare.java
+++ b/src/demos/es2/RedSquare.java
@@ -138,7 +138,7 @@ public class RedSquare implements MouseListener, GLEventListener {
throw new GLException("Error setting PMVMatrix in shader: "+st);
}
// Allocate vertex arrays
- GLArrayDataClient vertices = GLArrayDataClient.createGLSL(-1, "mgl_Vertex", 3, gl.GL_FLOAT, false, 4);
+ GLArrayDataClient vertices = GLArrayDataClient.createGLSL("mgl_Vertex", 3, gl.GL_FLOAT, false, 4);
{
// Fill them up
FloatBuffer verticeb = (FloatBuffer)vertices.getBuffer();
@@ -146,10 +146,10 @@ public class RedSquare implements MouseListener, GLEventListener {
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.flip();
}
+ vertices.seal(gl, true);
- GLArrayDataClient colors = GLArrayDataClient.createGLSL(-1, "mgl_Color", 4, gl.GL_FLOAT, false, 4);
+ GLArrayDataClient colors = GLArrayDataClient.createGLSL("mgl_Color", 4, gl.GL_FLOAT, false, 4);
{
// Fill them up
FloatBuffer colorb = (FloatBuffer)colors.getBuffer();
@@ -157,12 +157,9 @@ public class RedSquare implements MouseListener, GLEventListener {
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);
- colorb.flip();
}
+ colors.seal(gl, true);
- st.glVertexAttribPointer(gl, vertices);
- st.glVertexAttribPointer(gl, colors);
-
// OpenGL Render Settings
gl.glClearColor(0, 0, 0, 1);
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
diff --git a/src/demos/es2/perftst/PerfModule.java b/src/demos/es2/perftst/PerfModule.java
new file mode 100644
index 0000000..aaac612
--- /dev/null
+++ b/src/demos/es2/perftst/PerfModule.java
@@ -0,0 +1,94 @@
+package demos.es2.perftst;
+
+import java.nio.*;
+import javax.media.opengl.*;
+import javax.media.opengl.util.*;
+import javax.media.opengl.glsl.*;
+
+public abstract class PerfModule {
+
+ public abstract void initShaderState(GL2ES2 gl);
+
+ public abstract void run(GLAutoDrawable drawable, int loops);
+
+ ShaderState st = null;
+
+ public void initShaderState(GL2ES2 gl, String vShaderName, String fShaderName) {
+ if(st!=null) return;
+
+ long t0, t1;
+
+ st = new ShaderState();
+
+ // Create & Compile the shader objects
+ ShaderCode vp = ShaderCode.create(gl, gl.GL_VERTEX_SHADER, 1, Perftst.class,
+ "shader", "shader/bin", vShaderName);
+ ShaderCode fp = ShaderCode.create(gl, gl.GL_FRAGMENT_SHADER, 1, Perftst.class,
+ "shader", "shader/bin", fShaderName);
+
+ // Create & Link the shader program
+ ShaderProgram sp = new ShaderProgram();
+ sp.add(vp);
+ sp.add(fp);
+
+ t0 = System.currentTimeMillis();
+
+ if(!sp.link(gl, System.err)) {
+ throw new GLException("Couldn't link program: "+sp);
+ }
+
+ t1 = System.currentTimeMillis();
+
+ long dt = t1-t0;
+
+ System.out.println("shader creation: "+dt+" ms");
+
+ // Let's manage all our states using ShaderState.
+ st.attachShaderProgram(gl, sp);
+
+ st.glUseProgram(gl, true);
+ }
+
+ public static final void put(Buffer buffer, int type, float v) {
+ switch (type) {
+ case GL.GL_UNSIGNED_BYTE:
+ ((ByteBuffer)buffer).put((byte)(v*(float)0xFF));
+ break;
+ case GL.GL_BYTE:
+ ((ByteBuffer)buffer).put((byte)(v*(float)0x7F));
+ break;
+ case GL.GL_UNSIGNED_SHORT:
+ ((ShortBuffer)buffer).put((short)(v*(float)0xFFFF));
+ break;
+ case GL.GL_SHORT:
+ ((ShortBuffer)buffer).put((short)(v*(float)0x7FFF));
+ break;
+ case GL.GL_FLOAT:
+ ((FloatBuffer)buffer).put(v);
+ break;
+ case GL.GL_FIXED:
+ ((IntBuffer)buffer).put(FixedPoint.toFixed(v));
+ break;
+ }
+ }
+
+ public static final String getTypeName(int type) {
+ switch (type) {
+ case GL.GL_UNSIGNED_BYTE:
+ return "GL_UNSIGNED_BYTE";
+ case GL.GL_BYTE:
+ return "GL_BYTE";
+ case GL.GL_UNSIGNED_SHORT:
+ return "GL_UNSIGNED_SHORT";
+ case GL.GL_SHORT:
+ return "GL_SHORT";
+ case GL.GL_FLOAT:
+ return "GL_FLOAT";
+ case GL.GL_FIXED:
+ return "GL_FIXED";
+ }
+ return null;
+ }
+
+}
+
diff --git a/src/demos/es2/perftst/PerfUniLoad.java b/src/demos/es2/perftst/PerfUniLoad.java
new file mode 100755
index 0000000..a85de7f
--- /dev/null
+++ b/src/demos/es2/perftst/PerfUniLoad.java
@@ -0,0 +1,180 @@
+package demos.es2.perftst;
+
+import java.nio.*;
+import javax.media.opengl.*;
+import javax.media.opengl.util.*;
+import javax.media.opengl.glsl.*;
+
+import com.sun.javafx.newt.*;
+
+public class PerfUniLoad extends PerfModule {
+
+ GLUniformData[] dummyA, dummyB, dummyC;
+ final int dataType=GL.GL_FLOAT;
+
+ public PerfUniLoad() {
+ }
+
+ public void initShaderState(GL2ES2 gl) {
+ initShaderState(gl, "uni-vert-col", "fcolor");
+ }
+
+ protected void runOneSet(GLAutoDrawable drawable, int numObjs, int numArrayElem, int loops) {
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ //
+ // Vertices Data setup
+ //
+
+ if(numObjs>16) {
+ throw new GLException("numObjs must be within 0..16");
+ }
+
+ if(numArrayElem>16) {
+ throw new GLException("numArrayElem must be within 0..16");
+ }
+
+ st.glUseProgram(gl, true);
+
+ GLArrayDataServer vertices = GLArrayDataServer.createGLSL("mgl_Vertex", 3, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW);
+ {
+ FloatBuffer vb = (FloatBuffer)vertices.getBuffer();
+ vb.put(0f); vb.put(0f); vb.put(0f);
+ vb.put(1f); vb.put(0f); vb.put(0f);
+ vb.put(0f); vb.put(1f); vb.put(0f);
+ vb.put(1f); vb.put(1f); vb.put(0f);
+ }
+ vertices.seal(gl, true);
+
+ GLArrayDataServer colors = GLArrayDataServer.createGLSL("mgl_Color", 4, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW);
+ {
+ FloatBuffer cb = (FloatBuffer)colors.getBuffer();
+ cb.put(0f); cb.put(0f); cb.put(0f); cb.put(1f);
+ cb.put(1f); cb.put(0f); cb.put(0f); cb.put(1f);
+ cb.put(0f); cb.put(1f); cb.put(0f); cb.put(1f);
+ cb.put(0f); cb.put(0f); cb.put(1f); cb.put(1f);
+ }
+ colors.seal(gl, true);
+
+ //
+ // Uniform Data setup
+ //
+
+ GLUniformData[] dummyUni = new GLUniformData[numObjs];
+
+ float x=0f, y=0f, z=0f, w=0f;
+
+ for(int i=0; i<numObjs; i++) {
+ FloatBuffer fb = BufferUtil.newFloatBuffer(4*numArrayElem);
+ dummyUni[i] = new GLUniformData("mgl_Dummy"+i, 4, fb);
+
+ for(int j=0; j<numArrayElem; j++) {
+ // Fill them up
+ fb.put(x);
+ fb.put(y);
+ fb.put(z);
+ fb.put(w);
+ if(x==0f) x=1f;
+ else if(x==1f) { x=0f; y+=0.01f; }
+ if(y>1f) { x=0f; y=0f; z+=0.01f; }
+ }
+ fb.flip();
+ }
+
+ //
+ // run loops
+ //
+
+ long dtC, dt, dt2, dt3, dtF, dtS, dtT;
+ long tStart;
+ long[] tC = new long[loops];
+ long[] t0 = new long[loops];
+ long[][] t1 = new long[loops][numObjs];
+ long[][] t2 = new long[loops][numObjs];
+ long[] tF = new long[loops];
+ long[] tS = new long[loops];
+
+ tStart = System.currentTimeMillis();
+
+ for(int i=0; i<loops; i++) {
+ tC[i] = System.currentTimeMillis();
+
+ gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
+
+ t0[i] = System.currentTimeMillis();
+
+ for(int j=0; j<numObjs; j++) {
+ st.glUniform(gl, dummyUni[j]);
+
+ t1[i][j] = System.currentTimeMillis();
+
+ gl.glDrawArrays(GL.GL_LINE_STRIP, 0, vertices.getElementNumber());
+
+ t2[i][j] = System.currentTimeMillis();
+ }
+
+ gl.glFinish();
+
+ tF[i] = System.currentTimeMillis();
+
+ drawable.swapBuffers();
+
+ tS[i] = System.currentTimeMillis();
+ }
+
+ dt = tS[loops-1] - tStart;
+ int uniElements = numObjs * numArrayElem ;
+ int uniBytes = uniElements * BufferUtil.SIZEOF_FLOAT;
+ System.out.println("");
+
+ System.out.println("Loops "+loops+", uniform arrays "+dummyUni.length+", type FLOAT"+
+ ", uniforms array size "+numArrayElem+
+ ",\n total elements "+uniElements+
+ ", total bytes "+uniBytes+", total time: "+dt +
+ "ms, fps: "+((loops*1000)/dt)+
+ ",\n uni elem/s: " + ((double)(loops*uniElements)/((double)dt/1000.0)));
+
+ for(int i=0; i<loops; i++) {
+ dtC= t0[i] - tC[i];
+ dtF= tF[i] - t2[i][dummyUni.length-1];
+ dtS= tS[i] - tF[i];
+ dtT= tS[i] - tC[i];
+ if(dtT<=0) dtT=1;
+ System.out.println("\tloop "+i+": clear "+dtC+"ms, finish "+dtF+", swap "+dtS+"ms, total: "+ dtT+"ms, fps "+1000/dtT);
+ /*
+ for(int j=0; j<dummyUni.length; j++) {
+ dt = t1[i][j] - t0[i];
+ dt2= t2[i][j] - t1[i][j];
+ dtT= dt+dt2;
+ System.out.println("\t\tobj "+j+": uniform "+dt +"ms, draw "+dt2+"ms, total: "+ dtT);
+ } */
+ }
+ System.out.println("*****************************************************************");
+
+
+ st.glUseProgram(gl, false);
+
+ try {
+ Thread.sleep(1000);
+ } catch (Exception e) {}
+ }
+
+ public void run(GLAutoDrawable drawable, int loops) {
+ runOneSet(drawable, 1, 1, loops);
+
+ runOneSet(drawable, 4, 1, loops);
+ runOneSet(drawable, 1, 4, loops);
+
+ runOneSet(drawable, 8, 1, loops);
+ runOneSet(drawable, 1, 8, loops);
+
+ runOneSet(drawable, 16, 1, loops);
+ runOneSet(drawable, 1, 16, loops);
+
+ runOneSet(drawable, 2, 16, loops);
+ runOneSet(drawable, 4, 16, loops);
+ runOneSet(drawable, 8, 16, loops);
+ runOneSet(drawable, 16, 16, loops);
+ }
+
+}
diff --git a/src/demos/es2/perftst/PerfVBOLoad.java b/src/demos/es2/perftst/PerfVBOLoad.java
new file mode 100755
index 0000000..cf61e15
--- /dev/null
+++ b/src/demos/es2/perftst/PerfVBOLoad.java
@@ -0,0 +1,190 @@
+package demos.es2.perftst;
+
+import java.nio.*;
+import javax.media.opengl.*;
+import javax.media.opengl.util.*;
+import javax.media.opengl.glsl.*;
+
+import com.sun.javafx.newt.*;
+
+public class PerfVBOLoad extends PerfModule {
+
+ public PerfVBOLoad() {
+ }
+
+ public void initShaderState(GL2ES2 gl) {
+ initShaderState(gl, "vbo-vert-col", "fcolor");
+ }
+
+ protected void runOneSet(GLAutoDrawable drawable, int dataType, int numObjs, int numVertices, int loops) {
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ //
+ // data setup
+ //
+
+ GLArrayDataServer[] vertices = new GLArrayDataServer[numObjs];
+ GLArrayDataServer[] colors = new GLArrayDataServer[numObjs];
+
+ float x=0f, y=0f, z=0f;
+ float r=1f, g=1f, b=1f;
+
+ for(int i=0; i<numObjs; i++) {
+ vertices[i] = GLArrayDataServer.createGLSL("mgl_Vertex", 3, dataType, true, numVertices, GL.GL_STATIC_DRAW);
+ {
+ Buffer verticeb = vertices[i].getBuffer();
+ for(int j=0; j<numVertices; j++) {
+ // Fill them up
+ put(verticeb, dataType, x);
+ put(verticeb, dataType, y);
+ put(verticeb, dataType, z);
+ if(x==0f) x=1f;
+ else if(x==1f) { x=0f; y+=0.01f; }
+ if(y>1f) { x=0f; y=0f; z+=0.01f; }
+ }
+ }
+ colors[i] = GLArrayDataServer.createGLSL("mgl_Color", 4, dataType, true, numVertices, GL.GL_STATIC_DRAW);
+ {
+ // Fill them up
+ Buffer colorb = colors[i].getBuffer();
+ for(int j =0; j<numVertices; j++) {
+ put(colorb, dataType, r);
+ put(colorb, dataType, g);
+ put(colorb, dataType, b);
+ put(colorb, dataType, 1f-(float)i/10);
+ if(r<=1f) r+=0.01f;
+ else if(g<=1f) g+=0.01f;
+ else if(b<=1f) b+=0.01f;
+ else { r=0f; g=0f; b=0f; }
+ }
+ }
+ }
+
+ //
+ // run loops
+ //
+
+ long dtC, dt, dt2, dt3, dtF, dtS, dtT;
+ long tStart;
+ long[] tC = new long[loops];
+ long[] t0 = new long[loops];
+ long[][] t1 = new long[loops][numObjs];
+ long[][] t2 = new long[loops][numObjs];
+ long[][] t3 = new long[loops][numObjs];
+ long[] tF = new long[loops];
+ long[] tS = new long[loops];
+
+ // Push the 1st uniform down the path
+ st.glUseProgram(gl, true);
+
+ tStart = System.currentTimeMillis();
+
+ for(int i=0; i<loops; i++) {
+ tC[i] = System.currentTimeMillis();
+
+ gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
+
+ t0[i] = System.currentTimeMillis();
+
+ for(int j=0; j<numObjs; j++) {
+ if(i==0) {
+ vertices[j].seal(gl, true);
+ } else {
+ vertices[j].enableBuffer(gl, true);
+ }
+
+ t1[i][j] = System.currentTimeMillis();
+
+ if(i==0) {
+ colors[j].seal(gl, true);
+ } else {
+ colors[j].enableBuffer(gl, true);
+ }
+
+ t2[i][j] = System.currentTimeMillis();
+
+ gl.glDrawArrays(GL.GL_LINE_STRIP, 0, vertices[j].getElementNumber());
+ vertices[j].enableBuffer(gl, false);
+ colors[j].enableBuffer(gl, false);
+
+ t3[i][j] = System.currentTimeMillis();
+ }
+
+ gl.glFinish();
+
+ tF[i] = System.currentTimeMillis();
+
+ drawable.swapBuffers();
+
+ tS[i] = System.currentTimeMillis();
+ }
+
+ dt = tS[loops-1] - tStart;
+ int verticesElements = vertices[0].getElementNumber() * numObjs;
+ int verticesBytes = verticesElements * vertices[0].getComponentSize()* vertices[0].getComponentNumber();
+ int colorsElements = colors[0].getElementNumber() * colors.length;
+ int colorsBytes = colorsElements * colors[0].getComponentSize()* colors[0].getComponentNumber();
+ System.out.println("");
+
+ System.out.println("Loops "+loops+", objects "+numObjs+", type "+getTypeName(dataType)+
+ ", vertices p.o. "+vertices[0].getElementNumber()+
+ ", colors p.o. "+colors[0].getElementNumber()+
+ ",\n total elements "+(verticesElements+colorsElements)+
+ ", total bytes "+(verticesBytes+colorsBytes)+", total time: "+dt +
+ "ms, fps: "+((loops*1000)/dt)+
+ ",\n col.vert./s: " + ((double)(loops*verticesElements)/((double)dt/1000.0)));
+
+ for(int i=0; i<loops; i++) {
+ dtC= t0[i] - tC[i];
+ dtF= tF[i] - t3[i][numObjs-1];
+ dtS= tS[i] - tF[i];
+ dtT= tS[i] - tC[i];
+ if(dtT<=0) dtT=1;
+ System.out.println("\tloop "+i+": clear "+dtC+"ms, finish "+dtF+", swap "+dtS+"ms, total: "+ dtT+"ms, fps "+1000/dtT);
+ /*
+ for(int j=0; j<numObjs; j++) {
+ dt = t1[i][j] - t0[i];
+ dt2= t2[i][j] - t1[i][j];
+ dt3= t3[i][j] - t2[i][j];
+ dtT= dt+dt2+dt3;
+ System.out.println("\t\tobj "+j+": vertices "+dt +"ms, colors "+dt2+"ms, draw "+dt3+"ms, total: "+ dtT);
+ } */
+ }
+ System.out.println("*****************************************************************");
+
+
+ st.glUseProgram(gl, false);
+
+ try {
+ Thread.sleep(1000);
+ } catch (Exception e) {}
+ }
+
+ protected void runOneSet(GLAutoDrawable drawable, int numObjs, int numVertices, int loops) {
+ runOneSet(drawable, GL.GL_UNSIGNED_BYTE, numObjs, numVertices, loops);
+ runOneSet(drawable, GL.GL_BYTE, numObjs, numVertices, loops);
+ runOneSet(drawable, GL.GL_UNSIGNED_SHORT, numObjs, numVertices, loops);
+ runOneSet(drawable, GL.GL_SHORT, numObjs, numVertices, loops);
+ runOneSet(drawable, GL.GL_FLOAT, numObjs, numVertices, loops);
+
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+ if(gl.isGLES2()) {
+ runOneSet(drawable, GL.GL_FIXED, numObjs, numVertices, loops);
+ }
+ }
+
+ public void run(GLAutoDrawable drawable, int loops) {
+ runOneSet(drawable, 1, 100, loops);
+ runOneSet(drawable, 3, 100, loops);
+
+ runOneSet(drawable, 1, 1000, loops);
+ runOneSet(drawable, 3, 1000, loops);
+
+ runOneSet(drawable, 1, 10000, loops);
+ runOneSet(drawable, 3, 10000, loops);
+
+ runOneSet(drawable, 1, 100000, loops);
+ runOneSet(drawable, 3, 100000, loops);
+ }
+
+}
diff --git a/src/demos/es2/perftst/Perftst.java b/src/demos/es2/perftst/Perftst.java
new file mode 100755
index 0000000..d40c4c4
--- /dev/null
+++ b/src/demos/es2/perftst/Perftst.java
@@ -0,0 +1,171 @@
+package demos.es2.perftst;
+
+import java.nio.*;
+import javax.media.opengl.*;
+import javax.media.opengl.util.*;
+import javax.media.opengl.glsl.*;
+
+import com.sun.opengl.impl.GLReflection;
+
+import com.sun.javafx.newt.*;
+
+public class Perftst implements MouseListener, GLEventListener {
+
+ private GLWindow window;
+ private boolean quit = false;
+
+ private PerfModule pmod;
+ private ShaderState st;
+ private PMVMatrix pmvMatrix;
+
+
+ public void mouseClicked(MouseEvent e) {
+ quit=true;
+ }
+ public void mouseEntered(MouseEvent e) {
+ }
+ public void mouseExited(MouseEvent e) {
+ }
+ public void mousePressed(MouseEvent e) {
+ }
+ public void mouseReleased(MouseEvent e) {
+ }
+ public void mouseMoved(MouseEvent e) {
+ }
+ public void mouseDragged(MouseEvent e) {
+ }
+
+ private void run(int type, PerfModule pm) {
+ int width = 800;
+ int height = 480;
+ pmod = pm;
+ System.err.println("Perftst.run()");
+ GLProfile.setProfileGL2ES2();
+ try {
+ Window nWindow = null;
+ if(0!=(type&USE_AWT)) {
+ Display nDisplay = NewtFactory.createDisplay(NewtFactory.AWT, null); // local display
+ Screen nScreen = NewtFactory.createScreen(NewtFactory.AWT, nDisplay, 0); // screen 0
+ nWindow = NewtFactory.createWindow(NewtFactory.AWT, nScreen, 0); // dummy VisualID
+ }
+
+ GLCapabilities caps = new GLCapabilities();
+ // For emulation library, use 16 bpp
+ caps.setRedBits(5);
+ caps.setGreenBits(6);
+ caps.setBlueBits(5);
+ caps.setDepthBits(16);
+ window = GLWindow.create(nWindow, caps);
+
+ window.addMouseListener(this);
+ window.addGLEventListener(this);
+ // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_CURRENT); // default
+ // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_NONE); // no current ..
+
+ // Size OpenGL to Video Surface
+ window.setSize(width, height);
+ window.setFullscreen(true);
+ window.setVisible(true);
+
+ window.display();
+
+ // Shut things down cooperatively
+ window.close();
+ window.getFactory().shutdown();
+ System.out.println("Perftst shut down cleanly.");
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ drawable.setAutoSwapBufferMode(false);
+
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+ System.err.println("Entering initialization");
+ System.err.println("GL_VERSION=" + gl.glGetString(gl.GL_VERSION));
+ System.err.println("GL_EXTENSIONS:");
+ System.err.println(" " + gl.glGetString(gl.GL_EXTENSIONS));
+
+ if(gl.isGLES2()) {
+ pmvMatrix = gl.getGLES2().getPMVMatrix();
+ } else {
+ pmvMatrix = new PMVMatrix();
+ }
+
+ pmod.initShaderState(gl);
+ st = ShaderState.getCurrent();
+
+ // Push the 1st uniform down the path
+ st.glUseProgram(gl, true);
+
+ pmvMatrix.glMatrixMode(gl.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glMatrixMode(gl.GL_MODELVIEW);
+ pmvMatrix.glLoadIdentity();
+
+ if(!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()))) {
+ throw new GLException("Error setting PMVMatrix in shader: "+st);
+ }
+
+ // OpenGL Render Settings
+ gl.glClearColor(0, 0, 0, 1);
+ gl.glEnable(GL2ES2.GL_DEPTH_TEST);
+
+ st.glUseProgram(gl, false);
+
+ // Let's show the completed shader state ..
+ System.out.println(st);
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ st.glUseProgram(gl, true);
+
+ // Set location in front of camera
+ pmvMatrix.glMatrixMode(GL2ES2.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glOrthof(0f, 1.0f, 0.0f, 1.0f, 1.0f, 100.0f);
+
+ pmvMatrix.glMatrixMode(gl.GL_MODELVIEW);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glTranslatef(0, 0, -10);
+
+ GLUniformData ud = st.getUniform("mgl_PMVMatrix");
+ if(null!=ud) {
+ // same data object
+ st.glUniform(gl, ud);
+ }
+
+ st.glUseProgram(gl, false);
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ pmod.run(drawable, 10);
+ }
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+ }
+
+ public static int USE_NEWT = 0;
+ public static int USE_AWT = 1 << 0;
+
+ public static void main(String[] args) {
+ int type = USE_NEWT ;
+ String tstName = "demos.es2.perftst.PerfVBOLoad"; // default
+
+ for(int i=args.length-1; i>=0; i--) {
+ if(args[i].equals("-awt")) {
+ type |= USE_AWT;
+ }
+ if(args[i].equals("-test") && i+1<args.length ) {
+ tstName = args[i+1];
+ }
+ }
+
+ PerfModule pmod = (PerfModule) GLReflection.createInstance(tstName);
+ new Perftst().run(type, pmod);
+ System.exit(0);
+ }
+}
diff --git a/src/demos/es2/perftst/shader/bin/nvidia/fcolor.bfp b/src/demos/es2/perftst/shader/bin/nvidia/fcolor.bfp
new file mode 100755
index 0000000..454354c
--- /dev/null
+++ b/src/demos/es2/perftst/shader/bin/nvidia/fcolor.bfp
Binary files differ
diff --git a/src/demos/es2/perftst/shader/bin/nvidia/uni-vert-col.bvp b/src/demos/es2/perftst/shader/bin/nvidia/uni-vert-col.bvp
new file mode 100755
index 0000000..d31682c
--- /dev/null
+++ b/src/demos/es2/perftst/shader/bin/nvidia/uni-vert-col.bvp
Binary files differ
diff --git a/src/demos/es2/perftst/shader/bin/nvidia/vbo-vert-col.bvp b/src/demos/es2/perftst/shader/bin/nvidia/vbo-vert-col.bvp
new file mode 100755
index 0000000..ba0c982
--- /dev/null
+++ b/src/demos/es2/perftst/shader/bin/nvidia/vbo-vert-col.bvp
Binary files differ
diff --git a/src/demos/es2/perftst/shader/fcolor.fp b/src/demos/es2/perftst/shader/fcolor.fp
new file mode 100644
index 0000000..a94f705
--- /dev/null
+++ b/src/demos/es2/perftst/shader/fcolor.fp
@@ -0,0 +1,16 @@
+
+#ifdef GL_ES
+ #define MEDIUMP mediump
+ #define HIGHP highp
+#else
+ #define MEDIUMP
+ #define HIGHP
+#endif
+
+varying HIGHP vec4 frontColor;
+
+void main (void)
+{
+ gl_FragColor = frontColor;
+}
+
diff --git a/src/demos/es2/perftst/shader/scripts/nvidia-apx/glslc-ff.bat b/src/demos/es2/perftst/shader/scripts/nvidia-apx/glslc-ff.bat
new file mode 100755
index 0000000..c335b9d
--- /dev/null
+++ b/src/demos/es2/perftst/shader/scripts/nvidia-apx/glslc-ff.bat
@@ -0,0 +1,9 @@
+REM
+REM You have to call it from the 'shader' directory, e.g.:
+REM scripts\nvidia-apx\glslc-ff.bat
+REM
+IF !"%JOGLDIR%"==""! GOTO YESPATH
+set JOGLDIR=..
+:YESPATH
+
+java -cp %JOGLDIR%\jogl.core.jar;%JOGLDIR%\jogl.gles2.jar;%JOGLDIR%\jogl.fixed.jar;%JOGLDIR%\jogl.sdk.jar javax.media.opengl.sdk.glsl.CompileShaderNVidia fcolor.fp vbo-vert-col.vp uni-vert-col.vp
diff --git a/src/demos/es2/perftst/shader/uni-vert-col.vp b/src/demos/es2/perftst/shader/uni-vert-col.vp
new file mode 100644
index 0000000..f6fab17
--- /dev/null
+++ b/src/demos/es2/perftst/shader/uni-vert-col.vp
@@ -0,0 +1,57 @@
+
+#ifdef GL_ES
+ #define MEDIUMP mediump
+ #define HIGHP highp
+#else
+ #define MEDIUMP
+ #define HIGHP
+#endif
+
+uniform MEDIUMP mat4 mgl_PMVMatrix[2];
+uniform MEDIUMP vec4 mgl_Dummy0[16];
+uniform MEDIUMP vec4 mgl_Dummy1[16];
+uniform MEDIUMP vec4 mgl_Dummy2[16];
+uniform MEDIUMP vec4 mgl_Dummy3[16];
+uniform MEDIUMP vec4 mgl_Dummy4[16];
+uniform MEDIUMP vec4 mgl_Dummy5[16];
+uniform MEDIUMP vec4 mgl_Dummy6[16];
+uniform MEDIUMP vec4 mgl_Dummy7[16];
+uniform MEDIUMP vec4 mgl_Dummy8[16];
+uniform MEDIUMP vec4 mgl_Dummy9[16];
+uniform MEDIUMP vec4 mgl_Dummy10[16];
+uniform MEDIUMP vec4 mgl_Dummy11[16];
+uniform MEDIUMP vec4 mgl_Dummy12[16];
+uniform MEDIUMP vec4 mgl_Dummy13[16];
+uniform MEDIUMP vec4 mgl_Dummy14[16];
+uniform MEDIUMP vec4 mgl_Dummy15[16];
+attribute HIGHP vec4 mgl_Vertex;
+attribute HIGHP vec4 mgl_Color;
+varying HIGHP vec4 frontColor;
+
+void main(void)
+{
+ int i;
+ vec4 val;
+
+ for(i=0; i<16; i++) {
+ val += mgl_Dummy0[i];
+ val += mgl_Dummy1[i];
+ val += mgl_Dummy2[i];
+ val += mgl_Dummy3[i];
+ val += mgl_Dummy4[i];
+ val += mgl_Dummy5[i];
+ val += mgl_Dummy6[i];
+ val += mgl_Dummy7[i];
+ val += mgl_Dummy8[i];
+ val += mgl_Dummy9[i];
+ val += mgl_Dummy10[i];
+ val += mgl_Dummy11[i];
+ val += mgl_Dummy12[i];
+ val += mgl_Dummy13[i];
+ val += mgl_Dummy14[i];
+ val += mgl_Dummy15[i];
+ }
+
+ frontColor=mgl_Color+val;
+ gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;
+}
diff --git a/src/demos/es2/perftst/shader/vbo-vert-col.vp b/src/demos/es2/perftst/shader/vbo-vert-col.vp
new file mode 100644
index 0000000..0348e90
--- /dev/null
+++ b/src/demos/es2/perftst/shader/vbo-vert-col.vp
@@ -0,0 +1,19 @@
+
+#ifdef GL_ES
+ #define MEDIUMP mediump
+ #define HIGHP highp
+#else
+ #define MEDIUMP
+ #define HIGHP
+#endif
+
+uniform MEDIUMP mat4 mgl_PMVMatrix[2];
+attribute HIGHP vec4 mgl_Vertex;
+attribute HIGHP vec4 mgl_Color;
+varying HIGHP vec4 frontColor;
+
+void main(void)
+{
+ frontColor=mgl_Color;
+ gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;
+}