Commit Graph

150 Commits

Author SHA1 Message Date
Sasha Szpakowski 0b48dacb4e Remove convenience constructor functions for vertex and index buffers.
love.graphics.newVertexBuffer and newIndexBuffer don't do enough to justify their existence since love.graphics.newBuffer already covers all buffer creation functionality.

1-based indices in newIndexBuffer versus 0-based indices in newBuffer(..., {index=true}) was also confusing.
2023-03-26 20:46:24 -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 0b75f6cfa5 Missed some files... 2022-12-31 22:36:48 -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
Miku AuahDark 4862d95687 Deprecate love.graphics.setNewFont. 2022-10-17 01:30:44 +08: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 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 173fe3dab5 Add a love.graphics.setColorMask variant which accepts a single bool.
Remove the variant which accepted no args - it would be too confusing because setColorMask(false) does the opposite of what setColorMask(nil) used to do.
2022-01-22 23:27:53 -04:00
Alex Szpakowski f93d167a47 Merge branch '12.0-development' into metal 2022-01-12 18:23:23 -04:00
Alex Szpakowski f7f5290693 love.graphics.newMesh: DrawMode arg no longer defaults to 'fan'. 2022-01-09 14:37:33 -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
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 52101b2563 Add love.graphics.copyTextureToBuffer and copyBufferToTexture. 2021-12-28 12:46:56 -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
Alex Szpakowski c8038f22df Merge branch 'main' into 12.0-development 2021-12-24 11:35:35 -04:00
Miku AuahDark fb815edc28 Change luaL_loadbuffer chunkname with prefixes. 2021-12-12 09:23:00 +08:00
Alex Szpakowski a551fcd492 Initial support for writing to textures in compute shaders. 2021-08-13 14:43:03 -03:00
Alex Szpakowski cffd485976 Allow rendering to integer textures. 2021-08-12 17:43:33 -03:00
Alex Szpakowski 1cf8f1192c vertex format table in newMesh uses the same fields as newBuffer.
Deprecate (but don't remove) the old {name, type, elementcount} vertex format style. The new style is {name=attributename, format=dataformat}.
2021-08-02 16:11:58 -03:00
Alex Szpakowski 80f051b97d Merge pull request #1715 from bjornbytes/compute-shaders
Compute Shaders
2021-07-18 13:09:48 -03:00
bjorn 13a10ac482 love.graphics.newComputeShader; 2021-07-17 19:58:11 -07:00
bjorn 25fbf1d8ce love.graphics.dispatchThreadgroups; 2021-07-17 19:49:53 -07:00
Alex Szpakowski 5ef1709c02 Expose love.markDeprecated.
Arguments are (level, name, apitype, deprecationtype [, replacementname]). Call it inside a function.
2021-06-06 18:16:56 -03:00
Alex Szpakowski 21f5ba86d3 Merge branch 'master' into 12.0-development 2021-04-07 20:33:44 -03:00
Alex Szpakowski 2d2918a254 Merge branch '12.0-development' into metal 2021-03-26 21:42:08 -03:00
Alex Szpakowski 694d448e83 Vertex shaders can write to gl_PointSize (fixes #1603).
If a shader uses gl_PointSize then it can only be used when drawing points. If a shader doesn't use gl_PointSize then it can't be used when drawing points.

Added 'ConstantPointSize' and 'CurrentDPIScale' built-in shader uniforms.

ConstantPointSize is in DPI-scaled points, whereas gl_PointSize is in pixels, so to get the correct default behaviour a shader needs to do gl_PointSize = ConstantPointSize * CurrentDPIScale
2021-01-23 13:47:12 -04:00
Alex Szpakowski deff795908 Rename some internal buffer enums to better match what they do 2021-01-17 20:59:16 -04:00
Alex Szpakowski ef5a0250e9 Fix compilation on windows 2021-01-17 14:13:16 -04:00
Alex Szpakowski e2838131f2 Add love.graphics.copyBuffer. 2021-01-17 14:02:00 -04:00
Alex Szpakowski 20a92a4106 Merge branch '12.0-development' into metal 2020-12-22 22:37:17 -04:00
Alex Szpakowski 1f9d98263d Refactor Buffer internals.
Allows buffers created with love.graphics.newBuffer to only allocate VRAM data. Previously they had a copy of their contents in RAM.
Also makes it easier to implement Buffers in other graphics APIs and to implement more types of Buffers in the future.
2020-12-22 19:23:02 -04:00
Alex Szpakowski 27897b4af1 Merge branch '12.0-development' into metal 2020-10-24 00:36:33 -03:00
Alex Szpakowski 365387150e Merge branch 'master' into 12.0-development 2020-08-09 12:25:07 -03:00
Alex Szpakowski 5f4d2f3323 Fix love.graphics.newVolumeImage when explicit mipmaps are given
Fixes issue #1602
2020-08-09 12:12:28 -03:00
Alex Szpakowski f168333938 Simplify Buffer APIs.
Remove Buffer:set/getElement, Buffer:isCPUReadable, and the cpureadable flag in newBuffer's settings parameter.
2020-08-01 21:51:37 -03:00
Alex Szpakowski 7a50f32585 Merge branch '12.0-development' into metal 2020-07-29 18:21:19 -03:00
Alex Szpakowski b011487a3e Add new texel buffer type.
GLSL 3+ shaders can read from texel buffers by declaring a uniform samplerBuffer variable and calling texelFetch with a 0-based index, in the shader code. All attributes in a texel buffer's format array must have the same data format (e.g. all 'floatvec4' formats).

Shader:send accepts a texel Buffer for samplerBuffer uniforms.

Added 'texelbuffer' to love.graphics.getSupported (requires GLSL 3+ and desktop OpenGL).
Added 'texelbuffersize' to love.graphics.getSystemLimits. Returns the max number of values in a texel buffer (array length multiplied by the number of attributes declared in the buffer's format array).
2020-07-28 20:44:36 -03:00