Commit graph

86 commits

Author SHA1 Message Date
Sam Lantinga
b03fdbe67f Added missing SDL_assert.h 2013-09-28 14:06:51 -07:00
Sam Lantinga
43cc5c1cbb Added optimized YUV texture upload path with SDL_UpdateYUVTexture() 2013-09-28 14:06:47 -07:00
Edward Rudd
3a11d95444 add in High DPI support (aka Retina)
- based on Jørgen's patch with a few bug fixes
2013-09-20 13:43:00 -04:00
Sam Lantinga
08dfaaa2e6 Christoph Mallon: Remove pointless if (x) before SDL_free(x) 2013-08-29 08:29:21 -07:00
Sam Lantinga
8ee3d7a554 Fixed bug 1968 - SDL_RenderCopy stretch loses proportion on viewport boundaries for 3D renderers
driedfruit

SDL_RenderCopy clips dstrect against the viewport. Then it adjusts the
srcrect by "appropriate" amount of pixels. This amount is actually
wrong, quite a lot, because of the rounding errors introduced in the "*
factor / factor" scale.

            real_srcrect.x += (deltax * real_srcrect.w) / dstrect->w;
            real_srcrect.w += (deltaw * real_srcrect.w) / dstrect->w;

For example:

I have a 32 x 32 srcrect and a 64 x 64 dstrect. So far the
stretching is done perfectly, by a factor of 2.

Now, consider dstrect being clipped against the viewport, so it becomes
56 x 64. Now, the factor becomes 1.75 ! The adjustment to "srcrect"
can't handle this, cause srcrect is in integers.

And thus we now have incorrect mapping, with dstrect not being in the
right proportion to srcrect.

The problem is most evident when upscaling stuff, like displaying a 8x8
texture with a zoom of 64 or more, and moving it beyond the corners of
the screen. It *looks* really really bad.

Note: RenderCopyEX does no such clipping, and is right to do so. The fix would be to remove any such clipping from RenderCopy too. And then fix the software renderer, because it has the same fault, independently of RenderCopy.

[attached patch]
this leaves Software Renderer buggy, as it does it's own clipping later on
2013-08-01 09:15:36 -07:00
Sam Lantinga
ccb139c73a A little cleanup on the cleanup, just for consistency. 2013-07-23 19:18:01 -07:00
Jørgen P. Tjernø
8c0d5be080 Fix build errors from last change. 2013-07-23 17:40:16 -07:00
Jørgen P. Tjernø
e007150b45 Fix some clang analyzer warnings.
This fixes some analyzer warnings and a couple of minor memory leaks.
2013-07-23 17:40:13 -07:00
Sam Lantinga
188729834c Fixed bug 1813 - MouseMotion relative values do not respect renderer LogicalSize
driedfruit

A trivial issue, the xrel and yrel values of MouseMotion event struct are not adjusted to renderer logical size.
2013-07-21 12:54:27 -07:00
Sam Lantinga
1bcb90ff25 Don't crash if the current render target is destroyed. 2013-07-12 00:43:16 -07:00
Sam Lantinga
22b55373e7 Check the parameters to SDL_UpdateTexture() 2013-07-11 22:04:16 -07:00
Sam Lantinga
7ff764a482 Fixed the logical size for rendering to texture, thanks to Mason Wheeler.
Mason Wheeler

The SDL_RenderGetLogicalSize function should always return the amount of pixels that are currently available for rendering to.  But after updating to the latest SDL2, I started getting crashes because it was returning (0,0) as the logical size!  After a bit of debugging, I tracked it down to the following code in SDL_SetRenderTarget:

    if (texture) {
        renderer->viewport.x = 0;
        renderer->viewport.y = 0;
        renderer->viewport.w = texture->w;
        renderer->viewport.h = texture->h;
        renderer->scale.x = 1.0f;
        renderer->scale.y = 1.0f;
        renderer->logical_w = 0;
        renderer->logical_h = 0;
    }

