Commit Graph

302 Commits

Author SHA1 Message Date
bjorn 48d98a701c Use WebGL buffer path on AMD GPUs;
AHHHHHHHHHHHHH
2021-10-03 15:31:17 -07:00
bjorn 04d6996b94 Font:getWidth also returns width of last line; 2021-09-06 16:14:47 -07:00
bjorn fdb8a2423c Merge branch 'master' into dev 2021-07-10 09:44:03 -07:00
bjorn e2cad4ed81 Fix crash in Material:setTexture; 2021-07-10 09:42:49 -07:00
bjorn 4125796211 Fix shaders with nil stages;
The length was getting kept as zero, need to adjust length when
falling back to default shaders.
2021-06-21 10:22:15 -06:00
bjorn 82b7632cea Require material textures to be 2D; 2021-06-12 14:26:39 -06:00
bjorn 053c318995 Fix depth test;
- Use incoming depth settings to determine whether depth test should be
  enabled or disabled (wtf)
- Always track state.depthTest, even if depth test is disabled
2021-06-01 12:58:02 -06:00
bjorn 25bb12d07c Native textures don't destroy their handles;
If a Texture is created from a handle, that means someone else created
it, so we expect them to destroy it.  We were always destroying handles,
and I guess this was usually okay because glDeleteTextures is idempotent.

However, we're seeing a crash in the Oculus driver when OVR is torn
down.  Presumably it is trying to access its swapchain textures after we
destroyed them.  Not sure why this wasn't an observable issue before,
maybe it's a new regression.  Still, it makes sense to only delete the
GL texture handle if we were the one that created it.

We don't need to check this for the renderbuffer since we always own those.
2021-04-27 22:24:42 -06:00
bjorn f2590078a9 Don't always force AMD mode to true!; 2021-04-14 10:41:14 -06:00
bjorn 90b33572e1 Use WebGL buffer path on AMD GPUs;
AHHHHHHHHHHHHH
2021-04-13 10:52:28 -06:00
bjorn 6413a6eda2 Fix Model:getTriangles; Add Lua API; 2021-03-25 12:29:11 -06:00
bjorn e1195a92a0 lovrModelGetTriangles; 2021-03-25 12:29:11 -06:00
bjorn 3a35f81918 Fix underscores not printing;
Signed arithmetic strikes again.  Before the padding was configurable,
padding was just a #define'd constant, so signedness didn't matter.
2021-03-25 12:18:48 -06:00
bjorn a3b791a7e7 Fix Canvas flushing; 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 72a54bce2f Support STL models;
Only binary STL files are supported right now, ASCII is more challenging.
2021-02-23 12:07:16 -07:00
bjorn 1145085446 macOS fixes; 2021-02-22 17:07:28 -07:00
bjorn fb1447503b Fix gcc warnings; 2021-02-19 23:44:23 -07:00
bjorn 880d06a1d1 Only enable compute extensions on desktop GL; 2021-02-19 14:09:40 -07:00
bjorn 1757d30a59 Compute shader feature detection adjustment;
- Compute feature requires compute shaders, image load/store, and SSBOs.
- GLSL 330 is always used, instead of changing depending on compute shader extension.
- Explicitly enable compute shaders, image load/store, and SSBO extensions when needed.

