Search
lxdream.org :: lxdream/src/drivers/video_nsgl.m
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_nsgl.m
changeset 1258:f8a9c0fd2abb
prev1256:a9d29fe74bf3
author nkeynes
date Mon Mar 05 11:41:03 2012 +1000 (12 years ago)
permissions -rw-r--r--
last change Small cleanups:
Refactor the post-windowing setup into gl_init_driver() in video_gl.c
Move gl_sl.c into src/drivers and tidy up a bit.
Fix OS X compiling plugins with -mdynamic-no-pic
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * Cocoa (NSOpenGL) video driver
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     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.
    12  *
    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.
    17  */
    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 )
    28 {
    29     NSAutoreleasePool *pool = [NSAutoreleasePool new];
    30     NSOpenGLPixelFormatAttribute attributes[] = {
    31             NSOpenGLPFAWindow,
    32             // NSOpenGLPFADoubleBuffer,
    33             NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
    34             (NSOpenGLPixelFormatAttribute)nil };
    36     NSOpenGLPixelFormat *pixelFormat = 
    37         [[[NSOpenGLPixelFormat alloc] initWithAttributes: attributes] autorelease];
    38     nsgl_context = 
    39         [[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: nil];
    40     [nsgl_context setView: view];
    41     [nsgl_context makeCurrentContext];
    42     [pool release];
    43     driver->swap_buffers = video_nsgl_swap_buffers;
    44     driver->capabilities.has_gl = TRUE;
    45     driver->capabilities.depth_bits = 24;
    46     gl_init_driver(driver, TRUE);
    47     return TRUE;
    48 }
    50 void video_nsgl_update()
    51 {
    52     if( nsgl_context != nil ) {
    53         [nsgl_context update];
    54     }
    55 }
    57 void video_nsgl_make_current()
    58 {
    59     if( nsgl_context != nil ) {
    60         [nsgl_context makeCurrentContext];
    61     }
    62 }
    64 void video_nsgl_swap_buffers()
    65 {
    66     if( nsgl_context != nil ) {
    67         [nsgl_context flushBuffer];
    68     }
    69 }
    71 void video_nsgl_shutdown()
    72 {
    73     if( nsgl_context != nil ) {
    74         [NSOpenGLContext clearCurrentContext];
    75         [nsgl_context release];
    76         nsgl_context = nil;
    77     }
    78 }
.