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

public Class GLJPanel

extends JPanel
implements AWTGLAutoDrawable, WindowClosingProtocol, 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.WindowClosingProtocol, com.jogamp.opengl.awt.AWTGLAutoDrawable, com.jogamp.opengl.awt.ComponentEvents
Annotations
@SuppressWarnings:serial
Imports
java.awt.Color, .EventQueue, .FontMetrics, .Graphics, .Graphics2D, .GraphicsConfiguration, .GraphicsEnvironment, .Rectangle, java.awt.event.HierarchyEvent, .HierarchyListener, java.awt.geom.NoninvertibleTransformException, .Rectangle2D, java.awt.image.BufferedImage, .DataBufferInt, java.beans.Beans, java.nio.IntBuffer, java.util.List, com.jogamp.nativewindow.AbstractGraphicsDevice, .NativeSurface, .ScalableSurface, .SurfaceUpdatedListener, .WindowClosingProtocol, com.jogamp.nativewindow.util.PixelFormat, com.jogamp.opengl.GL, .GL2, .GL2ES3, .GL2GL3, .GLAnimatorControl, .GLAutoDrawable, .GLCapabilities, .GLCapabilitiesChooser, .GLCapabilitiesImmutable, .GLContext, .GLDrawable, .GLDrawableFactory, .GLEventListener, .GLException, .GLFBODrawable, .GLOffscreenAutoDrawable, .GLProfile, .GLRunnable, .GLSharedContextSetter, .Threading, .FBObject, .GLRendererQuirks, javax.swing.JPanel, jogamp.nativewindow.SurfaceScaleUtils, .WrappedSurface, jogamp.nativewindow.jawt.JAWTUtil, jogamp.opengl.Debug, .GLContextImpl, .GLDrawableFactoryImpl, .GLDrawableHelper, .GLDrawableImpl, jogamp.opengl.awt.AWTTilePainter, .Java2D, jogamp.opengl.util.glsl.GLSLTextureRaster, com.jogamp.common.util.InterruptSource, .PropertyAccess, com.jogamp.common.util.awt.AWTEDTExecutor, com.jogamp.common.util.locks.LockFactory, .RecursiveLock, com.jogamp.nativewindow.awt.AWTPrintLifecycle, .AWTWindowClosingProtocol, com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes, .GLPixelBuffer.SingletonGLPixelBufferProvider, .GLDrawableUtil, .GLPixelStorageModes, .TileRenderer, com.jogamp.opengl.util.awt.AWTGLPixelBuffer, .AWTGLPixelBuffer.AWTGLPixelBufferProvider, .AWTGLPixelBuffer.SingleAWTGLPixelBufferProvider, com.jogamp.opengl.util.texture.TextureState

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.

The GLJPanel can be made transparent by creating it with a GLCapabilities object with alpha bits specified and calling setOpaque(false). Pixels with resulting OpenGL alpha values less than 1.0 will be overlaid on any underlying Swing rendering.

This component attempts to use hardware-accelerated rendering via FBO or pbuffers and falls back on to software rendering if none of the former are available using GLDrawableFactory.createOffscreenDrawable(..).

A vertical-flip is required, if the drawable isGLOriented() and vertical flip is not skipped.
In this case this component performs the required vertical flip to bring the content from OpenGL's orientation into AWT's orientation.
In case GLSL based vertical-flip is not available, the CPU intensive System.arraycopy(..) is used line by line. See details about FBO and GLSL vertical flipping.

For performance reasons, as well as for GL state sideeffects, skipping vertical flip is highly recommended!

The OpenGL path is concluded by copying the rendered pixels an BufferedImage via glReadPixels(..) for later Java2D composition.

Finally the Java2D compositioning takes place via via Graphics.drawImage(...) on the prepared BufferedImage as described above.

Please read Java2D OpenGL Remarks.

FBO / GLSL Vertical Flip
If vertical flip is required, FBO is used, GLSL is available and vertical flip is not skipped, a fragment shader is utilized to flip the FBO texture vertically. This hardware-accelerated step can be disabled via system property jogl.gljpanel.noglsl.

The FBO / GLSL code path uses one texture-unit and binds the FBO texture to it's active texture-target, see setTextureUnit(int) and getTextureUnit().

The active and dedicated texture-unit's GL#GL_TEXTURE_2D state is preserved via TextureState. See also Order of Texture Commands.

The current gl-viewport is preserved.

