aboutsummaryrefslogtreecommitdiffstats
path: root/gl4java/awt/GLAnimCanvas.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2001-07-24 12:07:18 +0000
committerSven Gothel <[email protected]>2001-07-24 12:07:18 +0000
commit3583101e586a6fe3306f84d4d34ee764596e0632 (patch)
treed5c228654f882fa0f0c6214e6d4866ce44181b89 /gl4java/awt/GLAnimCanvas.java
parentc9eae90cb823d918ecc4bf5afa73ce3a0859d578 (diff)
optimized context switchingrel-2-8-0-0-prerelease-3
Diffstat (limited to 'gl4java/awt/GLAnimCanvas.java')
-rw-r--r--gl4java/awt/GLAnimCanvas.java149
1 files changed, 77 insertions, 72 deletions
diff --git a/gl4java/awt/GLAnimCanvas.java b/gl4java/awt/GLAnimCanvas.java
index b16206c..9268db8 100644
--- a/gl4java/awt/GLAnimCanvas.java
+++ b/gl4java/awt/GLAnimCanvas.java
@@ -131,7 +131,7 @@ import java.lang.Math;
*
*/
public class GLAnimCanvas extends GLCanvas
- implements Runnable
+ implements GLRunnable
{
/**
* To support frames per scounds,
@@ -173,7 +173,7 @@ public class GLAnimCanvas extends GLCanvas
protected boolean threadSuspended = false;
static {
- if(GLContext.loadNativeLibraries(null, null, null)==false)
+ if(GLContext.doLoadNativeLibraries(null, null, null)==false)
System.out.println("GLAnimCanvas could not load def. native libs.");
}
@@ -286,14 +286,12 @@ public class GLAnimCanvas extends GLCanvas
{
}
- protected boolean useRepaint = true;
+ protected boolean useRepaint = false;
protected boolean useFpsSleep = true;
protected boolean useYield = true;
- protected boolean useSDisplay = true;
-
/**
* The normal behavior is to use 'repaint'
* within the AWT-Event Thread to render.
@@ -310,7 +308,7 @@ public class GLAnimCanvas extends GLCanvas
* @see gl4java.awt.GLCanvas#sDisplay
* @see gl4java.awt.GLAnimCanvas#setUseFpsSleep
*/
- public void setUseRepaint(boolean b)
+ public synchronized void setUseRepaint(boolean b)
{
useRepaint = b;
}
@@ -327,7 +325,7 @@ public class GLAnimCanvas extends GLCanvas
* @see gl4java.awt.GLCanvas#sDisplay
* @see gl4java.awt.GLAnimCanvas#setUseRepaint
*/
- public void setUseFpsSleep(boolean b)
+ public synchronized void setUseFpsSleep(boolean b)
{
useFpsSleep = b;
}
@@ -338,13 +336,6 @@ public class GLAnimCanvas extends GLCanvas
useYield = b;
}
- /** The default behavior, if not using repaints, is to call
- sDisplay() in the thread's main loop; set this to false to
- call display() directly. */
- public void setUseSDisplay(boolean val) {
- useSDisplay = val;
- }
-
public boolean getUseRepaint()
{
return useRepaint;
@@ -360,15 +351,19 @@ public class GLAnimCanvas extends GLCanvas
return useYield;
}
- public boolean getUseSDisplay()
- {
- return useSDisplay;
- }
+ /**
+ * Identifies this object with the given thread ..
+ * If this object owns this thread, it must return true !
+ */
+ public boolean ownsThread(Thread thread)
+ {
+ return killme!=null && killme==thread ;
+ }
- /**
- * HERE WE DO HAVE OUR RUNNING THREAD !
- * WE NEED STUFF LIKE THAT FOR ANIMATION ;-)
- */
+ /**
+ * HERE WE DO HAVE OUR RUNNING THREAD !
+ * WE NEED STUFF LIKE THAT FOR ANIMATION ;-)
+ */
public void start()
{
if(killme == null)
@@ -409,6 +404,7 @@ public class GLAnimCanvas extends GLCanvas
protected boolean shallWeRender = true;
protected boolean isRunning = false;
+ protected boolean forceGLFree = false;
private long _fDelay = 0;
private long _fDelay_Frames = 10;
@@ -416,6 +412,20 @@ public class GLAnimCanvas extends GLCanvas
private boolean _fDelayRun=false;
/**
+ * Forcec this thread to release it's GLContext !
+ *
+ * To ensure this, this thread enables itself,
+ * and calls gljFree(true) to force the release !
+ *
+ * @see gl4java.awt.GLAnimCanvas#run
+ * @see gl4java.GLContext#gljMakeCurrent
+ */
+ public void freeGLContext()
+ {
+ forceGLFree=true;
+ }
+
+ /**
* The running loop for animations
* which initiates the call of display
*
@@ -428,10 +438,7 @@ public class GLAnimCanvas extends GLCanvas
isRunning = true;
- boolean firstRender = true;
-
int numInitRetries = 1;
- int numMakeCurrentRetries = 1;
synchronized (this) {
globalThreadNumber++;
@@ -441,56 +448,54 @@ public class GLAnimCanvas extends GLCanvas
{
if(cvsIsInit())
{
- if (firstRender) {
- if (!getAutoMakeContextCurrent()) {
- synchronized (this) {
- if (!glj.gljMakeCurrent()) {
- System.err.println("Error making context current (" +
- numMakeCurrentRetries + ")...");
- ++numMakeCurrentRetries;
- try {
- Thread.currentThread().sleep(100);
- } catch (Exception e) {
- }
- continue;
- }
- }
- System.err.println("Context made current in AnimCanvas's thread");
- }
- firstRender = false;
- }
-
- /* DRAW THE TINGS .. */
- if (shallWeRender)
- {
- if(useRepaint)
- repaint();
- else {
- if (useSDisplay) {
- sDisplay();
- } else {
- display();
- }
- }
- } else {
- synchronized (this) {
- threadSuspended=true;
- }
- }
-
- if(fps_isCounting)
- fps_frames++;
+ // if another thread want's to do use do ..
+ if(forceGLFree)
+ {
+ glj.gljFree(true);
+ forceGLFree=false;
+ if(GLContext.gljThreadDebug)
+ System.out.println("GLAnimCanvas: forceGLFree(1) - gljFree");
+ }
+ else if (shallWeRender)
+ {
+ /* DRAW THE TINGS .. */
+ if(useRepaint)
+ repaint();
+ else
+ sDisplay();
+
+ if(fps_isCounting)
+ fps_frames++;
+
+ } else {
+ synchronized (this) {
+ glj.gljFree(true);
+ threadSuspended=true;
+ }
+ }
} else {
- System.err.println("Waiting for canvas to initialize (" +
- numInitRetries + ")...");
- ++numInitRetries;
+ if(GLContext.gljThreadDebug)
+ {
+ System.err.println("Waiting for canvas to initialize (" +
+ numInitRetries + ")...");
+ }
+ ++numInitRetries;
try {
Thread.currentThread().sleep(100);
} catch (Exception e) {
}
}
+ // if another thread want's to do use do ..
+ if(forceGLFree)
+ {
+ glj.gljFree(true);
+ forceGLFree=false;
+ if(GLContext.gljThreadDebug)
+ System.out.println("GLAnimCanvas: forceGLFree(2) - gljFree");
+ }
+
try {
if(useFpsSleep)
{
@@ -516,6 +521,7 @@ public class GLAnimCanvas extends GLCanvas
}
if (threadSuspended) {
+ glj.gljFree(true);
stopFpsCounter();
synchronized (this) {
while (threadSuspended)
@@ -526,10 +532,8 @@ public class GLAnimCanvas extends GLCanvas
{}
}
- if (getAutoMakeContextCurrent()) {
- if(glj!=null)
- glj.gljFree(); // just to be sure ..
- }
+ if(glj!=null)
+ glj.gljFree(true); // just to be sure .. force freeing the context
synchronized (this) {
globalThreadNumber--;
@@ -550,7 +554,7 @@ public class GLAnimCanvas extends GLCanvas
* @see gl4java.awt.GLAnimCanvas#isAlive
* @see gl4java.awt.GLAnimCanvas#start
*/
- public void setSuspended(boolean suspend)
+ public synchronized void setSuspended(boolean suspend)
{
setSuspended(suspend, false);
}
@@ -567,6 +571,7 @@ public class GLAnimCanvas extends GLCanvas
* @param reInit if true the ReInit will be called additionally,
* where the user can set additional initialisations
*
+ * @see gl4java.awt.GLAnimCanvas#ReInit
* @see gl4java.awt.GLAnimCanvas#isAlive
* @see gl4java.awt.GLAnimCanvas#start
* @see gl4java.awt.GLAnimCanvas#run