net.java.games.jogl
Class GLCanvas

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Canvas
          extended bynet.java.games.jogl.GLCanvas
All Implemented Interfaces:
Accessible, ComponentEvents, GLDrawable, ImageObserver, MenuContainer, Serializable

public final class GLCanvas
extends Canvas
implements GLDrawable

A heavyweight AWT component which provides OpenGL rendering support. This is the primary implementation of GLDrawable; GLJPanel is provided for compatibility with Swing user interfaces when adding a heavyweight doesn't work either because of Z-ordering or LayoutManager problems. This class can not be instantiated directly; use GLDrawableFactory to construct them.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Canvas
Canvas.AccessibleAWTCanvas
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Method Summary
 void addGLEventListener(GLEventListener listener)
          Adds a GLEventListener to this drawable.
 void addNotify()
          Overridden from Canvas; used to indicate when it's safe to create an OpenGL context for the component.
 boolean canCreateOffscreenDrawable()
          Indicates whether this drawable is capable of fabricating a subordinate offscreen drawable for advanced rendering techniques which require offscreen hardware-accelerated surfaces.
 GLPbuffer createOffscreenDrawable(GLCapabilities capabilities, int initialWidth, int initialHeight)
          Creates a subordinate offscreen drawable (pbuffer) for this drawable.
 void display()
          Causes OpenGL rendering to be performed for this GLDrawable by calling GLEventListener.display(net.java.games.jogl.GLDrawable) for all registered GLEventListeners.
 boolean getAutoSwapBufferMode()
          Indicates whether automatic buffer swapping is enabled for this drawable.
 GL getGL()
          Returns the GL pipeline object this GLDrawable uses.
 GLU getGLU()
          Returns the GLU pipeline object this GLDrawable uses.
 boolean getNoAutoRedrawMode()
          Returns whether automatic redraws are disabled for this drawable.
 Thread getRenderingThread()
          Returns the rendering thread for this drawable, or null if none has been set.
 void paint(Graphics g)
          Overridden from Canvas; calls display().
 void removeGLEventListener(GLEventListener listener)
          Removes a GLEventListener from this drawable.
 void removeNotify()
          Overridden from Canvas; used to indicate that it's no longer safe to have an OpenGL context for the component.
 void reshape(int x, int y, int width, int height)
          Overridden from Canvas; causes GLDrawableHelper.reshape(net.java.games.jogl.GLDrawable, int, int, int, int) to be called on all registered GLEventListeners.
 void setAutoSwapBufferMode(boolean onOrOff)
          Enables or disables automatic buffer swapping for this drawable.
 void setGL(GL gl)
          Sets the GL pipeline object this GLDrawable uses.
 void setGLU(GLU glu)
          Sets the GLU pipeline object this GLDrawable uses.
 void setNoAutoRedrawMode(boolean noAutoRedraw)
          Disables automatic redraws of this drawable if possible.
 void setRenderingThread(Thread currentThreadOrNull)
           Changes this GLDrawable to allow OpenGL rendering only from the supplied thread, which must either be the current thread or null.
 void swapBuffers()
          Swaps the front and back buffers of this drawable.
 void update(Graphics g)
          Overridden from Canvas to prevent Java2D's clearing of the canvas from interfering with the OpenGL rendering.
 
Methods inherited from class java.awt.Canvas
createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.java.games.jogl.GLDrawable
getSize, getSize, setSize, setSize
 
Methods inherited from interface net.java.games.jogl.ComponentEvents
addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener
 

Method Detail

display

public void display()
Description copied from interface: GLDrawable
Causes OpenGL rendering to be performed for this GLDrawable by calling GLEventListener.display(net.java.games.jogl.GLDrawable) for all registered GLEventListeners. Called automatically by the window system toolkit upon receiving a repaint() request. When used in conjunction with GLDrawable.setRenderingThread(java.lang.Thread), this routine may be called manually by the application's main loop for higher performance and better control over the rendering process. It is legal to call another GLDrawable's display method from within GLEventListener.display(net.java.games.jogl.GLDrawable).

Specified by:
display in interface GLDrawable

paint

public void paint(Graphics g)
Overridden from Canvas; calls display(). Should not be invoked by applications directly.


addNotify

public void addNotify()
Overridden from Canvas; used to indicate when it's safe to create an OpenGL context for the component.


removeNotify

public void removeNotify()
Overridden from Canvas; used to indicate that it's no longer safe to have an OpenGL context for the component.


reshape

public void reshape(int x,
                    int y,
                    int width,
                    int height)
Overridden from Canvas; causes GLDrawableHelper.reshape(net.java.games.jogl.GLDrawable, int, int, int, int) to be called on all registered GLEventListeners. Called automatically by the AWT; should not be invoked by applications directly.


update

public void update(Graphics g)
Overridden from Canvas to prevent Java2D's clearing of the canvas from interfering with the OpenGL rendering.


addGLEventListener

public void addGLEventListener(GLEventListener listener)
Description copied from interface: GLDrawable
Adds a GLEventListener to this drawable. If multiple listeners are added to a given drawable, they are notified of events in an arbitrary order.

Specified by:
addGLEventListener in interface GLDrawable

removeGLEventListener

public void removeGLEventListener(GLEventListener listener)
Description copied from interface: GLDrawable
Removes a GLEventListener from this drawable. Note that if this is done from within a particular drawable's GLEventListener handler (reshape, display, etc.) that it is not guaranteed that all other listeners will be evaluated properly during this update cycle.