This is obviously wrong; 0 is never the correct value for a valid renderer.  Those last two lines should read:

        renderer->logical_w = texture->w;
        renderer->logical_h = texture->h;
2013-06-29 14:40:55 -07:00
Sam Lantinga
86e40a29d3 Fixed bug 1929 - SDL_Texture* from SDL_CreateTexture() causes GL_BindTexture() to segfault
Charles Huber

If SDL_CreateTexture() takes the !IsSupportedFormat() path it will return a SDL_Texture* with a NULL driverdata member.

If you then SDL_GL_BindTexture() this will cause a segfault in GL_BindTexture() when it unconditionally dereferences driverdata.
2013-06-25 20:21:31 -07:00
Sam Lantinga
20c5cf1e8b When the window is resized, the viewport is automatically reset.
This resolves lots of confusion around resizable windows.  Most people don't expect a viewport to be implicitly set when the renderer is created and then not to be reset to the window size if the window is resized.

Added common test command line parameters --logical WxH and --scale N to test the render logical size and scaling APIs.
2013-05-29 03:22:19 -07:00
Sam Lantinga
c55f53aa40 Fixed bug 1622 - SDL_RenderSetViewport with empty SDL_Rect raises wrong error for OpenGL rendering backend
It's now legal to set an empty viewport rect - it will prevent any rendering.

Also added an API to query the output size: SDL_GetRendererOutputSize()
2013-05-29 03:07:55 -07:00
Sam Lantinga
0cb6385637 File style cleanup for the SDL 2.0 release 2013-05-18 14:17:52 -07:00
Philipp Wiesemann
e2fe26af28 Fixed SDL_RenderSetClipRect() returning undefined instead of -1 on error. 2013-05-04 22:44:03 +02:00
Sam Lantinga
866f2e5f9e First pass on SDL render clip rect functionality 2013-05-04 04:46:00 -07:00
Sam Lantinga
b72f0b741e Fixed bug 1583 - Fix build for disabled SDL render subsystem
Marcus von Appen

If one wants to disable the SDL render subsystem, the build breaks on several platforms due to an empty render_drivers array in SDL_render.c.
2013-04-25 00:15:09 -07:00
Andreas Schiffler
5bd319e5b5 Fix bug 1764: incorrect variable assignment in RenderDrawLinesWithRects 2013-04-17 07:35:30 -07:00
Ryan C. Gordon
4f438b70a2 Make SDL_SetError and friends unconditionally return -1.
This lets us change things like this...

    if (Failed) {
        SDL_SetError("We failed");
        return -1;
    }

...into this...

    if (Failed) {
        return SDL_SetError("We failed");
    }


 Fixes Bugzilla #1778.
2013-03-31 12:48:50 -04:00
Sam Lantinga
3afbe992d5 Removed Nintendo DS support since nobody has volunteered to maintain it for over a year. 2013-03-17 09:44:58 -07:00
Captain Lex
47dac69dc7 Add PSP support 2013-03-17 20:07:02 +08:00
Sam Lantinga
95dcfa4c28 Happy New Year! 2013-02-15 08:47:44 -08:00
Sam Lantinga
b1a587fdf7 The logical size set for a render target is temporary and shouldn't conflict with the logical size set for a window. 2012-10-12 02:56:41 -07:00
Sam Lantinga
015f8a0971 Fixed a bug resetting the viewport with a render target. 2012-10-12 02:30:03 -07:00
Sam Lantinga
59fea78fe0 Added SDL_GetRenderTarget() API function
Also fixed a bug with setting logical size for a render target.
2012-10-12 02:20:10 -07:00
Ryan C. Gordon
ec7e2d0865 Helps to initialize variables in the right function. :) 2012-10-03 20:02:13 -04:00
Ryan C. Gordon
8dedb98eef Fixed compiler warning. 2012-10-03 19:20:53 -04:00
Sam Lantinga
778d89e384 Fixed texture list when swapping textures (thanks Drake Wilson!) 2012-10-02 00:28:23 -07:00
Sam Lantinga
732be0727f Initialized default scale for software renderer (thanks Marcus von Appen!) 2012-10-01 23:28:19 -07:00
Sam Lantinga
93b3a23ff2 Fixed a compiler warning 2012-10-01 23:23:04 -07:00
Sam Lantinga
3c4b366a81 Added SDL_RenderSetLogicalSize() and SDL_RenderGetLogicalSize() 2012-10-01 22:30:07 -07:00
Sam Lantinga
f366b098d4 Added SDL_RenderSetScale() and SDL_RenderGetScale() 2012-10-01 20:59:33 -07:00
Sam Lantinga
9bea482166 Fixed bug 1579 - Creating a texture with unsupported format may cause double-destruction
Alexander Hirsch 2012-08-25 20:01:29 PDT

