Search
lxdream.org :: lxdream/src/drivers/video_nsgl.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_nsgl.c
changeset 736:a02d1475ccfd
prev681:1755a126b109
next757:2780bc393e7c
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
nkeynes@663
     1
/**
nkeynes@663
     2
 * $Id$
nkeynes@663
     3
 *
nkeynes@663
     4
 * Cocoa (NSOpenGL) video driver
nkeynes@663
     5
 *
nkeynes@663
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@663
     7
 *
nkeynes@663
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@663
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@663
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@663
    11
 * (at your option) any later version.
nkeynes@663
    12
 *
nkeynes@663
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@663
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@663
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@663
    16
 * GNU General Public License for more details.
nkeynes@663
    17
 */
nkeynes@663
    18
nkeynes@663
    19
#include <AppKit/NSOpenGL.h>
nkeynes@663
    20
#include "drivers/video_nsgl.h"
nkeynes@663
    21
#include "drivers/video_gl.h"
nkeynes@663
    22
#include "pvr2/glutil.h"
nkeynes@663
    23
nkeynes@681
    24
static NSOpenGLContext *nsgl_context = nil;
nkeynes@663
    25
nkeynes@663
    26
gboolean video_nsgl_init_driver( NSView *view, display_driver_t driver )
nkeynes@663
    27
{
nkeynes@681
    28
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
nkeynes@736
    29
    NSOpenGLPixelFormatAttribute attributes[] = {
nkeynes@736
    30
            NSOpenGLPFAWindow,
nkeynes@736
    31
            // NSOpenGLPFADoubleBuffer,
nkeynes@736
    32
            NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
nkeynes@736
    33
            (NSOpenGLPixelFormatAttribute)nil };
nkeynes@665
    34
nkeynes@736
    35
    NSOpenGLPixelFormat *pixelFormat = 
nkeynes@736
    36
        [[[NSOpenGLPixelFormat alloc] initWithAttributes: attributes] autorelease];
nkeynes@736
    37
    nsgl_context = 
nkeynes@736
    38
        [[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: nil];
nkeynes@736
    39
    [nsgl_context setView: view];
nkeynes@736
    40
    [nsgl_context makeCurrentContext];
nkeynes@736
    41
    [pool release];
nkeynes@736
    42
    if( gl_fbo_is_supported() ) {
nkeynes@736
    43
        gl_fbo_init(driver);
nkeynes@736
    44
    } else {
nkeynes@736
    45
        ERROR( "FBO not supported" );
nkeynes@736
    46
        return FALSE;
nkeynes@736
    47
    }
nkeynes@736
    48
nkeynes@736
    49
    return TRUE;
nkeynes@663
    50
}
nkeynes@663
    51
nkeynes@681
    52
void video_nsgl_update()
nkeynes@681
    53
{
nkeynes@681
    54
    if( nsgl_context != nil ) {
nkeynes@681
    55
        [nsgl_context update];
nkeynes@681
    56
    }
nkeynes@681
    57
}
nkeynes@681
    58
nkeynes@681
    59
void video_nsgl_make_current()
nkeynes@681
    60
{
nkeynes@681
    61
    if( nsgl_context != nil ) {
nkeynes@681
    62
        [nsgl_context makeCurrentContext];
nkeynes@681
    63
    }
nkeynes@681
    64
}
nkeynes@681
    65
nkeynes@681
    66
void video_nsgl_swap_buffers()
nkeynes@681
    67
{
nkeynes@681
    68
    if( nsgl_context != nil ) {
nkeynes@681
    69
        [nsgl_context flushBuffer];
nkeynes@681
    70
    }
nkeynes@681
    71
}
nkeynes@681
    72
nkeynes@663
    73
void video_nsgl_shutdown()
nkeynes@663
    74
{
nkeynes@736
    75
    if( nsgl_context != nil ) {
nkeynes@736
    76
        [NSOpenGLContext clearCurrentContext];
nkeynes@736
    77
        [nsgl_context release];
nkeynes@736
    78
        nsgl_context = nil;
nkeynes@736
    79
    }
nkeynes@663
    80
}
.