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 964:f2f3c7612d06
next1076:18c164e8aec4
author nkeynes
date Thu Jan 15 04:15:11 2009 +0000 (12 years ago)
permissions -rw-r--r--
last change Add support for the Intel ICC compiler (C only, icc doesn't support Obj-C)
- Rename Obj-C source to .m
- Separate paths.c into paths_unix.c and paths_osx.m
- Add configuration detection of ICC, along with specific opt flags
file annotate diff log raw
nkeynes@964
     1
/**
nkeynes@964
     2
 * $Id$
nkeynes@964
     3
 *
nkeynes@964
     4
 * Cocoa (NSOpenGL) video driver
nkeynes@964
     5
 *
nkeynes@964
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@964
     7
 *
nkeynes@964
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@964
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@964
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@964
    11
 * (at your option) any later version.
nkeynes@964
    12
 *
nkeynes@964
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@964
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@964
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@964
    16
 * GNU General Public License for more details.
nkeynes@964
    17
 */
nkeynes@964
    18
nkeynes@964
    19
#include <AppKit/NSOpenGL.h>
nkeynes@964
    20
#include <Foundation/NSAutoreleasePool.h>
nkeynes@964
    21
#include "drivers/video_nsgl.h"
nkeynes@964
    22
#include "drivers/video_gl.h"
nkeynes@964
    23
#include "pvr2/glutil.h"
nkeynes@964
    24
nkeynes@964
    25
static NSOpenGLContext *nsgl_context = nil;
nkeynes@964
    26
nkeynes@964
    27
gboolean video_nsgl_init_driver( NSView *view, display_driver_t driver )
nkeynes@964
    28
{
nkeynes@964
    29
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
nkeynes@964
    30
    NSOpenGLPixelFormatAttribute attributes[] = {
nkeynes@964
    31
            NSOpenGLPFAWindow,
nkeynes@964
    32
            // NSOpenGLPFADoubleBuffer,
nkeynes@964
    33
            NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
nkeynes@964
    34
            (NSOpenGLPixelFormatAttribute)nil };
nkeynes@964
    35
nkeynes@964
    36
    NSOpenGLPixelFormat *pixelFormat = 
nkeynes@964
    37
        [[[NSOpenGLPixelFormat alloc] initWithAttributes: attributes] autorelease];
nkeynes@964
    38
    nsgl_context = 
nkeynes@964
    39
        [[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: nil];
nkeynes@964
    40
    [nsgl_context setView: view];
nkeynes@964
    41
    [nsgl_context makeCurrentContext];
nkeynes@964
    42
    [pool release];
nkeynes@964
    43
    if( gl_fbo_is_supported() ) {
nkeynes@964
    44
        gl_fbo_init(driver);
nkeynes@964
    45
    } else {
nkeynes@964
    46
        ERROR( "FBO not supported" );
nkeynes@964
    47
        return FALSE;
nkeynes@964
    48
    }
nkeynes@964
    49
nkeynes@964
    50
    return TRUE;
nkeynes@964
    51
}
nkeynes@964
    52
nkeynes@964
    53
void video_nsgl_update()
nkeynes@964
    54
{
nkeynes@964
    55
    if( nsgl_context != nil ) {
nkeynes@964
    56
        [nsgl_context update];
nkeynes@964
    57
    }
nkeynes@964
    58
}
nkeynes@964
    59
nkeynes@964
    60
void video_nsgl_make_current()
nkeynes@964
    61
{
nkeynes@964
    62
    if( nsgl_context != nil ) {
nkeynes@964
    63
        [nsgl_context makeCurrentContext];
nkeynes@964
    64
    }
nkeynes@964
    65
}
nkeynes@964
    66
nkeynes@964
    67
void video_nsgl_swap_buffers()
nkeynes@964
    68
{
nkeynes@964
    69
    if( nsgl_context != nil ) {
nkeynes@964
    70
        [nsgl_context flushBuffer];
nkeynes@964
    71
    }
nkeynes@964
    72
}
nkeynes@964
    73
nkeynes@964
    74
void video_nsgl_shutdown()
nkeynes@964
    75
{
nkeynes@964
    76
    if( nsgl_context != nil ) {
nkeynes@964
    77
        [NSOpenGLContext clearCurrentContext];
nkeynes@964
    78
        [nsgl_context release];
nkeynes@964
    79
        nsgl_context = nil;
nkeynes@964
    80
    }
nkeynes@964
    81
}
.