Setting up the OpenGL support
authorSam Lantinga <slouken@libsdl.org>
Sun, 16 Jul 2006 09:34:01 +0000
changeset 1912 8d384b647307
parent 1911 7577fd11cee4
child 1913 83420da906a5
Setting up the OpenGL support
include/SDL_compat.h
include/SDL_video.h
src/SDL_compat.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/dummy/SDL_nullrender.c
test/testgl.c
--- a/include/SDL_compat.h	Sun Jul 16 03:35:44 2006 +0000
+++ b/include/SDL_compat.h	Sun Jul 16 09:34:01 2006 +0000
@@ -172,6 +172,7 @@
                                                   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++ */
 #ifdef __cplusplus
--- a/include/SDL_video.h	Sun Jul 16 03:35:44 2006 +0000
+++ b/include/SDL_video.h	Sun Jul 16 09:34:01 2006 +0000
@@ -1499,6 +1499,10 @@
  *
  * \brief Set the swap interval for the current OpenGL context.
  *
+ * \param interval 0 for immediate updates, 1 for updates synchronized with the vertical retrace
+ *
+ * \return 0 on success, or -1 if setting the swap interval is not supported.
+ *
  * \sa SDL_GL_GetSwapInterval()
  */
 extern DECLSPEC int SDLCALL SDL_GL_SetSwapInterval(int interval);
@@ -1508,16 +1512,18 @@
  *
  * \brief Get the swap interval for the current OpenGL context.
  *
+ * \return 0 if there is no vertical retrace synchronization, 1 if the buffer swap is synchronized with the vertical retrace, and -1 if getting the swap interval is not supported.
+ *
  * \sa SDL_GL_SetSwapInterval()
  */
 extern DECLSPEC int SDLCALL SDL_GL_GetSwapInterval(void);
 
 /**
- * \fn void SDL_GL_SwapBuffers(void)
+ * \fn void SDL_GL_SwapWindow(SDL_WindowID windowID)
  *
- * Swap the OpenGL buffers, if double-buffering is supported.
+ * \brief Swap the OpenGL buffers for the window, if double-buffering is supported.
  */
-extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void);
+extern DECLSPEC void SDLCALL SDL_GL_SwapWindow(SDL_WindowID windowID);
 
 /**
  * \fn void SDL_GL_DeleteContext(SDL_GLContext context)
--- a/src/SDL_compat.c	Sun Jul 16 03:35:44 2006 +0000
+++ b/src/SDL_compat.c	Sun Jul 16 09:34:01 2006 +0000
@@ -36,6 +36,7 @@
 static SDL_Surface *SDL_VideoSurface;
 static SDL_Surface *SDL_ShadowSurface;
 static SDL_Surface *SDL_PublicSurface;
+static SDL_GLContext *SDL_VideoContext;
 static char *wm_title;
 
 char *
@@ -335,6 +336,11 @@
         SDL_FreeSurface(SDL_VideoSurface);
         SDL_VideoSurface = NULL;
     }
+    if (SDL_VideoContext) {
+        SDL_GL_MakeCurrent(0, SDL_VideoContext);
+        SDL_GL_DeleteContext(SDL_VideoContext);
+        SDL_VideoContext = NULL;
+    }
     if (SDL_VideoWindow) {
         SDL_GetWindowPosition(SDL_VideoWindow, &window_x, &window_y);
     }
@@ -432,6 +438,13 @@
 
     /* If we're in OpenGL mode, just create a stub surface and we're done! */
     if (flags & SDL_OPENGL) {
+        SDL_VideoContext = SDL_GL_CreateContext(SDL_VideoWindow);
+        if (!SDL_VideoContext) {
+            return NULL;
+        }
+        if (SDL_GL_MakeCurrent(SDL_VideoWindow, SDL_VideoContext) < 0) {
+            return NULL;
+        }
         SDL_VideoSurface =
             SDL_CreateRGBSurfaceFrom(NULL, width, height, bpp, 0, 0, 0, 0, 0);
         if (!SDL_VideoSurface) {
@@ -1418,4 +1431,16 @@
     }
 }
 
