diff options
Diffstat (limited to 'src/classes/com/sun')
14 files changed, 864 insertions, 660 deletions
diff --git a/src/classes/com/sun/opengl/impl/ProjectFloat.java b/src/classes/com/sun/opengl/impl/ProjectFloat.java index 637377237..309a6bdaf 100755 --- a/src/classes/com/sun/opengl/impl/ProjectFloat.java +++ b/src/classes/com/sun/opengl/impl/ProjectFloat.java @@ -153,8 +153,8 @@ public class ProjectFloat { // Array-based implementation private final float[] matrix = new float[16]; + private final float[][] tempInvertMatrix = new float[4][4]; - private final float[][] tempMatrix = new float[4][4]; private final float[] in = new float[4]; private final float[] out = new float[4]; @@ -164,8 +164,8 @@ public class ProjectFloat { // Buffer-based implementation private final FloatBuffer matrixBuf; + private final FloatBuffer tempInvertMatrixBuf; - private final FloatBuffer tempMatrixBuf; private final FloatBuffer inBuf; private final FloatBuffer outBuf; @@ -179,12 +179,12 @@ public class ProjectFloat { // Slice up one big buffer because some NIO implementations // allocate a huge amount of memory to back even the smallest of // buffers. - FloatBuffer buf = BufferUtil.newFloatBuffer(128); + FloatBuffer buf = BufferUtil.newFloatBuffer(2*16+2*4+3*3); int pos = 0; int sz = 16; matrixBuf = slice(buf, pos, sz); pos += sz; - tempMatrixBuf = slice(buf, pos, sz); + tempInvertMatrixBuf = slice(buf, pos, sz); pos += sz; sz = 4; inBuf = slice(buf, pos, sz); @@ -226,7 +226,7 @@ public class ProjectFloat { /** * Make matrix an identity matrix */ - private void gluMakeIdentityf(float[] m) { + public static void gluMakeIdentityf(float[] m) { for (int i = 0; i < 16; i++) { m[i] = IDENTITY_MATRIX[i]; } @@ -275,10 +275,10 @@ public class ProjectFloat { * * @return */ - private boolean __gluInvertMatrixf(float[] src, float[] inverse) { + public boolean gluInvertMatrixf(float[] src, float[] inverse) { int i, j, k, swap; float t; - float[][] temp = tempMatrix; + float[][] temp = tempInvertMatrix; for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { @@ -345,14 +345,14 @@ public class ProjectFloat { * * @return */ - private boolean __gluInvertMatrixf(FloatBuffer src, FloatBuffer inverse) { + public boolean gluInvertMatrixf(FloatBuffer src, FloatBuffer inverse) { int i, j, k, swap; float t; int srcPos = src.position(); int invPos = inverse.position(); - FloatBuffer temp = tempMatrixBuf; + FloatBuffer temp = tempInvertMatrixBuf; for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { @@ -772,7 +772,7 @@ public class ProjectFloat { gluMultMatricesf(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, matrix); - if (!__gluInvertMatrixf(matrix, matrix)) + if (!gluInvertMatrixf(matrix, matrix)) return false; in[0] = winx; @@ -829,7 +829,7 @@ public class ProjectFloat { gluMultMatricesf(modelMatrix, projMatrix, matrixBuf); - if (!__gluInvertMatrixf(matrixBuf, matrixBuf)) + if (!gluInvertMatrixf(matrixBuf, matrixBuf)) return false; in.put(0, winx); @@ -898,7 +898,7 @@ public class ProjectFloat { gluMultMatricesf(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, matrix); - if (!__gluInvertMatrixf(matrix, matrix)) + if (!gluInvertMatrixf(matrix, matrix)) return false; in[0] = winx; @@ -959,7 +959,7 @@ public class ProjectFloat { gluMultMatricesf(modelMatrix, projMatrix, matrixBuf); - if (!__gluInvertMatrixf(matrixBuf, matrixBuf)) + if (!gluInvertMatrixf(matrixBuf, matrixBuf)) return false; in.put(0, winx); diff --git a/src/classes/com/sun/opengl/impl/es2/FixedFuncShader.java b/src/classes/com/sun/opengl/impl/es2/FixedFuncShader.java deleted file mode 100644 index f6bf964a7..000000000 --- a/src/classes/com/sun/opengl/impl/es2/FixedFuncShader.java +++ /dev/null @@ -1,253 +0,0 @@ - -package com.sun.opengl.impl.es2; - -import javax.media.opengl.util.*; -import javax.media.opengl.*; -import java.nio.*; - -public class FixedFuncShader { - public FixedFuncShader(GL2ES2 gl, PMVMatrix pmvMatrix, ShaderData shaderData) { - init(gl, pmvMatrix, shaderData); - } - - public boolean isShaderDataValid() { - return shaderData.isValid(); - } - public boolean isValid() { - return shaderData.isValid() && shaderOk; - } - - public void glUseProgram(GL2ES2 gl, boolean on) { - if(shaderInUse==on) return; - if(!shaderOk) return; - gl.glUseProgram(on?shaderProgram:0); - shaderInUse = on; - } - - public void release(GL2ES2 gl) { - glUseProgram(gl, false); - gl.glDetachShader(shaderProgram, shaderData.vertexShader()); - gl.glDetachShader(shaderProgram, shaderData.fragmentShader()); - gl.glDeleteProgram(shaderProgram); - } - - public void syncUniforms(GL2ES2 gl) { - if(!shaderOk) return; - if(pmvMatrix.isDirty()) { - glUseProgram(gl, true); - gl.glUniformMatrix4fv(shaderPMVMatrix, 2, false, pmvMatrix.glGetPMVMatrixf()); - pmvMatrix.clear(); - } - } - - public int glArrayName2AttribName(int glName) { - switch(glName) { - case GL.GL_VERTEX_ARRAY: - return VERTEX_ARRAY; - case GL.GL_COLOR_ARRAY: - return COLOR_ARRAY; - case GL.GL_NORMAL_ARRAY: - return NORMAL_ARRAY; - case GL.GL_TEXTURE_COORD_ARRAY: - return TEXCOORD_ARRAY; - } - return -1; - } - - public void glEnableClientState(GL2ES2 gl, int glArrayName) { - if(!shaderOk) return; - int attribName = glArrayName2AttribName(glArrayName); - if(attribName>=0) { - glUseProgram(gl, true); - arrayInUse |= (1<<attribName); - gl.glEnableVertexAttribArray(attribName); - } - } - - public void glDisableClientState(GL2ES2 gl, int glArrayName) { - if(!shaderOk) return; - int attribName = glArrayName2AttribName(glArrayName); - if(attribName>=0) { - glUseProgram(gl, true); - gl.glDisableVertexAttribArray(attribName); - arrayInUse &= ~(1<<attribName); - if(0==arrayInUse) { - glUseProgram(gl, false); - } - } - } - - public void glVertexPointer(GL2ES2 gl, int size, int type, int stride, Buffer data ) { - if(!shaderOk) return; - glUseProgram(gl, true); - gl.glVertexAttribPointer(VERTEX_ARRAY, size, type, false, stride, data); - } - - public void glVertexPointer(GL2ES2 gl, int size, int type, int stride, long offset ) { - if(!shaderOk) return; - glUseProgram(gl, true); - gl.glVertexAttribPointer(VERTEX_ARRAY, size, type, false, stride, offset); - } - - public void glColorPointer(GL2ES2 gl, int size, int type, int stride, Buffer data ) { - if(!shaderOk) return; - glUseProgram(gl, true); - gl.glVertexAttribPointer(COLOR_ARRAY, size, type, false, stride, data); - } - - public void glColorPointer(GL2ES2 gl, int size, int type, int stride, long offset ) { - if(!shaderOk) return; - glUseProgram(gl, true); - gl.glVertexAttribPointer(COLOR_ARRAY, size, type, false, stride, offset); - } - - public void glColor4fv(GL2ES2 gl, FloatBuffer data ) { - glColorPointer(gl, 4, gl.GL_FLOAT, 0, data); - } - - public void glNormalPointer(GL2ES2 gl, int type, int stride, Buffer data ) { - if(!shaderOk) return; - glUseProgram(gl, true); - gl.glVertexAttribPointer(NORMAL_ARRAY, 3, type, false, stride, data); - } - - public void glNormalPointer(GL2ES2 gl, int type, int stride, long offset ) { - if(!shaderOk) return; - glUseProgram(gl, true); - gl.glVertexAttribPointer(NORMAL_ARRAY, 3, type, false, stride, offset); - } - - public void glTexCoordPointer(GL2ES2 gl, int size, int type, int stride, Buffer data ) { - if(!shaderOk) return; - glUseProgram(gl, true); - gl.glVertexAttribPointer(TEXCOORD_ARRAY, size, type, false, stride, data); - } - - public void glTexCoordPointer(GL2ES2 gl, int size, int type, int stride, long offset ) { - if(!shaderOk) return; - glUseProgram(gl, true); - gl.glVertexAttribPointer(TEXCOORD_ARRAY, size, type, false, stride, offset); - } - - public void setVertexAttribPointer(GL2ES2 gl, int glArrayName, int size, int type, int stride, Buffer data ) { - int attribName = glArrayName2AttribName(glArrayName); - if(!shaderOk || attribName<0) return; - glUseProgram(gl, true); - gl.glEnableVertexAttribArray(attribName); - gl.glVertexAttribPointer(attribName, size, type, false, stride, data); - } - - public void setVertexAttribPointer(GL2ES2 gl, int glArrayName, int size, int type, int stride, long offset ) { - int attribName = glArrayName2AttribName(glArrayName); - if(!shaderOk || attribName<0) return; - glUseProgram(gl, true); - gl.glEnableVertexAttribArray(attribName); - gl.glVertexAttribPointer(attribName, size, type, false, stride, offset); - } - - public void glLightfv(GL2ES2 gl, int light, int pname, java.nio.FloatBuffer params) { - if(!shaderOk) return; - light -=GL.GL_LIGHT0; - if(0 <= light && light <= 7) { - if(gl.GL_POSITION==pname && 0<=shaderLightsSource[light]) { - glUseProgram(gl, true); - gl.glUniform4fv(shaderLightsSource[light], 1, params); - } else if(gl.GL_AMBIENT==pname && 0<=shaderLigthsAmbient[light]) { - gl.glUniform4fv(shaderLigthsAmbient[light], 1, params); - } - } - } - - public void glShadeModel(GL2ES2 gl, int mode) { - if(!shaderOk || 0>shaderShadeModel) return; - glUseProgram(gl, true); - gl.glUniform1i(shaderShadeModel, mode); - } - - public void glActiveTexture(GL2ES2 gl, int texture) { - if(!shaderOk || 0>shaderShadeModel) return; - glUseProgram(gl, true); - texture-=gl.GL_TEXTURE0; - gl.glUniform1i(shaderActiveTexture, 0); - } - - protected void init(GL2ES2 gl, PMVMatrix pmvMatrix, ShaderData shaderData) { - if(shaderOk) return; - - if(null==pmvMatrix) { - throw new GLException("PMVMatrix is null"); - } - this.pmvMatrix=pmvMatrix; - this.shaderData=shaderData; - - if(!shaderData.createAndCompile(gl)) { - return; - } - - // Create the shader program - shaderProgram = gl.glCreateProgram(); - - // Attach the fragment and vertex shaders to it - gl.glAttachShader(shaderProgram, shaderData.vertexShader()); - gl.glAttachShader(shaderProgram, shaderData.fragmentShader()); - - gl.glBindAttribLocation(shaderProgram, VERTEX_ARRAY, "mgl_Vertex"); - gl.glBindAttribLocation(shaderProgram, COLOR_ARRAY, "mgl_Color"); - gl.glBindAttribLocation(shaderProgram, TEXCOORD_ARRAY, "mgl_MultiTexCoord0"); - - // Link the program - gl.glLinkProgram(shaderProgram); - - if ( ! gl.glIsProgramValid(shaderProgram, System.err) ) { - return; - } - - gl.glUseProgram(shaderProgram); - - shaderPMVMatrix = gl.glGetUniformLocation(shaderProgram, "mgl_PMVMatrix"); - if(0<=shaderPMVMatrix) { - gl.glUniformMatrix4fv(shaderPMVMatrix, 2, false, pmvMatrix.glGetPMVMatrixf()); - pmvMatrix.clear(); - shaderOk = true; - } else { - System.err.println("could not get uniform mgl_PMVMatrix: "+shaderPMVMatrix); - } - - // optional parameter .. - for(int i=0; i<7; i++) { - shaderLightsSource[i] = gl.glGetUniformLocation(shaderProgram, "mgl_LightSource"+i); - shaderLigthsAmbient[i] = gl.glGetUniformLocation(shaderProgram, "mgl_LightAmbient"+i); - } - shaderShadeModel = gl.glGetUniformLocation(shaderProgram, "mgl_ShadeModel"); - - shaderActiveTexture = gl.glGetUniformLocation(shaderProgram, "mgl_ActiveTexture"); - if(0<=shaderActiveTexture) { - gl.glUniform1i(shaderActiveTexture, 0); - } - - gl.glUseProgram(0); - shaderInUse = false; - } - - protected PMVMatrix pmvMatrix; - protected ShaderData shaderData; - - protected boolean shaderOk = false; - protected boolean shaderInUse = false; - protected int arrayInUse = 0; - protected int shaderProgram=-1; - - // attributes - protected static final int VERTEX_ARRAY = 0; // mgl_Vertex - protected static final int COLOR_ARRAY = 1; // mgl_Color - protected static final int NORMAL_ARRAY = 2; // ? - protected static final int TEXCOORD_ARRAY = 3; // mgl_MultiTexCoord0 - - // uniforms .. - protected int shaderPMVMatrix=-1; // mgl_PMVMatrix mat4 - protected int[] shaderLightsSource = new int[] { -1, -1, -1, -1, -1, -1, -1 }; // vec4f mgl_LightSourcei - protected int[] shaderLigthsAmbient = new int[] { -1, -1, -1, -1, -1, -1, -1 }; // vec4f mgl_LightAmbienti - protected int shaderShadeModel = -1; // mgl_ShadeModel int - protected int shaderActiveTexture = -1; // mgl_ActiveTexture int -} - diff --git a/src/classes/com/sun/opengl/impl/es2/FixedFuncShaderVertexColor.java b/src/classes/com/sun/opengl/impl/es2/FixedFuncShaderVertexColor.java deleted file mode 100644 index e3900d0b4..000000000 --- a/src/classes/com/sun/opengl/impl/es2/FixedFuncShaderVertexColor.java +++ /dev/null @@ -1,57 +0,0 @@ - -package com.sun.opengl.impl.es2; - -import javax.media.opengl.util.*; -import javax.media.opengl.*; -import java.nio.*; - -public class FixedFuncShaderVertexColor extends ShaderData { - - public static final String[][] vertShaderSource = new String[][] { { - "#ifdef GL_ES\n"+ - " #define MEDIUMP mediump\n"+ - " #define HIGHP highp\n"+ - "#else\n"+ - " #define MEDIUMP\n"+ - " #define HIGHP\n"+ - "#endif\n"+ - "\n"+ - "uniform MEDIUMP mat4 mgl_PMVMatrix[2];\n"+ - "attribute HIGHP vec4 mgl_Vertex;\n"+ - "attribute HIGHP vec4 mgl_Color;\n"+ - "varying HIGHP vec4 frontColor;\n"+ - "void main(void)\n"+ - "{\n"+ - " frontColor=mgl_Color;\n"+ - " gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;\n"+ - "}\n" } } ; - - public static final String[][] fragShaderSource = new String[][] { { - "#ifdef GL_ES\n"+ - " #define MEDIUMP mediump\n"+ - " #define HIGHP highp\n"+ - "#else\n"+ - " #define MEDIUMP\n"+ - " #define HIGHP\n"+ - "#endif\n"+ - "\n"+ - "varying HIGHP vec4 frontColor;\n"+ - "void main (void)\n"+ - "{\n"+ - " gl_FragColor = frontColor;\n"+ - "}\n" } } ; - - - public FixedFuncShaderVertexColor() { - super(1, 1); - } - - public int vertexShaderBinaryFormat() { return 0; } - public Buffer vertexShaderBinary() { return null; } - public String[][] vertexShaderSource() { return vertShaderSource; } - - public int fragmentShaderBinaryFormat() { return 0; } - public Buffer fragmentShaderBinary() { return null; } - public String[][] fragmentShaderSource() { return fragShaderSource; } -} - diff --git a/src/classes/com/sun/opengl/impl/es2/FixedFuncShaderVertexColorTexture.java b/src/classes/com/sun/opengl/impl/es2/FixedFuncShaderVertexColorTexture.java deleted file mode 100644 index 2c33c9c07..000000000 --- a/src/classes/com/sun/opengl/impl/es2/FixedFuncShaderVertexColorTexture.java +++ /dev/null @@ -1,67 +0,0 @@ - -package com.sun.opengl.impl.es2; - -import javax.media.opengl.util.*; -import javax.media.opengl.*; -import java.nio.*; - -public class FixedFuncShaderVertexColorTexture extends ShaderData { - - public static final String[][] vertShaderSource = new String[][] { { - "#ifdef GL_ES\n"+ - " #define MEDIUMP mediump\n"+ - " #define HIGHP highp\n"+ - "#else\n"+ - " #define MEDIUMP\n"+ - " #define HIGHP\n"+ - "#endif\n"+ - "\n"+ - "uniform MEDIUMP mat4 mgl_PMVMatrix[2];\n"+ - "attribute HIGHP vec4 mgl_Vertex;\n"+ - "attribute HIGHP vec4 mgl_Color;\n"+ - "attribute HIGHP vec4 mgl_MultiTexCoord0;\n"+ - "varying HIGHP vec4 gl_TexCoord[7];\n"+ - "varying HIGHP vec4 frontColor;\n"+ - "void main(void)\n"+ - "{\n"+ - " frontColor=mgl_Color;\n"+ - " gl_TexCoord[0] = mgl_MultiTexCoord0;\n"+ - " gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;\n"+ - "}\n" } } ; - - public static final String[][] fragShaderSource = new String[][] { { - "#ifdef GL_ES\n"+ - " #define MEDIUMP mediump\n"+ - " #define HIGHP highp\n"+ - "#else\n"+ - " #define MEDIUMP\n"+ - " #define HIGHP\n"+ - "#endif\n"+ - "\n"+ - "uniform HIGHP sampler2D mgl_ActiveTexture;\n"+ - "varying HIGHP vec4 frontColor;\n"+ - "const HIGHP vec4 one = vec4(1.0, 1.0, 1.0, 1.0);\n"+ - "const HIGHP vec4 zero = vec4(0.0, 0.0, 0.0, 0.0);\n"+ - "void main (void)\n"+ - "{\n"+ - " vec4 texColor = texture2D(mgl_ActiveTexture,gl_TexCoord[0].st);\n"+ - " if(greaterThan(texColor, zero)) {\n"+ - " gl_FragColor = vec4(frontColor.rgb*texColor.rgb, frontColor.a*texColor.a);\n"+ - " } else {\n"+ - " gl_FragColor = frontColor;\n"+ - " }\n"+ - "}\n" } } ; - - public FixedFuncShaderVertexColorTexture() { - super(1, 1); - } - - public int vertexShaderBinaryFormat() { return 0; } - public Buffer vertexShaderBinary() { return null; } - public String[][] vertexShaderSource() { return vertShaderSource; } - - public int fragmentShaderBinaryFormat() { return 0; } - public Buffer fragmentShaderBinary() { return null; } - public String[][] fragmentShaderSource() { return fragShaderSource; } -} - diff --git a/src/classes/com/sun/opengl/impl/es2/ShaderData.java b/src/classes/com/sun/opengl/impl/es2/ShaderData.java deleted file mode 100644 index 3a3c17811..000000000 --- a/src/classes/com/sun/opengl/impl/es2/ShaderData.java +++ /dev/null @@ -1,60 +0,0 @@ - -package com.sun.opengl.impl.es2; - -import javax.media.opengl.util.*; -import javax.media.opengl.*; -import java.nio.*; - -public abstract class ShaderData { - public abstract int vertexShaderBinaryFormat(); - public abstract Buffer vertexShaderBinary(); - public abstract String[][] vertexShaderSource(); - - public abstract int fragmentShaderBinaryFormat(); - public abstract Buffer fragmentShaderBinary(); - public abstract String[][] fragmentShaderSource(); - - public boolean isValid() { return valid; } - public void setValid(boolean val) { valid=val; } - - public ShaderData(int numVertexShader, int numFragmentShader) { - vertShader = BufferUtil.newIntBuffer(numVertexShader); - fragShader = BufferUtil.newIntBuffer(numFragmentShader); - } - - public IntBuffer vertexShader() { return vertShader; } - public IntBuffer fragmentShader() { return fragShader; } - - public boolean createAndCompile(GL2ES2 gl) { - if(isValid()) return true; - boolean res; - - // Create & Compile the vertex/fragment shader objects - res=gl.glCreateCompileShader(vertexShader(), gl.GL_VERTEX_SHADER, - vertexShaderBinaryFormat(), vertexShaderBinary(), - vertexShaderSource(), System.err); - if(!res) return false; - - res=gl.glCreateCompileShader(fragmentShader(), gl.GL_FRAGMENT_SHADER, - fragmentShaderBinaryFormat(), fragmentShaderBinary(), - fragmentShaderSource(), System.err); - if(!res) return false; - - setValid(true); - return true; - } - - public void release(GL2ES2 gl) { - if(isValid()) { - gl.glDeleteShader(fragmentShader()); - gl.glDeleteShader(vertexShader()); - setValid(false); - } - } - - protected IntBuffer vertShader = null; - protected IntBuffer fragShader = null; - - protected boolean valid=false; -} - diff --git a/src/classes/com/sun/opengl/impl/es2/VBOBufferDrawGLES2.java b/src/classes/com/sun/opengl/impl/es2/VBOBufferDrawGLES2.java deleted file mode 100644 index 30cf7e327..000000000 --- a/src/classes/com/sun/opengl/impl/es2/VBOBufferDrawGLES2.java +++ /dev/null @@ -1,70 +0,0 @@ - -package com.sun.opengl.impl.es2; - -import javax.media.opengl.util.VBOBufferDraw; -import javax.media.opengl.*; -import java.nio.*; - -public class VBOBufferDrawGLES2 extends VBOBufferDraw { - - public VBOBufferDrawGLES2(int glArrayType, int glDataType, int glBufferUsage, int comps, int initialSize) { - init(glArrayType, glDataType, glBufferUsage, comps, initialSize); - setVBOUsage(false); - //System.err.println("new VBOBufferDrawGLES2: "+this); - } - - protected void enableBufferGLImpl(GL gl, boolean newData) { - if(!bufferEnabled && null!=buffer) { - gl.glEnableClientState(glArrayType); - if(vboUsage) { - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName); - if(newData) { - gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * getBufferCompSize(), buffer, glBufferUsage); - } - switch(glArrayType) { - case GL.GL_VERTEX_ARRAY: - gl.glVertexPointer(components, glDataType, 0, 0); - break; - case GL.GL_NORMAL_ARRAY: - gl.glNormalPointer(glDataType, 0, 0); - break; - case GL.GL_COLOR_ARRAY: - gl.glColorPointer(components, glDataType, 0, 0); - break; - case GL.GL_TEXTURE_COORD_ARRAY: - gl.glTexCoordPointer(components, glDataType, 0, 0); - break; - default: - throw new GLException("invalid glArrayType: "+glArrayType+":\n\t"+this); - } - } else { - switch(glArrayType) { - case GL.GL_VERTEX_ARRAY: - gl.glVertexPointer(components, glDataType, 0, buffer); - break; - case GL.GL_NORMAL_ARRAY: - gl.glNormalPointer(glDataType, 0, buffer); - break; - case GL.GL_COLOR_ARRAY: - gl.glColorPointer(components, glDataType, 0, buffer); - break; - case GL.GL_TEXTURE_COORD_ARRAY: - gl.glTexCoordPointer(components, glDataType, 0, buffer); - break; - default: - throw new GLException("invalid glArrayType: "+glArrayType+":\n\t"+this); - } - } - bufferEnabled = true; - } - } - - protected void disableBufferGLImpl(GL gl) { - if(bufferEnabled && null!=buffer) { - gl.glDisableClientState(glArrayType); - bufferEnabled = false; - } - } - -} - diff --git a/src/classes/com/sun/opengl/impl/gl2es1/VBOBufferDrawGL2ES1.java b/src/classes/com/sun/opengl/impl/gl2es1/VBOBufferDrawGL2ES1.java deleted file mode 100644 index 5897b9a79..000000000 --- a/src/classes/com/sun/opengl/impl/gl2es1/VBOBufferDrawGL2ES1.java +++ /dev/null @@ -1,70 +0,0 @@ - -package com.sun.opengl.impl.gl2es1; - -import javax.media.opengl.util.VBOBufferDraw; -import javax.media.opengl.*; -import java.nio.*; - -public class VBOBufferDrawGL2ES1 extends VBOBufferDraw { - - public VBOBufferDrawGL2ES1(int glArrayType, int glDataType, int glBufferUsage, int comps, int initialSize) { - init(glArrayType, glDataType, glBufferUsage, comps, initialSize); - setVBOUsage(false); - //System.err.println("new VBOBufferDrawGL2ES1: "+this); - } - - protected void enableBufferGLImpl(GL gl, boolean newData) { - if(!bufferEnabled && null!=buffer) { - gl.glEnableClientState(glArrayType); - if(vboUsage) { - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName); - if(newData) { - gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * getBufferCompSize(), buffer, glBufferUsage); - } - switch(glArrayType) { - case GL.GL_VERTEX_ARRAY: - gl.glVertexPointer(components, glDataType, 0, 0); - break; - case GL.GL_NORMAL_ARRAY: - gl.glNormalPointer(glDataType, 0, 0); - break; - case GL.GL_COLOR_ARRAY: - gl.glColorPointer(components, glDataType, 0, 0); - break; - case GL.GL_TEXTURE_COORD_ARRAY: - gl.glTexCoordPointer(components, glDataType, 0, 0); - break; - default: - throw new GLException("invalid glArrayType: "+glArrayType+":\n\t"+this); - } - } else { - switch(glArrayType) { - case GL.GL_VERTEX_ARRAY: - gl.glVertexPointer(components, glDataType, 0, buffer); - break; - case GL.GL_NORMAL_ARRAY: - gl.glNormalPointer(glDataType, 0, buffer); - break; - case GL.GL_COLOR_ARRAY: - gl.glColorPointer(components, glDataType, 0, buffer); - break; - case GL.GL_TEXTURE_COORD_ARRAY: - gl.glTexCoordPointer(components, glDataType, 0, buffer); - break; - default: - throw new GLException("invalid glArrayType: "+glArrayType+":\n\t"+this); - } - } - bufferEnabled = true; - } - } - - protected void disableBufferGLImpl(GL gl) { - if(bufferEnabled && null!=buffer) { - gl.glDisableClientState(glArrayType); - bufferEnabled = false; - } - } - -} - diff --git a/src/classes/com/sun/opengl/impl/glsl/FixedFuncPipeline.java b/src/classes/com/sun/opengl/impl/glsl/FixedFuncPipeline.java new file mode 100644 index 000000000..e8cf58b42 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/glsl/FixedFuncPipeline.java @@ -0,0 +1,468 @@ + +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<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); + } + } + + public void glEnable(GL2ES2 gl, int cap, boolean enable) { + shaderState.glUseProgram(gl, true); + + switch(cap) { + case GL.GL_TEXTURE_2D: + textureEnabled=enable; + return; + case GL.GL_LIGHTING: + lightingEnabled=enable; + return; + } + + int light = cap - GL.GL_LIGHT0; + if(0 <= light && light < MAX_LIGHTS) { + if(enable) { + lightsEnabled |= (1 << light); + } else { + lightsEnabled &= ~(1 << light); + } + return; + } + + } + + 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(GLContext.mgl_Color)==true)?1:0; + if(ca!=ud.intValue()) { + ud.setData(ca); + shaderState.glUniform(gl, ud); + } + } + + ud = shaderState.getUniform(mgl_TexCoordEnabled); + if(null!=ud) { + if(textureCoordsEnabled!=ud.intValue()) { + ud.setData(textureCoordsEnabled); + shaderState.glUniform(gl, ud); + } + } + + ud = shaderState.getUniform(mgl_LightsEnabled); + if(null!=ud) { + if(lightsEnabled!=ud.intValue()) { + ud.setData(lightsEnabled); + shaderState.glUniform(gl, ud); + } + } + + 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.out.println("validate: "+this); + } + } + + public String toString() { + return "FixedFuncPipeline[pmv: "+pmvMatrix+ + ", textureEnabled: "+textureEnabled+ + ", textureCoordsEnabled: "+textureCoordsEnabled+ + ", lightingEnabled: "+lightingEnabled+ + ", lightsEnabled: "+lightsEnabled+ + ", ShaderState: "+shaderState+ + "]"; + } + + protected void init(GL2ES2 gl, PMVMatrix pmvMatrix) { + if(null==pmvMatrix) { + throw new GLException("PMVMatrix is null"); + } + this.pmvMatrix=pmvMatrix; + this.shaderState=new ShaderState(); + this.shaderState.setVerbose(verbose); + + ShaderCode vertexColor = new ShaderCode( gl.GL_VERTEX_SHADER, 1, -1, null, + FixedFuncShaderVertexColor.vertShaderSource); + + ShaderCode vertexColorLight = new ShaderCode( gl.GL_VERTEX_SHADER, 1, -1, null, + FixedFuncShaderVertexColorLight.vertShaderSource); + + ShaderCode fragmentColor = new ShaderCode( gl.GL_FRAGMENT_SHADER, 1, -1, null, + FixedFuncShaderFragmentColor.fragShaderSource); + + ShaderCode fragmentColorTexture = new ShaderCode( gl.GL_FRAGMENT_SHADER, 1, -1, null, + FixedFuncShaderFragmentColorTexture.fragShaderSource); + + shaderProgramColor = new ShaderProgram(); + shaderProgramColor.add(vertexColor); + shaderProgramColor.add(fragmentColor); + if(!shaderProgramColor.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColor program"); + } + + shaderProgramColorTexture = new ShaderProgram(); + shaderProgramColorTexture.add(vertexColor); + shaderProgramColorTexture.add(fragmentColorTexture); + if(!shaderProgramColorTexture.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColorTexture program"); + } + + shaderProgramColorLight = new ShaderProgram(); + shaderProgramColorLight.add(vertexColorLight); + shaderProgramColorLight.add(fragmentColor); + if(!shaderProgramColorLight.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColorLight program"); + } + + shaderProgramColorTextureLight = new ShaderProgram(); + shaderProgramColorTextureLight.add(vertexColorLight); + shaderProgramColorTextureLight.add(fragmentColorTexture); + if(!shaderProgramColorTextureLight.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColorLight program"); + } + + 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, 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)); + 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, 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 int textureCoordsEnabled=0; + protected int activeTextureUnit=0; + + protected boolean lightingEnabled=false; + protected int lightsEnabled=0; + + 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"; // 1i bitfield + + protected static final String mgl_ShadeModel = "mgl_ShadeModel"; // 1i + + protected static final String mgl_TexCoordEnabled = "mgl_TexCoordEnabled"; // 1i bitfield + protected static final String mgl_ActiveTexture = "mgl_ActiveTexture"; // 1i + protected static final String mgl_ActiveTextureIdx = "mgl_ActiveTextureIdx";// 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; +} + diff --git a/src/classes/com/sun/opengl/impl/glsl/FixedFuncShaderFragmentColor.java b/src/classes/com/sun/opengl/impl/glsl/FixedFuncShaderFragmentColor.java new file mode 100644 index 000000000..170a6c1da --- /dev/null +++ b/src/classes/com/sun/opengl/impl/glsl/FixedFuncShaderFragmentColor.java @@ -0,0 +1,27 @@ + +package com.sun.opengl.impl.es2; + +import javax.media.opengl.util.*; +import javax.media.opengl.*; +import java.nio.*; + +public class FixedFuncShaderFragmentColor { + + public static final String[][] fragShaderSource = new String[][] { { + "#ifdef GL_ES\n"+ + " #define MEDIUMP mediump\n"+ + " #define HIGHP highp\n"+ + "#else\n"+ + " #define MEDIUMP\n"+ + " #define HIGHP\n"+ + "#endif\n"+ + "\n"+ + "varying HIGHP vec4 frontColor;\n"+ + "\n"+ + "void main (void)\n"+ + "{\n"+ + " gl_FragColor = frontColor;\n"+ + "}\n" } } ; + +} + diff --git a/src/classes/com/sun/opengl/impl/glsl/FixedFuncShaderFragmentColorTexture.java b/src/classes/com/sun/opengl/impl/glsl/FixedFuncShaderFragmentColorTexture.java new file mode 100644 index 000000000..7367a7cb9 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/glsl/FixedFuncShaderFragmentColorTexture.java @@ -0,0 +1,39 @@ + +package com.sun.opengl.impl.es2; + +import javax.media.opengl.util.*; +import javax.media.opengl.*; +import java.nio.*; + +public class FixedFuncShaderFragmentColorTexture { + + public static final String[][] fragShaderSource = new String[][] { { + "#ifdef GL_ES\n"+ + " #define MEDIUMP mediump\n"+ + " #define HIGHP highp\n"+ + "#else\n"+ + " #define MEDIUMP\n"+ + " #define HIGHP\n"+ + "#endif\n"+ + "\n"+ + "const MEDIUMP int MAX_TEXTURE_UNITS = 8; // <=gl_MaxTextureImageUnits \n"+ + "const MEDIUMP int MAX_LIGHTS = 8; \n"+ + "const HIGHP vec4 zero = vec4(0.0, 0.0, 0.0, 0.0);\n"+ + "\n"+ + "uniform HIGHP sampler2D mgl_ActiveTexture;\n"+ + "uniform MEDIUMP int mgl_ActiveTextureIdx;\n"+ + "\n"+ + "varying HIGHP vec4 frontColor;\n"+ + "varying HIGHP vec4 mgl_TexCoord[MAX_TEXTURE_UNITS];\n"+ + "\n"+ + "void main (void)\n"+ + "{\n"+ + " vec4 texColor = texture2D(mgl_ActiveTexture,mgl_TexCoord[mgl_ActiveTextureIdx].st);\n"+ + " if(greaterThan(texColor, zero)) {\n"+ + " gl_FragColor = vec4(frontColor.rgb*texColor.rgb, frontColor.a * texColor.a) ; \n"+ + " } else {\n"+ + " gl_FragColor = frontColor;\n"+ + " }\n"+ + "}\n" } } ; +} + diff --git a/src/classes/com/sun/opengl/impl/glsl/FixedFuncShaderVertexColor.java b/src/classes/com/sun/opengl/impl/glsl/FixedFuncShaderVertexColor.java new file mode 100644 index 000000000..2fa8d5c46 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/glsl/FixedFuncShaderVertexColor.java @@ -0,0 +1,65 @@ + +package com.sun.opengl.impl.es2; + +import javax.media.opengl.util.*; +import javax.media.opengl.*; +import java.nio.*; + +public class FixedFuncShaderVertexColor { + + public static final String[][] vertShaderSource = new String[][] { { + "#ifdef GL_ES\n"+ + " #define MEDIUMP mediump\n"+ + " #define HIGHP highp\n"+ + "#else\n"+ + " #define MEDIUMP\n"+ + " #define HIGHP\n"+ + "#endif\n"+ + "\n"+ + "const MEDIUMP int MAX_TEXTURE_UNITS = 8; // <=gl_MaxTextureImageUnits \n"+ + "const MEDIUMP int MAX_LIGHTS = 8; \n"+ + "\n"+ + "uniform HIGHP mat4 mgl_PMVMatrix[3]; // P, Mv, and Mvi\n"+ + "uniform MEDIUMP int mgl_ColorEnabled;\n"+ + "uniform HIGHP vec4 mgl_ColorStatic;\n"+ + "uniform MEDIUMP int mgl_TexCoordEnabled;\n"+ + "\n"+ + "attribute HIGHP vec4 mgl_Vertex;\n"+ + "attribute HIGHP vec4 mgl_Color;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord0;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord1;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord2;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord3;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord4;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord5;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord6;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord7;\n"+ + "\n"+ + "varying HIGHP vec4 frontColor;\n"+ + "varying HIGHP vec4 mgl_TexCoord[MAX_TEXTURE_UNITS];\n"+ + "\n"+ + "void setTexCoord(in HIGHP vec4 defpos) {\n"+ + " mgl_TexCoord[0] = ( 0 != (mgl_TexCoordEnabled & 1) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + " mgl_TexCoord[1] = ( 0 != (mgl_TexCoordEnabled & 2) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + " mgl_TexCoord[2] = ( 0 != (mgl_TexCoordEnabled & 4) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + " mgl_TexCoord[3] = ( 0 != (mgl_TexCoordEnabled & 8) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + " mgl_TexCoord[4] = ( 0 != (mgl_TexCoordEnabled & 16) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + " mgl_TexCoord[5] = ( 0 != (mgl_TexCoordEnabled & 32) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + " mgl_TexCoord[6] = ( 0 != (mgl_TexCoordEnabled & 64) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + " mgl_TexCoord[7] = ( 0 != (mgl_TexCoordEnabled & 128) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + "}\n"+ + "\n"+ + "void main(void)\n"+ + "{\n"+ + " if(mgl_ColorEnabled>0) {\n"+ + " frontColor=mgl_Color;\n"+ + " } else {\n"+ + " frontColor=mgl_ColorStatic;\n"+ + " }\n"+ + "\n"+ + " gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;\n"+ + "\n"+ + " setTexCoord(gl_Position);\n"+ + "}\n" } } ; +} + diff --git a/src/classes/com/sun/opengl/impl/glsl/FixedFuncShaderVertexColorLight.java b/src/classes/com/sun/opengl/impl/glsl/FixedFuncShaderVertexColorLight.java new file mode 100644 index 000000000..f1e97a536 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/glsl/FixedFuncShaderVertexColorLight.java @@ -0,0 +1,136 @@ + +package com.sun.opengl.impl.es2; + +import javax.media.opengl.util.*; +import javax.media.opengl.*; +import java.nio.*; + +public class FixedFuncShaderVertexColorLight { + + public static final String[][] vertShaderSource = new String[][] { { + "#ifdef GL_ES\n"+ + " #define MEDIUMP mediump\n"+ + " #define HIGHP highp\n"+ + "#else\n"+ + " #define MEDIUMP\n"+ + " #define HIGHP\n"+ + "#endif\n"+ + "\n"+ + "struct mgl_LightSourceParameters {\n"+ + " vec4 ambient; \n"+ + " vec4 diffuse; \n"+ + " vec4 specular; \n"+ + " vec4 position; \n"+ + " // vec4 halfVector; // is computed here\n"+ + " vec3 spotDirection; \n"+ + " float spotExponent; \n"+ + " float spotCutoff; // (range: [0.0,90.0], 180.0)\n"+ + " //float spotCosCutoff; // (range: [1.0,0.0],-1.0)\n"+ + " float constantAttenuation; \n"+ + " float linearAttenuation; \n"+ + " float quadraticAttenuation; \n"+ + "};\n"+ + "struct mgl_MaterialParameters {\n"+ + " vec4 ambient; \n"+ + " vec4 diffuse; \n"+ + " vec4 specular; \n"+ + " vec4 emission; \n"+ + " float shininess; \n"+ + "};\n"+ + "\n"+ + "\n"+ + "const MEDIUMP int MAX_TEXTURE_UNITS = 8; // <=gl_MaxTextureImageUnits \n"+ + "const MEDIUMP int MAX_LIGHTS = 8; \n"+ + "\n"+ + "uniform HIGHP mat4 mgl_PMVMatrix[3]; // P, Mv, and Mvi\n"+ + "uniform HIGHP mat3 mgl_NormalMatrix; // transpose(inverse(ModelView)).3x3\n"+ + "uniform MEDIUMP int mgl_ColorEnabled;\n"+ + "uniform HIGHP vec4 mgl_ColorStatic;\n"+ + "uniform MEDIUMP int mgl_TexCoordEnabled;\n"+ + "uniform MEDIUMP int mgl_LightsEnabled;\n"+ + "uniform mgl_LightSourceParameters mgl_LightSource[MAX_LIGHTS];\n"+ + "uniform mgl_MaterialParameters mgl_FrontMaterial;\n"+ + "\n"+ + "attribute HIGHP vec4 mgl_Vertex;\n"+ + "attribute HIGHP vec3 mgl_Normal;\n"+ + "attribute HIGHP vec4 mgl_Color;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord0;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord1;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord2;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord3;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord4;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord5;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord6;\n"+ + "attribute HIGHP vec4 mgl_MultiTexCoord7;\n"+ + "\n"+ + "varying HIGHP vec4 frontColor;\n"+ + "varying HIGHP vec4 mgl_TexCoord[MAX_TEXTURE_UNITS];\n"+ + "\n"+ + "void setTexCoord(in HIGHP vec4 defpos) {\n"+ + " mgl_TexCoord[0] = ( 0 != (mgl_TexCoordEnabled & 1) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + " mgl_TexCoord[1] = ( 0 != (mgl_TexCoordEnabled & 2) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + " mgl_TexCoord[2] = ( 0 != (mgl_TexCoordEnabled & 4) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + " mgl_TexCoord[3] = ( 0 != (mgl_TexCoordEnabled & 8) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + " mgl_TexCoord[4] = ( 0 != (mgl_TexCoordEnabled & 16) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + " mgl_TexCoord[5] = ( 0 != (mgl_TexCoordEnabled & 32) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + " mgl_TexCoord[6] = ( 0 != (mgl_TexCoordEnabled & 64) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + " mgl_TexCoord[7] = ( 0 != (mgl_TexCoordEnabled & 128) ) ? mgl_MultiTexCoord0 : defpos;\n"+ + "}\n"+ + "\n"+ + "void main(void)\n"+ + "{\n"+ + " vec4 position;\n"+ + " vec3 normal, lightDir, cameraDir, halfDir;\n"+ + " vec4 ambient, diffuse, specular;\n"+ + " float NdotL, NdotHV, dist, attenuation;\n"+ + " int i;\n"+ + "\n"+ + " position = mgl_PMVMatrix[1] * mgl_Vertex; // vertex eye position \n"+ + "\n"+ + " normal = normalize(mgl_NormalMatrix * mgl_Normal); \n"+ + " // cameraPosition: (mgl_PMVMatrix[2] * vec4(0,0,0,1.0)).xyz \n"+ + " cameraDir = normalize( (mgl_PMVMatrix[2] * vec4(0,0,0,1.0)).xyz - mgl_Vertex.xyz ); \n"+ + "\n"+ + " ambient = vec4(0,0,0,0);\n"+ + " diffuse = vec4(0,0,0,0);\n"+ + " specular = vec4(0,0,0,0);\n"+ + "\n"+ + " for(i=0; i<MAX_LIGHTS; i++) {\n"+ + " if( 0!= (mgl_LightsEnabled & (1<<i)) ) {\n"+ + " ambient += mgl_LightSource[i].ambient;\n"+ + " lightDir = mgl_LightSource[i].position.xyz - position.xyz;\n"+ + " dist = length(lightDir);\n"+ + " lightDir = normalize(lightDir);\n"+ + " attenuation = 1.0 / ( \n"+ + " mgl_LightSource[i].constantAttenuation+ \n"+ + " mgl_LightSource[i].linearAttenuation * dist + \n"+ + " mgl_LightSource[i].quadraticAttenuation * dist * dist );\n"+ + " NdotL = max(0.0, dot(normal, lightDir));\n"+ + " diffuse += mgl_LightSource[i].diffuse * NdotL * attenuation;\n"+ + " if (NdotL != 0.0) {\n"+ + " halfDir = normalize (lightDir + cameraDir); \n"+ + " NdotHV = max(0.0, dot(normal, halfDir));\n"+ + " specular += mgl_LightSource[i].specular * \n"+ + " pow(NdotHV,gl_FrontMaterial.shininess) * attenuation;\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + " ambient += mgl_FrontMaterial.ambient;\n"+ + " diffuse *= mgl_FrontMaterial.diffuse;\n"+ + " specular *= mgl_FrontMaterial.specular;\n"+ + "\n"+ + " if(mgl_ColorEnabled>0) {\n"+ + " frontColor=mgl_Color;\n"+ + " } else {\n"+ + " frontColor=mgl_ColorStatic;\n"+ + " }\n"+ + " if( 0!= mgl_LightsEnabled ) {\n"+ + " frontColor *= ambient + diffuse + specular;\n"+ + " }\n"+ + "\n"+ + " gl_Position = mgl_PMVMatrix[0] * position;\n"+ + "\n"+ + " setTexCoord(gl_Position);\n"+ + "}\n" } } ; +} + diff --git a/src/classes/com/sun/opengl/impl/glsl/GLSLArrayDataServer.java b/src/classes/com/sun/opengl/impl/glsl/GLSLArrayDataServer.java new file mode 100644 index 000000000..551eb525f --- /dev/null +++ b/src/classes/com/sun/opengl/impl/glsl/GLSLArrayDataServer.java @@ -0,0 +1,58 @@ + +package com.sun.opengl.impl.glsl; + +import javax.media.opengl.*; +import javax.media.opengl.util.glsl.ShaderState; +import java.nio.*; + +public class GLSLArrayDataServer extends GLArrayDataServer { + + public GLSLArrayDataServer(String name, int comps, int dataType, boolean normalized, + int stride, Buffer buffer, int glBufferUsage) { + init(name, -1, comps, dataType, normalized, stride, buffer, 0, buffer.limit(), glBufferUsage, true); + } + + public GLSLArrayDataServer(String name, int comps, int dataType, boolean normalized, + int stride, long bufferOffset) { + init(name, -1, comps, dataType, normalized, stride, null, bufferOffset, 0, -1, true); + } + + public GLSLArrayDataServer(String name, int comps, int dataType, boolean normalized, + int initialSize, int glBufferUsage) { + init(name, -1, comps, dataType, normalized, 0, null, 0, initialSize, glBufferUsage, true); + } + + + protected void enableBufferGLImpl(GL gl, boolean enable) { + GL2ES2 glsl = gl.getGL2ES2(); + ShaderState st = ShaderState.getCurrent(); + if(null==st) { + throw new GLException("No ShaderState current"); + } + + if(enable) { + if(!st.glEnableVertexAttribArray(glsl, name)) { + throw new RuntimeException("Internal Error"); + } + bufferEnabled = true; + + if(vboUsage) { + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName); + if(!bufferWritten) { + gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * getBufferCompSize(), buffer, glBufferUsage); + } + } + if ( ! st.glVertexAttribPointer(glsl, this) ) { + throw new RuntimeException("Internal Error"); + } + bufferWritten=true; + } else { + if(!st.glDisableVertexAttribArray(glsl, name)) { + throw new RuntimeException("Internal Error"); + } + bufferEnabled = false; + } + } + +} + diff --git a/src/classes/com/sun/opengl/impl/glu/GLUquadricImpl.java b/src/classes/com/sun/opengl/impl/glu/GLUquadricImpl.java index 8c2a4eef2..031d23c50 100644 --- a/src/classes/com/sun/opengl/impl/glu/GLUquadricImpl.java +++ b/src/classes/com/sun/opengl/impl/glu/GLUquadricImpl.java @@ -130,6 +130,7 @@ import java.nio.*; */ public class GLUquadricImpl implements GLUquadric { + private boolean useGLSL; private int drawStyle; private int orientation; private boolean textureFlag; @@ -137,19 +138,29 @@ public class GLUquadricImpl implements GLUquadric { private boolean immModeSinkEnabled; private boolean immModeSinkImmediate; - public static final boolean USE_NORM_TXT = true; + public static final boolean USE_NORM = true; + public static final boolean USE_TEXT = false; private ImmModeSink immModeSink; - public GLUquadricImpl() { + public GLUquadricImpl(boolean useGLSL) { + this.useGLSL = useGLSL; drawStyle = GLU.GLU_FILL; orientation = GLU.GLU_OUTSIDE; textureFlag = false; normals = GLU.GLU_SMOOTH; - if(USE_NORM_TXT) { - immModeSink = new ImmModeSink(GL.GL_FLOAT, GL.GL_STATIC_DRAW, 3, 3, 0, 3, 32); + if(useGLSL) { + immModeSink = ImmModeSink.createGLSL (GL.GL_STATIC_DRAW, 32, + 3, GL.GL_FLOAT, // vertex + 0, GL.GL_FLOAT, // color + USE_NORM?3:0, GL.GL_SHORT, // normal + USE_TEXT?2:0, GL.GL_FLOAT); // texture } else { - immModeSink = new ImmModeSink(GL.GL_FLOAT, GL.GL_STATIC_DRAW, 3, 0, 0, 0, 32); + immModeSink = ImmModeSink.createFixed(GL.GL_STATIC_DRAW, 32, + 3, GL.GL_FLOAT, // vertex + 0, GL.GL_FLOAT, // color + USE_NORM?3:0, GL.GL_SHORT, // normal + USE_TEXT?2:0, GL.GL_FLOAT); // texture } immModeSinkImmediate=true; immModeSinkEnabled=!GLProfile.isGL2(); @@ -183,10 +194,18 @@ public class GLUquadricImpl implements GLUquadric { if(!immModeSinkEnabled) return null; ImmModeSink res = immModeSink; - if(USE_NORM_TXT) { - immModeSink = new ImmModeSink(GL.GL_FLOAT, GL.GL_STATIC_DRAW, 3, 3, 0, 3, 32); + if(useGLSL) { + immModeSink = ImmModeSink.createGLSL (GL.GL_STATIC_DRAW, 32, + 3, GL.GL_FLOAT, // vertex + 0, GL.GL_FLOAT, // color + USE_NORM?3:0, GL.GL_SHORT, // normal + USE_TEXT?2:0, GL.GL_FLOAT); // texture } else { - immModeSink = new ImmModeSink(GL.GL_FLOAT, GL.GL_STATIC_DRAW, 3, 0, 0, 0, 32); + immModeSink = ImmModeSink.createFixed(GL.GL_STATIC_DRAW, 32, + 3, GL.GL_FLOAT, // vertex + 0, GL.GL_FLOAT, // color + USE_NORM?3:0, GL.GL_SHORT, // normal + USE_TEXT?2:0, GL.GL_FLOAT); // texture } return res; } @@ -349,9 +368,7 @@ public class GLUquadricImpl implements GLUquadric { for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); - if(USE_NORM_TXT) { - normal3f(gl, x * nsign, y * nsign, nz * nsign); - } + normal3f(gl, x * nsign, y * nsign, nz * nsign); z = 0.0f; r = baseRadius; @@ -372,9 +389,7 @@ public class GLUquadricImpl implements GLUquadric { for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); - if(USE_NORM_TXT) { - normal3f(gl, x * nsign, y * nsign, nz * nsign); - } + normal3f(gl, x * nsign, y * nsign, nz * nsign); glVertex3f(gl, (x * r), (y * r), z); } glEnd(gl); @@ -388,9 +403,7 @@ public class GLUquadricImpl implements GLUquadric { for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); - if(USE_NORM_TXT) { - normal3f(gl, x * nsign, y * nsign, nz * nsign); - } + normal3f(gl, x * nsign, y * nsign, nz * nsign); glVertex3f(gl, (x * baseRadius), (y * baseRadius), 0.0f); } glEnd(gl); @@ -398,9 +411,7 @@ public class GLUquadricImpl implements GLUquadric { for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); - if(USE_NORM_TXT) { - normal3f(gl, x * nsign, y * nsign, nz * nsign); - } + normal3f(gl, x * nsign, y * nsign, nz * nsign); glVertex3f(gl, (x * topRadius), (y * topRadius), height); } glEnd(gl); @@ -411,9 +422,7 @@ public class GLUquadricImpl implements GLUquadric { for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); - if(USE_NORM_TXT) { - normal3f(gl, x * nsign, y * nsign, nz * nsign); - } + normal3f(gl, x * nsign, y * nsign, nz * nsign); glVertex3f(gl, (x * baseRadius), (y * baseRadius), 0.0f); glVertex3f(gl, (x * topRadius), (y * topRadius), (height)); } @@ -436,26 +445,18 @@ public class GLUquadricImpl implements GLUquadric { y = cos((i * da)); } if (nsign == 1.0f) { - if(USE_NORM_TXT) { - normal3f(gl, (x * nsign), (y * nsign), (nz * nsign)); - TXTR_COORD(gl, s, t); - } + normal3f(gl, (x * nsign), (y * nsign), (nz * nsign)); + TXTR_COORD(gl, s, t); glVertex3f(gl, (x * r), (y * r), z); - if(USE_NORM_TXT) { - normal3f(gl, (x * nsign), (y * nsign), (nz * nsign)); - TXTR_COORD(gl, s, t + dt); - } + normal3f(gl, (x * nsign), (y * nsign), (nz * nsign)); + TXTR_COORD(gl, s, t + dt); glVertex3f(gl, (x * (r + dr)), (y * (r + dr)), (z + dz)); } else { - if(USE_NORM_TXT) { - normal3f(gl, x * nsign, y * nsign, nz * nsign); - TXTR_COORD(gl, s, t); - } + normal3f(gl, x * nsign, y * nsign, nz * nsign); + TXTR_COORD(gl, s, t); glVertex3f(gl, (x * r), (y * r), z); - if(USE_NORM_TXT) { - normal3f(gl, x * nsign, y * nsign, nz * nsign); - TXTR_COORD(gl, s, t + dt); - } + normal3f(gl, x * nsign, y * nsign, nz * nsign); + TXTR_COORD(gl, s, t + dt); glVertex3f(gl, (x * (r + dr)), (y * (r + dr)), (z + dz)); } s += ds; @@ -959,19 +960,15 @@ public class GLUquadricImpl implements GLUquadric { if (!textureFlag) { // draw +Z end as a triangle fan glBegin(gl, GL.GL_TRIANGLE_FAN); - if(USE_NORM_TXT) { - glNormal3f(gl, 0.0f, 0.0f, 1.0f); - } + glNormal3f(gl, 0.0f, 0.0f, 1.0f); glVertex3f(gl, 0.0f, 0.0f, nsign * radius); for (j = 0; j <= slices; j++) { theta = (j == slices) ? 0.0f : j * dtheta; x = -sin(theta) * sin(drho); y = cos(theta) * sin(drho); z = nsign * cos(drho); - if(USE_NORM_TXT) { - if (normals) { - glNormal3f(gl, x * nsign, y * nsign, z * nsign); - } + if (normals) { + glNormal3f(gl, x * nsign, y * nsign, z * nsign); } glVertex3f(gl, x * radius, y * radius, z * radius); } @@ -999,22 +996,18 @@ public class GLUquadricImpl implements GLUquadric { x = -sin(theta) * sin(rho); y = cos(theta) * sin(rho); z = nsign * cos(rho); - if(USE_NORM_TXT) { - if (normals) { - glNormal3f(gl, x * nsign, y * nsign, z * nsign); - } - TXTR_COORD(gl, s, t); + if (normals) { + glNormal3f(gl, x * nsign, y * nsign, z * nsign); } + TXTR_COORD(gl, s, t); glVertex3f(gl, x * radius, y * radius, z * radius); x = -sin(theta) * sin(rho + drho); y = cos(theta) * sin(rho + drho); z = nsign * cos(rho + drho); - if(USE_NORM_TXT) { - if (normals) { - glNormal3f(gl, x * nsign, y * nsign, z * nsign); - } - TXTR_COORD(gl, s, t - dt); + if (normals) { + glNormal3f(gl, x * nsign, y * nsign, z * nsign); } + TXTR_COORD(gl, s, t - dt); s += ds; glVertex3f(gl, x * radius, y * radius, z * radius); } @@ -1025,9 +1018,7 @@ public class GLUquadricImpl implements GLUquadric { if (!textureFlag) { // draw -Z end as a triangle fan glBegin(gl, GL.GL_TRIANGLE_FAN); - if(USE_NORM_TXT) { - glNormal3f(gl, 0.0f, 0.0f, -1.0f); - } + glNormal3f(gl, 0.0f, 0.0f, -1.0f); glVertex3f(gl, 0.0f, 0.0f, -radius * nsign); rho = PI - drho; s = 1.0f; @@ -1036,10 +1027,8 @@ public class GLUquadricImpl implements GLUquadric { x = -sin(theta) * sin(rho); y = cos(theta) * sin(rho); z = nsign * cos(rho); - if(USE_NORM_TXT) { - if (normals) - glNormal3f(gl, x * nsign, y * nsign, z * nsign); - } + if (normals) + glNormal3f(gl, x * nsign, y * nsign, z * nsign); s -= ds; glVertex3f(gl, x * radius, y * radius, z * radius); } @@ -1148,10 +1137,13 @@ public class GLUquadricImpl implements GLUquadric { } private final void glNormal3f(GL gl, float x, float y, float z) { + short a=(short)(x*0xFFFF); + short b=(short)(y*0xFFFF); + short c=(short)(z*0xFFFF); if(immModeSinkEnabled) { - immModeSink.glNormal3f(x, y, z); + immModeSink.glNormal3s(a, b, c); } else { - ((GL2)gl).glNormal3f(x, y, z); + ((GL2)gl).glNormal3s(a, b, c); } } @@ -1179,11 +1171,7 @@ public class GLUquadricImpl implements GLUquadric { y /= mag; z /= mag; } - if(immModeSinkEnabled) { - immModeSink.glNormal3f(x, y, z); - } else { - ((GL2)gl).glNormal3f(x, y, z); - } + glNormal3f(gl, x, y, z); } private final void TXTR_COORD(GL gl, float x, float y) { |