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 681:1755a126b109
prev665:99ae9dc4cab7
next736:a02d1475ccfd
author nkeynes
date Sun Jun 01 00:47:45 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change First cut of the Cocoa GUI implementation
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@663
    29
	NSOpenGLPixelFormatAttribute attributes[] = {
nkeynes@663
    30
			NSOpenGLPFAWindow,
nkeynes@681
    31
//			NSOpenGLPFADoubleBuffer,
nkeynes@663
    32
			NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
nkeynes@663
    33
			(NSOpenGLPixelFormatAttribute)nil };
nkeynes@663
    34
	
nkeynes@663
    35
	NSOpenGLPixelFormat *pixelFormat = 
nkeynes@663
    36
		[[[NSOpenGLPixelFormat alloc] initWithAttributes: attributes] autorelease];
nkeynes@663
    37
	nsgl_context = 
nkeynes@663
    38
		[[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: nil];
nkeynes@663
    39
	[nsgl_context setView: view];
nkeynes@663
    40
	[nsgl_context makeCurrentContext];
nkeynes@681
    41
	[pool release];
nkeynes@663
    42
	if( gl_fbo_is_supported() ) {
nkeynes@663
    43
		gl_fbo_init(driver);
nkeynes@663
    44
	} else {
nkeynes@663
    45
		ERROR( "FBO not supported" );
nkeynes@663
    46
		return FALSE;
nkeynes@663
    47
	}
nkeynes@665
    48
nkeynes@663
    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@663
    75
	if( nsgl_context != nil ) {
nkeynes@663
    76
		[NSOpenGLContext clearCurrentContext];
nkeynes@663
    77
		[nsgl_context release];
nkeynes@663
    78
		nsgl_context = nil;
nkeynes@663
    79
	}
nkeynes@663
    80
}
.