Commit Graph

226 Commits

Author SHA1 Message Date
bjorn fdfcb5539f Merge branch 'master' into dev 2022-03-14 13:19:59 -07:00
bjorn c9fe026a66 Fix undefined behavior in arr_free;
Currently there is a single allocator function used in arr_t.  Its
behavior depends on the values for the pointer and size arguments:

- If pointer is NULL, it should allocate new memory.
- If pointer is non-NULL and size is positive, it should resize memory.
- If size is zero, it should free memory.

All instances of arr_t use realloc for this right now.  The problem
is that realloc's behavior is undefined when the size argument is zero.
On Windows and Linux, realloc will free the pointer, but on macOS this
isn't the case.  This means that arr_t leaks memory on macOS.

It's best to not rely on undefined behavior like this, so let's instead
use a helper function that behaves the way we want.
2022-03-14 12:27:58 -07:00
murat g ee3ba6ef3e Font filtering now respects the default setting. 2022-03-03 22:41:47 -08:00
bjorn b22dbd8f0c Add luax_checku32 and luax_optu32;
These functions read an unsigned 32 bit integer from the Lua stack
and error if the value is negative or too big.  Currently converting
Lua numbers to integers will silently wrap or invoke undefined behavior
when they are outside of the acceptable range.

For projects that don't want the overhead of type/bounds checks, the
supercharge build option (LOVR_UNCHECKED) can now be used to skip all
type/bounds checks.
2022-02-21 14:19:24 -08:00
bjorn 7ed47e946b Fix problem when requiring audio/graphics/headset in threads;
These modules access the conf table, which isn't available on threads.
2022-01-16 12:13:46 -08:00
bjorn 8462beef00 Fix/improve alpha cutoff;
The current flag did not work because float shader flags are not
supported.  It was also not very useful because it was per-shader
and did not use the alpha cutoff property of glTF materials.

Instead, let's turn the shader flag into an enable/disable boolean,
and add a scalar material property named "alphacutoff" that gets
read by the glTF importer.

When the alphaCutoff flag is enabled, the material property will be
compared against the pixel's alpha value to decide whether it should
get discarded.
2021-12-28 21:10:52 +02:00
bjorn 2b1b777e84 Fix crash when passing nothing to newTexture; 2021-03-26 20:02:38 -06:00
bjorn e63099ba6a Flatten api.h; 2021-03-15 18:54:27 -06:00
bjorn deb756392b Fix 'attempt to flush unmapped buffer' when creating empty Mesh; 2021-03-07 21:19:24 -07:00
bjorn 4f5adbc64c lovr.system; 2021-02-25 09:00:12 -07:00
bjorn 39a4d2c1d5 rm lovr.graphics.triangle; 2021-02-24 17:45:31 -07:00
bjorn a0b2200bef Fix lovr.graphics.getBlendMode when blending is off; 2021-02-19 14:05:18 -07:00
bjorn 0365f51f9d Fix crash when drawing zero lines; 2021-02-19 08:38:45 -07:00
bjorn 0919da4091 Improve MSDF font shader; Add spread/padding settings to Font; 2021-02-10 07:08:29 -07:00
bjorn 8164e0b6e8 TextureData is now named Image!;
The existing Image construct was renamed StorageImage.
2021-02-08 20:17:47 -07:00
bjorn 8c714c45b0 Clean up some includes; 2021-02-08 11:16:00 -07:00
bjorn 6d92d54079 Try having arr_t in util; 2021-02-08 18:25:05 -07:00
bjorn bc4cde1653 Adjust lovrRelease signature; 2021-02-08 17:52:26 -07:00
bjorn 3ded60948f rm core/ref; rm lovrAlloc; util does refcounting; 2021-02-08 17:26:44 -07:00
bjorn 1e7749a58a Fix MSVC warnings;
It's that time of year.
2020-11-12 18:08:05 -07:00
Nevyn Bengtsson 326d275424 don't free window icon before it's used
It seems to me like that lovrRelease will delete textureData->blob immediately,
which means the windowing system later can't use it because it's already freed.
There's already a free on line 378 which looks more correct.

