diff options
Diffstat (limited to 'gl4java/awt/GLCanvas.java')
-rw-r--r-- | gl4java/awt/GLCanvas.java | 180 |
1 files changed, 38 insertions, 142 deletions
diff --git a/gl4java/awt/GLCanvas.java b/gl4java/awt/GLCanvas.java index a7ade2a..041fabb 100644 --- a/gl4java/awt/GLCanvas.java +++ b/gl4java/awt/GLCanvas.java @@ -173,24 +173,6 @@ public class GLCanvas extends Canvas // The list of GLEventListeners private GLEventListenerList listeners = new GLEventListenerList(); - // Indicates whether init() has been called yet. - private volatile boolean initCalled = false; - - // Indicates whether the canvas will permit any calls to init() or - // display() from within the paint() method; defaults to true for - // backward compatibility. - private boolean enableAWTThreadRendering = true; - - // Indicates whether display() automatically makes the canvas's - // GLContext current and frees it each call; defaults to true for - // backward compatibility. On higher-end graphics cards it is - // important to minimize the number of "make current" calls even - // across frames; a GLAnimCanvas running in its own thread, and - // with AWT thread rendering disabled, will only make its - // associated context current once, at the beginning of its - // rendering loop. - private boolean autoMakeContextCurrent = true; - static { if(GLContext.doLoadNativeLibraries(null, null, null)==false) System.out.println("GLCanvas could not load def. native libs."); @@ -403,61 +385,6 @@ public class GLCanvas extends Canvas public final Window getTopLevelWindow() { return topLevelWindow; } - /** Enables/disables calls to init() and display() from within the - AWT thread. If this is enabled (the default, for backward - compatibility with earlier releases), the first call to - paint() from within the AWT thread (typically prompted by a - repaint()) will cause the canvas to be initialized, and - subsequent calls to paint() will cause display() to be called. - If AWT thread rendering is disabled, the AWT thread will not - cause init() or display() to be called if repaint() is called, - and the first call to display() will cause the canvas to be - initialized. This function is present both to work around bugs - in certain vendors' drivers which do not function properly in - multithreaded settings, and to allow improved performance of - GLAnimCanvas. */ - public void setAWTThreadRenderingEnabled(boolean val) { - enableAWTThreadRendering = val; - } - - /** Indicates whether AWT thread rendering is enabled; see {@link - #setAWTThreadRenderingEnabled}. */ - public boolean getAWTThreadRenderingEnabled() { - return enableAWTThreadRendering; - } - - /** Indicates whether the canvas automatically makes its - underlying GLContext current and frees it during each call to - display(); defaults to true for backward compatibility. On - higher-end graphics cards it is important to minimize the - number of "make current" calls even across frames; a - GLAnimCanvas running in its own thread and with AWT thread - rendering disabled will only make its associated context - current once, at the beginning of its rendering loop. */ - public void setAutoMakeContextCurrent(boolean val) { - autoMakeContextCurrent = val; - } - - /** Indicates whether the canvas automatically makes its - underlying GLContext current and frees it during each call to - display(); see {@link #setAutoMakeContextCurrent}. */ - public boolean getAutoMakeContextCurrent() { - return autoMakeContextCurrent; - } - - /** Convenience routine which Enables or disables optimized - context handling by calling {@link - #setAWTThreadRenderingEnabled} and {@link - #setAutoMakeContextCurrent} with the given boolean. */ - public void setOptimizeContextHandling(boolean yesOrNo) { - setAWTThreadRenderingEnabled(yesOrNo); - setAutoMakeContextCurrent(yesOrNo); - } - - public boolean getOptimizeContextHandling() { - return getAWTThreadRenderingEnabled() || getAutoMakeContextCurrent(); - } - /** * this function overrides the Canvas paint method ! * @@ -482,7 +409,7 @@ public class GLCanvas extends Canvas * @see gl4java.awt.GLCanvas#preInit * @see gl4java.awt.GLCanvas#init */ - public synchronized final void paint( Graphics g ) + public final void paint( Graphics g ) { if(glj == null || ( !glj.gljIsInit() && isGLEnabled() ) ) { @@ -521,10 +448,7 @@ public class GLCanvas extends Canvas (float)col.getGreen()/255.0f, (float)col.getBlue()/255.0f, 0.0f); - if (getAWTThreadRenderingEnabled()) { - init(); - initCalled = true; - } + init(); // fetch the top-level window , // to add us as the windowListener @@ -560,14 +484,9 @@ public class GLCanvas extends Canvas /* force a reshape, to be sure .. */ mustResize = true; - - // Free up the OpenGL context for another thread to use - glj.gljFree(); } - if (getAWTThreadRenderingEnabled()) { - sDisplay(); - } + sDisplay(); } /** @@ -711,15 +630,14 @@ public class GLCanvas extends Canvas protected long _f_dur = 0; /** + * Return the uses milli secounds of the last frame + */ + public long getLastFrameMillis() + { return _f_dur; } + + /** * * This is the thread save rendering-method called by paint. - * The actual thread will be set to highes priority befor calling - * 'display'. After 'display' the priority will be reset ! - * - * 'gljFree' will be NOT called after 'display'. - * - * We tested the above to use multi-threading and - * for the demonstration 'glDemos' it works ;-)) ! * * BE SURE, if you want to call 'display' by yourself * (e.g. in the run method for animation) @@ -730,11 +648,35 @@ public class GLCanvas extends Canvas * @see gl4java.awt.GLCanvas#paint * @see gl4java.awt.GLCanvas#display */ - public synchronized final void sDisplay() + public final void sDisplay() { + boolean ok = true; + + if(!cvsIsInit()) + { + return; + } + + if( mustResize ) + { + if( glj.gljMakeCurrent() == true ) + { + size = getSize(); + glj.gljResize( size.width, size.height ) ; + reshape(size.width, size.height); + mustResize = false; + invalidate(); + repaint(100); + glj.gljFree(true); /* force freeing the context here .. */ + } + } + long _s = System.currentTimeMillis(); - display(); + if(ok) + { + display(); + } _f_dur = System.currentTimeMillis()-_s; } @@ -747,7 +689,7 @@ public class GLCanvas extends Canvas * <p> * The default implementation of display() sends * preDisplay, display and postDisplay events to - * all {@link gl4java.GLEventListener}s associated with this + * all {@link gl4java.drawable.GLEventListener}s associated with this * GLCanvas in the above order. * * <p> @@ -761,8 +703,8 @@ public class GLCanvas extends Canvas { for_all(gl4java.GLEventListener) SEND display - gljFree() gljSwap() + gljFree() for_all(gl4java.GLEventListener) SEND postDisplay @@ -801,49 +743,9 @@ public class GLCanvas extends Canvas */ public void display() { - if(!cvsIsInit()) - { - return; - } - - if( mustResize ) - { - if (getAutoMakeContextCurrent()) { - if( glj.gljMakeCurrent() == true ) - { - size = getSize(); - glj.gljResize( size.width, size.height ) ; - reshape(size.width, size.height); - mustResize = false; - invalidate(); - repaint(100); - glj.gljFree(); - } - } else { - size = getSize(); - glj.gljResize( size.width, size.height ) ; - if (getAWTThreadRenderingEnabled()) { - reshape(size.width, size.height); - } - mustResize = false; - if (getAWTThreadRenderingEnabled()) { - invalidate(); - repaint(100); - } - } - } - - if (!getAWTThreadRenderingEnabled()) { - if (!initCalled) { - init(); - initCalled = true; - } - } - listeners.sendPreDisplayEvent(this); - if (getAutoMakeContextCurrent()) { - if (glj.gljMakeCurrent()) { + if (glj.gljMakeCurrent()) { listeners.sendDisplayEvent(this); glj.gljSwap(); @@ -851,12 +753,6 @@ public class GLCanvas extends Canvas glj.gljFree(); listeners.sendPostDisplayEvent(this); - } - } else { - listeners.sendDisplayEvent(this); - glj.gljSwap(); - glj.gljCheckGL(); - listeners.sendPostDisplayEvent(this); } } |