Commit Graph

104 Commits

Author SHA1 Message Date
bjorn a784321d84 Rework Buffer formats;
Summary:

- Buffer length can be zero (indicates single value instead of array)
- Internally, arrays aren't coerced to array-of-single-struct
- Removes support for "flat table" data (array-of-structs w/o wrapping
  each struct in a nested table)
- Use consistent syntax for reading table data into buffers:
  - Numbers are numbers
  - Vectors are numbers, tables, or vectors
  - Structs are tables with any combination of integer/string keys
    - Fields are assigned from integer keys in order, then any remaining
      fields use the string keys
  - Arrays are tables of elements, formatted as above
- Try to improve error messages for Buffer:setData errors
2024-04-17 17:54:23 -07:00
bjorn aef71192ac Add ConvexShape;
Also luax_readmesh supports ModelData input, and the indices pointer can
be NULL to only request the vertex positions.
2024-04-09 13:01:30 -07:00
bjorn 6f0b6391df Start CompoundShape; 2024-04-07 13:47:52 -07:00
bjorn 875a7f8237 Shader rework;
- Undeprecate ShaderType (it's good actually, kinda like a pipeline bind
  point and more specific than having lovr trying to make sense of a
  random set of stages).
- Use a default uniform block instead of push constants.  The Constants
  macro now maps to a uniform block declaration.
- It is no longer possible to create a shader by giving a single
  DefaultShader string (you can still give a per-stage DefaultShader
  though).
- lovr.graphics.compileShader now takes all stages instead of a single
  stage.  In general we need all stages when compiling GLSL because
  default uniforms require linking across stages.
2024-02-21 10:21:41 -08:00
bjorn 3cf76c81e7 Refactor shader stages; rm ShaderType;
Goal is to support more combinations of shader stages, both for
vertex-only shaders and mesh/raytracing shaders in the future.  In
general most of the logic that conflated "stage count" with "shader
type" has been changed to look at individual shader stages.
2024-01-05 14:59:19 -08:00
bjorn 19ac219b0c Add File object; 2023-11-21 18:49:32 -08:00
bjorn a28d66e3a1 Mesh:setMaterial takes texture too; 2023-10-31 16:08:00 -07:00
bjorn c8eb6606c6 OpenXR layer implementation; 2023-10-25 15:24:13 -07:00
bjorn 4c2e206e30 Bindings; 2023-10-25 15:23:41 -07:00
bjorn 842df4b305 Fix buffer readback issues; 2023-10-04 08:52:05 -07:00
bjorn 9542d46f33 Buffer format cleanup; 2023-09-11 03:01:11 -07:00
bjorn 4892d228b3 WIP; 2023-07-24 15:34:44 -07:00
bjorn be795c0ebd Change vec3 back to 3 floats; Clean up maf/vectors;
The "vec3 is 4 floats" thing was consistently confusing to people.  It's
reverted everywhere except for Curve.

maf now has full sets of methods for vec2/vec3/vec4, for consistency.

Vector bindings now use luax_readvec* helper functions for the
number/vector variants, and use maf for most functionality, which cleans
things up a lot.
2023-07-10 17:51:24 -07:00
bjorn 6e018b8c96 Replace HeadsetOrigin with 'seated' flag;
Origin type used to be a query-able property of the VR system that
indicated whether the tracking was roomscale or seated-scale.

The t.headset.offset config value could be used to design an
origin-agnostic experience, which by default shifted content up 1.7
meters when tracking was seated-scale.  That way, stuff rendered at
y=1.7m was always at "eye level".  It worked pretty well.

It's getting replaced with a t.headset.seated flag.

- If seated is false (the default), the origin of the coordinate space
  will be on the floor, enabling the y=1.7m eye level paradigm.  If
  tracking is not roomscale, a floor offset of 1.7m will be emulated.
- If seated is true, the origin of the coordinate space will be y=0
  at eye level (where the headset was when the app started).  This is
  the case on both roomscale and seated-scale tracking.

