diff --git a/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java b/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java index 7c932c33..17d4a6d8 100644 --- a/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java +++ b/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java @@ -98,6 +98,8 @@ public abstract class AbstractRenderPipeline extends TrackedObject { glBlitNamedFramebuffer(sourceFrameBuffer, targetFb, 0,0, width, height, 0,0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST); glBindFramebuffer(GL30.GL_FRAMEBUFFER, targetFb); + //GL11C.glClearStencil(1); + //GL11C.glClear(GL_STENCIL_BUFFER_BIT); //This whole thing is hell, we basicly want to create a mask stenicel/depth mask specificiclly // in theory we could do this in a single pass by passing in the depth buffer from the sourceFrambuffer diff --git a/src/main/java/me/cortex/voxy/client/core/gl/Capabilities.java b/src/main/java/me/cortex/voxy/client/core/gl/Capabilities.java index b54181cf..2c0d08c6 100644 --- a/src/main/java/me/cortex/voxy/client/core/gl/Capabilities.java +++ b/src/main/java/me/cortex/voxy/client/core/gl/Capabilities.java @@ -25,9 +25,11 @@ public class Capabilities { public final boolean indirectParameters; public final boolean isIntel; public final boolean subgroup; + public final boolean sparseBuffer; public Capabilities() { var cap = GL.getCapabilities(); + this.sparseBuffer = cap.GL_ARB_sparse_buffer; this.compute = cap.glDispatchComputeIndirect != 0; this.indirectParameters = cap.glMultiDrawElementsIndirectCountARB != 0; this.repFragTest = cap.GL_NV_representative_fragment_test; diff --git a/src/main/java/me/cortex/voxy/client/core/gl/GlBuffer.java b/src/main/java/me/cortex/voxy/client/core/gl/GlBuffer.java index 57b9e615..c0e21e1b 100644 --- a/src/main/java/me/cortex/voxy/client/core/gl/GlBuffer.java +++ b/src/main/java/me/cortex/voxy/client/core/gl/GlBuffer.java @@ -4,6 +4,7 @@ import me.cortex.voxy.common.util.TrackedObject; import org.lwjgl.opengl.GL11; import org.lwjgl.system.MemoryUtil; +import static org.lwjgl.opengl.ARBSparseBuffer.GL_SPARSE_STORAGE_BIT_ARB; import static org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE; import static org.lwjgl.opengl.GL15.glDeleteBuffers; import static org.lwjgl.opengl.GL45C.*; @@ -23,7 +24,9 @@ public class GlBuffer extends TrackedObject { this.id = glCreateBuffers(); this.size = size; glNamedBufferStorage(this.id, size, flags); - this.zero(); + if ((flags&GL_SPARSE_STORAGE_BIT_ARB)==0) { + this.zero(); + } COUNT++; TOTAL_SIZE += size; diff --git a/src/main/java/me/cortex/voxy/client/core/model/TextureUtils.java b/src/main/java/me/cortex/voxy/client/core/model/TextureUtils.java index bbc397e2..0e200e55 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/TextureUtils.java +++ b/src/main/java/me/cortex/voxy/client/core/model/TextureUtils.java @@ -1,6 +1,7 @@ package me.cortex.voxy.client.core.model; import net.caffeinemc.mods.sodium.client.util.color.ColorSRGB; +import net.minecraft.client.texture.MipmapHelper; //Texturing utils to manipulate data from the model bakery public class TextureUtils { @@ -177,7 +178,11 @@ public class TextureUtils { public static int mipColours(int one, int two, int three, int four) { - return weightedAverageColor(weightedAverageColor(one, two), weightedAverageColor(three, four)); + if (true) { + return MipmapHelper.blend(one, two, three, four, false); + } else { + return weightedAverageColor(weightedAverageColor(one, two), weightedAverageColor(three, four)); + } } //TODO: FIXME!!! ITS READING IT AS ABGR??? isnt the format RGBA?? diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/section/geometry/BasicSectionGeometryData.java b/src/main/java/me/cortex/voxy/client/core/rendering/section/geometry/BasicSectionGeometryData.java index d94ae4e8..41847ca2 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/section/geometry/BasicSectionGeometryData.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/section/geometry/BasicSectionGeometryData.java @@ -4,7 +4,9 @@ import me.cortex.voxy.client.core.gl.Capabilities; import me.cortex.voxy.client.core.gl.GlBuffer; import me.cortex.voxy.common.Logger; -import static org.lwjgl.opengl.GL11C.glFinish; +import static org.lwjgl.opengl.ARBSparseBuffer.GL_SPARSE_STORAGE_BIT_ARB; +import static org.lwjgl.opengl.ARBSparseBuffer.glNamedBufferPageCommitmentARB; +import static org.lwjgl.opengl.GL11C.*; public class BasicSectionGeometryData implements IGeometryData { public static final int SECTION_METADATA_SIZE = 32; @@ -28,7 +30,26 @@ public class BasicSectionGeometryData implements IGeometryData { } Logger.info(msg); Logger.info("if your game crashes/exits here without any other log message, try manually decreasing the geometry capacity"); - this.geometryBuffer = new GlBuffer(geometryCapacity); + glGetError();//Clear any errors + var buffer = new GlBuffer(geometryCapacity); + int error = glGetError(); + if (error != GL_NO_ERROR) { + if (error == GL_OUT_OF_MEMORY && Capabilities.INSTANCE.sparseBuffer) { + Logger.error("Failed to allocate geometry buffer, attempting workaround with sparse buffers"); + buffer.free(); + buffer = new GlBuffer(geometryCapacity, GL_SPARSE_STORAGE_BIT_ARB); + glNamedBufferPageCommitmentARB(buffer.id, 0, geometryCapacity, true); + buffer.zero(); + error = glGetError(); + if (error != GL_NO_ERROR) { + buffer.free(); + throw new IllegalStateException("Unable to allocate geometry buffer using workaround, got gl error " + error); + } + } else { + throw new IllegalStateException("Unable to allocate geometry buffer, got gl error " + error); + } + } + this.geometryBuffer = buffer; long delta = System.currentTimeMillis() - start; Logger.info("Successfully allocated and zeroed the geometry buffer in " + delta + "ms"); } diff --git a/src/main/resources/voxy.accesswidener b/src/main/resources/voxy.accesswidener index 454efdd1..5d3d403a 100644 --- a/src/main/resources/voxy.accesswidener +++ b/src/main/resources/voxy.accesswidener @@ -33,4 +33,6 @@ accessible class net/minecraft/client/world/ClientChunkManager$ClientChunkMap accessible method net/minecraft/client/world/ClientChunkManager$ClientChunkMap getChunk (I)Lnet/minecraft/world/chunk/WorldChunk; accessible method net/minecraft/client/world/ClientChunkManager$ClientChunkMap getIndex (II)I -accessible field net/minecraft/client/texture/SpriteAtlasTexture mipLevel I \ No newline at end of file +accessible field net/minecraft/client/texture/SpriteAtlasTexture mipLevel I + +accessible method net/minecraft/client/texture/MipmapHelper blend (IIIIZ)I \ No newline at end of file