| 1 | package net.minecraft.client.renderer.state.gui;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.VertexConsumer;
|
| 4 | import com.mojang.renderpearl.api.pipeline.RenderPipeline;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.client.gui.navigation.ScreenRectangle;
|
| 8 | import net.minecraft.client.gui.render.TextureSetup;
|
| 9 | import org.joml.Matrix3x2f;
|
| 10 | import org.joml.Matrix3x2fc;
|
| 11 | import org.jspecify.annotations.Nullable;
|
| 12 |
|
| 13 | @Environment(EnvType.CLIENT)
|
| 14 | public record BlitRenderState(
|
| 15 | RenderPipeline pipeline,
|
| 16 | TextureSetup textureSetup,
|
| 17 | Matrix3x2fc pose,
|
| 18 | int x0,
|
| 19 | int y0,
|
| 20 | int x1,
|
| 21 | int y1,
|
| 22 | float u0,
|
| 23 | float u1,
|
| 24 | float v0,
|
| 25 | float v1,
|
| 26 | int color,
|
| 27 | @Nullable ScreenRectangle scissorArea,
|
| 28 | @Nullable ScreenRectangle bounds
|
| 29 | ) implements GuiElementRenderState {
|
| 30 | public BlitRenderState(
|
| 31 | final RenderPipeline pipeline,
|
| 32 | final TextureSetup textureSetup,
|
| 33 | final Matrix3x2f pose,
|
| 34 | final int x0,
|
| 35 | final int y0,
|
| 36 | final int x1,
|
| 37 | final int y1,
|
| 38 | final float u0,
|
| 39 | final float u1,
|
| 40 | final float v0,
|
| 41 | final float v1,
|
| 42 | final int color,
|
| 43 | final @Nullable ScreenRectangle scissorArea
|
| 44 | ) {
|
| 45 | this(pipeline, textureSetup, pose, x0, y0, x1, y1, u0, u1, v0, v1, color, scissorArea, getBounds(x0, y0, x1, y1, pose, scissorArea));
|
| 46 | }
|
| 47 |
|
| 48 | @Override
|
| 49 | public void buildVertices(final VertexConsumer vertexConsumer) {
|
| 50 | vertexConsumer.addVertexWith2DPose(this.pose(), this.x0(), this.y0()).setUv(this.u0(), this.v0()).setColor(this.color());
|
| 51 | vertexConsumer.addVertexWith2DPose(this.pose(), this.x0(), this.y1()).setUv(this.u0(), this.v1()).setColor(this.color());
|
| 52 | vertexConsumer.addVertexWith2DPose(this.pose(), this.x1(), this.y1()).setUv(this.u1(), this.v1()).setColor(this.color());
|
| 53 | vertexConsumer.addVertexWith2DPose(this.pose(), this.x1(), this.y0()).setUv(this.u1(), this.v0()).setColor(this.color());
|
| 54 | }
|
| 55 |
|
| 56 | private static @Nullable ScreenRectangle getBounds(
|
| 57 | final int x0, final int y0, final int x1, final int y1, final Matrix3x2f pose, final @Nullable ScreenRectangle scissorArea
|
| 58 | ) {
|
| 59 | ScreenRectangle bounds = new ScreenRectangle(x0, y0, x1 - x0, y1 - y0).transformMaxBounds(pose);
|
| 60 | return scissorArea != null ? scissorArea.intersection(bounds) : bounds;
|
| 61 | }
|
| 62 | }
|
| 63 |
|