diff options
author | Kenneth Russel <[email protected]> | 2009-06-15 23:12:27 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2009-06-15 23:12:27 +0000 |
commit | 41cd6c47b23975098cd155517790e018670785e7 (patch) | |
tree | 247333528ad674d427ba96b1e05810f7961d609e /src/demos/es2/perftst/PerfModule.java | |
parent | 935d2596c13371bb745d921dbcb9f05b0c11a010 (diff) |
Copied JOGL_2_SANDBOX r350 on to trunk; JOGL_2_SANDBOX branch is now closed
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/trunk@352 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src/demos/es2/perftst/PerfModule.java')
-rw-r--r-- | src/demos/es2/perftst/PerfModule.java | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/demos/es2/perftst/PerfModule.java b/src/demos/es2/perftst/PerfModule.java new file mode 100644 index 0000000..1a6cda1 --- /dev/null +++ b/src/demos/es2/perftst/PerfModule.java @@ -0,0 +1,95 @@ +package demos.es2.perftst; + +import java.nio.*; +import javax.media.opengl.*; + +import com.sun.opengl.util.*; +import com.sun.opengl.util.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; + } + +} + |