This allows implementations that don't support GLSL 430 to run compute shaders,
and keeps the min supported GL version more consistently at GL3.3.
2021-02-19 14:07:27 -07:00
bjorn a2b7e1619d Fix wasm compilation issues; 2021-02-19 09:05:57 -07:00
bjorn 023067ec27 util.h no longer uses atomics; 2021-02-11 16:37:55 -07:00
bjorn 5ae5acfb18 Make Font texture rgba16f;
Sampling from rg11b10f does not appear to work on mobile.
2021-02-10 15:22:30 -07:00
bjorn 0919da4091 Improve MSDF font shader; Add spread/padding settings to Font; 2021-02-10 07:08:29 -07:00
bjorn 9377406854 Fix font wrap issue with spaces;
If a space starts before the wrap limit, but ends after it, the next
word won't wrap properly even though it should.
2021-02-09 08:06:37 -07:00
bjorn 84f65c26e4 Move utf8 back into util; 2021-02-08 20:55:51 -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 0e318aa46e Make Rasterizer opaque; 2021-02-08 10:58:39 -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 ed09bc3cfa rm unnecessary newlines in assert messages; 2021-02-07 16:58:50 -07:00
bjornbytes 80a33c0544 mat4_multiply -> mat4_mul;
quat_mul vs. mat4_multiply is inconsistent.  Going with mul over
multiply is consistent with vec3_sub and Lua's __mul metamethod.
2020-11-21 14:32:59 -07:00
bjorn e8db2f8187 Basic cylinder uvs; 2020-11-12 18:08:05 -07:00
bjorn 1e7749a58a Fix MSVC warnings;
It's that time of year.
2020-11-12 18:08:05 -07:00
bjornbytes 5c381ead34 Force set vsync in lovrGraphicsCreateWindow;
Headset drivers are allowed to override the vsync setting if vsync
messes up their frame timing.  The vsync property is effectively a
global piece of state in core/os and doesn't change across restarts
because the window is persistent.  This can mean that if you switch
from a headset driver that wants vsync off (anything except desktop)
to a headset driver that doesn't care what the vsync is (desktop),
you could end up with a vsync setting that doesn't match t.window.vsync.
I think this is a symptom of poor design somewhere and the best solution
to this probem is "to just not have it".  Similar issues exist for, e.g.
the window size (but that one is less weird because at least you were
the one who changed it).  For now we are just going to ensure that
lovr.graphics.createWindow always modifies the vsync property.
Untested, may need to adjust this fix later.
2020-11-02 11:57:02 -07:00
bjorn e12a6b7dc4 Fix WebGL; 2020-11-01 23:11:35 -07:00
bjorn 38875cb399 Fix buffer flushing;
lovrGraphicsMapBuffer had the potential to cause a flush.  Flushing
unmaps buffers.  This meant that during any of the calls to map while
creating a Batch, it was possible to cause a flush and unmap other
buffers that expected to be mapped.  This caused writes to unmapped
pointers and subsequent skipping of calls to glFlushMappedBufferRange.

The fix is to figure out if we need to flush upfront and get it out
of the way before mapping any buffers.
2020-10-29 12:12:34 -06:00
bjorn 6a4779e899 Pico: Reset index buffer binding using vao; 2020-10-19 19:24:18 -06:00
bjorn 0388213be4 Reset camera after lovr.headset.renderTo; 2020-10-02 19:50:00 -06:00
bjorn 96fee538b9 Revert "More strict compute shader test;"
This reverts commit 61abb6f02b.
2020-09-29 17:30:50 -06:00
bjorn dd6e05cf32 Fix timers feature being true on GLES; 2020-09-24 19:04:50 -07:00
bjorn f1447fd69a lovr.graphics.get/setViewPose; lovr.graphics.get/setProjection; 2020-09-24 19:03:37 -07:00
bjorn 61abb6f02b More strict compute shader test;
Some hardware supports ARB_compute_shader but not 4.3, causing
shader compilation failures because currently we switch to GLSL 430
if compute shaders are detected.

Instead, just detect GL 4.3 instead of looking for the compute shader
extension.  This means that compute shaders will sometimes be
unavailable even when they're supported.

It would be possible to improve this by modifying the way shaders
are compiled.  Maybe the highest supported GLSL version should be used,
but this makes shader authoring somewhat more difficult.
2020-09-24 05:29:35 -07:00
bjorn 9b0812c4f9 Disable timer queries on GLES;
They aren't compatible with multiview.
2020-09-19 17:25:54 -07:00
bjorn 2e65d71a74 Prevent mapped buffers from being discarded;
We never try to do this anyway, and the unmapping code in discard
doesn't flush contents so it's better for people to unmap the
buffer themselves before calling discard.
2020-09-19 17:21:37 -07:00
bjorn 61e9c746a8 Buffer sync fix;
It appears that GL_MAP_UNSYNCHRONIZED_BIT interferes with
GL_MAP_INVALIDATE_BUFFER_BIT's ability to discard buffer
contents.  Removing the unsynchronized bit fixes visual
glitches on Intel HD GPUs.
2020-09-19 17:19:34 -07:00
bjorn c7ca7eaa38 Add compute dispatch limit; 2020-09-18 15:19:34 -07:00
bjorn 4f730a89a7 android: fix t.graphics.debug; 2020-09-16 20:40:39 -07:00
bjorn 37522bd8a3 OpenXR: MSAA; 2020-08-26 13:42:42 -06:00
bjorn 80f9514295 Shader:sendImage only checks srgb flag for RGBA textures;
It doesn't need to check it for RGB and compressed textures because
those are already rejected.

