Commit Graph

25 Commits

Author SHA1 Message Date
Sam Lantinga
9130f7c377 Updated copyright for 2021 2021-01-02 10:25:38 -08:00
Sylvain Becker
f9b5f6cc0f Forward scale mode to SW renderer (Bug 5313) 2020-12-27 20:28:24 +01: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
a8780c6a28 Updated copyright date for 2020 2020-01-16 20:49:25 -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
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
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
Sam Lantinga
5e13087b0f Updated copyright for 2019 2019-01-04 22:01:14 -08:00
Ryan C. Gordon
8340b0f0e2 render: Add floating point versions of various draw APIs. 2018-10-23 01:34:03 -04:00
Ryan C. Gordon
cc56de44a4 render: A bunch of high-level improvements.
- high-level filters out duplicate render commands from the queue so
  backends don't have to.
- Setting draw color is now a render command, so backends can put color
  information into the vertex buffer to upload with everything else instead
  of setting it with slower dynamic data later.
- backends can request that they always batch, even for legacy programs,
  since the lowlevel API can deal with it (Metal, and eventually Vulkan
  and such...)
- high-level makes sure the queue has at least one setdrawcolor and
  setviewport command before any draw calls, so the backends don't ever have
  to manage cases where this hasn't been explicitly set yet.
- backends allocating vertex buffer space can specify alignment, and the
  high-level will keep track of gaps in the buffer between the last used
  positions and the aligned data that can be used for later allocations
  (Metal and such need to specify some constant data on 256 byte boundaries,
  but we don't want to waste all that space we had to skip to meet alignment
  requirements).
2018-09-23 23:20:40 -04:00
Ryan C. Gordon
5fb67f9f55 render: Move to a batching system for rendering (work in progress). 2018-09-20 15:46:02 -04:00
Sam Lantinga
74ec7cabdb Fixed race condition where Android touch events could get scaled by a render target's viewport 2018-06-18 13:13:56 -07:00
Sam Lantinga
eb14b635cd Fixed bug 4134 - Render targets lose scale quality after minimizing a fullscreen window
Olli-Samuli Lehmus

If one creates a window with the SDL_WINDOW_FULLSCREEN_DESKTOP flag, and creates a render target with SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"), and afterwards sets SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest"), after minimizing the window, the scale quality hint is lost on the render target. Textures however do keep their interpolation modes.
2018-05-07 19:52:25 -07:00
Sam Lantinga
e3cc5b2c6b Updated copyright for 2018 2018-01-03 10:03:25 -08:00
Sam Lantinga
cf3d450313 Added SDL_RenderGetMetalLayer() and SDL_RenderGetMetalCommandEncoder() 2017-12-08 14:30:10 -08:00
Ryan C. Gordon
2a2c8d42ca Initial shot at a renderer target for Apple's Metal API.
This isn't complete, but is enough to run testsprite2. It's currently
Mac-only; with a little work to figure out how to properly glue in a Metal
layer to a UIView, this will likely work on iOS, too.

This is only wired up to the configure script right now, and disabled by
default. CMake and Xcode still need their bits filled in as appropriate.
2016-04-21 03:16:44 -04:00
Sam Lantinga
c59d9923b3 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
Sam Lantinga
9dbe5a9686 Fixed bug 3311 - Broken touch positions with SDL_RenderSetLogicalSize & HIGHDPI on iOS
Eric wing

Hi, I think I found a bug when using SDL_WINDOW_ALLOW_HIGHDPI with SDL_RenderSetLogicalSize on iOS. I use SDL_RenderSetLogicalSize for all my stuff. I just tried turning on SDL_WINDOW_ALLOW_HIGHDPI on iOS and suddenly all my touch/mouse positions are really broken/far-off-the-mark.

I actually don't have a real retina device (still) so I'm seeing this using the iOS simulator with a 6plus template.

Attached is a simple test program that can reproduce the problem. It uses RenderSetLogicalSize and draws some moving happy faces (to show the boundaries/space of the LogicalSize and that it is working correctly for that part).

When you click/touch, it will draw one more happy face where your button point is.

If you comment out SDL_WINDOW_ALLOW_HIGHDPI, everything works as expected. But if you compile with it in, the mouse coordinates seem really far off the mark. (Face appears far up and to the left.)


Alex Szpakowski on the mailing list suggests the problem is
"I believe this is a bug in SDL_Render?s platform-agnostic mouse coordinate scaling code. It assumes the units of the mouse coordinates are always in pixels, which isn?t the case where high-DPI is involved (regardless of whether iOS is used) ? they?re actually in ?DPI independent? coordinates (which matches the window size, but not the renderer output size)."

Additionally, if this is correct, the Mac under Retina is also probably affected too and "as well as any other platform SDL adds high-dpi support for in the future".
2017-08-02 13:38:46 -07:00
Ryan C. Gordon
07519a6b95 Removed a bunch of unnecessary #ifdefs. 2017-02-26 00:40:04 -05:00
Sam Lantinga
45b774e3f7 Updated copyright for 2017 2017-01-01 18:33:28 -08:00
Sam Lantinga
3615633571 Renaming of guard header names to quiet -Wreserved-id-macro
Patch contributed by Sylvain
2016-11-20 21:34:54 -08:00
Ethan Lee
167cf14c1f SDL_RenderSetIntegerScale 2016-01-05 16:39:18 -05:00
Sam Lantinga
42065e785d Updated copyright to 2016 2016-01-02 10:10:34 -08:00
Philipp Wiesemann
0e45984fa0 Fixed crash if initialization of EGL failed but was tried again later.
The internal function SDL_EGL_LoadLibrary() did not delete and remove a mostly
uninitialized data structure if loading the library first failed. A later try to
use EGL then skipped initialization and assumed it was previously successful
because the data structure now already existed. This led to at least one crash
in the internal function SDL_EGL_ChooseConfig() because a NULL pointer was
dereferenced to make a call to eglBindAPI().
2015-06-21 17:33:46 +02:00