From 968cbf4ff0409b475c8d1305e451f7294613c6aa Mon Sep 17 00:00:00 2001 From: xCollateral <103696619+xCollateral@users.noreply.github.com> Date: Fri, 27 Sep 2024 16:47:58 +0200 Subject: [PATCH] Implement uploadIndexBuffer method --- .../mixin/render/vertex/VertexBufferM.java | 11 +++++++++-- src/main/java/net/vulkanmod/render/VBO.java | 13 +++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/vulkanmod/mixin/render/vertex/VertexBufferM.java b/src/main/java/net/vulkanmod/mixin/render/vertex/VertexBufferM.java index 78aefe55f..e9da55500 100644 --- a/src/main/java/net/vulkanmod/mixin/render/vertex/VertexBufferM.java +++ b/src/main/java/net/vulkanmod/mixin/render/vertex/VertexBufferM.java @@ -1,14 +1,13 @@ package net.vulkanmod.mixin.render.vertex; +import com.mojang.blaze3d.vertex.ByteBufferBuilder; import com.mojang.blaze3d.vertex.MeshData; import com.mojang.blaze3d.vertex.VertexBuffer; import net.minecraft.client.renderer.ShaderInstance; import net.vulkanmod.render.VBO; import org.joml.Matrix4f; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; @@ -54,6 +53,14 @@ public void upload(MeshData meshData) { vbo.upload(meshData); } + /** + * @author + */ + @Overwrite + public void uploadIndexBuffer(ByteBufferBuilder.Result result) { + vbo.uploadIndexBuffer(result.byteBuffer()); + } + /** * @author */ diff --git a/src/main/java/net/vulkanmod/render/VBO.java b/src/main/java/net/vulkanmod/render/VBO.java index e5f70ca88..1ebc59660 100644 --- a/src/main/java/net/vulkanmod/render/VBO.java +++ b/src/main/java/net/vulkanmod/render/VBO.java @@ -14,6 +14,7 @@ import net.vulkanmod.vulkan.memory.MemoryTypes; import net.vulkanmod.vulkan.memory.VertexBuffer; import net.vulkanmod.vulkan.shader.GraphicsPipeline; +import net.vulkanmod.vulkan.shader.Pipeline; import net.vulkanmod.vulkan.texture.VTextureSelector; import org.joml.Matrix4f; @@ -39,13 +40,13 @@ public void upload(MeshData meshData) { this.vertexCount = parameters.vertexCount(); this.mode = parameters.mode(); - this.configureVertexBuffer(parameters, meshData.vertexBuffer()); - this.configureIndexBuffer(parameters, meshData.indexBuffer()); + this.uploadVertexBuffer(parameters, meshData.vertexBuffer()); + this.uploadIndexBuffer(meshData.indexBuffer()); meshData.close(); } - private void configureVertexBuffer(MeshData.DrawState parameters, ByteBuffer data) { + private void uploadVertexBuffer(MeshData.DrawState parameters, ByteBuffer data) { if (data != null) { if (this.vertexBuffer != null) this.vertexBuffer.freeBuffer(); @@ -55,7 +56,7 @@ private void configureVertexBuffer(MeshData.DrawState parameters, ByteBuffer dat } } - private void configureIndexBuffer(MeshData.DrawState parameters, ByteBuffer data) { + public void uploadIndexBuffer(ByteBuffer data) { if (data == null) { AutoIndexBuffer autoIndexBuffer; @@ -141,6 +142,10 @@ public void draw() { if (this.indexCount != 0) { RenderSystem.assertOnRenderThread(); + Renderer renderer = Renderer.getInstance(); + Pipeline pipeline = renderer.getBoundPipeline(); + renderer.uploadAndBindUBOs(pipeline); + Renderer.getDrawer().drawIndexed(this.vertexBuffer, this.indexBuffer, this.indexCount); } }