Ryan C. Gordon
b7a4fdd318
metal: Make sure we have a command buffer available before trying to present.
...
This fixes a case where you render to the backbuffer, then render to a render
target, set the current target back to the backbuffer, and then present
without drawing anything else; in this circumstance, the Present command
would never happen.
Fixes Bugzilla #5011 .
2020-07-17 11:16:35 -04:00
Sam Lantinga
15294e2121
Fixed iOS build
2020-05-26 13:54:47 -07:00
Sam Lantinga
f16e6bfa8e
Fixed creating a metal renderer without specifying a metal window
2020-05-25 14:10:51 -07: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
Sam Lantinga
13155b35b4
The scissor rect needs to be updated when the viewport changes in the Metal renderer
2020-02-10 09:42:53 -08:00
Sam Lantinga
a8780c6a28
Updated copyright date for 2020
2020-01-16 20:49:25 -08:00
Sam Lantinga
981e0d367c
Fixed bug 4903 - Lack of color multiply with alpha (SDL_BLENDMODE_MOD + SDL_BLENDMODE_BLEND) blending mode for all renderers
...
Konrad
This kind of blending is rather quite useful and in my opinion should be available for all renderers. I do need it myself, but since I didn't want to use a custom blending mode which is supported only by certain renderers (e.g. not in software which is quite important for me) I did write implementation of SDL_BLENDMODE_MUL for all renderers altogether.
SDL_BLENDMODE_MUL implements following equation:
dstRGB = (srcRGB * dstRGB) + (dstRGB * (1-srcA))
dstA = (srcA * dstA) + (dstA * (1-srcA))
Background:
https://i.imgur.com/UsYhydP.png
Blended texture:
https://i.imgur.com/0juXQcV.png
Result for SDL_BLENDMODE_MOD:
https://i.imgur.com/wgNSgUl.png
Result for SDL_BLENDMODE_MUL:
https://i.imgur.com/Veokzim.png
I think I did cover all possibilities within included patch, but I didn't write any tests for SDL_BLENDMODE_MUL, so it would be lovely if someone could do it.
2020-01-16 08:52:59 -08:00
Ozkan Sezer
ef3ca2cc46
Fix build error in SDL_render_metal.m (bug #4916.)
...
Patch provided by Konrad. Error was introduced by commit 522164980828 for bug #4914 .
2019-12-23 19:55:10 +03: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
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
Alex Szpakowski
216f5b98ac
metal: Fix compilation when using older Apple SDKs (bug #4828 ).
2019-10-17 18:48:58 -03:00
Alex Szpakowski
bfdb0e9743
metal renderer: optimize SDL_RenderFillRect slightly.
2019-08-18 10:38:32 -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
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
Sam Lantinga
1213fe79d8
Worked around "Undefined symbol: ___isPlatformVersionAtLeast()" link error on Xcode 11 beta
2019-06-14 13:56:42 -07:00
Sam Lantinga
5e13087b0f
Updated copyright for 2019
2019-01-04 22:01:14 -08: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
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
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
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
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
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
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
8955fb9b31
render: First shot at moving metal backend over to new batching system.
2018-09-20 16:40:04 -04:00
Ryan C. Gordon
264b81b481
metal: Make sure layer drawableSize is adjusted on resize.
...
Fixes Bugzilla #4250 .
2018-09-06 00:56:13 -04:00
Ryan C. Gordon
3634e563c4
metal: SDL_UpdateYUVTexture shouldn't swap planes based on format.
2018-09-01 20:47:12 -04:00
Alex Szpakowski
8c41e2624e
metal: Fix SDL_RenderReadPixels to wait for the GPU to finish rendering to the active texture before reading its pixels.
2018-10-13 03:36:42 -03:00
Alex Szpakowski
d9094421e1
metal: Fix high dpi and resizing on macOS, and clean up iOS code. Fixes bug #4250 .
2018-10-12 17:55:42 -03: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
Sam Lantinga
72d4507918
Added availability check to fix compiler warning for symbol only available on tvOS 11.0 and newer
2018-01-10 10:42:40 -08:00
Alex Szpakowski
7d5437bb31
metal: set max texture size based on device capability.
2018-01-07 22:00:37 -04:00
Alex Szpakowski
a8c0532c08
metal: Fix pipeline states to use the pixel format of the current render target, instead of a hard-coded format.
2018-01-07 16:57:32 -04:00
Alex Szpakowski
740a90af37
metal: Add support for YUV/NV12 texture formats.
2018-01-06 18:54:12 -04:00
Alex Szpakowski
9a8683b275
metal: use a private instead of managed buffer for the renderer's non-changing constant data.
...
Recommended by Xcode's Metal frame capture analysis.
2018-01-04 22:16:42 -04:00
Alex Szpakowski
990ebba55a
metal: Implement fast hardware clearing when possible, by deferring the start of a render pass until a clear or draw operation happens.
2018-01-04 19:29:33 -04:00
Sam Lantinga
e3cc5b2c6b
Updated copyright for 2018
2018-01-03 10:03:25 -08:00
Alex Szpakowski
888198ee31
metal: Misc. improvements.
...
- Use a single buffer for various non-changing constants accessed by the GPU, instead of multiple buffers.
- Do the half-pixel offset for points and lines using a transform matrix so we don't need a malloc when rendering.
- Don't add a half-pixel offset for other primitives and textures. This matches D3D and GL render behaviour.
- Remove the half-texel texture coordinate offset since it's not needed now that there's no more half-pixel position offset when rendering a texture.
- Don't try to set texture usage on iOS 8 since it doesn't exist there.
2018-01-03 00:43:01 -04:00
Alex Szpakowski
f9cd765020
metal and moltenvk: fix highdpi.
2018-01-02 21:44:28 -04:00
Sam Lantinga
b3b5c47366
Fixed direction of y adjustment for new orthographic projection in the metal renderer
2018-01-02 14:32:15 -08:00
Sam Lantinga
fa86807ceb
Fixed metal renderer pixel centers when drawing
2018-01-02 14:11:10 -08:00
Alex Szpakowski
07f08b47ff
metal: Fix a typo preventing iOS compilation...
2018-01-01 23:06:08 -04:00
Alex Szpakowski
1cc6603378
metal: Clean up manual reference counting. Fixes some memory leaks.
2018-01-01 23:03:50 -04:00
Alex Szpakowski
a452a08458
iOS: fix build
2018-01-01 19:40:29 -04:00
Alex Szpakowski
639ea9fdbc
metal: Use sampler state objects instead of shader-declared samplers for linear vs nearest filtering.
...
This avoids a ton of shader duplication once multiple shaders that use samplers are added (e.g. the currently missing YUV shaders).
2018-01-01 19:37:16 -04:00
Alex Szpakowski
cf45cf70e5
metal: Add support for custom blend modes.
2018-01-01 18:06:27 -04:00
Alex Szpakowski
85470a2f95
metal: implement SDL_RenderCopyEx, and fix a memory leak in SDL_CreateTexture.
2017-12-31 21:06:16 -04:00
Alex Szpakowski
047d387b2e
metal: Use the existing cocoa code for creating a Metal view on macOS. Fixes the renderer size when the window is resized.
2017-12-31 15:30:08 -04:00
Alex Szpakowski
42b19c9749
metal: Respect the vsync flag on macOS 10.13+.
2017-12-30 22:39:55 -04:00
Alex Szpakowski
e24dc9053b
metal: use a projection matrix instead of manually transforming vertices into clip space on the CPU.
2017-12-30 20:32:22 -04:00
Alex Szpakowski
49df65c25a
metal: only 4 (instead of 5) vertices are needed to draw rectangles and textures, and only 3 (instead of 5) vertices are needed to cover the screen for the 'full-screen quad' when clearing.
2017-12-30 18:48:07 -04:00
Sam Lantinga
7ac46a7449
The newer compilers generate the property boilerplate automatically
2017-12-11 11:34:53 -08:00
Sam Lantinga
358e4d9c7e
Fixed Mac OS X build
2017-12-11 11:02:51 -08:00
Sam Lantinga
c2cc9c166c
Backed out using pixel texture coordinates, it had weird visual side effects
2017-12-09 19:48:38 -08:00
Sam Lantinga
8aad49238b
Fixed normalized coordinates when the viewport is set
2017-12-09 19:41:08 -08:00
Sam Lantinga
441d309551
Added support for linear sampling and pixel coordinates in the metal renderer
2017-12-09 15:00:41 -08:00
Sam Lantinga
f55c998891
Fixed pixel positioning and size for the Metal renderer
2017-12-09 12:58:41 -08:00
Ryan C. Gordon
7dac177cd1
metal: fixed render target support.
2017-12-09 03:28:23 -05:00
Ryan C. Gordon
85d12d8f21
metal: Added some comments and FIXMEs.
2017-12-09 03:27:52 -05:00
Ryan C. Gordon
686fc0937e
metal: Cleaned up some reference count politics.
2017-12-08 18:26:26 -05:00
Sam Lantinga
cf3d450313
Added SDL_RenderGetMetalLayer() and SDL_RenderGetMetalCommandEncoder()
2017-12-08 14:30:10 -08:00
Sam Lantinga
c403c0fa9a
Fixed Metal renderer memory leak
2017-12-08 13:20:20 -08:00
Ryan C. Gordon
81a33985e1
metal: Don't check if Metal is available if targeting modern macOS versions.
2017-12-08 14:03:36 -05:00
Sam Lantinga
b733dcc208
Minor cleanup
2017-12-08 12:02:23 -08:00
Sam Lantinga
5182c23c6b
Fixed minor memory leak in the Metal renderer
2017-12-08 11:35:19 -08:00
Sam Lantinga
dc04f290a3
Defer getting the next drawable until we actually start rendering
...
This works better for games where there may be a bunch of simulation logic that needs to be run before the next rendering pass, and prevents blocking if the next drawable is busy.
2017-12-08 08:58:02 -08:00
Sam Lantinga
104decd16d
Fixed runtime errors on iOS
2017-12-07 18:08:51 -08:00
Sam Lantinga
ba9c336e04
Fixed building for simulators or older iOS SDKs
2017-12-07 17:47:01 -08:00
Sam Lantinga
6deb1e7595
Fixed compiling Metal renderer on iOS
2017-12-07 17:12:03 -08:00
Sam Lantinga
1ae73a2be8
Added iOS and OSX versions of the Metal shaders
2017-12-07 16:08:47 -08:00
Sam Lantinga
b2859af6df
Enable building the Metal renderer by default, and weak link the Metal framework so the SDL library is safe to use on older Macs
...
Also generate iOS versions of the Metal shaders
2017-12-07 16:08:09 -08:00
Ryan C. Gordon
2a2c8d42ca
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