summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2005-09-09 09:05:33 +0000
committerKenneth Russel <[email protected]>2005-09-09 09:05:33 +0000
commit8130f512b1c140372d85b58303cb10eeeb914435 (patch)
treebfbd98822a81eb61c7cf87c3b9990321e9ec7ecc /src
parentba4ea2f846e55283efbc19d4dc7a62a1f116e4b1 (diff)
Initial integration of JOGL with the Java2D OpenGL pipeline in the Sun JDK.
GLJPanel has a new rendering path which captures the Java2D back buffer via GLDrawableFactory.createExternalGLDrawable()/createExternalGLContext() and creates a new context on it for performing JOGL rendering. The new path is enabled by default in Mustang build 51 and later when the Java2D/OpenGL pipeline is turned on via -Dsun.java2d.opengl=true, and yields huge speedups relative to the previous pbuffer-based GLJPanel implementation. GLJPanel in the new configuration is nearly as fast as the GLCanvas, and still provides 100% correct Swing integration. No public API changes were required to JOGL in order to implement this integration with one exception in GLJPanel.isOGLPipelineEnabled(): see below. Issues still remain, such as the desire to run all (not just some) OpenGL work on the Java2D-internal Queue Flusher Thread to maintain single-threaded behavior of the library. Currently GLCanvas's OpenGL work is run on the EDT while GLJPanel's and GLPbuffer's OpenGL work is run on the QFT. Significant restructuring to the GLCanvas will be required to achieve this goal. There is some lag of mouse events with demos which are more expensive to render which needs to be investigated. It will not be possible to implement calling of display() on other non-pbuffer GLAutoDrawables from within the GLEventListener's display() callback in this model. There are other issues as well. GLJPanel falls back to using a pbuffer internally when the Java2D back buffer's pixel format is not suitable for rendering the JOGL demos (for example, the InfiniteShadowVolumes demo, which requires stencil bits). Added GLJPanel.isOGLPipelineEnabled() which applications can use to decide whether to clear the color buffer or leave prior Java2D rendering results in place for non-opaque GLJPanels. The JGears demo has been modified to query that flag to maintain the gradient behind it while rendering the gears directly into the Java2D back buffer. GLCanvas uses the pixel format specified by Java2D if one is already set. It turns out that when the Java2D OpenGL pipeline is enabled, one is always set by default even though no Java2D rendering is performed into it, because the AWT clears the background of Canvases by default in certain situations. This can be disabled (only globally, unfortunately) by specifying -Dsun.awt.noerasebackground=true. Fixed issues with HDR and HWShadowmapsSimple demos where they needed to pay attention to the x and y coordinates passed down in the reshape callback in order to set up the correct OpenGL viewport. Fixed minor shutdown-related issues with demos using gleem's ManipManager. Tested (on NVidia hardware only so far) on Windows and X11 platforms with Mustang build 51. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/branches/JSR-231@125 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src')
-rw-r--r--src/demos/gears/Gears.java8
-rwxr-xr-xsrc/demos/hdr/HDR.java19
-rw-r--r--src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java24
-rw-r--r--src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java1
-rw-r--r--src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java1
-rw-r--r--src/demos/vertexProgRefract/VertexProgRefract.java1
-rw-r--r--src/demos/vertexProgWarp/VertexProgWarp.java1
7 files changed, 36 insertions, 19 deletions
diff --git a/src/demos/gears/Gears.java b/src/demos/gears/Gears.java
index 3e8bd44..4c6f367 100644
--- a/src/demos/gears/Gears.java
+++ b/src/demos/gears/Gears.java
@@ -113,7 +113,13 @@ public class Gears implements GLEventListener, MouseListener, MouseMotionListene
angle += 2.0f;
GL gl = drawable.getGL();
- gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ if ((drawable instanceof GLJPanel) &&
+ ((GLJPanel) drawable).isOGLPipelineEnabled() &&
+ !((GLJPanel) drawable).isOpaque()) {
+ gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
+ } else {
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ }
gl.glPushMatrix();
gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
diff --git a/src/demos/hdr/HDR.java b/src/demos/hdr/HDR.java
index e10072a..8173d97 100755
--- a/src/demos/hdr/HDR.java
+++ b/src/demos/hdr/HDR.java
@@ -224,6 +224,7 @@ public class HDR extends Demo {
public void shutdownDemo() {
ManipManager.getManipManager().unregisterWindow(drawable);
+ drawable.removeGLEventListener(this);
super.shutdownDemo();
}
@@ -260,7 +261,7 @@ public class HDR extends Demo {
unavailableExtension("Floating-point textures not available (need one of GL_NV_float_buffer, GL_ATI_texture_float, or GL_APPLE_float_pixels");
}
- setOrthoProjection(gl, win_w, win_h);
+ setOrthoProjection(gl, 0, 0, win_w, win_h);
gamma_tex = createGammaTexture(gl, 1024, 1.0f / 2.2f);
vignette_tex = createVignetteTexture(gl, pbuffer_w, pbuffer_h, 0.25f*pbuffer_w, 0.7f*pbuffer_w);
@@ -421,7 +422,7 @@ public class HDR extends Demo {
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
- setOrthoProjection(drawable.getGL(), width, height);
+ setOrthoProjection(drawable.getGL(), x, y, width, height);
win_w = width;
win_h = height;
}
@@ -762,7 +763,7 @@ public class HDR extends Demo {
GL gl = drawable.getGL();
// FIXME: what about the ExaminerViewer?
- setOrthoProjection(gl, blur_w, blur_h);
+ setOrthoProjection(gl, 0, 0, blur_w, blur_h);
pipeline.initFloatingPointTexture(gl, blur_pbuffer_tex, blur_w, blur_h);
}
@@ -794,7 +795,7 @@ public class HDR extends Demo {
GL gl = drawable.getGL();
// FIXME: what about the ExaminerViewer?
- setOrthoProjection(gl, blur_w, blur_h);
+ setOrthoProjection(gl, 0, 0, blur_w, blur_h);
pipeline.initFloatingPointTexture(gl, blur2_pbuffer_tex, blur_w, blur_h);
}
@@ -808,7 +809,7 @@ public class HDR extends Demo {
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
pipeline.enableFragmentProgram(gl, shrink_fprog);
- setOrthoProjection(gl, blur_w, blur_h);
+ setOrthoProjection(gl, 0, 0, blur_w, blur_h);
gl.glActiveTexture(GL.GL_TEXTURE0);
gl.glBindTexture(GL.GL_TEXTURE_RECTANGLE_NV, pbuffer_tex);
drawQuadRect2(gl, blur_w, blur_h, pbuffer_w, pbuffer_h);
@@ -838,7 +839,7 @@ public class HDR extends Demo {
public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
- setOrthoProjection(gl, pbuffer_w, pbuffer_h);
+ setOrthoProjection(gl, 0, 0, pbuffer_w, pbuffer_h);
pipeline.initTexture(gl, tonemap_pbuffer_tex, pbuffer_w, pbuffer_h);
}
@@ -860,7 +861,7 @@ public class HDR extends Demo {
// Rendering routines
//
- private void setOrthoProjection(GL gl, int w, int h) {
+ private void setOrthoProjection(GL gl, int x, int y, int w, int h) {
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0, w, 0, h, -1.0, 1.0);
@@ -868,7 +869,7 @@ public class HDR extends Demo {
gl.glLoadIdentity();
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
- gl.glViewport(0, 0, w, h);
+ gl.glViewport(x, y, w, h);
}
private void setPerspectiveProjection(GL gl, GLU glu, int w, int h) {
@@ -886,7 +887,7 @@ public class HDR extends Demo {
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
- setOrthoProjection(gl, blur_w, blur_h);
+ setOrthoProjection(gl, 0, 0, blur_w, blur_h);
drawQuadRect(gl, blur_w, blur_h);
gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
diff --git a/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java b/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java
index ca2a8aa..23029bd 100644
--- a/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java
+++ b/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java
@@ -95,6 +95,7 @@ public class HWShadowmapsSimple extends Demo {
public void shutdownDemo() {
ManipManager.getManipManager().unregisterWindow(drawable);
+ drawable.removeGLEventListener(this);
super.shutdownDemo();
}
@@ -168,6 +169,8 @@ public class HWShadowmapsSimple extends Demo {
private Mat4f spotlightTransform = new Mat4f();
private Mat4f spotlightInverseTransform = new Mat4f();
private Mat4f objectTransform = new Mat4f();
+ private int viewportX;
+ private int viewportY;
public void init(GLAutoDrawable drawable) {
// Use debug pipeline
@@ -348,13 +351,16 @@ public class HWShadowmapsSimple extends Demo {
switch (displayMode) {
case RENDER_SCENE_FROM_CAMERA_VIEW: render_scene_from_camera_view(gl, glu, drawable, params); break;
case RENDER_SCENE_FROM_CAMERA_VIEW_SHADOWED: render_scene_from_camera_view_shadowed(gl, glu, drawable, params); break;
- case RENDER_SCENE_FROM_LIGHT_VIEW: render_scene_from_light_view(gl, glu, drawable); break;
+ case RENDER_SCENE_FROM_LIGHT_VIEW: render_scene_from_light_view(gl, glu, drawable, viewportX, viewportY); break;
default: throw new RuntimeException("Illegal display mode " + displayMode);
}
}
// Unused routines
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ viewportX = x;
+ viewportY = y;
+ }
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
private void checkExtension(GL gl, String extensionName) {
@@ -428,7 +434,7 @@ public class HWShadowmapsSimple extends Demo {
((Tweak) tweaks.get(POLYGON_OFFSET_BIAS)).val);
gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
- render_scene_from_light_view(gl, glu, drawable);
+ render_scene_from_light_view(gl, glu, drawable, 0, 0);
gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
@@ -654,7 +660,7 @@ public class HWShadowmapsSimple extends Demo {
gl.glActiveTexture(GL.GL_TEXTURE0);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
- gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight());
+ gl.glViewport(viewportX, viewportY, drawable.getWidth(), drawable.getHeight());
applyTransform(gl, cameraPerspective);
gl.glMatrixMode(GL.GL_MODELVIEW);
render_scene(gl, cameraTransform, drawable, params);
@@ -723,7 +729,7 @@ public class HWShadowmapsSimple extends Demo {
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
- gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight());
+ gl.glViewport(viewportX, viewportY, drawable.getWidth(), drawable.getHeight());
applyTransform(gl, cameraPerspective);
gl.glMatrixMode(GL.GL_MODELVIEW);
render_scene(gl, cameraTransform, drawable, params);
@@ -739,15 +745,15 @@ public class HWShadowmapsSimple extends Demo {
render_light_frustum(gl);
}
- private void largest_square_power_of_two_viewport(GL gl, GLAutoDrawable drawable) {
+ private void largest_square_power_of_two_viewport(GL gl, GLAutoDrawable drawable, int viewportX, int viewportY) {
float min = Math.min(drawable.getWidth(), drawable.getHeight());
float log2min = (float) Math.log(min) / (float) Math.log(2.0);
float pow2 = (float) Math.floor(log2min);
int size = 1 << (int) pow2;
- gl.glViewport(0, 0, size, size);
+ gl.glViewport(viewportX, viewportY, size, size);
}
- private void render_scene_from_light_view(GL gl, GLU glu, GLAutoDrawable drawable) {
+ private void render_scene_from_light_view(GL gl, GLU glu, GLAutoDrawable drawable, int viewportX, int viewportY) {
// place light
gl.glPushMatrix();
gl.glLoadIdentity();
@@ -781,7 +787,7 @@ public class HWShadowmapsSimple extends Demo {
glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
gl.glMatrixMode(GL.GL_MODELVIEW);
if (displayMode == RENDER_SCENE_FROM_LIGHT_VIEW)
- largest_square_power_of_two_viewport(gl, drawable);
+ largest_square_power_of_two_viewport(gl, drawable, viewportX, viewportY);
render_scene(gl, spotlightTransform, null, null);
gl.glActiveTexture(GL.GL_TEXTURE1);
diff --git a/src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java b/src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java
index 05594be..75d5cf6 100644
--- a/src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java
+++ b/src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java
@@ -105,6 +105,7 @@ public class InfiniteShadowVolumes extends Demo {
public void shutdownDemo() {
ManipManager.getManipManager().unregisterWindow(drawable);
+ drawable.removeGLEventListener(this);
super.shutdownDemo();
}
diff --git a/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java b/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java
index 6fbab29..24ce3cc 100644
--- a/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java
+++ b/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java
@@ -95,6 +95,7 @@ public class ProceduralTexturePhysics extends Demo {
public void shutdownDemo() {
ManipManager.getManipManager().unregisterWindow(drawable);
+ drawable.removeGLEventListener(this);
super.shutdownDemo();
}
diff --git a/src/demos/vertexProgRefract/VertexProgRefract.java b/src/demos/vertexProgRefract/VertexProgRefract.java
index 8c1e867..e3b4ab5 100644
--- a/src/demos/vertexProgRefract/VertexProgRefract.java
+++ b/src/demos/vertexProgRefract/VertexProgRefract.java
@@ -454,6 +454,7 @@ public class VertexProgRefract extends Demo {
//
public void shutdownDemo() {
ManipManager.getManipManager().unregisterWindow(drawable);
+ drawable.removeGLEventListener(this);
super.shutdownDemo();
}
diff --git a/src/demos/vertexProgWarp/VertexProgWarp.java b/src/demos/vertexProgWarp/VertexProgWarp.java
index e740a64..cba8b23 100644
--- a/src/demos/vertexProgWarp/VertexProgWarp.java
+++ b/src/demos/vertexProgWarp/VertexProgWarp.java
@@ -301,6 +301,7 @@ public class VertexProgWarp extends Demo {
//
public void shutdownDemo() {
ManipManager.getManipManager().unregisterWindow(drawable);
+ drawable.removeGLEventListener(this);
super.shutdownDemo();
}