Commit graph

135 commits

Author SHA1 Message Date
Sam Lantinga
e1d71b88e1 Back out change initializing renderer blend mode incorrectly. 2018-11-17 12:12:29 -08:00
Sam Lantinga
f1b7d53e6c The default draw blendmode is SDL_BLENDMODE_NONE 2018-11-17 00:58:45 -08:00
Ryan C. Gordon
9f99a9c642 Merge SDL-ryan-batching-renderer branch to default.
--HG--
extra : rebase_source : 83b86d35497a01be6f48055490580bbba19ccc7a
extra : amend_source : faae1a04859499ede43aba3ba50fc4f62b5afbcb
2018-10-31 15:03:41 -04:00
Cameron Gutman
030c9068a7 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
Ryan C. Gordon
637cfa5d6b Small stack allocations fall back to malloc if they're unexpectedly large.
--HG--
branch : SDL-ryan-batching-renderer
2018-10-22 20:50:32 -04:00
Ryan C. Gordon
e33a87b4e6 render: Make the GL backends cache and defer more state changes.
--HG--
branch : SDL-ryan-batching-renderer
extra : histedit_source : 9989445300dd74771e6143b70ef194e88d123c18
2018-10-01 22:53:45 -04:00
Ryan C. Gordon
e523763256 render: OpenGL renderer now caches some state, to improve non-batching mode.
(other minor bug fixes in here, too)

--HG--
branch : SDL-ryan-batching-renderer
extra : amend_source : 1232922bfab60e6b4f23f1c2a35275716ed273bb
2018-09-25 19:20:31 -04:00
Ryan C. Gordon
dbf1408ad8 render: get rid of the predeclared functions in the GL and Metal renderers.
(others to come as I continue to update render backends!)

--HG--
branch : SDL-ryan-batching-renderer
extra : source : 17cc45c0b2e4274617a5ed8ac06f819d3eb40717
2018-09-24 12:30:47 -04:00
Ryan C. Gordon
7b78f799ae render: Make opengl backend take advantage of new high-level features.
--HG--
branch : SDL-ryan-batching-renderer
extra : source : f4665fc62a607285c0c2352dadeb3b290c29d097
2018-09-24 02:08:34 -04:00
Ryan C. Gordon
6fdeb95d0c render: Update Metal and GL backends to use new high-level features, etc.
Now nothing is uploaded as dynamic data with Metal's setVertexBytes, etc; it's
all in the one big vertex buffer, now.

