Commit Graph

375 Commits

Author SHA1 Message Date
Sylvain Becker
6d639fce2d SDL_ScaleMode: fix compilation GLES renderer 2019-12-23 16:47:00 +01:00
Ryan C. Gordon
131e13a773 direct3d11: Always set vertex buffers when updating them (thanks, Konrad!).
Fixes Bugzilla #4913.
2019-12-22 20:48:43 -05: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
Ryan C. Gordon
7b08eb481d direct3d11: Fixed incorrect texture coordinates (thanks, Martin!).
Fixes Bugzilla #4860.
2019-12-03 03:07:34 -05:00
Sylvain Becker
9e509e4a4f SDL_render_gles2: remove ineffective widening cast
warning: either cast from 'int' to 'size_t' (aka 'unsigned long') is ineffective, or there is loss of precision before the conversion [bugprone-misplaced-widening-cast]
2019-10-30 16:45:53 +01:00
Sylvain Becker
60d3965ece Readability: remove redundant return, continue, enum declaration 2019-10-30 15:36:17 +01:00
Alex Szpakowski
a9b867ab07 macOS Fix potential memory leaks in the Metal renderer caught by clang's static analyzer. 2019-10-26 14:39:50 -03:00
Ryan C. Gordon
1ce1364b29 d3d11: Don't fail if there's no vertex data to upload (thanks, Martin!).
Fixes Bugzilla #4832.
2019-10-26 12:56:18 -04:00
Alex Szpakowski
216f5b98ac metal: Fix compilation when using older Apple SDKs (bug #4828). 2019-10-17 18:48:58 -03: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
72660a51dd Fixed bug 4825 - SDL Renderer OpenGL: Buffer overflow (SDL_RENDERCMD_DRAW_LINES) 2019-10-13 20:52:52 +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
Ryan C. Gordon
847bd8d983 direct3d: Be more aggressive about resetting state when textures go away.
Fixes Bugzilla #4768.
2019-09-02 00:11:58 -04:00
Ryan C. Gordon
a3804ba1da d3d11: Fixed VB state, avoiding unnecessary recreation (Thanks, Alex!).
Fixes Bugzilla #4779.
2019-09-01 22:41:44 -04:00
Alex Szpakowski
0c26373842 gl/gles/gles2 render: fix SDL_RenderClear being affected by the clip rect in some situations. 2019-08-26 18:49:04 -03:00
Alex Szpakowski
bfdb0e9743 metal renderer: optimize SDL_RenderFillRect slightly. 2019-08-18 10:38:32 -03: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
e8278d0d5b metal renderer: use vertex attributes instead of indexing into a buffer with the vertex id in the shader. Allows for more flexibility with vertex setup in the future.
Also optimize vertex buffer binding slightly.
2019-08-17 16:53:08 -03:00
Alex Szpakowski
55a46abf0a metal renderer: more closely match buffer data alignment requirements from the metal specification. 2019-08-17 01:09:30 -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
Alex Szpakowski
e5acccc7c3 metal renderer: use the device address space instead of the constant address space for colors.
It doesn't negatively impact GPU performance in my tests, and it removes the need for 256 byte memory alignment of color data on macOS.
2019-08-17 00:37:22 -03:00
Alex Szpakowski
3fb5cabe5e metal: Update compiled shaders based on compilation script changes 2019-08-16 22:13:30 -03:00
Alex Szpakowski
9e57e3e595 metal: Update shader compilation script with fixes for newer xcode versions and for running on older platforms 2019-08-16 22:11:50 -03:00
Alex Szpakowski
aebaa316c7 Add public APIs for creating a Metal view attached to an SDL window. Add SDL_metal.h. 2019-08-05 12:35:32 -03:00
Sylvain Becker
22a2decf64 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
2019-06-28 16:38:42 +02:00
Sylvain Becker
cfed0b7738 Add an "error" label in SDL_CreateRenderer (no op) 2019-06-28 16:14:50 +02:00
Ryan C. Gordon
31bb95f11f direct3d: Use D3DPOOL_DEFAULT for vertex buffers after all, release correctly.
Fixes Bugzilla #4679.
Fixes Bugzilla #4537.
2019-06-21 15:07:39 -04:00
Cameron Gutman
e681623cb2 direct3d: Fix dirty textures failing to update
Even if the texture itself has not changed since last time, the data may have
so we must call UpdateDirtyTexture() to handle that possibility.
2019-06-20 19:51:00 -07:00
Ryan C. Gordon
7162649f78 opengl: Be more robust in failing cases.
Load all possible symbols, not just until one fails, in case they get used
during shutdown, etc.

Fixes Bugzilla #4093.
2019-06-18 18:58:39 -04:00
Sam Lantinga
5dcac4ccdf Fixed 4669 - Using the software SDL_Renderer on Android leads to GL errors & black screen when window resizes
Sylvain

I think what happening with the software renderer is:

* you're somehow in background (so texture creation is not possible)
* it resizes and wants to push a SDL_WINDOWEVENT_SIZE_CHANGED
It call:
https://hg.libsdl.org/SDL/file/a010811d40dd/src/render/SDL_render.c#l683
* GetOutputSize
* SW_GetOutputSize
* SW_ActivateRenderer
* SDL_GetWindowSurface
* SDL_CreateWindowFramebuffer which is mapped to SDL_CreateWindowTexture
and it ends up re-creating the surface/a texture, while being in background
2019-06-18 10:08:19 -07:00
Sylvain Becker
e96d4760ac Android: resize with software rendering, reverted again (Bug 4669) 2019-06-18 18:53:58 +02:00
Sylvain Becker
12b92260cc Android: try to fix resize with software rendering (bug 4669) 2019-06-18 18:40:40 +02:00
Sylvain Becker
8a20d40d90 Android: revert commit SW_GetOutputSize, again (Bug 4669) 2019-06-18 18:22:18 +02:00
Sylvain Becker
98cc7589b1 Android: prevent using SW_GetOutputSize with software renderer (Bug 4669) 2019-06-18 10:41:11 +02:00
Sam Lantinga
1213fe79d8 Worked around "Undefined symbol: ___isPlatformVersionAtLeast()" link error on Xcode 11 beta 2019-06-14 13:56:42 -07:00
Ryan C. Gordon
3e9bf28413 software: Fixed compiler warning and dos2unix'd the endlines. 2019-06-11 15:06:35 -04:00
Ryan C. Gordon
04fedce0e8 software: Correctly track viewport and cliprect.
Fixes Bugzilla #4457.
2019-06-11 14:09:53 -04:00
Ryan C. Gordon
a2f2b73554 direct3d: Use D3DPOOL_MANAGED for vertex buffers.
Fixes Bugzilla #4537.
2019-06-11 13:02:56 -04:00
Ryan C. Gordon
f7b7a9727b direct3d: Fixed SDL_RenderSetClipRect usage.
Fixes Bugzilla #4459.
2019-06-11 10:12:47 -04:00
Ryan C. Gordon
4f59d372f8 direct3d: don't dereference bogus pointer if current texture was destroyed.
Fixes Bugzilla #4460.
2019-06-11 09:29:48 -04:00
Ryan C. Gordon
a6af0b8291 direct3d: Fixed more compiler warnings on Visual Studio 64-bit builds. 2019-06-11 02:31:57 -04:00
Sam Lantinga
b5e9ebbafa Fixed compiler warning
warning C4018: '<' : signed/unsigned mismatch
2019-06-08 19:12:05 -07:00
Sam Lantinga
41c718db85 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
Sam Lantinga
2ee9b1ddce Fixed bug 4025 - SDL_Renderer OpenGL : add support for textures ABGR, RGB, BGR
Sylvain

OpenGLES2 SDL renderer has support for textures ARGB, ABGR, RGB and BGR, whereas OpenGL SDL renderer only had ARGB.

If you think it's worth adding it, here's a patch. I quickly tried and it worked, but there may be missing things or corner case.
2019-05-19 11:01:36 -07:00
Sylvain Becker
d68e501db4 Fixed bug 4582 - Maximize/Resize not working on Windows 10
When viewport is set, projectionAndView changes, but ID3D11DeviceContext_UpdateSubresource was not called.
2019-04-08 13:43:48 +02:00
Ryan C. Gordon
8ab698af15 opengles2: Fix static analysis warning.
Not clear if this could ever dereference NULL in real life, but better safe
than sorry!
2019-03-21 10:39:49 -04:00
Sam Lantinga
b2e76d860f Fixed Windows RT build 2019-03-19 16:52:09 -07:00
Sylvain Becker
b28e956b8c Fixed bug 4542 - Image flipped vertically when rendering on texture
Have to recompute  viewport because projection/glOrtho is different
wether rendering is on target texture or not
2019-03-12 07:59:53 +01:00
Ryan C. Gordon
40781dfb15 opengles2: patched to compile. 2019-02-04 23:35:18 -05:00
Ryan C. Gordon
b7504f311b opengles2: keep cached texturing state correct. 2019-02-04 23:32:28 -05:00
Ryan C. Gordon
a609c03ac6 opengles1: keep cached texturing state correct. 2019-02-04 23:24:10 -05:00
Ryan C. Gordon
40a52ceef7 render: Fix OpenGL draw state cache for various points of texture binding. 2019-02-04 18:55:39 -05:00
Sylvain Becker
07548602d6 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.
2019-01-19 16:47:43 +01:00
Sylvain Becker
be991f3a78 Fixed bug 4453 - GLES / GLES2: first white renderer clear cmd is drawn as black 2019-01-12 13:34:03 +01:00
Sam Lantinga
5e13087b0f Updated copyright for 2019 2019-01-04 22:01:14 -08:00
Sylvain Becker
9cdd0dd996 PSP renderer: use colors from 'draw' union (very likely, but un-tested) 2018-12-29 17:59:34 +01:00
Sylvain Becker
ebd9efb361 opengles 1: same fix as in bug #4433 2018-12-29 16:37:44 +01:00
Sylvain Becker
87b7636918 opengles 1: use color from 'draw' union in SetDrawState() 2018-12-29 16:34:50 +01:00
Alex Szpakowski
dc3443602b render: Fix internal state getting out of sync when destroying a texture that was just rendered and then creating a new one, in the GL and GLES2 backends. Fixes bug #4433. 2018-12-21 20:53:31 -04:00
Ryan C. Gordon
0a70590118 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!
2018-12-19 18:10:02 -05:00
Alex Szpakowski
c7db6ade7d metal: Implement SDL_LockTexture for YUV formats. 2018-12-19 18:27:21 -04:00
Alex Szpakowski
ce8c716ada metal: Implement SDL_LockTexture for non-YUV textures. 2018-12-18 14:23:05 -04:00
Sylvain Becker
e5476c653d 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.
2018-12-15 14:50:12 +01:00
Sylvain Becker
39ec1699e7 opengles2: fix prototype of glDeleteBuffers 2018-12-06 10:24:44 +01:00
Sylvain Becker
252dc85e95 Fix warnings detected on Android build 2018-12-06 09:22:00 +01:00
Sylvain Becker
6259a72636 Warnings: fix a documentation warning and missing prototypes 2018-12-05 16:13:12 +01:00
Ryan C. Gordon
cca9d24cde direct3d: be more aggressive about resetting invalidated cached state.
Fixes Bugzilla #4402.
2018-12-03 09:26:05 -05:00
Ryan C. Gordon
939bf1c4d8 render: fix some static analysis warnings. 2018-12-03 02:06:17 -05:00
Ryan C. Gordon
33f78eb163 direct3d: Make sure streaming textures update before being used for drawing.
Fixes Bugzilla #4402.
2018-12-03 01:58:23 -05:00
Ryan C. Gordon
b744108af8 Patched to compile on C89 compilers. 2018-12-02 21:57:33 -05:00
Ryan C. Gordon
3c9361509b direct3d: Release and NULL out vertex buffers on reset.
Otherwise they are irretrievably lost on window resize, etc, which makes
rendering freeze and other disasters.

Fixes Bugzilla #4358.
2018-12-02 20:55:57 -05:00
Alex Szpakowski
37b1f989ce metal: use a staging texture in SDL_UpdateTexture, to make sure it doesn't stomp texture data being drawn in a previous frame on the GPU. 2018-11-25 22:13:09 -04:00
Alex Szpakowski
872936a485 metal: Fix an incorrect division. 2018-11-21 23:46:37 -04:00
Alex Szpakowski
4a58722b9f metal: SDL_RenderFillRects uses one draw call per 16k rectangles (within the given FillRects call), instead of one draw call per rectangle. Reduces CPU usage when drawing many rectangles. 2018-11-21 23:37:23 -04:00
Ryan C. Gordon
457e58c40b opengles: Fixed compiler warnings. 2018-11-17 16:24:52 -05:00
Sam Lantinga
9719f89db2 Back out change initializing renderer blend mode incorrectly. 2018-11-17 12:12:29 -08:00
Ryan C. Gordon
fde7592ada direct3d11: Fixed missing rendering of solid primitives.
Fixes Bugzilla #4388.
2018-11-17 14:39:42 -05:00
Ryan C. Gordon
782f1685ff Fixed a few compiler warnings. 2018-11-17 14:37:51 -05:00
Sam Lantinga
29e15ce62d The default draw blendmode is SDL_BLENDMODE_NONE 2018-11-17 00:58:45 -08:00
Ryan C. Gordon
9262c0de9b software: fix blits with color mods that change during a command queue run. 2018-11-14 22:38:58 -05:00
Alex Szpakowski
244b79e194 metal: SDL_RenderReadPixels on macOS synchronizes the render target's texture data if it's managed, before reading from it. 2018-11-04 14:31:56 -04:00
Alex Szpakowski
c9fed27289 metal: fix the SDL_RENDERER_PRESENTVSYNC flag not being set on the renderer info on macOS, when vsync is used. 2018-11-04 12:31:02 -04:00
Alex Szpakowski
c2bba9e448 metal: fix the size of the buffer used for constant data. 2018-11-04 12:24:05 -04:00
Alex Szpakowski
457390fcf8 metal: avoid an extra buffer allocation and GPU data copy in RunCommandQueue, it's not needed. Improves overall performance. 2018-11-01 20:24:21 -03:00
Alex Szpakowski
4e86dfd8d1 metal: remove an obsolete section of a constant buffer. 2018-11-01 19:49:01 -03:00
Ozkan Sezer
0d79a8a1b2 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
2018-11-01 20:04:24 +03:00
Ryan C. Gordon
4659e73892 merge fallout: Patched to compile, fixed some compiler warnings, etc. 2018-11-01 12:31:45 -04:00
Ryan C. Gordon
62494a2e27 Merge SDL-ryan-batching-renderer branch to default. 2018-10-31 15:03:41 -04:00
Ryan C. Gordon
8340b0f0e2 render: Add floating point versions of various draw APIs. 2018-10-23 01:34:03 -04:00
Cameron Gutman
329f2eb99e Fix crash when GL_LoadFunctions()/GLES2_LoadFunctions() fails
https://bugzilla.libsdl.org/show_bug.cgi?id=4350

We can't safely call GL_DestroyRenderer() until GL_LoadFunctions()
succeeds because we will be missing functions that we try to use
when activating the renderer for destruction if we have an GL context.
2018-10-31 20:17:53 -07:00
Sam Lantinga
da56cefa8b Fixed bug 4188 - Software renderer SDL_RenderCopyEx blits corrupt image under certain cases
Sylvain

Re-opening this issue.

It fixes the test-case, but it introduces a regression with another bug (bug #4313).

So here's a new patch that activate cropping of the source surface to solve the issue.
It also reverts the wrong changeset.
It prevents unneeded colorkey error message.
2018-10-30 07:00:03 -07:00
Micha? Janiszewski
91820998fc Add and update include guards
Include guards in most changed files were missing, I added them keeping
the same style as other SDL files. In some cases I moved the include
guards around to be the first thing the header has to take advantage of
any possible improvements compiler may have for inclusion guards.
2018-10-28 21:36:48 +01:00
Ryan C. Gordon
b262b0ebc9 Small stack allocations fall back to malloc if they're unexpectedly large. 2018-10-22 20:50:32 -04:00
Ryan C. Gordon
eedf2c965d opengles2: Fixed several incorrect things. 2018-10-06 17:08:04 -04:00
Ryan C. Gordon
6ecd0b2c35 opengles2: removed useless memcpy. 2018-10-04 21:10:42 -04:00
Ryan C. Gordon
ef3d970ace opengles2: Fixed incorrect cliprect state. 2018-10-04 20:22:28 -04:00
Ryan C. Gordon
208c4b0361 metal: CopyEx transform matrix must be aligned for constant buffer access. 2018-10-04 20:21:58 -04:00
Ryan C. Gordon
638d624f5a metal: Don't try to create a zero-byte vertex buffer.
(Which will cause a crash in Metal, or an assert in the validation layer.)
2018-10-04 20:21:23 -04:00