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 1251:b8ab59d39756
prev1159:580436b01b6c
next1256:a9d29fe74bf3
author nkeynes
date Sat Mar 03 16:11:28 2012 +1000 (9 years ago)
permissions -rw-r--r--
last change Support depth component 16 as well as 24 (add capability flag for the available bits)
Put remaining TODOs inside HAVE_OPENGL_FIXEDFUNC blocks
Add swap-buffer calls for EGL (does not appear to support rendering directly
to front-buffer)
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     if( gl_fbo_is_supported() ) {
    47         gl_fbo_init(driver);
    48     } else {
    49         /* Note there is a 'native' buffer framework, but since all current
    50          * Apple drivers appear to support FBO, there's not much point in
    51          * doing the work to support them.
    52          */
    53         ERROR( "FBO not supported" );
    54         return FALSE;
    55     }
    56     gl_vbo_init(driver);
    58     return TRUE;
    59 }
    61 void video_nsgl_update()
    62 {
    63     if( nsgl_context != nil ) {
    64         [nsgl_context update];
    65     }
    66 }
    68 void video_nsgl_make_current()
    69 {
    70     if( nsgl_context != nil ) {
    71         [nsgl_context makeCurrentContext];
    72     }
    73 }
    75 void video_nsgl_swap_buffers()
    76 {
    77     if( nsgl_context != nil ) {
    78         [nsgl_context flushBuffer];
    79     }
    80 }
    82 void video_nsgl_shutdown()
    83 {
    84     if( nsgl_context != nil ) {
    85         [NSOpenGLContext clearCurrentContext];
    86         [nsgl_context release];
    87         nsgl_context = nil;
    88     }
    89 }
.