aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/com/sun/opengl/impl/macosx
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/com/sun/opengl/impl/macosx')
-rw-r--r--src/classes/com/sun/opengl/impl/macosx/MacOSXGLContext.java148
-rw-r--r--src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLDrawable.java3
2 files changed, 125 insertions, 26 deletions
diff --git a/src/classes/com/sun/opengl/impl/macosx/MacOSXGLContext.java b/src/classes/com/sun/opengl/impl/macosx/MacOSXGLContext.java
index e41ad856d..16855efb8 100644
--- a/src/classes/com/sun/opengl/impl/macosx/MacOSXGLContext.java
+++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXGLContext.java
@@ -102,34 +102,130 @@ public abstract class MacOSXGLContext extends GLContextImpl
}
int[] viewNotReady = new int[1];
GLCapabilities capabilities = drawable.getCapabilities();
- nsContext = CGL.createContext(share,
- drawable.getView(),
- capabilities.getDoubleBuffered() ? 1 : 0,
- capabilities.getStereo() ? 1 : 0,
- capabilities.getRedBits(),
- capabilities.getGreenBits(),
- capabilities.getBlueBits(),
- capabilities.getAlphaBits(),
- capabilities.getDepthBits(),
- capabilities.getStencilBits(),
- capabilities.getAccumRedBits(),
- capabilities.getAccumGreenBits(),
- capabilities.getAccumBlueBits(),
- capabilities.getAccumAlphaBits(),
- capabilities.getSampleBuffers() ? 1 : 0,
- capabilities.getNumSamples(),
- (pbuffer ? 1 : 0),
- (floatingPoint ? 1 : 0),
- viewNotReady, 0);
- if (nsContext == 0) {
- if (viewNotReady[0] == 1) {
- if (DEBUG) {
- System.err.println("!!! View not ready for " + getClass().getName());
+ int[] iattribs = new int[128];
+ int[] ivalues = new int[128];
+ int idx = 0;
+ if (pbuffer) {
+ iattribs[idx] = CGL.NSOpenGLPFAPixelBuffer; ivalues[idx] = 1; idx++;
+ }
+ if (floatingPoint) {
+ iattribs[idx] = CGL.kCGLPFAColorFloat; ivalues[idx] = 1; idx++;
+ }
+ iattribs[idx] = CGL.NSOpenGLPFADoubleBuffer; ivalues[idx] = (capabilities.getDoubleBuffered() ? 1 : 0); idx++;
+ iattribs[idx] = CGL.NSOpenGLPFAStereo; ivalues[idx] = (capabilities.getStereo() ? 1 : 0); idx++;
+ iattribs[idx] = CGL.NSOpenGLPFAColorSize; ivalues[idx] = (capabilities.getRedBits() +
+ capabilities.getGreenBits() +
+ capabilities.getBlueBits()); idx++;
+ iattribs[idx] = CGL.NSOpenGLPFAAlphaSize; ivalues[idx] = capabilities.getAlphaBits(); idx++;
+ iattribs[idx] = CGL.NSOpenGLPFADepthSize; ivalues[idx] = capabilities.getDepthBits(); idx++;
+ iattribs[idx] = CGL.NSOpenGLPFAAccumSize; ivalues[idx] = (capabilities.getAccumRedBits() +
+ capabilities.getAccumGreenBits() +
+ capabilities.getAccumBlueBits() +
+ capabilities.getAccumAlphaBits()); idx++;
+ iattribs[idx] = CGL.NSOpenGLPFAStencilSize; ivalues[idx] = capabilities.getStencilBits(); idx++;
+ if (capabilities.getSampleBuffers()) {
+ iattribs[idx] = CGL.NSOpenGLPFASampleBuffers; ivalues[idx] = 1; idx++;
+ iattribs[idx] = CGL.NSOpenGLPFASamples; ivalues[idx] = capabilities.getNumSamples(); idx++;
+ }
+
+ long pixelFormat = CGL.createPixelFormat(iattribs, 0, idx, ivalues, 0);
+ if (pixelFormat == 0) {
+ throw new GLException("Unable to allocate pixel format with requested GLCapabilities");
+ }
+ try {
+ // Try to allocate a context with this
+ nsContext = CGL.createContext(share,
+ drawable.getView(),
+ pixelFormat,
+ viewNotReady, 0);
+ if (nsContext == 0) {
+ if (viewNotReady[0] == 1) {
+ if (DEBUG) {
+ System.err.println("!!! View not ready for " + getClass().getName());
+ }
+ // View not ready at the window system level -- this is OK
+ return false;
+ }
+ throw new GLException("Error creating NSOpenGLContext with requested pixel format");
+ }
+
+ // On this platform the pixel format is associated with the
+ // context and not the drawable. However it's a reasonable
+ // approximation to just store the chosen pixel format up in the
+ // drawable since the public API doesn't provide for a different
+ // GLCapabilities per context.
+ if (drawable.getChosenGLCapabilities() == null) {
+ // Figure out what attributes we really got
+ GLCapabilities caps = new GLCapabilities();
+ CGL.queryPixelFormat(pixelFormat, iattribs, 0, idx, ivalues, 0);
+ for (int i = 0; i < idx; i++) {
+ int attr = iattribs[i];
+ switch (attr) {
+ case CGL.kCGLPFAColorFloat:
+ caps.setPbufferFloatingPointBuffers(ivalues[i] != 0);
+ break;
+
+ case CGL.NSOpenGLPFADoubleBuffer:
+ caps.setDoubleBuffered(ivalues[i] != 0);
+ break;
+
+ case CGL.NSOpenGLPFAStereo:
+ caps.setStereo(ivalues[i] != 0);
+ break;
+
+ case CGL.NSOpenGLPFAColorSize:
+ {
+ int bitSize = ivalues[i];
+ if (bitSize == 32)
+ bitSize = 24;
+ bitSize /= 3;
+ caps.setRedBits(bitSize);
+ caps.setGreenBits(bitSize);
+ caps.setBlueBits(bitSize);
+ }
+ break;
+
+ case CGL.NSOpenGLPFAAlphaSize:
+ caps.setAlphaBits(ivalues[i]);
+ break;
+
+ case CGL.NSOpenGLPFADepthSize:
+ caps.setDepthBits(ivalues[i]);
+ break;
+
+ case CGL.NSOpenGLPFAAccumSize:
+ {
+ int bitSize = ivalues[i] / 4;
+ caps.setAccumRedBits(bitSize);
+ caps.setAccumGreenBits(bitSize);
+ caps.setAccumBlueBits(bitSize);
+ caps.setAccumAlphaBits(bitSize);
+ }
+ break;
+
+ case CGL.NSOpenGLPFAStencilSize:
+ caps.setStencilBits(ivalues[i]);
+ break;
+
+ case CGL.NSOpenGLPFASampleBuffers:
+ caps.setSampleBuffers(ivalues[i] != 0);
+ break;
+
+ case CGL.NSOpenGLPFASamples:
+ caps.setNumSamples(ivalues[i]);
+ break;
+
+ default:
+ break;
+ }
}
- // View not ready at the window system level -- this is OK
- return false;
+
+ drawable.setChosenGLCapabilities(caps);
}
- throw new GLException("Error creating nsContext");
+
+
+ } finally {
+ CGL.deletePixelFormat(pixelFormat);
}
GLContextShareSet.contextCreated(this);
return true;
diff --git a/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLDrawable.java b/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLDrawable.java
index 2cb501020..7a42ad37c 100644
--- a/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLDrawable.java
+++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLDrawable.java
@@ -102,6 +102,9 @@ public class MacOSXOnscreenGLDrawable extends MacOSXGLDrawable {
public void setRealized(boolean realized) {
this.realized = realized;
+ // Might as well clear out the "chosen" pixel format, though it's
+ // associated with the GLContext on this platform and not the drawable
+ setChosenGLCapabilities(null);
}
public void setSize(int width, int height) {