diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/classes/com/sun/javafx/newt/KeyEvent.java | 2 | ||||
-rwxr-xr-x | src/classes/com/sun/javafx/newt/Window.java | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/GLUquadricImpl.java | 366 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/ImageUtil.java | 1 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/util/ImmModeSink.java | 318 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/util/VBOBufferDraw.java | 389 | ||||
-rwxr-xr-x | src/classes/javax/media/opengl/glu/GLUquadric.java | 11 | ||||
-rwxr-xr-x | src/native/jogl/X11Window.c | 2 |
8 files changed, 937 insertions, 154 deletions
diff --git a/src/classes/com/sun/javafx/newt/KeyEvent.java b/src/classes/com/sun/javafx/newt/KeyEvent.java index 47d7d1f7d..26e306687 100644 --- a/src/classes/com/sun/javafx/newt/KeyEvent.java +++ b/src/classes/com/sun/javafx/newt/KeyEvent.java @@ -57,7 +57,7 @@ public class KeyEvent extends InputEvent public String toString() { return "KeyEvent["+getEventTypeString(eventType)+ - ", code "+keyCode+", char "+keyChar+", "+super.toString(); + ", code "+keyCode+", char "+keyChar+", isActionKey "+isActionKey()+" "+super.toString(); } public static String getEventTypeString(int type) { diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java index b5a0db6bb..8c1cecd3f 100755 --- a/src/classes/com/sun/javafx/newt/Window.java +++ b/src/classes/com/sun/javafx/newt/Window.java @@ -43,7 +43,7 @@ public abstract class Window implements NativeWindow { public static final boolean DEBUG_MOUSE_EVENT = false; public static final boolean DEBUG_KEY_EVENT = false; - public static final boolean DEBUG_IMPLEMENTATION = true; + public static final boolean DEBUG_IMPLEMENTATION = false; protected static Window create(String type, Screen screen, int visualID) { try { diff --git a/src/classes/com/sun/opengl/impl/GLUquadricImpl.java b/src/classes/com/sun/opengl/impl/GLUquadricImpl.java index a8df92309..7422e8c15 100644 --- a/src/classes/com/sun/opengl/impl/GLUquadricImpl.java +++ b/src/classes/com/sun/opengl/impl/GLUquadricImpl.java @@ -115,8 +115,10 @@ package com.sun.opengl.impl; +import com.sun.opengl.util.ImmModeSink; import javax.media.opengl.*; import javax.media.opengl.glu.*; +import java.nio.*; /** * GLUquadricImpl.java @@ -124,7 +126,7 @@ import javax.media.opengl.glu.*; * * Created 22-dec-2003 (originally Quadric.java) * @author Erik Duijs - * @author Kenneth Russell + * @author Kenneth Russell, Sven Gothel */ public class GLUquadricImpl implements GLUquadric { @@ -132,12 +134,41 @@ public class GLUquadricImpl implements GLUquadric { private int orientation; private boolean textureFlag; private int normals; + private boolean vboImmediateDraw; + + public static final boolean USE_NORM_TXT = false; + + private ImmModeSink vboBuffer; public GLUquadricImpl() { drawStyle = GLU.GLU_FILL; orientation = GLU.GLU_OUTSIDE; textureFlag = false; normals = GLU.GLU_SMOOTH; + if(USE_NORM_TXT) { + vboBuffer = new ImmModeSink(GL.GL_FLOAT, GL.GL_STATIC_DRAW, 3, 3, 0, 3, 32); + } else { + vboBuffer = new ImmModeSink(GL.GL_FLOAT, GL.GL_STATIC_DRAW, 3, 0, 0, 0, 32); + } + vboImmediateDraw=true; + } + + public void setVBOImmediateMode(boolean val) { + this.vboImmediateDraw=val; + } + + public ImmModeSink replaceVBOBuffer() { + ImmModeSink res = vboBuffer; + if(USE_NORM_TXT) { + vboBuffer = new ImmModeSink(GL.GL_FLOAT, GL.GL_STATIC_DRAW, 3, 3, 0, 3, 32); + } else { + vboBuffer = new ImmModeSink(GL.GL_FLOAT, GL.GL_STATIC_DRAW, 3, 0, 0, 0, 32); + } + return res; + } + + public void resetVBOBuffer(GL gl) { + vboBuffer.reset(gl); } /** @@ -243,6 +274,7 @@ public class GLUquadricImpl implements GLUquadric { return textureFlag; } + /** * draws a cylinder oriented along the z axis. The base of the * cylinder is placed at z = 0, and the top at z=height. Like a sphere, a @@ -287,69 +319,79 @@ public class GLUquadricImpl implements GLUquadric { // Z component of normal vectors if (drawStyle == GLU.GLU_POINT) { - gl.glBegin(GL.GL_POINTS); + vboBuffer.glBegin(GL.GL_POINTS); for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); - normal3f(gl, x * nsign, y * nsign, nz * nsign); + if(USE_NORM_TXT) { + normal3f(gl, x * nsign, y * nsign, nz * nsign); + } z = 0.0f; r = baseRadius; for (j = 0; j <= stacks; j++) { - gl.glVertex3f((x * r), (y * r), z); + vboBuffer.glVertex3f((x * r), (y * r), z); z += dz; r += dr; } } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } else if (drawStyle == GLU.GLU_LINE || drawStyle == GLU.GLU_SILHOUETTE) { // Draw rings if (drawStyle == GLU.GLU_LINE) { z = 0.0f; r = baseRadius; for (j = 0; j <= stacks; j++) { - gl.glBegin(GL.GL_LINE_LOOP); + vboBuffer.glBegin(GL.GL_LINE_LOOP); for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); - normal3f(gl, x * nsign, y * nsign, nz * nsign); - gl.glVertex3f((x * r), (y * r), z); + if(USE_NORM_TXT) { + normal3f(gl, x * nsign, y * nsign, nz * nsign); + } + vboBuffer.glVertex3f((x * r), (y * r), z); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); z += dz; r += dr; } } else { // draw one ring at each end if (baseRadius != 0.0) { - gl.glBegin(GL.GL_LINE_LOOP); + vboBuffer.glBegin(GL.GL_LINE_LOOP); for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); - normal3f(gl, x * nsign, y * nsign, nz * nsign); - gl.glVertex3f((x * baseRadius), (y * baseRadius), 0.0f); + if(USE_NORM_TXT) { + normal3f(gl, x * nsign, y * nsign, nz * nsign); + } + vboBuffer.glVertex3f((x * baseRadius), (y * baseRadius), 0.0f); } - gl.glEnd(); - gl.glBegin(GL.GL_LINE_LOOP); + vboBuffer.glEnd(gl, vboImmediateDraw); + vboBuffer.glBegin(GL.GL_LINE_LOOP); for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); - normal3f(gl, x * nsign, y * nsign, nz * nsign); - gl.glVertex3f((x * topRadius), (y * topRadius), height); + if(USE_NORM_TXT) { + normal3f(gl, x * nsign, y * nsign, nz * nsign); + } + vboBuffer.glVertex3f((x * topRadius), (y * topRadius), height); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } } // draw length lines - gl.glBegin(GL.GL_LINES); + vboBuffer.glBegin(GL.GL_LINES); for (i = 0; i < slices; i++) { x = cos((i * da)); y = sin((i * da)); - normal3f(gl, x * nsign, y * nsign, nz * nsign); - gl.glVertex3f((x * baseRadius), (y * baseRadius), 0.0f); - gl.glVertex3f((x * topRadius), (y * topRadius), (height)); + if(USE_NORM_TXT) { + normal3f(gl, x * nsign, y * nsign, nz * nsign); + } + vboBuffer.glVertex3f((x * baseRadius), (y * baseRadius), 0.0f); + vboBuffer.glVertex3f((x * topRadius), (y * topRadius), (height)); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } else if (drawStyle == GLU.GLU_FILL) { float ds = 1.0f / slices; float dt = 1.0f / stacks; @@ -358,7 +400,7 @@ public class GLUquadricImpl implements GLUquadric { r = baseRadius; for (j = 0; j < stacks; j++) { float s = 0.0f; - gl.glBegin(GL.GL_QUAD_STRIP); + vboBuffer.glBegin(vboBuffer.GL_QUAD_STRIP); for (i = 0; i <= slices; i++) { if (i == slices) { x = sin(0.0f); @@ -368,23 +410,31 @@ public class GLUquadricImpl implements GLUquadric { y = cos((i * da)); } if (nsign == 1.0f) { - normal3f(gl, (x * nsign), (y * nsign), (nz * nsign)); - TXTR_COORD(gl, s, t); - gl.glVertex3f((x * r), (y * r), z); - normal3f(gl, (x * nsign), (y * nsign), (nz * nsign)); - TXTR_COORD(gl, s, t + dt); - gl.glVertex3f((x * (r + dr)), (y * (r + dr)), (z + dz)); + if(USE_NORM_TXT) { + normal3f(gl, (x * nsign), (y * nsign), (nz * nsign)); + TXTR_COORD(vboBuffer, s, t); + } + vboBuffer.glVertex3f((x * r), (y * r), z); + if(USE_NORM_TXT) { + normal3f(gl, (x * nsign), (y * nsign), (nz * nsign)); + TXTR_COORD(vboBuffer, s, t + dt); + } + vboBuffer.glVertex3f((x * (r + dr)), (y * (r + dr)), (z + dz)); } else { - normal3f(gl, x * nsign, y * nsign, nz * nsign); - TXTR_COORD(gl, s, t); - gl.glVertex3f((x * r), (y * r), z); - normal3f(gl, x * nsign, y * nsign, nz * nsign); - TXTR_COORD(gl, s, t + dt); - gl.glVertex3f((x * (r + dr)), (y * (r + dr)), (z + dz)); + if(USE_NORM_TXT) { + normal3f(gl, x * nsign, y * nsign, nz * nsign); + TXTR_COORD(vboBuffer, s, t); + } + vboBuffer.glVertex3f((x * r), (y * r), z); + if(USE_NORM_TXT) { + normal3f(gl, x * nsign, y * nsign, nz * nsign); + TXTR_COORD(vboBuffer, s, t + dt); + } + vboBuffer.glVertex3f((x * (r + dr)), (y * (r + dr)), (z + dz)); } s += ds; } // for slices - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); r += dr; t += dt; z += dz; @@ -417,10 +467,10 @@ public class GLUquadricImpl implements GLUquadric { /* Normal vectors */ if (normals != GLU.GLU_NONE) { if (orientation == GLU.GLU_OUTSIDE) { - gl.glNormal3f(0.0f, 0.0f, +1.0f); + vboBuffer.glNormal3f(0.0f, 0.0f, +1.0f); } else { - gl.glNormal3f(0.0f, 0.0f, -1.0f); + vboBuffer.glNormal3f(0.0f, 0.0f, -1.0f); } } @@ -442,7 +492,7 @@ public class GLUquadricImpl implements GLUquadric { float r2 = r1 + dr; if (orientation == GLU.GLU_OUTSIDE) { int s; - gl.glBegin(gl.GL_QUAD_STRIP); + vboBuffer.glBegin(vboBuffer.GL_QUAD_STRIP); for (s = 0; s <= slices; s++) { float a; if (s == slices) @@ -451,16 +501,16 @@ public class GLUquadricImpl implements GLUquadric { a = s * da; sa = sin(a); ca = cos(a); - TXTR_COORD(gl, 0.5f + sa * r2 / dtc, 0.5f + ca * r2 / dtc); - gl.glVertex2f(r2 * sa, r2 * ca); - TXTR_COORD(gl, 0.5f + sa * r1 / dtc, 0.5f + ca * r1 / dtc); - gl.glVertex2f(r1 * sa, r1 * ca); + TXTR_COORD(vboBuffer, 0.5f + sa * r2 / dtc, 0.5f + ca * r2 / dtc); + vboBuffer.glVertex2f(r2 * sa, r2 * ca); + TXTR_COORD(vboBuffer, 0.5f + sa * r1 / dtc, 0.5f + ca * r1 / dtc); + vboBuffer.glVertex2f(r1 * sa, r1 * ca); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } else { int s; - gl.glBegin(GL.GL_QUAD_STRIP); + vboBuffer.glBegin(vboBuffer.GL_QUAD_STRIP); for (s = slices; s >= 0; s--) { float a; if (s == slices) @@ -469,12 +519,12 @@ public class GLUquadricImpl implements GLUquadric { a = s * da; sa = sin(a); ca = cos(a); - TXTR_COORD(gl, 0.5f - sa * r2 / dtc, 0.5f + ca * r2 / dtc); - gl.glVertex2f(r2 * sa, r2 * ca); - TXTR_COORD(gl, 0.5f - sa * r1 / dtc, 0.5f + ca * r1 / dtc); - gl.glVertex2f(r1 * sa, r1 * ca); + TXTR_COORD(vboBuffer, 0.5f - sa * r2 / dtc, 0.5f + ca * r2 / dtc); + vboBuffer.glVertex2f(r2 * sa, r2 * ca); + TXTR_COORD(vboBuffer, 0.5f - sa * r1 / dtc, 0.5f + ca * r1 / dtc); + vboBuffer.glVertex2f(r1 * sa, r1 * ca); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } r1 = r2; } @@ -486,31 +536,31 @@ public class GLUquadricImpl implements GLUquadric { /* draw loops */ for (l = 0; l <= loops; l++) { float r = innerRadius + l * dr; - gl.glBegin(GL.GL_LINE_LOOP); + vboBuffer.glBegin(GL.GL_LINE_LOOP); for (s = 0; s < slices; s++) { float a = s * da; - gl.glVertex2f(r * sin(a), r * cos(a)); + vboBuffer.glVertex2f(r * sin(a), r * cos(a)); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } /* draw spokes */ for (s = 0; s < slices; s++) { float a = s * da; float x = sin(a); float y = cos(a); - gl.glBegin(GL.GL_LINE_STRIP); + vboBuffer.glBegin(GL.GL_LINE_STRIP); for (l = 0; l <= loops; l++) { float r = innerRadius + l * dr; - gl.glVertex2f(r * x, r * y); + vboBuffer.glVertex2f(r * x, r * y); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } break; } case GLU.GLU_POINT: { int s; - gl.glBegin(GL.GL_POINTS); + vboBuffer.glBegin(GL.GL_POINTS); for (s = 0; s < slices; s++) { float a = s * da; float x = sin(a); @@ -518,33 +568,33 @@ public class GLUquadricImpl implements GLUquadric { int l; for (l = 0; l <= loops; l++) { float r = innerRadius * l * dr; - gl.glVertex2f(r * x, r * y); + vboBuffer.glVertex2f(r * x, r * y); } } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); break; } case GLU.GLU_SILHOUETTE: { if (innerRadius != 0.0) { float a; - gl.glBegin(GL.GL_LINE_LOOP); + vboBuffer.glBegin(GL.GL_LINE_LOOP); for (a = 0.0f; a < 2.0 * PI; a += da) { float x = innerRadius * sin(a); float y = innerRadius * cos(a); - gl.glVertex2f(x, y); + vboBuffer.glVertex2f(x, y); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } { float a; - gl.glBegin(GL.GL_LINE_LOOP); + vboBuffer.glBegin(GL.GL_LINE_LOOP); for (a = 0; a < 2.0f * PI; a += da) { float x = outerRadius * sin(a); float y = outerRadius * cos(a); - gl.glVertex2f(x, y); + vboBuffer.glVertex2f(x, y); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } break; } @@ -644,9 +694,9 @@ public class GLUquadricImpl implements GLUquadric { case GLU.GLU_FLAT : case GLU.GLU_SMOOTH : if (orientation == GLU.GLU_OUTSIDE) { - gl.glNormal3f(0.0f, 0.0f, 1.0f); + vboBuffer.glNormal3f(0.0f, 0.0f, 1.0f); } else { - gl.glNormal3f(0.0f, 0.0f, -1.0f); + vboBuffer.glNormal3f(0.0f, 0.0f, -1.0f); } break; default : @@ -659,11 +709,11 @@ public class GLUquadricImpl implements GLUquadric { if (innerRadius == .0f) { finish = loops - 1; /* Triangle strip for inner polygons */ - gl.glBegin(GL.GL_TRIANGLE_FAN); + vboBuffer.glBegin(GL.GL_TRIANGLE_FAN); if (textureFlag) { - gl.glTexCoord2f(0.5f, 0.5f); + vboBuffer.glTexCoord2f(0.5f, 0.5f); } - gl.glVertex3f(0.0f, 0.0f, 0.0f); + vboBuffer.glVertex3f(0.0f, 0.0f, 0.0f); radiusLow = outerRadius - deltaRadius * ((float) (loops - 1) / loops); if (textureFlag) { texLow = radiusLow / outerRadius / 2; @@ -672,21 +722,21 @@ public class GLUquadricImpl implements GLUquadric { if (orientation == GLU.GLU_OUTSIDE) { for (i = slices; i >= 0; i--) { if (textureFlag) { - gl.glTexCoord2f(texLow * sinCache[i] + 0.5f, + vboBuffer.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); } - gl.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + vboBuffer.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); } } else { for (i = 0; i <= slices; i++) { if (textureFlag) { - gl.glTexCoord2f(texLow * sinCache[i] + 0.5f, + vboBuffer.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); } - gl.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + vboBuffer.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); } } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } else { finish = loops; } @@ -698,43 +748,43 @@ public class GLUquadricImpl implements GLUquadric { texHigh = radiusHigh / outerRadius / 2; } - gl.glBegin(GL.GL_QUAD_STRIP); + vboBuffer.glBegin(vboBuffer.GL_QUAD_STRIP); for (i = 0; i <= slices; i++) { if (orientation == GLU.GLU_OUTSIDE) { if (textureFlag) { - gl.glTexCoord2f(texLow * sinCache[i] + 0.5f, + vboBuffer.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); } - gl.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + vboBuffer.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); if (textureFlag) { - gl.glTexCoord2f(texHigh * sinCache[i] + 0.5f, + vboBuffer.glTexCoord2f(texHigh * sinCache[i] + 0.5f, texHigh * cosCache[i] + 0.5f); } - gl.glVertex3f(radiusHigh * sinCache[i], + vboBuffer.glVertex3f(radiusHigh * sinCache[i], radiusHigh * cosCache[i], 0.0f); } else { if (textureFlag) { - gl.glTexCoord2f(texHigh * sinCache[i] + 0.5f, + vboBuffer.glTexCoord2f(texHigh * sinCache[i] + 0.5f, texHigh * cosCache[i] + 0.5f); } - gl.glVertex3f(radiusHigh * sinCache[i], + vboBuffer.glVertex3f(radiusHigh * sinCache[i], radiusHigh * cosCache[i], 0.0f); if (textureFlag) { - gl.glTexCoord2f(texLow * sinCache[i] + 0.5f, + vboBuffer.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); } - gl.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + vboBuffer.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); } } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } break; case GLU.GLU_POINT : - gl.glBegin(GL.GL_POINTS); + vboBuffer.glBegin(GL.GL_POINTS); for (i = 0; i < slices2; i++) { sintemp = sinCache[i]; costemp = cosCache[i]; @@ -744,25 +794,25 @@ public class GLUquadricImpl implements GLUquadric { if (textureFlag) { texLow = radiusLow / outerRadius / 2; - gl.glTexCoord2f(texLow * sinCache[i] + 0.5f, + vboBuffer.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); } - gl.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f); + vboBuffer.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f); } } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); break; case GLU.GLU_LINE : if (innerRadius == outerRadius) { - gl.glBegin(GL.GL_LINE_STRIP); + vboBuffer.glBegin(GL.GL_LINE_STRIP); for (i = 0; i <= slices; i++) { if (textureFlag) { - gl.glTexCoord2f(sinCache[i] / 2 + 0.5f, cosCache[i] / 2 + 0.5f); + vboBuffer.glTexCoord2f(sinCache[i] / 2 + 0.5f, cosCache[i] / 2 + 0.5f); } - gl.glVertex3f(innerRadius * sinCache[i], innerRadius * cosCache[i], 0.0f); + vboBuffer.glVertex3f(innerRadius * sinCache[i], innerRadius * cosCache[i], 0.0f); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); break; } for (j = 0; j <= loops; j++) { @@ -771,20 +821,20 @@ public class GLUquadricImpl implements GLUquadric { texLow = radiusLow / outerRadius / 2; } - gl.glBegin(GL.GL_LINE_STRIP); + vboBuffer.glBegin(GL.GL_LINE_STRIP); for (i = 0; i <= slices; i++) { if (textureFlag) { - gl.glTexCoord2f(texLow * sinCache[i] + 0.5f, + vboBuffer.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); } - gl.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + vboBuffer.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } for (i = 0; i < slices2; i++) { sintemp = sinCache[i]; costemp = cosCache[i]; - gl.glBegin(GL.GL_LINE_STRIP); + vboBuffer.glBegin(GL.GL_LINE_STRIP); for (j = 0; j <= loops; j++) { radiusLow = outerRadius - deltaRadius * ((float) j / loops); if (textureFlag) { @@ -792,12 +842,12 @@ public class GLUquadricImpl implements GLUquadric { } if (textureFlag) { - gl.glTexCoord2f(texLow * sinCache[i] + 0.5f, + vboBuffer.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); } - gl.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f); + vboBuffer.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } break; case GLU.GLU_SILHOUETTE : @@ -805,18 +855,18 @@ public class GLUquadricImpl implements GLUquadric { for (i = 0; i <= slices; i += slices) { sintemp = sinCache[i]; costemp = cosCache[i]; - gl.glBegin(GL.GL_LINE_STRIP); + vboBuffer.glBegin(GL.GL_LINE_STRIP); for (j = 0; j <= loops; j++) { radiusLow = outerRadius - deltaRadius * ((float) j / loops); if (textureFlag) { texLow = radiusLow / outerRadius / 2; - gl.glTexCoord2f(texLow * sinCache[i] + 0.5f, + vboBuffer.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); } - gl.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f); + vboBuffer.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } } for (j = 0; j <= loops; j += loops) { @@ -825,15 +875,15 @@ public class GLUquadricImpl implements GLUquadric { texLow = radiusLow / outerRadius / 2; } - gl.glBegin(GL.GL_LINE_STRIP); + vboBuffer.glBegin(GL.GL_LINE_STRIP); for (i = 0; i <= slices; i++) { if (textureFlag) { - gl.glTexCoord2f(texLow * sinCache[i] + 0.5f, + vboBuffer.glTexCoord2f(texLow * sinCache[i] + 0.5f, texLow * cosCache[i] + 0.5f); } - gl.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); + vboBuffer.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); if (innerRadius == outerRadius) break; } @@ -882,20 +932,24 @@ public class GLUquadricImpl implements GLUquadric { if (drawStyle == GLU.GLU_FILL) { if (!textureFlag) { // draw +Z end as a triangle fan - gl.glBegin(GL.GL_TRIANGLE_FAN); - gl.glNormal3f(0.0f, 0.0f, 1.0f); - gl.glVertex3f(0.0f, 0.0f, nsign * radius); + vboBuffer.glBegin(GL.GL_TRIANGLE_FAN); + if(USE_NORM_TXT) { + vboBuffer.glNormal3f(0.0f, 0.0f, 1.0f); + } + vboBuffer.glVertex3f(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 (normals) { - gl.glNormal3f(x * nsign, y * nsign, z * nsign); + if(USE_NORM_TXT) { + if (normals) { + vboBuffer.glNormal3f(x * nsign, y * nsign, z * nsign); + } } - gl.glVertex3f(x * radius, y * radius, z * radius); + vboBuffer.glVertex3f(x * radius, y * radius, z * radius); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } ds = 1.0f / slices; @@ -912,37 +966,43 @@ public class GLUquadricImpl implements GLUquadric { // draw intermediate stacks as quad strips for (i = imin; i < imax; i++) { rho = i * drho; - gl.glBegin(GL.GL_QUAD_STRIP); + vboBuffer.glBegin(vboBuffer.GL_QUAD_STRIP); s = 0.0f; for (j = 0; j <= slices; j++) { theta = (j == slices) ? 0.0f : j * dtheta; x = -sin(theta) * sin(rho); y = cos(theta) * sin(rho); z = nsign * cos(rho); - if (normals) { - gl.glNormal3f(x * nsign, y * nsign, z * nsign); + if(USE_NORM_TXT) { + if (normals) { + vboBuffer.glNormal3f(x * nsign, y * nsign, z * nsign); + } + TXTR_COORD(vboBuffer, s, t); } - TXTR_COORD(gl, s, t); - gl.glVertex3f(x * radius, y * radius, z * radius); + vboBuffer.glVertex3f(x * radius, y * radius, z * radius); x = -sin(theta) * sin(rho + drho); y = cos(theta) * sin(rho + drho); z = nsign * cos(rho + drho); - if (normals) { - gl.glNormal3f(x * nsign, y * nsign, z * nsign); + if(USE_NORM_TXT) { + if (normals) { + vboBuffer.glNormal3f(x * nsign, y * nsign, z * nsign); + } + TXTR_COORD(vboBuffer, s, t - dt); } - TXTR_COORD(gl, s, t - dt); s += ds; - gl.glVertex3f(x * radius, y * radius, z * radius); + vboBuffer.glVertex3f(x * radius, y * radius, z * radius); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); t -= dt; } if (!textureFlag) { // draw -Z end as a triangle fan - gl.glBegin(GL.GL_TRIANGLE_FAN); - gl.glNormal3f(0.0f, 0.0f, -1.0f); - gl.glVertex3f(0.0f, 0.0f, -radius * nsign); + vboBuffer.glBegin(GL.GL_TRIANGLE_FAN); + if(USE_NORM_TXT) { + vboBuffer.glNormal3f(0.0f, 0.0f, -1.0f); + } + vboBuffer.glVertex3f(0.0f, 0.0f, -radius * nsign); rho = PI - drho; s = 1.0f; for (j = slices; j >= 0; j--) { @@ -950,12 +1010,14 @@ public class GLUquadricImpl implements GLUquadric { x = -sin(theta) * sin(rho); y = cos(theta) * sin(rho); z = nsign * cos(rho); - if (normals) - gl.glNormal3f(x * nsign, y * nsign, z * nsign); + if(USE_NORM_TXT) { + if (normals) + vboBuffer.glNormal3f(x * nsign, y * nsign, z * nsign); + } s -= ds; - gl.glVertex3f(x * radius, y * radius, z * radius); + vboBuffer.glVertex3f(x * radius, y * radius, z * radius); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } } else if ( drawStyle == GLU.GLU_LINE @@ -965,42 +1027,42 @@ public class GLUquadricImpl implements GLUquadric { i < stacks; i++) { // stack line at i==stacks-1 was missing here rho = i * drho; - gl.glBegin(GL.GL_LINE_LOOP); + vboBuffer.glBegin(GL.GL_LINE_LOOP); for (j = 0; j < slices; j++) { theta = j * dtheta; x = cos(theta) * sin(rho); y = sin(theta) * sin(rho); z = cos(rho); if (normals) - gl.glNormal3f(x * nsign, y * nsign, z * nsign); - gl.glVertex3f(x * radius, y * radius, z * radius); + vboBuffer.glNormal3f(x * nsign, y * nsign, z * nsign); + vboBuffer.glVertex3f(x * radius, y * radius, z * radius); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } // draw slice lines for (j = 0; j < slices; j++) { theta = j * dtheta; - gl.glBegin(GL.GL_LINE_STRIP); + vboBuffer.glBegin(GL.GL_LINE_STRIP); for (i = 0; i <= stacks; i++) { rho = i * drho; x = cos(theta) * sin(rho); y = sin(theta) * sin(rho); z = cos(rho); if (normals) - gl.glNormal3f(x * nsign, y * nsign, z * nsign); - gl.glVertex3f(x * radius, y * radius, z * radius); + vboBuffer.glNormal3f(x * nsign, y * nsign, z * nsign); + vboBuffer.glVertex3f(x * radius, y * radius, z * radius); } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } } else if (drawStyle == GLU.GLU_POINT) { // top and bottom-most points - gl.glBegin(GL.GL_POINTS); + vboBuffer.glBegin(GL.GL_POINTS); if (normals) - gl.glNormal3f(0.0f, 0.0f, nsign); - gl.glVertex3f(0.0f, 0.0f, radius); + vboBuffer.glNormal3f(0.0f, 0.0f, nsign); + vboBuffer.glVertex3f(0.0f, 0.0f, radius); if (normals) - gl.glNormal3f(0.0f, 0.0f, -nsign); - gl.glVertex3f(0.0f, 0.0f, -radius); + vboBuffer.glNormal3f(0.0f, 0.0f, -nsign); + vboBuffer.glVertex3f(0.0f, 0.0f, -radius); // loop over stacks for (i = 1; i < stacks - 1; i++) { @@ -1011,11 +1073,11 @@ public class GLUquadricImpl implements GLUquadric { y = sin(theta) * sin(rho); z = cos(rho); if (normals) - gl.glNormal3f(x * nsign, y * nsign, z * nsign); - gl.glVertex3f(x * radius, y * radius, z * radius); + vboBuffer.glNormal3f(x * nsign, y * nsign, z * nsign); + vboBuffer.glVertex3f(x * radius, y * radius, z * radius); } } - gl.glEnd(); + vboBuffer.glEnd(gl, vboImmediateDraw); } } @@ -1043,11 +1105,11 @@ public class GLUquadricImpl implements GLUquadric { y /= mag; z /= mag; } - gl.glNormal3f(x, y, z); + vboBuffer.glNormal3f(x, y, z); } - private void TXTR_COORD(GL gl, float x, float y) { - if (textureFlag) gl.glTexCoord2f(x,y); + private final void TXTR_COORD(ImmModeSink vboBuffer, float x, float y) { + if (textureFlag) vboBuffer.glTexCoord2f(x,y); } private float sin(float r) { diff --git a/src/classes/com/sun/opengl/util/ImageUtil.java b/src/classes/com/sun/opengl/util/ImageUtil.java index f8981bd36..92d0433da 100755 --- a/src/classes/com/sun/opengl/util/ImageUtil.java +++ b/src/classes/com/sun/opengl/util/ImageUtil.java @@ -123,4 +123,5 @@ public class ImageUtil { return thumb; } + } diff --git a/src/classes/com/sun/opengl/util/ImmModeSink.java b/src/classes/com/sun/opengl/util/ImmModeSink.java new file mode 100644 index 000000000..642260103 --- /dev/null +++ b/src/classes/com/sun/opengl/util/ImmModeSink.java @@ -0,0 +1,318 @@ + +package com.sun.opengl.util; + +import javax.media.opengl.*; +import java.nio.*; +import java.util.Iterator; +import java.util.ArrayList; + +public class ImmModeSink { + + public static final boolean DEBUG_BEGIN_END = false; + public static final boolean DEBUG_DRAW = false; + public static final boolean FLOAT2FIXED = false; + + public static final int GL_QUADS = 0x0007; + public static final int GL_QUAD_STRIP = 0x0008; + public static final int GL_POLYGON = 0x0009; + + public ImmModeSink(int glDataType, int glDrawUsage, + int vComps, int nComps, int cComps, int tComps, int initialSize) { + + vboSet = new VBOSet(glDataType, glDrawUsage, vComps, nComps, cComps, tComps, initialSize); + this.vboSetList = new ArrayList(); + } + + private void destroyList(GL gl) { + for(Iterator i=vboSetList.iterator(); i.hasNext() ; ) { + ((VBOSet)i.next()).destroy(gl); + } + vboSetList.clear(); + } + + public void destroy(GL gl) { + destroyList(gl); + + vboSet.destroy(gl); + } + + public void reset() { + reset(null); + } + + public void reset(GL gl) { + destroyList(gl); + vboSet.reset(gl); + } + + public String toString() { + return "ImmModeSink[listsz: "+vboSetList.size()+ + ",\n"+vboSet+ + "]"; + } + + public void draw(GL gl, boolean disableBufferAfterDraw) { + if(DEBUG_DRAW) { + Exception e = new Exception("ImmModeSink.draw(disableBufferAfterDraw: "+disableBufferAfterDraw+"):\n\t"+this); + e.printStackTrace(); + } + int n=0; + for(Iterator i=vboSetList.iterator(); i.hasNext() ; n++) { + ((VBOSet)i.next()).draw(gl, disableBufferAfterDraw, n); + } + } + + public void glBegin(int mode) { + if(DEBUG_BEGIN_END) { + Exception e = new Exception("ImmModeSink.glBegin("+vboSet.mode+"):\n\t"+this); + e.printStackTrace(); + } + vboSet.modeOrig = mode; + switch(mode) { + case GL_QUADS: + mode=GL.GL_TRIANGLE_STRIP; + break; + case GL_QUAD_STRIP: + mode=GL.GL_TRIANGLE_STRIP; + break; + case GL_POLYGON: + mode=GL.GL_LINES; + break; + } + vboSet.mode = mode; + vboSet.checkSeal(false); + } + + public final void glEnd(GL gl) { + glEnd(gl, true); + } + + public void glEnd(GL gl, boolean immediateDraw) { + if(DEBUG_BEGIN_END) { + Exception e = new Exception("ImmModeSink START glEnd(immediate: "+immediateDraw+"):\n\t"+this); + e.printStackTrace(); + } + if(immediateDraw) { + vboSet.seal(gl, false); + vboSet.draw(gl, true, -1); + reset(gl); + } else { + vboSet.seal(gl, true); + vboSetList.add(vboSet); + vboSet = vboSet.regenerate(); + } + } + + public final void glVertex2f(float x, float y) { + vboSet.glVertex2f(x,y); + } + + public final void glVertex3f(float x, float y, float z) { + vboSet.glVertex3f(x,y,z); + } + + public final void glNormal3f(float x, float y, float z) { + vboSet.glNormal3f(x,y,z); + } + + public final void glColor3f(float x, float y, float z) { + vboSet.glColor3f(x,y,z); + } + + public final void glTexCoord2f(float x, float y) { + vboSet.glTexCoord2f(x,y); + } + + public final void glTexCoord3f(float x, float y, float z) { + vboSet.glTexCoord3f(x,y,z); + } + + private VBOSet vboSet; + private ArrayList vboSetList; + + protected static class VBOSet { + protected VBOSet(int glDataType, int glDrawUsage, + int vComps, int nComps, int cComps, int tComps, int initialSize) { + nComps = 0; + tComps = 0; + if(FLOAT2FIXED && glDataType==GL.GL_FLOAT) { + glDataType=GL.GL_FIXED; + } + this.glDataType=glDataType; + this.glDrawUsage=glDrawUsage; + this.vComps=vComps; + this.nComps=nComps; + this.cComps=cComps; + this.tComps=tComps; + this.initialSize=initialSize; + + this.vertexVBO = new VBOBufferDraw(GL.GL_VERTEX_ARRAY, glDataType, glDrawUsage, vComps, initialSize); + this.normalVBO = new VBOBufferDraw(GL.GL_NORMAL_ARRAY, glDataType, glDrawUsage, nComps, initialSize); + this.colorVBO = new VBOBufferDraw(GL.GL_COLOR_ARRAY, glDataType, glDrawUsage, cComps, initialSize); + this.texcoordVBO = new VBOBufferDraw(GL.GL_TEXTURE_COORD_ARRAY, glDataType, glDrawUsage, tComps, initialSize); + + this.sealed=false; + this.mode = -1; + this.modeOrig = -1; + } + + protected final VBOSet regenerate() { + return new VBOSet(glDataType, glDrawUsage, vComps, nComps, cComps, tComps, initialSize); + } + + protected void destroy(GL gl) { + vertexVBO.destroy(gl); + normalVBO.destroy(gl); + colorVBO.destroy(gl); + texcoordVBO.destroy(gl); + + this.mode = -1; + this.modeOrig = -1; + this.sealed=false; + } + + protected void reset(GL gl) { + vertexVBO.reset(gl); + normalVBO.reset(gl); + colorVBO.reset(gl); + texcoordVBO.reset(gl); + + this.mode = -1; + this.modeOrig = -1; + this.sealed=false; + } + + public String toString() { + return "VBOSet[mode "+mode+ + ", modeOrig "+modeOrig+ + ", sealed "+sealed+ + ",\n\t vertexVBO "+vertexVBO+ + ",\n\t normalVBO "+normalVBO+ + ",\n\t colorVBO "+colorVBO+ + ",\n\t texcoordVBO "+texcoordVBO+ + "]"; + } + + protected void checkSeal(boolean test) throws GLException { + if(mode<0) { + throw new GLException("No mode set yet, call glBegin(mode) first:\n\t"+this); + } + if(sealed!=test) { + if(test) { + throw new GLException("Not Sealed yet, call glEnd() first:\n\t"+this); + } else { + throw new GLException("Already Sealed, can't modify VBO after glEnd():\n\t"+this); + } + } + } + + protected void rewind() { + checkSeal(true); + + vertexVBO.rewind(); + normalVBO.rewind(); + colorVBO.rewind(); + texcoordVBO.rewind(); + } + + protected void seal(GL gl, boolean disableBufferAfterSeal) + { + checkSeal(false); + sealed = true; + + vertexVBO.seal(gl, disableBufferAfterSeal); + normalVBO.seal(gl, disableBufferAfterSeal); + colorVBO.seal(gl, disableBufferAfterSeal); + texcoordVBO.seal(gl, disableBufferAfterSeal); + } + + protected void draw(GL gl, boolean disableBufferAfterDraw, int i) + { + if(DEBUG_DRAW) { + Exception e = new Exception("ImmModeSink.draw["+i+"](disableBufferAfterDraw: "+disableBufferAfterDraw+"):\n\t"+this); + e.printStackTrace(); + } + vertexVBO.enableBuffer(gl); + normalVBO.enableBuffer(gl); + colorVBO.enableBuffer(gl); + texcoordVBO.enableBuffer(gl); + + if (vertexVBO.getBuffer()!=null) { + gl.glDrawArrays(mode, 0, vertexVBO.getVerticeNumber()); + } + + if(disableBufferAfterDraw) { + vertexVBO.disableBuffer(gl); + normalVBO.disableBuffer(gl); + colorVBO.disableBuffer(gl); + texcoordVBO.disableBuffer(gl); + } + } + + protected void glVertex2f(float x, float y) { + checkSeal(false); + vertexVBO.putf(x); + if(vertexVBO.getComponents()>1) + vertexVBO.putf(y); + vertexVBO.padding(2); + } + + protected void glVertex3f(float x, float y, float z) { + checkSeal(false); + vertexVBO.putf(x); + if(vertexVBO.getComponents()>1) + vertexVBO.putf(y); + if(vertexVBO.getComponents()>2) + vertexVBO.putf(z); + vertexVBO.padding(3); + } + + protected void glNormal3f(float x, float y, float z) { + checkSeal(false); + normalVBO.putf(x); + if(normalVBO.getComponents()>1) + normalVBO.putf(y); + if(normalVBO.getComponents()>2) + normalVBO.putf(z); + normalVBO.padding(3); + } + + protected void glColor3f(float x, float y, float z) { + checkSeal(false); + colorVBO.putf(x); + if(colorVBO.getComponents()>1) + colorVBO.putf(y); + if(colorVBO.getComponents()>2) + colorVBO.putf(z); + colorVBO.padding(3); + } + + protected void glTexCoord2f(float x, float y) { + checkSeal(false); + texcoordVBO.putf(x); + if(texcoordVBO.getComponents()>1) + texcoordVBO.putf(y); + texcoordVBO.padding(2); + } + + protected void glTexCoord3f(float x, float y, float z) { + checkSeal(false); + texcoordVBO.putf(x); + if(texcoordVBO.getComponents()>1) + texcoordVBO.putf(y); + if(texcoordVBO.getComponents()>2) + texcoordVBO.putf(z); + texcoordVBO.padding(3); + } + + VBOBufferDraw vertexVBO; + VBOBufferDraw normalVBO; + VBOBufferDraw colorVBO; + VBOBufferDraw texcoordVBO; + int mode, modeOrig; + int glDataType, glDrawUsage, vComps, nComps, cComps, tComps, initialSize; + boolean sealed; + } + +} + diff --git a/src/classes/com/sun/opengl/util/VBOBufferDraw.java b/src/classes/com/sun/opengl/util/VBOBufferDraw.java new file mode 100644 index 000000000..932cf8e9e --- /dev/null +++ b/src/classes/com/sun/opengl/util/VBOBufferDraw.java @@ -0,0 +1,389 @@ + +package com.sun.opengl.util; + +import javax.media.opengl.*; +import java.nio.*; + +public class VBOBufferDraw { + + public VBOBufferDraw(int glArrayType, int glDataType, int glBufferUsage, int comps, int initialSize) { + switch(glArrayType) { + case GL.GL_VERTEX_ARRAY: + case GL.GL_NORMAL_ARRAY: + case GL.GL_COLOR_ARRAY: + case GL.GL_TEXTURE_COORD_ARRAY: + break; + default: + throw new GLException("invalid glArrayType: "+glArrayType+":\n\t"+this); + } + this.glArrayType = glArrayType; + this.glDataType = glDataType; + this.clazz = getBufferClass(glDataType); + this.buffer = null; + this.components = comps; + this.initialSize = initialSize; + switch(glBufferUsage) { + case GL.GL_STATIC_DRAW: + // FIXME: case GL.GL_STREAM_DRAW: + case GL.GL_DYNAMIC_DRAW: + break; + default: + throw new GLException("invalid glBufferUsage: "+glBufferUsage+":\n\t"+this); + } + this.glBufferUsage = glBufferUsage; + this.vboName = 0; + this.sealed=false; + this.bufferEnabled=false; + growVBO(initialSize); + } + + public int getGLArrayType() { + return glArrayType; + } + + public int getGlDataType() { + return glDataType; + } + + public int getComponents() { + return components; + } + + public Class getBufferClass() { + return clazz; + } + + public Buffer getBuffer() { + return buffer; + } + + public int getBufferUsage() { + return glBufferUsage; + } + + public void destroy(GL gl) { + reset(gl); + if(vboName!=0) { + int[] tmp = new int[1]; + tmp[0] = vboName; + gl.glDeleteBuffers(1, tmp, 0); + vboName = 0; + } + } + + public void reset() { + reset(null); + } + + public void reset(GL gl) { + if(gl!=null) { + disableBuffer(gl); + } + this.sealed=false; + if(buffer!=null) { + buffer.clear(); + } + } + + private final void init_vbo(GL gl) { + if(vboName==0) { + int[] tmp = new int[1]; + gl.glGenBuffers(1, tmp, 0); + vboName = tmp[0]; + } + } + + private final void checkSeal(boolean test) throws GLException { + if(sealed!=test) { + if(test) { + throw new GLException("Not Sealed yet, seal first:\n\t"+this); + } else { + throw new GLException("Already Sealed, can't modify VBO:\n\t"+this); + } + } + } + + public final boolean growVBOIfNecessary(int spare) { + if(buffer==null) { + throw new GLException("buffer no configured:\n\t"+this); + } + if(buffer!=null && buffer.remaining()<spare) { + growVBO(); + return true; + } + return false; + } + + public final void growVBO() { + growVBO(initialSize); + } + + public static final Class getBufferClass(int glDataType) { + switch(glDataType) { + case GL.GL_BYTE: + case GL.GL_UNSIGNED_BYTE: + return ByteBuffer.class; + case GL.GL_SHORT: + case GL.GL_UNSIGNED_SHORT: + return ShortBuffer.class; + case GL.GL_FIXED: + return IntBuffer.class; + case GL.GL_FLOAT: + return FloatBuffer.class; + default: + throw new GLException("Given OpenGL data type not supported: "+glDataType); + } + } + + public final int getBufferCompSize() { + if(clazz==ByteBuffer.class) { + return BufferUtil.SIZEOF_BYTE; + } + if(clazz==ShortBuffer.class) { + return BufferUtil.SIZEOF_SHORT; + } + if(clazz==IntBuffer.class) { + return BufferUtil.SIZEOF_INT; + } + if(clazz==FloatBuffer.class) { + return BufferUtil.SIZEOF_FLOAT; + } + throw new GLException("Given Buffer Class not supported: "+clazz+":\n\t"+this); + } + + public final void growVBO(int additional) { + int osize; + + checkSeal(false); + + if(components>0) { + osize = (buffer!=null)?buffer.capacity():0; + if(clazz==ByteBuffer.class) { + ByteBuffer newBBuffer = BufferUtil.newByteBuffer( (osize+additional) * components ); + if(buffer!=null) { + buffer.flip(); + newBBuffer.put((ByteBuffer)buffer); + } + buffer = newBBuffer; + } else if(clazz==ShortBuffer.class) { + ShortBuffer newSBuffer = BufferUtil.newShortBuffer( (osize+additional) * components ); + if(buffer!=null) { + buffer.flip(); + newSBuffer.put((ShortBuffer)buffer); + } + buffer = newSBuffer; + } else if(clazz==IntBuffer.class) { + IntBuffer newIBuffer = BufferUtil.newIntBuffer( (osize+additional) * components ); + if(buffer!=null) { + buffer.flip(); + newIBuffer.put((IntBuffer)buffer); + } + buffer = newIBuffer; + } else if(clazz==FloatBuffer.class) { + FloatBuffer newFBuffer = BufferUtil.newFloatBuffer( (osize+additional) * components ); + if(buffer!=null) { + buffer.flip(); + newFBuffer.put((FloatBuffer)buffer); + } + buffer = newFBuffer; + } else { + throw new GLException("Given Buffer Class not supported: "+clazz+":\n\t"+this); + } + } + } + + public void rewind() { + checkSeal(true); + + if(buffer!=null) { + buffer.rewind(); + } + } + + public int getVerticeNumber() { + return ( buffer!=null ) ? ( buffer.limit() / components ) : 0 ; + } + + public void seal(GL gl, boolean disableAfterSeal) + { + checkSeal(false); + sealed = true; + init_vbo(gl); + + if (null!=buffer) { + buffer.flip(); + enableBuffer(gl, true); + } + if(null==buffer || disableAfterSeal) { + disableBuffer(gl); + } + + } + + public void enableBuffer(GL gl) + { + enableBuffer(gl, false); + } + + private void enableBuffer(GL gl, boolean newData) + { + checkSeal(true); + + if(!bufferEnabled && null!=buffer) { + gl.glEnableClientState(glArrayType); + 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(components, glDataType, 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); + } + bufferEnabled = true; + } + } + + public void disableBuffer(GL gl) { + if(bufferEnabled && null!=buffer) { + gl.glDisableClientState(glArrayType); + bufferEnabled = false; + } + } + + public void padding(int done) { + if(buffer==null) return; // JAU + if(buffer==null) { + throw new GLException("buffer no configured:\n\t"+this); + } + while(done<components) { + if(clazz==ByteBuffer.class) { + ((ByteBuffer)buffer).put((byte)0); + } else if(clazz==ShortBuffer.class) { + ((ShortBuffer)buffer).put((short)0); + } else if(clazz==IntBuffer.class) { + ((IntBuffer)buffer).put(0); + } else if(clazz==FloatBuffer.class) { + ((FloatBuffer)buffer).put(0f); + } else { + throw new GLException("Given Buffer Class not supported: "+clazz+" :\n\t"+this); + } + done++; + } + } + + public void putb(byte v) { + if(buffer==null) return; // JAU + growVBOIfNecessary(1); + if(clazz==ByteBuffer.class) { + ((ByteBuffer)buffer).put(v); + } else if(clazz==ShortBuffer.class) { + ((ShortBuffer)buffer).put((short)v); + } else if(clazz==IntBuffer.class) { + ((IntBuffer)buffer).put((int)v); + } else { + throw new GLException("Byte doesn't match Buffer Class: "+clazz+" :\n\t"+this); + } + } + + public void puts(short v) { + if(buffer==null) return; // JAU + growVBOIfNecessary(1); + if(clazz==ShortBuffer.class) { + ((ShortBuffer)buffer).put(v); + } else if(clazz==IntBuffer.class) { + ((IntBuffer)buffer).put((int)v); + } else { + throw new GLException("Short doesn't match Buffer Class: "+clazz+" :\n\t"+this); + } + } + + public void puti(int v) { + if(buffer==null) return; // JAU + growVBOIfNecessary(1); + if(clazz==IntBuffer.class) { + ((IntBuffer)buffer).put(v); + } else { + throw new GLException("Integer doesn't match Buffer Class: "+clazz+" :\n\t"+this); + } + } + + public void putx(int v) { + if(buffer==null) return; // JAU + growVBOIfNecessary(1); + if(clazz==IntBuffer.class) { + ((IntBuffer)buffer).put(v); + } else { + throw new GLException("Fixed doesn't match Buffer Class: "+clazz+" :\n\t"+this); + } + } + + public void putf(float v) { + if(buffer==null) return; // JAU + growVBOIfNecessary(1); + if(clazz==FloatBuffer.class) { + ((FloatBuffer)buffer).put(v); + } else if(clazz==IntBuffer.class) { + ((IntBuffer)buffer).put(Float2Fixed(v)); + } else { + throw new GLException("Float doesn't match Buffer Class: "+clazz+" :\n\t"+this); + } + } + + public void putd(double v) { + if(buffer==null) return; // JAU + growVBOIfNecessary(1); + if(clazz==FloatBuffer.class) { + // FIXME: ok ? + ((FloatBuffer)buffer).put((float)v); + } else { + throw new GLException("Double doesn't match Buffer Class: "+clazz+" :\n\t"+this); + } + } + + public String toString() { + return "VBOBufferDraw[vertices "+getVerticeNumber()+ + ", glArrayType "+glArrayType+ + ", glDataType "+glDataType+ + ", bufferClazz "+clazz+ + ", components "+components+ + ", initialSize "+initialSize+ + ", glBufferUsage "+glBufferUsage+ + ", vboName "+vboName+ + ", sealed "+sealed+ + ", bufferEnabled "+bufferEnabled+ + ",\n\tbuffer "+buffer+ + "]"; + } + + public static final int Float2Fixed(float value) + { + if (value < -32768) value = -32768; + if (value > 32767) value = 32767; + return (int)(value * 65536); + } + + private int glArrayType; + private int glDataType; + private Class clazz; + private Buffer buffer; + private int components; + private int initialSize; + private int glBufferUsage; + private int vboName; + private boolean sealed; + private boolean bufferEnabled; + +} + diff --git a/src/classes/javax/media/opengl/glu/GLUquadric.java b/src/classes/javax/media/opengl/glu/GLUquadric.java index bcb21fb90..882df6cb6 100755 --- a/src/classes/javax/media/opengl/glu/GLUquadric.java +++ b/src/classes/javax/media/opengl/glu/GLUquadric.java @@ -1,8 +1,19 @@ package javax.media.opengl.glu; +import javax.media.opengl.GL; +import com.sun.opengl.util.ImmModeSink; + /** * Wrapper for a GLU quadric object. */ public interface GLUquadric { + // creates a new ImmModeSink (VBO Buffers) and + // returns the old vbo buffer with it's rendering result + public ImmModeSink replaceVBOBuffer(); + + public void setVBOImmediateMode(boolean val); + + // gl may be null, then the GL client states are not disabled + public void resetVBOBuffer(GL gl); } diff --git a/src/native/jogl/X11Window.c b/src/native/jogl/X11Window.c index f4d9872d4..d4c764a6a 100755 --- a/src/native/jogl/X11Window.c +++ b/src/native/jogl/X11Window.c @@ -307,6 +307,8 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setVisible0 XSelectInput(dpy, w, ExposureMask|ButtonPressMask|ButtonReleaseMask|PointerMotionMask| KeyPressMask|KeyReleaseMask); XSetInputFocus(dpy, w, RevertToNone, CurrentTime); + + XSync(dpy, False); } else { XSelectInput(dpy, w, 0); XUnmapWindow(dpy, w); |