--HG--
branch : SDL-ryan-batching-renderer
extra : source : 67011faccbdbdff56162a9eb25a2bc964c064a03
2018-09-23 23:22:56 -04:00
Ryan C. Gordon
2316f6a784 render: first shot at reworking opengl backend for new batching system.
--HG--
branch : SDL-ryan-batching-renderer
extra : source : 5208dec7e274c9036cdb7ea205682f82f3ac2f7c
2018-09-20 16:36:54 -04: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
sezero
d9c8979193 revert the recent typecast assignment changes (see bug #4079)
also change the void* typedefs for the two vulkan function
pointers added in vulkan_internal.h  into generic function
pointer typedefs.
2018-02-12 17:00:00 +03:00
Sam Lantinga
e9a1c0c9d0 Fixed ISO C99 compatibility
SDL now builds with gcc 7.2 with the following command line options:
-Wall -pedantic-errors -Wno-deprecated-declarations -Wno-overlength-strings --std=c99
2018-01-30 18:08:34 -08:00
Sam Lantinga
346af016a5 Updated copyright for 2018 2018-01-03 10:03:25 -08:00
Sam Lantinga
145d2469ae Updated SDL's YUV support, many thanks to Adrien Descamps
New functions get and set the YUV colorspace conversion mode:
	SDL_SetYUVConversionMode()
	SDL_GetYUVConversionMode()
	SDL_GetYUVConversionModeForResolution()

SDL_ConvertPixels() converts between all supported RGB and YUV formats, with SSE acceleration for converting from planar YUV formats (YV12, NV12, etc) to common RGB/RGBA formats.

Added a new test program, testyuv, to verify correctness and speed of YUV conversion functionality.
2017-11-12 22:51:12 -08:00
Sam Lantinga
c6a9bb2e6b Fixed bug 3857 - SDL_ConvertPixels misses YUV conversions
Sylvain

Few issues with YUV on SDL2 when using odd dimensions, and missing conversions from/back to YUV formats.

1) The big part is that SDL_ConvertPixels() does not convert to/from YUV in most cases. This now works with any format and also with odd dimensions,
  by adding two internal functions SDL_ConvertPixels_YUV_to_ARGB8888 and SDL_ConvertPixels_ARGB8888_to_YUV (could it be XRGB888 ?).
  The target format is hard coded to ARGB888 (which is the default in the internal of the software renderer).
  In case of different YUV conversion, it will do an intermediate conversion to a ARGB8888 buffer.

  SDL_ConvertPixels_YUV_to_ARGB8888 is somehow redundant with all the "Color*Dither*Mod*".
  But it allows some completeness of SDL_ConvertPixels to handle all YUV format.
  It also works with odd dimensions.

  Moreover, I did some benchmark(SDL_ConvertPixel vs Color32DitherYV12Mod1X and Color32DitherYUY2Mod1X).
  gcc-6.3 and clang-4.0. gcc performs better than clang. And, with gcc, SDL_ConvertPixels() performs better (20%) than the two C function Color32Dither*().
  For instance, to convert 10 times a 3888x2592 image, it takes ~195 ms with SDL_ConvertPixels and ~235 ms with Color32Dither*().
  Especially because of gcc vectorize feature that optimises all conversion loops (-ftree-loop-vectorize).

  Nb: I put no image pitch for the YUV buffers. because it complexify a little bit the code and the API :
  There would be some ambiguity when setting the pitch exactly to image width:
  would it a be pitch of image width (for luma and chroma). or just contiguous data ? (could set pitch=0 for the later).


2) Small issues with odd dimensions:
  If width "w" is odd, luma plane width is still "w" whereas chroma planes will be "(w + 1)/2". Almost the same for odd h.
  Solution is to strategically substitute "w" by "(w+1)/2" at the good places ...

- In the repository, SDL_ConvertPixels() handles YUV only if yuv source format is exactly the same as YUV destination format.
  It basically does a memcpy of pixels, but it's done incorrectly when width or height is odd (wrong size of chroma planes). This is fixed.

- SDL Renderers don't support odd width/height for YUV textures.
  This is fixed for software, opengl, opengles2. (opengles 1 does not support it and fallback to software rendering).
  This is *not* fixed for D3D and D3D11 ... (and others, psp ?)
  Only *two* Dither function are fixed ... not sure if others are really used.

- This is not possible to create a NV12/NV12 texture with the software renderer, whereas other renderers allow it.
  This is fixed, by using SDL_ConvertPixels underneath.

- It was not possible to SDL_UpdateTexture() of format NV12/NV21 with the software renderer. this is fixed.

Here's also two testcases:
- that do all combination of conversion.
- to test partial UpdateTexture
2017-10-06 16:50:24 -07:00
Ozkan Sezer
0216e916d3 Watcom supports __FUNCTION__ identifier (and surely not __PRETTY_FUNCTION__)
Partially fixes Bugzilla #3758.
2017-08-17 21:35:46 -04:00
Sam Lantinga
e97f14a10e Fixed compiler warnings 2017-08-14 20:07:30 -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
d03fc29320 Fixed bug 3243 - SDL_SetRenderDrawColor() behaves wrong with RGBA=0
Simon Hug

The bug is in the GL_ResetState and GLES_ResetState functions which get called after a new GL context is created. These functions set the cached current color to transparent black, but the GL specification says the initial color is opaque white.

