diff options
author | Kenneth Russel <[email protected]> | 2005-07-18 23:15:37 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2005-07-18 23:15:37 +0000 |
commit | 35435c313ba527c9bea35a14f72492d2f80a9c84 (patch) | |
tree | ae7f1ed0a184d990292f0e295fa943c0139868a0 /src/net/java/games/jogl/impl/macosx | |
parent | 8f5492988de9fddf61623b7274915c777ad3a97d (diff) |
Moved pbuffer creation support from MacOSXOnscreenGLDrawable to
MacOSXGLContextFactory. This completes the transition from creating
pbuffers as a subordinate object of a GLCanvas to creating them as
standalone GLDrawables. Deleted code from GLAutoDrawable and all
implementations related to pbuffer instantiation.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JSR-231@328 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java/games/jogl/impl/macosx')
5 files changed, 64 insertions, 46 deletions
diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java index cde1d54b1..f6b7cebf1 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java @@ -233,16 +233,6 @@ public abstract class MacOSXGLContext extends GLContextImpl throw new GLException("Should not call this"); } - public boolean canCreatePbufferContext() { - return false; - } - - public GLDrawableImpl createPbufferDrawable(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - public void bindPbufferToTexture() { throw new GLException("Should not call this"); } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXGLContextFactory.java b/src/net/java/games/jogl/impl/macosx/MacOSXGLContextFactory.java index a3c502b7c..150468bfb 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXGLContextFactory.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXGLContextFactory.java @@ -40,8 +40,12 @@ package net.java.games.jogl.impl.macosx; import java.awt.Component; +import java.awt.EventQueue; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; import net.java.games.jogl.*; import net.java.games.jogl.impl.*; @@ -73,4 +77,42 @@ public class MacOSXGLContextFactory extends GLContextFactory { GLCapabilitiesChooser chooser) { return new MacOSXOffscreenGLDrawable(capabilities); } + + public boolean canCreateGLPbuffer(GLCapabilities capabilities, + int initialWidth, + int initialHeight) { + return true; + } + + public GLPbuffer createGLPbuffer(final GLCapabilities capabilities, + final int initialWidth, + final int initialHeight, + final GLContext shareWith) { + final List returnList = new ArrayList(); + Runnable r = new Runnable() { + public void run() { + MacOSXPbufferGLDrawable pbufferDrawable = new MacOSXPbufferGLDrawable(capabilities, + initialWidth, + initialHeight); + GLPbufferImpl pbuffer = new GLPbufferImpl(pbufferDrawable, shareWith); + returnList.add(pbuffer); + } + }; + maybeDoSingleThreadedWorkaround(r); + return (GLPbuffer) returnList.get(0); + } + + private void maybeDoSingleThreadedWorkaround(Runnable action) { + if (SingleThreadedWorkaround.doWorkaround() && !EventQueue.isDispatchThread()) { + try { + EventQueue.invokeAndWait(action); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (InterruptedException e) { + throw new GLException(e); + } + } else { + action.run(); + } + } } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLDrawable.java b/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLDrawable.java index d7da03ec0..1118680ca 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLDrawable.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLDrawable.java @@ -56,8 +56,6 @@ public class MacOSXOffscreenGLDrawable extends MacOSXPbufferGLDrawable { destroy(); initWidth = width; initHeight = height; - // Floating-point frame buffers are never used with offscreen - // drawables (in GLJPanel) so don't need a GL object here - createPbuffer(null); + createPbuffer(); } } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java index 6dd2c4b4a..6accb37c0 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java @@ -46,8 +46,6 @@ import net.java.games.jogl.impl.*; public class MacOSXOnscreenGLContext extends MacOSXGLContext { protected MacOSXOnscreenGLDrawable drawable; - // Variables for pbuffer support - List pbuffersToInstantiate = new ArrayList(); public MacOSXOnscreenGLContext(MacOSXOnscreenGLDrawable drawable, GLContext shareWith) { @@ -55,18 +53,6 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext { this.drawable = drawable; } - public boolean canCreatePbufferContext() { - return true; - } - - public GLDrawableImpl createPbufferDrawable(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - MacOSXPbufferGLDrawable buf = new MacOSXPbufferGLDrawable(capabilities, initialWidth, initialHeight); - pbuffersToInstantiate.add(buf); - return buf; - } - protected int makeCurrentImpl() throws GLException { try { int lockRes = drawable.lockSurface(); @@ -87,12 +73,6 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext { // of an ancestor, but this also wasn't sufficient and left garbage on the // screen in some situations. CGL.updateContext(nsContext, drawable.getView()); - // Instantiate any pending pbuffers - while (!pbuffersToInstantiate.isEmpty()) { - MacOSXPbufferGLDrawable buf = - (MacOSXPbufferGLDrawable) pbuffersToInstantiate.remove(pbuffersToInstantiate.size() - 1); - buf.createPbuffer(getGL()); - } } else { // View might not have been ready drawable.unlockSurface(); diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLDrawable.java b/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLDrawable.java index fc5f3c22e..282d8a08b 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLDrawable.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLDrawable.java @@ -61,6 +61,8 @@ public class MacOSXPbufferGLDrawable extends MacOSXGLDrawable { super(capabilities, null); this.initWidth = initialWidth; this.initHeight = initialHeight; + + createPbuffer(); } public GLContext createContext(GLContext shareWith) { @@ -91,7 +93,19 @@ public class MacOSXPbufferGLDrawable extends MacOSXGLDrawable { return height; } - public void createPbuffer(GL gl) { + public GLCapabilities getCapabilities() { + return capabilities; + } + + public long getPbuffer() { + return pBuffer; + } + + public void swapBuffers() throws GLException { + // FIXME: do we need to do anything if the pbuffer is double-buffered? + } + + protected void createPbuffer() { int renderTarget; if (capabilities.getOffscreenRenderToTextureRectangle()) { width = initWidth; @@ -105,9 +119,15 @@ public class MacOSXPbufferGLDrawable extends MacOSXGLDrawable { int internalFormat = GL.GL_RGBA; if (capabilities.getOffscreenFloatingPointBuffers()) { + // FIXME: want to check availability of GL_APPLE_float_pixels + // extension, but need valid OpenGL context in order to do so -- + // in worst case would need to create dummy window / GLCanvas + // (undesirable) -- could maybe also do this with pbuffers + /* if (!gl.isExtensionAvailable("GL_APPLE_float_pixels")) { throw new GLException("Floating-point support (GL_APPLE_float_pixels) not available"); } + */ switch (capabilities.getRedBits()) { case 16: internalFormat = GL.GL_RGBA_FLOAT16_APPLE; break; case 32: internalFormat = GL.GL_RGBA_FLOAT32_APPLE; break; @@ -125,18 +145,6 @@ public class MacOSXPbufferGLDrawable extends MacOSXGLDrawable { } } - public GLCapabilities getCapabilities() { - return capabilities; - } - - public long getPbuffer() { - return pBuffer; - } - - public void swapBuffers() throws GLException { - // FIXME: do we need to do anything if the pbuffer is double-buffered? - } - private int getNextPowerOf2(int number) { if (((number-1) & number) == 0) { //ex: 8 -> 0b1000; 8-1=7 -> 0b0111; 0b1000&0b0111 == 0 |