Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Implemented OpenGL support on Mac OS X

The OpenGL renderer works without changes, yay! :)
  • Loading branch information
slouken committed Jul 25, 2006
1 parent a570316 commit dafecf2a1b64ef5ab9f983cc217e03c8fa40d3f2
@@ -171,7 +171,6 @@ extern DECLSPEC void SDLCALL SDL_UnlockYUVOverlay(SDL_Overlay * overlay);
extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay * overlay,
SDL_Rect * dstrect);
extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay * overlay);
extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value);
extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void);

/* Ends C function definitions when using C++ */
@@ -1444,6 +1444,10 @@ extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
*
* \return 0 on success, or -1 if the library couldn't be loaded
*
* This should be done after initializing the video driver, but before
* creating any OpenGL windows. If no OpenGL library is loaded, the default
* library will be loaded upon creation of the first OpenGL window.
*
* \note If you do this, you need to retrieve all of the GL functions used in
* your program from the dynamic library using SDL_GL_GetProcAddress().
*
@@ -1476,11 +1480,9 @@ extern DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value);
/**
* \fn int SDL_GL_GetWindowAttribute(SDL_WindowID windowID, SDL_GLattr attr, int *value)
*
* \brief Get the actual value for an OpenGL window attribute.
* \brief Get the actual value for an attribute from the current context.
*/
extern DECLSPEC int SDLCALL SDL_GL_GetWindowAttribute(SDL_WindowID windowID,
SDL_GLattr attr,
int *value);
extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value);

/**
* \fn SDL_GLContext SDL_GL_CreateContext(SDL_WindowID windowID)
@@ -1432,12 +1432,6 @@ SDL_FreeYUVOverlay(SDL_Overlay * overlay)
}
}

int
SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
{
return SDL_GL_GetWindowAttribute(SDL_VideoWindow, attr, value);
}

void
SDL_GL_SwapBuffers(void)
{
@@ -232,8 +232,6 @@ struct SDL_VideoDevice
*/
int (*GL_LoadLibrary) (_THIS, const char *path);
void *(*GL_GetProcAddress) (_THIS, const char *proc);
int (*GL_GetWindowAttribute) (_THIS, SDL_Window * window,
SDL_GLattr attrib, int *value);
SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
int (*GL_SetSwapInterval) (_THIS, int interval);
@@ -2131,6 +2131,7 @@ SDL_GL_ExtensionSupported(const char *extension)
int
SDL_GL_SetAttribute(SDL_GLattr attr, int value)
{
#if SDL_VIDEO_OPENGL
int retval;

if (!_this) {
@@ -2194,26 +2195,101 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value)
break;
}
return retval;
#else
SDL_Unsupported();
return -1;
#endif /* SDL_VIDEO_OPENGL */
}