The attached patch changes the values to 0xffffffff to reflect the initial state of the current color. Should the ResetState functions get called anywhere else in the future, this probably has to call the GL functions itself to ensure that the colors match.
2017-08-12 12:59:22 -07:00
Ryan C. Gordon
93fd0ff629 render: GL_DestroyRender() should activate first.
Otherwise, we might destroy a different GL context's resources.
2017-05-18 21:00:11 -04:00
Philipp Wiesemann
2573690129 Removed newlines from error messages. 2017-03-26 21:00:19 +02:00
Sam Lantinga
c271bbc006 Fixed bug 3569 - GL_UpdateViewport leaves PROJECTION matrix selected
Tom Seddon

GL_ActivateRenderer may call GL_UpdateViewport, which leaves the GL_PROJECTION matrix selected. But after GL_ResetState, the GL_MODELVIEW matrix is selected, suggesting that's the intended default state.

It seems at least like these should be consistent. Presumably GL_UpdateViewport should be doing a glMatrixMode(GL_MODELVIEW) before it finishes.
2017-01-27 21:23:27 -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
Ryan C. Gordon
7fe9264adf Pacify some GCC strict-aliasing compiler warnings.
--HG--
extra : rebase_source : 0f01f82ed177f327ec971d11c60b1516210d2561
2016-11-23 21:52:48 -05:00
Sam Lantinga
bc850ed2b0 Fixed typo getting the drawable size 2016-10-13 04:57:31 -07:00
Sam Lantinga
8cb0e92e2c Fixed bug 3355 - false "Invalid renderer" after creating an "opengles2" renderer.
Call SDL_GL_GetDrawableSize() directly because we may be in the initialization path and SDL_GetRendererOutputSize() will fail because the renderer magic isn't set up yet.
2016-10-13 08:46:34 -07:00
Steffen Pankratz
50322148b7 Fixed a memory leak in function GL_RenderReadPixels 2016-10-11 17:31:29 +02:00
Sam Lantinga
1b032a0419 Implemented SDL_GetHintBoolean() to make it easier to check boolean hints 2016-10-07 23:40:44 -07:00
Philipp Wiesemann
820e748f8a Fixed wrong pixel format if reading pixels from OpenGL renderer. 2016-10-02 22:32:35 +02:00
Sam Lantinga
b675802c8c Fixed build warnings and errors 2016-10-01 14:48:18 -07:00
Sam Lantinga
a64ed63bba Fixed bug 3345 - SDL_RenderClear inconsistency with ClipRect
Simon Hug

The description of the SDL_RenderClear function in the SDL_render.h header says the following:

"This function clears the entire rendering target, ignoring the viewport."

The word "entire" implies that the clipping rectangle set with SDL_RenderSetClipRect also gets ignored. This is left somewhat ambiguous if only the viewport is mentioned. Minor thing, but let's see what the implementations actually do.

The software renderer ignores the clipping rectangle when clearing. It even has a comment on this: /* By definition the clear ignores the clip rect */

