Package panamagl.canvas
Class GLCanvasSwing
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
panamagl.canvas.GLCanvasSwing
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible,panamagl.canvas.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 throughsetGLEventListener(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.canvas.GLCanvasSwing- Author:
- Martin Pernollet
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classTheGLCanvasSwing.ResizeHandlerwill trigger rendering on the main macOS thread and then trigger repaint by the thread selected byattached to theinvalid reference
ThreadRedirectOffscreenRenderer.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategyNested classes/interfaces inherited from interface panamagl.canvas.GLCanvas
panamagl.canvas.GLCanvas.Flip -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected panamagl.performance.RenderCounterprotected booleanprotected booleanprotected panamagl.canvas.GLCanvas.Flipprotected panamagl.GLEventListenerprotected panamagl.offscreen.OffscreenRendererprotected BufferedImageprotected panamagl.canvas.overlay.PerformanceOverlay_AWTprotected AtomicBooleanFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionGLCanvasSwing(panamagl.factory.PanamaGLFactory factory) Initialize a panel able to render OpenGL through aGLEventListenerand relatedGLinterface. -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled after the JPanel has been added to the Swing hierarchy but before it is made visible.voiddisplay()If the panel initialization has achieved, triggers an offscreen rendering from the AWT thread, hence happening asynchronously.panamagl.opengl.GLContextpanamagl.offscreen.FBOgetFBO()panamagl.canvas.GLCanvas.FlipgetFlip()panamagl.opengl.GLgetGL()panamagl.GLEventListenerpanamagl.performance.RenderCounterpanamagl.offscreen.OffscreenRendererpanamagl.Image<?> booleanReturn true if the offscreen renderer has been initialized, which means that this panel has been added to a parent component.booleanReturn true if display has started but has not yet finishedprotected voidShow performance in a 2D text overlay.voidInvoked only for redraw query that are not coalesced with other redraw queries by the AWT Event Queue.voidRender GL image and stop counting elapsed time for rendering (started atdisplay())voidCalled before the JPanel is removed from the Swing hierarchy.voidsetFBO(panamagl.offscreen.FBO fbo) voidsetFlip(panamagl.canvas.GLCanvas.Flip flip) voidsetGLEventListener(panamagl.GLEventListener glEvents) voidsetMonitoring(panamagl.performance.RenderCounter counter) voidsetOffscreenRenderer(panamagl.offscreen.OffscreenRenderer offscreen) protected voidsetRendering(boolean status) voidsetScreenshot(panamagl.Image<?> image) Update the image to be displayed.voidInvoked each time redraw should be performed, even if the redraw query is coalesced with other redraw queries by the AWT Event Queue.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardActionMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface panamagl.canvas.GLCanvas
getHeight, getWidth, isVisible, repaint
-
Field Details
-
listener
protected panamagl.GLEventListener listener -
offscreen
protected panamagl.offscreen.OffscreenRenderer offscreen -
out
-
rendering
-
counter
protected panamagl.performance.RenderCounter counter -
overlay
protected panamagl.canvas.overlay.PerformanceOverlay_AWT overlay -
debug
protected boolean debug -
debugPerf
protected boolean debugPerf -
flip
protected panamagl.canvas.GLCanvas.Flip flip
-
-
Constructor Details
-
GLCanvasSwing
public GLCanvasSwing() -
GLCanvasSwing
public GLCanvasSwing(panamagl.factory.PanamaGLFactory factory) Initialize a panel able to render OpenGL through aGLEventListenerand relatedGLinterface.
-
-
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, callisInitialized().- Overrides:
addNotifyin classJComponent
-
removeNotify
public void removeNotify()Called before the JPanel is removed from the Swing hierarchy.- Overrides:
removeNotifyin classJComponent
-
update
Invoked each time redraw should be performed, even if the redraw query is coalesced with other redraw queries by the AWT Event Queue.- Overrides:
updatein classJComponent
-
paint
Invoked only for redraw query that are not coalesced with other redraw queries by the AWT Event Queue.- Overrides:
paintin classJComponent
-
paintComponent
Render GL image and stop counting elapsed time for rendering (started atdisplay())- Overrides:
paintComponentin classJComponent
-
display
public void display()If the panel initialization has achieved, triggers an offscreen rendering from the AWT thread, hence happening asynchronously.- Specified by:
displayin interfacepanamagl.canvas.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:
isInitializedin interfacepanamagl.canvas.GLCanvas
-
isRendering
public boolean isRendering()Return true if display has started but has not yet finished- Specified by:
isRenderingin interfacepanamagl.canvas.GLCanvas
-
setRendering
protected void setRendering(boolean status) -
overlayPerformance
Show performance in a 2D text overlay. -
getGLEventListener
public panamagl.GLEventListener getGLEventListener()- Specified by:
getGLEventListenerin interfacepanamagl.canvas.GLCanvas
-
setGLEventListener
public void setGLEventListener(panamagl.GLEventListener glEvents) - Specified by:
setGLEventListenerin interfacepanamagl.canvas.GLCanvas
-
getGL
public panamagl.opengl.GL getGL()- Specified by:
getGLin interfacepanamagl.canvas.GLCanvas
-
getContext
public panamagl.opengl.GLContext getContext()- Specified by:
getContextin interfacepanamagl.canvas.GLCanvas
-
getScreenshot
public panamagl.Image<?> getScreenshot()- Specified by:
getScreenshotin interfacepanamagl.canvas.GLCanvas
-
setScreenshot
public void setScreenshot(panamagl.Image<?> image) Update the image to be displayed. Should not be used by anything else than offscreen rendering. TODO : make method name clearer and visibility hidden?- Specified by:
setScreenshotin interfacepanamagl.canvas.GLCanvas
-
getMonitoring
public panamagl.performance.RenderCounter getMonitoring()- Specified by:
getMonitoringin interfacepanamagl.canvas.GLCanvas
-
setMonitoring
public void setMonitoring(panamagl.performance.RenderCounter counter) -
getOffscreenRenderer
public panamagl.offscreen.OffscreenRenderer getOffscreenRenderer()- Specified by:
getOffscreenRendererin interfacepanamagl.canvas.GLCanvas
-
setOffscreenRenderer
public void setOffscreenRenderer(panamagl.offscreen.OffscreenRenderer offscreen) - Specified by:
setOffscreenRendererin interfacepanamagl.canvas.GLCanvas
-
getFlip
public panamagl.canvas.GLCanvas.Flip getFlip()- Specified by:
getFlipin interfacepanamagl.canvas.GLCanvas
-
setFlip
public void setFlip(panamagl.canvas.GLCanvas.Flip flip) - Specified by:
setFlipin interfacepanamagl.canvas.GLCanvas
-
getFBO
public panamagl.offscreen.FBO getFBO() -
setFBO
public void setFBO(panamagl.offscreen.FBO fbo)
-