aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-02-23 14:51:06 +0100
committerSven Gothel <[email protected]>2014-02-23 14:51:06 +0100
commit3352601e0860584509adf2b76f993d03893ded4b (patch)
tree974fccc8c0eb2f5ad9d4ffd741dfc35869ed67b5 /src/jogl/classes/jogamp/opengl/GLPbufferImpl.java
parentf51933f0ebe9ae030c26c066e59a728ce08b8559 (diff)
parentc67de337a8aaf52e36104c3f13e273aa19d21f1f (diff)
Merge branch 'master' into stash_glyphcache
Conflicts: make/scripts/tests.sh src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java src/jogl/classes/com/jogamp/graph/curve/Region.java src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java src/jogl/classes/com/jogamp/graph/font/Font.java src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java src/jogl/classes/jogamp/graph/curve/text/GlyphString.java src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/GLPbufferImpl.java')
-rw-r--r--src/jogl/classes/jogamp/opengl/GLPbufferImpl.java298
1 files changed, 46 insertions, 252 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java b/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java
index 0f4f7f8e2..c32957b86 100644
--- a/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLPbufferImpl.java
@@ -1,22 +1,22 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Copyright (c) 2010 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:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution 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.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -29,283 +29,77 @@
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
package jogamp.opengl;
-import com.jogamp.common.util.locks.LockFactory;
-import com.jogamp.common.util.locks.RecursiveLock;
-
-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;
-/** 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. */
+import com.jogamp.common.util.locks.LockFactory;
+import com.jogamp.common.util.locks.RecursiveLock;
-public class GLPbufferImpl implements GLPbuffer {
- private GLDrawableImpl pbufferDrawable;
- private GLContextImpl context;
- private GLDrawableHelper drawableHelper = new GLDrawableHelper();
- private int floatMode;
- private int additionalCtxCreationFlags = 0;
+@SuppressWarnings("deprecation")
+public class GLPbufferImpl extends GLAutoDrawableBase implements GLPbuffer {
- public GLPbufferImpl(GLDrawableImpl pbufferDrawable,
- GLContext parentContext) {
- GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable)
- pbufferDrawable.getNativeSurface().getGraphicsConfiguration().getChosenCapabilities();
- if(caps.isOnscreen()) {
- if(caps.isPBuffer()) {
- throw new IllegalArgumentException("Error: Given drawable is Onscreen and Pbuffer: "+pbufferDrawable);
- }
- throw new IllegalArgumentException("Error: Given drawable is Onscreen: "+pbufferDrawable);
- } else {
- if(!caps.isPBuffer()) {
- throw new IllegalArgumentException("Error: Given drawable is not Pbuffer: "+pbufferDrawable);
- }
- }
- this.pbufferDrawable = pbufferDrawable;
- context = (GLContextImpl) pbufferDrawable.createContext(parentContext);
+ public GLPbufferImpl(GLDrawableImpl pbufferDrawable, GLContextImpl pbufferContext) {
+ super(pbufferDrawable, pbufferContext, true); // drawable := pbufferDrawable, context := pbufferContext
}
- public GLContext createContext(GLContext shareWith) {
- return pbufferDrawable.createContext(shareWith);
- }
+ //
+ // pbuffer specifics
+ //
- public void setRealized(boolean realized) {
- }
+ //
+ // GLDrawable delegation
+ //
- public boolean isRealized() {
- return true;
+ @Override
+ public final void swapBuffers() throws GLException {
+ defaultSwapBuffers();
}
- public void destroy() {
- if(pbufferDrawable.isRealized()) {
- final AbstractGraphicsDevice adevice = pbufferDrawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice();
-
- if (null != context && context.isCreated()) {
- try {
- drawableHelper.disposeGL(GLPbufferImpl.this, pbufferDrawable, context, null);
- } catch (GLException gle) {
- gle.printStackTrace();
- }
- context = null;
- // drawableHelper.reset();
- }
- pbufferDrawable.destroy();
- pbufferDrawable = null;
-
- if(null != adevice) {
- adevice.close();
- }
- }
- }
+ //
+ // GLAutoDrawable completion
+ //
+ private final RecursiveLock lock = LockFactory.createRecursiveLock(); // instance wide lock
- public void setSize(int width, int height) {
- // FIXME
- throw new GLException("Not yet implemented");
- }
+ @Override
+ protected final RecursiveLock getLock() { return lock; }
- public NativeSurface getNativeSurface() {
- return pbufferDrawable.getNativeSurface();
+ @Override
+ public final Object getUpstreamWidget() {
+ return null;
}
- public long getHandle() {
- return pbufferDrawable.getHandle();
+ @Override
+ public void destroy() {
+ defaultDestroy();
}
+ @Override
public GLDrawableFactory getFactory() {
- return pbufferDrawable.getFactory();
- }
-
- public int getWidth() {
- return pbufferDrawable.getWidth();
- }
-
- public int getHeight() {
- return pbufferDrawable.getHeight();
- }
-
- public void display() {
- invokeGL(displayAction);
- }
-
- public void repaint() {
- display();
- }
-
- public void addGLEventListener(GLEventListener listener) {
- drawableHelper.addGLEventListener(listener);
- }
-
- public void addGLEventListener(int index, GLEventListener listener) {
- drawableHelper.addGLEventListener(index, listener);
- }
-
- public void removeGLEventListener(GLEventListener listener) {
- drawableHelper.removeGLEventListener(listener);
- }
-
- public void setAnimator(GLAnimatorControl animatorControl) {
- drawableHelper.setAnimator(animatorControl);
- }
-
- public GLAnimatorControl getAnimator() {
- return drawableHelper.getAnimator();
- }
-
- public void invoke(boolean wait, GLRunnable glRunnable) {
- drawableHelper.invoke(this, wait, glRunnable);
- }
-
- public void setContext(GLContext ctx) {
- context=(GLContextImpl)ctx;
- if(null != context) {
- context.setContextCreationFlags(additionalCtxCreationFlags);
- }
+ return drawable.getFactory();
}
- public GLContext getContext() {
- return context;
- }
-
- public GLDrawable getDrawable() {
- return pbufferDrawable;
- }
-
- public GL getGL() {
- return getContext().getGL();
- }
-
- public GL setGL(GL gl) {
- return getContext().setGL(gl);
- }
-
- public void setAutoSwapBufferMode(boolean onOrOff) {
- drawableHelper.setAutoSwapBufferMode(onOrOff);
- }
-
- public boolean getAutoSwapBufferMode() {
- return drawableHelper.getAutoSwapBufferMode();
- }
-
- public void swapBuffers() {
- invokeGL(swapBuffersAction);
- }
-
- public void setContextCreationFlags(int flags) {
- additionalCtxCreationFlags = flags;
- if(null != context) {
- context.setContextCreationFlags(additionalCtxCreationFlags);
- }
- }
-
- public int getContextCreationFlags() {
- return additionalCtxCreationFlags;
- }
-
- 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();
- }
-
- 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();
- }
-
- public GLCapabilitiesImmutable getChosenGLCapabilities() {
- if (pbufferDrawable == null)
- return null;
-
- return pbufferDrawable.getChosenGLCapabilities();
- }
-
- public GLCapabilitiesImmutable getRequestedGLCapabilities() {
- if (pbufferDrawable == null)
- return null;
-
- return pbufferDrawable.getRequestedGLCapabilities();
- }
-
- 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();
- }
-
- public boolean isSurfaceLocked() {
- return recurLock.isLocked();
- }
-
- public int getFloatingPointMode() {
- if (floatMode == 0) {
- throw new GLException("Pbuffer not initialized, or floating-point support not requested");
- }
- return floatMode;
- }
-
- //----------------------------------------------------------------------
- // Internals only below this point
- //
-
- private void invokeGL(Runnable invokeGLAction) {
- drawableHelper.invokeGL(pbufferDrawable, context, invokeGLAction, initAction);
- }
-
-
- class InitAction implements Runnable {
- public void run() {
- floatMode = context.getFloatingPointMode();
- drawableHelper.init(GLPbufferImpl.this);
- }
- }
- private InitAction initAction = new InitAction();
-
- class DisplayAction implements Runnable {
- public void run() {
- drawableHelper.display(GLPbufferImpl.this);
- }
- }
- private DisplayAction displayAction = new DisplayAction();
-
- class SwapBuffersAction implements Runnable {
- public void run() {
- pbufferDrawable.swapBuffers();
+ @Override
+ public final void display() {
+ final RecursiveLock _lock = lock;
+ _lock.lock(); // sync: context/drawable could been recreated/destroyed while animating
+ try {
+ if( null != context ) {
+ helper.invokeGL(drawable, context, defaultDisplayAction, defaultInitAction);
+ }
+ } finally {
+ _lock.unlock();
}
}
- private SwapBuffersAction swapBuffersAction = new SwapBuffersAction();
}