diff options
author | Sven Gothel <[email protected]> | 2008-08-30 07:46:46 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2008-08-30 07:46:46 +0000 |
commit | 4ccc754cfb90bbcc8393ec1c6b8f593fc2cce751 (patch) | |
tree | f31c721f2268e02b86dfb26288fb52f46542f726 /src/demos | |
parent | b6600156175b22e94fbeb7a84682cce105050863 (diff) |
PerfTextLoad (wip)
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/branches/JOGL_2_SANDBOX@283 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src/demos')
-rwxr-xr-x | src/demos/es2/perftst/PerfTextLoad.java | 185 | ||||
-rw-r--r-- | src/demos/es2/perftst/data/bob2.gif | bin | 0 -> 23146 bytes | |||
-rw-r--r-- | src/demos/es2/perftst/data/gif2tgas.sh | 28 | ||||
-rw-r--r-- | src/demos/es2/perftst/shader/ftext.fp | 4 |
4 files changed, 132 insertions, 85 deletions
diff --git a/src/demos/es2/perftst/PerfTextLoad.java b/src/demos/es2/perftst/PerfTextLoad.java index c250863..532b3b7 100755 --- a/src/demos/es2/perftst/PerfTextLoad.java +++ b/src/demos/es2/perftst/PerfTextLoad.java @@ -1,19 +1,19 @@ package demos.es2.perftst; import java.nio.*; +import java.io.*; +import java.net.*; import javax.media.opengl.*; import javax.media.opengl.util.*; import javax.media.opengl.glsl.*; +import com.sun.opengl.util.texture.*; +import com.sun.opengl.util.io.*; import com.sun.javafx.newt.*; public class PerfTextLoad extends PerfModule { - static final int MAX_ARRAYS = 12; - static final int MAX_ARRAY_ELEM = 16; + static final int MAX_TEXTURE_ENGINES = 8; - GLUniformData[] dummyA, dummyB, dummyC; - final int dataType=GL.GL_FLOAT; - public PerfTextLoad() { } @@ -21,68 +21,77 @@ public class PerfTextLoad extends PerfModule { initShaderState(gl, "vbo-vert-text", "ftext"); } - protected void runOneSet(GLAutoDrawable drawable, int numObjs, int numArrayElem, int loops) { - GL2ES2 gl = drawable.getGL().getGL2ES2(); + Texture[] textures = null; + TextureData[] textDatas = null; - // - // Vertices Data setup - // + protected void runOneSet(GLAutoDrawable drawable, String textBaseName, int numObjs, int numTextures, int loops) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); - if(numObjs>MAX_ARRAYS) { - throw new GLException("numObjs must be within 0.."+MAX_ARRAYS); + if(numTextures>MAX_TEXTURE_ENGINES) { + throw new GLException("numTextures must be within 1.."+MAX_TEXTURE_ENGINES); } - if(numArrayElem>MAX_ARRAY_ELEM) { - throw new GLException("numArrayElem must be within 0.."+MAX_ARRAY_ELEM); + String textName = null; + textDatas = new TextureData[numObjs]; + textures = new Texture[numTextures]; + try { + for(int i=0; i<numObjs; i++) { + textName = "data/"+textBaseName+"."+(i+1)+".tga"; + URL urlText = Locator.getResource(Perftst.class, textName); + if(urlText==null) { + throw new RuntimeException("couldn't fetch "+textName); + } + textDatas[i] = TextureIO.newTextureData(urlText.openStream(), false, TextureIO.TGA); + } + for(int i=0; i<numTextures; i++) { + gl.glActiveTexture(i); + textures[i] = new Texture(GL.GL_TEXTURE_2D); + } + } catch (IOException ioe) { + System.err.println("couldn't fetch "+textName); + throw new RuntimeException(ioe); } + // + // Vertices Data setup + // + st.glUseProgram(gl, true); - GLArrayDataServer vertices = GLArrayDataServer.createGLSL("mgl_Vertex", 3, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); + GLArrayDataServer vertices = GLArrayDataServer.createGLSL("mgl_Vertex", 2, 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(1f); vb.put(1f); vb.put(0f); - vb.put(1f); vb.put(1f); vb.put(0f); + vb.put(0f); vb.put(0f); + vb.put(1f); vb.put(0f); + vb.put(0f); vb.put(1f); + vb.put(1f); vb.put(1f); } vertices.seal(gl, true); - GLArrayDataServer colors = GLArrayDataServer.createGLSL("mgl_Color", 4, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); + GLArrayDataServer texCoords = GLArrayDataServer.createGLSL("mgl_MultiTexCoord0", 2, 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); + FloatBuffer cb = (FloatBuffer)texCoords.getBuffer(); + cb.put(0f); cb.put(0f); + cb.put(1f); cb.put(0f); + cb.put(0f); cb.put(1f); + cb.put(1f); cb.put(1f); } - colors.seal(gl, true); + texCoords.seal(gl, true); // - // Uniform Data setup + // texture 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); - 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(); - - dummyUni[i] = new GLUniformData("mgl_Dummy"+i, 4, fb); + long[] tU = new long[numObjs+1]; + tU[0] = System.currentTimeMillis(); + for(int j=0; j<numTextures; j++) { + gl.glActiveTexture(j); + textures[j].updateImage(textDatas[0]); + tU[j+1] = System.currentTimeMillis(); } + GLUniformData activeTexture = new GLUniformData("mgl_ActiveTexture", 0); + st.glUniform(gl, activeTexture); + // // run loops // @@ -90,8 +99,9 @@ public class PerfTextLoad extends PerfModule { long dtC, dt, dt2, dt3, dtF, dtS, dtT; long[] tC = new long[loops]; long[] t0 = new long[loops]; - long[][] t1 = new long[loops][numObjs]; - long[][] t2 = new long[loops][numObjs]; + long[][][] t1 = new long[loops][numObjs][numTextures]; + long[][][] t2 = new long[loops][numObjs][numTextures]; + long[][][] t3 = new long[loops][numObjs][numTextures]; long[] tF = new long[loops]; long[] tS = new long[loops]; @@ -103,13 +113,21 @@ public class PerfTextLoad extends PerfModule { t0[i] = System.currentTimeMillis(); for(int j=0; j<numObjs; j++) { - st.glUniform(gl, dummyUni[j]); + for(int k=0; k<numTextures; k++) { + gl.glActiveTexture(GL.GL_TEXTURE0+k); + textures[k].enable(); + textures[k].bind(); + + t1[i][j][k] = System.currentTimeMillis(); - t1[i][j] = System.currentTimeMillis(); + textures[k].updateImage(textDatas[j]); - gl.glDrawArrays(GL.GL_LINE_STRIP, 0, vertices.getElementNumber()); + t2[i][j][k] = System.currentTimeMillis(); - t2[i][j] = System.currentTimeMillis(); + gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, vertices.getElementNumber()); + + t3[i][j][k] = System.currentTimeMillis(); + } } gl.glFinish(); @@ -119,10 +137,16 @@ public class PerfTextLoad extends PerfModule { drawable.swapBuffers(); tS[i] = System.currentTimeMillis(); + try { + Thread.sleep(1000); + } catch (Exception e) {} } - int uniElements = numObjs * numArrayElem ; - int uniBytes = uniElements * BufferUtil.SIZEOF_FLOAT; + int textBytes = 0; + for(int j=0; j<numObjs; j++) { + textBytes += textDatas[j].getEstimatedMemorySize(); + } + textBytes*=numTextures; dt = 0; for(int i=1; i<loops; i++) { @@ -130,16 +154,14 @@ public class PerfTextLoad extends PerfModule { } 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 + + System.out.println("Loops "+loops+", textures "+numTextures+", objects "+numObjs+ + ", total bytes "+textBytes+", total time: "+dt + "ms, fps(-1): "+(((loops-1)*1000)/dt)+ - ",\n uni elem/s: " + ((double)(loops*uniElements)/((double)dt/1000.0))); + ",\n text bytes /s: " + ((double)(loops*textBytes)/((double)dt/1000.0))); for(int i=0; i<loops; i++) { dtC= t0[i] - tC[i]; - dtF= tF[i] - t2[i][dummyUni.length-1]; + dtF= tF[i] - t3[i][numObjs-1][numTextures-1]; dtS= tS[i] - tF[i]; dtT= tS[i] - tC[i]; if(dtT<=0) dtT=1; @@ -148,41 +170,36 @@ public class PerfTextLoad extends PerfModule { 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); + dt3= t3[i][j] - t2[i][j]; + dtT= dt+dt2+dt3; + System.out.println("\t\tobj "+j+": setup "+dt +"ms, update "+dt2 +"ms, draw "+dt3+"ms, total: "+ dtT); } */ } System.out.println("*****************************************************************"); - st.glUseProgram(gl, false); + for(int i=0; i<numTextures; i++) { + textures[i].disable(); + textures[i].dispose(); + textures[i]=null; + } + for(int i=0; i<numObjs; i++) { + textDatas[i] = null; + } + textures=null; + textDatas=null; + System.gc(); try { Thread.sleep(100); } catch (Exception e) {} + System.gc(); } 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); - - if(MAX_ARRAYS>8) { - runOneSet(drawable, MAX_ARRAYS, 1, loops); - runOneSet(drawable, 1, MAX_ARRAYS, loops); - } - runOneSet(drawable, 1, 16, loops); - - runOneSet(drawable, 2, 16, loops); - runOneSet(drawable, 4, 16, loops); - runOneSet(drawable, 8, 16, loops); - if(MAX_ARRAYS>8) { - runOneSet(drawable, MAX_ARRAYS, 16, loops); - } + runOneSet(drawable, "bob2.64x64", 33, 1, loops); + //runOneSet(drawable, "bob2.128x128", 33, 1, loops); + //runOneSet(drawable, "bob2.256x256", 33, 1, loops); } } diff --git a/src/demos/es2/perftst/data/bob2.gif b/src/demos/es2/perftst/data/bob2.gif Binary files differnew file mode 100644 index 0000000..2faba51 --- /dev/null +++ b/src/demos/es2/perftst/data/bob2.gif diff --git a/src/demos/es2/perftst/data/gif2tgas.sh b/src/demos/es2/perftst/data/gif2tgas.sh new file mode 100644 index 0000000..2fd184b --- /dev/null +++ b/src/demos/es2/perftst/data/gif2tgas.sh @@ -0,0 +1,28 @@ +#! /bin/sh + +rm -rf tmp +mkdir -p tmp + +function gif2tga() +{ + bname=$1 + shift + images=$1 + shift + xysize=$1 + shift + + i=1 ; + while [ $i -le $images ] ; do + giftopnm -image $i $bname.gif > tmp/$bname.$i.pnm + pamscale -xsize=$xysize -ysize=$xysize tmp/$bname.$i.pnm > tmp/$bname.$xysize"x"$xysize.$i.pam + pamtotga -rgb -norle tmp/$bname.$xysize"x"$xysize.$i.pam > $bname.$xysize"x"$xysize.$i.tga + let i=$i+1 + done +} + +gif2tga bob2 33 64 +gif2tga bob2 33 128 +gif2tga bob2 33 256 +gif2tga bob2 33 512 + diff --git a/src/demos/es2/perftst/shader/ftext.fp b/src/demos/es2/perftst/shader/ftext.fp index d9bb6df..1bd251b 100644 --- a/src/demos/es2/perftst/shader/ftext.fp +++ b/src/demos/es2/perftst/shader/ftext.fp @@ -8,9 +8,11 @@ #endif varying vec4 mgl_TexCoord0; +uniform sampler2D mgl_ActiveTexture; void main (void) { - gl_FragColor = vec4(texture2D(0, mgl_TexCoord0.st).rgb, 1.0); + // gl_FragColor = vec4(texture2D(mgl_ActiveTexture, mgl_TexCoord0.st).rgb, 1.0); + gl_FragColor = vec4(0.2, 0.2, 0.2, 1.0) + vec4(texture2D(mgl_ActiveTexture, mgl_TexCoord0.st).rgb, 1.0); } |