diff options
4 files changed, 97 insertions, 4 deletions
diff --git a/src/main/java/makamys/lodmod/LODMod.java b/src/main/java/makamys/lodmod/LODMod.java index 1366a09..27aac70 100644 --- a/src/main/java/makamys/lodmod/LODMod.java +++ b/src/main/java/makamys/lodmod/LODMod.java @@ -193,6 +193,15 @@ public class LODMod } @SubscribeEvent + public void onRenderTick(TickEvent.RenderTickEvent event) { + if(event.phase == TickEvent.Phase.END) { + if(isActive()) { + renderer.onRenderTickEnd(); + } + } + } + + @SubscribeEvent public void onRenderOverlay(RenderGameOverlayEvent event) { FontRenderer fontRenderer = RenderManager.instance.getFontRenderer(); if(isActive() && event.type == ElementType.TEXT && fontRenderer != null && Minecraft.getMinecraft().gameSettings.showDebugInfo) diff --git a/src/main/java/makamys/lodmod/renderer/GPUMemoryManager.java b/src/main/java/makamys/lodmod/renderer/GPUMemoryManager.java index 72f22a2..a04adb2 100644 --- a/src/main/java/makamys/lodmod/renderer/GPUMemoryManager.java +++ b/src/main/java/makamys/lodmod/renderer/GPUMemoryManager.java @@ -7,15 +7,13 @@ import static org.lwjgl.opengl.GL15.glBufferData; import static org.lwjgl.opengl.GL15.glBufferSubData; import static org.lwjgl.opengl.GL15.glDeleteBuffers; import static org.lwjgl.opengl.GL15.glGenBuffers; -import static org.lwjgl.opengl.GL30.glBindVertexArray; -import static org.lwjgl.opengl.GL30.glGenVertexArrays; - import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import makamys.lodmod.renderer.Mesh.GPUStatus; +import makamys.lodmod.util.GuiHelper; public class GPUMemoryManager { @@ -118,5 +116,34 @@ public class GPUMemoryManager { public List<String> getDebugText() { return Arrays.asList("VRAM: " + (nextMeshOffset / 1024 / 1024) + "MB / " + (BUFFER_SIZE / 1024 / 1024) + "MB"); } + + public void drawInfo() { + int scale = 10000; + int rowLength = 512; + int yOff = 20; + + int meshI = 0; + for(Mesh mesh : sentMeshes) { + + int o = mesh.offset / 10000; + int o2 = (mesh.offset + mesh.buffer.limit()) / 10000; + if(o / rowLength == o2 / rowLength) { + if(mesh.gpuStatus != Mesh.GPUStatus.PENDING_DELETE) { + GuiHelper.drawRectangle(o % rowLength, o / rowLength + yOff, mesh.buffer.limit() / scale + 1, 1, meshI % 2 == 0 ? 0xFFFFFF : 0x808080); + } + } else { + for(int i = o; i < o2; i++) { + int x = i % rowLength; + int y = i / rowLength; + if(mesh.gpuStatus != Mesh.GPUStatus.PENDING_DELETE) { + GuiHelper.drawRectangle(x, y + yOff, 1, 1, 0xFFFFFF); + } + } + } + meshI++; + } + GuiHelper.drawRectangle(0 % rowLength, 0 + yOff, 4, 4, 0x00FF00); + GuiHelper.drawRectangle((BUFFER_SIZE / scale) % rowLength, (BUFFER_SIZE / scale) / rowLength + yOff, 4, 4, 0xFF0000); + } } diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java index 5ed9377..fb49e7b 100644 --- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java +++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java @@ -43,6 +43,7 @@ import org.lwjgl.util.vector.Matrix4f; import makamys.lodmod.LODMod; import makamys.lodmod.ducks.IWorldRenderer; import makamys.lodmod.renderer.Mesh.GPUStatus; +import makamys.lodmod.util.GuiHelper; import makamys.lodmod.util.Util; import static org.lwjgl.opengl.GL11.*; @@ -60,6 +61,7 @@ public class LODRenderer { public boolean renderWorld; public boolean rendererActive; + private boolean showMemoryDebugger; private static int MAX_MESHES = 100000; @@ -147,6 +149,14 @@ public class LODRenderer { Minecraft.getMinecraft().entityRenderer.disableLightmap((double)alpha); } + public void onRenderTickEnd() { + if(showMemoryDebugger && mem != null) { + GuiHelper.begin(); + mem.drawInfo(); + GuiHelper.end(); + } + } + private void sort() { Entity player = Minecraft.getMinecraft().renderViewEntity; for(List<Mesh> list : sentMeshes) { @@ -250,7 +260,8 @@ public class LODRenderer { if(Keyboard.isKeyDown(Keyboard.KEY_R) && !wasDown[Keyboard.KEY_R]) { loadShader(); } - if(Keyboard.isKeyDown(Keyboard.KEY_G) && !wasDown[Keyboard.KEY_G]) { + if(Keyboard.isKeyDown(Keyboard.KEY_M) && !wasDown[Keyboard.KEY_M]) { + showMemoryDebugger = !showMemoryDebugger; //LODChunk chunk = getLODChunk(9, -18); //setMeshVisible(chunk.chunkMeshes[7], false, true); //freezeMeshes = false; diff --git a/src/main/java/makamys/lodmod/util/GuiHelper.java b/src/main/java/makamys/lodmod/util/GuiHelper.java new file mode 100644 index 0000000..0f0f80e --- /dev/null +++ b/src/main/java/makamys/lodmod/util/GuiHelper.java @@ -0,0 +1,46 @@ +package makamys.lodmod.util; + +import org.lwjgl.opengl.GL11; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Tessellator; + +public class GuiHelper { + + public static void begin() { + GL11.glDisable(GL11.GL_TEXTURE_2D); + + Minecraft mc = Minecraft.getMinecraft(); + + //GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); + GL11.glMatrixMode(GL11.GL_PROJECTION); + //GL11.glEnable(GL11.GL_COLOR_MATERIAL); + GL11.glLoadIdentity(); + GL11.glOrtho(0.0D, (double)mc.displayWidth, (double)mc.displayHeight, 0.0D, 1000.0D, 3000.0D); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glLoadIdentity(); + GL11.glTranslatef(0.0F, 0.0F, -2000.0F); + //GL11.glLineWidth(1.0F); + //GL11.glDisable(GL11.GL_TEXTURE_2D); + } + + public static void drawRectangle(int x, int y, int w, int h, int color) { + Tessellator tessellator = Tessellator.instance; + //GL11.glEnable(GL11.GL_BLEND); + tessellator.startDrawingQuads(); + tessellator.setColorOpaque_I(color); + tessellator.addVertex(x, y, 0); + tessellator.addVertex(x, y+h, 0); + tessellator.addVertex(x+w, y+h, 0); + tessellator.addVertex(x+w, y, 0); + + tessellator.draw(); + } + + public static void end() { + //GL11.glDisable(GL11.GL_BLEND); + + //GL11.glEnable(GL11.GL_TEXTURE_2D); + } + +} |