Top Description Inners Fields Constructors Methods
com.jogamp.opengl.awt

public Class GLCanvas

extends Canvas
implements AWTGLAutoDrawable, WindowClosingProtocol, OffscreenLayerOption, AWTPrintLifecycle, GLSharedContextSetter, ScalableSurface
Class Inheritance
All Implemented Interfaces
com.jogamp.nativewindow.ScalableSurface, com.jogamp.opengl.GLSharedContextSetter, com.jogamp.opengl.GLAutoDrawable, com.jogamp.opengl.GLDrawable, com.jogamp.nativewindow.NativeSurfaceHolder, com.jogamp.nativewindow.awt.AWTPrintLifecycle, com.jogamp.nativewindow.OffscreenLayerOption, com.jogamp.nativewindow.WindowClosingProtocol, com.jogamp.opengl.awt.AWTGLAutoDrawable, com.jogamp.opengl.awt.ComponentEvents
Annotations
@SuppressWarnings:serial
Imports
java.beans.Beans, java.lang.reflect.Method, .InvocationTargetException, java.security.AccessController, .PrivilegedAction, java.awt.Canvas, .Color, .FontMetrics, .Frame, .Graphics, .Graphics2D, .GraphicsConfiguration, .GraphicsDevice, .EventQueue, java.awt.event.HierarchyEvent, .HierarchyListener, java.awt.geom.NoninvertibleTransformException, .Rectangle2D, java.util.ArrayList, .List, com.jogamp.nativewindow.AbstractGraphicsConfiguration, .OffscreenLayerOption, .ScalableSurface, .VisualIDHolder, .WindowClosingProtocol, .AbstractGraphicsDevice, .AbstractGraphicsScreen, .GraphicsConfigurationFactory, .NativeSurface, .NativeWindowFactory, com.jogamp.opengl.GL, .GLAnimatorControl, .GLAutoDrawable, .GLCapabilities, .GLCapabilitiesChooser, .GLCapabilitiesImmutable, .GLContext, .GLDrawable, .GLDrawableFactory, .GLEventListener, .GLException, .GLOffscreenAutoDrawable, .GLProfile, .GLRunnable, .GLSharedContextSetter, .Threading, .JoglVersion, com.jogamp.common.GlueGenVersion, com.jogamp.common.util.VersionUtil, com.jogamp.common.util.awt.AWTEDTExecutor, com.jogamp.common.util.locks.LockFactory, .RecursiveLock, com.jogamp.nativewindow.awt.AWTGraphicsConfiguration, .AWTGraphicsDevice, .AWTGraphicsScreen, .AWTPrintLifecycle, .AWTWindowClosingProtocol, .JAWTWindow, com.jogamp.opengl.util.GLDrawableUtil, .TileRenderer, jogamp.nativewindow.SurfaceScaleUtils, jogamp.opengl.Debug, .GLContextImpl, .GLDrawableHelper, .GLDrawableImpl, jogamp.opengl.awt.AWTTilePainter

A heavyweight AWT component which provides OpenGL rendering support. This is the primary implementation of an AWT 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.
Offscreen Layer Remarks
setShallUseOffscreenLayer(true) maybe called to use an offscreen drawable (FBO or PBuffer) allowing the underlying JAWT mechanism to composite the image, if supported.

setShallUseOffscreenLayer(true) is being called if GLCapabilitiesImmutable#isOnscreen() is false.

Java2D OpenGL Remarks
To avoid any conflicts with a potential Java2D OpenGL context,
you shall consider setting the following JVM properties:
This is especially true in case you want to utilize a GLProfile other than GLProfile#GL2, eg. using GLProfile#getMaxFixedFunc().
On the other hand, if you like to experiment with GLJPanel's utilization of Java2D's OpenGL pipeline, you have to set them to
Disable Background Erase
GLCanvas tries to disable background erase for the AWT Canvas before native peer creation (X11) and after it (Windows),
utilizing the optional java.awt.Toolkit method disableBeackgroundErase(java.awt.Canvas).
However if this does not give you the desired results, you may want to disable AWT background erase in general:

