diff options
author | Gerard Ziemski <[email protected]> | 2003-11-19 18:47:55 +0000 |
---|---|---|
committer | Gerard Ziemski <[email protected]> | 2003-11-19 18:47:55 +0000 |
commit | 0f343197b80999930287b8043c9197a685437116 (patch) | |
tree | a0689efc66f766056a894ae8c6a95dab2b920ed8 /src/net/java | |
parent | bbe6acb715a9d6486d6bd257d78b3d6f6e240fad (diff) |
implemented GLJPanel for Mac OS X
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@74 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java')
10 files changed, 146 insertions, 77 deletions
diff --git a/src/net/java/games/jogl/GLJPanel.java b/src/net/java/games/jogl/GLJPanel.java index 07952eef3..b887d01c1 100644 --- a/src/net/java/games/jogl/GLJPanel.java +++ b/src/net/java/games/jogl/GLJPanel.java @@ -133,8 +133,8 @@ public final class GLJPanel extends JPanel implements GLDrawable { getGL().glViewport(fx, fy, fwidth, fheight); drawableHelper.reshape(GLJPanel.this, fx, fy, fwidth, fheight); if (offscreenImage != null && - (offscreenImage.getWidth() != getWidth() || - offscreenImage.getHeight() != getHeight())) { + (offscreenImage.getWidth() != context.getOffscreenContextWidth() || + offscreenImage.getHeight() != context.getOffscreenContextHeight())) { offscreenImage.flush(); offscreenImage = null; } @@ -222,7 +222,7 @@ public final class GLJPanel extends JPanel implements GLDrawable { // Must now copy pixels from offscreen context into surface if (offscreenImage == null) { int awtFormat = context.getOffscreenContextBufferedImageType(); - offscreenImage = new BufferedImage(getWidth(), getHeight(), awtFormat); + offscreenImage = new BufferedImage(context.getOffscreenContextWidth(), context.getOffscreenContextHeight(), awtFormat); switch (awtFormat) { case BufferedImage.TYPE_3BYTE_BGR: glFormat = GL.GL_BGR; @@ -240,7 +240,7 @@ public final class GLJPanel extends JPanel implements GLDrawable { case BufferedImage.TYPE_INT_ARGB: glFormat = GL.GL_BGRA; - glType = GL.GL_UNSIGNED_BYTE; + glType = context.getOffscreenContextPixelDataType(); glComps = 4; dbInt = (DataBufferInt) offscreenImage.getRaster().getDataBuffer(); break; @@ -269,7 +269,7 @@ public final class GLJPanel extends JPanel implements GLDrawable { // would require changing the generated bitmaps too. gl.glPixelStorei(GL.GL_PACK_SWAP_BYTES, GL.GL_FALSE); gl.glPixelStorei(GL.GL_PACK_LSB_FIRST, GL.GL_TRUE); - gl.glPixelStorei(GL.GL_PACK_ROW_LENGTH, getWidth()); + gl.glPixelStorei(GL.GL_PACK_ROW_LENGTH, offscreenImage.getWidth()); gl.glPixelStorei(GL.GL_PACK_SKIP_ROWS, 0); gl.glPixelStorei(GL.GL_PACK_SKIP_PIXELS, 0); gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1); @@ -277,9 +277,9 @@ public final class GLJPanel extends JPanel implements GLDrawable { // Actually read the pixels. gl.glReadBuffer(context.getOffscreenContextReadBuffer()); if (dbByte != null) { - gl.glReadPixels(0, 0, getWidth(), getHeight(), glFormat, glType, dbByte.getData()); + gl.glReadPixels(0, 0, offscreenImage.getWidth(), offscreenImage.getHeight(), glFormat, glType, dbByte.getData()); } else if (dbInt != null) { - gl.glReadPixels(0, 0, getWidth(), getHeight(), glFormat, glType, dbInt.getData()); + gl.glReadPixels(0, 0, offscreenImage.getWidth(), offscreenImage.getHeight(), glFormat, glType, dbInt.getData()); } // Restore saved modes. @@ -295,11 +295,11 @@ public final class GLJPanel extends JPanel implements GLDrawable { if (context.offscreenImageNeedsVerticalFlip()) { g.drawImage(offscreenImage, - 0, 0, getWidth(), getHeight(), - 0, getHeight(), getWidth(), 0, + 0, 0, offscreenImage.getWidth(), offscreenImage.getHeight(), + 0, offscreenImage.getHeight(), offscreenImage.getWidth(), 0, GLJPanel.this); } else { - g.drawImage(offscreenImage, 0, 0, getWidth(), getHeight(), GLJPanel.this); + g.drawImage(offscreenImage, 0, 0, offscreenImage.getWidth(), offscreenImage.getHeight(), GLJPanel.this); } } } diff --git a/src/net/java/games/jogl/impl/GLContext.java b/src/net/java/games/jogl/impl/GLContext.java index e0def092a..82672b1c3 100644 --- a/src/net/java/games/jogl/impl/GLContext.java +++ b/src/net/java/games/jogl/impl/GLContext.java @@ -464,12 +464,21 @@ public abstract class GLContext { which to read pixels (GL.GL_FRONT or GL.GL_BACK). */ public abstract int getOffscreenContextReadBuffer(); + /** Only called for offscreen contexts; needed by glReadPixels */ + public abstract int getOffscreenContextWidth(); + + /** Only called for offscreen contexts; needed by glReadPixels */ + public abstract int getOffscreenContextHeight(); + + /** Only called for offscreen contexts; needed by glReadPixels */ + public abstract int getOffscreenContextPixelDataType(); + /** On some platforms the mismatch between OpenGL's coordinate system (origin at bottom left) and the window system's coordinate system (origin at top left) necessitates a vertical flip of pixels read from offscreen contexts. */ public abstract boolean offscreenImageNeedsVerticalFlip(); - + /** Attempts to make the GL context current. If necessary, creates a context and calls the initAction once the context is current. Most error conditions cause an exception to be thrown, except diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java index e1618a15a..d636eaa6f 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java @@ -85,11 +85,29 @@ public abstract class MacOSXGLContext extends GLContext protected abstract boolean isOffscreen(); - public abstract int getOffscreenContextBufferedImageType(); + public int getOffscreenContextBufferedImageType() { + throw new GLException("Should not call this"); + } - public abstract int getOffscreenContextReadBuffer(); + public int getOffscreenContextReadBuffer() { + throw new GLException("Should not call this"); + } - public abstract boolean offscreenImageNeedsVerticalFlip(); + public int getOffscreenContextWidth() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextHeight() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextPixelDataType() { + throw new GLException("Should not call this"); + } + + public boolean offscreenImageNeedsVerticalFlip() { + throw new GLException("Should not call this"); + } /** * Creates and initializes an appropriate OpenGl nsContext. Should only be diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java index 431710a7c..1bbb32eda 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java @@ -43,48 +43,42 @@ import java.awt.image.BufferedImage; import net.java.games.jogl.*; import net.java.games.jogl.impl.*; -public class MacOSXOffscreenGLContext extends MacOSXGLContext -{ - // Width and height of the underlying bitmap - private int width; - private int height; - +public class MacOSXOffscreenGLContext extends MacOSXPbufferGLContext +{ public MacOSXOffscreenGLContext(GLCapabilities capabilities, GLCapabilitiesChooser chooser, GLContext shareWith) { - super(null, capabilities, chooser, shareWith); - } - - protected GL createGL() { - return new MacOSXGLImpl(this); + super(capabilities, -1, -1); } protected boolean isOffscreen() { return true; } + public boolean offscreenImageNeedsVerticalFlip() { + return true; + } + public int getOffscreenContextBufferedImageType() { return BufferedImage.TYPE_INT_ARGB; } - public int getOffscreenContextReadBuffer() { - return GL.GL_FRONT; + public int getOffscreenContextWidth() { + return initWidth; } - - public boolean offscreenImageNeedsVerticalFlip() { - // We can take care of this in the DIB creation (see below) - return false; + + public int getOffscreenContextHeight() { + return initWidth; } - - public boolean canCreatePbufferContext() { - // For now say no - return false; + + public int getOffscreenContextPixelDataType() { + return GL.GL_UNSIGNED_INT_8_8_8_8_REV; } - - public synchronized GLContext createPbufferContext(GLCapabilities capabilities, int initialWidth, int initialHeight) { - throw new GLException("Not supported"); + + public int getOffscreenContextReadBuffer() { + return GL.GL_BACK; } - + public void bindPbufferToTexture() { throw new GLException("Should not call this"); } @@ -94,13 +88,12 @@ public class MacOSXOffscreenGLContext extends MacOSXGLContext } protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - if (pendingOffscreenResize) { + if (pendingOffscreenResize && (nsContext != 0)) { if (pendingOffscreenWidth != width || pendingOffscreenHeight != height) { - if (nsContext != 0) { - destroy(); - } - width = pendingOffscreenWidth; - height = pendingOffscreenHeight; + destroyPBuffer(); + initWidth = pendingOffscreenWidth; + initHeight = pendingOffscreenHeight; + createPbuffer(0, 0); pendingOffscreenResize = false; } } @@ -108,9 +101,5 @@ public class MacOSXOffscreenGLContext extends MacOSXGLContext } protected synchronized void swapBuffers() throws GLException { - } - - private void destroy() { - free(); - } + } } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java index 97020de28..27b8a67f7 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java @@ -80,10 +80,6 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext { } } - protected GL createGL() { - return new MacOSXGLImpl(this); - } - protected boolean isOffscreen() { return false; } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java index 70068ce63..5e2662b47 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java @@ -4,16 +4,20 @@ import net.java.games.jogl.*; import net.java.games.jogl.impl.*; public class MacOSXPbufferGLContext extends MacOSXGLContext { + private static final boolean DEBUG = false; + + // see MacOSXWindowSystemInterface.m createPBuffer + private static final boolean USE_GL_TEXTURE_RECTANGLE_EXT = true; - private int initWidth; - private int initHeight; + protected int initWidth; + protected int initHeight; private long pBuffer; private int pBufferTextureName; - private int width; - private int height; + protected int width; + protected int height; // FIXME: kept around because we create the OpenGL context lazily to // better integrate with the MacOSXGLContext framework @@ -23,10 +27,6 @@ public class MacOSXPbufferGLContext extends MacOSXGLContext { super(null, capabilities, null, null); this.initWidth = initialWidth; this.initHeight = initialHeight; - if (initWidth <= 0 || initHeight <= 0) { - throw new GLException("Initial width and height of pbuffer must be positive (were (" + - initWidth + ", " + initHeight + "))"); - } } public boolean canCreatePbufferContext() { @@ -61,14 +61,35 @@ public class MacOSXPbufferGLContext extends MacOSXGLContext { nsContextOfParent = parentContext; - width = getNextPowerOf2(initWidth); - height = getNextPowerOf2(initHeight); - + if (USE_GL_TEXTURE_RECTANGLE_EXT) + { + // GL_TEXTURE_RECTANGLE_EXT + width = initWidth; + height = initHeight; + } + else + { + // GL_TEXTURE_2D + width = getNextPowerOf2(initWidth); + height = getNextPowerOf2(initHeight); + } + if (DEBUG) { System.err.println("Created pbuffer " + width + " x " + height); } } + public void destroyPBuffer() { + if (this.pBuffer != 0) { + CGL.destroyPBuffer(nsContext, pBuffer); + } + this.pBuffer = 0; + + if (DEBUG) { + System.err.println("Destroyed pbuffer " + width + " x " + height); + } + } + public void handleModeSwitch(long parentView, long parentContext) { throw new GLException("Not yet implemented"); } @@ -79,18 +100,6 @@ public class MacOSXPbufferGLContext extends MacOSXGLContext { return false; } - public int getOffscreenContextBufferedImageType() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - protected void swapBuffers() throws GLException { // FIXME: do we need to do anything if the pbuffer is double-buffered? } diff --git a/src/net/java/games/jogl/impl/windows/WindowsGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsGLContext.java index 9232cf37a..ff61bbd52 100644 --- a/src/net/java/games/jogl/impl/windows/WindowsGLContext.java +++ b/src/net/java/games/jogl/impl/windows/WindowsGLContext.java @@ -101,6 +101,18 @@ public abstract class WindowsGLContext extends GLContext { public abstract int getOffscreenContextBufferedImageType(); + public int getOffscreenContextWidth() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextHeight() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextPixelDataType() { + throw new GLException("Should not call this"); + } + public abstract int getOffscreenContextReadBuffer(); public abstract boolean offscreenImageNeedsVerticalFlip(); diff --git a/src/net/java/games/jogl/impl/windows/WindowsOffscreenGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsOffscreenGLContext.java index 8c2e72a7d..6185ae9fd 100644 --- a/src/net/java/games/jogl/impl/windows/WindowsOffscreenGLContext.java +++ b/src/net/java/games/jogl/impl/windows/WindowsOffscreenGLContext.java @@ -73,6 +73,18 @@ public class WindowsOffscreenGLContext extends WindowsGLContext { } } + public int getOffscreenContextWidth() { + return width; + } + + public int getOffscreenContextHeight() { + return height; + } + + public int getOffscreenContextPixelDataType() { + return GL.GL_UNSIGNED_BYTE; + } + public int getOffscreenContextReadBuffer() { // On Windows these contexts are always single-buffered return GL.GL_FRONT; diff --git a/src/net/java/games/jogl/impl/x11/X11GLContext.java b/src/net/java/games/jogl/impl/x11/X11GLContext.java index 3fb142bff..39bae6f62 100644 --- a/src/net/java/games/jogl/impl/x11/X11GLContext.java +++ b/src/net/java/games/jogl/impl/x11/X11GLContext.java @@ -93,6 +93,18 @@ public abstract class X11GLContext extends GLContext { public abstract int getOffscreenContextBufferedImageType(); + public int getOffscreenContextWidth() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextHeight() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextPixelDataType() { + throw new GLException("Should not call this"); + } + public abstract int getOffscreenContextReadBuffer(); public abstract boolean offscreenImageNeedsVerticalFlip(); diff --git a/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java b/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java index 6d4557407..10ffdc854 100644 --- a/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java +++ b/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java @@ -76,6 +76,18 @@ public class X11OffscreenGLContext extends X11GLContext { } } + public int getOffscreenContextWidth() { + return width; + } + + public int getOffscreenContextHeight() { + return height; + } + + public int getOffscreenContextPixelDataType() { + return GL.GL_UNSIGNED_BYTE; + } + public int getOffscreenContextReadBuffer() { if (isDoubleBuffered) { return GL.GL_BACK; |