Commit Graph

593 Commits

Author SHA1 Message Date
Sasha Szpakowski e47acd766d Show a popup error if love.window loads but love.graphics does not.
Also include backend-specific errors in graphics initalization error messages.
Improves visibility of errors related to vulkan/metal/opengl initialization.
Related to #2335.
2026-07-12 11:01:02 -03:00
Sasha Szpakowski 142ce87335 graphics: improve setScissor's handling of fractional DPI-scaled coordinates. 2026-06-21 14:58:22 -03:00
Sasha Szpakowski 8884fb3f10 graphics: clean up some shared backbuffer settings code. 2026-06-14 19:31:40 -03:00
John Doe fc5eeb11a3 Fix copyright notice date 2026-01-21 18:49:11 +00:00
John Doe 6f08eb94c6 Update copyright notice with correct year 2025-07-12 23:19:22 +01:00
Sasha Szpakowski f8b1942ce4 opengl: fix scissor state when switching between a canvas and the screen while a scissor is active.
Fixes #2112.
2024-11-16 00:08:06 -04:00
Sasha Szpakowski 337d8fa048 remove source code support for SDL2 2024-10-18 20:22:26 -03:00
Sasha Szpakowski 8227b7bcba iOS: fix compile errors when SDL3 is used 2024-10-08 17:05:39 -03:00
Sasha Szpakowski 50ff1e4d2b use location numbers for vertex input attributes, instead of name-based binding.
- add 'location' named field to buffer and mesh vertex format tables, replaces 'name' field.
- location numbers are expected to match 'layout (location = #)' qualifiers in vertex inputs in shader code.
- deprecate vertex inputs in shader code that don't have layout location qualifiers.
- love's default vertex attributes use location 0 for position, 1 for texcoord, and 2 for color.
- add new variants of Mesh:attachAttribute, setAttributeEnabled, and isAttributeEnabled which take location numbers instead of names.

Improves draw performance in vulkan and metal backends.
2024-09-07 18:06:03 -03:00
Sasha Szpakowski 36fa78f392 workaround for nvidia shader compiler bug on very old windows drivers. 2024-08-10 11:12:27 -03:00
Sasha Szpakowski 8b37337436 Remove a workaround for a driver that's no longer supported 2024-06-20 18:14:46 -03:00
Sasha Szpakowski 54a31ec615 Minimum required opengl version is now OpenGL 3.3 / OpenGL ES 3.0. 2024-06-19 18:08:09 -03:00
Sasha Szpakowski 03f364e131 graphics: bind internal depth-compare textures to unbound sampler2DShadow vars. 2024-05-03 20:56:13 -03:00
Sasha Szpakowski e04b5f931d Move internal auto-generation for canvas mipmaps to high level code. 2024-04-14 11:31:10 -03:00
Sasha Szpakowski b01ff0e8ee opengl: fix GL errors when MSAA is enabled for the window. 2024-04-09 17:33:11 -03:00
Sasha Szpakowski 7bfbd647ba Make shader clip space consistent across APIs and projection matrices.
- All shaders are expected to output clip space values that are effectively y-up, with [-1, 1] z, in NDC.
- The transform to a backend's expected clip space values from the above range now happens after user vertex shader code is run, instead of inside a projection matrix.
- Projection matrices no longer need to be flipped when rendering to a canvas versus the main screen.

This means custom projection matrices might need to be altered to account for the more consistent range.
2024-03-23 22:00:02 -03:00
Sasha Szpakowski 4d1865fe1a opengl: attempt to fix the Android workaround for r8 pixel format support. 2024-03-17 13:54:40 -03:00
Sasha Szpakowski f8859358c3 allow graphics debug output when OpenGL ES 3.2 is used. 2024-03-12 18:28:26 -03:00
Sasha Szpakowski 930053d81d opengl: ignore debug notifications when debug output is enabled. 2024-03-12 18:27:49 -03:00
Sasha Szpakowski 42812ad521 Add texture views. Fixes #2022.
Add love.graphics.newTextureView(basetexture, viewsettings). Requires GLSL4 support.
Add 'viewformats' boolean setting to texture setting tables.
Add Texture:hasViewFormats.

The viewsettings table has the following fields:
  format = nil, -- set this to a pixel format to override the base format. It must have the same number of bytes per pixel as the original, and the 'viewformats' setting on the original texture must be true for this to work. Cannot be used for compressed or depth/stencil textures.
  type = nil, -- set this to a texture type to override the base texture type. 2d base textures can make [2d, array] views. [array, cube] base textures can make [2d, array, cube] views.
  mipmapstart = nil, -- set to a number to use a less detailed mipmap level as a base.
  mipmapcount = nil, -- set to a number to override the number of mipmaps in the texture view.
  layerstart = nil, -- set to a number to use a specific layer or cube face as a base.
  layers = nil, -- set to a number to override the number of layers in an array texture view.
