diff options
author | Sven Gothel <[email protected]> | 2008-08-12 08:39:08 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2008-08-12 08:39:08 +0000 |
commit | 9517539e3b43d21017465180376329439bc25f12 (patch) | |
tree | 8e44e0a090301e67bc4e66b53ebd6d14827d48f2 /make/gl-impl-CustomJavaCode-gl2_es2.java | |
parent | 28d62d086afefaf752b38ce5c2c67bc826b5a286 (diff) |
Working:
APX 2500
ES 2.0 + FixedFunction GLSL
ES 1.0
+++
javax.media.opengl.glsl
- Shader and program state management
- Loading and merging shader source code
- Loading binaries incl. auto selection
of the binary file in respect to the supported binary format.
I.e. in case of GLES2.GL_NVIDIA_PLATFORM_BINARY_NV:
source: com/sun/opengl/impl/glsl/fixed/shader/ashader.fp
binary: com/sun/opengl/impl/glsl/fixed/shader/bin/nvidia/ashader.bfp
ShaderCode sc = ShaderCode.create( gl, gl.GL_VERTEX_SHADER, 1, FixedFuncPipeline.class,
"shader", "shader/bin", "ashader");
(Derivation of com.sun.javafx.graphics.gl2es2.ShaderUtil)
javax.media.opengl.sdk.glsl
CompileShaderNVidia implements abstract CompileShader
Toolkit to convert JOGL shader source to binaries,
according to the location rule as described in ShaderCode.
Example: Converts all fixed function shader to binaries.
jogl/src/classes/com/sun/opengl/impl/glsl/fixed/shader/scripts/nvidia-apx/glslc-ff.bat
(Generalization of com.sun.javafx.graphics.gl2es2.PrecompileNVShader)
+++
Fixed function now resides in 'jogl.fixed.jar'
- contains shader source and binaries
- contains the implementation
GL2ES2:
- removed glShaderBinaryOrSource()
- use glCreateLoadShader() for binary and
glCreateCompileShader() for source
- using addition glGetError() check for shader upload/compilation
- Skipping 'glValidateProgram' in case of ES2 and no compiler,
since it fails on APX2500 ..
- added: (caching the results)
"public Set glGetShaderBinaryFormats()"
"public boolean glShaderCompilerAvailable()"
- shader-name and binary-data buffer: use 'remaining()'
instead of 'limit()'
BufferUtil:
- adding variant: <Type>Buffer new<Type>Buffer(<type>[] values, int offset, int len)
+++
Working on all profiles ES1 + ES2 (CVM) with lighting:
demo.es1.cube.Cube
demo.es1.cube.CubeImmModeSink
demo.es1.cubefbo.Main
javabullet.demos.genericjoint.GenericJointDemo
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1749 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'make/gl-impl-CustomJavaCode-gl2_es2.java')
-rw-r--r-- | make/gl-impl-CustomJavaCode-gl2_es2.java | 137 |
1 files changed, 83 insertions, 54 deletions
diff --git a/make/gl-impl-CustomJavaCode-gl2_es2.java b/make/gl-impl-CustomJavaCode-gl2_es2.java index 0a525c4e7..aef836468 100644 --- a/make/gl-impl-CustomJavaCode-gl2_es2.java +++ b/make/gl-impl-CustomJavaCode-gl2_es2.java @@ -76,18 +76,15 @@ } return false; } - if(!glIsProgramStatusValid(programObj, GL_VALIDATE_STATUS)) { - if(null!=verboseOut) { - verboseOut.println("Program status invalid: "+programObj+"\n\t"+ glGetProgramInfoLog(programObj)); - } - return false; - } - glValidateProgram(programObj); - if(!glIsProgramStatusValid(programObj, GL_VALIDATE_STATUS)) { - if(null!=verboseOut) { - verboseOut.println("Program validation failed: "+programObj+"\n\t"+ glGetProgramInfoLog(programObj)); + if ( !isGLES2() || glShaderCompilerAvailable() ) { + // failed on APX2500 (ES2.0, no compiler) for valid programs + glValidateProgram(programObj); + if(!glIsProgramStatusValid(programObj, GL_VALIDATE_STATUS)) { + if(null!=verboseOut) { + verboseOut.println("Program validation failed: "+programObj+"\n\t"+ glGetProgramInfoLog(programObj)); + } + return false; } - return false; } return true; } @@ -100,9 +97,60 @@ shaders.rewind(); } + private Boolean shaderCompilerAvailable = null; + private Set shaderBinaryFormats = null; + + public Set glGetShaderBinaryFormats() + { + if(null==shaderBinaryFormats) { + HashSet formatSet = new HashSet(); + + int[] param = new int[1]; + + glGetIntegerv(GL2ES2.GL_NUM_SHADER_BINARY_FORMATS, param, 0); + int numFormats = param[0]; + if(numFormats>0) { + int[] formats = new int[numFormats]; + glGetIntegerv(GL2ES2.GL_SHADER_BINARY_FORMATS, formats, 0); + shaderBinaryFormats = new HashSet(numFormats); + for(int i=0; i<numFormats; i++) { + shaderBinaryFormats.add(new Integer(formats[i])); + } + } else { + shaderBinaryFormats = new HashSet(0); + } + } + return shaderBinaryFormats; + } + + + public boolean glShaderCompilerAvailable() { + if(null==shaderCompilerAvailable) { + Set bfs = glGetShaderBinaryFormats(); + if(isGLES2()) { + byte[] param = new byte[1]; + glGetBooleanv(GL2ES2.GL_SHADER_COMPILER, param, 0); + boolean v = param[0]!=(byte)0x00; + if(!v && bfs.size()==0) { + // no supported binary formats, hence a compiler must be available! + v = true; + } + shaderCompilerAvailable = new Boolean(v); + } else if( isGL2() || isGL2ES2() ) { + shaderCompilerAvailable = new Boolean(true); + } else { + throw new GLException("invalid profile"); + } + } + return shaderCompilerAvailable.booleanValue(); + } public void glShaderSource(int shader, java.lang.String[] source) { + if(!glShaderCompilerAvailable()) { + throw new GLException("no compiler is available"); + } + int count = (null!=source)?source.length:0; if(count<=0) { throw new GLException("Method \"glShaderSource\" called with invalid length of source: "+count); @@ -118,7 +166,7 @@ public void glShaderSource(IntBuffer shaders, java.lang.String[][] sources) { int sourceNum = (null!=sources)?sources.length:0; - int shaderNum = (null!=shaders)?shaders.limit():0; + int shaderNum = (null!=shaders)?shaders.remaining():0; if(shaderNum<=0 || sourceNum<=0 || shaderNum!=sourceNum) { throw new GLException("Method \"glShaderSource\" called with invalid number of shaders and/or sources: shaders="+ shaderNum+", sources="+sourceNum); @@ -130,47 +178,22 @@ public void glShaderBinary(IntBuffer shaders, int binFormat, java.nio.Buffer bin) { - int shaderNum = shaders.limit(); + if(glGetShaderBinaryFormats().size()<=0) { + throw new GLException("no binary formats are supported"); + } + + int shaderNum = shaders.remaining(); if(shaderNum<=0) { throw new GLException("Method \"glShaderBinary\" called with shaders number <= 0"); } if(null==bin) { throw new GLException("Method \"glShaderBinary\" without binary (null)"); } - int binLength = bin.limit(); + int binLength = bin.remaining(); if(0>=binLength) { - throw new GLException("Method \"glShaderBinary\" without binary (limit == 0)"); - } - try { - glShaderBinary(shaderNum, shaders, binFormat, bin, binLength); - } catch (Exception e) { } - } - - /** - * Wrapper for glShaderBinary and glShaderSource. - * Tries binary first, if not null, then the source code, if not null. - * The binary trial will fail in case no binary interface exist (GL2 profile), - * hence the fallback to the source code. - */ - public void glShaderBinaryOrSource(IntBuffer shaders, - int binFormat, java.nio.Buffer bin, - java.lang.String[][] sources) - { - int shaderNum = shaders.limit(); - if(shaderNum<=0) { - throw new GLException("Method \"glShaderBinaryOrSource\" called with shaders number <= 0"); - } - if(null!=bin) { - try { - glShaderBinary(shaders, binFormat, bin); - return; // done - } catch (Exception e) { } + throw new GLException("Method \"glShaderBinary\" without binary (remaining == 0)"); } - if(null!=sources) { - glShaderSource(shaders, sources); - return; // done - } - throw new GLException("Method \"glShaderBinaryOrSource\" without binary nor source"); + glShaderBinary(shaderNum, shaders, binFormat, bin, binLength); } public void glCompileShader(IntBuffer shaders) @@ -182,27 +205,33 @@ shaders.rewind(); } - public boolean glCreateCompileShader(IntBuffer shader, int shaderType, - int binFormat, java.nio.Buffer bin, - java.lang.String[][] sources) + public boolean glCreateLoadShader(IntBuffer shader, int shaderType, + int binFormat, java.nio.Buffer bin, + PrintStream verboseOut) { - return glCreateCompileShader(shader, shaderType, - binFormat, bin, - sources, null); + glGetError(); // flush previous errors .. + + glCreateShader(shaderType, shader); + + glShaderBinary(shader, binFormat, bin); + + return glGetError() == GL.GL_NO_ERROR; } public boolean glCreateCompileShader(IntBuffer shader, int shaderType, - int binFormat, java.nio.Buffer bin, java.lang.String[][] sources, PrintStream verboseOut) { + glGetError(); // flush previous errors .. + glCreateShader(shaderType, shader); - glShaderBinaryOrSource(shader, binFormat, bin, sources); + glShaderSource(shader, sources); glCompileShader(shader); - return glIsShaderStatusValid(shader, GL_COMPILE_STATUS, verboseOut); + return glIsShaderStatusValid(shader, GL_COMPILE_STATUS, verboseOut) && + glGetError() == GL.GL_NO_ERROR; } public void glAttachShader(int program, IntBuffer shaders) |