package com.sun.opengl.impl.es2; import javax.media.opengl.*; import javax.media.opengl.util.*; import javax.media.opengl.util.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); } public void glDisableClientState(GL2ES2 gl, int glArrayIndex) { shaderState.glUseProgram(gl, true); shaderState.glDisableVertexAttribArray(gl, getArrayIndexName(glArrayIndex)); textureCoordsEnabled &= ~(1 << activeTextureUnit); } 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