+int
+SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
+{
+    return SDL_GL_GetWindowAttribute(SDL_VideoWindow, attr, value);
+}
+
+void
+SDL_GL_SwapBuffers(void)
+{
+    SDL_GL_SwapWindow(SDL_VideoWindow);
+}
+
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/SDL_sysvideo.h	Sun Jul 16 03:35:44 2006 +0000
+++ b/src/video/SDL_sysvideo.h	Sun Jul 16 09:34:01 2006 +0000
@@ -227,36 +227,21 @@
     void (*VideoQuit) (_THIS);
 
     /* * * */
-    /* OpenGL support */
-
-    /* Sets the dll to use for OpenGL and loads it */
+    /* OpenGL support
+     */
     int (*GL_LoadLibrary) (_THIS, const char *path);
-
-    /* Retrieves the address of a function in the gl library */
     void *(*GL_GetProcAddress) (_THIS, const char *proc);
-
-    /* Get attribute information from the windowing system. */
     int (*GL_GetAttribute) (_THIS, SDL_GLattr attrib, int *value);
-
-    /* Make the context associated with this driver current */
-    int (*GL_MakeCurrent) (_THIS);
-
-    /* Swap the current buffers in double buffer mode. */
-    void (*GL_SwapBuffers) (_THIS);
-
-    /* Determine whether the mouse should be in relative mode or not.
-       This function is called when the input grab state or cursor
-       visibility state changes.
-       If the cursor is not visible, and the input is grabbed, the
-       driver can place the mouse in relative mode, which may result
-       in higher accuracy sampling of the pointer motion.
-     */
-    void (*CheckMouseMode) (_THIS);
+      SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
+    int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
+    int (*GL_SetSwapInterval) (_THIS, int interval);
+    int (*GL_GetSwapInterval) (_THIS);
+    void (*GL_SwapWindow) (_THIS, SDL_Window * window);
+    void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
 
     /* * * */
-    /* Event manager functions */
-
-    /* Handle any queued OS events */
+    /* Event manager functions
+     */
     void (*PumpEvents) (_THIS);
 
     /* * * */
@@ -266,8 +251,6 @@
     int current_display;
     Uint32 next_object_id;
 
-    /* Driver information flags */
-
     /* * * */
     /* Data used by the GL drivers */
     struct
--- a/src/video/SDL_video.c	Sun Jul 16 03:35:44 2006 +0000
+++ b/src/video/SDL_video.c	Sun Jul 16 09:34:01 2006 +0000
@@ -153,6 +153,12 @@
     return 0;
 }
 
