small cleanup

This commit is contained in:
mcrcortex
2025-10-07 13:39:02 +10:00
parent 34caf07d8c
commit e2beabe2d3
5 changed files with 2 additions and 206 deletions

View File

@@ -137,7 +137,6 @@ public class TextureUtils {
//NOTE: data goes from bottom left to top right (x first then y)
public static int[] computeBounds(ColourDepthTextureData data, int checkMode) {
final var depth = data.depth();
//Compute x bounds first
int minX = 0;
minXCheck:

View File

@@ -11,11 +11,12 @@ import org.lwjgl.system.MemoryUtil;
import java.util.function.Consumer;
import static me.cortex.voxy.client.core.rendering.section.geometry.BasicSectionGeometryManager.SECTION_METADATA_SIZE;
//Is basicly the manager for an "undefined" data store, the underlying store is irrelevant
// this manager serves as an overlay, that is, it allows an implementation to do "async management" of the data store
public class BasicAsyncGeometryManager implements IGeometryManager {
public static final int SECTION_METADATA_SIZE = 32;
private static final long GEOMETRY_ELEMENT_SIZE = 8;
private final HierarchicalBitSet allocationSet;
private final AllocationArena allocationHeap = new AllocationArena();

View File

@@ -1,94 +0,0 @@
package me.cortex.voxy.client.core.rendering.util;
import me.cortex.voxy.client.core.gl.GlBuffer;
import me.cortex.voxy.client.core.gl.shader.Shader;
import me.cortex.voxy.client.core.gl.shader.ShaderType;
import org.lwjgl.system.MemoryUtil;
import java.util.function.Supplier;
import static org.lwjgl.opengl.GL20.glUniform1i;
import static org.lwjgl.opengl.GL30.glBindBufferBase;
import static org.lwjgl.opengl.GL43.GL_SHADER_STORAGE_BUFFER;
import static org.lwjgl.opengl.GL43C.glDispatchCompute;
//Utilities for common operations not suited for basic gl functions
// such as sparse memory setting
//TODO CLEAN THIS SHIT UP
public class ComputeUtils {
private ComputeUtils() {}
public static ComputeUtils INSTANCE = new ComputeUtils();
private static final int SETTING_BUFFER_BINDING = 1;
private static final int ENTRY_BUFFER_BINDING = 2;
//TODO: FIXME! This should itself be just a raw streaming buffer/mapped ptr (probably)
private final GlBuffer SCRATCH = new GlBuffer(1<<20);//1 MB scratch buffer... this should be enough.. right?
private int maxCount;
private int count;
private long ptr;
private final Supplier<Shader> uintSetShader = makeCacheSetShader("uint");
public void prepSetUint(int maxCount) {
if (this.count != 0 || this.maxCount != 0 || this.ptr != 0) {
throw new IllegalStateException();
}
this.ptr = UploadStream.INSTANCE.upload(SCRATCH, 0, maxCount*8L);
this.maxCount = maxCount;
}
public void pushSetUint(int index, int value) {
//For uint it goes
// {uint value; uint index;}
if (this.maxCount <= this.count++) {
throw new IllegalStateException("Pushed to many values to prepared set");
}
MemoryUtil.memPutInt(this.ptr, value); this.ptr += 4;
MemoryUtil.memPutInt(this.ptr, index); this.ptr += 4;
}
public void finishSetUint(GlBuffer dst) {
UploadStream.INSTANCE.commit();
this.uintSetShader.get().bind();
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, SETTING_BUFFER_BINDING, dst.id);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, ENTRY_BUFFER_BINDING, this.SCRATCH.id);
glUniform1i(0, this.count);
glDispatchCompute((this.count+127)/128, 1, 1);
this.ptr = 0;
this.maxCount = 0;
this.count = 0;
}
private static Supplier<Shader> makeCacheSetShader(String type) {
return makeAndCache(()->makeSetShader(type));
}
private static Shader makeSetShader(String type) {
return Shader.make()
.define("TYPE", type)
.define("SETTING_BUFFER_BINDING", SETTING_BUFFER_BINDING)
.define("ENTRY_BUFFER_BINDING", ENTRY_BUFFER_BINDING)
.add(ShaderType.COMPUTE, "voxy:util/set.comp")
.compile();
}
private static <T> Supplier<T> makeAndCache(Supplier<T> maker) {
Object[] value = new Object[1];
boolean[] hasSet = new boolean[1];
return ()->{
if (hasSet[0]) {
return (T) value[0];
} else {
var val = maker.get();
hasSet[0] = true;
value[0] = val;
return val;
}
};
}
}

View File

@@ -1,25 +0,0 @@
package me.cortex.voxy.client.core.rendering.util;
import me.cortex.voxy.client.core.gl.GlBuffer;
import me.cortex.voxy.common.util.UnsafeUtil;
import org.lwjgl.system.MemoryUtil;
//Just a utility for making a deferred upload (make on other thread then upload on render thread)
public final class DeferredUpload {
public final long ptr;
private final long size;
private final long offset;
private final GlBuffer buffer;
public DeferredUpload(GlBuffer buffer, long offset, long size) {
this.ptr = MemoryUtil.nmemAlloc(size);
this.offset = offset;
this.buffer = buffer;
this.size = size;
}
public void upload() {
long upPtr = UploadStream.INSTANCE.upload(this.buffer, this.offset, this.size);
UnsafeUtil.memcpy(this.ptr, upPtr, this.size);
MemoryUtil.nmemFree(this.ptr);
}
}

View File

@@ -1,85 +0,0 @@
package me.cortex.voxy.client.core.rendering.util;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL13.GL_ACTIVE_TEXTURE;
import static org.lwjgl.opengl.GL13.glActiveTexture;
public class GlStateCapture {
private final int[] capabilityIds;
private final boolean[] enabledCaps;
private final int[] textureUnits;
private final int[] textures;
private GlStateCapture(int[] caps, int[] textureUnits) {
this.capabilityIds = caps;
this.enabledCaps = new boolean[caps.length];
this.textureUnits = textureUnits;
this.textures = new int[textureUnits.length];
}
public void capture() {
this.textureUnits[0] = glGetInteger(GL_ACTIVE_TEXTURE);
//Capture all the texture data
for (int i = 0; i < this.textures.length; i++) {
glActiveTexture(this.textureUnits[i]);
this.textures[i] = glGetInteger(GL_TEXTURE_BINDING_2D);
}
//Reset the original active texture
glActiveTexture(this.textureUnits[0]);
for (int i = 0; i < this.capabilityIds.length; i++) {
this.enabledCaps[i] = glIsEnabled(this.capabilityIds[i]);
}
}
public void restore() {
//Capture all the texture data
for (int i = 1; i < this.textures.length; i++) {
glActiveTexture(this.textureUnits[i]);
//glBindSampler(this.textureUnits[i]-GL_TEXTURE0, 0);
glBindTexture(GL_TEXTURE_2D, this.textures[i]);
}
//Reset the original active texture
glActiveTexture(this.textureUnits[0]);
glBindTexture(GL_TEXTURE_2D, this.textures[0]);
for (int i = 0; i < this.capabilityIds.length; i++) {
if (this.enabledCaps[i]) {
glEnable(this.capabilityIds[i]);
} else {
glDisable(this.capabilityIds[i]);
}
}
}
public static Builder make() {
return new Builder();
}
public static class Builder {
private final IntArrayList caps = new IntArrayList();
private final IntArrayList textures = new IntArrayList();
private Builder() {
this.addTexture(-1);//Special texture unit, used to capture the current texture unit
}
public Builder addCapability(int cap) {
this.caps.add(cap);
return this;
}
public Builder addTexture(int unit) {
this.textures.add(unit);
return this;
}
public GlStateCapture build() {
return new GlStateCapture(this.caps.toIntArray(), this.textures.toIntArray());
}
}
}