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 663:553bb7d6befa
next665:99ae9dc4cab7
author nkeynes
date Thu Apr 17 08:15:19 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Commit NSGL work-in-progress
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@663
    24
static NSOpenGLContext *nsgl_context;
nkeynes@663
    25
nkeynes@663
    26
gboolean video_nsgl_init_driver( NSView *view, display_driver_t driver )
nkeynes@663
    27
{
nkeynes@663
    28
	NSOpenGLPixelFormatAttribute attributes[] = {
nkeynes@663
    29
			NSOpenGLPFAWindow,
nkeynes@663
    30
			NSOpenGLPFADoubleBuffer,
nkeynes@663
    31
			NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
nkeynes@663
    32
			(NSOpenGLPixelFormatAttribute)nil };
nkeynes@663
    33
	
nkeynes@663
    34
	NSOpenGLPixelFormat *pixelFormat = 
nkeynes@663
    35
		[[[NSOpenGLPixelFormat alloc] initWithAttributes: attributes] autorelease];
nkeynes@663
    36
	nsgl_context = 
nkeynes@663
    37
		[[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: nil];
nkeynes@663
    38
	[nsgl_context setView: view];
nkeynes@663
    39
	[nsgl_context makeCurrentContext];
nkeynes@663
    40
	
nkeynes@663
    41
	if( gl_fbo_is_supported() ) {
nkeynes@663
    42
		gl_fbo_init(driver);
nkeynes@663
    43
	} else {
nkeynes@663
    44
		ERROR( "FBO not supported" );
nkeynes@663
    45
		return FALSE;
nkeynes@663
    46
	}
nkeynes@663
    47
	
nkeynes@663
    48
    if( glsl_is_supported() ) {
nkeynes@663
    49
    	if( !glsl_load_shaders( glsl_vertex_shader_src, NULL ) ) {
nkeynes@663
    50
            WARN( "Unable to load GL shaders" );
nkeynes@663
    51
        }
nkeynes@663
    52
    }
nkeynes@663
    53
	return TRUE;
nkeynes@663
    54
}
nkeynes@663
    55
nkeynes@663
    56
void video_nsgl_shutdown()
nkeynes@663
    57
{
nkeynes@663
    58
	if( nsgl_context != nil ) {
nkeynes@663
    59
		[NSOpenGLContext clearCurrentContext];
nkeynes@663
    60
		[nsgl_context release];
nkeynes@663
    61
		nsgl_context = nil;
nkeynes@663
    62
	}
nkeynes@663
    63
}
.