Commit Graph

258 Commits

Author SHA1 Message Date
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
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 a533982cb4 Replace internal 'staging' buffer data type with new 'readback' type. 2022-05-30 21:43:25 -03:00
niki 75a6bc9b5d Merge remote-tracking branch 'origin/12.0-development' into vulkan 2022-05-06 16:46:55 +02: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 c28731ea80 opengl: fix love's internal quad index buffer failing to populate 2022-02-12 09:37:30 -04:00
niki 197dfb9738 start implementing vulkan Shader type 2022-02-06 22:56:24 +01:00
niki 7d680838b6 restructure to not hardcore draw vk commands 2022-02-05 20:44:36 +01:00
niki 65074dae15 hello world triangle 2022-02-04 23:45:58 +01:00
Alex Szpakowski 5549279eb1 Use metal by default on supported systems.
There are still issues to fix with the Metal backend, but it's more easily testable now at least.
2022-01-31 21:27:59 -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 c26f6ed94f metal: improve performance of auto depth/stencil in setCanvas. 2022-01-22 23:12:42 -04:00
Alex Szpakowski 4c3c875aa9 metal: clean up some code around render pipeline states. 2022-01-22 21:29:57 -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 d96e1636b1 Improve setCanvas validation of volume texture layer + mipmap values. 2022-01-16 13:00:12 -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 a76606e76e metal: fix some define checks. 2022-01-06 17:34:20 -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 5426be4252 Prefer OpenGL to Metal (for now) 2022-01-05 20:58:38 -04:00
Alex Szpakowski 44a434604a t.renderers/excluderenderers doesn't affect renderer order. 2022-01-05 20:52:17 -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
Alex Szpakowski 42e8df1489 Add a GraphicsFeature support enum for 32 bit index buffers.
Some old OpenGL ES 2 systems don't support them.
2022-01-03 16:09:38 -04:00
Alex Szpakowski ac8f5374c2 Fix a minor validation bug. 2022-01-03 14:36:22 -04:00
Alex Szpakowski 0c4be3d5e3 Add love.graphics.drawShaderVertices (name subject to change).
It draws a number of vertices, or a number of indices from an index buffer, without using any vertex data from a vertex buffer. A custom shader is required while using it.

It is useful when a custom GLSL3 vertex shader which uses love_VertexID is used to pull or compute per-vertex information from other sources.
2022-01-03 14:33:54 -04:00
Alex Szpakowski de89f5a9eb love.graphics.apply/replaceTransform can accept x,y,angle,etc. args. 2022-01-03 11:57:05 -04:00
Alex Szpakowski 40aa50662a Merge branch '12.0-development' into metal 2022-01-01 15:36:57 -04:00
Alex Szpakowski 8e7fd10b6f Update copyright year for 2022 2021-12-31 18:33:40 -04:00
Alex Szpakowski 52101b2563 Add love.graphics.copyTextureToBuffer and copyBufferToTexture. 2021-12-28 12:46:56 -04:00
Alex Szpakowski 5b3a5e7721 Remove the need for copysource and copydest buffer usage flags. 2021-12-27 21:17:04 -04:00
Alex Szpakowski 3d8117ccbb Merge branch '12.0-development' into metal 2021-12-24 15:35:18 -04:00
Alex Szpakowski e63025b74f Merge branch '12.0-development' into metal 2021-12-24 15:34:05 -04:00