Commit Graph

294 Commits

Author SHA1 Message Date
Sasha Szpakowski 3412a4defc Improve format fallbacks when using setCanvas with automatic depth/stencil. 2025-01-25 13:25:20 -04:00
Sasha Szpakowski da365e2ab9 Add t.graphics.lowpower = true/false love.conf option (defaults to false).
Add love.graphics.isLowPowerPreferred.

It's currently hooked up in the vulkan backend.
#2127
2024-12-20 21:02:20 -04:00
Sasha Szpakowski 486cc22dbd prefer vulkan over opengl by default on windows/linux. 2024-12-10 19:44:39 -04:00
Sasha Szpakowski e1494d4ad2 revert to previous names for a couple graphics enums 2024-10-03 12:42:11 -03:00
Sasha Szpakowski 64e4eaec74 vulkan: memory barriers for buffer copy/write operations. 2024-09-30 14:43:27 -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 906f615a9e disallow texture:replacePixels and non-canvas textures for depth/stencil pixel formats. 2024-07-15 17:55:31 -03:00
Sasha Szpakowski bb5cea6d7d clean up setCanvas error checking code 2024-07-15 17:44:03 -03:00
Sasha Szpakowski 72af731320 Fix wording of some error checks in setCanvas. 2024-07-15 17:24:21 -03:00
Sasha Szpakowski 25a6576785 Remove more obsolete code. 2024-06-20 22:14:31 -03:00
Sasha Szpakowski 66a1197053 Remove a couple internal support checks that aren't needed anymore. 2024-06-20 17:50:36 -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 b48d81d976 rename love.graphics.setCustomProjection to setProjection. 2024-03-31 21:12:01 -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 698d305212 Remove love.graphics.setOrthoProjection and setPerspectiveProjection 2024-03-23 17:58:34 -03:00
Sasha Szpakowski ed6a50178c Filled polygons have texture coordinates computed from their bounds.
Fixes #1951.
2024-02-25 20:09:06 -04: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 8bf04df6e1 Fix uninitialized pointers leading to crashes 2024-01-08 22:31:06 -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 501c41e10f Fix compiler warning 2024-01-06 15:44:39 -04:00
Sasha Szpakowski 131b6c51e0 graphics: fix recursion when creating a default texture. 2024-01-06 15:22:02 -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 e42019c59e Add buffer stats to love.graphics.getStats.
- Add 'buffers' field, to count the total number of graphics buffer objects.
- Add 'buffermemory' field, to estimate the total number of bytes of graphics memory used by all buffers.
2023-12-25 23:25:46 +01:00
Sasha Szpakowski 5a0a6a1a27 All constructors for making a TrueType font take an optional settings table.
This supersedes the existing optional hinting and dpi scale parameters. The table's fields are:
{
  hinting = "normal",
  dpiscale = 1, -- nil will default to the current window DPI scale.
}
2023-10-20 20:19:30 -03: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 416abdbc59 love.graphics.copyBuffer: slightly more robust error handling. 2023-02-19 19:36:32 -04: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 d3747cebb1 Rename love.graphics.drawShaderVertices to drawFromShader. 2023-02-05 15:16:10 -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 94d05e319b Clear auto-generated temporary depth/stencil buffers in setCanvas.
Previously it would discard them, which needed the user to call love.graphics.clear afterward to get them into a valid state.

The current code has suboptimal performance if the user still calls clear after setCanvas (a common situation), so more optimizations will probably be needed.

Fixes #1843.
2023-01-11 18:17:22 -04:00
Sasha Szpakowski d085f44e6a Merge branch '12.0-development' into text-shaping 2023-01-01 12:18:54 -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
Sasha Szpakowski 7a0f6621e7 Initial (WIP) Harfbuzz text shaping integration.
This a significant refactor / rewrite of much of the love.graphics Font code.
Text positioning is now split into TextShaper classes in the love.font module. This isn't exposed to users yet.
BMFonts and ImageFonts use the same text shaping as before (in the new TextShaper API). Fonts loaded via FreeType now use Harfbuzz for text shaping.

The new code isn't at feature-parity with the old code yet. Harfbuzz-based text shaping enables kerning support in more fonts, character combining into ligature glyphs, and directions other than left-to-right (this isn't supported in love yet).
2022-12-26 19:06:08 -04:00
Sasha Szpakowski f17d3d94f1 Rename love.graphics Text objects to TextBatch.
The name Text is too generic compared to what they're designed for, it made people unnecessarily confused about their purpose.
2022-12-08 18:46:44 -04:00
niki fe8cbfecbf vulkan: remove shader version code 2022-09-19 15:43:25 +02:00
niki 9fde550ab5 prioritize opengl over vulkan 2022-09-18 16:11:08 +02:00
niki 00974b5820 vulkan: move shader compilation into Shader 2022-07-18 22:28:41 +02:00
niki 565455c3ea proper selection of vulkan renderer 2022-07-10 03:46:12 +02:00
niki 4c415479c0 Merge remote-tracking branch 'origin/12.0-development' into vulkan 2022-06-11 01:22:29 +02:00