diff options
Diffstat (limited to 'src')
18 files changed, 1110 insertions, 169 deletions
diff --git a/src/classes/com/sun/opengl/impl/ProjectFloat.java b/src/classes/com/sun/opengl/impl/ProjectFloat.java index 4e6c4ac85..637377237 100755 --- a/src/classes/com/sun/opengl/impl/ProjectFloat.java +++ b/src/classes/com/sun/opengl/impl/ProjectFloat.java @@ -136,6 +136,13 @@ public class ProjectFloat { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; + private static final float[] ZERO_MATRIX = + new float[] { + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f }; + // Note that we have cloned parts of the implementation in order to // support incoming Buffers. The reason for this is to avoid loading // non-direct buffer subclasses unnecessarily, because doing so can @@ -201,16 +208,25 @@ public class ProjectFloat { /** * Make matrix an identity matrix */ - private void __gluMakeIdentityf(FloatBuffer m) { + public static void gluMakeIdentityf(FloatBuffer m) { int oldPos = m.position(); m.put(IDENTITY_MATRIX); m.position(oldPos); } /** + * Make matrix an zero matrix + */ + public static void gluMakeZero(FloatBuffer m) { + int oldPos = m.position(); + m.put(ZERO_MATRIX); + m.position(oldPos); + } + + /** * Make matrix an identity matrix */ - private void __gluMakeIdentityf(float[] m) { + private void gluMakeIdentityf(float[] m) { for (int i = 0; i < 16; i++) { m[i] = IDENTITY_MATRIX[i]; } @@ -269,7 +285,7 @@ public class ProjectFloat { temp[i][j] = src[i*4+j]; } } - __gluMakeIdentityf(inverse); + gluMakeIdentityf(inverse); for (i = 0; i < 4; i++) { // @@ -343,7 +359,7 @@ public class ProjectFloat { temp.put(i*4+j, src.get(i*4+j + srcPos)); } } - __gluMakeIdentityf(inverse); + gluMakeIdentityf(inverse); for (i = 0; i < 4; i++) { // @@ -403,7 +419,7 @@ public class ProjectFloat { * @param b * @param r */ - private void __gluMultMatricesf(float[] a, int a_offset, float[] b, int b_offset, float[] r) { + private void gluMultMatricesf(float[] a, int a_offset, float[] b, int b_offset, float[] r) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { r[i*4+j] = @@ -421,7 +437,7 @@ public class ProjectFloat { * @param b * @param r */ - private void __gluMultMatricesf(FloatBuffer a, FloatBuffer b, FloatBuffer r) { + public static void gluMultMatricesf(FloatBuffer a, FloatBuffer b, FloatBuffer r) { int aPos = a.position(); int bPos = b.position(); int rPos = r.position(); @@ -442,11 +458,11 @@ public class ProjectFloat { * * @param v */ - private static void normalize(float[] v) { + public static void normalize(float[] v) { float r; r = (float) Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); - if ( r == 0.0 ) + if ( r == 0.0 || r == 1.0) return; r = 1.0f / r; @@ -463,7 +479,7 @@ public class ProjectFloat { * * @param v */ - private static void normalize(FloatBuffer v) { + public static void normalize(FloatBuffer v) { float r; int vPos = v.position(); @@ -471,7 +487,7 @@ public class ProjectFloat { r = (float) Math.sqrt(v.get(0+vPos) * v.get(0+vPos) + v.get(1+vPos) * v.get(1+vPos) + v.get(2+vPos) * v.get(2+vPos)); - if ( r == 0.0 ) + if ( r == 0.0 || r == 1.0) return; r = 1.0f / r; @@ -522,7 +538,7 @@ public class ProjectFloat { * @param bottom * @param top */ - public void gluOrtho2D(GL2ES1 gl, float left, float right, float bottom, float top) { + public void gluOrtho2D(GL gl, float left, float right, float bottom, float top) { gl.glOrthof(left, right, bottom, top, -1, 1); } @@ -534,7 +550,7 @@ public class ProjectFloat { * @param zNear * @param zFar */ - public void gluPerspective(GL2ES1 gl, float fovy, float aspect, float zNear, float zFar) { + public void gluPerspective(GL gl, float fovy, float aspect, float zNear, float zFar) { float sine, cotangent, deltaZ; float radians = fovy / 2 * (float) Math.PI / 180; @@ -547,7 +563,7 @@ public class ProjectFloat { cotangent = (float) Math.cos(radians) / sine; - __gluMakeIdentityf(matrixBuf); + gluMakeIdentityf(matrixBuf); matrixBuf.put(0 * 4 + 0, cotangent / aspect); matrixBuf.put(1 * 4 + 1, cotangent); @@ -572,7 +588,7 @@ public class ProjectFloat { * @param upy * @param upz */ - public void gluLookAt(GL2ES1 gl, + public void gluLookAt(GL gl, float eyex, float eyey, float eyez, @@ -603,7 +619,7 @@ public class ProjectFloat { /* Recompute up as: up = side x forward */ cross(side, forward, up); - __gluMakeIdentityf(matrixBuf); + gluMakeIdentityf(matrixBuf); matrixBuf.put(0 * 4 + 0, side.get(0)); matrixBuf.put(1 * 4 + 0, side.get(1)); matrixBuf.put(2 * 4 + 0, side.get(2)); @@ -754,7 +770,7 @@ public class ProjectFloat { float[] in = this.in; float[] out = this.out; - __gluMultMatricesf(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, matrix); + gluMultMatricesf(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, matrix); if (!__gluInvertMatrixf(matrix, matrix)) return false; @@ -811,7 +827,7 @@ public class ProjectFloat { FloatBuffer in = this.inBuf; FloatBuffer out = this.outBuf; - __gluMultMatricesf(modelMatrix, projMatrix, matrixBuf); + gluMultMatricesf(modelMatrix, projMatrix, matrixBuf); if (!__gluInvertMatrixf(matrixBuf, matrixBuf)) return false; @@ -880,7 +896,7 @@ public class ProjectFloat { float[] in = this.in; float[] out = this.out; - __gluMultMatricesf(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, matrix); + gluMultMatricesf(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, matrix); if (!__gluInvertMatrixf(matrix, matrix)) return false; @@ -941,7 +957,7 @@ public class ProjectFloat { FloatBuffer in = this.inBuf; FloatBuffer out = this.outBuf; - __gluMultMatricesf(modelMatrix, projMatrix, matrixBuf); + gluMultMatricesf(modelMatrix, projMatrix, matrixBuf); if (!__gluInvertMatrixf(matrixBuf, matrixBuf)) return false; @@ -985,7 +1001,7 @@ public class ProjectFloat { * @param deltaY * @param viewport */ - public void gluPickMatrix(GL2ES1 gl, + public void gluPickMatrix(GL gl, float x, float y, float deltaX, @@ -1013,7 +1029,7 @@ public class ProjectFloat { * @param viewport * @param viewport_offset */ - public void gluPickMatrix(GL2ES1 gl, + public void gluPickMatrix(GL gl, float x, float y, float deltaX, diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java index 061a3eb38..60aed64be 100755 --- a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java @@ -55,7 +55,7 @@ public class EGLDrawable extends GLDrawableImpl { this.chooser = chooser; surface=EGL.EGL_NO_SURFACE; - display = EGL.eglGetDisplay((component.getDisplayHandle()>0)?component.getDisplayHandle():EGL.EGL_DEFAULT_DISPLAY); + display = EGL.eglGetDisplay((0!=component.getDisplayHandle())?component.getDisplayHandle():EGL.EGL_DEFAULT_DISPLAY); if (display == EGL.EGL_NO_DISPLAY) { throw new GLException("eglGetDisplay failed"); } diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java index 9f6d6b789..9ff4b7eac 100755 --- a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java +++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java @@ -79,6 +79,11 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { throw new GLException("Invalid GL Profile for EGL: "+GLProfile.getProfile()); } + // EGL Unix + glesLibNames.add("libEGL"); + // EGL Windows + glesLibNames.add("EGL"); + ClassLoader loader = getClass().getClassLoader(); for (Iterator iter = glesLibNames.iterator(); iter.hasNext(); ) { NativeLibrary lib = NativeLibrary.open((String) iter.next(), loader); @@ -92,11 +97,6 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { throw new GLException("Unable to dynamically load OpenGL ES library for profile \"" + GLProfile.getProfile() + "\""); } - // On the NVidia APX 2500 we need to separately load the EGL library - NativeLibrary eglLib = NativeLibrary.open("libEGL", loader); - if (eglLib != null) { - libs.add(eglLib); - } glesLibraries = libs; if (GLProfile.isGLES2()) { @@ -175,24 +175,20 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { public int[] glCapabilities2AttribList(GLCapabilities caps) { int[] attrs = new int[] { - EGL.EGL_DEPTH_SIZE, caps.getDepthBits(), - // FIXME: does this need to be configurable? - EGL.EGL_SURFACE_TYPE, EGL.EGL_WINDOW_BIT, - EGL.EGL_RED_SIZE, caps.getRedBits(), - EGL.EGL_GREEN_SIZE, caps.getGreenBits(), - EGL.EGL_BLUE_SIZE, caps.getBlueBits(), - EGL.EGL_ALPHA_SIZE, (caps.getAlphaBits() > 0 ? caps.getAlphaBits() : EGL.EGL_DONT_CARE), - EGL.EGL_STENCIL_SIZE, (caps.getStencilBits() > 0 ? caps.getStencilBits() : EGL.EGL_DONT_CARE), - EGL.EGL_NONE, EGL.EGL_NONE, - EGL.EGL_NONE - }; - - // FIXME: we need to query the EGL version to determine - // whether we are allowed to specify the renderable type - + EGL.EGL_RENDERABLE_TYPE, EGL.EGL_OPENGL_ES_BIT, + // FIXME: does this need to be configurable? + EGL.EGL_SURFACE_TYPE, EGL.EGL_WINDOW_BIT, + EGL.EGL_RED_SIZE, caps.getRedBits(), + EGL.EGL_GREEN_SIZE, caps.getGreenBits(), + EGL.EGL_BLUE_SIZE, caps.getBlueBits(), + EGL.EGL_ALPHA_SIZE, (caps.getAlphaBits() > 0 ? caps.getAlphaBits() : EGL.EGL_DONT_CARE), + EGL.EGL_STENCIL_SIZE, (caps.getStencilBits() > 0 ? caps.getStencilBits() : EGL.EGL_DONT_CARE), + EGL.EGL_DEPTH_SIZE, caps.getDepthBits(), + EGL.EGL_NONE + }; if (GLProfile.isGLES2()) { - attrs[attrs.length - 3] = EGL.EGL_RENDERABLE_TYPE; - attrs[attrs.length - 2] = EGL.EGL_OPENGL_ES2_BIT; + // ES 2 + attrs[1] = EGL.EGL_OPENGL_ES2_BIT; } return attrs; diff --git a/src/classes/com/sun/opengl/impl/es2/FixedFuncShader.java b/src/classes/com/sun/opengl/impl/es2/FixedFuncShader.java new file mode 100644 index 000000000..b0fe47b11 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/es2/FixedFuncShader.java @@ -0,0 +1,246 @@ + +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 && 0<=shaderLightsPos[light] ) { + glUseProgram(gl, true); + gl.glUniform4fv(shaderLightsPos[light], 1, params); + if(0<=shaderLightsSrc[light]) { + gl.glUniform1i(shaderLightsSrc[light], pname); + } + } + } + + public void glShadeModel(GL2ES2 gl, int mode) { + if(!shaderOk || 0>shaderShadeModel) return; + glUseProgram(gl, true); + gl.glUniform1i(shaderShadeModel, mode); + } + + 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++) { + shaderLightsPos[i] = gl.glGetUniformLocation(shaderProgram, "mgl_LightPos"+i); + shaderLightsSrc[i] = gl.glGetUniformLocation(shaderProgram, "mgl_LightSrc"+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; + protected int[] shaderLightsPos = new int[] { -1, -1, -1, -1, -1, -1, -1 }; + protected int[] shaderLightsSrc = new int[] { -1, -1, -1, -1, -1, -1, -1 }; + protected int shaderShadeModel = -1; + protected int shaderActiveTexture = -1; + +} + diff --git a/src/classes/com/sun/opengl/impl/es2/FixedFuncShaderVertexColor.java b/src/classes/com/sun/opengl/impl/es2/FixedFuncShaderVertexColor.java new file mode 100644 index 000000000..e3900d0b4 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/es2/FixedFuncShaderVertexColor.java @@ -0,0 +1,57 @@ + +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 new file mode 100644 index 000000000..039479c78 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/es2/FixedFuncShaderVertexColorTexture.java @@ -0,0 +1,60 @@ + +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 gl_MultiTexCoord0;\n"+ + "varying HIGHP vec4 frontColor;\n"+ + "void main(void)\n"+ + "{\n"+ + " frontColor=mgl_Color;\n"+ + " gl_TexCoord[0] = gl_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"+ + "void main (void)\n"+ + "{\n"+ + " vec4 texColor = texture2D(mgl_activeTexture,gl_TexCoord[0].st);\n"+ + " gl_FragColor = frontColor+texColor;\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 new file mode 100644 index 000000000..3a3c17811 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/es2/ShaderData.java @@ -0,0 +1,60 @@ + +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 new file mode 100644 index 000000000..30cf7e327 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/es2/VBOBufferDrawGLES2.java @@ -0,0 +1,70 @@ + +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 new file mode 100644 index 000000000..5897b9a79 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/gl2es1/VBOBufferDrawGL2ES1.java @@ -0,0 +1,70 @@ + +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/glu/GLUquadricImpl.java b/src/classes/com/sun/opengl/impl/glu/GLUquadricImpl.java index 667a4c780..8c2a4eef2 100644 --- a/src/classes/com/sun/opengl/impl/glu/GLUquadricImpl.java +++ b/src/classes/com/sun/opengl/impl/glu/GLUquadricImpl.java @@ -191,7 +191,7 @@ public class GLUquadricImpl implements GLUquadric { return res; } - public void resetImmModeSink(GL2ES1 gl) { + public void resetImmModeSink(GL gl) { if(immModeSinkEnabled) { immModeSink.reset(gl); } @@ -326,7 +326,7 @@ public class GLUquadricImpl implements GLUquadric { * @param slices Specifies the number of subdivisions around the z axis. * @param stacks Specifies the number of subdivisions along the z axis. */ - public void drawCylinder(GL2ES1 gl, float baseRadius, float topRadius, float height, int slices, int stacks) { + public void drawCylinder(GL gl, float baseRadius, float topRadius, float height, int slices, int stacks) { float da, r, dr, dz; float x, y, z, nz, nsign; @@ -345,7 +345,7 @@ public class GLUquadricImpl implements GLUquadric { // Z component of normal vectors if (drawStyle == GLU.GLU_POINT) { - glBegin(gl, GL2ES1.GL_POINTS); + glBegin(gl, GL.GL_POINTS); for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); @@ -368,7 +368,7 @@ public class GLUquadricImpl implements GLUquadric { z = 0.0f; r = baseRadius; for (j = 0; j <= stacks; j++) { - glBegin(gl, GL2ES1.GL_LINE_LOOP); + glBegin(gl, GL.GL_LINE_LOOP); for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); @@ -384,7 +384,7 @@ public class GLUquadricImpl implements GLUquadric { } else { // draw one ring at each end if (baseRadius != 0.0) { - glBegin(gl, GL2ES1.GL_LINE_LOOP); + glBegin(gl, GL.GL_LINE_LOOP); for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); @@ -394,7 +394,7 @@ public class GLUquadricImpl implements GLUquadric { glVertex3f(gl, (x * baseRadius), (y * baseRadius), 0.0f); } glEnd(gl); - glBegin(gl, GL2ES1.GL_LINE_LOOP); + glBegin(gl, GL.GL_LINE_LOOP); for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); @@ -407,7 +407,7 @@ public class GLUquadricImpl implements GLUquadric { } } // draw length lines - glBegin(gl, GL2ES1.GL_LINES); + glBegin(gl, GL.GL_LINES); for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); @@ -486,7 +486,7 @@ public class GLUquadricImpl implements GLUquadric { * (1, 0.5), at (0, r, 0) it is (0.5, 1), at (-r, 0, 0) it is (0, 0.5), and at * (0, -r, 0) it is (0.5, 0). */ - public void drawDisk(GL2ES1 gl, float innerRadius, float outerRadius, int slices, int loops) + public void drawDisk(GL gl, float innerRadius, float outerRadius, int slices, int loops) { float da, dr; @@ -562,7 +562,7 @@ public class GLUquadricImpl implements GLUquadric { /* draw loops */ for (l = 0; l <= loops; l++) { float r = innerRadius + l * dr; - glBegin(gl, GL2ES1.GL_LINE_LOOP); + glBegin(gl, GL.GL_LINE_LOOP); for (s = 0; s < slices; s++) { float a = s * da; glVertex2f(gl, r * sin(a), r * cos(a)); @@ -574,7 +574,7 @@ public class GLUquadricImpl implements GLUquadric { float a = s * da; float x = sin(a); float y = cos(a); - glBegin(gl, GL2ES1.GL_LINE_STRIP); + glBegin(gl, GL.GL_LINE_STRIP); for (l = 0; l <= loops; l++) { float r = innerRadius + l * dr; glVertex2f(gl, r * x, r * y); @@ -586,7 +586,7 @@ public class GLUquadricImpl implements GLUquadric { case GLU.GLU_POINT: { int s; - glBegin(gl, GL2ES1.GL_POINTS); + glBegin(gl, GL.GL_POINTS); for (s = 0; s < slices; s++) { float a = s * da; float x = sin(a); @@ -604,7 +604,7 @@ public class GLUquadricImpl implements GLUquadric { { if (innerRadius != 0.0) { float a; - glBegin(gl, GL2ES1.GL_LINE_LOOP); + glBegin(gl, GL.GL_LINE_LOOP); for (a = 0.0f; a < 2.0 * PI; a += da) { float x = innerRadius * sin(a); float y = innerRadius * cos(a); @@ -614,7 +614,7 @@ public class GLUquadricImpl implements GLUquadric { } { float a; - glBegin(gl, GL2ES1.GL_LINE_LOOP); + glBegin(gl, GL.GL_LINE_LOOP); for (a = 0; a < 2.0f * PI; a += da) { float x = outerRadius * sin(a); float y = outerRadius * cos(a); @@ -652,7 +652,7 @@ public class GLUquadricImpl implements GLUquadric { * is (1, 0.5), at (0, r, 0) it is (0.5, 1), at (-r, 0, 0) it is (0, 0.5), * and at (0, -r, 0) it is (0.5, 0). */ - public void drawPartialDisk(GL2ES1 gl, + public void drawPartialDisk(GL gl, float innerRadius, float outerRadius, int slices, @@ -735,7 +735,7 @@ public class GLUquadricImpl implements GLUquadric { if (innerRadius == .0f) { finish = loops - 1; /* Triangle strip for inner polygons */ - glBegin(gl, GL2ES1.GL_TRIANGLE_FAN); + glBegin(gl, GL.GL_TRIANGLE_FAN); if (textureFlag) { glTexCoord2f(gl, 0.5f, 0.5f); } @@ -810,7 +810,7 @@ public class GLUquadricImpl implements GLUquadric { } break; case GLU.GLU_POINT : - glBegin(gl, GL2ES1.GL_POINTS); + glBegin(gl, GL.GL_POINTS); for (i = 0; i < slices2; i++) { sintemp = sinCache[i]; costemp = cosCache[i]; @@ -830,7 +830,7 @@ public class GLUquadricImpl implements GLUquadric { break; case GLU.GLU_LINE : if (innerRadius == outerRadius) { - glBegin(gl, GL2ES1.GL_LINE_STRIP); + glBegin(gl, GL.GL_LINE_STRIP); for (i = 0; i <= slices; i++) { if (textureFlag) { @@ -847,7 +847,7 @@ public class GLUquadricImpl implements GLUquadric { texLow = radiusLow / outerRadius / 2; } - glBegin(gl, GL2ES1.GL_LINE_STRIP); + glBegin(gl, GL.GL_LINE_STRIP); for (i = 0; i <= slices; i++) { if (textureFlag) { glTexCoord2f(gl, texLow * sinCache[i] + 0.5f, @@ -860,7 +860,7 @@ public class GLUquadricImpl implements GLUquadric { for (i = 0; i < slices2; i++) { sintemp = sinCache[i]; costemp = cosCache[i]; - glBegin(gl, GL2ES1.GL_LINE_STRIP); + glBegin(gl, GL.GL_LINE_STRIP); for (j = 0; j <= loops; j++) { radiusLow = outerRadius - deltaRadius * ((float) j / loops); if (textureFlag) { @@ -881,7 +881,7 @@ public class GLUquadricImpl implements GLUquadric { for (i = 0; i <= slices; i += slices) { sintemp = sinCache[i]; costemp = cosCache[i]; - glBegin(gl, GL2ES1.GL_LINE_STRIP); + glBegin(gl, GL.GL_LINE_STRIP); for (j = 0; j <= loops; j++) { radiusLow = outerRadius - deltaRadius * ((float) j / loops); @@ -901,7 +901,7 @@ public class GLUquadricImpl implements GLUquadric { texLow = radiusLow / outerRadius / 2; } - glBegin(gl, GL2ES1.GL_LINE_STRIP); + glBegin(gl, GL.GL_LINE_STRIP); for (i = 0; i <= slices; i++) { if (textureFlag) { glTexCoord2f(gl, texLow * sinCache[i] + 0.5f, @@ -934,7 +934,7 @@ public class GLUquadricImpl implements GLUquadric { * 0.0 at the +y axis, to 0.25 at the +x axis, to 0.5 at the -y axis, to 0.75 * at the -x axis, and back to 1.0 at the +y axis. */ - public void drawSphere(GL2ES1 gl, float radius, int slices, int stacks) { + public void drawSphere(GL gl, float radius, int slices, int stacks) { // TODO float rho, drho, theta, dtheta; @@ -958,7 +958,7 @@ public class GLUquadricImpl implements GLUquadric { if (drawStyle == GLU.GLU_FILL) { if (!textureFlag) { // draw +Z end as a triangle fan - glBegin(gl, GL2ES1.GL_TRIANGLE_FAN); + glBegin(gl, GL.GL_TRIANGLE_FAN); if(USE_NORM_TXT) { glNormal3f(gl, 0.0f, 0.0f, 1.0f); } @@ -1024,7 +1024,7 @@ public class GLUquadricImpl implements GLUquadric { if (!textureFlag) { // draw -Z end as a triangle fan - glBegin(gl, GL2ES1.GL_TRIANGLE_FAN); + glBegin(gl, GL.GL_TRIANGLE_FAN); if(USE_NORM_TXT) { glNormal3f(gl, 0.0f, 0.0f, -1.0f); } @@ -1053,7 +1053,7 @@ public class GLUquadricImpl implements GLUquadric { i < stacks; i++) { // stack line at i==stacks-1 was missing here rho = i * drho; - glBegin(gl, GL2ES1.GL_LINE_LOOP); + glBegin(gl, GL.GL_LINE_LOOP); for (j = 0; j < slices; j++) { theta = j * dtheta; x = cos(theta) * sin(rho); @@ -1068,7 +1068,7 @@ public class GLUquadricImpl implements GLUquadric { // draw slice lines for (j = 0; j < slices; j++) { theta = j * dtheta; - glBegin(gl, GL2ES1.GL_LINE_STRIP); + glBegin(gl, GL.GL_LINE_STRIP); for (i = 0; i <= stacks; i++) { rho = i * drho; x = cos(theta) * sin(rho); @@ -1082,7 +1082,7 @@ public class GLUquadricImpl implements GLUquadric { } } else if (drawStyle == GLU.GLU_POINT) { // top and bottom-most points - glBegin(gl, GL2ES1.GL_POINTS); + glBegin(gl, GL.GL_POINTS); if (normals) glNormal3f(gl, 0.0f, 0.0f, nsign); glVertex3f(gl, 0.0f, 0.0f, radius); @@ -1115,7 +1115,7 @@ public class GLUquadricImpl implements GLUquadric { private static final float PI = (float)Math.PI; private static final int CACHE_SIZE = 240; - private final void glBegin(GL2ES1 gl, int mode) { + private final void glBegin(GL gl, int mode) { if(immModeSinkEnabled) { immModeSink.glBegin(mode); } else { @@ -1123,7 +1123,7 @@ public class GLUquadricImpl implements GLUquadric { } } - private final void glEnd(GL2ES1 gl) { + private final void glEnd(GL gl) { if(immModeSinkEnabled) { immModeSink.glEnd(gl, immModeSinkImmediate); } else { @@ -1131,7 +1131,7 @@ public class GLUquadricImpl implements GLUquadric { } } - private final void glVertex2f(GL2ES1 gl, float x, float y) { + private final void glVertex2f(GL gl, float x, float y) { if(immModeSinkEnabled) { immModeSink.glVertex2f(x, y); } else { @@ -1139,7 +1139,7 @@ public class GLUquadricImpl implements GLUquadric { } } - private final void glVertex3f(GL2ES1 gl, float x, float y, float z) { + private final void glVertex3f(GL gl, float x, float y, float z) { if(immModeSinkEnabled) { immModeSink.glVertex3f(x, y, z); } else { @@ -1147,7 +1147,7 @@ public class GLUquadricImpl implements GLUquadric { } } - private final void glNormal3f(GL2ES1 gl, float x, float y, float z) { + private final void glNormal3f(GL gl, float x, float y, float z) { if(immModeSinkEnabled) { immModeSink.glNormal3f(x, y, z); } else { @@ -1155,7 +1155,7 @@ public class GLUquadricImpl implements GLUquadric { } } - private final void glTexCoord2f(GL2ES1 gl, float x, float y) { + private final void glTexCoord2f(GL gl, float x, float y) { if(immModeSinkEnabled) { immModeSink.glTexCoord2f(x, y); } else { @@ -1170,7 +1170,7 @@ public class GLUquadricImpl implements GLUquadric { * @param y * @param z */ - private void normal3f(GL2ES1 gl, float x, float y, float z) { + private void normal3f(GL gl, float x, float y, float z) { float mag; mag = (float)Math.sqrt(x * x + y * y + z * z); @@ -1186,7 +1186,7 @@ public class GLUquadricImpl implements GLUquadric { } } - private final void TXTR_COORD(GL2ES1 gl, float x, float y) { + private final void TXTR_COORD(GL gl, float x, float y) { if (textureFlag) glTexCoord2f(gl, x,y); } diff --git a/src/classes/javax/media/opengl/GLProfile.java b/src/classes/javax/media/opengl/GLProfile.java index d4c8d4c6b..bc9709341 100644 --- a/src/classes/javax/media/opengl/GLProfile.java +++ b/src/classes/javax/media/opengl/GLProfile.java @@ -107,7 +107,7 @@ public class GLProfile { public static synchronized final void setProfileGL2ES1() { setProfile(new String[] { GLES1, GL2ES12, GL2 }); if(null==profile) { - throw new GLException("Profiles GLES1 and GL2 not available"); + throw new GLException("Profiles GLES1, GL2ES12 and GL2 not available"); } } @@ -117,7 +117,17 @@ public class GLProfile { public static synchronized final void setProfileGL2ES2() { setProfile(new String[] { GLES2, GL2ES12, GL2 }); if(null==profile) { - throw new GLException("Profiles GLES2 and GL2 not available"); + throw new GLException("Profiles GLES2, GL2ES12 and GL2 not available"); + } + } + + /** + * Selects a profile, implementing the interface GL + */ + public static synchronized final void setProfileGLAny() { + setProfile(new String[] { GLES2, GLES1, GL2ES12, GL2 }); + if(null==profile) { + throw new GLException("Profiles GLES2, GLES1, GL2ES12 and GL2 not available"); } } diff --git a/src/classes/javax/media/opengl/glu/GLUquadric.java b/src/classes/javax/media/opengl/glu/GLUquadric.java index 937d77f8b..c925917e9 100755 --- a/src/classes/javax/media/opengl/glu/GLUquadric.java +++ b/src/classes/javax/media/opengl/glu/GLUquadric.java @@ -1,6 +1,6 @@ package javax.media.opengl.glu; -import javax.media.opengl.GL2ES1; +import javax.media.opengl.GL; import javax.media.opengl.util.ImmModeSink; /** @@ -29,5 +29,5 @@ public interface GLUquadric { public ImmModeSink replaceImmModeSink(); // gl may be null, then the GL client states are not disabled - public void resetImmModeSink(GL2ES1 gl); + public void resetImmModeSink(GL gl); } diff --git a/src/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp b/src/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp index 3ead1a4e9..363d623cb 100755 --- a/src/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp +++ b/src/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp @@ -69,13 +69,18 @@ public class BufferUtil { return bb; } - public static ByteBuffer newByteBuffer(byte[] values) { - ByteBuffer bb = newByteBuffer(values.length); - bb.put(values); + public static ByteBuffer newByteBuffer(byte[] values, int offset) { + int len = values.length-offset; + ByteBuffer bb = newByteBuffer(len); + bb.put(values, offset, len); bb.rewind(); return bb; } + public static ByteBuffer newByteBuffer(byte[] values) { + return newByteBuffer(values, 0); + } + /** Allocates a new direct FloatBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order. */ @@ -84,13 +89,18 @@ public class BufferUtil { return bb.asFloatBuffer(); } - public static FloatBuffer newFloatBuffer(float[] values) { - FloatBuffer bb = newFloatBuffer(values.length); - bb.put(values); + public static FloatBuffer newFloatBuffer(float[] values, int offset) { + int len = values.length-offset; + FloatBuffer bb = newFloatBuffer(len); + bb.put(values, offset, len); bb.rewind(); return bb; } + public static FloatBuffer newFloatBuffer(float[] values) { + return newFloatBuffer(values, 0); + } + /** Allocates a new direct IntBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order. */ @@ -99,13 +109,19 @@ public class BufferUtil { return bb.asIntBuffer(); } - public static IntBuffer newIntBuffer(int[] values) { - IntBuffer bb = newIntBuffer(values.length); - bb.put(values); + public static IntBuffer newIntBuffer(int[] values, int offset) { + int len = values.length-offset; + IntBuffer bb = newIntBuffer(len); + bb.put(values, offset, len); bb.rewind(); return bb; } + public static IntBuffer newIntBuffer(int[] values) { + return newIntBuffer(values, 0); + } + + /** Allocates a new direct ShortBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order. */ @@ -114,13 +130,19 @@ public class BufferUtil { return bb.asShortBuffer(); } - public static ShortBuffer newShortBuffer(short[] values) { - ShortBuffer bb = newShortBuffer(values.length); - bb.put(values); + public static ShortBuffer newShortBuffer(short[] values, int offset) { + int len = values.length-offset; + ShortBuffer bb = newShortBuffer(len); + bb.put(values, offset, len); bb.rewind(); return bb; } + public static ShortBuffer newShortBuffer(short[] values) { + return newShortBuffer(values, 0); + } + + //---------------------------------------------------------------------- // Copy routines (type-to-type) // diff --git a/src/classes/javax/media/opengl/util/BufferUtil.java.javase b/src/classes/javax/media/opengl/util/BufferUtil.java.javase index 66a8acaff..944e4d8d4 100755 --- a/src/classes/javax/media/opengl/util/BufferUtil.java.javase +++ b/src/classes/javax/media/opengl/util/BufferUtil.java.javase @@ -69,13 +69,19 @@ public class BufferUtil { return bb; } - public static ByteBuffer newByteBuffer(byte[] values) { - ByteBuffer bb = newByteBuffer(values.length); - bb.put(values); + public static ByteBuffer newByteBuffer(byte[] values, int offset) { + int len = values.length-offset; + ByteBuffer bb = newByteBuffer(len); + bb.put(values, offset, len); bb.rewind(); return bb; } + public static ByteBuffer newByteBuffer(byte[] values) { + return newByteBuffer(values, 0); + } + + /** Allocates a new direct DoubleBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order. */ @@ -84,6 +90,19 @@ public class BufferUtil { return bb.asDoubleBuffer(); } + public static DoubleBuffer newDoubleBuffer(double[] values, int offset) { + int len = values.length-offset; + DoubleBuffer bb = newDoubleBuffer(len); + bb.put(values, offset, len); + bb.rewind(); + return bb; + } + + public static DoubleBuffer newDoubleBuffer(double[] values) { + return newDoubleBuffer(values, 0); + } + + /** Allocates a new direct FloatBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order. */ @@ -92,13 +111,19 @@ public class BufferUtil { return bb.asFloatBuffer(); } - public static FloatBuffer newFloatBuffer(float[] values) { - FloatBuffer bb = newFloatBuffer(values.length); - bb.put(values); + public static FloatBuffer newFloatBuffer(float[] values, int offset) { + int len = values.length-offset; + FloatBuffer bb = newFloatBuffer(len); + bb.put(values, offset, len); bb.rewind(); return bb; } + public static FloatBuffer newFloatBuffer(float[] values) { + return newFloatBuffer(values, 0); + } + + /** Allocates a new direct IntBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order. */ @@ -107,13 +132,18 @@ public class BufferUtil { return bb.asIntBuffer(); } - public static IntBuffer newIntBuffer(int[] values) { - IntBuffer bb = newIntBuffer(values.length); - bb.put(values); + public static IntBuffer newIntBuffer(int[] values, int offset) { + int len = values.length-offset; + IntBuffer bb = newIntBuffer(len); + bb.put(values, offset, len); bb.rewind(); return bb; } + public static IntBuffer newIntBuffer(int[] values) { + return newIntBuffer(values, 0); + } + /** Allocates a new direct LongBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order. */ @@ -130,13 +160,18 @@ public class BufferUtil { return bb.asShortBuffer(); } - public static ShortBuffer newShortBuffer(short[] values) { - ShortBuffer bb = newShortBuffer(values.length); - bb.put(values); + public static ShortBuffer newShortBuffer(short[] values, int offset) { + int len = values.length-offset; + ShortBuffer bb = newShortBuffer(len); + bb.put(values, offset, len); bb.rewind(); return bb; } + public static ShortBuffer newShortBuffer(short[] values) { + return newShortBuffer(values, 0); + } + //---------------------------------------------------------------------- // Copy routines (type-to-type) // diff --git a/src/classes/javax/media/opengl/util/FBObject.java b/src/classes/javax/media/opengl/util/FBObject.java index 867512445..8e27f65c6 100755 --- a/src/classes/javax/media/opengl/util/FBObject.java +++ b/src/classes/javax/media/opengl/util/FBObject.java @@ -36,7 +36,9 @@ package javax.media.opengl.util; import javax.media.opengl.*; public class FBObject { - private int fb, fbo_tex, depth_rb, stencil_rb, width, height, vStatus, attr; + private int width, height, attr; + private int fb, fbo_tex, depth_rb, stencil_rb, vStatus; + private int texInternalFormat, texDataFormat, texDataType; public static final int ATTR_DEPTH = 1 << 0; public static final int ATTR_STENCIL = 1 << 1; @@ -107,6 +109,29 @@ public class FBObject { } public void init(GL gl) { + int textureInternalFormat, textureDataFormat, textureDataType; + + if(gl.isGL2()) { + textureInternalFormat=GL.GL_RGBA8; + textureDataFormat=GL2.GL_BGRA; + textureDataType=GL2.GL_UNSIGNED_INT_8_8_8_8_REV; + } else if(gl.isGLES()) { + textureInternalFormat=GL.GL_RGBA; + textureDataFormat=GL.GL_RGBA; + textureDataType=GL.GL_UNSIGNED_SHORT_5_5_5_1; + } else { + textureInternalFormat=GL.GL_RGB; + textureDataFormat=GL.GL_RGB; + textureDataType=GL.GL_UNSIGNED_BYTE; + } + init(gl, textureInternalFormat, textureDataFormat, textureDataType); + } + + public void init(GL gl, int textureInternalFormat, int textureDataFormat, int textureDataType) { + texInternalFormat=textureInternalFormat; + texDataFormat=textureDataFormat; + texDataType=textureDataType; + // generate fbo .. int name[] = new int[1]; @@ -137,13 +162,8 @@ public class FBObject { gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fb); gl.glBindTexture(GL.GL_TEXTURE_2D, fbo_tex); - if(gl.isGL2()) { - gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA8, width, height, 0, - GL2.GL_BGRA, GL2.GL_UNSIGNED_INT_8_8_8_8_REV, null); - } else { - gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB8, width, height, 0, - GL.GL_RGB, GL.GL_UNSIGNED_BYTE, null); - } + gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, texInternalFormat, width, height, 0, + texDataFormat, texDataType, null); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); //gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL2.GL_CLAMP); diff --git a/src/classes/javax/media/opengl/util/PMVMatrix.java b/src/classes/javax/media/opengl/util/PMVMatrix.java new file mode 100755 index 000000000..4e8693be0 --- /dev/null +++ b/src/classes/javax/media/opengl/util/PMVMatrix.java @@ -0,0 +1,310 @@ + +package javax.media.opengl.util; + +import javax.media.opengl.*; +import com.sun.opengl.impl.ProjectFloat; +import java.nio.*; +import java.util.ArrayList; +import java.util.List; + +public class PMVMatrix { + + protected ProjectFloat pvmProjectf = null; + protected FloatBuffer matrixPMV, matrixP, matrixMV; + protected FloatBuffer matrixTemp, matrixTrans, matrixRot, matrixScale, matrixOrtho, matrixPersp, matrixFrustum; + protected float[] vec3f; + protected List/*FloatBuffer*/ matrixPStack, matrixMVStack; + protected int matrixMode = GL.GL_MODELVIEW; + protected boolean modifiedPMV = false; + + public PMVMatrix() { + pvmProjectf = new ProjectFloat(); + + matrixPMV = BufferUtil.newFloatBuffer(2*16); + matrixP = slice(matrixPMV, 0*16, 16); + matrixMV = slice(matrixPMV, 1*16, 16); + matrixPMV.rewind(); + + FloatBuffer buf = BufferUtil.newFloatBuffer(7*16); + + matrixTemp=slice(buf, 0*16, 16); + + matrixTrans=slice(buf, 1*16, 16); + pvmProjectf.gluMakeIdentityf(matrixTrans); + + matrixRot=slice(buf, 2*16, 16); + pvmProjectf.gluMakeIdentityf(matrixRot); + + matrixScale=slice(buf, 3*16, 16); + pvmProjectf.gluMakeIdentityf(matrixScale); + + matrixOrtho=slice(buf, 4*16, 16); + pvmProjectf.gluMakeIdentityf(matrixOrtho); + + matrixFrustum=slice(buf, 5*16, 16); + pvmProjectf.gluMakeZero(matrixFrustum); + + matrixPersp=slice(buf, 6*16, 16); + pvmProjectf.gluMakeIdentityf(matrixPersp); + + vec3f=new float[3]; + + matrixPStack = new ArrayList(); + matrixMVStack= new ArrayList(); + + // default values and mode + glMatrixMode(GL.GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL.GL_MODELVIEW); + glLoadIdentity(); + modifiedPMV = true; + } + + private static FloatBuffer slice(FloatBuffer buf, int pos, int len) { + buf.position(pos); + buf.limit(pos + len); + return buf.slice(); + } + + public boolean isDirty() { + return modifiedPMV; + } + + public void clear() { + modifiedPMV=false; + } + + public final int glGetMatrixMode() { + return matrixMode; + } + + public void glMatrixMode(int matrixName) { + switch(matrixName) { + case GL.GL_MODELVIEW: + case GL.GL_PROJECTION: + break; + default: + throw new GLUnsupportedException("unsupported matrixName: "+matrixName); + } + matrixMode = matrixName; + } + + public final FloatBuffer glGetPMVMatrixf() { + return matrixPMV; + } + + public final FloatBuffer glGetMatrixf() { + return glGetMatrixf(matrixMode); + } + + public final FloatBuffer glGetMatrixf(int matrixName) { + if(matrixName==GL.GL_MODELVIEW) { + return matrixMV; + } else if(matrixName==GL.GL_PROJECTION) { + return matrixP; + } + return null; + } + + public void glLoadMatrixf(java.nio.FloatBuffer m) { + if(matrixMode==GL.GL_MODELVIEW) { + matrixMV.clear(); + matrixMV.put(m); + matrixMV.rewind(); + } else if(matrixMode==GL.GL_PROJECTION) { + matrixP.clear(); + matrixP.put(m); + matrixP.rewind(); + } + modifiedPMV = true; + } + + public void glPopMatrix() { + if(matrixMode==GL.GL_MODELVIEW) { + matrixMV=(FloatBuffer)matrixMVStack.remove(0); + } else if(matrixMode==GL.GL_PROJECTION) { + matrixP=(FloatBuffer)matrixPStack.remove(0); + } + modifiedPMV = true; + } + + public void glPushMatrix() { + if(matrixMode==GL.GL_MODELVIEW) { + matrixMVStack.add(0, matrixMV); + } else if(matrixMode==GL.GL_PROJECTION) { + matrixPStack.add(0, matrixP); + } + } + + public void glLoadIdentity() { + if(matrixMode==GL.GL_MODELVIEW) { + matrixMV.clear(); + pvmProjectf.gluMakeIdentityf(matrixMV); + matrixMV.rewind(); + } else if(matrixMode==GL.GL_PROJECTION) { + matrixP.clear(); + pvmProjectf.gluMakeIdentityf(matrixP); + matrixP.rewind(); + } + modifiedPMV = true; + } + + public void glMultMatrixf(FloatBuffer m) { + if(matrixMode==GL.GL_MODELVIEW) { + pvmProjectf.gluMultMatricesf(m, matrixMV, matrixTemp); + matrixMV.clear(); + matrixMV.put(matrixTemp); + matrixMV.rewind(); + } else if(matrixMode==GL.GL_PROJECTION) { + pvmProjectf.gluMultMatricesf(m, matrixP, matrixTemp); + matrixP.clear(); + matrixP.put(matrixTemp); + matrixP.rewind(); + } + matrixTemp.rewind(); + modifiedPMV = true; + } + + public void glTranslatef(float x, float y, float z) { + // Translation matrix: + // 1 0 0 0 + // 0 1 0 0 + // 0 0 1 0 + // x y z 1 + matrixTrans.put(3*4+0, x); + matrixTrans.put(3*4+1, y); + matrixTrans.put(3*4+2, z); + + glMultMatrixf(matrixTrans); + } + + public void glRotatef(float angdeg, float x, float y, float z) { + float angrad = angdeg * (float) Math.PI / 180; + float c = (float)Math.cos(angrad); + float ic= 1.0f - c; + float s = (float)Math.sin(angrad); + + vec3f[0]=x; vec3f[1]=y; vec3f[2]=z; + pvmProjectf.normalize(vec3f); + x = vec3f[0]; y = vec3f[1]; z = vec3f[2]; + + // Rotation matrix: + // xx(1−c)+c xy(1−c)+zs xz(1−c)-ys 0 + // xy(1−c)-zs yy(1−c)+c yz(1−c)+xs 0 + // xz(1−c)+ys yz(1−c)-xs zz(1−c)+c 0 + // 0 0 0 1 + float xy = x*y; + float xz = x*z; + float xs = x*s; + float ys = y*s; + float yz = y*z; + float zs = z*s; + matrixRot.put(0*4+0, x*x*ic+c); + matrixRot.put(0*4+1, xy*ic+zs); + matrixRot.put(0*4+2, xz*ic-ys); + + matrixRot.put(1*4+0, xy*ic-zs); + matrixRot.put(1*4+1, y*y*ic+c); + matrixRot.put(1*4+2, yz*ic+xs); + + matrixRot.put(2*4+0, xz*ic+ys); + matrixRot.put(2*4+1, yz*ic-xs); + matrixRot.put(2*4+2, z*z*ic+c); + + glMultMatrixf(matrixRot); + } + + public void glScalef(float x, float y, float z) { + // Scale matrix: + // x 0 0 0 + // 0 y 0 0 + // 0 0 z 0 + // 0 0 0 1 + matrixScale.put(0*4+0, x); + matrixScale.put(1*4+1, y); + matrixScale.put(2*4+2, z); + + glMultMatrixf(matrixScale); + } + + public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) { + // Ortho matrix: + // 2/dx 0 0 0 + // 0 2/dy 0 0 + // 0 0 2/dz 0 + // tx tx tx 1 + float dx=right-left; + float dy=top-bottom; + float dz=zFar-zNear; + float tx=-1.0f*(right+left)/dx; + float ty=-1.0f*(top+bottom)/dy; + float tz=-1.0f*(zFar+zNear)/dz; + + matrixOrtho.put(0*4+0, 2.0f/dx); + matrixOrtho.put(1*4+1, 2.0f/dy); + matrixOrtho.put(2*4+2, -2.0f/dz); + matrixOrtho.put(3*4+0, tx); + matrixOrtho.put(3*4+1, ty); + matrixOrtho.put(3*4+2, tz); + + glMultMatrixf(matrixOrtho); + } + + public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) { + if(zNear<=0.0f||zFar<0.0f) { + throw new GLException("GL_INVALID_VALUE: zNear and zFar must be positive, and zNear>0"); + } + if(left==right || top==bottom) { + throw new GLException("GL_INVALID_VALUE: top,bottom and left,right must not be equal"); + } + // Frustum matrix: + // 2*zNear/dx 0 A 0 + // 0 2*zNear/dy B 0 + // 0 0 C D + // 0 0 −1 0 + float zNear2 = 2.0f*zNear; + float dx=right-left; + float dy=top-bottom; + float dz=zFar-zNear; + float A=(right+left)/dx; + float B=(top+bottom)/dy; + float C=-1.0f*(zFar+zNear)/dz; + float D=-2.0f*(zFar*zNear)/dz; + + matrixFrustum.put(0*4+0, zNear2/dx); + matrixFrustum.put(1*4+1, zNear2/dy); + matrixFrustum.put(2*4+2, C); + matrixFrustum.put(0*4+2, A); + matrixFrustum.put(1*4+2, B); + matrixFrustum.put(2*4+3, D); + matrixFrustum.put(3*4+2, -1.0f); + + glMultMatrixf(matrixFrustum); + } + + public void gluPerspective(float fovy, float aspect, float zNear, float zFar) { + float radians = fovy/2 * (float) Math.PI / 180; + + float sine, cotangent, deltaZ; + + deltaZ = zFar - zNear; + sine = (float) Math.sin(radians); + + if ((deltaZ == 0.0f) || (sine == 0.0f) || (aspect == 0.0f)) { + return; + } + + cotangent = (float) Math.cos(radians) / sine; + + matrixPersp.put(0 * 4 + 0, cotangent / aspect); + matrixPersp.put(1 * 4 + 1, cotangent); + matrixPersp.put(2 * 4 + 2, - (zFar + zNear) / deltaZ); + matrixPersp.put(2 * 4 + 3, -1); + matrixPersp.put(3 * 4 + 2, -2 * zNear * zFar / deltaZ); + matrixPersp.put(3 * 4 + 3, 0); + + glMultMatrixf(matrixPersp); + } +} + + diff --git a/src/classes/javax/media/opengl/util/VBOBufferDraw.java b/src/classes/javax/media/opengl/util/VBOBufferDraw.java index 34b1be0b1..8ce1b3232 100644 --- a/src/classes/javax/media/opengl/util/VBOBufferDraw.java +++ b/src/classes/javax/media/opengl/util/VBOBufferDraw.java @@ -2,16 +2,22 @@ package javax.media.opengl.util; import javax.media.opengl.*; -import javax.media.opengl.util.gl2es1.VBOBufferDrawGL2ES1; import java.nio.*; +import com.sun.opengl.impl.*; public abstract class VBOBufferDraw { public static VBOBufferDraw create(int glArrayType, int glDataType, int glBufferUsage, int comps, int initialSize) throws GLException { + Class[] types = new Class[]{ int.class, int.class, int.class, int.class, int.class }; + Object[] args = new Integer[]{ new Integer(glArrayType), new Integer(glDataType), new Integer(glBufferUsage), + new Integer(comps), new Integer(initialSize) } ; + if(GLProfile.isGL2ES1()) { - return new VBOBufferDrawGL2ES1(glArrayType, glDataType, glBufferUsage, comps, initialSize); + return (VBOBufferDraw) GLReflection.createInstance("com.sun.opengl.impl.gl2es1.VBOBufferDrawGL2ES1", types, args); + } else if(GLProfile.isGLES2()) { + return (VBOBufferDraw) GLReflection.createInstance("com.sun.opengl.impl.es2.VBOBufferDrawGLES2", types, args); } throw new GLException("VBOBufferDraw not supported for profile: "+GLProfile.getProfile()); } @@ -19,9 +25,14 @@ public abstract class VBOBufferDraw { protected void init(int glArrayType, int glDataType, int glBufferUsage, int comps, int initialSize) throws GLException { + vboUsage=true; + switch(glArrayType) { case GL2ES1.GL_VERTEX_ARRAY: case GL2ES1.GL_NORMAL_ARRAY: + if(3!=comps && 0!=comps) { + throw new GLException("component size for NORMAL_ARRAY must be 3 or 0: "+comps+" \n\t"+this); + } case GL2ES1.GL_COLOR_ARRAY: case GL2ES1.GL_TEXTURE_COORD_ARRAY: break; @@ -50,6 +61,13 @@ public abstract class VBOBufferDraw { growVBO(initialSize); } + public boolean usesVBO() { return vboUsage; } + + public void setVBOUsage(boolean vboUsage) { + checkSeal(false); + this.vboUsage=vboUsage; + } + public int getGLArrayType() { return glArrayType; } @@ -99,7 +117,7 @@ public abstract class VBOBufferDraw { } private final void init_vbo(GL gl) { - if(vboName==0) { + if(vboUsage && vboName==0) { int[] tmp = new int[1]; gl.glGenBuffers(1, tmp, 0); vboName = tmp[0]; @@ -350,6 +368,7 @@ public abstract class VBOBufferDraw { ", components "+components+ ", initialSize "+initialSize+ ", glBufferUsage "+glBufferUsage+ + ", vboUsage "+vboUsage+ ", vboName "+vboName+ ", sealed "+sealed+ ", bufferEnabled "+bufferEnabled+ @@ -367,6 +386,7 @@ public abstract class VBOBufferDraw { protected int vboName; protected boolean sealed; protected boolean bufferEnabled; + protected boolean vboUsage; } diff --git a/src/classes/javax/media/opengl/util/gl2es1/VBOBufferDrawGL2ES1.java b/src/classes/javax/media/opengl/util/gl2es1/VBOBufferDrawGL2ES1.java deleted file mode 100644 index fbca6b569..000000000 --- a/src/classes/javax/media/opengl/util/gl2es1/VBOBufferDrawGL2ES1.java +++ /dev/null @@ -1,51 +0,0 @@ - -package javax.media.opengl.util.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); - } - - protected void enableBufferGLImpl(GL _gl, boolean newData) { - GL2ES1 gl = _gl.getGL2ES1(); - if(!bufferEnabled && null!=buffer) { - gl.glEnableClientState(glArrayType); - gl.glBindBuffer(GL2ES1.GL_ARRAY_BUFFER, vboName); - if(newData) { - gl.glBufferData(GL2ES1.GL_ARRAY_BUFFER, buffer.limit() * getBufferCompSize(), buffer, glBufferUsage); - } - switch(glArrayType) { - case GL2ES1.GL_VERTEX_ARRAY: - gl.glVertexPointer(components, glDataType, 0, 0); - break; - case GL2ES1.GL_NORMAL_ARRAY: - gl.glNormalPointer(components, glDataType, 0); - break; - case GL2ES1.GL_COLOR_ARRAY: - gl.glColorPointer(components, glDataType, 0, 0); - break; - case GL2ES1.GL_TEXTURE_COORD_ARRAY: - gl.glTexCoordPointer(components, glDataType, 0, 0); - break; - default: - throw new GLException("invalid glArrayType: "+glArrayType+":\n\t"+this); - } - bufferEnabled = true; - } - } - - protected void disableBufferGLImpl(GL _gl) { - GL2ES1 gl = _gl.getGL2ES1(); - if(bufferEnabled && null!=buffer) { - gl.glDisableClientState(glArrayType); - bufferEnabled = false; - } - } - -} - |