diff --git a/src/main/java/com/jozufozu/flywheel/Flywheel.java b/src/main/java/com/jozufozu/flywheel/Flywheel.java index 569bc73c6..91c204ed2 100644 --- a/src/main/java/com/jozufozu/flywheel/Flywheel.java +++ b/src/main/java/com/jozufozu/flywheel/Flywheel.java @@ -6,6 +6,7 @@ import org.slf4j.Logger; import com.jozufozu.flywheel.backend.Backends; import com.jozufozu.flywheel.backend.Loader; import com.jozufozu.flywheel.backend.Pipelines; +import com.jozufozu.flywheel.backend.engine.UniformBuffer; import com.jozufozu.flywheel.backend.engine.batching.DrawBuffer; import com.jozufozu.flywheel.config.BackendArgument; import com.jozufozu.flywheel.config.FlwCommands; @@ -81,6 +82,7 @@ public class Flywheel { forgeEventBus.addListener(EventPriority.HIGHEST, QuadConverter::onReloadRenderers); forgeEventBus.addListener(Models::onReloadRenderers); forgeEventBus.addListener(DrawBuffer::onReloadRenderers); + forgeEventBus.addListener(UniformBuffer::onReloadRenderers); forgeEventBus.addListener(VisualizedRenderDispatcher::onRenderStage); forgeEventBus.addListener(VisualizedRenderDispatcher::onBeginFrame); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/UniformBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/engine/UniformBuffer.java index ee7497703..0d1c7ea6b 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/UniformBuffer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/UniformBuffer.java @@ -6,6 +6,7 @@ import java.util.Set; import org.lwjgl.opengl.GL32; import com.google.common.collect.ImmutableList; +import com.jozufozu.flywheel.api.event.ReloadRenderersEvent; import com.jozufozu.flywheel.api.uniform.ShaderUniforms; import com.jozufozu.flywheel.gl.buffer.GlBuffer; import com.jozufozu.flywheel.gl.buffer.GlBufferType; @@ -60,27 +61,39 @@ public class UniformBuffer { } } + private void delete() { + providerSet.delete(); + buffer.delete(); + } + + public static void onReloadRenderers(ReloadRenderersEvent event) { + if (instance != null) { + instance.delete(); + instance = null; + } + } + private static class LiveProvider { - private final ShaderUniforms provider; + private final ShaderUniforms shaderUniforms; private final int offset; private final int size; - private ShaderUniforms.Provider activeProvider; + private ShaderUniforms.Provider provider; - private LiveProvider(ShaderUniforms provider, int offset, int size) { - this.provider = provider; + private LiveProvider(ShaderUniforms shaderUniforms, int offset, int size) { + this.shaderUniforms = shaderUniforms; this.offset = offset; this.size = size; } private void updatePtr(MemoryBlock bufferBase) { - if (activeProvider != null) { - activeProvider.delete(); + if (provider != null) { + provider.delete(); } - activeProvider = provider.activate(bufferBase.ptr() + offset); + provider = shaderUniforms.activate(bufferBase.ptr() + offset); } public boolean maybePoll() { - return activeProvider != null && activeProvider.poll(); + return provider != null && provider.poll(); } } @@ -116,5 +129,10 @@ public class UniformBuffer { } return changed; } + + public void delete() { + allocatedProviders.forEach(p -> p.provider.delete()); + data.free(); + } } } diff --git a/src/main/java/com/jozufozu/flywheel/mixin/ClientMainMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/ClientMainMixin.java index ac83e5a5b..c2187ecdf 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/ClientMainMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/ClientMainMixin.java @@ -12,7 +12,7 @@ public class ClientMainMixin { @Inject(method = "main([Ljava/lang/String;)V", at = @At("HEAD")) private static void flywheel$injectRenderDoc(CallbackInfo ci) { // Only try to load RenderDoc if a system property is set to true. - if (!Boolean.parseBoolean(System.getProperty("flw.loadRenderDoc"))) { + if (!Boolean.getBoolean("flw.loadRenderDoc")) { return; }