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