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
10 changed files
with
241 additions
and
46 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ public void destroy() { | |
} | ||
|
||
if (this.voxels != null) { | ||
this.voxels.free(); | ||
// this.voxels.free(); | ||
} | ||
} | ||
|
||
|
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
7 changes: 7 additions & 0 deletions
7
.../src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/region/PendingDispatch.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,7 @@ | ||
package net.caffeinemc.mods.sodium.client.render.chunk.region; | ||
|
||
import net.caffeinemc.mods.sodium.client.gl.arena.GlBufferSegment; | ||
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSection; | ||
|
||
public record PendingDispatch(int frame, GlBufferSegment segment, RenderSection section) { | ||
} |
42 changes: 42 additions & 0 deletions
42
...in/java/net/caffeinemc/mods/sodium/client/render/chunk/region/PersistentBufferObject.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.region; | ||
|
||
import it.unimi.dsi.fastutil.longs.Long2LongFunction; | ||
import org.lwjgl.opengl.GL46C; | ||
|
||
public class PersistentBufferObject { | ||
public int frameId; | ||
public int bufferId; | ||
public long size; | ||
private long mapLocation; | ||
|
||
public PersistentBufferObject(long size) { | ||
bufferId = GL46C.glCreateBuffers(); | ||
this.size = size; | ||
if (size == 0) return; | ||
|
||
GL46C.glNamedBufferStorage(bufferId, size * 3, GL46C.GL_MAP_WRITE_BIT | GL46C.GL_MAP_PERSISTENT_BIT); | ||
mapLocation = GL46C.nglMapNamedBufferRange(bufferId, 0, size * 3, GL46C.GL_MAP_WRITE_BIT | GL46C.GL_MAP_FLUSH_EXPLICIT_BIT | GL46C.GL_MAP_PERSISTENT_BIT); | ||
} | ||
|
||
public void beginFrame() { | ||
frameId = (frameId + 1) % 3; | ||
} | ||
|
||
public void updateAndFlush(Long2LongFunction updater) { | ||
if (size == 0) return; | ||
|
||
long usedSize = updater.applyAsLong(mapLocation + (size * frameId)); | ||
|
||
GL46C.glFlushMappedNamedBufferRange(bufferId, size * frameId, usedSize); | ||
} | ||
|
||
public void bind() { | ||
if (size == 0) return; | ||
GL46C.glBindBufferRange(GL46C.GL_UNIFORM_BUFFER, 9, bufferId, size * frameId, size); | ||
} | ||
|
||
public void close() { | ||
GL46C.glUnmapNamedBuffer(bufferId); | ||
GL46C.glDeleteBuffers(bufferId); | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/region/VoxelCompute.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,47 @@ | ||
package net.caffeinemc.mods.sodium.client.render.chunk.region; | ||
|
||
import com.mojang.blaze3d.platform.GlStateManager; | ||
import org.apache.commons.io.IOUtils; | ||
import org.lwjgl.opengl.GL20C; | ||
import org.lwjgl.opengl.GL46C; | ||
|
||
import java.io.IOException; | ||
|
||
public class VoxelCompute { | ||
private static int compute; | ||
|
||
static { | ||
compute = GL46C.glCreateProgram(); | ||
int shader = GL46C.glCreateShader(GL46C.GL_COMPUTE_SHADER); | ||
try { | ||
GlStateManager.glShaderSource(shader, IOUtils.toString(VoxelCompute.class.getResourceAsStream("/voxel.csh"))); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
GL46C.glCompileShader(shader); | ||
GL46C.glAttachShader(compute, shader); | ||
GL46C.glLinkProgram(compute); | ||
|
||
String log = GlStateManager.glGetProgramInfoLog(compute, 16384); | ||
|
||
if (!log.isEmpty()) { | ||
System.out.println("Program link log for voxel: " + log); | ||
|
||
} | ||
int result = GlStateManager.glGetProgrami(compute, GL20C.GL_LINK_STATUS); | ||
|
||
if (result != GL20C.GL_TRUE) { | ||
throw new RuntimeException(log); | ||
} | ||
|
||
GL46C.glDetachShader(compute, shader); | ||
GL46C.glDeleteShader(shader); | ||
} | ||
|
||
public static void run(int size, PersistentBufferObject ubo) { | ||
if (size == 0) return; | ||
ubo.bind(); | ||
GL46C.glUseProgram(compute); | ||
GL46C.glDispatchCompute(size, 1, 1); | ||
} | ||
} |
Oops, something went wrong.