diff options
Diffstat (limited to 'src/main/kotlin/util/render/RenderInWorldContext.kt')
-rw-r--r-- | src/main/kotlin/util/render/RenderInWorldContext.kt | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/src/main/kotlin/util/render/RenderInWorldContext.kt b/src/main/kotlin/util/render/RenderInWorldContext.kt index b61b9aa..ae8d6d3 100644 --- a/src/main/kotlin/util/render/RenderInWorldContext.kt +++ b/src/main/kotlin/util/render/RenderInWorldContext.kt @@ -8,14 +8,12 @@ import java.lang.Math.pow import org.joml.Matrix4f import org.joml.Vector3f import net.minecraft.client.gl.VertexBuffer -import net.minecraft.client.render.BufferBuilder -import net.minecraft.client.render.BufferRenderer import net.minecraft.client.render.Camera -import net.minecraft.client.render.GameRenderer import net.minecraft.client.render.RenderLayer import net.minecraft.client.render.RenderPhase import net.minecraft.client.render.RenderTickCounter import net.minecraft.client.render.Tessellator +import net.minecraft.client.render.VertexConsumer import net.minecraft.client.render.VertexConsumerProvider import net.minecraft.client.render.VertexFormat import net.minecraft.client.render.VertexFormats @@ -47,7 +45,7 @@ class RenderInWorldContext private constructor( RenderLayer.MultiPhaseParameters.builder() .depthTest(RenderPhase.ALWAYS_DEPTH_TEST) .transparency(RenderPhase.TRANSLUCENT_TRANSPARENCY) - .program(RenderPhase.COLOR_PROGRAM) + .program(RenderPhase.POSITION_COLOR_PROGRAM) .build(false)) val LINES = RenderLayer.of("firmament_rendertype_lines", VertexFormats.LINES, @@ -72,7 +70,7 @@ class RenderInWorldContext private constructor( fun block(blockPos: BlockPos) { matrixStack.push() matrixStack.translate(blockPos.x.toFloat(), blockPos.y.toFloat(), blockPos.z.toFloat()) - buildCube(matrixStack.peek().positionMatrix, tesselator) + buildCube(matrixStack.peek().positionMatrix, vertexConsumers.getBuffer(RenderLayer.getDebugFilledBox())) matrixStack.pop() } @@ -136,22 +134,24 @@ class RenderInWorldContext private constructor( } fun tinyBlock(vec3d: Vec3d, size: Float) { - RenderSystem.setShader(GameRenderer::getPositionColorProgram) + val buf = vertexConsumers.getBuffer(RenderLayer.getDebugFilledBox()) // TODO: custom rendewr layer here, maybe matrixStack.push() matrixStack.translate(vec3d.x, vec3d.y, vec3d.z) matrixStack.scale(size, size, size) matrixStack.translate(-.5, -.5, -.5) - buildCube(matrixStack.peek().positionMatrix, tesselator) + buildCube(matrixStack.peek().positionMatrix, buf) matrixStack.pop() + vertexConsumers.draw() } fun wireframeCube(blockPos: BlockPos, lineWidth: Float = 10F) { - RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram) + val buf = vertexConsumers.getBuffer(RenderLayer.LINES) matrixStack.push() RenderSystem.lineWidth(lineWidth / pow(camera.pos.squaredDistanceTo(blockPos.toCenterPos()), 0.25).toFloat()) matrixStack.translate(blockPos.x.toFloat(), blockPos.y.toFloat(), blockPos.z.toFloat()) - buildWireFrameCube(matrixStack.peek(), tesselator) - matrixStack.pop() + buildWireFrameCube(matrixStack.peek(), buf) + matrixStack.pop() + vertexConsumers.draw() } fun line(vararg points: Vec3d, lineWidth: Float = 10F) { @@ -165,6 +165,7 @@ class RenderInWorldContext private constructor( fun line(points: List<Vec3d>, lineWidth: Float = 10F) { RenderSystem.lineWidth(lineWidth) + // TODO: replace with renderlayers val buffer = tesselator.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES) val matrix = matrixStack.peek() @@ -191,7 +192,7 @@ class RenderInWorldContext private constructor( companion object { private fun doLine( matrix: MatrixStack.Entry, - buf: BufferBuilder, + buf: VertexConsumer, i: Float, j: Float, k: Float, @@ -213,9 +214,7 @@ class RenderInWorldContext private constructor( } - private fun buildWireFrameCube(matrix: MatrixStack.Entry, tessellator: Tessellator) { - val buf = tessellator.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES) - + private fun buildWireFrameCube(matrix: MatrixStack.Entry, buf: VertexConsumer) { for (i in 0..1) { for (j in 0..1) { val i = i.toFloat() @@ -225,11 +224,9 @@ class RenderInWorldContext private constructor( doLine(matrix, buf, i, j, 0F, i, j, 1F) } } - BufferRenderer.drawWithGlobalProgram(buf.end()) } - private fun buildCube(matrix: Matrix4f, tessellator: Tessellator) { - val buf = tessellator.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR) + private fun buildCube(matrix: Matrix4f, buf: VertexConsumer) { buf.vertex(matrix, 0.0F, 0.0F, 0.0F).color(-1).next() buf.vertex(matrix, 0.0F, 0.0F, 1.0F).color(-1).next() buf.vertex(matrix, 0.0F, 1.0F, 1.0F).color(-1).next() @@ -266,7 +263,6 @@ class RenderInWorldContext private constructor( buf.vertex(matrix, 1.0F, 1.0F, 1.0F).color(-1).next() buf.vertex(matrix, 0.0F, 1.0F, 1.0F).color(-1).next() buf.vertex(matrix, 1.0F, 0.0F, 1.0F).color(-1).next() - RenderLayers.TRANSLUCENT_TRIS.draw(buf.end()) } |