+static void
+SDL_UninitializedVideo()
+{
+    SDL_SetError("Video subsystem has not been initialized");
+}
+
 int
 SDL_GetNumVideoDrivers(void)
 {
@@ -285,6 +291,7 @@
 SDL_GetCurrentVideoDriver()
 {
     if (!_this) {
+        SDL_UninitializedVideo();
         return NULL;
     }
     return _this->name;
@@ -334,6 +341,7 @@
 SDL_GetNumVideoDisplays(void)
 {
     if (!_this) {
+        SDL_UninitializedVideo();
         return 0;
     }
     return _this->num_displays;
@@ -343,7 +351,7 @@
 SDL_SelectVideoDisplay(int index)
 {
     if (!_this) {
-        SDL_SetError("Video subsystem has not been initialized");
+        SDL_UninitializedVideo();
         return (-1);
     }
     if (index >= 0) {
@@ -535,7 +543,7 @@
     int i, ncolors;
 
     if (!_this) {
-        SDL_SetError("Video subsystem has not been initialized");
+        SDL_UninitializedVideo();
         return -1;
     }
 
@@ -621,7 +629,7 @@
     int i;
 
     if (!_this) {
-        SDL_SetError("Video subsystem has not been initialized");
+        SDL_UninitializedVideo();
         return -1;
     }
 
@@ -659,7 +667,7 @@
     int status = 0;
 
     if (!_this) {
-        SDL_SetError("Video subsystem has not been initialized");
+        SDL_UninitializedVideo();
         return -1;
     }
     palette = SDL_CurrentDisplay.palette;
@@ -684,7 +692,7 @@
     SDL_Palette *palette;
 
     if (!_this) {
-        SDL_SetError("Video subsystem has not been initialized");
+        SDL_UninitializedVideo();
         return -1;
     }
 
@@ -721,7 +729,12 @@
     SDL_Window *windows;
 
     if (!_this) {
-        SDL_SetError("Video subsystem has not been initialized");
+        SDL_UninitializedVideo();
+        return 0;
+    }
+
+    if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
+        SDL_SetError("No OpenGL support in video driver");
         return 0;
     }
 
@@ -783,7 +796,7 @@
     SDL_Window *windows;
 
     if (!_this) {
-        SDL_SetError("Video subsystem has not been initialized");
+        SDL_UninitializedVideo();
         return (0);
     }
 
@@ -822,6 +835,7 @@
     int i, j;
 
     if (!_this) {
+        SDL_UninitializedVideo();
         return NULL;
     }
 
@@ -841,6 +855,7 @@
 SDL_GetDisplayFromWindow(SDL_Window * window)
 {
     if (!_this) {
+        SDL_UninitializedVideo();
         return NULL;
     }
     return &_this->displays[window->display];
@@ -1281,6 +1296,7 @@
 SDL_GetRendererInfo(int index, SDL_RendererInfo * info)
 {
     if (!_this) {
+        SDL_UninitializedVideo();
         return -1;
     }
 
@@ -1374,6 +1390,7 @@
     SDL_Texture *texture;
 
     if (!_this) {
+        SDL_UninitializedVideo();
         return 0;
     }
 
@@ -1752,6 +1769,7 @@
     SDL_Rect real_rect;
 
     if (!_this) {
+        SDL_UninitializedVideo();
         return -1;
     }
 
@@ -1821,6 +1839,7 @@
     SDL_Renderer *renderer;
 
     if (!_this) {
+        SDL_UninitializedVideo();
         return;
     }
 
@@ -1839,6 +1858,7 @@
     SDL_Renderer *renderer;
 
     if (!_this) {
+        SDL_UninitializedVideo();
         return;
     }
 
@@ -1977,21 +1997,21 @@
     _this = NULL;
 }
 
-/* Load the GL driver library */
 int
 SDL_GL_LoadLibrary(const char *path)
 {
     int retval;
 
-    retval = -1;
-    if (_this == NULL) {
-        SDL_SetError("Video subsystem has not been initialized");
+    if (!_this) {
+        SDL_UninitializedVideo();
+        return -1;
+    }
+
+    if (_this->GL_LoadLibrary) {
+        retval = _this->GL_LoadLibrary(_this, path);
     } else {
-        if (_this->GL_LoadLibrary) {
-            retval = _this->GL_LoadLibrary(_this, path);
-        } else {
-            SDL_SetError("No dynamic GL support in video driver");
-        }
+        SDL_SetError("No dynamic GL support in video driver");
+        retval = -1;
     }
     return (retval);
 }
@@ -2001,6 +2021,11 @@
 {
     void *func;
 
+    if (!_this) {
+        SDL_UninitializedVideo();
+        return NULL;
+    }
+
     func = NULL;
     if (_this->GL_GetProcAddress) {
         if (_this->gl_config.driver_loaded) {
@@ -2014,12 +2039,16 @@
     return func;
 }
 
-/* Set the specified GL attribute for setting up a GL video mode */
 int
 SDL_GL_SetAttribute(SDL_GLattr attr, int value)
 {
     int retval;
 
+    if (!_this) {
+        SDL_UninitializedVideo();
+        return -1;
+    }
+
     retval = 0;
     switch (attr) {
     case SDL_GL_RED_SIZE:
@@ -2075,30 +2104,113 @@
         retval = -1;
         break;
     }
-    return (retval);
+    return retval;
 }
 
-/* Retrieve an attribute value from the windowing system. */
 int
-SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
+SDL_GL_GetWindowAttribute(SDL_WindowID windowID, SDL_GLattr attr, int *value)
 {
-    int retval = -1;
+    SDL_Window *window = SDL_GetWindowFromID(windowID);
+    int retval;
+
+    if (!window) {
+        return -1;
+    }
 
     if (_this->GL_GetAttribute) {
         retval = _this->GL_GetAttribute(_this, attr, value);
     } else {
         *value = 0;
         SDL_SetError("GL_GetAttribute not supported");
+        retval = -1;
     }
     return retval;
 }
 
-/* Perform a GL buffer swap on the current GL context */
+SDL_GLContext
+SDL_GL_CreateContext(SDL_WindowID windowID)
+{
+    SDL_Window *window = SDL_GetWindowFromID(windowID);
+
+    if (!window) {
+        return NULL;
+    }
+    if (!(window->flags & SDL_WINDOW_OPENGL)) {
+        SDL_SetError("The specified window isn't an OpenGL window");
+        return NULL;
+    }
+    return _this->GL_CreateContext(_this, window);
+}
+
+int
+SDL_GL_MakeCurrent(SDL_WindowID windowID, SDL_GLContext context)
+{
+    SDL_Window *window = SDL_GetWindowFromID(windowID);
+
+    if (!window || !context) {
+        return -1;
+    }
+    if (!(window->flags & SDL_WINDOW_OPENGL)) {
+        SDL_SetError("The specified window isn't an OpenGL window");
+        return -1;
+    }
+    return _this->GL_MakeCurrent(_this, window, context);
+}
+
+int
+SDL_GL_SetSwapInterval(int interval)
+{
+    if (!_this) {
+        SDL_UninitializedVideo();
+        return -1;
+    }
+
+    if (_this->GL_SetSwapInterval) {
+        return _this->GL_SetSwapInterval(_this, interval);
+    } else {
+        SDL_SetError("Setting the swap interval is not supported");
+        return -1;
+    }
+}
+
+int
+SDL_GL_GetSwapInterval(void)
+{
+    if (!_this) {
+        SDL_UninitializedVideo();
+        return -1;
+    }
+
+    if (_this->GL_GetSwapInterval) {
+        return _this->GL_GetSwapInterval(_this);
+    } else {
+        SDL_SetError("Getting the swap interval is not supported");
+        return -1;
+    }
+}
+
 void
-SDL_GL_SwapBuffers(void)
+SDL_GL_SwapWindow(SDL_WindowID windowID)
 {
-    // FIXME: Track the current window context - do we provide N contexts, and match them to M windows, or is there a one-to-one mapping?
-    _this->GL_SwapBuffers(_this);
+    SDL_Window *window = SDL_GetWindowFromID(windowID);
+
+    if (!window) {
+        return;
+    }
+    if (!(window->flags & SDL_WINDOW_OPENGL)) {
+        SDL_SetError("The specified window isn't an OpenGL window");
+        return;
+    }
+    return _this->GL_SwapWindow(_this, window);
+}
+
+void
+SDL_GL_DeleteContext(SDL_GLContext context)
+{
+    if (!_this || !context) {
+        return;
+    }
+    _this->GL_DeleteContext(_this, context);
 }
 
 #if 0                           // FIXME
--- a/src/video/dummy/SDL_nullrender.c	Sun Jul 16 03:35:44 2006 +0000
+++ b/src/video/dummy/SDL_nullrender.c	Sun Jul 16 09:34:01 2006 +0000
@@ -28,47 +28,51 @@
 
 /* SDL surface based renderer implementation */
 
-static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags);
+static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window,
+                                              Uint32 flags);
 static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer,
-                                SDL_Texture * texture);
+                                   SDL_Texture * texture);
 static int SDL_DUMMY_QueryTexturePixels(SDL_Renderer * renderer,
-                                     SDL_Texture * texture, void **pixels,
-                                     int *pitch);
+                                        SDL_Texture * texture, void **pixels,
+                                        int *pitch);
 static int SDL_DUMMY_SetTexturePalette(SDL_Renderer * renderer,
-                                    SDL_Texture * texture,
-                                    const SDL_Color * colors, int firstcolor,
-                                    int ncolors);
+                                       SDL_Texture * texture,
+                                       const SDL_Color * colors,
+                                       int firstcolor, int ncolors);
 static int SDL_DUMMY_GetTexturePalette(SDL_Renderer * renderer,
-                                    SDL_Texture * texture, SDL_Color * colors,
-                                    int firstcolor, int ncolors);
+                                       SDL_Texture * texture,
+                                       SDL_Color * colors, int firstcolor,
+                                       int ncolors);
 static int SDL_DUMMY_UpdateTexture(SDL_Renderer * renderer,
-                                SDL_Texture * texture, const SDL_Rect * rect,
-                                const void *pixels, int pitch);
-static int SDL_DUMMY_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
-                              const SDL_Rect * rect, int markDirty,
-                              void **pixels, int *pitch);
+                                   SDL_Texture * texture,
+                                   const SDL_Rect * rect, const void *pixels,
+                                   int pitch);
+static int SDL_DUMMY_LockTexture(SDL_Renderer * renderer,
+                                 SDL_Texture * texture, const SDL_Rect * rect,
+                                 int markDirty, void **pixels, int *pitch);
 static void SDL_DUMMY_UnlockTexture(SDL_Renderer * renderer,
-                                 SDL_Texture * texture);
+                                    SDL_Texture * texture);
 static void SDL_DUMMY_DirtyTexture(SDL_Renderer * renderer,
-                                SDL_Texture * texture, int numrects,
-                                const SDL_Rect * rects);
+                                   SDL_Texture * texture, int numrects,
+                                   const SDL_Rect * rects);
 static void SDL_DUMMY_SelectRenderTexture(SDL_Renderer * renderer,
-                                       SDL_Texture * texture);
-static int SDL_DUMMY_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
-                             Uint32 color);
-static int SDL_DUMMY_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
-                             const SDL_Rect * srcrect,
-                             const SDL_Rect * dstrect, int blendMode,
-                             int scaleMode);
+                                          SDL_Texture * texture);
+static int SDL_DUMMY_RenderFill(SDL_Renderer * renderer,
+                                const SDL_Rect * rect, Uint32 color);
+static int SDL_DUMMY_RenderCopy(SDL_Renderer * renderer,
+                                SDL_Texture * texture,
+                                const SDL_Rect * srcrect,
+                                const SDL_Rect * dstrect, int blendMode,
+                                int scaleMode);
 static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer,
