aboutsummaryrefslogtreecommitdiffstats
path: root/src/native
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/native
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/native')
-rw-r--r--src/native/jogl/MacOSXWindowSystemInterface.m162
1 files changed, 101 insertions, 61 deletions
diff --git a/src/native/jogl/MacOSXWindowSystemInterface.m b/src/native/jogl/MacOSXWindowSystemInterface.m
index e9d90fcdc..5cf975c10 100644
--- a/src/native/jogl/MacOSXWindowSystemInterface.m
+++ b/src/native/jogl/MacOSXWindowSystemInterface.m
@@ -379,33 +379,110 @@ long validateParameter(NSOpenGLPixelFormatAttribute atttribute, long value)
return value;
}
-void* createContext(void* shareContext, void* view,
- int doubleBuffer,
- int stereo,
- int redBits,
- int greenBits,
- int blueBits,
- int alphaBits,
- int depthBits,
- int stencilBits,
- int accumRedBits,
- int accumGreenBits,
- int accumBlueBits,
- int accumAlphaBits,
- int sampleBuffers,
- int numSamples,
- int pbuffer,
- int floatingPoint,
+void* createPixelFormat(int* iattrs, int niattrs, int* ivalues) {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+
+ getRendererInfo();
+
+ // http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSOpenGLPixelFormat.html
+ NSOpenGLPixelFormatAttribute attribs[256];
+
+ int idx = 0;
+ int i;
+ for (i = 0; i < niattrs; i++) {
+ int attr = iattrs[i];
+ switch (attr) {
+ case NSOpenGLPFAPixelBuffer:
+ if (ivalues[i] != 0) {
+ attribs[idx++] = NSOpenGLPFAPixelBuffer;
+ }
+ break;
+
+ case kCGLPFAColorFloat:
+ if (ivalues[i] != 0) {
+ attribs[idx++] = kCGLPFAColorFloat;
+ }
+ break;
+
+ case NSOpenGLPFADoubleBuffer:
+ if (ivalues[i] != 0) {
+ attribs[idx++] = NSOpenGLPFADoubleBuffer;
+ }
+ break;
+
+ case NSOpenGLPFAStereo:
+ if (ivalues[i] != 0) {
+ attribs[idx++] = NSOpenGLPFAStereo;
+ }
+ break;
+
+ case NSOpenGLPFAColorSize:
+ case NSOpenGLPFAAlphaSize:
+ case NSOpenGLPFADepthSize:
+ case NSOpenGLPFAAccumSize:
+ case NSOpenGLPFASampleBuffers:
+ case NSOpenGLPFASamples:
+ attribs[idx++] = attr;
+ attribs[idx++] = ivalues[i];
+ break;
+
+ case NSOpenGLPFAStencilSize:
+ attribs[idx++] = attr;
+ attribs[idx++] = validateParameter(NSOpenGLPFAStencilSize, ivalues[i]);
+ break;
+
+ default:
+ // Need better way to signal to caller
+ return nil;
+ }
+ }
+
+ // Zero-terminate
+ attribs[idx++] = 0;
+
+ NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
+ if (fmt == nil) {
+ // should we fallback to defaults or not?
+ fmt = [NSOpenGLView defaultPixelFormat];
+ }
+
+ [pool release];
+ return fmt;
+}
+
+void queryPixelFormat(void* pixelFormat, int* iattrs, int niattrs, int* ivalues) {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ NSOpenGLPixelFormat* fmt = (NSOpenGLPixelFormat*) pixelFormat;
+ long tmp;
+ // FIXME: think about how specifying this might affect the API
+ int virtualScreen = 0;
+
+ int i;
+ for (i = 0; i < niattrs; i++) {
+ [fmt getValues: &tmp
+ forAttribute: (NSOpenGLPixelFormatAttribute) iattrs[i]
+ forVirtualScreen: virtualScreen];
+ ivalues[i] = (int) tmp;
+ }
+ [pool release];
+}
+
+void deletePixelFormat(void* pixelFormat) {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ NSOpenGLPixelFormat* fmt = (NSOpenGLPixelFormat*) pixelFormat;
+ [fmt release];
+ [pool release];
+}
+
+void* createContext(void* shareContext,
+ void* view,
+ void* pixelFormat,
int* viewNotReady)
{
getRendererInfo();
- int colorSize = alphaBits + redBits + greenBits + blueBits;
- int accumSize = accumAlphaBits + accumRedBits + accumGreenBits + accumBlueBits;
-
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- NSOpenGLContext *nsChareCtx = (NSOpenGLContext*)shareContext;
NSView *nsView = (NSView*)view;
if (nsView != NULL)
@@ -438,47 +515,10 @@ void* createContext(void* shareContext, void* view,
return NULL;
}
}
-
- // http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSOpenGLPixelFormat.html
- NSOpenGLPixelFormatAttribute attribs[256];
- int idx = 0;
- if (pbuffer != 0)
- {
- attribs[idx++] = NSOpenGLPFAPixelBuffer;
- }
- if (floatingPoint != 0)
- {
- attribs[idx++] = kCGLPFAColorFloat /* NSOpenGLPFAColorFloat */;
- }
- if (doubleBuffer != 0)
- {
- attribs[idx++] = NSOpenGLPFADoubleBuffer;
- }
- if (stereo != 0)
- {
- attribs[idx++] = NSOpenGLPFAStereo;
- }
- attribs[idx++] = NSOpenGLPFAColorSize; attribs[idx++] = colorSize;
- attribs[idx++] = NSOpenGLPFAAlphaSize; attribs[idx++] = alphaBits;
- attribs[idx++] = NSOpenGLPFADepthSize; attribs[idx++] = depthBits;
- attribs[idx++] = NSOpenGLPFAStencilSize; attribs[idx++] = validateParameter(NSOpenGLPFAStencilSize, stencilBits);
- attribs[idx++] = NSOpenGLPFAAccumSize; attribs[idx++] = accumSize;
- if (sampleBuffers != 0)
- {
- attribs[idx++] = NSOpenGLPFASampleBuffers; attribs[idx++] = sampleBuffers;
- attribs[idx++] = NSOpenGLPFASamples; attribs[idx++] = numSamples;
- }
- attribs[idx++] = 0;
-
- NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
- if (fmt == nil)
- {
- // should we fallback to defaults or not?
- fmt = [NSOpenGLView defaultPixelFormat];
- }
- NSOpenGLContext* nsContext = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nsChareCtx];
- [fmt release];
+ NSOpenGLContext* nsContext = [[NSOpenGLContext alloc]
+ initWithFormat: (NSOpenGLPixelFormat*) pixelFormat
+ shareContext: (NSOpenGLContext*) shareContext];
if (nsView != nil)
{