aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc')
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/FixedFuncUtil.java81
-rwxr-xr-xsrc/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncHook.java332
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncPipeline.java554
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColor.fp16
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColor.vp22
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorLight.vp70
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorTexture.fp47
-rwxr-xr-xsrc/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bfpbin0 -> 1108 bytes
-rwxr-xr-xsrc/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bvpbin0 -> 2344 bytes
-rwxr-xr-xsrc/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorLight.bvpbin0 -> 8787 bytes
-rwxr-xr-xsrc/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorTexture.bfpbin0 -> 2392 bytes
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/es_precision.glsl14
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_attribute.glsl19
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_const.glsl10
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_lightdef.glsl26
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_settexcoord.vp35
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform.glsl18
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform_light.glsl15
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_varying.glsl12
-rwxr-xr-xsrc/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc-ff.bat9
-rwxr-xr-xsrc/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc.bat9
21 files changed, 1289 insertions, 0 deletions
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/FixedFuncUtil.java b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/FixedFuncUtil.java
new file mode 100644
index 000000000..02d6ec92e
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/FixedFuncUtil.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ */
+
+package com.sun.opengl.util.glsl.fixedfunc;
+
+import javax.media.opengl.*;
+import javax.media.opengl.fixedfunc.*;
+
+import com.sun.opengl.util.glsl.fixedfunc.impl.*;
+
+/**
+ * Tool to pipeline GL2ES2 into a fixed function emulation implementing GL2ES1.
+ */
+public class FixedFuncUtil {
+ /**
+ * @return If gl is a GL2ES1, return the type cast object,
+ * otherwise create a fixed function emulation pipeline with the GL2ES2 impl.
+ * @throws GLException if the GL object is neither GL2ES1 nor GL2ES2
+ */
+ public static final GL2ES1 getFixedFuncImpl(GL gl) {
+ if(gl.isGL2ES1()) {
+ return gl.getGL2ES1();
+ } else if(gl.isGL2ES2()) {
+ GL2ES2 es2 = (GL2ES2)gl;
+ FixedFuncHook hook = new FixedFuncHook(es2);
+ FixedFuncImpl impl = new FixedFuncImpl(es2, hook);
+ gl.getContext().setGL(impl);
+ return impl;
+ }
+ throw new GLException("GL Object is neither GL2ES1 nor GL2ES2");
+ }
+
+ /**
+ * Mapping fixed function (client) array indices to
+ * GLSL array attribute names.
+ *
+ * Useful for uniq mapping of canonical array index names as listed.
+ *
+ * @see #mgl_Vertex
+ * @see javax.media.opengl.fixedfunc.GLPointerFunc#GL_VERTEX_ARRAY
+ * @see #mgl_Normal
+ * @see javax.media.opengl.fixedfunc.GLPointerFunc#GL_NORMAL_ARRAY
+ * @see #mgl_Color
+ * @see javax.media.opengl.fixedfunc.GLPointerFunc#GL_COLOR_ARRAY
+ * @see #mgl_MultiTexCoord
+ * @see javax.media.opengl.fixedfunc.GLPointerFunc#GL_TEXTURE_COORD_ARRAY
+ * @see javax.media.opengl.fixedfunc.GLPointerFunc#glEnableClientState
+ * @see javax.media.opengl.fixedfunc.GLPointerFunc#glVertexPointer
+ * @see javax.media.opengl.fixedfunc.GLPointerFunc#glColorPointer
+ * @see javax.media.opengl.fixedfunc.GLPointerFunc#glNormalPointer
+ * @see javax.media.opengl.fixedfunc.GLPointerFunc#glTexCoordPointer
+ */
+ public static String getPredefinedArrayIndexName(int glArrayIndex) {
+ return FixedFuncPipeline.getPredefinedArrayIndexName(glArrayIndex);
+ }
+
+ /**
+ * String name for
+ * @see javax.media.opengl.GL#GL_VERTEX_ARRAY
+ */
+ public static final String mgl_Vertex = FixedFuncPipeline.mgl_Vertex;
+
+ /**
+ * String name for
+ * @see javax.media.opengl.GL#GL_NORMAL_ARRAY
+ */
+ public static final String mgl_Normal = FixedFuncPipeline.mgl_Normal;
+
+ /**
+ * String name for
+ * @see javax.media.opengl.GL#GL_COLOR_ARRAY
+ */
+ public static final String mgl_Color = FixedFuncPipeline.mgl_Color;
+
+ /**
+ * String name for
+ * @see javax.media.opengl.GL#GL_TEXTURE_COORD_ARRAY
+ */
+ public static final String mgl_MultiTexCoord = FixedFuncPipeline.mgl_MultiTexCoord;
+}
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncHook.java b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncHook.java
new file mode 100755
index 000000000..626f3fdaa
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncHook.java
@@ -0,0 +1,332 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ */
+
+package com.sun.opengl.util.glsl.fixedfunc.impl;
+
+import javax.media.opengl.*;
+import javax.media.opengl.fixedfunc.*;
+import javax.media.opengl.util.*;
+import javax.media.opengl.glu.*;
+import com.sun.gluegen.runtime.BufferFactory;
+import com.sun.opengl.util.*;
+import com.sun.opengl.util.glsl.*;
+import java.nio.*;
+
+public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFunc {
+ public static final int MAX_TEXTURE_UNITS = 8;
+
+ protected FixedFuncPipeline fixedFunction=null;
+ protected PMVMatrix pmvMatrix=null;
+ protected GL2ES2 gl=null;
+
+ public FixedFuncHook (GL2ES2 gl) {
+ this(gl, null);
+ }
+
+ public FixedFuncHook (GL2ES2 gl, PMVMatrix matrix) {
+ this.gl = gl;
+ pmvMatrix = (null!=matrix)?matrix:new PMVMatrix();
+
+ fixedFunction = new FixedFuncPipeline(gl, pmvMatrix);
+ }
+
+ public FixedFuncHook(GL2ES2 gl, PMVMatrix matrix,
+ Class shaderRootClass, String shaderSrcRoot, String shaderBinRoot,
+ String vertexColorFile,
+ String vertexColorLightFile,
+ String fragmentColorFile,
+ String fragmentColorTextureFile) {
+ this.gl = gl;
+ pmvMatrix = matrix;
+
+ fixedFunction = new FixedFuncPipeline(gl, pmvMatrix,
+ shaderRootClass, shaderSrcRoot, shaderBinRoot,
+ vertexColorFile, vertexColorLightFile, fragmentColorFile, fragmentColorTextureFile);
+ }
+
+ public void destroy() {
+ fixedFunction.destroy(gl);
+ fixedFunction = null;
+ }
+
+ public PMVMatrix getMatrix() { return pmvMatrix; }
+
+ //
+ // FixedFuncHookIf - hooks
+ //
+ public void glDrawArrays(int mode, int first, int count) {
+ fixedFunction.validate(gl);
+ gl.glDrawArrays(mode, first, count);
+ }
+ public void glDrawElements(int mode, int count, int type, java.nio.Buffer indices) {
+ fixedFunction.validate(gl);
+ gl.glDrawElements(mode, count, type, indices);
+ }
+ public void glDrawElements(int mode, int count, int type, long indices_buffer_offset) {
+ fixedFunction.validate(gl);
+ gl.glDrawElements(mode, count, type, indices_buffer_offset);
+ }
+
+ public void glActiveTexture(int texture) {
+ fixedFunction.glActiveTexture(gl, texture);
+ gl.glActiveTexture(texture);
+ }
+ public void glEnable(int cap) {
+ if(fixedFunction.glEnable(gl, cap, true)) {
+ gl.glEnable(cap);
+ }
+ }
+ public void glDisable(int cap) {
+ if(fixedFunction.glEnable(gl, cap, false)) {
+ gl.glDisable(cap);
+ }
+ }
+ public void glCullFace(int faceName) {
+ fixedFunction.glCullFace(gl, faceName);
+ gl.glCullFace(faceName);
+ }
+
+ public void glGetFloatv(int pname, java.nio.FloatBuffer params) {
+ if(pmvMatrix.isMatrixGetName(pname)) {
+ pmvMatrix.glGetFloatv(pname, params);
+ return;
+ }
+ gl.glGetFloatv(pname, params);
+ }
+ public void glGetFloatv(int pname, float[] params, int params_offset) {
+ if(pmvMatrix.isMatrixGetName(pname)) {
+ pmvMatrix.glGetFloatv(pname, params, params_offset);
+ return;
+ }
+ gl.glGetFloatv(pname, params, params_offset);
+ }
+ public void glGetIntegerv(int pname, IntBuffer params) {
+ if(pmvMatrix.isMatrixGetName(pname)) {
+ pmvMatrix.glGetIntegerv(pname, params);
+ return;
+ }
+ gl.glGetIntegerv(pname, params);
+ }
+ public void glGetIntegerv(int pname, int[] params, int params_offset) {
+ if(pmvMatrix.isMatrixGetName(pname)) {
+ pmvMatrix.glGetIntegerv(pname, params, params_offset);
+ return;
+ }
+ gl.glGetIntegerv(pname, params, params_offset);
+ }
+
+ //
+ // MatrixIf
+ //
+ public int glGetMatrixMode() {
+ return pmvMatrix.glGetMatrixMode();
+ }
+ public void glMatrixMode(int mode) {
+ pmvMatrix.glMatrixMode(mode);
+ }
+ public void glLoadMatrixf(java.nio.FloatBuffer m) {
+ pmvMatrix.glLoadMatrixf(m);
+ }
+ public void glLoadMatrixf(float[] m, int m_offset) {
+ glLoadMatrixf(BufferUtil.newFloatBuffer(m, m_offset));
+ }
+ public void glPopMatrix() {
+ pmvMatrix.glPopMatrix();
+ }
+ public void glPushMatrix() {
+ pmvMatrix.glPushMatrix();
+ }
+ public void glLoadIdentity() {
+ pmvMatrix.glLoadIdentity();
+ }
+ public void glMultMatrixf(java.nio.FloatBuffer m) {
+ pmvMatrix.glMultMatrixf(m);
+ }
+ public void glMultMatrixf(float[] m, int m_offset) {
+ glMultMatrixf(BufferUtil.newFloatBuffer(m, m_offset));
+ }
+ public void glTranslatef(float x, float y, float z) {
+ pmvMatrix.glTranslatef(x, y, z);
+ }
+ public void glRotatef(float angdeg, float x, float y, float z) {
+ pmvMatrix.glRotatef(angdeg, x, y, z);
+ }
+ public void glScalef(float x, float y, float z) {
+ pmvMatrix.glScalef(x, y, z);
+ }
+ public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) {
+ pmvMatrix.glOrthof(left, right, bottom, top, zNear, zFar);
+ }
+ public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) {
+ pmvMatrix.glFrustumf(left, right, bottom, top, zNear, zFar);
+ }
+
+ //
+ // LightingIf
+ //
+ public void glColor4f(float red, float green, float blue, float alpha) {
+ fixedFunction.glColor4fv(gl, BufferUtil.newFloatBuffer(new float[] { red, green, blue, alpha }));
+ }
+
+ public void glLightfv(int light, int pname, java.nio.FloatBuffer params) {
+ fixedFunction.glLightfv(gl, light, pname, params);
+ }
+ public void glLightfv(int light, int pname, float[] params, int params_offset) {
+ glLightfv(light, pname, BufferUtil.newFloatBuffer(params, params_offset));
+ }
+ public void glMaterialfv(int face, int pname, java.nio.FloatBuffer params) {
+ fixedFunction.glMaterialfv(gl, face, pname, params);
+ }
+ public void glMaterialfv(int face, int pname, float[] params, int params_offset) {
+ glMaterialfv(face, pname, BufferUtil.newFloatBuffer(params, params_offset));
+ }
+ public void glMaterialf(int face, int pname, float param) {
+ glMaterialfv(face, pname, BufferUtil.newFloatBuffer(new float[] { param }));
+ }
+ public void glShadeModel(int mode) {
+ fixedFunction.glShadeModel(gl, mode);
+ }
+
+ //
+ // PointerIf
+ //
+ public void glEnableClientState(int glArrayIndex) {
+ fixedFunction.glEnableClientState(gl, glArrayIndex);
+ }
+ public void glDisableClientState(int glArrayIndex) {
+ fixedFunction.glDisableClientState(gl, glArrayIndex);
+ }
+
+ public void glVertexPointer(GLArrayData array) {
+ if(array.isVBO()) {
+ if(!gl.glIsVBOArrayEnabled()) {
+ throw new GLException("VBO array is not enabled: "+array);
+ }
+ } else {
+ if(gl.glIsVBOArrayEnabled()) {
+ throw new GLException("VBO array is not disabled: "+array);
+ }
+ BufferFactory.rangeCheck(array.getBuffer(), 1);
+ if (!BufferFactory.isDirect(array.getBuffer())) {
+ throw new GLException("Argument \"pointer\" was not a direct buffer"); }
+ }
+ fixedFunction.glVertexPointer(gl, array);
+ }
+
+ public void glVertexPointer(int size, int type, int stride, java.nio.Buffer pointer) {
+ glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, false, stride, pointer, 0, 0));
+ }
+ public void glVertexPointer(int size, int type, int stride, long pointer_buffer_offset) {
+ int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
+ if(vboName==0) {
+ throw new GLException("no GL_ARRAY_BUFFER VBO bound");
+ }
+ glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, false,
+ stride, null, vboName, pointer_buffer_offset));
+ }
+
+ public void glColorPointer(GLArrayData array) {
+ if(array.isVBO()) {
+ if(!gl.glIsVBOArrayEnabled()) {
+ throw new GLException("VBO array is not enabled: "+array);
+ }
+ } else {
+ if(gl.glIsVBOArrayEnabled()) {
+ throw new GLException("VBO array is not disabled: "+array);
+ }
+ BufferFactory.rangeCheck(array.getBuffer(), 1);
+ if (!BufferFactory.isDirect(array.getBuffer())) {
+ throw new GLException("Argument \"pointer\" was not a direct buffer"); }
+ }
+ fixedFunction.glColorPointer(gl, array);
+ }
+ public void glColorPointer(int size, int type, int stride, java.nio.Buffer pointer) {
+ glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, false,
+ stride, pointer, 0, 0));
+ }
+ public void glColorPointer(int size, int type, int stride, long pointer_buffer_offset) {
+ int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
+ if(vboName==0) {
+ throw new GLException("no GL_ARRAY_BUFFER VBO bound");
+ }
+ glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, false,
+ stride, null, vboName, pointer_buffer_offset));
+ }
+
+ public void glNormalPointer(GLArrayData array) {
+ if(array.getComponentNumber()!=3) {
+ throw new GLException("Only 3 components per normal allowed");
+ }
+ if(array.isVBO()) {
+ if(!gl.glIsVBOArrayEnabled()) {
+ throw new GLException("VBO array is not enabled: "+array);
+ }
+ } else {
+ if(gl.glIsVBOArrayEnabled()) {
+ throw new GLException("VBO array is not disabled: "+array);
+ }
+ BufferFactory.rangeCheck(array.getBuffer(), 1);
+ if (!BufferFactory.isDirect(array.getBuffer())) {
+ throw new GLException("Argument \"pointer\" was not a direct buffer"); }
+ }
+ fixedFunction.glNormalPointer(gl, array);
+ }
+ public void glNormalPointer(int type, int stride, java.nio.Buffer pointer) {
+ glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, false,
+ stride, pointer, 0, 0));
+ }
+ public void glNormalPointer(int type, int stride, long pointer_buffer_offset) {
+ int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
+ if(vboName==0) {
+ throw new GLException("no GL_ARRAY_BUFFER VBO bound");
+ }
+ glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, false,
+ stride, null, vboName, pointer_buffer_offset));
+ }
+
+ public void glTexCoordPointer(GLArrayData array) {
+ if(array.isVBO()) {
+ if(!gl.glIsVBOArrayEnabled()) {
+ throw new GLException("VBO array is not enabled: "+array);
+ }
+ } else {
+ if(gl.glIsVBOArrayEnabled()) {
+ throw new GLException("VBO array is not disabled: "+array);
+ }
+ BufferFactory.rangeCheck(array.getBuffer(), 1);
+ if (!BufferFactory.isDirect(array.getBuffer())) {
+ throw new GLException("Argument \"pointer\" was not a direct buffer"); }
+ }
+ fixedFunction.glTexCoordPointer(gl, array);
+ }
+ public void glTexCoordPointer(int size, int type, int stride, java.nio.Buffer pointer) {
+ glTexCoordPointer(
+ GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, false, stride, pointer, 0,0));
+ }
+ public void glTexCoordPointer(int size, int type, int stride, long pointer_buffer_offset) {
+ int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
+ if(vboName==0) {
+ throw new GLException("no GL_ARRAY_BUFFER VBO bound");
+ }
+ glTexCoordPointer(
+ GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, false,
+ stride, null, vboName, pointer_buffer_offset) );
+ }
+
+ public final String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append(getClass().getName()+" (");
+ if(null!=pmvMatrix) {
+ buf.append(", matrixDirty: "+pmvMatrix.isDirty());
+ }
+ buf.append("\n\t, FixedFunction: "+fixedFunction);
+ buf.append(gl);
+ buf.append(" )");
+
+ return buf.toString();
+ }
+
+}
+
+
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncPipeline.java b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncPipeline.java
new file mode 100644
index 000000000..1b8dd1f11
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/FixedFuncPipeline.java
@@ -0,0 +1,554 @@
+
+package com.sun.opengl.util.glsl.fixedfunc.impl;
+
+import javax.media.opengl.*;
+import javax.media.opengl.fixedfunc.*;
+import com.sun.opengl.util.*;
+import com.sun.opengl.util.glsl.*;
+import com.sun.opengl.util.glsl.fixedfunc.*;
+import java.nio.*;
+
+public class FixedFuncPipeline {
+ public static final int MAX_TEXTURE_UNITS = 8;
+ public static final int MAX_LIGHTS = 8;
+
+ // We can't have any dependencies on the FixedFuncUtil class for build bootstrapping reasons
+ public static final String mgl_Vertex = "mgl_Vertex";
+ public static final String mgl_Normal = "mgl_Normal";
+ public static final String mgl_Color = "mgl_Color";
+ public static final String mgl_MultiTexCoord = "mgl_MultiTexCoord" ;
+
+ public static String getPredefinedArrayIndexName(int glArrayIndex) {
+ switch(glArrayIndex) {
+ case GLPointerFunc.GL_VERTEX_ARRAY:
+ return mgl_Vertex;
+ case GLPointerFunc.GL_NORMAL_ARRAY:
+ return mgl_Normal;
+ case GLPointerFunc.GL_COLOR_ARRAY:
+ return mgl_Color;
+ case GLPointerFunc.GL_TEXTURE_COORD_ARRAY:
+ return mgl_MultiTexCoord;
+ }
+ return null;
+ }
+
+ public FixedFuncPipeline(GL2ES2 gl, PMVMatrix pmvMatrix) {
+ init(gl, pmvMatrix, FixedFuncPipeline.class, shaderSrcRootDef, shaderBinRootDef,
+ vertexColorFileDef, vertexColorLightFileDef, fragmentColorFileDef, fragmentColorTextureFileDef);
+ }
+ public FixedFuncPipeline(GL2ES2 gl, PMVMatrix pmvMatrix, Class shaderRootClass, String shaderSrcRoot, String shaderBinRoot,
+ String vertexColorFile,
+ String vertexColorLightFile,
+ String fragmentColorFile,
+ String fragmentColorTextureFile) {
+ init(gl, pmvMatrix, shaderRootClass, shaderSrcRoot, shaderBinRoot,
+ vertexColorFile, vertexColorLightFile, fragmentColorFile, fragmentColorTextureFile);
+ }
+
+ public boolean verbose() { return verbose; }
+
+ public void setVerbose(boolean v) { verbose=v; }
+
+ public boolean isValid() {
+ return shaderState.linked();
+ }
+
+ public ShaderState getShaderState() {
+ return shaderState;
+ }
+
+ public int getActiveTextureUnit() {
+ return activeTextureUnit;
+ }
+
+ public String getArrayIndexName(int glArrayIndex) {
+ String name = getPredefinedArrayIndexName(glArrayIndex);
+ switch(glArrayIndex) {
+ case GLPointerFunc.GL_VERTEX_ARRAY:
+ case GLPointerFunc.GL_NORMAL_ARRAY:
+ case GLPointerFunc.GL_COLOR_ARRAY:
+ break;
+ case GLPointerFunc.GL_TEXTURE_COORD_ARRAY:
+ name = name + activeTextureUnit;
+ }
+ return name;
+ }
+
+ public void destroy(GL2ES2 gl) {
+ shaderProgramColor.release(gl, true);
+ shaderProgramColorLight.release(gl, true);
+ shaderProgramColorTexture.release(gl, true);
+ shaderProgramColorTextureLight.release(gl, true);
+ shaderState.destroy(gl);
+ }
+
+ 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 -=GLLightingFunc.GL_LIGHT0;
+ if(0 <= light && light < MAX_LIGHTS) {
+ GLUniformData ud = null;
+ switch(pname) {
+ case GLLightingFunc.GL_AMBIENT:
+ ud = shaderState.getUniform(mgl_LightSource+"["+light+"].ambient");
+ break;
+ case GLLightingFunc.GL_DIFFUSE:
+ ud = shaderState.getUniform(mgl_LightSource+"["+light+"].diffuse");
+ break;
+ case GLLightingFunc.GL_SPECULAR:
+ ud = shaderState.getUniform(mgl_LightSource+"["+light+"].specular");
+ break;
+ case GLLightingFunc.GL_POSITION:
+ ud = shaderState.getUniform(mgl_LightSource+"["+light+"].position");
+ break;
+ case GLLightingFunc.GL_SPOT_DIRECTION:
+ ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotDirection");
+ break;
+ case GLLightingFunc.GL_SPOT_EXPONENT:
+ ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotExponent");
+ break;
+ case GLLightingFunc.GL_SPOT_CUTOFF:
+ ud = shaderState.getUniform(mgl_LightSource+"["+light+"].spotCutoff");
+ break;
+ case GLLightingFunc.GL_CONSTANT_ATTENUATION:
+ ud = shaderState.getUniform(mgl_LightSource+"["+light+"].constantAttenuation");
+ break;
+ case GLLightingFunc.GL_LINEAR_ATTENUATION:
+ ud = shaderState.getUniform(mgl_LightSource+"["+light+"].linearAttenuation");
+ break;
+ case GLLightingFunc.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 GLLightingFunc.GL_AMBIENT:
+ ud = shaderState.getUniform(mgl_FrontMaterial+".ambient");
+ break;
+ case GLLightingFunc.GL_AMBIENT_AND_DIFFUSE:
+ glMaterialfv(gl, face, GLLightingFunc.GL_AMBIENT, params);
+ // fall through intended ..
+ case GLLightingFunc.GL_DIFFUSE:
+ ud = shaderState.getUniform(mgl_FrontMaterial+".diffuse");
+ break;
+ case GLLightingFunc.GL_SPECULAR:
+ ud = shaderState.getUniform(mgl_FrontMaterial+".specular");
+ break;
+ case GLLightingFunc.GL_EMISSION:
+ ud = shaderState.getUniform(mgl_FrontMaterial+".emission");
+ break;
+ case GLLightingFunc.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<MAX_TEXTURE_UNITS) {
+ shaderState.glUseProgram(gl, true);
+ GLUniformData ud;
+ ud = shaderState.getUniform(mgl_ActiveTexture);
+ if(null!=ud) {
+ ud.setData(textureUnit);
+ shaderState.glUniform(gl, ud);
+ }
+ ud = shaderState.getUniform(mgl_ActiveTextureIdx);
+ if(null!=ud) {
+ ud.setData(textureUnit);
+ shaderState.glUniform(gl, ud);
+ }
+ activeTextureUnit = textureUnit;
+ } else {
+ throw new GLException("glActivateTexture textureUnit not within GL_TEXTURE0 + [0.."+MAX_TEXTURE_UNITS+"]: "+textureUnit);
+ }
+ }
+
+ /**
+ * @return false if digested in regard to GL2ES2 spec,
+ * eg this call must not be passed to an underlying ES2 implementation.
+ * true if this call shall be passed to an underlying GL2ES2/ES2 implementation as well.
+ */
+ public boolean glEnable(GL2ES2 gl, int cap, boolean enable) {
+ switch(cap) {
+ case GL.GL_TEXTURE_2D:
+ textureEnabled=enable;
+ return true;
+ case GLLightingFunc.GL_LIGHTING:
+ lightingEnabled=enable;
+ return false;
+ case GL.GL_CULL_FACE:
+ cullFace=Math.abs(cullFace);
+ if(!enable) {
+ cullFace*=-1;
+ }
+ return true;
+ }
+
+ int light = cap - GLLightingFunc.GL_LIGHT0;
+ if(0 <= light && light < MAX_LIGHTS) {
+ if ( (lightsEnabled.get(light)==1) != enable ) {
+ lightsEnabled.put(light, enable?1:0);
+ lightsEnabledDirty = true;
+ return false;
+ }
+ }
+ return true; // pass it on ..
+ }
+
+ public void glCullFace(GL2ES2 gl, int faceName) {
+ switch(faceName) {
+ case GL.GL_FRONT:
+ faceName = 1; break;
+ case GL.GL_BACK:
+ faceName = 2; break;
+ case GL.GL_FRONT_AND_BACK:
+ faceName = 3; break;
+ }
+ if(0>cullFace) {
+ faceName *= -1;
+ }
+ cullFace = faceName;
+ }
+
+ public void validate(GL2ES2 gl) {
+ shaderState.glUseProgram(gl, true);
+ GLUniformData ud;
+ if(pmvMatrix.update()) {
+ ud = shaderState.getUniform(mgl_PMVMatrix);
+ if(null!=ud) {
+ // same data object ..
+ shaderState.glUniform(gl, ud);
+ } else {
+ throw new GLException("Failed to update: mgl_PMVMatrix");
+ }
+ ud = shaderState.getUniform(mgl_NormalMatrix);
+ if(null!=ud) {
+ // same data object ..
+ shaderState.glUniform(gl, ud);
+ }
+ }
+ ud = shaderState.getUniform(mgl_ColorEnabled);
+ if(null!=ud) {
+ int ca = (shaderState.isVertexAttribArrayEnabled(mgl_Color)==true)?1:0;
+ if(ca!=ud.intValue()) {
+ ud.setData(ca);
+ shaderState.glUniform(gl, ud);
+ }
+ }
+ ud = shaderState.getUniform(mgl_CullFace);
+ if(null!=ud) {
+ if(cullFace!=ud.intValue()) {
+ ud.setData(cullFace);
+ shaderState.glUniform(gl, ud);
+ }
+ }
+
+ if(lightsEnabledDirty) {
+ ud = shaderState.getUniform(mgl_LightsEnabled);
+ if(null!=ud) {
+ // same data object
+ shaderState.glUniform(gl, ud);
+ }
+ lightsEnabledDirty=false;
+ }
+
+ if(textureCoordsEnabledDirty) {
+ ud = shaderState.getUniform(mgl_TexCoordEnabled);
+ if(null!=ud) {
+ // same data object
+ shaderState.glUniform(gl, ud);
+ }
+ textureCoordsEnabledDirty=false;
+ }
+
+ if(textureEnabled) {
+ if(lightingEnabled) {
+ shaderState.attachShaderProgram(gl, shaderProgramColorTextureLight);
+ } else {
+ shaderState.attachShaderProgram(gl, shaderProgramColorTexture);
+ }
+ } else {
+ if(lightingEnabled) {
+ shaderState.attachShaderProgram(gl, shaderProgramColorLight);
+ } else {
+ shaderState.attachShaderProgram(gl, shaderProgramColor);
+ }
+ }
+ if(DEBUG) {
+ System.err.println("validate: "+this);
+ }
+ }
+
+ public String toString() {
+ return "FixedFuncPipeline[pmv: "+pmvMatrix+
+ ", textureEnabled: "+textureEnabled+
+ ", textureCoordsEnabled: "+textureCoordsEnabled+
+ ", lightingEnabled: "+lightingEnabled+
+ ", lightsEnabled: "+lightsEnabled+
+ "\n\t, shaderProgramColor: "+shaderProgramColor+
+ "\n\t, shaderProgramColorTexture: "+shaderProgramColorTexture+
+ "\n\t, shaderProgramColorLight: "+shaderProgramColorLight+
+ "\n\t, shaderProgramColorTextureLight: "+shaderProgramColorTextureLight+
+ "\n\t, ShaderState: "+shaderState+
+ "]";
+ }
+
+ protected void init(GL2ES2 gl, PMVMatrix pmvMatrix, Class shaderRootClass, String shaderSrcRoot, String shaderBinRoot,
+ String vertexColorFile,
+ String vertexColorLightFile,
+ String fragmentColorFile,
+ String fragmentColorTextureFile)
+ {
+ if(null==pmvMatrix) {
+ throw new GLException("PMVMatrix is null");
+ }
+ this.pmvMatrix=pmvMatrix;
+ this.shaderState=new ShaderState();
+ this.shaderState.setVerbose(verbose);
+ ShaderCode vertexColor, vertexColorLight, fragmentColor, fragmentColorTexture;
+
+ vertexColor = ShaderCode.create( gl, gl.GL_VERTEX_SHADER, 1, shaderRootClass,
+ shaderSrcRoot, shaderBinRoot, vertexColorFile);
+
+ vertexColorLight = ShaderCode.create( gl, gl.GL_VERTEX_SHADER, 1, shaderRootClass,
+ shaderSrcRoot, shaderBinRoot, vertexColorLightFile);
+
+ fragmentColor = ShaderCode.create( gl, gl.GL_FRAGMENT_SHADER, 1, shaderRootClass,
+ shaderSrcRoot, shaderBinRoot, fragmentColorFile);
+
+ fragmentColorTexture = ShaderCode.create( gl, gl.GL_FRAGMENT_SHADER, 1, shaderRootClass,
+ shaderSrcRoot, shaderBinRoot, fragmentColorTextureFile);
+
+ shaderProgramColor = new ShaderProgram();
+ shaderProgramColor.add(vertexColor);
+ shaderProgramColor.add(fragmentColor);
+ if(!shaderProgramColor.link(gl, System.err)) {
+ throw new GLException("Couldn't link VertexColor program: "+shaderProgramColor);
+ }
+
+ shaderProgramColorTexture = new ShaderProgram();
+ shaderProgramColorTexture.add(vertexColor);
+ shaderProgramColorTexture.add(fragmentColorTexture);
+ if(!shaderProgramColorTexture.link(gl, System.err)) {
+ throw new GLException("Couldn't link VertexColorTexture program: "+shaderProgramColorTexture);
+ }
+
+ shaderProgramColorLight = new ShaderProgram();
+ shaderProgramColorLight.add(vertexColorLight);
+ shaderProgramColorLight.add(fragmentColor);
+ if(!shaderProgramColorLight.link(gl, System.err)) {
+ throw new GLException("Couldn't link VertexColorLight program: "+shaderProgramColorLight);
+ }
+
+ shaderProgramColorTextureLight = new ShaderProgram();
+ shaderProgramColorTextureLight.add(vertexColorLight);
+ shaderProgramColorTextureLight.add(fragmentColorTexture);
+ if(!shaderProgramColorTextureLight.link(gl, System.err)) {
+ throw new GLException("Couldn't link VertexColorLight program: "+shaderProgramColorTextureLight);
+ }
+
+ shaderState.attachShaderProgram(gl, shaderProgramColor);
+ shaderState.glUseProgram(gl, true);
+
+ // mandatory ..
+ if(!shaderState.glUniform(gl, new GLUniformData(mgl_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMviMatrixf()))) {
+ throw new GLException("Error setting PMVMatrix in shader: "+this);
+ }
+
+ // optional parameter ..
+ shaderState.glUniform(gl, new GLUniformData(mgl_NormalMatrix, 3, 3, pmvMatrix.glGetNormalMatrixf()));
+
+ shaderState.glUniform(gl, new GLUniformData(mgl_ColorEnabled, 0));
+ shaderState.glUniform(gl, new GLUniformData(mgl_ColorStatic, 4, zero4f));
+ shaderState.glUniform(gl, new GLUniformData(mgl_TexCoordEnabled, 1, textureCoordsEnabled));
+ shaderState.glUniform(gl, new GLUniformData(mgl_ActiveTexture, activeTextureUnit));
+ shaderState.glUniform(gl, new GLUniformData(mgl_ActiveTextureIdx, activeTextureUnit));
+ shaderState.glUniform(gl, new GLUniformData(mgl_ShadeModel, 0));
+ shaderState.glUniform(gl, new GLUniformData(mgl_CullFace, cullFace));
+ for(int i=0; i<MAX_LIGHTS; i++) {
+ shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].ambient", 4, defAmbient));
+ shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].diffuse", 4, defDiffuse));
+ shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].specular", 4, defSpecular));
+ shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].position", 4, defPosition));
+ shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotDirection", 3, defSpotDir));
+ shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotExponent", defSpotExponent));
+ shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotCutoff", defSpotCutoff));
+ shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].constantAttenuation", defConstantAtten));
+ shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].linearAttenuation", defLinearAtten));
+ shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].quadraticAttenuation", defQuadraticAtten));
+ }
+ shaderState.glUniform(gl, new GLUniformData(mgl_LightsEnabled, 1, lightsEnabled));
+ shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".ambient", 4, defMatAmbient));
+ shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".diffuse", 4, defMatDiffuse));
+ shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".specular", 4, defMatSpecular));
+ shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".emission", 4, defMatEmission));
+ shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".shininess", defMatShininess));
+
+ shaderState.glUseProgram(gl, false);
+ }
+
+ protected static final boolean DEBUG=false;
+ protected boolean verbose=false;
+
+ protected boolean textureEnabled=false;
+ protected IntBuffer textureCoordsEnabled = BufferUtil.newIntBuffer(new int[] { 0, 0, 0, 0, 0, 0, 0, 0 });
+ protected boolean textureCoordsEnabledDirty = false;
+ protected int activeTextureUnit=0;
+
+ protected int cullFace=-2; // <=0 disabled, 1: front, 2: back (default, but disabled), 3: front & back
+
+ protected boolean lightingEnabled=false;
+ protected IntBuffer lightsEnabled = BufferUtil.newIntBuffer(new int[] { 0, 0, 0, 0, 0, 0, 0, 0 });
+ protected boolean lightsEnabledDirty = false;
+
+ protected PMVMatrix pmvMatrix;
+ protected ShaderState shaderState;
+ protected ShaderProgram shaderProgramColor;
+ protected ShaderProgram shaderProgramColorTexture;
+ protected ShaderProgram shaderProgramColorLight;
+ protected ShaderProgram shaderProgramColorTextureLight;
+
+ // uniforms ..
+ protected static final String mgl_PMVMatrix = "mgl_PMVMatrix"; // m4fv[3]
+ protected static final String mgl_NormalMatrix = "mgl_NormalMatrix"; // m4fv
+ protected static final String mgl_ColorEnabled = "mgl_ColorEnabled"; // 1i
+ protected static final String mgl_ColorStatic = "mgl_ColorStatic"; // 4fv
+
+ protected static final String mgl_LightSource = "mgl_LightSource"; // struct mgl_LightSourceParameters[MAX_LIGHTS]
+ protected static final String mgl_FrontMaterial = "mgl_FrontMaterial"; // struct mgl_MaterialParameters
+ protected static final String mgl_LightsEnabled = "mgl_LightsEnabled"; // int mgl_LightsEnabled[MAX_LIGHTS];
+
+ protected static final String mgl_ShadeModel = "mgl_ShadeModel"; // 1i
+
+ protected static final String mgl_TexCoordEnabled = "mgl_TexCoordEnabled"; // int mgl_TexCoordEnabled[MAX_TEXTURE_UNITS];
+ protected static final String mgl_ActiveTexture = "mgl_ActiveTexture"; // 1i
+ protected static final String mgl_ActiveTextureIdx = "mgl_ActiveTextureIdx";// 1i
+
+ protected static final String mgl_CullFace = "mgl_CullFace"; // 1i
+
+ protected static final FloatBuffer zero4f = BufferUtil.newFloatBuffer(new float[] { 0.0f, 0.0f, 0.0f, 0.0f });
+
+ public static final FloatBuffer defAmbient = BufferUtil.newFloatBuffer(new float[] { 0f, 0f, 0f, 1f });
+ public static final FloatBuffer defDiffuse = zero4f;
+ public static final FloatBuffer defSpecular= zero4f;
+ public static final FloatBuffer defPosition= BufferUtil.newFloatBuffer(new float[] { 0f, 0f, 1f, 0f });
+ public static final FloatBuffer defSpotDir = BufferUtil.newFloatBuffer(new float[] { 0f, 0f, -1f });
+ public static final float defSpotExponent = 0f;
+ public static final float defSpotCutoff = 180f;
+ public static final float defConstantAtten = 1f;
+ public static final float defLinearAtten = 0f;
+ public static final float defQuadraticAtten= 0f;
+
+ public static final FloatBuffer defMatAmbient = BufferUtil.newFloatBuffer(new float[] { 0.2f, 0.2f, 0.2f, 1.0f });
+ public static final FloatBuffer defMatDiffuse = BufferUtil.newFloatBuffer(new float[] { 0.8f, 0.8f, 0.8f, 1.0f });
+ public static final FloatBuffer defMatSpecular= BufferUtil.newFloatBuffer(new float[] { 0f, 0f, 0f, 1f});
+ public static final FloatBuffer defMatEmission= BufferUtil.newFloatBuffer(new float[] { 0f, 0f, 0f, 1f});
+ public static final float defMatShininess = 0f;
+
+ protected static final String vertexColorFileDef = "FixedFuncColor";
+ protected static final String vertexColorLightFileDef = "FixedFuncColorLight";
+ protected static final String fragmentColorFileDef = "FixedFuncColor";
+ protected static final String fragmentColorTextureFileDef = "FixedFuncColorTexture";
+ protected static final String shaderSrcRootDef = "shaders" ;
+ protected static final String shaderBinRootDef = "shaders/bin" ;
+}
+
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColor.fp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColor.fp
new file mode 100644
index 000000000..408ff7251
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColor.fp
@@ -0,0 +1,16 @@
+#include es_precision.glsl
+
+#include mgl_uniform.glsl
+#include mgl_varying.glsl
+
+void main (void)
+{
+ if( mgl_CullFace > 0 &&
+ ( ( mgl_CullFace == 1 && gl_FrontFacing ) ||
+ ( mgl_CullFace == 2 && !gl_FrontFacing ) ||
+ ( mgl_CullFace == 3 ) ) ) {
+ discard;
+ }
+ gl_FragColor = frontColor;
+}
+
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColor.vp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColor.vp
new file mode 100644
index 000000000..346e40196
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColor.vp
@@ -0,0 +1,22 @@
+#include es_precision.glsl
+
+#include mgl_const.glsl
+#include mgl_uniform.glsl
+#include mgl_attribute.glsl
+#include mgl_varying.glsl
+
+#include mgl_settexcoord.vp
+
+void main(void)
+{
+ if(mgl_ColorEnabled>0) {
+ frontColor=mgl_Color;
+ } else {
+ frontColor=mgl_ColorStatic;
+ }
+
+ gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;
+
+ setTexCoord(gl_Position);
+}
+
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorLight.vp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorLight.vp
new file mode 100644
index 000000000..ce203cfb9
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorLight.vp
@@ -0,0 +1,70 @@
+#include es_precision.glsl
+#include mgl_lightdef.glsl
+
+#include mgl_const.glsl
+#include mgl_uniform.glsl
+#include mgl_uniform_light.glsl
+#include mgl_attribute.glsl
+#include mgl_varying.glsl
+
+#include mgl_settexcoord.vp
+
+void main(void)
+{
+ vec4 position;
+ vec3 normal, lightDir, cameraDir, halfDir;
+ vec4 ambient, diffuse, specular;
+ float NdotL, NdotHV, dist, attenuation;
+ int i;
+
+ position = mgl_PMVMatrix[1] * mgl_Vertex; // vertex eye position
+
+ normal = normalize(mgl_NormalMatrix * mgl_Normal);
+ // cameraPosition: (mgl_PMVMatrix[2] * vec4(0,0,0,1.0)).xyz
+ cameraDir = normalize( (mgl_PMVMatrix[2] * vec4(0,0,0,1.0)).xyz - mgl_Vertex.xyz );
+
+ ambient = vec4(0,0,0,0);
+ diffuse = vec4(0,0,0,0);
+ specular = vec4(0,0,0,0);
+
+ bool lightEnabled = false;
+
+ for(i=0; i<MAX_LIGHTS; i++) {
+ if( 0!= mgl_LightsEnabled[i] ) {
+ lightEnabled = true;
+ ambient += mgl_LightSource[i].ambient;
+ lightDir = mgl_LightSource[i].position.xyz - position.xyz;
+ dist = length(lightDir);
+ lightDir = normalize(lightDir);
+ attenuation = 1.0 / (
+ mgl_LightSource[i].constantAttenuation+
+ mgl_LightSource[i].linearAttenuation * dist +
+ mgl_LightSource[i].quadraticAttenuation * dist * dist );
+ NdotL = max(0.0, dot(normal, lightDir));
+ diffuse += mgl_LightSource[i].diffuse * NdotL * attenuation;
+ if (NdotL != 0.0) {
+ halfDir = normalize (lightDir + cameraDir);
+ NdotHV = max(0.0, dot(normal, halfDir));
+ specular += mgl_LightSource[i].specular *
+ pow(NdotHV,mgl_FrontMaterial.shininess) * attenuation;
+ }
+ }
+ }
+ ambient += mgl_FrontMaterial.ambient;
+ diffuse *= mgl_FrontMaterial.diffuse;
+ specular *= mgl_FrontMaterial.specular;
+
+ if(mgl_ColorEnabled>0) {
+ frontColor=mgl_Color;
+ } else {
+ frontColor=mgl_ColorStatic;
+ }
+ if( lightEnabled ) {
+ frontColor *= ambient + diffuse + specular;
+ }
+
+ gl_Position = mgl_PMVMatrix[0] * position;
+
+ setTexCoord(gl_Position);
+}
+
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorTexture.fp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorTexture.fp
new file mode 100644
index 000000000..86e6ace73
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/FixedFuncColorTexture.fp
@@ -0,0 +1,47 @@
+
+#include es_precision.glsl
+#include mgl_lightdef.glsl
+
+#include mgl_const.glsl
+#include mgl_uniform.glsl
+#include mgl_varying.glsl
+
+vec4 getTexColor(in sampler2D tex, in int idx) {
+ vec4 coord;
+ if(idx==0) {
+ coord= mgl_TexCoords[0];
+ } else if(idx==1) {
+ coord= mgl_TexCoords[1];
+ } else if(idx==2) {
+ coord= mgl_TexCoords[2];
+ } else if(idx==3) {
+ coord= mgl_TexCoords[3];
+ } else if(idx==4) {
+ coord= mgl_TexCoords[4];
+ } else if(idx==5) {
+ coord= mgl_TexCoords[5];
+ } else if(idx==6) {
+ coord= mgl_TexCoords[6];
+ } else {
+ coord= mgl_TexCoords[7];
+ }
+ return texture2D(tex, coord.st);
+}
+
+void main (void)
+{
+ if( mgl_CullFace > 0 &&
+ ( ( mgl_CullFace == 1 && gl_FrontFacing ) ||
+ ( mgl_CullFace == 2 && !gl_FrontFacing ) ||
+ ( mgl_CullFace == 3 ) ) ) {
+ discard;
+ }
+
+ vec4 texColor = getTexColor(mgl_ActiveTexture,mgl_ActiveTextureIdx);
+
+ if(length(texColor.rgb)>0.0) {
+ gl_FragColor = vec4(frontColor.rgb*texColor.rgb, frontColor.a) ;
+ } else {
+ gl_FragColor = frontColor;
+ }
+}
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bfp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bfp
new file mode 100755
index 000000000..3ebaaee1d
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bfp
Binary files differ
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bvp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bvp
new file mode 100755
index 000000000..279ef72c7
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColor.bvp
Binary files differ
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorLight.bvp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorLight.bvp
new file mode 100755
index 000000000..5a9deea71
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorLight.bvp
Binary files differ
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorTexture.bfp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorTexture.bfp
new file mode 100755
index 000000000..ce1397fe1
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/bin/nvidia/FixedFuncColorTexture.bfp
Binary files differ
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/es_precision.glsl b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/es_precision.glsl
new file mode 100644
index 000000000..fd6abe54e
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/es_precision.glsl
@@ -0,0 +1,14 @@
+#ifndef es_precision_glsl
+#define es_precision_glsl
+
+#ifdef GL_ES
+ #define MEDIUMP mediump
+ #define HIGHP highp
+ #define LOWP lowp
+#else
+ #define MEDIUMP
+ #define HIGHP
+ #define LOWP
+#endif
+
+#endif // es_precision_glsl
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_attribute.glsl b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_attribute.glsl
new file mode 100644
index 000000000..b09bdb05a
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_attribute.glsl
@@ -0,0 +1,19 @@
+
+#ifndef mgl_attribute_glsl
+#define mgl_attribute_glsl
+
+#include es_precision.glsl
+
+attribute HIGHP vec4 mgl_Vertex;
+attribute HIGHP vec3 mgl_Normal;
+attribute HIGHP vec4 mgl_Color;
+attribute HIGHP vec4 mgl_MultiTexCoord0;
+attribute HIGHP vec4 mgl_MultiTexCoord1;
+attribute HIGHP vec4 mgl_MultiTexCoord2;
+attribute HIGHP vec4 mgl_MultiTexCoord3;
+attribute HIGHP vec4 mgl_MultiTexCoord4;
+attribute HIGHP vec4 mgl_MultiTexCoord5;
+attribute HIGHP vec4 mgl_MultiTexCoord6;
+attribute HIGHP vec4 mgl_MultiTexCoord7;
+
+#endif // mgl_attribute_glsl
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_const.glsl b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_const.glsl
new file mode 100644
index 000000000..1a464a1cb
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_const.glsl
@@ -0,0 +1,10 @@
+
+#ifndef mgl_const_glsl
+#define mgl_const_glsl
+
+#include es_precision.glsl
+
+const LOWP int MAX_TEXTURE_UNITS = 8; // <=gl_MaxTextureImageUnits
+const LOWP int MAX_LIGHTS = 8;
+
+#endif // mgl_const_glsl
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_lightdef.glsl b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_lightdef.glsl
new file mode 100644
index 000000000..98e214139
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_lightdef.glsl
@@ -0,0 +1,26 @@
+#ifndef mgl_lightdef_glsl
+#define mgl_lightdef_glsl
+
+struct mgl_LightSourceParameters {
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 specular;
+ vec4 position;
+ // vec4 halfVector; // is computed here
+ vec3 spotDirection;
+ float spotExponent;
+ float spotCutoff; // (range: [0.0,90.0], 180.0)
+ //float spotCosCutoff; // (range: [1.0,0.0],-1.0)
+ float constantAttenuation;
+ float linearAttenuation;
+ float quadraticAttenuation;
+};
+struct mgl_MaterialParameters {
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 specular;
+ vec4 emission;
+ float shininess;
+};
+
+#endif // mgl_lightdef_glsl
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_settexcoord.vp b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_settexcoord.vp
new file mode 100644
index 000000000..1efe328d0
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_settexcoord.vp
@@ -0,0 +1,35 @@
+#ifndef mgl_settexcoord_vp
+#define mgl_settexcoord_vp
+
+#include es_precision.glsl
+
+#include mgl_const.glsl
+#include mgl_uniform.glsl
+#include mgl_attribute.glsl
+#include mgl_varying.glsl
+
+void setTexCoord(in vec4 defpos) {
+ /**
+ * bitwise operator not supported on APX 2500 ES 2.0
+ *
+ mgl_TexCoords[0] = ( 0 != (mgl_TexCoordEnabled & 1) ) ? mgl_MultiTexCoord0 : defpos;
+ mgl_TexCoords[1] = ( 0 != (mgl_TexCoordEnabled & 2) ) ? mgl_MultiTexCoord1 : defpos;
+ mgl_TexCoords[2] = ( 0 != (mgl_TexCoordEnabled & 4) ) ? mgl_MultiTexCoord2 : defpos;
+ mgl_TexCoords[3] = ( 0 != (mgl_TexCoordEnabled & 8) ) ? mgl_MultiTexCoord3 : defpos;
+ mgl_TexCoords[4] = ( 0 != (mgl_TexCoordEnabled & 16) ) ? mgl_MultiTexCoord4 : defpos;
+ mgl_TexCoords[5] = ( 0 != (mgl_TexCoordEnabled & 32) ) ? mgl_MultiTexCoord5 : defpos;
+ mgl_TexCoords[6] = ( 0 != (mgl_TexCoordEnabled & 64) ) ? mgl_MultiTexCoord6 : defpos;
+ mgl_TexCoords[7] = ( 0 != (mgl_TexCoordEnabled & 128) ) ? mgl_MultiTexCoord7 : defpos;
+ */
+
+ mgl_TexCoords[0] = ( 0 != mgl_TexCoordEnabled[0] ) ? mgl_MultiTexCoord0 : defpos;
+ mgl_TexCoords[1] = ( 0 != mgl_TexCoordEnabled[1] ) ? mgl_MultiTexCoord1 : defpos;
+ mgl_TexCoords[2] = ( 0 != mgl_TexCoordEnabled[2] ) ? mgl_MultiTexCoord2 : defpos;
+ mgl_TexCoords[3] = ( 0 != mgl_TexCoordEnabled[3] ) ? mgl_MultiTexCoord3 : defpos;
+ mgl_TexCoords[4] = ( 0 != mgl_TexCoordEnabled[4] ) ? mgl_MultiTexCoord4 : defpos;
+ mgl_TexCoords[5] = ( 0 != mgl_TexCoordEnabled[5] ) ? mgl_MultiTexCoord5 : defpos;
+ mgl_TexCoords[6] = ( 0 != mgl_TexCoordEnabled[6] ) ? mgl_MultiTexCoord6 : defpos;
+ mgl_TexCoords[7] = ( 0 != mgl_TexCoordEnabled[7] ) ? mgl_MultiTexCoord7 : defpos;
+}
+
+#endif // mgl_settexcoord_vp
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform.glsl b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform.glsl
new file mode 100644
index 000000000..d8b3c7f95
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform.glsl
@@ -0,0 +1,18 @@
+
+#ifndef mgl_uniform_glsl
+#define mgl_uniform_glsl
+
+#include es_precision.glsl
+
+#include mgl_const.glsl
+
+uniform HIGHP mat4 mgl_PMVMatrix[3]; // P, Mv, and Mvi
+uniform HIGHP mat3 mgl_NormalMatrix; // transpose(inverse(ModelView)).3x3
+uniform LOWP int mgl_ColorEnabled;
+uniform HIGHP vec4 mgl_ColorStatic;
+uniform LOWP int mgl_TexCoordEnabled[MAX_TEXTURE_UNITS];
+uniform sampler2D mgl_ActiveTexture;
+uniform LOWP int mgl_ActiveTextureIdx;
+uniform LOWP int mgl_CullFace;
+
+#endif // mgl_uniform_glsl
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform_light.glsl b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform_light.glsl
new file mode 100644
index 000000000..0dedb5d5d
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_uniform_light.glsl
@@ -0,0 +1,15 @@
+
+#ifndef mgl_uniform_light_glsl
+#define mgl_uniform_light_glsl
+
+#include es_precision.glsl
+
+#include mgl_const.glsl
+#include mgl_lightdef.glsl
+
+uniform LOWP int mgl_LightsEnabled[MAX_LIGHTS];
+
+uniform mgl_LightSourceParameters mgl_LightSource[MAX_LIGHTS];
+uniform mgl_MaterialParameters mgl_FrontMaterial;
+
+#endif // mgl_uniform_light_glsl
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_varying.glsl b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_varying.glsl
new file mode 100644
index 000000000..fc9f735d1
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/mgl_varying.glsl
@@ -0,0 +1,12 @@
+
+#ifndef mgl_varying_glsl
+#define mgl_varying_glsl
+
+#include es_precision.glsl
+
+#include mgl_const.glsl
+
+varying vec4 frontColor;
+varying vec4 mgl_TexCoords[MAX_TEXTURE_UNITS];
+
+#endif // mgl_varying_glsl
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc-ff.bat b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc-ff.bat
new file mode 100755
index 000000000..002dca8ef
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc-ff.bat
@@ -0,0 +1,9 @@
+REM
+REM You have to call it from the 'shaders' directory, e.g.:
+REM scripts\nvidia-apx\glslc-ff.bat
+REM
+IF !"%JOGLDIR%"==""! GOTO YESPATH
+set JOGLDIR=..\lib
+:YESPATH
+
+java -cp %JOGLDIR%\jogl.core.jar;%JOGLDIR%\jogl.gles2.jar;%JOGLDIR%\jogl.fixed.jar;%JOGLDIR%\jogl.sdk.jar com.sun.opengl.util.glsl.sdk.CompileShaderNVidia FixedFuncColor.fp FixedFuncColorTexture.fp FixedFuncColorLight.vp FixedFuncColor.vp
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc.bat b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc.bat
new file mode 100755
index 000000000..9b5a4b39c
--- /dev/null
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/impl/shaders/scripts/nvidia-apx/glslc.bat
@@ -0,0 +1,9 @@
+REM
+REM You have to call it from the 'shaders' directory, e.g.:
+REM scripts\nvidia-apx\glslc.bat <FileName>
+REM
+IF !"%JOGLDIR%"==""! GOTO YESPATH
+set JOGLDIR=..\lib
+:YESPATH
+
+java -cp %JOGLDIR%\jogl.core.jar;%JOGLDIR%\jogl.gles2.jar;%JOGLDIR%\jogl.fixed.jar;%JOGLDIR%\jogl.sdk.jar com.sun.opengl.util.glsl.sdk.CompileShaderNVidia %1