1.21.5 BufferRenderer is completely gone? #4566
Description
Do we have to use I cannot seem to find any examples or documentation regarding this, any help would be much appreciated. |
Replies: 4 comments 12 replies
|
It seems that we now need to use RenderLayer.getSolid().draw(yourBuiltBuffer);You might as well create your own layer using I am new modding, I might not be entirely correct. |
|
Thanks for the tip! For the other people who might run into the same issue, here are the changes I made to make it work for me:First, I made a
|
|
How to use @Mixin(value = InGameHud.class)
public class Test {
@Inject(method = "render", at = @At(value = "RETURN"))
private void onRender(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) {
Matrix3x2fStack matrices = context.getMatrices();
matrices.pushMatrix();
GlStateManager._enableBlend();
GlStateManager._disableDepthTest();
Tessellator tess = Tessellator.getInstance();
BufferBuilder buff = tess.begin(ExampleModClient.renderLayer.getDrawMode(), ExampleModClient.renderLayer.getVertexFormat());
int rgb = Color.RED.getRGB();
buff.vertex(matrices, 0, 0).color(rgb);
buff.vertex(matrices,1000, 1000).color(rgb);
ExampleModClient.renderLayer.draw(buff.end());
GlStateManager._enableDepthTest();
GlStateManager._disableBlend();
matrices.popMatrix();
}
}
public static final RenderPipeline DEBUG_LINES = RenderPipelines.register(
RenderPipeline.builder(RenderPipelines.POSITION_COLOR_SNIPPET)
.withLocation("pipeline/debug_lines")
.withVertexFormat(VertexFormats.POSITION_COLOR, VertexFormat.DrawMode.DEBUG_LINES)
.withCull(false)
.build()
);
public static final RenderLayer renderLayer = RenderLayer.of(
"debug_lines",
1536,
DEBUG_LINES,
RenderLayer.MultiPhaseParameters.builder().lineWidth(new RenderPhase.LineWidth(OptionalDouble.of(1))).build(false)
); |
|
You can copy the code from public void draw(BuiltBuffer buffer) {
RenderPipeline renderPipeline = this.getPipeline();
this.startDrawing();
BuiltBuffer var3 = buffer;
try {
GpuBuffer gpuBuffer = renderPipeline.getVertexFormat().uploadImmediateVertexBuffer(buffer.getBuffer());
GpuBuffer gpuBuffer2;
VertexFormat.IndexType indexType;
if (buffer.getSortedBuffer() == null) {
RenderSystem.ShapeIndexBuffer shapeIndexBuffer = RenderSystem.getSequentialBuffer(buffer.getDrawParameters().mode());
gpuBuffer2 = shapeIndexBuffer.getIndexBuffer(buffer.getDrawParameters().indexCount());
indexType = shapeIndexBuffer.getIndexType();
} else {
gpuBuffer2 = renderPipeline.getVertexFormat().uploadImmediateIndexBuffer(buffer.getSortedBuffer());
indexType = buffer.getDrawParameters().indexType();
}
Framebuffer framebuffer = this.phases.target.get();
try (RenderPass renderPass = RenderSystem.getDevice().createCommandEncoder().createRenderPass(framebuffer.getColorAttachment(), OptionalInt.empty(), framebuffer.useDepthAttachment ? framebuffer.getDepthAttachment() : null, OptionalDouble.empty())) {
renderPass.setPipeline(renderPipeline);
renderPass.setVertexBuffer(0, gpuBuffer);
if (RenderSystem.SCISSOR_STATE.isEnabled()) {
renderPass.enableScissor(RenderSystem.SCISSOR_STATE);
}
for(int i = 0; i < 12; ++i) {
GpuTexture gpuTexture = RenderSystem.getShaderTexture(i);
if (gpuTexture != null) {
renderPass.bindSampler("Sampler" + i, gpuTexture);
}
}
renderPass.setIndexBuffer(gpuBuffer2, indexType);
renderPass.drawIndexed(0, buffer.getDrawParameters().indexCount());
}
} catch (Throwable var14) {
if (buffer != null) {
try {
var3.close();
} catch (Throwable var11) {
var14.addSuppressed(var11);
}
}
throw var14;
}
if (buffer != null) {
buffer.close();
}
this.endDrawing();
}Basically you can change this to: This function contains complex logic, you can skip many phases (e.g. index buffer) in custom render. |
It seems that we now need to use
RenderLayer.draw(BuiltBuffer). Thus, we need to select aRenderLayerthat matches what we want to render. They use aRenderPipeline, where the shader is specified. For example, theRenderLayer.SOLIDlayer uses thecore/terrainshader through theRenderPipelines.SOLIDpipeline. If you wanted to render something on theSOLIDlayer, you would do something like this:You might as well create your own layer using
RenderLayer.of.I am new modding, I might not be entirely correct.