Commit graph

151 commits

Author SHA1 Message Date
Ryan C. Gordon
8e76fc1c37 render: patched to compile on C89 compilers, other untested code fixes.
--HG--
branch : SDL-ryan-batching-renderer
2018-09-29 04:00:38 +00:00
Ryan C. Gordon
3fb340541a render: moved opengles2 over to new interface.
--HG--
branch : SDL-ryan-batching-renderer
2018-09-28 19:47:44 -04:00
Ryan C. Gordon
6292445c7a render: Move non-batching flushes to different place.
This lets us batch up a few commands that are all related to the same API
call.

--HG--
branch : SDL-ryan-batching-renderer
2018-09-25 17:04:47 -04:00
Ryan C. Gordon
b8773215d9 render: Add command queue debug logging.
--HG--
branch : SDL-ryan-batching-renderer
extra : source : 7b514b380529e2e8d77cd63eda3fb81cc96d42a9
2018-09-24 02:07:35 -04:00
Ryan C. Gordon
b288df490b 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).

--HG--
branch : SDL-ryan-batching-renderer
extra : source : a3d62fbb80e46d9d544fa52944c3bac5375b5489
2018-09-23 23:20:40 -04:00
Ryan C. Gordon
e7e52b63c0 render: Move to a batching system for rendering (work in progress).
--HG--
branch : SDL-ryan-batching-renderer
extra : source : 6160933718a85a6c45cf63723b404c49579b44f1
2018-09-20 15:46:02 -04:00
Sam Lantinga
a2da3d641d Fixed race condition where Android touch events could get scaled by a render target's viewport 2018-06-18 13:13:56 -07:00
Ozkan Sezer
b34726884e do the direct3d tap dance for overscan hint only if SDL_VIDEO_RENDER_D3D == 1 2018-05-10 08:25:23 +03:00
Sam Lantinga
40f5b81553 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
346af016a5 Updated copyright for 2018 2018-01-03 10:03:25 -08:00
Sam Lantinga
35623271c9 Fixed bug 3981 - Inverted logic bug in SDL_renderer "overscan" feature
Eric wing

There is a tiny bug in the new overscan code for the SDL_renderer.

In SDL_renderer.c, line 1265, the if check for SDL_strcasecmp with "direct3d" needs to be inverted.

