forked from CaffeineMC/sodium
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
295 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...n/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/PersistentVoxelBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package net.caffeinemc.mods.sodium.client.render.chunk; | ||
|
||
import org.lwjgl.opengl.GL46C; | ||
import org.lwjgl.system.MemoryUtil; | ||
|
||
public class PersistentVoxelBuffer { | ||
private final int id; | ||
private final long capacity; | ||
private long mapping; | ||
private boolean flushIfNeeded; | ||
private long minRange = Long.MAX_VALUE, maxRange = Long.MIN_VALUE; | ||
|
||
public PersistentVoxelBuffer(long capacity) { | ||
this.id = GL46C.glCreateBuffers(); | ||
this.capacity = capacity; | ||
|
||
GL46C.glNamedBufferStorage(id, capacity, GL46C.GL_MAP_WRITE_BIT | GL46C.GL_MAP_PERSISTENT_BIT); | ||
|
||
mapping = GL46C.nglMapNamedBufferRange(id, 0, capacity, GL46C.GL_MAP_WRITE_BIT | GL46C.GL_MAP_FLUSH_EXPLICIT_BIT | GL46C.GL_MAP_PERSISTENT_BIT); | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void write(long offset, int id) { | ||
flushIfNeeded = true; | ||
minRange = Math.min(minRange, offset); | ||
maxRange = Math.max(maxRange, offset + 4); | ||
MemoryUtil.memPutInt(mapping + offset, id); | ||
} | ||
|
||
public void flush() { | ||
if (flushIfNeeded) { | ||
GL46C.glFlushMappedNamedBufferRange(id, minRange, maxRange - minRange); | ||
|
||
minRange = Long.MAX_VALUE; | ||
maxRange = Long.MIN_VALUE; | ||
flushIfNeeded = false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...c/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/tasks/VoxelBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net.caffeinemc.mods.sodium.client.render.chunk.compile.tasks; | ||
|
||
import net.caffeinemc.mods.sodium.client.util.NativeBuffer; | ||
import org.lwjgl.system.MemoryUtil; | ||
|
||
public class VoxelBuffer { | ||
private final NativeBuffer buffer; | ||
|
||
public static final int VOXEL_SIZE = 8; | ||
|
||
public VoxelBuffer() { | ||
buffer = new NativeBuffer((16 * 16 * 16) * VOXEL_SIZE); | ||
} | ||
|
||
public void write(int x, int y, int z, int id, int light) { | ||
long index = this.buffer.getPointer() + (x + y * 16L + z * 16L * 16L); | ||
MemoryUtil.memPutInt(index, id); | ||
MemoryUtil.memPutInt(index + 4, light); | ||
} | ||
|
||
public NativeBuffer getBuffer() { | ||
return buffer; | ||
} | ||
|
||
public void delete() { | ||
buffer.free(); | ||
} | ||
} |
Oops, something went wrong.