summaryrefslogtreecommitdiffstats
path: root/src/demos/es2/perftst/PerfUniLoad.java
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/demos/es2/perftst/PerfUniLoad.java
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/demos/es2/perftst/PerfUniLoad.java')
-rwxr-xr-xsrc/demos/es2/perftst/PerfUniLoad.java180
1 files changed, 180 insertions, 0 deletions
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);
+ }
+
+}