Commit 79452369 authored by Sam Lantinga's avatar Sam Lantinga

Implemented OpenGL support on Mac OS X

The OpenGL renderer works without changes, yay! :)

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401982
parent 941ef5db
...@@ -171,7 +171,6 @@ extern DECLSPEC void SDLCALL SDL_UnlockYUVOverlay(SDL_Overlay * overlay); ...@@ -171,7 +171,6 @@ extern DECLSPEC void SDLCALL SDL_UnlockYUVOverlay(SDL_Overlay * overlay);
extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay * overlay, extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay * overlay,
SDL_Rect * dstrect); SDL_Rect * dstrect);
extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay * overlay); 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); extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void);
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */
......
...@@ -1444,6 +1444,10 @@ extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src, ...@@ -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 * \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 * \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(). * 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); ...@@ -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) * \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, extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value);
SDL_GLattr attr,
int *value);
/** /**
* \fn SDL_GLContext SDL_GL_CreateContext(SDL_WindowID windowID) * \fn SDL_GLContext SDL_GL_CreateContext(SDL_WindowID windowID)
......
...@@ -1432,12 +1432,6 @@ SDL_FreeYUVOverlay(SDL_Overlay * overlay) ...@@ -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 void
SDL_GL_SwapBuffers(void) SDL_GL_SwapBuffers(void)
{ {
......
...@@ -232,8 +232,6 @@ struct SDL_VideoDevice ...@@ -232,8 +232,6 @@ struct SDL_VideoDevice
*/ */
int (*GL_LoadLibrary) (_THIS, const char *path); int (*GL_LoadLibrary) (_THIS, const char *path);
void *(*GL_GetProcAddress) (_THIS, const char *proc); 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); SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context); int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
int (*GL_SetSwapInterval) (_THIS, int interval); int (*GL_SetSwapInterval) (_THIS, int interval);
......
...@@ -2131,6 +2131,7 @@ SDL_GL_ExtensionSupported(const char *extension) ...@@ -2131,6 +2131,7 @@ SDL_GL_ExtensionSupported(const char *extension)
int int
SDL_GL_SetAttribute(SDL_GLattr attr, int value) SDL_GL_SetAttribute(SDL_GLattr attr, int value)
{ {
#if SDL_VIDEO_OPENGL
int retval; int retval;
if (!_this) { if (!_this) {
...@@ -2194,26 +2195,101 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value) ...@@ -2194,26 +2195,101 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value)
break; break;
} }
return retval; return retval;
#else
SDL_Unsupported();
return -1;
#endif /* SDL_VIDEO_OPENGL */
} }
int 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); #if SDL_VIDEO_OPENGL
int retval; void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
GLenum attrib = 0;
if (!window) { glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
if (!glGetIntegervFunc) {
return -1; return -1;
} }
switch (attr) {
if (_this->GL_GetWindowAttribute) { case SDL_GL_RED_SIZE:
retval = _this->GL_GetWindowAttribute(_this, window, attr, value); attrib = GL_RED_BITS;
} else { break;
*value = 0; case SDL_GL_BLUE_SIZE:
SDL_SetError("GL_GetWindowAttribute not supported"); attrib = GL_BLUE_BITS;
retval = -1; 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;
} }
return retval; 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;
}
glGetIntegerv(attrib, (GLint *) value);
return 0;
#else
SDL_Unsupported();
return -1;
#endif /* SDL_VIDEO_OPENGL */
} }
SDL_GLContext SDL_GLContext
...@@ -2240,6 +2316,9 @@ SDL_GL_MakeCurrent(SDL_WindowID windowID, SDL_GLContext context) ...@@ -2240,6 +2316,9 @@ SDL_GL_MakeCurrent(SDL_WindowID windowID, SDL_GLContext context)
SDL_SetError("The specified window isn't an OpenGL window"); SDL_SetError("The specified window isn't an OpenGL window");
return -1; return -1;
} }
if (!context) {
window = NULL;
}
return _this->GL_MakeCurrent(_this, window, context); return _this->GL_MakeCurrent(_this, window, context);
} }
...@@ -2296,6 +2375,7 @@ SDL_GL_DeleteContext(SDL_GLContext context) ...@@ -2296,6 +2375,7 @@ SDL_GL_DeleteContext(SDL_GLContext context)
if (!_this || !context) { if (!_this || !context) {
return; return;
} }
_this->GL_MakeCurrent(_this, NULL, NULL);
_this->GL_DeleteContext(_this, context); _this->GL_DeleteContext(_this, context);
} }
......
...@@ -30,20 +30,11 @@ ...@@ -30,20 +30,11 @@
@end @end
#endif #endif
@interface SDLApplication : NSApplication @implementation NSApplication(SDL)
- (void)setRunning
{ {
}
- (void)finishLaunching;
@end
@implementation SDLApplication
- (void)finishLaunching
{
[super finishLaunching];
_running = 1; _running = 1;
} }
@end @end
static NSString * static NSString *
...@@ -141,13 +132,14 @@ Cocoa_RegisterApp(void) ...@@ -141,13 +132,14 @@ Cocoa_RegisterApp(void)
pool = [[NSAutoreleasePool alloc] init]; pool = [[NSAutoreleasePool alloc] init];
if (NSApp == nil) { if (NSApp == nil) {
[SDLApplication sharedApplication]; [NSApplication sharedApplication];
if ([NSApp mainMenu] == nil) { if ([NSApp mainMenu] == nil) {
CreateApplicationMenus(); CreateApplicationMenus();
} }
[NSApp finishLaunching]; [NSApp finishLaunching];
} }
[NSApp setRunning];
[pool release]; [pool release];
} }
......
/*
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: */
/*
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: */
...@@ -33,9 +33,7 @@ ...@@ -33,9 +33,7 @@
#include "SDL_cocoakeyboard.h" #include "SDL_cocoakeyboard.h"
#include "SDL_cocoamodes.h" #include "SDL_cocoamodes.h"
#include "SDL_cocoamouse.h" #include "SDL_cocoamouse.h"
/*
#include "SDL_cocoaopengl.h" #include "SDL_cocoaopengl.h"
*/
#include "SDL_cocoawindow.h" #include "SDL_cocoawindow.h"
/* Private display data */ /* Private display data */
......
...@@ -87,11 +87,9 @@ Cocoa_CreateDevice(int devindex) ...@@ -87,11 +87,9 @@ Cocoa_CreateDevice(int devindex)
device->SetWindowGrab = Cocoa_SetWindowGrab; device->SetWindowGrab = Cocoa_SetWindowGrab;
device->DestroyWindow = Cocoa_DestroyWindow; device->DestroyWindow = Cocoa_DestroyWindow;
device->GetWindowWMInfo = Cocoa_GetWindowWMInfo; device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
/*
#ifdef SDL_VIDEO_OPENGL #ifdef SDL_VIDEO_OPENGL
device->GL_LoadLibrary = Cocoa_GL_LoadLibrary; device->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
device->GL_GetProcAddress = Cocoa_GL_GetProcAddress; device->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
device->GL_GetWindowAttribute = Cocoa_GL_GetWindowAttribute;
device->GL_CreateContext = Cocoa_GL_CreateContext; device->GL_CreateContext = Cocoa_GL_CreateContext;
device->GL_MakeCurrent = Cocoa_GL_MakeCurrent; device->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
device->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval; device->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
...@@ -99,7 +97,6 @@ Cocoa_CreateDevice(int devindex) ...@@ -99,7 +97,6 @@ Cocoa_CreateDevice(int devindex)
device->GL_SwapWindow = Cocoa_GL_SwapWindow; device->GL_SwapWindow = Cocoa_GL_SwapWindow;
device->GL_DeleteContext = Cocoa_GL_DeleteContext; device->GL_DeleteContext = Cocoa_GL_DeleteContext;
#endif #endif
*/
device->free = Cocoa_DeleteDevice; device->free = Cocoa_DeleteDevice;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
typedef struct SDL_WindowData SDL_WindowData; typedef struct SDL_WindowData SDL_WindowData;
/* *INDENT-OFF* */
@interface Cocoa_WindowListener:NSResponder { @interface Cocoa_WindowListener:NSResponder {
SDL_WindowData *_data; SDL_WindowData *_data;
} }
...@@ -58,7 +59,10 @@ typedef struct SDL_WindowData SDL_WindowData; ...@@ -58,7 +59,10 @@ typedef struct SDL_WindowData SDL_WindowData;
-(void) mouseExited:(NSEvent *) theEvent; -(void) mouseExited:(NSEvent *) theEvent;
-(void) keyDown:(NSEvent *) theEvent; -(void) keyDown:(NSEvent *) theEvent;
-(void) keyUp:(NSEvent *) theEvent; -(void) keyUp:(NSEvent *) theEvent;
@end struct SDL_WindowData @end
/* *INDENT-ON* */
struct SDL_WindowData
{ {
SDL_WindowID windowID; SDL_WindowID windowID;
NSWindow *window; NSWindow *window;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
static __inline__ void ConvertNSRect(NSRect *r) 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; r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
} }
...@@ -325,6 +326,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window) ...@@ -325,6 +326,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
NSRect rect; NSRect rect;
unsigned int style; unsigned int style;
NSString *title; NSString *title;
int status;
pool = [[NSAutoreleasePool alloc] init]; pool = [[NSAutoreleasePool alloc] init];
...@@ -380,18 +382,15 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window) ...@@ -380,18 +382,15 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
if (SetupWindowData(window, nswindow, YES) < 0) { if (SetupWindowData(window, nswindow, YES) < 0) {
[nswindow release]; [nswindow release];
[pool release];
return -1; return -1;
} }
#ifdef SDL_VIDEO_OPENGL #ifdef SDL_VIDEO_OPENGL
/*
if (window->flags & SDL_WINDOW_OPENGL) { if (window->flags & SDL_WINDOW_OPENGL) {
if (Cocoa_GL_SetupWindow(_this, window) < 0) { if (Cocoa_GL_SetupWindow(_this, window) < 0) {
Cocoa_DestroyWindow(_this, window); Cocoa_DestroyWindow(_this, window);
return -1; return -1;
} }
} }
*/
#endif #endif
return 0; return 0;
} }
...@@ -522,11 +521,9 @@ Cocoa_DestroyWindow(_THIS, SDL_Window * window) ...@@ -522,11 +521,9 @@ Cocoa_DestroyWindow(_THIS, SDL_Window * window)
if (data) { if (data) {
NSAutoreleasePool *pool; NSAutoreleasePool *pool;
#ifdef SDL_VIDEO_OPENGL #ifdef SDL_VIDEO_OPENGL
/*
if (window->flags & SDL_WINDOW_OPENGL) { if (window->flags & SDL_WINDOW_OPENGL) {
Cocoa_GL_CleanupWindow(_this, window); Cocoa_GL_CleanupWindow(_this, window);
} }
*/
#endif #endif
pool = [[NSAutoreleasePool alloc] init]; pool = [[NSAutoreleasePool alloc] init];
[data->listener close]; [data->listener close];
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#if SDL_VIDEO_OPENGL #if SDL_VIDEO_OPENGL
#include "SDL_opengl.h" #include "SDL_opengl.h"
#define DEFAULT_GL_DRIVER_PATH "OPENGL32.DLL" #define DEFAULT_OPENGL_PATH "OPENGL32.DLL"
int int
...@@ -47,7 +47,7 @@ WIN_GL_LoadLibrary(_THIS, const char *path) ...@@ -47,7 +47,7 @@ WIN_GL_LoadLibrary(_THIS, const char *path)
} }
} }
if (path == NULL) { if (path == NULL) {
path = DEFAULT_GL_DRIVER_PATH; path = DEFAULT_OPENGL_PATH;
} }
wpath = WIN_UTF8ToString(path); wpath = WIN_UTF8ToString(path);
handle = LoadLibrary(wpath); handle = LoadLibrary(wpath);
...@@ -414,153 +414,6 @@ WIN_GL_CleanupWindow(_THIS, SDL_Window * window) ...@@ -414,153 +414,6 @@ WIN_GL_CleanupWindow(_THIS, SDL_Window * window)
WIN_GL_Shutdown(_this); 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 SDL_GLContext
WIN_GL_CreateContext(_THIS, SDL_Window * window) WIN_GL_CreateContext(_THIS, SDL_Window * window)
{ {
...@@ -623,9 +476,7 @@ WIN_GL_SwapWindow(_THIS, SDL_Window * window) ...@@ -623,9 +476,7 @@ WIN_GL_SwapWindow(_THIS, SDL_Window * window)
void void
WIN_GL_DeleteContext(_THIS, SDL_GLContext context) 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 */ #endif /* SDL_VIDEO_OPENGL */
......
...@@ -55,8 +55,6 @@ extern int WIN_GL_LoadLibrary(_THIS, const char *path); ...@@ -55,8 +55,6 @@ extern int WIN_GL_LoadLibrary(_THIS, const char *path);
extern void *WIN_GL_GetProcAddress(_THIS, const char *proc); extern void *WIN_GL_GetProcAddress(_THIS, const char *proc);
extern int WIN_GL_SetupWindow(_THIS, SDL_Window * window); extern int WIN_GL_SetupWindow(_THIS, SDL_Window * window);
extern void WIN_GL_CleanupWindow(_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 SDL_GLContext WIN_GL_CreateContext(_THIS, SDL_Window * window);
extern int WIN_GL_MakeCurrent(_THIS, SDL_Window * window, extern int WIN_GL_MakeCurrent(_THIS, SDL_Window * window,
SDL_GLContext context); SDL_GLContext context);
......
...@@ -126,7 +126,6 @@ WIN_CreateDevice(int devindex) ...@@ -126,7 +126,6 @@ WIN_CreateDevice(int devindex)
#ifdef SDL_VIDEO_OPENGL #ifdef SDL_VIDEO_OPENGL
device->GL_LoadLibrary = WIN_GL_LoadLibrary; device->GL_LoadLibrary = WIN_GL_LoadLibrary;
device->GL_GetProcAddress = WIN_GL_GetProcAddress; device->GL_GetProcAddress = WIN_GL_GetProcAddress;
device->GL_GetWindowAttribute = WIN_GL_GetWindowAttribute;
device->GL_CreateContext = WIN_GL_CreateContext; device->GL_CreateContext = WIN_GL_CreateContext;
device->GL_MakeCurrent = WIN_GL_MakeCurrent; device->GL_MakeCurrent = WIN_GL_MakeCurrent;
device->GL_SetSwapInterval = WIN_GL_SetSwapInterval; device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
......
...@@ -244,28 +244,25 @@ main(int argc, char *argv[]) ...@@ -244,28 +244,25 @@ main(int argc, char *argv[])
printf("Extensions : %s\n", glGetString(GL_EXTENSIONS)); printf("Extensions : %s\n", glGetString(GL_EXTENSIONS));
printf("\n"); 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); 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); 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); 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); 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); printf("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value);
if (fsaa) { if (fsaa) {
SDL_GL_GetWindowAttribute(state->windows[0], SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
SDL_GL_MULTISAMPLEBUFFERS, &value);
printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
SDL_GL_GetWindowAttribute(state->windows[0], SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
SDL_GL_MULTISAMPLESAMPLES, &value);
printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
value); value);
} }
if (accel) { if (accel) {
SDL_GL_GetWindowAttribute(state->windows[0], SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
SDL_GL_ACCELERATED_VISUAL, &value);
printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment