Commit Graph

890 Commits (38219e08d95ecc298fe476e90e802cd288dc72f6)

Author SHA1 Message Date
Cameron Cawley c8eea02071 Fix C89 build errors in Windows builds 2022-05-18 15:03:15 -07:00
Alex Szpakowski ec8fa57750 macOS: always use Objective-C ARC (automatic ref counting).
Change Cocoa SDL_VideoData and SDL_WindowData implementations from C structs to Objective-C objects, since bridging between C and ObjC is easier that way.
2022-05-09 21:53:40 -07:00
Eddy Jansson 9e5cbf034a Disallow non-positive allocation.
Ensure that we're not trying to call SDL_small_alloc()
with a count of zero.

Transforming the code like this fixes a
-Wmaybe-uninitialized warning from GCC 12.0.1
2022-04-29 18:34:13 -07:00
Eddy Jansson 6c2928b4be Switch uses of MIN() to SDL_min()
We're excluding files in src/hidapi to minimize the
diff against the upstream project.
2022-04-29 10:39:51 -07:00
Sam Lantinga 981e1e3c44 Fixed logical size synchronization issue on macOS
https://discourse.libsdl.org/t/sdl-2-0-22-prerelease/35306/6
2022-04-23 10:35:05 -07:00
Jaylon Gowie d9009388c8 SceKernelMemBlockType to unsigned int 2022-04-19 14:17:27 -07:00
Jaylon Gowie 3753a7b1c3 Fix recent changes in VitaSDK 2022-04-19 14:17:27 -07:00
Sam Lantinga b9fe6ba0e7 Fixed compile warnings 2022-04-18 13:09:08 -07:00
Sylvain 1ede941f5c SDL_render.c: internally change viewport/cliprect type from SDL_FRect to SDL_DRect (double precision). (see bug #5547) 2022-04-18 12:26:32 -07:00
pionere 0adb67017b avoid NullPointer in SDL_GetRenderTarget 2022-04-15 15:47:35 -04:00
Ethan Lee ba0ba9ef16 direct3d11: Set the swapchain target immediately after creating it.
Fixes #4782
2022-04-07 23:47:20 -07:00
Ethan Lee cb81630816 render: Update the size/scale/viewport on moves, in addition to resizes.
For OpenGL this means resetting the viewport state shadowing flag too.

Fixes #1504
2022-04-07 23:38:33 -07:00
Cameron Cawley 57118fb7de render: Fix setting the scale mode for non-native textures 2022-04-02 09:51:28 -07:00
Ivan Epifanov 95c0fec518 Vita: PVROGL: fix indentation and ifdef guards 2022-03-31 06:02:50 -07:00
Jaylon Gowie 8c542a3591 Desktop OpenGL 1.X/2.X PSVita Support 2022-03-31 00:02:56 -04:00
Mathieu Eyraud 1db47d468a Fix potential memory leak in QueueCmdFillRects 2022-03-28 08:34:32 -07:00
Ivan Epifanov 95ed83137f Vita: Use preallocated memory pool for textures 2022-03-27 10:07:49 -07:00
Ryan C. Gordon 7bc498d325
direct3d: Implement missing blend operations.
This is only for Direct3D 9; Direct3D 11 already had this implemented.

Fixes #5375.
2022-03-27 09:14:07 -04:00
Ivan Epifanov 69d0b6e3c6 Vita: Fix NULL-pointer dereference 2022-03-25 09:29:20 -04:00
Ryan C. Gordon 4fe7b2cbd1
static analysis: Fixed several complaints from codechecker.
There are still some pending Objective-C specific issues.

Reference issue #4600.
2022-03-24 11:00:43 -04:00
Ivan Epifanov eadc064e2c Vita: add native YUV textures support.
* Fail if texture init fails.
* Refactor and cleanup.
2022-03-24 07:51:20 -04:00
Sylvain Becker c23a7ad38a
Add SDL_RenderGetWindow() API to get the window associated with a renderer (#5440)
Add SDL_RenderGetWindow() API to get the window associated with a renderer
2022-03-23 17:07:56 +01:00
Sylvain 83df4a354e
SDL_render.c: remove unsused case, since renderer target has been forced to NULL previously (see bug #4213) 2022-03-22 15:25:01 +01:00
Sylvain 9dc201d448
Fixed bug #2962 - when SDL_RenderReadPixels format = 0, used format of the target texture
include/SDL_render.h, format:
"0 to use the format of the rendering target "
2022-03-21 10:41:14 +01:00
Ryan C. Gordon d81fee7623
SDL_Rect: Added floating point versions of all the rectangle APIs.
Fixes #5110.
2022-03-19 10:35:24 -04:00
Sylvain b2db570ce9
SDL_triangle_blit_slow: sync code with SDL_blit_slow to handle ARGB2101010 2022-03-16 18:09:40 +01:00
Sylvain Becker 3bebdaccb7 METAL: clip rect w/h must be <= render pass 2022-03-15 10:37:17 +01:00
Ozkan Sezer bf69868924 reduced a few ifdefs, fixed an unused warning if built w/o SDL_HAVE_YUV. 2022-03-10 01:55:04 +03:00
Sam Lantinga c6eef542ab Removed dead code 2022-03-09 13:48:31 -08:00
pionere 911ba8d343
hide impossible branch in D3D_UnlockTexture 2022-03-09 20:17:55 +01:00
Sylvain ea5b482bff
Remove unused warning 2022-03-09 15:38:36 +01:00
Sylvain 04256a5372
Fix compilation (see #5313) 2022-03-09 15:12:25 +01:00
pionere 0983fcee5e
fix memory leak in D3D11_CreateRenderer 2022-03-09 15:03:49 +01:00
pionere 3f8b450de2
extend the code hidden by SDL_HAVE_YUV 2022-03-09 15:03:30 +01:00
pionere ce1883e1e7
fix compile error with disabled SDL_HAVE_YUV (vita)
- UpdateTextureYUV is not defined if SDL_HAVE_YUV is not defined/zero
+ calling SDL_free suffice if the VITA_GXM_RenderData was just allocated
2022-03-09 15:02:44 +01:00
Sam Lantinga b064ad6ac5 Allow GL_ARB_texture_non_power_of_two environment variable to override OpenGL 2.0 check 2022-03-08 18:14:10 -08:00
Ryan C. Gordon 60ddb74cfe video: rework how we prepare a texture framebuffer.
Now we see if we can create an SDL_Renderer, and if that renderer reports
itself as "accelerated," and added some initial heuristics to the OpenGL
renderer to make better decisions about what qualifies as "accelerated."

This adds some FIXMEs that might be merely hypothetical, and removes the
old OpenGL checks from the video subsystem that probably weren't meaningful
in modern times. This will definitely need to improve the existing list
in the GL renderer, to catch things like llvmpipe, etc.

Reference issue #4624.
2022-02-23 09:36:06 -05:00
Ryan C. Gordon 293a0aa80e
opengl: If GL version >= 2.0, NPOT textures are supported, so favor them.
Fixes #5041.
2022-02-22 10:54:21 -05:00
Sam Lantinga 978fbc3250 Fixed compile warnings 2022-02-21 12:02:44 -08:00
Sylvain 9d86ec8573
Palette format: software Render Jitter in rotation (see #5143)
- same fix applied for rotation with palette surfaces
- allow other 8bits format (eg 332)
2022-02-18 09:57:10 +01:00
Sylvain ceb09ee740
Fixed #5143 - software Render Jitter in rotation
better precision calculating rotated coordinates and interpolation
2022-02-17 23:11:02 +01:00
Sylvain 75ffa24e3a
Software Render Jitter in rotation (bug #5143)
The output surface doesn't necessarily to have even width and height.
2022-02-15 13:35:59 +01:00
Sylvain 61abc4e5b6
PSP: SDL_RenderCopyEx rotation and global scaling around the wrong way (see #bug 3070) 2022-02-15 11:34:50 +01:00
Sylvain 18b76fcc5d
Fixed bug #3070 - SDL_RenderCopyEx rotation and global scaling around the wrong way (software renderer) 2022-02-15 11:33:56 +01:00
Sylvain e366ad1288
Fixed bug #2308: SDL_RenderCopyEx rotation center precision (software renderer) 2022-02-15 10:02:34 +01:00
Wouter Wijsman 66ee79bd68 [PSP] Don't swizzle streaming textures
It was causing issues in the teststreaming demo and unswizzling
later is inefficient and causes issues.
2022-02-14 10:59:25 +01:00
Wouter Wijsman abc8198a1f Render all sides when drawing rect on PSP 2022-02-09 09:36:19 -08:00
Wouter Wijsman 54304b971d Fix rotation direction and center point on PSP 2022-02-08 09:47:10 -08:00
Wouter Wijsman 2b572dff88 Make RenderCopyEx rotate around center
This still isn't perfect. The rotation is the wrong way around and the
images are upside down.
2022-02-08 09:47:10 -08:00
Sylvain b0dd4c7d36 SDL_Render OpenGL: do batching like in the GLES2 backend (with no VBO) 2022-02-07 14:02:20 -05:00
Sylvain 90f0d2ce49 Revert OpenGL point drawing performance, do to proper batching 2022-02-07 14:02:20 -05:00
pionere 6d5592a201 minor cleanup of SDL_CreateRenderer 2022-02-05 10:05:25 -05:00
pionere 2cfc83eab7
sync D3D_RenderReadPixels with D3D11_RenderReadPixels
- use the result of SDL_ConvertPixels to propagate error
- get rid of the verbose error message of D3D11_RenderReadPixels in case SDL_ConvertPixels failed
2022-02-02 14:56:38 -05:00
Sylvain f7d3abddba
Fixed bug #964 - SDL_RenderCopy stretch loses proportion on viewport.
Handle the case when there is blending
2022-01-29 10:19:08 +01:00
pionere 60deadba59 re-use return value of SDL_SetError/WIN_SetErrorFromHRESULT/SDL_OutOfMemory 2022-01-28 20:40:19 -05:00
pionere ebdd536676 use SDL_InvalidParamError or SDL_assert instead of custom SDL_SetError 2022-01-28 20:40:19 -05:00
Sylvain f5911bdc59 GLES2: disable texcoord when not using it (see bug #5235)
similar to opengl backend code:
- glDisableVertexAttribArray doesn't need to depend on 'drawstate.texture' value
- move binding code to SetCopyState()
2022-01-28 19:25:40 +01:00
Sylvain 096fe37bb2 GLES2: revert 7bf8c5a388 2022-01-28 19:25:40 +01:00
Sylvain a988ce5544
Fixed bug #964 - SDL_RenderCopy stretch loses proportion on viewport boundaries 2022-01-28 17:24:59 +01:00
Sylvain 7bf8c5a388 GLES2: disable texcoord when not using it (see bug #5235) 2022-01-27 21:49:05 -05:00
Cameron Gutman c6ec5a07f1 d3d11: Respect SDL_HINT_RENDER_DIRECT3D_THREADSAFE when creating device 2022-01-26 18:44:29 -06:00
Ryan C. Gordon 426c1f4b85
opengles2: fix comment about client-side arrays. 2022-01-19 14:28:30 -05:00
Ryan C. Gordon f9b918ff40 opengles2: Use client-side arrays on everything but Emscripten.
Turns out they're much faster!

Fixes #5206.
2022-01-11 19:41:41 -05:00
Sam Lantinga a29d3acc9e Updated Bresenham line drawing to match software renderer output 2022-01-09 11:12:13 -08:00
Sam Lantinga 1f32dd8edc Fixed overdraw with duplicate points, fixed not drawing single point lines 2022-01-09 06:36:18 -08:00
Ryan C. Gordon c275436f56
opengles2: Batching lines/points used wrong var for summing vertex counts.
Fixed this in the vitagxm backend too, but I don't know what the state of
that code is otherwise.

Reference Issue #5061.
2022-01-09 00:39:02 -05:00
Sam Lantinga 3b083b9911 Fixed compile warning 2022-01-08 14:07:42 -08:00
Sam Lantinga b82af9dfbf Improved OpenGL point drawing performance (thanks @slime73!)
We'll do proper call batching for the SDL 2.0.22 release
2022-01-08 14:05:50 -08:00
Sam Lantinga 1a73c45a08 Fixed incorrect color in the OpenGL driver 2022-01-08 13:35:17 -08:00
Sylvain 3cdda8f8ab
PSP: use 'data' variable which is alread the driver data 2022-01-08 21:58:26 +01:00
Sam Lantinga 4ef2529bf9 More efficient calculation of render_count 2022-01-08 12:37:57 -08:00
Sam Lantinga 5346c93b62 Fixed assertion on number of points rendered 2022-01-08 12:28:43 -08:00
Sam Lantinga 4b71962031 Prevent overdraw with connected line segments 2022-01-08 12:02:30 -08:00
Sam Lantinga 09ece861d1 Added the hint SDL_HINT_RENDER_LINE_METHOD to select the line rendering method 2022-01-08 11:36:52 -08:00
Sam Lantinga c1e6079836 As an optimization, draw horizontal and vertical lines using rectangles 2022-01-08 11:09:11 -08:00
Sam Lantinga 3da7c6305a Assert that we have drawn the expected number of points 2022-01-08 11:07:03 -08:00
Sam Lantinga 9f56faeedc Added line drawing using Bresenham's line algorithm (thanks @rtrussell!) 2022-01-08 10:59:31 -08:00
Sam Lantinga fe3a33a092 Use RenderGeometry for drawing lines at all scales 2022-01-08 10:10:18 -08:00
Sam Lantinga 1694782b2a Remove redundant work when render scale is 1.0 2022-01-08 09:32:23 -08:00
Sam Lantinga 2026a78dc2 Don't flush in RenderDraw*WithRects()
This allows these functions to be reused in the future for other primitives
2022-01-08 09:23:58 -08:00
Sam Lantinga 18e4d9fed1 Re-enable line drawing path in render drivers
This is still used for scaled line drawing in RenderDrawLinesWithRects()
2022-01-08 09:02:25 -08:00
Ozkan Sezer 4472b83129 PSP_RunCommandQueue: fix argument to PSP_SetBlendState()
src/render/psp/SDL_render_psp.c: In function 'PSP_RunCommandQueue':
src/render/psp/SDL_render_psp.c:1200: warning: passing argument 1 of 'PSP_SetBlendState' from incompatible pointer type
2022-01-08 11:56:56 +03:00
Ryan C. Gordon cc2013378d
render: Fixed some compiler warnings.
Fixes #5197.
2022-01-07 20:22:51 -05:00
Ryan C. Gordon 6d3b5d66cd
psp: draw lines with RenderGeometry, same as with the other renderers. 2022-01-07 18:18:53 -05:00
Sylvain 9cb2c549fa Remove QueueDrawLines from D3D, D3D11 2022-01-07 14:10:23 -08:00
Sylvain b88b6b3c23 Remove QueueDrawLines from METAL 2022-01-07 14:10:23 -08:00
Sylvain 9aac55317d Remove QueueDrawLines from GL, GLES, GLES2 2022-01-07 14:10:23 -08:00
Sylvain 8ea8b2e697 Use QueueDrawLine if provided, otherwise use RenderGeometry 2022-01-07 14:10:23 -08:00
Sylvain Becker c498727471
render: Use RenderGeometry to draw lines
This patch is from @1bsyl

Fixes #5061.
2022-01-07 16:14:28 -05:00
Sam Lantinga 4b38d4c96b Leave the Metal view active on the window when recreating the Metal renderer
Fixes https://github.com/libsdl-org/SDL/issues/5140

Also move the metal tag definition to SDL_syswm.h so it can be used by applications
2022-01-07 12:38:45 -08:00
Ryan C. Gordon 88ac517df0
opengles2: Fix point drawing. 2022-01-07 15:04:04 -05:00
Wouter Wijsman 515b5f2a39 Fix build errors in PSP port 2022-01-06 10:17:05 -08:00
Wouter Wijsman 34e34ad5a5 Remove debug code from PSP renderer 2022-01-06 10:17:05 -08:00
stdgregwar 520c89a00a cleaning 2022-01-06 10:17:05 -08:00
stdgregwar 09f4711f40 Fix LRU when destroying texture. 2022-01-06 10:17:05 -08:00
stdgregwar c3ec62d6a6 PSP lazier blend states, display mode report with 16bit option 2022-01-06 10:17:05 -08:00
stdgregwar 0f5368fe11 PSP cached blending and texturing state, ABGR1555 stencil hack 2022-01-06 10:17:05 -08:00
stdgregwar fe405eb27b fixed LRU cache code 2022-01-06 10:17:05 -08:00
stdgregwar c1f152292b Spill render targets to ram on PSP 2022-01-06 10:17:05 -08:00
stdgregwar 77d874e3c0 Attempt to make render to texture work on PSP 2022-01-06 10:17:05 -08:00
Sam Lantinga 120c76c84b Updated copyright for 2022 2022-01-03 09:40:21 -08:00
Sylvain 8622eda9e9
SDL_RenderGeometry / software: TRIANGLE_GET_TEXTCOORD interpolates up to the max values included, so reduce by 1 2022-01-02 22:34:56 +01:00
Alex Szpakowski 724468ae2c GL renderer uses glDrawArrays instead of glBegin/glEnd.
Also change internal colors sent to GL to use unorm8 components instead of float, for improved performance.
2021-12-27 10:52:47 -05:00
Sylvain 44c84c0d8e
GLES2/Big-endian: don´t swap datas for yuv textures (Thanks 0x1F9F1 !) 2021-12-17 17:44:34 +01:00
Sylvain 3a69828e87
Fixed GLES2 back-end on Big Endian Platform (see #5093) 2021-12-17 13:15:39 +01:00
Sylvain 3d5fcb5da6 Fix warning 2021-12-16 09:19:53 -08:00
Sylvain 4342e6bd21 SDL_render.c: lighten the cast syntax 2021-12-16 09:19:53 -08:00
Sylvain 50d49c63ed GLES2 backend: cast with SDL_Vertex and SDL_VertexSolid 2021-12-16 09:19:53 -08:00
stdgregwar 0b7b0977fc fix PSP texure artifacts 2021-12-15 18:00:28 -08:00
Francisco Javier Trujillo Mata 0341ec93fe Improve performance when vsync is enabled and the game is not reaching the 60 FPS 2021-12-15 11:29:49 -08:00
Alex Szpakowski 3a5e148b13 Renderer backends use SDL_Color instead of int for geometry colors. 2021-12-14 12:19:16 -08:00
Sam Lantinga b08e57e926 Don't try to create a vbo if we aren't using any vertices 2021-12-14 09:32:05 -08:00
Sylvain b7885abc44
Fixed bug #5087: SDL_RenderGeometryRaw() passes colors as int* instead of SDL_Color* 2021-12-14 10:31:55 +01:00
Alex Szpakowski 323ba6c008 d3d11 renderer: reduce vertex bandwidth and calculations. 2021-12-13 15:14:33 -08:00
Sylvain 8927d73b1c
RenderGeometry: simplify casting (Thanks Daniel Gibson) 2021-12-12 09:55:23 +01:00
Sylvain d7f66ba1ec
Remove strict aliasing warning in opengles2 backend 2021-12-11 20:04:53 +01:00
Sylvain 3e43d6e34b
SDL_RenderGeometry: remove some warning "dereferencing type-punned pointer might break strict-aliasing" 2021-12-11 17:19:00 +01:00
Sylvain 1940d289bf
SW Renderer: fix invalid read if VSYNC hint is initially set with an empty value (eg "")
because:
- GeHint return a value pointer.
- SetHint free internally the pointer
- The -now invalid- pointer is re-read

==9363== Invalid read of size 1
==9363==    at 0x4946860: SW_CreateRenderer (SDL_render_sw.c:1044)
==9363==    by 0x48F0EC3: SDL_CreateRenderer_REAL (SDL_render.c:938)
==9363==    by 0x48C5921: SDL_CreateRenderer (SDL_dynapi_procs.h:332)
==9363==    by 0x401584: main (main.c:421)
==9363==  Address 0x9c24040 is 0 bytes inside a block of size 1 free'd
==9363==    at 0x484621F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==9363==    by 0x494E403: SDL_free_REAL (SDL_malloc.c:5432)
==9363==    by 0x48A6153: SDL_SetHintWithPriority_REAL (SDL_hints.c:76)
==9363==    by 0x48A6254: SDL_SetHint_REAL (SDL_hints.c:101)
2021-12-08 09:41:33 +01:00
stdgregwar 21d46b7e0c PSP renderer fixed 2021-12-07 20:55:04 +03:00
Ozkan Sezer 801dcbc5ef SDL_render_sw.c: fix -Wshadow warnings. 2021-12-07 14:04:10 +03:00
Wouter Wijsman e17a3154ed Fix build issue 2021-12-07 14:03:00 +03:00
Wouter Wijsman 7266cf66c7 Clean up PSP render code to fit C standard used better 2021-12-07 14:03:00 +03:00
Wouter Wijsman 07608bf45f Fix ISO C90 violations in psp render code 2021-12-07 14:03:00 +03:00
Sylvain d09f80ef18
SDL_DrawPointsF: fix error message typo 2021-12-07 11:31:57 +01:00
Sylvain 6dafc85017
SDL_DrawLines: minor simpification:
- scale is  1.0f, don't need to multiply
- typo in error message
- remap SDL_DrawLines to SDL_DrawLinesF
2021-12-07 10:44:12 +01:00
Sylvain a0818a63e3
Fixed bug #5071 - Float conversion warnings in SDL_render.c (see also #5003) 2021-12-07 10:07:15 +01:00
Sylvain e14d10263c Change viewport and cliprect to float version: from SDL_Rect to SDL_FRect 2021-12-02 10:01:50 +01:00
Sylvain 7828362da9 SDL_Renderer software, D3D11: don't use "renderer->viewport" in back-ends, but use the one from SETVIEWPORT cmd 2021-12-02 10:01:50 +01:00
Eric Wasylishen b786c10013 SDL_render_gl.c: GL_RunCommandQueue: always set viewport_dirty on macOS
Without this, moving the window changes the viewport and causes contents
to render stretched.

Fixes #1504
2021-11-27 07:12:34 -05:00
Ryan C. Gordon 86c0cf2bb1
software: Draw a single pixel for a line with the same start/end point.
Otherwise it would drop it, which seems like a bug to me, as it normally
fills the endpoint on lines.

Reference #2006.
2021-11-26 14:34:51 -05:00
DarkContact e77cfb9a11 Fixed d3d11 renderer creation 2021-11-24 10:11:35 -05:00
Sylvain 2a24418bd3
More "Integer overflow generates Illegal instruction under sanitizers" (see bug #4995) 2021-11-23 09:44:37 +01:00
Sylvain 8dd6edec00
Fixed bug #3232 - Integer overflow generates Illegal instruction under sanitizers + see bug #4995 2021-11-23 09:30:42 +01:00
Ozkan Sezer e18be04bc6 Fixed undefined behavior in QueueCmdSetDrawColor()
Fixes https://github.com/libsdl-org/SDL/issues/4995
Patch from Andrew Kelley
2021-11-23 08:01:02 +03:00
Sylvain aef7105408 Use SDL_free 2021-11-22 08:38:46 -08:00
Sylvain fb218e582a PSP: use SDL_malloc/SDL_free 2021-11-22 08:38:46 -08:00
Sylvain 161dd83c9a Don´t use "trunc" as var name, since it's also a function 2021-11-22 08:38:46 -08:00
Sylvain d31251b014 use SDL's functions version inplace of libc version 2021-11-22 08:38:46 -08:00
Sylvain 49369142bd
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
2021-11-21 17:40:48 +01:00
Sam Lantinga 9ec2b35147 Fixed the GLES2 shader count to be in sync with the enum 2021-11-15 13:45:53 -08:00
Sylvain d4df5d33c5
GLES2: prevent batching if blend mode changes (see bug #4964) 2021-11-15 09:43:44 +01:00
Sylvain 92f2fdfc84
GLES2: batch non joined lines (see #4964) 2021-11-15 09:36:18 +01:00
Sylvain 17f156fae5
Fixed bug #4964 - opengles2 & batching = conjoined lines
put back the initial switch case because groups of joined lines cannot be batched.
2021-11-15 09:08:09 +01:00
Sylvain d8888e468e
Fixed bug #4964 - opengles2 & batching = conjoined lines 2021-11-15 08:37:49 +01:00
Sam Lantinga c55ab9631f Added a hint for alternate OpenGL NV12 data format 2021-11-13 22:21:57 -08:00
Sylvain 70c8d20a46
Revert previous commit a50ca98e2b (see bug #4625) 2021-11-13 15:04:19 +01:00
Sylvain a50ca98e2b
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
2021-11-13 14:48:36 +01:00
Misa 3bf7994fe2 Add and use `SDL_FALLTHROUGH` for fallthroughs
Case fallthrough warnings can be suppressed using the __fallthrough__
compiler attribute. Unfortunately, not all compilers have this
attribute, or even have __has_attribute to check if they have the
__fallthrough__ attribute. [[fallthrough]] is also available in C++17
and the next C2x, but not everyone uses C++17 or C2x.

So define the SDL_FALLTHROUGH macro to deal with those problems - if we
are using C++17 or C2x, it expands to [[fallthrough]]; else if the
compiler has __has_attribute and has the __fallthrough__ attribute, then
it expands to __attribute__((__fallthrough__)); else it expands to an
empty statement, with a /* fallthrough */ comment (it's a do {} while
(0) statement, because users of this macro need to use a semicolon,
because [[fallthrough]] and __attribute__((__fallthrough__)) require a
semicolon).

Clang before Clang 10 and GCC before GCC 7 have problems with using
__attribute__ as a sole statement and warn about a "declaration not
declaring anything", so fall back to using the /* fallthrough */ comment
if we are using those older compiler versions.

Applications using SDL are also free to use this macro (because it is
defined in begin_code.h).

All existing /* fallthrough */ comments have been replaced with this
macro. Some of them were unnecessary because they were the last case in
a switch; using SDL_FALLTHROUGH in those cases would result in a compile
error on compilers that support __fallthrough__, for having a
__attribute__((__fallthrough__)) statement that didn't immediately
precede a case label.
2021-11-12 07:26:14 +03:00
Sam Lantinga abc12a832c Revert "Add and use `SDL_FALLTHROUGH` for fallthroughs"
This reverts commit 66a08aa391.

This causes problems with older compilers:
https://github.com/libsdl-org/SDL/pull/4791#issuecomment-966630997
2021-11-11 15:58:44 -08:00
Misa 66a08aa391 Add and use `SDL_FALLTHROUGH` for fallthroughs
Case fallthrough warnings can be suppressed using the __fallthrough__
compiler attribute. Unfortunately, not all compilers have this
attribute, or even have __has_attribute to check if they have the
__fallthrough__ attribute. [[fallthrough]] is also available in C++17
and the next C2x, but not everyone uses C++17 or C2x.

So define the SDL_FALLTHROUGH macro to deal with those problems - if we
are using C++17 or C2x, it expands to [[fallthrough]]; else if the
compiler has __has_attribute and has the __fallthrough__ attribute, then
it expands to __attribute__((__fallthrough__)); else it expands to an
empty statement, with a /* fallthrough */ comment (it's a do {} while
(0) statement, because users of this macro need to use a semicolon,
because [[fallthrough]] and __attribute__((__fallthrough__)) require a
semicolon).

Applications using SDL are also free to use this macro (because it is
defined in begin_code.h).

All existing /* fallthrough */ comments have been replaced with this
macro. Some of them were unnecessary because they were the last case in
a switch; using SDL_FALLTHROUGH in those cases would result in a compile
error on compilers that support __fallthrough__, for having a
__attribute__((__fallthrough__)) statement that didn't immediately
precede a case label.
2021-11-11 07:23:25 -08:00
Sam Lantinga 6c4b4ee7a6 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.
2021-11-10 09:41:43 -08:00
Sam Lantinga 3a31a45028 End the scene before resetting the D3D device, since we'll start with BeginScene after that.
If we don't do this, we'll end up with unbalanced Begin/End scene pairs which causes D3DERR_INVALIDCALL in the present.

Fixes https://github.com/libsdl-org/SDL/issues/4933
2021-11-10 05:24:31 -08:00
Eric Wasylishen 0d98793693
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>
2021-11-09 21:03:42 -08:00
Ryan C. Gordon 04f42e0468 metal: Deal better with -[CAMetalLayer nextDrawable] returning nil.
Fixes #4863.
2021-11-09 12:03:12 -05:00
Sam Lantinga 637bcd0b72 Fixed build warnings 2021-11-07 11:19:07 -08:00
Ivan Epifanov 848d7b1254 Vita: Implement command batching 2021-11-02 13:43:22 -07:00
Ivan Epifanov 3f7a94fc94 Vita: Remove FillRects 2021-11-02 13:43:22 -07:00
Northfear fba82ad1cb Remove sceGxmFinish from RenderPresent on Vita. Make sure that rendering is finished on render texture during locking 2021-10-31 09:17:13 -04:00
Sylvain 4960cc3dcb
Fixed a few warnings 2021-10-25 16:18:40 +02:00
Sylvain b793394590
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) 2021-10-25 13:46:40 +02:00
Ozkan Sezer b3f9d8f38d remove unused local vars after the latest commits. 2021-10-25 07:05:50 +03:00
Sylvain 502e9c3b45 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)
2021-10-24 22:27:56 -04:00
Sylvain 79732c9d1e Remove FillRects from back-end, where RenderGeometry can be used 2021-10-24 22:27:56 -04:00
Sylvain f02ad2820f Remove FillRects from back-end, where RenderGeometry can be used 2021-10-24 22:27:56 -04:00
Sylvain 70b10c753d Use correct indices when using RenderGeometry / FillRects 2021-10-24 22:27:56 -04:00
Sylvain 16beed9aeb Less code since color is constant when done with triangles 2021-10-24 22:27:56 -04:00
Sylvain 99a346439c OpenGLES2: LINES and POINTS successive commands are combined into a single draw call
(using the same case for DRAW_GEOMETRY)
2021-10-24 22:27:56 -04:00
Sylvain f0cdc1d0f6 OpenGLES2: remove FillRects, since it's can be done with RenderGeometry 2021-10-24 22:27:56 -04:00
Sylvain 37c39d5cb4 Use geometry to implement FillRects 2021-10-24 22:27:56 -04:00
Sylvain b0eef52fe1 GLES2 batching: probably need to check for blendMode changes 2021-10-24 22:27:56 -04:00
Sylvain c27e1249e1 Remove SDL_HAVE_RENDER_GEOMETRY define 2021-10-24 22:27:56 -04:00
Sylvain 77026f673b Metal: remove RenderCopy and RenderCopyEx from back-end 2021-10-24 22:27:56 -04:00
Sylvain 0e5160a056 VITA: remove RenderCopy and RenderCopyEx from back-end 2021-10-24 22:27:56 -04:00
Sylvain 73f4ab4c13 Direct3D11: remove RenderCopy and RenderCopyEx from back-end 2021-10-24 22:27:56 -04:00
Sylvain ab758398af Direct3D: remove RenderCopy and RenderCopyEx from back-end 2021-10-24 22:27:56 -04:00
Sylvain 1fe7e3616b OpenGL: a few opengl functions become unused 2021-10-24 22:27:56 -04:00
Sylvain 88548070a5 OpenGLES: remove RenderCopy and RenderCopyEx from back-end 2021-10-24 22:27:56 -04:00
Sylvain d192515428 OpenGL: remove RenderCopy and RenderCopyEx from back-end 2021-10-24 22:27:56 -04:00
Sylvain b92056bbea OpenGLES2: remove RenderCopy and RenderCopyEx from back-end 2021-10-24 22:27:56 -04:00
Sylvain 76f9fb96d9 Use RenderGeometry to implement RenderCopy and RenderCopyEx at higher level 2021-10-24 22:27:56 -04:00
Ryan C. Gordon 08797adaef opengles2: Attempt to batch RenderCopy calls into a single glDrawArrays call. 2021-10-24 22:27:56 -04:00
Sam Lantinga b360965d0d Added a hint for alternate OpenGL NV12 data format 2021-10-21 20:48:05 -07:00
Sam Lantinga a34fe8161f Added the ability to bind NV12 textures in the OpenGL renderer 2021-10-21 12:28:35 -07:00
Sylvain f080273acd
PSP: add implementation for RenderGeometry 2021-10-04 22:01:11 +02:00
Sylvain dd9b2daf8d
PSP: fixed build 2021-10-04 21:56:42 +02:00
Sylvain 77acd44f28
DirectFB: fixed creation of palette textures 2021-10-01 22:30:51 +02:00
Ryan C. Gordon 114d1d46ac
direct3d: Remove unnecessary render target support check.
Direct3D 9 dictates that caps.NumSimultaneousRTs must always be at least 1,
which is to say that Direct3D 9 level hardware must always support render
targets.

(caps.NumSimultaneousRTs is meant to show if you can draw to multiple render
targets in a single draw call.)

We had already hardcoded SDL_RENDERER_TARGETTEXTURE as available earlier in
the function anyhow.

Fixes #4781.
2021-09-27 23:18:25 -04:00
Northfear 14f225198d Use SDL_calloc for allocation of gxm_texture 2021-09-26 14:16:35 -07:00
Northfear 5292156398 End Scene on RunCommandQueue on Vita 2021-09-22 11:54:26 -07:00
Sam Lantinga eb3bf80f9c Fixed compiler warnings using Visual Studio 2019 2021-09-21 18:15:09 -07:00
Northfear 3b2fbb1cb7 End current scene before destroying the texture on Vita 2021-09-20 15:55:36 -07:00
Northfear fc4296c114 Use aligned stride in sceGxmColorSurfaceInit 2021-09-20 13:23:42 -07:00
Northfear 7080bc2a91 Fallback to SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE if CDRAM texture allocation fails 2021-09-20 13:23:42 -07:00
Ryan C. Gordon ca9a321715
render: GL/GLES now draw lines almost perfectly matching software renderer.
One place known to differ in a significant way is a single line segment that
starts and ends on the same point; the GL renderers will light up a single
pixel here, whereas the software renderer will not. My current belief is this
is a bug in the software renderer, based on the wording of the docs:

"SDL_RenderDrawLine() draws the line to include both end points."

You can see an example program that triggers that difference in Bug #2006.

As it stands, the GL renderers might _also_ render diagonal lines differently,
as the the Bresenham step might vary between implementations (one does three
pixels and then two, the other does two and then three, etc). But this patch
causes those lines to start and end on the correct pixel, and that's the best
we can do, and all anyone really needs here.

Not closing any bugs with this patch (yet!), but here are several that it
appears to fix. If no other corner cases pop up, we'll call this done.

Reference Bug #2006.
Reference Bug #1626.
Reference Bug #4001.
...and probably others...
2021-09-19 15:47:24 -04:00
Ryan C. Gordon 857cc7c0c9
render: constified some local variables in SDL_AllocateRenderVertices. 2021-09-19 00:38:06 -04:00
Ryan C. Gordon 5faea84c63
render: Mark viewport/cliprect dirty when window is resized.
Fixes #4751.
2021-09-18 11:54:25 -04:00
Ivan Epifanov 79ec8986d3 Vita: refactor gxm texture render and add SDL_RenderGeometry support 2021-09-16 09:03:17 -07:00
Misa 4a9947336c `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.
2021-09-14 16:18:02 -07:00
Misa 4549769d7d 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.
2021-09-14 09:56:29 -07:00
Ivan Epifanov 10d3df44f1 Vita: fix copyright dates 2021-09-09 07:22:01 -07:00
Ryan C. Gordon d49d955d73
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.)
2021-09-08 11:44:17 -04:00
Sylvain 183eb0673b
Fixed bug #4711: prevent opengl SDL_renderer from crashing if GL_ARB_multitexture isn't supported 2021-09-01 15:46:32 +02:00
Sylvain be6bee0b5a
SW_RenderGeometry: add a redundant check to clear static analysis (see bug #4600) 2021-08-27 07:47:28 +02:00
Sylvain 54ca1d190e
SW_RenderGeometry: add a redundant check to clear static analysis (see bug #4600) 2021-08-27 07:44:03 +02:00
Sylvain b17aa5d080
SW_RenderGeometry: remove a few static analysis false positives (see bug #4600) 2021-08-27 07:16:40 +02:00
Sylvain e426bb80cb
Fixed bug #4671 - D3D_QueueGeometry: use "count / 3" (Thanks alittlesail!) 2021-08-20 07:50:30 +02:00
Sylvain ae5336a3d2
Fixed bug #4669: D3D_QueueGeometry: -0.5f offset position of vertexs
This similar to D3D_QueueCopy positions
2021-08-19 14:03:10 +02:00
Ozkan Sezer 8270172e74 fix -Wshorten-64-to-32 warnings in android builds.
see: https://github.com/libsdl-org/SDL/pull/4195#issuecomment-901506386
2021-08-19 12:11:10 +03:00
Sylvain 154384a776 Add (uintptr_t) casts 2021-08-19 00:10:59 +02:00
Sylvain 1670104ad8 Change 'size_indice' to 'size_indices' 2021-08-19 00:10:59 +02:00
Sylvain a8f89a01aa Change 'size_indice' to 'size_indices' 2021-08-19 00:10:59 +02:00
Sylvain 47db47c1cc Add SDL_HAVE_RENDER_GEOMETRY to compile or not with RenderGeometry support 2021-08-19 00:10:59 +02:00
Sylvain b9bd9da78f OpenGLES2: transfert color as 4 bytes, instead of 4 floats 2021-08-19 00:10:59 +02:00
Sylvain Becker c6ceaaeb4b METAL: use Uchar4Normalized format to transfert color as 4 bytes, instead of 4 floats 2021-08-19 00:10:59 +02:00
Sylvain eff840bb9b Add OpenGLES implementation 2021-08-19 00:10:59 +02:00
Sylvain 32e7910135 Fix warnings 2021-08-19 00:10:59 +02:00
Sylvain 6e47f53869 Fix warnings 2021-08-19 00:10:59 +02:00
Sylvain 4869a3d294 Add Direct3D9 implementation (not tested) 2021-08-19 00:10:59 +02:00
Sylvain 4ba3763897 Save and restore SDL renderer state after transforming triangles to rect 2021-08-19 00:10:59 +02:00
Sylvain cd0663e053 Fix declaration-after-statement and remove tabs 2021-08-19 00:10:59 +02:00
Sylvain Becker cd4663dfcb Update D3D11 for SDL_RenderGeometryRaw 2021-08-19 00:10:59 +02:00
Sylvain Becker 9f59170743 Update METAL backend for SDL_RenderGeometryRaw 2021-08-19 00:10:59 +02:00
Sylvain 61d9e9164f 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
2021-08-19 00:10:59 +02:00
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 111c70e141 Use 64 bits precision to prevent overflow when interpolating color / texture with wide triangles 2021-08-19 00:10:59 +02:00
Sylvain f73c1eff10 Use normalized texture coordinates 2021-08-19 00:10:59 +02:00
Sylvain 5828cc415a Update METAL backend: fix a typo in drawline 2021-08-19 00:10:59 +02:00
Sylvain Becker 9a8a8e65b8 Update SDL_render_d3d11.c
Fix D3D11 compilation
2021-08-19 00:10:59 +02:00
Sylvain Becker 121114d061 Update METAL compiled shaders 2021-08-19 00:10:59 +02:00
Sylvain Becker 2d01573bb9 Add METAL shaders 2021-08-19 00:10:59 +02:00
Sylvain Becker 1e77dae7b7 Add METAL implementation 2021-08-19 00:10:59 +02:00
Sylvain 1ebef0732a Add D3D11 implementation (not yet tested) 2021-08-19 00:10:59 +02:00
Sylvain 3ee511d71c Add software renderer implementation 2021-08-19 00:10:59 +02:00
Sylvain 37f78fc1cc Add OpenGL implementation 2021-08-19 00:10:59 +02:00
Sylvain faded41ab1 Add OpenGLES2 implementation 2021-08-19 00:10:59 +02:00
Sylvain 6e26d320c6 Add sysrender interface 2021-08-19 00:10:59 +02:00
Sylvain 53a2608bd2 Renderer opengles2: turn color Uniform into Attribute.
all attributes are copied interleaved (based on rmg-nik initial patch+
+ minor clean up of data structure
+ add check for colorswap
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
Sam Lantinga a91ab883e9 Fixed building on Windows with cmake, ninja, and clang 2021-08-06 12:28:24 -07:00
Ryan C. Gordon 5fc13fcb21 direct3d: Commit viewport state before clearing, attempt 2.
This reintroduces the fix from 0e16ee8330, but just marks
the viewport state as dirty after a clear that needs to expand the
viewport to fill the render target, as we'll need to also reset
the orthographic projection state elsewhere, and that won't
happen if we clear the dirty flag here.

Fixes #4210.
(again.)
(...sorry...!)
2021-08-04 07:00:17 -04: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
Sam Lantinga 9d64e6b442 Revert "direct3d: Commit dirty viewport state before clearing."
This reverts commit 0e16ee8330.
2021-08-03 00:29:33 -07:00
Ryan C. Gordon 0e16ee8330 direct3d: Commit dirty viewport state before clearing.
Otherwise you might have set the viewport to the full size of
the render target in SDL's API but this change hasn't been
transmitted to Direct3D yet by the time we attempt to clear.

Fixes #4210.
2021-08-03 02:32:56 -04: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
Ryan C. Gordon 585c11c5ae
direct3d: Fix possibly-incorrect scissor test when clearing.
Thanks to @JayFoxRox who did the detective work on this!

Fixes #3357.
2021-07-30 00:33:15 -04:00
Jessica Clarke 8f38ba4d68 Fix casts that should be using uintptr_t
This is needed to support CHERI, and thus Arm's experimental Morello
prototype, where pointers are implemented using unforgeable capabilities
that include bounds and permissions metadata to provide fine-grained
spatial and referential memory safety, as well as revocation by sweeping
memory to provide heap temporal memory safety.

On most systems (anything with a flat memory hierarchy rather than using
segment-based addressing), size_t and uintptr_t are the same type.
However, on CHERI, size_t is just an integer offset, whereas uintptr_t
is still a capability as described above. Casting a pointer to size_t
will strip the metadata and validity tag, and casting from size_t to a
pointer will result in a null-derived capability whose validity tag is
not set, and thus cannot be dereferenced without faulting.

The audio and cursor casts were harmless as they intend to stuff an
integer into a pointer, but using uintptr_t is the idiomatic way to do
that and silences our compiler warnings (which our build tool makes
fatal by default as they often indicate real problems). The iconv and
egl casts were true positives as SDL_iconv_t and iconv_t are pointer
types, as is NativeDisplayType on most OSes, so this would have trapped
at run time when using the round-tripped pointers. The gles2 casts were
also harmless; the OpenGL API defines this argument to be a pointer type
(and uses the argument name "pointer"), but it in fact represents an
integer offset, so like audio and cursor the additional idiomatic cast
is needed to silence the warning.
2021-07-29 14:42:15 -07:00
Ivan Epifanov f806064e7e Remove 'support' for rgb/bgr textures, that was causing issues with them 2021-07-19 10:14:13 -04:00
Ivan Epifanov 817976da69 VITA: Rewrite and fix RenderCopyEx rotation 2021-07-13 08:45:33 -07:00