-                                   const SDL_Rect * rect, void *pixels,
-                                   int pitch);
+                                      const SDL_Rect * rect, void *pixels,
+                                      int pitch);
 static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer,
-                                    const SDL_Rect * rect, const void *pixels,
-                                    int pitch);
+                                       const SDL_Rect * rect,
+                                       const void *pixels, int pitch);
 static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer);
 static void SDL_DUMMY_DestroyTexture(SDL_Renderer * renderer,
-                                  SDL_Texture * texture);
+                                     SDL_Texture * texture);
 static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer);
 
 
@@ -195,7 +199,9 @@
             return -1;
         }
 
-        texture->driverdata = SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask, Bmask, Amask);
+        texture->driverdata =
+            SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask,
+                                 Bmask, Amask);
     }
 
     if (!texture->driverdata) {
@@ -206,10 +212,11 @@
 
 static int
 SDL_DUMMY_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
-                          void **pixels, int *pitch)
+                             void **pixels, int *pitch)
 {
     if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
-        return SDL_SW_QueryYUVTexturePixels((SDL_SW_YUVTexture *) texture->driverdata, pixels, pitch);
+        return SDL_SW_QueryYUVTexturePixels((SDL_SW_YUVTexture *) texture->
+                                            driverdata, pixels, pitch);
     } else {
         SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
 
@@ -221,8 +228,8 @@
 
 static int
 SDL_DUMMY_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
-                         const SDL_Color * colors, int firstcolor,
-                         int ncolors)
+                            const SDL_Color * colors, int firstcolor,
+                            int ncolors)
 {
     if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
         SDL_SetError("YUV textures don't have a palette");
@@ -237,7 +244,7 @@
 
 static int
 SDL_DUMMY_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
-                         SDL_Color * colors, int firstcolor, int ncolors)
+                            SDL_Color * colors, int firstcolor, int ncolors)
 {
     if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
         SDL_SetError("YUV textures don't have a palette");
@@ -253,7 +260,7 @@
 
 static int
 SDL_DUMMY_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
-                     const SDL_Rect * rect, const void *pixels, int pitch)
+                        const SDL_Rect * rect, const void *pixels, int pitch)
 {
     if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
         return SDL_SW_UpdateYUVTexture((SDL_SW_YUVTexture *) texture->
@@ -280,8 +287,8 @@
 
 static int
 SDL_DUMMY_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
-                   const SDL_Rect * rect, int markDirty, void **pixels,
-                   int *pitch)
+                      const SDL_Rect * rect, int markDirty, void **pixels,
+                      int *pitch)
 {
     if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
         return SDL_SW_LockYUVTexture((SDL_SW_YUVTexture *) texture->
@@ -308,15 +315,16 @@
 
 static void
 SDL_DUMMY_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
-                    int numrects, const SDL_Rect * rects)
+                       int numrects, const SDL_Rect * rects)
 {
 }
 
 static int
 SDL_DUMMY_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
