Class GLCanvasSwing

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, GLCanvas

public class GLCanvasSwing extends JPanel implements GLCanvas
This panel push to the screen an OpenGL image rendered offscreen by an OffscreenRenderer. The panel mainly deals with
  • OpenGL context initialization, after the panel is added to a parent, and before it is made visible.
  • repaint and resize events that are propagated to the OpenGL application through a GLEventListener, which must be provided by the user of this panel through setGLEventListener(GLEventListener).
  • measuring performance, that is evaluating the time required to trigger offscreen image rendering and image painting onscreen.

Threading

The panel is also responsible for triggering OpenGL initialization and rendering in the appropriate threads, which may depend on the running operating system.

Threading on macOS

Debugging

Hint : to debug this class, invoke a program using it with flag -Dpanamagl.GLPanel
Author:
Martin Pernollet
See Also:
  • Field Details

  • Constructor Details

    • GLCanvasSwing

      public GLCanvasSwing()
    • GLCanvasSwing

      public GLCanvasSwing(PanamaGLFactory factory)
      Initialize a panel able to render OpenGL through a GLEventListener and related GL interface.
  • Method Details

    • addNotify

      public void addNotify()
      Called after the JPanel has been added to the Swing hierarchy but before it is made visible. Initialization may occur in other threads and not be completed when this method returns. To ensure the component is initialized, call
      invalid @link
      invalid input: ''
      Overrides:
      addNotify in class JComponent
    • removeNotify

      public void removeNotify()
      Called before the JPanel is removed from the Swing hierarchy.
      Overrides:
      removeNotify in class JComponent
    • update

      public void update(Graphics g)
      Invoked each time redraw should be performed, even if the redraw query is coalesced with other redraw queries by the AWT Event Queue.
      Overrides:
      update in class JComponent
    • paint

      public void paint(Graphics g)
      Invoked only for redraw query that are not coalesced with other redraw queries by the AWT Event Queue.
      Overrides:
      paint in class JComponent
    • paintComponent

      public void paintComponent(Graphics g)
      Render GL image and stop counting elapsed time for rendering (started at display())
      Overrides:
      paintComponent in class JComponent
    • display

      public void display()
      If the panel initialization has achieved, this triggers an offscreen rendering, maybe on a separated thread (macOS case), from which an asynchronous repaint will be triggered.
      Specified by:
      display in interface GLCanvas
    • isInitialized

      public boolean isInitialized()
      Return true if the offscreen renderer has been initialized, which means that this panel has been added to a parent component.
      Specified by:
      isInitialized in interface GLCanvas
    • isRendering

      public boolean isRendering()
      Return true if display has started but has not yet finished
      Specified by:
      isRendering in interface GLCanvas
    • setRendering

      protected void setRendering(boolean status)
    • overlayPerformance

      protected void overlayPerformance(Graphics g)
      Show performance in a 2D text overlay.
    • getGLEventListener

      public GLEventListener getGLEventListener()
      Description copied from interface: GLCanvas
      Return the event listener handling init, drawing and resize requests.
      Specified by:
      getGLEventListener in interface GLCanvas
    • setGLEventListener

      public void setGLEventListener(GLEventListener glEvents)
      Description copied from interface: GLCanvas
      Set the event listener handling init, drawing and resize requests.
      Specified by:
      setGLEventListener in interface GLCanvas
    • getGL

      public GL getGL()
      Description copied from interface: GLCanvas
      Return the GL instance allowing to invoke OpenGL.
      Specified by:
      getGL in interface GLCanvas
    • getContext

      public GLContext getContext()
      Description copied from interface: GLCanvas
      Return the GL context.
      Specified by:
      getContext in interface GLCanvas
    • getScreenshot

      public Image<?> getScreenshot()
      Specified by:
      getScreenshot in interface GLCanvas
    • setScreenshot

      public void setScreenshot(Image<?> image)
      Specified by:
      setScreenshot in interface GLCanvas
    • getFBO

      public FBO getFBO()
    • setFBO

      public void setFBO(FBO fbo)
    • getMonitoring

      public RenderCounter getMonitoring()
      Description copied from interface: GLCanvas
      Return the performance information about this panel.
      Specified by:
      getMonitoring in interface GLCanvas
    • setMonitoring

      public void setMonitoring(RenderCounter counter)
    • getOffscreenRenderer

      public OffscreenRenderer getOffscreenRenderer()
      Specified by:
      getOffscreenRenderer in interface GLCanvas
    • setOffscreenRenderer

      public void setOffscreenRenderer(OffscreenRenderer offscreen)
      Specified by:
      setOffscreenRenderer in interface GLCanvas
    • getFlip

      public GLCanvas.Flip getFlip()
      Specified by:
      getFlip in interface GLCanvas
    • setFlip

      public void setFlip(GLCanvas.Flip flip)
      Specified by:
      setFlip in interface GLCanvas