Instead of:
if(SDL_strcasecmp("direct3d", SDL_GetCurrentVideoDriver())) {

It should be:
if(0 == SDL_strcasecmp("direct3d", SDL_GetCurrentVideoDriver())) {

This bug causes the "overscan" mode to pretty much be completely ignored in all cases and all things remain letterboxed (as before the feature).
2017-12-12 16:34:16 -08:00
Sam Lantinga
f16b7e735b Added SDL_RenderGetMetalLayer() and SDL_RenderGetMetalCommandEncoder() 2017-12-08 14:30:10 -08:00
Ryan C. Gordon
e1fb05694a 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
f686a7de99 Normalize touch events to the render viewport (thanks Sylvain!) 2017-10-12 08:37:55 -07:00
Sam Lantinga
5f531376c2 Fixed build warning 2017-08-14 20:37:07 -07:00
Sam Lantinga
e97f14a10e Fixed compiler warnings 2017-08-14 20:07:30 -07:00
Sam Lantinga
73cc20bc31 Fixed bug 2344 - CHECK_WINDOW_MAGIC should include __FILE__ and __LINE__
Martin Gerhardy

just for easier debugging issues in the own code...

SDL_CreateRenderer should maybe also use this macro

Ryan C. Gordon

I'll go one better: it should have an SDL_assert().
2017-08-14 16:34:54 -07:00
Sam Lantinga
808e24ac4a 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
67823aa306 Fixed bug 3744 - missing SDLCALL in several functions
Ozkan Sezer

The attached patch adds missing SDLCALL to several functions, so that
they properly match the headers as intended.
2017-08-13 21:06:52 -07:00
Sam Lantinga
f315ab8ebc Fixed copy-paste error, thanks Alen! 2017-08-13 20:13:11 -07:00
Philipp Wiesemann
ac6afcf3ca Fixed compiler warnings about type conversions.
Found by buildbot.
2017-08-04 23:00:30 +02:00
Sam Lantinga
071ebfc1d7 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
260c6a36e6 Merged Eric Wing's overscan patch.
Fixes Bugzilla #2799.
2017-06-06 14:06:40 -04:00
Ryan C. Gordon
82d0a04881 Fix some more compiler warnings on armcc. 2017-03-03 16:38:17 -05:00
Ryan C. Gordon
cbb4c1dc3b Better fix for static analysis issue in SDL_DestroyRenderer().
Follow up fix for Bugzilla #3544.
2017-01-06 21:17:33 -05:00
Sam Lantinga
3cbab22892 Just roll back the entire portion of the commit from b6ec7005ca15 which caused bug 3544 until we figure out what the right static analysis fix is. 2017-01-06 00:40:22 -08:00
Sam Lantinga
17e16c2e64 Fixed bug 3544 - Memory freeing bug in SDL_DestroyRenderer/SDL_DestroyTexture
felix

Here's a snippet of SDL_DestroyRenderer from hg revision 10746:95c57a177719:

    SDL_Texture *texture = NULL;
    SDL_Texture *nexttexture = NULL;
    /* ... */
    for (texture = renderer->textures; texture; texture = nexttexture) {
        nexttexture = texture->next;
        SDL_DestroyTexture(texture);
    }

SDL_DestroyTexture removes the texture from the linked list pointed to by the renderer and ends up calling SDL_DestroyTextureInternal, which contains this:

    if (texture->native) {
        SDL_DestroyTexture(texture->native);
    }

If it happens that texture->native is an alias of nexttexture two stack frames up, SDL_DestroyRenderer will end up trying to destroy an already freed texture. I've had this very situation happen in dosemu2.

Bug introduced in revision 10650:b6ec7005ca15, which has a somewhat ironic description of "Fixed all known static analysis bugs"...
2017-01-06 00:32:06 -08:00
Sam Lantinga
1b24bfad38 Updated copyright for 2017 2017-01-01 18:33:28 -08:00
Ryan C. Gordon
893f89bb1c Fixed all known static analysis bugs, with checker-279 on macOS.
--HG--
extra : rebase_source : 340383a2099de0ed7e61343fb21f59685d11a87e
2016-11-24 21:41:09 -05:00
Sam Lantinga
b4b349081d Fixed divide by zero if setting integer scale without setting logical width and height 2016-10-14 00:51:57 -07:00
Sam Lantinga
1b032a0419 Implemented SDL_GetHintBoolean() to make it easier to check boolean hints 2016-10-07 23:40:44 -07:00
Eric Wing
8c1d01fb76 overscan (feature for SDL_RenderSetLogicalSize): Fix to ignore overscan hint when using the Direct3D 9 backend.
D39 does not support negative viewport values which the current implementation relies on.
D3D11 does support negative viewport values so that will continue working.
Refer to Bug 2799.
2016-04-04 19:25:24 -07:00
Sam Lantinga
b5793055d2 Fixed bug 3029 - software renderer cuts off edges when rotate-blitting with a multiple of 90 degrees
Adam M.

When doing a rotated texture copy with the software renderer, where the angle is a multiple of 90 degrees, one or two edges of the image get cut off. This is because of the following line in sw_rotate.c:
    if ((unsigned)dx < (unsigned)sw && (unsigned)dy < (unsigned)sh) {
which is effectively saying:
    if (dx >= 0 && dx < src->w-1 && dy >= 0 && dy < src->h-1) {

As a result, it doesn't process pixels in the right column or bottom row of the source image (except when they're accessed as part of the bilinear filtering for nearby pixels). This causes it to look like the edges are cut off, and it's especially obvious with an exact multiple of 90 degrees.
2016-10-07 18:00:30 -07:00
Sam Lantinga
744356e892 Fixed bug 3116 - renderer->hidden in SDL_RenderCopy(Ex)
Daniel

Seems like check of the visibility of renderer (renderer->hidden) is missing in SDL_RenderCopyEx.

In SDL_RenderCopy it should be done much earlier (after checking support for RenderCopyEx, line 1750).
2016-10-01 14:31:00 -07:00
Sam Lantinga
7e0287b129 Fixed bug 3174 - SDL_SetRenderTarget clip rect
Marcel Bakker

In SDL_SetRenderTarget(),
i think the intended behavior was to clear the clip rect when a new target is set.
2016-10-01 13:29:30 -07:00
Philipp Wiesemann
208f4688d4 Fixed compile warnings about type conversion.
Found by buildbot.
2016-01-16 21:25:10 +01:00
Ethan Lee
c93d43c4e0 SDL_RenderSetIntegerScale 2016-01-05 16:39:18 -05:00
Eric Wing
45f310fb48 merged SDL 2.0.4 rc2 2015-06-21 04:04:14 -07:00
Sam Lantinga
8dd2c29b23 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Adam M.

There are three problems in the code that I see.
1. SW_RenderCopyEx enables a color key on surface_scaled even if the source surface didn't have a color key.
2. SW_RenderCopyEx doesn't copy blend mode, color mod, or alpha mod from src to surface_scaled.
3. When SDL_BlitScaled(src, srcrect, surface_scaled, &tmp_rect) is called, it blends the src pixels into surface_scaled instead of overwriting them (if src has blending, etc. enabled).

I've attached a patch that 1) fixes the three problems that I mentioned, 2) adds the requested performance improvement of using the regular blit function if no rotation or flipping is needed, 3) avoids cloning the source surface if no stretching is required, and simplifies the rotation code slightly.
2015-06-19 23:20:43 -07:00
Eric Wing
88a535d7ae merged SDL 2.0.4rc1+ 2015-06-17 20:03:08 -07:00
Sam Lantinga
f7c6aa58fd Fixed bug 2367 - Bad mouse motion coordinates with two windows where one has changed logical size
Andreas Ragnerstam

I have two windows where one has a renderer where the logical size has been changed with SDL_RenderSetLogicalSize. When I get SDL_MOUSEMOTION events belonging to the non-scaled window these will have been scaled with the factor of the scaled window, which is not expected.

Adding some printf debugging to SDL_RendererEventWatch of SDL_render.c, where (event->type == SDL_MOUSEMOTION), I found that for every mouse motion SDL_RendererEventWatch is called twice and the event->motion.x and event.motion.y are set twice for the event, once for each renderer where only the last one set will be saved to the event struct. This will work fine if both renderers have the same scale, but otherwise the motion coordinates will be scaled for the renderer belonging to another window than the mouse was moved in.

I guess one solution would be to check that window == renderer->window for SDL_MOUSEMOTION events, similar to what is done for when SDL_WINDOWEVENT events.

I get the same error on both X11 and Windows.
The same problem also exists for SDL_MOUSEBUTTONDOWN and SDL_MOUSEBUTTONUP events.
2015-05-28 12:18:05 -07:00
Sam Lantinga
7ee8dda270 Updated copyright to 2016 2016-01-02 10:10:34 -08:00
David Ludwig
4a76370838 Fixed bug 3202 - Fix renderer visibility on a window maximized directly from the minimized state
Many thanks to id.zeta for details on the bug, and for the fix!

--HG--
extra : rebase_source : 9362e46110ea0930ab99f2935c5a4eac8ab723bd
2015-12-27 17:55:45 -05:00
Philipp Wiesemann
446d7f5566 Changed an error return value from 0 to NULL for consistency. 2015-08-21 23:50:37 +02:00
Ryan C. Gordon
2193e198e8 Drop out of SDL_UpdateTexture() early if the rectangle is zero pixels.
Hopefully makes static analysis happy about a zero-byte malloc elsewhere.
2015-05-26 16:42:36 -04:00
Sam Lantinga
56b58afdbe Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
Eric Wing
4c34a1682a Adds support to control the scaling policy/mode of SDL_RenderSetLogicalSize for both letterbox (current behavior) and a new overscan mode (expand to fill the entire screen, even if some parts draw off the screen).
The expected use case is for games that are designed with multiple aspect ratios already in mind and leave optional margins on the edges of the game which won't hurt if they are cut off.

An example use case is a game is designed for wide-screen/16:9, but then wants to deploy on an iPad which is 4:3. Normally, SDL will letterbox, which will shrink things and result in wasted space. But the designer already thought about 4:3 and designed the edges of the game so they could be cut off without any functional loss. So rather than wasting space with letterboxing, "overscan" mode will zoom the rendering to fill up the entire screen. Parts on the edges will be drawn offscreen, but since the game was already designed with this in mind, it is fine. The end result is the iPad (4:3) experience is much better since it feels like a game designed for that screen aspect ratio.

This patch introduces a new SDL_hint: SDL_HINT_RENDER_LOGICAL_SIZE_MODE.
Valid values are "letterbox" or "0" for letterboxing and "overscan" or "1" for overscan.
The default mode is letterbox to preserve existing behavior.

// Example usage:
SDL_SetHint(SDL_HINT_RENDER_LOGICAL_SIZE_MODE, "overscan");
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
2014-12-03 04:41:26 -08:00
Sam Lantinga
cf895bf696 Fixed bug where the render target is updated instead of the default output when the window is resized. 2014-08-17 14:34:41 -07:00
Sam Lantinga
3d8224313f Fixed bug 2681 - dereference a NULL pointer dst_fmt in SDL_CreateTextureFromSurface function
Nitz

In SDL_CreateTextureFromSurface:

SDL_PixelFormat *dst_fmt;
/* Set up a destination surface for the texture update */
         dst_fmt = SDL_AllocFormat(format);
            temp = SDL_ConvertSurface(surface, dst_fmt, 0);

Here is need of NULL check for dst_fmt because there are chances of NULL return from SDL_AllocFormat(format);
2014-08-16 23:30:44 -07:00
Jørgen P. Tjernø
431aca234b Render: Allow empty cliprect.
This fixes an issue where an empty cliprect is treated the same as a NULL
cliprect, causing the render backends to disable clipping.

Also adds a new API, SDL_RenderIsClipEnabled(render) that allows you to
differentiate between:
 - SDL_RenderSetClipRect(render, NULL)
 - SDL_Rect r = {0,0,0,0}; SDL_RenderSetClipRect(render, &r);

Fixes https://bugzilla.libsdl.org/show_bug.cgi?id=2504

--HG--
extra : amend_source : 9e5ac76e3f009d9ae49bc61c350df3ba891267b5
extra : histedit_source : b92b8be4d05b19a89fa0dee57f7ed6b1e924cb99%2Cce419f6ade87bafc78ff42702c1f263d2469e7e7
2014-04-19 13:15:41 -07:00