Commit Graph

120 Commits

Author SHA1 Message Date
Sylvain
cc37c38e30 Add SDL_RenderGeometry based on SDL_RenderGeometryRaw 2021-08-19 00:10:59 +02:00
Sylvain
e481261173 Move to SDL_RenderGeometryRaw prototype with separate xy/uv/color pointer parameters 2021-08-19 00:10:59 +02:00
Sylvain
f73c1eff10 Use normalized texture coordinates 2021-08-19 00:10:59 +02:00
Sylvain
6e26d320c6 Add sysrender interface 2021-08-19 00:10:59 +02:00
Sam Lantinga
f5794f9eeb Added SDL_SetTextureUserData() and SDL_GetTextureUserData() to associate a user-specified pointer with an SDL texture 2021-08-10 15:17:59 -07:00
Sam Lantinga
fcfd19db86 Added support for SDL_RENDERER_PRESENTVSYNC to the software renderer
This fixes https://github.com/libsdl-org/SDL/issues/4612
2021-08-10 12:02:59 -07:00
David Gow
4077f7a2d9 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.
2021-08-03 09:30:43 -07:00
David Gow
8f06a629aa 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 10:53:49 -04:00
Ivan Epifanov
dd2a285825 Remove leftovers 2021-06-11 13:21:07 -04:00
Sylvain
e87c7940f5
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
2021-04-13 14:42:38 +02:00
Ryan C. Gordon
57c2a4566f
render: draw when hidden, except on iOS and Android.
Fixes #2979.
2021-04-02 14:01:41 -04:00
Vanfanel
e14fb54e3f [KMSDRM] Undo SDL_CreateRenderer() modifications aimed at create opengles2 when KMSDRM is in use because it's a harmful solution. 2021-03-16 11:07:54 -07:00
Vanfanel
108bb5aabe [KMSDRM] Modify SDL_CreateRenderer() to create an opengles2 renderer when the KMSDRM backend is being used and no renderer name has been specified. 2021-03-15 18:47:22 -07:00
Ivan Epifanov
6c3bf56503 Unified build with both renderers 2021-03-08 09:07:12 -08:00
Ivan Epifanov
6ba8497518 Remove vita2d render, add raw gxm render 2021-03-08 09:07:12 -08:00
Ivan Epifanov
ef0bbfd6c6 Include anf fix vita2d renderer 2021-03-08 09:07:12 -08:00
Ivan Epifanov
dbb730d395 Separate vita piglet renderer. Add proper render initialization and window re-creation. 2021-03-08 09:07:12 -08:00
Sylvain Becker
70b353d1a5 SDL_Update{YUV,NV}Texture: also intersect rect with texture dimension 2021-02-10 10:22:17 -05:00
Sylvain Becker
13626c3681 SDL_UpdateTexture: intersect update rect with texture dimension
- fix crash with software renderer
- fix non texture update with opengl/gles2
2021-02-10 10:22:17 -05:00
Sylvain Becker
be4cfd51c3 Add SDL_UpdateNVTexture() to update NV12/21 Texture (bug #5430)
for renderer software, opengl, and opengles2
2021-01-05 11:56:22 +01:00
Sam Lantinga
9130f7c377 Updated copyright for 2021 2021-01-02 10:25:38 -08:00
Sylvain Becker
3edf337d66 Simplify RenderGetViewportSize 2021-01-02 17:29:34 +01:00
Sylvain Becker
2af765da11 SDL_RenderGetViewportF: only need the size of viewport (see bug #5424) 2021-01-02 17:18:13 +01:00
Sylvain Becker
41597249e8 SDL_RenderGetViewportF: remove debug messages 2021-01-02 16:15:22 +01:00
Sylvain Becker
8c48c4238a Add SDL_RenderGetViewportF: fix lost of precision while scaling (see bug #5424) 2021-01-02 16:12:30 +01:00
Sylvain Becker
590a5469ed 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
2020-12-30 16:12:14 +01:00
Sylvain Becker
5dabc4d72f Revert changeset 14590 544ac819e8b3 , does not fully fix 2020-12-28 18:17:25 +01:00
Sylvain Becker
9efdafd43d SDL_RenderCopy: scale before doing intersection
this prevents drawing 1 pixel outside the screen, in letterbox mode
2020-12-28 18:07:03 +01:00
Sam Lantinga
cb36189692 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.
2020-12-09 07:16:22 -08:00
Sam Lantinga
88cb4962cd Fixed bug 5291 - SDL_SetRenderTarget unnecessarily changes target when current target is the native texture of the passed in texture 2020-12-09 06:42:31 -08:00
Ryan C. Gordon
a720d1a294 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.
2020-08-09 00:55:39 -04:00
Sylvain Becker
39690a0478 Fix static analysis warning in SDL_render.c 2020-05-15 21:33:47 +02:00
Ryan C. Gordon
a96d8a4355 render: Fixed compiler warning about implicit cast. 2020-04-13 22:05:36 -04:00
hmk
0918903f3c render: add a hint for toggling relative scaling
Fixes Bugzilla #4811.
2019-09-30 22:54:16 +03:00
hmk
aa188048f1 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.
2020-04-10 12:23:08 -04:00
Sam Lantinga
b6afbe6317 Added SDL_log.h to SDL_internal.h so logging is available everywhere 2020-04-07 09:38:57 -07:00
Sylvain Becker
e6189f4046 Fix warnining implicit declaration of SDL_DetectPalette (Thanks meyraud705) 2020-03-17 15:47:30 +01:00
Sylvain Becker
838bbf1f7a Fixed bug 5037 - Regression 2.0.12 Alpha value of 0 on palette may become opaque
(see also bug 3827)
2020-03-17 09:35:42 +01:00
Sylvain Becker
9a7c2b2246 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)
2020-02-23 09:59:52 +01:00
Sam Lantinga
b5e3d264f2 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
2020-01-23 01:00:52 -08:00
Sylvain Becker
7df22cf2c2 A few #defines to reduce SDL2 footprint.
Only applied when library is statically linked
2020-01-21 21:33:40 +01:00
Sam Lantinga
a8780c6a28 Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
Sam Lantinga
981e0d367c 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.
2020-01-16 08:52:59 -08:00
Sam Lantinga
5e19e66c73 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.
2019-12-22 13:39:44 -08:00
Sylvain Becker
fe20c35be8 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)
2019-10-14 16:40:46 +02:00
Sylvain Becker
7d47f526a7 SDL_LockTextureToSurface: robustness of locked region compared to texture size 2019-10-01 09:26:30 +02:00
Sylvain Becker
1ae61f1009 Added a helper function SDL_LockTextureToSurface()
Similar to SDL_LockTexture(), except the locked area is exposed as a SDL surface.
2019-09-30 20:58:44 +02:00
Alex Szpakowski
ff7888e698 render: fix colors not being set properly after the previous change 2019-08-18 09:35:11 -03:00
Alex Szpakowski
1be03b4089 render: avoid a couple redundant memcmp calls in all drawing functions. Improves performance slightly. 2019-08-17 22:26:33 -03:00
Alex Szpakowski
69c6924ccc render: simplify vertex and uniform data allocation. Improves performance of various SDL_Render functions (bug #4764). 2019-08-17 00:43:44 -03:00