Search
lxdream.org :: lxdream/src/drivers/video_nsgl.m :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_nsgl.m
changeset 964:f2f3c7612d06
next1076:18c164e8aec4
author nkeynes
date Sat Jun 13 00:50:48 2009 +0000 (14 years ago)
permissions -rw-r--r--
last change Build drivers with library dependencies as shared objects (ie plugins)
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/drivers/video_nsgl.m Sat Jun 13 00:50:48 2009 +0000
1.3 @@ -0,0 +1,81 @@
1.4 +/**
1.5 + * $Id$
1.6 + *
1.7 + * Cocoa (NSOpenGL) video driver
1.8 + *
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + */
1.21 +
1.22 +#include <AppKit/NSOpenGL.h>
1.23 +#include <Foundation/NSAutoreleasePool.h>
1.24 +#include "drivers/video_nsgl.h"
1.25 +#include "drivers/video_gl.h"
1.26 +#include "pvr2/glutil.h"
1.27 +
1.28 +static NSOpenGLContext *nsgl_context = nil;
1.29 +
1.30 +gboolean video_nsgl_init_driver( NSView *view, display_driver_t driver )
1.31 +{
1.32 + NSAutoreleasePool *pool = [NSAutoreleasePool new];
1.33 + NSOpenGLPixelFormatAttribute attributes[] = {
1.34 + NSOpenGLPFAWindow,
1.35 + // NSOpenGLPFADoubleBuffer,
1.36 + NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
1.37 + (NSOpenGLPixelFormatAttribute)nil };
1.38 +
1.39 + NSOpenGLPixelFormat *pixelFormat =
1.40 + [[[NSOpenGLPixelFormat alloc] initWithAttributes: attributes] autorelease];
1.41 + nsgl_context =
1.42 + [[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: nil];
1.43 + [nsgl_context setView: view];
1.44 + [nsgl_context makeCurrentContext];
1.45 + [pool release];
1.46 + if( gl_fbo_is_supported() ) {
1.47 + gl_fbo_init(driver);
1.48 + } else {
1.49 + ERROR( "FBO not supported" );
1.50 + return FALSE;
1.51 + }
1.52 +
1.53 + return TRUE;
1.54 +}
1.55 +
1.56 +void video_nsgl_update()
1.57 +{
1.58 + if( nsgl_context != nil ) {
1.59 + [nsgl_context update];
1.60 + }
1.61 +}
1.62 +
1.63 +void video_nsgl_make_current()
1.64 +{
1.65 + if( nsgl_context != nil ) {
1.66 + [nsgl_context makeCurrentContext];
1.67 + }
1.68 +}
1.69 +
1.70 +void video_nsgl_swap_buffers()
1.71 +{
1.72 + if( nsgl_context != nil ) {
1.73 + [nsgl_context flushBuffer];
1.74 + }
1.75 +}
1.76 +
1.77 +void video_nsgl_shutdown()
1.78 +{
1.79 + if( nsgl_context != nil ) {
1.80 + [NSOpenGLContext clearCurrentContext];
1.81 + [nsgl_context release];
1.82 + nsgl_context = nil;
1.83 + }
1.84 +}
.