Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Implemented OpenGL support on Mac OS X
Browse files Browse the repository at this point in the history
The OpenGL renderer works without changes, yay! :)
  • Loading branch information
slouken committed Jul 25, 2006
1 parent a570316 commit dafecf2
Show file tree
Hide file tree
Showing 16 changed files with 528 additions and 214 deletions.
1 change: 0 additions & 1 deletion include/SDL_compat.h
Expand Up @@ -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++ */
Expand Down
10 changes: 6 additions & 4 deletions include/SDL_video.h
Expand Up @@ -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().
*
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions src/SDL_compat.c
Expand Up @@ -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)
{
Expand Down
2 changes: 0 additions & 2 deletions src/video/SDL_sysvideo.h
Expand Up @@ -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);
Expand Down
104 changes: 92 additions & 12 deletions src/video/SDL_video.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
16 changes: 4 additions & 12 deletions src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -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 *
Expand Down Expand Up @@ -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];
}

Expand Down
51 changes: 51 additions & 0 deletions src/video/cocoa/SDL_cocoaopengl.h
@@ -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.