From 9517539e3b43d21017465180376329439bc25f12 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 12 Aug 2008 08:39:08 +0000 Subject: 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: Buffer newBuffer([] 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 --- .../opengl/impl/glsl/fixed/FixedFuncPipeline.java | 487 +++++++++++++++++++++ 1 file changed, 487 insertions(+) create mode 100644 src/classes/com/sun/opengl/impl/glsl/fixed/FixedFuncPipeline.java (limited to 'src/classes/com/sun/opengl/impl/glsl/fixed') diff --git a/src/classes/com/sun/opengl/impl/glsl/fixed/FixedFuncPipeline.java b/src/classes/com/sun/opengl/impl/glsl/fixed/FixedFuncPipeline.java new file mode 100644 index 000000000..f9798f48a --- /dev/null +++ b/src/classes/com/sun/opengl/impl/glsl/fixed/FixedFuncPipeline.java @@ -0,0 +1,487 @@ + +package com.sun.opengl.impl.glsl.fixed; + +import javax.media.opengl.*; +import javax.media.opengl.util.*; +import javax.media.opengl.glsl.*; +import java.nio.*; + +public class FixedFuncPipeline { + public static final int MAX_TEXTURE_UNITS = 8; + public static final int MAX_LIGHTS = 8; + + public FixedFuncPipeline(GL2ES2 gl, PMVMatrix pmvMatrix) { + init(gl, pmvMatrix); + } + + public boolean verbose() { return verbose; } + + public void setVerbose(boolean v) { verbose=v; } + + public boolean isValid() { + return shaderState.linked(); + } + + public ShaderState getShaderState() { + return shaderState; + } + + public void enableLighting(boolean enable) { + lightingEnabled=enable; + } + + public boolean lightingEnabled() { + return lightingEnabled; + } + + public int getActiveTextureUnit() { + return activeTextureUnit; + } + + public String getArrayIndexName(int glArrayIndex) { + String name = GLContext.getPredefinedArrayIndexName(glArrayIndex); + switch(glArrayIndex) { + case GL.GL_VERTEX_ARRAY: + case GL.GL_NORMAL_ARRAY: + case GL.GL_COLOR_ARRAY: + break; + case GL.GL_TEXTURE_COORD_ARRAY: + name = name + activeTextureUnit; + } + return name; + } + + public void release(GL2ES2 gl) { + shaderState.release(gl); + shaderProgramColor.release(gl, true); + shaderProgramColorLight.release(gl, true); + shaderProgramColorTexture.release(gl, true); + shaderProgramColorTextureLight.release(gl, true); + } + + public void glEnableClientState(GL2ES2 gl, int glArrayIndex) { + shaderState.glUseProgram(gl, true); + + shaderState.glEnableVertexAttribArray(gl, getArrayIndexName(glArrayIndex)); + // textureCoordsEnabled |= (1 << activeTextureUnit); + if ( textureCoordsEnabled.get(activeTextureUnit) != 1 ) { + textureCoordsEnabled.put(activeTextureUnit, 1); + textureCoordsEnabledDirty = true; + } + } + + public void glDisableClientState(GL2ES2 gl, int glArrayIndex) { + shaderState.glUseProgram(gl, true); + + shaderState.glDisableVertexAttribArray(gl, getArrayIndexName(glArrayIndex)); + // textureCoordsEnabled &= ~(1 << activeTextureUnit); + if ( textureCoordsEnabled.get(activeTextureUnit) != 0 ) { + textureCoordsEnabled.put(activeTextureUnit, 0); + textureCoordsEnabledDirty = true; + } + } + + public void glVertexPointer(GL2ES2 gl, GLArrayData data) { + shaderState.glUseProgram(gl, true); + shaderState.glVertexAttribPointer(gl, data); + } + + public void glColorPointer(GL2ES2 gl, GLArrayData data) { + shaderState.glUseProgram(gl, true); + shaderState.glVertexAttribPointer(gl, data); + } + + public void glColor4fv(GL2ES2 gl, FloatBuffer data ) { + shaderState.glUseProgram(gl, true); + GLUniformData ud = shaderState.getUniform(mgl_ColorStatic); + if(null!=ud) { + ud.setData(data); + shaderState.glUniform(gl, ud); + } + } + + public void glNormalPointer(GL2ES2 gl, GLArrayData data) { + shaderState.glUseProgram(gl, true); + shaderState.glVertexAttribPointer(gl, data); + } + + public void glTexCoordPointer(GL2ES2 gl, GLArrayData data) { + shaderState.glUseProgram(gl, true); + data.setName( getArrayIndexName(data.getIndex()) ); + shaderState.glVertexAttribPointer(gl, data); + } + + public void glLightfv(GL2ES2 gl, int light, int pname, java.nio.FloatBuffer params) { + shaderState.glUseProgram(gl, true); + light -=GL.GL_LIGHT0; + if(0 <= light && light < MAX_LIGHTS) { + GLUniformData ud = null; + switch(pname) { + case GL.GL_AMBIENT: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].ambient"); + break; + case GL.GL_DIFFUSE: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].diffuse"); + break; + case GL.GL_SPECULAR: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].specular"); + break; + case GL.GL_POSITION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].position"); + break; + case GL.GL_SPOT_DIRECTION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotDirection"); + break; + case GL.GL_SPOT_EXPONENT: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotExponent"); + break; + case GL.GL_SPOT_CUTOFF: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotCutoff"); + break; + case GL.GL_CONSTANT_ATTENUATION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].constantAttenuation"); + break; + case GL.GL_LINEAR_ATTENUATION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].linearAttenuation"); + break; + case GL.GL_QUADRATIC_ATTENUATION: + ud = shaderState.getUniform(mgl_LightSource+"["+light+"].quadraticAttenuation"); + break; + default: + if(verbose) { + System.err.println("glLightfv pname not within [GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_POSITION GL_SPOT_DIRECTION]: "+pname); + } + return; + } + if(null!=ud) { + ud.setData(params); + shaderState.glUniform(gl, ud); + } + } else if(verbose) { + System.err.println("glLightfv light not within [0.."+MAX_LIGHTS+"]: "+light); + } + } + + public void glMaterialfv(GL2ES2 gl, int face, int pname, java.nio.FloatBuffer params) { + shaderState.glUseProgram(gl, true); + + switch (face) { + case GL.GL_FRONT: + case GL.GL_FRONT_AND_BACK: + break; + case GL.GL_BACK: + if(verbose) { + System.err.println("glMaterialfv face GL_BACK currently not supported"); + } + break; + default: + } + + GLUniformData ud = null; + switch(pname) { + case GL.GL_AMBIENT: + ud = shaderState.getUniform(mgl_FrontMaterial+".ambient"); + break; + case GL.GL_AMBIENT_AND_DIFFUSE: + glMaterialfv(gl, face, GL.GL_AMBIENT, params); + // fall through intended .. + case GL.GL_DIFFUSE: + ud = shaderState.getUniform(mgl_FrontMaterial+".diffuse"); + break; + case GL.GL_SPECULAR: + ud = shaderState.getUniform(mgl_FrontMaterial+".specular"); + break; + case GL.GL_EMISSION: + ud = shaderState.getUniform(mgl_FrontMaterial+".emission"); + break; + case GL.GL_SHININESS: + ud = shaderState.getUniform(mgl_FrontMaterial+".shininess"); + break; + default: + if(verbose) { + System.err.println("glMaterialfv pname not within [GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_EMISSION GL_SHININESS]: "+pname); + } + return; + } + if(null!=ud) { + ud.setData(params); + shaderState.glUniform(gl, ud); + } + } + + public void glShadeModel(GL2ES2 gl, int mode) { + shaderState.glUseProgram(gl, true); + GLUniformData ud = shaderState.getUniform(mgl_ShadeModel); + if(null!=ud) { + ud.setData(mode); + shaderState.glUniform(gl, ud); + } + } + + public void glActiveTexture(GL2ES2 gl, int textureUnit) { + textureUnit -= GL.GL_TEXTURE0; + if(0 <= textureUnit && textureUnit