It may also be a good idea to zero-out the srgb flag for formats that
it doesn't apply to.
2020-08-18 20:20:48 -06:00
bjorn 82159a9885 rm persistent mapping; sync Mesh and ShaderBlock; 2020-08-17 03:29:30 -06:00
bjorn 4177202cc7 Don't enable GL debug output in WebGL; 2020-08-08 17:38:12 -06:00
Nevyn Bengtsson b938a839e0 fix crash in lovrGraphicsGetPixelDensity
Neither Quest nor Pico check for null on its out-params.
Better to send in dummy params to avoid nulls.
2020-08-05 14:48:58 +02:00
bjorn b45baacb66 Handle active attributes that don't have a location;
There are some attributes that don't have a location (gl_InstanceID
is being reported for some reason).  Their location is -1 and this
causes a left shift of a negative value which is undefined.
2020-07-30 02:46:17 -06:00
bjorn 99fdcc8287 Fix calling convention of GL debug callback; 2020-07-29 14:56:46 -06:00
bjorn f0a5a8838b OpenGL debug messages and contexts;
The new t.graphics.debug flag controls the following:

- If enabled, a debug context is created
- If disabled, a no-error context is created
- If enabled, GL debug messages are forwarded to lovr.log
2020-07-28 16:12:30 -06:00
bjorn e3aa4c7d5d t.graphics.debug flag; 2020-07-28 16:12:15 -06:00
bjorn ac58a1aeba Pico: Draw the rest of the owl;
Add entrypoints, headset backend code, fill in the Activity, and
add various special cases to account for the asynchronous render loop,
lack of sRGB support, and OpenGL state resets.
2020-07-27 14:56:21 -06:00
bjorn d045929065 ShaderBlock:getShaderCode: add namespace support; 2020-07-04 17:50:00 -06:00
bjorn a1aa3c8ae8 Finish vrapi driver; 2020-06-09 18:02:03 -06:00
bjorn 90e985c45b Fix MSAA Canvas readback; 2020-05-26 09:53:26 -06:00
bjorn d6abcdfb0e Fix 2 memory leaks; 2020-05-23 13:03:16 -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 75e26f0051 Move core/hash to core/util; 2020-05-19 13:49:40 -06:00
bjorn 92ac93e6b8 Improve image uniform errors; 2020-05-18 15:14:17 -06:00
bjorn 1e78ac8669 Add r16, rg16, rgba16 texture formats; 2020-05-10 01:59:58 -06:00
bjorn b0289de9a6 Error instead of crashing when skin has too many joints;
ModelData is still allowed to load skins with more joints, since
the limitation is in the graphics side of things (Model).

Eventually we will use a buffer for joints to alleviate this.
2020-05-02 14:14:29 -06:00
bjorn c0d73ab541 Add resize event; lovr.resize callback; 2020-05-02 13:09:10 -06:00
pendingchaos 28a2e5fd4c Fix when depth test is disabled but depth write is enabled
GL_DEPTH_TEST controls both whether depth testing and depth writes are
enabled. So if depth testing is disabled and depth writes are enabled,
GL_DEPTH_TEST has to be enabled and the compare mode should be GL_ALWAYS.
2020-04-21 23:39:16 +01:00
bjorn 37d8df4784 Allow initializing empty TextureData with Blob; 2020-03-29 13:47:57 -06: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 45648baa1c Scope a variable better; 2020-03-02 22:23:59 -08:00
bjorn 90b605f012 Add restart cookie; lovr.event.restart; arg.restart; 2020-02-26 14:40:40 -08:00
bjorn fa771b04bd Fix CMake; 2020-02-23 01:01:34 -08:00
bjorn f8b8d427d7 Opaque Mesh; Opaque OpenGL; 2020-02-23 00:29:21 -08:00
bjorn aabb8cb830 Opaque Shader; 2020-02-23 00:29:21 -08:00
bjorn d034e8c01b Opaque Canvas; 2020-02-23 00:29:21 -08:00
bjorn 52d4f7e520 Opaque Texture; 2020-02-23 00:29:21 -08:00
bjorn b045d42782 Opaque Buffer; 2020-02-23 00:29:21 -08:00
bjorn 81f4232da5 opengl: Init compareMode for native textures; 2020-02-19 15:34:32 -08:00
bjorn aa0e01ddab Cleanup; 2020-02-17 17:27:57 -08:00
bjorn bfdebffb34 Fix volume textures; 2020-02-17 17:27:57 -08:00
bjorn 2db1f2b743 Fix erroneous GLES enables;
None of these exist in OpenGL ES.  These were throwing seemingly
innocuous GL errors, so this is mostly just a matter of correctness.
2020-02-16 01:23:27 -08:00
bjorn 443376efde ModelData: Use union for transform fields;
Nodes can have either a transform matrix, or decomposed transform
properties, but never both.  Using a union means we can store both
of those variants in the same piece of memory, using the existing
matrix boolean to figure out which one to use.

