From 17520c2e6eeac14839ecc510472353bf84a9c985 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 13 May 2024 10:31:55 -0700 Subject: [PATCH] Removed SDL_RendererFlags The flags parameter has been removed from SDL_CreateRenderer() and SDL_RENDERER_PRESENTVSYNC has been replaced with SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER during window creation and SDL_PROP_RENDERER_VSYNC_NUMBER after renderer creation. SDL_SetRenderVSync() now takes additional values besides 0 and 1. The maximum texture size has been removed from SDL_RendererInfo, replaced with SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER. --- docs/README-migration.md | 9 ++- docs/README-ps2.md | 4 -- docs/README-visualc.md | 2 +- docs/README-wayland.md | 2 +- docs/README-winrt.md | 6 +- include/SDL3/SDL_hints.h | 16 ----- include/SDL3/SDL_oldnames.h | 2 - include/SDL3/SDL_render.h | 30 +++------ include/SDL3/SDL_test_common.h | 2 +- src/dynapi/SDL_dynapi_procs.h | 2 +- src/render/SDL_render.c | 69 ++++++++++---------- src/render/direct3d/SDL_render_d3d.c | 55 +++++++++++----- src/render/direct3d11/SDL_render_d3d11.c | 82 +++++++++++------------- src/render/direct3d12/SDL_render_d3d12.c | 40 ++++++------ src/render/metal/SDL_render_metal.m | 33 +++++----- src/render/opengl/SDL_render_gl.c | 43 +++---------- src/render/opengles2/SDL_render_gles2.c | 54 +++++----------- src/render/ps2/SDL_render_ps2.c | 29 ++++----- src/render/psp/SDL_render_psp.c | 12 +--- src/render/software/SDL_render_sw.c | 2 +- src/render/vitagxm/SDL_render_vita_gxm.c | 12 +--- src/render/vulkan/SDL_render_vulkan.c | 27 ++++---- src/test/SDL_test_common.c | 62 ++++++------------ src/video/SDL_video.c | 4 +- test/checkkeysthreads.c | 2 +- test/testautomation_render.c | 2 +- test/testautomation_video.c | 4 +- test/testcontroller.c | 2 +- test/testgl.c | 14 +--- test/testgles.c | 6 +- test/testgles2.c | 6 +- test/testgles2_sdf.c | 6 +- test/testmessage.c | 2 +- test/testmouse.c | 2 +- test/testnative.c | 2 +- test/testoffscreen.c | 2 +- test/testpopup.c | 2 +- test/testshape.c | 2 +- test/teststreaming.c | 2 +- test/testwaylandcustom.c | 2 +- test/testyuv.c | 2 +- 41 files changed, 265 insertions(+), 394 deletions(-) diff --git a/docs/README-migration.md b/docs/README-migration.md index 9a4ba2ccc..697826380 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -722,12 +722,13 @@ The following hints have been removed: * SDL_HINT_IDLE_TIMER_DISABLED - use SDL_DisableScreenSaver() instead * SDL_HINT_IME_SUPPORT_EXTENDED_TEXT - the normal text editing event has extended text * SDL_HINT_MOUSE_RELATIVE_SCALING - mouse coordinates are no longer automatically scaled by the SDL renderer +* SDL_HINT_PS2_DYNAMIC_VSYNC - use SDL_SetRendererVSync(renderer, -1) instead * SDL_HINT_RENDER_BATCHING - Render batching is always enabled, apps should call SDL_FlushRenderer() before calling into a lower-level graphics API. * SDL_HINT_RENDER_LOGICAL_SIZE_MODE - the logical size mode is explicitly set with SDL_SetRenderLogicalPresentation() * SDL_HINT_RENDER_OPENGL_SHADERS - shaders are always used if they are available * SDL_HINT_RENDER_SCALE_QUALITY - textures now default to linear filtering, use SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST) if you want nearest pixel mode instead -* SDL_HINT_VIDEO_EXTERNAL_CONTEXT - replaced with SDL_PROP_WINDOW_CREATE_EXTERNAL_GRAPHICS_CONTEXT_BOOLEAN in SDL_CreateWindowWithProperties() * SDL_HINT_THREAD_STACK_SIZE - the stack size can be specified using SDL_CreateThreadWithStackSize() +* SDL_HINT_VIDEO_EXTERNAL_CONTEXT - replaced with SDL_PROP_WINDOW_CREATE_EXTERNAL_GRAPHICS_CONTEXT_BOOLEAN in SDL_CreateWindowWithProperties() * SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL - replaced with SDL_PROP_WINDOW_CREATE_OPENGL_BOOLEAN in SDL_CreateWindowWithProperties() * SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN - replaced with SDL_PROP_WINDOW_CREATE_VULKAN_BOOLEAN in SDL_CreateWindowWithProperties() * SDL_HINT_VIDEO_HIGHDPI_DISABLED - high DPI support is always enabled @@ -752,7 +753,6 @@ The following hints have been renamed: * SDL_HINT_LINUX_HAT_DEADZONES => SDL_HINT_JOYSTICK_LINUX_HAT_DEADZONES * SDL_HINT_LINUX_JOYSTICK_CLASSIC => SDL_HINT_JOYSTICK_LINUX_CLASSIC * SDL_HINT_LINUX_JOYSTICK_DEADZONES => SDL_HINT_JOYSTICK_LINUX_DEADZONES -* SDL_HINT_PS2_DYNAMIC_VSYNC => SDL_HINT_RENDER_PS2_DYNAMIC_VSYNC The following functions have been removed: * SDL_ClearHints() - replaced with SDL_ResetHints() @@ -1092,12 +1092,14 @@ was used to figure out the index of a driver, so one would call it in a for-loop for the driver named "opengl" or whatnot. SDL_GetRenderDriver() has been added for this functionality, which returns only the name of the driver. -Additionally, SDL_CreateRenderer()'s second argument is no longer an integer index, but a +SDL_CreateRenderer()'s second argument is no longer an integer index, but a `const char *` representing a renderer's name; if you were just using a for-loop to find which index is the "opengl" or whatnot driver, you can just pass that string directly here, now. Passing NULL is the same as passing -1 here in SDL2, to signify you want SDL to decide for you. +SDL_CreateRenderer()'s flags parameter has been removed. See specific flags below for how to achieve the same functionality in SDL 3.0. + SDL_CreateWindowAndRenderer() now takes the window title as the first parameter. Mouse and touch events are no longer filtered to change their coordinates, instead you @@ -1169,6 +1171,7 @@ The following symbols have been renamed: The following symbols have been removed: * SDL_RENDERER_ACCELERATED - all renderers except `SDL_SOFTWARE_RENDERER` are accelerated +* SDL_RENDERER_PRESENTVSYNC - replaced with SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER during renderer creation and SDL_PROP_RENDERER_VSYNC_NUMBER after renderer creation * SDL_RENDERER_SOFTWARE - you can check whether the name of the renderer is `SDL_SOFTWARE_RENDERER` * SDL_RENDERER_TARGETTEXTURE - all renderers support target texture functionality diff --git a/docs/README-ps2.md b/docs/README-ps2.md index cc9d245ae..60b1d2002 100644 --- a/docs/README-ps2.md +++ b/docs/README-ps2.md @@ -16,10 +16,6 @@ cmake --build build cmake --install build ``` -## Hints -The PS2 port has a special Hint for having a dynamic VSYNC. The Hint is `SDL_HINT_RENDER_PS2_DYNAMIC_VSYNC`. -If you enabled the dynamic vsync having as well `SDL_RENDERER_PRESENTVSYNC` enabled, then if the app is not able to run at 60 FPS, automatically the `vsync` will be disabled having a better performance, instead of dropping FPS to 30. - ## Notes If you trying to debug a SDL app through [ps2client](https://github.com/ps2dev/ps2client) you need to avoid the IOP reset, otherwise you will lose the connection with your computer. So to avoid the reset of the IOP CPU, you need to call to the macro `SDL_PS2_SKIP_IOP_RESET();`. diff --git a/docs/README-visualc.md b/docs/README-visualc.md index a631fce12..068614a2e 100644 --- a/docs/README-visualc.md +++ b/docs/README-visualc.md @@ -88,7 +88,7 @@ Here's a sample SDL snippet to verify everything is setup in your IDE: SDL_Init(SDL_INIT_VIDEO); window = SDL_CreateWindow("Hello SDL", WIDTH, HEIGHT, 0); - renderer = SDL_CreateRenderer(window, NULL, SDL_RENDERER_PRESENTVSYNC); + renderer = SDL_CreateRenderer(window, NULL); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); diff --git a/docs/README-wayland.md b/docs/README-wayland.md index 6dac845ca..bd6601cc2 100644 --- a/docs/README-wayland.md +++ b/docs/README-wayland.md @@ -186,7 +186,7 @@ int main(int argc, char *argv[]) } /* Create a renderer */ - sdlRenderer = SDL_CreateRenderer(sdlWindow, NULL, 0); + sdlRenderer = SDL_CreateRenderer(sdlWindow, NULL); if (!sdlRenderer) { goto exit; } diff --git a/docs/README-winrt.md b/docs/README-winrt.md index 2ab720150..c19c0f333 100644 --- a/docs/README-winrt.md +++ b/docs/README-winrt.md @@ -88,9 +88,9 @@ Here is a rough list of what works, and what doesn't: UWP itself). * turning off VSync when rendering on Windows Phone. Attempts to turn VSync off on Windows Phone result either in Direct3D not drawing anything, or it - forcing VSync back on. As such, SDL_RENDERER_PRESENTVSYNC will always get - turned-on on Windows Phone. This limitation is not present in non-Phone - WinRT (such as Windows 8.x), where turning off VSync appears to work. + forcing VSync back on. As such, vsync will always get turned-on on Windows + Phone. This limitation is not present in non-Phone WinRT (such as Windows 8.x), + where turning off VSync appears to work. * probably anything else that's not listed as supported diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h index 392505188..671a841b6 100644 --- a/include/SDL3/SDL_hints.h +++ b/include/SDL3/SDL_hints.h @@ -2570,22 +2570,6 @@ extern "C" { */ #define SDL_HINT_RENDER_METAL_PREFER_LOW_POWER_DEVICE "SDL_RENDER_METAL_PREFER_LOW_POWER_DEVICE" -/** - * A variable controlling whether vsync is automatically disabled if doesn't - * reach enough FPS. - * - * The variable can be set to the following values: - * - * - "0": It will be using VSYNC as defined in the main flag. (default) - * - "1": If VSYNC was previously enabled, then it will disable VSYNC if - * doesn't reach enough speed - * - * This hint should be set before creating a renderer. - * - * \since This hint is available since SDL 3.0.0. - */ -#define SDL_HINT_RENDER_PS2_DYNAMIC_VSYNC "SDL_RENDER_PS2_DYNAMIC_VSYNC" - /** * A variable controlling whether updates to the SDL screen surface should be * synchronized with the vertical refresh, to avoid tearing. diff --git a/include/SDL3/SDL_oldnames.h b/include/SDL3/SDL_oldnames.h index 88e7064f0..4e06737c3 100644 --- a/include/SDL3/SDL_oldnames.h +++ b/include/SDL3/SDL_oldnames.h @@ -291,7 +291,6 @@ #define SDL_HINT_LINUX_HAT_DEADZONES SDL_HINT_JOYSTICK_LINUX_HAT_DEADZONES #define SDL_HINT_LINUX_JOYSTICK_CLASSIC SDL_HINT_JOYSTICK_LINUX_CLASSIC #define SDL_HINT_LINUX_JOYSTICK_DEADZONES SDL_HINT_JOYSTICK_LINUX_DEADZONES -#define SDL_HINT_PS2_DYNAMIC_VSYNC SDL_HINT_RENDER_PS2_DYNAMIC_VSYNC /* ##SDL_joystick.h */ #define SDL_JOYSTICK_TYPE_GAMECONTROLLER SDL_JOYSTICK_TYPE_GAMEPAD @@ -800,7 +799,6 @@ #define SDL_HINT_LINUX_HAT_DEADZONES SDL_HINT_LINUX_HAT_DEADZONES_renamed_SDL_HINT_JOYSTICK_LINUX_HAT_DEADZONES #define SDL_HINT_LINUX_JOYSTICK_CLASSIC SDL_HINT_LINUX_JOYSTICK_CLASSIC_renamed_SDL_HINT_JOYSTICK_LINUX_CLASSIC #define SDL_HINT_LINUX_JOYSTICK_DEADZONES SDL_HINT_LINUX_JOYSTICK_DEADZONES_renamed_SDL_HINT_JOYSTICK_LINUX_DEADZONES -#define SDL_HINT_PS2_DYNAMIC_VSYNC SDL_HINT_PS2_DYNAMIC_VSYNC_renamed_SDL_HINT_RENDER_PS2_DYNAMIC_VSYNC /* ##SDL_joystick.h */ #define SDL_JOYSTICK_TYPE_GAMECONTROLLER SDL_JOYSTICK_TYPE_GAMECONTROLLER_renamed_SDL_JOYSTICK_TYPE_GAMEPAD diff --git a/include/SDL3/SDL_render.h b/include/SDL3/SDL_render.h index 74c5278f0..10d08dba7 100644 --- a/include/SDL3/SDL_render.h +++ b/include/SDL3/SDL_render.h @@ -68,15 +68,6 @@ extern "C" { */ #define SDL_SOFTWARE_RENDERER "software" -/** - * Flags used when creating a rendering context. - * - * \since This datatype is available since SDL 3.0.0. - */ -typedef Uint32 SDL_RendererFlags; - -#define SDL_RENDERER_PRESENTVSYNC 0x00000004u /**< Present is synchronized with the refresh rate */ - /** * Information on the capabilities of a render driver or context. * @@ -85,11 +76,8 @@ typedef Uint32 SDL_RendererFlags; typedef struct SDL_RendererInfo { const char *name; /**< The name of the renderer */ - SDL_RendererFlags flags; /**< Supported ::SDL_RendererFlags */ int num_texture_formats; /**< The number of available texture formats */ const SDL_PixelFormatEnum *texture_formats; /**< The available texture formats */ - int max_texture_width; /**< The maximum texture width */ - int max_texture_height; /**< The maximum texture height */ } SDL_RendererInfo; /** @@ -228,7 +216,6 @@ extern DECLSPEC int SDLCALL SDL_CreateWindowAndRenderer(const char *title, int w * \param window the window where rendering is displayed * \param name the name of the rendering driver to initialize, or NULL to * initialize the first one supporting the requested flags - * \param flags 0, or one or more SDL_RendererFlags OR'd together * \returns a valid rendering context or NULL if there was an error; call * SDL_GetError() for more information. * @@ -241,7 +228,7 @@ extern DECLSPEC int SDLCALL SDL_CreateWindowAndRenderer(const char *title, int w * \sa SDL_GetRenderDriver * \sa SDL_GetRendererInfo */ -extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window *window, const char *name, SDL_RendererFlags flags); +extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window *window, const char *name); /** * Create a 2D rendering context for a window, with the specified properties. @@ -261,8 +248,8 @@ extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window *window, co * supports HDR output. If you select SDL_COLORSPACE_SRGB_LINEAR, drawing * still uses the sRGB colorspace, but values can go beyond 1.0 and float * (linear) format textures can be used for HDR content. - * - `SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN`: true if you want - * present synchronized with the refresh rate + * - `SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER`: non-zero if you want + * present synchronized with the refresh rate. This property can take any value that is supported by SDL_SetRenderVSync() for the renderer. * * With the vulkan renderer: * @@ -297,7 +284,7 @@ extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRendererWithProperties(SDL_Prop #define SDL_PROP_RENDERER_CREATE_WINDOW_POINTER "window" #define SDL_PROP_RENDERER_CREATE_SURFACE_POINTER "surface" #define SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER "output_colorspace" -#define SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN "present_vsync" +#define SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER "present_vsync" #define SDL_PROP_RENDERER_CREATE_VULKAN_INSTANCE_POINTER "vulkan.instance" #define SDL_PROP_RENDERER_CREATE_VULKAN_SURFACE_NUMBER "vulkan.surface" #define SDL_PROP_RENDERER_CREATE_VULKAN_PHYSICAL_DEVICE_POINTER "vulkan.physical_device" @@ -372,6 +359,8 @@ extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer *renderer, SDL_Rend * displayed, if any * - `SDL_PROP_RENDERER_SURFACE_POINTER`: the surface where rendering is * displayed, if this is a software renderer without a window + * - `SDL_PROP_RENDERER_VSYNC_NUMBER`: the current vsync setting + * - `SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER`: the maximum texture width and height * - `SDL_PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER`: an SDL_ColorSpace value * describing the colorspace for output to the display, defaults to * SDL_COLORSPACE_SRGB. @@ -441,6 +430,8 @@ extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetRendererProperties(SDL_Renderer #define SDL_PROP_RENDERER_NAME_STRING "SDL.renderer.name" #define SDL_PROP_RENDERER_WINDOW_POINTER "SDL.renderer.window" #define SDL_PROP_RENDERER_SURFACE_POINTER "SDL.renderer.surface" +#define SDL_PROP_RENDERER_VSYNC_NUMBER "SDL.renderer.vsync" +#define SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER "SDL.renderer.max_texture_size" #define SDL_PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER "SDL.renderer.output_colorspace" #define SDL_PROP_RENDERER_HDR_ENABLED_BOOLEAN "SDL.renderer.HDR_enabled" #define SDL_PROP_RENDERER_SDR_WHITE_POINT_FLOAT "SDL.renderer.SDR_white_point" @@ -2145,7 +2136,7 @@ extern DECLSPEC int SDLCALL SDL_AddVulkanRenderSemaphores(SDL_Renderer *renderer * Toggle VSync of the given renderer. * * \param renderer The renderer to toggle - * \param vsync 1 for on, 0 for off. All other values are reserved + * \param vsync the vertical refresh sync interval, 1 to synchronize present with every vertical refresh, 2 to synchronize present with every second vertical refresh, etc., or -1 for late swap tearing (adaptive vsync). Not every value is supported by every renderer, so you should check the return value to see whether the requested setting is supported. * \returns 0 on success or a negative error code on failure; call * SDL_GetError() for more information. * @@ -2159,8 +2150,7 @@ extern DECLSPEC int SDLCALL SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync * Get VSync of the given renderer. * * \param renderer The renderer to toggle - * \param vsync an int filled with 1 for on, 0 for off. All other values are - * reserved + * \param vsync an int filled with the current vertical refresh sync interval * \returns 0 on success or a negative error code on failure; call * SDL_GetError() for more information. * diff --git a/include/SDL3/SDL_test_common.h b/include/SDL3/SDL_test_common.h index d8f2af3f4..3c502238b 100644 --- a/include/SDL3/SDL_test_common.h +++ b/include/SDL3/SDL_test_common.h @@ -90,7 +90,7 @@ typedef struct /* Renderer info */ const char *renderdriver; - Uint32 render_flags; + int render_vsync; SDL_bool skip_renderer; SDL_Renderer **renderers; SDL_Texture **targets; diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 4a9047bc2..a8b40db86 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -137,7 +137,7 @@ SDL_DYNAPI_PROC(SDL_PixelFormat*,SDL_CreatePixelFormat,(SDL_PixelFormatEnum a),( SDL_DYNAPI_PROC(SDL_Window*,SDL_CreatePopupWindow,(SDL_Window *a, int b, int c, int d, int e, SDL_WindowFlags f),(a,b,c,d,e,f),return) SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_CreateProperties,(void),(),return) SDL_DYNAPI_PROC(SDL_RWLock*,SDL_CreateRWLock,(void),(),return) -SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateRenderer,(SDL_Window *a, const char *b, SDL_RendererFlags c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateRenderer,(SDL_Window *a, const char *b),(a,b),return) SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateRendererWithProperties,(SDL_PropertiesID a),(a),return) SDL_DYNAPI_PROC(SDL_Semaphore*,SDL_CreateSemaphore,(Uint32 a),(a),return) SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateSoftwareRenderer,(SDL_Surface *a),(a),return) diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index bf346cba9..a6c292ab5 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -857,7 +857,7 @@ int SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_Wi return -1; } - *renderer = SDL_CreateRenderer(*window, NULL, 0); + *renderer = SDL_CreateRenderer(*window, NULL); if (!*renderer) { SDL_DestroyWindow(*window); *window = NULL; @@ -969,7 +969,7 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props) hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC); if (hint && *hint) { - SDL_SetBooleanProperty(props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_GetHintBoolean(SDL_HINT_RENDER_VSYNC, SDL_TRUE)); + SDL_SetNumberProperty(props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER, SDL_GetHintBoolean(SDL_HINT_RENDER_VSYNC, SDL_TRUE)); } if (surface) { @@ -1019,16 +1019,6 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props) } } - if (SDL_GetBooleanProperty(props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_FALSE)) { - renderer->wanted_vsync = SDL_TRUE; - - if (!(renderer->info.flags & SDL_RENDERER_PRESENTVSYNC)) { - renderer->simulate_vsync = SDL_TRUE; - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } - } - SDL_CalculateSimulatedVSyncInterval(renderer, window); - VerifyDrawQueueFunctions(renderer); renderer->magic = &SDL_renderer_magic; @@ -1102,12 +1092,24 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props) SDL_AddEventWatch(SDL_RendererEventWatch, renderer); } + int vsync = (int)SDL_GetNumberProperty(props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER, 0); + if (SDL_SetRenderVSync(renderer, vsync) < 0) { + if (vsync == 0) { + // Some renderers require vsync enabled + SDL_SetRenderVSync(renderer, 1); + } + } + SDL_CalculateSimulatedVSyncInterval(renderer, window); + SDL_LogInfo(SDL_LOG_CATEGORY_RENDER, "Created renderer: %s", renderer->info.name); #ifdef SDL_PLATFORM_ANDROID Android_ActivityMutex_Unlock(); #endif + + SDL_ClearError(); + return renderer; error: @@ -1125,15 +1127,12 @@ error: #endif } -SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, const char *name, SDL_RendererFlags flags) +SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, const char *name) { SDL_Renderer *renderer; SDL_PropertiesID props = SDL_CreateProperties(); SDL_SetProperty(props, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, window); SDL_SetStringProperty(props, SDL_PROP_RENDERER_CREATE_NAME_STRING, name); - if (flags & SDL_RENDERER_PRESENTVSYNC) { - SDL_SetBooleanProperty(props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_TRUE); - } renderer = SDL_CreateRendererWithProperties(props); SDL_DestroyProperties(props); return renderer; @@ -1305,9 +1304,9 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert SDL_SetError("Texture dimensions can't be 0"); return NULL; } - if ((renderer->info.max_texture_width && w > renderer->info.max_texture_width) || - (renderer->info.max_texture_height && h > renderer->info.max_texture_height)) { - SDL_SetError("Texture dimensions are limited to %dx%d", renderer->info.max_texture_width, renderer->info.max_texture_height); + int max_texture_size = (int)SDL_GetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, 0); + if (max_texture_size && (w > max_texture_size || h > max_texture_size)) { + SDL_SetError("Texture dimensions are limited to %dx%d", max_texture_size, max_texture_size); return NULL; } @@ -4726,10 +4725,6 @@ int SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync) { CHECK_RENDERER_MAGIC(renderer, -1); - if (vsync != 0 && vsync != 1) { - return SDL_Unsupported(); - } - renderer->wanted_vsync = vsync ? SDL_TRUE : SDL_FALSE; /* for the software renderer, forward eventually the call to the WindowTexture renderer */ @@ -4742,17 +4737,25 @@ int SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync) } #endif - if (!renderer->SetVSync || - renderer->SetVSync(renderer, vsync) != 0) { - renderer->simulate_vsync = vsync ? SDL_TRUE : SDL_FALSE; - if (renderer->simulate_vsync) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } else { - renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC; + if (!renderer->SetVSync) { + switch (vsync) { + case 0: + renderer->simulate_vsync = SDL_FALSE; + break; + case 1: + renderer->simulate_vsync = SDL_TRUE; + break; + default: + return SDL_Unsupported(); + } + } else if (renderer->SetVSync(renderer, vsync) < 0) { + if (vsync == 1) { + renderer->simulate_vsync = SDL_TRUE; + } else { + return -1; } - } else { - renderer->simulate_vsync = SDL_FALSE; } + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_VSYNC_NUMBER, vsync); return 0; } @@ -4762,6 +4765,6 @@ int SDL_GetRenderVSync(SDL_Renderer *renderer, int *vsync) if (!vsync) { return SDL_InvalidParamError("vsync"); } - *vsync = renderer->wanted_vsync; + *vsync = (int)SDL_GetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_VSYNC_NUMBER, 0); return 0; } diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c index a7b2b0edb..3c4f862e2 100644 --- a/src/render/direct3d/SDL_render_d3d.c +++ b/src/render/direct3d/SDL_render_d3d.c @@ -1552,13 +1552,38 @@ static int D3D_Reset(SDL_Renderer *renderer) static int D3D_SetVSync(SDL_Renderer *renderer, const int vsync) { D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata; - if (vsync) { - data->pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE; - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } else { - data->pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC; + + DWORD PresentationInterval; + switch (vsync) { + case 0: + PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + break; + case 1: + PresentationInterval = D3DPRESENT_INTERVAL_ONE; + break; + case 2: + PresentationInterval = D3DPRESENT_INTERVAL_TWO; + break; + case 3: + PresentationInterval = D3DPRESENT_INTERVAL_THREE; + break; + case 4: + PresentationInterval = D3DPRESENT_INTERVAL_FOUR; + break; + default: + return SDL_Unsupported(); } + + D3DCAPS9 caps; + HRESULT result = IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps); + if (FAILED(result)) { + return D3D_SetError("GetDeviceCaps()", result); + } + if (!(caps.PresentationIntervals & PresentationInterval)) { + return SDL_Unsupported(); + } + data->pparams.PresentationInterval = PresentationInterval; + if (D3D_Reset(renderer) < 0) { /* D3D_Reset will call SDL_SetError() */ return -1; @@ -1644,17 +1669,17 @@ int D3D_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Propertie pparams.BackBufferFormat = D3DFMT_UNKNOWN; pparams.FullScreen_RefreshRateInHz = 0; } - if (SDL_GetBooleanProperty(create_props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_FALSE)) { - pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE; - } else { - pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - } + pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; /* Get the adapter for the display that the window is on */ displayID = SDL_GetDisplayForWindow(window); data->adapter = SDL_Direct3D9GetAdapterIndex(displayID); - IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps); + result = IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps); + if (FAILED(result)) { + D3D_DestroyRenderer(renderer); + return D3D_SetError("GetDeviceCaps()", result); + } device_flags = D3DCREATE_FPU_PRESERVE; if (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) { @@ -1690,14 +1715,10 @@ int D3D_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Propertie return D3D_SetError("GetPresentParameters()", result); } IDirect3DSwapChain9_Release(chain); - if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } data->pparams = pparams; IDirect3DDevice9_GetDeviceCaps(data->device, &caps); - renderer->info.max_texture_width = caps.MaxTextureWidth; - renderer->info.max_texture_height = caps.MaxTextureHeight; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, SDL_min(caps.MaxTextureWidth, caps.MaxTextureHeight)); if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND) { data->enableSeparateAlphaBlend = SDL_TRUE; diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c index 5eff5783c..5c2ad3e78 100644 --- a/src/render/direct3d11/SDL_render_d3d11.c +++ b/src/render/direct3d11/SDL_render_d3d11.c @@ -170,6 +170,8 @@ typedef struct ID3D11DeviceContext1 *d3dContext; IDXGISwapChain1 *swapChain; DXGI_SWAP_EFFECT swapEffect; + UINT syncInterval; + UINT presentFlags; ID3D11RenderTargetView *mainRenderTargetView; ID3D11RenderTargetView *currentOffscreenRenderTargetView; ID3D11InputLayout *inputLayout; @@ -690,21 +692,21 @@ static HRESULT D3D11_CreateDeviceResources(SDL_Renderer *renderer) switch (data->featureLevel) { case D3D_FEATURE_LEVEL_11_1: case D3D_FEATURE_LEVEL_11_0: - renderer->info.max_texture_width = renderer->info.max_texture_height = 16384; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, 16384); break; case D3D_FEATURE_LEVEL_10_1: case D3D_FEATURE_LEVEL_10_0: - renderer->info.max_texture_width = renderer->info.max_texture_height = 8192; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, 8192); break; case D3D_FEATURE_LEVEL_9_3: - renderer->info.max_texture_width = renderer->info.max_texture_height = 4096; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, 4096); break; case D3D_FEATURE_LEVEL_9_2: case D3D_FEATURE_LEVEL_9_1: - renderer->info.max_texture_width = renderer->info.max_texture_height = 2048; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, 2048); break; default: @@ -2692,31 +2694,19 @@ done: static int D3D11_RenderPresent(SDL_Renderer *renderer) { D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata; - UINT syncInterval; - UINT presentFlags; HRESULT result; DXGI_PRESENT_PARAMETERS parameters; SDL_zero(parameters); #if SDL_WINAPI_FAMILY_PHONE - syncInterval = 1; - presentFlags = 0; - result = IDXGISwapChain_Present(data->swapChain, syncInterval, presentFlags); + result = IDXGISwapChain_Present(data->swapChain, data->syncInterval, data->presentFlags); #else - if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) { - syncInterval = 1; - presentFlags = 0; - } else { - syncInterval = 0; - presentFlags = DXGI_PRESENT_DO_NOT_WAIT; - } - /* The application may optionally specify "dirty" or "scroll" * rects to improve efficiency in certain scenarios. * This option is not available on Windows Phone 8, to note. */ - result = IDXGISwapChain1_Present1(data->swapChain, syncInterval, presentFlags, ¶meters); + result = IDXGISwapChain1_Present1(data->swapChain, data->syncInterval, data->presentFlags, ¶meters); #endif /* Discard the contents of the render target. @@ -2747,19 +2737,39 @@ static int D3D11_RenderPresent(SDL_Renderer *renderer) return 0; } -#if SDL_WINAPI_FAMILY_PHONE -/* no-op. */ -#else static int D3D11_SetVSync(SDL_Renderer *renderer, const int vsync) { - if (vsync) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; + D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata; + +#if SDL_WINAPI_FAMILY_PHONE + /* VSync is required in Windows Phone, at least for Win Phone 8.0 and 8.1. + * Failure to use it seems to either result in: + * + * - with the D3D11 debug runtime turned OFF, vsync seemingly gets turned + * off (framerate doesn't get capped), but nothing appears on-screen + * + * - with the D3D11 debug runtime turned ON, vsync gets automatically + * turned back on, and the following gets output to the debug console: + * + * DXGI ERROR: IDXGISwapChain::Present: Interval 0 is not supported, changed to Interval 1. [ UNKNOWN ERROR #1024: ] + */ + if (vsync == 0) { + return SDL_Unsupported(); + } +#endif + if (vsync < 0) { + return SDL_Unsupported(); + } + + if (vsync > 0) { + data->syncInterval = vsync; + data->presentFlags = 0; } else { - renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC; + data->syncInterval = 0; + data->presentFlags = DXGI_PRESENT_DO_NOT_WAIT; } return 0; } -#endif static int D3D11_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) { @@ -2803,6 +2813,7 @@ static int D3D11_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ renderer->RenderPresent = D3D11_RenderPresent; renderer->DestroyTexture = D3D11_DestroyTexture; renderer->DestroyRenderer = D3D11_DestroyRenderer; + renderer->SetVSync = D3D11_SetVSync; renderer->driverdata = data; D3D11_InvalidateCachedState(renderer); @@ -2817,25 +2828,8 @@ static int D3D11_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_NV21); SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_P010); -#if SDL_WINAPI_FAMILY_PHONE - /* VSync is required in Windows Phone, at least for Win Phone 8.0 and 8.1. - * Failure to use it seems to either result in: - * - * - with the D3D11 debug runtime turned OFF, vsync seemingly gets turned - * off (framerate doesn't get capped), but nothing appears on-screen - * - * - with the D3D11 debug runtime turned ON, vsync gets automatically - * turned back on, and the following gets output to the debug console: - * - * DXGI ERROR: IDXGISwapChain::Present: Interval 0 is not supported, changed to Interval 1. [ UNKNOWN ERROR #1024: ] - */ - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; -#else - if (SDL_GetBooleanProperty(create_props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_FALSE)) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } - renderer->SetVSync = D3D11_SetVSync; -#endif + data->syncInterval = 0; + data->presentFlags = DXGI_PRESENT_DO_NOT_WAIT; /* HACK: make sure the SDL_Renderer references the SDL_Window data now, in * order to give init functions access to the underlying window handle: diff --git a/src/render/direct3d12/SDL_render_d3d12.c b/src/render/direct3d12/SDL_render_d3d12.c index da4736943..4b03ca6d5 100644 --- a/src/render/direct3d12/SDL_render_d3d12.c +++ b/src/render/direct3d12/SDL_render_d3d12.c @@ -212,6 +212,8 @@ typedef struct ID3D12GraphicsCommandList2 *commandList; DXGI_SWAP_EFFECT swapEffect; UINT swapFlags; + UINT syncInterval; + UINT presentFlags; DXGI_FORMAT renderTargetFormat; SDL_bool pixelSizeChanged; @@ -3085,10 +3087,6 @@ done: static int D3D12_RenderPresent(SDL_Renderer *renderer) { D3D12_RenderData *data = (D3D12_RenderData *)renderer->driverdata; -#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) - UINT syncInterval; - UINT presentFlags; -#endif HRESULT result; /* Transition the render target to present state */ @@ -3104,18 +3102,10 @@ static int D3D12_RenderPresent(SDL_Renderer *renderer) #if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES) result = D3D12_XBOX_PresentFrame(data->commandQueue, data->frameToken, data->renderTargets[data->currentBackBufferIndex]); #else - if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) { - syncInterval = 1; - presentFlags = 0; - } else { - syncInterval = 0; - presentFlags = DXGI_PRESENT_ALLOW_TEARING; - } - /* The application may optionally specify "dirty" or "scroll" * rects to improve efficiency in certain scenarios. */ - result = D3D_CALL(data->swapChain, Present, syncInterval, presentFlags); + result = D3D_CALL(data->swapChain, Present, data->syncInterval, data->presentFlags); #endif if (FAILED(result) && result != DXGI_ERROR_WAS_STILL_DRAWING) { @@ -3166,10 +3156,18 @@ static int D3D12_RenderPresent(SDL_Renderer *renderer) static int D3D12_SetVSync(SDL_Renderer *renderer, const int vsync) { - if (vsync) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; + D3D12_RenderData *data = (D3D12_RenderData *)renderer->driverdata; + + if (vsync < 0) { + return SDL_Unsupported(); + } + + if (vsync > 0) { + data->syncInterval = vsync; + data->presentFlags = 0; } else { - renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC; + data->syncInterval = 0; + data->presentFlags = DXGI_PRESENT_ALLOW_TEARING; } return 0; } @@ -3221,6 +3219,7 @@ int D3D12_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Propert renderer->RenderPresent = D3D12_RenderPresent; renderer->DestroyTexture = D3D12_DestroyTexture; renderer->DestroyRenderer = D3D12_DestroyRenderer; + renderer->SetVSync = D3D12_SetVSync; renderer->driverdata = data; D3D12_InvalidateCachedState(renderer); @@ -3234,13 +3233,10 @@ int D3D12_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Propert SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_NV12); SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_NV21); SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_P010); - renderer->info.max_texture_width = 16384; - renderer->info.max_texture_height = 16384; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, 16384); - if (SDL_GetBooleanProperty(create_props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_FALSE)) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } - renderer->SetVSync = D3D12_SetVSync; + data->syncInterval = 0; + data->presentFlags = DXGI_PRESENT_ALLOW_TEARING; /* HACK: make sure the SDL_Renderer references the SDL_Window data now, in * order to give init functions access to the underlying window handle: diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m index 7b376889a..450b18f1b 100644 --- a/src/render/metal/SDL_render_metal.m +++ b/src/render/metal/SDL_render_metal.m @@ -1829,17 +1829,25 @@ static int METAL_SetVSync(SDL_Renderer *renderer, const int vsync) #if (defined(SDL_PLATFORM_MACOS) && defined(MAC_OS_X_VERSION_10_13)) || TARGET_OS_MACCATALYST if (@available(macOS 10.13, *)) { METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->driverdata; - if (vsync) { - data.mtllayer.displaySyncEnabled = YES; - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } else { + switch (vsync) { + case 0: data.mtllayer.displaySyncEnabled = NO; - renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC; + break; + case 1: + data.mtllayer.displaySyncEnabled = YES; + break; + default: + return SDL_Unsupported(); } return 0; } #endif - return SDL_SetError("This Apple OS does not support displaySyncEnabled!"); + switch (vsync) { + case 1: + return 0; + default: + return SDL_Unsupported(); + } } static SDL_MetalView GetWindowView(SDL_Window *window) @@ -2153,15 +2161,9 @@ static int METAL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ #if (defined(SDL_PLATFORM_MACOS) && defined(MAC_OS_X_VERSION_10_13)) || TARGET_OS_MACCATALYST if (@available(macOS 10.13, *)) { - data.mtllayer.displaySyncEnabled = SDL_GetBooleanProperty(create_props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_FALSE); - if (data.mtllayer.displaySyncEnabled) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } - } else -#endif - { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; + data.mtllayer.displaySyncEnabled = NO; } +#endif /* https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf */ maxtexsize = 4096; @@ -2197,8 +2199,7 @@ static int METAL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ } #endif - renderer->info.max_texture_width = maxtexsize; - renderer->info.max_texture_height = maxtexsize; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, maxtexsize); return 0; } diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c index c6ec93298..4833ce6a8 100644 --- a/src/render/opengl/SDL_render_gl.c +++ b/src/render/opengl/SDL_render_gl.c @@ -1589,12 +1589,9 @@ static int GL_SetVSync(SDL_Renderer *renderer, const int vsync) { int retval; int interval = 0; - if (vsync) { - retval = SDL_GL_SetSwapInterval(1); - } else { - retval = SDL_GL_SetSwapInterval(0); - } - if (retval != 0) { + + retval = SDL_GL_SetSwapInterval(vsync); + if (retval < 0) { return retval; } @@ -1602,13 +1599,10 @@ static int GL_SetVSync(SDL_Renderer *renderer, const int vsync) if (retval < 0) { return retval; } - - if (interval != 0) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } else { - renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC; + if (interval != vsync) { + return SDL_Unsupported(); } - return retval; + return 0; } static int GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) @@ -1678,7 +1672,6 @@ static int GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro renderer->DestroyTexture = GL_DestroyTexture; renderer->DestroyRenderer = GL_DestroyRenderer; renderer->SetVSync = GL_SetVSync; - renderer->info.flags = 0; /* will set some flags below. */ renderer->driverdata = data; GL_InvalidateCachedState(renderer); renderer->window = window; @@ -1711,21 +1704,6 @@ static int GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro */ #endif - if (SDL_GetBooleanProperty(create_props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_FALSE)) { - SDL_GL_SetSwapInterval(1); - } else { - SDL_GL_SetSwapInterval(0); - } - - { - int interval = 0; - if (SDL_GL_GetSwapInterval(&interval) < 0) { - /* Error */ - } else if (interval != 0) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } - } - /* Check for debug output support */ if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &value) == 0 && (value & SDL_GL_CONTEXT_DEBUG_FLAG)) { @@ -1768,19 +1746,16 @@ static int GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro if (non_power_of_two_supported) { data->GL_ARB_texture_non_power_of_two_supported = SDL_TRUE; data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); - renderer->info.max_texture_width = value; - renderer->info.max_texture_height = value; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, value); } else if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) { data->GL_ARB_texture_rectangle_supported = SDL_TRUE; data->textype = GL_TEXTURE_RECTANGLE_ARB; data->glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &value); - renderer->info.max_texture_width = value; - renderer->info.max_texture_height = value; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, value); } else { data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); - renderer->info.max_texture_width = value; - renderer->info.max_texture_height = value; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, value); } /* Check for multitexture support */ diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index 8aa1b9a12..af1417a98 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -2014,12 +2014,19 @@ static int GLES2_SetVSync(SDL_Renderer *renderer, const int vsync) { int retval; int interval = 0; - if (vsync) { - retval = SDL_GL_SetSwapInterval(1); - } else { - retval = SDL_GL_SetSwapInterval(0); + +#ifdef SDL_PLATFORM_WINRT + /* DLudwig, 2013-11-29: ANGLE for WinRT doesn't seem to work unless VSync + * is turned on. Not doing so will freeze the screen's contents to that + * of the first drawn frame. + */ + if (vsync == 0) { + return SDL_Unsupported(); } - if (retval != 0) { +#endif + + retval = SDL_GL_SetSwapInterval(vsync); + if (retval < 0) { return retval; } @@ -2027,13 +2034,10 @@ static int GLES2_SetVSync(SDL_Renderer *renderer, const int vsync) if (retval < 0) { return retval; } - - if (interval != 0) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } else { - renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC; + if (interval != vsync) { + return SDL_Unsupported(); } - return retval; + return 0; } /************************************************************************************************* @@ -2117,29 +2121,6 @@ static int GLES2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ goto error; } -#ifdef SDL_PLATFORM_WINRT - /* DLudwig, 2013-11-29: ANGLE for WinRT doesn't seem to work unless VSync - * is turned on. Not doing so will freeze the screen's contents to that - * of the first drawn frame. - */ - SDL_SetBooleanProperty(create_props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_TRUE); -#endif - - if (SDL_GetBooleanProperty(create_props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_FALSE)) { - SDL_GL_SetSwapInterval(1); - } else { - SDL_GL_SetSwapInterval(0); - } - - { - int interval = 0; - if (SDL_GL_GetSwapInterval(&interval) < 0) { - /* Error */ - } else if (interval != 0) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } - } - /* Check for debug output support */ if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &value) == 0 && (value & SDL_GL_CONTEXT_DEBUG_FLAG)) { @@ -2148,10 +2129,7 @@ static int GLES2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ value = 0; data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); - renderer->info.max_texture_width = value; - value = 0; - data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); - renderer->info.max_texture_height = value; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, value); #if USE_VERTEX_BUFFER_OBJECTS /* we keep a few of these and cycle through them, so data can live for a few frames. */ diff --git a/src/render/ps2/SDL_render_ps2.c b/src/render/ps2/SDL_render_ps2.c index 9df832077..d8e91b423 100644 --- a/src/render/ps2/SDL_render_ps2.c +++ b/src/render/ps2/SDL_render_ps2.c @@ -54,7 +54,7 @@ typedef struct uint64_t drawColor; SDL_Rect *viewport; int32_t vsync_callback_id; - uint8_t vsync; /* 0 (Disabled), 1 (Enabled), 2 (Dynamic) */ + int vsync; /* 0 (Disabled), 1 (Enabled), -1 (Dynamic) */ } PS2_RenderData; static int vsync_sema_id = 0; @@ -544,7 +544,7 @@ static int PS2_RenderPresent(SDL_Renderer *renderer) PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata; if (data->gsGlobal->DoubleBuffering == GS_SETTING_OFF) { - if (data->vsync == 2) { // Dynamic + if (data->vsync == -1) { // Dynamic gsKit_sync(data->gsGlobal); } else if (data->vsync == 1) { gsKit_vsync_wait(); @@ -553,7 +553,7 @@ static int PS2_RenderPresent(SDL_Renderer *renderer) } else { gsKit_queue_exec(data->gsGlobal); gsKit_finish(); - if (data->vsync == 2) { // Dynamic + if (data->vsync == -1) { // Dynamic gsKit_sync(data->gsGlobal); } else if (data->vsync == 1) { gsKit_vsync_wait(); @@ -607,8 +607,16 @@ static void PS2_DestroyRenderer(SDL_Renderer *renderer) static int PS2_SetVSync(SDL_Renderer *renderer, const int vsync) { PS2_RenderData *data = (PS2_RenderData *)renderer->driverdata; - SDL_bool dynamicVsync = SDL_GetHintBoolean(SDL_HINT_RENDER_PS2_DYNAMIC_VSYNC, SDL_FALSE); - data->vsync = vsync ? (dynamicVsync ? 2 : 1) : 0; + switch (vsync) { + case -1: + case 0: + case 1: + // Supported + break; + default: + return SDL_Unsupported(); + } + data->vsync = vsync; return 0; } @@ -617,7 +625,6 @@ static int PS2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pr PS2_RenderData *data; GSGLOBAL *gsGlobal; ee_sema_t sema; - SDL_bool dynamicVsync; SDL_SetupRendererColorspace(renderer, create_props); @@ -669,10 +676,6 @@ static int PS2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pr gsKit_clear(gsGlobal, GS_BLACK); data->gsGlobal = gsGlobal; - dynamicVsync = SDL_GetHintBoolean(SDL_HINT_RENDER_PS2_DYNAMIC_VSYNC, SDL_FALSE); - if (SDL_GetBooleanProperty(create_props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_FALSE)) { - data->vsync = (dynamicVsync ? 2 : 1); - } renderer->WindowEvent = PS2_WindowEvent; renderer->CreateTexture = PS2_CreateTexture; @@ -699,12 +702,8 @@ static int PS2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pr renderer->info.name = PS2_RenderDriver.name; SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_ABGR1555); SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_ABGR8888); - renderer->info.max_texture_width = 1024; - renderer->info.max_texture_height = 1024; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, 1024); - if (data->vsync) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } return 0; } diff --git a/src/render/psp/SDL_render_psp.c b/src/render/psp/SDL_render_psp.c index cb9ea3f8a..d5a38e4ec 100644 --- a/src/render/psp/SDL_render_psp.c +++ b/src/render/psp/SDL_render_psp.c @@ -1333,19 +1333,12 @@ static int PSP_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pr SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_ABGR1555); SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_ABGR4444); SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_ABGR8888); - renderer->info.max_texture_width = 512; - renderer->info.max_texture_height = 512; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, 512); data->initialized = SDL_TRUE; data->most_recent_target = NULL; data->least_recent_target = NULL; - if (SDL_GetBooleanProperty(create_props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_FALSE)) { - data->vsync = SDL_TRUE; - } else { - data->vsync = SDL_FALSE; - } - pixelformat = PixelFormatToPSPFMT(SDL_GetWindowPixelFormat(window)); switch (pixelformat) { case GU_PSM_4444: @@ -1399,9 +1392,6 @@ static int PSP_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pr sceKernelRegisterSubIntrHandler(PSP_VBLANK_INT, 0, psp_on_vblank, data); sceKernelEnableSubIntr(PSP_VBLANK_INT, 0); - if (data->vsync) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } return 0; } diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c index 80cd0406b..dd72a1b1a 100644 --- a/src/render/software/SDL_render_sw.c +++ b/src/render/software/SDL_render_sw.c @@ -1179,7 +1179,7 @@ static int SW_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro const SDL_bool no_hint_set = (!hint || !*hint); if (no_hint_set) { - if (SDL_GetBooleanProperty(create_props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_FALSE)) { + if (SDL_GetBooleanProperty(create_props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER, 0)) { SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1"); } else { SDL_SetHint(SDL_HINT_RENDER_VSYNC, "0"); diff --git a/src/render/vitagxm/SDL_render_vita_gxm.c b/src/render/vitagxm/SDL_render_vita_gxm.c index 3cb1ba0d9..c20206dca 100644 --- a/src/render/vitagxm/SDL_render_vita_gxm.c +++ b/src/render/vitagxm/SDL_render_vita_gxm.c @@ -185,10 +185,8 @@ static int VITA_GXM_SetVSync(SDL_Renderer *renderer, const int vsync) VITA_GXM_RenderData *data = renderer->driverdata; if (vsync) { data->displayData.wait_vblank = SDL_TRUE; - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; } else { data->displayData.wait_vblank = SDL_FALSE; - renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC; } return 0; } @@ -246,18 +244,10 @@ static int VITA_GXM_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, S SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_IYUV); SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_NV12); SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_NV21); - renderer->info.max_texture_width = 4096; - renderer->info.max_texture_height = 4096; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, 4096); data->initialized = SDL_TRUE; - if (SDL_GetBooleanProperty(create_props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_FALSE)) { - data->displayData.wait_vblank = SDL_TRUE; - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } else { - data->displayData.wait_vblank = SDL_FALSE; - } - #ifdef DEBUG_RAZOR sceSysmoduleLoadModule(SCE_SYSMODULE_RAZOR_HUD); sceSysmoduleLoadModule(SCE_SYSMODULE_RAZOR_CAPTURE); diff --git a/src/render/vulkan/SDL_render_vulkan.c b/src/render/vulkan/SDL_render_vulkan.c index 5967fcef4..79577c2cd 100644 --- a/src/render/vulkan/SDL_render_vulkan.c +++ b/src/render/vulkan/SDL_render_vulkan.c @@ -293,6 +293,7 @@ typedef struct VkSurfaceCapabilitiesKHR surfaceCapabilities; VkSurfaceFormatKHR *surfaceFormats; SDL_bool recreateSwapchain; + int vsync; VkFramebuffer *framebuffers; VkRenderPass renderPasses[SDL_VULKAN_NUM_RENDERPASSES]; @@ -2091,7 +2092,7 @@ static VkResult VULKAN_CreateSwapChain(SDL_Renderer *renderer, int w, int h) /* Choose a present mode. If vsync is requested, then use VK_PRESENT_MODE_FIFO_KHR which is guaranteed to be supported */ VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR; - if (!(renderer->info.flags & SDL_RENDERER_PRESENTVSYNC)) { + if (!rendererData->vsync) { uint32_t presentModeCount = 0; result = vkGetPhysicalDeviceSurfacePresentModesKHR(rendererData->physicalDevice, rendererData->surface, &presentModeCount, NULL); if (result != VK_SUCCESS) { @@ -4024,13 +4025,16 @@ static int VULKAN_SetVSync(SDL_Renderer *renderer, const int vsync) { VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->driverdata; - Uint32 prevFlags = renderer->info.flags; - if (vsync) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } else { - renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC; + switch (vsync) { + case 0: + case 1: + /* Supported */ + break; + default: + return SDL_Unsupported(); } - if (prevFlags != renderer->info.flags) { + if (vsync != rendererData->vsync) { + rendererData->vsync = vsync; rendererData->recreateSwapchain = SDL_TRUE; } return 0; @@ -4083,6 +4087,7 @@ static int VULKAN_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL renderer->RenderPresent = VULKAN_RenderPresent; renderer->DestroyTexture = VULKAN_DestroyTexture; renderer->DestroyRenderer = VULKAN_DestroyRenderer; + renderer->SetVSync = VULKAN_SetVSync; renderer->driverdata = rendererData; VULKAN_InvalidateCachedState(renderer); @@ -4091,13 +4096,7 @@ static int VULKAN_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_XRGB8888); SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_XBGR2101010); SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_RGBA64_FLOAT); - renderer->info.max_texture_width = 16384; - renderer->info.max_texture_height = 16384; - - if (SDL_GetBooleanProperty(create_props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_BOOLEAN, SDL_FALSE)) { - renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; - } - renderer->SetVSync = VULKAN_SetVSync; + SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, 16384); /* HACK: make sure the SDL_Renderer references the SDL_Window data now, in * order to give init functions access to the underlying window handle: diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index 2550bb43e..684b2837a 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -535,7 +535,7 @@ int SDLTest_CommonArg(SDLTest_CommonState *state, int index) return 2; } if (SDL_strcasecmp(argv[index], "--vsync") == 0) { - state->render_flags |= SDL_RENDERER_PRESENTVSYNC; + state->render_vsync = 1; return 1; } if (SDL_strcasecmp(argv[index], "--noframe") == 0) { @@ -952,18 +952,6 @@ static void SDLTest_PrintButtonMask(char *text, size_t maxlen, Uint32 flags) } } -static void SDLTest_PrintRendererFlag(char *text, size_t maxlen, Uint32 flag) -{ - switch (flag) { - case SDL_RENDERER_PRESENTVSYNC: - SDL_snprintfcat(text, maxlen, "PresentVSync"); - break; - default: - SDL_snprintfcat(text, maxlen, "0x%8.8x", flag); - break; - } -} - static void SDLTest_PrintPixelFormat(char *text, size_t maxlen, Uint32 format) { const char *name = SDL_GetPixelFormatName(format); @@ -1019,41 +1007,30 @@ static void SDLTest_PrintScaleMode(char *text, size_t maxlen, SDL_ScaleMode scal } } -static void SDLTest_PrintRenderer(SDL_RendererInfo *info) +static void SDLTest_PrintRenderer(SDL_Renderer *renderer) { - int i, count; + SDL_RendererInfo info; + int i; char text[1024]; + int max_texture_size; - SDL_Log(" Renderer %s:\n", info->name); + SDL_GetRendererInfo(renderer, &info); - (void)SDL_snprintf(text, sizeof(text), " Flags: 0x%8.8" SDL_PRIX32, info->flags); - SDL_snprintfcat(text, sizeof(text), " ("); - count = 0; - for (i = 0; i < 8 * sizeof(info->flags); ++i) { - Uint32 flag = (1 << i); - if (info->flags & flag) { - if (count > 0) { - SDL_snprintfcat(text, sizeof(text), " | "); - } - SDLTest_PrintRendererFlag(text, sizeof(text), flag); - ++count; - } - } - SDL_snprintfcat(text, sizeof(text), ")"); - SDL_Log("%s\n", text); + SDL_Log(" Renderer %s:\n", info.name); + SDL_Log(" VSync: %d\n", (int)SDL_GetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_VSYNC_NUMBER, 0)); - (void)SDL_snprintf(text, sizeof(text), " Texture formats (%d): ", info->num_texture_formats); - for (i = 0; i < info->num_texture_formats; ++i) { + (void)SDL_snprintf(text, sizeof(text), " Texture formats (%d): ", info.num_texture_formats); + for (i = 0; i < info.num_texture_formats; ++i) { if (i > 0) { SDL_snprintfcat(text, sizeof(text), ", "); } - SDLTest_PrintPixelFormat(text, sizeof(text), info->texture_formats[i]); + SDLTest_PrintPixelFormat(text, sizeof(text), info.texture_formats[i]); } SDL_Log("%s\n", text); - if (info->max_texture_width || info->max_texture_height) { - SDL_Log(" Max Texture Size: %dx%d\n", - info->max_texture_width, info->max_texture_height); + max_texture_size = (int)SDL_GetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, 0); + if (max_texture_size) { + SDL_Log(" Max Texture Size: %dx%d\n", max_texture_size, max_texture_size); } } @@ -1395,8 +1372,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state) } if (!state->skip_renderer && (state->renderdriver || !(state->window_flags & (SDL_WINDOW_OPENGL | SDL_WINDOW_VULKAN | SDL_WINDOW_METAL)))) { - state->renderers[i] = SDL_CreateRenderer(state->windows[i], - state->renderdriver, state->render_flags); + state->renderers[i] = SDL_CreateRenderer(state->windows[i], state->renderdriver); if (!state->renderers[i]) { SDL_Log("Couldn't create renderer: %s\n", SDL_GetError()); @@ -1406,6 +1382,9 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state) state->logical_w = state->window_w; state->logical_h = state->window_h; } + if (state->render_vsync) { + SDL_SetRenderVSync(state->renderers[i], state->render_vsync); + } if (SDL_SetRenderLogicalPresentation(state->renderers[i], state->logical_w, state->logical_h, state->logical_presentation, state->logical_scale_mode) < 0) { SDL_Log("Couldn't set logical presentation: %s\n", SDL_GetError()); return SDL_FALSE; @@ -1414,11 +1393,8 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state) SDL_SetRenderScale(state->renderers[i], state->scale, state->scale); } if (state->verbose & VERBOSE_RENDER) { - SDL_RendererInfo info; - SDL_Log("Current renderer:\n"); - SDL_GetRendererInfo(state->renderers[i], &info); - SDLTest_PrintRenderer(&info); + SDLTest_PrintRenderer(state->renderers[i]); } } diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index d794fccbb..cf752dbf1 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -290,7 +290,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, S /* Check to see if there's a specific driver requested */ if (specific_accelerated_renderer) { - renderer = SDL_CreateRenderer(window, hint, 0); + renderer = SDL_CreateRenderer(window, hint); if (!renderer || (SDL_GetRendererInfo(renderer, &info) < 0)) { if (renderer) { SDL_DestroyRenderer(renderer); @@ -302,7 +302,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, S for (i = 0; i < total; ++i) { const char *name = SDL_GetRenderDriver(i); if (name && (SDL_strcmp(name, SDL_SOFTWARE_RENDERER) != 0)) { - renderer = SDL_CreateRenderer(window, name, 0); + renderer = SDL_CreateRenderer(window, name); if (renderer) { break; /* this will work. */ } diff --git a/test/checkkeysthreads.c b/test/checkkeysthreads.c index d04975117..4a1c08def 100644 --- a/test/checkkeysthreads.c +++ b/test/checkkeysthreads.c @@ -276,7 +276,7 @@ int main(int argc, char *argv[]) /* On wayland, no window will actually show until something has actually been displayed. */ - renderer = SDL_CreateRenderer(window, NULL, 0); + renderer = SDL_CreateRenderer(window, NULL); SDL_RenderPresent(renderer); #ifdef SDL_PLATFORM_IOS diff --git a/test/testautomation_render.c b/test/testautomation_render.c index a49f8d2b4..a7a192193 100644 --- a/test/testautomation_render.c +++ b/test/testautomation_render.c @@ -62,7 +62,7 @@ static void InitCreateRenderer(void *arg) renderer_name = SDL_SOFTWARE_RENDERER; } - renderer = SDL_CreateRenderer(window, renderer_name, 0); + renderer = SDL_CreateRenderer(window, renderer_name); SDLTest_AssertPass("SDL_CreateRenderer()"); SDLTest_AssertCheck(renderer != NULL, "Check SDL_CreateRenderer result: %s", renderer != NULL ? "success" : SDL_GetError()); if (renderer == NULL) { diff --git a/test/testautomation_video.c b/test/testautomation_video.c index 44d63b80c..d25922feb 100644 --- a/test/testautomation_video.c +++ b/test/testautomation_video.c @@ -45,7 +45,7 @@ static SDL_Window *createVideoSuiteTestWindow(const char *title) } if (needs_renderer) { - SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL, 0); + SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL); if (renderer) { SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); SDL_RenderClear(renderer); @@ -1728,7 +1728,7 @@ static int video_setWindowCenteredOnDisplay(void *arg) /* Wayland windows require that a frame be presented before they are fully mapped and visible onscreen. */ if (video_driver_is_wayland) { - SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL, 0); + SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL); if (renderer) { SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); diff --git a/test/testcontroller.c b/test/testcontroller.c index a7a89f915..74b7a1355 100644 --- a/test/testcontroller.c +++ b/test/testcontroller.c @@ -2028,7 +2028,7 @@ int main(int argc, char *argv[]) return 2; } - screen = SDL_CreateRenderer(window, NULL, 0); + screen = SDL_CreateRenderer(window, NULL); if (!screen) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError()); SDL_DestroyWindow(window); diff --git a/test/testgl.c b/test/testgl.c index 24772686c..e70172b8a 100644 --- a/test/testgl.c +++ b/test/testgl.c @@ -295,18 +295,8 @@ int main(int argc, char *argv[]) return 0; } - if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) { - /* try late-swap-tearing first. If not supported, try normal vsync. */ - if (SDL_GL_SetSwapInterval(-1) == 0) { - swap_interval = -1; - } else { - SDL_GL_SetSwapInterval(1); - swap_interval = 1; - } - } else { - SDL_GL_SetSwapInterval(0); /* disable vsync. */ - swap_interval = 0; - } + SDL_GL_SetSwapInterval(state->render_vsync); + swap_interval = state->render_vsync; mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay()); if (mode) { diff --git a/test/testgles.c b/test/testgles.c index e6fc077ea..45ff614b6 100644 --- a/test/testgles.c +++ b/test/testgles.c @@ -190,11 +190,7 @@ int main(int argc, char *argv[]) } } - if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) { - SDL_GL_SetSwapInterval(1); - } else { - SDL_GL_SetSwapInterval(0); - } + SDL_GL_SetSwapInterval(state->render_vsync); mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay()); if (mode) { diff --git a/test/testgles2.c b/test/testgles2.c index b0b9994a9..21a690d11 100644 --- a/test/testgles2.c +++ b/test/testgles2.c @@ -771,11 +771,7 @@ int main(int argc, char *argv[]) return 0; } - if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) { - SDL_GL_SetSwapInterval(1); - } else { - SDL_GL_SetSwapInterval(0); - } + SDL_GL_SetSwapInterval(state->render_vsync); mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay()); SDL_Log("Threaded : %s\n", threaded ? "yes" : "no"); diff --git a/test/testgles2_sdf.c b/test/testgles2_sdf.c index bdf2c7092..a8b27055f 100644 --- a/test/testgles2_sdf.c +++ b/test/testgles2_sdf.c @@ -605,11 +605,7 @@ int main(int argc, char *argv[]) SDL_SetSurfaceBlendMode(g_surf_sdf, SDL_BLENDMODE_BLEND); } - if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) { - SDL_GL_SetSwapInterval(1); - } else { - SDL_GL_SetSwapInterval(0); - } + SDL_GL_SetSwapInterval(state->render_vsync); mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay()); if (mode) { diff --git a/test/testmessage.c b/test/testmessage.c index e81bcda02..76ee074c2 100644 --- a/test/testmessage.c +++ b/test/testmessage.c @@ -204,7 +204,7 @@ int main(int argc, char *argv[]) /* On wayland, no window will actually show until something has actually been displayed. */ - SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL, 0); + SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL); SDL_RenderPresent(renderer); success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, diff --git a/test/testmouse.c b/test/testmouse.c index 2e087c05c..3382764d7 100644 --- a/test/testmouse.c +++ b/test/testmouse.c @@ -322,7 +322,7 @@ int main(int argc, char *argv[]) loop_data.done = SDL_FALSE; - loop_data.renderer = SDL_CreateRenderer(window, NULL, 0); + loop_data.renderer = SDL_CreateRenderer(window, NULL); if (!loop_data.renderer) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError()); SDL_DestroyWindow(window); diff --git a/test/testnative.c b/test/testnative.c index 02b0708c3..483408b21 100644 --- a/test/testnative.c +++ b/test/testnative.c @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) SDL_SetWindowTitle(window, "SDL Native Window Test"); /* Create the renderer */ - renderer = SDL_CreateRenderer(window, NULL, 0); + renderer = SDL_CreateRenderer(window, NULL); if (!renderer) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError()); quit(5); diff --git a/test/testoffscreen.c b/test/testoffscreen.c index 59696d693..a69a0f757 100644 --- a/test/testoffscreen.c +++ b/test/testoffscreen.c @@ -127,7 +127,7 @@ int main(int argc, char *argv[]) return SDL_FALSE; } - renderer = SDL_CreateRenderer(window, NULL, 0); + renderer = SDL_CreateRenderer(window, NULL); if (!renderer) { SDL_Log("Couldn't create renderer: %s\n", diff --git a/test/testpopup.c b/test/testpopup.c index 1782acc85..2ebf71d3f 100644 --- a/test/testpopup.c +++ b/test/testpopup.c @@ -105,7 +105,7 @@ static SDL_bool create_popup(struct PopupWindow *new_popup, SDL_bool is_menu) (int)x, (int)y + v_off, w, h, flags); if (new_win) { - new_renderer = SDL_CreateRenderer(new_win, state->renderdriver, state->render_flags); + new_renderer = SDL_CreateRenderer(new_win, state->renderdriver); new_popup->win = new_win; new_popup->renderer = new_renderer; diff --git a/test/testshape.c b/test/testshape.c index 971a04b6c..bf2a2a268 100644 --- a/test/testshape.c +++ b/test/testshape.c @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) goto quit; } - renderer = SDL_CreateRenderer(window, NULL, 0); + renderer = SDL_CreateRenderer(window, NULL); if (!renderer) { SDL_Log("Couldn't create renderer: %s\n", SDL_GetError()); goto quit; diff --git a/test/teststreaming.c b/test/teststreaming.c index 0d1cae6d0..8669157c1 100644 --- a/test/teststreaming.c +++ b/test/teststreaming.c @@ -180,7 +180,7 @@ int main(int argc, char **argv) quit(3); } - renderer = SDL_CreateRenderer(window, NULL, 0); + renderer = SDL_CreateRenderer(window, NULL); if (!renderer) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError()); quit(4); diff --git a/test/testwaylandcustom.c b/test/testwaylandcustom.c index 46a03ac35..b953e08d4 100644 --- a/test/testwaylandcustom.c +++ b/test/testwaylandcustom.c @@ -224,7 +224,7 @@ int main(int argc, char **argv) } /* Create the renderer */ - renderer = SDL_CreateRenderer(window, NULL, 0); + renderer = SDL_CreateRenderer(window, NULL); if (!renderer) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Renderer creation failed"); goto exit; diff --git a/test/testyuv.c b/test/testyuv.c index d3cc1b7a1..6f551a94a 100644 --- a/test/testyuv.c +++ b/test/testyuv.c @@ -471,7 +471,7 @@ int main(int argc, char **argv) return 4; } - renderer = SDL_CreateRenderer(window, NULL, 0); + renderer = SDL_CreateRenderer(window, NULL); if (!renderer) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError()); return 4;