Specified by:
removeGLEventListener in interface GLDrawable

getGL

public GL getGL()
Description copied from interface: GLDrawable
Returns the GL pipeline object this GLDrawable uses.

Specified by:
getGL in interface GLDrawable

setGL

public void setGL(GL gl)
Description copied from interface: GLDrawable
Sets the GL pipeline object this GLDrawable uses.

Specified by:
setGL in interface GLDrawable

getGLU

public GLU getGLU()
Description copied from interface: GLDrawable
Returns the GLU pipeline object this GLDrawable uses.

Specified by:
getGLU in interface GLDrawable

setGLU

public void setGLU(GLU glu)
Description copied from interface: GLDrawable
Sets the GLU pipeline object this GLDrawable uses.

Specified by:
setGLU in interface GLDrawable

setRenderingThread

public void setRenderingThread(Thread currentThreadOrNull)
                        throws GLException
Description copied from interface: GLDrawable

Changes this GLDrawable to allow OpenGL rendering only from the supplied thread, which must either be the current thread or null. Attempts by other threads to perform OpenGL operations like rendering or resizing the window will be ignored as long as the thread is set. Setting up the rendering thread is not required but enables the system to perform additional optimizations, in particular when the application requires control over the rendering loop. Before exiting, setRenderingThread(null) must be called or other threads will be unable to perform OpenGL rendering to this drawable. Throws GLException if the rendering thread for this drawable has been set and attempts are made to set or clear the rendering thread from another thread, or if the passed thread is not equal to the current thread or null. Also throws GLException if the current thread attempts to call setRenderingThread on more than one drawable.

NOTE: Currently this routine is only advisory, which means that on some platforms the underlying optimizations are disabled and setting the rendering thread has no effect. Applications should not rely on setRenderingThread to prevent rendering from other threads.

Specified by:
setRenderingThread in interface GLDrawable
Throws:
GLException - if the rendering thread for this drawable has been set by another thread or if the passed thread is not equal to the current thread or null

getRenderingThread

public Thread getRenderingThread()
Description copied from interface: GLDrawable
Returns the rendering thread for this drawable, or null if none has been set.

Specified by:
getRenderingThread in interface GLDrawable

setNoAutoRedrawMode

public void setNoAutoRedrawMode(boolean noAutoRedraw)
Description copied from interface: GLDrawable
Disables automatic redraws of this drawable if possible. This is provided as an overriding mechanism for applications which perform animation on the drawable and for which the (currently advisory) GLDrawable.setRenderingThread(java.lang.Thread) does not provide strict enough guarantees. Its sole purpose is to avoid deadlocks that are unfortunately all too easy to run into when both animating a drawable from a given thread as well as having updates performed by the AWT event thread (repaints, etc.). When it is enabled, repaint requests driven by the AWT will not result in the OpenGL event listeners' display methods being called from the AWT thread, unless (as with GLJPanel) this is the only mechanism by which repaints are done. The necessity of this API may be rethought in a future release. Defaults to false.

Specified by:
setNoAutoRedrawMode in interface GLDrawable

getNoAutoRedrawMode

public boolean getNoAutoRedrawMode()
Description copied from interface: GLDrawable
Returns whether automatic redraws are disabled for this drawable. Defaults to false.

Specified by:
getNoAutoRedrawMode in interface GLDrawable

setAutoSwapBufferMode

public void setAutoSwapBufferMode(boolean onOrOff)
Description copied from interface: GLDrawable
Enables or disables automatic buffer swapping for this drawable. By default this property is set to true; when true, after all GLEventListeners have been called for a display() event, the front and back buffers are swapped, displaying the results of the render. When disabled, the user is responsible for calling GLDrawable.swapBuffers() manually.

Specified by:
setAutoSwapBufferMode in interface GLDrawable

getAutoSwapBufferMode

public boolean getAutoSwapBufferMode()
Description copied from interface: GLDrawable
Indicates whether automatic buffer swapping is enabled for this drawable. See GLDrawable.setAutoSwapBufferMode(boolean).

Specified by:
getAutoSwapBufferMode in interface GLDrawable

swapBuffers

public void swapBuffers()
Description copied from interface: GLDrawable
Swaps the front and back buffers of this drawable. When automatic buffer swapping is enabled (as is the default), it is not necessary to call this method and doing so may have undefined results.

Specified by:
swapBuffers in interface GLDrawable

canCreateOffscreenDrawable

public boolean canCreateOffscreenDrawable()
Description copied from interface: GLDrawable
Indicates whether this drawable is capable of fabricating a subordinate offscreen drawable for advanced rendering techniques which require offscreen hardware-accelerated surfaces.

Specified by:
canCreateOffscreenDrawable in interface GLDrawable

createOffscreenDrawable

public GLPbuffer createOffscreenDrawable(GLCapabilities capabilities,
                                         int initialWidth,
                                         int initialHeight)
Description copied from interface: GLDrawable
Creates a subordinate offscreen drawable (pbuffer) for this drawable. This routine should only be called if GLDrawable.canCreateOffscreenDrawable() returns true. The passed capabilities are matched according to the platform-dependent pbuffer format selection algorithm, which currently can not be overridden.

Specified by:
createOffscreenDrawable in interface GLDrawable