-                  Uint32 color)
+                     Uint32 color)
 {
-    SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata;
+    SDL_DUMMY_RenderData *data =
+        (SDL_DUMMY_RenderData *) renderer->driverdata;
     SDL_Surface *target = data->screens[data->current_screen];
     SDL_Rect real_rect = *rect;
     Uint8 r, g, b, a;
@@ -332,10 +340,11 @@
 
 static int
 SDL_DUMMY_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
-                  const SDL_Rect * srcrect, const SDL_Rect * dstrect,
-                  int blendMode, int scaleMode)
+                     const SDL_Rect * srcrect, const SDL_Rect * dstrect,
+                     int blendMode, int scaleMode)
 {
-    SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata;
+    SDL_DUMMY_RenderData *data =
+        (SDL_DUMMY_RenderData *) renderer->driverdata;
     SDL_Window *window = SDL_GetWindowFromID(renderer->window);
     SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
 
@@ -362,9 +371,11 @@
         }
         if (scaleMode != SDL_TextureScaleMode_None &&
             (srcrect->w != dstrect->w || srcrect->h != dstrect->h)) {
-            return SDL_SoftStretch(surface, &real_srcrect, target, &real_dstrect);
+            return SDL_SoftStretch(surface, &real_srcrect, target,
+                                   &real_dstrect);
         } else {
-            return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
+            return SDL_LowerBlit(surface, &real_srcrect, target,
+                                 &real_dstrect);
         }
     }
 }
