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 void flush() { @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 void delete() { 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 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 void lightChunks(LongSet chunks) { // 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 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 void addLightSections(LongSet out) { 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 c4d5fb8ea..b79a52edd 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 @@ -280,6 +280,16 @@ public void delete() { 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() { if (GlCompat.DRIVER == Driver.INTEL) { 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 void flush(LightStorage lightStorage) { 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 InstancedDrawManager(InstancingPrograms programs) { 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