summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java7
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java41
-rwxr-xr-xsrc/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java2
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java1
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java18
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java23
-rwxr-xr-xsrc/jogl/classes/com/jogamp/opengl/util/Animator.java14
-rw-r--r--src/jogl/classes/javax/media/opengl/GLContext.java7
-rw-r--r--src/jogl/classes/javax/media/opengl/GLDrawableFactory.java7
9 files changed, 51 insertions, 69 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java
index 7143344bf..7d0c3a0c2 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java
@@ -256,11 +256,8 @@ public abstract class GLContextImpl extends GLContext {
* @see #destroyContextARBImpl
*/
public int makeCurrent() throws GLException {
- // Support calls to makeCurrent() over and over again with
- // different contexts without releasing them
- // Could implement this more efficiently without explicit
- // releasing of the underlying context; would require more error
- // checking during the makeCurrentImpl phase
+ // One context can only be current by one thread,
+ // and one thread can only have one context current!
GLContext current = getCurrent();
if (current != null) {
if (current == this) {
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java
index cdf5beb24..8f0299c1c 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java
@@ -54,24 +54,10 @@ import java.lang.reflect.*;
public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
protected static final boolean DEBUG = Debug.debug("GLDrawableFactory");
- private boolean isValid = false;
-
- public void shutdown() {
- validate();
- isValid = false;
- }
-
- protected final void validate() {
- if(!isValid) {
- throw new GLException("GLDrawableFactory is already shutdown!");
- }
- }
-
//---------------------------------------------------------------------------
// Dispatching GLDrawable construction in respect to the NativeWindow Capabilities
//
public GLDrawable createGLDrawable(NativeWindow target) {
- validate();
if (target == null) {
throw new IllegalArgumentException("Null target");
}
@@ -132,7 +118,6 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
GLCapabilitiesChooser chooser,
int width,
int height) {
- validate();
if(height<=0 || height<=0) {
throw new GLException("Width and height of pbuffer must be positive (were (" +
width + ", " + height + "))");
@@ -148,7 +133,6 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
int width,
int height,
GLContext shareWith) {
- validate();
return new GLPbufferImpl( (GLDrawableImpl) createGLPbufferDrawable(capabilities, chooser, height, height),
shareWith);
}
@@ -165,7 +149,6 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
GLCapabilitiesChooser chooser,
int width,
int height) {
- validate();
if(width<=0 || height<=0) {
throw new GLException("Width and height of pbuffer must be positive (were (" +
width + ", " + height + "))");
@@ -185,10 +168,30 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
protected abstract GLDrawableImpl getSharedDrawable();
protected abstract GLContextImpl getSharedContext();
+ protected abstract void shutdown();
+
+ // Shutdown hook mechanism for the factory
+ private boolean factoryShutdownHookRegistered;
+ private Thread factoryShutdownHook;
+ private synchronized void registerFactoryShutdownHook() {
+ if (factoryShutdownHookRegistered)
+ return;
+ if (factoryShutdownHook == null) {
+ factoryShutdownHook = new Thread(new Runnable() {
+ public void run() {
+ synchronized (GLDrawableFactoryImpl.this) {
+ shutdown();
+ }
+ }
+ });
+ }
+ Runtime.getRuntime().addShutdownHook(factoryShutdownHook);
+ factoryShutdownHookRegistered = true;
+ }
protected GLDrawableFactoryImpl() {
super();
- isValid = true;
+ registerFactoryShutdownHook();
}
protected void maybeDoSingleThreadedWorkaround(Runnable action) {
@@ -294,7 +297,6 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
* out-of-bounds
*/
public boolean setDisplayGamma(float gamma, float brightness, float contrast) throws IllegalArgumentException {
- validate();
if ((brightness < -1.0f) || (brightness > 1.0f)) {
throw new IllegalArgumentException("Brightness must be between -1.0 and 1.0");
}
@@ -327,7 +329,6 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
}
public synchronized void resetDisplayGamma() {
- validate();
if (gammaShutdownHook == null) {
throw new IllegalArgumentException("Should not call this unless setDisplayGamma called first");
}
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java
index 4fccf22f8..fb0da9c40 100755
--- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java
@@ -61,7 +61,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl {
super();
}
-
+ protected void shutdown() {}
protected final GLDrawableImpl getSharedDrawable() { return null; }
protected final GLContextImpl getSharedContext() { return null; }
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java
index d10434252..61d24a106 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java
@@ -62,6 +62,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl implements D
} catch (JogampRuntimeException jre) { /* n/a .. */ }
}
+ protected void shutdown() {}
protected final GLDrawableImpl getSharedDrawable() { return null; }
protected final GLContextImpl getSharedContext() { return null; }
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java
index a4bf89b81..ee4592adf 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java
@@ -92,17 +92,14 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
boolean canCreateGLPbuffer = false;
protected final GLDrawableImpl getSharedDrawable() {
- validate();
return sharedDrawable;
}
protected final GLContextImpl getSharedContext() {
- validate();
return sharedContext;
}
- public void shutdown() {
- super.shutdown();
+ protected void shutdown() {
if (DEBUG) {
System.err.println("!!! Shutdown Shared:");
System.err.println("!!! CTX : "+sharedContext);
@@ -119,7 +116,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
}
public GLDrawableImpl createOnscreenDrawable(NativeWindow target) {
- validate();
if (target == null) {
throw new IllegalArgumentException("Null target");
}
@@ -127,7 +123,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
}
protected GLDrawableImpl createOffscreenDrawable(NativeWindow target) {
- validate();
if (target == null) {
throw new IllegalArgumentException("Null target");
}
@@ -135,12 +130,10 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
}
public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) {
- validate();
return canCreateGLPbuffer;
}
protected GLDrawableImpl createGLPbufferDrawableImpl(final NativeWindow target) {
- validate();
if (target == null) {
throw new IllegalArgumentException("Null target");
}
@@ -174,7 +167,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
}
protected NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) {
- validate();
AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault();
NullWindow nw = new NullWindow(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(
capabilities, chooser, screen) );
@@ -183,22 +175,18 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
}
public GLContext createExternalGLContext() {
- validate();
return WindowsExternalWGLContext.create(this, null);
}
public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) {
- validate();
return true;
}
public GLDrawable createExternalGLDrawable() {
- validate();
return WindowsExternalWGLDrawable.create(this, null);
}
public void loadOpenGL32Library() {
- validate();
if (hopengl32 == 0) {
hopengl32 = WGL.LoadLibraryA("OpenGL32");
if (DEBUG) {
@@ -210,7 +198,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
}
public void loadGLULibrary() {
- validate();
if (hglu32 == 0) {
hglu32 = WGL.LoadLibraryA("GLU32");
if (hglu32 == 0) {
@@ -220,7 +207,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
}
public long dynamicLookupFunction(String glFuncName) {
- validate();
long res = WGL.wglGetProcAddress(glFuncName);
if (res == 0) {
// It may happen that a driver doesn't return the OpenGL32 core function pointer
@@ -253,13 +239,11 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
}
public boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) {
- validate();
return false;
}
public GLContext createContextOnJava2DSurface(Object graphics, GLContext shareWith)
throws GLException {
- validate();
throw new GLException("Unimplemented on this platform");
}
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java
index d8e5f7646..9a0edcfbb 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java
@@ -104,17 +104,14 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna
private X11GLXContext sharedContext=null;
protected final GLDrawableImpl getSharedDrawable() {
- validate();
return sharedDrawable;
}
protected final GLContextImpl getSharedContext() {
- validate();
return sharedContext;
}
- public void shutdown() {
- super.shutdown();
+ protected void shutdown() {
if (DEBUG) {
System.err.println("!!! Shutdown Shared:");
System.err.println("!!! CTX : "+sharedContext);
@@ -131,16 +128,14 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna
}
if(null!=sharedScreen) {
X11GraphicsDevice sharedDevice = (X11GraphicsDevice) sharedScreen.getDevice();
- if(null!=sharedDevice) {
- X11Util.closeThreadLocalDisplay(null);
- }
sharedScreen = null;
}
- X11Util.shutdown( !isVendorATI(), DEBUG );
+ // X11Util.shutdown( !isVendorATI(), DEBUG ); // works NV .. but ..
+ // X11Util.shutdown( true, DEBUG ); // fails ATI, works NV .. but
+ X11Util.shutdown( false, DEBUG );
}
public GLDrawableImpl createOnscreenDrawable(NativeWindow target) {
- validate();
if (target == null) {
throw new IllegalArgumentException("Null target");
}
@@ -151,7 +146,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna
}
protected GLDrawableImpl createOffscreenDrawable(NativeWindow target) {
- validate();
if (target == null) {
throw new IllegalArgumentException("Null target");
}
@@ -162,14 +156,12 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna
}
public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) {
- validate();
return glxVersionGreaterEqualThan(device, 1, 3);
}
private boolean glxVersionsQueried = false;
private int glxVersionMajor=0, glxVersionMinor=0;
public boolean glxVersionGreaterEqualThan(AbstractGraphicsDevice device, int majorReq, int minorReq) {
- validate();
if (!glxVersionsQueried) {
if(null == device) {
device = (X11GraphicsDevice) sharedScreen.getDevice();
@@ -195,7 +187,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna
}
protected GLDrawableImpl createGLPbufferDrawableImpl(final NativeWindow target) {
- validate();
if (target == null) {
throw new IllegalArgumentException("Null target");
}
@@ -228,7 +219,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna
protected NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) {
- validate();
NullWindow nw = null;
X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle());
try{
@@ -243,22 +233,18 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna
}
public GLContext createExternalGLContext() {
- validate();
return X11ExternalGLXContext.create(this, null);
}
public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) {
- validate();
return canCreateGLPbuffer(device);
}
public GLDrawable createExternalGLDrawable() {
- validate();
return X11ExternalGLXDrawable.create(this, null);
}
public void loadGLULibrary() {
- validate();
X11Lib.dlopen("/usr/lib/libGLU.so");
}
@@ -273,7 +259,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna
}
public boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) {
- validate();
return false;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/Animator.java b/src/jogl/classes/com/jogamp/opengl/util/Animator.java
index 30be0bd90..9bef8e9c3 100755
--- a/src/jogl/classes/com/jogamp/opengl/util/Animator.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/Animator.java
@@ -154,12 +154,19 @@ public class Animator {
impl.display(this, ignoreExceptions, printExceptions);
}
+ private long startTime = 0;
+ private long curTime = 0;
+ private int totalFrames = 0;
+
class MainLoop implements Runnable {
public void run() {
try {
if(DEBUG) {
System.out.println("Animator started: "+Thread.currentThread());
}
+ startTime = System.currentTimeMillis();
+ curTime = startTime;
+
while (!shouldStop) {
// Don't consume CPU unless there is work to be done
if (drawables.size() == 0) {
@@ -173,6 +180,8 @@ public class Animator {
}
}
display();
+ curTime = System.currentTimeMillis();
+ totalFrames++;
if (!runAsFastAsPossible) {
// Avoid swamping the CPU
Thread.yield();
@@ -191,6 +200,11 @@ public class Animator {
}
}
+ public long getStartTime() { return startTime; }
+ public long getCurrentTime() { return curTime; }
+ public long getDuration() { return curTime-startTime; }
+ public int getTotalFrames() { return totalFrames; }
+
/** Starts this animator. */
public synchronized void start() {
if (thread != null) {
diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java
index 2709dd506..c07bbeaf4 100644
--- a/src/jogl/classes/javax/media/opengl/GLContext.java
+++ b/src/jogl/classes/javax/media/opengl/GLContext.java
@@ -188,6 +188,13 @@ public abstract class GLContext {
}
/**
+ * @return true if this GLContext is current on this thread
+ */
+ public final boolean isCurrent() {
+ return getCurrent() == this ;
+ }
+
+ /**
* Sets the thread-local variable returned by {@link #getCurrent}
* and has no other side-effects. For use by third parties adding
* new GLContext implementations; not for use by end users.
diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
index b02bffb61..ca6bc7564 100644
--- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
+++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
@@ -168,13 +168,6 @@ public abstract class GLDrawableFactory {
throw new GLException("No native platform GLDrawableFactory, nor EGLDrawableFactory available: "+glProfileImplName);
}
- /** Shuts down this GLDrawableFactory, releasing resources
- associated with it. Before calling this method you should first
- destroy any GLContexts and GLDrawables that have been created
- and are still in use. No further OpenGL calls may be made after
- shutting down the GLDrawableFactory. */
- public abstract void shutdown();
-
//----------------------------------------------------------------------
// Methods to create high-level objects