From 1c8d052544c21184d126b7cd09022ba6307553d6 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Sat, 12 Jul 2025 14:13:16 +1000 Subject: [PATCH] add todo and optimized imports --- .../core/gl/shader/AutoBindingShader.java | 22 +++++++++++++++++++ .../HierarchicalOcclusionTraverser.java | 5 ++--- .../core/rendering/section/MDICViewport.java | 1 - 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/core/gl/shader/AutoBindingShader.java b/src/main/java/me/cortex/voxy/client/core/gl/shader/AutoBindingShader.java index ce2d69a7..81b0209d 100644 --- a/src/main/java/me/cortex/voxy/client/core/gl/shader/AutoBindingShader.java +++ b/src/main/java/me/cortex/voxy/client/core/gl/shader/AutoBindingShader.java @@ -14,6 +14,7 @@ import static org.lwjgl.opengl.GL30.glBindBufferRange; import static org.lwjgl.opengl.GL31.GL_UNIFORM_BUFFER; import static org.lwjgl.opengl.GL33.glBindSampler; import static org.lwjgl.opengl.GL43.GL_SHADER_STORAGE_BUFFER; +import static org.lwjgl.opengl.GL44.*; //TODO: rewrite the entire shader builder system @@ -26,6 +27,8 @@ public class AutoBindingShader extends Shader { private final List bindings = new ArrayList<>(); private final List textureBindings = new ArrayList<>(); + private boolean rebuild = true; + AutoBindingShader(Shader.Builder builder, int program) { super(program); this.defines = builder.defines; @@ -70,6 +73,8 @@ public class AutoBindingShader extends Shader { } private void insertOrReplaceBinding(BufferBinding binding) { + this.rebuild = true; + //Check if there is already a binding at the index with the target, if so, replace it for (int i = 0; i < this.bindings.size(); i++) { var entry = this.bindings.get(i); @@ -92,6 +97,16 @@ public class AutoBindingShader extends Shader { } public AutoBindingShader texture(int unit, int sampler, GlTexture texture) { + this.rebuild = true; + + for (int i = 0; i < this.textureBindings.size(); i++) { + var entry = this.textureBindings.get(i); + if (entry.unit == unit) { + this.textureBindings.set(i, new TextureBinding(unit, sampler, texture)); + return this; + } + } + this.textureBindings.add(new TextureBinding(unit, sampler, texture)); return this; } @@ -99,6 +114,13 @@ public class AutoBindingShader extends Shader { @Override public void bind() { super.bind(); + //TODO: replace with multibind and use the invalidate flag + /* + glBindSamplers(); + glBindTextures(); + glBindBuffersBase(); + glBindBuffersRange(); + */ if (!this.bindings.isEmpty()) { for (var binding : this.bindings) { binding.buffer.assertNotFreed(); diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/HierarchicalOcclusionTraverser.java b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/HierarchicalOcclusionTraverser.java index 35038fb8..476a226b 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/HierarchicalOcclusionTraverser.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/HierarchicalOcclusionTraverser.java @@ -7,11 +7,10 @@ import me.cortex.voxy.client.core.gl.GlBuffer; import me.cortex.voxy.client.core.gl.shader.AutoBindingShader; import me.cortex.voxy.client.core.gl.shader.Shader; import me.cortex.voxy.client.core.gl.shader.ShaderType; -import me.cortex.voxy.client.core.rendering.building.RenderGenerationService; -import me.cortex.voxy.client.core.rendering.util.PrintfDebugUtil; -import me.cortex.voxy.client.core.rendering.util.HiZBuffer; import me.cortex.voxy.client.core.rendering.Viewport; +import me.cortex.voxy.client.core.rendering.building.RenderGenerationService; import me.cortex.voxy.client.core.rendering.util.DownloadStream; +import me.cortex.voxy.client.core.rendering.util.PrintfDebugUtil; import me.cortex.voxy.client.core.rendering.util.UploadStream; import me.cortex.voxy.common.util.MemoryBuffer; import me.cortex.voxy.common.world.WorldEngine; diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/section/MDICViewport.java b/src/main/java/me/cortex/voxy/client/core/rendering/section/MDICViewport.java index 850bafbc..e28ffb47 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/section/MDICViewport.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/section/MDICViewport.java @@ -3,7 +3,6 @@ package me.cortex.voxy.client.core.rendering.section; import me.cortex.voxy.client.core.gl.GlBuffer; import me.cortex.voxy.client.core.rendering.Viewport; import me.cortex.voxy.client.core.rendering.hierachical.HierarchicalOcclusionTraverser; -import me.cortex.voxy.client.core.rendering.util.HiZBuffer; public class MDICViewport extends Viewport { public final GlBuffer drawCountCallBuffer = new GlBuffer(1024).zero();