src/render/SDL_render.c


Log

Author Commit Date CI Message
Ozkan Sezer e18be04b 2021-11-23T08:01:02 Fixed undefined behavior in QueueCmdSetDrawColor() Fixes https://github.com/libsdl-org/SDL/issues/4995 Patch from Andrew Kelley
Sylvain 161dd83c 2021-11-22T11:15:23 DonĀ“t use "trunc" as var name, since it's also a function
Sylvain 49369142 2021-11-21T17:40:48 Fixed bug #4625: with integer scale, viewport (as reported by SDL_RenderGetViewport) becomes -2147483648x-2147483648 0 isn't valid scale. Min integer scale is 1.0f
Sylvain 70c8d20a 2021-11-13T15:04:19 Revert previous commit a50ca98e2b9ca10368b62e93b6a0977dc68fd584 (see bug #4625)
Sylvain a50ca98e 2021-11-13T14:48:36 Fixed bug #4625 - SDL_RenderSetLogicalSize issues viewport becomes -2147483648x-2147483648 when logical_w/h is greater than window size. division should be done with floats
Sam Lantinga 6c4b4ee7 2021-11-10T09:41:43 Don't assert on API parameters This causes lots of spam in test automation and it's not clear it's useful to developers. If we need this level of validation, we should add a log category for it.
Eric Wasylishen 0d987936 2021-11-09T22:03:42 testwm2: Fix video modes menu hit detection when highdpi or logical size used (#4936) * SDLTest_CommonDrawWindowInfo: log SDL_RenderGetScale, SDL_RenderGetLogicalSize * testwm2: fix video modes menu hit detection in High DPI cases - also when logical size is specified, e.g. `--logical 640x480 --resizable --allow-highdpi` * add function to determine logical coordinates of renderer point when given window point * change since to the targeted milestone * fix typo * rename for consistency * Change logical coordinate type to float, since we can render with floating point precision. * add function to convert logical to window coordinates * testwm2: use new SDL_RenderWindowToLogical * SDL_render.c: alternate SDL_RenderWindowToLogical/SDL_RenderLogicalToWindow Co-authored-by: John Blat <johnblat64@protonmail.com> Co-authored-by: John Blat <47202511+johnblat64@users.noreply.github.com>
Sylvain 4960cc3d 2021-10-25T16:18:40 Fixed a few warnings
Sylvain b7933945 2021-10-25T13:46:40 SDL_Renderer: make clear that we use render geometry for fillrect/copy/copyex when there is no specific back-end implementation (currently software, PSP, directfb)
Sylvain 502e9c3b 2021-10-24T17:16:49 SDL_Renderer simplifications: - Factorize PrepQueueCmdDraw{,DrawTexture,Solid) into one single function - Change SDL_Texture/Renderer r,g,b,a Uint8 into an SDL_Color, so that it can be passed directly to RenderGeometry - Don't automatically queue a SET_DRAW_COLOR cmd for RenderGeometry (and update GLES2 renderer)
Sylvain 70b10c75 2021-09-24T22:39:49 Use correct indices when using RenderGeometry / FillRects
Sylvain 16beed9a 2021-09-24T17:09:04 Less code since color is constant when done with triangles
Sylvain 37c39d5c 2021-09-23T22:45:45 Use geometry to implement FillRects
Sylvain 76f9fb96 2021-09-20T16:32:08 Use RenderGeometry to implement RenderCopy and RenderCopyEx at higher level
Sylvain 77acd44f 2021-10-01T22:30:51 DirectFB: fixed creation of palette textures
Ryan C. Gordon 857cc7c0 2021-09-19T00:05:21 render: constified some local variables in SDL_AllocateRenderVertices.
Misa 4a994733 2021-09-14T15:51:17 `SDL_RenderSetVSync()`: Restrict `vsync` to 0 or 1 In the future, we might want to support special swap intervals. To prevent applications from expecting nonzero values of vsync to be the same as "on", fail with SDL_Unsupported() if the value passed is neither 0 nor 1.
Misa 4549769d 2021-03-07T15:20:45 Add `SDL_RenderSetVSync()` Currently, if an application wants to toggle VSync, they'd have to tear down the renderer and recreate it. This patch fixes that by letting applications call SDL_RenderSetVSync(). This is the same as the patch in #3673, except it applies to all renderers (including PSP, even thought it seems that the VSync flag is disabled for that renderer). Furthermore, the renderer flags also change as well, which #3673 didn't do. It is also an API instead of using hint callbacks (which could be potentially dangerous). Closes #3673.
Ryan C. Gordon d49d955d 2021-09-08T11:44:17 render: SDL_RenderGeometry should still render when hidden, in most cases. (otherwise render targets may fail, etc...the check is a legacy helper for iOS apps that crash if you try to use OpenGL while in the background.)
Sylvain be6bee0b 2021-08-27T07:47:28 SW_RenderGeometry: add a redundant check to clear static analysis (see bug #4600)
Sylvain b17aa5d0 2021-08-27T07:16:40 SW_RenderGeometry: remove a few static analysis false positives (see bug #4600)
Ozkan Sezer 8270172e 2021-08-19T12:11:10 fix -Wshorten-64-to-32 warnings in android builds. see: https://github.com/libsdl-org/SDL/pull/4195#issuecomment-901506386
Sylvain 1670104a 2021-04-23T12:27:35 Change 'size_indice' to 'size_indices'
Sylvain a8f89a01 2021-04-23T12:00:14 Change 'size_indice' to 'size_indices'
Sylvain 47db47c1 2021-04-06T21:32:02 Add SDL_HAVE_RENDER_GEOMETRY to compile or not with RenderGeometry support
Sylvain 6e47f538 2021-04-01T20:18:05 Fix warnings
Sylvain 4ba37638 2021-04-01T12:43:39 Save and restore SDL renderer state after transforming triangles to rect
Sylvain cd0663e0 2021-04-01T11:47:45 Fix declaration-after-statement and remove tabs
Sylvain 61d9e916 2021-04-01T10:16:27 For the software renderer, try to reinterpret triangles as SDL_Rect With Dear ImGui + software renderer, it draws: - by default at 250 fps - drops to 70 fps if you show the color picker - drops to 10 fps if put the color picker fullscreen
Sylvain cc37c38e 2021-04-01T09:55:00 Add SDL_RenderGeometry based on SDL_RenderGeometryRaw
Sylvain e4812611 2021-04-01T09:49:16 Move to SDL_RenderGeometryRaw prototype with separate xy/uv/color pointer parameters
Sylvain f73c1eff 2021-03-17T09:58:49 Use normalized texture coordinates
Sylvain 6e26d320 2021-03-16T15:09:34 Add sysrender interface
Sam Lantinga f5794f9e 2021-08-10T15:17:59 Added SDL_SetTextureUserData() and SDL_GetTextureUserData() to associate a user-specified pointer with an SDL texture
Sam Lantinga fcfd19db 2021-08-10T12:02:17 Added support for SDL_RENDERER_PRESENTVSYNC to the software renderer This fixes https://github.com/libsdl-org/SDL/issues/4612
David Gow 4077f7a2 2021-08-03T20:55:45 Update the Renderer dpi_scale on SIZE_CHANGED event (fix #4580) The Renderer logical scaling code scales mouse coordinates, and needs to take the window DPI into account on HIGHDPI windows. However, the variable which tracks this, renderer->dpi_scale, is set once when the renderer is created, and then not updated. In the event that the window is moved to another screen, or the screen DPI otherwise changes, this will be outdates, and potentially the coordinates will be all wrong. So let's update the dpi_scale on the SIZE_CHANGED event: it's at least a possibility that this will be issued on some OSes when DPI changes, and it's otherwise already handled by SDL_Renderer's event filter.
David Gow 8f06a629 2021-07-30T22:31:17 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.
Ivan Epifanov dd2a2858 2021-06-10T12:00:56 Remove leftovers
Sylvain e87c7940 2021-04-13T14:42:38 Fixed bug 3829 - Don't FOURCC format for target textures FOURCC isn't supported by renderer back-ends for target access So use a correct format and fallback to with native/yuv path
Ryan C. Gordon 57c2a456 2021-04-02T14:01:41 render: draw when hidden, except on iOS and Android. Fixes #2979.
Vanfanel e14fb54e 2021-03-16T10:47:57 [KMSDRM] Undo SDL_CreateRenderer() modifications aimed at create opengles2 when KMSDRM is in use because it's a harmful solution.
Vanfanel 108bb5aa 2021-03-16T00:51:17 [KMSDRM] Modify SDL_CreateRenderer() to create an opengles2 renderer when the KMSDRM backend is being used and no renderer name has been specified.
Ivan Epifanov 6c3bf565 2020-11-23T12:44:54 Unified build with both renderers
Ivan Epifanov 6ba84975 2020-11-21T23:04:27 Remove vita2d render, add raw gxm render
Ivan Epifanov ef0bbfd6 2020-11-16T20:40:22 Include anf fix vita2d renderer
Ivan Epifanov dbb730d3 2020-11-14T23:37:26 Separate vita piglet renderer. Add proper render initialization and window re-creation.
Sylvain Becker 70b353d1 2021-01-27T10:54:49 SDL_Update{YUV,NV}Texture: also intersect rect with texture dimension
Sylvain Becker 13626c36 2021-01-27T10:20:13 SDL_UpdateTexture: intersect update rect with texture dimension - fix crash with software renderer - fix non texture update with opengl/gles2
Sylvain Becker be4cfd51 2021-01-05T11:56:22 Add SDL_UpdateNVTexture() to update NV12/21 Texture (bug #5430) for renderer software, opengl, and opengles2
Sam Lantinga 9130f7c3 2021-01-02T10:25:38 Updated copyright for 2021
Sylvain Becker 3edf337d 2021-01-02T17:29:34 Simplify RenderGetViewportSize
Sylvain Becker 2af765da 2021-01-02T17:18:13 SDL_RenderGetViewportF: only need the size of viewport (see bug #5424)
Sylvain Becker 41597249 2021-01-02T16:15:22 SDL_RenderGetViewportF: remove debug messages
Sylvain Becker 8c48c423 2021-01-02T16:12:30 Add SDL_RenderGetViewportF: fix lost of precision while scaling (see bug #5424)
Sylvain Becker 590a5469 2020-12-30T16:12:14 Fixed bug 5424 - Renderer doesn't use entirely the viewport when scaling is used Viewport/Clip dimensions are calculated usingg SDL_ceil whereas all renders use SDL_floor
Sylvain Becker 5dabc4d7 2020-12-28T18:17:25 Revert changeset 14590 544ac819e8b3 , does not fully fix
Sylvain Becker 9efdafd4 2020-12-28T18:07:03 SDL_RenderCopy: scale before doing intersection this prevents drawing 1 pixel outside the screen, in letterbox mode
Sam Lantinga cb361896 2020-12-09T07:16:22 Fixed bug 5235 - All internal sources should include SDL_assert.h Ryan C. Gordon We should really stick this in SDL_internal.h or something so it's always available.
Sam Lantinga 88cb4962 2020-12-09T06:42:31 Fixed bug 5291 - SDL_SetRenderTarget unnecessarily changes target when current target is the native texture of the passed in texture
Ryan C. Gordon a720d1a2 2020-08-09T00:55:39 render: fixes to how we convert touch events for logical scaling. We now handle HiDPI correctly, and touches are clamped to the viewport. So if you are rendering to a logical 640x480 in a 720p window, and touch the letterboxing at point (640,700), it will report the touch at (0.5,1.0) instead of outside the documented range.
Sylvain Becker 39690a04 2020-05-15T21:33:47 Fix static analysis warning in SDL_render.c
Ryan C. Gordon a96d8a43 2020-04-13T22:05:36 render: Fixed compiler warning about implicit cast.
hmk aa188048 2020-04-10T12:23:08 render: Scale relative mouse motion better for logical sizing From hmk: "When scaling is enabled (e.g. via SDL_RenderSetLogicalSize, size not equal to window size), mouse motion events are also scaled. Small motions are rounded up (SDL_max() when the value after scaling is less than 1), while larger motions are truncated by the floating point -> integer conversion. https://hg.libsdl.org/SDL/file/b18197f9bf9d/src/render/SDL_render.c#l658 The end result feels something like mouse reverse mouse acceleration + angle snapping at low speeds, but less consistent (amount of truncation & rounding depends on how fast the mouse is moved) and potentially much worse if the scaling factor is large. This pretty much makes it useless for anything where you need precise mouse aiming (think of games). I suspect this is why aiming gets so terrible in some games that let you use scaling to reduce the render resolution (e.g. Ion Fury). With 4x4 scaling, I can reproduce a situation where it takes three fast flicks of the mouse across the pad to undo one slow sweep across the pad. In other words, extreme reverse acceleration. This does not happen when scaling is disabled. Furthermore, any game that uses relative mouse motion events for 3D camera rotation probably wants the raw mouse deltas and not a value that depends on scaling and resolution and rounding and truncation. Ideal camera rotation just takes mouse input, multiplies it by sensitivity, and adds it to the angle-in-radians or whatever measure is used for yaw & pitch. Pixels and screen resolution or window dimensions should not be a part of the equation at all, even if it could be implemented without rounding errors. [...] This [patch] completely eliminates angle snapping for me, and makes sensitivity consistent. In other words, it's completely usable for, say, aiming in a first person shooter." Partially fixes Bugzilla #4811.
Sam Lantinga b6afbe63 2020-04-07T09:38:57 Added SDL_log.h to SDL_internal.h so logging is available everywhere
Sylvain Becker e6189f40 2020-03-17T15:47:30 Fix warnining implicit declaration of SDL_DetectPalette (Thanks meyraud705)
Sylvain Becker 838bbf1f 2020-03-17T09:35:42 Fixed bug 5037 - Regression 2.0.12 Alpha value of 0 on palette may become opaque (see also bug 3827)
Sylvain Becker 9a7c2b22 2020-02-23T09:59:52 Fixed bug 4999 - Palette surface always promoted to alpha (Thanks Cameron Gutman!) MSVC Static analysis: Incorrect alpha_value check in SDL_render.c (see also bug 4425)
Sam Lantinga b5e3d264 2020-01-23T01:00:52 Added a single SDL_LEAN_AND_MEAN define to turn on minimal SDL builds Protected more code with #ifdefs to reduce the size of minimal shared library builds
Sylvain Becker 7df22cf2 2020-01-21T21:33:40 A few #defines to reduce SDL2 footprint. Only applied when library is statically linked
Sam Lantinga a8780c6a 2020-01-16T20:49:25 Updated copyright date for 2020
Sam Lantinga 981e0d36 2020-01-16T08:52:59 Fixed bug 4903 - Lack of color multiply with alpha (SDL_BLENDMODE_MOD + SDL_BLENDMODE_BLEND) blending mode for all renderers Konrad This kind of blending is rather quite useful and in my opinion should be available for all renderers. I do need it myself, but since I didn't want to use a custom blending mode which is supported only by certain renderers (e.g. not in software which is quite important for me) I did write implementation of SDL_BLENDMODE_MUL for all renderers altogether. SDL_BLENDMODE_MUL implements following equation: dstRGB = (srcRGB * dstRGB) + (dstRGB * (1-srcA)) dstA = (srcA * dstA) + (dstA * (1-srcA)) Background: https://i.imgur.com/UsYhydP.png Blended texture: https://i.imgur.com/0juXQcV.png Result for SDL_BLENDMODE_MOD: https://i.imgur.com/wgNSgUl.png Result for SDL_BLENDMODE_MUL: https://i.imgur.com/Veokzim.png I think I did cover all possibilities within included patch, but I didn't write any tests for SDL_BLENDMODE_MUL, so it would be lovely if someone could do it.
Sam Lantinga 5e19e66c 2019-12-22T13:39:44 Fixed bug 4914 - Expose SDL_ScaleMode and add SDL_SetTextureScaleMode/SDL_GetTextureScaleMode Konrad This was something rather trivial to add, but asked at least several times before (I did google about it as well). It should be possible to dynamically change scaling mode of the texture. It is actually trivial task, but until now it was only possible with a hint before creating a texture. I needed it for my game as well, so I took the liberty of writing it myself. This patch adds following functions: SDL_SetTextureScaleMode(SDL_Texture * texture, SDL_ScaleMode scaleMode); SDL_GetTextureScaleMode(SDL_Texture * texture, SDL_ScaleMode *scaleMode); That way you can change texture scaling on the fly.
Sylvain Becker fe20c35b 2019-10-14T16:40:46 Fixed race condition when scaling Touch events, and changing the renderer target. Always read the output size of the main renderer. (similar to bug 2107)
Sylvain Becker 7d47f526 2019-10-01T09:26:30 SDL_LockTextureToSurface: robustness of locked region compared to texture size
hmk 0918903f 2019-09-30T22:54:16 render: add a hint for toggling relative scaling Fixes Bugzilla #4811.
Sylvain Becker 1ae61f10 2019-09-30T20:58:44 Added a helper function SDL_LockTextureToSurface() Similar to SDL_LockTexture(), except the locked area is exposed as a SDL surface.
Alex Szpakowski ff7888e6 2019-08-18T09:35:11 render: fix colors not being set properly after the previous change
Alex Szpakowski 1be03b40 2019-08-17T22:26:33 render: avoid a couple redundant memcmp calls in all drawing functions. Improves performance slightly.
Alex Szpakowski 69c6924c 2019-08-17T00:43:44 render: simplify vertex and uniform data allocation. Improves performance of various SDL_Render functions (bug #4764).
Sylvain Becker 22a2decf 2019-06-28T16:38:42 Android: concurrency issues, make sure Activity is in running State when calling functions like SDL_CreateWindow, SDL_CreateRenderer, Android_GLES_CreateContext Bugs 4694, 4681, 4142
Sylvain Becker cfed0b77 2019-06-28T16:14:50 Add an "error" label in SDL_CreateRenderer (no op)
Sam Lantinga b5e9ebba 2019-06-08T19:12:05 Fixed compiler warning warning C4018: '<' : signed/unsigned mismatch
Sam Lantinga 41c718db 2019-05-19T12:04:06 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)
Sam Lantinga b2e76d86 2019-03-19T16:52:09 Fixed Windows RT build
Sylvain Becker 07548602 2019-01-19T16:47:43 Fixed bug 3657 - Color-key doesn't work when an alpha channel is present When surface format is the same as renderer format, it still needs an intermediate conversion to transform colorkey to alpha.
Sam Lantinga 5e13087b 2019-01-04T22:01:14 Updated copyright for 2019
Ryan C. Gordon 0a705901 2018-12-19T18:10:02 render: Prefer the Metal renderer over OpenGL. This is the best option for macOS and iOS, the only platforms with Metal. Pre-Metal versions of these platforms will fall back to OpenGL (ES), as appropriate. Huge thanks to Alexander Szpakowski, who worked incredibly hard to get the Metal renderer to such a high-quality state!
Sylvain Becker e5476c65 2018-12-15T14:50:12 Fixed bug 4425 - promote to alpha format, palette surface with alpha values. SDL_CreateTextureFromSurface() forgets to choose a texture format with alpha for surfaces that have palettes with alpha values.
Sylvain Becker 252dc85e 2018-12-06T09:22:00 Fix warnings detected on Android build
Ryan C. Gordon 939bf1c4 2018-12-03T02:06:17 render: fix some static analysis warnings.
Ozkan Sezer 0d79a8a1 2018-11-01T20:04:24 fix build using Watcom : ./src/render/SDL_render.c(2168): Error! E1054: Expression must be constant ./src/render/SDL_render.c(2168): Error! E1054: Expression must be constant ./src/render/SDL_render.c(2175): Error! E1054: Expression must be constant ./src/render/SDL_render.c(2175): Error! E1054: Expression must be constant ./src/render/SDL_render.c(2322): Error! E1054: Expression must be constant ./src/render/SDL_render.c(2322): Error! E1054: Expression must be constant ./src/render/SDL_render.c(2322): Error! E1054: Expression must be constant ./src/render/SDL_render.c(2322): Error! E1054: Expression must be constant ./src/render/SDL_render.c(2329): Error! E1054: Expression must be constant ./src/render/SDL_render.c(2329): Error! E1054: Expression must be constant ./src/render/SDL_render.c(2329): Error! E1054: Expression must be constant ./src/render/SDL_render.c(2329): Error! E1054: Expression must be constant ./src/render/software/SDL_render_sw.c(602): Error! E1054: Expression must be constant ./src/render/software/SDL_render_sw.c(602): Error! E1054: Expression must be constant ./src/render/software/SDL_render_sw.c(602): Error! E1054: Expression must be constant ./src/render/software/SDL_render_sw.c(602): Error! E1054: Expression must be constant
Ryan C. Gordon 4659e738 2018-11-01T12:31:45 merge fallout: Patched to compile, fixed some compiler warnings, etc.
Ryan C. Gordon 62494a2e 2018-10-31T15:03:41 Merge SDL-ryan-batching-renderer branch to default.
Ryan C. Gordon 8340b0f0 2018-10-23T01:34:03 render: Add floating point versions of various draw APIs.
Ryan C. Gordon b262b0eb 2018-10-22T20:50:32 Small stack allocations fall back to malloc if they're unexpectedly large.
Ryan C. Gordon 1ecf4dfc 2018-10-04T16:34:44 render: Added SDL_RenderFlush().
Ryan C. Gordon fdc52a65 2018-09-29T04:00:38 render: patched to compile on C89 compilers, other untested code fixes.
Ryan C. Gordon c20a858d 2018-09-28T19:47:44 render: moved opengles2 over to new interface.
Sam Lantinga 7df0f4fd 2018-09-27T14:56:29 Fixed bug 4277 - warnings patch Sylvain Patch a few warnings when using: -Wmissing-prototypes -Wdocumentation -Wdocumentation-unknown-command They are automatically enabled with -Wall
Sam Lantinga 60afec79 2018-09-25T19:53:16 Removed redundant SDL_GetColorKey() call. (thanks Sylvain!)