OpenGL Context Sharing
To share a GLContext see the following note in the documentation overview: context sharing as well as GLSharedContextSetter.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private int
private volatile AWTGraphicsConfiguration
private volatile GraphicsDevice
private final AWTWindowClosingProtocol
private final GLCapabilitiesImmutable
private final GLCapabilitiesChooser
private volatile GLContextImpl
private static final boolean
private final Runnable
private static boolean
private static Method
private final Runnable
private final Runnable
private final Runnable
disposeJAWTWindowAndAWTDeviceOnEDT

Disposes the JAWTWindow and AbstractGraphicsDevice within EDT, since resources created (X11: Display), must be destroyed in the same thread, where they have been created.

private volatile GLDrawableImpl
private final float[]
private final GLDrawableHelper
private final HierarchyListener
private final Runnable
private volatile boolean
private volatile JAWTWindow
private final RecursiveLock
private final float[]
private final float[]
private volatile boolean
private GLAnimatorControl
private AWTTilePainter
private GLAutoDrawable
private final Runnable
private final Runnable
pack-priv final float[]
private volatile boolean
private final Runnable
private final Runnable
private boolean
private final Runnable
private final Runnable

Constructor Summary

AccessConstructor and Description
public
GLCanvas()

Creates a new GLCanvas component with a default set of OpenGL capabilities, using the default OpenGL capabilities selection mechanism, on the default screen device.

public
GLCanvas(final GLCapabilitiesImmutable capsReqUser)

Creates a new GLCanvas component with the requested set of OpenGL capabilities, using the default OpenGL capabilities selection mechanism, on the default screen device.

public
GLCanvas(final GLCapabilitiesImmutable capsReqUser, final GLCapabilitiesChooser chooser, final GraphicsDevice device)

Creates a new GLCanvas component.

Method Summary

Modifier and TypeMethod and Description
public void
addGLEventListener(final GLEventListener
The GLEventListener object to be inserted
listener
)

Implements com.jogamp.opengl.GLAutoDrawable.addGLEventListener.

Adds the given listener to the end of this drawable queue.
public void
addGLEventListener(final int
Position where the listener will be inserted. Should be within (0 <= index && index <= size()). An index value of -1 is interpreted as the end of the list, size().
index
,
final GLEventListener
The GLEventListener object to be inserted
listener
)

Implements com.jogamp.opengl.GLAutoDrawable.addGLEventListener.

Adds the given listener at the given index of this drawable queue.
public void
addNotify()

Overrides java.awt.Canvas.addNotify.

Overridden to track when this component is added to a container.
public boolean
areAllGLEventListenerInitialized()

Implements com.jogamp.opengl.GLAutoDrawable.areAllGLEventListenerInitialized.

Returns true if all added GLEventListener are initialized, otherwise false.
private AWTGraphicsConfiguration

Returns:

the chosen AWTGraphicsConfiguration
chooseGraphicsConfiguration
(final GLCapabilitiesImmutable capsChosen, final GLCapabilitiesImmutable capsRequested, final GLCapabilitiesChooser chooser, final GraphicsDevice device)

Issues the GraphicsConfigurationFactory's choosing facility within EDT, since resources created (X11: Display), must be destroyed in the same thread, where they have been created.

public GLContext
createContext(final GLContext shareWith)

Implements com.jogamp.opengl.GLAutoDrawable.createContext.

Creates a new context for drawing to this drawable that will optionally share buffer objects, textures and other server-side OpenGL objects with the specified GLContext.
private boolean
createContextImpl(final GLDrawable drawable)

private void
public void
destroy()

Implements com.jogamp.opengl.GLAutoDrawable.destroy.

Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
protected void
destroyImpl(final boolean destroyJAWTWindowAndAWTDevice)

private void
public void
display()

Implements com.jogamp.opengl.GLAutoDrawable.display.

Causes OpenGL rendering to be performed for this GLAutoDrawable in the following order:

public GLEventListener
disposeGLEventListener(final GLEventListener
The GLEventListener object to be disposed and removed if remove is true
listener
,
final boolean
pass true to have the listener removed from this drawable queue, otherwise pass false
remove
)

