Last active
November 22, 2025 04:50
-
-
Save lowercasebtw/30ab38e2506abb9b29235ea8ccbcf2f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package btw.mixces.animatium; | |
| import com.mojang.blaze3d.buffers.GpuBuffer; | |
| import com.mojang.blaze3d.buffers.GpuBufferSlice; | |
| import com.mojang.blaze3d.pipeline.RenderPipeline; | |
| import com.mojang.blaze3d.pipeline.RenderTarget; | |
| import com.mojang.blaze3d.systems.RenderPass; | |
| import com.mojang.blaze3d.systems.RenderSystem; | |
| import com.mojang.blaze3d.systems.ScissorState; | |
| import com.mojang.blaze3d.textures.GpuTextureView; | |
| import com.mojang.blaze3d.vertex.MeshData; | |
| import com.mojang.blaze3d.vertex.VertexFormat; | |
| import net.minecraft.client.Minecraft; | |
| import java.util.OptionalDouble; | |
| import java.util.OptionalInt; | |
| import java.util.function.Consumer; | |
| public class BufferUploader { | |
| public void drawWithShader(RenderPipeline renderPipeline, GpuBufferSlice dynamicTransforms, MeshData meshData, Consumer<RenderPass> renderPassConsumer) { | |
| GpuBuffer vertexBuffer = renderPipeline.getVertexFormat().uploadImmediateVertexBuffer(meshData.vertexBuffer()); | |
| GpuBuffer indexBuffer; | |
| VertexFormat.IndexType indexType; | |
| if (meshData.indexBuffer() == null) { | |
| RenderSystem.AutoStorageIndexBuffer autoStorageIndexBuffer = RenderSystem.getSequentialBuffer(meshData.drawState().mode()); | |
| indexBuffer = autoStorageIndexBuffer.getBuffer(meshData.drawState().indexCount()); | |
| indexType = autoStorageIndexBuffer.type(); | |
| } else { | |
| indexBuffer = renderPipeline.getVertexFormat().uploadImmediateIndexBuffer(meshData.indexBuffer()); | |
| indexType = meshData.drawState().indexType(); | |
| } | |
| RenderTarget renderTarget = Minecraft.getInstance().getMainRenderTarget(); | |
| GpuTextureView colorTexture = RenderSystem.outputColorTextureOverride != null ? RenderSystem.outputColorTextureOverride : renderTarget.getColorTextureView(); | |
| GpuTextureView depthTexture = renderTarget.useDepth ? (RenderSystem.outputDepthTextureOverride != null ? RenderSystem.outputDepthTextureOverride : renderTarget.getDepthTextureView()) : null; | |
| try (RenderPass renderPass = RenderSystem.getDevice().createCommandEncoder().createRenderPass(() -> "Immediate draw for " + renderPipeline.getLocation(), colorTexture, OptionalInt.empty(), depthTexture, OptionalDouble.empty())) { | |
| renderPass.setPipeline(renderPipeline); | |
| ScissorState scissorState = RenderSystem.getScissorStateForRenderTypeDraws(); | |
| if (scissorState.enabled()) { | |
| renderPass.enableScissor(scissorState.x(), scissorState.y(), scissorState.width(), scissorState.height()); | |
| } | |
| RenderSystem.bindDefaultUniforms(renderPass); | |
| renderPass.setUniform("DynamicTransforms", dynamicTransforms); | |
| renderPass.setVertexBuffer(0, vertexBuffer); | |
| for (int i = 0; i < 12; ++i) { | |
| GpuTextureView gpuTextureView3 = RenderSystem.getShaderTexture(i); | |
| if (gpuTextureView3 != null) { | |
| renderPass.bindSampler("Sampler" + i, gpuTextureView3); | |
| } | |
| } | |
| renderPass.setIndexBuffer(indexBuffer, indexType); | |
| renderPass.drawIndexed(0, 0, meshData.drawState().indexCount(), 1); | |
| } | |
| meshData.close(); | |
| } | |
| public void drawWithShader(RenderPipeline renderPipeline, GpuBufferSlice dynamicTransforms, MeshData meshData) { | |
| drawWithShader(renderPipeline, dynamicTransforms, meshData, (renderPass) -> { | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment