Skip to content

Commit

Permalink
use profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Glease committed Aug 25, 2022
1 parent ebf2d6f commit 1481b68
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/com/gtnewhorizon/structurelib/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand Down Expand Up @@ -388,10 +389,10 @@ public void onClientTick(ClientTickEvent e) {
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();
Expand All @@ -416,8 +417,12 @@ public void onRenderWorldLast(RenderWorldLastEvent e) {
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
Expand All @@ -433,19 +438,24 @@ public void onRenderWorldLast(RenderWorldLastEvent e) {
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);
renderThrough = hint.renderThrough;
}
hint.draw(tes);
}
p.endStartSection("Draw");
tes.draw();
p.endSection();

GL11.glPopAttrib();
GL11.glPopMatrix();
p.endSection();
}
}
}
51 changes: 51 additions & 0 deletions src/main/java/com/gtnewhorizon/structurelib/GLHelper.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 1481b68

Please sign in to comment.