From 8dbf01a344a4ee54293e122b6fdc664c57ee8efb Mon Sep 17 00:00:00 2001 From: peytonplayz585 <106421860+PeytonPlayz595@users.noreply.github.com> Date: Sun, 27 Aug 2023 10:06:02 -0500 Subject: [PATCH] Started on VBOs --- .../shadow/opengl/OpenGLManager.java | 30 ++++++++++++++++ .../shadow/opengl/VertexBuffer.java | 34 +++++++++++++++++++ .../shadow/opengl/VertexBufferUploader.java | 12 +++++++ .../v1_8/minecraft/ChunkUpdateManager.java | 18 +++++++--- .../java/net/minecraft/client/Minecraft.java | 2 +- .../renderer/chunk/VboChunkFactory.java | 11 ++++++ 6 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 src/main/java/net/PeytonPlayz585/shadow/opengl/OpenGLManager.java create mode 100644 src/main/java/net/PeytonPlayz585/shadow/opengl/VertexBuffer.java create mode 100644 src/main/java/net/PeytonPlayz585/shadow/opengl/VertexBufferUploader.java create mode 100644 src/main/java/net/minecraft/client/renderer/chunk/VboChunkFactory.java diff --git a/src/main/java/net/PeytonPlayz585/shadow/opengl/OpenGLManager.java b/src/main/java/net/PeytonPlayz585/shadow/opengl/OpenGLManager.java new file mode 100644 index 0000000..b9da9d8 --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/shadow/opengl/OpenGLManager.java @@ -0,0 +1,30 @@ +package net.PeytonPlayz585.shadow.opengl; + +import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL; +import net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL; +import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer; +import net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums; + +public class OpenGLManager { + + public static void setClientActiveTexture(int lightmaptexunit) { + PlatformOpenGL._wglActiveTexture(lightmaptexunit); + } + + public static void glBindBuffer(int glArrayBuffer, IBufferGL vbo) { + PlatformOpenGL._wglBindBuffer(glArrayBuffer, vbo); + } + + public static void glBufferData(int glArrayBuffer, ByteBuffer p_181722_1_, int i) { + PlatformOpenGL._wglBufferData(glArrayBuffer, p_181722_1_, i); + } + + public static void glDrawArrays(int glTriangles, int i, int j) { + PlatformOpenGL._wglDrawArrays(RealOpenGLEnums.GL_TRIANGLES, 0, 6); + } + + public static void glEnableClientState(int i) { + //PlatformOpenGL._wglEnableVertexAttribArray(i); + } + +} diff --git a/src/main/java/net/PeytonPlayz585/shadow/opengl/VertexBuffer.java b/src/main/java/net/PeytonPlayz585/shadow/opengl/VertexBuffer.java new file mode 100644 index 0000000..9e1560f --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/shadow/opengl/VertexBuffer.java @@ -0,0 +1,34 @@ +package net.PeytonPlayz585.shadow.opengl; + +import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.GL_COMPILE; + +import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL; +import net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL; +import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer; +import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU; +import net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums; +import net.lax1dude.eaglercraft.v1_8.opengl.VertexFormat; +import net.lax1dude.eaglercraft.v1_8.opengl.WorldRenderer; + +public class VertexBuffer { + //private IBufferGL vbo = null; + + public void bindBuffer(IBufferGL vbo) { + OpenGLManager.glBindBuffer(RealOpenGLEnums.GL_ARRAY_BUFFER, vbo); + } + + public void func_181722_a(WorldRenderer p_181722_1_, int parInt1) { + if(p_181722_1_.getVertexCount() > 0) { + EaglercraftGPU.glNewList(parInt1, GL_COMPILE); + VertexFormat fmt = p_181722_1_.getVertexFormat(); + ByteBuffer buf = p_181722_1_.getByteBuffer(); + EaglercraftGPU.renderBuffer(buf.position(0).compact().limit(p_181722_1_.getVertexCount() * fmt.attribStride), fmt.eaglercraftAttribBits, 7, p_181722_1_.getVertexCount()); + p_181722_1_.reset(); + EaglercraftGPU.glEndList(); + } + } + + public void unbindBuffer(IBufferGL vbo) { + OpenGLManager.glBindBuffer(RealOpenGLEnums.GL_ARRAY_BUFFER, vbo); + } +} \ No newline at end of file diff --git a/src/main/java/net/PeytonPlayz585/shadow/opengl/VertexBufferUploader.java b/src/main/java/net/PeytonPlayz585/shadow/opengl/VertexBufferUploader.java new file mode 100644 index 0000000..3866c2b --- /dev/null +++ b/src/main/java/net/PeytonPlayz585/shadow/opengl/VertexBufferUploader.java @@ -0,0 +1,12 @@ +package net.PeytonPlayz585.shadow.opengl; + +import net.lax1dude.eaglercraft.v1_8.opengl.WorldRenderer; + +public class VertexBufferUploader { + + private VertexBuffer vertexBuffer = new VertexBuffer(); + + public void func_181679_a(WorldRenderer p_181679_1_, int parInt1) { + this.vertexBuffer.func_181722_a(p_181679_1_, parInt1); + } +} diff --git a/src/main/java/net/lax1dude/eaglercraft/v1_8/minecraft/ChunkUpdateManager.java b/src/main/java/net/lax1dude/eaglercraft/v1_8/minecraft/ChunkUpdateManager.java index b80bf04..582ce1e 100644 --- a/src/main/java/net/lax1dude/eaglercraft/v1_8/minecraft/ChunkUpdateManager.java +++ b/src/main/java/net/lax1dude/eaglercraft/v1_8/minecraft/ChunkUpdateManager.java @@ -5,6 +5,7 @@ import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*; import java.util.LinkedList; import java.util.List; +import net.PeytonPlayz585.shadow.opengl.VertexBufferUploader; import net.lax1dude.eaglercraft.v1_8.log4j.LogManager; import net.lax1dude.eaglercraft.v1_8.log4j.Logger; import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU; @@ -25,6 +26,7 @@ public class ChunkUpdateManager { private static final Logger LOGGER = LogManager.getLogger(); private final WorldVertexBufferUploader worldVertexUploader; + private final VertexBufferUploader vertexUploader = new VertexBufferUploader(); private final RegionRenderCacheBuilder renderCache; private int chunkUpdatesTotal = 0; @@ -192,11 +194,13 @@ public class ChunkUpdateManager { } } - public void uploadChunk(final EnumWorldBlockLayer player, final WorldRenderer chunkRenderer, - final RenderChunk compiledChunkIn, final CompiledChunk parCompiledChunk) { - this.uploadDisplayList(chunkRenderer, - ((ListedRenderChunk) compiledChunkIn).getDisplayList(player, parCompiledChunk), compiledChunkIn); - chunkRenderer.setTranslation(0.0D, 0.0D, 0.0D); + public void uploadChunk(final EnumWorldBlockLayer player, final WorldRenderer p_178503_2_, final RenderChunk chunkRenderer, final CompiledChunk compiledChunkIn) { + if(Minecraft.getMinecraft().gameSettings.useVbo) { + this.uploadVertexBuffer(p_178503_2_, ((ListedRenderChunk) chunkRenderer).getDisplayList(player, compiledChunkIn)); + } else { + this.uploadDisplayList(p_178503_2_, ((ListedRenderChunk) chunkRenderer).getDisplayList(player, compiledChunkIn), chunkRenderer); + } + p_178503_2_.setTranslation(0.0D, 0.0D, 0.0D); } private void uploadDisplayList(WorldRenderer chunkRenderer, int parInt1, RenderChunk parRenderChunk) { @@ -206,6 +210,10 @@ public class ChunkUpdateManager { GlStateManager.popMatrix(); EaglercraftGPU.glEndList(); } + + private void uploadVertexBuffer(WorldRenderer p_178506_1_, int parInt1) { + this.vertexUploader.func_181679_a(p_178506_1_, parInt1); + } public boolean isAlreadyQueued(RenderChunk update) { for(int i = 0, l = queue.size(); i < l; ++i) { diff --git a/src/main/java/net/minecraft/client/Minecraft.java b/src/main/java/net/minecraft/client/Minecraft.java index 7f83f05..da70ffb 100644 --- a/src/main/java/net/minecraft/client/Minecraft.java +++ b/src/main/java/net/minecraft/client/Minecraft.java @@ -821,7 +821,7 @@ public class Minecraft implements IThreadListener { .getValueMax() ? "inf" : Integer.valueOf(this.gameSettings.limitFramerate), this.gameSettings.enableVsync ? " vsync" : "", this.gameSettings.fancyGraphics ? "" : " fast", this.gameSettings.clouds == 0 ? "" - : (this.gameSettings.clouds == 1 ? " fast-clouds" : " fancy-clouds") }); + : (this.gameSettings.clouds == 1 ? " fast-clouds" : " fancy-clouds"), gameSettings.useVbo ? " vbo" : "" }); RenderChunk.renderChunksUpdated = 0; this.debugUpdateTime += 1000L; this.fpsCounter = 0; diff --git a/src/main/java/net/minecraft/client/renderer/chunk/VboChunkFactory.java b/src/main/java/net/minecraft/client/renderer/chunk/VboChunkFactory.java new file mode 100644 index 0000000..fda85b7 --- /dev/null +++ b/src/main/java/net/minecraft/client/renderer/chunk/VboChunkFactory.java @@ -0,0 +1,11 @@ +package net.minecraft.client.renderer.chunk; + +import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; + +public class VboChunkFactory implements IRenderChunkFactory { + public RenderChunk makeRenderChunk(World worldIn, RenderGlobal globalRenderer, BlockPos pos, int index) { + return new RenderChunk(worldIn, globalRenderer, pos, index); + } +} \ No newline at end of file