aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/com/sun/opengl/impl/macosx/MacOSXGLContext.java
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2006-11-19 20:51:57 +0000
committerKenneth Russel <[email protected]>2006-11-19 20:51:57 +0000
commita303cd13ff62f94a0459978735620e37d72bbb77 (patch)
tree32b580af4e878d479890c12b8eae9c98e10a4874 /src/classes/com/sun/opengl/impl/macosx/MacOSXGLContext.java
parentbf82eceb6f78d5ee6e4c0f9f02590d2a58e647d3 (diff)
Fixed Issue 213: Expose GLCaps from GLDrawable
Added getChosenGLCapabilities() to the GLDrawable interface. Implemented on Windows, Unix and Mac OS X platforms with various techniques. Attempts to provide correct answers in all cases, even when the GLCapabilitiesChooser mechanism is not supported. Required addition of new platform-specific Java code in most cases to either re-convert existing PIXELFORMATDESCRIPTORS / XVisualInfos, or to query the pixel format or visual chosen for drawables like pbuffers for which the chooser mechanism is not (yet) implemented. Tested on Windows, Solaris/x86, and Mac OS X with on-screen, off-screen and pbuffer drawables. (Full support for the Java2D/JOGL bridge is not yet in place; the answer returned from the GLJPanel in this case is currently the default GLCapabilities, and it is likely that "external" GLDrawables will return null.) git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@989 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl/impl/macosx/MacOSXGLContext.java')
-rw-r--r--src/classes/com/sun/opengl/impl/macosx/MacOSXGLContext.java148
1 files changed, 122 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;