2024-02-24 15:45:43 -04:00
Sasha Szpakowski 1e97e09b28 Rework internal module registration to happen in constructors. 2024-02-24 15:21:38 -04:00
Sasha Szpakowski 64a30f177f Merge branch 'main' into 12.0-development 2024-02-10 12:24:48 -04:00
Sasha Szpakowski 94d5864144 update year for copyright notice 2024-02-10 12:13:22 -04:00
Sasha Szpakowski 3e8345280f Move default texel and shader storage buffers to high level code. 2024-01-08 22:13:47 -04:00
Sasha Szpakowski aaab9791d5 Improve backbuffer depth buffer.
- Setting the depth buffer for the backbuffer is now done as a boolean instead of a bit depth integer, in love.conf or love.window.setMode.
- Error if depth writes are enabled when the active canvas setup or backbuffer does not have a depth buffer (now it matches stencil behaviour).
- Don't allocate a backbuffer depth-stencil buffer if they're not requested. Metal also determines the format for that buffer based on which combination of depth and stencil is requested. OpenGL still has to allocate the depth-stencil buffer for the backbuffer all the time, because changing it requires the context to be recreated.
2024-01-06 15:21:06 -04:00
Sasha Szpakowski 04462ece30 graphics: clean up some stencil code 2024-01-04 21:35:52 -04:00
Sasha Szpakowski 9b5851e039 Move current love.graphics.setStencilMode functionality to setStencilState.
Add new higher level love.graphics.setStencilMode function.
- Add love.graphics.setStencilMode(mode [, value = 1])
- Add love.graphics.setStencilMode().
- Add mode, value = love.graphics.getStencilMode().

The possible modes are "off" (same as no parameters), "draw", and "test".
The "draw" mode disables color writes and sets the stencil state to ("replace", "always") using the given value.
The "test" mode enables color writes and sets the stencil state to ("keep", "equal") using the given value to compare to.
2024-01-04 16:23:49 -04:00
Sasha Szpakowski dbcdbc47d5 Add debugname field to shader options table. 2023-12-29 16:51:24 +01:00
Sasha Szpakowski 8872497561 graphics: handle default textures in high level code.
Previously each backend had to set up default textures with its own code, which needs some care for it to be robust.
2023-12-27 21:28:02 +01:00
Sasha Szpakowski 343d192f10 Compressed texture formats have explicit sRGB variants 2023-10-14 15:01:01 -03:00
Sasha Szpakowski 983ea6c0e6 Remove explicit support for systems that don't support rgba8 canvases.
This is just a very small number of really old OpenGL ES 2 drivers.
2023-10-13 21:53:45 -03:00
Sasha Szpakowski 8958d155ab opengl: Fix blue component of love.graphics.setColorMask 2023-10-09 15:13:03 -03:00
Sasha Szpakowski 4787d50078 opengl: fix color mask 2023-10-09 14:10:24 -03:00
Sasha Szpakowski 2789e5eabf opengl: fix clearing integer format Canvases. 2023-10-08 21:36:10 -03:00
Sasha Szpakowski b8cbb62bc3 opengl: scissor and color mask no longer affects love.graphics.clear.
This makes it more consistent with other backends.
2023-10-08 21:08:59 -03:00
Sasha Szpakowski 2178b634c8 Add functions for indirect draws and compute dispatches.
Resolves #1879.

- Add an 'indirectdraw' boolean field to the graphics feature support table returned by love.graphics.getSupported. This is almost always supported when compute shaders are supported, except on a few older phones.

- Add an 'indirectarguments' boolean field to the settings table in love.graphics.newBuffer.

- Add love.graphics.dispatchIndirect(shader, argumentsbuffer [, argumentsindex = 1]).
    The compute dispatch's threadgroup width, height, and depth values are fetched from the buffer (as 3 uints) instead of coming from function parameters.

- Add love.graphics.drawIndirect(mesh, argumentsbuffer, argumentsindex, x, y, ....).
    Vertex or index count, instance count, and other related parameters for drawing the mesh are fetched from the buffer (as 4 or 5 uints depending on whether the mesh has an index buffer) instead of coming from function parameters. It's usually a good idea to keep parameters other than the instance count in sync with what the mesh should be using.

- Add love.graphics.drawFromShaderIndirect(drawmode, argumentsbuffer [, argumentsindex = 1] [, maintexture = nil]) and drawFromShaderIndirect(indexbuffer, argumentsbuffer [, argumentsindex] [, maintexture = nil]).
    Vertex or index count, instance count, and other related parameters are fetched from the buffer as 4 or 5 uints, as above.

For the dispatch indirect arguments buffer, it has to have 3 uint32 elements: { uint threadgroupsX, uint threadgroupsY, uint threadgroupsZ }.

