From 4f62229ecb5cdc1c6aa1e997aa15a093265a0972 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 16 Jul 2006 09:34:01 +0000 Subject: [PATCH] Setting up the OpenGL support --- include/SDL_compat.h | 1 + include/SDL_video.h | 12 ++- src/SDL_compat.c | 25 +++++ src/video/SDL_sysvideo.h | 37 ++----- src/video/SDL_video.c | 162 ++++++++++++++++++++++++++----- src/video/dummy/SDL_nullrender.c | 109 ++++++++++++--------- test/testgl.c | 14 +-- 7 files changed, 250 insertions(+), 110 deletions(-) diff --git a/include/SDL_compat.h b/include/SDL_compat.h index 520fbc85f..8aaa0ea7e 100644 --- a/include/SDL_compat.h +++ b/include/SDL_compat.h @@ -172,6 +172,7 @@ extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay * overlay, SDL_Rect * dstrect); extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay * overlay); extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value); +extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/include/SDL_video.h b/include/SDL_video.h index daa37b3df..966f5b3f9 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -1499,6 +1499,10 @@ extern DECLSPEC int SDLCALL SDL_GL_MakeCurrent(SDL_WindowID windowID, * * \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 @@ extern DECLSPEC int SDLCALL SDL_GL_SetSwapInterval(int interval); * * \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) diff --git a/src/SDL_compat.c b/src/SDL_compat.c index afc9241bd..80c18aff4 100644 --- a/src/SDL_compat.c +++ b/src/SDL_compat.c @@ -36,6 +36,7 @@ static SDL_TextureID SDL_VideoTexture; 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_SetVideoMode(int width, int height, int bpp, Uint32 flags) 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 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) /* 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 @@ SDL_FreeYUVOverlay(SDL_Overlay * overlay) } } +int +SDL_GL_GetAttribute(SDL_GLattr attr, int *value) +{ + return SDL_GL_GetWindowAttribute(SDL_VideoWindow, attr, value); +} + +void +SDL_GL_SwapBuffers(void) +{ + SDL_GL_SwapWindow(SDL_VideoWindow); +} + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 5342e2ac7..2bb7cb7bf 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -227,36 +227,21 @@ struct SDL_VideoDevice 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 @@ struct SDL_VideoDevice int current_display; Uint32 next_object_id; - /* Driver information flags */ - /* * * */ /* Data used by the GL drivers */ struct diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 3ce605a86..e0c81afe7 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -153,6 +153,12 @@ cmpmodes(const void *A, const void *B) return 0; } +static void +SDL_UninitializedVideo() +{ + SDL_SetError("Video subsystem has not been initialized"); +} + int SDL_GetNumVideoDrivers(void) { @@ -285,6 +291,7 @@ const char * SDL_GetCurrentVideoDriver() { if (!_this) { + SDL_UninitializedVideo(); return NULL; } return _this->name; @@ -334,6 +341,7 @@ int SDL_GetNumVideoDisplays(void) { if (!_this) { + SDL_UninitializedVideo(); return 0; } return _this->num_displays; @@ -343,7 +351,7 @@ int 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 @@ SDL_SetDisplayMode(const SDL_DisplayMode * mode) int i, ncolors; if (!_this) { - SDL_SetError("Video subsystem has not been initialized"); + SDL_UninitializedVideo(); return -1; } @@ -621,7 +629,7 @@ SDL_SetFullscreenDisplayMode(const SDL_DisplayMode * mode) int i; if (!_this) { - SDL_SetError("Video subsystem has not been initialized"); + SDL_UninitializedVideo(); return -1; } @@ -659,7 +667,7 @@ SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors) 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_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors) SDL_Palette *palette; if (!_this) { - SDL_SetError("Video subsystem has not been initialized"); + SDL_UninitializedVideo(); return -1; } @@ -721,7 +729,12 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) 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_CreateWindowFrom(const void *data) SDL_Window *windows; if (!_this) { - SDL_SetError("Video subsystem has not been initialized"); + SDL_UninitializedVideo(); return (0); } @@ -822,6 +835,7 @@ SDL_GetWindowFromID(SDL_WindowID windowID) int i, j; if (!_this) { + SDL_UninitializedVideo(); return NULL; } @@ -841,6 +855,7 @@ SDL_VideoDisplay * SDL_GetDisplayFromWindow(SDL_Window * window) { if (!_this) { + SDL_UninitializedVideo(); return NULL; } return &_this->displays[window->display]; @@ -1281,6 +1296,7 @@ int SDL_GetRendererInfo(int index, SDL_RendererInfo * info) { if (!_this) { + SDL_UninitializedVideo(); return -1; } @@ -1374,6 +1390,7 @@ SDL_CreateTexture(Uint32 format, int access, int w, int h) SDL_Texture *texture; if (!_this) { + SDL_UninitializedVideo(); return 0; } @@ -1752,6 +1769,7 @@ SDL_RenderFill(const SDL_Rect * rect, Uint32 color) SDL_Rect real_rect; if (!_this) { + SDL_UninitializedVideo(); return -1; } @@ -1821,6 +1839,7 @@ SDL_RenderPresent(void) SDL_Renderer *renderer; if (!_this) { + SDL_UninitializedVideo(); return; } @@ -1839,6 +1858,7 @@ SDL_DestroyTexture(SDL_TextureID textureID) SDL_Renderer *renderer; if (!_this) { + SDL_UninitializedVideo(); return; } @@ -1977,21 +1997,21 @@ SDL_VideoQuit(void) _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 @@ SDL_GL_GetProcAddress(const char *proc) { void *func; + if (!_this) { + SDL_UninitializedVideo(); + return NULL; + } + func = NULL; if (_this->GL_GetProcAddress) { if (_this->gl_config.driver_loaded) { @@ -2014,12 +2039,16 @@ SDL_GL_GetProcAddress(const char *proc) 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 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value) 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 diff --git a/src/video/dummy/SDL_nullrender.c b/src/video/dummy/SDL_nullrender.c index 0c19275c3..1e094ffd8 100644 --- a/src/video/dummy/SDL_nullrender.c +++ b/src/video/dummy/SDL_nullrender.c @@ -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 @@ SDL_DUMMY_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) 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 @@ SDL_DUMMY_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) 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 @@ SDL_DUMMY_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, 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 @@ SDL_DUMMY_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, 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 @@ SDL_DUMMY_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, 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 @@ SDL_DUMMY_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 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 @@ SDL_DUMMY_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) 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 @@ SDL_DUMMY_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, 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 @@ SDL_DUMMY_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, } 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 @@ static void 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 @@ SDL_DUMMY_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) 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) { diff --git a/test/testgl.c b/test/testgl.c index 6b3254647..6730b9249 100644 --- a/test/testgl.c +++ b/test/testgl.c @@ -457,16 +457,16 @@ RunGLTest(int argc, char *argv[], 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 @@ RunGLTest(int argc, char *argv[], 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 */