Skip to content

Commit

Permalink
Implement uploadIndexBuffer method
Browse files Browse the repository at this point in the history
  • Loading branch information
xCollateral committed Sep 27, 2024
1 parent b119f00 commit 968cbf4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/net/vulkanmod/render/VBO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 968cbf4

Please sign in to comment.