diff options
Diffstat (limited to 'src/classes/javax')
8 files changed, 456 insertions, 90 deletions
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; - } - } - -} - |