Commit Graph

279 Commits

Author SHA1 Message Date
Sasha Szpakowski 36fa78f392 workaround for nvidia shader compiler bug on very old windows drivers. 2024-08-10 11:12:27 -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 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 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 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 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 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 f4c38eb00a Revert "vulkan: use push constants for builtin uniforms"
This reverts commit 47e3fc85d2.
2022-09-15 15:55:47 +02:00
niki 47e3fc85d2 vulkan: use push constants for builtin uniforms
when available
2022-09-15 15:17:06 +02:00
niki 4c415479c0 Merge remote-tracking branch 'origin/12.0-development' into vulkan 2022-06-11 01:22:29 +02: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
niki 75a6bc9b5d Merge remote-tracking branch 'origin/12.0-development' into vulkan 2022-05-06 16:46:55 +02: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
niki 197dfb9738 start implementing vulkan Shader type 2022-02-06 22:56:24 +01:00
niki 65074dae15 hello world triangle 2022-02-04 23:45:58 +01: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 62de8f62c7 metal: hook up emulated 'fan' mesh draw mode. 2022-01-22 12:59:09 -04:00
Alex Szpakowski 4ca3535cd2 Metal: fix clamp-to-one texture wrap mode detection. 2022-01-15 23:31:07 -04:00
Alex Szpakowski f93d167a47 Merge branch '12.0-development' into metal 2022-01-12 18:23:23 -04:00
Alex Szpakowski ff83ee6a9c Add basic ortho and perspective projection APIs to love.graphics.
- Added love.graphics.setOrthoProjection.
- Added love.graphics.setPerspectiveProjection.
- Added love.graphics.resetProjection.

Note that the projection is reset whenever the canvas changes.
2022-01-08 22:56:21 -04:00
Alex Szpakowski d51e012812 Merge branch '12.0-development' into metal 2022-01-05 21:12:22 -04:00
Alex Szpakowski 7f3538d2ba Merge branch 'main' into 12.0-development 2022-01-05 21:10:27 -04:00
Alex Szpakowski 5864d83c31 Add ability to configure which renderers are used by love.graphics.
- Add t.renderers and t.excluderenderers love.conf fields. They can be an array of renderer names.
- Add --renderers a,list,of,renderernames and --excluderenderers more,renderers argument options.
2022-01-04 21:29:56 -04:00
Alex Szpakowski ecbc5ca7f6 Add love.graphics.getQuadIndexBuffer.
love's pre-generated quad index buffer is useful when combined with drawShaderVertices. Note that it uses 16 bit indices so it can only draw up to 16k quads in a single call.
2022-01-03 16:22:08 -04:00