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)
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@964
    46
    if( gl_fbo_is_supported() ) {
nkeynes@964
    47
        gl_fbo_init(driver);
nkeynes@964
    48
    } else {
nkeynes@1076
    49
        /* Note there is a 'native' buffer framework, but since all current
nkeynes@1076
    50
         * Apple drivers appear to support FBO, there's not much point in
nkeynes@1076
    51
         * doing the work to support them.
nkeynes@1076
    52
         */
nkeynes@964
    53
        ERROR( "FBO not supported" );
nkeynes@964
    54
        return FALSE;
nkeynes@964
    55
    }
nkeynes@1159
    56
    gl_vbo_init(driver);
nkeynes@964
    57
nkeynes@964
    58
    return TRUE;
nkeynes@964
    59
}
nkeynes@964
    60
nkeynes@964
    61
void video_nsgl_update()
nkeynes@964
    62
{
nkeynes@964
    63
    if( nsgl_context != nil ) {
nkeynes@964
    64
        [nsgl_context update];
nkeynes@964
    65
    }
nkeynes@964
    66
}
nkeynes@964
    67
nkeynes@964
    68
void video_nsgl_make_current()
nkeynes@964
    69
{
nkeynes@964
    70
    if( nsgl_context != nil ) {
nkeynes@964
    71
        [nsgl_context makeCurrentContext];
nkeynes@964
    72
    }
nkeynes@964
    73
}
nkeynes@964
    74
nkeynes@964
    75
void video_nsgl_swap_buffers()
nkeynes@964
    76
{
nkeynes@964
    77
    if( nsgl_context != nil ) {
nkeynes@964
    78
        [nsgl_context flushBuffer];
nkeynes@964
    79
    }
nkeynes@964
    80
}
nkeynes@964
    81
nkeynes@964
    82
void video_nsgl_shutdown()
nkeynes@964
    83
{
nkeynes@964
    84
    if( nsgl_context != nil ) {
nkeynes@964
    85
        [NSOpenGLContext clearCurrentContext];
nkeynes@964
    86
        [nsgl_context release];
nkeynes@964
    87
        nsgl_context = nil;
nkeynes@964
    88
    }
nkeynes@964
    89
}
.