For non-indexed draws, the arguments buffer has to have 4 uint32 elements: { uint vertexCount, uint instanceCount, uint baseVertex, uint baseInstance }. Note that baseInstance should always be set to 0 as many drivers don't support non-zero values.

For draws which use an index buffer, the arguments buffer has to have 5 uint32 elements: { uint indexCount, uint instanceCount, uint firstIndex, uint baseVertex, uint baseInstance }. As above, the baseInstance value should always be 0.

A buffer can be created to have an array of those structures, which can be used with the argumentsindex parameter of the Indirect dispatch/draw functions.
2023-02-05 15:55:19 -04:00
Sasha Szpakowski defe811f62 Allow creating a mipmapped texture with less than the full mip range.
When creating a texture with user-specified mipmaps, it no longer errors if all mipmaps down to 1x1 aren't present.

Added a 'mipmapcount' field to the settings table in newImage and friends (only used when mipmaps are enabled for the texture.) If it's set, only mipmap levels up to the specified count will be created instead of always creating the full range.

Old OpenGL ES 2 devices don't support loading a mipmapped texture without the full mipmap range, so there's a new 'mipmaprange' boolean field in the table returned by love.graphics.getSupported.
2023-01-29 16:02:39 -04:00
Sasha Szpakowski 249d90067e Don't discard the backbuffer depth/stencil in setCanvas.
#1893.
2023-01-11 08:58:12 -04:00
Sasha Szpakowski f6cdbdc868 Merge branch 'main' into 12.0-development 2022-12-31 22:46:34 -04:00
Sasha Szpakowski c823dbca96 Update copyright year for 2023 2022-12-31 22:25:49 -04:00
Alex Szpakowski 258d2334af OpenGL: Fix missing 'keep' and 'zero' stencil action implementations.
Fixes #1818
2022-07-09 09:00:58 -03:00
Alex Szpakowski 3a5c3df02f Add sync and async texture and buffer readback APIs.
- Add imagedata = love.graphics.readbackTexture(texture, [slice, mipmap, x, y, w, h, [dest, destx, desty]]).
- Add readback = love.graphics.readbackTextureAsync(texture, [slice, mipmap, x, y, w, h, [dest, destx, desty]]).
- Add bytedata = love.graphics.readbackBuffer(buffer, [offset, size, [dest, destoffset]]).
- Add readback = ove.graphics.readbackBufferAsync(buffer, [offset, size, [dest, destoffset]]).
- Deprecate Texture:newImageData.

The async variants return a new GraphicsReadback object. It has the following methods:
- isComplete()
- hasError()
- wait()
- getBufferData()
- getImageData()
- update() (called automatically every frame by love, not normally needed).

Support notes:
- readbackBuffer and readbackBufferAsync require buffer copying support.
- readbackTexture with a render target (canvas) is always supported. readbackTexture with a non-render-target requires copy-texture-to-buffer support.
- readbackTextureAsync with a render target requires copy-render-target-to-buffer support. readbackTextureAsync with a non-render-target requires copy-texture-to-buffer support.
2022-05-30 21:53:55 -03:00
Alex Szpakowski fb450b1df4 Add internal code for temporary buffers. 2022-05-30 21:46:55 -03:00
Alex Szpakowski ee336e5393 opengl: restructure code for computing format support. 2022-04-23 13:15:58 -03:00
Alex Szpakowski 28a64c2b29 Use uint32 instead of int for some internal bit-flags. 2022-04-23 09:41:29 -03:00
Miku AuahDark 405e33a689 Use int instead of PixelFormatUsageFlags for isPixelFormatSupported. 2022-03-05 13:42:20 +08:00
Alex Szpakowski 0fa00e0bdc love.graphics.newShader: add a compile options table parameter.
The only field currently read from the table is 'defines', which can contain either an array of define names, or name-value pairs.
For example: newShader(file, {defines={"MYFEATURE_ENABLED", MYSETTING=1}})

Fixes #1577
2022-02-20 12:23:41 -04:00
Alex Szpakowski 6dbb7fa5de Add love.graphics.setStencilMode. Remove old stencil API.
- Add setStencilMode(drawaction, comparemode, value = 0, readmask = 0xFF, writemask = 0xFF).
- Add getStencilMode.
- Remove love.graphics.stencil.
- Remove love.graphics.set/getStencilTest.

Note that the new setStencilMode API does not clear the stencil buffer, and does not turn off color writes (it can still be done manually), unlike love.graphics.stencil.

Fixes #1161.
Fixes #1251.
2022-01-22 23:36:07 -04:00
Alex Szpakowski 87592513a2 metal: fix automatic depth/stencil with setCanvas. 2022-01-22 20:57:06 -04:00
Alex Szpakowski 4ca3535cd2 Metal: fix clamp-to-one texture wrap mode detection. 2022-01-15 23:31:07 -04:00