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 757:2780bc393e7c
prev736:a02d1475ccfd
author nkeynes
date Mon Jul 21 00:16:09 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Minor fixes for Tiger build
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@757
    20
#include <Foundation/NSAutoreleasePool.h>
nkeynes@663
    21
#include "drivers/video_nsgl.h"
nkeynes@663
    22
#include "drivers/video_gl.h"
nkeynes@663
    23
#include "pvr2/glutil.h"
nkeynes@663
    24
nkeynes@681
    25
static NSOpenGLContext *nsgl_context = nil;
nkeynes@663
    26
nkeynes@663
    27
gboolean video_nsgl_init_driver( NSView *view, display_driver_t driver )
nkeynes@663
    28
{
nkeynes@681
    29
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
nkeynes@736
    30
    NSOpenGLPixelFormatAttribute attributes[] = {
nkeynes@736
    31
            NSOpenGLPFAWindow,
nkeynes@736
    32
            // NSOpenGLPFADoubleBuffer,
nkeynes@736
    33
            NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
nkeynes@736
    34
            (NSOpenGLPixelFormatAttribute)nil };
nkeynes@665
    35
nkeynes@736
    36
    NSOpenGLPixelFormat *pixelFormat = 
nkeynes@736
    37
        [[[NSOpenGLPixelFormat alloc] initWithAttributes: attributes] autorelease];
nkeynes@736
    38
    nsgl_context = 
nkeynes@736
    39
        [[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: nil];
nkeynes@736
    40
    [nsgl_context setView: view];
nkeynes@736
    41
    [nsgl_context makeCurrentContext];
nkeynes@736
    42
    [pool release];
nkeynes@736
    43
    if( gl_fbo_is_supported() ) {
nkeynes@736
    44
        gl_fbo_init(driver);
nkeynes@736
    45
    } else {
nkeynes@736
    46
        ERROR( "FBO not supported" );
nkeynes@736
    47
        return FALSE;
nkeynes@736
    48
    }
nkeynes@736
    49
nkeynes@736
    50
    return TRUE;
nkeynes@663
    51
}
nkeynes@663
    52
nkeynes@681
    53
void video_nsgl_update()
nkeynes@681
    54
{
nkeynes@681
    55
    if( nsgl_context != nil ) {
nkeynes@681
    56
        [nsgl_context update];
nkeynes@681
    57
    }
nkeynes@681
    58
}
nkeynes@681
    59
nkeynes@681
    60
void video_nsgl_make_current()
nkeynes@681
    61
{
nkeynes@681
    62
    if( nsgl_context != nil ) {
nkeynes@681
    63
        [nsgl_context makeCurrentContext];
nkeynes@681
    64
    }
nkeynes@681
    65
}
nkeynes@681
    66
nkeynes@681
    67
void video_nsgl_swap_buffers()
nkeynes@681
    68
{
nkeynes@681
    69
    if( nsgl_context != nil ) {
nkeynes@681
    70
        [nsgl_context flushBuffer];
nkeynes@681
    71
    }
nkeynes@681
    72
}
nkeynes@681
    73
nkeynes@663
    74
void video_nsgl_shutdown()
nkeynes@663
    75
{
nkeynes@736
    76
    if( nsgl_context != nil ) {
nkeynes@736
    77
        [NSOpenGLContext clearCurrentContext];
nkeynes@736
    78
        [nsgl_context release];
nkeynes@736
    79
        nsgl_context = nil;
nkeynes@736
    80
    }
nkeynes@663
    81
}
.