This reduces the size of the struct by 48 bytes (152 -> 104), which
ends up speeding up some model operations, I'm guessing due to the
CPU cache.
2020-02-11 16:38:31 -08:00
bjorn c502f5b62a Add highp shader flag that sets default fragment precision to highp;
Also, precision qualifier is required to work on desktop GL, so
we don't need ifdefs for it!
2020-02-07 19:44:51 -08:00
bjorn 67ba5f3a82 Add more graphics stats; 2020-01-31 03:43:52 -08:00
bjorn be4db58fa3 "Fix" compute blocks on GLES;
There can only be one compute block.
2020-01-30 19:14:25 -08:00
bjorn c9c5d43829 Shader:hasBlock; Shader:sendBlock errors on missing block; 2020-01-30 18:26:05 -08:00
bjorn 78f272247b newCanvas creates array textures when multiview; 2020-01-30 17:48:01 -08:00
bjorn f8d3172868 opengl: Prefer state.features.compute to ARB_compute_shader; 2020-01-29 18:22:16 -08:00
bjorn c73fadf5a3 Mark compute shaders as available on ES3.2; 2020-01-29 14:08:09 -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
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
bjorn 8c429e89ac Fix -Wshadow; 2020-01-23 11:18:04 -08:00
bjorn 4c1917f6ce Fix some prototypes; 2020-01-23 10:55:46 -08: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 c0d1e28deb Fix ifdef for glTexStorage;
It's always present on GLES.
2020-01-14 19:39:10 -08:00
bjorn 541400e0fe oculus_mobile: Create framebuffers from bridged swapchain textures;
This is a change that shifts the responsibility regarding the creation
of OpenGL framebuffers from vrapi-provided swapchain texture handles.
Previously, the LovrApp component of lovr-oculus-mobile was creating
framebuffers and passing native framebuffer IDs to lovr.  With this
change, lovr-oculus-mobile passes vrapi's swapchain textures to lovr
unmodified.  This allows lovr to create canvases using its conventional
method and also means that the properties of the canvases are no longer
hardcoded, so things like resolution and multisampling can be
customized.

