2015-06-21 17:33:46 +02:00
|
|
|
|
/*
|
|
|
|
|
|
Simple DirectMedia Layer
|
2024-01-01 13:15:26 -08:00
|
|
|
|
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
|
|
appreciated but is not required.
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
|
|
misrepresented as being the original software.
|
|
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
|
|
*/
|
2022-11-29 18:34:15 -08:00
|
|
|
|
#include "SDL_internal.h"
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// The SDL 2D rendering system
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
#include "SDL_sysrender.h"
|
|
|
|
|
|
#include "software/SDL_render_sw_c.h"
|
2020-03-17 15:47:30 +01:00
|
|
|
|
#include "../video/SDL_pixels_c.h"
|
2023-01-01 23:05:25 +01:00
|
|
|
|
#include "../video/SDL_video_c.h"
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-01-24 02:40:51 +01:00
|
|
|
|
#ifdef SDL_PLATFORM_ANDROID
|
2022-11-30 12:51:59 -08:00
|
|
|
|
#include "../core/android/SDL_android.h"
|
2024-07-24 12:43:44 -07:00
|
|
|
|
#include "../video/android/SDL_androidevents.h"
|
2019-06-28 16:38:42 +02:00
|
|
|
|
#endif
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2021-04-02 14:01:41 -04:00
|
|
|
|
/* as a courtesy to iOS apps, we don't try to draw when in the background, as
|
|
|
|
|
|
that will crash the app. However, these apps _should_ have used
|
2023-01-23 17:54:09 -08:00
|
|
|
|
SDL_AddEventWatch to catch SDL_EVENT_WILL_ENTER_BACKGROUND events and stopped
|
2021-04-02 14:01:41 -04:00
|
|
|
|
drawing themselves. Other platforms still draw, as the compositor can use it,
|
|
|
|
|
|
and more importantly: drawing to render targets isn't lost. But I still think
|
|
|
|
|
|
this should probably be removed at some point in the future. --ryan. */
|
2024-01-24 02:40:51 +01:00
|
|
|
|
#if defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_TVOS) || defined(SDL_PLATFORM_ANDROID)
|
2021-04-02 14:01:41 -04:00
|
|
|
|
#define DONT_DRAW_WHILE_HIDDEN 1
|
|
|
|
|
|
#else
|
|
|
|
|
|
#define DONT_DRAW_WHILE_HIDDEN 0
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2024-02-11 23:12:20 -06:00
|
|
|
|
#define SDL_PROP_WINDOW_RENDERER_POINTER "SDL.internal.window.renderer"
|
2024-03-03 09:46:54 -08:00
|
|
|
|
#define SDL_PROP_TEXTURE_PARENT_POINTER "SDL.internal.texture.parent"
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-06-03 04:09:28 -07:00
|
|
|
|
#define CHECK_RENDERER_MAGIC_BUT_NOT_DESTROYED_FLAG(renderer, retval) \
|
|
|
|
|
|
if (!SDL_ObjectValid(renderer, SDL_OBJECT_TYPE_RENDERER)) { \
|
|
|
|
|
|
SDL_InvalidParamError("renderer"); \
|
|
|
|
|
|
return retval; \
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-18 10:20:31 -04:00
|
|
|
|
#define CHECK_RENDERER_MAGIC(renderer, retval) \
|
|
|
|
|
|
CHECK_RENDERER_MAGIC_BUT_NOT_DESTROYED_FLAG(renderer, retval); \
|
|
|
|
|
|
if ((renderer)->destroyed) { \
|
|
|
|
|
|
SDL_SetError("Renderer's window has been destroyed, can't use further"); \
|
|
|
|
|
|
return retval; \
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-05 15:20:48 +01:00
|
|
|
|
#define CHECK_TEXTURE_MAGIC(texture, retval) \
|
2024-06-03 04:09:28 -07:00
|
|
|
|
if (!SDL_ObjectValid(texture, SDL_OBJECT_TYPE_TEXTURE)) { \
|
2022-12-05 15:20:48 +01:00
|
|
|
|
SDL_InvalidParamError("texture"); \
|
|
|
|
|
|
return retval; \
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Predefined blend modes
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
#define SDL_COMPOSE_BLENDMODE(srcColorFactor, dstColorFactor, colorOperation, \
|
|
|
|
|
|
srcAlphaFactor, dstAlphaFactor, alphaOperation) \
|
2022-12-05 15:20:48 +01:00
|
|
|
|
(SDL_BlendMode)(((Uint32)(colorOperation) << 0) | \
|
|
|
|
|
|
((Uint32)(srcColorFactor) << 4) | \
|
|
|
|
|
|
((Uint32)(dstColorFactor) << 8) | \
|
|
|
|
|
|
((Uint32)(alphaOperation) << 16) | \
|
|
|
|
|
|
((Uint32)(srcAlphaFactor) << 20) | \
|
|
|
|
|
|
((Uint32)(dstAlphaFactor) << 24))
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
#define SDL_BLENDMODE_NONE_FULL \
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ZERO, SDL_BLENDOPERATION_ADD, \
|
|
|
|
|
|
SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ZERO, SDL_BLENDOPERATION_ADD)
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
#define SDL_BLENDMODE_BLEND_FULL \
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, \
|
|
|
|
|
|
SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD)
|
|
|
|
|
|
|
2024-07-15 08:27:58 -07:00
|
|
|
|
#define SDL_BLENDMODE_BLEND_PREMULTIPLIED_FULL \
|
|
|
|
|
|
SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, \
|
|
|
|
|
|
SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD)
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
#define SDL_BLENDMODE_ADD_FULL \
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD, \
|
|
|
|
|
|
SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD)
|
|
|
|
|
|
|
2024-07-15 08:27:58 -07:00
|
|
|
|
#define SDL_BLENDMODE_ADD_PREMULTIPLIED_FULL \
|
|
|
|
|
|
SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD, \
|
|
|
|
|
|
SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD)
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
#define SDL_BLENDMODE_MOD_FULL \
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_SRC_COLOR, SDL_BLENDOPERATION_ADD, \
|
|
|
|
|
|
SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
#define SDL_BLENDMODE_MUL_FULL \
|
2020-01-16 08:52:59 -08:00
|
|
|
|
SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_DST_COLOR, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, \
|
2023-03-15 22:06:41 +01:00
|
|
|
|
SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD)
|
2020-01-16 08:52:59 -08:00
|
|
|
|
|
2023-03-29 21:49:01 +00:00
|
|
|
|
#ifndef SDL_RENDER_DISABLED
|
2015-06-21 17:33:46 +02:00
|
|
|
|
static const SDL_RenderDriver *render_drivers[] = {
|
2024-02-15 20:55:02 +03:00
|
|
|
|
#if SDL_VIDEO_RENDER_D3D11
|
2015-06-21 17:33:46 +02:00
|
|
|
|
&D3D11_RenderDriver,
|
|
|
|
|
|
#endif
|
2024-02-28 09:00:36 -08:00
|
|
|
|
#if SDL_VIDEO_RENDER_D3D12
|
|
|
|
|
|
&D3D12_RenderDriver,
|
|
|
|
|
|
#endif
|
2024-02-15 20:55:02 +03:00
|
|
|
|
#if SDL_VIDEO_RENDER_D3D
|
2023-03-02 15:08:24 -08:00
|
|
|
|
&D3D_RenderDriver,
|
2022-06-06 17:42:30 -07:00
|
|
|
|
#endif
|
2024-02-15 20:55:02 +03:00
|
|
|
|
#if SDL_VIDEO_RENDER_METAL
|
2018-12-19 18:10:02 -05:00
|
|
|
|
&METAL_RenderDriver,
|
|
|
|
|
|
#endif
|
2024-02-15 20:55:02 +03:00
|
|
|
|
#if SDL_VIDEO_RENDER_OGL
|
2015-06-21 17:33:46 +02:00
|
|
|
|
&GL_RenderDriver,
|
|
|
|
|
|
#endif
|
2024-02-15 20:55:02 +03:00
|
|
|
|
#if SDL_VIDEO_RENDER_OGL_ES2
|
2015-06-21 17:33:46 +02:00
|
|
|
|
&GLES2_RenderDriver,
|
|
|
|
|
|
#endif
|
2024-02-15 20:55:02 +03:00
|
|
|
|
#if SDL_VIDEO_RENDER_PS2
|
2022-06-30 11:44:35 -03:00
|
|
|
|
&PS2_RenderDriver,
|
|
|
|
|
|
#endif
|
2024-02-15 20:55:02 +03:00
|
|
|
|
#if SDL_VIDEO_RENDER_PSP
|
2015-06-21 17:33:46 +02:00
|
|
|
|
&PSP_RenderDriver,
|
|
|
|
|
|
#endif
|
2024-02-15 20:55:02 +03:00
|
|
|
|
#if SDL_VIDEO_RENDER_VITA_GXM
|
2020-11-16 20:40:22 +03:00
|
|
|
|
&VITA_GXM_RenderDriver,
|
|
|
|
|
|
#endif
|
Vulkan Renderer (#9114)
This pull request adds an implementation of a Vulkan Render backend to SDL. I have so far tested this primarily on Windows, but also smoke tested on Linux and macOS (MoltenVK). I have not tried it yet on Android, but it should be usable there as well (sans any bugs I missed). This began as a port of the SDL Direct3D12 Renderer, which is the closest thing to Vulkan as existed in the SDL codebase. The shaders are more or less identical (with the only differences being in descriptor bindings vs root descriptors). The shaders are built using the HLSL frontend of glslang.
Everything in the code is pure Vulkan 1.0 (no extensions), with the exception of HDR support which requires the Vulkan instance extension `VK_EXT_swapchain_colorspace`. The code could have been simplified considerably if I used dynamic rendering, push descriptors, extended dynamic state, and other modern Vulkan-isms, but I felt it was more important to make the code as vanilla Vulkan as possible so that it would run on any Vulkan implementation.
The main differences with the Direct3D12 renderer are:
* Having to manage renderpasses for performing clears. There is likely some optimization that would still remain for more efficient use of TBDR hardware where there might be some unnecessary load/stores, but it does attempt to do clears using renderpasses.
* Constant buffer data couldn't be directly updated in the command buffer since I didn't want to rely on push descriptors, so there is a persistently mapped buffer with increasing offset per swapchain image where CB data gets written.
* Many more resources are dependent on the swapchain resizing due to i.e. Vulkan requiring the VkFramebuffer to reference the VkImageView of the swapchain, so there is a bit more code around handling that than was necessary in D3D12.
* For NV12/NV21 textures, rather than there being plane data in the texture itself, the UV data is placed in a separate `VkImage`/`VkImageView`.
I've verified that `testcolorspace` works with both sRGB and HDR linear. I've tested `testoverlay` works with the various YUV/NV12/NV21 formats. I've tested `testsprite`. I've checked that window resizing and swapchain out-of-date handling when minimizing are working. I've run through `testautomation` with the render tests. I also have run several of the tests with Vulkan validation and synchronization validation. Surely I will have missed some things, but I think it's in a good state to be merged and build out from here.
2024-02-22 17:58:11 -05:00
|
|
|
|
#if SDL_VIDEO_RENDER_VULKAN
|
|
|
|
|
|
&VULKAN_RenderDriver,
|
|
|
|
|
|
#endif
|
2020-01-21 21:33:40 +01:00
|
|
|
|
#if SDL_VIDEO_RENDER_SW
|
2015-06-21 17:33:46 +02:00
|
|
|
|
&SW_RenderDriver
|
2020-01-21 21:33:40 +01:00
|
|
|
|
#endif
|
2015-06-21 17:33:46 +02:00
|
|
|
|
};
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
#endif // !SDL_RENDER_DISABLED
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-06-23 00:41:19 -07:00
|
|
|
|
static SDL_Renderer *SDL_renderers;
|
|
|
|
|
|
|
|
|
|
|
|
void SDL_QuitRender(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
while (SDL_renderers) {
|
|
|
|
|
|
SDL_DestroyRenderer(SDL_renderers);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-01-29 18:32:27 -08:00
|
|
|
|
|
2024-07-08 14:59:18 -07:00
|
|
|
|
int SDL_AddSupportedTextureFormat(SDL_Renderer *renderer, SDL_PixelFormat format)
|
2024-05-09 12:10:42 -07:00
|
|
|
|
{
|
2024-07-08 14:59:18 -07:00
|
|
|
|
SDL_PixelFormat *texture_formats = (SDL_PixelFormat *)SDL_realloc((void *)renderer->texture_formats, (renderer->num_texture_formats + 2) * sizeof(SDL_PixelFormat));
|
2024-05-09 12:10:42 -07:00
|
|
|
|
if (!texture_formats) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2024-06-03 19:26:43 -07:00
|
|
|
|
texture_formats[renderer->num_texture_formats++] = format;
|
|
|
|
|
|
texture_formats[renderer->num_texture_formats] = SDL_PIXELFORMAT_UNKNOWN;
|
|
|
|
|
|
renderer->texture_formats = texture_formats;
|
2024-07-12 09:39:58 -07:00
|
|
|
|
SDL_SetPointerProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER, texture_formats);
|
2024-05-09 12:10:42 -07:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-29 18:32:27 -08:00
|
|
|
|
void SDL_SetupRendererColorspace(SDL_Renderer *renderer, SDL_PropertiesID props)
|
|
|
|
|
|
{
|
|
|
|
|
|
renderer->output_colorspace = (SDL_Colorspace)SDL_GetNumberProperty(props, SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER, SDL_COLORSPACE_SRGB);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static float sRGBtoLinear(float v)
|
|
|
|
|
|
{
|
|
|
|
|
|
return v <= 0.04045f ? (v / 12.92f) : SDL_powf(((v + 0.055f) / 1.055f), 2.4f);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static float sRGBfromLinear(float v)
|
|
|
|
|
|
{
|
|
|
|
|
|
return v <= 0.0031308f ? (v * 12.92f) : (SDL_powf(v, 1.0f / 2.4f) * 1.055f - 0.055f);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool SDL_RenderingLinearSpace(SDL_Renderer *renderer)
|
2024-01-29 18:32:27 -08:00
|
|
|
|
{
|
2024-02-02 12:09:37 -08:00
|
|
|
|
SDL_Colorspace colorspace;
|
2024-01-29 18:32:27 -08:00
|
|
|
|
|
2024-02-02 12:09:37 -08:00
|
|
|
|
if (renderer->target) {
|
|
|
|
|
|
colorspace = renderer->target->colorspace;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
colorspace = renderer->output_colorspace;
|
2024-01-29 18:32:27 -08:00
|
|
|
|
}
|
2024-02-19 08:45:02 -08:00
|
|
|
|
if (colorspace == SDL_COLORSPACE_SRGB_LINEAR) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
return true;
|
2024-02-02 12:09:37 -08:00
|
|
|
|
}
|
2024-08-22 09:21:26 -07:00
|
|
|
|
return false;
|
2024-01-29 18:32:27 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-02 12:09:37 -08:00
|
|
|
|
void SDL_ConvertToLinear(SDL_FColor *color)
|
2024-01-29 18:32:27 -08:00
|
|
|
|
{
|
2024-02-02 12:09:37 -08:00
|
|
|
|
color->r = sRGBtoLinear(color->r);
|
|
|
|
|
|
color->g = sRGBtoLinear(color->g);
|
|
|
|
|
|
color->b = sRGBtoLinear(color->b);
|
|
|
|
|
|
}
|
2024-01-29 18:32:27 -08:00
|
|
|
|
|
2024-02-02 12:09:37 -08:00
|
|
|
|
void SDL_ConvertFromLinear(SDL_FColor *color)
|
|
|
|
|
|
{
|
|
|
|
|
|
color->r = sRGBfromLinear(color->r);
|
|
|
|
|
|
color->g = sRGBfromLinear(color->g);
|
|
|
|
|
|
color->b = sRGBfromLinear(color->b);
|
2024-01-29 18:32:27 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static SDL_INLINE void DebugLogRenderCommands(const SDL_RenderCommand *cmd)
|
2018-09-24 02:07:35 -04:00
|
|
|
|
{
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
unsigned int i = 1;
|
|
|
|
|
|
SDL_Log("Render commands to flush:");
|
|
|
|
|
|
while (cmd) {
|
|
|
|
|
|
switch (cmd->command) {
|
|
|
|
|
|
case SDL_RENDERCMD_NO_OP:
|
|
|
|
|
|
SDL_Log(" %u. no-op", i++);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case SDL_RENDERCMD_SETVIEWPORT:
|
|
|
|
|
|
SDL_Log(" %u. set viewport (first=%u, rect={(%d, %d), %dx%d})", i++,
|
|
|
|
|
|
(unsigned int) cmd->data.viewport.first,
|
|
|
|
|
|
cmd->data.viewport.rect.x, cmd->data.viewport.rect.y,
|
|
|
|
|
|
cmd->data.viewport.rect.w, cmd->data.viewport.rect.h);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case SDL_RENDERCMD_SETCLIPRECT:
|
|
|
|
|
|
SDL_Log(" %u. set cliprect (enabled=%s, rect={(%d, %d), %dx%d})", i++,
|
|
|
|
|
|
cmd->data.cliprect.enabled ? "true" : "false",
|
|
|
|
|
|
cmd->data.cliprect.rect.x, cmd->data.cliprect.rect.y,
|
|
|
|
|
|
cmd->data.cliprect.rect.w, cmd->data.cliprect.rect.h);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case SDL_RENDERCMD_SETDRAWCOLOR:
|
2024-02-05 23:20:43 -08:00
|
|
|
|
SDL_Log(" %u. set draw color (first=%u, r=%d, g=%d, b=%d, a=%d, color_scale=%g)", i++,
|
2018-09-24 02:07:35 -04:00
|
|
|
|
(unsigned int) cmd->data.color.first,
|
2024-06-13 19:25:01 +03:00
|
|
|
|
(int) cmd->data.color.color.r, (int) cmd->data.color.color.g,
|
|
|
|
|
|
(int) cmd->data.color.color.b, (int) cmd->data.color.color.a, cmd->data.color.color_scale);
|
2018-09-24 02:07:35 -04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case SDL_RENDERCMD_CLEAR:
|
2024-02-05 23:20:43 -08:00
|
|
|
|
SDL_Log(" %u. clear (first=%u, r=%d, g=%d, b=%d, a=%d, color_scale=%g)", i++,
|
2018-09-24 02:07:35 -04:00
|
|
|
|
(unsigned int) cmd->data.color.first,
|
2024-06-13 19:25:01 +03:00
|
|
|
|
(int) cmd->data.color.color.r, (int) cmd->data.color.color.g,
|
|
|
|
|
|
(int) cmd->data.color.color.b, (int) cmd->data.color.color.a, cmd->data.color.color_scale);
|
2018-09-24 02:07:35 -04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case SDL_RENDERCMD_DRAW_POINTS:
|
2024-02-05 23:20:43 -08:00
|
|
|
|
SDL_Log(" %u. draw points (first=%u, count=%u, r=%d, g=%d, b=%d, a=%d, blend=%d, color_scale=%g)", i++,
|
2018-09-24 02:07:35 -04:00
|
|
|
|
(unsigned int) cmd->data.draw.first,
|
|
|
|
|
|
(unsigned int) cmd->data.draw.count,
|
2024-06-13 19:25:01 +03:00
|
|
|
|
(int) cmd->data.draw.color.r, (int) cmd->data.draw.color.g,
|
|
|
|
|
|
(int) cmd->data.draw.color.b, (int) cmd->data.draw.color.a,
|
2024-02-05 23:20:43 -08:00
|
|
|
|
(int) cmd->data.draw.blend, cmd->data.draw.color_scale);
|
2018-09-24 02:07:35 -04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case SDL_RENDERCMD_DRAW_LINES:
|
2024-02-05 23:20:43 -08:00
|
|
|
|
SDL_Log(" %u. draw lines (first=%u, count=%u, r=%d, g=%d, b=%d, a=%d, blend=%d, color_scale=%g)", i++,
|
2018-09-24 02:07:35 -04:00
|
|
|
|
(unsigned int) cmd->data.draw.first,
|
|
|
|
|
|
(unsigned int) cmd->data.draw.count,
|
2024-06-13 19:25:01 +03:00
|
|
|
|
(int) cmd->data.draw.color.r, (int) cmd->data.draw.color.g,
|
|
|
|
|
|
(int) cmd->data.draw.color.b, (int) cmd->data.draw.color.a,
|
2024-02-05 23:20:43 -08:00
|
|
|
|
(int) cmd->data.draw.blend, cmd->data.draw.color_scale);
|
2018-09-24 02:07:35 -04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case SDL_RENDERCMD_FILL_RECTS:
|
2024-02-05 23:20:43 -08:00
|
|
|
|
SDL_Log(" %u. fill rects (first=%u, count=%u, r=%d, g=%d, b=%d, a=%d, blend=%d, color_scale=%g)", i++,
|
2018-09-24 02:07:35 -04:00
|
|
|
|
(unsigned int) cmd->data.draw.first,
|
|
|
|
|
|
(unsigned int) cmd->data.draw.count,
|
2024-06-13 19:25:01 +03:00
|
|
|
|
(int) cmd->data.draw.color.r, (int) cmd->data.draw.color.g,
|
|
|
|
|
|
(int) cmd->data.draw.color.b, (int) cmd->data.draw.color.a,
|
2024-02-05 23:20:43 -08:00
|
|
|
|
(int) cmd->data.draw.blend, cmd->data.draw.color_scale);
|
2018-09-24 02:07:35 -04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case SDL_RENDERCMD_COPY:
|
2024-02-05 23:20:43 -08:00
|
|
|
|
SDL_Log(" %u. copy (first=%u, count=%u, r=%d, g=%d, b=%d, a=%d, blend=%d, color_scale=%g, tex=%p)", i++,
|
2018-09-24 02:07:35 -04:00
|
|
|
|
(unsigned int) cmd->data.draw.first,
|
|
|
|
|
|
(unsigned int) cmd->data.draw.count,
|
2024-06-13 19:25:01 +03:00
|
|
|
|
(int) cmd->data.draw.color.r, (int) cmd->data.draw.color.g,
|
|
|
|
|
|
(int) cmd->data.draw.color.b, (int) cmd->data.draw.color.a,
|
2024-02-05 23:20:43 -08:00
|
|
|
|
(int) cmd->data.draw.blend, cmd->data.draw.color_scale, cmd->data.draw.texture);
|
2018-09-24 02:07:35 -04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case SDL_RENDERCMD_COPY_EX:
|
2024-02-05 23:20:43 -08:00
|
|
|
|
SDL_Log(" %u. copyex (first=%u, count=%u, r=%d, g=%d, b=%d, a=%d, blend=%d, color_scale=%g, tex=%p)", i++,
|
2018-09-24 02:07:35 -04:00
|
|
|
|
(unsigned int) cmd->data.draw.first,
|
|
|
|
|
|
(unsigned int) cmd->data.draw.count,
|
2024-06-13 19:25:01 +03:00
|
|
|
|
(int) cmd->data.draw.color.r, (int) cmd->data.draw.color.g,
|
|
|
|
|
|
(int) cmd->data.draw.color.b, (int) cmd->data.draw.color.a,
|
2024-02-05 23:20:43 -08:00
|
|
|
|
(int) cmd->data.draw.blend, cmd->data.draw.color_scale, cmd->data.draw.texture);
|
2018-09-24 02:07:35 -04:00
|
|
|
|
break;
|
2021-04-01 20:18:05 +02:00
|
|
|
|
|
|
|
|
|
|
case SDL_RENDERCMD_GEOMETRY:
|
2024-02-05 23:20:43 -08:00
|
|
|
|
SDL_Log(" %u. geometry (first=%u, count=%u, r=%d, g=%d, b=%d, a=%d, blend=%d, color_scale=%g, tex=%p)", i++,
|
2021-04-01 20:18:05 +02:00
|
|
|
|
(unsigned int) cmd->data.draw.first,
|
|
|
|
|
|
(unsigned int) cmd->data.draw.count,
|
2024-06-13 19:25:01 +03:00
|
|
|
|
(int) cmd->data.draw.color.r, (int) cmd->data.draw.color.g,
|
|
|
|
|
|
(int) cmd->data.draw.color.b, (int) cmd->data.draw.color.a,
|
2024-02-05 23:20:43 -08:00
|
|
|
|
(int) cmd->data.draw.blend, cmd->data.draw.color_scale, cmd->data.draw.texture);
|
2021-04-01 20:18:05 +02:00
|
|
|
|
break;
|
|
|
|
|
|
|
2018-09-24 02:07:35 -04:00
|
|
|
|
}
|
|
|
|
|
|
cmd = cmd->next;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
2018-09-20 15:46:02 -04:00
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int FlushRenderCommands(SDL_Renderer *renderer)
|
2018-09-20 15:46:02 -04:00
|
|
|
|
{
|
|
|
|
|
|
int retval;
|
2018-09-23 23:20:40 -04:00
|
|
|
|
|
2023-11-11 10:28:24 +01:00
|
|
|
|
SDL_assert((renderer->render_commands == NULL) == (renderer->render_commands_tail == NULL));
|
2018-09-20 15:46:02 -04:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
if (!renderer->render_commands) { // nothing to do!
|
2018-09-20 15:46:02 -04:00
|
|
|
|
SDL_assert(renderer->vertex_data_used == 0);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-24 02:07:35 -04:00
|
|
|
|
DebugLogRenderCommands(renderer->render_commands);
|
|
|
|
|
|
|
2018-09-20 15:46:02 -04:00
|
|
|
|
retval = renderer->RunCommandQueue(renderer, renderer->render_commands, renderer->vertex_data, renderer->vertex_data_used);
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Move the whole render command queue to the unused pool so we can reuse them next time.
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (renderer->render_commands_tail) {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
renderer->render_commands_tail->next = renderer->render_commands_pool;
|
|
|
|
|
|
renderer->render_commands_pool = renderer->render_commands;
|
|
|
|
|
|
renderer->render_commands_tail = NULL;
|
|
|
|
|
|
renderer->render_commands = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
renderer->vertex_data_used = 0;
|
|
|
|
|
|
renderer->render_command_generation++;
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->color_queued = false;
|
|
|
|
|
|
renderer->color_scale_queued = false;
|
|
|
|
|
|
renderer->viewport_queued = false;
|
|
|
|
|
|
renderer->cliprect_queued = false;
|
2018-09-20 15:46:02 -04:00
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int FlushRenderCommandsIfTextureNeeded(SDL_Texture *texture)
|
2018-09-20 15:46:02 -04:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Renderer *renderer = texture->renderer;
|
|
|
|
|
|
if (texture->last_command_generation == renderer->render_command_generation) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// the current command queue depends on this texture, flush the queue now before it changes
|
2018-09-20 15:46:02 -04:00
|
|
|
|
return FlushRenderCommands(renderer);
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-25 22:41:23 -05:00
|
|
|
|
int SDL_FlushRenderer(SDL_Renderer *renderer)
|
2018-10-04 16:34:44 -04:00
|
|
|
|
{
|
2024-08-22 06:53:25 -07:00
|
|
|
|
if (FlushRenderCommands(renderer) < 0) {
|
2023-11-25 22:41:23 -05:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
renderer->InvalidateCachedState(renderer);
|
|
|
|
|
|
return 0;
|
2018-10-04 16:34:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const size_t alignment, size_t *offset)
|
2018-09-20 15:46:02 -04:00
|
|
|
|
{
|
2018-09-23 23:20:40 -04:00
|
|
|
|
const size_t needed = renderer->vertex_data_used + numbytes + alignment;
|
2021-09-19 00:05:21 -04:00
|
|
|
|
const size_t current_offset = renderer->vertex_data_used;
|
2018-09-23 23:20:40 -04:00
|
|
|
|
|
2021-09-19 00:05:21 -04:00
|
|
|
|
const size_t aligner = (alignment && ((current_offset & (alignment - 1)) != 0)) ? (alignment - (current_offset & (alignment - 1))) : 0;
|
|
|
|
|
|
const size_t aligned = current_offset + aligner;
|
2018-09-23 23:20:40 -04:00
|
|
|
|
|
2019-08-17 00:43:44 -03:00
|
|
|
|
if (renderer->vertex_data_allocation < needed) {
|
2018-09-23 23:20:40 -04:00
|
|
|
|
const size_t current_allocation = renderer->vertex_data ? renderer->vertex_data_allocation : 1024;
|
2019-08-17 00:43:44 -03:00
|
|
|
|
size_t newsize = current_allocation * 2;
|
|
|
|
|
|
void *ptr;
|
|
|
|
|
|
while (newsize < needed) {
|
|
|
|
|
|
newsize *= 2;
|
|
|
|
|
|
}
|
2020-11-14 23:37:26 +03:00
|
|
|
|
|
2019-08-17 00:43:44 -03:00
|
|
|
|
ptr = SDL_realloc(renderer->vertex_data, newsize);
|
2020-11-14 23:37:26 +03:00
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!ptr) {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
renderer->vertex_data = ptr;
|
|
|
|
|
|
renderer->vertex_data_allocation = newsize;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (offset) {
|
2018-09-23 23:20:40 -04:00
|
|
|
|
*offset = aligned;
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-23 23:20:40 -04:00
|
|
|
|
renderer->vertex_data_used += aligner + numbytes;
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
return ((Uint8 *)renderer->vertex_data) + aligned;
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static SDL_RenderCommand *AllocateRenderCommand(SDL_Renderer *renderer)
|
2018-09-20 15:46:02 -04:00
|
|
|
|
{
|
|
|
|
|
|
SDL_RenderCommand *retval = NULL;
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// !!! FIXME: are there threading limitations in SDL's render API? If not, we need to mutex this.
|
2018-09-20 15:46:02 -04:00
|
|
|
|
retval = renderer->render_commands_pool;
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (retval) {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
renderer->render_commands_pool = retval->next;
|
|
|
|
|
|
retval->next = NULL;
|
|
|
|
|
|
} else {
|
2024-03-07 05:20:20 -08:00
|
|
|
|
retval = (SDL_RenderCommand *)SDL_calloc(1, sizeof(*retval));
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!retval) {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-11 10:28:24 +01:00
|
|
|
|
SDL_assert((renderer->render_commands == NULL) == (renderer->render_commands_tail == NULL));
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (renderer->render_commands_tail) {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
renderer->render_commands_tail->next = retval;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
renderer->render_commands = retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
renderer->render_commands_tail = retval;
|
|
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 09:21:02 -07:00
|
|
|
|
static void UpdatePixelViewport(SDL_Renderer *renderer, SDL_RenderViewState *view)
|
2023-02-03 12:25:46 -08:00
|
|
|
|
{
|
2024-06-12 09:21:02 -07:00
|
|
|
|
view->pixel_viewport.x = (int)SDL_floorf(view->viewport.x * view->scale.x);
|
|
|
|
|
|
view->pixel_viewport.y = (int)SDL_floorf(view->viewport.y * view->scale.y);
|
|
|
|
|
|
if (view->viewport.w >= 0) {
|
|
|
|
|
|
view->pixel_viewport.w = (int)SDL_ceilf(view->viewport.w * view->scale.x);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
} else {
|
2024-06-12 19:08:06 -07:00
|
|
|
|
view->pixel_viewport.w = view->pixel_w;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
}
|
2024-06-12 09:21:02 -07:00
|
|
|
|
if (view->viewport.h >= 0) {
|
|
|
|
|
|
view->pixel_viewport.h = (int)SDL_ceilf(view->viewport.h * view->scale.y);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
} else {
|
2024-06-12 19:08:06 -07:00
|
|
|
|
view->pixel_viewport.h = view->pixel_h;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int QueueCmdSetViewport(SDL_Renderer *renderer)
|
2018-09-23 23:20:40 -04:00
|
|
|
|
{
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_Rect viewport;
|
2018-09-23 23:20:40 -04:00
|
|
|
|
int retval = 0;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
|
2024-06-12 09:21:02 -07:00
|
|
|
|
viewport = renderer->view->pixel_viewport;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
|
|
|
|
|
|
if (!renderer->viewport_queued ||
|
|
|
|
|
|
SDL_memcmp(&viewport, &renderer->last_queued_viewport, sizeof(viewport)) != 0) {
|
2018-09-23 23:20:40 -04:00
|
|
|
|
SDL_RenderCommand *cmd = AllocateRenderCommand(renderer);
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (cmd) {
|
2018-09-23 23:20:40 -04:00
|
|
|
|
cmd->command = SDL_RENDERCMD_SETVIEWPORT;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
cmd->data.viewport.first = 0; // render backend will fill this in.
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_copyp(&cmd->data.viewport.rect, &viewport);
|
2018-09-23 23:20:40 -04:00
|
|
|
|
retval = renderer->QueueSetViewport(renderer, cmd);
|
|
|
|
|
|
if (retval < 0) {
|
|
|
|
|
|
cmd->command = SDL_RENDERCMD_NO_OP;
|
|
|
|
|
|
} else {
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_copyp(&renderer->last_queued_viewport, &viewport);
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->viewport_queued = true;
|
2018-09-23 23:20:40 -04:00
|
|
|
|
}
|
2023-02-03 12:25:46 -08:00
|
|
|
|
} else {
|
|
|
|
|
|
retval = -1;
|
2018-09-23 23:20:40 -04:00
|
|
|
|
}
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
2018-09-25 17:04:47 -04:00
|
|
|
|
return retval;
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 09:21:02 -07:00
|
|
|
|
static void UpdatePixelClipRect(SDL_Renderer *renderer, SDL_RenderViewState *view)
|
|
|
|
|
|
{
|
2024-06-12 19:08:06 -07:00
|
|
|
|
view->pixel_clip_rect.x = (int)SDL_floorf(view->clip_rect.x * view->scale.x);
|
|
|
|
|
|
view->pixel_clip_rect.y = (int)SDL_floorf(view->clip_rect.y * view->scale.y);
|
|
|
|
|
|
view->pixel_clip_rect.w = (int)SDL_ceilf(view->clip_rect.w * view->scale.x);
|
|
|
|
|
|
view->pixel_clip_rect.h = (int)SDL_ceilf(view->clip_rect.h * view->scale.y);
|
2024-06-12 09:21:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int QueueCmdSetClipRect(SDL_Renderer *renderer)
|
2018-09-23 23:20:40 -04:00
|
|
|
|
{
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_Rect clip_rect;
|
2018-09-23 23:20:40 -04:00
|
|
|
|
int retval = 0;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
|
2024-06-12 19:08:06 -07:00
|
|
|
|
clip_rect = renderer->view->pixel_clip_rect;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
|
|
|
|
|
|
if (!renderer->cliprect_queued ||
|
|
|
|
|
|
renderer->view->clipping_enabled != renderer->last_queued_cliprect_enabled ||
|
|
|
|
|
|
SDL_memcmp(&clip_rect, &renderer->last_queued_cliprect, sizeof(clip_rect)) != 0) {
|
2018-09-23 23:20:40 -04:00
|
|
|
|
SDL_RenderCommand *cmd = AllocateRenderCommand(renderer);
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (cmd) {
|
2018-09-23 23:20:40 -04:00
|
|
|
|
cmd->command = SDL_RENDERCMD_SETCLIPRECT;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
cmd->data.cliprect.enabled = renderer->view->clipping_enabled;
|
|
|
|
|
|
SDL_copyp(&cmd->data.cliprect.rect, &clip_rect);
|
|
|
|
|
|
SDL_copyp(&renderer->last_queued_cliprect, &clip_rect);
|
|
|
|
|
|
renderer->last_queued_cliprect_enabled = renderer->view->clipping_enabled;
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->cliprect_queued = true;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
} else {
|
|
|
|
|
|
retval = -1;
|
2018-09-23 23:20:40 -04:00
|
|
|
|
}
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
2018-09-25 17:04:47 -04:00
|
|
|
|
return retval;
|
2018-09-23 23:20:40 -04:00
|
|
|
|
}
|
2018-09-20 15:46:02 -04:00
|
|
|
|
|
2024-01-29 13:28:33 -08:00
|
|
|
|
static int QueueCmdSetDrawColor(SDL_Renderer *renderer, SDL_FColor *color)
|
2018-09-23 23:20:40 -04:00
|
|
|
|
{
|
|
|
|
|
|
int retval = 0;
|
2021-01-02 17:29:34 +01:00
|
|
|
|
|
2024-01-29 13:28:33 -08:00
|
|
|
|
if (!renderer->color_queued ||
|
|
|
|
|
|
color->r != renderer->last_queued_color.r ||
|
|
|
|
|
|
color->g != renderer->last_queued_color.g ||
|
|
|
|
|
|
color->b != renderer->last_queued_color.b ||
|
|
|
|
|
|
color->a != renderer->last_queued_color.a) {
|
2018-09-23 23:20:40 -04:00
|
|
|
|
SDL_RenderCommand *cmd = AllocateRenderCommand(renderer);
|
|
|
|
|
|
retval = -1;
|
|
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (cmd) {
|
2018-09-23 23:20:40 -04:00
|
|
|
|
cmd->command = SDL_RENDERCMD_SETDRAWCOLOR;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
cmd->data.color.first = 0; // render backend will fill this in.
|
2024-02-05 23:20:43 -08:00
|
|
|
|
cmd->data.color.color_scale = renderer->color_scale;
|
2024-01-29 13:28:33 -08:00
|
|
|
|
cmd->data.color.color = *color;
|
2018-09-23 23:20:40 -04:00
|
|
|
|
retval = renderer->QueueSetDrawColor(renderer, cmd);
|
|
|
|
|
|
if (retval < 0) {
|
|
|
|
|
|
cmd->command = SDL_RENDERCMD_NO_OP;
|
|
|
|
|
|
} else {
|
2024-01-29 13:28:33 -08:00
|
|
|
|
renderer->last_queued_color = *color;
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->color_queued = true;
|
2018-09-23 23:20:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-09-25 17:04:47 -04:00
|
|
|
|
return retval;
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int QueueCmdClear(SDL_Renderer *renderer)
|
2018-09-20 15:46:02 -04:00
|
|
|
|
{
|
|
|
|
|
|
SDL_RenderCommand *cmd = AllocateRenderCommand(renderer);
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!cmd) {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmd->command = SDL_RENDERCMD_CLEAR;
|
2018-09-23 23:20:40 -04:00
|
|
|
|
cmd->data.color.first = 0;
|
2024-02-05 23:20:43 -08:00
|
|
|
|
cmd->data.color.color_scale = renderer->color_scale;
|
2024-01-29 13:28:33 -08:00
|
|
|
|
cmd->data.color.color = renderer->color;
|
2018-09-25 17:04:47 -04:00
|
|
|
|
return 0;
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static SDL_RenderCommand *PrepQueueCmdDraw(SDL_Renderer *renderer, const SDL_RenderCommandType cmdtype, SDL_Texture *texture)
|
2018-09-23 23:20:40 -04:00
|
|
|
|
{
|
2021-10-24 17:16:49 +02:00
|
|
|
|
SDL_RenderCommand *cmd = NULL;
|
|
|
|
|
|
int retval = 0;
|
2024-01-29 13:28:33 -08:00
|
|
|
|
SDL_FColor *color;
|
2021-10-24 17:16:49 +02:00
|
|
|
|
SDL_BlendMode blendMode;
|
|
|
|
|
|
|
|
|
|
|
|
if (texture) {
|
|
|
|
|
|
color = &texture->color;
|
|
|
|
|
|
blendMode = texture->blendMode;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
color = &renderer->color;
|
|
|
|
|
|
blendMode = renderer->blendMode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (cmdtype != SDL_RENDERCMD_GEOMETRY) {
|
|
|
|
|
|
retval = QueueCmdSetDrawColor(renderer, color);
|
|
|
|
|
|
}
|
2019-08-18 09:35:11 -03:00
|
|
|
|
|
|
|
|
|
|
/* Set the viewport and clip rect directly before draws, so the backends
|
|
|
|
|
|
* don't have to worry about that state not being valid at draw time. */
|
2019-08-17 22:26:33 -03:00
|
|
|
|
if (retval == 0 && !renderer->viewport_queued) {
|
2018-09-23 23:20:40 -04:00
|
|
|
|
retval = QueueCmdSetViewport(renderer);
|
|
|
|
|
|
}
|
2019-08-17 22:26:33 -03:00
|
|
|
|
if (retval == 0 && !renderer->cliprect_queued) {
|
2018-09-23 23:20:40 -04:00
|
|
|
|
retval = QueueCmdSetClipRect(renderer);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-24 17:16:49 +02:00
|
|
|
|
if (retval == 0) {
|
2018-09-23 23:20:40 -04:00
|
|
|
|
cmd = AllocateRenderCommand(renderer);
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (cmd) {
|
2018-09-23 23:20:40 -04:00
|
|
|
|
cmd->command = cmdtype;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
cmd->data.draw.first = 0; // render backend will fill this in.
|
|
|
|
|
|
cmd->data.draw.count = 0; // render backend will fill this in.
|
2024-02-05 23:20:43 -08:00
|
|
|
|
cmd->data.draw.color_scale = renderer->color_scale;
|
2024-01-29 13:28:33 -08:00
|
|
|
|
cmd->data.draw.color = *color;
|
2021-10-24 17:16:49 +02:00
|
|
|
|
cmd->data.draw.blend = blendMode;
|
|
|
|
|
|
cmd->data.draw.texture = texture;
|
2024-07-17 22:49:05 -07:00
|
|
|
|
cmd->data.draw.texture_address_mode = SDL_TEXTURE_ADDRESS_CLAMP;
|
2018-09-23 23:20:40 -04:00
|
|
|
|
}
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
return cmd;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int QueueCmdDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, const int count)
|
2018-09-20 15:46:02 -04:00
|
|
|
|
{
|
2021-10-24 17:16:49 +02:00
|
|
|
|
SDL_RenderCommand *cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_DRAW_POINTS, NULL);
|
2018-09-20 15:46:02 -04:00
|
|
|
|
int retval = -1;
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (cmd) {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
retval = renderer->QueueDrawPoints(renderer, cmd, points, count);
|
|
|
|
|
|
if (retval < 0) {
|
|
|
|
|
|
cmd->command = SDL_RENDERCMD_NO_OP;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-09-25 17:04:47 -04:00
|
|
|
|
return retval;
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int QueueCmdDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, const int count)
|
2018-09-20 15:46:02 -04:00
|
|
|
|
{
|
2021-10-24 17:16:49 +02:00
|
|
|
|
SDL_RenderCommand *cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_DRAW_LINES, NULL);
|
2018-09-20 15:46:02 -04:00
|
|
|
|
int retval = -1;
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (cmd) {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
retval = renderer->QueueDrawLines(renderer, cmd, points, count);
|
|
|
|
|
|
if (retval < 0) {
|
|
|
|
|
|
cmd->command = SDL_RENDERCMD_NO_OP;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-09-25 17:04:47 -04:00
|
|
|
|
return retval;
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int QueueCmdFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, const int count)
|
2018-09-20 15:46:02 -04:00
|
|
|
|
{
|
2021-09-23 22:45:45 +02:00
|
|
|
|
SDL_RenderCommand *cmd;
|
2018-09-20 15:46:02 -04:00
|
|
|
|
int retval = -1;
|
2023-11-09 22:29:15 +01:00
|
|
|
|
const int use_rendergeometry = (!renderer->QueueFillRects);
|
2021-09-23 22:45:45 +02:00
|
|
|
|
|
2021-10-25 13:46:40 +02:00
|
|
|
|
cmd = PrepQueueCmdDraw(renderer, (use_rendergeometry ? SDL_RENDERCMD_GEOMETRY : SDL_RENDERCMD_FILL_RECTS), NULL);
|
2021-09-23 22:45:45 +02:00
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (cmd) {
|
2021-10-25 13:46:40 +02:00
|
|
|
|
if (use_rendergeometry) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool isstack1;
|
|
|
|
|
|
bool isstack2;
|
2021-09-23 22:45:45 +02:00
|
|
|
|
float *xy = SDL_small_alloc(float, 4 * 2 * count, &isstack1);
|
|
|
|
|
|
int *indices = SDL_small_alloc(int, 6 * count, &isstack2);
|
|
|
|
|
|
|
|
|
|
|
|
if (xy && indices) {
|
|
|
|
|
|
int i;
|
|
|
|
|
|
float *ptr_xy = xy;
|
|
|
|
|
|
int *ptr_indices = indices;
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const int xy_stride = 2 * sizeof(float);
|
2021-09-23 22:45:45 +02:00
|
|
|
|
const int num_vertices = 4 * count;
|
|
|
|
|
|
const int num_indices = 6 * count;
|
|
|
|
|
|
const int size_indices = 4;
|
2022-10-18 08:40:03 -07:00
|
|
|
|
int cur_index = 0;
|
|
|
|
|
|
const int *rect_index_order = renderer->rect_index_order;
|
2021-09-23 22:45:45 +02:00
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
|
|
float minx, miny, maxx, maxy;
|
|
|
|
|
|
|
|
|
|
|
|
minx = rects[i].x;
|
|
|
|
|
|
miny = rects[i].y;
|
|
|
|
|
|
maxx = rects[i].x + rects[i].w;
|
|
|
|
|
|
maxy = rects[i].y + rects[i].h;
|
|
|
|
|
|
|
|
|
|
|
|
*ptr_xy++ = minx;
|
|
|
|
|
|
*ptr_xy++ = miny;
|
|
|
|
|
|
*ptr_xy++ = maxx;
|
|
|
|
|
|
*ptr_xy++ = miny;
|
|
|
|
|
|
*ptr_xy++ = maxx;
|
|
|
|
|
|
*ptr_xy++ = maxy;
|
|
|
|
|
|
*ptr_xy++ = minx;
|
|
|
|
|
|
*ptr_xy++ = maxy;
|
|
|
|
|
|
|
2022-10-18 08:40:03 -07:00
|
|
|
|
*ptr_indices++ = cur_index + rect_index_order[0];
|
|
|
|
|
|
*ptr_indices++ = cur_index + rect_index_order[1];
|
|
|
|
|
|
*ptr_indices++ = cur_index + rect_index_order[2];
|
|
|
|
|
|
*ptr_indices++ = cur_index + rect_index_order[3];
|
|
|
|
|
|
*ptr_indices++ = cur_index + rect_index_order[4];
|
|
|
|
|
|
*ptr_indices++ = cur_index + rect_index_order[5];
|
|
|
|
|
|
cur_index += 4;
|
2021-09-23 22:45:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
retval = renderer->QueueGeometry(renderer, cmd, NULL,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
xy, xy_stride, &renderer->color, 0 /* color_stride */, NULL, 0,
|
|
|
|
|
|
num_vertices, indices, num_indices, size_indices,
|
|
|
|
|
|
1.0f, 1.0f);
|
2021-09-23 22:45:45 +02:00
|
|
|
|
|
|
|
|
|
|
if (retval < 0) {
|
|
|
|
|
|
cmd->command = SDL_RENDERCMD_NO_OP;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-03-28 15:39:13 +02:00
|
|
|
|
SDL_small_free(xy, isstack1);
|
|
|
|
|
|
SDL_small_free(indices, isstack2);
|
2022-11-30 12:51:59 -08:00
|
|
|
|
|
2021-09-23 22:45:45 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
retval = renderer->QueueFillRects(renderer, cmd, rects, count);
|
|
|
|
|
|
if (retval < 0) {
|
|
|
|
|
|
cmd->command = SDL_RENDERCMD_NO_OP;
|
|
|
|
|
|
}
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-09-25 17:04:47 -04:00
|
|
|
|
return retval;
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-02 08:56:54 -08:00
|
|
|
|
static int QueueCmdCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect)
|
2018-09-20 15:46:02 -04:00
|
|
|
|
{
|
2021-10-24 17:16:49 +02:00
|
|
|
|
SDL_RenderCommand *cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_COPY, texture);
|
2018-09-20 15:46:02 -04:00
|
|
|
|
int retval = -1;
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (cmd) {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
retval = renderer->QueueCopy(renderer, cmd, texture, srcrect, dstrect);
|
|
|
|
|
|
if (retval < 0) {
|
|
|
|
|
|
cmd->command = SDL_RENDERCMD_NO_OP;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-09-25 17:04:47 -04:00
|
|
|
|
return retval;
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int QueueCmdCopyEx(SDL_Renderer *renderer, SDL_Texture *texture,
|
2023-03-02 08:56:54 -08:00
|
|
|
|
const SDL_FRect *srcquad, const SDL_FRect *dstrect,
|
2024-01-20 06:31:37 -08:00
|
|
|
|
const double angle, const SDL_FPoint *center, const SDL_FlipMode flip, float scale_x, float scale_y)
|
2018-09-20 15:46:02 -04:00
|
|
|
|
{
|
2021-10-24 17:16:49 +02:00
|
|
|
|
SDL_RenderCommand *cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_COPY_EX, texture);
|
2018-09-20 15:46:02 -04:00
|
|
|
|
int retval = -1;
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (cmd) {
|
2022-02-15 11:33:56 +01:00
|
|
|
|
retval = renderer->QueueCopyEx(renderer, cmd, texture, srcquad, dstrect, angle, center, flip, scale_x, scale_y);
|
2018-09-20 15:46:02 -04:00
|
|
|
|
if (retval < 0) {
|
|
|
|
|
|
cmd->command = SDL_RENDERCMD_NO_OP;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-09-25 17:04:47 -04:00
|
|
|
|
return retval;
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int QueueCmdGeometry(SDL_Renderer *renderer, SDL_Texture *texture,
|
|
|
|
|
|
const float *xy, int xy_stride,
|
2024-01-29 13:28:33 -08:00
|
|
|
|
const SDL_FColor *color, int color_stride,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const float *uv, int uv_stride,
|
|
|
|
|
|
int num_vertices,
|
|
|
|
|
|
const void *indices, int num_indices, int size_indices,
|
2024-07-17 22:49:05 -07:00
|
|
|
|
float scale_x, float scale_y, SDL_TextureAddressMode texture_address_mode)
|
2021-03-16 15:09:34 +01:00
|
|
|
|
{
|
|
|
|
|
|
SDL_RenderCommand *cmd;
|
|
|
|
|
|
int retval = -1;
|
2021-10-24 17:16:49 +02:00
|
|
|
|
cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_GEOMETRY, texture);
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (cmd) {
|
2024-07-17 22:49:05 -07:00
|
|
|
|
cmd->data.draw.texture_address_mode = texture_address_mode;
|
|
|
|
|
|
|
2021-04-01 09:49:16 +02:00
|
|
|
|
retval = renderer->QueueGeometry(renderer, cmd, texture,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
xy, xy_stride,
|
|
|
|
|
|
color, color_stride, uv, uv_stride,
|
|
|
|
|
|
num_vertices, indices, num_indices, size_indices,
|
|
|
|
|
|
scale_x, scale_y);
|
2021-03-16 15:09:34 +01:00
|
|
|
|
if (retval < 0) {
|
|
|
|
|
|
cmd->command = SDL_RENDERCMD_NO_OP;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
2018-09-20 15:46:02 -04:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
static void UpdateMainViewDimensions(SDL_Renderer *renderer)
|
|
|
|
|
|
{
|
|
|
|
|
|
int window_w = 0, window_h = 0;
|
|
|
|
|
|
|
2023-05-16 16:29:52 -07:00
|
|
|
|
if (renderer->window) {
|
|
|
|
|
|
SDL_GetWindowSize(renderer->window, &window_w, &window_h);
|
|
|
|
|
|
}
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_GetRenderOutputSize(renderer, &renderer->main_view.pixel_w, &renderer->main_view.pixel_h);
|
|
|
|
|
|
if (window_w > 0 && window_h > 0) {
|
2024-06-12 19:08:06 -07:00
|
|
|
|
renderer->dpi_scale.x = (float)renderer->main_view.pixel_w / window_w;
|
|
|
|
|
|
renderer->dpi_scale.y = (float)renderer->main_view.pixel_h / window_h;
|
2023-05-16 16:29:52 -07:00
|
|
|
|
} else {
|
|
|
|
|
|
renderer->dpi_scale.x = 1.0f;
|
|
|
|
|
|
renderer->dpi_scale.y = 1.0f;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
}
|
2024-06-12 09:21:02 -07:00
|
|
|
|
UpdatePixelViewport(renderer, &renderer->main_view);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-19 08:45:02 -08:00
|
|
|
|
static void UpdateHDRProperties(SDL_Renderer *renderer)
|
|
|
|
|
|
{
|
2024-06-17 19:23:10 -04:00
|
|
|
|
SDL_PropertiesID window_props;
|
2024-02-19 08:45:02 -08:00
|
|
|
|
SDL_PropertiesID renderer_props;
|
|
|
|
|
|
|
2024-06-17 19:23:10 -04:00
|
|
|
|
window_props = SDL_GetWindowProperties(renderer->window);
|
|
|
|
|
|
if (!window_props) {
|
2024-02-19 08:45:02 -08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
renderer_props = SDL_GetRendererProperties(renderer);
|
|
|
|
|
|
if (!renderer_props) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
renderer->color_scale /= renderer->SDR_white_point;
|
|
|
|
|
|
|
|
|
|
|
|
if (renderer->output_colorspace == SDL_COLORSPACE_SRGB_LINEAR) {
|
2024-06-17 19:23:10 -04:00
|
|
|
|
renderer->SDR_white_point = SDL_GetFloatProperty(window_props, SDL_PROP_WINDOW_SDR_WHITE_LEVEL_FLOAT, 1.0f);
|
|
|
|
|
|
renderer->HDR_headroom = SDL_GetFloatProperty(window_props, SDL_PROP_WINDOW_HDR_HEADROOM_FLOAT, 1.0f);
|
2024-02-19 08:45:02 -08:00
|
|
|
|
} else {
|
|
|
|
|
|
renderer->SDR_white_point = 1.0f;
|
|
|
|
|
|
renderer->HDR_headroom = 1.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (renderer->HDR_headroom > 1.0f) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
SDL_SetBooleanProperty(renderer_props, SDL_PROP_RENDERER_HDR_ENABLED_BOOLEAN, true);
|
2024-02-19 08:45:02 -08:00
|
|
|
|
} else {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
SDL_SetBooleanProperty(renderer_props, SDL_PROP_RENDERER_HDR_ENABLED_BOOLEAN, false);
|
2024-02-19 08:45:02 -08:00
|
|
|
|
}
|
|
|
|
|
|
SDL_SetFloatProperty(renderer_props, SDL_PROP_RENDERER_SDR_WHITE_POINT_FLOAT, renderer->SDR_white_point);
|
|
|
|
|
|
SDL_SetFloatProperty(renderer_props, SDL_PROP_RENDERER_HDR_HEADROOM_FLOAT, renderer->HDR_headroom);
|
|
|
|
|
|
|
|
|
|
|
|
renderer->color_scale *= renderer->SDR_white_point;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
static int UpdateLogicalPresentation(SDL_Renderer *renderer);
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
int SDL_GetNumRenderDrivers(void)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2023-03-30 20:26:31 +02:00
|
|
|
|
#ifndef SDL_RENDER_DISABLED
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return SDL_arraysize(render_drivers);
|
|
|
|
|
|
#else
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-13 23:26:49 -05:00
|
|
|
|
const char *SDL_GetRenderDriver(int index)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2023-03-30 20:26:31 +02:00
|
|
|
|
#ifndef SDL_RENDER_DISABLED
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (index < 0 || index >= SDL_GetNumRenderDrivers()) {
|
2022-12-13 23:26:49 -05:00
|
|
|
|
SDL_SetError("index must be in the range of 0 - %d",
|
2015-06-21 17:33:46 +02:00
|
|
|
|
SDL_GetNumRenderDrivers() - 1);
|
2022-12-13 23:26:49 -05:00
|
|
|
|
return NULL;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2024-07-26 18:57:18 -07:00
|
|
|
|
return render_drivers[index]->name;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
#else
|
2022-12-13 23:26:49 -05:00
|
|
|
|
SDL_SetError("SDL not built with rendering support");
|
|
|
|
|
|
return NULL;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-06 07:36:42 -07:00
|
|
|
|
static SDL_bool SDLCALL SDL_RendererEventWatch(void *userdata, SDL_Event *event)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Renderer *renderer = (SDL_Renderer *)userdata;
|
|
|
|
|
|
|
2023-01-23 17:54:09 -08:00
|
|
|
|
if (event->type >= SDL_EVENT_WINDOW_FIRST && event->type <= SDL_EVENT_WINDOW_LAST) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
|
|
|
|
|
|
if (window == renderer->window) {
|
|
|
|
|
|
if (renderer->WindowEvent) {
|
|
|
|
|
|
renderer->WindowEvent(renderer, &event->window);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-28 15:22:16 -08:00
|
|
|
|
if (event->type == SDL_EVENT_WINDOW_RESIZED ||
|
2024-07-24 15:10:15 -07:00
|
|
|
|
event->type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED ||
|
|
|
|
|
|
event->type == SDL_EVENT_WINDOW_METAL_VIEW_RESIZED) {
|
2023-02-03 12:25:46 -08:00
|
|
|
|
UpdateMainViewDimensions(renderer);
|
|
|
|
|
|
UpdateLogicalPresentation(renderer);
|
2023-01-23 17:54:09 -08:00
|
|
|
|
} else if (event->type == SDL_EVENT_WINDOW_HIDDEN) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->hidden = true;
|
2023-01-23 17:54:09 -08:00
|
|
|
|
} else if (event->type == SDL_EVENT_WINDOW_SHOWN) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->hidden = false;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2023-01-23 17:54:09 -08:00
|
|
|
|
} else if (event->type == SDL_EVENT_WINDOW_MINIMIZED) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->hidden = true;
|
2023-01-23 17:54:09 -08:00
|
|
|
|
} else if (event->type == SDL_EVENT_WINDOW_RESTORED ||
|
|
|
|
|
|
event->type == SDL_EVENT_WINDOW_MAXIMIZED) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_HIDDEN)) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->hidden = false;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2024-02-19 08:45:02 -08:00
|
|
|
|
} else if (event->type == SDL_EVENT_WINDOW_DISPLAY_CHANGED) {
|
|
|
|
|
|
UpdateHDRProperties(renderer);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-06-17 19:23:10 -04:00
|
|
|
|
} else if (event->type == SDL_EVENT_WINDOW_HDR_STATE_CHANGED) {
|
2024-02-19 08:45:02 -08:00
|
|
|
|
UpdateHDRProperties(renderer);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2017-10-12 08:37:55 -07:00
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
|
return true;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-25 19:37:19 -07:00
|
|
|
|
int SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool hidden = (window_flags & SDL_WINDOW_HIDDEN) != 0;
|
2024-04-25 16:42:18 -07:00
|
|
|
|
|
|
|
|
|
|
if (!window) {
|
|
|
|
|
|
return SDL_InvalidParamError("window");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!renderer) {
|
|
|
|
|
|
return SDL_InvalidParamError("renderer");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Hide the window so if the renderer recreates it, we don't get a visual flash on screen
|
|
|
|
|
|
window_flags |= SDL_WINDOW_HIDDEN;
|
2024-04-25 19:37:19 -07:00
|
|
|
|
*window = SDL_CreateWindow(title, width, height, window_flags);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (!*window) {
|
|
|
|
|
|
*renderer = NULL;
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-13 10:31:55 -07:00
|
|
|
|
*renderer = SDL_CreateRenderer(*window, NULL);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (!*renderer) {
|
2024-04-25 16:42:18 -07:00
|
|
|
|
SDL_DestroyWindow(*window);
|
2024-04-25 16:46:44 -07:00
|
|
|
|
*window = NULL;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-25 16:42:18 -07:00
|
|
|
|
if (!hidden) {
|
|
|
|
|
|
SDL_ShowWindow(*window);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-30 20:26:31 +02:00
|
|
|
|
#ifndef SDL_RENDER_DISABLED
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static SDL_INLINE void VerifyDrawQueueFunctions(const SDL_Renderer *renderer)
|
2018-09-20 15:46:02 -04:00
|
|
|
|
{
|
|
|
|
|
|
/* all of these functions are required to be implemented, even as no-ops, so we don't
|
|
|
|
|
|
have to check that they aren't NULL over and over. */
|
2023-11-11 10:28:24 +01:00
|
|
|
|
SDL_assert(renderer->QueueSetViewport != NULL);
|
|
|
|
|
|
SDL_assert(renderer->QueueSetDrawColor != NULL);
|
|
|
|
|
|
SDL_assert(renderer->QueueDrawPoints != NULL);
|
|
|
|
|
|
SDL_assert(renderer->QueueDrawLines != NULL || renderer->QueueGeometry != NULL);
|
|
|
|
|
|
SDL_assert(renderer->QueueFillRects != NULL || renderer->QueueGeometry != NULL);
|
|
|
|
|
|
SDL_assert(renderer->QueueCopy != NULL || renderer->QueueGeometry != NULL);
|
|
|
|
|
|
SDL_assert(renderer->RunCommandQueue != NULL);
|
2018-09-20 15:46:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-05 20:29:33 +01:00
|
|
|
|
static SDL_RenderLineMethod SDL_GetRenderLineMethod(void)
|
2022-01-08 11:36:29 -08:00
|
|
|
|
{
|
|
|
|
|
|
const char *hint = SDL_GetHint(SDL_HINT_RENDER_LINE_METHOD);
|
|
|
|
|
|
|
|
|
|
|
|
int method = 0;
|
|
|
|
|
|
if (hint) {
|
|
|
|
|
|
method = SDL_atoi(hint);
|
|
|
|
|
|
}
|
|
|
|
|
|
switch (method) {
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
return SDL_RENDERLINEMETHOD_POINTS;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
return SDL_RENDERLINEMETHOD_LINES;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
return SDL_RENDERLINEMETHOD_GEOMETRY;
|
|
|
|
|
|
default:
|
|
|
|
|
|
return SDL_RENDERLINEMETHOD_POINTS;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-15 08:02:14 -07:00
|
|
|
|
static void SDL_CalculateSimulatedVSyncInterval(SDL_Renderer *renderer, SDL_Window *window)
|
|
|
|
|
|
{
|
2023-01-29 13:30:55 -08:00
|
|
|
|
SDL_DisplayID displayID = SDL_GetDisplayForWindow(window);
|
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
if (modes) {
for (i = 0; i < num_modes; ++i) {
SDL_DisplayMode *mode = modes[i];
SDL_Log("Display %" SDL_PRIu32 " mode %d: %dx%d@%gHz, %d%% scale\n",
display, i, mode->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f));
}
SDL_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-01-31 21:23:14 -08:00
|
|
|
|
const SDL_DisplayMode *mode;
|
2024-07-13 08:52:43 -07:00
|
|
|
|
int refresh_num, refresh_den;
|
2022-09-15 08:02:14 -07:00
|
|
|
|
|
2023-01-29 13:30:55 -08:00
|
|
|
|
if (displayID == 0) {
|
|
|
|
|
|
displayID = SDL_GetPrimaryDisplay();
|
2022-09-15 08:02:14 -07:00
|
|
|
|
}
|
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
if (modes) {
for (i = 0; i < num_modes; ++i) {
SDL_DisplayMode *mode = modes[i];
SDL_Log("Display %" SDL_PRIu32 " mode %d: %dx%d@%gHz, %d%% scale\n",
display, i, mode->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f));
}
SDL_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-01-31 21:23:14 -08:00
|
|
|
|
mode = SDL_GetDesktopDisplayMode(displayID);
|
2024-07-13 08:52:43 -07:00
|
|
|
|
if (mode && mode->refresh_rate_numerator > 0 && mode->refresh_rate_denominator > 0) {
|
|
|
|
|
|
refresh_num = mode->refresh_rate_numerator;
|
|
|
|
|
|
refresh_den = mode->refresh_rate_denominator;
|
2023-01-02 15:47:19 -08:00
|
|
|
|
} else {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Pick a good default refresh rate
|
2024-07-13 08:52:43 -07:00
|
|
|
|
refresh_num = 60;
|
|
|
|
|
|
refresh_den = 1;
|
2022-09-15 08:02:14 -07:00
|
|
|
|
}
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Flip numerator and denominator to change from framerate to interval
|
2024-07-13 08:52:43 -07:00
|
|
|
|
renderer->simulate_vsync_interval_ns = (SDL_NS_PER_SECOND * refresh_den) / refresh_num;
|
2022-09-15 08:02:14 -07:00
|
|
|
|
}
|
2023-02-03 12:25:46 -08:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
#endif // !SDL_RENDER_DISABLED
|
2022-09-15 08:02:14 -07:00
|
|
|
|
|
2023-11-13 12:13:20 -08:00
|
|
|
|
|
|
|
|
|
|
SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2023-03-30 20:26:31 +02:00
|
|
|
|
#ifndef SDL_RENDER_DISABLED
|
2024-07-12 09:39:58 -07:00
|
|
|
|
SDL_Window *window = (SDL_Window *)SDL_GetPointerProperty(props, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, NULL);
|
|
|
|
|
|
SDL_Surface *surface = (SDL_Surface *)SDL_GetPointerProperty(props, SDL_PROP_RENDERER_CREATE_SURFACE_POINTER, NULL);
|
2024-01-27 13:00:37 -08:00
|
|
|
|
const char *name = SDL_GetStringProperty(props, SDL_PROP_RENDERER_CREATE_NAME_STRING, NULL);
|
2022-12-13 23:26:49 -05:00
|
|
|
|
const int n = SDL_GetNumRenderDrivers();
|
2015-06-21 17:33:46 +02:00
|
|
|
|
const char *hint;
|
2024-01-31 17:25:25 -08:00
|
|
|
|
int i, attempted = 0;
|
2024-02-06 01:53:03 -08:00
|
|
|
|
SDL_PropertiesID new_props;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-07-24 12:43:44 -07:00
|
|
|
|
#ifdef SDL_PLATFORM_ANDROID
|
|
|
|
|
|
if (Android_WaitActiveAndLockActivity() < 0) {
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2024-04-18 10:16:50 -04:00
|
|
|
|
SDL_Renderer *renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer));
|
|
|
|
|
|
if (!renderer) {
|
2024-07-24 12:43:44 -07:00
|
|
|
|
goto error;
|
2024-04-18 10:16:50 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
|
SDL_SetObjectValid(renderer, SDL_OBJECT_TYPE_RENDERER, true);
|
2024-04-18 10:16:50 -04:00
|
|
|
|
|
2024-03-10 11:05:26 -07:00
|
|
|
|
if ((!window && !surface) || (window && surface)) {
|
2022-02-05 12:02:54 +01:00
|
|
|
|
SDL_InvalidParamError("window");
|
2019-06-28 16:14:50 +02:00
|
|
|
|
goto error;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-10 11:05:26 -07:00
|
|
|
|
if (window && SDL_WindowHasSurface(window)) {
|
2023-06-10 08:39:20 -07:00
|
|
|
|
SDL_SetError("Surface already associated with window");
|
|
|
|
|
|
goto error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-10 11:05:26 -07:00
|
|
|
|
if (window && SDL_GetRenderer(window)) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
SDL_SetError("Renderer already associated with window");
|
2019-06-28 16:14:50 +02:00
|
|
|
|
goto error;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-10 12:02:17 -07:00
|
|
|
|
hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
|
|
|
|
|
|
if (hint && *hint) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER, SDL_GetHintBoolean(SDL_HINT_RENDER_VSYNC, true));
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-10 11:05:26 -07:00
|
|
|
|
if (surface) {
|
2024-03-11 20:16:20 +01:00
|
|
|
|
#if SDL_VIDEO_RENDER_SW
|
2024-04-18 10:16:50 -04:00
|
|
|
|
const int rc = SW_CreateRendererForSurface(renderer, surface, props);
|
2024-03-11 20:16:20 +01:00
|
|
|
|
#else
|
2024-04-18 10:16:50 -04:00
|
|
|
|
const int rc = SDL_SetError("SDL not built with software renderer");
|
2024-03-11 20:16:20 +01:00
|
|
|
|
#endif
|
2024-08-22 06:53:25 -07:00
|
|
|
|
if (rc < 0) {
|
2024-03-10 11:05:26 -07:00
|
|
|
|
goto error;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2024-04-18 10:16:50 -04:00
|
|
|
|
int rc = -1;
|
2024-03-10 11:05:26 -07:00
|
|
|
|
if (!name) {
|
|
|
|
|
|
name = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-03-10 11:05:26 -07:00
|
|
|
|
if (name) {
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
|
|
const SDL_RenderDriver *driver = render_drivers[i];
|
2024-05-09 12:10:42 -07:00
|
|
|
|
if (SDL_strcasecmp(name, driver->name) == 0) {
|
2024-04-18 10:16:50 -04:00
|
|
|
|
// Create a new renderer instance
|
2024-03-10 11:05:26 -07:00
|
|
|
|
++attempted;
|
2024-04-18 10:16:50 -04:00
|
|
|
|
rc = driver->CreateRenderer(renderer, window, props);
|
2024-03-10 11:05:26 -07:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
|
|
const SDL_RenderDriver *driver = render_drivers[i];
|
2024-04-18 10:16:50 -04:00
|
|
|
|
// Create a new renderer instance
|
2024-01-31 17:25:25 -08:00
|
|
|
|
++attempted;
|
2024-04-18 10:16:50 -04:00
|
|
|
|
rc = driver->CreateRenderer(renderer, window, props);
|
|
|
|
|
|
if (rc == 0) {
|
|
|
|
|
|
break; // Yay, we got one!
|
2024-03-10 11:05:26 -07:00
|
|
|
|
}
|
2024-07-27 16:19:05 -07:00
|
|
|
|
SDL_DestroyRendererWithoutFreeing(renderer);
|
2024-04-18 10:16:50 -04:00
|
|
|
|
SDL_zerop(renderer); // make sure we don't leave function pointers from a previous CreateRenderer() in this struct.
|
2022-12-13 23:26:49 -05:00
|
|
|
|
}
|
2022-02-05 12:02:54 +01:00
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-08-22 06:53:25 -07:00
|
|
|
|
if (rc < 0) {
|
2024-03-10 11:05:26 -07:00
|
|
|
|
if (!name || !attempted) {
|
|
|
|
|
|
SDL_SetError("Couldn't find matching render driver");
|
|
|
|
|
|
}
|
|
|
|
|
|
goto error;
|
2024-01-31 17:25:25 -08:00
|
|
|
|
}
|
2022-12-13 23:26:49 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-28 16:14:50 +02:00
|
|
|
|
VerifyDrawQueueFunctions(renderer);
|
2018-09-20 15:46:02 -04:00
|
|
|
|
|
2019-06-28 16:14:50 +02:00
|
|
|
|
renderer->window = window;
|
|
|
|
|
|
renderer->target_mutex = SDL_CreateMutex();
|
2024-03-10 11:05:26 -07:00
|
|
|
|
if (surface) {
|
2024-06-12 19:08:06 -07:00
|
|
|
|
renderer->main_view.pixel_w = surface->w;
|
|
|
|
|
|
renderer->main_view.pixel_h = surface->h;
|
2024-03-10 11:05:26 -07:00
|
|
|
|
}
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->main_view.viewport.w = -1;
|
|
|
|
|
|
renderer->main_view.viewport.h = -1;
|
|
|
|
|
|
renderer->main_view.scale.x = 1.0f;
|
|
|
|
|
|
renderer->main_view.scale.y = 1.0f;
|
|
|
|
|
|
renderer->view = &renderer->main_view;
|
2019-06-28 16:14:50 +02:00
|
|
|
|
renderer->dpi_scale.x = 1.0f;
|
|
|
|
|
|
renderer->dpi_scale.y = 1.0f;
|
2024-06-12 09:21:02 -07:00
|
|
|
|
UpdatePixelViewport(renderer, &renderer->main_view);
|
|
|
|
|
|
UpdatePixelClipRect(renderer, &renderer->main_view);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
UpdateMainViewDimensions(renderer);
|
2019-06-28 16:14:50 +02:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Default value, if not specified by the renderer back-end
|
2022-10-18 08:40:03 -07:00
|
|
|
|
if (renderer->rect_index_order[0] == 0 && renderer->rect_index_order[1] == 0) {
|
|
|
|
|
|
renderer->rect_index_order[0] = 0;
|
|
|
|
|
|
renderer->rect_index_order[1] = 1;
|
|
|
|
|
|
renderer->rect_index_order[2] = 2;
|
|
|
|
|
|
renderer->rect_index_order[3] = 0;
|
|
|
|
|
|
renderer->rect_index_order[4] = 2;
|
|
|
|
|
|
renderer->rect_index_order[5] = 3;
|
2022-10-18 10:34:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// new textures start at zero, so we start at 1 so first render doesn't flush by accident.
|
2019-06-28 16:14:50 +02:00
|
|
|
|
renderer->render_command_generation = 1;
|
|
|
|
|
|
|
2024-04-04 12:39:24 -07:00
|
|
|
|
if (renderer->software) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Software renderer always uses line method, for speed
|
2024-03-10 11:05:26 -07:00
|
|
|
|
renderer->line_method = SDL_RENDERLINEMETHOD_LINES;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
renderer->line_method = SDL_GetRenderLineMethod();
|
|
|
|
|
|
}
|
2022-01-08 11:36:29 -08:00
|
|
|
|
|
2024-02-19 08:45:02 -08:00
|
|
|
|
renderer->SDR_white_point = 1.0f;
|
|
|
|
|
|
renderer->HDR_headroom = 1.0f;
|
2024-02-05 23:20:43 -08:00
|
|
|
|
renderer->color_scale = 1.0f;
|
|
|
|
|
|
|
2024-02-09 07:09:59 -08:00
|
|
|
|
if (window) {
|
|
|
|
|
|
if (SDL_GetWindowFlags(window) & SDL_WINDOW_TRANSPARENT) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->transparent_window = true;
|
2024-02-09 07:09:59 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SDL_GetWindowFlags(window) & (SDL_WINDOW_HIDDEN | SDL_WINDOW_MINIMIZED)) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->hidden = true;
|
2024-02-09 07:09:59 -08:00
|
|
|
|
}
|
2019-06-28 16:14:50 +02:00
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-02-06 01:53:03 -08:00
|
|
|
|
new_props = SDL_GetRendererProperties(renderer);
|
2024-06-03 19:26:43 -07:00
|
|
|
|
SDL_SetStringProperty(new_props, SDL_PROP_RENDERER_NAME_STRING, renderer->name);
|
2024-02-06 01:53:03 -08:00
|
|
|
|
if (window) {
|
2024-07-12 09:39:58 -07:00
|
|
|
|
SDL_SetPointerProperty(new_props, SDL_PROP_RENDERER_WINDOW_POINTER, window);
|
2024-02-06 01:53:03 -08:00
|
|
|
|
}
|
|
|
|
|
|
if (surface) {
|
2024-07-12 09:39:58 -07:00
|
|
|
|
SDL_SetPointerProperty(new_props, SDL_PROP_RENDERER_SURFACE_POINTER, surface);
|
2024-02-06 01:53:03 -08:00
|
|
|
|
}
|
|
|
|
|
|
SDL_SetNumberProperty(new_props, SDL_PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER, renderer->output_colorspace);
|
2024-02-19 08:45:02 -08:00
|
|
|
|
UpdateHDRProperties(renderer);
|
2024-02-06 01:53:03 -08:00
|
|
|
|
|
2024-03-10 11:05:26 -07:00
|
|
|
|
if (window) {
|
2024-07-12 09:39:58 -07:00
|
|
|
|
SDL_SetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_RENDERER_POINTER, renderer);
|
2024-03-10 11:05:26 -07:00
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2022-12-27 06:21:13 -08:00
|
|
|
|
SDL_SetRenderViewport(renderer, NULL);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
|
2024-03-10 11:05:26 -07:00
|
|
|
|
if (window) {
|
|
|
|
|
|
SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
|
|
|
|
|
|
}
|
2019-06-28 16:14:50 +02:00
|
|
|
|
|
2024-05-13 10:31:55 -07:00
|
|
|
|
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);
|
|
|
|
|
|
|
2019-06-28 16:14:50 +02:00
|
|
|
|
SDL_LogInfo(SDL_LOG_CATEGORY_RENDER,
|
2024-06-03 19:26:43 -07:00
|
|
|
|
"Created renderer: %s", renderer->name);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-06-23 00:41:19 -07:00
|
|
|
|
renderer->next = SDL_renderers;
|
|
|
|
|
|
SDL_renderers = renderer;
|
|
|
|
|
|
|
2024-01-24 02:40:51 +01:00
|
|
|
|
#ifdef SDL_PLATFORM_ANDROID
|
2024-07-23 20:55:24 -07:00
|
|
|
|
Android_UnlockActivityMutex();
|
2019-06-28 16:38:42 +02:00
|
|
|
|
#endif
|
2024-05-13 10:31:55 -07:00
|
|
|
|
|
|
|
|
|
|
SDL_ClearError();
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return renderer;
|
2019-06-28 16:14:50 +02:00
|
|
|
|
|
|
|
|
|
|
error:
|
2024-01-24 02:40:51 +01:00
|
|
|
|
#ifdef SDL_PLATFORM_ANDROID
|
2024-07-23 20:55:24 -07:00
|
|
|
|
Android_UnlockActivityMutex();
|
2019-06-28 16:38:42 +02:00
|
|
|
|
#endif
|
2024-07-24 12:43:44 -07:00
|
|
|
|
|
|
|
|
|
|
if (renderer) {
|
2024-07-27 13:36:12 -07:00
|
|
|
|
SDL_DestroyRenderer(renderer);
|
2024-07-24 12:43:44 -07:00
|
|
|
|
}
|
2019-06-28 16:14:50 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
#else
|
|
|
|
|
|
SDL_SetError("SDL not built with rendering support");
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-13 10:31:55 -07:00
|
|
|
|
SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, const char *name)
|
2023-11-13 12:13:20 -08:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
|
|
SDL_PropertiesID props = SDL_CreateProperties();
|
2024-07-12 09:39:58 -07:00
|
|
|
|
SDL_SetPointerProperty(props, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, window);
|
2024-04-04 12:39:24 -07:00
|
|
|
|
SDL_SetStringProperty(props, SDL_PROP_RENDERER_CREATE_NAME_STRING, name);
|
2023-11-13 12:13:20 -08:00
|
|
|
|
renderer = SDL_CreateRendererWithProperties(props);
|
|
|
|
|
|
SDL_DestroyProperties(props);
|
|
|
|
|
|
return renderer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_Renderer *SDL_CreateSoftwareRenderer(SDL_Surface *surface)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-02-15 20:55:02 +03:00
|
|
|
|
#if SDL_VIDEO_RENDER_SW
|
2015-06-21 17:33:46 +02:00
|
|
|
|
SDL_Renderer *renderer;
|
2024-07-05 08:05:20 -07:00
|
|
|
|
|
2024-07-13 08:52:43 -07:00
|
|
|
|
if (!surface) {
|
2024-07-05 08:05:20 -07:00
|
|
|
|
SDL_InvalidParamError("surface");
|
2024-07-13 08:52:43 -07:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
2024-07-05 08:05:20 -07:00
|
|
|
|
|
2024-03-10 11:05:26 -07:00
|
|
|
|
SDL_PropertiesID props = SDL_CreateProperties();
|
2024-07-12 09:39:58 -07:00
|
|
|
|
SDL_SetPointerProperty(props, SDL_PROP_RENDERER_CREATE_SURFACE_POINTER, surface);
|
2024-03-10 11:05:26 -07:00
|
|
|
|
renderer = SDL_CreateRendererWithProperties(props);
|
|
|
|
|
|
SDL_DestroyProperties(props);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return renderer;
|
|
|
|
|
|
#else
|
|
|
|
|
|
SDL_SetError("SDL not built with rendering support");
|
|
|
|
|
|
return NULL;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
#endif // !SDL_RENDER_DISABLED
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_Renderer *SDL_GetRenderer(SDL_Window *window)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-07-12 09:39:58 -07:00
|
|
|
|
return (SDL_Renderer *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_RENDERER_POINTER, NULL);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_Window *SDL_GetRenderWindow(SDL_Renderer *renderer)
|
2022-03-23 17:07:56 +01:00
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, NULL);
|
|
|
|
|
|
return renderer->window;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-03 19:26:43 -07:00
|
|
|
|
const char *SDL_GetRendererName(SDL_Renderer *renderer)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-06-03 19:26:43 -07:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, NULL);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-07-26 18:57:18 -07:00
|
|
|
|
return SDL_GetPersistentString(renderer->name);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-11 16:59:51 -07:00
|
|
|
|
SDL_PropertiesID SDL_GetRendererProperties(SDL_Renderer *renderer)
|
|
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (renderer->props == 0) {
|
|
|
|
|
|
renderer->props = SDL_CreateProperties();
|
|
|
|
|
|
}
|
|
|
|
|
|
return renderer->props;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 19:08:06 -07:00
|
|
|
|
int SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h)
|
2023-02-03 12:25:46 -08:00
|
|
|
|
{
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (w) {
|
|
|
|
|
|
*w = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (h) {
|
|
|
|
|
|
*h = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (renderer->GetOutputSize) {
|
2024-06-12 19:08:06 -07:00
|
|
|
|
return renderer->GetOutputSize(renderer, w, h);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
} else if (renderer->window) {
|
2024-06-12 19:08:06 -07:00
|
|
|
|
return SDL_GetWindowSizeInPixels(renderer->window, w, h);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
} else {
|
2024-01-19 06:35:02 -08:00
|
|
|
|
SDL_assert(!"This should never happen");
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return SDL_SetError("Renderer doesn't support querying output size");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 19:08:06 -07:00
|
|
|
|
int SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h)
|
2023-02-03 12:25:46 -08:00
|
|
|
|
{
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (w) {
|
|
|
|
|
|
*w = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (h) {
|
|
|
|
|
|
*h = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (w) {
|
|
|
|
|
|
*w = renderer->view->pixel_w;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (h) {
|
|
|
|
|
|
*h = renderer->view->pixel_h;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
|
static bool IsSupportedBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode)
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
{
|
2022-11-30 12:51:59 -08:00
|
|
|
|
switch (blendMode) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// These are required to be supported by all renderers
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
case SDL_BLENDMODE_NONE:
|
|
|
|
|
|
case SDL_BLENDMODE_BLEND:
|
2024-07-15 08:27:58 -07:00
|
|
|
|
case SDL_BLENDMODE_BLEND_PREMULTIPLIED:
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
case SDL_BLENDMODE_ADD:
|
2024-07-15 08:27:58 -07:00
|
|
|
|
case SDL_BLENDMODE_ADD_PREMULTIPLIED:
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
case SDL_BLENDMODE_MOD:
|
2020-01-16 08:52:59 -08:00
|
|
|
|
case SDL_BLENDMODE_MUL:
|
2024-08-22 09:21:26 -07:00
|
|
|
|
return true;
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
return renderer->SupportsBlendMode && renderer->SupportsBlendMode(renderer, blendMode);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
|
static bool IsSupportedFormat(SDL_Renderer *renderer, SDL_PixelFormat format)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-03-05 21:11:32 +01:00
|
|
|
|
int i;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-06-03 19:26:43 -07:00
|
|
|
|
for (i = 0; i < renderer->num_texture_formats; ++i) {
|
|
|
|
|
|
if (renderer->texture_formats[i] == format) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
return true;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-08-22 09:21:26 -07:00
|
|
|
|
return false;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-08 14:59:18 -07:00
|
|
|
|
static Uint32 GetClosestSupportedFormat(SDL_Renderer *renderer, SDL_PixelFormat format)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-03-05 21:11:32 +01:00
|
|
|
|
int i;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
if (SDL_ISPIXELFORMAT_FOURCC(format)) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Look for an exact match
|
2024-06-03 19:26:43 -07:00
|
|
|
|
for (i = 0; i < renderer->num_texture_formats; ++i) {
|
|
|
|
|
|
if (renderer->texture_formats[i] == format) {
|
|
|
|
|
|
return renderer->texture_formats[i];
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-02-01 14:20:40 -08:00
|
|
|
|
} else if (SDL_ISPIXELFORMAT_10BIT(format) || SDL_ISPIXELFORMAT_FLOAT(format)) {
|
2024-02-19 08:45:02 -08:00
|
|
|
|
if (SDL_ISPIXELFORMAT_10BIT(format)) {
|
2024-06-03 19:26:43 -07:00
|
|
|
|
for (i = 0; i < renderer->num_texture_formats; ++i) {
|
|
|
|
|
|
if (SDL_ISPIXELFORMAT_10BIT(renderer->texture_formats[i])) {
|
|
|
|
|
|
return renderer->texture_formats[i];
|
2024-02-19 08:45:02 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-06-03 19:26:43 -07:00
|
|
|
|
for (i = 0; i < renderer->num_texture_formats; ++i) {
|
|
|
|
|
|
if (SDL_ISPIXELFORMAT_FLOAT(renderer->texture_formats[i])) {
|
|
|
|
|
|
return renderer->texture_formats[i];
|
2024-02-01 14:20:40 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
} else {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool hasAlpha = SDL_ISPIXELFORMAT_ALPHA(format);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// We just want to match the first format that has the same channels
|
2024-06-03 19:26:43 -07:00
|
|
|
|
for (i = 0; i < renderer->num_texture_formats; ++i) {
|
|
|
|
|
|
if (!SDL_ISPIXELFORMAT_FOURCC(renderer->texture_formats[i]) &&
|
|
|
|
|
|
SDL_ISPIXELFORMAT_ALPHA(renderer->texture_formats[i]) == hasAlpha) {
|
|
|
|
|
|
return renderer->texture_formats[i];
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-06-03 19:26:43 -07:00
|
|
|
|
return renderer->texture_formats[0];
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-13 12:13:20 -08:00
|
|
|
|
SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_PropertiesID props)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Texture *texture;
|
2024-07-08 14:59:18 -07:00
|
|
|
|
SDL_PixelFormat format = (SDL_PixelFormat)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER, SDL_PIXELFORMAT_UNKNOWN);
|
2024-07-21 17:26:46 -07:00
|
|
|
|
SDL_TextureAccess access = (SDL_TextureAccess)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER, SDL_TEXTUREACCESS_STATIC);
|
2024-01-27 13:00:37 -08:00
|
|
|
|
int w = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER, 0);
|
|
|
|
|
|
int h = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER, 0);
|
2024-01-31 17:25:25 -08:00
|
|
|
|
SDL_Colorspace default_colorspace;
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool texture_is_fourcc_and_target;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
if (!format) {
|
2024-06-03 19:26:43 -07:00
|
|
|
|
format = renderer->texture_formats[0];
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
if (SDL_BYTESPERPIXEL(format) == 0) {
|
|
|
|
|
|
SDL_SetError("Invalid texture format");
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (SDL_ISPIXELFORMAT_INDEXED(format)) {
|
2021-10-01 22:30:51 +02:00
|
|
|
|
if (!IsSupportedFormat(renderer, format)) {
|
|
|
|
|
|
SDL_SetError("Palettized textures are not supported");
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
if (w <= 0 || h <= 0) {
|
|
|
|
|
|
SDL_SetError("Texture dimensions can't be 0");
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
2024-05-13 10:31:55 -07:00
|
|
|
|
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);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
2024-01-29 18:32:27 -08:00
|
|
|
|
|
2024-01-31 17:25:25 -08:00
|
|
|
|
default_colorspace = SDL_GetDefaultColorspaceForFormat(format);
|
2024-01-29 18:32:27 -08:00
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
texture = (SDL_Texture *)SDL_calloc(1, sizeof(*texture));
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!texture) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
2024-08-22 09:21:26 -07:00
|
|
|
|
SDL_SetObjectValid(texture, SDL_OBJECT_TYPE_TEXTURE, true);
|
2024-01-31 17:25:25 -08:00
|
|
|
|
texture->colorspace = (SDL_Colorspace)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER, default_colorspace);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
texture->format = format;
|
|
|
|
|
|
texture->access = access;
|
|
|
|
|
|
texture->w = w;
|
|
|
|
|
|
texture->h = h;
|
2024-01-29 13:28:33 -08:00
|
|
|
|
texture->color.r = 1.0f;
|
|
|
|
|
|
texture->color.g = 1.0f;
|
|
|
|
|
|
texture->color.b = 1.0f;
|
|
|
|
|
|
texture->color.a = 1.0f;
|
2024-07-16 18:00:20 -07:00
|
|
|
|
texture->blendMode = SDL_ISPIXELFORMAT_ALPHA(format) ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE;
|
2024-02-11 19:07:07 -08:00
|
|
|
|
texture->scaleMode = SDL_SCALEMODE_LINEAR;
|
2024-06-12 19:08:06 -07:00
|
|
|
|
texture->view.pixel_w = w;
|
|
|
|
|
|
texture->view.pixel_h = h;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
texture->view.viewport.w = -1;
|
|
|
|
|
|
texture->view.viewport.h = -1;
|
|
|
|
|
|
texture->view.scale.x = 1.0f;
|
|
|
|
|
|
texture->view.scale.y = 1.0f;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
texture->renderer = renderer;
|
|
|
|
|
|
texture->next = renderer->textures;
|
|
|
|
|
|
if (renderer->textures) {
|
|
|
|
|
|
renderer->textures->prev = texture;
|
|
|
|
|
|
}
|
|
|
|
|
|
renderer->textures = texture;
|
|
|
|
|
|
|
2024-06-12 09:21:02 -07:00
|
|
|
|
UpdatePixelViewport(renderer, &texture->view);
|
|
|
|
|
|
UpdatePixelClipRect(renderer, &texture->view);
|
|
|
|
|
|
|
2024-02-22 14:47:58 -08:00
|
|
|
|
texture->SDR_white_point = SDL_GetFloatProperty(props, SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT, SDL_GetDefaultSDRWhitePoint(texture->colorspace));
|
|
|
|
|
|
texture->HDR_headroom = SDL_GetFloatProperty(props, SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT, SDL_GetDefaultHDRHeadroom(texture->colorspace));
|
2024-02-19 08:45:02 -08:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// FOURCC format cannot be used directly by renderer back-ends for target texture
|
2024-01-29 18:32:27 -08:00
|
|
|
|
texture_is_fourcc_and_target = (access == SDL_TEXTUREACCESS_TARGET && SDL_ISPIXELFORMAT_FOURCC(format));
|
2021-04-13 14:42:38 +02:00
|
|
|
|
|
2024-01-29 18:32:27 -08:00
|
|
|
|
if (!texture_is_fourcc_and_target && IsSupportedFormat(renderer, format)) {
|
2023-11-13 12:13:20 -08:00
|
|
|
|
if (renderer->CreateTexture(renderer, texture, props) < 0) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
SDL_DestroyTexture(texture);
|
2015-08-21 23:50:37 +02:00
|
|
|
|
return NULL;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2021-04-13 14:42:38 +02:00
|
|
|
|
int closest_format;
|
2024-02-01 14:20:40 -08:00
|
|
|
|
SDL_PropertiesID native_props = SDL_CreateProperties();
|
2021-04-13 14:42:38 +02:00
|
|
|
|
|
2024-01-29 18:32:27 -08:00
|
|
|
|
if (!texture_is_fourcc_and_target) {
|
2021-04-13 14:42:38 +02:00
|
|
|
|
closest_format = GetClosestSupportedFormat(renderer, format);
|
|
|
|
|
|
} else {
|
2024-06-03 19:26:43 -07:00
|
|
|
|
closest_format = renderer->texture_formats[0];
|
2021-04-13 14:42:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-11 19:58:20 -07:00
|
|
|
|
default_colorspace = SDL_GetDefaultColorspaceForFormat(closest_format);
|
|
|
|
|
|
if (SDL_COLORSPACETYPE(texture->colorspace) == SDL_COLORSPACETYPE(default_colorspace)) {
|
|
|
|
|
|
SDL_SetNumberProperty(native_props, SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER, texture->colorspace);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
SDL_SetNumberProperty(native_props, SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER, default_colorspace);
|
|
|
|
|
|
}
|
2024-02-01 14:20:40 -08:00
|
|
|
|
SDL_SetNumberProperty(native_props, SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER, closest_format);
|
|
|
|
|
|
SDL_SetNumberProperty(native_props, SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER, texture->access);
|
|
|
|
|
|
SDL_SetNumberProperty(native_props, SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER, texture->w);
|
|
|
|
|
|
SDL_SetNumberProperty(native_props, SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER, texture->h);
|
|
|
|
|
|
|
|
|
|
|
|
texture->native = SDL_CreateTextureWithProperties(renderer, native_props);
|
|
|
|
|
|
SDL_DestroyProperties(native_props);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (!texture->native) {
|
|
|
|
|
|
SDL_DestroyTexture(texture);
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-12 09:39:58 -07:00
|
|
|
|
SDL_SetPointerProperty(SDL_GetTextureProperties(texture->native), SDL_PROP_TEXTURE_PARENT_POINTER, texture);
|
2024-03-03 09:46:54 -08:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Swap textures to have texture before texture->native in the list
|
2015-06-21 17:33:46 +02:00
|
|
|
|
texture->native->next = texture->next;
|
|
|
|
|
|
if (texture->native->next) {
|
|
|
|
|
|
texture->native->next->prev = texture->native;
|
|
|
|
|
|
}
|
|
|
|
|
|
texture->prev = texture->native->prev;
|
|
|
|
|
|
if (texture->prev) {
|
|
|
|
|
|
texture->prev->next = texture;
|
|
|
|
|
|
}
|
|
|
|
|
|
texture->native->prev = texture;
|
|
|
|
|
|
texture->next = texture->native;
|
|
|
|
|
|
renderer->textures = texture;
|
|
|
|
|
|
|
|
|
|
|
|
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
|
2020-01-21 21:33:40 +01:00
|
|
|
|
#if SDL_HAVE_YUV
|
2015-06-21 17:33:46 +02:00
|
|
|
|
texture->yuv = SDL_SW_CreateYUVTexture(format, w, h);
|
2020-01-21 21:33:40 +01:00
|
|
|
|
#else
|
|
|
|
|
|
SDL_SetError("SDL not built with YUV support");
|
|
|
|
|
|
#endif
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (!texture->yuv) {
|
|
|
|
|
|
SDL_DestroyTexture(texture);
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (access == SDL_TEXTUREACCESS_STREAMING) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// The pitch is 4 byte aligned
|
2015-06-21 17:33:46 +02:00
|
|
|
|
texture->pitch = (((w * SDL_BYTESPERPIXEL(format)) + 3) & ~3);
|
2022-12-01 16:07:03 -05:00
|
|
|
|
texture->pixels = SDL_calloc(1, (size_t)texture->pitch * h);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (!texture->pixels) {
|
|
|
|
|
|
SDL_DestroyTexture(texture);
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-02-19 08:45:02 -08:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Now set the properties for the new texture
|
2024-02-19 08:45:02 -08:00
|
|
|
|
props = SDL_GetTextureProperties(texture);
|
|
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_COLORSPACE_NUMBER, texture->colorspace);
|
2024-06-12 09:21:02 -07:00
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, texture->format);
|
|
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_ACCESS_NUMBER, texture->access);
|
|
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, texture->w);
|
|
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, texture->h);
|
2024-02-19 08:45:02 -08:00
|
|
|
|
SDL_SetFloatProperty(props, SDL_PROP_TEXTURE_SDR_WHITE_POINT_FLOAT, texture->SDR_white_point);
|
|
|
|
|
|
if (texture->HDR_headroom > 0.0f) {
|
|
|
|
|
|
SDL_SetFloatProperty(props, SDL_PROP_TEXTURE_HDR_HEADROOM_FLOAT, texture->HDR_headroom);
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return texture;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-21 17:26:46 -07:00
|
|
|
|
SDL_Texture *SDL_CreateTexture(SDL_Renderer *renderer, SDL_PixelFormat format, SDL_TextureAccess access, int w, int h)
|
2023-11-13 12:13:20 -08:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Texture *texture;
|
|
|
|
|
|
SDL_PropertiesID props = SDL_CreateProperties();
|
2024-01-27 13:00:37 -08:00
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER, format);
|
|
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER, access);
|
|
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER, w);
|
|
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER, h);
|
2023-11-13 12:13:20 -08:00
|
|
|
|
texture = SDL_CreateTextureWithProperties(renderer, props);
|
|
|
|
|
|
SDL_DestroyProperties(props);
|
|
|
|
|
|
return texture;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-07 10:22:57 +02:00
|
|
|
|
static int SDL_UpdateTextureFromSurface(SDL_Texture *texture, SDL_Rect *rect, SDL_Surface *surface)
|
|
|
|
|
|
{
|
2024-08-13 10:52:50 -07:00
|
|
|
|
SDL_TextureAccess access;
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool direct_update;
|
2024-08-07 10:22:57 +02:00
|
|
|
|
SDL_PixelFormat tex_format;
|
|
|
|
|
|
SDL_PropertiesID surface_props;
|
|
|
|
|
|
SDL_PropertiesID tex_props;
|
|
|
|
|
|
SDL_Colorspace surface_colorspace = SDL_COLORSPACE_UNKNOWN;
|
|
|
|
|
|
SDL_Colorspace texture_colorspace = SDL_COLORSPACE_UNKNOWN;
|
|
|
|
|
|
|
|
|
|
|
|
if (texture == NULL || surface == NULL) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tex_props = SDL_GetTextureProperties(texture);
|
|
|
|
|
|
if (!tex_props) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
surface_props = SDL_GetSurfaceProperties(surface);
|
|
|
|
|
|
if (!surface_props) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-13 10:52:50 -07:00
|
|
|
|
tex_format = (SDL_PixelFormat)SDL_GetNumberProperty(tex_props, SDL_PROP_TEXTURE_FORMAT_NUMBER, 0);
|
|
|
|
|
|
access = (SDL_TextureAccess)SDL_GetNumberProperty(tex_props, SDL_PROP_TEXTURE_ACCESS_NUMBER, 0);
|
2024-08-07 10:22:57 +02:00
|
|
|
|
|
|
|
|
|
|
if (access != SDL_TEXTUREACCESS_STATIC && access != SDL_TEXTUREACCESS_STREAMING) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
surface_colorspace = SDL_GetSurfaceColorspace(surface);
|
|
|
|
|
|
texture_colorspace = surface_colorspace;
|
|
|
|
|
|
|
|
|
|
|
|
if (surface_colorspace == SDL_COLORSPACE_SRGB_LINEAR ||
|
|
|
|
|
|
SDL_COLORSPACETRANSFER(surface_colorspace) == SDL_TRANSFER_CHARACTERISTICS_PQ) {
|
|
|
|
|
|
if (SDL_ISPIXELFORMAT_FLOAT(tex_format)) {
|
|
|
|
|
|
texture_colorspace = SDL_COLORSPACE_SRGB_LINEAR;
|
|
|
|
|
|
} else if (SDL_ISPIXELFORMAT_10BIT(tex_format)) {
|
|
|
|
|
|
texture_colorspace = SDL_COLORSPACE_HDR10;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
texture_colorspace = SDL_COLORSPACE_SRGB;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tex_format == surface->format && texture_colorspace == surface_colorspace) {
|
|
|
|
|
|
if (SDL_ISPIXELFORMAT_ALPHA(surface->format) && SDL_SurfaceHasColorKey(surface)) {
|
|
|
|
|
|
/* Surface and Renderer formats are identical.
|
|
|
|
|
|
* Intermediate conversion is needed to convert color key to alpha (SDL_ConvertColorkeyToAlpha()). */
|
2024-08-22 09:21:26 -07:00
|
|
|
|
direct_update = false;
|
2024-08-07 10:22:57 +02:00
|
|
|
|
} else {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Update Texture directly
|
2024-08-22 09:21:26 -07:00
|
|
|
|
direct_update = true;
|
2024-08-07 10:22:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Surface and Renderer formats are different, it needs an intermediate conversion.
|
2024-08-22 09:21:26 -07:00
|
|
|
|
direct_update = false;
|
2024-08-07 10:22:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (direct_update) {
|
|
|
|
|
|
if (SDL_MUSTLOCK(surface)) {
|
|
|
|
|
|
SDL_LockSurface(surface);
|
|
|
|
|
|
SDL_UpdateTexture(texture, rect, surface->pixels, surface->pitch);
|
|
|
|
|
|
SDL_UnlockSurface(surface);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
SDL_UpdateTexture(texture, rect, surface->pixels, surface->pitch);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
SDL_Surface *temp = NULL;
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Set up a destination surface for the texture update
|
2024-08-07 10:22:57 +02:00
|
|
|
|
temp = SDL_ConvertSurfaceAndColorspace(surface, tex_format, NULL, texture_colorspace, surface_props);
|
|
|
|
|
|
if (temp) {
|
|
|
|
|
|
SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch);
|
|
|
|
|
|
SDL_DestroySurface(temp);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
Uint8 r, g, b, a;
|
|
|
|
|
|
SDL_BlendMode blendMode;
|
|
|
|
|
|
|
|
|
|
|
|
SDL_GetSurfaceColorMod(surface, &r, &g, &b);
|
|
|
|
|
|
SDL_SetTextureColorMod(texture, r, g, b);
|
|
|
|
|
|
|
|
|
|
|
|
SDL_GetSurfaceAlphaMod(surface, &a);
|
|
|
|
|
|
SDL_SetTextureAlphaMod(texture, a);
|
|
|
|
|
|
|
|
|
|
|
|
if (SDL_SurfaceHasColorKey(surface)) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// We converted to a texture with alpha format
|
2024-08-07 10:22:57 +02:00
|
|
|
|
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
SDL_GetSurfaceBlendMode(surface, &blendMode);
|
|
|
|
|
|
SDL_SetTextureBlendMode(texture, blendMode);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *surface)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool needAlpha;
|
2019-03-19 16:52:09 -07:00
|
|
|
|
int i;
|
2024-07-08 14:59:18 -07:00
|
|
|
|
SDL_PixelFormat format = SDL_PIXELFORMAT_UNKNOWN;
|
|
|
|
|
|
SDL_Palette *palette;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
SDL_Texture *texture;
|
2024-07-08 14:59:18 -07:00
|
|
|
|
SDL_PropertiesID props;
|
2024-02-19 08:45:02 -08:00
|
|
|
|
SDL_Colorspace surface_colorspace = SDL_COLORSPACE_UNKNOWN;
|
|
|
|
|
|
SDL_Colorspace texture_colorspace = SDL_COLORSPACE_UNKNOWN;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, NULL);
|
|
|
|
|
|
|
2024-07-08 14:59:18 -07:00
|
|
|
|
if (!SDL_SurfaceValid(surface)) {
|
2022-01-17 16:26:02 +01:00
|
|
|
|
SDL_InvalidParamError("SDL_CreateTextureFromSurface(): surface");
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// See what the best texture format is
|
2024-07-08 14:59:18 -07:00
|
|
|
|
if (SDL_ISPIXELFORMAT_ALPHA(surface->format) || SDL_SurfaceHasColorKey(surface)) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
needAlpha = true;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
} else {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
needAlpha = false;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2018-12-15 14:50:12 +01:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// If Palette contains alpha values, promotes to alpha format
|
2024-07-08 14:59:18 -07:00
|
|
|
|
palette = SDL_GetSurfacePalette(surface);
|
|
|
|
|
|
if (palette) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool is_opaque, has_alpha_channel;
|
2024-07-08 14:59:18 -07:00
|
|
|
|
SDL_DetectPalette(palette, &is_opaque, &has_alpha_channel);
|
2020-03-17 09:35:42 +01:00
|
|
|
|
if (!is_opaque) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
needAlpha = true;
|
2018-12-15 14:50:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-08 14:59:18 -07:00
|
|
|
|
texture_colorspace = SDL_GetSurfaceColorspace(surface);
|
2024-02-01 10:30:58 -08:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Try to have the best pixel format for the texture
|
|
|
|
|
|
// No alpha, but a colorkey => promote to alpha
|
2024-07-08 14:59:18 -07:00
|
|
|
|
if (!SDL_ISPIXELFORMAT_ALPHA(surface->format) && SDL_SurfaceHasColorKey(surface)) {
|
|
|
|
|
|
if (surface->format == SDL_PIXELFORMAT_XRGB8888) {
|
2024-06-03 19:26:43 -07:00
|
|
|
|
for (i = 0; i < renderer->num_texture_formats; ++i) {
|
|
|
|
|
|
if (renderer->texture_formats[i] == SDL_PIXELFORMAT_ARGB8888) {
|
Fixed bug 4469 - make SDL_CreateTextureFromSurface pick a more appropriate format
Sylvain
Currently SDL_CreateTextureFromSurface picks first valid format, and do a conversion.
format = renderer->info.texture_formats[0];
for (i = 0; i < renderer->info.num_texture_formats; ++i) {
if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
format = renderer->info.texture_formats[i];
break;
It could try to find a better format, for instance :
if SDL_Surface has no Amask, but a colorkey :
if surface fmt is RGB888, try to pick ARGB8888 renderer fmt
if surface fmt is BGR888, try to pick ABGR8888 renderer fmt
else
try to pick the same renderer format as surface fmt
if no format has been picked, use the fallback.
I think it goes with bug 4290 fastpath BlitNtoN
when you expand a surface with pixel format of size 24 to 32, there is a fast path possible.
So with this issue:
- if you have a surface with colorkey (RGB or BGR, not palette), it takes a renderer format where the conversion is faster.
(it avoids, if possible, RGB -> ABGR which means switching RGB to BGR)
- if you have a surface ABGR format, it try to take the ABGR from the renderer.
(it avoids, if possible, ABGR -> ARGB, which means switch RGB to BGR)
2019-05-19 12:04:06 -07:00
|
|
|
|
format = SDL_PIXELFORMAT_ARGB8888;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-07-08 14:59:18 -07:00
|
|
|
|
} else if (surface->format == SDL_PIXELFORMAT_XBGR8888) {
|
2024-06-03 19:26:43 -07:00
|
|
|
|
for (i = 0; i < renderer->num_texture_formats; ++i) {
|
|
|
|
|
|
if (renderer->texture_formats[i] == SDL_PIXELFORMAT_ABGR8888) {
|
Fixed bug 4469 - make SDL_CreateTextureFromSurface pick a more appropriate format
Sylvain
Currently SDL_CreateTextureFromSurface picks first valid format, and do a conversion.
format = renderer->info.texture_formats[0];
for (i = 0; i < renderer->info.num_texture_formats; ++i) {
if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
format = renderer->info.texture_formats[i];
break;
It could try to find a better format, for instance :
if SDL_Surface has no Amask, but a colorkey :
if surface fmt is RGB888, try to pick ARGB8888 renderer fmt
if surface fmt is BGR888, try to pick ABGR8888 renderer fmt
else
try to pick the same renderer format as surface fmt
if no format has been picked, use the fallback.
I think it goes with bug 4290 fastpath BlitNtoN
when you expand a surface with pixel format of size 24 to 32, there is a fast path possible.
So with this issue:
- if you have a surface with colorkey (RGB or BGR, not palette), it takes a renderer format where the conversion is faster.
(it avoids, if possible, RGB -> ABGR which means switching RGB to BGR)
- if you have a surface ABGR format, it try to take the ABGR from the renderer.
(it avoids, if possible, ABGR -> ARGB, which means switch RGB to BGR)
2019-05-19 12:04:06 -07:00
|
|
|
|
format = SDL_PIXELFORMAT_ABGR8888;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Exact match would be fine
|
2024-06-03 19:26:43 -07:00
|
|
|
|
for (i = 0; i < renderer->num_texture_formats; ++i) {
|
2024-07-08 14:59:18 -07:00
|
|
|
|
if (renderer->texture_formats[i] == surface->format) {
|
|
|
|
|
|
format = surface->format;
|
Fixed bug 4469 - make SDL_CreateTextureFromSurface pick a more appropriate format
Sylvain
Currently SDL_CreateTextureFromSurface picks first valid format, and do a conversion.
format = renderer->info.texture_formats[0];
for (i = 0; i < renderer->info.num_texture_formats; ++i) {
if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
format = renderer->info.texture_formats[i];
break;
It could try to find a better format, for instance :
if SDL_Surface has no Amask, but a colorkey :
if surface fmt is RGB888, try to pick ARGB8888 renderer fmt
if surface fmt is BGR888, try to pick ABGR8888 renderer fmt
else
try to pick the same renderer format as surface fmt
if no format has been picked, use the fallback.
I think it goes with bug 4290 fastpath BlitNtoN
when you expand a surface with pixel format of size 24 to 32, there is a fast path possible.
So with this issue:
- if you have a surface with colorkey (RGB or BGR, not palette), it takes a renderer format where the conversion is faster.
(it avoids, if possible, RGB -> ABGR which means switching RGB to BGR)
- if you have a surface ABGR format, it try to take the ABGR from the renderer.
(it avoids, if possible, ABGR -> ARGB, which means switch RGB to BGR)
2019-05-19 12:04:06 -07:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Look for 10-bit pixel formats if needed
|
2024-07-08 14:59:18 -07:00
|
|
|
|
if (format == SDL_PIXELFORMAT_UNKNOWN && SDL_ISPIXELFORMAT_10BIT(surface->format)) {
|
2024-06-03 19:26:43 -07:00
|
|
|
|
for (i = 0; i < renderer->num_texture_formats; ++i) {
|
|
|
|
|
|
if (SDL_ISPIXELFORMAT_10BIT(renderer->texture_formats[i])) {
|
|
|
|
|
|
format = renderer->texture_formats[i];
|
2024-02-19 08:45:02 -08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Look for floating point pixel formats if needed
|
2024-02-01 11:22:04 -08:00
|
|
|
|
if (format == SDL_PIXELFORMAT_UNKNOWN &&
|
2024-07-08 14:59:18 -07:00
|
|
|
|
(SDL_ISPIXELFORMAT_10BIT(surface->format) || SDL_ISPIXELFORMAT_FLOAT(surface->format))) {
|
2024-06-03 19:26:43 -07:00
|
|
|
|
for (i = 0; i < renderer->num_texture_formats; ++i) {
|
|
|
|
|
|
if (SDL_ISPIXELFORMAT_FLOAT(renderer->texture_formats[i])) {
|
|
|
|
|
|
format = renderer->texture_formats[i];
|
2024-02-01 11:22:04 -08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Fallback, choose a valid pixel format
|
Fixed bug 4469 - make SDL_CreateTextureFromSurface pick a more appropriate format
Sylvain
Currently SDL_CreateTextureFromSurface picks first valid format, and do a conversion.
format = renderer->info.texture_formats[0];
for (i = 0; i < renderer->info.num_texture_formats; ++i) {
if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
format = renderer->info.texture_formats[i];
break;
It could try to find a better format, for instance :
if SDL_Surface has no Amask, but a colorkey :
if surface fmt is RGB888, try to pick ARGB8888 renderer fmt
if surface fmt is BGR888, try to pick ABGR8888 renderer fmt
else
try to pick the same renderer format as surface fmt
if no format has been picked, use the fallback.
I think it goes with bug 4290 fastpath BlitNtoN
when you expand a surface with pixel format of size 24 to 32, there is a fast path possible.
So with this issue:
- if you have a surface with colorkey (RGB or BGR, not palette), it takes a renderer format where the conversion is faster.
(it avoids, if possible, RGB -> ABGR which means switching RGB to BGR)
- if you have a surface ABGR format, it try to take the ABGR from the renderer.
(it avoids, if possible, ABGR -> ARGB, which means switch RGB to BGR)
2019-05-19 12:04:06 -07:00
|
|
|
|
if (format == SDL_PIXELFORMAT_UNKNOWN) {
|
2024-06-03 19:26:43 -07:00
|
|
|
|
format = renderer->texture_formats[0];
|
|
|
|
|
|
for (i = 0; i < renderer->num_texture_formats; ++i) {
|
|
|
|
|
|
if (!SDL_ISPIXELFORMAT_FOURCC(renderer->texture_formats[i]) &&
|
|
|
|
|
|
SDL_ISPIXELFORMAT_ALPHA(renderer->texture_formats[i]) == needAlpha) {
|
|
|
|
|
|
format = renderer->texture_formats[i];
|
Fixed bug 4469 - make SDL_CreateTextureFromSurface pick a more appropriate format
Sylvain
Currently SDL_CreateTextureFromSurface picks first valid format, and do a conversion.
format = renderer->info.texture_formats[0];
for (i = 0; i < renderer->info.num_texture_formats; ++i) {
if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
format = renderer->info.texture_formats[i];
break;
It could try to find a better format, for instance :
if SDL_Surface has no Amask, but a colorkey :
if surface fmt is RGB888, try to pick ARGB8888 renderer fmt
if surface fmt is BGR888, try to pick ABGR8888 renderer fmt
else
try to pick the same renderer format as surface fmt
if no format has been picked, use the fallback.
I think it goes with bug 4290 fastpath BlitNtoN
when you expand a surface with pixel format of size 24 to 32, there is a fast path possible.
So with this issue:
- if you have a surface with colorkey (RGB or BGR, not palette), it takes a renderer format where the conversion is faster.
(it avoids, if possible, RGB -> ABGR which means switching RGB to BGR)
- if you have a surface ABGR format, it try to take the ABGR from the renderer.
(it avoids, if possible, ABGR -> ARGB, which means switch RGB to BGR)
2019-05-19 12:04:06 -07:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-22 11:50:58 -08:00
|
|
|
|
if (surface_colorspace == SDL_COLORSPACE_SRGB_LINEAR ||
|
|
|
|
|
|
SDL_COLORSPACETRANSFER(surface_colorspace) == SDL_TRANSFER_CHARACTERISTICS_PQ) {
|
|
|
|
|
|
if (SDL_ISPIXELFORMAT_FLOAT(format)) {
|
|
|
|
|
|
texture_colorspace = SDL_COLORSPACE_SRGB_LINEAR;
|
|
|
|
|
|
} else if (SDL_ISPIXELFORMAT_10BIT(format)) {
|
|
|
|
|
|
texture_colorspace = SDL_COLORSPACE_HDR10;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
texture_colorspace = SDL_COLORSPACE_SRGB;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-30 23:11:18 -08:00
|
|
|
|
props = SDL_CreateProperties();
|
2024-02-19 08:45:02 -08:00
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER, texture_colorspace);
|
|
|
|
|
|
if (surface_colorspace == texture_colorspace) {
|
|
|
|
|
|
SDL_SetFloatProperty(props, SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT,
|
|
|
|
|
|
SDL_GetSurfaceSDRWhitePoint(surface, surface_colorspace));
|
|
|
|
|
|
}
|
|
|
|
|
|
SDL_SetFloatProperty(props, SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT,
|
|
|
|
|
|
SDL_GetSurfaceHDRHeadroom(surface, surface_colorspace));
|
2024-01-30 23:11:18 -08:00
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER, format);
|
|
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER, SDL_TEXTUREACCESS_STATIC);
|
|
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER, surface->w);
|
|
|
|
|
|
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER, surface->h);
|
|
|
|
|
|
texture = SDL_CreateTextureWithProperties(renderer, props);
|
2024-03-11 03:06:42 +02:00
|
|
|
|
SDL_DestroyProperties(props);
|
2024-01-30 23:11:18 -08:00
|
|
|
|
if (!texture) {
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-07 10:22:57 +02:00
|
|
|
|
if (SDL_UpdateTextureFromSurface(texture, NULL, surface) < 0) {
|
|
|
|
|
|
SDL_DestroyTexture(texture);
|
|
|
|
|
|
return NULL;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-08 14:15:56 -05:00
|
|
|
|
SDL_Renderer *SDL_GetRendererFromTexture(SDL_Texture *texture)
|
2024-01-08 10:17:38 -05:00
|
|
|
|
{
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, NULL);
|
2024-07-17 10:10:31 -07:00
|
|
|
|
|
2024-01-08 10:17:38 -05:00
|
|
|
|
return texture->renderer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-11 16:59:51 -07:00
|
|
|
|
SDL_PropertiesID SDL_GetTextureProperties(SDL_Texture *texture)
|
|
|
|
|
|
{
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (texture->props == 0) {
|
|
|
|
|
|
texture->props = SDL_CreateProperties();
|
|
|
|
|
|
}
|
|
|
|
|
|
return texture->props;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 09:21:02 -07:00
|
|
|
|
int SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (w) {
|
|
|
|
|
|
*w = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (h) {
|
|
|
|
|
|
*h = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (w) {
|
2024-06-12 09:21:02 -07:00
|
|
|
|
*w = (float)texture->w;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
if (h) {
|
2024-06-12 09:21:02 -07:00
|
|
|
|
*h = (float)texture->h;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
int SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b)
|
2024-01-29 13:28:33 -08:00
|
|
|
|
{
|
|
|
|
|
|
const float fR = (float)r / 255.0f;
|
|
|
|
|
|
const float fG = (float)g / 255.0f;
|
|
|
|
|
|
const float fB = (float)b / 255.0f;
|
|
|
|
|
|
|
|
|
|
|
|
return SDL_SetTextureColorModFloat(texture, fR, fG, fB);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SDL_SetTextureColorModFloat(SDL_Texture *texture, float r, float g, float b)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
2021-10-24 17:16:49 +02:00
|
|
|
|
texture->color.r = r;
|
|
|
|
|
|
texture->color.g = g;
|
|
|
|
|
|
texture->color.b = b;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (texture->native) {
|
2024-01-29 13:28:33 -08:00
|
|
|
|
return SDL_SetTextureColorModFloat(texture->native, r, g, b);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2018-09-20 15:46:02 -04:00
|
|
|
|
return 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
int SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b)
|
2024-01-29 13:28:33 -08:00
|
|
|
|
{
|
2024-07-17 10:10:31 -07:00
|
|
|
|
float fR = 1.0f, fG = 1.0f, fB = 1.0f;
|
2024-01-29 13:28:33 -08:00
|
|
|
|
|
|
|
|
|
|
if (SDL_GetTextureColorModFloat(texture, &fR, &fG, &fB) < 0) {
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (r) {
|
|
|
|
|
|
*r = 255;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (g) {
|
|
|
|
|
|
*g = 255;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (b) {
|
|
|
|
|
|
*b = 255;
|
|
|
|
|
|
}
|
2024-01-29 13:28:33 -08:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (r) {
|
|
|
|
|
|
*r = (Uint8)(fR * 255.0f);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (g) {
|
|
|
|
|
|
*g = (Uint8)(fG * 255.0f);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (b) {
|
|
|
|
|
|
*b = (Uint8)(fB * 255.0f);
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SDL_GetTextureColorModFloat(SDL_Texture *texture, float *r, float *g, float *b)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-01-29 18:32:27 -08:00
|
|
|
|
SDL_FColor color;
|
|
|
|
|
|
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (r) {
|
|
|
|
|
|
*r = 1.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (g) {
|
|
|
|
|
|
*g = 1.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (b) {
|
|
|
|
|
|
*b = 1.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
2024-01-29 18:32:27 -08:00
|
|
|
|
color = texture->color;
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (r) {
|
2024-01-29 18:32:27 -08:00
|
|
|
|
*r = color.r;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
if (g) {
|
2024-01-29 18:32:27 -08:00
|
|
|
|
*g = color.g;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
if (b) {
|
2024-01-29 18:32:27 -08:00
|
|
|
|
*b = color.b;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
int SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha)
|
2024-01-29 13:28:33 -08:00
|
|
|
|
{
|
|
|
|
|
|
const float fA = (float)alpha / 255.0f;
|
|
|
|
|
|
|
|
|
|
|
|
return SDL_SetTextureAlphaModFloat(texture, fA);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SDL_SetTextureAlphaModFloat(SDL_Texture *texture, float alpha)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
2021-10-24 17:16:49 +02:00
|
|
|
|
texture->color.a = alpha;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (texture->native) {
|
2024-01-29 13:28:33 -08:00
|
|
|
|
return SDL_SetTextureAlphaModFloat(texture->native, alpha);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2018-09-20 15:46:02 -04:00
|
|
|
|
return 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
int SDL_GetTextureAlphaMod(SDL_Texture *texture, Uint8 *alpha)
|
2024-01-29 13:28:33 -08:00
|
|
|
|
{
|
2024-05-17 09:42:38 -07:00
|
|
|
|
float fA = 1.0f;
|
2024-01-29 13:28:33 -08:00
|
|
|
|
|
|
|
|
|
|
if (SDL_GetTextureAlphaModFloat(texture, &fA) < 0) {
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (alpha) {
|
|
|
|
|
|
*alpha = 255;
|
|
|
|
|
|
}
|
2024-01-29 13:28:33 -08:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (alpha) {
|
|
|
|
|
|
*alpha = (Uint8)(fA * 255.0f);
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SDL_GetTextureAlphaModFloat(SDL_Texture *texture, float *alpha)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (alpha) {
|
|
|
|
|
|
*alpha = 1.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (alpha) {
|
2021-10-24 17:16:49 +02:00
|
|
|
|
*alpha = texture->color.a;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
int SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
2024-07-16 21:15:56 -07:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_INVALID) {
|
|
|
|
|
|
return SDL_InvalidParamError("blendMode");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
renderer = texture->renderer;
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
if (!IsSupportedBlendMode(renderer, blendMode)) {
|
|
|
|
|
|
return SDL_Unsupported();
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
texture->blendMode = blendMode;
|
|
|
|
|
|
if (texture->native) {
|
|
|
|
|
|
return SDL_SetTextureBlendMode(texture->native, blendMode);
|
|
|
|
|
|
}
|
2018-09-20 15:46:02 -04:00
|
|
|
|
return 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-17 09:40:25 -07:00
|
|
|
|
int SDL_GetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode *blendMode)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (blendMode) {
|
|
|
|
|
|
*blendMode = SDL_BLENDMODE_INVALID;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-17 09:40:25 -07:00
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-07-17 09:40:25 -07:00
|
|
|
|
if (blendMode) {
|
|
|
|
|
|
*blendMode = texture->blendMode;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
int SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode)
|
2019-12-22 13:39:44 -08:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
|
|
|
|
|
renderer = texture->renderer;
|
|
|
|
|
|
texture->scaleMode = scaleMode;
|
|
|
|
|
|
if (texture->native) {
|
|
|
|
|
|
return SDL_SetTextureScaleMode(texture->native, scaleMode);
|
2022-04-02 13:49:50 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
renderer->SetTextureScaleMode(renderer, texture, scaleMode);
|
2019-12-22 13:39:44 -08:00
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-17 09:40:25 -07:00
|
|
|
|
int SDL_GetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode *scaleMode)
|
2019-12-22 13:39:44 -08:00
|
|
|
|
{
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (scaleMode) {
|
|
|
|
|
|
*scaleMode = SDL_SCALEMODE_LINEAR;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-17 09:40:25 -07:00
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
2019-12-22 13:39:44 -08:00
|
|
|
|
|
2024-07-17 09:40:25 -07:00
|
|
|
|
if (scaleMode) {
|
|
|
|
|
|
*scaleMode = texture->scaleMode;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
2019-12-22 13:39:44 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-23 01:00:52 -08:00
|
|
|
|
#if SDL_HAVE_YUV
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect,
|
|
|
|
|
|
const void *pixels, int pitch)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Texture *native = texture->native;
|
|
|
|
|
|
SDL_Rect full_rect;
|
|
|
|
|
|
|
|
|
|
|
|
if (SDL_SW_UpdateYUVTexture(texture->yuv, rect, pixels, pitch) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
full_rect.x = 0;
|
|
|
|
|
|
full_rect.y = 0;
|
|
|
|
|
|
full_rect.w = texture->w;
|
|
|
|
|
|
full_rect.h = texture->h;
|
|
|
|
|
|
rect = &full_rect;
|
|
|
|
|
|
|
|
|
|
|
|
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// We can lock the texture and copy to it
|
2016-11-24 21:41:09 -05:00
|
|
|
|
void *native_pixels = NULL;
|
|
|
|
|
|
int native_pitch = 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
|
|
|
|
|
|
rect->w, rect->h, native_pixels, native_pitch);
|
|
|
|
|
|
SDL_UnlockTexture(native);
|
|
|
|
|
|
} else {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Use a temporary buffer for updating
|
2016-11-24 21:41:09 -05:00
|
|
|
|
const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
|
2022-12-01 16:07:03 -05:00
|
|
|
|
const size_t alloclen = (size_t)rect->h * temp_pitch;
|
2016-11-24 21:41:09 -05:00
|
|
|
|
if (alloclen > 0) {
|
|
|
|
|
|
void *temp_pixels = SDL_malloc(alloclen);
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!temp_pixels) {
|
error: SDL's allocators now call SDL_OutOfMemory on error.
This means the allocator's caller doesn't need to use SDL_OutOfMemory directly
if the allocation fails.
This applies to the usual allocators: SDL_malloc, SDL_calloc, SDL_realloc
(all of these regardless of if the app supplied a custom allocator or we're
using system malloc() or an internal copy of dlmalloc under the hood),
SDL_aligned_alloc, SDL_small_alloc, SDL_strdup, SDL_asprintf, SDL_wcsdup...
probably others. If it returns something you can pass to SDL_free, it should
work.
The caller might still need to use SDL_OutOfMemory if something that wasn't
SDL allocated the memory: operator new in C++ code, Objective-C's alloc
message, win32 GlobalAlloc, etc.
Fixes #8642.
2023-11-30 00:14:27 -05:00
|
|
|
|
return -1;
|
2016-11-24 21:41:09 -05:00
|
|
|
|
}
|
|
|
|
|
|
SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
|
|
|
|
|
|
rect->w, rect->h, temp_pixels, temp_pitch);
|
|
|
|
|
|
SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
|
|
|
|
|
|
SDL_free(temp_pixels);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
#endif // SDL_HAVE_YUV
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect,
|
|
|
|
|
|
const void *pixels, int pitch)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Texture *native = texture->native;
|
|
|
|
|
|
|
2016-11-24 21:41:09 -05:00
|
|
|
|
if (!rect->w || !rect->h) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
return 0; // nothing to do.
|
2016-11-24 21:41:09 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// We can lock the texture and copy to it
|
2016-11-24 21:41:09 -05:00
|
|
|
|
void *native_pixels = NULL;
|
|
|
|
|
|
int native_pitch = 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
SDL_ConvertPixels(rect->w, rect->h,
|
|
|
|
|
|
texture->format, pixels, pitch,
|
|
|
|
|
|
native->format, native_pixels, native_pitch);
|
|
|
|
|
|
SDL_UnlockTexture(native);
|
|
|
|
|
|
} else {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Use a temporary buffer for updating
|
2016-11-24 21:41:09 -05:00
|
|
|
|
const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
|
2022-12-01 16:07:03 -05:00
|
|
|
|
const size_t alloclen = (size_t)rect->h * temp_pitch;
|
2016-11-24 21:41:09 -05:00
|
|
|
|
if (alloclen > 0) {
|
|
|
|
|
|
void *temp_pixels = SDL_malloc(alloclen);
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!temp_pixels) {
|
error: SDL's allocators now call SDL_OutOfMemory on error.
This means the allocator's caller doesn't need to use SDL_OutOfMemory directly
if the allocation fails.
This applies to the usual allocators: SDL_malloc, SDL_calloc, SDL_realloc
(all of these regardless of if the app supplied a custom allocator or we're
using system malloc() or an internal copy of dlmalloc under the hood),
SDL_aligned_alloc, SDL_small_alloc, SDL_strdup, SDL_asprintf, SDL_wcsdup...
probably others. If it returns something you can pass to SDL_free, it should
work.
The caller might still need to use SDL_OutOfMemory if something that wasn't
SDL allocated the memory: operator new in C++ code, Objective-C's alloc
message, win32 GlobalAlloc, etc.
Fixes #8642.
2023-11-30 00:14:27 -05:00
|
|
|
|
return -1;
|
2016-11-24 21:41:09 -05:00
|
|
|
|
}
|
|
|
|
|
|
SDL_ConvertPixels(rect->w, rect->h,
|
|
|
|
|
|
texture->format, pixels, pitch,
|
|
|
|
|
|
native->format, temp_pixels, temp_pitch);
|
|
|
|
|
|
SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
|
|
|
|
|
|
SDL_free(temp_pixels);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
int SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2021-01-27 10:20:13 +01:00
|
|
|
|
SDL_Rect real_rect;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!pixels) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return SDL_InvalidParamError("pixels");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!pitch) {
|
|
|
|
|
|
return SDL_InvalidParamError("pitch");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-27 10:20:13 +01:00
|
|
|
|
real_rect.x = 0;
|
|
|
|
|
|
real_rect.y = 0;
|
|
|
|
|
|
real_rect.w = texture->w;
|
|
|
|
|
|
real_rect.h = texture->h;
|
|
|
|
|
|
if (rect) {
|
2022-12-27 11:01:11 -08:00
|
|
|
|
if (!SDL_GetRectIntersection(rect, &real_rect, &real_rect)) {
|
2021-01-27 10:20:13 +01:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-27 10:20:13 +01:00
|
|
|
|
if (real_rect.w == 0 || real_rect.h == 0) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
return 0; // nothing to do.
|
2020-01-21 21:33:40 +01:00
|
|
|
|
#if SDL_HAVE_YUV
|
2015-06-21 17:33:46 +02:00
|
|
|
|
} else if (texture->yuv) {
|
2021-01-27 10:20:13 +01:00
|
|
|
|
return SDL_UpdateTextureYUV(texture, &real_rect, pixels, pitch);
|
2020-01-21 21:33:40 +01:00
|
|
|
|
#endif
|
2015-06-21 17:33:46 +02:00
|
|
|
|
} else if (texture->native) {
|
2021-01-27 10:20:13 +01:00
|
|
|
|
return SDL_UpdateTextureNative(texture, &real_rect, pixels, pitch);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
} else {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
SDL_Renderer *renderer = texture->renderer;
|
|
|
|
|
|
if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2021-01-27 10:20:13 +01:00
|
|
|
|
return renderer->UpdateTexture(renderer, texture, &real_rect, pixels, pitch);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-23 01:00:52 -08:00
|
|
|
|
#if SDL_HAVE_YUV
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rect,
|
|
|
|
|
|
const Uint8 *Yplane, int Ypitch,
|
|
|
|
|
|
const Uint8 *Uplane, int Upitch,
|
|
|
|
|
|
const Uint8 *Vplane, int Vpitch)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Texture *native = texture->native;
|
|
|
|
|
|
SDL_Rect full_rect;
|
|
|
|
|
|
|
|
|
|
|
|
if (SDL_SW_UpdateYUVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
full_rect.x = 0;
|
|
|
|
|
|
full_rect.y = 0;
|
|
|
|
|
|
full_rect.w = texture->w;
|
|
|
|
|
|
full_rect.h = texture->h;
|
|
|
|
|
|
rect = &full_rect;
|
|
|
|
|
|
|
2016-11-24 21:41:09 -05:00
|
|
|
|
if (!rect->w || !rect->h) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
return 0; // nothing to do.
|
2016-11-24 21:41:09 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// We can lock the texture and copy to it
|
2016-11-24 21:41:09 -05:00
|
|
|
|
void *native_pixels = NULL;
|
|
|
|
|
|
int native_pitch = 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
|
|
|
|
|
|
rect->w, rect->h, native_pixels, native_pitch);
|
|
|
|
|
|
SDL_UnlockTexture(native);
|
|
|
|
|
|
} else {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Use a temporary buffer for updating
|
2016-11-24 21:41:09 -05:00
|
|
|
|
const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
|
2022-12-01 16:07:03 -05:00
|
|
|
|
const size_t alloclen = (size_t)rect->h * temp_pitch;
|
2016-11-24 21:41:09 -05:00
|
|
|
|
if (alloclen > 0) {
|
|
|
|
|
|
void *temp_pixels = SDL_malloc(alloclen);
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!temp_pixels) {
|
error: SDL's allocators now call SDL_OutOfMemory on error.
This means the allocator's caller doesn't need to use SDL_OutOfMemory directly
if the allocation fails.
This applies to the usual allocators: SDL_malloc, SDL_calloc, SDL_realloc
(all of these regardless of if the app supplied a custom allocator or we're
using system malloc() or an internal copy of dlmalloc under the hood),
SDL_aligned_alloc, SDL_small_alloc, SDL_strdup, SDL_asprintf, SDL_wcsdup...
probably others. If it returns something you can pass to SDL_free, it should
work.
The caller might still need to use SDL_OutOfMemory if something that wasn't
SDL allocated the memory: operator new in C++ code, Objective-C's alloc
message, win32 GlobalAlloc, etc.
Fixes #8642.
2023-11-30 00:14:27 -05:00
|
|
|
|
return -1;
|
2016-11-24 21:41:09 -05:00
|
|
|
|
}
|
|
|
|
|
|
SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
|
|
|
|
|
|
rect->w, rect->h, temp_pixels, temp_pitch);
|
|
|
|
|
|
SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
|
|
|
|
|
|
SDL_free(temp_pixels);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2021-01-05 11:56:22 +01:00
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect,
|
|
|
|
|
|
const Uint8 *Yplane, int Ypitch,
|
|
|
|
|
|
const Uint8 *UVplane, int UVpitch)
|
2021-01-05 11:56:22 +01:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Texture *native = texture->native;
|
|
|
|
|
|
SDL_Rect full_rect;
|
|
|
|
|
|
|
|
|
|
|
|
if (SDL_SW_UpdateNVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, UVplane, UVpitch) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
full_rect.x = 0;
|
|
|
|
|
|
full_rect.y = 0;
|
|
|
|
|
|
full_rect.w = texture->w;
|
|
|
|
|
|
full_rect.h = texture->h;
|
|
|
|
|
|
rect = &full_rect;
|
|
|
|
|
|
|
|
|
|
|
|
if (!rect->w || !rect->h) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
return 0; // nothing to do.
|
2021-01-05 11:56:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// We can lock the texture and copy to it
|
2021-01-05 11:56:22 +01:00
|
|
|
|
void *native_pixels = NULL;
|
|
|
|
|
|
int native_pitch = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
|
|
|
|
|
|
rect->w, rect->h, native_pixels, native_pitch);
|
|
|
|
|
|
SDL_UnlockTexture(native);
|
|
|
|
|
|
} else {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Use a temporary buffer for updating
|
2021-01-05 11:56:22 +01:00
|
|
|
|
const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
|
2022-12-01 16:07:03 -05:00
|
|
|
|
const size_t alloclen = (size_t)rect->h * temp_pitch;
|
2021-01-05 11:56:22 +01:00
|
|
|
|
if (alloclen > 0) {
|
|
|
|
|
|
void *temp_pixels = SDL_malloc(alloclen);
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!temp_pixels) {
|
error: SDL's allocators now call SDL_OutOfMemory on error.
This means the allocator's caller doesn't need to use SDL_OutOfMemory directly
if the allocation fails.
This applies to the usual allocators: SDL_malloc, SDL_calloc, SDL_realloc
(all of these regardless of if the app supplied a custom allocator or we're
using system malloc() or an internal copy of dlmalloc under the hood),
SDL_aligned_alloc, SDL_small_alloc, SDL_strdup, SDL_asprintf, SDL_wcsdup...
probably others. If it returns something you can pass to SDL_free, it should
work.
The caller might still need to use SDL_OutOfMemory if something that wasn't
SDL allocated the memory: operator new in C++ code, Objective-C's alloc
message, win32 GlobalAlloc, etc.
Fixes #8642.
2023-11-30 00:14:27 -05:00
|
|
|
|
return -1;
|
2021-01-05 11:56:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
|
|
|
|
|
|
rect->w, rect->h, temp_pixels, temp_pitch);
|
|
|
|
|
|
SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
|
|
|
|
|
|
SDL_free(temp_pixels);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
#endif // SDL_HAVE_YUV
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
int SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect,
|
2015-06-21 17:33:46 +02:00
|
|
|
|
const Uint8 *Yplane, int Ypitch,
|
|
|
|
|
|
const Uint8 *Uplane, int Upitch,
|
|
|
|
|
|
const Uint8 *Vplane, int Vpitch)
|
|
|
|
|
|
{
|
2020-01-21 21:33:40 +01:00
|
|
|
|
#if SDL_HAVE_YUV
|
2015-06-21 17:33:46 +02:00
|
|
|
|
SDL_Renderer *renderer;
|
2021-01-27 10:54:49 +01:00
|
|
|
|
SDL_Rect real_rect;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!Yplane) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return SDL_InvalidParamError("Yplane");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!Ypitch) {
|
|
|
|
|
|
return SDL_InvalidParamError("Ypitch");
|
|
|
|
|
|
}
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!Uplane) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return SDL_InvalidParamError("Uplane");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!Upitch) {
|
|
|
|
|
|
return SDL_InvalidParamError("Upitch");
|
|
|
|
|
|
}
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!Vplane) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return SDL_InvalidParamError("Vplane");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!Vpitch) {
|
|
|
|
|
|
return SDL_InvalidParamError("Vpitch");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (texture->format != SDL_PIXELFORMAT_YV12 &&
|
|
|
|
|
|
texture->format != SDL_PIXELFORMAT_IYUV) {
|
|
|
|
|
|
return SDL_SetError("Texture format must by YV12 or IYUV");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-27 10:54:49 +01:00
|
|
|
|
real_rect.x = 0;
|
|
|
|
|
|
real_rect.y = 0;
|
|
|
|
|
|
real_rect.w = texture->w;
|
|
|
|
|
|
real_rect.h = texture->h;
|
|
|
|
|
|
if (rect) {
|
2022-12-27 11:01:11 -08:00
|
|
|
|
SDL_GetRectIntersection(rect, &real_rect, &real_rect);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-27 10:54:49 +01:00
|
|
|
|
if (real_rect.w == 0 || real_rect.h == 0) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
return 0; // nothing to do.
|
2016-11-24 21:41:09 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (texture->yuv) {
|
2021-01-27 10:54:49 +01:00
|
|
|
|
return SDL_UpdateTextureYUVPlanar(texture, &real_rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
SDL_assert(!texture->native);
|
|
|
|
|
|
renderer = texture->renderer;
|
|
|
|
|
|
SDL_assert(renderer->UpdateTextureYUV);
|
|
|
|
|
|
if (renderer->UpdateTextureYUV) {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2021-01-27 10:54:49 +01:00
|
|
|
|
return renderer->UpdateTextureYUV(renderer, texture, &real_rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
return SDL_Unsupported();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-01-21 21:33:40 +01:00
|
|
|
|
#else
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
#endif
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
int SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect,
|
|
|
|
|
|
const Uint8 *Yplane, int Ypitch,
|
|
|
|
|
|
const Uint8 *UVplane, int UVpitch)
|
2021-01-05 11:56:22 +01:00
|
|
|
|
{
|
|
|
|
|
|
#if SDL_HAVE_YUV
|
|
|
|
|
|
SDL_Renderer *renderer;
|
2021-01-27 10:54:49 +01:00
|
|
|
|
SDL_Rect real_rect;
|
2021-01-05 11:56:22 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!Yplane) {
|
2021-01-05 11:56:22 +01:00
|
|
|
|
return SDL_InvalidParamError("Yplane");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!Ypitch) {
|
|
|
|
|
|
return SDL_InvalidParamError("Ypitch");
|
|
|
|
|
|
}
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!UVplane) {
|
2021-01-05 11:56:22 +01:00
|
|
|
|
return SDL_InvalidParamError("UVplane");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!UVpitch) {
|
|
|
|
|
|
return SDL_InvalidParamError("UVpitch");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (texture->format != SDL_PIXELFORMAT_NV12 &&
|
|
|
|
|
|
texture->format != SDL_PIXELFORMAT_NV21) {
|
|
|
|
|
|
return SDL_SetError("Texture format must by NV12 or NV21");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-27 10:54:49 +01:00
|
|
|
|
real_rect.x = 0;
|
|
|
|
|
|
real_rect.y = 0;
|
|
|
|
|
|
real_rect.w = texture->w;
|
|
|
|
|
|
real_rect.h = texture->h;
|
|
|
|
|
|
if (rect) {
|
2022-12-27 11:01:11 -08:00
|
|
|
|
SDL_GetRectIntersection(rect, &real_rect, &real_rect);
|
2021-01-05 11:56:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-27 10:54:49 +01:00
|
|
|
|
if (real_rect.w == 0 || real_rect.h == 0) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
return 0; // nothing to do.
|
2021-01-05 11:56:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (texture->yuv) {
|
2021-01-27 10:54:49 +01:00
|
|
|
|
return SDL_UpdateTextureNVPlanar(texture, &real_rect, Yplane, Ypitch, UVplane, UVpitch);
|
2021-01-05 11:56:22 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
SDL_assert(!texture->native);
|
|
|
|
|
|
renderer = texture->renderer;
|
|
|
|
|
|
SDL_assert(renderer->UpdateTextureNV);
|
|
|
|
|
|
if (renderer->UpdateTextureNV) {
|
|
|
|
|
|
if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2021-01-27 10:54:49 +01:00
|
|
|
|
return renderer->UpdateTextureNV(renderer, texture, &real_rect, Yplane, Ypitch, UVplane, UVpitch);
|
2021-01-05 11:56:22 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
return SDL_Unsupported();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#else
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-23 01:00:52 -08:00
|
|
|
|
#if SDL_HAVE_YUV
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int SDL_LockTextureYUV(SDL_Texture *texture, const SDL_Rect *rect,
|
|
|
|
|
|
void **pixels, int *pitch)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
return SDL_SW_LockYUVTexture(texture->yuv, rect, pixels, pitch);
|
|
|
|
|
|
}
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
#endif // SDL_HAVE_YUV
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int SDL_LockTextureNative(SDL_Texture *texture, const SDL_Rect *rect,
|
|
|
|
|
|
void **pixels, int *pitch)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
texture->locked_rect = *rect;
|
2022-11-30 12:51:59 -08:00
|
|
|
|
*pixels = (void *)((Uint8 *)texture->pixels +
|
|
|
|
|
|
rect->y * texture->pitch +
|
|
|
|
|
|
rect->x * SDL_BYTESPERPIXEL(texture->format));
|
2015-06-21 17:33:46 +02:00
|
|
|
|
*pitch = texture->pitch;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Rect full_rect;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
|
|
|
|
|
|
return SDL_SetError("SDL_LockTexture(): texture must be streaming");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!rect) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
full_rect.x = 0;
|
|
|
|
|
|
full_rect.y = 0;
|
|
|
|
|
|
full_rect.w = texture->w;
|
|
|
|
|
|
full_rect.h = texture->h;
|
|
|
|
|
|
rect = &full_rect;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-21 21:33:40 +01:00
|
|
|
|
#if SDL_HAVE_YUV
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (texture->yuv) {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return SDL_LockTextureYUV(texture, rect, pixels, pitch);
|
2020-01-21 21:33:40 +01:00
|
|
|
|
} else
|
|
|
|
|
|
#endif
|
2022-11-30 12:51:59 -08:00
|
|
|
|
if (texture->native) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Calls a real SDL_LockTexture/SDL_UnlockTexture on unlock, flushing then.
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return SDL_LockTextureNative(texture, rect, pixels, pitch);
|
|
|
|
|
|
} else {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
SDL_Renderer *renderer = texture->renderer;
|
|
|
|
|
|
if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return renderer->LockTexture(renderer, texture, rect, pixels, pitch);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
int SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect, SDL_Surface **surface)
|
2019-09-30 20:58:44 +02:00
|
|
|
|
{
|
2019-10-01 09:26:30 +02:00
|
|
|
|
SDL_Rect real_rect;
|
2019-09-30 20:58:44 +02:00
|
|
|
|
void *pixels = NULL;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
int pitch = 0; // fix static analysis
|
2020-05-15 21:33:47 +02:00
|
|
|
|
int ret;
|
2019-09-30 20:58:44 +02:00
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!texture || !surface) {
|
2019-09-30 20:58:44 +02:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-01 09:26:30 +02:00
|
|
|
|
real_rect.x = 0;
|
|
|
|
|
|
real_rect.y = 0;
|
|
|
|
|
|
real_rect.w = texture->w;
|
|
|
|
|
|
real_rect.h = texture->h;
|
|
|
|
|
|
if (rect) {
|
2022-12-27 11:01:11 -08:00
|
|
|
|
SDL_GetRectIntersection(rect, &real_rect, &real_rect);
|
2019-09-30 20:58:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-01 09:26:30 +02:00
|
|
|
|
ret = SDL_LockTexture(texture, &real_rect, &pixels, &pitch);
|
2019-09-30 20:58:44 +02:00
|
|
|
|
if (ret < 0) {
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-08 14:59:18 -07:00
|
|
|
|
texture->locked_surface = SDL_CreateSurfaceFrom(real_rect.w, real_rect.h, texture->format, pixels, pitch);
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!texture->locked_surface) {
|
2019-09-30 20:58:44 +02:00
|
|
|
|
SDL_UnlockTexture(texture);
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*surface = texture->locked_surface;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-23 01:00:52 -08:00
|
|
|
|
#if SDL_HAVE_YUV
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static void SDL_UnlockTextureYUV(SDL_Texture *texture)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Texture *native = texture->native;
|
|
|
|
|
|
void *native_pixels = NULL;
|
|
|
|
|
|
int native_pitch = 0;
|
|
|
|
|
|
SDL_Rect rect;
|
|
|
|
|
|
|
|
|
|
|
|
rect.x = 0;
|
|
|
|
|
|
rect.y = 0;
|
|
|
|
|
|
rect.w = texture->w;
|
|
|
|
|
|
rect.h = texture->h;
|
|
|
|
|
|
|
|
|
|
|
|
if (SDL_LockTexture(native, &rect, &native_pixels, &native_pitch) < 0) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
SDL_SW_CopyYUVToRGB(texture->yuv, &rect, native->format,
|
|
|
|
|
|
rect.w, rect.h, native_pixels, native_pitch);
|
|
|
|
|
|
SDL_UnlockTexture(native);
|
|
|
|
|
|
}
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
#endif // SDL_HAVE_YUV
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static void SDL_UnlockTextureNative(SDL_Texture *texture)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Texture *native = texture->native;
|
|
|
|
|
|
void *native_pixels = NULL;
|
|
|
|
|
|
int native_pitch = 0;
|
|
|
|
|
|
const SDL_Rect *rect = &texture->locked_rect;
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const void *pixels = (void *)((Uint8 *)texture->pixels +
|
|
|
|
|
|
rect->y * texture->pitch +
|
|
|
|
|
|
rect->x * SDL_BYTESPERPIXEL(texture->format));
|
2015-06-21 17:33:46 +02:00
|
|
|
|
int pitch = texture->pitch;
|
|
|
|
|
|
|
|
|
|
|
|
if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
SDL_ConvertPixels(rect->w, rect->h,
|
|
|
|
|
|
texture->format, pixels, pitch,
|
|
|
|
|
|
native->format, native_pixels, native_pitch);
|
|
|
|
|
|
SDL_UnlockTexture(native);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-09 20:16:41 +01:00
|
|
|
|
void SDL_UnlockTexture(SDL_Texture *texture)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2023-02-09 20:16:41 +01:00
|
|
|
|
CHECK_TEXTURE_MAGIC(texture,);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
|
2023-02-09 20:16:41 +01:00
|
|
|
|
return;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2020-01-21 21:33:40 +01:00
|
|
|
|
#if SDL_HAVE_YUV
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (texture->yuv) {
|
|
|
|
|
|
SDL_UnlockTextureYUV(texture);
|
2020-01-21 21:33:40 +01:00
|
|
|
|
} else
|
|
|
|
|
|
#endif
|
2022-11-30 12:51:59 -08:00
|
|
|
|
if (texture->native) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
SDL_UnlockTextureNative(texture);
|
|
|
|
|
|
} else {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
SDL_Renderer *renderer = texture->renderer;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
renderer->UnlockTexture(renderer, texture);
|
|
|
|
|
|
}
|
2019-09-30 20:58:44 +02:00
|
|
|
|
|
2022-12-27 06:36:39 -08:00
|
|
|
|
SDL_DestroySurface(texture->locked_surface);
|
2019-09-30 20:58:44 +02:00
|
|
|
|
texture->locked_surface = NULL;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
static int SDL_SetRenderTargetInternal(SDL_Renderer *renderer, SDL_Texture *texture)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// texture == NULL is valid and means reset the target to the window
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (texture) {
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
if (renderer != texture->renderer) {
|
|
|
|
|
|
return SDL_SetError("Texture was not created with this renderer");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (texture->access != SDL_TEXTUREACCESS_TARGET) {
|
|
|
|
|
|
return SDL_SetError("Texture not created with SDL_TEXTUREACCESS_TARGET");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (texture->native) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Always render to the native texture
|
2015-06-21 17:33:46 +02:00
|
|
|
|
texture = texture->native;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-09 06:42:31 -08:00
|
|
|
|
if (texture == renderer->target) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Nothing to do!
|
2020-12-09 06:42:31 -08:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
FlushRenderCommands(renderer); // time to send everything to the GPU!
|
2020-12-09 06:42:31 -08:00
|
|
|
|
|
2018-06-18 13:13:56 -07:00
|
|
|
|
SDL_LockMutex(renderer->target_mutex);
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
renderer->target = texture;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (texture) {
|
|
|
|
|
|
renderer->view = &texture->view;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
renderer->view = &renderer->main_view;
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
if (renderer->SetRenderTarget(renderer, texture) < 0) {
|
2018-06-18 13:13:56 -07:00
|
|
|
|
SDL_UnlockMutex(renderer->target_mutex);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-18 13:13:56 -07:00
|
|
|
|
SDL_UnlockMutex(renderer->target_mutex);
|
|
|
|
|
|
|
2018-09-23 23:20:40 -04:00
|
|
|
|
if (QueueCmdSetViewport(renderer) < 0) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2018-09-23 23:20:40 -04:00
|
|
|
|
if (QueueCmdSetClipRect(renderer) < 0) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// All set!
|
2023-11-20 20:26:12 -05:00
|
|
|
|
return 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
int SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
|
|
|
|
|
|
{
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!texture && renderer->logical_target) {
|
2023-02-03 12:25:46 -08:00
|
|
|
|
return SDL_SetRenderTargetInternal(renderer, renderer->logical_target);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return SDL_SetRenderTargetInternal(renderer, texture);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SDL_Texture *SDL_GetRenderTarget(SDL_Renderer *renderer)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2022-04-12 09:01:17 +02:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, NULL);
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->target == renderer->logical_target) {
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
} else {
|
2024-07-12 09:39:58 -07:00
|
|
|
|
return (SDL_Texture *)SDL_GetPointerProperty(SDL_GetTextureProperties(renderer->target), SDL_PROP_TEXTURE_PARENT_POINTER, renderer->target);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
static int UpdateLogicalPresentation(SDL_Renderer *renderer)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-06-12 09:21:02 -07:00
|
|
|
|
float logical_w = 1.0f, logical_h = 1.0f;
|
2024-06-12 19:08:06 -07:00
|
|
|
|
float output_w = (float)renderer->main_view.pixel_w;
|
|
|
|
|
|
float output_h = (float)renderer->main_view.pixel_h;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
float want_aspect = 1.0f;
|
|
|
|
|
|
float real_aspect = 1.0f;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
float scale;
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// All done!
|
2016-10-14 00:51:57 -07:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-06-12 09:21:02 -07:00
|
|
|
|
if (SDL_GetTextureSize(renderer->logical_target, &logical_w, &logical_h) < 0) {
|
2023-05-16 16:29:52 -07:00
|
|
|
|
goto error;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-06-12 09:21:02 -07:00
|
|
|
|
want_aspect = logical_w / logical_h;
|
|
|
|
|
|
real_aspect = output_w / output_h;
|
2023-05-16 16:29:52 -07:00
|
|
|
|
|
2023-03-02 08:56:54 -08:00
|
|
|
|
renderer->logical_src_rect.x = 0.0f;
|
|
|
|
|
|
renderer->logical_src_rect.y = 0.0f;
|
2024-06-12 09:21:02 -07:00
|
|
|
|
renderer->logical_src_rect.w = logical_w;
|
|
|
|
|
|
renderer->logical_src_rect.h = logical_h;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_INTEGER_SCALE) {
|
2016-01-05 16:39:18 -05:00
|
|
|
|
if (want_aspect > real_aspect) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
scale = (float)((int)output_w / (int)logical_w); // This an integer division!
|
2016-01-05 16:39:18 -05:00
|
|
|
|
} else {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
scale = (float)((int)output_h / (int)logical_h); // This an integer division!
|
2016-01-05 16:39:18 -05:00
|
|
|
|
}
|
2021-11-21 17:40:48 +01:00
|
|
|
|
|
|
|
|
|
|
if (scale < 1.0f) {
|
|
|
|
|
|
scale = 1.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->logical_dst_rect.w = SDL_floorf(logical_w * scale);
|
|
|
|
|
|
renderer->logical_dst_rect.x = (output_w - renderer->logical_dst_rect.w) / 2.0f;
|
|
|
|
|
|
renderer->logical_dst_rect.h = SDL_floorf(logical_h * scale);
|
|
|
|
|
|
renderer->logical_dst_rect.y = (output_h - renderer->logical_dst_rect.h) / 2.0f;
|
|
|
|
|
|
|
2023-05-16 16:29:52 -07:00
|
|
|
|
} else if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_STRETCH ||
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_fabsf(want_aspect - real_aspect) < 0.0001f) {
|
|
|
|
|
|
renderer->logical_dst_rect.x = 0.0f;
|
|
|
|
|
|
renderer->logical_dst_rect.y = 0.0f;
|
2024-06-12 09:21:02 -07:00
|
|
|
|
renderer->logical_dst_rect.w = output_w;
|
|
|
|
|
|
renderer->logical_dst_rect.h = output_h;
|
2022-06-27 14:45:14 +02:00
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
} else if (want_aspect > real_aspect) {
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// We want a wider aspect ratio than is available - letterbox it
|
2024-06-12 09:21:02 -07:00
|
|
|
|
scale = output_w / logical_w;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->logical_dst_rect.x = 0.0f;
|
2024-06-12 09:21:02 -07:00
|
|
|
|
renderer->logical_dst_rect.w = output_w;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->logical_dst_rect.h = SDL_floorf(logical_h * scale);
|
|
|
|
|
|
renderer->logical_dst_rect.y = (output_h - renderer->logical_dst_rect.h) / 2.0f;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
} else { // renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_OVERSCAN
|
2022-11-30 12:51:59 -08:00
|
|
|
|
/* We want a wider aspect ratio than is available -
|
2023-02-03 12:25:46 -08:00
|
|
|
|
zoom so logical height matches the real height
|
|
|
|
|
|
and the width will grow off the screen
|
Adds support to control the scaling policy/mode of SDL_RenderSetLogicalSize for both letterbox (current behavior) and a new overscan mode (expand to fill the entire screen, even if some parts draw off the screen).
The expected use case is for games that are designed with multiple aspect ratios already in mind and leave optional margins on the edges of the game which won't hurt if they are cut off.
An example use case is a game is designed for wide-screen/16:9, but then wants to deploy on an iPad which is 4:3. Normally, SDL will letterbox, which will shrink things and result in wasted space. But the designer already thought about 4:3 and designed the edges of the game so they could be cut off without any functional loss. So rather than wasting space with letterboxing, "overscan" mode will zoom the rendering to fill up the entire screen. Parts on the edges will be drawn offscreen, but since the game was already designed with this in mind, it is fine. The end result is the iPad (4:3) experience is much better since it feels like a game designed for that screen aspect ratio.
This patch introduces a new SDL_hint: SDL_HINT_RENDER_LOGICAL_SIZE_MODE.
Valid values are "letterbox" or "0" for letterboxing and "overscan" or "1" for overscan.
The default mode is letterbox to preserve existing behavior.
// Example usage:
SDL_SetHint(SDL_HINT_RENDER_LOGICAL_SIZE_MODE, "overscan");
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
2014-12-03 04:41:26 -08:00
|
|
|
|
*/
|
2024-06-12 09:21:02 -07:00
|
|
|
|
scale = output_h / logical_h;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->logical_dst_rect.y = 0.0f;
|
2024-06-12 09:21:02 -07:00
|
|
|
|
renderer->logical_dst_rect.h = output_h;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->logical_dst_rect.w = SDL_floorf(logical_w * scale);
|
|
|
|
|
|
renderer->logical_dst_rect.x = (output_w - renderer->logical_dst_rect.w) / 2.0f;
|
Adds support to control the scaling policy/mode of SDL_RenderSetLogicalSize for both letterbox (current behavior) and a new overscan mode (expand to fill the entire screen, even if some parts draw off the screen).
The expected use case is for games that are designed with multiple aspect ratios already in mind and leave optional margins on the edges of the game which won't hurt if they are cut off.
An example use case is a game is designed for wide-screen/16:9, but then wants to deploy on an iPad which is 4:3. Normally, SDL will letterbox, which will shrink things and result in wasted space. But the designer already thought about 4:3 and designed the edges of the game so they could be cut off without any functional loss. So rather than wasting space with letterboxing, "overscan" mode will zoom the rendering to fill up the entire screen. Parts on the edges will be drawn offscreen, but since the game was already designed with this in mind, it is fine. The end result is the iPad (4:3) experience is much better since it feels like a game designed for that screen aspect ratio.
This patch introduces a new SDL_hint: SDL_HINT_RENDER_LOGICAL_SIZE_MODE.
Valid values are "letterbox" or "0" for letterboxing and "overscan" or "1" for overscan.
The default mode is letterbox to preserve existing behavior.
// Example usage:
SDL_SetHint(SDL_HINT_RENDER_LOGICAL_SIZE_MODE, "overscan");
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
2014-12-03 04:41:26 -08:00
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
} else {
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// We want a narrower aspect ratio than is available - use side-bars
|
2024-06-12 09:21:02 -07:00
|
|
|
|
scale = output_h / logical_h;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->logical_dst_rect.y = 0.0f;
|
2024-06-12 09:21:02 -07:00
|
|
|
|
renderer->logical_dst_rect.h = output_h;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->logical_dst_rect.w = SDL_floorf(logical_w * scale);
|
|
|
|
|
|
renderer->logical_dst_rect.x = (output_w - renderer->logical_dst_rect.w) / 2.0f;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
} else { // renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_OVERSCAN
|
Adds support to control the scaling policy/mode of SDL_RenderSetLogicalSize for both letterbox (current behavior) and a new overscan mode (expand to fill the entire screen, even if some parts draw off the screen).
The expected use case is for games that are designed with multiple aspect ratios already in mind and leave optional margins on the edges of the game which won't hurt if they are cut off.
An example use case is a game is designed for wide-screen/16:9, but then wants to deploy on an iPad which is 4:3. Normally, SDL will letterbox, which will shrink things and result in wasted space. But the designer already thought about 4:3 and designed the edges of the game so they could be cut off without any functional loss. So rather than wasting space with letterboxing, "overscan" mode will zoom the rendering to fill up the entire screen. Parts on the edges will be drawn offscreen, but since the game was already designed with this in mind, it is fine. The end result is the iPad (4:3) experience is much better since it feels like a game designed for that screen aspect ratio.
This patch introduces a new SDL_hint: SDL_HINT_RENDER_LOGICAL_SIZE_MODE.
Valid values are "letterbox" or "0" for letterboxing and "overscan" or "1" for overscan.
The default mode is letterbox to preserve existing behavior.
// Example usage:
SDL_SetHint(SDL_HINT_RENDER_LOGICAL_SIZE_MODE, "overscan");
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
2014-12-03 04:41:26 -08:00
|
|
|
|
/* We want a narrower aspect ratio than is available -
|
2023-02-03 12:25:46 -08:00
|
|
|
|
zoom so logical width matches the real width
|
|
|
|
|
|
and the height will grow off the screen
|
Adds support to control the scaling policy/mode of SDL_RenderSetLogicalSize for both letterbox (current behavior) and a new overscan mode (expand to fill the entire screen, even if some parts draw off the screen).
The expected use case is for games that are designed with multiple aspect ratios already in mind and leave optional margins on the edges of the game which won't hurt if they are cut off.
An example use case is a game is designed for wide-screen/16:9, but then wants to deploy on an iPad which is 4:3. Normally, SDL will letterbox, which will shrink things and result in wasted space. But the designer already thought about 4:3 and designed the edges of the game so they could be cut off without any functional loss. So rather than wasting space with letterboxing, "overscan" mode will zoom the rendering to fill up the entire screen. Parts on the edges will be drawn offscreen, but since the game was already designed with this in mind, it is fine. The end result is the iPad (4:3) experience is much better since it feels like a game designed for that screen aspect ratio.
This patch introduces a new SDL_hint: SDL_HINT_RENDER_LOGICAL_SIZE_MODE.
Valid values are "letterbox" or "0" for letterboxing and "overscan" or "1" for overscan.
The default mode is letterbox to preserve existing behavior.
// Example usage:
SDL_SetHint(SDL_HINT_RENDER_LOGICAL_SIZE_MODE, "overscan");
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
2014-12-03 04:41:26 -08:00
|
|
|
|
*/
|
2024-06-12 09:21:02 -07:00
|
|
|
|
scale = output_w / logical_w;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->logical_dst_rect.x = 0.0f;
|
2024-06-12 09:21:02 -07:00
|
|
|
|
renderer->logical_dst_rect.w = output_w;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->logical_dst_rect.h = SDL_floorf(logical_h * scale);
|
|
|
|
|
|
renderer->logical_dst_rect.y = (output_h - renderer->logical_dst_rect.h) / 2.0f;
|
Adds support to control the scaling policy/mode of SDL_RenderSetLogicalSize for both letterbox (current behavior) and a new overscan mode (expand to fill the entire screen, even if some parts draw off the screen).
The expected use case is for games that are designed with multiple aspect ratios already in mind and leave optional margins on the edges of the game which won't hurt if they are cut off.
An example use case is a game is designed for wide-screen/16:9, but then wants to deploy on an iPad which is 4:3. Normally, SDL will letterbox, which will shrink things and result in wasted space. But the designer already thought about 4:3 and designed the edges of the game so they could be cut off without any functional loss. So rather than wasting space with letterboxing, "overscan" mode will zoom the rendering to fill up the entire screen. Parts on the edges will be drawn offscreen, but since the game was already designed with this in mind, it is fine. The end result is the iPad (4:3) experience is much better since it feels like a game designed for that screen aspect ratio.
This patch introduces a new SDL_hint: SDL_HINT_RENDER_LOGICAL_SIZE_MODE.
Valid values are "letterbox" or "0" for letterboxing and "overscan" or "1" for overscan.
The default mode is letterbox to preserve existing behavior.
// Example usage:
SDL_SetHint(SDL_HINT_RENDER_LOGICAL_SIZE_MODE, "overscan");
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
2014-12-03 04:41:26 -08:00
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_SetTextureScaleMode(renderer->logical_target, renderer->logical_scale_mode);
|
2022-06-27 14:45:14 +02:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (!renderer->target) {
|
|
|
|
|
|
SDL_SetRenderTarget(renderer, renderer->logical_target);
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
return 0;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
|
|
|
|
|
|
error:
|
2024-06-12 19:08:06 -07:00
|
|
|
|
SDL_SetRenderLogicalPresentation(renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_SCALEMODE_NEAREST);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
return -1;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 19:08:06 -07:00
|
|
|
|
int SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (mode == SDL_LOGICAL_PRESENTATION_DISABLED) {
|
|
|
|
|
|
if (renderer->logical_target) {
|
|
|
|
|
|
SDL_DestroyTexture(renderer->logical_target);
|
|
|
|
|
|
}
|
2023-05-16 16:29:52 -07:00
|
|
|
|
} else {
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_target) {
|
2024-06-12 19:08:06 -07:00
|
|
|
|
SDL_PropertiesID props = SDL_GetTextureProperties(renderer->logical_target);
|
|
|
|
|
|
if (!props) {
|
2023-02-03 12:25:46 -08:00
|
|
|
|
goto error;
|
|
|
|
|
|
}
|
2024-06-12 19:08:06 -07:00
|
|
|
|
|
|
|
|
|
|
int existing_w = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, 0);
|
|
|
|
|
|
int existing_h = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, 0);
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (w != existing_w || h != existing_h) {
|
|
|
|
|
|
SDL_DestroyTexture(renderer->logical_target);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!renderer->logical_target) {
|
2024-06-12 19:08:06 -07:00
|
|
|
|
renderer->logical_target = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_UNKNOWN, SDL_TEXTUREACCESS_TARGET, w, h);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (!renderer->logical_target) {
|
|
|
|
|
|
goto error;
|
|
|
|
|
|
}
|
|
|
|
|
|
SDL_SetTextureBlendMode(renderer->logical_target, SDL_BLENDMODE_NONE);
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->logical_presentation_mode = mode;
|
|
|
|
|
|
renderer->logical_scale_mode = scale_mode;
|
|
|
|
|
|
|
|
|
|
|
|
return UpdateLogicalPresentation(renderer);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
error:
|
2024-06-12 19:08:06 -07:00
|
|
|
|
SDL_SetRenderLogicalPresentation(renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_SCALEMODE_NEAREST);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
return -1;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 19:08:06 -07:00
|
|
|
|
int SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-06-12 19:08:06 -07:00
|
|
|
|
if (w) {
|
|
|
|
|
|
*w = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (h) {
|
|
|
|
|
|
*h = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (mode) {
|
|
|
|
|
|
*mode = SDL_LOGICAL_PRESENTATION_DISABLED;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (scale_mode) {
|
|
|
|
|
|
*scale_mode = SDL_SCALEMODE_NEAREST;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_target) {
|
2024-06-12 19:08:06 -07:00
|
|
|
|
SDL_PropertiesID props = SDL_GetTextureProperties(renderer->logical_target);
|
|
|
|
|
|
if (!props) {
|
2023-02-03 12:25:46 -08:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2024-06-12 19:08:06 -07:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (w) {
|
2024-06-12 19:08:06 -07:00
|
|
|
|
*w = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, 0);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
}
|
|
|
|
|
|
if (h) {
|
2024-06-12 19:08:06 -07:00
|
|
|
|
*h = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, 0);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2023-02-03 12:25:46 -08:00
|
|
|
|
|
|
|
|
|
|
if (mode) {
|
|
|
|
|
|
*mode = renderer->logical_presentation_mode;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (scale_mode) {
|
|
|
|
|
|
*scale_mode = renderer->logical_scale_mode;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2024-06-12 19:08:06 -07:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
return 0;
|
2024-06-29 14:12:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SDL_GetRenderLogicalPresentationRect(SDL_Renderer *renderer, SDL_FRect *rect)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (rect) {
|
|
|
|
|
|
SDL_zerop(rect);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (rect) {
|
|
|
|
|
|
if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED) {
|
|
|
|
|
|
int output_w = 0, output_h = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (SDL_GetRenderOutputSize(renderer, &output_w, &output_h) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rect->x = 0.0f;
|
|
|
|
|
|
rect->y = 0.0f;
|
|
|
|
|
|
rect->w = (float)output_w;
|
|
|
|
|
|
rect->h = (float)output_h;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
SDL_copyp(rect, &renderer->logical_dst_rect);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-03 18:29:48 -07:00
|
|
|
|
static void SDL_RenderLogicalBorders(SDL_Renderer *renderer)
|
|
|
|
|
|
{
|
|
|
|
|
|
const SDL_FRect *dst = &renderer->logical_dst_rect;
|
|
|
|
|
|
|
|
|
|
|
|
if (dst->x > 0.0f || dst->y > 0.0f) {
|
|
|
|
|
|
SDL_BlendMode saved_blend_mode = renderer->blendMode;
|
2024-01-29 13:28:33 -08:00
|
|
|
|
SDL_FColor saved_color = renderer->color;
|
2023-07-03 18:29:48 -07:00
|
|
|
|
|
|
|
|
|
|
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
|
2024-01-31 10:25:50 -08:00
|
|
|
|
SDL_SetRenderDrawColorFloat(renderer, 0.0f, 0.0f, 0.0f, 1.0f);
|
2023-07-03 18:29:48 -07:00
|
|
|
|
|
|
|
|
|
|
if (dst->x > 0.0f) {
|
|
|
|
|
|
SDL_FRect rect;
|
|
|
|
|
|
|
|
|
|
|
|
rect.x = 0.0f;
|
|
|
|
|
|
rect.y = 0.0f;
|
|
|
|
|
|
rect.w = dst->x;
|
2024-06-12 19:08:06 -07:00
|
|
|
|
rect.h = (float)renderer->view->pixel_h;
|
2023-07-03 18:29:48 -07:00
|
|
|
|
SDL_RenderFillRect(renderer, &rect);
|
|
|
|
|
|
|
|
|
|
|
|
rect.x = dst->x + dst->w;
|
2024-06-12 19:08:06 -07:00
|
|
|
|
rect.w = (float)renderer->view->pixel_w - rect.x;
|
2023-07-03 18:29:48 -07:00
|
|
|
|
SDL_RenderFillRect(renderer, &rect);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (dst->y > 0.0f) {
|
|
|
|
|
|
SDL_FRect rect;
|
|
|
|
|
|
|
|
|
|
|
|
rect.x = 0.0f;
|
|
|
|
|
|
rect.y = 0.0f;
|
2024-06-12 19:08:06 -07:00
|
|
|
|
rect.w = (float)renderer->view->pixel_w;
|
2023-07-03 18:29:48 -07:00
|
|
|
|
rect.h = dst->y;
|
|
|
|
|
|
SDL_RenderFillRect(renderer, &rect);
|
|
|
|
|
|
|
|
|
|
|
|
rect.y = dst->y + dst->h;
|
2024-06-12 19:08:06 -07:00
|
|
|
|
rect.h = (float)renderer->view->pixel_h - rect.y;
|
2023-07-03 18:29:48 -07:00
|
|
|
|
SDL_RenderFillRect(renderer, &rect);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SDL_SetRenderDrawBlendMode(renderer, saved_blend_mode);
|
2024-01-31 10:25:50 -08:00
|
|
|
|
SDL_SetRenderDrawColorFloat(renderer, saved_color.r, saved_color.g, saved_color.b, saved_color.a);
|
2023-07-03 18:29:48 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void SDL_RenderLogicalPresentation(SDL_Renderer *renderer)
|
|
|
|
|
|
{
|
2023-11-11 10:28:24 +01:00
|
|
|
|
SDL_assert(renderer->target == NULL);
|
2023-07-03 18:29:48 -07:00
|
|
|
|
SDL_SetRenderViewport(renderer, NULL);
|
|
|
|
|
|
SDL_SetRenderClipRect(renderer, NULL);
|
|
|
|
|
|
SDL_SetRenderScale(renderer, 1.0f, 1.0f);
|
|
|
|
|
|
SDL_RenderLogicalBorders(renderer);
|
|
|
|
|
|
SDL_RenderTexture(renderer, renderer->logical_target, &renderer->logical_src_rect, &renderer->logical_dst_rect);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
int SDL_RenderCoordinatesFromWindow(SDL_Renderer *renderer, float window_x, float window_y, float *x, float *y)
|
2016-01-05 16:39:18 -05:00
|
|
|
|
{
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_RenderViewState *view;
|
|
|
|
|
|
float render_x, render_y;
|
|
|
|
|
|
|
2016-01-05 16:39:18 -05:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Convert from window coordinates to pixels within the window
|
2023-02-03 12:25:46 -08:00
|
|
|
|
render_x = window_x * renderer->dpi_scale.x;
|
|
|
|
|
|
render_y = window_y * renderer->dpi_scale.y;
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Convert from pixels within the window to pixels within the view
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_target) {
|
2023-03-02 08:56:54 -08:00
|
|
|
|
const SDL_FRect *src = &renderer->logical_src_rect;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
const SDL_FRect *dst = &renderer->logical_dst_rect;
|
|
|
|
|
|
render_x = ((render_x - dst->x) * src->w) / dst->w;
|
|
|
|
|
|
render_y = ((render_y - dst->y) * src->h) / dst->h;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Convert from pixels within the view to render coordinates
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_target) {
|
|
|
|
|
|
view = &renderer->logical_target->view;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
view = &renderer->main_view;
|
|
|
|
|
|
}
|
|
|
|
|
|
render_x = (render_x / view->scale.x) - view->viewport.x;
|
|
|
|
|
|
render_y = (render_y / view->scale.y) - view->viewport.y;
|
2016-01-05 16:39:18 -05:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (x) {
|
|
|
|
|
|
*x = render_x;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (y) {
|
|
|
|
|
|
*y = render_y;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
2016-01-05 16:39:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
int SDL_RenderCoordinatesToWindow(SDL_Renderer *renderer, float x, float y, float *window_x, float *window_y)
|
2016-01-05 16:39:18 -05:00
|
|
|
|
{
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_RenderViewState *view;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Convert from render coordinates to pixels within the view
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_target) {
|
|
|
|
|
|
view = &renderer->logical_target->view;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
view = &renderer->main_view;
|
|
|
|
|
|
}
|
|
|
|
|
|
x = (view->viewport.x + x) * view->scale.x;
|
|
|
|
|
|
y = (view->viewport.y + y) * view->scale.y;
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Convert from pixels within the view to pixels within the window
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_target) {
|
2023-03-02 08:56:54 -08:00
|
|
|
|
const SDL_FRect *src = &renderer->logical_src_rect;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
const SDL_FRect *dst = &renderer->logical_dst_rect;
|
|
|
|
|
|
x = dst->x + ((x * dst->w) / src->w);
|
|
|
|
|
|
y = dst->y + ((y * dst->h) / src->h);
|
|
|
|
|
|
}
|
2016-01-05 16:39:18 -05:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Convert from pixels within the window to window coordinates
|
2023-02-03 12:25:46 -08:00
|
|
|
|
x /= renderer->dpi_scale.x;
|
|
|
|
|
|
y /= renderer->dpi_scale.y;
|
|
|
|
|
|
|
|
|
|
|
|
if (window_x) {
|
|
|
|
|
|
*window_x = x;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (window_y) {
|
|
|
|
|
|
*window_y = y;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (event->type == SDL_EVENT_MOUSE_MOTION) {
|
|
|
|
|
|
SDL_Window *window = SDL_GetWindowFromID(event->motion.windowID);
|
|
|
|
|
|
if (window == renderer->window) {
|
|
|
|
|
|
SDL_RenderCoordinatesFromWindow(renderer, event->motion.x, event->motion.y, &event->motion.x, &event->motion.y);
|
|
|
|
|
|
|
|
|
|
|
|
if (event->motion.xrel != 0.0f) {
|
|
|
|
|
|
SDL_RenderViewState *view;
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Convert from window coordinates to pixels within the window
|
2023-02-03 12:25:46 -08:00
|
|
|
|
float scale = renderer->dpi_scale.x;
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Convert from pixels within the window to pixels within the view
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_target) {
|
2023-03-02 08:56:54 -08:00
|
|
|
|
const SDL_FRect *src = &renderer->logical_src_rect;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
const SDL_FRect *dst = &renderer->logical_dst_rect;
|
|
|
|
|
|
scale = (scale * src->w) / dst->w;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Convert from pixels within the view to render coordinates
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_target) {
|
|
|
|
|
|
view = &renderer->logical_target->view;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
view = &renderer->main_view;
|
|
|
|
|
|
}
|
|
|
|
|
|
scale = (scale / view->scale.x);
|
|
|
|
|
|
|
|
|
|
|
|
event->motion.xrel *= scale;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (event->motion.yrel != 0.0f) {
|
|
|
|
|
|
SDL_RenderViewState *view;
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Convert from window coordinates to pixels within the window
|
2023-02-03 12:25:46 -08:00
|
|
|
|
float scale = renderer->dpi_scale.y;
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Convert from pixels within the window to pixels within the view
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_target) {
|
2023-03-02 08:56:54 -08:00
|
|
|
|
const SDL_FRect *src = &renderer->logical_src_rect;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
const SDL_FRect *dst = &renderer->logical_dst_rect;
|
|
|
|
|
|
scale = (scale * src->h) / dst->h;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Convert from pixels within the view to render coordinates
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_target) {
|
|
|
|
|
|
view = &renderer->logical_target->view;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
view = &renderer->main_view;
|
|
|
|
|
|
}
|
|
|
|
|
|
scale = (scale / view->scale.y);
|
|
|
|
|
|
|
|
|
|
|
|
event->motion.yrel *= scale;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN ||
|
|
|
|
|
|
event->type == SDL_EVENT_MOUSE_BUTTON_UP) {
|
|
|
|
|
|
SDL_Window *window = SDL_GetWindowFromID(event->button.windowID);
|
|
|
|
|
|
if (window == renderer->window) {
|
|
|
|
|
|
SDL_RenderCoordinatesFromWindow(renderer, event->button.x, event->button.y, &event->button.x, &event->button.y);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (event->type == SDL_EVENT_MOUSE_WHEEL) {
|
|
|
|
|
|
SDL_Window *window = SDL_GetWindowFromID(event->wheel.windowID);
|
|
|
|
|
|
if (window == renderer->window) {
|
2024-02-11 08:03:26 -08:00
|
|
|
|
SDL_RenderCoordinatesFromWindow(renderer, event->wheel.mouse_x,
|
|
|
|
|
|
event->wheel.mouse_y,
|
|
|
|
|
|
&event->wheel.mouse_x,
|
|
|
|
|
|
&event->wheel.mouse_y);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
}
|
|
|
|
|
|
} else if (event->type == SDL_EVENT_FINGER_DOWN ||
|
|
|
|
|
|
event->type == SDL_EVENT_FINGER_UP ||
|
|
|
|
|
|
event->type == SDL_EVENT_FINGER_MOTION) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// FIXME: Are these events guaranteed to be window relative?
|
2023-05-16 16:29:52 -07:00
|
|
|
|
if (renderer->window) {
|
|
|
|
|
|
int w, h;
|
|
|
|
|
|
if (SDL_GetWindowSize(renderer->window, &w, &h) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
SDL_RenderCoordinatesFromWindow(renderer, event->tfinger.x * w, event->tfinger.y * h, &event->tfinger.x, &event->tfinger.y);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
}
|
2024-01-16 12:00:36 -08:00
|
|
|
|
} else if (event->type == SDL_EVENT_DROP_POSITION ||
|
|
|
|
|
|
event->type == SDL_EVENT_DROP_FILE ||
|
|
|
|
|
|
event->type == SDL_EVENT_DROP_TEXT ||
|
|
|
|
|
|
event->type == SDL_EVENT_DROP_COMPLETE) {
|
|
|
|
|
|
SDL_Window *window = SDL_GetWindowFromID(event->drop.windowID);
|
|
|
|
|
|
if (window == renderer->window) {
|
2024-01-16 14:07:42 -08:00
|
|
|
|
SDL_RenderCoordinatesFromWindow(renderer, event->drop.x, event->drop.y, &event->drop.x, &event->drop.y);
|
2024-01-16 12:00:36 -08:00
|
|
|
|
}
|
2023-02-03 12:25:46 -08:00
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
2016-01-05 16:39:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 19:08:06 -07:00
|
|
|
|
int SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (rect) {
|
2024-06-12 09:21:02 -07:00
|
|
|
|
SDL_copyp(&renderer->view->viewport, rect);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
} else {
|
2024-06-12 19:08:06 -07:00
|
|
|
|
renderer->view->viewport.x = 0;
|
|
|
|
|
|
renderer->view->viewport.y = 0;
|
|
|
|
|
|
renderer->view->viewport.w = -1;
|
|
|
|
|
|
renderer->view->viewport.h = -1;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2024-06-12 09:21:02 -07:00
|
|
|
|
UpdatePixelViewport(renderer, renderer->view);
|
|
|
|
|
|
|
2023-11-20 20:26:12 -05:00
|
|
|
|
return QueueCmdSetViewport(renderer);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 19:08:06 -07:00
|
|
|
|
int SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (rect) {
|
|
|
|
|
|
SDL_zerop(rect);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
if (rect) {
|
2023-02-03 12:25:46 -08:00
|
|
|
|
rect->x = renderer->view->viewport.x;
|
|
|
|
|
|
rect->y = renderer->view->viewport.y;
|
|
|
|
|
|
if (renderer->view->viewport.w >= 0) {
|
|
|
|
|
|
rect->w = renderer->view->viewport.w;
|
|
|
|
|
|
} else {
|
2024-06-12 19:08:06 -07:00
|
|
|
|
rect->w = (int)SDL_ceilf(renderer->view->pixel_w / renderer->view->scale.x);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
}
|
|
|
|
|
|
if (renderer->view->viewport.h >= 0) {
|
|
|
|
|
|
rect->h = renderer->view->viewport.h;
|
|
|
|
|
|
} else {
|
2024-06-12 19:08:06 -07:00
|
|
|
|
rect->h = (int)SDL_ceilf(renderer->view->pixel_h / renderer->view->scale.y);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2023-02-03 12:25:46 -08:00
|
|
|
|
return 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-09 16:37:04 -08:00
|
|
|
|
SDL_bool SDL_RenderViewportSet(SDL_Renderer *renderer)
|
|
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
2024-06-12 19:08:06 -07:00
|
|
|
|
if (renderer->view->viewport.w >= 0 &&
|
|
|
|
|
|
renderer->view->viewport.h >= 0) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
return true;
|
2024-06-12 09:21:02 -07:00
|
|
|
|
}
|
2024-08-22 09:21:26 -07:00
|
|
|
|
return false;
|
2024-02-09 16:37:04 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-27 15:05:51 -08:00
|
|
|
|
static void GetRenderViewportSize(SDL_Renderer *renderer, SDL_FRect *rect)
|
2021-01-02 16:12:30 +01:00
|
|
|
|
{
|
2021-01-02 17:29:34 +01:00
|
|
|
|
rect->x = 0.0f;
|
|
|
|
|
|
rect->y = 0.0f;
|
2024-06-12 19:08:06 -07:00
|
|
|
|
if (renderer->view->viewport.w >= 0) {
|
|
|
|
|
|
rect->w = (float)renderer->view->viewport.w;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
} else {
|
|
|
|
|
|
rect->w = renderer->view->pixel_w / renderer->view->scale.x;
|
|
|
|
|
|
}
|
2024-06-12 19:08:06 -07:00
|
|
|
|
if (renderer->view->viewport.h >= 0) {
|
|
|
|
|
|
rect->h = (float)renderer->view->viewport.h;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
} else {
|
|
|
|
|
|
rect->h = renderer->view->pixel_h / renderer->view->scale.y;
|
|
|
|
|
|
}
|
2021-01-02 16:12:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-24 17:14:00 -07:00
|
|
|
|
int SDL_GetRenderSafeArea(SDL_Renderer *renderer, SDL_Rect *rect)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (rect) {
|
|
|
|
|
|
SDL_zerop(rect);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (renderer->target || !renderer->window) {
|
|
|
|
|
|
// The entire viewport is safe for rendering
|
|
|
|
|
|
return SDL_GetRenderViewport(renderer, rect);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (rect) {
|
|
|
|
|
|
// Get the window safe rect
|
|
|
|
|
|
SDL_Rect safe;
|
|
|
|
|
|
if (SDL_GetWindowSafeArea(renderer->window, &safe) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Convert the coordinates into the render space
|
|
|
|
|
|
float minx = (float)safe.x;
|
|
|
|
|
|
float miny = (float)safe.y;
|
|
|
|
|
|
float maxx = (float)safe.x + safe.w;
|
|
|
|
|
|
float maxy = (float)safe.y + safe.h;
|
|
|
|
|
|
if (SDL_RenderCoordinatesFromWindow(renderer, minx, miny, &minx, &miny) < 0 ||
|
|
|
|
|
|
SDL_RenderCoordinatesFromWindow(renderer, maxx, maxy, &maxx, &maxy) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rect->x = (int)SDL_ceilf(minx);
|
|
|
|
|
|
rect->y = (int)SDL_ceilf(miny);
|
|
|
|
|
|
rect->w = (int)SDL_ceilf(maxx - minx);
|
|
|
|
|
|
rect->h = (int)SDL_ceilf(maxy - miny);
|
|
|
|
|
|
|
|
|
|
|
|
// Clip with the viewport
|
|
|
|
|
|
SDL_Rect viewport;
|
|
|
|
|
|
if (SDL_GetRenderViewport(renderer, &viewport) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!SDL_GetRectIntersection(rect, &viewport, rect)) {
|
|
|
|
|
|
return SDL_SetError("No safe area within viewport");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 19:08:06 -07:00
|
|
|
|
int SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1)
|
|
|
|
|
|
|
2023-09-09 14:36:21 +01:00
|
|
|
|
if (rect && rect->w >= 0 && rect->h >= 0) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->view->clipping_enabled = true;
|
2024-06-12 09:21:02 -07:00
|
|
|
|
SDL_copyp(&renderer->view->clip_rect, rect);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
} else {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->view->clipping_enabled = false;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_zero(renderer->view->clip_rect);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2024-06-12 09:21:02 -07:00
|
|
|
|
UpdatePixelClipRect(renderer, renderer->view);
|
2018-09-25 17:04:47 -04:00
|
|
|
|
|
2023-11-20 20:26:12 -05:00
|
|
|
|
return QueueCmdSetClipRect(renderer);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 19:08:06 -07:00
|
|
|
|
int SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_Rect *rect)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (rect) {
|
|
|
|
|
|
SDL_zerop(rect);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
if (rect) {
|
2024-06-12 09:21:02 -07:00
|
|
|
|
SDL_copyp(rect, &renderer->view->clip_rect);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2023-02-03 12:25:46 -08:00
|
|
|
|
return 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_bool SDL_RenderClipEnabled(SDL_Renderer *renderer)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-08-22 09:21:26 -07:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, false)
|
2023-02-03 12:25:46 -08:00
|
|
|
|
return renderer->view->clipping_enabled;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-27 06:21:13 -08:00
|
|
|
|
int SDL_SetRenderScale(SDL_Renderer *renderer, float scaleX, float scaleY)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2023-02-03 12:25:46 -08:00
|
|
|
|
int retval = 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->view->scale.x == scaleX &&
|
|
|
|
|
|
renderer->view->scale.y == scaleY) {
|
|
|
|
|
|
return 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2021-11-09 22:03:42 -07:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->view->scale.x = scaleX;
|
|
|
|
|
|
renderer->view->scale.y = scaleY;
|
2024-06-12 09:21:02 -07:00
|
|
|
|
UpdatePixelViewport(renderer, renderer->view);
|
|
|
|
|
|
UpdatePixelClipRect(renderer, renderer->view);
|
2021-11-09 22:03:42 -07:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// The scale affects the existing viewport and clip rectangle
|
2023-02-03 12:25:46 -08:00
|
|
|
|
retval += QueueCmdSetViewport(renderer);
|
|
|
|
|
|
retval += QueueCmdSetClipRect(renderer);
|
2023-11-20 20:26:12 -05:00
|
|
|
|
return retval;
|
2021-11-09 22:03:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
int SDL_GetRenderScale(SDL_Renderer *renderer, float *scaleX, float *scaleY)
|
2021-11-09 22:03:42 -07:00
|
|
|
|
{
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (scaleX) {
|
|
|
|
|
|
*scaleX = 1.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (scaleY) {
|
|
|
|
|
|
*scaleY = 1.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
2021-11-09 22:03:42 -07:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (scaleX) {
|
|
|
|
|
|
*scaleX = renderer->view->scale.x;
|
2021-11-09 22:03:42 -07:00
|
|
|
|
}
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (scaleY) {
|
|
|
|
|
|
*scaleY = renderer->view->scale.y;
|
2021-11-09 22:03:42 -07:00
|
|
|
|
}
|
2023-02-03 12:25:46 -08:00
|
|
|
|
return 0;
|
2021-11-09 22:03:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
int SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
2024-01-29 13:28:33 -08:00
|
|
|
|
{
|
|
|
|
|
|
const float fR = (float)r / 255.0f;
|
|
|
|
|
|
const float fG = (float)g / 255.0f;
|
|
|
|
|
|
const float fB = (float)b / 255.0f;
|
|
|
|
|
|
const float fA = (float)a / 255.0f;
|
|
|
|
|
|
|
|
|
|
|
|
return SDL_SetRenderDrawColorFloat(renderer, fR, fG, fB, fA);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SDL_SetRenderDrawColorFloat(SDL_Renderer *renderer, float r, float g, float b, float a)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
2021-10-24 17:16:49 +02:00
|
|
|
|
renderer->color.r = r;
|
|
|
|
|
|
renderer->color.g = g;
|
|
|
|
|
|
renderer->color.b = b;
|
|
|
|
|
|
renderer->color.a = a;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
int SDL_GetRenderDrawColor(SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
|
2024-01-29 13:28:33 -08:00
|
|
|
|
{
|
|
|
|
|
|
float fR, fG, fB, fA;
|
|
|
|
|
|
|
|
|
|
|
|
if (SDL_GetRenderDrawColorFloat(renderer, &fR, &fG, &fB, &fA) < 0) {
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (r) {
|
|
|
|
|
|
*r = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (g) {
|
|
|
|
|
|
*g = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (b) {
|
|
|
|
|
|
*b = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (a) {
|
|
|
|
|
|
*a = 0;
|
|
|
|
|
|
}
|
2024-01-29 13:28:33 -08:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (r) {
|
|
|
|
|
|
*r = (Uint8)(fR * 255.0f);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (g) {
|
|
|
|
|
|
*g = (Uint8)(fG * 255.0f);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (b) {
|
|
|
|
|
|
*b = (Uint8)(fB * 255.0f);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (a) {
|
|
|
|
|
|
*a = (Uint8)(fA * 255.0f);
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SDL_GetRenderDrawColorFloat(SDL_Renderer *renderer, float *r, float *g, float *b, float *a)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-01-29 18:32:27 -08:00
|
|
|
|
SDL_FColor color;
|
|
|
|
|
|
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (r) {
|
|
|
|
|
|
*r = 0.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (g) {
|
|
|
|
|
|
*g = 0.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (b) {
|
|
|
|
|
|
*b = 0.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (a) {
|
|
|
|
|
|
*a = 0.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
2024-01-29 18:32:27 -08:00
|
|
|
|
color = renderer->color;
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (r) {
|
2024-01-29 18:32:27 -08:00
|
|
|
|
*r = color.r;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
if (g) {
|
2024-01-29 18:32:27 -08:00
|
|
|
|
*g = color.g;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
if (b) {
|
2024-01-29 18:32:27 -08:00
|
|
|
|
*b = color.b;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
if (a) {
|
2024-01-29 18:32:27 -08:00
|
|
|
|
*a = color.a;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-05 23:20:43 -08:00
|
|
|
|
int SDL_SetRenderColorScale(SDL_Renderer *renderer, float scale)
|
|
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
2024-02-19 08:45:02 -08:00
|
|
|
|
renderer->color_scale = scale * renderer->SDR_white_point;
|
2024-02-05 23:20:43 -08:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-17 09:40:25 -07:00
|
|
|
|
int SDL_GetRenderColorScale(SDL_Renderer *renderer, float *scale)
|
2024-02-05 23:20:43 -08:00
|
|
|
|
{
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (scale) {
|
|
|
|
|
|
*scale = 1.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-17 09:40:25 -07:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
2024-02-05 23:20:43 -08:00
|
|
|
|
|
2024-07-17 09:40:25 -07:00
|
|
|
|
if (scale) {
|
|
|
|
|
|
*scale = renderer->color_scale / renderer->SDR_white_point;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
2024-02-05 23:20:43 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
int SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
2024-07-16 21:15:56 -07:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_INVALID) {
|
|
|
|
|
|
return SDL_InvalidParamError("blendMode");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_INVALID) {
|
|
|
|
|
|
return SDL_InvalidParamError("blendMode");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
if (!IsSupportedBlendMode(renderer, blendMode)) {
|
|
|
|
|
|
return SDL_Unsupported();
|
|
|
|
|
|
}
|
2024-07-17 10:10:31 -07:00
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
renderer->blendMode = blendMode;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-17 09:40:25 -07:00
|
|
|
|
int SDL_GetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode *blendMode)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (blendMode) {
|
|
|
|
|
|
*blendMode = SDL_BLENDMODE_INVALID;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-17 09:40:25 -07:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-07-21 14:32:19 -07:00
|
|
|
|
if (blendMode) {
|
|
|
|
|
|
*blendMode = renderer->blendMode;
|
|
|
|
|
|
}
|
2024-07-17 09:40:25 -07:00
|
|
|
|
return 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
int SDL_RenderClear(SDL_Renderer *renderer)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
2024-07-17 10:10:31 -07:00
|
|
|
|
|
|
|
|
|
|
return QueueCmdClear(renderer);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
int SDL_RenderPoint(SDL_Renderer *renderer, float x, float y)
|
2018-10-23 01:34:03 -04:00
|
|
|
|
{
|
2018-11-01 20:04:24 +03:00
|
|
|
|
SDL_FPoint fpoint;
|
|
|
|
|
|
fpoint.x = x;
|
|
|
|
|
|
fpoint.y = y;
|
2022-12-31 11:19:32 -08:00
|
|
|
|
return SDL_RenderPoints(renderer, &fpoint, 1);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
static int RenderPointsWithRects(SDL_Renderer *renderer, const SDL_FPoint *fpoints, const int count)
|
2018-10-23 01:34:03 -04:00
|
|
|
|
{
|
2022-04-29 22:36:12 +02:00
|
|
|
|
int retval;
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool isstack;
|
2022-04-29 22:36:12 +02:00
|
|
|
|
SDL_FRect *frects;
|
2018-10-23 01:34:03 -04:00
|
|
|
|
int i;
|
|
|
|
|
|
|
2022-04-29 22:36:12 +02:00
|
|
|
|
if (count < 1) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
frects = SDL_small_alloc(SDL_FRect, count, &isstack);
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!frects) {
|
error: SDL's allocators now call SDL_OutOfMemory on error.
This means the allocator's caller doesn't need to use SDL_OutOfMemory directly
if the allocation fails.
This applies to the usual allocators: SDL_malloc, SDL_calloc, SDL_realloc
(all of these regardless of if the app supplied a custom allocator or we're
using system malloc() or an internal copy of dlmalloc under the hood),
SDL_aligned_alloc, SDL_small_alloc, SDL_strdup, SDL_asprintf, SDL_wcsdup...
probably others. If it returns something you can pass to SDL_free, it should
work.
The caller might still need to use SDL_OutOfMemory if something that wasn't
SDL allocated the memory: operator new in C++ code, Objective-C's alloc
message, win32 GlobalAlloc, etc.
Fixes #8642.
2023-11-30 00:14:27 -05:00
|
|
|
|
return -1;
|
2018-10-23 01:34:03 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i) {
|
2023-02-03 12:25:46 -08:00
|
|
|
|
frects[i].x = fpoints[i].x * renderer->view->scale.x;
|
|
|
|
|
|
frects[i].y = fpoints[i].y * renderer->view->scale.y;
|
|
|
|
|
|
frects[i].w = renderer->view->scale.x;
|
|
|
|
|
|
frects[i].h = renderer->view->scale.y;
|
2018-10-23 01:34:03 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-04-29 22:36:12 +02:00
|
|
|
|
retval = QueueCmdFillRects(renderer, frects, count);
|
2018-10-23 01:34:03 -04:00
|
|
|
|
|
|
|
|
|
|
SDL_small_free(frects, isstack);
|
|
|
|
|
|
|
2022-01-08 09:23:58 -08:00
|
|
|
|
return retval;
|
2018-10-23 01:34:03 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
int SDL_RenderPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
|
2018-10-23 01:34:03 -04:00
|
|
|
|
{
|
|
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!points) {
|
2022-12-31 11:19:32 -08:00
|
|
|
|
return SDL_InvalidParamError("SDL_RenderPoints(): points");
|
2018-10-23 01:34:03 -04:00
|
|
|
|
}
|
|
|
|
|
|
if (count < 1) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-02 14:01:41 -04:00
|
|
|
|
#if DONT_DRAW_WHILE_HIDDEN
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Don't draw while we're hidden
|
2018-10-23 01:34:03 -04:00
|
|
|
|
if (renderer->hidden) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2021-04-02 14:01:41 -04:00
|
|
|
|
#endif
|
2018-10-23 01:34:03 -04:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->view->scale.x != 1.0f || renderer->view->scale.y != 1.0f) {
|
2022-12-31 11:19:32 -08:00
|
|
|
|
retval = RenderPointsWithRects(renderer, points, count);
|
2022-01-08 09:23:58 -08:00
|
|
|
|
} else {
|
2022-01-08 09:32:23 -08:00
|
|
|
|
retval = QueueCmdDrawPoints(renderer, points, count);
|
2022-01-08 09:23:58 -08:00
|
|
|
|
}
|
2023-11-20 20:26:12 -05:00
|
|
|
|
return retval;
|
2018-10-23 01:34:03 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
int SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y2)
|
2018-10-23 01:34:03 -04:00
|
|
|
|
{
|
2018-11-01 20:04:24 +03:00
|
|
|
|
SDL_FPoint points[2];
|
|
|
|
|
|
points[0].x = x1;
|
|
|
|
|
|
points[0].y = y1;
|
|
|
|
|
|
points[1].x = x2;
|
|
|
|
|
|
points[1].y = y2;
|
2022-12-31 11:19:32 -08:00
|
|
|
|
return SDL_RenderLines(renderer, points, 2);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
|
static int RenderLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x2, int y2, bool draw_last)
|
2022-01-08 10:59:31 -08:00
|
|
|
|
{
|
2024-06-12 19:08:06 -07:00
|
|
|
|
const int MAX_PIXELS = SDL_max(renderer->view->pixel_w, renderer->view->pixel_h) * 4;
|
2022-01-09 11:11:34 -08:00
|
|
|
|
int i, deltax, deltay, numpixels;
|
|
|
|
|
|
int d, dinc1, dinc2;
|
|
|
|
|
|
int x, xinc1, xinc2;
|
|
|
|
|
|
int y, yinc1, yinc2;
|
|
|
|
|
|
int retval;
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool isstack;
|
2022-01-09 11:11:34 -08:00
|
|
|
|
SDL_FPoint *points;
|
2023-11-25 01:51:35 -05:00
|
|
|
|
SDL_Rect viewport;
|
2023-11-24 19:31:30 -05:00
|
|
|
|
|
|
|
|
|
|
/* the backend might clip this further to the clipping rect, but we
|
|
|
|
|
|
just want a basic safety against generating millions of points for
|
|
|
|
|
|
massive lines. */
|
2024-06-12 09:21:02 -07:00
|
|
|
|
viewport = renderer->view->pixel_viewport;
|
2024-01-19 16:28:00 -08:00
|
|
|
|
viewport.x = 0;
|
|
|
|
|
|
viewport.y = 0;
|
2023-11-25 01:51:35 -05:00
|
|
|
|
if (!SDL_GetRectAndLineIntersection(&viewport, &x1, &y1, &x2, &y2)) {
|
2023-11-24 19:31:30 -05:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2022-01-09 11:11:34 -08:00
|
|
|
|
|
|
|
|
|
|
deltax = SDL_abs(x2 - x1);
|
|
|
|
|
|
deltay = SDL_abs(y2 - y1);
|
|
|
|
|
|
|
|
|
|
|
|
if (deltax >= deltay) {
|
|
|
|
|
|
numpixels = deltax + 1;
|
|
|
|
|
|
d = (2 * deltay) - deltax;
|
|
|
|
|
|
dinc1 = deltay * 2;
|
|
|
|
|
|
dinc2 = (deltay - deltax) * 2;
|
|
|
|
|
|
xinc1 = 1;
|
|
|
|
|
|
xinc2 = 1;
|
|
|
|
|
|
yinc1 = 0;
|
|
|
|
|
|
yinc2 = 1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
numpixels = deltay + 1;
|
|
|
|
|
|
d = (2 * deltax) - deltay;
|
|
|
|
|
|
dinc1 = deltax * 2;
|
|
|
|
|
|
dinc2 = (deltax - deltay) * 2;
|
|
|
|
|
|
xinc1 = 0;
|
|
|
|
|
|
xinc2 = 1;
|
|
|
|
|
|
yinc1 = 1;
|
|
|
|
|
|
yinc2 = 1;
|
2022-01-08 11:36:29 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-09 11:11:34 -08:00
|
|
|
|
if (x1 > x2) {
|
|
|
|
|
|
xinc1 = -xinc1;
|
|
|
|
|
|
xinc2 = -xinc2;
|
2022-01-08 10:59:31 -08:00
|
|
|
|
}
|
2022-01-09 11:11:34 -08:00
|
|
|
|
if (y1 > y2) {
|
|
|
|
|
|
yinc1 = -yinc1;
|
|
|
|
|
|
yinc2 = -yinc2;
|
2022-01-08 10:59:31 -08:00
|
|
|
|
}
|
2022-01-09 11:11:34 -08:00
|
|
|
|
|
|
|
|
|
|
x = x1;
|
|
|
|
|
|
y = y1;
|
2022-01-08 10:59:31 -08:00
|
|
|
|
|
2022-01-08 12:28:43 -08:00
|
|
|
|
if (!draw_last) {
|
2022-01-09 11:11:34 -08:00
|
|
|
|
--numpixels;
|
2022-01-08 12:02:08 -08:00
|
|
|
|
}
|
2022-01-08 10:59:31 -08:00
|
|
|
|
|
2023-02-03 15:45:43 -08:00
|
|
|
|
if (numpixels > MAX_PIXELS) {
|
|
|
|
|
|
return SDL_SetError("Line too long (tried to draw %d pixels, max %d)", numpixels, MAX_PIXELS);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-09 11:11:34 -08:00
|
|
|
|
points = SDL_small_alloc(SDL_FPoint, numpixels, &isstack);
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!points) {
|
error: SDL's allocators now call SDL_OutOfMemory on error.
This means the allocator's caller doesn't need to use SDL_OutOfMemory directly
if the allocation fails.
This applies to the usual allocators: SDL_malloc, SDL_calloc, SDL_realloc
(all of these regardless of if the app supplied a custom allocator or we're
using system malloc() or an internal copy of dlmalloc under the hood),
SDL_aligned_alloc, SDL_small_alloc, SDL_strdup, SDL_asprintf, SDL_wcsdup...
probably others. If it returns something you can pass to SDL_free, it should
work.
The caller might still need to use SDL_OutOfMemory if something that wasn't
SDL allocated the memory: operator new in C++ code, Objective-C's alloc
message, win32 GlobalAlloc, etc.
Fixes #8642.
2023-11-30 00:14:27 -05:00
|
|
|
|
return -1;
|
2022-01-08 11:36:29 -08:00
|
|
|
|
}
|
2022-01-09 11:11:34 -08:00
|
|
|
|
for (i = 0; i < numpixels; ++i) {
|
|
|
|
|
|
points[i].x = (float)x;
|
|
|
|
|
|
points[i].y = (float)y;
|
2022-01-08 11:36:29 -08:00
|
|
|
|
|
2022-01-09 11:11:34 -08:00
|
|
|
|
if (d < 0) {
|
|
|
|
|
|
d += dinc1;
|
|
|
|
|
|
x += xinc1;
|
|
|
|
|
|
y += yinc1;
|
2022-01-08 10:59:31 -08:00
|
|
|
|
} else {
|
2022-01-09 11:11:34 -08:00
|
|
|
|
d += dinc2;
|
|
|
|
|
|
x += xinc2;
|
|
|
|
|
|
y += yinc2;
|
2022-01-08 10:59:31 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->view->scale.x != 1.0f || renderer->view->scale.y != 1.0f) {
|
2022-12-31 11:19:32 -08:00
|
|
|
|
retval = RenderPointsWithRects(renderer, points, numpixels);
|
2022-01-08 10:59:31 -08:00
|
|
|
|
} else {
|
2022-01-09 11:11:34 -08:00
|
|
|
|
retval = QueueCmdDrawPoints(renderer, points, numpixels);
|
2022-01-08 10:59:31 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SDL_small_free(points, isstack);
|
|
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-27 15:05:51 -08:00
|
|
|
|
static int RenderLinesWithRectsF(SDL_Renderer *renderer,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const SDL_FPoint *points, const int count)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2023-02-03 12:25:46 -08:00
|
|
|
|
const float scale_x = renderer->view->scale.x;
|
|
|
|
|
|
const float scale_y = renderer->view->scale.y;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
SDL_FRect *frect;
|
|
|
|
|
|
SDL_FRect *frects;
|
2018-09-20 15:46:02 -04:00
|
|
|
|
int i, nrects = 0;
|
2018-09-25 17:04:47 -04:00
|
|
|
|
int retval = 0;
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool isstack;
|
|
|
|
|
|
bool drew_line = false;
|
|
|
|
|
|
bool draw_last = false;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
frects = SDL_small_alloc(SDL_FRect, count - 1, &isstack);
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!frects) {
|
error: SDL's allocators now call SDL_OutOfMemory on error.
This means the allocator's caller doesn't need to use SDL_OutOfMemory directly
if the allocation fails.
This applies to the usual allocators: SDL_malloc, SDL_calloc, SDL_realloc
(all of these regardless of if the app supplied a custom allocator or we're
using system malloc() or an internal copy of dlmalloc under the hood),
SDL_aligned_alloc, SDL_small_alloc, SDL_strdup, SDL_asprintf, SDL_wcsdup...
probably others. If it returns something you can pass to SDL_free, it should
work.
The caller might still need to use SDL_OutOfMemory if something that wasn't
SDL allocated the memory: operator new in C++ code, Objective-C's alloc
message, win32 GlobalAlloc, etc.
Fixes #8642.
2023-11-30 00:14:27 -05:00
|
|
|
|
return -1;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
for (i = 0; i < count - 1; ++i) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool same_x = (points[i].x == points[i + 1].x);
|
|
|
|
|
|
bool same_y = (points[i].y == points[i + 1].y);
|
2022-01-09 06:36:18 -08:00
|
|
|
|
|
|
|
|
|
|
if (i == (count - 2)) {
|
2022-11-30 12:51:59 -08:00
|
|
|
|
if (!drew_line || points[i + 1].x != points[0].x || points[i + 1].y != points[0].y) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
draw_last = true;
|
2022-01-08 12:02:08 -08:00
|
|
|
|
}
|
2022-01-09 06:36:18 -08:00
|
|
|
|
} else {
|
|
|
|
|
|
if (same_x && same_y) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2022-01-08 12:02:08 -08:00
|
|
|
|
}
|
2022-01-09 06:36:18 -08:00
|
|
|
|
if (same_x) {
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const float minY = SDL_min(points[i].y, points[i + 1].y);
|
|
|
|
|
|
const float maxY = SDL_max(points[i].y, points[i + 1].y);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
frect = &frects[nrects++];
|
2022-01-08 12:02:08 -08:00
|
|
|
|
frect->x = points[i].x * scale_x;
|
|
|
|
|
|
frect->y = minY * scale_y;
|
|
|
|
|
|
frect->w = scale_x;
|
|
|
|
|
|
frect->h = (maxY - minY + draw_last) * scale_y;
|
2022-11-30 12:51:59 -08:00
|
|
|
|
if (!draw_last && points[i + 1].y < points[i].y) {
|
2022-01-08 12:02:08 -08:00
|
|
|
|
frect->y += scale_y;
|
|
|
|
|
|
}
|
2022-01-09 06:36:18 -08:00
|
|
|
|
} else if (same_y) {
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const float minX = SDL_min(points[i].x, points[i + 1].x);
|
|
|
|
|
|
const float maxX = SDL_max(points[i].x, points[i + 1].x);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
frect = &frects[nrects++];
|
2022-01-08 12:02:08 -08:00
|
|
|
|
frect->x = minX * scale_x;
|
|
|
|
|
|
frect->y = points[i].y * scale_y;
|
|
|
|
|
|
frect->w = (maxX - minX + draw_last) * scale_x;
|
|
|
|
|
|
frect->h = scale_y;
|
2022-11-30 12:51:59 -08:00
|
|
|
|
if (!draw_last && points[i + 1].x < points[i].x) {
|
2022-01-08 12:02:08 -08:00
|
|
|
|
frect->x += scale_x;
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
} else {
|
2022-12-27 15:05:51 -08:00
|
|
|
|
retval += RenderLineBresenham(renderer, (int)SDL_roundf(points[i].x), (int)SDL_roundf(points[i].y),
|
2022-11-30 12:51:59 -08:00
|
|
|
|
(int)SDL_roundf(points[i + 1].x), (int)SDL_roundf(points[i + 1].y), draw_last);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2024-08-22 09:21:26 -07:00
|
|
|
|
drew_line = true;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
render: Fix -Wmaybe-uninitialized warning in RenderDrawLinesWithRects{,F}
The RenderDrawLinesWithRects and RenderDrawLinesWithRectsF functions can
sometimes call QueueCmdFillRects() with the data pointed to by frects
uninitialised. This can occur if none of the lines can be replaced with
rects, in which case the frects array is empty, and nrects is 0.
gcc 10.3.0 will detect this possibility, and print a warning like:
/home/david/Development/SDL/src/render/SDL_render.c: In function 'RenderDrawLinesWithRectsF':
/home/david/Development/SDL/src/render/SDL_render.c:2725:15: warning: '<unknown>' may be used uninitialized [-Wmaybe-uninitialized]
2725 | retval += QueueCmdFillRects(renderer, frects, nrects);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/david/Development/SDL/src/render/SDL_render.c:499:1: note: by argument 2 of type 'const SDL_FRect *' to 'QueueCmdFillRects' declared here
499 | QueueCmdFillRects(SDL_Renderer *renderer, const SDL_FRect * rects, const int count)
| ^~~~~~~~~~~~~~~~~
This is harmless, because when this is uninitialised, nrects is always
0, so QueueCmdFillRects() does nothing anyway. We therefore can work
around this by only calling QueueCmdFillRects() when nrects is nonzero.
Somewhat impressively, gcc recognises that this is now safe.
2021-07-30 22:31:17 +08:00
|
|
|
|
if (nrects) {
|
|
|
|
|
|
retval += QueueCmdFillRects(renderer, frects, nrects);
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2018-10-22 20:50:32 -04:00
|
|
|
|
SDL_small_free(frects, isstack);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2018-09-25 17:04:47 -04:00
|
|
|
|
if (retval < 0) {
|
|
|
|
|
|
retval = -1;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2022-01-08 09:23:58 -08:00
|
|
|
|
return retval;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
int SDL_RenderLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
|
2018-10-23 01:34:03 -04:00
|
|
|
|
{
|
2022-01-07 22:14:28 +01:00
|
|
|
|
int retval = 0;
|
2018-10-23 01:34:03 -04:00
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!points) {
|
2022-12-31 11:19:32 -08:00
|
|
|
|
return SDL_InvalidParamError("SDL_RenderLines(): points");
|
2018-10-23 01:34:03 -04:00
|
|
|
|
}
|
|
|
|
|
|
if (count < 2) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-02 14:01:41 -04:00
|
|
|
|
#if DONT_DRAW_WHILE_HIDDEN
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Don't draw while we're hidden
|
2018-10-23 01:34:03 -04:00
|
|
|
|
if (renderer->hidden) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2021-04-02 14:01:41 -04:00
|
|
|
|
#endif
|
2018-10-23 01:34:03 -04:00
|
|
|
|
|
2022-01-08 11:36:29 -08:00
|
|
|
|
if (renderer->line_method == SDL_RENDERLINEMETHOD_POINTS) {
|
2022-12-27 15:05:51 -08:00
|
|
|
|
retval = RenderLinesWithRectsF(renderer, points, count);
|
2022-01-08 11:36:29 -08:00
|
|
|
|
} else if (renderer->line_method == SDL_RENDERLINEMETHOD_GEOMETRY) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool isstack1;
|
|
|
|
|
|
bool isstack2;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
const float scale_x = renderer->view->scale.x;
|
|
|
|
|
|
const float scale_y = renderer->view->scale.y;
|
2022-01-07 22:14:28 +01:00
|
|
|
|
float *xy = SDL_small_alloc(float, 4 * 2 * count, &isstack1);
|
|
|
|
|
|
int *indices = SDL_small_alloc(int,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
(4) * 3 * (count - 1) + (2) * 3 * (count), &isstack2);
|
2022-01-07 22:14:28 +01:00
|
|
|
|
|
|
|
|
|
|
if (xy && indices) {
|
|
|
|
|
|
int i;
|
|
|
|
|
|
float *ptr_xy = xy;
|
|
|
|
|
|
int *ptr_indices = indices;
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const int xy_stride = 2 * sizeof(float);
|
2022-01-07 22:14:28 +01:00
|
|
|
|
int num_vertices = 4 * count;
|
|
|
|
|
|
int num_indices = 0;
|
|
|
|
|
|
const int size_indices = 4;
|
2022-10-18 08:40:03 -07:00
|
|
|
|
int cur_index = -4;
|
2022-01-07 22:14:28 +01:00
|
|
|
|
const int is_looping = (points[0].x == points[count - 1].x && points[0].y == points[count - 1].y);
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
SDL_FPoint p; // previous point
|
2022-01-07 22:14:28 +01:00
|
|
|
|
p.x = p.y = 0.0f;
|
|
|
|
|
|
/* p q
|
|
|
|
|
|
|
|
|
|
|
|
0----1------ 4----5
|
|
|
|
|
|
| \ |``\ | \ |
|
|
|
|
|
|
| \ | ` `\| \ |
|
|
|
|
|
|
3----2-------7----6
|
|
|
|
|
|
*/
|
|
|
|
|
|
for (i = 0; i < count; ++i) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
SDL_FPoint q = points[i]; // current point
|
2022-01-07 22:14:28 +01:00
|
|
|
|
|
2022-01-08 10:10:18 -08:00
|
|
|
|
q.x *= scale_x;
|
|
|
|
|
|
q.y *= scale_y;
|
|
|
|
|
|
|
2022-01-07 22:14:28 +01:00
|
|
|
|
*ptr_xy++ = q.x;
|
|
|
|
|
|
*ptr_xy++ = q.y;
|
2022-01-08 10:10:18 -08:00
|
|
|
|
*ptr_xy++ = q.x + scale_x;
|
2022-01-07 22:14:28 +01:00
|
|
|
|
*ptr_xy++ = q.y;
|
2022-01-08 10:10:18 -08:00
|
|
|
|
*ptr_xy++ = q.x + scale_x;
|
|
|
|
|
|
*ptr_xy++ = q.y + scale_y;
|
2022-01-07 22:14:28 +01:00
|
|
|
|
*ptr_xy++ = q.x;
|
2022-01-08 10:10:18 -08:00
|
|
|
|
*ptr_xy++ = q.y + scale_y;
|
2022-01-07 22:14:28 +01:00
|
|
|
|
|
2022-12-05 15:20:48 +01:00
|
|
|
|
#define ADD_TRIANGLE(i1, i2, i3) \
|
|
|
|
|
|
*ptr_indices++ = cur_index + (i1); \
|
|
|
|
|
|
*ptr_indices++ = cur_index + (i2); \
|
|
|
|
|
|
*ptr_indices++ = cur_index + (i3); \
|
2022-11-30 12:51:59 -08:00
|
|
|
|
num_indices += 3;
|
2022-01-07 22:14:28 +01:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// closed polyline, don´t draw twice the point
|
2022-01-07 22:14:28 +01:00
|
|
|
|
if (i || is_looping == 0) {
|
|
|
|
|
|
ADD_TRIANGLE(4, 5, 6)
|
|
|
|
|
|
ADD_TRIANGLE(4, 6, 7)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// first point only, no segment
|
2022-01-07 22:14:28 +01:00
|
|
|
|
if (i == 0) {
|
|
|
|
|
|
p = q;
|
2022-10-18 08:40:03 -07:00
|
|
|
|
cur_index += 4;
|
2022-01-07 22:14:28 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// draw segment
|
2022-01-07 22:14:28 +01:00
|
|
|
|
if (p.y == q.y) {
|
|
|
|
|
|
if (p.x < q.x) {
|
|
|
|
|
|
ADD_TRIANGLE(1, 4, 7)
|
|
|
|
|
|
ADD_TRIANGLE(1, 7, 2)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ADD_TRIANGLE(5, 0, 3)
|
|
|
|
|
|
ADD_TRIANGLE(5, 3, 6)
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (p.x == q.x) {
|
|
|
|
|
|
if (p.y < q.y) {
|
|
|
|
|
|
ADD_TRIANGLE(2, 5, 4)
|
|
|
|
|
|
ADD_TRIANGLE(2, 4, 3)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ADD_TRIANGLE(6, 1, 0)
|
|
|
|
|
|
ADD_TRIANGLE(6, 0, 7)
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (p.y < q.y) {
|
|
|
|
|
|
if (p.x < q.x) {
|
|
|
|
|
|
ADD_TRIANGLE(1, 5, 4)
|
|
|
|
|
|
ADD_TRIANGLE(1, 4, 2)
|
|
|
|
|
|
ADD_TRIANGLE(2, 4, 7)
|
|
|
|
|
|
ADD_TRIANGLE(2, 7, 3)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ADD_TRIANGLE(4, 0, 5)
|
|
|
|
|
|
ADD_TRIANGLE(5, 0, 3)
|
|
|
|
|
|
ADD_TRIANGLE(5, 3, 6)
|
|
|
|
|
|
ADD_TRIANGLE(6, 3, 2)
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (p.x < q.x) {
|
|
|
|
|
|
ADD_TRIANGLE(0, 4, 7)
|
|
|
|
|
|
ADD_TRIANGLE(0, 7, 1)
|
|
|
|
|
|
ADD_TRIANGLE(1, 7, 6)
|
|
|
|
|
|
ADD_TRIANGLE(1, 6, 2)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ADD_TRIANGLE(6, 5, 1)
|
|
|
|
|
|
ADD_TRIANGLE(6, 1, 0)
|
|
|
|
|
|
ADD_TRIANGLE(7, 6, 0)
|
|
|
|
|
|
ADD_TRIANGLE(7, 0, 3)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
p = q;
|
2022-10-18 08:40:03 -07:00
|
|
|
|
cur_index += 4;
|
2022-01-07 22:14:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
retval = QueueCmdGeometry(renderer, NULL,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
xy, xy_stride, &renderer->color, 0 /* color_stride */, NULL, 0,
|
|
|
|
|
|
num_vertices, indices, num_indices, size_indices,
|
2024-07-17 22:49:05 -07:00
|
|
|
|
1.0f, 1.0f, SDL_TEXTURE_ADDRESS_CLAMP);
|
2022-01-07 22:14:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-24 11:00:43 -04:00
|
|
|
|
SDL_small_free(xy, isstack1);
|
|
|
|
|
|
SDL_small_free(indices, isstack2);
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
} else if (renderer->view->scale.x != 1.0f || renderer->view->scale.y != 1.0f) {
|
2022-12-27 15:05:51 -08:00
|
|
|
|
retval = RenderLinesWithRectsF(renderer, points, count);
|
2022-01-07 22:14:28 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
retval = QueueCmdDrawLines(renderer, points, count);
|
|
|
|
|
|
}
|
2018-10-23 01:34:03 -04:00
|
|
|
|
|
2023-11-20 20:26:12 -05:00
|
|
|
|
return retval;
|
2018-10-23 01:34:03 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
int SDL_RenderRect(SDL_Renderer *renderer, const SDL_FRect *rect)
|
2018-10-23 01:34:03 -04:00
|
|
|
|
{
|
|
|
|
|
|
SDL_FRect frect;
|
|
|
|
|
|
SDL_FPoint points[5];
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// If 'rect' == NULL, then outline the whole surface
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!rect) {
|
2022-12-27 15:05:51 -08:00
|
|
|
|
GetRenderViewportSize(renderer, &frect);
|
2018-10-23 01:34:03 -04:00
|
|
|
|
rect = &frect;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
points[0].x = rect->x;
|
|
|
|
|
|
points[0].y = rect->y;
|
2022-11-30 12:51:59 -08:00
|
|
|
|
points[1].x = rect->x + rect->w - 1;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
points[1].y = rect->y;
|
2022-11-30 12:51:59 -08:00
|
|
|
|
points[2].x = rect->x + rect->w - 1;
|
|
|
|
|
|
points[2].y = rect->y + rect->h - 1;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
points[3].x = rect->x;
|
2022-11-30 12:51:59 -08:00
|
|
|
|
points[3].y = rect->y + rect->h - 1;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
points[4].x = rect->x;
|
|
|
|
|
|
points[4].y = rect->y;
|
2022-12-31 11:19:32 -08:00
|
|
|
|
return SDL_RenderLines(renderer, points, 5);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
int SDL_RenderRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!rects) {
|
2022-12-27 06:21:13 -08:00
|
|
|
|
return SDL_InvalidParamError("SDL_RenderRects(): rects");
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
if (count < 1) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-02 14:01:41 -04:00
|
|
|
|
#if DONT_DRAW_WHILE_HIDDEN
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Don't draw while we're hidden
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (renderer->hidden) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2021-04-02 14:01:41 -04:00
|
|
|
|
#endif
|
2016-10-01 14:31:00 -07:00
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
for (i = 0; i < count; ++i) {
|
2022-12-27 06:21:13 -08:00
|
|
|
|
if (SDL_RenderRect(renderer, &rects[i]) < 0) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
int SDL_RenderFillRect(SDL_Renderer *renderer, const SDL_FRect *rect)
|
2018-10-23 01:34:03 -04:00
|
|
|
|
{
|
|
|
|
|
|
SDL_FRect frect;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// If 'rect' == NULL, then fill the whole surface
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!rect) {
|
2022-12-27 15:05:51 -08:00
|
|
|
|
GetRenderViewportSize(renderer, &frect);
|
2018-10-23 01:34:03 -04:00
|
|
|
|
rect = &frect;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
2022-12-31 11:19:32 -08:00
|
|
|
|
return SDL_RenderFillRects(renderer, rect, 1);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-31 11:19:32 -08:00
|
|
|
|
int SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
SDL_FRect *frects;
|
|
|
|
|
|
int i;
|
2018-09-25 17:04:47 -04:00
|
|
|
|
int retval;
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool isstack;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!rects) {
|
2022-01-17 16:26:02 +01:00
|
|
|
|
return SDL_InvalidParamError("SDL_RenderFillRects(): rects");
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
if (count < 1) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2016-10-01 14:31:00 -07:00
|
|
|
|
|
2021-04-02 14:01:41 -04:00
|
|
|
|
#if DONT_DRAW_WHILE_HIDDEN
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Don't draw while we're hidden
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (renderer->hidden) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2021-04-02 14:01:41 -04:00
|
|
|
|
#endif
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2018-10-22 20:50:32 -04:00
|
|
|
|
frects = SDL_small_alloc(SDL_FRect, count, &isstack);
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!frects) {
|
error: SDL's allocators now call SDL_OutOfMemory on error.
This means the allocator's caller doesn't need to use SDL_OutOfMemory directly
if the allocation fails.
This applies to the usual allocators: SDL_malloc, SDL_calloc, SDL_realloc
(all of these regardless of if the app supplied a custom allocator or we're
using system malloc() or an internal copy of dlmalloc under the hood),
SDL_aligned_alloc, SDL_small_alloc, SDL_strdup, SDL_asprintf, SDL_wcsdup...
probably others. If it returns something you can pass to SDL_free, it should
work.
The caller might still need to use SDL_OutOfMemory if something that wasn't
SDL allocated the memory: operator new in C++ code, Objective-C's alloc
message, win32 GlobalAlloc, etc.
Fixes #8642.
2023-11-30 00:14:27 -05:00
|
|
|
|
return -1;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < count; ++i) {
|
2023-02-03 12:25:46 -08:00
|
|
|
|
frects[i].x = rects[i].x * renderer->view->scale.x;
|
|
|
|
|
|
frects[i].y = rects[i].y * renderer->view->scale.y;
|
|
|
|
|
|
frects[i].w = rects[i].w * renderer->view->scale.x;
|
|
|
|
|
|
frects[i].h = rects[i].h * renderer->view->scale.y;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-25 17:04:47 -04:00
|
|
|
|
retval = QueueCmdFillRects(renderer, frects, count);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2018-10-22 20:50:32 -04:00
|
|
|
|
SDL_small_free(frects, isstack);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2023-11-20 20:26:12 -05:00
|
|
|
|
return retval;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-20 13:47:01 -07:00
|
|
|
|
static int SDL_RenderTextureInternal(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect)
|
2018-10-23 01:34:03 -04:00
|
|
|
|
{
|
2018-09-25 17:04:47 -04:00
|
|
|
|
int retval;
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool use_rendergeometry = (!renderer->QueueCopy);
|
2018-09-20 15:46:02 -04:00
|
|
|
|
|
2021-10-25 13:46:40 +02:00
|
|
|
|
if (use_rendergeometry) {
|
2021-09-20 16:32:08 +02:00
|
|
|
|
float xy[8];
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const int xy_stride = 2 * sizeof(float);
|
2021-09-20 16:32:08 +02:00
|
|
|
|
float uv[8];
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const int uv_stride = 2 * sizeof(float);
|
2021-09-20 16:32:08 +02:00
|
|
|
|
const int num_vertices = 4;
|
2022-10-18 08:40:03 -07:00
|
|
|
|
const int *indices = renderer->rect_index_order;
|
2021-09-20 16:32:08 +02:00
|
|
|
|
const int num_indices = 6;
|
|
|
|
|
|
const int size_indices = 4;
|
|
|
|
|
|
float minu, minv, maxu, maxv;
|
|
|
|
|
|
float minx, miny, maxx, maxy;
|
|
|
|
|
|
|
2024-07-20 13:47:01 -07:00
|
|
|
|
minu = srcrect->x / texture->w;
|
|
|
|
|
|
minv = srcrect->y / texture->h;
|
|
|
|
|
|
maxu = (srcrect->x + srcrect->w) / texture->w;
|
|
|
|
|
|
maxv = (srcrect->y + srcrect->h) / texture->h;
|
2021-09-20 16:32:08 +02:00
|
|
|
|
|
2024-07-20 13:47:01 -07:00
|
|
|
|
minx = dstrect->x;
|
|
|
|
|
|
miny = dstrect->y;
|
|
|
|
|
|
maxx = dstrect->x + dstrect->w;
|
|
|
|
|
|
maxy = dstrect->y + dstrect->h;
|
2021-09-20 16:32:08 +02:00
|
|
|
|
|
|
|
|
|
|
uv[0] = minu;
|
|
|
|
|
|
uv[1] = minv;
|
|
|
|
|
|
uv[2] = maxu;
|
|
|
|
|
|
uv[3] = minv;
|
|
|
|
|
|
uv[4] = maxu;
|
|
|
|
|
|
uv[5] = maxv;
|
|
|
|
|
|
uv[6] = minu;
|
|
|
|
|
|
uv[7] = maxv;
|
|
|
|
|
|
|
|
|
|
|
|
xy[0] = minx;
|
|
|
|
|
|
xy[1] = miny;
|
|
|
|
|
|
xy[2] = maxx;
|
|
|
|
|
|
xy[3] = miny;
|
|
|
|
|
|
xy[4] = maxx;
|
|
|
|
|
|
xy[5] = maxy;
|
|
|
|
|
|
xy[6] = minx;
|
|
|
|
|
|
xy[7] = maxy;
|
|
|
|
|
|
|
|
|
|
|
|
retval = QueueCmdGeometry(renderer, texture,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
xy, xy_stride, &texture->color, 0 /* color_stride */, uv, uv_stride,
|
|
|
|
|
|
num_vertices,
|
|
|
|
|
|
indices, num_indices, size_indices,
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->view->scale.x,
|
2024-07-17 22:49:05 -07:00
|
|
|
|
renderer->view->scale.y, SDL_TEXTURE_ADDRESS_CLAMP);
|
2021-09-20 16:32:08 +02:00
|
|
|
|
} else {
|
2024-07-20 13:47:01 -07:00
|
|
|
|
SDL_FRect rect;
|
2021-09-20 16:32:08 +02:00
|
|
|
|
|
2024-07-20 13:47:01 -07:00
|
|
|
|
rect.x = dstrect->x * renderer->view->scale.x;
|
|
|
|
|
|
rect.y = dstrect->y * renderer->view->scale.y;
|
|
|
|
|
|
rect.w = dstrect->w * renderer->view->scale.x;
|
|
|
|
|
|
rect.h = dstrect->h * renderer->view->scale.y;
|
2021-09-20 16:32:08 +02:00
|
|
|
|
|
2024-07-20 13:47:01 -07:00
|
|
|
|
retval = QueueCmdCopy(renderer, texture, srcrect, &rect);
|
2021-09-20 16:32:08 +02:00
|
|
|
|
}
|
2023-11-20 20:26:12 -05:00
|
|
|
|
return retval;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-20 13:47:01 -07:00
|
|
|
|
int SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect)
|
|
|
|
|
|
{
|
|
|
|
|
|
SDL_FRect real_srcrect;
|
|
|
|
|
|
SDL_FRect real_dstrect;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (renderer != texture->renderer) {
|
|
|
|
|
|
return SDL_SetError("Texture was not created with this renderer");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if DONT_DRAW_WHILE_HIDDEN
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Don't draw while we're hidden
|
2024-07-20 13:47:01 -07:00
|
|
|
|
if (renderer->hidden) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
real_srcrect.x = 0.0f;
|
|
|
|
|
|
real_srcrect.y = 0.0f;
|
|
|
|
|
|
real_srcrect.w = (float)texture->w;
|
|
|
|
|
|
real_srcrect.h = (float)texture->h;
|
|
|
|
|
|
if (srcrect) {
|
|
|
|
|
|
if (!SDL_GetRectIntersectionFloat(srcrect, &real_srcrect, &real_srcrect)) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GetRenderViewportSize(renderer, &real_dstrect);
|
|
|
|
|
|
if (dstrect) {
|
|
|
|
|
|
if (!SDL_HasRectIntersectionFloat(dstrect, &real_dstrect)) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
real_dstrect = *dstrect;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (texture->native) {
|
|
|
|
|
|
texture = texture->native;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
texture->last_command_generation = renderer->render_command_generation;
|
|
|
|
|
|
|
|
|
|
|
|
return SDL_RenderTextureInternal(renderer, texture, &real_srcrect, &real_dstrect);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-27 06:21:13 -08:00
|
|
|
|
int SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
|
2023-03-02 08:56:54 -08:00
|
|
|
|
const SDL_FRect *srcrect, const SDL_FRect *dstrect,
|
2024-01-20 06:31:37 -08:00
|
|
|
|
const double angle, const SDL_FPoint *center, const SDL_FlipMode flip)
|
2018-10-23 01:34:03 -04:00
|
|
|
|
{
|
2023-03-02 08:56:54 -08:00
|
|
|
|
SDL_FRect real_srcrect;
|
2018-10-23 01:34:03 -04:00
|
|
|
|
SDL_FRect real_dstrect;
|
|
|
|
|
|
SDL_FPoint real_center;
|
|
|
|
|
|
int retval;
|
2021-10-25 13:46:40 +02:00
|
|
|
|
int use_rendergeometry;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
if (flip == SDL_FLIP_NONE && (int)(angle / 360) == angle / 360) { // fast path when we don't need rotation or flipping
|
2022-12-31 11:19:32 -08:00
|
|
|
|
return SDL_RenderTexture(renderer, texture, srcrect, dstrect);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (renderer != texture->renderer) {
|
|
|
|
|
|
return SDL_SetError("Texture was not created with this renderer");
|
|
|
|
|
|
}
|
2021-09-20 16:32:08 +02:00
|
|
|
|
if (!renderer->QueueCopyEx && !renderer->QueueGeometry) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return SDL_SetError("Renderer does not support RenderCopyEx");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-02 14:01:41 -04:00
|
|
|
|
#if DONT_DRAW_WHILE_HIDDEN
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Don't draw while we're hidden
|
2016-10-01 14:31:00 -07:00
|
|
|
|
if (renderer->hidden) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2021-04-02 14:01:41 -04:00
|
|
|
|
#endif
|
2016-10-01 14:31:00 -07:00
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
use_rendergeometry = (!renderer->QueueCopyEx);
|
2021-10-25 13:46:40 +02:00
|
|
|
|
|
2023-03-02 08:56:54 -08:00
|
|
|
|
real_srcrect.x = 0.0f;
|
|
|
|
|
|
real_srcrect.y = 0.0f;
|
|
|
|
|
|
real_srcrect.w = (float)texture->w;
|
|
|
|
|
|
real_srcrect.h = (float)texture->h;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (srcrect) {
|
2023-03-02 08:56:54 -08:00
|
|
|
|
if (!SDL_GetRectIntersectionFloat(srcrect, &real_srcrect, &real_srcrect)) {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// We don't intersect the dstrect with the viewport as RenderCopy does because of potential rotation clipping issues... TODO: should we?
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (dstrect) {
|
|
|
|
|
|
real_dstrect = *dstrect;
|
|
|
|
|
|
} else {
|
2022-12-27 15:05:51 -08:00
|
|
|
|
GetRenderViewportSize(renderer, &real_dstrect);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (texture->native) {
|
|
|
|
|
|
texture = texture->native;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-01 14:31:00 -07:00
|
|
|
|
if (center) {
|
|
|
|
|
|
real_center = *center;
|
|
|
|
|
|
} else {
|
2018-10-23 01:34:03 -04:00
|
|
|
|
real_center.x = real_dstrect.w / 2.0f;
|
|
|
|
|
|
real_center.y = real_dstrect.h / 2.0f;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-20 16:32:08 +02:00
|
|
|
|
texture->last_command_generation = renderer->render_command_generation;
|
|
|
|
|
|
|
2021-10-25 13:46:40 +02:00
|
|
|
|
if (use_rendergeometry) {
|
2021-09-20 16:32:08 +02:00
|
|
|
|
float xy[8];
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const int xy_stride = 2 * sizeof(float);
|
2021-09-20 16:32:08 +02:00
|
|
|
|
float uv[8];
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const int uv_stride = 2 * sizeof(float);
|
2021-09-20 16:32:08 +02:00
|
|
|
|
const int num_vertices = 4;
|
2022-10-18 08:40:03 -07:00
|
|
|
|
const int *indices = renderer->rect_index_order;
|
2021-09-20 16:32:08 +02:00
|
|
|
|
const int num_indices = 6;
|
|
|
|
|
|
const int size_indices = 4;
|
|
|
|
|
|
float minu, minv, maxu, maxv;
|
|
|
|
|
|
float minx, miny, maxx, maxy;
|
|
|
|
|
|
float centerx, centery;
|
|
|
|
|
|
|
|
|
|
|
|
float s_minx, s_miny, s_maxx, s_maxy;
|
|
|
|
|
|
float c_minx, c_miny, c_maxx, c_maxy;
|
|
|
|
|
|
|
2022-11-25 22:35:24 +03:00
|
|
|
|
const float radian_angle = (float)((SDL_PI_D * angle) / 180.0);
|
2021-10-25 16:18:40 +02:00
|
|
|
|
const float s = SDL_sinf(radian_angle);
|
|
|
|
|
|
const float c = SDL_cosf(radian_angle);
|
2021-09-20 16:32:08 +02:00
|
|
|
|
|
2023-03-02 08:56:54 -08:00
|
|
|
|
minu = real_srcrect.x / texture->w;
|
|
|
|
|
|
minv = real_srcrect.y / texture->h;
|
|
|
|
|
|
maxu = (real_srcrect.x + real_srcrect.w) / texture->w;
|
|
|
|
|
|
maxv = (real_srcrect.y + real_srcrect.h) / texture->h;
|
2021-09-20 16:32:08 +02:00
|
|
|
|
|
|
|
|
|
|
centerx = real_center.x + real_dstrect.x;
|
|
|
|
|
|
centery = real_center.y + real_dstrect.y;
|
|
|
|
|
|
|
|
|
|
|
|
if (flip & SDL_FLIP_HORIZONTAL) {
|
|
|
|
|
|
minx = real_dstrect.x + real_dstrect.w;
|
|
|
|
|
|
maxx = real_dstrect.x;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
minx = real_dstrect.x;
|
|
|
|
|
|
maxx = real_dstrect.x + real_dstrect.w;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (flip & SDL_FLIP_VERTICAL) {
|
|
|
|
|
|
miny = real_dstrect.y + real_dstrect.h;
|
|
|
|
|
|
maxy = real_dstrect.y;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
miny = real_dstrect.y;
|
|
|
|
|
|
maxy = real_dstrect.y + real_dstrect.h;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uv[0] = minu;
|
|
|
|
|
|
uv[1] = minv;
|
|
|
|
|
|
uv[2] = maxu;
|
|
|
|
|
|
uv[3] = minv;
|
|
|
|
|
|
uv[4] = maxu;
|
|
|
|
|
|
uv[5] = maxv;
|
|
|
|
|
|
uv[6] = minu;
|
|
|
|
|
|
uv[7] = maxv;
|
|
|
|
|
|
|
|
|
|
|
|
/* apply rotation with 2x2 matrix ( c -s )
|
|
|
|
|
|
* ( s c ) */
|
|
|
|
|
|
s_minx = s * (minx - centerx);
|
|
|
|
|
|
s_miny = s * (miny - centery);
|
|
|
|
|
|
s_maxx = s * (maxx - centerx);
|
|
|
|
|
|
s_maxy = s * (maxy - centery);
|
|
|
|
|
|
c_minx = c * (minx - centerx);
|
|
|
|
|
|
c_miny = c * (miny - centery);
|
|
|
|
|
|
c_maxx = c * (maxx - centerx);
|
|
|
|
|
|
c_maxy = c * (maxy - centery);
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// (minx, miny)
|
2021-09-20 16:32:08 +02:00
|
|
|
|
xy[0] = (c_minx - s_miny) + centerx;
|
|
|
|
|
|
xy[1] = (s_minx + c_miny) + centery;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// (maxx, miny)
|
2021-09-20 16:32:08 +02:00
|
|
|
|
xy[2] = (c_maxx - s_miny) + centerx;
|
|
|
|
|
|
xy[3] = (s_maxx + c_miny) + centery;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// (maxx, maxy)
|
2021-09-20 16:32:08 +02:00
|
|
|
|
xy[4] = (c_maxx - s_maxy) + centerx;
|
|
|
|
|
|
xy[5] = (s_maxx + c_maxy) + centery;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// (minx, maxy)
|
2021-09-20 16:32:08 +02:00
|
|
|
|
xy[6] = (c_minx - s_maxy) + centerx;
|
|
|
|
|
|
xy[7] = (s_minx + c_maxy) + centery;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2021-09-20 16:32:08 +02:00
|
|
|
|
retval = QueueCmdGeometry(renderer, texture,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
xy, xy_stride, &texture->color, 0 /* color_stride */, uv, uv_stride,
|
|
|
|
|
|
num_vertices,
|
|
|
|
|
|
indices, num_indices, size_indices,
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->view->scale.x,
|
2024-07-17 22:49:05 -07:00
|
|
|
|
renderer->view->scale.y, SDL_TEXTURE_ADDRESS_CLAMP);
|
2021-09-20 16:32:08 +02:00
|
|
|
|
} else {
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
retval = QueueCmdCopyEx(renderer, texture, &real_srcrect, &real_dstrect, angle, &real_center, flip,
|
|
|
|
|
|
renderer->view->scale.x,
|
|
|
|
|
|
renderer->view->scale.y);
|
2021-09-20 16:32:08 +02:00
|
|
|
|
}
|
2023-11-20 20:26:12 -05:00
|
|
|
|
return retval;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-20 13:47:01 -07:00
|
|
|
|
static int SDL_RenderTextureTiled_Wrap(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect)
|
|
|
|
|
|
{
|
|
|
|
|
|
float xy[8];
|
|
|
|
|
|
const int xy_stride = 2 * sizeof(float);
|
|
|
|
|
|
float uv[8];
|
|
|
|
|
|
const int uv_stride = 2 * sizeof(float);
|
|
|
|
|
|
const int num_vertices = 4;
|
|
|
|
|
|
const int *indices = renderer->rect_index_order;
|
|
|
|
|
|
const int num_indices = 6;
|
|
|
|
|
|
const int size_indices = 4;
|
|
|
|
|
|
float minu, minv, maxu, maxv;
|
|
|
|
|
|
float minx, miny, maxx, maxy;
|
|
|
|
|
|
|
|
|
|
|
|
minu = 0.0f;
|
|
|
|
|
|
minv = 0.0f;
|
|
|
|
|
|
maxu = dstrect->w / (srcrect->w * scale);
|
|
|
|
|
|
maxv = dstrect->h / (srcrect->h * scale);
|
|
|
|
|
|
|
|
|
|
|
|
minx = dstrect->x;
|
|
|
|
|
|
miny = dstrect->y;
|
|
|
|
|
|
maxx = dstrect->x + dstrect->w;
|
|
|
|
|
|
maxy = dstrect->y + dstrect->h;
|
|
|
|
|
|
|
|
|
|
|
|
uv[0] = minu;
|
|
|
|
|
|
uv[1] = minv;
|
|
|
|
|
|
uv[2] = maxu;
|
|
|
|
|
|
uv[3] = minv;
|
|
|
|
|
|
uv[4] = maxu;
|
|
|
|
|
|
uv[5] = maxv;
|
|
|
|
|
|
uv[6] = minu;
|
|
|
|
|
|
uv[7] = maxv;
|
|
|
|
|
|
|
|
|
|
|
|
xy[0] = minx;
|
|
|
|
|
|
xy[1] = miny;
|
|
|
|
|
|
xy[2] = maxx;
|
|
|
|
|
|
xy[3] = miny;
|
|
|
|
|
|
xy[4] = maxx;
|
|
|
|
|
|
xy[5] = maxy;
|
|
|
|
|
|
xy[6] = minx;
|
|
|
|
|
|
xy[7] = maxy;
|
|
|
|
|
|
|
|
|
|
|
|
return QueueCmdGeometry(renderer, texture,
|
|
|
|
|
|
xy, xy_stride, &texture->color, 0 /* color_stride */, uv, uv_stride,
|
|
|
|
|
|
num_vertices,
|
|
|
|
|
|
indices, num_indices, size_indices,
|
|
|
|
|
|
renderer->view->scale.x,
|
|
|
|
|
|
renderer->view->scale.y, SDL_TEXTURE_ADDRESS_WRAP);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int SDL_RenderTextureTiled_Iterate(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect)
|
|
|
|
|
|
{
|
|
|
|
|
|
float tile_width = srcrect->w * scale;
|
|
|
|
|
|
float tile_height = srcrect->h * scale;
|
|
|
|
|
|
float float_rows, float_cols;
|
|
|
|
|
|
float remaining_w = SDL_modff(dstrect->w / tile_width, &float_cols);
|
|
|
|
|
|
float remaining_h = SDL_modff(dstrect->h / tile_height, &float_rows);
|
|
|
|
|
|
float remaining_src_w = remaining_w * srcrect->w;
|
|
|
|
|
|
float remaining_src_h = remaining_h * srcrect->h;
|
|
|
|
|
|
float remaining_dst_w = remaining_w * tile_width;
|
|
|
|
|
|
float remaining_dst_h = remaining_h * tile_height;
|
|
|
|
|
|
int rows = (int)float_rows;
|
|
|
|
|
|
int cols = (int)float_cols;
|
|
|
|
|
|
SDL_FRect curr_src, curr_dst;
|
|
|
|
|
|
|
|
|
|
|
|
SDL_copyp(&curr_src, srcrect);
|
|
|
|
|
|
curr_dst.y = dstrect->y;
|
|
|
|
|
|
curr_dst.w = tile_width;
|
|
|
|
|
|
curr_dst.h = tile_height;
|
|
|
|
|
|
for (int y = 0; y < rows; ++y) {
|
|
|
|
|
|
curr_dst.x = dstrect->x;
|
|
|
|
|
|
for (int x = 0; x < cols; ++x) {
|
|
|
|
|
|
if (SDL_RenderTextureInternal(renderer, texture, &curr_src, &curr_dst) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
curr_dst.x += curr_dst.w;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (remaining_dst_w > 0.0f) {
|
|
|
|
|
|
curr_src.w = remaining_src_w;
|
|
|
|
|
|
curr_dst.w = remaining_dst_w;
|
|
|
|
|
|
if (SDL_RenderTextureInternal(renderer, texture, &curr_src, &curr_dst) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
curr_src.w = srcrect->w;
|
|
|
|
|
|
curr_dst.w = tile_width;
|
|
|
|
|
|
}
|
|
|
|
|
|
curr_dst.y += curr_dst.h;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (remaining_dst_h > 0.0f) {
|
|
|
|
|
|
curr_src.h = remaining_src_h;
|
|
|
|
|
|
curr_dst.h = remaining_dst_h;
|
|
|
|
|
|
curr_dst.x = dstrect->x;
|
|
|
|
|
|
for (int x = 0; x < cols; ++x) {
|
|
|
|
|
|
if (SDL_RenderTextureInternal(renderer, texture, &curr_src, &curr_dst) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
curr_dst.x += curr_dst.w;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (remaining_dst_w > 0.0f) {
|
|
|
|
|
|
curr_src.w = remaining_src_w;
|
|
|
|
|
|
curr_dst.w = remaining_dst_w;
|
|
|
|
|
|
if (SDL_RenderTextureInternal(renderer, texture, &curr_src, &curr_dst) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SDL_RenderTextureTiled(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect)
|
|
|
|
|
|
{
|
|
|
|
|
|
SDL_FRect real_srcrect;
|
|
|
|
|
|
SDL_FRect real_dstrect;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (renderer != texture->renderer) {
|
|
|
|
|
|
return SDL_SetError("Texture was not created with this renderer");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (scale <= 0.0f) {
|
|
|
|
|
|
return SDL_InvalidParamError("scale");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if DONT_DRAW_WHILE_HIDDEN
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Don't draw while we're hidden
|
2024-07-20 13:47:01 -07:00
|
|
|
|
if (renderer->hidden) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
real_srcrect.x = 0.0f;
|
|
|
|
|
|
real_srcrect.y = 0.0f;
|
|
|
|
|
|
real_srcrect.w = (float)texture->w;
|
|
|
|
|
|
real_srcrect.h = (float)texture->h;
|
|
|
|
|
|
if (srcrect) {
|
|
|
|
|
|
if (!SDL_GetRectIntersectionFloat(srcrect, &real_srcrect, &real_srcrect)) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GetRenderViewportSize(renderer, &real_dstrect);
|
|
|
|
|
|
if (dstrect) {
|
|
|
|
|
|
if (!SDL_HasRectIntersectionFloat(dstrect, &real_dstrect)) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
real_dstrect = *dstrect;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (texture->native) {
|
|
|
|
|
|
texture = texture->native;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
texture->last_command_generation = renderer->render_command_generation;
|
|
|
|
|
|
|
|
|
|
|
|
// See if we can use geometry with repeating texture coordinates
|
|
|
|
|
|
if (!renderer->software &&
|
|
|
|
|
|
(!srcrect ||
|
|
|
|
|
|
(real_srcrect.x == 0.0f && real_srcrect.y == 0.0f &&
|
|
|
|
|
|
real_srcrect.w == (float)texture->w && real_srcrect.h == (float)texture->h))) {
|
|
|
|
|
|
return SDL_RenderTextureTiled_Wrap(renderer, texture, &real_srcrect, scale, &real_dstrect);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return SDL_RenderTextureTiled_Iterate(renderer, texture, &real_srcrect, scale, &real_dstrect);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-31 22:09:42 -07:00
|
|
|
|
int SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, const SDL_FRect *dstrect)
|
2024-07-20 16:39:09 -07:00
|
|
|
|
{
|
|
|
|
|
|
SDL_FRect full_src, full_dst;
|
|
|
|
|
|
SDL_FRect curr_src, curr_dst;
|
2024-07-31 22:09:42 -07:00
|
|
|
|
float dst_left_width;
|
|
|
|
|
|
float dst_right_width;
|
|
|
|
|
|
float dst_top_height;
|
|
|
|
|
|
float dst_bottom_height;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (renderer != texture->renderer) {
|
|
|
|
|
|
return SDL_SetError("Texture was not created with this renderer");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!srcrect) {
|
|
|
|
|
|
full_src.x = 0;
|
|
|
|
|
|
full_src.y = 0;
|
|
|
|
|
|
full_src.w = (float)texture->w;
|
|
|
|
|
|
full_src.h = (float)texture->h;
|
|
|
|
|
|
srcrect = &full_src;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!dstrect) {
|
|
|
|
|
|
GetRenderViewportSize(renderer, &full_dst);
|
|
|
|
|
|
dstrect = &full_dst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (scale <= 0.0f || scale == 1.0f) {
|
2024-07-31 22:09:42 -07:00
|
|
|
|
dst_left_width = left_width;
|
|
|
|
|
|
dst_right_width = right_width;
|
|
|
|
|
|
dst_top_height = top_height;
|
|
|
|
|
|
dst_bottom_height = bottom_height;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
} else {
|
2024-07-31 22:09:42 -07:00
|
|
|
|
dst_left_width = (left_width * scale);
|
|
|
|
|
|
dst_right_width = (right_width * scale);
|
|
|
|
|
|
dst_top_height = (top_height * scale);
|
|
|
|
|
|
dst_bottom_height = (bottom_height * scale);
|
2024-07-20 16:39:09 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Upper-left corner
|
|
|
|
|
|
curr_src.x = srcrect->x;
|
|
|
|
|
|
curr_src.y = srcrect->y;
|
2024-07-31 22:09:42 -07:00
|
|
|
|
curr_src.w = left_width;
|
|
|
|
|
|
curr_src.h = top_height;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
curr_dst.x = dstrect->x;
|
|
|
|
|
|
curr_dst.y = dstrect->y;
|
2024-07-31 22:09:42 -07:00
|
|
|
|
curr_dst.w = dst_left_width;
|
|
|
|
|
|
curr_dst.h = dst_top_height;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Upper-right corner
|
2024-07-31 22:09:42 -07:00
|
|
|
|
curr_src.x = srcrect->x + srcrect->w - right_width;
|
|
|
|
|
|
curr_src.w = right_width;
|
|
|
|
|
|
curr_dst.x = dstrect->x + dstrect->w - dst_right_width;
|
|
|
|
|
|
curr_dst.w = dst_right_width;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Lower-right corner
|
2024-07-31 22:09:42 -07:00
|
|
|
|
curr_src.y = srcrect->y + srcrect->h - bottom_height;
|
|
|
|
|
|
curr_dst.y = dstrect->y + dstrect->h - dst_bottom_height;
|
|
|
|
|
|
curr_dst.h = dst_bottom_height;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Lower-left corner
|
|
|
|
|
|
curr_src.x = srcrect->x;
|
2024-07-31 22:09:42 -07:00
|
|
|
|
curr_src.w = left_width;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
curr_dst.x = dstrect->x;
|
2024-07-31 22:09:42 -07:00
|
|
|
|
curr_dst.w = dst_left_width;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Left
|
2024-07-31 22:09:42 -07:00
|
|
|
|
curr_src.y = srcrect->y + top_height;
|
|
|
|
|
|
curr_src.h = srcrect->h - top_height - bottom_height;
|
|
|
|
|
|
curr_dst.y = dstrect->y + dst_top_height;
|
|
|
|
|
|
curr_dst.h = dstrect->h - dst_top_height - dst_bottom_height;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Right
|
2024-07-31 22:09:42 -07:00
|
|
|
|
curr_src.x = srcrect->x + srcrect->w - right_width;
|
|
|
|
|
|
curr_src.w = right_width;
|
|
|
|
|
|
curr_dst.x = dstrect->x + dstrect->w - dst_right_width;
|
|
|
|
|
|
curr_dst.w = dst_right_width;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Top
|
2024-07-31 22:09:42 -07:00
|
|
|
|
curr_src.x = srcrect->x + left_width;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
curr_src.y = srcrect->y;
|
2024-07-31 22:09:42 -07:00
|
|
|
|
curr_src.w = srcrect->w - left_width - right_width;
|
|
|
|
|
|
curr_src.h = top_height;
|
|
|
|
|
|
curr_dst.x = dstrect->x + dst_left_width;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
curr_dst.y = dstrect->y;
|
2024-07-31 22:09:42 -07:00
|
|
|
|
curr_dst.w = dstrect->w - dst_left_width - dst_right_width;
|
|
|
|
|
|
curr_dst.h = dst_top_height;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Bottom
|
2024-07-31 22:09:42 -07:00
|
|
|
|
curr_src.y = srcrect->y + srcrect->h - bottom_height;
|
|
|
|
|
|
curr_dst.y = dstrect->y + dstrect->h - dst_bottom_height;
|
|
|
|
|
|
curr_dst.h = dst_bottom_height;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Center
|
2024-07-31 22:09:42 -07:00
|
|
|
|
curr_src.x = srcrect->x + left_width;
|
|
|
|
|
|
curr_src.y = srcrect->y + top_height;
|
|
|
|
|
|
curr_src.w = srcrect->w - left_width - right_width;
|
|
|
|
|
|
curr_src.h = srcrect->h - top_height - bottom_height;
|
|
|
|
|
|
curr_dst.x = dstrect->x + dst_left_width;
|
|
|
|
|
|
curr_dst.y = dstrect->y + dst_top_height;
|
|
|
|
|
|
curr_dst.w = dstrect->w - dst_left_width - dst_right_width;
|
|
|
|
|
|
curr_dst.h = dstrect->h - dst_top_height - dst_bottom_height;
|
2024-07-20 16:39:09 -07:00
|
|
|
|
if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2024-07-31 22:09:42 -07:00
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
int SDL_RenderGeometry(SDL_Renderer *renderer,
|
|
|
|
|
|
SDL_Texture *texture,
|
|
|
|
|
|
const SDL_Vertex *vertices, int num_vertices,
|
|
|
|
|
|
const int *indices, int num_indices)
|
2021-04-01 09:55:00 +02:00
|
|
|
|
{
|
2021-12-14 10:31:55 +01:00
|
|
|
|
if (vertices) {
|
2021-12-16 11:10:07 +01:00
|
|
|
|
const float *xy = &vertices->position.x;
|
2022-11-30 12:51:59 -08:00
|
|
|
|
int xy_stride = sizeof(SDL_Vertex);
|
2024-01-29 13:28:33 -08:00
|
|
|
|
const SDL_FColor *color = &vertices->color;
|
2022-11-30 12:51:59 -08:00
|
|
|
|
int color_stride = sizeof(SDL_Vertex);
|
2021-12-16 11:10:07 +01:00
|
|
|
|
const float *uv = &vertices->tex_coord.x;
|
2022-11-30 12:51:59 -08:00
|
|
|
|
int uv_stride = sizeof(SDL_Vertex);
|
2021-12-14 10:31:55 +01:00
|
|
|
|
int size_indices = 4;
|
Removed SDL_RenderGeometryRawFloat()
After discussion with @ocornut, SDL_RenderGeometryRaw() will take floating point colors and conversion from 8-bit color can happen on the application side. We can always add an 8-bit color fast path in the future if we need it on handheld platforms.
If you need code to do this in your application, you can use the following:
int SDL_RenderGeometryRaw8BitColor(SDL_Renderer *renderer, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices)
{
int i, retval, isstack;
const Uint8 *color2 = (const Uint8 *)color;
SDL_FColor *color3;
if (num_vertices <= 0) {
return SDL_InvalidParamError("num_vertices");
}
if (!color) {
return SDL_InvalidParamError("color");
}
color3 = (SDL_FColor *)SDL_small_alloc(SDL_FColor, num_vertices, &isstack);
if (!color3) {
return -1;
}
for (i = 0; i < num_vertices; ++i) {
color3[i].r = color->r / 255.0f;
color3[i].g = color->g / 255.0f;
color3[i].b = color->b / 255.0f;
color3[i].a = color->a / 255.0f;
color2 += color_stride;
color = (const SDL_Color *)color2;
}
retval = SDL_RenderGeometryRaw(renderer, texture, xy, xy_stride, color3, sizeof(*color3), uv, uv_stride, num_vertices, indices, num_indices, size_indices);
SDL_small_free(color3, isstack);
return retval;
}
Fixes https://github.com/libsdl-org/SDL/issues/9009
2024-06-28 23:55:23 -07:00
|
|
|
|
return SDL_RenderGeometryRaw(renderer, texture, xy, xy_stride, color, color_stride, uv, uv_stride, num_vertices, indices, num_indices, size_indices);
|
2021-12-14 10:31:55 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
return SDL_InvalidParamError("vertices");
|
|
|
|
|
|
}
|
2021-04-01 09:55:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-13 04:15:46 +00:00
|
|
|
|
#if SDL_VIDEO_RENDER_SW
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int remap_one_indice(
|
|
|
|
|
|
int prev,
|
|
|
|
|
|
int k,
|
|
|
|
|
|
SDL_Texture *texture,
|
|
|
|
|
|
const float *xy, int xy_stride,
|
2024-01-29 13:28:33 -08:00
|
|
|
|
const SDL_FColor *color, int color_stride,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const float *uv, int uv_stride)
|
2021-04-01 10:16:27 +02:00
|
|
|
|
{
|
|
|
|
|
|
const float *xy0_, *xy1_, *uv0_, *uv1_;
|
2024-01-29 13:28:33 -08:00
|
|
|
|
const SDL_FColor *col0_, *col1_;
|
2022-11-30 12:51:59 -08:00
|
|
|
|
xy0_ = (const float *)((const char *)xy + prev * xy_stride);
|
|
|
|
|
|
xy1_ = (const float *)((const char *)xy + k * xy_stride);
|
2021-04-01 10:16:27 +02:00
|
|
|
|
if (xy0_[0] != xy1_[0]) {
|
|
|
|
|
|
return k;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (xy0_[1] != xy1_[1]) {
|
|
|
|
|
|
return k;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (texture) {
|
2022-11-30 12:51:59 -08:00
|
|
|
|
uv0_ = (const float *)((const char *)uv + prev * uv_stride);
|
|
|
|
|
|
uv1_ = (const float *)((const char *)uv + k * uv_stride);
|
2021-04-01 10:16:27 +02:00
|
|
|
|
if (uv0_[0] != uv1_[0]) {
|
|
|
|
|
|
return k;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (uv0_[1] != uv1_[1]) {
|
|
|
|
|
|
return k;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-01-29 13:28:33 -08:00
|
|
|
|
col0_ = (const SDL_FColor *)((const char *)color + prev * color_stride);
|
|
|
|
|
|
col1_ = (const SDL_FColor *)((const char *)color + k * color_stride);
|
2021-04-01 10:16:27 +02:00
|
|
|
|
|
2024-01-29 13:28:33 -08:00
|
|
|
|
if (SDL_memcmp(col0_, col1_, sizeof(*col0_)) != 0) {
|
2021-04-01 10:16:27 +02:00
|
|
|
|
return k;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return prev;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int remap_indices(
|
|
|
|
|
|
int prev[3],
|
|
|
|
|
|
int k,
|
|
|
|
|
|
SDL_Texture *texture,
|
|
|
|
|
|
const float *xy, int xy_stride,
|
2024-01-29 13:28:33 -08:00
|
|
|
|
const SDL_FColor *color, int color_stride,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const float *uv, int uv_stride)
|
2021-04-01 10:16:27 +02:00
|
|
|
|
{
|
|
|
|
|
|
int i;
|
|
|
|
|
|
if (prev[0] == -1) {
|
|
|
|
|
|
return k;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
|
|
int new_k = remap_one_indice(prev[i], k, texture, xy, xy_stride, color, color_stride, uv, uv_stride);
|
|
|
|
|
|
if (new_k != k) {
|
|
|
|
|
|
return new_k;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return k;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-27 07:16:40 +02:00
|
|
|
|
#define DEBUG_SW_RENDER_GEOMETRY 0
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// For the software renderer, try to reinterpret triangles as SDL_Rect
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static int SDLCALL SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer,
|
|
|
|
|
|
SDL_Texture *texture,
|
|
|
|
|
|
const float *xy, int xy_stride,
|
2024-01-29 13:28:33 -08:00
|
|
|
|
const SDL_FColor *color, int color_stride,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const float *uv, int uv_stride,
|
|
|
|
|
|
int num_vertices,
|
|
|
|
|
|
const void *indices, int num_indices, int size_indices)
|
2021-04-01 10:16:27 +02:00
|
|
|
|
{
|
|
|
|
|
|
int i;
|
|
|
|
|
|
int retval = 0;
|
|
|
|
|
|
int count = indices ? num_indices : num_vertices;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
int prev[3]; // Previous triangle vertex indices
|
2024-06-12 09:21:02 -07:00
|
|
|
|
float texw = 0.0f, texh = 0.0f;
|
2021-04-01 20:18:05 +02:00
|
|
|
|
SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
2024-01-31 10:25:50 -08:00
|
|
|
|
float r = 0, g = 0, b = 0, a = 0;
|
2021-04-01 12:43:39 +02:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Save
|
2024-07-17 09:40:25 -07:00
|
|
|
|
SDL_GetRenderDrawBlendMode(renderer, &blendMode);
|
2024-01-31 10:25:50 -08:00
|
|
|
|
SDL_GetRenderDrawColorFloat(renderer, &r, &g, &b, &a);
|
2021-04-01 10:16:27 +02:00
|
|
|
|
|
|
|
|
|
|
if (texture) {
|
2024-06-12 09:21:02 -07:00
|
|
|
|
SDL_GetTextureSize(texture, &texw, &texh);
|
2021-04-01 10:16:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
prev[0] = -1;
|
|
|
|
|
|
prev[1] = -1;
|
|
|
|
|
|
prev[2] = -1;
|
2021-08-27 07:47:28 +02:00
|
|
|
|
size_indices = indices ? size_indices : 0;
|
2021-04-01 10:16:27 +02:00
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; i += 3) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
int k0, k1, k2; // Current triangle indices
|
2021-04-01 10:16:27 +02:00
|
|
|
|
int is_quad = 1;
|
2021-08-27 07:16:40 +02:00
|
|
|
|
#if DEBUG_SW_RENDER_GEOMETRY
|
2021-04-01 10:16:27 +02:00
|
|
|
|
int is_uniform = 1;
|
|
|
|
|
|
int is_rectangle = 1;
|
2021-08-27 07:16:40 +02:00
|
|
|
|
#endif
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
int A = -1; // Top left vertex
|
|
|
|
|
|
int B = -1; // Bottom right vertex
|
|
|
|
|
|
int C = -1; // Third vertex of current triangle
|
|
|
|
|
|
int C2 = -1; // Last, vertex of previous triangle
|
2021-04-01 10:16:27 +02:00
|
|
|
|
|
2021-04-23 12:00:14 +02:00
|
|
|
|
if (size_indices == 4) {
|
2021-04-01 10:16:27 +02:00
|
|
|
|
k0 = ((const Uint32 *)indices)[i];
|
|
|
|
|
|
k1 = ((const Uint32 *)indices)[i + 1];
|
|
|
|
|
|
k2 = ((const Uint32 *)indices)[i + 2];
|
2021-04-23 12:00:14 +02:00
|
|
|
|
} else if (size_indices == 2) {
|
2021-04-01 10:16:27 +02:00
|
|
|
|
k0 = ((const Uint16 *)indices)[i];
|
|
|
|
|
|
k1 = ((const Uint16 *)indices)[i + 1];
|
|
|
|
|
|
k2 = ((const Uint16 *)indices)[i + 2];
|
2021-04-23 12:00:14 +02:00
|
|
|
|
} else if (size_indices == 1) {
|
2021-04-01 10:16:27 +02:00
|
|
|
|
k0 = ((const Uint8 *)indices)[i];
|
|
|
|
|
|
k1 = ((const Uint8 *)indices)[i + 1];
|
|
|
|
|
|
k2 = ((const Uint8 *)indices)[i + 2];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/* Vertices were not provided by indices. Maybe some are duplicated.
|
|
|
|
|
|
* We try to indentificate the duplicates by comparing with the previous three vertices */
|
|
|
|
|
|
k0 = remap_indices(prev, i, texture, xy, xy_stride, color, color_stride, uv, uv_stride);
|
|
|
|
|
|
k1 = remap_indices(prev, i + 1, texture, xy, xy_stride, color, color_stride, uv, uv_stride);
|
|
|
|
|
|
k2 = remap_indices(prev, i + 2, texture, xy, xy_stride, color, color_stride, uv, uv_stride);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (prev[0] == -1) {
|
|
|
|
|
|
prev[0] = k0;
|
|
|
|
|
|
prev[1] = k1;
|
|
|
|
|
|
prev[2] = k2;
|
2021-04-01 11:47:45 +02:00
|
|
|
|
continue;
|
2021-04-01 10:16:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Two triangles forming a quadialateral,
|
|
|
|
|
|
* prev and current triangles must have exactly 2 common vertices */
|
|
|
|
|
|
{
|
|
|
|
|
|
int cnt = 0, j = 3;
|
|
|
|
|
|
while (j--) {
|
|
|
|
|
|
int p = prev[j];
|
|
|
|
|
|
if (p == k0 || p == k1 || p == k2) {
|
|
|
|
|
|
cnt++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
is_quad = (cnt == 2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Identify vertices
|
2021-04-01 10:16:27 +02:00
|
|
|
|
if (is_quad) {
|
|
|
|
|
|
const float *xy0_, *xy1_, *xy2_;
|
|
|
|
|
|
float x0, x1, x2;
|
|
|
|
|
|
float y0, y1, y2;
|
2022-11-30 12:51:59 -08:00
|
|
|
|
xy0_ = (const float *)((const char *)xy + k0 * xy_stride);
|
|
|
|
|
|
xy1_ = (const float *)((const char *)xy + k1 * xy_stride);
|
|
|
|
|
|
xy2_ = (const float *)((const char *)xy + k2 * xy_stride);
|
|
|
|
|
|
x0 = xy0_[0];
|
|
|
|
|
|
y0 = xy0_[1];
|
|
|
|
|
|
x1 = xy1_[0];
|
|
|
|
|
|
y1 = xy1_[1];
|
|
|
|
|
|
x2 = xy2_[0];
|
|
|
|
|
|
y2 = xy2_[1];
|
2021-04-01 10:16:27 +02:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Find top-left
|
2021-04-01 10:16:27 +02:00
|
|
|
|
if (x0 <= x1 && y0 <= y1) {
|
|
|
|
|
|
if (x0 <= x2 && y0 <= y2) {
|
|
|
|
|
|
A = k0;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
A = k2;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (x1 <= x2 && y1 <= y2) {
|
|
|
|
|
|
A = k1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
A = k2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Find bottom-right
|
2021-04-01 10:16:27 +02:00
|
|
|
|
if (x0 >= x1 && y0 >= y1) {
|
|
|
|
|
|
if (x0 >= x2 && y0 >= y2) {
|
|
|
|
|
|
B = k0;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
B = k2;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (x1 >= x2 && y1 >= y2) {
|
|
|
|
|
|
B = k1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
B = k2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Find C
|
2021-04-01 10:16:27 +02:00
|
|
|
|
if (k0 != A && k0 != B) {
|
|
|
|
|
|
C = k0;
|
|
|
|
|
|
} else if (k1 != A && k1 != B) {
|
|
|
|
|
|
C = k1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
C = k2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Find C2
|
2021-04-01 10:16:27 +02:00
|
|
|
|
if (prev[0] != A && prev[0] != B) {
|
|
|
|
|
|
C2 = prev[0];
|
|
|
|
|
|
} else if (prev[1] != A && prev[1] != B) {
|
|
|
|
|
|
C2 = prev[1];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
C2 = prev[2];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
xy0_ = (const float *)((const char *)xy + A * xy_stride);
|
|
|
|
|
|
xy1_ = (const float *)((const char *)xy + B * xy_stride);
|
|
|
|
|
|
xy2_ = (const float *)((const char *)xy + C * xy_stride);
|
|
|
|
|
|
x0 = xy0_[0];
|
|
|
|
|
|
y0 = xy0_[1];
|
|
|
|
|
|
x1 = xy1_[0];
|
|
|
|
|
|
y1 = xy1_[1];
|
|
|
|
|
|
x2 = xy2_[0];
|
|
|
|
|
|
y2 = xy2_[1];
|
2021-04-01 10:16:27 +02:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Check if triangle A B C is rectangle
|
2022-11-27 17:38:43 +01:00
|
|
|
|
if ((x0 == x2 && y1 == y2) || (y0 == y2 && x1 == x2)) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// ok
|
2021-04-01 10:16:27 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
is_quad = 0;
|
2021-08-27 07:16:40 +02:00
|
|
|
|
#if DEBUG_SW_RENDER_GEOMETRY
|
2021-04-01 10:16:27 +02:00
|
|
|
|
is_rectangle = 0;
|
2021-08-27 07:16:40 +02:00
|
|
|
|
#endif
|
2021-04-01 10:16:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
xy2_ = (const float *)((const char *)xy + C2 * xy_stride);
|
|
|
|
|
|
x2 = xy2_[0];
|
|
|
|
|
|
y2 = xy2_[1];
|
2021-04-01 10:16:27 +02:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Check if triangle A B C2 is rectangle
|
2022-11-27 17:38:43 +01:00
|
|
|
|
if ((x0 == x2 && y1 == y2) || (y0 == y2 && x1 == x2)) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// ok
|
2021-04-01 10:16:27 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
is_quad = 0;
|
2021-08-27 07:16:40 +02:00
|
|
|
|
#if DEBUG_SW_RENDER_GEOMETRY
|
2021-04-01 10:16:27 +02:00
|
|
|
|
is_rectangle = 0;
|
2021-08-27 07:16:40 +02:00
|
|
|
|
#endif
|
2021-04-01 10:16:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Check if uniformly colored
|
2021-04-01 10:16:27 +02:00
|
|
|
|
if (is_quad) {
|
2024-01-29 13:28:33 -08:00
|
|
|
|
const SDL_FColor *col0_ = (const SDL_FColor *)((const char *)color + A * color_stride);
|
|
|
|
|
|
const SDL_FColor *col1_ = (const SDL_FColor *)((const char *)color + B * color_stride);
|
|
|
|
|
|
const SDL_FColor *col2_ = (const SDL_FColor *)((const char *)color + C * color_stride);
|
|
|
|
|
|
const SDL_FColor *col3_ = (const SDL_FColor *)((const char *)color + C2 * color_stride);
|
|
|
|
|
|
if (SDL_memcmp(col0_, col1_, sizeof(*col0_)) == 0 &&
|
|
|
|
|
|
SDL_memcmp(col0_, col2_, sizeof(*col0_)) == 0 &&
|
|
|
|
|
|
SDL_memcmp(col0_, col3_, sizeof(*col0_)) == 0) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// ok
|
2021-04-01 10:16:27 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
is_quad = 0;
|
2021-08-27 07:16:40 +02:00
|
|
|
|
#if DEBUG_SW_RENDER_GEOMETRY
|
2021-04-01 10:16:27 +02:00
|
|
|
|
is_uniform = 0;
|
2021-08-27 07:16:40 +02:00
|
|
|
|
#endif
|
2021-04-01 10:16:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Start rendering rect
|
2021-04-01 10:16:27 +02:00
|
|
|
|
if (is_quad) {
|
2023-03-02 08:56:54 -08:00
|
|
|
|
SDL_FRect s;
|
2021-04-01 10:16:27 +02:00
|
|
|
|
SDL_FRect d;
|
|
|
|
|
|
const float *xy0_, *xy1_, *uv0_, *uv1_;
|
2024-01-29 13:28:33 -08:00
|
|
|
|
const SDL_FColor *col0_ = (const SDL_FColor *)((const char *)color + k0 * color_stride);
|
2021-04-01 10:16:27 +02:00
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
xy0_ = (const float *)((const char *)xy + A * xy_stride);
|
|
|
|
|
|
xy1_ = (const float *)((const char *)xy + B * xy_stride);
|
2021-04-01 10:16:27 +02:00
|
|
|
|
|
|
|
|
|
|
if (texture) {
|
2022-11-30 12:51:59 -08:00
|
|
|
|
uv0_ = (const float *)((const char *)uv + A * uv_stride);
|
|
|
|
|
|
uv1_ = (const float *)((const char *)uv + B * uv_stride);
|
2023-03-02 08:56:54 -08:00
|
|
|
|
s.x = uv0_[0] * texw;
|
|
|
|
|
|
s.y = uv0_[1] * texh;
|
|
|
|
|
|
s.w = uv1_[0] * texw - s.x;
|
|
|
|
|
|
s.h = uv1_[1] * texh - s.y;
|
2023-03-30 14:02:02 -07:00
|
|
|
|
} else {
|
|
|
|
|
|
s.x = s.y = s.w = s.h = 0;
|
2021-04-01 10:16:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
d.x = xy0_[0];
|
|
|
|
|
|
d.y = xy0_[1];
|
|
|
|
|
|
d.w = xy1_[0] - d.x;
|
|
|
|
|
|
d.h = xy1_[1] - d.y;
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Rect + texture
|
2021-04-01 10:16:27 +02:00
|
|
|
|
if (texture && s.w != 0 && s.h != 0) {
|
2024-01-29 13:28:33 -08:00
|
|
|
|
SDL_SetTextureAlphaModFloat(texture, col0_->a);
|
|
|
|
|
|
SDL_SetTextureColorModFloat(texture, col0_->r, col0_->g, col0_->b);
|
2022-06-07 16:30:01 +02:00
|
|
|
|
if (s.w > 0 && s.h > 0) {
|
2022-12-31 11:19:32 -08:00
|
|
|
|
SDL_RenderTexture(renderer, texture, &s, &d);
|
2022-06-07 16:30:01 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
int flags = 0;
|
|
|
|
|
|
if (s.w < 0) {
|
|
|
|
|
|
flags |= SDL_FLIP_HORIZONTAL;
|
|
|
|
|
|
s.w *= -1;
|
|
|
|
|
|
s.x -= s.w;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (s.h < 0) {
|
|
|
|
|
|
flags |= SDL_FLIP_VERTICAL;
|
|
|
|
|
|
s.h *= -1;
|
|
|
|
|
|
s.y -= s.h;
|
|
|
|
|
|
}
|
2024-03-07 05:20:20 -08:00
|
|
|
|
SDL_RenderTextureRotated(renderer, texture, &s, &d, 0, NULL, (SDL_FlipMode)flags);
|
2022-06-07 16:30:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-27 07:16:40 +02:00
|
|
|
|
#if DEBUG_SW_RENDER_GEOMETRY
|
2024-01-29 13:28:33 -08:00
|
|
|
|
SDL_Log("Rect-COPY: RGB %f %f %f - Alpha:%f - texture=%p: src=(%d,%d, %d x %d) dst (%f, %f, %f x %f)", col0_->r, col0_->g, col0_->b, col0_->a,
|
2021-08-27 07:16:40 +02:00
|
|
|
|
(void *)texture, s.x, s.y, s.w, s.h, d.x, d.y, d.w, d.h);
|
|
|
|
|
|
#endif
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
} else if (d.w != 0.0f && d.h != 0.0f) { // Rect, no texture
|
2021-04-01 10:16:27 +02:00
|
|
|
|
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
2024-01-29 13:28:33 -08:00
|
|
|
|
SDL_SetRenderDrawColorFloat(renderer, col0_->r, col0_->g, col0_->b, col0_->a);
|
2022-12-31 11:19:32 -08:00
|
|
|
|
SDL_RenderFillRect(renderer, &d);
|
2021-08-27 07:16:40 +02:00
|
|
|
|
#if DEBUG_SW_RENDER_GEOMETRY
|
2024-01-29 13:28:33 -08:00
|
|
|
|
SDL_Log("Rect-FILL: RGB %f %f %f - Alpha:%f - texture=%p: dst (%f, %f, %f x %f)", col0_->r, col0_->g, col0_->b, col0_->a,
|
2022-06-07 16:30:01 +02:00
|
|
|
|
(void *)texture, d.x, d.y, d.w, d.h);
|
2021-04-01 10:16:27 +02:00
|
|
|
|
} else {
|
2024-01-29 13:28:33 -08:00
|
|
|
|
SDL_Log("Rect-DISMISS: RGB %f %f %f - Alpha:%f - texture=%p: src=(%d,%d, %d x %d) dst (%f, %f, %f x %f)", col0_->r, col0_->g, col0_->b, col0_->a,
|
2021-08-27 07:16:40 +02:00
|
|
|
|
(void *)texture, s.x, s.y, s.w, s.h, d.x, d.y, d.w, d.h);
|
|
|
|
|
|
#endif
|
2021-04-01 10:16:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
prev[0] = -1;
|
|
|
|
|
|
} else {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Render triangles
|
2021-04-01 10:16:27 +02:00
|
|
|
|
if (prev[0] != -1) {
|
2021-08-27 07:16:40 +02:00
|
|
|
|
#if DEBUG_SW_RENDER_GEOMETRY
|
|
|
|
|
|
SDL_Log("Triangle %d %d %d - is_uniform:%d is_rectangle:%d", prev[0], prev[1], prev[2], is_uniform, is_rectangle);
|
|
|
|
|
|
#endif
|
2021-04-01 10:16:27 +02:00
|
|
|
|
retval = QueueCmdGeometry(renderer, texture,
|
|
|
|
|
|
xy, xy_stride, color, color_stride, uv, uv_stride,
|
2023-02-03 12:25:46 -08:00
|
|
|
|
num_vertices, prev, 3, 4,
|
|
|
|
|
|
renderer->view->scale.x,
|
2024-07-17 22:49:05 -07:00
|
|
|
|
renderer->view->scale.y, SDL_TEXTURE_ADDRESS_CLAMP);
|
2021-04-01 10:16:27 +02:00
|
|
|
|
if (retval < 0) {
|
2021-04-01 12:43:39 +02:00
|
|
|
|
goto end;
|
2021-04-01 10:16:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
prev[0] = k0;
|
|
|
|
|
|
prev[1] = k1;
|
|
|
|
|
|
prev[2] = k2;
|
|
|
|
|
|
}
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
} // End for (), next triangle
|
2021-04-01 10:16:27 +02:00
|
|
|
|
|
|
|
|
|
|
if (prev[0] != -1) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// flush the last triangle
|
2021-08-27 07:16:40 +02:00
|
|
|
|
#if DEBUG_SW_RENDER_GEOMETRY
|
|
|
|
|
|
SDL_Log("Last triangle %d %d %d", prev[0], prev[1], prev[2]);
|
|
|
|
|
|
#endif
|
2021-04-01 10:16:27 +02:00
|
|
|
|
retval = QueueCmdGeometry(renderer, texture,
|
|
|
|
|
|
xy, xy_stride, color, color_stride, uv, uv_stride,
|
2023-02-03 12:25:46 -08:00
|
|
|
|
num_vertices, prev, 3, 4,
|
|
|
|
|
|
renderer->view->scale.x,
|
2024-07-17 22:49:05 -07:00
|
|
|
|
renderer->view->scale.y, SDL_TEXTURE_ADDRESS_CLAMP);
|
2021-04-01 10:16:27 +02:00
|
|
|
|
if (retval < 0) {
|
2021-04-01 12:43:39 +02:00
|
|
|
|
goto end;
|
2021-04-01 10:16:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-01 12:43:39 +02:00
|
|
|
|
end:
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Restore
|
2021-04-01 12:43:39 +02:00
|
|
|
|
SDL_SetRenderDrawBlendMode(renderer, blendMode);
|
2024-01-31 10:25:50 -08:00
|
|
|
|
SDL_SetRenderDrawColorFloat(renderer, r, g, b, a);
|
2021-04-01 12:43:39 +02:00
|
|
|
|
|
2021-04-01 10:16:27 +02:00
|
|
|
|
return retval;
|
|
|
|
|
|
}
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
#endif // SDL_VIDEO_RENDER_SW
|
2021-04-01 10:16:27 +02:00
|
|
|
|
|
Removed SDL_RenderGeometryRawFloat()
After discussion with @ocornut, SDL_RenderGeometryRaw() will take floating point colors and conversion from 8-bit color can happen on the application side. We can always add an 8-bit color fast path in the future if we need it on handheld platforms.
If you need code to do this in your application, you can use the following:
int SDL_RenderGeometryRaw8BitColor(SDL_Renderer *renderer, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices)
{
int i, retval, isstack;
const Uint8 *color2 = (const Uint8 *)color;
SDL_FColor *color3;
if (num_vertices <= 0) {
return SDL_InvalidParamError("num_vertices");
}
if (!color) {
return SDL_InvalidParamError("color");
}
color3 = (SDL_FColor *)SDL_small_alloc(SDL_FColor, num_vertices, &isstack);
if (!color3) {
return -1;
}
for (i = 0; i < num_vertices; ++i) {
color3[i].r = color->r / 255.0f;
color3[i].g = color->g / 255.0f;
color3[i].b = color->b / 255.0f;
color3[i].a = color->a / 255.0f;
color2 += color_stride;
color = (const SDL_Color *)color2;
}
retval = SDL_RenderGeometryRaw(renderer, texture, xy, xy_stride, color3, sizeof(*color3), uv, uv_stride, num_vertices, indices, num_indices, size_indices);
SDL_small_free(color3, isstack);
return retval;
}
Fixes https://github.com/libsdl-org/SDL/issues/9009
2024-06-28 23:55:23 -07:00
|
|
|
|
int SDL_RenderGeometryRaw(SDL_Renderer *renderer,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
SDL_Texture *texture,
|
|
|
|
|
|
const float *xy, int xy_stride,
|
2024-01-29 13:28:33 -08:00
|
|
|
|
const SDL_FColor *color, int color_stride,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const float *uv, int uv_stride,
|
|
|
|
|
|
int num_vertices,
|
|
|
|
|
|
const void *indices, int num_indices, int size_indices)
|
2021-03-16 15:09:34 +01:00
|
|
|
|
{
|
|
|
|
|
|
int i;
|
|
|
|
|
|
int count = indices ? num_indices : num_vertices;
|
2024-07-17 22:49:05 -07:00
|
|
|
|
SDL_TextureAddressMode texture_address_mode;
|
2021-03-16 15:09:34 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (!renderer->QueueGeometry) {
|
|
|
|
|
|
return SDL_Unsupported();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (texture) {
|
|
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (renderer != texture->renderer) {
|
|
|
|
|
|
return SDL_SetError("Texture was not created with this renderer");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!xy) {
|
2021-04-01 09:49:16 +02:00
|
|
|
|
return SDL_InvalidParamError("xy");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (!color) {
|
2021-04-01 09:49:16 +02:00
|
|
|
|
return SDL_InvalidParamError("color");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (texture && !uv) {
|
2021-04-01 09:49:16 +02:00
|
|
|
|
return SDL_InvalidParamError("uv");
|
2021-03-16 15:09:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (count % 3 != 0) {
|
|
|
|
|
|
return SDL_InvalidParamError(indices ? "num_indices" : "num_vertices");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-01 09:49:16 +02:00
|
|
|
|
if (indices) {
|
2021-04-23 12:27:35 +02:00
|
|
|
|
if (size_indices != 1 && size_indices != 2 && size_indices != 4) {
|
2021-04-23 12:00:14 +02:00
|
|
|
|
return SDL_InvalidParamError("size_indices");
|
2021-04-01 09:49:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2021-04-23 12:00:14 +02:00
|
|
|
|
size_indices = 0;
|
2021-04-01 09:49:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-08 11:44:17 -04:00
|
|
|
|
#if DONT_DRAW_WHILE_HIDDEN
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Don't draw while we're hidden
|
2021-03-16 15:09:34 +01:00
|
|
|
|
if (renderer->hidden) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2021-09-08 11:44:17 -04:00
|
|
|
|
#endif
|
2021-03-16 15:09:34 +01:00
|
|
|
|
|
|
|
|
|
|
if (num_vertices < 3) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (texture && texture->native) {
|
|
|
|
|
|
texture = texture->native;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-17 22:49:05 -07:00
|
|
|
|
texture_address_mode = renderer->texture_address_mode;
|
|
|
|
|
|
if (texture_address_mode == SDL_TEXTURE_ADDRESS_AUTO && texture) {
|
|
|
|
|
|
texture_address_mode = SDL_TEXTURE_ADDRESS_CLAMP;
|
2021-03-16 15:09:34 +01:00
|
|
|
|
for (i = 0; i < num_vertices; ++i) {
|
2022-11-30 12:51:59 -08:00
|
|
|
|
const float *uv_ = (const float *)((const char *)uv + i * uv_stride);
|
2021-04-01 09:49:16 +02:00
|
|
|
|
float u = uv_[0];
|
|
|
|
|
|
float v = uv_[1];
|
|
|
|
|
|
if (u < 0.0f || v < 0.0f || u > 1.0f || v > 1.0f) {
|
2024-07-17 22:49:05 -07:00
|
|
|
|
texture_address_mode = SDL_TEXTURE_ADDRESS_WRAP;
|
|
|
|
|
|
break;
|
2021-03-16 15:09:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (indices) {
|
|
|
|
|
|
for (i = 0; i < num_indices; ++i) {
|
2021-04-01 09:49:16 +02:00
|
|
|
|
int j;
|
2021-04-23 12:00:14 +02:00
|
|
|
|
if (size_indices == 4) {
|
2021-04-01 09:49:16 +02:00
|
|
|
|
j = ((const Uint32 *)indices)[i];
|
2021-04-23 12:00:14 +02:00
|
|
|
|
} else if (size_indices == 2) {
|
2021-04-01 09:49:16 +02:00
|
|
|
|
j = ((const Uint16 *)indices)[i];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
j = ((const Uint8 *)indices)[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
if (j < 0 || j >= num_vertices) {
|
2021-03-16 15:09:34 +01:00
|
|
|
|
return SDL_SetError("Values of 'indices' out of bounds");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (texture) {
|
|
|
|
|
|
texture->last_command_generation = renderer->render_command_generation;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// For the software renderer, try to reinterpret triangles as SDL_Rect
|
2024-03-13 04:15:46 +00:00
|
|
|
|
#if SDL_VIDEO_RENDER_SW
|
2024-07-17 22:49:05 -07:00
|
|
|
|
if (renderer->software && texture_address_mode == SDL_TEXTURE_ADDRESS_CLAMP) {
|
2021-04-01 10:16:27 +02:00
|
|
|
|
return SDL_SW_RenderGeometryRaw(renderer, texture,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
xy, xy_stride, color, color_stride, uv, uv_stride, num_vertices,
|
|
|
|
|
|
indices, num_indices, size_indices);
|
2021-04-01 10:16:27 +02:00
|
|
|
|
}
|
2024-03-13 04:15:46 +00:00
|
|
|
|
#endif
|
2021-04-01 10:16:27 +02:00
|
|
|
|
|
2024-02-03 12:33:55 -08:00
|
|
|
|
return QueueCmdGeometry(renderer, texture,
|
2022-11-30 12:51:59 -08:00
|
|
|
|
xy, xy_stride, color, color_stride, uv, uv_stride,
|
|
|
|
|
|
num_vertices,
|
|
|
|
|
|
indices, num_indices, size_indices,
|
2023-02-03 12:25:46 -08:00
|
|
|
|
renderer->view->scale.x,
|
2024-07-17 22:49:05 -07:00
|
|
|
|
renderer->view->scale.y, texture_address_mode);
|
2021-03-16 15:09:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-03 10:18:12 -08:00
|
|
|
|
SDL_Surface *SDL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Rect real_rect;
|
2024-02-19 08:45:02 -08:00
|
|
|
|
SDL_Surface *surface;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2024-02-03 10:18:12 -08:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, NULL);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
if (!renderer->RenderReadPixels) {
|
2024-02-03 10:18:12 -08:00
|
|
|
|
SDL_Unsupported();
|
|
|
|
|
|
return NULL;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
FlushRenderCommands(renderer); // we need to render before we read the results.
|
2018-09-20 15:46:02 -04:00
|
|
|
|
|
2024-06-12 09:21:02 -07:00
|
|
|
|
real_rect = renderer->view->pixel_viewport;
|
2023-02-03 12:25:46 -08:00
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (rect) {
|
2022-12-27 11:01:11 -08:00
|
|
|
|
if (!SDL_GetRectIntersection(rect, &real_rect, &real_rect)) {
|
2024-02-03 10:18:12 -08:00
|
|
|
|
return NULL;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-19 08:45:02 -08:00
|
|
|
|
surface = renderer->RenderReadPixels(renderer, &real_rect);
|
|
|
|
|
|
if (surface) {
|
|
|
|
|
|
SDL_PropertiesID props = SDL_GetSurfaceProperties(surface);
|
|
|
|
|
|
|
|
|
|
|
|
if (renderer->target) {
|
|
|
|
|
|
SDL_SetFloatProperty(props, SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT, renderer->target->SDR_white_point);
|
|
|
|
|
|
SDL_SetFloatProperty(props, SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT, renderer->target->HDR_headroom);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
SDL_SetFloatProperty(props, SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT, renderer->SDR_white_point);
|
|
|
|
|
|
SDL_SetFloatProperty(props, SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT, renderer->HDR_headroom);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return surface;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-09 07:09:59 -08:00
|
|
|
|
static void SDL_RenderApplyWindowShape(SDL_Renderer *renderer)
|
|
|
|
|
|
{
|
2024-07-12 09:39:58 -07:00
|
|
|
|
SDL_Surface *shape = (SDL_Surface *)SDL_GetPointerProperty(SDL_GetWindowProperties(renderer->window), SDL_PROP_WINDOW_SHAPE_POINTER, NULL);
|
2024-02-09 07:09:59 -08:00
|
|
|
|
if (shape != renderer->shape_surface) {
|
|
|
|
|
|
if (renderer->shape_texture) {
|
|
|
|
|
|
SDL_DestroyTexture(renderer->shape_texture);
|
|
|
|
|
|
renderer->shape_texture = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (shape) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// There's nothing we can do if this fails, so just keep on going
|
2024-02-09 07:09:59 -08:00
|
|
|
|
renderer->shape_texture = SDL_CreateTextureFromSurface(renderer, shape);
|
|
|
|
|
|
|
|
|
|
|
|
SDL_SetTextureBlendMode(renderer->shape_texture,
|
|
|
|
|
|
SDL_ComposeCustomBlendMode(
|
|
|
|
|
|
SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDOPERATION_ADD,
|
|
|
|
|
|
SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDOPERATION_ADD));
|
|
|
|
|
|
}
|
|
|
|
|
|
renderer->shape_surface = shape;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (renderer->shape_texture) {
|
|
|
|
|
|
SDL_RenderTexture(renderer, renderer->shape_texture, NULL, NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-27 15:05:51 -08:00
|
|
|
|
static void SDL_SimulateRenderVSync(SDL_Renderer *renderer)
|
2022-09-15 01:00:12 -07:00
|
|
|
|
{
|
2022-12-02 01:17:17 -08:00
|
|
|
|
Uint64 now, elapsed;
|
|
|
|
|
|
const Uint64 interval = renderer->simulate_vsync_interval_ns;
|
2022-09-15 01:00:12 -07:00
|
|
|
|
|
|
|
|
|
|
if (!interval) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// We can't do sub-ns delay, so just return here
|
2022-09-15 01:00:12 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-02 01:17:17 -08:00
|
|
|
|
now = SDL_GetTicksNS();
|
2022-09-15 01:00:12 -07:00
|
|
|
|
elapsed = (now - renderer->last_present);
|
|
|
|
|
|
if (elapsed < interval) {
|
2022-12-02 01:17:17 -08:00
|
|
|
|
Uint64 duration = (interval - elapsed);
|
|
|
|
|
|
SDL_DelayNS(duration);
|
|
|
|
|
|
now = SDL_GetTicksNS();
|
2022-09-15 01:00:12 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-15 07:05:55 -07:00
|
|
|
|
elapsed = (now - renderer->last_present);
|
2022-12-04 09:28:03 -08:00
|
|
|
|
if (!renderer->last_present || elapsed > SDL_MS_TO_NS(1000)) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// It's been too long, reset the presentation timeline
|
2022-09-15 01:00:12 -07:00
|
|
|
|
renderer->last_present = now;
|
2022-09-15 07:05:55 -07:00
|
|
|
|
} else {
|
|
|
|
|
|
renderer->last_present += (elapsed / interval) * interval;
|
2022-09-15 01:00:12 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-06 20:24:12 +01:00
|
|
|
|
int SDL_RenderPresent(SDL_Renderer *renderer)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-08-22 09:21:26 -07:00
|
|
|
|
bool presented = true;
|
2022-09-15 01:00:12 -07:00
|
|
|
|
|
2023-02-06 20:24:12 +01:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->logical_target) {
|
|
|
|
|
|
SDL_SetRenderTargetInternal(renderer, NULL);
|
2023-07-03 18:29:48 -07:00
|
|
|
|
SDL_RenderLogicalPresentation(renderer);
|
2023-02-03 12:25:46 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-09 07:09:59 -08:00
|
|
|
|
if (renderer->transparent_window) {
|
|
|
|
|
|
SDL_RenderApplyWindowShape(renderer);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
FlushRenderCommands(renderer); // time to send everything to the GPU!
|
2018-09-20 15:46:02 -04:00
|
|
|
|
|
2021-04-02 14:01:41 -04:00
|
|
|
|
#if DONT_DRAW_WHILE_HIDDEN
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Don't present while we're hidden
|
2015-06-21 17:33:46 +02:00
|
|
|
|
if (renderer->hidden) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
presented = false;
|
2022-09-15 01:00:12 -07:00
|
|
|
|
} else
|
2021-04-02 14:01:41 -04:00
|
|
|
|
#endif
|
2023-02-03 12:25:46 -08:00
|
|
|
|
if (renderer->RenderPresent(renderer) < 0) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
presented = false;
|
2022-09-15 01:00:12 -07:00
|
|
|
|
}
|
2021-04-02 14:01:41 -04:00
|
|
|
|
|
2023-03-08 22:55:44 -05:00
|
|
|
|
if (renderer->logical_target) {
|
|
|
|
|
|
SDL_SetRenderTargetInternal(renderer, renderer->logical_target);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
if (renderer->simulate_vsync ||
|
2022-09-15 01:00:12 -07:00
|
|
|
|
(!presented && renderer->wanted_vsync)) {
|
2022-12-27 15:05:51 -08:00
|
|
|
|
SDL_SimulateRenderVSync(renderer);
|
2022-09-15 01:00:12 -07:00
|
|
|
|
}
|
2023-02-06 20:24:12 +01:00
|
|
|
|
return 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
|
static int SDL_DestroyTextureInternal(SDL_Texture *texture, bool is_destroying)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
|
|
|
2023-02-06 20:24:12 +01:00
|
|
|
|
CHECK_TEXTURE_MAGIC(texture, -1);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
2023-10-11 16:59:51 -07:00
|
|
|
|
SDL_DestroyProperties(texture->props);
|
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
|
renderer = texture->renderer;
|
2023-02-05 20:29:33 +01:00
|
|
|
|
if (is_destroying) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Renderer get destroyed, avoid to queue more commands
|
2018-09-20 15:46:02 -04:00
|
|
|
|
} else {
|
2023-02-05 20:29:33 +01:00
|
|
|
|
if (texture == renderer->target) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
SDL_SetRenderTargetInternal(renderer, NULL); // implies command queue flush
|
2023-07-03 18:29:48 -07:00
|
|
|
|
|
|
|
|
|
|
if (texture == renderer->logical_target) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Complete any logical presentation
|
2023-07-03 18:29:48 -07:00
|
|
|
|
SDL_RenderLogicalPresentation(renderer);
|
|
|
|
|
|
FlushRenderCommands(renderer);
|
|
|
|
|
|
}
|
2023-02-05 20:29:33 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
FlushRenderCommandsIfTextureNeeded(texture);
|
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-05 08:35:40 -08:00
|
|
|
|
if (texture == renderer->logical_target) {
|
|
|
|
|
|
renderer->logical_target = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
|
SDL_SetObjectValid(texture, SDL_OBJECT_TYPE_TEXTURE, false);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
|
|
if (texture->next) {
|
|
|
|
|
|
texture->next->prev = texture->prev;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (texture->prev) {
|
|
|
|
|
|
texture->prev->next = texture->next;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
renderer->textures = texture->next;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-06 00:40:22 -08:00
|
|
|
|
if (texture->native) {
|
2023-02-05 20:29:33 +01:00
|
|
|
|
SDL_DestroyTextureInternal(texture->native, is_destroying);
|
2017-01-06 00:40:22 -08:00
|
|
|
|
}
|
2020-01-21 21:33:40 +01:00
|
|
|
|
#if SDL_HAVE_YUV
|
2017-01-06 00:40:22 -08:00
|
|
|
|
if (texture->yuv) {
|
|
|
|
|
|
SDL_SW_DestroyYUVTexture(texture->yuv);
|
|
|
|
|
|
}
|
2020-01-21 21:33:40 +01:00
|
|
|
|
#endif
|
2017-01-06 00:40:22 -08:00
|
|
|
|
SDL_free(texture->pixels);
|
|
|
|
|
|
|
|
|
|
|
|
renderer->DestroyTexture(renderer, texture);
|
2019-09-30 20:58:44 +02:00
|
|
|
|
|
2022-12-27 06:36:39 -08:00
|
|
|
|
SDL_DestroySurface(texture->locked_surface);
|
2019-09-30 20:58:44 +02:00
|
|
|
|
texture->locked_surface = NULL;
|
|
|
|
|
|
|
2017-01-06 00:40:22 -08:00
|
|
|
|
SDL_free(texture);
|
2023-02-06 20:24:12 +01:00
|
|
|
|
return 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-09 16:53:47 +01:00
|
|
|
|
void SDL_DestroyTexture(SDL_Texture *texture)
|
2015-06-21 17:33:46 +02:00
|
|
|
|
{
|
2024-08-22 09:21:26 -07:00
|
|
|
|
SDL_DestroyTextureInternal(texture, false /* is_destroying */);
|
2023-02-05 20:29:33 +01:00
|
|
|
|
}
|
2023-02-05 08:35:40 -08:00
|
|
|
|
|
2023-02-05 20:29:33 +01:00
|
|
|
|
static void SDL_DiscardAllCommands(SDL_Renderer *renderer)
|
|
|
|
|
|
{
|
|
|
|
|
|
SDL_RenderCommand *cmd;
|
2023-02-05 08:35:40 -08:00
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
if (renderer->render_commands_tail) {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
renderer->render_commands_tail->next = renderer->render_commands_pool;
|
|
|
|
|
|
cmd = renderer->render_commands;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
cmd = renderer->render_commands_pool;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
renderer->render_commands_pool = NULL;
|
|
|
|
|
|
renderer->render_commands_tail = NULL;
|
|
|
|
|
|
renderer->render_commands = NULL;
|
|
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
|
while (cmd) {
|
2018-09-20 15:46:02 -04:00
|
|
|
|
SDL_RenderCommand *next = cmd->next;
|
|
|
|
|
|
SDL_free(cmd);
|
|
|
|
|
|
cmd = next;
|
|
|
|
|
|
}
|
2023-02-05 20:29:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-18 10:20:31 -04:00
|
|
|
|
void SDL_DestroyRendererWithoutFreeing(SDL_Renderer *renderer)
|
2023-02-05 20:29:33 +01:00
|
|
|
|
{
|
2024-04-18 10:20:31 -04:00
|
|
|
|
SDL_assert(renderer != NULL);
|
|
|
|
|
|
SDL_assert(!renderer->destroyed);
|
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->destroyed = true;
|
2023-02-05 20:29:33 +01:00
|
|
|
|
|
|
|
|
|
|
SDL_DelEventWatch(SDL_RendererEventWatch, renderer);
|
|
|
|
|
|
|
2024-07-27 13:36:12 -07:00
|
|
|
|
if (renderer->window) {
|
|
|
|
|
|
SDL_PropertiesID props = SDL_GetWindowProperties(renderer->window);
|
|
|
|
|
|
if (SDL_GetPointerProperty(props, SDL_PROP_WINDOW_RENDERER_POINTER, NULL) == renderer) {
|
|
|
|
|
|
SDL_ClearProperty(props, SDL_PROP_WINDOW_RENDERER_POINTER);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-05 20:29:33 +01:00
|
|
|
|
SDL_DiscardAllCommands(renderer);
|
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Free existing textures for this renderer
|
2023-02-05 20:29:33 +01:00
|
|
|
|
while (renderer->textures) {
|
|
|
|
|
|
SDL_Texture *tex = renderer->textures;
|
2024-08-22 09:21:26 -07:00
|
|
|
|
SDL_DestroyTextureInternal(renderer->textures, true /* is_destroying */);
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
SDL_assert(tex != renderer->textures); // satisfy static analysis.
|
2023-02-05 20:29:33 +01:00
|
|
|
|
}
|
2018-09-20 15:46:02 -04:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// Clean up renderer-specific resources
|
2024-07-27 13:36:12 -07:00
|
|
|
|
if (renderer->DestroyRenderer) {
|
|
|
|
|
|
renderer->DestroyRenderer(renderer);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-27 13:36:12 -07:00
|
|
|
|
if (renderer->target_mutex) {
|
|
|
|
|
|
SDL_DestroyMutex(renderer->target_mutex);
|
|
|
|
|
|
renderer->target_mutex = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (renderer->vertex_data) {
|
|
|
|
|
|
SDL_free(renderer->vertex_data);
|
|
|
|
|
|
renderer->vertex_data = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (renderer->texture_formats) {
|
|
|
|
|
|
SDL_free(renderer->texture_formats);
|
|
|
|
|
|
renderer->texture_formats = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (renderer->props) {
|
|
|
|
|
|
SDL_DestroyProperties(renderer->props);
|
|
|
|
|
|
renderer->props = 0;
|
|
|
|
|
|
}
|
2024-04-18 10:20:31 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SDL_DestroyRenderer(SDL_Renderer *renderer)
|
|
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC_BUT_NOT_DESTROYED_FLAG(renderer,);
|
|
|
|
|
|
|
|
|
|
|
|
// if we've already destroyed the renderer through SDL_DestroyWindow, we just need
|
|
|
|
|
|
// to free the renderer pointer. This lets apps destroy the window and renderer
|
|
|
|
|
|
// in either order.
|
|
|
|
|
|
if (!renderer->destroyed) {
|
|
|
|
|
|
SDL_DestroyRendererWithoutFreeing(renderer);
|
|
|
|
|
|
}
|
2024-06-23 00:41:19 -07:00
|
|
|
|
|
|
|
|
|
|
SDL_Renderer *curr = SDL_renderers;
|
|
|
|
|
|
SDL_Renderer *prev = NULL;
|
|
|
|
|
|
while (curr) {
|
|
|
|
|
|
if (curr == renderer) {
|
|
|
|
|
|
if (prev) {
|
|
|
|
|
|
prev->next = renderer->next;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
SDL_renderers = renderer->next;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
prev = curr;
|
|
|
|
|
|
curr = curr->next;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
|
SDL_SetObjectValid(renderer, SDL_OBJECT_TYPE_RENDERER, false); // It's no longer magical...
|
2024-04-18 10:16:50 -04:00
|
|
|
|
|
|
|
|
|
|
SDL_free(renderer);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
void *SDL_GetRenderMetalLayer(SDL_Renderer *renderer)
|
2017-12-08 14:30:10 -08:00
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
if (renderer->GetMetalLayer) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
FlushRenderCommands(renderer); // in case the app is going to mess with it.
|
2017-12-08 14:30:10 -08:00
|
|
|
|
return renderer->GetMetalLayer(renderer);
|
|
|
|
|
|
}
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
void *SDL_GetRenderMetalCommandEncoder(SDL_Renderer *renderer)
|
2017-12-08 14:30:10 -08:00
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
if (renderer->GetMetalCommandEncoder) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
FlushRenderCommands(renderer); // in case the app is going to mess with it.
|
2017-12-08 14:30:10 -08:00
|
|
|
|
return renderer->GetMetalCommandEncoder(renderer);
|
|
|
|
|
|
}
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-02 10:03:37 -08:00
|
|
|
|
int SDL_AddVulkanRenderSemaphores(SDL_Renderer *renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore)
|
|
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
|
|
|
|
|
if (!renderer->AddVulkanRenderSemaphores) {
|
|
|
|
|
|
return SDL_Unsupported();
|
|
|
|
|
|
}
|
|
|
|
|
|
return renderer->AddVulkanRenderSemaphores(renderer, wait_stage_mask, wait_semaphore, signal_semaphore);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static SDL_BlendMode SDL_GetShortBlendMode(SDL_BlendMode blendMode)
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
{
|
2017-08-14 20:07:30 -07:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_NONE_FULL) {
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
return SDL_BLENDMODE_NONE;
|
2017-08-14 20:07:30 -07:00
|
|
|
|
}
|
|
|
|
|
|
if (blendMode == SDL_BLENDMODE_BLEND_FULL) {
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
return SDL_BLENDMODE_BLEND;
|
2017-08-14 20:07:30 -07:00
|
|
|
|
}
|
2024-07-15 08:27:58 -07:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_BLEND_PREMULTIPLIED_FULL) {
|
|
|
|
|
|
return SDL_BLENDMODE_BLEND_PREMULTIPLIED;
|
|
|
|
|
|
}
|
2017-08-14 20:07:30 -07:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_ADD_FULL) {
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
return SDL_BLENDMODE_ADD;
|
2017-08-14 20:07:30 -07:00
|
|
|
|
}
|
2024-07-15 08:27:58 -07:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_ADD_PREMULTIPLIED_FULL) {
|
|
|
|
|
|
return SDL_BLENDMODE_ADD_PREMULTIPLIED;
|
|
|
|
|
|
}
|
2017-08-14 20:07:30 -07:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_MOD_FULL) {
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
return SDL_BLENDMODE_MOD;
|
|
|
|
|
|
}
|
2020-01-16 08:52:59 -08:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_MUL_FULL) {
|
|
|
|
|
|
return SDL_BLENDMODE_MUL;
|
|
|
|
|
|
}
|
2017-08-14 20:07:30 -07:00
|
|
|
|
return blendMode;
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
|
static SDL_BlendMode SDL_GetLongBlendMode(SDL_BlendMode blendMode)
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
{
|
2017-08-14 20:07:30 -07:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_NONE) {
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
return SDL_BLENDMODE_NONE_FULL;
|
2017-08-14 20:07:30 -07:00
|
|
|
|
}
|
|
|
|
|
|
if (blendMode == SDL_BLENDMODE_BLEND) {
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
return SDL_BLENDMODE_BLEND_FULL;
|
2017-08-14 20:07:30 -07:00
|
|
|
|
}
|
2024-07-15 08:27:58 -07:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_BLEND_PREMULTIPLIED) {
|
|
|
|
|
|
return SDL_BLENDMODE_BLEND_PREMULTIPLIED_FULL;
|
|
|
|
|
|
}
|
2017-08-14 20:07:30 -07:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_ADD) {
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
return SDL_BLENDMODE_ADD_FULL;
|
2017-08-14 20:07:30 -07:00
|
|
|
|
}
|
2024-07-15 08:27:58 -07:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_ADD_PREMULTIPLIED) {
|
|
|
|
|
|
return SDL_BLENDMODE_ADD_PREMULTIPLIED_FULL;
|
|
|
|
|
|
}
|
2017-08-14 20:07:30 -07:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_MOD) {
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
return SDL_BLENDMODE_MOD_FULL;
|
|
|
|
|
|
}
|
2020-01-16 08:52:59 -08:00
|
|
|
|
if (blendMode == SDL_BLENDMODE_MUL) {
|
|
|
|
|
|
return SDL_BLENDMODE_MUL_FULL;
|
|
|
|
|
|
}
|
2017-08-14 20:07:30 -07:00
|
|
|
|
return blendMode;
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_BlendMode SDL_ComposeCustomBlendMode(SDL_BlendFactor srcColorFactor, SDL_BlendFactor dstColorFactor,
|
|
|
|
|
|
SDL_BlendOperation colorOperation,
|
|
|
|
|
|
SDL_BlendFactor srcAlphaFactor, SDL_BlendFactor dstAlphaFactor,
|
|
|
|
|
|
SDL_BlendOperation alphaOperation)
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
{
|
|
|
|
|
|
SDL_BlendMode blendMode = SDL_COMPOSE_BLENDMODE(srcColorFactor, dstColorFactor, colorOperation,
|
|
|
|
|
|
srcAlphaFactor, dstAlphaFactor, alphaOperation);
|
|
|
|
|
|
return SDL_GetShortBlendMode(blendMode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode)
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
{
|
|
|
|
|
|
blendMode = SDL_GetLongBlendMode(blendMode);
|
|
|
|
|
|
return (SDL_BlendFactor)(((Uint32)blendMode >> 4) & 0xF);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_BlendFactor SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode)
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
{
|
|
|
|
|
|
blendMode = SDL_GetLongBlendMode(blendMode);
|
|
|
|
|
|
return (SDL_BlendFactor)(((Uint32)blendMode >> 8) & 0xF);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_BlendOperation SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode)
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
{
|
|
|
|
|
|
blendMode = SDL_GetLongBlendMode(blendMode);
|
|
|
|
|
|
return (SDL_BlendOperation)(((Uint32)blendMode >> 0) & 0xF);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_BlendFactor SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode)
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
{
|
|
|
|
|
|
blendMode = SDL_GetLongBlendMode(blendMode);
|
|
|
|
|
|
return (SDL_BlendFactor)(((Uint32)blendMode >> 20) & 0xF);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_BlendFactor SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode)
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
{
|
|
|
|
|
|
blendMode = SDL_GetLongBlendMode(blendMode);
|
|
|
|
|
|
return (SDL_BlendFactor)(((Uint32)blendMode >> 24) & 0xF);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-03 12:25:46 -08:00
|
|
|
|
SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode)
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
{
|
|
|
|
|
|
blendMode = SDL_GetLongBlendMode(blendMode);
|
2017-08-14 20:37:07 -07:00
|
|
|
|
return (SDL_BlendOperation)(((Uint32)blendMode >> 16) & 0xF);
|
Implemented more flexible blending modes for accelerated renderers
This fixes bug 2594 - Propose new blend mode, SDL_BLENDMODE_BLEND_DSTA
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD);
This fixes bug 2828 - Subtractive Blending
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT,
SDL_BLENDFACTOR_ZERO,
SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_SUBTRACT);
This goes partway to fixing bug 3684 - Add support for a pre-multiplied alpha blending mode
blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD,
SDL_BLENDFACTOR_ONE,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
SDL_BLENDOPERATION_ADD);
2017-08-14 05:51:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-27 06:21:13 -08:00
|
|
|
|
int SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync)
|
2021-03-07 15:20:45 -08:00
|
|
|
|
{
|
|
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->wanted_vsync = vsync ? true : false;
|
2022-09-15 01:00:12 -07:00
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
|
// for the software renderer, forward the call to the WindowTexture renderer
|
2024-03-13 04:15:46 +00:00
|
|
|
|
#if SDL_VIDEO_RENDER_SW
|
2024-04-04 12:39:24 -07:00
|
|
|
|
if (renderer->software) {
|
2024-05-27 10:27:17 -07:00
|
|
|
|
if (!renderer->window) {
|
2024-07-13 10:04:15 -07:00
|
|
|
|
if (!vsync) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return SDL_Unsupported();
|
|
|
|
|
|
}
|
2024-05-27 10:27:17 -07:00
|
|
|
|
}
|
|
|
|
|
|
if (SDL_SetWindowTextureVSync(NULL, renderer->window, vsync) == 0) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->simulate_vsync = false;
|
2023-01-01 23:05:25 +01:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-13 04:15:46 +00:00
|
|
|
|
#endif
|
2023-01-01 23:05:25 +01:00
|
|
|
|
|
2024-05-13 10:31:55 -07:00
|
|
|
|
if (!renderer->SetVSync) {
|
|
|
|
|
|
switch (vsync) {
|
|
|
|
|
|
case 0:
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->simulate_vsync = false;
|
2024-05-13 10:31:55 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->simulate_vsync = true;
|
2024-05-13 10:31:55 -07:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
return SDL_Unsupported();
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (renderer->SetVSync(renderer, vsync) < 0) {
|
|
|
|
|
|
if (vsync == 1) {
|
2024-08-22 09:21:26 -07:00
|
|
|
|
renderer->simulate_vsync = true;
|
2023-03-18 00:39:02 +03:00
|
|
|
|
} else {
|
2024-05-13 10:31:55 -07:00
|
|
|
|
return -1;
|
2023-03-18 00:39:02 +03:00
|
|
|
|
}
|
2021-03-07 15:20:45 -08:00
|
|
|
|
}
|
2024-05-13 10:31:55 -07:00
|
|
|
|
SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_VSYNC_NUMBER, vsync);
|
2022-09-15 01:00:12 -07:00
|
|
|
|
return 0;
|
2021-03-07 15:20:45 -08:00
|
|
|
|
}
|
2023-01-02 20:21:02 +01:00
|
|
|
|
|
|
|
|
|
|
int SDL_GetRenderVSync(SDL_Renderer *renderer, int *vsync)
|
|
|
|
|
|
{
|
2024-07-17 10:10:31 -07:00
|
|
|
|
if (vsync) {
|
|
|
|
|
|
*vsync = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-02 20:21:02 +01:00
|
|
|
|
CHECK_RENDERER_MAGIC(renderer, -1);
|
2024-07-17 10:10:31 -07:00
|
|
|
|
|
|
|
|
|
|
if (vsync) {
|
|
|
|
|
|
*vsync = (int)SDL_GetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_VSYNC_NUMBER, 0);
|
2023-01-02 20:21:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|