aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/games/jogl/GLCanvas.java
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2005-07-17 06:13:24 +0000
committerKenneth Russel <[email protected]>2005-07-17 06:13:24 +0000
commit7e7e225eaf4fddb31152ab204bf1776f26079d40 (patch)
tree522044c1fb226235fa34b9d013945f320765edd8 /src/net/java/games/jogl/GLCanvas.java
parent9d28b7f7fffdaeee7353945000546cb73a00157b (diff)
Further context-related changes for the JSR-231 API. The GLContext
implementations on all platforms have been split into orthogonal GLDrawable and GLContext concepts. It is now possible to create more than one GLContet per GLDrawable (though this has not been tested yet). GLCanvas has been reimplemented in terms of GLDrawableFactory.getGLDrawable(). More functionality has been moved from GLDrawable to GLAutoDrawable. Reimplemented lazy sending of reshape GLEventListener events in GLCanvas and GLJPanel and deleted notion of deferred reshapes from GLDrawableHelper and elsewhere. Sharing of textures and display lists is now expressed in terms of GLContexts instead of GLDrawables. Still need to move pbuffer creation into GLDrawableFactory from the onscreen GLContext implementations. Added option to gleem ExaminerViewer to disable automatic redraws upon mouse events and respecified more of gleem to work on GLAutoDrawables rather than GLDrawables. Updated all JOGL demos to work with new APIs and slightly different initialization sequences (in particular, for pbuffers -- this will change with the addition of GLDrawableFactory.createGLPbuffer()). git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JSR-231@324 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java/games/jogl/GLCanvas.java')
-rw-r--r--src/net/java/games/jogl/GLCanvas.java71
1 files changed, 38 insertions, 33 deletions
diff --git a/src/net/java/games/jogl/GLCanvas.java b/src/net/java/games/jogl/GLCanvas.java
index e7a15ccf9..29ce3a701 100644
--- a/src/net/java/games/jogl/GLCanvas.java
+++ b/src/net/java/games/jogl/GLCanvas.java
@@ -63,18 +63,28 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
protected static final boolean DEBUG = Debug.debug("GLCanvas");
private GLDrawableHelper drawableHelper = new GLDrawableHelper();
+ private GLDrawable drawable;
private GLContextImpl context;
+ private boolean autoSwapBufferMode = true;
+ private boolean sendReshape = false;
public GLCanvas(GLCapabilities capabilities,
GLCapabilitiesChooser chooser,
- GLDrawable shareWith,
+ GLContext shareWith,
GraphicsDevice device) {
super(GLDrawableFactory.getFactory().chooseGraphicsConfiguration(capabilities, chooser, device));
- context = (GLContextImpl) GLContextFactory.getFactory().createGLContext(this, capabilities, chooser,
- GLContextHelper.getContext(shareWith));
+ drawable = GLDrawableFactory.getFactory().getGLDrawable(this, capabilities, chooser);
+ context = (GLContextImpl) drawable.createContext(shareWith);
context.setSynchronized(true);
}
+ public GLContext createContext(GLContext shareWith) {
+ return drawable.createContext(shareWith);
+ }
+
+ public void setRealized(boolean realized) {
+ }
+
public void display() {
maybeDoSingleThreadedWorkaround(displayOnEventDispatchThreadAction,
displayAction,
@@ -91,7 +101,7 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
create an OpenGL context for the component. */
public void addNotify() {
super.addNotify();
- context.setRealized();
+ drawable.setRealized(true);
if (DEBUG) {
System.err.println("GLCanvas.addNotify()");
}
@@ -101,6 +111,7 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
safe to have an OpenGL context for the component. */
public void removeNotify() {
context.destroy();
+ drawable.setRealized(false);
super.removeNotify();
if (DEBUG) {
System.err.println("GLCanvas.removeNotify()");
@@ -113,24 +124,7 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
directly. */
public void reshape(int x, int y, int width, int height) {
super.reshape(x, y, width, height);
- // Note: we ignore the given x and y within the parent component
- // since we are drawing directly into this heavyweight component.
- final int fx = 0;
- final int fy = 0;
- final int fwidth = width;
- final int fheight = height;
- final Runnable reshapeRunnable = new Runnable() {
- public void run() {
- getGL().glViewport(fx, fy, fwidth, fheight);
- drawableHelper.reshape(GLCanvas.this, fx, fy, fwidth, fheight);
- }
- };
- final Runnable reshapeOnEDTRunnable = new Runnable() {
- public void run() {
- drawableHelper.invokeGL(context, reshapeRunnable, true, initAction);
- }
- };
- maybeDoSingleThreadedWorkaround(reshapeOnEDTRunnable, reshapeRunnable, true);
+ sendReshape = true;
}
/** Overridden from Canvas to prevent Java2D's clearing of the
@@ -147,6 +141,10 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
drawableHelper.removeGLEventListener(listener);
}
+ public GLContext getContext() {
+ return context;
+ }
+
public GL getGL() {
return context.getGL();
}
@@ -164,11 +162,11 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
}
public void setAutoSwapBufferMode(boolean onOrOff) {
- context.setAutoSwapBufferMode(onOrOff);
+ drawableHelper.setAutoSwapBufferMode(onOrOff);
}
public boolean getAutoSwapBufferMode() {
- return context.getAutoSwapBufferMode();
+ return drawableHelper.getAutoSwapBufferMode();
}
public void swapBuffers() {
@@ -182,11 +180,8 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
public GLPbuffer createOffscreenDrawable(GLCapabilities capabilities,
int initialWidth,
int initialHeight) {
- return new GLPbufferImpl(context.createPbufferContext(capabilities, initialWidth, initialHeight));
- }
-
- GLContext getContext() {
- return context;
+ // FIXME: add option to not share textures and display lists with parent context
+ return new GLPbufferImpl(context.createPbufferDrawable(capabilities, initialWidth, initialHeight), getContext());
}
//----------------------------------------------------------------------
@@ -213,7 +208,7 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
throw new GLException(e);
}
} else {
- drawableHelper.invokeGL(context, invokeGLAction, isReshape, initAction);
+ drawableHelper.invokeGL(drawable, context, invokeGLAction, initAction);
}
}
@@ -226,6 +221,16 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
class DisplayAction implements Runnable {
public void run() {
+ if (sendReshape) {
+ // Note: we ignore the given x and y within the parent component
+ // since we are drawing directly into this heavyweight component.
+ int width = getWidth();
+ int height = getHeight();
+ getGL().glViewport(0, 0, width, height);
+ drawableHelper.reshape(GLCanvas.this, 0, 0, width, height);
+ sendReshape = false;
+ }
+
drawableHelper.display(GLCanvas.this);
}
}
@@ -233,7 +238,7 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
class SwapBuffersAction implements Runnable {
public void run() {
- context.swapBuffers();
+ drawable.swapBuffers();
}
}
private SwapBuffersAction swapBuffersAction = new SwapBuffersAction();
@@ -243,14 +248,14 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
// being resized on the AWT event dispatch thread
class DisplayOnEventDispatchThreadAction implements Runnable {
public void run() {
- drawableHelper.invokeGL(context, displayAction, false, initAction);
+ drawableHelper.invokeGL(drawable, context, displayAction, initAction);
}
}
private DisplayOnEventDispatchThreadAction displayOnEventDispatchThreadAction =
new DisplayOnEventDispatchThreadAction();
class SwapBuffersOnEventDispatchThreadAction implements Runnable {
public void run() {
- drawableHelper.invokeGL(context, swapBuffersAction, false, initAction);
+ drawableHelper.invokeGL(drawable, context, swapBuffersAction, initAction);
}
}
private SwapBuffersOnEventDispatchThreadAction swapBuffersOnEventDispatchThreadAction =