Implements com.jogamp.opengl.GLAutoDrawable.disposeGLEventListener.

Disposes the given listener via dispose(..) if it has been initialized and added to this queue.
public void
flushGLRunnables()

Implements com.jogamp.opengl.GLAutoDrawable.flushGLRunnables.

Flushes all enqueued GLRunnable of this GLAutoDrawable including notifying waiting executor.
public GLAnimatorControl
public boolean
getAutoSwapBufferMode()

Implements com.jogamp.opengl.GLAutoDrawable.getAutoSwapBufferMode.

Indicates whether automatic buffer swapping is enabled for this drawable.
public GLCapabilitiesImmutable
getChosenGLCapabilities()

Implements com.jogamp.opengl.GLDrawable.getChosenGLCapabilities.

Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / visual / GLProfile) for this drawable.
public GLContext
getContext()

Implements com.jogamp.opengl.GLAutoDrawable.getContext.

Returns the context associated with this drawable.
public int
public final float[]
getCurrentSurfaceScale(final float[]
float[2] storage for the result
result
)

Implements com.jogamp.nativewindow.ScalableSurface.getCurrentSurfaceScale.

Returns the current pixel scale of the associated NativeSurface.
public WindowClosingProtocol.WindowClosingMode
public final GLDrawable
getDelegatedDrawable()

Implements com.jogamp.opengl.GLAutoDrawable.getDelegatedDrawable.

If the implementation uses delegation, return the delegated GLDrawable instance, otherwise return this instance.
public final Thread
public GLDrawableFactory
getFactory()

Implements com.jogamp.opengl.GLDrawable.getFactory.

Return the GLDrawableFactory being used to create this instance.
public GL
getGL()

Implements com.jogamp.opengl.GLAutoDrawable.getGL.

Returns the GL pipeline object this GLAutoDrawable uses.
public GLEventListener
getGLEventListener(final int
Position of the listener to be returned. Should be within (0 <= index && index < size()). An index value of -1 is interpreted as last listener, size()-1.
index
)

Implements com.jogamp.opengl.GLAutoDrawable.getGLEventListener.

Returns the GLEventListener at the given index of this drawable queue.
public int
public boolean
getGLEventListenerInitState(final GLEventListener
the GLEventListener object to query it's initialized state.
listener
)

Implements com.jogamp.opengl.GLAutoDrawable.getGLEventListenerInitState.

Retrieves whether the given listener is initialized or not.
public GLProfile
getGLProfile()

Implements com.jogamp.opengl.GLDrawable.getGLProfile.

Fetches the GLProfile for this drawable.
public GraphicsConfiguration
getGraphicsConfiguration()

Overrides java.awt.Component.getGraphicsConfiguration.

Gets the GraphicsConfiguration associated with this Component.
public long
getHandle()

Implements com.jogamp.opengl.GLDrawable.getHandle.

Returns the GL drawable handle, guaranteed to be valid after realization and while it's surface is being locked.
public float[]
getMaximumSurfaceScale(final float[]
float[2] storage for the result
result
)

Implements com.jogamp.nativewindow.ScalableSurface.getMaximumSurfaceScale.

Returns the maximum pixel scale of the associated NativeSurface.
public float[]
getMinimumSurfaceScale(final float[]
float[2] storage for the result
result
)

Implements com.jogamp.nativewindow.ScalableSurface.getMinimumSurfaceScale.

Returns the minimum pixel scale of the associated NativeSurface.
public NativeSurface
private final String
public GLCapabilitiesImmutable
getRequestedGLCapabilities()

Implements com.jogamp.opengl.GLDrawable.getRequestedGLCapabilities.

Fetches the GLCapabilitiesImmutable corresponding to the user requested OpenGL capabilities (pixel format / visual / GLProfile) for this drawable.
public final float[]
getRequestedSurfaceScale(final float[]
float[2] storage for the result
result
)

Implements com.jogamp.nativewindow.ScalableSurface.getRequestedSurfaceScale.

Returns the requested pixel scale of the associated NativeSurface.
public final boolean
public int
getSurfaceHeight()