So basically 'seated' is an opt-in preference for where the app wants
its vertical origin to be.

One advantage of this is that it's possible to consistently get a y=0
eye level coordinate space, which was not possible before.  This makes
it easier to design simpler experiences that only need to render a
floating UI and don't want to render a full environment or deal with
offsetting everything relative to a 'floor'.  This also makes it easier
to implement hybrid VR+flatscreen experiences, because the camera is at
y=0 when the headset module is disabled.

The opt-in nature of the flag, coupled with the fact that it is
consistent across all types of tracking and hardware, is hopefully a
more useful design.
2023-06-28 16:38:36 -07:00
bjorn 7e464d8abb Add optional mode argument to lovr.filesystem.load;
Matches Lua 5.2 / LuaJIT syntax.  luax_loadbufferx polyfills new Lua API.
2023-06-28 16:10:30 -07:00
bjorn 68878f9197 Rename/refactor more Buffer stuff;
BufferField -> DataField
fields -> format
decontaminate buffer constructor
2023-06-23 21:14:19 -07:00
bjorn 0ff633fa56 mv FieldType DataType; 2023-06-23 19:11:30 -07:00
bjorn f98306e786 rm transfer passes; rm Tally for now;
- Add Buffer:newReadback
- Add Buffer:getData
- Buffer:getPointer works with permanent buffers
- Buffer:setData works with permanent buffers
- Buffer:clear works with permanent buffers
- Add Texture:newReadback
- Add Texture:getPixels
- Add Texture:setPixels
- Add Texture:clear
- Add Texture:generateMipmaps
- Buffer readbacks can now return tables in addition to Blobs using Readback:getData

Tally is coming back soon with an improved API, it's temporarily removed
since it made the transfer rework a bit easier.

Note that synchronous readbacks (Buffer:getData, Texture:getPixels)
internally call lovr.graphics.submit, so they invalidate existing Pass
objects.  This will be improved soon.
2023-04-29 18:31:03 -07:00
bjorn 775b6e4ff7 Rename some buffer helper functions; 2023-04-29 18:31:03 -07:00
Bjorn 2d8db03faa
Merge pull request #642 from bjornbytes/buffer-improvements
Buffer Format Improvements
2023-03-21 23:07:20 -07:00
bjorn f32800c044 Clean up Model lookeruppers; Model:getMaterial takes string; 2023-03-21 21:30:11 -07:00
bjorn 92e9efd882 More flexible Buffer formats; Deprecate temp buffers;
- Pass:mesh accepts tables for vertices/indices
- Add Pass:setVertexFormat to set format used for table-based meshes
- Pass:send accepts tables for buffers
- Pass:send supports arbitrarily nested structs/arrays for push constants
- Buffer formats support arbitrarily nested structs/arrays
  - Zero-length buffers are valid and represent structs
  - Fields can have names using 'name'
  - Field types can be tables of other fields (structs)
  - Fields can have 'length' key
- newBuffer syntax has been changed to put format first (old version
  still works)
- Buffers can be created from shader variables, avoiding need to declare
  matching format.
- Pass:clear/Pass:read use byte offsets instead of indices
- Pass:copy uses byte offsets when copying a Buffer to a Buffer
- Deprecate lovr.graphics.getBuffer (tables can be used instead)
2023-03-20 13:54:37 -07:00
bjorn 41dd24edc4 Organize math module files; 2023-02-07 21:44:43 -08:00
bjorn e9776f98c6 Fix compatibility with Lua 5.2, 5.3, 5.4;
Part of this involved putting the Lua header back in api.h, since we
need to know the Lua version to define some macros properly.
2022-11-24 14:33:55 -08:00
bjorn f8f748320e Minor Shape improvements;
- Add helper functions for creating shapes to avoid duplication between
  newShape and newShapeCollider.
