From 1481b68133401f73de5af0ee2b4e8c76f4640ae1 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Thu, 25 Aug 2022 14:24:27 +0800 Subject: [PATCH] use profiler --- .../structurelib/ClientProxy.java | 16 ++++-- .../gtnewhorizon/structurelib/GLHelper.java | 51 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/gtnewhorizon/structurelib/GLHelper.java diff --git a/src/main/java/com/gtnewhorizon/structurelib/ClientProxy.java b/src/main/java/com/gtnewhorizon/structurelib/ClientProxy.java index 5295e3ce..8c16c12e 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/ClientProxy.java +++ b/src/main/java/com/gtnewhorizon/structurelib/ClientProxy.java @@ -20,6 +20,7 @@ import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; +import net.minecraft.profiler.Profiler; import net.minecraft.util.ChatComponentText; import net.minecraft.util.IIcon; import net.minecraft.util.Vec3; @@ -388,10 +389,10 @@ public class ClientProxy extends CommonProxy { for (HintGroup c : allGroups) allHintsForRender.addAll(c.getHints()); sortRequired = true; } - if (renderThrough > 0 && (sortRequired || playerPos.squareDistanceTo(lastPlayerPos) > 1e-4)) { + if (renderThrough > 0 && (sortRequired || playerPos.squareDistanceTo(lastPlayerPos) > 1e-2)) { // only sort if there is anything that need depth test disabled // only redo sort if player moved some distance - // default is 0.01 block + // default is 0.1 block // if there was a full rebuild, go sort it as well allHintsForRender.sort(Comparator.comparingDouble(info -> info.getSquareDistanceTo(playerPos))); resetPlayerLocation(); @@ -416,8 +417,12 @@ public class ClientProxy extends CommonProxy { if (allHintsForRender.isEmpty()) return; // seriously, I'm not a OpenGL expert, so I'm probably doing a lot of very stupid stuff here. - // Please contribute patches if you find something to optimize. + // Please consider contributing patches if you find something to optimize. + Profiler p = Minecraft.getMinecraft().mcProfiler; + + p.startSection("HintParticle"); + p.startSection("Prepare"); GL11.glPushMatrix(); GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT); // TODO figure out original states GL11.glDisable(GL11.GL_CULL_FACE); // we need the back facing rendered because the thing is transparent @@ -433,8 +438,10 @@ public class ClientProxy extends CommonProxy { HintParticleInfo hint = allHintsForRender.get(i); if (renderThrough != hint.renderThrough) { if (i > 0) { + p.endStartSection("Draw"); tes.draw(); tes.startDrawingQuads(); + p.endStartSection("Prepare"); } if (hint.renderThrough) GL11.glDisable(GL11.GL_DEPTH_TEST); else GL11.glEnable(GL11.GL_DEPTH_TEST); @@ -442,10 +449,13 @@ public class ClientProxy extends CommonProxy { } hint.draw(tes); } + p.endStartSection("Draw"); tes.draw(); + p.endSection(); GL11.glPopAttrib(); GL11.glPopMatrix(); + p.endSection(); } } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/GLHelper.java b/src/main/java/com/gtnewhorizon/structurelib/GLHelper.java new file mode 100644 index 00000000..ae7a3192 --- /dev/null +++ b/src/main/java/com/gtnewhorizon/structurelib/GLHelper.java @@ -0,0 +1,51 @@ +package com.gtnewhorizon.structurelib; + +import java.nio.ByteBuffer; +import org.lwjgl.opengl.ARBVertexBufferObject; +import org.lwjgl.opengl.ContextCapabilities; +import org.lwjgl.opengl.GL15; +import org.lwjgl.opengl.GLContext; + +class GLHelper { + public static final boolean vboSupported; + private static final boolean arbVbo; + + static { + ContextCapabilities contextcapabilities = GLContext.getCapabilities(); + + arbVbo = !contextcapabilities.OpenGL15 && contextcapabilities.GL_ARB_vertex_buffer_object; + vboSupported = contextcapabilities.OpenGL15 || arbVbo; + } + + public static int glGenBuffers() { + return arbVbo ? ARBVertexBufferObject.glGenBuffersARB() : GL15.glGenBuffers(); + } + + public static void glBindBuffer(int target, int buffer) { + if (arbVbo) { + ARBVertexBufferObject.glBindBufferARB(target, buffer); + } else { + GL15.glBindBuffer(target, buffer); + } + } + + public static void glBufferData(int target, ByteBuffer data, int usage) { + if (arbVbo) { + ARBVertexBufferObject.glBufferDataARB(target, data, usage); + } else { + GL15.glBufferData(target, data, usage); + } + } + + public static void glDeleteBuffers(int buffer) { + if (arbVbo) { + ARBVertexBufferObject.glDeleteBuffersARB(buffer); + } else { + GL15.glDeleteBuffers(buffer); + } + } + + public static boolean useVbo() { + return vboSupported; + } +}