When creating a SDL_Texture with unsupported format (I'll now refer to it as
texture A), SDL_CreateTexture will call SDL_CreateTexture again with
GetClosestSupportedFormat to set texture->native (which I will now refer to as
texture B).
This causes texture B to be put before A in renderer->textures.

If texture A is explicitly destroyed, everything is fine. Otherwise, upon
SDL_DestroyRenderer, the loop will first encounter texture B, destroy it, then
texture A, destroy that which will want to destroy texture->native and since it
is already destroyed set an error.

The solution could be as simple as swapping texture A with B after
texture->native gets set in SDL_CreateTextures.
2012-09-28 04:09:06 -07:00
Sam Lantinga
f380ecb137 Removed executable bit from source files 2012-09-27 14:35:28 -07:00
Sam Lantinga
73f3a3e912 Fixed error message when destroying a software renderer, thanks to wahono for the patch. 2012-09-06 21:34:52 -07:00
Gabriel Jacobo
b1656ffb91 Return a valid error in SDL_GL_Bind/UnbindTexture, thank you buildbot! 2012-09-03 11:54:48 -03:00
Gabriel Jacobo
bd7b381374 Implements SDL_GL_BindTexture and SDL_GL_UnbindTexture (#1576) 2012-09-03 11:16:12 -03:00
Gabriel Jacobo
5c98584a78 Fix for #1577, SDL_RenderCopyEx - Runtime check fails when dstrect == NULL and center == NULL
Thanks Michael Ehrmann.
2012-08-24 11:56:21 -03:00
Ryan C. Gordon
8912814135 Removed some unused variables that gcc 4.6.1 complains about. 2012-08-09 14:14:41 -04:00
Gabriel Jacobo
6ef1aefc05 Fixes #1523 by removing inconsistent use of texture->access 2012-06-21 11:16:14 -03:00
Gabriel Jacobo
17bdcc6e8e RenderCopyEx,rotation and flipping for all hardware/software backends (#1308) 2012-06-01 19:51:08 -03:00
Sam Lantinga
aaf23fe8af Fixed loading textures when the window starts hidden.
The viewport automatically resets to the window size when you programmatically resize the window.
2012-01-22 21:46:06 -05:00
Sam Lantinga
39b2ae4a20 Added a convenience function SDL_CreateWindowAndRenderer() 2012-01-22 19:22:53 -05:00
Sam Lantinga
0458fa488a Renamed SetTargetTexture() to SetRenderTarget() 2012-01-22 01:26:28 -05:00
Sam Lantinga
da686e5bd4 Reorganized the render target code, moving the viewport handling to the general code and adding software implementation. 2012-01-21 22:22:30 -05:00
Sam Lantinga
23b96d3406 Added a renderer flag to expose whether a renderer supports render to texture. 2012-01-19 21:06:47 -05:00
Sam Lantinga
a49a88676f Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Thanks guys!
2012-01-18 22:45:49 -05:00
Sam Lantinga
d0375e624c Better error messaging when SDL can't create a window surface. 2012-01-07 14:21:22 -05:00