Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More updating #18

Open
wants to merge 38 commits into
base: compat_next_1_16_4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8f506df
new: Initial "thin GL" implementation
jellysquid3 Apr 12, 2021
7ca45ad
change: Deprecate legacy OpenGL, update usages to Core classes
jellysquid3 Apr 16, 2021
346e224
change: Replace legacy projection matrix capturing code
jellysquid3 Apr 16, 2021
6f1762f
fix: Try and make config saving more durable
jellysquid3 May 9, 2021
67da26b
fix: Mark tripwire as translucent so that it is rendered back-to-fron…
coderbot16 May 9, 2021
35995f7
fix: Use correct Modrinth link (#622)
May 9, 2021
0d74b67
change: Bump dependency versions are target Minecraft 1.16.5
jellysquid3 May 9, 2021
8d88e83
fix: Prevent slider thumb from rendering outside of slider area
bytzo Feb 27, 2021
8582920
fix: Remove offset from mouse when setting value of slider control
bytzo Feb 28, 2021
7e2366b
fix: Allow controls to reset themselves when modified options are undone
bytzo Mar 4, 2021
653a3e9
change: Remove resettable interface
bytzo Mar 5, 2021
446a6cc
fix: Compare current and modified option values using equals()
bytzo Mar 5, 2021
0d6af7e
fix: Prevent hidden button widgets from being pressed
bytzo Apr 7, 2021
e206e86
fix: Change spelling of "visibel" to "visible"
bytzo Apr 7, 2021
9fbf07a
fix: Allow for more precise widget rendering
bytzo Apr 9, 2021
f4d0820
change: Move chunk copying into meshing threads
jellysquid3 May 27, 2021
04d07b8
Merge branch '1.16.x/thingl' into 1.16.x/next
jellysquid3 Jun 5, 2021
d87da3c
Bump version to 0.2.0
jellysquid3 Jun 5, 2021
4046bbd
fix: Increase WorldSlice neighbor radius to match vanilla
comp500 Mar 14, 2021
972c7c1
new: Add version information to F3, closes #598
jellysquid3 Jun 5, 2021
a0f651c
fix: Send chunk unload events when load distance changes
jellysquid3 Jun 8, 2021
1b9f003
fix: Use client render distance to cull chunks
jellysquid3 Jun 8, 2021
56dc005
fix: Use correct blended biome array size
jellysquid3 Jun 8, 2021
e578bdf
merge: Resolve conflicts with #672
jellysquid3 Jun 8, 2021
35552d3
change: Client render distance only affects X/Z axis
jellysquid3 Jun 8, 2021
f5d30ef
new: Add a donation button in the settings screen
jellysquid3 Jun 11, 2021
6dabc68
change: Adjust margins in options screen
jellysquid3 Jun 11, 2021
cfea306
change: Adjust advanced optimization settings
jellysquid3 Jun 11, 2021
76d7b3c
change: Change "Chunk Face Culling" to "Block Face Culling"
jellysquid3 Jun 11, 2021
62935a4
fix: Use provided config path
Leo40Git Jun 11, 2021
4049ebd
fix: Disable multi-draw option again if using an unsupported driver
jellysquid3 Jun 12, 2021
4ae0452
fix: Track chunk map re-centering more carefully
jellysquid3 Jun 12, 2021
d43017e
fix: Off-by-one error when checking the destination buffer's length i…
jellysquid3 Jun 12, 2021
d7fbb5f
fix: Reload renderer on view distance change automatically
jellysquid3 Jun 12, 2021
82c76d4
fix: Thread-safety problem in MultipartBakedModel
jellysquid3 Jun 15, 2021
c517524
change: Always reload the renderer when changing view distance
jellysquid3 Jun 17, 2021
53a5a2b
change: Tweak usage hints for multi-draw command buffer
jellysquid3 Jun 19, 2021
448932a
Curseforge now natively supports fabric
Aresiel Jun 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Fabric mods before, you can find a variety of community guides for doing so [her

![GitHub release](https://img.shields.io/github/release/CaffeineMC/sodium-fabric.svg)

The latest releases of Sodium are published to our [Modrinth](https://modrinth.com/mods/sodium) and
The latest releases of Sodium are published to our [Modrinth](https://modrinth.com/mod/sodium) and
[GitHub release](https://github.com/CaffeineMC/sodium-fabric/releases) pages. Releases are considered by our team to be
**suitable for general use**, but they are not guaranteed to be free of bugs and other issues.

Expand Down Expand Up @@ -54,11 +54,6 @@ If you are using the CurseForge client, you can continue to find downloads throu
[CurseForge page](https://www.curseforge.com/minecraft/mc-mods/sodium). Unless you are using the CurseForge
client, you should prefer the downloads linked on our Modrinth or GitHub release pages above.

The CurseForge client does not natively support Fabric modding, so you will need to install
[Jumploader](https://www.curseforge.com/minecraft/mc-mods/jumploader) in order to set up your Fabric environment. Due to
the extra complexity and startup overhead this workaround adds, we generally do not recommend using this method unless
you have an existing setup with it.

---

### Reporting Issues
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.16.4
yarn_mappings=1.16.4+build.1
loader_version=0.10.6+build.214
minecraft_version=1.16.5
yarn_mappings=1.16.5+build.9
loader_version=0.11.3

# Mod Properties
mod_version=0.1.1
mod_version=0.2.0
maven_group=me.jellysquid.mods
archives_base_name=sodium-fabric

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@
import me.jellysquid.mods.sodium.client.gui.SodiumGameOptions;
import me.jellysquid.mods.sodium.client.util.UnsafeUtil;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.nio.file.Paths;

public class SodiumClientMod implements ClientModInitializer {
private static SodiumGameOptions CONFIG;
private static Logger LOGGER;

private static String MOD_VERSION;

@Override
public void onInitializeClient() {
ModContainer mod = FabricLoader.getInstance()
.getModContainer("sodium")
.orElseThrow(NullPointerException::new);

MOD_VERSION = mod.getMetadata()
.getVersion()
.getFriendlyString();
}

public static SodiumGameOptions options() {
Expand All @@ -34,13 +44,21 @@ public static Logger logger() {
}

private static SodiumGameOptions loadConfig() {
SodiumGameOptions config = SodiumGameOptions.load(new File("config/sodium-options.json"));
SodiumGameOptions config = SodiumGameOptions.load(FabricLoader.getInstance().getConfigDir().resolve("sodium-options.json"));
onConfigChanged(config);

return config;
}

public static void onConfigChanged(SodiumGameOptions options) {
UnsafeUtil.setEnabled(options.advanced.useMemoryIntrinsics);
UnsafeUtil.setEnabled(options.advanced.allowDirectMemoryAccess);
}

public static String getVersion() {
if (MOD_VERSION == null) {
throw new NullPointerException("Mod version hasn't been populated yet");
}

return MOD_VERSION;
}
}
13 changes: 12 additions & 1 deletion src/main/java/me/jellysquid/mods/sodium/client/gl/GlObject.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.jellysquid.mods.sodium.client.gl;

import me.jellysquid.mods.sodium.client.gl.device.RenderDevice;

/**
* An abstract object used to represent objects in OpenGL code safely. This class hides the direct handle to a OpenGL
* object, requiring that it first be checked by all callers to prevent null pointer de-referencing. However, this will
Expand All @@ -9,8 +11,13 @@
public class GlObject {
private static final int INVALID_HANDLE = Integer.MIN_VALUE;

protected final RenderDevice device;
private int handle = INVALID_HANDLE;

public GlObject(RenderDevice owner) {
this.device = owner;
}

protected final void setHandle(int handle) {
this.handle = handle;
}
Expand All @@ -31,7 +38,11 @@ protected final boolean isHandleValid() {
return this.handle != INVALID_HANDLE;
}

protected final void invalidateHandle() {
public final void invalidateHandle() {
this.handle = INVALID_HANDLE;
}

public RenderDevice getDevice() {
return this.device;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,128 +2,98 @@

import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
import me.jellysquid.mods.sodium.client.gl.buffer.GlBuffer;
import me.jellysquid.mods.sodium.client.gl.buffer.GlBufferTarget;
import me.jellysquid.mods.sodium.client.gl.buffer.GlBufferUsage;
import me.jellysquid.mods.sodium.client.gl.buffer.GlMutableBuffer;
import me.jellysquid.mods.sodium.client.gl.util.MemoryTracker;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL31;
import org.lwjgl.opengl.GL33;
import me.jellysquid.mods.sodium.client.gl.device.CommandList;
import me.jellysquid.mods.sodium.client.gl.device.RenderDevice;

import java.util.Set;

public class GlBufferArena {
private static final GlBufferUsage BUFFER_USAGE = GlBufferUsage.GL_DYNAMIC_DRAW;

private final RenderDevice device;
private final int resizeIncrement;

private final MemoryTracker memoryTracker;
private final Set<GlBufferRegion> freeRegions = new ObjectLinkedOpenHashSet<>();
private final Set<GlBufferSegment> freeRegions = new ObjectLinkedOpenHashSet<>();

private GlBuffer vertexBuffer;
private boolean isBufferBound;
private GlMutableBuffer vertexBuffer;

private int position;
private int capacity;
private int allocCount;
private int usedBytes;

public GlBufferArena(MemoryTracker memoryTracker, int initialSize, int resizeIncrement) {
this.memoryTracker = memoryTracker;

this.vertexBuffer = this.createBuffer();
this.vertexBuffer.bind(GL31.GL_COPY_WRITE_BUFFER);
this.vertexBuffer.allocate(GL31.GL_COPY_WRITE_BUFFER, initialSize);
this.vertexBuffer.unbind(GL31.GL_COPY_WRITE_BUFFER);
public GlBufferArena(RenderDevice device, int initialSize, int resizeIncrement) {
this.device = device;

this.memoryTracker.onMemoryAllocate(this.vertexBuffer.getSize());
try (CommandList commands = device.createCommandList()) {
this.vertexBuffer = commands.createMutableBuffer(BUFFER_USAGE);
commands.allocateBuffer(GlBufferTarget.COPY_WRITE_BUFFER, this.vertexBuffer, initialSize);
}

this.resizeIncrement = resizeIncrement;
this.capacity = initialSize;
}

private void resize(int size) {
this.memoryTracker.onMemoryRelease(this.vertexBuffer.getSize());

GlBuffer src = this.vertexBuffer;
src.unbind(GL31.GL_COPY_WRITE_BUFFER);

GlBuffer dst = this.createBuffer();

GlBuffer.copy(src, dst, 0, 0, this.capacity, size);
src.delete();
private void resize(CommandList commandList, int newCapacity) {
GlMutableBuffer src = this.vertexBuffer;
GlMutableBuffer dst = commandList.createMutableBuffer(BUFFER_USAGE);

dst.bind(GL31.GL_COPY_WRITE_BUFFER);
commandList.allocateBuffer(GlBufferTarget.COPY_WRITE_BUFFER, dst, newCapacity);
commandList.copyBufferSubData(src, dst, 0, 0, this.position);
commandList.deleteBuffer(src);

this.vertexBuffer = dst;
this.capacity = size;

this.memoryTracker.onMemoryAllocate(this.vertexBuffer.getSize());
}

private GlBuffer createBuffer() {
return new GlMutableBuffer(GL15.GL_DYNAMIC_DRAW);
}

public void bind() {
this.vertexBuffer.bind(GL31.GL_COPY_WRITE_BUFFER);
this.isBufferBound = true;
this.capacity = newCapacity;
}

public void ensureCapacity(int len) {
if (this.position + len >= this.capacity) {
this.resize(this.getNextSize(len));
public void prepareBuffer(CommandList commandList, int bytes) {
if (this.position + bytes >= this.capacity) {
this.resize(commandList, this.getNextSize(bytes));
}
}

public GlBufferRegion upload(int readTarget, int offset, int len) {
this.checkBufferBound();
this.ensureCapacity(len);
public GlBufferSegment uploadBuffer(CommandList commandList, GlBuffer readBuffer, int readOffset, int byteCount) {
this.prepareBuffer(commandList, byteCount);

GlBufferRegion segment = this.alloc(len);
GL33.glCopyBufferSubData(readTarget, GL31.GL_COPY_WRITE_BUFFER, offset, segment.getStart(), len);
GlBufferSegment segment = this.alloc(byteCount);

return segment;
}

public void unbind() {
this.checkBufferBound();
commandList.copyBufferSubData(readBuffer, this.vertexBuffer, readOffset, segment.getStart(), byteCount);

this.vertexBuffer.unbind(GL31.GL_COPY_WRITE_BUFFER);
this.isBufferBound = false;
return segment;
}

private int getNextSize(int len) {
return Math.max(this.capacity + this.resizeIncrement, this.capacity + len);
}

public void free(GlBufferRegion segment) {
public void free(GlBufferSegment segment) {
if (!this.freeRegions.add(segment)) {
throw new IllegalArgumentException("Segment already freed");
}

this.memoryTracker.onMemoryFree(segment.getLength());
this.allocCount--;
this.usedBytes -= segment.getLength();
}

private GlBufferRegion alloc(int len) {
GlBufferRegion segment = this.allocReuse(len);
private GlBufferSegment alloc(int len) {
GlBufferSegment segment = this.allocReuse(len);

if (segment == null) {
segment = new GlBufferRegion(this, this.position, len);
segment = new GlBufferSegment(this, this.position, len);

this.position += len;
}

this.allocCount++;
this.usedBytes += segment.getLength();

this.memoryTracker.onMemoryUse(segment.getLength());

return segment;
}

private GlBufferRegion allocReuse(int len) {
GlBufferRegion bestSegment = null;
private GlBufferSegment allocReuse(int len) {
GlBufferSegment bestSegment = null;

for (GlBufferRegion segment : this.freeRegions) {
for (GlBufferSegment segment : this.freeRegions) {
if (segment.getLength() < len) {
continue;
}
Expand All @@ -142,17 +112,16 @@ private GlBufferRegion allocReuse(int len) {
int excess = bestSegment.getLength() - len;

if (excess > 0) {
this.freeRegions.add(new GlBufferRegion(this, bestSegment.getStart() + len, excess));
this.freeRegions.add(new GlBufferSegment(this, bestSegment.getStart() + len, excess));
}

return new GlBufferRegion(this, bestSegment.getStart(), len);
return new GlBufferSegment(this, bestSegment.getStart(), len);
}

public void delete() {
this.memoryTracker.onMemoryFree(this.usedBytes);
this.memoryTracker.onMemoryRelease(this.vertexBuffer.getSize());

this.vertexBuffer.delete();
try (CommandList commands = this.device.createCommandList()) {
commands.deleteBuffer(this.vertexBuffer);
}
}

public boolean isEmpty() {
Expand All @@ -162,10 +131,4 @@ public boolean isEmpty() {
public GlBuffer getBuffer() {
return this.vertexBuffer;
}

private void checkBufferBound() {
if (!this.isBufferBound) {
throw new IllegalStateException("Buffer is not bound");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package me.jellysquid.mods.sodium.client.gl.arena;

public class GlBufferRegion {
public class GlBufferSegment {
private final GlBufferArena arena;
private final int start;
private final int len;

GlBufferRegion(GlBufferArena arena, int start, int len) {
GlBufferSegment(GlBufferArena arena, int start, int len) {
this.arena = arena;
this.start = start;
this.len = len;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,21 @@

import me.jellysquid.mods.sodium.client.gl.GlObject;
import me.jellysquid.mods.sodium.client.gl.func.GlFunctions;
import me.jellysquid.mods.sodium.client.gl.device.RenderDevice;

/**
* Provides Vertex Array functionality on supported platforms.
*/
public class GlVertexArray extends GlObject {
public GlVertexArray() {
public static final int NULL_ARRAY_ID = 0;

public GlVertexArray(RenderDevice owner) {
super(owner);

if (!GlFunctions.isVertexArraySupported()) {
throw new UnsupportedOperationException("Vertex arrays are unsupported on this platform");
}

this.setHandle(GlFunctions.VERTEX_ARRAY.glGenVertexArrays());
}

public void unbind() {
GlFunctions.VERTEX_ARRAY.glBindVertexArray(0);
}

public void bind() {
GlFunctions.VERTEX_ARRAY.glBindVertexArray(this.handle());
}

public void delete() {
GlFunctions.VERTEX_ARRAY.glDeleteVertexArrays(this.handle());

this.invalidateHandle();
}

}
Loading