Also, icon appears flipped if 'flipped' is set to true here on Linux. Is GLFW
inconsistent between linux and windows, or should it indeed be false?
2020-11-06 21:00:38 +01:00
bjorn 51f470cf85 Easier enums; 2020-09-27 17:13:00 -07:00
bjorn f1447fd69a lovr.graphics.get/setViewPose; lovr.graphics.get/setProjection; 2020-09-24 19:03:37 -07:00
bjorn c7ca7eaa38 Add compute dispatch limit; 2020-09-18 15:19:34 -07:00
bjorn ec257b179f Support Lua 5.2, 5.3, 5.4; 2020-08-19 13:12:57 -06:00
bjorn d937be35b5 Fix lovr.graphics.line(nil); 2020-08-17 14:43:46 -06:00
bjorn 82159a9885 rm persistent mapping; sync Mesh and ShaderBlock; 2020-08-17 03:29:30 -06:00
bjorn e3aa4c7d5d t.graphics.debug flag; 2020-07-28 16:12:15 -06:00
bjorn 6bce095660 Fix newComputeShader(nil); 2020-06-07 15:47:53 -06:00
bjorn 1185fcf6e1 Autodetect integer attribute types;
Fixes inability to use integer attributes with Mesh.
2020-05-21 00:31:49 -06:00
bjorn 1e78ac8669 Add r16, rg16, rgba16 texture formats; 2020-05-10 01:59:58 -06:00
bjorn a01cc5a376 Fix lovr.graphics.getDefaultFilter; 2020-03-05 19:27:08 -08:00
bjorn c02839f5c2 Allow anisotropy to be used with any TextureFilter;
Instead of anisotropic being its own filter, it is now removed and
anisotropy settings can be used with any of the other filter modes.
2020-03-05 09:46:49 -08:00
bjorn 18dcb07b98 Convert stuff over to use new enum system; 2020-02-16 18:31:02 -08:00
bjorn 67ba5f3a82 Add more graphics stats; 2020-01-31 03:43:52 -08:00
bjorn 78f272247b newCanvas creates array textures when multiview; 2020-01-30 17:48:01 -08:00
bjorn 56dc8d0b9e Handle stereo shaders better;
- Creating a shader from a DefaultShader will respect the stereo flags.
- Auto shaders will properly be stereo/nonstereo based on the target Canvas.
2020-01-27 16:33:15 -08:00
bjorn 4379d25e1c Organization; 2020-01-27 14:02:54 -08:00
Cassie Jones 3e09120173 Compile shaders using source lengths
The previous implementation relied on glShaderSource inferring source
lengths when the lengths weren't specified. This relies on the sources
being properly null-terminated, however, which isn't the case due to
file loading changes which now use pointer + length. This could cause
intermittent crashes.

Changing this on the shader side meant adding some extra arguments for
passing around shader source lengths. For most of the other cases, where
we're using string literals as the sources, we can just specify -1 as
the length, since OpenGL will calculate the string length for you any
time the length is negative.
2020-01-27 16:13:21 -05:00
Nevyn Bengtsson 95edb43654 TextureData: holds Blob instead of being Blob, just like SoundData
also replaces TextureData:getPointer with TextureData;getBlob
2020-01-19 22:59:44 +01:00
bjorn a103637419 Fix ModelData refcounting; 2019-12-20 04:52:55 -08:00
bjorn e316e6156b lovr.graphics.get/setColorMask; 2019-12-10 13:44:51 -08:00
bjorn 403ed8d3b0 Windows; 2019-12-10 12:19:50 -08:00
bjorn 1902787b1b Modify GPU timer API;
- lovr.graphics.tock returns the latest value of the timer, or 0.
- Timers are not in the stats table anymore.