There were also some issues with multiview canvases in LÖVR due to some
misconceptions about how multisampled multiview rendering works.  These
issues have also been fixed in this commit.
2020-01-14 18:26:01 -08:00
bjorn 0841268d45 Fix garbled text when printing out spaces;
Apparently requesting/rendering zero vertices was clogging stuff
somewhere.  It seems good enough to just explicitly not render
anything if we weren't gonna do it anyway.
2020-01-14 00:37:09 -08:00
bjorn 48b887f7ee Always pass identity matrix for animated shader;
So at least something shows up if you have an unskinned mesh with
a skinned shader.
2020-01-13 20:47:47 -08:00
bjorn dc1c011380 Fix bug with std140 offset logic; 2020-01-09 21:57:25 -08:00
Bjorn 16b93869ee
Merge pull request #143 from bjornbytes/shadow-samplers
Shadow samplers;
2019-12-14 11:34:38 -08:00
bjorn e2d8f8c645 platform -> os;
The function names are staying the same for now.
2019-12-13 19:55:46 -08:00
bjorn 5957d07448 Fix warnings; 2019-12-13 03:41:35 -08:00
bjorn e316e6156b lovr.graphics.get/setColorMask; 2019-12-10 13:44:51 -08:00
bjorn c87d6dec3d lovrPlatformGetProcAddress;
Seems nicer than a global and allows for logging/hooks;
2019-12-10 13:15:12 -08:00
bjorn 2f9400a5f7 Adjust includes; 2019-12-10 13:01:28 -08:00
bjorn c07b9e3fec rm unnecessary include; 2019-11-28 16:04:41 -08:00
bjorn 3e347f0521 Properly initialize uniform.dirty; 2019-11-28 15:31:27 -08:00
bjorn 2ecc1c552f Fix uniform array hashing; 2019-11-26 11:34:39 -08:00
bjorn bd169a4a4d Fix readable buffers;
Unsynchronized/invalidated mapping doesn't work if the read bit is set.
2019-11-14 12:42:52 -08:00
bjorn d21911d010 Add core/map hash table; rm lib/map; 2019-10-30 00:07:05 -07:00
bjorn 4d2aa81647 Reset active texture in lovrGpuInit; 2019-10-15 11:34:49 -07:00
bjorn d93e17e800 Texture:setCompareMode; Shadow samplers; 2019-10-14 17:12:34 -07:00
bjorn ac441ec15b lovrGraphicsGetCamera; 2019-10-12 12:45:11 -07:00
bjorn 5f404e2b1f WebVR fixes;
- Re-add the maf.c file that exports all the maf symbols.
- Fix lovrGpuTock for WebGL.
2019-10-07 19:50:17 -07:00
bjorn 403b217781 Fix Model destructor memory issues;
- Memory leaks.
- Freeing things that weren't allocated.
2019-09-20 13:46:27 -07:00
bjorn 2c29119e44 Fix non-interpolated cubic spline keyframe evaluation; 2019-09-19 23:01:50 -07: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 17ae64baec Fix sphere winding; 2019-08-31 03:00:40 -07:00
bjorn f64e2064ef Adjust Canvas padding so it's 128 bytes; 2019-08-23 01:43:35 -07:00
bjorn 80eaea21f1 Adjust Buffer padding so it's 48 bytes; 2019-08-23 01:35:46 -07:00
bjorn 8d8f4eef73 Adjust Texture padding so it's 64 bytes; 2019-08-23 01:34:23 -07:00
bjorn 28344928c9 Simplify arr; 2019-08-21 23:16:58 -07:00
bjorn 13655d0df4 Simplify logging; 2019-08-21 19:02:02 -07:00
bjorn cd09e1e695 rm sds; 2019-08-21 16:30:20 -07:00
bjorn a4781c7013 Fix cylinder winding; 2019-08-12 20:03:32 -07:00
bjorn 948363e7df OpenGL: Enable seamless cubemap filtering;
It is always used in WebGL 2 and OpenGL ES 3.
2019-08-09 17:22:00 -07:00
bjorn 4d3bfea67c Model:getMaterial(name|index); rm Model:setMaterial; 2019-08-09 16:10:46 -07:00
bjorn b5be93b94b Fix problem with falsy shader flags; 2019-08-07 15:56:13 -07:00
bjorn 54d58c79cd Fix issue where multiple shader flags don't work; 2019-08-06 14:38:49 -07:00
bjorn edd162052c Fix diffuse texture batching; 2019-08-06 11:38:12 -07:00
bjorn 96c47d590c rm lovrEnvironmentTexture from Material; 2019-08-05 15:20:17 -07:00
bjorn aab987dbef Fix WebGL gamma correction;
Ugh, WebGL doesn't have sRGB backbuffers.
2019-08-01 13:26:45 -07:00
bjorn 7690db28af Windows: Fix all the int warnings; 2019-07-31 17:51:49 -07:00
bjorn 4b9e6849c8 Better boolean shader flags; Multicanvas flag;
Instead of boolean shader flags turning into actual booleans defines
in the shader source, for GLSL they turn into defines.  This lets you
use ifdef, which is the more common intended usage.

Also MULTICANVAS is now a boolean shader flag.  The old MULTICANVAS
define is deprecated.
2019-07-28 18:08:23 -07:00
bjorn f564444641 Fix some WebGL issues; 2019-07-28 17:28:18 -07:00
bjorn 239a9514ea Model: Fix animations that aren't keyed at t=0; 2019-07-19 16:42:51 -07:00
bjorn 84cdc592bc Make sure lovrBufferUnmap always unmaps; 2019-07-12 20:16:18 -07:00
bjorn 2eb4b779ab Model cleanup; 2019-07-11 20:13:47 -07:00
bjorn 4b4020d3a7 Model:pose; Model:getNodePose; 2019-07-11 20:09:46 -07:00
bjorn f81a65430b Add support for cubic spline keyframe interpolation; 2019-07-11 11:05:53 -07:00
bjorn 3c07ad6b0b Replace Animator with Model:animate; 2019-07-10 22:08:19 -07:00
bjorn f208a5e067 Fix array initialization;
Because the new arr.h contains an array on the stack, we can't
initialize it and then copy it, or the pointer to the stack array
will be pointing to the wrong thing, causing incorrect behavior.
2019-07-09 09:06:11 -07:00
bjorn af29e29e4d Fix lovr.graphics.setProjection;
Needed to be using new frameData stuff.
2019-07-08 14:35:54 -07:00
bjorn 57f97056da Use I4ui instead of I1ui for lovrDrawID constant value;
glVertexAttribI1ui isn't supported on GLES for some reason.
2019-07-02 12:51:36 -07:00
bjorn 2d6aa18069 Be a little more correct about when draw id is written; 2019-07-02 00:14:01 -07:00