Implemented OpenGL support on Mac OS X
authorSam Lantinga <slouken@libsdl.org>
Tue, 25 Jul 2006 06:22:42 +0000
changeset 193683946ee0ff1f
parent 1935 8a9b367a80f3
child 1937 05e88d266921
Implemented OpenGL support on Mac OS X
The OpenGL renderer works without changes, yay! :)
include/SDL_compat.h
include/SDL_video.h
src/SDL_compat.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/cocoa/SDL_cocoaevents.m
src/video/cocoa/SDL_cocoaopengl.h
src/video/cocoa/SDL_cocoaopengl.m
src/video/cocoa/SDL_cocoavideo.h
src/video/cocoa/SDL_cocoavideo.m
src/video/cocoa/SDL_cocoawindow.h
src/video/cocoa/SDL_cocoawindow.m
src/video/win32/SDL_win32opengl.c
src/video/win32/SDL_win32opengl.h
src/video/win32/SDL_win32video.c
test/testgl2.c
     1.1 --- a/include/SDL_compat.h	Mon Jul 24 23:30:14 2006 +0000
     1.2 +++ b/include/SDL_compat.h	Tue Jul 25 06:22:42 2006 +0000
     1.3 @@ -171,7 +171,6 @@
     1.4  extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay * overlay,
     1.5                                                    SDL_Rect * dstrect);
     1.6  extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay * overlay);
     1.7 -extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value);
     1.8  extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void);
     1.9  
    1.10  /* Ends C function definitions when using C++ */
     2.1 --- a/include/SDL_video.h	Mon Jul 24 23:30:14 2006 +0000
     2.2 +++ b/include/SDL_video.h	Tue Jul 25 06:22:42 2006 +0000
     2.3 @@ -1444,6 +1444,10 @@
     2.4   *
     2.5   * \return 0 on success, or -1 if the library couldn't be loaded
     2.6   *
     2.7 + * This should be done after initializing the video driver, but before
     2.8 + * creating any OpenGL windows.  If no OpenGL library is loaded, the default
     2.9 + * library will be loaded upon creation of the first OpenGL window.
    2.10 + *
    2.11   * \note If you do this, you need to retrieve all of the GL functions used in
    2.12   *       your program from the dynamic library using SDL_GL_GetProcAddress().
    2.13   *
    2.14 @@ -1476,11 +1480,9 @@
    2.15  /**
    2.16   * \fn int SDL_GL_GetWindowAttribute(SDL_WindowID windowID, SDL_GLattr attr, int *value)
    2.17   *
    2.18 - * \brief Get the actual value for an OpenGL window attribute.
    2.19 + * \brief Get the actual value for an attribute from the current context.
    2.20   */
    2.21 -extern DECLSPEC int SDLCALL SDL_GL_GetWindowAttribute(SDL_WindowID windowID,
    2.22 -                                                      SDL_GLattr attr,
    2.23 -                                                      int *value);
    2.24 +extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value);
    2.25  
    2.26  /**
    2.27   * \fn SDL_GLContext SDL_GL_CreateContext(SDL_WindowID windowID)
     3.1 --- a/src/SDL_compat.c	Mon Jul 24 23:30:14 2006 +0000
     3.2 +++ b/src/SDL_compat.c	Tue Jul 25 06:22:42 2006 +0000
     3.3 @@ -1432,12 +1432,6 @@
     3.4      }
     3.5  }
     3.6  
     3.7 -int
     3.8 -SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
     3.9 -{
    3.10 -    return SDL_GL_GetWindowAttribute(SDL_VideoWindow, attr, value);
    3.11 -}
    3.12 -
    3.13  void
    3.14  SDL_GL_SwapBuffers(void)
    3.15  {
     4.1 --- a/src/video/SDL_sysvideo.h	Mon Jul 24 23:30:14 2006 +0000
     4.2 +++ b/src/video/SDL_sysvideo.h	Tue Jul 25 06:22:42 2006 +0000
     4.3 @@ -232,8 +232,6 @@
     4.4       */
     4.5      int (*GL_LoadLibrary) (_THIS, const char *path);
     4.6      void *(*GL_GetProcAddress) (_THIS, const char *proc);
     4.7 -    int (*GL_GetWindowAttribute) (_THIS, SDL_Window * window,
     4.8 -                                  SDL_GLattr attrib, int *value);
     4.9        SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
    4.10      int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
    4.11      int (*GL_SetSwapInterval) (_THIS, int interval);
     5.1 --- a/src/video/SDL_video.c	Mon Jul 24 23:30:14 2006 +0000
     5.2 +++ b/src/video/SDL_video.c	Tue Jul 25 06:22:42 2006 +0000
     5.3 @@ -2131,6 +2131,7 @@
     5.4  int
     5.5  SDL_GL_SetAttribute(SDL_GLattr attr, int value)
     5.6  {
     5.7 +#if SDL_VIDEO_OPENGL
     5.8      int retval;
     5.9  
    5.10      if (!_this) {
    5.11 @@ -2194,26 +2195,101 @@
    5.12          break;
    5.13      }
    5.14      return retval;
    5.15 +#else
    5.16 +    SDL_Unsupported();
    5.17 +    return -1;
    5.18 +#endif /* SDL_VIDEO_OPENGL */
    5.19  }
    5.20  
    5.21  int
    5.22 -SDL_GL_GetWindowAttribute(SDL_WindowID windowID, SDL_GLattr attr, int *value)
    5.23 +SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
    5.24  {
    5.25 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
    5.26 -    int retval;
    5.27 +#if SDL_VIDEO_OPENGL
    5.28 +    void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
    5.29 +    GLenum attrib = 0;
    5.30  
    5.31 -    if (!window) {
    5.32 +    glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
    5.33 +    if (!glGetIntegervFunc) {
    5.34 +        return -1;
    5.35 +    }
    5.36 +    switch (attr) {
    5.37 +    case SDL_GL_RED_SIZE:
    5.38 +        attrib = GL_RED_BITS;
    5.39 +        break;
    5.40 +    case SDL_GL_BLUE_SIZE:
    5.41 +        attrib = GL_BLUE_BITS;
    5.42 +        break;
    5.43 +    case SDL_GL_GREEN_SIZE:
    5.44 +        attrib = GL_GREEN_BITS;
    5.45 +        break;
    5.46 +    case SDL_GL_ALPHA_SIZE:
    5.47 +        attrib = GL_ALPHA_BITS;
    5.48 +        break;
    5.49 +    case SDL_GL_DOUBLEBUFFER:
    5.50 +        attrib = GL_DOUBLEBUFFER;
    5.51 +        break;
    5.52 +    case SDL_GL_DEPTH_SIZE:
    5.53 +        attrib = GL_DEPTH_BITS;
    5.54 +        break;
    5.55 +    case SDL_GL_STENCIL_SIZE:
    5.56 +        attrib = GL_STENCIL_BITS;
    5.57 +        break;
    5.58 +    case SDL_GL_ACCUM_RED_SIZE:
    5.59 +        attrib = GL_ACCUM_RED_BITS;
    5.60 +        break;
    5.61 +    case SDL_GL_ACCUM_GREEN_SIZE:
    5.62 +        attrib = GL_ACCUM_GREEN_BITS;
    5.63 +        break;
    5.64 +    case SDL_GL_ACCUM_BLUE_SIZE:
    5.65 +        attrib = GL_ACCUM_BLUE_BITS;
    5.66 +        break;
    5.67 +    case SDL_GL_ACCUM_ALPHA_SIZE:
    5.68 +        attrib = GL_ACCUM_ALPHA_BITS;
    5.69 +        break;
    5.70 +    case SDL_GL_STEREO:
    5.71 +        attrib = GL_STEREO;
    5.72 +        break;
    5.73 +    case SDL_GL_MULTISAMPLEBUFFERS:
    5.74 +        attrib = GL_SAMPLE_BUFFERS_ARB;
    5.75 +        break;
    5.76 +    case SDL_GL_MULTISAMPLESAMPLES:
    5.77 +        attrib = GL_SAMPLES_ARB;
    5.78 +        break;
    5.79 +    case SDL_GL_BUFFER_SIZE:
    5.80 +        {
    5.81 +            GLint bits = 0;
    5.82 +            GLint component;
    5.83 +
    5.84 +            /* there doesn't seem to be a single flag in OpenGL for this! */
    5.85 +            glGetIntegerv(GL_RED_BITS, &component);
    5.86 +            bits += component;
    5.87 +            glGetIntegerv(GL_GREEN_BITS, &component);
    5.88 +            bits += component;
    5.89 +            glGetIntegerv(GL_BLUE_BITS, &component);
    5.90 +            bits += component;
    5.91 +            glGetIntegerv(GL_ALPHA_BITS, &component);
    5.92 +            bits += component;
    5.93 +
    5.94 +            *value = bits;
    5.95 +            return 0;
    5.96 +        }
    5.97 +    case SDL_GL_ACCELERATED_VISUAL:
    5.98 +        {
    5.99 +            /* FIXME: How do we get this information? */
   5.100 +            *value = (_this->gl_config.accelerated != 0);
   5.101 +            return 0;
   5.102 +        }
   5.103 +    default:
   5.104 +        SDL_SetError("Unknown OpenGL attribute");
   5.105          return -1;
   5.106      }
   5.107  
   5.108 -    if (_this->GL_GetWindowAttribute) {
   5.109 -        retval = _this->GL_GetWindowAttribute(_this, window, attr, value);
   5.110 -    } else {
   5.111 -        *value = 0;
   5.112 -        SDL_SetError("GL_GetWindowAttribute not supported");
   5.113 -        retval = -1;
   5.114 -    }
   5.115 -    return retval;
   5.116 +    glGetIntegerv(attrib, (GLint *) value);
   5.117 +    return 0;
   5.118 +#else
   5.119 +    SDL_Unsupported();
   5.120 +    return -1;
   5.121 +#endif /* SDL_VIDEO_OPENGL */
   5.122  }
   5.123  
   5.124  SDL_GLContext
   5.125 @@ -2240,6 +2316,9 @@
   5.126          SDL_SetError("The specified window isn't an OpenGL window");
   5.127          return -1;
   5.128      }
   5.129 +    if (!context) {
   5.130 +        window = NULL;
   5.131 +    }
   5.132      return _this->GL_MakeCurrent(_this, window, context);
   5.133  }
   5.134  
   5.135 @@ -2296,6 +2375,7 @@
   5.136      if (!_this || !context) {
   5.137          return;
   5.138      }
   5.139 +    _this->GL_MakeCurrent(_this, NULL, NULL);
   5.140      _this->GL_DeleteContext(_this, context);
   5.141  }
   5.142  
     6.1 --- a/src/video/cocoa/SDL_cocoaevents.m	Mon Jul 24 23:30:14 2006 +0000
     6.2 +++ b/src/video/cocoa/SDL_cocoaevents.m	Tue Jul 25 06:22:42 2006 +0000
     6.3 @@ -30,20 +30,11 @@
     6.4  @end
     6.5  #endif
     6.6  
     6.7 -@interface SDLApplication : NSApplication
     6.8 +@implementation NSApplication(SDL)
     6.9 +- (void)setRunning
    6.10  {
    6.11 -}
    6.12 -- (void)finishLaunching;
    6.13 -@end
    6.14 -
    6.15 -@implementation SDLApplication
    6.16 -
    6.17 -- (void)finishLaunching
    6.18 -{
    6.19 -    [super finishLaunching];
    6.20      _running = 1;
    6.21  }
    6.22 -
    6.23  @end
    6.24  
    6.25  static NSString *
    6.26 @@ -141,13 +132,14 @@
    6.27  
    6.28      pool = [[NSAutoreleasePool alloc] init];
    6.29      if (NSApp == nil) {
    6.30 -        [SDLApplication sharedApplication];
    6.31 +        [NSApplication sharedApplication];
    6.32  
    6.33          if ([NSApp mainMenu] == nil) {
    6.34              CreateApplicationMenus();
    6.35          }
    6.36          [NSApp finishLaunching];
    6.37      }
    6.38 +    [NSApp setRunning];
    6.39      [pool release];
    6.40  }
    6.41  
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/video/cocoa/SDL_cocoaopengl.h	Tue Jul 25 06:22:42 2006 +0000
     7.3 @@ -0,0 +1,51 @@
     7.4 +/*
     7.5 +    SDL - Simple DirectMedia Layer
     7.6 +    Copyright (C) 1997-2006 Sam Lantinga
     7.7 +
     7.8 +    This library is free software; you can redistribute it and/or
     7.9 +    modify it under the terms of the GNU Lesser General Public
    7.10 +    License as published by the Free Software Foundation; either
    7.11 +    version 2.1 of the License, or (at your option) any later version.
    7.12 +
    7.13 +    This library is distributed in the hope that it will be useful,
    7.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 +    Lesser General Public License for more details.
    7.17 +
    7.18 +    You should have received a copy of the GNU Lesser General Public
    7.19 +    License along with this library; if not, write to the Free Software
    7.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    7.21 +
    7.22 +    Sam Lantinga
    7.23 +    slouken@libsdl.org
    7.24 +*/
    7.25 +#include "SDL_config.h"
    7.26 +
    7.27 +#ifndef _SDL_cocoaopengl_h
    7.28 +#define _SDL_cocoaopengl_h
    7.29 +
    7.30 +#if SDL_VIDEO_OPENGL
    7.31 +
    7.32 +struct SDL_GLDriverData
    7.33 +{
    7.34 +    int initialized;
    7.35 +};
    7.36 +
    7.37 +/* OpenGL functions */
    7.38 +extern int Cocoa_GL_LoadLibrary(_THIS, const char *path);
    7.39 +extern void *Cocoa_GL_GetProcAddress(_THIS, const char *proc);
    7.40 +extern int Cocoa_GL_SetupWindow(_THIS, SDL_Window * window);
    7.41 +extern void Cocoa_GL_CleanupWindow(_THIS, SDL_Window * window);
    7.42 +extern SDL_GLContext Cocoa_GL_CreateContext(_THIS, SDL_Window * window);
    7.43 +extern int Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window,
    7.44 +                                SDL_GLContext context);
    7.45 +extern int Cocoa_GL_SetSwapInterval(_THIS, int interval);
    7.46 +extern int Cocoa_GL_GetSwapInterval(_THIS);
    7.47 +extern void Cocoa_GL_SwapWindow(_THIS, SDL_Window * window);
    7.48 +extern void Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context);
    7.49 +
    7.50 +#endif /* SDL_VIDEO_OPENGL */
    7.51 +
    7.52 +#endif /* _SDL_cocoaopengl_h */
    7.53 +
    7.54 +/* vi: set ts=4 sw=4 expandtab: */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/video/cocoa/SDL_cocoaopengl.m	Tue Jul 25 06:22:42 2006 +0000
     8.3 @@ -0,0 +1,357 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 1997-2006 Sam Lantinga
     8.7 +
     8.8 +    This library is free software; you can redistribute it and/or
     8.9 +    modify it under the terms of the GNU Lesser General Public
    8.10 +    License as published by the Free Software Foundation; either
    8.11 +    version 2.1 of the License, or (at your option) any later version.
    8.12 +
    8.13 +    This library is distributed in the hope that it will be useful,
    8.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +    Lesser General Public License for more details.
    8.17 +
    8.18 +    You should have received a copy of the GNU Lesser General Public
    8.19 +    License along with this library; if not, write to the Free Software
    8.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    8.21 +
    8.22 +    Sam Lantinga
    8.23 +    slouken@libsdl.org
    8.24 +*/
    8.25 +#include "SDL_config.h"
    8.26 +
    8.27 +#include "SDL_cocoavideo.h"
    8.28 +
    8.29 +/* NSOpenGL implementation of SDL OpenGL support */
    8.30 +
    8.31 +#if SDL_VIDEO_OPENGL
    8.32 +#include <OpenGL/CGLTypes.h>
    8.33 +
    8.34 +#include "SDL_loadso.h"
    8.35 +#include "SDL_opengl.h"
    8.36 +
    8.37 +
    8.38 +#define DEFAULT_OPENGL_PATH  "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
    8.39 +
    8.40 +/* This is implemented in Mac OS X 10.3 and above */
    8.41 +#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
    8.42 +@implementation NSOpenGLContext(CGLContextAccess)
    8.43 +- (CGLContextObj)CGLContextObj;
    8.44 +{
    8.45 +    return _contextAuxiliary;
    8.46 +}
    8.47 +@end
    8.48 +#endif /* < 10.3 */
    8.49 +
    8.50 +int
    8.51 +Cocoa_GL_LoadLibrary(_THIS, const char *path)
    8.52 +{
    8.53 +    if (_this->gl_config.driver_loaded) {
    8.54 +        if (path) {
    8.55 +            SDL_SetError("OpenGL library already loaded");
    8.56 +            return -1;
    8.57 +        } else {
    8.58 +            ++_this->gl_config.driver_loaded;
    8.59 +            return 0;
    8.60 +        }
    8.61 +    }
    8.62 +    if (path == NULL) {
    8.63 +        path = DEFAULT_OPENGL_PATH;
    8.64 +    }
    8.65 +    _this->gl_config.dll_handle = SDL_LoadObject(path);
    8.66 +    if (!_this->gl_config.dll_handle) {
    8.67 +        return -1;
    8.68 +    }
    8.69 +    SDL_strlcpy(_this->gl_config.driver_path, path,
    8.70 +                SDL_arraysize(_this->gl_config.driver_path));
    8.71 +    _this->gl_config.driver_loaded = 1;
    8.72 +    return 0;
    8.73 +}
    8.74 +
    8.75 +void *
    8.76 +Cocoa_GL_GetProcAddress(_THIS, const char *proc)
    8.77 +{
    8.78 +    return SDL_LoadFunction(_this->gl_config.dll_handle, proc);
    8.79 +}
    8.80 +
    8.81 +static void
    8.82 +Cocoa_GL_UnloadLibrary(_THIS)
    8.83 +{
    8.84 +    if (_this->gl_config.driver_loaded > 0) {
    8.85 +        if (--_this->gl_config.driver_loaded > 0) {
    8.86 +            return;
    8.87 +        }
    8.88 +        SDL_UnloadObject(_this->gl_config.dll_handle);
    8.89 +        _this->gl_config.dll_handle = NULL;
    8.90 +    }
    8.91 +}
    8.92 +
    8.93 +static void
    8.94 +Cocoa_GL_Shutdown(_THIS)
    8.95 +{
    8.96 +    if (!_this->gl_data || (--_this->gl_data->initialized > 0)) {
    8.97 +        return;
    8.98 +    }
    8.99 +
   8.100 +    Cocoa_GL_UnloadLibrary(_this);
   8.101 +
   8.102 +    SDL_free(_this->gl_data);
   8.103 +    _this->gl_data = NULL;
   8.104 +}
   8.105 +
   8.106 +static int
   8.107 +Cocoa_GL_Initialize(_THIS)
   8.108 +{
   8.109 +    if (_this->gl_data) {
   8.110 +        ++_this->gl_data->initialized;
   8.111 +        return 0;
   8.112 +    }
   8.113 +
   8.114 +    _this->gl_data =
   8.115 +        (struct SDL_GLDriverData *) SDL_calloc(1,
   8.116 +                                               sizeof(struct
   8.117 +                                                      SDL_GLDriverData));
   8.118 +    if (!_this->gl_data) {
   8.119 +        SDL_OutOfMemory();
   8.120 +        return -1;
   8.121 +    }
   8.122 +    _this->gl_data->initialized = 1;
   8.123 +
   8.124 +    if (Cocoa_GL_LoadLibrary(_this, NULL) < 0) {
   8.125 +        return -1;
   8.126 +    }
   8.127 +    return 0;
   8.128 +}
   8.129 +
   8.130 +int
   8.131 +Cocoa_GL_SetupWindow(_THIS, SDL_Window * window)
   8.132 +{
   8.133 +    if (Cocoa_GL_Initialize(_this) < 0) {
   8.134 +        return -1;
   8.135 +    }
   8.136 +    return 0;
   8.137 +}
   8.138 +
   8.139 +void
   8.140 +Cocoa_GL_CleanupWindow(_THIS, SDL_Window * window)
   8.141 +{
   8.142 +    Cocoa_GL_Shutdown(_this);
   8.143 +}
   8.144 +
   8.145 +SDL_GLContext
   8.146 +Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
   8.147 +{
   8.148 +    NSAutoreleasePool *pool;
   8.149 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   8.150 +    SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
   8.151 +    NSOpenGLPixelFormatAttribute attr[32];
   8.152 +    NSOpenGLPixelFormat *fmt;
   8.153 +    NSOpenGLContext *nscontext;
   8.154 +    int i = 0;
   8.155 +
   8.156 +    pool = [[NSAutoreleasePool alloc] init];
   8.157 +
   8.158 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   8.159 +        attr[i++] = NSOpenGLPFAFullScreen;
   8.160 +    }
   8.161 +
   8.162 +    attr[i++] = NSOpenGLPFAColorSize;
   8.163 +    attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
   8.164 +
   8.165 +    attr[i++] = NSOpenGLPFADepthSize;
   8.166 +    attr[i++] = _this->gl_config.depth_size;
   8.167 +
   8.168 +    if (_this->gl_config.double_buffer) {
   8.169 +        attr[i++] = NSOpenGLPFADoubleBuffer;
   8.170 +    }
   8.171 +
   8.172 +    if (_this->gl_config.stereo) {
   8.173 +        attr[i++] = NSOpenGLPFAStereo;
   8.174 +    }
   8.175 +
   8.176 +    if (_this->gl_config.stencil_size) {
   8.177 +        attr[i++] = NSOpenGLPFAStencilSize;
   8.178 +        attr[i++] = _this->gl_config.stencil_size;
   8.179 +    }
   8.180 +
   8.181 +    if ((_this->gl_config.accum_red_size +
   8.182 +         _this->gl_config.accum_green_size +
   8.183 +         _this->gl_config.accum_blue_size +
   8.184 +         _this->gl_config.accum_alpha_size) > 0) {
   8.185 +        attr[i++] = NSOpenGLPFAAccumSize;
   8.186 +        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;
   8.187 +    }
   8.188 +
   8.189 +    if (_this->gl_config.multisamplebuffers) {
   8.190 +        attr[i++] = NSOpenGLPFASampleBuffers;
   8.191 +        attr[i++] = _this->gl_config.multisamplebuffers;
   8.192 +    }
   8.193 +
   8.194 +    if (_this->gl_config.multisamplesamples) {
   8.195 +        attr[i++] = NSOpenGLPFASamples;
   8.196 +        attr[i++] = _this->gl_config.multisamplesamples;
   8.197 +        attr[i++] = NSOpenGLPFANoRecovery;
   8.198 +    }
   8.199 +
   8.200 +    if (_this->gl_config.accelerated > 0) {
   8.201 +        attr[i++] = NSOpenGLPFAAccelerated;
   8.202 +    }
   8.203 +
   8.204 +    attr[i++] = NSOpenGLPFAScreenMask;
   8.205 +    attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
   8.206 +    attr[i] = 0;
   8.207 +
   8.208 +    fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
   8.209 +    if (fmt == nil) {
   8.210 +        SDL_SetError ("Failed creating OpenGL pixel format");
   8.211 +        [pool release];
   8.212 +        return NULL;
   8.213 +    }
   8.214 +
   8.215 +    nscontext = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
   8.216 +
   8.217 +    [fmt release];
   8.218 +
   8.219 +    if (nscontext == nil) {
   8.220 +        SDL_SetError ("Failed creating OpenGL context");
   8.221 +        [pool release];
   8.222 +        return NULL;
   8.223 +    }
   8.224 +
   8.225 +    /*
   8.226 +     * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
   8.227 +     *  "You are blowing a couple of the internal OpenGL function caches. This
   8.228 +     *  appears to be happening in the VAO case.  You can tell OpenGL to up
   8.229 +     *  the cache size by issuing the following calls right after you create
   8.230 +     *  the OpenGL context.  The default cache size is 16."    --ryan.
   8.231 +     */
   8.232 +
   8.233 +    #ifndef GLI_ARRAY_FUNC_CACHE_MAX
   8.234 +    #define GLI_ARRAY_FUNC_CACHE_MAX 284
   8.235 +    #endif
   8.236 +
   8.237 +    #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
   8.238 +    #define GLI_SUBMIT_FUNC_CACHE_MAX 280
   8.239 +    #endif
   8.240 +
   8.241 +    {
   8.242 +        long cache_max = 64;
   8.243 +        CGLContextObj ctx = [nscontext CGLContextObj];
   8.244 +        CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
   8.245 +        CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
   8.246 +    }
   8.247 +
   8.248 +    /* End Wisdom from Apple Engineer section. --ryan. */
   8.249 +
   8.250 +    /* FIXME: should this go somewhere else? */
   8.251 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   8.252 +        [nscontext setFullScreen];
   8.253 +    }
   8.254 +
   8.255 +    [pool release];
   8.256 +    return nscontext;
   8.257 +}
   8.258 +
   8.259 +int
   8.260 +Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
   8.261 +{
   8.262 +    NSAutoreleasePool *pool;
   8.263 +
   8.264 +    pool = [[NSAutoreleasePool alloc] init];
   8.265 +
   8.266 +    if (context) {
   8.267 +        SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
   8.268 +        NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
   8.269 +
   8.270 +        [nscontext setView:[windowdata->window contentView]];
   8.271 +        [nscontext makeCurrentContext];
   8.272 +    } else {
   8.273 +        [NSOpenGLContext clearCurrentContext];
   8.274 +    }
   8.275 +
   8.276 +    [pool release];
   8.277 +    return 0;
   8.278 +}
   8.279 +
   8.280 +int
   8.281 +Cocoa_GL_SetSwapInterval(_THIS, int interval)
   8.282 +{
   8.283 +    NSAutoreleasePool *pool;
   8.284 +    NSOpenGLContext *nscontext;
   8.285 +    long value;
   8.286 +    int status;
   8.287 +
   8.288 +    pool = [[NSAutoreleasePool alloc] init];
   8.289 +
   8.290 +    nscontext = [NSOpenGLContext currentContext];
   8.291 +    if (nscontext != nil) {
   8.292 +        value = interval;
   8.293 +        [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
   8.294 +        status = 0;
   8.295 +    } else {
   8.296 +        SDL_SetError("No current OpenGL context");
   8.297 +        status = -1;
   8.298 +    }
   8.299 +
   8.300 +    [pool release];
   8.301 +    return status;
   8.302 +}
   8.303 +
   8.304 +int
   8.305 +Cocoa_GL_GetSwapInterval(_THIS)
   8.306 +{
   8.307 +    NSAutoreleasePool *pool;
   8.308 +    NSOpenGLContext *nscontext;
   8.309 +    long value;
   8.310 +    int status;
   8.311 +
   8.312 +    pool = [[NSAutoreleasePool alloc] init];
   8.313 +
   8.314 +    nscontext = [NSOpenGLContext currentContext];
   8.315 +    if (nscontext != nil) {
   8.316 +        [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
   8.317 +        status = (int)value;
   8.318 +    } else {
   8.319 +        SDL_SetError("No current OpenGL context");
   8.320 +        status = -1;
   8.321 +    }
   8.322 +
   8.323 +    [pool release];
   8.324 +    return status;
   8.325 +}
   8.326 +
   8.327 +void
   8.328 +Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
   8.329 +{
   8.330 +    NSAutoreleasePool *pool;
   8.331 +    NSOpenGLContext *nscontext;
   8.332 +
   8.333 +    pool = [[NSAutoreleasePool alloc] init];
   8.334 +
   8.335 +    /* FIXME: Do we need to get the context for the window? */
   8.336 +    nscontext = [NSOpenGLContext currentContext];
   8.337 +    if (nscontext != nil) {
   8.338 +        [nscontext flushBuffer];
   8.339 +    }
   8.340 +
   8.341 +    [pool release];
   8.342 +}
   8.343 +
   8.344 +void
   8.345 +Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
   8.346 +{
   8.347 +    NSAutoreleasePool *pool;
   8.348 +    NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
   8.349 +
   8.350 +    pool = [[NSAutoreleasePool alloc] init];
   8.351 +
   8.352 +    [nscontext clearDrawable];
   8.353 +    [nscontext release];
   8.354 +
   8.355 +    [pool release];
   8.356 +}
   8.357 +
   8.358 +#endif /* SDL_VIDEO_OPENGL */
   8.359 +
   8.360 +/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- a/src/video/cocoa/SDL_cocoavideo.h	Mon Jul 24 23:30:14 2006 +0000
     9.2 +++ b/src/video/cocoa/SDL_cocoavideo.h	Tue Jul 25 06:22:42 2006 +0000
     9.3 @@ -33,9 +33,7 @@
     9.4  #include "SDL_cocoakeyboard.h"
     9.5  #include "SDL_cocoamodes.h"
     9.6  #include "SDL_cocoamouse.h"
     9.7 -/*
     9.8  #include "SDL_cocoaopengl.h"
     9.9 -*/
    9.10  #include "SDL_cocoawindow.h"
    9.11  
    9.12  /* Private display data */
    10.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Mon Jul 24 23:30:14 2006 +0000
    10.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Tue Jul 25 06:22:42 2006 +0000
    10.3 @@ -87,11 +87,9 @@
    10.4      device->SetWindowGrab = Cocoa_SetWindowGrab;
    10.5      device->DestroyWindow = Cocoa_DestroyWindow;
    10.6      device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
    10.7 -    /*
    10.8  #ifdef SDL_VIDEO_OPENGL
    10.9      device->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
   10.10      device->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
   10.11 -    device->GL_GetWindowAttribute = Cocoa_GL_GetWindowAttribute;
   10.12      device->GL_CreateContext = Cocoa_GL_CreateContext;
   10.13      device->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
   10.14      device->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
   10.15 @@ -99,7 +97,6 @@
   10.16      device->GL_SwapWindow = Cocoa_GL_SwapWindow;
   10.17      device->GL_DeleteContext = Cocoa_GL_DeleteContext;
   10.18  #endif
   10.19 -    */
   10.20  
   10.21      device->free = Cocoa_DeleteDevice;
   10.22  
    11.1 --- a/src/video/cocoa/SDL_cocoawindow.h	Mon Jul 24 23:30:14 2006 +0000
    11.2 +++ b/src/video/cocoa/SDL_cocoawindow.h	Tue Jul 25 06:22:42 2006 +0000
    11.3 @@ -26,6 +26,7 @@
    11.4  
    11.5  typedef struct SDL_WindowData SDL_WindowData;
    11.6  
    11.7 +/* *INDENT-OFF* */
    11.8  @interface Cocoa_WindowListener:NSResponder {
    11.9      SDL_WindowData *_data;
   11.10  }
   11.11 @@ -58,7 +59,10 @@
   11.12  -(void) mouseExited:(NSEvent *) theEvent;
   11.13  -(void) keyDown:(NSEvent *) theEvent;
   11.14  -(void) keyUp:(NSEvent *) theEvent;
   11.15 -@end struct SDL_WindowData
   11.16 +@end
   11.17 +/* *INDENT-ON* */
   11.18 +
   11.19 +struct SDL_WindowData
   11.20  {
   11.21      SDL_WindowID windowID;
   11.22      NSWindow *window;
    12.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Jul 24 23:30:14 2006 +0000
    12.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Tue Jul 25 06:22:42 2006 +0000
    12.3 @@ -31,6 +31,7 @@
    12.4  
    12.5  static __inline__ void ConvertNSRect(NSRect *r)
    12.6  {
    12.7 +    /* FIXME: Cache the display used for this window */
    12.8      r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
    12.9  }
   12.10  
   12.11 @@ -325,6 +326,7 @@
   12.12      NSRect rect;
   12.13      unsigned int style;
   12.14      NSString *title;
   12.15 +    int status;
   12.16  
   12.17      pool = [[NSAutoreleasePool alloc] init];
   12.18  
   12.19 @@ -380,18 +382,15 @@
   12.20  
   12.21      if (SetupWindowData(window, nswindow, YES) < 0) {
   12.22          [nswindow release];
   12.23 -        [pool release];
   12.24          return -1;
   12.25      }
   12.26  #ifdef SDL_VIDEO_OPENGL
   12.27 -    /*
   12.28      if (window->flags & SDL_WINDOW_OPENGL) {
   12.29          if (Cocoa_GL_SetupWindow(_this, window) < 0) {
   12.30              Cocoa_DestroyWindow(_this, window);
   12.31              return -1;
   12.32          }
   12.33      }
   12.34 -    */
   12.35  #endif
   12.36      return 0;
   12.37  }
   12.38 @@ -522,11 +521,9 @@
   12.39      if (data) {
   12.40          NSAutoreleasePool *pool;
   12.41  #ifdef SDL_VIDEO_OPENGL
   12.42 -        /*
   12.43          if (window->flags & SDL_WINDOW_OPENGL) {
   12.44              Cocoa_GL_CleanupWindow(_this, window);
   12.45          }
   12.46 -        */
   12.47  #endif
   12.48          pool = [[NSAutoreleasePool alloc] init];
   12.49          [data->listener close];
    13.1 --- a/src/video/win32/SDL_win32opengl.c	Mon Jul 24 23:30:14 2006 +0000
    13.2 +++ b/src/video/win32/SDL_win32opengl.c	Tue Jul 25 06:22:42 2006 +0000
    13.3 @@ -28,7 +28,7 @@
    13.4  #if SDL_VIDEO_OPENGL
    13.5  #include "SDL_opengl.h"
    13.6  
    13.7 -#define DEFAULT_GL_DRIVER_PATH "OPENGL32.DLL"
    13.8 +#define DEFAULT_OPENGL_PATH "OPENGL32.DLL"
    13.9  
   13.10  
   13.11  int
   13.12 @@ -47,7 +47,7 @@
   13.13          }
   13.14      }
   13.15      if (path == NULL) {
   13.16 -        path = DEFAULT_GL_DRIVER_PATH;
   13.17 +        path = DEFAULT_OPENGL_PATH;
   13.18      }
   13.19      wpath = WIN_UTF8ToString(path);
   13.20      handle = LoadLibrary(wpath);
   13.21 @@ -414,153 +414,6 @@
   13.22      WIN_GL_Shutdown(_this);
   13.23  }
   13.24  
   13.25 -int
   13.26 -WIN_GL_GetWindowAttribute(_THIS, SDL_Window * window, SDL_GLattr attrib,
   13.27 -                          int *value)
   13.28 -{
   13.29 -    HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
   13.30 -    int pixel_format;
   13.31 -
   13.32 -    pixel_format = GetPixelFormat(hdc);
   13.33 -
   13.34 -    if (_this->gl_data->WGL_ARB_pixel_format) {
   13.35 -        int wgl_attrib;
   13.36 -
   13.37 -        switch (attrib) {
   13.38 -        case SDL_GL_RED_SIZE:
   13.39 -            wgl_attrib = WGL_RED_BITS_ARB;
   13.40 -            break;
   13.41 -        case SDL_GL_GREEN_SIZE:
   13.42 -            wgl_attrib = WGL_GREEN_BITS_ARB;
   13.43 -            break;
   13.44 -        case SDL_GL_BLUE_SIZE:
   13.45 -            wgl_attrib = WGL_BLUE_BITS_ARB;
   13.46 -            break;
   13.47 -        case SDL_GL_ALPHA_SIZE:
   13.48 -            wgl_attrib = WGL_ALPHA_BITS_ARB;
   13.49 -            break;
   13.50 -        case SDL_GL_DOUBLEBUFFER:
   13.51 -            wgl_attrib = WGL_DOUBLE_BUFFER_ARB;
   13.52 -            break;
   13.53 -        case SDL_GL_BUFFER_SIZE:
   13.54 -            wgl_attrib = WGL_COLOR_BITS_ARB;
   13.55 -            break;
   13.56 -        case SDL_GL_DEPTH_SIZE:
   13.57 -            wgl_attrib = WGL_DEPTH_BITS_ARB;
   13.58 -            break;
   13.59 -        case SDL_GL_STENCIL_SIZE:
   13.60 -            wgl_attrib = WGL_STENCIL_BITS_ARB;
   13.61 -            break;
   13.62 -        case SDL_GL_ACCUM_RED_SIZE:
   13.63 -            wgl_attrib = WGL_ACCUM_RED_BITS_ARB;
   13.64 -            break;
   13.65 -        case SDL_GL_ACCUM_GREEN_SIZE:
   13.66 -            wgl_attrib = WGL_ACCUM_GREEN_BITS_ARB;
   13.67 -            break;
   13.68 -        case SDL_GL_ACCUM_BLUE_SIZE:
   13.69 -            wgl_attrib = WGL_ACCUM_BLUE_BITS_ARB;
   13.70 -            break;
   13.71 -        case SDL_GL_ACCUM_ALPHA_SIZE:
   13.72 -            wgl_attrib = WGL_ACCUM_ALPHA_BITS_ARB;
   13.73 -            break;
   13.74 -        case SDL_GL_STEREO:
   13.75 -            wgl_attrib = WGL_STEREO_ARB;
   13.76 -            break;
   13.77 -        case SDL_GL_MULTISAMPLEBUFFERS:
   13.78 -            wgl_attrib = WGL_SAMPLE_BUFFERS_ARB;
   13.79 -            break;
   13.80 -        case SDL_GL_MULTISAMPLESAMPLES:
   13.81 -            wgl_attrib = WGL_SAMPLES_ARB;
   13.82 -            break;
   13.83 -        case SDL_GL_ACCELERATED_VISUAL:
   13.84 -            wgl_attrib = WGL_ACCELERATION_ARB;
   13.85 -            _this->gl_data->wglGetPixelFormatAttribivARB(hdc, pixel_format, 0,
   13.86 -                                                         1, &wgl_attrib,
   13.87 -                                                         value);
   13.88 -            if (*value == WGL_NO_ACCELERATION_ARB) {
   13.89 -                *value = SDL_FALSE;
   13.90 -            } else {
   13.91 -                *value = SDL_TRUE;
   13.92 -            }
   13.93 -            return 0;
   13.94 -            break;
   13.95 -        default:
   13.96 -            return (-1);
   13.97 -        }
   13.98 -        _this->gl_data->wglGetPixelFormatAttribivARB(hdc, pixel_format, 0, 1,
   13.99 -                                                     &wgl_attrib, value);
  13.100 -        return 0;
  13.101 -    } else {
  13.102 -        PIXELFORMATDESCRIPTOR pfd;
  13.103 -        int retval;
  13.104 -
  13.105 -        if (!DescribePixelFormat(hdc, pixel_format, sizeof(pfd), &pfd)) {
  13.106 -            WIN_SetError("DescribePixelFormat()");
  13.107 -            return -1;
  13.108 -        }
  13.109 -        retval = 0;
  13.110 -        switch (attrib) {
  13.111 -        case SDL_GL_RED_SIZE:
  13.112 -            *value = pfd.cRedBits;
  13.113 -            break;
  13.114 -        case SDL_GL_GREEN_SIZE:
  13.115 -            *value = pfd.cGreenBits;
  13.116 -            break;
  13.117 -        case SDL_GL_BLUE_SIZE:
  13.118 -            *value = pfd.cBlueBits;
  13.119 -            break;
  13.120 -        case SDL_GL_ALPHA_SIZE:
  13.121 -            *value = pfd.cAlphaBits;
  13.122 -            break;
  13.123 -        case SDL_GL_DOUBLEBUFFER:
  13.124 -            if (pfd.dwFlags & PFD_DOUBLEBUFFER) {
  13.125 -                *value = 1;
  13.126 -            } else {
  13.127 -                *value = 0;
  13.128 -            }
  13.129 -            break;
  13.130 -        case SDL_GL_BUFFER_SIZE:
  13.131 -            *value = pfd.cColorBits;
  13.132 -            break;
  13.133 -        case SDL_GL_DEPTH_SIZE:
  13.134 -            *value = pfd.cDepthBits;
  13.135 -            break;
  13.136 -        case SDL_GL_STENCIL_SIZE:
  13.137 -            *value = pfd.cStencilBits;
  13.138 -            break;
  13.139 -        case SDL_GL_ACCUM_RED_SIZE:
  13.140 -            *value = pfd.cAccumRedBits;
  13.141 -            break;
  13.142 -        case SDL_GL_ACCUM_GREEN_SIZE:
  13.143 -            *value = pfd.cAccumGreenBits;
  13.144 -            break;
  13.145 -        case SDL_GL_ACCUM_BLUE_SIZE:
  13.146 -            *value = pfd.cAccumBlueBits;
  13.147 -            break;
  13.148 -        case SDL_GL_ACCUM_ALPHA_SIZE:
  13.149 -            *value = pfd.cAccumAlphaBits;
  13.150 -            break;
  13.151 -        case SDL_GL_STEREO:
  13.152 -            if (pfd.dwFlags & PFD_STEREO) {
  13.153 -                *value = 1;
  13.154 -            } else {
  13.155 -                *value = 0;
  13.156 -            }
  13.157 -            break;
  13.158 -        case SDL_GL_MULTISAMPLEBUFFERS:
  13.159 -            *value = 0;
  13.160 -            break;
  13.161 -        case SDL_GL_MULTISAMPLESAMPLES:
  13.162 -            *value = 1;
  13.163 -            break;
  13.164 -        default:
  13.165 -            retval = -1;
  13.166 -            break;
  13.167 -        }
  13.168 -        return retval;
  13.169 -    }
  13.170 -}
  13.171 -
  13.172  SDL_GLContext
  13.173  WIN_GL_CreateContext(_THIS, SDL_Window * window)
  13.174  {
  13.175 @@ -623,9 +476,7 @@
  13.176  void
  13.177  WIN_GL_DeleteContext(_THIS, SDL_GLContext context)
  13.178  {
  13.179 -    if (context) {
  13.180 -        _this->gl_data->wglDeleteContext((HGLRC) context);
  13.181 -    }
  13.182 +    _this->gl_data->wglDeleteContext((HGLRC) context);
  13.183  }
  13.184  
  13.185  #endif /* SDL_VIDEO_OPENGL */
    14.1 --- a/src/video/win32/SDL_win32opengl.h	Mon Jul 24 23:30:14 2006 +0000
    14.2 +++ b/src/video/win32/SDL_win32opengl.h	Tue Jul 25 06:22:42 2006 +0000
    14.3 @@ -55,8 +55,6 @@
    14.4  extern void *WIN_GL_GetProcAddress(_THIS, const char *proc);
    14.5  extern int WIN_GL_SetupWindow(_THIS, SDL_Window * window);
    14.6  extern void WIN_GL_CleanupWindow(_THIS, SDL_Window * window);
    14.7 -extern int WIN_GL_GetWindowAttribute(_THIS, SDL_Window * window,
    14.8 -                                     SDL_GLattr attrib, int *value);
    14.9  extern SDL_GLContext WIN_GL_CreateContext(_THIS, SDL_Window * window);
   14.10  extern int WIN_GL_MakeCurrent(_THIS, SDL_Window * window,
   14.11                                SDL_GLContext context);
    15.1 --- a/src/video/win32/SDL_win32video.c	Mon Jul 24 23:30:14 2006 +0000
    15.2 +++ b/src/video/win32/SDL_win32video.c	Tue Jul 25 06:22:42 2006 +0000
    15.3 @@ -126,7 +126,6 @@
    15.4  #ifdef SDL_VIDEO_OPENGL
    15.5      device->GL_LoadLibrary = WIN_GL_LoadLibrary;
    15.6      device->GL_GetProcAddress = WIN_GL_GetProcAddress;
    15.7 -    device->GL_GetWindowAttribute = WIN_GL_GetWindowAttribute;
    15.8      device->GL_CreateContext = WIN_GL_CreateContext;
    15.9      device->GL_MakeCurrent = WIN_GL_MakeCurrent;
   15.10      device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
    16.1 --- a/test/testgl2.c	Mon Jul 24 23:30:14 2006 +0000
    16.2 +++ b/test/testgl2.c	Tue Jul 25 06:22:42 2006 +0000
    16.3 @@ -244,28 +244,25 @@
    16.4      printf("Extensions : %s\n", glGetString(GL_EXTENSIONS));
    16.5      printf("\n");
    16.6  
    16.7 -    SDL_GL_GetWindowAttribute(state->windows[0], SDL_GL_RED_SIZE, &value);
    16.8 +    SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
    16.9      printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
   16.10 -    SDL_GL_GetWindowAttribute(state->windows[0], SDL_GL_GREEN_SIZE, &value);
   16.11 +    SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
   16.12      printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
   16.13 -    SDL_GL_GetWindowAttribute(state->windows[0], SDL_GL_BLUE_SIZE, &value);
   16.14 +    SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
   16.15      printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
   16.16 -    SDL_GL_GetWindowAttribute(state->windows[0], SDL_GL_DEPTH_SIZE, &value);
   16.17 +    SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
   16.18      printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
   16.19 -    SDL_GL_GetWindowAttribute(state->windows[0], SDL_GL_DOUBLEBUFFER, &value);
   16.20 +    SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &value);
   16.21      printf("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value);
   16.22      if (fsaa) {
   16.23 -        SDL_GL_GetWindowAttribute(state->windows[0],
   16.24 -                                  SDL_GL_MULTISAMPLEBUFFERS, &value);
   16.25 +        SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
   16.26          printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
   16.27 -        SDL_GL_GetWindowAttribute(state->windows[0],
   16.28 -                                  SDL_GL_MULTISAMPLESAMPLES, &value);
   16.29 +        SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
   16.30          printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
   16.31                 value);
   16.32      }
   16.33      if (accel) {
   16.34 -        SDL_GL_GetWindowAttribute(state->windows[0],
   16.35 -                                  SDL_GL_ACCELERATED_VISUAL, &value);
   16.36 +        SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
   16.37          printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
   16.38      }
   16.39