Warning (Bug 842): Certain GL states other than viewport and texture (see above) influencing rendering, will also influence the GLSL vertical flip, e.g. glFrontFace(GL#GL_CCW). It is recommended to reset those states to default when leaving the GLEventListener#display(GLAutoDrawable) method! We may change this behavior in the future, i.e. preserve all influencing states.

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
pack-priv static interface
GLJPanel.Backend

Abstraction of the different rendering backends: i.e., pure software / pixmap rendering, pbuffer-based acceleration, Java 2D JOGL bridge

private class
pack-priv class
pack-priv class
pack-priv class

Field Summary

Modifier and TypeField and Description
private int
private boolean
private final AWTWindowClosingProtocol
private volatile GLJPanel.Backend
private final GLCapabilitiesChooser
private AWTGLPixelBuffer.AWTGLPixelBufferProvider
private static final boolean
private static final boolean
private static final boolean
private final Runnable
private volatile GLDrawableFactoryImpl
private boolean
private final float[]
private final GLDrawableHelper
private final HierarchyListener
private final Object
private volatile boolean
private volatile boolean
private static boolean
java2DGLPipelineOK

Indicates whether the Java 2D OpenGL pipeline's usage is error free.

private static final boolean
java2dOGLEnabledByProp

Indicates whether the Java 2D OpenGL pipeline is requested by user.

private final RecursiveLock
private final float[]
private final float[]
private final Runnable
private int
panelHeight

Scaled pixel height of the actual GLJPanel: reshapeHeight -> panelHeight -> backend.height

private int
panelWidth

Scaled pixel width of the actual GLJPanel: reshapeWidth -> panelWidth -> backend.width

private volatile boolean
private GLAnimatorControl
private AWTTilePainter
private GLAutoDrawable
private final Runnable
private volatile GLCapabilitiesImmutable
reqOffscreenCaps

Requested single buffered offscreen caps

private final float[]
private int
private int
reshapeHeight

For handling reshape events lazily: reshapeHeight -> panelHeight -> backend.height in pixel units (scaled)

private int
reshapeWidth

For handling reshape events lazily: reshapeWidth -> panelWidth -> backend.width in pixel units (scaled)

private boolean
private final Runnable
private final Runnable
private static AWTGLPixelBuffer.SingleAWTGLPixelBufferProvider
private static final boolean
private boolean
private final GLJPanel.Updater
private final Runnable
private final Runnable
private final Runnable
private static final boolean
private static final boolean
useJava2DGLPipeline

Indicates whether the Java 2D OpenGL pipeline is enabled, resource-compatible and requested by user.

private int
private int

Constructor Summary

AccessConstructor and Description
public
GLJPanel()

Creates a new GLJPanel component with a default set of OpenGL capabilities and using the default OpenGL capabilities selection mechanism.

public
GLJPanel(final GLCapabilitiesImmutable userCapsRequest)

Creates a new GLJPanel component with the requested set of OpenGL capabilities, using the default OpenGL capabilities selection mechanism.

public
GLJPanel(final GLCapabilitiesImmutable userCapsRequest, final GLCapabilitiesChooser chooser)

Creates a new GLJPanel 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 javax.swing.JComponent.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.
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.
public void
destroy()

Implements com.jogamp.opengl.GLAutoDrawable.destroy.

Just an alias for removeNotify
public void
display()

Implements com.jogamp.opengl.GLAutoDrawable.display.

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

protected void
dispose(final Runnable post)

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 AWTGLPixelBuffer.AWTGLPixelBufferProvider
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 final 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.
private int
getGLInteger(final GL gl, final int which)

public final GLProfile
getGLProfile()

Implements com.jogamp.opengl.GLDrawable.getGLProfile.

Fetches the GLProfile for this drawable.
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 final 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.
private static synchronized AWTGLPixelBuffer.SingleAWTGLPixelBufferProvider
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.
public final int
getTextureUnit()

Returns the used texture unit, i.e. a value of [0..n], or -1 if non used.

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<>
private boolean
public final boolean
initializeBackend(final boolean offthread)

Attempts to initialize the backend, if not initialized yet.

private boolean
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 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.
private boolean
protected void
paintComponent(final Graphics
the Graphics object to protect
g
)

Overrides javax.swing.JComponent.paintComponent.

Overridden to cause OpenGL rendering to be performed during repaint cycles.
protected void
printComponent(final Graphics
the Graphics context in which to paint
g
)

Overrides javax.swing.JComponent.printComponent.

This is invoked during a printing operation.
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 javax.swing.JComponent.removeNotify.

Overridden to track when this component is removed from a container.
public void
reshape(final int
the new horizontal location
x
,
final int
the new vertical location
y
,
final int
the new width
width
,
final int
the new height
height
)

Overrides javax.swing.JComponent.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 enable)

Implements com.jogamp.opengl.GLAutoDrawable.setAutoSwapBufferMode.

Enables or disables automatic buffer swapping for this drawable.
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 void
setOpaque(final boolean
true if this component should be opaque
opaque
)

Overrides javax.swing.JComponent.setOpaque.

If true the component paints every pixel within its bounds.
public void
public 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.
public final void
setRequestedGLCapabilities(final GLCapabilitiesImmutable
new capabilities.
caps
)

Set a new requested GLCapabilitiesImmutable for this GLJPanel allowing reconfiguration.

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 void
setSkipGLOrientationVerticalFlip(final boolean v)

Skip isGLOriented() based vertical flip, which usually is required by the offscreen backend, see details about vertical flip and FBO / GLSL vertical flip.

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 final void
setTextureUnit(final int
requested texture unit
v
)

Allows user to request a texture unit to be used, must be called before the first initialization, i.e. display() call.

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 boolean
shouldPreserveColorBufferIfTranslucent()

For a translucent GLJPanel (one for which setOpaque(false) has been called), indicates whether the application should preserve the OpenGL color buffer (GL_COLOR_BUFFER_BIT) for correct rendering of the GLJPanel and underlying widgets which may show through portions of the GLJPanel with alpha values less than 1.

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.
private final boolean
private final void
Inherited from javax.swing.JPanel:
getAccessibleContextgetUIgetUIClassIDparamStringsetUIupdateUI