int
SDL_GL_GetWindowAttribute(SDL_WindowID windowID, SDL_GLattr attr, int *value)
SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
{
SDL_Window *window = SDL_GetWindowFromID(windowID);
int retval;
#if SDL_VIDEO_OPENGL
void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
GLenum attrib = 0;

if (!window) {
glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
if (!glGetIntegervFunc) {
return -1;
}

if (_this->GL_GetWindowAttribute) {
retval = _this->GL_GetWindowAttribute(_this, window, attr, value);
} else {
*value = 0;
SDL_SetError("GL_GetWindowAttribute not supported");
retval = -1;
switch (attr) {
case SDL_GL_RED_SIZE:
attrib = GL_RED_BITS;
break;
case SDL_GL_BLUE_SIZE:
attrib = GL_BLUE_BITS;
break;
case SDL_GL_GREEN_SIZE:
attrib = GL_GREEN_BITS;
break;
case SDL_GL_ALPHA_SIZE:
attrib = GL_ALPHA_BITS;
break;
case SDL_GL_DOUBLEBUFFER:
attrib = GL_DOUBLEBUFFER;
break;
case SDL_GL_DEPTH_SIZE:
attrib = GL_DEPTH_BITS;
break;
case SDL_GL_STENCIL_SIZE:
attrib = GL_STENCIL_BITS;
break;
case SDL_GL_ACCUM_RED_SIZE:
attrib = GL_ACCUM_RED_BITS;
break;
case SDL_GL_ACCUM_GREEN_SIZE:
attrib = GL_ACCUM_GREEN_BITS;
break;
case SDL_GL_ACCUM_BLUE_SIZE:
attrib = GL_ACCUM_BLUE_BITS;
break;
case SDL_GL_ACCUM_ALPHA_SIZE:
attrib = GL_ACCUM_ALPHA_BITS;
break;
case SDL_GL_STEREO:
attrib = GL_STEREO;
break;
case SDL_GL_MULTISAMPLEBUFFERS:
attrib = GL_SAMPLE_BUFFERS_ARB;
break;
case SDL_GL_MULTISAMPLESAMPLES:
attrib = GL_SAMPLES_ARB;
break;
case SDL_GL_BUFFER_SIZE:
{
GLint bits = 0;
GLint component;

/* there doesn't seem to be a single flag in OpenGL for this! */
glGetIntegerv(GL_RED_BITS, &component);
bits += component;
glGetIntegerv(GL_GREEN_BITS, &component);
bits += component;
glGetIntegerv(GL_BLUE_BITS, &component);
bits += component;
glGetIntegerv(GL_ALPHA_BITS, &component);
bits += component;

*value = bits;
return 0;
}
case SDL_GL_ACCELERATED_VISUAL:
{
/* FIXME: How do we get this information? */
*value = (_this->gl_config.accelerated != 0);
return 0;
}
default:
SDL_SetError("Unknown OpenGL attribute");
return -1;
}
return retval;

glGetIntegerv(attrib, (GLint *) value);
return 0;
#else
SDL_Unsupported();
return -1;
#endif /* SDL_VIDEO_OPENGL */
}

SDL_GLContext
@@ -2240,6 +2316,9 @@ SDL_GL_MakeCurrent(SDL_WindowID windowID, SDL_GLContext context)
SDL_SetError("The specified window isn't an OpenGL window");
return -1;
}
if (!context) {
window = NULL;
}
return _this->GL_MakeCurrent(_this, window, context);
}

@@ -2296,6 +2375,7 @@ SDL_GL_DeleteContext(SDL_GLContext context)
if (!_this || !context) {
return;
}
_this->GL_MakeCurrent(_this, NULL, NULL);
_this->GL_DeleteContext(_this, context);
}

@@ -30,20 +30,11 @@ - (void)setAppleMenu:(NSMenu *)menu;
@end
#endif

@interface SDLApplication : NSApplication
@implementation NSApplication(SDL)
- (void)setRunning
{
}
- (void)finishLaunching;
@end

@implementation SDLApplication

- (void)finishLaunching
{
[super finishLaunching];
_running = 1;
}

@end

static NSString *
@@ -141,13 +132,14 @@ - (void)finishLaunching

pool = [[NSAutoreleasePool alloc] init];
if (NSApp == nil) {
[SDLApplication sharedApplication];
[NSApplication sharedApplication];

if ([NSApp mainMenu] == nil) {
CreateApplicationMenus();
}
[NSApp finishLaunching];
}
[NSApp setRunning];
[pool release];
}

@@ -0,0 +1,51 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"

#ifndef _SDL_cocoaopengl_h
#define _SDL_cocoaopengl_h

#if SDL_VIDEO_OPENGL

struct SDL_GLDriverData
{
int initialized;
};

/* OpenGL functions */
extern int Cocoa_GL_LoadLibrary(_THIS, const char *path);
extern void *Cocoa_GL_GetProcAddress(_THIS, const char *proc);
extern int Cocoa_GL_SetupWindow(_THIS, SDL_Window * window);
extern void Cocoa_GL_CleanupWindow(_THIS, SDL_Window * window);
extern SDL_GLContext Cocoa_GL_CreateContext(_THIS, SDL_Window * window);
extern int Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window,
SDL_GLContext context);
extern int Cocoa_GL_SetSwapInterval(_THIS, int interval);
extern int Cocoa_GL_GetSwapInterval(_THIS);
extern void Cocoa_GL_SwapWindow(_THIS, SDL_Window * window);
extern void Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context);

#endif /* SDL_VIDEO_OPENGL */

#endif /* _SDL_cocoaopengl_h */

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit dafecf2

Please sign in to comment.