Commit Graph

67 Commits

Author SHA1 Message Date
Sam Lantinga
9130f7c377 Updated copyright for 2021 2021-01-02 10:25:38 -08:00
Sam Lantinga
cb36189692 Fixed bug 5235 - All internal sources should include SDL_assert.h
Ryan C. Gordon

We should really stick this in SDL_internal.h or something so it's always available.
2020-12-09 07:16:22 -08:00
Sylvain Becker
754286c61c SDL Renderer: specify the correct flag when recreating the window 2020-12-02 13:45:24 +01:00
Ryan C. Gordon
0e4ce84801 opengl: Make diagonal lines match the software renderer.
OpenGL leaves the final line segment open, SDL's software renderer does not,
so we need a tiny bit of trigonometry here to move one more pixel in the right
direction.
2020-11-08 20:57:17 -05:00
Ryan C. Gordon
93a2c58c7e opengl: Use GL_LINE_STRIP instead of breaking down into seperate GL_LINES.
Surely GL drivers have improved in the last seven years. I hope...?
2020-11-08 12:37:09 -05:00
Ryan C. Gordon
c33f808354 render: Restoring line rendering fixes that were previously put on hold.
(Backed out hg changeset 7a4240daba46)
2020-10-20 11:12:49 -04:00
Sam Lantinga
b6afbe6317 Added SDL_log.h to SDL_internal.h so logging is available everywhere 2020-04-07 09:38:57 -07:00
Ryan C. Gordon
19a5f4ab5d opengl: Don't enable/disable texturing except when actually rendering.
Otherwise our cached state goes out of sync when updating a texture. Since
these state changes aren't necessary, they were removed instead of updating
the cached state.

Fixes Bugzilla #4998.
2020-03-22 14:32:47 -04:00
Ryan C. Gordon
93b26f172c opengl: Backed out hg changeset 94f9f40a957f
This is the OpenGL line drawing fix for Bugzilla #3182, but there's some
disagreement about what the renderers should do here, so I'm backing this out
until after 2.0.12 ships, and then we'll reevaluate all the renderer backends
to decide what's correct, and make them all work the same.
2020-02-17 16:15:04 -05:00
Ryan C. Gordon
ed10d9473f opengl: Build out full GL_LINES and respect the diamond-exit rule.
Likewise for the GLES1 and GLES2 renderers.

This solves the missing pixel at the end of a line and removes all the
heuristics for various platforms/drivers. It's possible we could still use
GL_LINE_STRIP with this and save some vertex buffer space, assuming this
doesn't upset some driver somewhere, but this seems to be a clean fix that
makes the GL renderers match the software renderer output.

Diamond-exit rule explanation:
http://graphics-software-engineer.blogspot.com/2012/04/rasterization-rules.html

Fixes Bugzilla #3182.
2020-02-10 12:53:54 -05:00
Sam Lantinga
a8780c6a28 Updated copyright date for 2020 2020-01-16 20:49:25 -08: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
Sylvain Becker
60d3965ece Readability: remove redundant return, continue, enum declaration 2019-10-30 15:36:17 +01:00
Sylvain Becker
72660a51dd Fixed bug 4825 - SDL Renderer OpenGL: Buffer overflow (SDL_RENDERCMD_DRAW_LINES) 2019-10-13 20:52:52 +02: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
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
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
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
40a52ceef7 render: Fix OpenGL draw state cache for various points of texture binding. 2019-02-04 18:55:39 -05:00
Sam Lantinga
5e13087b0f Updated copyright for 2019 2019-01-04 22:01:14 -08: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
Sam Lantinga
9719f89db2 Back out change initializing renderer blend mode incorrectly. 2018-11-17 12:12:29 -08:00
Sam Lantinga
29e15ce62d The default draw blendmode is SDL_BLENDMODE_NONE 2018-11-17 00:58:45 -08:00
Ryan C. Gordon
62494a2e27 Merge SDL-ryan-batching-renderer branch to default. 2018-10-31 15:03:41 -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
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
0c2e10dce4 render: Make the GL backends cache and defer more state changes. 2018-10-01 22:53:45 -04:00
Ryan C. Gordon
d04e55240e render: OpenGL renderer now caches some state, to improve non-batching mode.
(other minor bug fixes in here, too)
2018-09-25 19:20:31 -04:00
Ryan C. Gordon
c01da21756 render: get rid of the predeclared functions in the GL and Metal renderers.
(others to come as I continue to update render backends!)
2018-09-24 12:30:47 -04:00
Ryan C. Gordon
051d1cfcd1 render: Make opengl backend take advantage of new high-level features. 2018-09-24 02:08:34 -04:00
Ryan C. Gordon
2241b33f55 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.
2018-09-23 23:22:56 -04:00
Ryan C. Gordon
55cb9966db render: first shot at reworking opengl backend for new batching system. 2018-09-20 16:36:54 -04:00
Sam Lantinga
eb14b635cd 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
40b27fd51b 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
90e72bf4e2 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
e3cc5b2c6b Updated copyright for 2018 2018-01-03 10:03:25 -08:00
Sam Lantinga
a6a4e27ae8 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
e9652b1987 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
c68d3ab785 Watcom supports __FUNCTION__ identifier (and surely not __PRETTY_FUNCTION__)
Partially fixes Bugzilla #3758.
2017-08-17 21:35:46 -04:00
Sam Lantinga
9451cd81ae Fixed compiler warnings 2017-08-14 20:07:30 -07:00
Sam Lantinga
c59d9923b3 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
6f843b902d 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
02773811b3 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
266816b4aa Removed newlines from error messages. 2017-03-26 21:00:19 +02:00
Sam Lantinga
13433c4a61 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
45b774e3f7 Updated copyright for 2017 2017-01-01 18:33:28 -08:00
Ryan C. Gordon
fb5fd67ccb Fixed all known static analysis bugs, with checker-279 on macOS. 2016-11-24 21:41:09 -05:00
Ryan C. Gordon
e93e91f0b5 Pacify some GCC strict-aliasing compiler warnings. 2016-11-23 21:52:48 -05:00