aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-07-02 19:42:52 +0200
committerSven Gothel <[email protected]>2012-07-02 19:42:52 +0200
commiteed8508ae1132e5f45f788e9cb3f3d5a1050ac70 (patch)
treee1eec83da8dee44392407b59672134109fc63b6f /src/jogl/classes/jogamp
parent08e3f9bff494a5366781328734e83ae0202696fa (diff)
GLAutoDrawable: Refine API doc; Use new abstract impl. GLAutoDrawableBase (GLWindow, ..); Add new GLAutoDrawableDelegate.
- Refine API doc - 'void setContext(GLContext)' -> 'GLContext setContext(GLContext)' - Add note to createContext(GLContext) override -Use new abstract impl. GLAutoDrawableBase, used by: - GLWindow - GLAutoDrawableDelegate - GLPbufferImpl - Add new GLAutoDrawableDelegate incl. unit test
Diffstat (limited to 'src/jogl/classes/jogamp')
-rw-r--r--src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java337
-rw-r--r--src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java7
-rw-r--r--src/jogl/classes/jogamp/opengl/GLPbufferImpl.java278
3 files changed, 389 insertions, 233 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java b/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java
new file mode 100644
index 000000000..3f50fe420
--- /dev/null
+++ b/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java
@@ -0,0 +1,337 @@
+/**
+ * Copyright 2012 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package jogamp.opengl;
+
+import java.io.PrintStream;
+
+import javax.media.nativewindow.NativeSurface;
+import javax.media.opengl.FPSCounter;
+import javax.media.opengl.GL;
+import javax.media.opengl.GLAnimatorControl;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLAutoDrawableDelegate;
+import javax.media.opengl.GLCapabilitiesImmutable;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLException;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLRunnable;
+
+import com.jogamp.opengl.util.Animator;
+
+
+/**
+ * Abstract common code for GLAutoDrawable implementations.
+ *
+ * @see GLAutoDrawable
+ * @see GLAutoDrawableDelegate
+ * @see GLPBufferImpl
+ * @see GLWindow
+ */
+public abstract class GLAutoDrawableBase implements GLAutoDrawable, FPSCounter {
+ public static final boolean DEBUG = Debug.debug("GLAutoDrawable");
+
+ protected final GLDrawableHelper helper = new GLDrawableHelper();
+ protected final FPSCounterImpl fpsCounter = new FPSCounterImpl();
+
+ protected GLDrawableImpl drawable;
+ protected GLContextImpl context;
+ protected int additionalCtxCreationFlags = 0;
+ protected boolean sendReshape = false;
+ protected boolean sendDestroy = false;
+
+ public GLAutoDrawableBase(GLDrawableImpl drawable, GLContextImpl context) {
+ this.drawable = drawable;
+ this.context = context;
+ resetFPSCounter();
+ }
+
+ /** Returns the delegated GLDrawable */
+ public final GLDrawable getDelegatedDrawable() { return drawable; }
+
+ protected void defaultRepaintOp() {
+ if( null != drawable && drawable.isRealized() ) {
+ if( !drawable.getNativeSurface().isSurfaceLockedByOtherThread() && !helper.isAnimatorAnimating() ) {
+ display();
+ }
+ }
+ }
+
+ protected void defaultReshapeOp() {
+ if( null!=drawable ) {
+ if(DEBUG) {
+ System.err.println("GLAutoDrawableBase.sizeChanged: ("+Thread.currentThread().getName()+"): "+getWidth()+"x"+getHeight()+" - surfaceHandle 0x"+Long.toHexString(getNativeSurface().getSurfaceHandle()));
+ }
+ sendReshape = true;
+ defaultRepaintOp();
+ }
+ }
+
+ //
+ // GLAutoDrawable
+ //
+
+ protected final Runnable defaultInitAction = new Runnable() {
+ @Override
+ public final void run() {
+ // Lock: Locked Surface/Window by MakeCurrent/Release
+ helper.init(GLAutoDrawableBase.this);
+ resetFPSCounter();
+ } };
+
+ protected final Runnable defaultDisplayAction = new Runnable() {
+ @Override
+ public final void run() {
+ // Lock: Locked Surface/Window by display _and_ MakeCurrent/Release
+ if (sendReshape) {
+ helper.reshape(GLAutoDrawableBase.this, 0, 0, getWidth(), getHeight());
+ sendReshape = false;
+ }
+ helper.display(GLAutoDrawableBase.this);
+ fpsCounter.tickFPS();
+ } };
+
+ @Override
+ public final GLContext getContext() {
+ return context;
+ }
+
+ @Override
+ public final GLContext setContext(GLContext newCtx) {
+ final GLContext oldCtx = context;
+ final boolean newCtxCurrent = helper.switchContext(drawable, oldCtx, newCtx, additionalCtxCreationFlags);
+ context=(GLContextImpl)newCtx;
+ if(newCtxCurrent) {
+ context.makeCurrent();
+ }
+ return oldCtx;
+ }
+
+ @Override
+ public final GL getGL() {
+ if (context == null) {
+ return null;
+ }
+ return context.getGL();
+ }
+
+ @Override
+ public final GL setGL(GL gl) {
+ if (context != null) {
+ context.setGL(gl);
+ return gl;
+ }
+ return null;
+ }
+
+ @Override
+ public final void addGLEventListener(GLEventListener listener) {
+ helper.addGLEventListener(listener);
+ }
+
+ @Override
+ public final void addGLEventListener(int index, GLEventListener listener)
+ throws IndexOutOfBoundsException {
+ helper.addGLEventListener(index, listener);
+ }
+
+ @Override
+ public final void removeGLEventListener(GLEventListener listener) {
+ helper.removeGLEventListener(listener);
+ }
+
+ @Override
+ public final void setAnimator(GLAnimatorControl animatorControl)
+ throws GLException {
+ helper.setAnimator(animatorControl);
+ }
+
+ @Override
+ public final GLAnimatorControl getAnimator() {
+ return helper.getAnimator();
+ }
+
+ @Override
+ public final void invoke(boolean wait, GLRunnable glRunnable) {
+ helper.invoke(this, wait, glRunnable);
+ }
+
+ @Override
+ public final void setAutoSwapBufferMode(boolean enable) {
+ helper.setAutoSwapBufferMode(enable);
+ }
+
+ @Override
+ public final boolean getAutoSwapBufferMode() {
+ return helper.getAutoSwapBufferMode();
+ }
+
+ @Override
+ public final void setContextCreationFlags(int flags) {
+ additionalCtxCreationFlags = flags;
+ if(null != context) {
+ context.setContextCreationFlags(additionalCtxCreationFlags);
+ }
+ }
+
+ @Override
+ public final int getContextCreationFlags() {
+ return additionalCtxCreationFlags;
+ }
+
+ //
+ // FPSCounter
+ //
+
+ @Override
+ public final void setUpdateFPSFrames(int frames, PrintStream out) {
+ fpsCounter.setUpdateFPSFrames(frames, out);
+ }
+
+ @Override
+ public final void resetFPSCounter() {
+ fpsCounter.resetFPSCounter();
+ }
+
+ @Override
+ public final int getUpdateFPSFrames() {
+ return fpsCounter.getUpdateFPSFrames();
+ }
+
+ @Override
+ public final long getFPSStartTime() {
+ return fpsCounter.getFPSStartTime();
+ }
+
+ @Override
+ public final long getLastFPSUpdateTime() {
+ return fpsCounter.getLastFPSUpdateTime();
+ }
+
+ @Override
+ public final long getLastFPSPeriod() {
+ return fpsCounter.getLastFPSPeriod();
+ }
+
+ @Override
+ public final float getLastFPS() {
+ return fpsCounter.getLastFPS();
+ }
+
+ @Override
+ public final int getTotalFPSFrames() {
+ return fpsCounter.getTotalFPSFrames();
+ }
+
+ @Override
+ public final long getTotalFPSDuration() {
+ return fpsCounter.getTotalFPSDuration();
+ }
+
+ @Override
+ public final float getTotalFPS() {
+ return fpsCounter.getTotalFPS();
+ }
+
+ //
+ // GLDrawable delegation
+ //
+
+ @Override
+ public final GLContext createContext(final GLContext shareWith) {
+ if(drawable != null) {
+ final GLContext _ctx = drawable.createContext(shareWith);
+ _ctx.setContextCreationFlags(additionalCtxCreationFlags);
+ return _ctx;
+ }
+ return null;
+ }
+
+ @Override
+ public final boolean isRealized() {
+ return null != drawable ? drawable.isRealized() : false;
+ }
+
+ @Override
+ public int getWidth() {
+ return null != drawable ? drawable.getWidth() : 0;
+ }
+
+ @Override
+ public int getHeight() {
+ return null != drawable ? drawable.getHeight() : 0;
+ }
+
+ /**
+ * @param t the thread for which context release shall be skipped, usually the animation thread,
+ * ie. {@link Animator#getThread()}.
+ * @deprecated this is an experimental feature,
+ * intended for measuring performance in regards to GL context switch
+ */
+ @Deprecated
+ public void setSkipContextReleaseThread(Thread t) {
+ helper.setSkipContextReleaseThread(t);
+ }
+
+ /**
+ * @deprecated see {@link #setSkipContextReleaseThread(Thread)}
+ */
+ @Deprecated
+ public Thread getSkipContextReleaseThread() {
+ return helper.getSkipContextReleaseThread();
+ }
+
+ @Override
+ public final void swapBuffers() throws GLException {
+ if(drawable!=null && context != null) {
+ drawable.swapBuffers();
+ }
+ }
+
+ @Override
+ public final GLCapabilitiesImmutable getChosenGLCapabilities() {
+ return null != drawable ? drawable.getChosenGLCapabilities() : null;
+ }
+
+ @Override
+ public final GLProfile getGLProfile() {
+ return null != drawable ? drawable.getGLProfile() : null;
+ }
+
+ @Override
+ public final NativeSurface getNativeSurface() {
+ return null != drawable ? drawable.getNativeSurface() : null;
+ }
+
+ @Override
+ public final long getHandle() {
+ return null != drawable ? drawable.getHandle() : 0;
+ }
+}
diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java b/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
index 3c60eb699..e5c44a8d4 100644
--- a/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
@@ -130,8 +130,8 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
throw new IllegalArgumentException("Null target");
}
final MutableGraphicsConfiguration config = (MutableGraphicsConfiguration) target.getGraphicsConfiguration();
- GLCapabilitiesImmutable chosenCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
- AbstractGraphicsDevice adevice = config.getScreen().getDevice();
+ final GLCapabilitiesImmutable chosenCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
+ final AbstractGraphicsDevice adevice = config.getScreen().getDevice();
GLDrawable result = null;
adevice.lock();
try {
@@ -183,7 +183,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
//---------------------------------------------------------------------------
//
- // PBuffer GLDrawable construction
+ // PBuffer Offscreen GLDrawable construction
//
public abstract boolean canCreateGLPbuffer(AbstractGraphicsDevice device);
@@ -226,7 +226,6 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
return new GLPbufferImpl( drawable, shareWith);
}
-
//---------------------------------------------------------------------------
//
// Offscreen GLDrawable construction
diff --git a/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java b/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java
index 0ed3be48b..d98b41bdc 100644
--- a/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java
@@ -41,38 +41,26 @@
package jogamp.opengl;
import javax.media.nativewindow.AbstractGraphicsDevice;
-import javax.media.nativewindow.NativeSurface;
-import javax.media.opengl.GL;
-import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.GLCapabilitiesImmutable;
import javax.media.opengl.GLContext;
-import javax.media.opengl.GLDrawable;
import javax.media.opengl.GLDrawableFactory;
-import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLException;
import javax.media.opengl.GLPbuffer;
-import javax.media.opengl.GLProfile;
-import javax.media.opengl.GLRunnable;
-
-import com.jogamp.common.util.locks.LockFactory;
-import com.jogamp.common.util.locks.RecursiveLock;
/** Platform-independent class exposing pbuffer functionality to
applications. This class is not exposed in the public API as it
would probably add no value; however it implements the GLDrawable
interface so can be interacted with via its display() method. */
-public class GLPbufferImpl implements GLPbuffer {
- private GLDrawableImpl pbufferDrawable;
- private GLContextImpl context;
- private GLDrawableHelper drawableHelper = new GLDrawableHelper();
+public class GLPbufferImpl extends GLAutoDrawableBase implements GLPbuffer {
private int floatMode;
- private int additionalCtxCreationFlags = 0;
public GLPbufferImpl(GLDrawableImpl pbufferDrawable,
- GLContext parentContext) {
+ GLContext sharedContext) {
+ super(pbufferDrawable, null); // drawable := pbufferDrawable
+
GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable)
- pbufferDrawable.getNativeSurface().getGraphicsConfiguration().getChosenCapabilities();
+ drawable.getNativeSurface().getGraphicsConfiguration().getChosenCapabilities();
if(caps.isOnscreen()) {
if(caps.isPBuffer()) {
throw new IllegalArgumentException("Error: Given drawable is Onscreen and Pbuffer: "+pbufferDrawable);
@@ -83,40 +71,63 @@ public class GLPbufferImpl implements GLPbuffer {
throw new IllegalArgumentException("Error: Given drawable is not Pbuffer: "+pbufferDrawable);
}
}
- this.pbufferDrawable = pbufferDrawable;
- context = (GLContextImpl) pbufferDrawable.createContext(parentContext);
+ context = (GLContextImpl) drawable.createContext(sharedContext);
}
+ //
+ // pbuffer specifics
+ //
+
@Override
- public final GLContext createContext(GLContext shareWith) {
- return pbufferDrawable.createContext(shareWith);
+ public void bindTexture() {
+ // Doesn't make much sense to try to do this on the event dispatch
+ // thread given that it has to be called while the context is current
+ context.bindPbufferToTexture();
}
@Override
- public final void setRealized(boolean realized) {
+ public void releaseTexture() {
+ // Doesn't make much sense to try to do this on the event dispatch
+ // thread given that it has to be called while the context is current
+ context.releasePbufferFromTexture();
}
@Override
- public final boolean isRealized() {
- return true;
+ public int getFloatingPointMode() {
+ if (floatMode == 0) {
+ throw new GLException("Pbuffer not initialized, or floating-point support not requested");
+ }
+ return floatMode;
}
+ //
+ // GLDrawable delegation
+ //
+
+ @Override
+ public final void setRealized(boolean realized) {
+ }
+
+ //
+ // GLAutoDrawable completion
+ //
+
@Override
public void destroy() {
- if(pbufferDrawable.isRealized()) {
- final AbstractGraphicsDevice adevice = pbufferDrawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice();
+ if(drawable.isRealized()) {
+ final AbstractGraphicsDevice adevice = drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice();
if (null != context && context.isCreated()) {
try {
- drawableHelper.disposeGL(GLPbufferImpl.this, pbufferDrawable, context, null);
+ helper.disposeGL(GLPbufferImpl.this, drawable, context, null);
} catch (GLException gle) {
gle.printStackTrace();
}
context = null;
// drawableHelper.reset();
}
- pbufferDrawable.destroy();
- pbufferDrawable = null;
+ drawable.destroy();
+ drawable = null;
if(null != adevice) {
adevice.close();
@@ -124,217 +135,26 @@ public class GLPbufferImpl implements GLPbuffer {
}
}
- public void setSize(int width, int height) {
- // FIXME
- throw new GLException("Not yet implemented");
- }
-
- @Override
- public NativeSurface getNativeSurface() {
- return pbufferDrawable.getNativeSurface();
- }
-
- @Override
- public long getHandle() {
- return pbufferDrawable.getHandle();
- }
-
@Override
public GLDrawableFactory getFactory() {
- return pbufferDrawable.getFactory();
- }
-
- @Override
- public int getWidth() {
- return pbufferDrawable.getWidth();
- }
-
- @Override
- public int getHeight() {
- return pbufferDrawable.getHeight();
+ return drawable.getFactory();
}
@Override
public void display() {
- invokeGL(displayAction);
- }
-
- public void repaint() {
- display();
- }
-
- @Override
- public void addGLEventListener(GLEventListener listener) {
- drawableHelper.addGLEventListener(listener);
- }
-
- @Override
- public void addGLEventListener(int index, GLEventListener listener) {
- drawableHelper.addGLEventListener(index, listener);
- }
-
- @Override
- public void removeGLEventListener(GLEventListener listener) {
- drawableHelper.removeGLEventListener(listener);
- }
-
- @Override
- public void setAnimator(GLAnimatorControl animatorControl) {
- drawableHelper.setAnimator(animatorControl);
- }
-
- @Override
- public GLAnimatorControl getAnimator() {
- return drawableHelper.getAnimator();
- }
-
- @Override
- public void invoke(boolean wait, GLRunnable glRunnable) {
- drawableHelper.invoke(this, wait, glRunnable);
- }
-
- @Override
- public void setContext(GLContext ctx) {
- context=(GLContextImpl)ctx;
- if(null != context) {
- context.setContextCreationFlags(additionalCtxCreationFlags);
- }
- }
-
- @Override
- public GLContext getContext() {
- return context;
- }
-
- public GLDrawable getDrawable() {
- return pbufferDrawable;
- }
-
- @Override
- public GL getGL() {
- return getContext().getGL();
- }
-
- @Override
- public GL setGL(GL gl) {
- return getContext().setGL(gl);
- }
-
- @Override
- public void setAutoSwapBufferMode(boolean onOrOff) {
- drawableHelper.setAutoSwapBufferMode(onOrOff);
- }
-
- @Override
- public boolean getAutoSwapBufferMode() {
- return drawableHelper.getAutoSwapBufferMode();
- }
-
- @Override
- public void swapBuffers() {
- invokeGL(swapBuffersAction);
- }
-
- @Override
- public void setContextCreationFlags(int flags) {
- additionalCtxCreationFlags = flags;
- if(null != context) {
- context.setContextCreationFlags(additionalCtxCreationFlags);
- }
- }
-
- @Override
- public int getContextCreationFlags() {
- return additionalCtxCreationFlags;
- }
-
- @Override
- public void bindTexture() {
- // Doesn't make much sense to try to do this on the event dispatch
- // thread given that it has to be called while the context is current
- context.bindPbufferToTexture();
- }
-
- @Override
- public void releaseTexture() {
- // Doesn't make much sense to try to do this on the event dispatch
- // thread given that it has to be called while the context is current
- context.releasePbufferFromTexture();
- }
-
- @Override
- public GLCapabilitiesImmutable getChosenGLCapabilities() {
- if (pbufferDrawable == null)
- return null;
-
- return pbufferDrawable.getChosenGLCapabilities();
- }
-
- public GLCapabilitiesImmutable getRequestedGLCapabilities() {
- if (pbufferDrawable == null)
- return null;
-
- return pbufferDrawable.getRequestedGLCapabilities();
- }
-
- @Override
- public GLProfile getGLProfile() {
- if (pbufferDrawable == null)
- return null;
-
- return pbufferDrawable.getGLProfile();
- }
-
- private RecursiveLock recurLock = LockFactory.createRecursiveLock();
-
- public int lockSurface() throws GLException {
- recurLock.lock();
- return NativeSurface.LOCK_SUCCESS;
- }
-
- public void unlockSurface() {
- recurLock.unlock();
- }
-
- @Override
- public int getFloatingPointMode() {
- if (floatMode == 0) {
- throw new GLException("Pbuffer not initialized, or floating-point support not requested");
- }
- return floatMode;
+ if( null == drawable || !drawable.isRealized() || null == context ) { return; }
+ helper.invokeGL(drawable, context, defaultDisplayAction, initAction);
}
//----------------------------------------------------------------------
// Internals only below this point
//
- private void invokeGL(Runnable invokeGLAction) {
- drawableHelper.invokeGL(pbufferDrawable, context, invokeGLAction, initAction);
- }
-
-
- class InitAction implements Runnable {
+ protected final Runnable initAction = new Runnable() {
@Override
- public void run() {
- floatMode = context.getFloatingPointMode();
- drawableHelper.init(GLPbufferImpl.this);
- }
- }
- private InitAction initAction = new InitAction();
-
- class DisplayAction implements Runnable {
- @Override
- public void run() {
- drawableHelper.display(GLPbufferImpl.this);
- }
- }
- private DisplayAction displayAction = new DisplayAction();
-
- class SwapBuffersAction implements Runnable {
- @Override
- public void run() {
- pbufferDrawable.swapBuffers();
- }
- }
- private SwapBuffersAction swapBuffersAction = new SwapBuffersAction();
+ public final void run() {
+ floatMode = context.getFloatingPointMode();
+ defaultInitAction.run();
+ } };
+
}