@@ -373,7 +384,8 @@
 SDL_DUMMY_RenderPresent(SDL_Renderer * renderer)
 {
     static int frame_number;
-    SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata;
+    SDL_DUMMY_RenderData *data =
+        (SDL_DUMMY_RenderData *) renderer->driverdata;
 
     /* Send the data to the display */
     if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
@@ -406,7 +418,8 @@
 static void
 SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer)
 {
-    SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata;
+    SDL_DUMMY_RenderData *data =
+        (SDL_DUMMY_RenderData *) renderer->driverdata;
     int i;
 
     if (data) {
--- a/test/testgl.c	Sun Jul 16 03:35:44 2006 +0000
+++ b/test/testgl.c	Sun Jul 16 09:34:01 2006 +0000
@@ -457,16 +457,16 @@
     if (accel) {
         SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
     }
-    if (sync) {
-        SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
-    } else {
-        SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);
-    }
     if (SDL_SetVideoMode(w, h, bpp, video_flags) == NULL) {
         fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
         SDL_Quit();
         exit(1);
     }
+    if (sync) {
+        SDL_GL_SetSwapInterval(1);
+    } else {
+        SDL_GL_SetSwapInterval(0);
+    }
 
     printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel);
     printf("\n");
@@ -498,8 +498,8 @@
         printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
     }
     if (sync) {
-        SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &value);
-        printf("SDL_GL_SWAP_CONTROL: requested 1, got %d\n", value);
+        printf("Buffer swap interval: requested 1, got %d\n",
+               SDL_GL_GetSwapInterval());
     }
 
     /* Set the window manager title bar */