Implements com.jogamp.opengl.GLDrawable.getSurfaceHeight.

Returns the height of this GLDrawable's surface client area in pixel units.
public int
getSurfaceWidth()

Implements com.jogamp.opengl.GLDrawable.getSurfaceWidth.

Returns the width of this GLDrawable's surface client area in pixel units.
protected static String
public final RecursiveLock
getUpstreamLock()

Implements com.jogamp.opengl.GLAutoDrawable.getUpstreamLock.

Returns the recursive lock object of the upstream widget to synchronize multithreaded access on top of NativeSurface#lockSurface().
public final Object
getUpstreamWidget()

Implements com.jogamp.opengl.GLAutoDrawable.getUpstreamWidget.

Method may return the upstream UI toolkit object holding this GLAutoDrawable instance, if exist.</td<></td<></td<></td<></td<>
public boolean
invoke(final boolean
if true block until execution of glRunnable is finished, otherwise return immediately w/o waiting
wait
,
final GLRunnable
the GLRunnable to execute within display()
glRunnable
)

Implements com.jogamp.opengl.GLAutoDrawable.invoke.

Enqueues a one-shot GLRunnable, which will be executed within the next display() call after all registered GLEventListeners display(GLAutoDrawable) methods have been called.
public boolean
invoke(final boolean
if true block until execution of the last glRunnable is finished, otherwise return immediately w/o waiting
wait
,
final List<GLRunnable>
the GLRunnables to execute within display()
glRunnables
)

Implements com.jogamp.opengl.GLAutoDrawable.invoke.

Extends invoke(boolean, GLRunnable) functionality allowing to inject a list of GLRunnables.
public boolean
isGLOriented()

Implements com.jogamp.opengl.GLDrawable.isGLOriented.

Returns true if the drawable is rendered in OpenGL's coordinate system, origin at bottom left.
public final boolean
isOffscreenLayerSurfaceEnabled()

Implements com.jogamp.nativewindow.OffscreenLayerOption.isOffscreenLayerSurfaceEnabled.

Returns true if this instance uses an offscreen layer, otherwise false.
public boolean
isRealized()

Implements com.jogamp.opengl.GLDrawable.isRealized.

Returns true if this drawable is realized, otherwise true.
public final boolean
isThreadGLCapable()

Implements com.jogamp.opengl.GLAutoDrawable.isThreadGLCapable.

Indicates whether the current thread is capable of performing OpenGL-related work.
public static void
main(final String[] args)

A most simple JOGL AWT test entry

public void
paint(final Graphics
the specified Graphics context
g
)

Overrides java.awt.Canvas.paint.

Overridden to cause OpenGL rendering to be performed during repaint cycles.
public void
public GLEventListener
removeGLEventListener(final GLEventListener
The GLEventListener object to be removed
listener
)

Implements com.jogamp.opengl.GLAutoDrawable.removeGLEventListener.

Removes the given listener from this drawable queue.
public void
removeNotify()

Overrides java.awt.Component.removeNotify.

Overridden to track when this component is removed from a container.

public void
reshape(final int
the x coordinate of the upper left corner of the rectangle
x
,
final int
the y coordinate of the upper left corner of the rectangle
y
,
final int
the width of the rectangle
width
,
final int
the height of the rectangle
height
)

Overrides java.awt.Component.reshape.

Overridden to cause GLDrawableHelper#reshape to be called on all registered GLEventListeners.
private void
reshapeImpl(final int width, final int height)

public void
setAnimator(final GLAnimatorControl
null reference indicates no animator is using this GLAutoDrawable,
a valid reference indicates an animator is using this GLAutoDrawable.
animatorControl
)

Implements com.jogamp.opengl.GLAutoDrawable.setAnimator.

Registers the usage of an animator, an com.jogamp.opengl.GLAnimatorControl implementation.
public void
setAutoSwapBufferMode(final boolean onOrOff)

Implements com.jogamp.opengl.GLAutoDrawable.setAutoSwapBufferMode.

Enables or disables automatic buffer swapping for this drawable.
private void
public GLContext
setContext(final GLContext
the new context, maybe null for dis-association.
newCtx
,
final boolean
if true, destroy the previous context if exists
destroyPrevCtx
)

