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 (8 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
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@1076
    43
    driver->swap_buffers = video_nsgl_swap_buffers;
nkeynes@1134
    44
    driver->capabilities.has_gl = TRUE;
nkeynes@1251
    45
    driver->capabilities.depth_bits = 24;
nkeynes@1258
    46
    gl_init_driver(driver, TRUE);
nkeynes@964
    47
    return TRUE;
nkeynes@964
    48
}
nkeynes@964
    49
nkeynes@964
    50
void video_nsgl_update()
nkeynes@964
    51
{
nkeynes@964
    52
    if( nsgl_context != nil ) {
nkeynes@964
    53
        [nsgl_context update];
nkeynes@964
    54
    }
nkeynes@964
    55
}
nkeynes@964
    56
nkeynes@964
    57
void video_nsgl_make_current()
nkeynes@964
    58
{
nkeynes@964
    59
    if( nsgl_context != nil ) {
nkeynes@964
    60
        [nsgl_context makeCurrentContext];
nkeynes@964
    61
    }
nkeynes@964
    62
}
nkeynes@964
    63
nkeynes@964
    64
void video_nsgl_swap_buffers()
nkeynes@964
    65
{
nkeynes@964
    66
    if( nsgl_context != nil ) {
nkeynes@964
    67
        [nsgl_context flushBuffer];
nkeynes@964
    68
    }
nkeynes@964
    69
}
nkeynes@964
    70
nkeynes@964
    71
void video_nsgl_shutdown()
nkeynes@964
    72
{
nkeynes@964
    73
    if( nsgl_context != nil ) {
nkeynes@964
    74
        [NSOpenGLContext clearCurrentContext];
nkeynes@964
    75
        [nsgl_context release];
nkeynes@964
    76
        nsgl_context = nil;
nkeynes@964
    77
    }
nkeynes@964
    78
}
.