- Add lovr.physics.newMeshShape and lovr.physics.newTerrainShape
- Register TerrainShape so it has all the base Shape methods
- Smooth out a few TerrainShape warnings
2022-11-09 20:53:42 -08:00
bjorn 79cd7c10a1 Improve temporary buffers;
- They no longer live in temporary memory, but in a dedicated pool.
- There are error checks for using a temporary buffer after it's invalid
  - However, these are imperfect, and could be improved.  One idea is to
    avoid recycling a temporary buffer until its refcount decays (i.e.
    Lua finally decides to garbage collect it).  This would explode
    memory usage sometimes, so it could only be enabled when
    t.graphics.debug is true.
2022-08-22 20:30:09 -07:00
bjorn f515346e20 Rename CoordinateSpace;
It's now OriginType, and global -> root and local -> parent.
2022-08-17 22:33:43 -07:00
bjorn ad6360d2fd Clean up boot.lua;
A lot of clean up can happen now that C doesn't push delayed errors to
Lua.  This was happening for Pico and WebVR, neither of which are used
anymore.

Also default vsync to true but force it off if VR is active.
2022-08-12 20:18:55 -07:00
bjorn 3c71828afa Revert "Change the way modules are destroyed;"
This reverts commit 019814e2c1.
2022-08-08 23:16:34 -07:00
bjorn 019814e2c1 Change the way modules are destroyed;
They are now destroyed explicitly after tearing down the Lua state
instead of relying on finalizers.  It's definitely annoying to make it
coordinated in a centralized way like this instead of being distributed,
but there's not really any reliabel way to ensure that graphics objects
are destroyed before the graphics module/device is destroyed, which is a
problem.
2022-08-04 21:44:34 -07:00
bjorn aa4fce2842 Rename luax_atexit internals; 2022-08-04 21:33:37 -07:00
bjorn 89312c1c4b Add on-disk shader cache;
Set t.graphics.shadercache to true (the default) and lovr will
read/write a shader cache file from/to disk.
2022-08-02 22:06:44 -07:00
bjorn faa690b7f0 Material API;
Just returns everything as a table.  Some sort of key-value thing would
be nice but complicates the implementation.
2022-07-17 09:29:13 -07:00
bjorn 0b76ab7e96 Add a few Tally things; 2022-07-12 19:59:12 -07:00
bjorn 1c571001e7 Finish Model API; 2022-07-12 19:35:23 -07:00
bjorn d088c5471d Model;
Does not include some of the fancier accessors yet.
2022-07-03 17:26:31 -07:00
bjorn 1f8d37a160 Font:getKerning; 2022-06-29 21:49:55 -07:00
bjorn 7711fe8b65 Font:getWrap; Simplify Font internals; 2022-06-29 20:17:26 -07:00
bjorn 0306096577 luax_optu32 doesn't evaluate index twice; 2022-06-20 18:17:51 -07:00
bjorn 86b2c934e8 Materials, mostly; 2022-06-16 23:49:09 -07:00
bjorn fc616f92c2 Pass:mesh; Pass:setMeshMode; 2022-06-09 23:05:32 -07:00
bjorn 2abf1a4a0c Fix luax_optu32; 2022-06-09 23:05:02 -07:00
bjorn a8b35074e0 Pass:send supports push constants; 2022-06-05 18:54:26 -07:00
bjorn 0104fe1910 Fancy compare mode aliases; 2022-05-31 21:33:06 -07:00
bjorn 6a531c04a8 luax_tofloat; 2022-05-30 13:32:40 -07:00
bjorn ff77a30f01 Default shaders; 2022-05-27 20:47:20 -07:00
bjorn bfa0d94f2d Pass pipeline API; 2022-05-11 12:50:26 -07:00
bjorn d9e5ba8b9f Slightly broken compileShader/newShader; 2022-05-09 11:47:06 -07:00
bjorn 1fde5a36d0 Transform stack; 2022-05-06 17:26:38 -07:00
bjorn 77a32333e0 lovr.graphics.pass; 2022-04-30 18:56:38 -07:00