Implemented OpenGL support on Mac OS X
The OpenGL renderer works without changes, yay! :)
--- a/include/SDL_compat.h Mon Jul 24 23:30:14 2006 +0000
+++ b/include/SDL_compat.h Tue Jul 25 06:22:42 2006 +0000
@@ -171,7 +171,6 @@
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++ */
--- a/include/SDL_video.h Mon Jul 24 23:30:14 2006 +0000
+++ b/include/SDL_video.h Tue Jul 25 06:22:42 2006 +0000
@@ -1444,6 +1444,10 @@
*
* \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 @@
/**
* \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)
--- a/src/SDL_compat.c Mon Jul 24 23:30:14 2006 +0000
+++ b/src/SDL_compat.c Tue Jul 25 06:22:42 2006 +0000
@@ -1432,12 +1432,6 @@
}
}
-int
-SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
-{
- return SDL_GL_GetWindowAttribute(SDL_VideoWindow, attr, value);
-}
-
void
SDL_GL_SwapBuffers(void)
{
--- a/src/video/SDL_sysvideo.h Mon Jul 24 23:30:14 2006 +0000
+++ b/src/video/SDL_sysvideo.h Tue Jul 25 06:22:42 2006 +0000
@@ -232,8 +232,6 @@
*/
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);
--- a/src/video/SDL_video.c Mon Jul 24 23:30:14 2006 +0000
+++ b/src/video/SDL_video.c Tue Jul 25 06:22:42 2006 +0000
@@ -2131,6 +2131,7 @@
int
SDL_GL_SetAttribute(SDL_GLattr attr, int value)
{
+#if SDL_VIDEO_OPENGL
int retval;
if (!_this) {
@@ -2194,26 +2195,101 @@
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;
+ }
+ 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;
}
- if (_this->GL_GetWindowAttribute) {
- retval = _this->GL_GetWindowAttribute(_this, window, attr, value);
- } else {
- *value = 0;
- SDL_SetError("GL_GetWindowAttribute not supported");
- retval = -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_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 @@
if (!_this || !context) {
return;
}
+ _this->GL_MakeCurrent(_this, NULL, NULL);
_this->GL_DeleteContext(_this, context);
}
--- a/src/video/cocoa/SDL_cocoaevents.m Mon Jul 24 23:30:14 2006 +0000
+++ b/src/video/cocoa/SDL_cocoaevents.m Tue Jul 25 06:22:42 2006 +0000
@@ -30,20 +30,11 @@
@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 @@
pool = [[NSAutoreleasePool alloc] init];
if (NSApp == nil) {
- [SDLApplication sharedApplication];
+ [NSApplication sharedApplication];
if ([NSApp mainMenu] == nil) {
CreateApplicationMenus();
}
[NSApp finishLaunching];
}
+ [NSApp setRunning];
[pool release];
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/cocoa/SDL_cocoaopengl.h Tue Jul 25 06:22:42 2006 +0000
@@ -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: */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/cocoa/SDL_cocoaopengl.m Tue Jul 25 06:22:42 2006 +0000
@@ -0,0 +1,357 @@
+/*
+ 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"
+
+#include "SDL_cocoavideo.h"
+
+/* NSOpenGL implementation of SDL OpenGL support */
+
+#if SDL_VIDEO_OPENGL
+#include <OpenGL/CGLTypes.h>
+
+#include "SDL_loadso.h"
+#include "SDL_opengl.h"
+
+
+#define DEFAULT_OPENGL_PATH "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
+
+/* This is implemented in Mac OS X 10.3 and above */
+#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
+@implementation NSOpenGLContext(CGLContextAccess)
+- (CGLContextObj)CGLContextObj;
+{
+ return _contextAuxiliary;
+}
+@end
+#endif /* < 10.3 */
+
+int
+Cocoa_GL_LoadLibrary(_THIS, const char *path)
+{
+ if (_this->gl_config.driver_loaded) {
+ if (path) {
+ SDL_SetError("OpenGL library already loaded");
+ return -1;
+ } else {
+ ++_this->gl_config.driver_loaded;
+ return 0;
+ }
+ }
+ if (path == NULL) {
+ path = DEFAULT_OPENGL_PATH;
+ }
+ _this->gl_config.dll_handle = SDL_LoadObject(path);
+ if (!_this->gl_config.dll_handle) {
+ return -1;
+ }
+ SDL_strlcpy(_this->gl_config.driver_path, path,
+ SDL_arraysize(_this->gl_config.driver_path));
+ _this->gl_config.driver_loaded = 1;
+ return 0;
+}
+
+void *
+Cocoa_GL_GetProcAddress(_THIS, const char *proc)
+{
+ return SDL_LoadFunction(_this->gl_config.dll_handle, proc);
+}
+
+static void
+Cocoa_GL_UnloadLibrary(_THIS)
+{
+ if (_this->gl_config.driver_loaded > 0) {
+ if (--_this->gl_config.driver_loaded > 0) {
+ return;
+ }
+ SDL_UnloadObject(_this->gl_config.dll_handle);
+ _this->gl_config.dll_handle = NULL;
+ }
+}
+
+static void
+Cocoa_GL_Shutdown(_THIS)
+{
+ if (!_this->gl_data || (--_this->gl_data->initialized > 0)) {
+ return;
+ }
+
+ Cocoa_GL_UnloadLibrary(_this);
+
+ SDL_free(_this->gl_data);
+ _this->gl_data = NULL;
+}
+
+static int
+Cocoa_GL_Initialize(_THIS)
+{
+ if (_this->gl_data) {
+ ++_this->gl_data->initialized;
+ return 0;
+ }
+
+ _this->gl_data =
+ (struct SDL_GLDriverData *) SDL_calloc(1,
+ sizeof(struct
+ SDL_GLDriverData));
+ if (!_this->gl_data) {
+ SDL_OutOfMemory();
+ return -1;
+ }
+ _this->gl_data->initialized = 1;
+
+ if (Cocoa_GL_LoadLibrary(_this, NULL) < 0) {
+ return -1;
+ }
+ return 0;
+}
+
+int
+Cocoa_GL_SetupWindow(_THIS, SDL_Window * window)
+{
+ if (Cocoa_GL_Initialize(_this) < 0) {
+ return -1;
+ }
+ return 0;
+}
+
+void
+Cocoa_GL_CleanupWindow(_THIS, SDL_Window * window)
+{
+ Cocoa_GL_Shutdown(_this);
+}
+
+SDL_GLContext
+Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
+{
+ NSAutoreleasePool *pool;
+ SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
+ SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
+ NSOpenGLPixelFormatAttribute attr[32];
+ NSOpenGLPixelFormat *fmt;
+ NSOpenGLContext *nscontext;
+ int i = 0;
+
+ pool = [[NSAutoreleasePool alloc] init];
+
+ if (window->flags & SDL_WINDOW_FULLSCREEN) {
+ attr[i++] = NSOpenGLPFAFullScreen;
+ }
+
+ attr[i++] = NSOpenGLPFAColorSize;
+ attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
+
+ attr[i++] = NSOpenGLPFADepthSize;
+ attr[i++] = _this->gl_config.depth_size;
+
+ if (_this->gl_config.double_buffer) {
+ attr[i++] = NSOpenGLPFADoubleBuffer;
+ }
+
+ if (_this->gl_config.stereo) {
+ attr[i++] = NSOpenGLPFAStereo;
+ }
+
+ if (_this->gl_config.stencil_size) {
+ attr[i++] = NSOpenGLPFAStencilSize;
+ attr[i++] = _this->gl_config.stencil_size;
+ }
+
+ if ((_this->gl_config.accum_red_size +
+ _this->gl_config.accum_green_size +
+ _this->gl_config.accum_blue_size +
+ _this->gl_config.accum_alpha_size) > 0) {
+ attr[i++] = NSOpenGLPFAAccumSize;
+ attr[i++] = _this->gl_config.accum_red_size + _this->gl_config.accum_green_size + _this->gl_config.accum_blue_size + _this->gl_config.accum_alpha_size;
+ }
+
+ if (_this->gl_config.multisamplebuffers) {
+ attr[i++] = NSOpenGLPFASampleBuffers;
+ attr[i++] = _this->gl_config.multisamplebuffers;
+ }
+
+ if (_this->gl_config.multisamplesamples) {
+ attr[i++] = NSOpenGLPFASamples;
+ attr[i++] = _this->gl_config.multisamplesamples;
+ attr[i++] = NSOpenGLPFANoRecovery;
+ }
+
+ if (_this->gl_config.accelerated > 0) {
+ attr[i++] = NSOpenGLPFAAccelerated;
+ }
+
+ attr[i++] = NSOpenGLPFAScreenMask;
+ attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
+ attr[i] = 0;
+
+ fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
+ if (fmt == nil) {
+ SDL_SetError ("Failed creating OpenGL pixel format");
+ [pool release];
+ return NULL;
+ }
+
+ nscontext = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
+
+ [fmt release];
+
+ if (nscontext == nil) {
+ SDL_SetError ("Failed creating OpenGL context");
+ [pool release];
+ return NULL;
+ }
+
+ /*
+ * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
+ * "You are blowing a couple of the internal OpenGL function caches. This
+ * appears to be happening in the VAO case. You can tell OpenGL to up
+ * the cache size by issuing the following calls right after you create
+ * the OpenGL context. The default cache size is 16." --ryan.
+ */
+
+ #ifndef GLI_ARRAY_FUNC_CACHE_MAX
+ #define GLI_ARRAY_FUNC_CACHE_MAX 284
+ #endif
+
+ #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
+ #define GLI_SUBMIT_FUNC_CACHE_MAX 280
+ #endif
+
+ {
+ long cache_max = 64;
+ CGLContextObj ctx = [nscontext CGLContextObj];
+ CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
+ CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
+ }
+
+ /* End Wisdom from Apple Engineer section. --ryan. */
+
+ /* FIXME: should this go somewhere else? */
+ if (window->flags & SDL_WINDOW_FULLSCREEN) {
+ [nscontext setFullScreen];
+ }
+
+ [pool release];
+ return nscontext;
+}
+
+int
+Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
+{
+ NSAutoreleasePool *pool;
+
+ pool = [[NSAutoreleasePool alloc] init];
+
+ if (context) {
+ SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
+ NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
+
+ [nscontext setView:[windowdata->window contentView]];
+ [nscontext makeCurrentContext];
+ } else {
+ [NSOpenGLContext clearCurrentContext];
+ }
+
+ [pool release];
+ return 0;
+}
+
+int
+Cocoa_GL_SetSwapInterval(_THIS, int interval)
+{
+ NSAutoreleasePool *pool;
+ NSOpenGLContext *nscontext;
+ long value;
+ int status;
+
+ pool = [[NSAutoreleasePool alloc] init];
+
+ nscontext = [NSOpenGLContext currentContext];
+ if (nscontext != nil) {
+ value = interval;
+ [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
+ status = 0;
+ } else {
+ SDL_SetError("No current OpenGL context");
+ status = -1;
+ }
+
+ [pool release];
+ return status;
+}
+
+int
+Cocoa_GL_GetSwapInterval(_THIS)
+{
+ NSAutoreleasePool *pool;
+ NSOpenGLContext *nscontext;
+ long value;
+ int status;
+
+ pool = [[NSAutoreleasePool alloc] init];
+
+ nscontext = [NSOpenGLContext currentContext];
+ if (nscontext != nil) {
+ [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
+ status = (int)value;
+ } else {
+ SDL_SetError("No current OpenGL context");
+ status = -1;
+ }
+
+ [pool release];
+ return status;
+}
+
+void
+Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
+{
+ NSAutoreleasePool *pool;
+ NSOpenGLContext *nscontext;
+
+ pool = [[NSAutoreleasePool alloc] init];
+
+ /* FIXME: Do we need to get the context for the window? */
+ nscontext = [NSOpenGLContext currentContext];
+ if (nscontext != nil) {
+ [nscontext flushBuffer];
+ }
+
+ [pool release];
+}
+
+void
+Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
+{
+ NSAutoreleasePool *pool;
+ NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
+
+ pool = [[NSAutoreleasePool alloc] init];
+
+ [nscontext clearDrawable];
+ [nscontext release];
+
+ [pool release];
+}
+
+#endif /* SDL_VIDEO_OPENGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/cocoa/SDL_cocoavideo.h Mon Jul 24 23:30:14 2006 +0000
+++ b/src/video/cocoa/SDL_cocoavideo.h Tue Jul 25 06:22:42 2006 +0000
@@ -33,9 +33,7 @@
#include "SDL_cocoakeyboard.h"
#include "SDL_cocoamodes.h"
#include "SDL_cocoamouse.h"
-/*
#include "SDL_cocoaopengl.h"
-*/
#include "SDL_cocoawindow.h"
/* Private display data */
--- a/src/video/cocoa/SDL_cocoavideo.m Mon Jul 24 23:30:14 2006 +0000
+++ b/src/video/cocoa/SDL_cocoavideo.m Tue Jul 25 06:22:42 2006 +0000
@@ -87,11 +87,9 @@
device->SetWindowGrab = Cocoa_SetWindowGrab;
device->DestroyWindow = Cocoa_DestroyWindow;
device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
- /*
#ifdef SDL_VIDEO_OPENGL
device->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
device->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
- device->GL_GetWindowAttribute = Cocoa_GL_GetWindowAttribute;
device->GL_CreateContext = Cocoa_GL_CreateContext;
device->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
device->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
@@ -99,7 +97,6 @@
device->GL_SwapWindow = Cocoa_GL_SwapWindow;
device->GL_DeleteContext = Cocoa_GL_DeleteContext;
#endif
- */
device->free = Cocoa_DeleteDevice;
--- a/src/video/cocoa/SDL_cocoawindow.h Mon Jul 24 23:30:14 2006 +0000
+++ b/src/video/cocoa/SDL_cocoawindow.h Tue Jul 25 06:22:42 2006 +0000
@@ -26,6 +26,7 @@
typedef struct SDL_WindowData SDL_WindowData;
+/* *INDENT-OFF* */
@interface Cocoa_WindowListener:NSResponder {
SDL_WindowData *_data;
}
@@ -58,7 +59,10 @@
-(void) mouseExited:(NSEvent *) theEvent;
-(void) keyDown:(NSEvent *) theEvent;
-(void) keyUp:(NSEvent *) theEvent;
-@end struct SDL_WindowData
+@end
+/* *INDENT-ON* */
+
+struct SDL_WindowData
{
SDL_WindowID windowID;
NSWindow *window;
--- a/src/video/cocoa/SDL_cocoawindow.m Mon Jul 24 23:30:14 2006 +0000
+++ b/src/video/cocoa/SDL_cocoawindow.m Tue Jul 25 06:22:42 2006 +0000
@@ -31,6 +31,7 @@
static __inline__ void ConvertNSRect(NSRect *r)
{
+ /* FIXME: Cache the display used for this window */
r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
}
@@ -325,6 +326,7 @@
NSRect rect;
unsigned int style;
NSString *title;
+ int status;
pool = [[NSAutoreleasePool alloc] init];
@@ -380,18 +382,15 @@
if (SetupWindowData(window, nswindow, YES) < 0) {
[nswindow release];
- [pool release];
return -1;
}
#ifdef SDL_VIDEO_OPENGL
- /*
if (window->flags & SDL_WINDOW_OPENGL) {
if (Cocoa_GL_SetupWindow(_this, window) < 0) {
Cocoa_DestroyWindow(_this, window);
return -1;
}
}
- */
#endif
return 0;
}
@@ -522,11 +521,9 @@
if (data) {
NSAutoreleasePool *pool;
#ifdef SDL_VIDEO_OPENGL
- /*
if (window->flags & SDL_WINDOW_OPENGL) {
Cocoa_GL_CleanupWindow(_this, window);
}
- */
#endif
pool = [[NSAutoreleasePool alloc] init];
[data->listener close];
--- a/src/video/win32/SDL_win32opengl.c Mon Jul 24 23:30:14 2006 +0000
+++ b/src/video/win32/SDL_win32opengl.c Tue Jul 25 06:22:42 2006 +0000
@@ -28,7 +28,7 @@
#if SDL_VIDEO_OPENGL
#include "SDL_opengl.h"
-#define DEFAULT_GL_DRIVER_PATH "OPENGL32.DLL"
+#define DEFAULT_OPENGL_PATH "OPENGL32.DLL"
int
@@ -47,7 +47,7 @@
}
}
if (path == NULL) {
- path = DEFAULT_GL_DRIVER_PATH;
+ path = DEFAULT_OPENGL_PATH;
}
wpath = WIN_UTF8ToString(path);
handle = LoadLibrary(wpath);
@@ -414,153 +414,6 @@
WIN_GL_Shutdown(_this);
}
-int
-WIN_GL_GetWindowAttribute(_THIS, SDL_Window * window, SDL_GLattr attrib,
- int *value)
-{
- HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
- int pixel_format;
-
- pixel_format = GetPixelFormat(hdc);
-
- if (_this->gl_data->WGL_ARB_pixel_format) {
- int wgl_attrib;
-
- switch (attrib) {
- case SDL_GL_RED_SIZE:
- wgl_attrib = WGL_RED_BITS_ARB;
- break;
- case SDL_GL_GREEN_SIZE:
- wgl_attrib = WGL_GREEN_BITS_ARB;
- break;
- case SDL_GL_BLUE_SIZE:
- wgl_attrib = WGL_BLUE_BITS_ARB;
- break;
- case SDL_GL_ALPHA_SIZE:
- wgl_attrib = WGL_ALPHA_BITS_ARB;
- break;
- case SDL_GL_DOUBLEBUFFER:
- wgl_attrib = WGL_DOUBLE_BUFFER_ARB;
- break;
- case SDL_GL_BUFFER_SIZE:
- wgl_attrib = WGL_COLOR_BITS_ARB;
- break;
- case SDL_GL_DEPTH_SIZE:
- wgl_attrib = WGL_DEPTH_BITS_ARB;
- break;
- case SDL_GL_STENCIL_SIZE:
- wgl_attrib = WGL_STENCIL_BITS_ARB;
- break;
- case SDL_GL_ACCUM_RED_SIZE:
- wgl_attrib = WGL_ACCUM_RED_BITS_ARB;
- break;
- case SDL_GL_ACCUM_GREEN_SIZE:
- wgl_attrib = WGL_ACCUM_GREEN_BITS_ARB;
- break;
- case SDL_GL_ACCUM_BLUE_SIZE:
- wgl_attrib = WGL_ACCUM_BLUE_BITS_ARB;
- break;
- case SDL_GL_ACCUM_ALPHA_SIZE:
- wgl_attrib = WGL_ACCUM_ALPHA_BITS_ARB;
- break;
- case SDL_GL_STEREO:
- wgl_attrib = WGL_STEREO_ARB;
- break;
- case SDL_GL_MULTISAMPLEBUFFERS:
- wgl_attrib = WGL_SAMPLE_BUFFERS_ARB;
- break;
- case SDL_GL_MULTISAMPLESAMPLES:
- wgl_attrib = WGL_SAMPLES_ARB;
- break;
- case SDL_GL_ACCELERATED_VISUAL:
- wgl_attrib = WGL_ACCELERATION_ARB;
- _this->gl_data->wglGetPixelFormatAttribivARB(hdc, pixel_format, 0,
- 1, &wgl_attrib,
- value);
- if (*value == WGL_NO_ACCELERATION_ARB) {
- *value = SDL_FALSE;
- } else {
- *value = SDL_TRUE;
- }
- return 0;
- break;
- default:
- return (-1);
- }
- _this->gl_data->wglGetPixelFormatAttribivARB(hdc, pixel_format, 0, 1,
- &wgl_attrib, value);
- return 0;
- } else {
- PIXELFORMATDESCRIPTOR pfd;
- int retval;
-
- if (!DescribePixelFormat(hdc, pixel_format, sizeof(pfd), &pfd)) {
- WIN_SetError("DescribePixelFormat()");
- return -1;
- }
- retval = 0;
- switch (attrib) {
- case SDL_GL_RED_SIZE:
- *value = pfd.cRedBits;
- break;
- case SDL_GL_GREEN_SIZE:
- *value = pfd.cGreenBits;
- break;
- case SDL_GL_BLUE_SIZE:
- *value = pfd.cBlueBits;
- break;
- case SDL_GL_ALPHA_SIZE:
- *value = pfd.cAlphaBits;
- break;
- case SDL_GL_DOUBLEBUFFER:
- if (pfd.dwFlags & PFD_DOUBLEBUFFER) {
- *value = 1;
- } else {
- *value = 0;
- }
- break;
- case SDL_GL_BUFFER_SIZE:
- *value = pfd.cColorBits;
- break;
- case SDL_GL_DEPTH_SIZE:
- *value = pfd.cDepthBits;
- break;
- case SDL_GL_STENCIL_SIZE:
- *value = pfd.cStencilBits;
- break;
- case SDL_GL_ACCUM_RED_SIZE:
- *value = pfd.cAccumRedBits;
- break;
- case SDL_GL_ACCUM_GREEN_SIZE:
- *value = pfd.cAccumGreenBits;
- break;
- case SDL_GL_ACCUM_BLUE_SIZE:
- *value = pfd.cAccumBlueBits;
- break;
- case SDL_GL_ACCUM_ALPHA_SIZE:
- *value = pfd.cAccumAlphaBits;
- break;
- case SDL_GL_STEREO:
- if (pfd.dwFlags & PFD_STEREO) {
- *value = 1;
- } else {
- *value = 0;
- }
- break;
- case SDL_GL_MULTISAMPLEBUFFERS:
- *value = 0;
- break;
- case SDL_GL_MULTISAMPLESAMPLES:
- *value = 1;
- break;
- default:
- retval = -1;
- break;
- }
- return retval;
- }
-}
-
SDL_GLContext
WIN_GL_CreateContext(_THIS, SDL_Window * window)
{
@@ -623,9 +476,7 @@
void
WIN_GL_DeleteContext(_THIS, SDL_GLContext context)
{
- if (context) {
- _this->gl_data->wglDeleteContext((HGLRC) context);
- }
+ _this->gl_data->wglDeleteContext((HGLRC) context);
}
#endif /* SDL_VIDEO_OPENGL */
--- a/src/video/win32/SDL_win32opengl.h Mon Jul 24 23:30:14 2006 +0000
+++ b/src/video/win32/SDL_win32opengl.h Tue Jul 25 06:22:42 2006 +0000
@@ -55,8 +55,6 @@
extern void *WIN_GL_GetProcAddress(_THIS, const char *proc);
extern int WIN_GL_SetupWindow(_THIS, SDL_Window * window);
extern void WIN_GL_CleanupWindow(_THIS, SDL_Window * window);
-extern int WIN_GL_GetWindowAttribute(_THIS, SDL_Window * window,
- SDL_GLattr attrib, int *value);
extern SDL_GLContext WIN_GL_CreateContext(_THIS, SDL_Window * window);
extern int WIN_GL_MakeCurrent(_THIS, SDL_Window * window,
SDL_GLContext context);
--- a/src/video/win32/SDL_win32video.c Mon Jul 24 23:30:14 2006 +0000
+++ b/src/video/win32/SDL_win32video.c Tue Jul 25 06:22:42 2006 +0000
@@ -126,7 +126,6 @@
#ifdef SDL_VIDEO_OPENGL
device->GL_LoadLibrary = WIN_GL_LoadLibrary;
device->GL_GetProcAddress = WIN_GL_GetProcAddress;
- device->GL_GetWindowAttribute = WIN_GL_GetWindowAttribute;
device->GL_CreateContext = WIN_GL_CreateContext;
device->GL_MakeCurrent = WIN_GL_MakeCurrent;
device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
--- a/test/testgl2.c Mon Jul 24 23:30:14 2006 +0000
+++ b/test/testgl2.c Tue Jul 25 06:22:42 2006 +0000
@@ -244,28 +244,25 @@
printf("Extensions : %s\n", glGetString(GL_EXTENSIONS));
printf("\n");
- SDL_GL_GetWindowAttribute(state->windows[0], SDL_GL_RED_SIZE, &value);
+ SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
- SDL_GL_GetWindowAttribute(state->windows[0], SDL_GL_GREEN_SIZE, &value);
+ SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
- SDL_GL_GetWindowAttribute(state->windows[0], SDL_GL_BLUE_SIZE, &value);
+ SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
- SDL_GL_GetWindowAttribute(state->windows[0], SDL_GL_DEPTH_SIZE, &value);
+ SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
- SDL_GL_GetWindowAttribute(state->windows[0], SDL_GL_DOUBLEBUFFER, &value);
+ SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &value);
printf("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value);
if (fsaa) {
- SDL_GL_GetWindowAttribute(state->windows[0],
- SDL_GL_MULTISAMPLEBUFFERS, &value);
+ SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
- SDL_GL_GetWindowAttribute(state->windows[0],
- SDL_GL_MULTISAMPLESAMPLES, &value);
+ SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
value);
}
if (accel) {
- SDL_GL_GetWindowAttribute(state->windows[0],
- SDL_GL_ACCELERATED_VISUAL, &value);
+ SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
}