From b3eed5170f323d1c6d4d90de28a691eebeb035df Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Tue, 13 May 2008 11:21:23 +0000 Subject: OpenGL ES 1 and ES 2 demos, not built by default; build.xml changes to conditionally build these demos via ant -Djogl.es1=1 or ant -Djogl.es2=1 git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/trunk@228 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4 --- make/build.xml | 59 +++++++++++- src/demos/apx/es1/RedSquare.java | 165 ++++++++++++++++++++++++++++++++++ src/demos/apx/es2/Basic.java | 147 ++++++++++++++++++++++++++++++ src/demos/apx/es2/Shader.java | 189 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 557 insertions(+), 3 deletions(-) create mode 100755 src/demos/apx/es1/RedSquare.java create mode 100755 src/demos/apx/es2/Basic.java create mode 100755 src/demos/apx/es2/Shader.java diff --git a/make/build.xml b/make/build.xml index 1394819..0b66f11 100644 --- a/make/build.xml +++ b/make/build.xml @@ -31,6 +31,23 @@ + + + + + + + + + + + + + + + + + @@ -39,7 +56,7 @@ - + @@ -73,7 +90,7 @@ - + @@ -81,7 +98,7 @@ - + @@ -125,6 +142,42 @@ /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0) { + int[] binaryFormats = new int[numBinaryFormats[0]]; + gl.glGetIntegerv(GL.GL_SHADER_BINARY_FORMATS, binaryFormats, 0); + boolean gotVertexFormat = false; + boolean gotFragmentFormat = false; + + for (int i = 0; i < binaryFormats.length && (!gotVertexFormat || !gotFragmentFormat); i++) { + if (!gotVertexFormat) { + gotVertexFormat = (binaryFormats[i] == vertexShaderFormat); + } + if (!gotFragmentFormat) { + gotFragmentFormat = (binaryFormats[i] == fragmentShaderFormat); + } + } + + if (!gotVertexFormat) { + throw new RuntimeException("Binary vertex program format 0x" + Integer.toHexString(vertexShaderFormat) + + " not available"); + } + + if (!gotFragmentFormat) { + throw new RuntimeException("Binary fragment program format 0x" + Integer.toHexString(fragmentShaderFormat) + + " not available"); + } + } + // Set up the shaders + setupBinaryShader(vertexShader, vertexShaderCode, vertexShaderFormat); + setupBinaryShader(fragmentShader, fragmentShaderCode, fragmentShaderFormat); + + // Set up the shader program + gl.glLinkProgram(program); + if (!glslLog(program, GL.GL_LINK_STATUS, "link")) { + throw new GLException("Error linking program"); + } + } + + private void allocProgram() { + GL gl = GLU.getCurrentGL(); + vertexShader = gl.glCreateShader(GL.GL_VERTEX_SHADER); + fragmentShader = gl.glCreateShader(GL.GL_FRAGMENT_SHADER); + program = gl.glCreateProgram(); + gl.glAttachShader(program, vertexShader); + gl.glAttachShader(program, fragmentShader); + } + + private void setupBinaryShader(int shader, + byte[] shaderData, + int binaryFormat) { + ByteBuffer buf = ByteBuffer.wrap(shaderData); + int[] tmp = new int[1]; + tmp[0] = shader; + GL gl = GLU.getCurrentGL(); + gl.glShaderBinary(1, tmp, 0, binaryFormat, buf, shaderData.length); + } + + private boolean glslLog(int obj, int checkCompile, String op) { + boolean success = false; + + GL gl = GLU.getCurrentGL(); + + // log output. + String str = null; + if (checkCompile == GL.GL_COMPILE_STATUS) { + int[] len = new int[1]; + gl.glGetShaderiv(obj, GL.GL_INFO_LOG_LENGTH, len, 0); + if (len[0] > 0) { + byte[] buf = new byte[len[0]]; + gl.glGetShaderInfoLog(obj, len[0], null, 0, buf, 0); + try { + str = new String(buf, 0, buf.length, "US-ASCII"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + } else { + // LINK or VALIDATE + int[] len = new int[1]; + gl.glGetProgramiv(obj, GL.GL_INFO_LOG_LENGTH, len, 0); + if (len[0] > 0) { + byte[] buf = new byte[len[0]]; + gl.glGetProgramInfoLog(obj, len[0], null, 0, buf, 0); + try { + str = new String(buf, 0, buf.length, "US-ASCII"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + } + + if (str != null) { + System.out.println("--- "); + System.out.println(op); + System.out.println(" log ---"); + System.out.println(str); + } + + // check the compile / link status. + if (checkCompile == GL.GL_COMPILE_STATUS) { + int[] status = new int[1]; + + gl.glGetShaderiv(obj, checkCompile, status, 0); + success = (status[0] != 0); + if (!success) { + int[] len = new int[1]; + gl.glGetShaderiv(obj, GL.GL_SHADER_SOURCE_LENGTH, len, 0); + if (len[0] > 0) { + byte[] buf = new byte[len[0]]; + gl.glGetShaderSource(obj, len[0], null, 0, buf, 0); + try { + str = new String(buf, 0, buf.length, "US-ASCII"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + if (str != null) { + System.out.println("--- "); + System.out.println(op); + System.out.println(" code ---"); + System.out.println(str); + } + } + } + } else { // LINK or VALIDATE + int[] status = new int[1]; + gl.glGetProgramiv(obj, checkCompile, status, 0); + success = (status[0] != 0); + } + + if (!success) { + System.out.println("--- "); + System.out.println(op); + System.out.println(" failed"); + } + + return success; + } +} -- cgit v1.2.3