Most other render drivers (opengl, opengles, opengles2, direct3d, and psp [I assume. Can't test it.]) use the scissor test for the ClipRect and don't disable it when clearing. Clearing will only happen within the clipping rectangle for these drivers.

An exception is direct3d11 which uses a clear function that ignores the scissor test.
2016-10-01 11:46:32 -07:00
Sam Lantinga
f1c567b2c1 Fixed bug 3349 - GLES2_RenderReadPixels doesn't use target texture format
Simon Hug

The OpenGL ES 2 renderer does not check the target texture format when using SDL_RenderReadPixels and just always uses ABGR8888. This can result in swapped or wrong colors.

The attached patch adds a check and selects the target texture format, if a texture is set as the target.
2016-10-01 11:38:53 -07:00
Sam Lantinga
225b99cc77 Fixed bug 3350 - GL renderers don't need to flip rows after reading back pixels from the target texture
Simon Hug

All OpenGL renderers always flip the rows of the pixels that come from glReadPixels. This is unnecessary for target textures since these are already top down.

Also, the rect->y value can be used directly for target textures for the same reason. I don't see any code that would handle the logical render size for target textures. Or am I missing something?

The attached patch makes the renderers only the flip rows if the data comes from the default framebuffer.
2016-10-01 11:34:04 -07:00
Sam Lantinga
469d83652d Fixed bug 3361 - Texture color modulation doesn't work with active NONE blend mode (opengl and opengles)
Simon Hug

The GL_SetBlendMode and GLES_SetBlendMode functions of the opengl and opengles renderers call the glTexEnvf to set the texture env mode to either GL_MODULATE (the default) or GL_REPLACE for the NONE blend mode. Using GL_REPLACE disables color and alpha modulation for textures.

These glTexEnv calls were put in the SetBlendMode function back in 2006 [1], but there the NONE code still used the GL_DECAL mode. The GL_REPLACE mode came in 2008 [2]. I'm a bit confused why that wasn't always GL_MODULATE and a bit surprised nobody reported that yet (unless I missed it). I guess only a few use the gles renderer and the newish shaders mask the issue.
2016-10-01 11:04:45 -07:00
Sam Lantinga
6c7cd4c330 Fixed bug 3362 - OpenGL renderer doesn't check if framebuffers are supported when creating target textures
Simon Hug

The GL_CreateTexture function doesn't have any checks for the case where the driver doesn't support the framebuffer object extension. It will call into GL_GetFBO which will call the non-existent glGenFramebuffersEXT.

Also, for some reason GL_CreateContext always sets the SDL_RENDERER_TARGETTEXTURE info flag, even if it is not supported. Changeset 6e6bd53feff0 [1] makes this change, but doesn't explain why. It seems to me like the code would already have taken care of this [2].

The attached patch adds some checks and stops SDL from reporting render target support if there is none. The application can then properly inform the user instead of just crashing.
2016-10-01 10:52:24 -07:00
Sam Lantinga
7ee8dda270 Updated copyright to 2016 2016-01-02 10:10:34 -08:00
Ryan C. Gordon
fcd63f6ac9 OpenGL+GLES renderers: Fixed incorrect clip rectangle coords (thanks, Marcel!).
Fixes Bugzilla #2700.

--HG--
extra : rebase_source : 330d2ad63fbea2eb79133a9e47c0abec2cc36974
2015-12-28 15:15:58 -05:00
Alex Szpakowski
219ef64ec0 SDL_GL_GetAttribute: If a GL context isn't active, only return failure when the specified attribute needs an active GL context to be queried. 2015-12-10 20:25:34 -04:00
Sam Lantinga
d727fa668a Fixed clip rectangle calculation when there is a viewport offset 2015-05-28 18:57:10 -07:00
Sam Lantinga
56b58afdbe Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
Philipp Wiesemann
65093881bc Fixed two inconsistencies on failed allocation. 2015-02-08 22:50:16 +01:00
Philipp Wiesemann
21dbdf0eab Fixed three memory leaks on failed allocation. 2015-02-08 21:25:37 +01:00
Sam Lantinga
f9a36bc6bb Fixed bug 2699 - possible memory leak in GL_RenderReadPixels
Benoit Pierre

If glReadPixels returns an error, than the temporary buffer is not deallocated
2014-08-24 00:02:12 -07:00
Sam Lantinga
bafc5ef326 Take advantage of GL_ARB_texture_non_power_of_two when it's available 2014-08-14 21:31:50 -07:00
Sam Lantinga
c7790bdb2b Added NV12 and NV21 texture support for OpenGL and OpenGL ES 2.0 renderers 2014-08-06 11:34:54 -07:00
Sam Lantinga
cb2cf20706 Fixed bug 2657 - Memory leak in GL_CreateTexture function
Nitz

In GL_CreateTexture function:

if (GL_CheckError("glGenTexures()", renderer) < 0) {
        SDL_free(data);
        return -1;
    }

Here only data is getting free but data->pixels getting leak.
So have to free data->pixels before free data.
2014-07-26 16:52:26 -07:00
Sam Lantinga
6905c61819 Restore window OpenGL state if creating an OpenGL renderer fails 2014-06-22 02:48:43 -07:00