2008-10-25 17:47:46 +00:00
|
|
|
#import "cocoaGL.h"
|
|
|
|
|
|
|
|
NSWindow *cocoaGLCreateWindow(int w,int h)
|
|
|
|
{
|
|
|
|
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
NSWindow *window;
|
|
|
|
window = [[NSWindow alloc] initWithContentRect:NSMakeRect(50,50,w,h)
|
|
|
|
styleMask:NSTitledWindowMask | NSResizableWindowMask
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:FALSE];
|
|
|
|
|
|
|
|
[window setTitle:@"Dolphin on OSX"];
|
2009-04-24 01:30:45 +00:00
|
|
|
//[window makeKeyAndOrderFront: nil];
|
2008-10-25 17:47:46 +00:00
|
|
|
|
|
|
|
[pool release];
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2008-12-18 21:40:50 +00:00
|
|
|
void cocoaGLSetTitle(NSWindow *win, const char *title)
|
2008-10-25 17:47:46 +00:00
|
|
|
{
|
2008-12-18 21:40:50 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
|
|
|
[win setTitle: [[[NSString alloc] initWithCString: title encoding: NSASCIIStringEncoding] autorelease]];
|
2008-10-25 17:47:46 +00:00
|
|
|
|
2008-12-18 21:40:50 +00:00
|
|
|
[pool release];
|
2008-10-25 17:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cocoaGLMakeCurrent(NSOpenGLContext *ctx, NSWindow *win)
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool;
|
|
|
|
|
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
|
|
|
int value = 0;
|
|
|
|
[ctx setValues:&value forParameter:NSOpenGLCPSwapInterval];
|
|
|
|
|
|
|
|
if (ctx) {
|
|
|
|
|
|
|
|
[ctx setView:[win contentView]];
|
|
|
|
[ctx update];
|
|
|
|
[ctx makeCurrentContext];
|
|
|
|
} else {
|
|
|
|
[NSOpenGLContext clearCurrentContext];
|
|
|
|
}
|
|
|
|
|
|
|
|
[pool release];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NSOpenGLContext* cocoaGLInit(int mode)
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool;
|
|
|
|
NSOpenGLPixelFormatAttribute attr[32];
|
|
|
|
NSOpenGLPixelFormat *fmt;
|
|
|
|
NSOpenGLContext *context;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
|
|
|
attr[i++] = NSOpenGLPFADepthSize;
|
|
|
|
attr[i++] = 24;
|
|
|
|
attr[i++] = NSOpenGLPFADoubleBuffer;
|
|
|
|
|
|
|
|
attr[i++] = NSOpenGLPFASampleBuffers;
|
|
|
|
attr[i++] = mode;
|
|
|
|
attr[i++] = NSOpenGLPFASamples;
|
|
|
|
attr[i++] = 1;
|
2009-04-24 01:30:45 +00:00
|
|
|
#ifdef GL_VERSION_1_3
|
|
|
|
|
|
|
|
#else
|
2009-03-09 10:43:56 +00:00
|
|
|
#ifdef GL_VERSION_1_2
|
2009-04-24 01:30:45 +00:00
|
|
|
#warning "your card only supports ogl 1.2, dolphin will use software renderer"
|
2008-10-25 17:47:46 +00:00
|
|
|
//if opengl < 1.3 uncomment this twoo lines to use software renderer
|
2009-04-24 01:30:45 +00:00
|
|
|
attr[i++] = NSOpenGLPFARendererID;
|
|
|
|
attr[i++] = kCGLRendererGenericFloatID;
|
|
|
|
#endif
|
2009-03-09 10:43:56 +00:00
|
|
|
#endif
|
2008-10-25 17:47:46 +00:00
|
|
|
attr[i++] = NSOpenGLPFAScreenMask;
|
|
|
|
attr[i++] = CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID());
|
|
|
|
|
|
|
|
attr[i] = 0;
|
|
|
|
|
|
|
|
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
|
|
|
|
if (fmt == nil) {
|
|
|
|
printf("failed to create pixel format\n");
|
|
|
|
[pool release];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
|
|
|
|
|
|
|
|
[fmt release];
|
|
|
|
|
|
|
|
if (context == nil) {
|
|
|
|
printf("failed to create context\n");
|
|
|
|
[pool release];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
[pool release];
|
|
|
|
|
|
|
|
return context;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void cocoaGLDelete(NSOpenGLContext *ctx)
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool;
|
|
|
|
|
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
|
|
|
[ctx clearDrawable];
|
|
|
|
[ctx release];
|
|
|
|
|
|
|
|
[pool release];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void cocoaGLSwap(NSOpenGLContext *ctx,NSWindow *window)
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool;
|
|
|
|
|
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
[window makeKeyAndOrderFront: nil];
|
|
|
|
|
|
|
|
ctx = [NSOpenGLContext currentContext];
|
|
|
|
if (ctx != nil) {
|
|
|
|
[ctx flushBuffer];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("bad cocoa gl ctx\n");
|
|
|
|
}
|
|
|
|
[pool release];
|
|
|
|
|
|
|
|
}
|