From ef2bb09fcd21ab3b226c7a6dbc21123028e2a840 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Sat, 6 Jul 2024 13:50:25 -0700 Subject: [PATCH] Literally unusable - Trim out dead light code from *EmbeddedEnvironment - Fix indirect never deleting empty culling groups - Fix embedded transforms not being applied --- .../engine/embed/AbstractEmbeddedEnvironment.java | 4 ---- .../engine/embed/NestedEmbeddedEnvironment.java | 6 ------ .../engine/embed/TopLevelEmbeddedEnvironment.java | 6 ------ .../backend/engine/indirect/IndirectCullingGroup.java | 10 ++++++++++ .../backend/engine/indirect/IndirectDrawManager.java | 6 +++++- .../engine/instancing/InstancedDrawManager.java | 4 ++-- .../assets/flywheel/flywheel/internal/common.vert | 4 ++-- 7 files changed, 19 insertions(+), 21 deletions(-) diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/embed/AbstractEmbeddedEnvironment.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/embed/AbstractEmbeddedEnvironment.java index 5d6c573d1..2861dee83 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/embed/AbstractEmbeddedEnvironment.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/embed/AbstractEmbeddedEnvironment.java @@ -57,8 +57,6 @@ public abstract class AbstractEmbeddedEnvironment implements Environment, Visual @Override public void setupDraw(GlProgram program) { - setupLight(program); - program.setMat4(EmbeddingUniforms.MODEL_MATRIX, poseComposed); program.setMat3(EmbeddingUniforms.NORMAL_MATRIX, normalComposed); } @@ -109,7 +107,5 @@ public abstract class AbstractEmbeddedEnvironment implements Environment, Visual deleted = true; } - public abstract void setupLight(GlProgram program); - public abstract void composeMatrices(Matrix4f pose, Matrix3f normal); } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/embed/NestedEmbeddedEnvironment.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/embed/NestedEmbeddedEnvironment.java index e2b727476..516d1f358 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/embed/NestedEmbeddedEnvironment.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/embed/NestedEmbeddedEnvironment.java @@ -5,7 +5,6 @@ import org.joml.Matrix4f; import dev.engine_room.flywheel.api.event.RenderStage; import dev.engine_room.flywheel.backend.engine.EngineImpl; -import dev.engine_room.flywheel.backend.gl.shader.GlProgram; import it.unimi.dsi.fastutil.longs.LongSet; public class NestedEmbeddedEnvironment extends AbstractEmbeddedEnvironment { @@ -21,11 +20,6 @@ public class NestedEmbeddedEnvironment extends AbstractEmbeddedEnvironment { // noop } - @Override - public void setupLight(GlProgram program) { - parent.setupLight(program); - } - @Override public void composeMatrices(Matrix4f pose, Matrix3f normal) { parent.composeMatrices(pose, normal); diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/embed/TopLevelEmbeddedEnvironment.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/embed/TopLevelEmbeddedEnvironment.java index a79ce7ae8..4c58a8660 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/embed/TopLevelEmbeddedEnvironment.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/embed/TopLevelEmbeddedEnvironment.java @@ -5,7 +5,6 @@ import org.joml.Matrix4f; import dev.engine_room.flywheel.api.event.RenderStage; import dev.engine_room.flywheel.backend.engine.EngineImpl; -import dev.engine_room.flywheel.backend.gl.shader.GlProgram; import it.unimi.dsi.fastutil.longs.LongArraySet; import it.unimi.dsi.fastutil.longs.LongSet; @@ -27,11 +26,6 @@ public class TopLevelEmbeddedEnvironment extends AbstractEmbeddedEnvironment { out.addAll(lightSections); } - @Override - public void setupLight(GlProgram program) { - program.setBool(EmbeddingUniforms.USE_LIGHT_VOLUME, !lightSections.isEmpty()); - } - @Override public void composeMatrices(Matrix4f pose, Matrix3f normal) { pose.set(this.pose); diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/indirect/IndirectCullingGroup.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/indirect/IndirectCullingGroup.java index f72f66af9..2bd19e776 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/indirect/IndirectCullingGroup.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/indirect/IndirectCullingGroup.java @@ -277,6 +277,16 @@ public class IndirectCullingGroup { buffers.delete(); } + public boolean checkEmptyAndDelete() { + var out = indirectDraws.isEmpty(); + + if (out) { + delete(); + } + + return out; + } + private record MultiDraw(Material material, int start, int end) { private void submit() { GlCompat.safeMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, this.start * IndirectBuffers.DRAW_COMMAND_STRIDE, this.end - this.start, (int) IndirectBuffers.DRAW_COMMAND_STRIDE); diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/indirect/IndirectDrawManager.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/indirect/IndirectDrawManager.java index acc555013..1aadae5a3 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/indirect/IndirectDrawManager.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/indirect/IndirectDrawManager.java @@ -107,7 +107,11 @@ public class IndirectDrawManager extends DrawManager> { group.flushInstancers(); } - instancers.values().removeIf(instancer -> instancer.instanceCount() == 0); + cullingGroups.values() + .removeIf(IndirectCullingGroup::checkEmptyAndDelete); + + instancers.values() + .removeIf(instancer -> instancer.instanceCount() == 0); meshPool.flush(); diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedDrawManager.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedDrawManager.java index 9130af672..6ea923cc1 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedDrawManager.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/instancing/InstancedDrawManager.java @@ -61,8 +61,8 @@ public class InstancedDrawManager extends DrawManager> { public void flush(LightStorage lightStorage) { super.flush(lightStorage); - var instancers = this.instancers.values(); - instancers.removeIf(instancer -> { + this.instancers.values() + .removeIf(instancer -> { // Update the instancers and remove any that are empty. instancer.update(); diff --git a/common/src/backend/resources/assets/flywheel/flywheel/internal/common.vert b/common/src/backend/resources/assets/flywheel/flywheel/internal/common.vert index 0ba630c8f..075dae3f6 100644 --- a/common/src/backend/resources/assets/flywheel/flywheel/internal/common.vert +++ b/common/src/backend/resources/assets/flywheel/flywheel/internal/common.vert @@ -66,7 +66,7 @@ vec2 getCrumblingTexCoord() { } #endif -#ifdef _FLW_EMBEDDED +#ifdef FLW_EMBEDDED uniform mat4 _flw_modelMatrix; uniform mat3 _flw_normalMatrix; #endif @@ -82,7 +82,7 @@ void _flw_main(in FlwInstance instance, in uint stableInstanceID) { _flw_crumblingTexCoord = getCrumblingTexCoord(); #endif - #ifdef _FLW_EMBEDDED + #ifdef FLW_EMBEDDED flw_vertexPos = _flw_modelMatrix * flw_vertexPos; flw_vertexNormal = _flw_normalMatrix * flw_vertexNormal; #endif