4 * Cocoa (NSOpenGL) video driver
6 * Copyright (c) 2005 Nathan Keynes.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #include <AppKit/NSOpenGL.h>
20 #include <Foundation/NSAutoreleasePool.h>
21 #include "drivers/video_nsgl.h"
22 #include "drivers/video_gl.h"
23 #include "pvr2/glutil.h"
25 static NSOpenGLContext *nsgl_context = nil;
27 gboolean video_nsgl_init_driver( NSView *view, display_driver_t driver )
29 NSAutoreleasePool *pool = [NSAutoreleasePool new];
30 NSOpenGLPixelFormatAttribute attributes[] = {
32 // NSOpenGLPFADoubleBuffer,
33 NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
34 (NSOpenGLPixelFormatAttribute)nil };
36 NSOpenGLPixelFormat *pixelFormat =
37 [[[NSOpenGLPixelFormat alloc] initWithAttributes: attributes] autorelease];
39 [[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: nil];
40 [nsgl_context setView: view];
41 [nsgl_context makeCurrentContext];
43 driver->swap_buffers = video_nsgl_swap_buffers;
44 driver->capabilities.has_gl = TRUE;
45 if( gl_fbo_is_supported() ) {
48 /* Note there is a 'native' buffer framework, but since all current
49 * Apple drivers appear to support FBO, there's not much point in
50 * doing the work to support them.
52 ERROR( "FBO not supported" );
60 void video_nsgl_update()
62 if( nsgl_context != nil ) {
63 [nsgl_context update];
67 void video_nsgl_make_current()
69 if( nsgl_context != nil ) {
70 [nsgl_context makeCurrentContext];
74 void video_nsgl_swap_buffers()
76 if( nsgl_context != nil ) {
77 [nsgl_context flushBuffer];
81 void video_nsgl_shutdown()
83 if( nsgl_context != nil ) {
84 [NSOpenGLContext clearCurrentContext];
85 [nsgl_context release];
.