Class GLJPanel

All Implemented Interfaces:
AWTPrintLifecycle, NativeSurfaceHolder, ScalableSurface, WindowClosingProtocol, AWTGLAutoDrawable, ComponentEvents, GLAutoDrawable, GLDrawable, GLSharedContextSetter, ImageObserver, MenuContainer, Serializable, Accessible

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

See Also: