Class EmulGLCanvas
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Canvas
-
- jgl.GLCanvas
-
- org.jzy3d.plot3d.rendering.canvas.EmulGLCanvas
-
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible,IMonitorable,ICanvas,IScreenCanvas
public class EmulGLCanvas extends GLCanvas implements IScreenCanvas, IMonitorable
This canvas allows rendering charts with jGL as OpenGL backend which perform in CPU. The below schema depicts how this canvas does painting :
- Author:
- Martin Pernollet
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.awt.Canvas
Canvas.AccessibleAWTCanvas
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
Fields Modifier and Type Field Description protected IAnimatoranimatorprotected List<ICanvasListener>canvasListenersprotected booleandebugEventsset to TRUE to show in console events of the component (to debug GLUT)protected AtomicBooleanisRenderingFlagprotected doublelastRenderingTimeMsprotected Monitormonitorprotected EmulGLPainterpainterprotected intprofileDisplayCountprotected FontprofileDisplayFontprotected booleanprofileDisplayMethodset to TRUE to overlay performance info on top left cornerprotected TicTocprofileDisplayTimerprotected List<org.jzy3d.plot3d.rendering.canvas.EmulGLCanvas.ProfileInfo>profileInfostatic booleanTO_BE_CHOOSEN_REPAINT_WITH_FLUSHSpecify actual way of forcing repaint if true : manual if false : trigger component.resize event to force resize + view.render + glFlush + swap imageprotected Viewview-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface org.jzy3d.plot3d.rendering.canvas.ICanvas
ALLOW_WATCH_PIXEL_SCALE, LAST_RENDER_TIME_UNDEFINED
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
Constructor Summary
Constructors Constructor Description EmulGLCanvas(IChartFactory factory, Scene scene, Quality quality)Initialize a canvas for rendering 3D
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Monitor monitor)voidaddCanvasListener(ICanvasListener listener)voidaddKeyController(Object o)A generic interface for mouse listener to remain Windowing toolkit independant.voidaddMouseController(Object o)A generic interface for mouse listener to remain Windowing toolkit independant.protected voidcheckAlphaChannelOfColorBuffer(EmulGLPainter painter)voiddisplay()voiddispose()Performs all required cleanup when destroying a Canvas.voiddoMotion(int x, int y)Handle mouse events emitted by GLUT.voiddoRender()Triggers an atomic rendering of a frame, measure rendering performance and update the status of rendering (active or not).voiddoReshape(int w, int h)Handle resize events emitted by GLUT.protected voidfirePixelScaleChanged(double pixelScaleX, double pixelScaleY)voidforceRepaint()Can be used to update image if camera has changed position.IAnimatorgetAnimation()List<ICanvasListener>getCanvasListeners()StringgetDebugInfo()StringgetFullname()AtomicBooleangetIsRenderingFlag()StringgetLabel()doublegetLastRenderingTimeMs()Coord2dgetPixelScale()Provide pixel scale as feasible by the Hardware, OS, and JVM, independently of what was asked byICanvas.setPixelScale(float[]).intgetRendererHeight()Returns the renderer's height, i.e. the display height.intgetRendererWidth()Returns the renderer's width, i.e. the display width.ViewgetView()Returns a reference to the held view.protected voidinit(int width, int height)Equivalent to registering a Renderer3d in native canvas.protected voidinitGLUT(int width, int height)Configure GLUT callback which yield to the below flow diagram
protected voidinitView()booleanisDebugEvents()booleanisProfileDisplayMethod()protected voidmonitorRenderingTime(Monitor monitor, double mili)voidpaint(Graphics g)This overrides theGLCanvashenceCanvasmethods to copy the image of the 3D scene as generated whileGL.glFlush().protected voidpaintProfileInfo(BufferedImage glImage)Render profile on top of an image (probably the image of the GL scene) previously collected while {@link EmulGLCanvas#doRender(). Painting profile info is synchronized on the profile info list to ensure it is not modified while drawing (which occurs if synchronization is disabled).voidprintCallTrace()voidprintCallTrace(int from, String filterLine)Print stack but drops any class.method name not containing the filter (in case it is not null)protected voidprintCountGLBegin()voidprocessEvent(AWTEvent e)This override letGLUT.processEvent(AWTEvent)be informed ofAWTEventtraversing this canvas (mouse, keyboard, resize).protected voidprofile(double mili)protected voidprofile(String message, int x, int y, Color c)Draw a 2d text at the given positionprotected voidprofileClear()voidremoveCanvasListener(ICanvasListener listener)voidremoveKeyController(Object o)A generic interface for key listener to remain Windowing toolkit independant. * Implementation of this method should simply cast the input assuming it will correspond to canvas-compatible key listener.voidremoveMouseController(Object o)A generic interface for key listener to remain Windowing toolkit independant.protected voidresetCountGLBegin()BufferedImagescreenshot()voidscreenshot(File file)voidsetDebugEvents(boolean debugEvents)voidsetPixelScale(float[] scale)Defines pixel scale.voidsetProfileDisplayMethod(boolean profileDisplayMethod)protected booleanshouldPrintEvent(AWTEvent e)protected voidupdatePainterWithGL()RegisterEmulGLPainter.-
Methods inherited from class jgl.GLCanvas
getGL, getGLU, getGLUT, getPixelScaleFromG2D, glut_enable_events, update
-
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
-
-
-
-
Field Detail
-
TO_BE_CHOOSEN_REPAINT_WITH_FLUSH
public static final boolean TO_BE_CHOOSEN_REPAINT_WITH_FLUSH
Specify actual way of forcing repaint- if true : manual
- if false : trigger component.resize event to force resize + view.render + glFlush + swap image
- See Also:
- Constant Field Values
-
view
protected View view
-
painter
protected EmulGLPainter painter
-
animator
protected IAnimator animator
-
canvasListeners
protected List<ICanvasListener> canvasListeners
-
isRenderingFlag
protected AtomicBoolean isRenderingFlag
-
debugEvents
protected boolean debugEvents
set to TRUE to show in console events of the component (to debug GLUT)
-
profileDisplayMethod
protected boolean profileDisplayMethod
set to TRUE to overlay performance info on top left corner
-
profileDisplayTimer
protected TicToc profileDisplayTimer
-
profileDisplayFont
protected Font profileDisplayFont
-
profileDisplayCount
protected int profileDisplayCount
-
profileInfo
protected List<org.jzy3d.plot3d.rendering.canvas.EmulGLCanvas.ProfileInfo> profileInfo
-
monitor
protected Monitor monitor
-
lastRenderingTimeMs
protected double lastRenderingTimeMs
-
-
Constructor Detail
-
EmulGLCanvas
public EmulGLCanvas(IChartFactory factory, Scene scene, Quality quality)
Initialize a canvas for rendering 3D
-
-
Method Detail
-
processEvent
public void processEvent(AWTEvent e)
Description copied from class:GLCanvasThis override letGLUT.processEvent(AWTEvent)be informed ofAWTEventtraversing this canvas (mouse, keyboard, resize). One should registerGLUT.glutDisplayFunc(String)to register a display callback,GLUT.glutMotionFunc(String)to register a mouse motion callback, etc. NB : This relies on the fact the GLUT already invoked {@link this#glut_enable_events}.- Overrides:
processEventin classGLCanvas
-
shouldPrintEvent
protected boolean shouldPrintEvent(AWTEvent e)
-
init
protected void init(int width, int height)Equivalent to registering a Renderer3d in native canvas.
-
initView
protected void initView()
-
initGLUT
protected void initGLUT(int width, int height)Configure GLUT callback which yield to the below flow diagram
-
paint
public void paint(Graphics g)
This overrides theGLCanvashenceCanvasmethods to copy the image of the 3D scene as generated whileGL.glFlush(). It is called when the application needs to paint the canvas, which assume a rendering has already been process bydoRender()which produce an image that the canvas can use for fast pixel swap.doRender()on its side is triggered whenGLUTthinks it is relevant. This may occur becauseEmulGLCanvastriggered aComponentEvent.COMPONENT_RESIZEDevent.
-
display
public void display()
- Specified by:
displayin interfaceIScreenCanvas
-
forceRepaint
public void forceRepaint()
Can be used to update image if camera has changed position. (usually called byView.shoot()) Warning if this is invoked by a thread external to AWT, this may redraw GL while GL is already used by AWT, which would turn GL into an inconsistent state.- Specified by:
forceRepaintin interfaceICanvas- Overrides:
forceRepaintin classGLCanvas
-
doRender
public void doRender()
Triggers an atomic rendering of a frame, measure rendering performance and update the status of rendering (active or not). This method is callback registered in withGLUT.glutDisplayFunc(String)which will be called when OpenGL need to update display. OpenGL updates as soon as the component that GLUT listen to (which is thisEmulGLCanvastriggers aComponentEvent.COMPONENT_RESIZEDevent. Performance measurement can be seen on screen ifsetProfileDisplayMethod(boolean)was set to true OR can be collected by aMonitordefined byadd(Monitor). This method is synchronized to prevent multiple concurrent calls to doDisplay which might make jGL get crazy with GL state consistency : GL states must be consistent during a complete rendering pass, and should not be modified by a second rendering pass in the middle of the first one. Consistency may be on drawing a complete geometry in appropriate order (glBegin, glVertex, glEnd) or in the way OpenGL 1.0 fixed pipeline is cleanly handled. In addition, the display method has aisRenderingFlagso that external components may known that the canvas is currently rendering or not. This allows ignoring a rendering query in case the canvas is not ready for working. This is different from making use ofsynchronized(which lead to a queue of calls to be resolved) in that one may simply not append work to do according to the status of the canvas.
-
printCallTrace
public void printCallTrace()
-
printCallTrace
public void printCallTrace(int from, String filterLine)Print stack but drops any class.method name not containing the filter (in case it is not null)
-
getLastRenderingTimeMs
public double getLastRenderingTimeMs()
- Specified by:
getLastRenderingTimeMsin interfaceICanvas
-
getIsRenderingFlag
public AtomicBoolean getIsRenderingFlag()
-
doReshape
public void doReshape(int w, int h)Handle resize events emitted by GLUT.GLUT.processComponentEvent(ComponentEvent)is calling reshape handler (this method) THEN the display handler ({@link #doDisplay()), so this method will only inform {@link GLUT} andViewthat window size changed.
-
doMotion
public void doMotion(int x, int y)Handle mouse events emitted by GLUT. Most probably not registered as mouse already handled by Jzy3D.
-
screenshot
public BufferedImage screenshot()
- Specified by:
screenshotin interfaceICanvas
-
screenshot
public void screenshot(File file) throws IOException
- Specified by:
screenshotin interfaceICanvas- Throws:
IOException
-
updatePainterWithGL
protected void updatePainterWithGL()
RegisterEmulGLPainter.
-
getView
public View getView()
Description copied from interface:ICanvasReturns a reference to the held view.
-
getRendererWidth
public int getRendererWidth()
Description copied from interface:ICanvasReturns the renderer's width, i.e. the display width.- Specified by:
getRendererWidthin interfaceICanvas
-
getRendererHeight
public int getRendererHeight()
Description copied from interface:ICanvasReturns the renderer's height, i.e. the display height.- Specified by:
getRendererHeightin interfaceICanvas
-
dispose
public void dispose()
Description copied from interface:ICanvasPerforms all required cleanup when destroying a Canvas.
-
setPixelScale
public void setPixelScale(float[] scale)
Description copied from interface:ICanvasDefines pixel scale. On MacOS Retina displays, a X*Y chart uses a (X*2)*(Y*2) viewport. This makes some calculation based on viewport (such asCamera.screenToModel(IPainter, org.jzy3d.maths.Coord3d)output wrong result. When running on Retina display, those two options fixed buggy mouse selections on Retina:- setPixelScale(new float[]{0.5f,0.5f})
- setPixelScale(new float[] { ScalableSurface.IDENTITY_PIXELSCALE,
ScalableSurface.IDENTITY_PIXELSCALE })
- Specified by:
setPixelScalein interfaceICanvas
-
getPixelScale
public Coord2d getPixelScale()
Description copied from interface:ICanvasProvide pixel scale as feasible by the Hardware, OS, and JVM, independently of what was asked byICanvas.setPixelScale(float[]). Hence the two functions may not be consistent together.- Specified by:
getPixelScalein interfaceICanvas
-
getAnimation
public IAnimator getAnimation()
- Specified by:
getAnimationin interfaceIScreenCanvas
-
addMouseController
public void addMouseController(Object o)
Description copied from interface:ICanvasA generic interface for mouse listener to remain Windowing toolkit independant. Implementation of this method should simply cast the input assuming it will correspond to canvas-compatible mouse listener.- Specified by:
addMouseControllerin interfaceICanvas
-
removeMouseController
public void removeMouseController(Object o)
Description copied from interface:ICanvasA generic interface for key listener to remain Windowing toolkit independant. Implementation of this method should simply cast the input assuming it will correspond to canvas-compatible key listener.- Specified by:
removeMouseControllerin interfaceICanvas
-
addKeyController
public void addKeyController(Object o)
Description copied from interface:ICanvasA generic interface for mouse listener to remain Windowing toolkit independant. Implementation of this method should simply cast the input assuming it will correspond to canvas-compatible mouse listener.- Specified by:
addKeyControllerin interfaceICanvas
-
removeKeyController
public void removeKeyController(Object o)
Description copied from interface:ICanvasA generic interface for key listener to remain Windowing toolkit independant. * Implementation of this method should simply cast the input assuming it will correspond to canvas-compatible key listener.- Specified by:
removeKeyControllerin interfaceICanvas
-
addCanvasListener
public void addCanvasListener(ICanvasListener listener)
- Specified by:
addCanvasListenerin interfaceICanvas
-
removeCanvasListener
public void removeCanvasListener(ICanvasListener listener)
- Specified by:
removeCanvasListenerin interfaceICanvas
-
getCanvasListeners
public List<ICanvasListener> getCanvasListeners()
- Specified by:
getCanvasListenersin interfaceICanvas
-
firePixelScaleChanged
protected void firePixelScaleChanged(double pixelScaleX, double pixelScaleY)
-
getDebugInfo
public String getDebugInfo()
- Specified by:
getDebugInfoin interfaceICanvas
-
paintProfileInfo
protected void paintProfileInfo(BufferedImage glImage)
Render profile on top of an image (probably the image of the GL scene) previously collected while {@link EmulGLCanvas#doRender(). Painting profile info is synchronized on the profile info list to ensure it is not modified while drawing (which occurs if synchronization is disabled). Despite we did not observed any lag due to such rendering, it is important to keep in mind that displaying profile information requires a synchronized access to this info list which is on the other side synchronized to protect exporting rendering info of the last call todoRender().
-
profile
protected void profile(double mili)
-
profile
protected void profile(String message, int x, int y, Color c)
Draw a 2d text at the given position
-
profileClear
protected void profileClear()
-
isDebugEvents
public boolean isDebugEvents()
-
setDebugEvents
public void setDebugEvents(boolean debugEvents)
-
isProfileDisplayMethod
public boolean isProfileDisplayMethod()
-
setProfileDisplayMethod
public void setProfileDisplayMethod(boolean profileDisplayMethod)
-
checkAlphaChannelOfColorBuffer
protected void checkAlphaChannelOfColorBuffer(EmulGLPainter painter)
-
printCountGLBegin
protected void printCountGLBegin()
-
resetCountGLBegin
protected void resetCountGLBegin()
-
getFullname
public String getFullname()
- Specified by:
getFullnamein interfaceIMonitorable
-
getLabel
public String getLabel()
- Specified by:
getLabelin interfaceIMonitorable
-
add
public void add(Monitor monitor)
- Specified by:
addin interfaceIMonitorable
-
monitorRenderingTime
protected void monitorRenderingTime(Monitor monitor, double mili)
-
-