| 1 | package net.minecraft.client.gui.render.pip;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 4 | import net.fabricmc.api.EnvType;
|
| 5 | import net.fabricmc.api.Environment;
|
| 6 | import net.minecraft.client.renderer.SubmitNodeCollector;
|
| 7 | import net.minecraft.client.renderer.rendertype.RenderTypes;
|
| 8 | import net.minecraft.client.renderer.state.gui.pip.GuiProfilerChartRenderState;
|
| 9 | import net.minecraft.util.ARGB;
|
| 10 | import net.minecraft.util.Mth;
|
| 11 | import net.minecraft.util.profiling.ResultField;
|
| 12 |
|
| 13 | @Environment(EnvType.CLIENT)
|
| 14 | public class GuiProfilerChartRenderer extends PictureInPictureRenderer<GuiProfilerChartRenderState> {
|
| 15 | @Override
|
| 16 | public Class<GuiProfilerChartRenderState> getRenderStateClass() {
|
| 17 | return GuiProfilerChartRenderState.class;
|
| 18 | }
|
| 19 |
|
| 20 | protected void renderToTexture(final GuiProfilerChartRenderState chartState, final PoseStack poseStack, final SubmitNodeCollector submitNodeCollector) {
|
| 21 | double totalPercentage = 0.0;
|
| 22 | poseStack.translate(0.0F, -5.0F, 0.0F);
|
| 23 |
|
| 24 | for (ResultField result : chartState.chartData()) {
|
| 25 | double slicePercentage = result.percentage;
|
| 26 | double currentPercentage = totalPercentage;
|
| 27 | totalPercentage += slicePercentage;
|
| 28 | int steps = Mth.floor(slicePercentage / 4.0) + 1;
|
| 29 | int color = ARGB.opaque(result.getColor());
|
| 30 | int shadeColor = ARGB.multiply(color, -8355712);
|
| 31 | submitNodeCollector.submitCustomGeometry(poseStack, RenderTypes.debugTriangleFan(), (pose, buffer) -> {
|
| 32 | buffer.addVertex(pose, 0.0F, 0.0F, 0.0F).setColor(color);
|
| 33 |
|
| 34 | for (int j = steps; j >= 0; j--) {
|
| 35 | float dir = (float)((currentPercentage + slicePercentage * j / steps) * (float) (Math.PI * 2) / 100.0);
|
| 36 | float xx = Mth.sin(dir) * 105.0F;
|
| 37 | float yy = Mth.cos(dir) * 105.0F * 0.5F;
|
| 38 | buffer.addVertex(pose, xx, yy, 0.0F).setColor(color);
|
| 39 | }
|
| 40 | });
|
| 41 | submitNodeCollector.submitCustomGeometry(poseStack, RenderTypes.debugQuads(), (pose, buffer) -> {
|
| 42 | for (int j = steps; j > 0; j--) {
|
| 43 | float dir0 = (float)((currentPercentage + slicePercentage * j / steps) * (float) (Math.PI * 2) / 100.0);
|
| 44 | float x0 = Mth.sin(dir0) * 105.0F;
|
| 45 | float y0 = Mth.cos(dir0) * 105.0F * 0.5F;
|
| 46 | float dir1 = (float)((currentPercentage + slicePercentage * (j - 1) / steps) * (float) (Math.PI * 2) / 100.0);
|
| 47 | float x1 = Mth.sin(dir1) * 105.0F;
|
| 48 | float y1 = Mth.cos(dir1) * 105.0F * 0.5F;
|
| 49 | if (!((y0 + y1) / 2.0F < 0.0F)) {
|
| 50 | buffer.addVertex(pose, x0, y0, 0.0F).setColor(shadeColor);
|
| 51 | buffer.addVertex(pose, x0, y0 + 10.0F, 0.0F).setColor(shadeColor);
|
| 52 | buffer.addVertex(pose, x1, y1 + 10.0F, 0.0F).setColor(shadeColor);
|
| 53 | buffer.addVertex(pose, x1, y1, 0.0F).setColor(shadeColor);
|
| 54 | }
|
| 55 | }
|
| 56 | });
|
| 57 | }
|
| 58 | }
|
| 59 |
|
| 60 | @Override
|
| 61 | protected float getTranslateY(final int height, final int guiScale) {
|
| 62 | return height / 2.0F;
|
| 63 | }
|
| 64 |
|
| 65 | @Override
|
| 66 | protected String getTextureLabel() {
|
| 67 | return "profiler chart";
|
| 68 | }
|
| 69 | }
|
| 70 |
|