| 1 | package com.mojang.renderpearl.api.commands;
|
| 2 |
|
| 3 | import com.mojang.renderpearl.api.buffers.GpuBuffer;
|
| 4 | import com.mojang.renderpearl.api.buffers.GpuBufferSlice;
|
| 5 | import com.mojang.renderpearl.api.pipeline.CompiledRenderPipeline;
|
| 6 | import com.mojang.renderpearl.api.pipeline.IndexType;
|
| 7 | import com.mojang.renderpearl.api.textures.GpuSampler;
|
| 8 | import com.mojang.renderpearl.api.textures.GpuTextureView;
|
| 9 | import com.mojang.renderpearl.util.UncheckedAutoCloseable;
|
| 10 | import java.nio.ByteBuffer;
|
| 11 | import java.nio.IntBuffer;
|
| 12 | import java.util.Collection;
|
| 13 | import java.util.function.BiConsumer;
|
| 14 | import java.util.function.Supplier;
|
| 15 | import net.fabricmc.api.EnvType;
|
| 16 | import net.fabricmc.api.Environment;
|
| 17 | import org.jspecify.annotations.Nullable;
|
| 18 | import org.lwjgl.PointerBuffer;
|
| 19 |
|
| 20 | @Environment(EnvType.CLIENT)
|
| 21 | public interface RenderPass extends UncheckedAutoCloseable {
|
| 22 | int MAX_VERTEX_BUFFERS = 16;
|
| 23 | int INDIRECT_DRAW_SIZE = 16;
|
| 24 | int INDIRECT_INDEXED_DRAW_SIZE = 20;
|
| 25 |
|
| 26 | void pushDebugGroup(Supplier<String> label);
|
| 27 |
|
| 28 | void popDebugGroup();
|
| 29 |
|
| 30 | void writeTimestamp(GpuQueryPool pool, int index);
|
| 31 |
|
| 32 | void setPipeline(CompiledRenderPipeline pipeline);
|
| 33 |
|
| 34 | void setUniform(String name, @Nullable GpuTextureView textureView, @Nullable GpuSampler sampler);
|
| 35 |
|
| 36 | void setUniform(String name, GpuBuffer value);
|
| 37 |
|
| 38 | void setUniform(String name, GpuBufferSlice value);
|
| 39 |
|
| 40 | void pushConstants(ByteBuffer value);
|
| 41 |
|
| 42 | void enableScissor(int x, int y, int width, int height);
|
| 43 |
|
| 44 | void disableScissor();
|
| 45 |
|
| 46 | void setVertexBuffer(int slot, @Nullable GpuBufferSlice vertexBuffer);
|
| 47 |
|
| 48 | void setIndexBuffer(GpuBuffer indexBuffer, IndexType indexType);
|
| 49 |
|
| 50 | void drawIndexed(int indexCount, int instanceCount, int firstIndex, int vertexOffset, int firstInstance);
|
| 51 |
|
| 52 | void multiDrawIndexed(IntBuffer drawParameters, int instanceCount, int firstInstance, int drawCount);
|
| 53 |
|
| 54 | void multiDrawIndexed(PointerBuffer firstIndexOffsets, IntBuffer indexCounts, IntBuffer vertexOffsets, int drawCount);
|
| 55 |
|
| 56 | void drawIndexedIndirect(GpuBufferSlice commands, int drawCount);
|
| 57 |
|
| 58 | <T> void drawMultipleIndexed(
|
| 59 | Collection<RenderPass.Draw<T>> draws,
|
| 60 | @Nullable GpuBuffer defaultIndexBuffer,
|
| 61 | @Nullable IndexType defaultIndexType,
|
| 62 | Collection<String> dynamicUniforms,
|
| 63 | T uniformArgument
|
| 64 | );
|
| 65 |
|
| 66 | void draw(int vertexCount, int instanceCount, int firstVertex, int firstInstance);
|
| 67 |
|
| 68 | void multiDraw(IntBuffer drawParameters, int instanceCount, int firstInstance, int drawCount);
|
| 69 |
|
| 70 | void multiDraw(IntBuffer firstVertices, IntBuffer vertexCounts, int drawCount);
|
| 71 |
|
| 72 | void drawIndirect(GpuBufferSlice commands, final int drawCount);
|
| 73 |
|
| 74 | @Environment(EnvType.CLIENT)
|
| 75 | record Draw<T>(
|
| 76 | int slot,
|
| 77 | GpuBuffer vertexBuffer,
|
| 78 | @Nullable GpuBuffer indexBuffer,
|
| 79 | @Nullable IndexType indexType,
|
| 80 | int firstIndex,
|
| 81 | int indexCount,
|
| 82 | int baseVertex,
|
| 83 | @Nullable BiConsumer<T, RenderPass.UniformUploader> uniformUploaderConsumer
|
| 84 | ) {
|
| 85 | public Draw(
|
| 86 | final int slot,
|
| 87 | final GpuBuffer vertexBuffer,
|
| 88 | final GpuBuffer indexBuffer,
|
| 89 | final IndexType indexType,
|
| 90 | final int firstIndex,
|
| 91 | final int indexCount,
|
| 92 | final int baseVertex
|
| 93 | ) {
|
| 94 | this(slot, vertexBuffer, indexBuffer, indexType, firstIndex, indexCount, baseVertex, null);
|
| 95 | }
|
| 96 | }
|
| 97 |
|
| 98 | @Environment(EnvType.CLIENT)
|
| 99 | record RenderArea(int x, int y, int width, int height) {
|
| 100 | public boolean fillsTexture(final GpuTextureView texture) {
|
| 101 | return this.x == 0 && this.y == 0 && this.width == texture.getWidth(0) && this.height == texture.getHeight(0);
|
| 102 | }
|
| 103 | }
|
| 104 |
|
| 105 | @Environment(EnvType.CLIENT)
|
| 106 | interface UniformUploader {
|
| 107 | void setUniform(String name, GpuBufferSlice buffer);
|
| 108 |
|
| 109 | void pushConstants(ByteBuffer buffer);
|
| 110 | }
|
| 111 | }
|
| 112 |
|