This is to prepare for an upcoming internal change that affects timers.
2019-09-18 18:21:38 -07:00
bjorn 00412e2e79 Add a conf.lua flag for making the window resizable; 2019-08-28 00:59:03 -07:00
bjorn 31fed6a940 Fix stereo flag for custom shaders; 2019-08-27 14:59:17 -07:00
bjorn 305596adf8 Fix windows build;
LOVR_EXPORT needs to be on the declaration, unfortunately.
2019-08-26 15:53:10 -07:00
bjorn 9b0e43b249 Fix t.window = nil; 2019-08-21 22:26:31 -07:00
bjorn 8d4760167f luax is now api; 2019-08-21 15:27:26 -07:00
bjorn 26e7233fde Fix some API issues with lightuserdata; 2019-08-19 14:35:06 -07:00
bjorn c703092f87 Add missing timers GraphicsFeature; 2019-08-13 22:11:59 -07:00
bjorn 93f076acc9 Fix default uniform values;
Not supported in GLES.
2019-08-09 17:36:14 -07:00
bjorn 289d365866 Better error messages when loading cubemaps; 2019-08-07 15:14:59 -07:00
bjorn 96c47d590c rm lovrEnvironmentTexture from Material; 2019-08-05 15:20:17 -07:00
bjorn 06fb8b2503 Simplify fill;
lovr.graphics.fill renders a fullscreen quad, it's convenient because
you don't need to set up a mesh and toggle all the pipeline states.

However, if you are dealing with copying/rendering between stereo
textures, you have to write your own shader for that.  For now.
2019-08-03 16:03:13 -07:00
bjorn 7690db28af Windows: Fix all the int warnings; 2019-07-31 17:51:49 -07:00
bjorn ca8e280dcd Fix texture refcounting in lovr.graphics.newTexture;
Also a memory leak with window icons (does anyone use that?)
2019-07-31 14:43:35 -07:00
bjorn 9156fa2cbf Vector rework; 2019-07-16 20:30:51 -07:00
bjorn 4b4020d3a7 Model:pose; Model:getNodePose; 2019-07-11 20:09:46 -07:00
bjorn 3c07ad6b0b Replace Animator with Model:animate; 2019-07-10 22:08:19 -07:00
bjorn 2fb393306c rm skybox args;
They used to always be necessary, now they are almost never necessary.
2019-06-29 21:01:03 -07:00
bjorn 551dea8c86 Adjust includes; 2019-06-27 13:44:09 -07:00
bjorn 928ccee5f1 Multiview; 2019-06-25 01:21:59 -07:00
bjorn 879c789a08 Polyfill M_PI;
It technically isn't part of C, which is causing problems on some systems.
2019-06-20 21:43:40 -07:00
bjorn 4611b1c9a3 Add no-op standard shader; 2019-06-20 14:21:35 -07:00
bjorn eb1e257209 Add new array implementation; Upgrade filesystem;
Filesystem:

- Uses streaming file IO.
- Uses less memory when requiring files.
- Simplifies its require path implementation.
2019-06-16 13:30:30 -07:00
bjorn 79083c7df1 Fix warnings on newer versions of gcc; 2019-06-11 19:57:20 -07:00
bjorn 98f4365474 Add astc and dxt GraphicsFeatures; 2019-06-09 23:59:57 -07:00
bjorn b0a7d5c122 ASTC textures;
I like typing numbers.
2019-06-09 09:11:29 -07:00
bjorn 06c6b172de vec3 has 4 elements; 2019-06-03 07:20:03 -07:00
bjorn 22fe333150 Update refcounting (again);
- Ref struct only stores refcount now and is more general.
- Proxy stores a hash of its type name instead of an enum.
- Variants store additional information instead of using a vtable.
- Remove the concept of superclasses from the API.
- Clean up some miscellaneous includes.
2019-06-02 01:02:26 -07:00
bjorn d2bff7d239 lovr.graphics.tick and tock;
Initial support for GPU timer queries.
2019-06-01 17:29:53 -07:00
bjorn c5210deae8 Fix ShaderFlag parsing; 2019-05-28 03:43:12 -07:00
bjorn 3bf08f0ca3 Add the ability to create default shaders;
lovr.graphics.newShader('font')
2019-05-22 18:00:02 -07:00
bjorn c464bde609 Add DefaultShaders enum; 2019-05-22 16:36:40 -07:00
bjorn 4a47afca38 Organize api folder; 2019-05-19 00:31:42 -07:00
Renamed from src/api/graphics.c (Browse further)