net.java.games.jogl
Class GLJPanel
JPanel
net.java.games.jogl.GLJPanel
- ComponentEvents, GLDrawable
public final class GLJPanel
extends JPanel
A lightweight Swing component which provides OpenGL rendering
support. Provided for compatibility with Swing user interfaces
when adding a heavyweight doesn't work either because of
Z-ordering or LayoutManager problems. This component attempts to
use hardware-accelerated rendering via pbuffers and falls back on
to software rendering if problems occur. This class can not be
instantiated directly; use
GLDrawableFactory
to construct
them.
Note that because this component attempts to use pbuffers for
rendering, and because pbuffers can not be resized, somewhat
surprising behavior may occur during resize operations; the
GLEventListener.init(GLDrawable)
method may be called multiple times as the
pbuffer is resized to be able to cover the size of the GLJPanel.
This behavior is correct, as the textures and display lists for
the GLJPanel will have been lost during the resize operation. The
application should attempt to make its GLEventListener.init()
methods as side-effect-free as possible.
protected static boolean | DEBUG
|
void | addGLEventListener(GLEventListener listener) - Adds a
GLEventListener to this drawable.
|
void | addNotify()
|
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(GLDrawable) for all registered
GLEventListener s.
|
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 | paintComponent(Graphics g) - Overridden from JComponent; calls
GLEventListener.display(GLDrawable) .
|
void | removeGLEventListener(GLEventListener listener) - Removes a
GLEventListener from this drawable.
|
void | removeNotify() - Overridden from JPanel; 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(GLDrawable,int,int,int,int)
to be called on all registered GLEventListener s.
|
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 noAutoRedraws) - Disables automatic redraws of this drawable if possible.
|
void | setOpaque(boolean opaque)
|
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.
|
DEBUG
protected static final boolean DEBUG
addNotify
public void addNotify()
canCreateOffscreenDrawable
public boolean canCreateOffscreenDrawable()
Indicates whether this drawable is capable of fabricating a
subordinate offscreen drawable for advanced rendering techniques
which require offscreen hardware-accelerated surfaces. Note that
this method is only guaranteed to return a correct result once
your GLEventListener's init() method has been called.
- canCreateOffscreenDrawable in interface GLDrawable
createOffscreenDrawable
public GLPbuffer createOffscreenDrawable(GLCapabilities capabilities,
int initialWidth,
int initialHeight)
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.
- createOffscreenDrawable in interface GLDrawable
getGL
public GL getGL()
Returns the
GL
pipeline object this GLDrawable uses. If
this method is called outside of the
GLEventListener
's
callback methods (init, display, etc.) it may return null. Users
should not rely on the identity of the returned GL object; for
example, users should not maintain a hash table with the GL
object as the key. Additionally, the GL object should not be
cached in client code, but should be re-fetched from the
GLDrawable at the beginning of each call to init, display,
etc.
- getGL in interface GLDrawable
getNoAutoRedrawMode
public boolean getNoAutoRedrawMode()
Returns whether automatic redraws are disabled for this
drawable. Defaults to false.
- getNoAutoRedrawMode in interface GLDrawable
getRenderingThread
public Thread getRenderingThread()
Returns the rendering thread for this drawable, or null if none
has been set.
- getRenderingThread in interface GLDrawable
paintComponent
public void paintComponent(Graphics g)
removeGLEventListener
public void removeGLEventListener(GLEventListener listener)
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.
- removeGLEventListener in interface GLDrawable
removeNotify
public void removeNotify()
Overridden from JPanel; 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)
setAutoSwapBufferMode
public void setAutoSwapBufferMode(boolean onOrOff)
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.
- setAutoSwapBufferMode in interface GLDrawable
setGL
public void setGL(GL gl)
Sets the
GL
pipeline object this GLDrawable uses. This
should only be called from within the GLEventListener's callback
methods, and usually only from within the init() method, in
order to install a composable pipeline. See the JOGL demos for
examples.
- setGL in interface GLDrawable
setGLU
public void setGLU(GLU glu)
Sets the
GLU
pipeline object this GLDrawable uses.
- setGLU in interface GLDrawable
setNoAutoRedrawMode
public void setNoAutoRedrawMode(boolean noAutoRedraws)
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(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.
- setNoAutoRedrawMode in interface GLDrawable
setOpaque
public void setOpaque(boolean opaque)
setRenderingThread
public void setRenderingThread(Thread currentThreadOrNull)
throws GLException
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.
- setRenderingThread in interface GLDrawable
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
swapBuffers
public void swapBuffers()
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.
- swapBuffers in interface GLDrawable