Implements com.jogamp.opengl.GLAutoDrawable.setContext.

Associate the new context, newtCtx, to this auto-drawable.
public void
setContextCreationFlags(final int
Additional context creation flags.
flags
)

Implements com.jogamp.opengl.GLAutoDrawable.setContextCreationFlags.

public WindowClosingProtocol.WindowClosingMode
public final Thread
setExclusiveContextThread(final Thread
the exclusive thread to claim the context, or null for default operation.
t
)

Implements com.jogamp.opengl.GLAutoDrawable.setExclusiveContextThread.

Dedicates this instance's GLContext to the given thread.
public GL
setGL(final GL gl)

Implements com.jogamp.opengl.GLAutoDrawable.setGL.

Sets the GL pipeline object this GLAutoDrawable uses.
public void
setGLEventListenerInitState(final GLEventListener
the GLEventListener object to perform a state change.
listener
,
final boolean
if true, mark the listener initialized, otherwise uninitialized.
initialized
)

Implements com.jogamp.opengl.GLAutoDrawable.setGLEventListenerInitState.

Sets the given listener's initialized state.
public final void
setRealized(final boolean realized)

Implements com.jogamp.opengl.GLDrawable.setRealized.

Indicates to GLDrawable implementations whether the underlying surface has been created and can be drawn into.
private final void
setRealizedImpl(final boolean realized)

public void
setShallUseOffscreenLayer(final boolean v)

Implements com.jogamp.nativewindow.OffscreenLayerOption.setShallUseOffscreenLayer.

Request an offscreen layer, if supported.
public final void
setSharedAutoDrawable(final GLAutoDrawable
The GLAutoDrawable, which OpenGL context shall be shared by this GLAutoDrawable's GLContext.
sharedAutoDrawable
)

Implements com.jogamp.opengl.GLSharedContextSetter.setSharedAutoDrawable.

Specifies an GLAutoDrawable, which OpenGL context shall be shared by this GLAutoDrawable's GLContext.
public final void
setSharedContext(final GLContext
The OpenGL context to be shared by this GLAutoDrawable's GLContext.
sharedContext
)

Implements com.jogamp.opengl.GLSharedContextSetter.setSharedContext.

Specifies an OpenGL context, which shall be shared by this GLAutoDrawable's GLContext.
public final boolean
setSurfaceScale(final float[]
requested surface pixel scale float[2] values for x- and y-direction.
pixelScale
)

Implements com.jogamp.nativewindow.ScalableSurface.setSurfaceScale.

Request a pixel scale in x- and y-direction for the associated NativeSurface, where size_in_pixel_units = pixel_scale * size_in_window_units.
private final boolean
public void
setupPrint(final double
Graphics2D scaling factor, i.e. rendering 1/scaleMatX * width pixels
scaleMatX
,
final double
Graphics2D scaling factor, i.e. rendering 1/scaleMatY * height pixels
scaleMatY
,
final int
multisampling value: < 0 turns off, == 0 leaves as-is, > 0 enables using given num samples
numSamples
,
final int
custom tile width for tile renderer, pass -1 for default.
tileWidth
,
final int
custom tile height for tile renderer, pass -1 for default. FIXME: Add border size !
tileHeight
)

Implements com.jogamp.nativewindow.awt.AWTPrintLifecycle.setupPrint.

Shall be called before PrinterJob#print().
public void
swapBuffers()

Implements com.jogamp.opengl.GLDrawable.swapBuffers.

Swaps the front and back buffers of this drawable.
public String
toString()

Overrides java.awt.Component.toString.

Implements com.jogamp.opengl.GLDrawable.toString.

Returns a string representation of this component and its values.
public void
update(final Graphics
the specified Graphics context
g
)

Overrides java.awt.Canvas.update.

Overridden from Canvas to prevent the AWT's clearing of the canvas from interfering with the OpenGL rendering.
private final boolean
private boolean
Inherited from java.awt.Canvas:
createBufferStrategycreateBufferStrategygetAccessibleContextgetBufferStrategy