| 1 | package net.minecraft.client.renderer.rendertype;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.systems.RenderSystem;
|
| 4 | import com.mojang.blaze3d.systems.ScissorState;
|
| 5 | import com.mojang.renderpearl.api.buffers.GpuBuffer;
|
| 6 | import com.mojang.renderpearl.api.buffers.GpuBufferSlice;
|
| 7 | import com.mojang.renderpearl.api.commands.RenderPass;
|
| 8 | import com.mojang.renderpearl.api.pipeline.RenderPipeline;
|
| 9 | import com.mojang.renderpearl.api.textures.GpuSampler;
|
| 10 | import com.mojang.renderpearl.api.textures.GpuTextureView;
|
| 11 | import java.util.List;
|
| 12 | import net.fabricmc.api.EnvType;
|
| 13 | import net.fabricmc.api.Environment;
|
| 14 | import net.minecraft.client.renderer.StagedVertexBuffer;
|
| 15 | import net.minecraft.client.renderer.oit.OitPipelineSet;
|
| 16 | import net.minecraft.client.renderer.oit.OitStage;
|
| 17 | import org.jspecify.annotations.Nullable;
|
| 18 |
|
| 19 | @Environment(EnvType.CLIENT)
|
| 20 | public record PreparedRenderType(
|
| 21 | String name,
|
| 22 | RenderPipeline pipeline,
|
| 23 | @Nullable OitPipelineSet oitPipelineSet,
|
| 24 | GpuBufferSlice dynamicTransforms,
|
| 25 | ScissorState scissorState,
|
| 26 | List<PreparedRenderType.Texture> textures
|
| 27 | ) {
|
| 28 | public void drawFromBuffer(final StagedVertexBuffer.ExecuteInfo info, final RenderPass renderPass) {
|
| 29 | this.draw(info, renderPass, this.pipeline);
|
| 30 | }
|
| 31 |
|
| 32 | public void drawFromBufferOit(final StagedVertexBuffer.ExecuteInfo info, final OitStage stage, final RenderPass renderPass) {
|
| 33 | if (this.oitPipelineSet == null) {
|
| 34 | throw new IllegalStateException("Render type " + this.name + " does not have OIT pipelines set up.");
|
| 35 | }
|
| 36 |
|
| 37 | this.draw(info, renderPass, this.oitPipelineSet.getPipeline(stage));
|
| 38 | }
|
| 39 |
|
| 40 | private void draw(final StagedVertexBuffer.ExecuteInfo info, final RenderPass renderPass, final RenderPipeline renderPipeline) {
|
| 41 | renderPass.pushDebugGroup(() -> "Render Type " + this.name);
|
| 42 | GpuBuffer indexBuffer = info.indexBuffer();
|
| 43 | renderPass.setPipeline(RenderSystem.getCompiledPipeline(renderPipeline));
|
| 44 | if (this.scissorState.enabled()) {
|
| 45 | renderPass.enableScissor(this.scissorState.x(), this.scissorState.y(), this.scissorState.width(), this.scissorState.height());
|
| 46 | }
|
| 47 |
|
| 48 | RenderSystem.bindDefaultUniforms(renderPass);
|
| 49 | renderPass.setUniform("DynamicTransforms", this.dynamicTransforms);
|
| 50 | renderPass.setVertexBuffer(0, info.vertexBuffer().slice());
|
| 51 |
|
| 52 | for (PreparedRenderType.Texture texture : this.textures) {
|
| 53 | renderPass.setUniform(texture.name, texture.textureView, texture.sampler);
|
| 54 | }
|
| 55 |
|
| 56 | renderPass.setIndexBuffer(indexBuffer, info.indexType());
|
| 57 | renderPass.drawIndexed(info.indexCount(), 1, info.firstIndex(), info.baseVertex(), 0);
|
| 58 | renderPass.popDebugGroup();
|
| 59 | }
|
| 60 |
|
| 61 | @Environment(EnvType.CLIENT)
|
| 62 | public record Texture(String name, GpuTextureView textureView, GpuSampler sampler) {
|
| 63 | }
|
| 64 | }
|
| 65 |
|