Bilinear interpolation for quad vertex data via geometry shader #12
No files matched your search
-22
@@ -25,7 +25,6 @@ import java.util.Collection;
|
|||||||
|
|
||||||
public class PrimitiveRenderSectionManager extends RenderSectionManager {
|
public class PrimitiveRenderSectionManager extends RenderSectionManager {
|
||||||
private final World world;
|
private final World world;
|
||||||
private final ReferenceSet<RenderSection> sectionsWithGlobalEntities = new ReferenceOpenHashSet<>();
|
|
||||||
|
|
||||||
public PrimitiveRenderSectionManager(RenderPassConfiguration<?> configuration, World world, int renderDistance, CommandList commandList, int minSection, int maxSection, int requestedThreads) {
|
public PrimitiveRenderSectionManager(RenderPassConfiguration<?> configuration, World world, int renderDistance, CommandList commandList, int minSection, int maxSection, int requestedThreads) {
|
||||||
super(configuration, () -> new PrimitiveChunkBuildContext(world, configuration), DefaultChunkRenderer::new, renderDistance, commandList, minSection, maxSection, requestedThreads);
|
super(configuration, () -> new PrimitiveChunkBuildContext(world, configuration), DefaultChunkRenderer::new, renderDistance, commandList, minSection, maxSection, requestedThreads);
|
||||||
@@ -83,25 +82,4 @@ public class PrimitiveRenderSectionManager extends RenderSectionManager {
|
|||||||
protected boolean allowImportantRebuilds() {
|
protected boolean allowImportantRebuilds() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateSectionInfo(RenderSection render, BuiltRenderSectionData info) {
|
|
||||||
super.updateSectionInfo(render, info);
|
|
||||||
|
|
||||||
if (info == null || (info instanceof MinecraftBuiltRenderSectionData<?, ?> mcInfo) && mcInfo.globalBlockEntities.isEmpty()) {
|
|
||||||
this.sectionsWithGlobalEntities.remove(render);
|
|
||||||
} else {
|
|
||||||
this.sectionsWithGlobalEntities.add(render);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() {
|
|
||||||
super.destroy();
|
|
||||||
this.sectionsWithGlobalEntities.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<RenderSection> getSectionsWithGlobalEntities() {
|
|
||||||
return ReferenceSets.unmodifiable(this.sectionsWithGlobalEntities);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,6 @@ dependencies {
|
|||||||
compileOnly "org.jetbrains:annotations:24.1.0"
|
compileOnly "org.jetbrains:annotations:24.1.0"
|
||||||
compileOnly("org.projectlombok:lombok:1.18.30")
|
compileOnly("org.projectlombok:lombok:1.18.30")
|
||||||
annotationProcessor("org.projectlombok:lombok:1.18.30")
|
annotationProcessor("org.projectlombok:lombok:1.18.30")
|
||||||
compileOnly("com.google.guava:guava:31.1-jre")
|
|
||||||
compileOnly("org.ow2.asm:asm:9.6")
|
compileOnly("org.ow2.asm:asm:9.6")
|
||||||
compileOnly("org.ow2.asm:asm-tree:9.6")
|
compileOnly("org.ow2.asm:asm-tree:9.6")
|
||||||
compileOnly("org.ow2.asm:asm-util:9.6")
|
compileOnly("org.ow2.asm:asm-util:9.6")
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.embeddedt.embeddium.impl.asm;
|
package org.embeddedt.embeddium.impl.asm;
|
||||||
|
|
||||||
import com.google.common.base.Suppliers;
|
|
||||||
import org.objectweb.asm.*;
|
import org.objectweb.asm.*;
|
||||||
import org.objectweb.asm.util.CheckClassAdapter;
|
import org.objectweb.asm.util.CheckClassAdapter;
|
||||||
|
|
||||||
@@ -10,11 +9,14 @@ import java.lang.invoke.MethodType;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class ProxyClassGenerator<DELEGATE, INTERFACE> {
|
public class ProxyClassGenerator<DELEGATE, INTERFACE> {
|
||||||
// DEFINE_CLASS is borrowed from FerriteCore under MIT as a small utility
|
private static Definer DEFINER;
|
||||||
private static final Supplier<Definer> DEFINE_CLASS = Suppliers.memoize(() -> {
|
|
||||||
|
private static synchronized Definer getDefiner() {
|
||||||
|
if (DEFINER != null) {
|
||||||
|
return DEFINER;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// Try to create a Java 9+ style class definer
|
// Try to create a Java 9+ style class definer
|
||||||
// These are all public methods, but just don't exist in Java 8
|
// These are all public methods, but just don't exist in Java 8
|
||||||
@@ -23,7 +25,7 @@ public class ProxyClassGenerator<DELEGATE, INTERFACE> {
|
|||||||
);
|
);
|
||||||
Object privateLookup = makePrivateLookup.invoke(null, ProxyClassGenerator.class, MethodHandles.lookup());
|
Object privateLookup = makePrivateLookup.invoke(null, ProxyClassGenerator.class, MethodHandles.lookup());
|
||||||
Method defineClass = MethodHandles.Lookup.class.getMethod("defineClass", byte[].class);
|
Method defineClass = MethodHandles.Lookup.class.getMethod("defineClass", byte[].class);
|
||||||
return (bytes, name) -> (Class<?>) defineClass.invoke(privateLookup, (Object) bytes);
|
DEFINER = (bytes, name) -> (Class<?>) defineClass.invoke(privateLookup, (Object) bytes);
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
try {
|
try {
|
||||||
// If that fails, try a Java 8 style definer
|
// If that fails, try a Java 8 style definer
|
||||||
@@ -32,13 +34,14 @@ public class ProxyClassGenerator<DELEGATE, INTERFACE> {
|
|||||||
);
|
);
|
||||||
defineClass.setAccessible(true);
|
defineClass.setAccessible(true);
|
||||||
ClassLoader loader = ProxyClassGenerator.class.getClassLoader();
|
ClassLoader loader = ProxyClassGenerator.class.getClassLoader();
|
||||||
return (bytes, name) -> (Class<?>) defineClass.invoke(loader, name, bytes, 0, bytes.length);
|
DEFINER = (bytes, name) -> (Class<?>) defineClass.invoke(loader, name, bytes, 0, bytes.length);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
// Fail if neither works
|
// Fail if neither works
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
return DEFINER;
|
||||||
|
}
|
||||||
|
|
||||||
private final Class<?> delegateClass;
|
private final Class<?> delegateClass;
|
||||||
private final Class<?> proxyClass;
|
private final Class<?> proxyClass;
|
||||||
@@ -145,7 +148,7 @@ public class ProxyClassGenerator<DELEGATE, INTERFACE> {
|
|||||||
private Class<?> createWrapperClass() {
|
private Class<?> createWrapperClass() {
|
||||||
byte[] bytes = createWrapperClassBytecode();
|
byte[] bytes = createWrapperClassBytecode();
|
||||||
try {
|
try {
|
||||||
return DEFINE_CLASS.get().define(bytes, this.proxyClassName.replace('/', '.'));
|
return getDefiner().define(bytes, this.proxyClassName.replace('/', '.'));
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new RuntimeException("Error defining WorldSlice wrapper", e);
|
throw new RuntimeException("Error defining WorldSlice wrapper", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package org.embeddedt.embeddium.impl.common.util;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class TimeUtil {
|
||||||
|
private static final TimeUnit[] UNITS = TimeUnit.values();
|
||||||
|
|
||||||
|
private static TimeUnit chooseUnit(long duration, TimeUnit unit) {
|
||||||
|
for (int i = UNITS.length - 1; i > unit.ordinal(); i--) {
|
||||||
|
if (UNITS[i].convert(duration, unit) > 0) {
|
||||||
|
return UNITS[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String abbreviateTime(TimeUnit unit) {
|
||||||
|
return switch (unit) {
|
||||||
|
case NANOSECONDS -> "ns";
|
||||||
|
case MICROSECONDS -> "us";
|
||||||
|
case MILLISECONDS -> "ms";
|
||||||
|
case SECONDS -> "s";
|
||||||
|
case MINUTES -> "min";
|
||||||
|
case HOURS -> "h";
|
||||||
|
case DAYS -> "d";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String stringifyTime(long duration, TimeUnit unit) {
|
||||||
|
return stringifyTime(duration, unit, chooseUnit(duration, unit));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String stringifyTime(long duration, TimeUnit unit, TimeUnit displayUnit) {
|
||||||
|
double displayDuration = ((double)duration) / unit.convert(1, displayUnit);
|
||||||
|
return String.format(Locale.ROOT, "%.4g %s", displayDuration, abbreviateTime(displayUnit));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package org.embeddedt.embeddium.impl.gl.profiling;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayFIFOQueue;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.lwjgl.opengl.GL32C;
|
||||||
|
import org.lwjgl.opengl.GL33C;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
|
||||||
|
public class TimerQueryManager implements Closeable {
|
||||||
|
private static final int INVALID_ID = -1;
|
||||||
|
/**
|
||||||
|
* The number of frames the timer query manager should wait before reading the data from the GPU.
|
||||||
|
*/
|
||||||
|
private static final int QUERY_FRAME_LAG_COUNT = 3;
|
||||||
|
|
||||||
|
private record InFlightQuery(int startTime, int endTime) {
|
||||||
|
long getTimeDelta() {
|
||||||
|
long startTime = GL33C.glGetQueryObjectui64(this.startTime, GL32C.GL_QUERY_RESULT);
|
||||||
|
long endTime = GL33C.glGetQueryObjectui64(this.endTime, GL32C.GL_QUERY_RESULT);
|
||||||
|
return endTime - startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void delete() {
|
||||||
|
GL32C.glDeleteQueries(startTime);
|
||||||
|
GL32C.glDeleteQueries(endTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ObjectArrayFIFOQueue<InFlightQuery> inFlightQueries = new ObjectArrayFIFOQueue<>();
|
||||||
|
private int startQueryId = INVALID_ID;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private long lastTime;
|
||||||
|
|
||||||
|
public void startProfiling() {
|
||||||
|
if (startQueryId != INVALID_ID) {
|
||||||
|
throw new IllegalStateException("Query already started but not ended");
|
||||||
|
}
|
||||||
|
int id = GL32C.glGenQueries();
|
||||||
|
GL33C.glQueryCounter(id, GL33C.GL_TIMESTAMP);
|
||||||
|
startQueryId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void finishProfiling() {
|
||||||
|
if (startQueryId == INVALID_ID) {
|
||||||
|
throw new IllegalStateException("Trying to end query that hasn't started yet");
|
||||||
|
}
|
||||||
|
int id = GL32C.glGenQueries();
|
||||||
|
GL33C.glQueryCounter(id, GL33C.GL_TIMESTAMP);
|
||||||
|
inFlightQueries.enqueue(new InFlightQuery(startQueryId, id));
|
||||||
|
startQueryId = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTime() {
|
||||||
|
if (inFlightQueries.size() < QUERY_FRAME_LAG_COUNT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var query = inFlightQueries.dequeue();
|
||||||
|
lastTime = query.getTimeDelta();
|
||||||
|
query.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
while (!inFlightQueries.isEmpty()) {
|
||||||
|
inFlightQueries.dequeue().delete();
|
||||||
|
}
|
||||||
|
if (startQueryId != -1) {
|
||||||
|
GL32C.glDeleteQueries(startQueryId);
|
||||||
|
startQueryId = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
-4
@@ -1,11 +1,29 @@
|
|||||||
package org.embeddedt.embeddium.impl.gl.tessellation;
|
package org.embeddedt.embeddium.impl.gl.tessellation;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL20C;
|
import org.lwjgl.opengl.GL11C;
|
||||||
import org.lwjgl.opengl.GL43C;
|
import org.lwjgl.opengl.GL32C;
|
||||||
|
import org.lwjgl.opengl.GL40C;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An enumeration over the supported OpenGL primitive types.
|
||||||
|
*/
|
||||||
public enum GlPrimitiveType {
|
public enum GlPrimitiveType {
|
||||||
TRIANGLES(GL20C.GL_TRIANGLES),
|
POINTS(GL11C.GL_POINTS),
|
||||||
PATCHES(GL43C.GL_PATCHES);
|
|
||||||
|
LINES(GL11C.GL_LINES),
|
||||||
|
LINE_STRIP(GL11C.GL_LINE_STRIP),
|
||||||
|
LINE_LOOP(GL11C.GL_LINE_LOOP),
|
||||||
|
|
||||||
|
TRIANGLES(GL11C.GL_TRIANGLES),
|
||||||
|
TRIANGLE_STRIP(GL11C.GL_TRIANGLE_STRIP),
|
||||||
|
TRIANGLE_FAN(GL11C.GL_TRIANGLE_FAN),
|
||||||
|
|
||||||
|
LINES_ADJACENCY(GL32C.GL_LINES_ADJACENCY),
|
||||||
|
LINE_STRIP_ADJACENCY(GL32C.GL_LINE_STRIP_ADJACENCY),
|
||||||
|
TRIANGLES_ADJACENCY(GL32C.GL_TRIANGLES_ADJACENCY),
|
||||||
|
TRIANGLE_STRIP_ADJACENCY(GL32C.GL_TRIANGLE_STRIP_ADJACENCY),
|
||||||
|
|
||||||
|
PATCHES(GL40C.GL_PATCHES);
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -11,19 +11,19 @@ import java.util.Objects;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public record RenderPassConfiguration<R>(ChunkVertexType vertexType,
|
public record RenderPassConfiguration<R>(Map<R, Material> chunkRenderTypeToMaterialMap,
|
||||||
Map<R, Material> chunkRenderTypeToMaterialMap,
|
|
||||||
Map<R, Collection<TerrainRenderPass>> vanillaRenderStages,
|
Map<R, Collection<TerrainRenderPass>> vanillaRenderStages,
|
||||||
Function<TerrainRenderPass, ChunkPrimitiveType> primitiveTypeGetter,
|
|
||||||
Material defaultSolidMaterial,
|
Material defaultSolidMaterial,
|
||||||
Material defaultCutoutMippedMaterial,
|
Material defaultCutoutMippedMaterial,
|
||||||
Material defaultTranslucentMaterial) {
|
Material defaultTranslucentMaterial) {
|
||||||
|
@Deprecated
|
||||||
public ChunkVertexType getVertexTypeForPass(TerrainRenderPass pass) {
|
public ChunkVertexType getVertexTypeForPass(TerrainRenderPass pass) {
|
||||||
return this.vertexType;
|
return pass.vertexType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public ChunkPrimitiveType getPrimitiveTypeForPass(TerrainRenderPass pass) {
|
public ChunkPrimitiveType getPrimitiveTypeForPass(TerrainRenderPass pass) {
|
||||||
return this.primitiveTypeGetter.apply(pass);
|
return pass.primitiveType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getMaterialForRenderType(Object type) {
|
public Material getMaterialForRenderType(Object type) {
|
||||||
|
|||||||
+64
-1
@@ -4,8 +4,10 @@ import it.unimi.dsi.fastutil.longs.Long2ReferenceMap;
|
|||||||
import it.unimi.dsi.fastutil.longs.Long2ReferenceOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ReferenceOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.objects.*;
|
import it.unimi.dsi.fastutil.objects.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.embeddedt.embeddium.impl.common.util.TimeUtil;
|
||||||
import org.embeddedt.embeddium.impl.gl.device.CommandList;
|
import org.embeddedt.embeddium.impl.gl.device.CommandList;
|
||||||
import org.embeddedt.embeddium.impl.gl.device.RenderDevice;
|
import org.embeddedt.embeddium.impl.gl.device.RenderDevice;
|
||||||
|
import org.embeddedt.embeddium.impl.gl.profiling.TimerQueryManager;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildContext;
|
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildContext;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildOutput;
|
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildOutput;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.compile.executor.ChunkBuilder;
|
import org.embeddedt.embeddium.impl.render.chunk.compile.executor.ChunkBuilder;
|
||||||
@@ -15,6 +17,7 @@ import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderSortT
|
|||||||
import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderTask;
|
import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderTask;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.data.BuiltRenderSectionData;
|
import org.embeddedt.embeddium.impl.render.chunk.data.BuiltRenderSectionData;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.data.BuiltSectionMeshParts;
|
import org.embeddedt.embeddium.impl.render.chunk.data.BuiltSectionMeshParts;
|
||||||
|
import org.embeddedt.embeddium.impl.render.chunk.data.MinecraftBuiltRenderSectionData;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.lists.ChunkRenderList;
|
import org.embeddedt.embeddium.impl.render.chunk.lists.ChunkRenderList;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.lists.RenderListManager;
|
import org.embeddedt.embeddium.impl.render.chunk.lists.RenderListManager;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.lists.SectionTicker;
|
import org.embeddedt.embeddium.impl.render.chunk.lists.SectionTicker;
|
||||||
@@ -32,6 +35,7 @@ import org.embeddedt.embeddium.impl.util.PositionUtil;
|
|||||||
import org.embeddedt.embeddium.impl.util.iterator.ByteIterator;
|
import org.embeddedt.embeddium.impl.util.iterator.ByteIterator;
|
||||||
import org.embeddedt.embeddium.impl.render.ShaderModBridge;
|
import org.embeddedt.embeddium.impl.render.ShaderModBridge;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.sorting.TranslucentQuadAnalyzer;
|
import org.embeddedt.embeddium.impl.render.chunk.sorting.TranslucentQuadAnalyzer;
|
||||||
|
import org.embeddedt.embeddium.impl.util.suppliers.ExpiringSupplier;
|
||||||
import org.jetbrains.annotations.MustBeInvokedByOverriders;
|
import org.jetbrains.annotations.MustBeInvokedByOverriders;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
@@ -39,6 +43,7 @@ import org.joml.Vector3ic;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.LockSupport;
|
import java.util.concurrent.locks.LockSupport;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
@@ -75,6 +80,10 @@ public abstract class RenderSectionManager {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private final RenderListManager shadowRenderListManager;
|
private final RenderListManager shadowRenderListManager;
|
||||||
|
|
||||||
|
protected final ReferenceSet<RenderSection> sectionsWithGlobalEntities = new ReferenceOpenHashSet<>();
|
||||||
|
|
||||||
|
private final Object2ObjectOpenHashMap<TerrainRenderPass, TimerQueryManager> renderPassDrawTimers = new Object2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
public RenderSectionManager(RenderPassConfiguration<?> configuration, Supplier<ChunkBuildContext> contextSupplier, BiFunction<RenderDevice, RenderPassConfiguration<?>, ChunkRenderer> chunkRenderer, int renderDistance, CommandList commandList, int minSection, int maxSection, int requestedThreads) {
|
public RenderSectionManager(RenderPassConfiguration<?> configuration, Supplier<ChunkBuildContext> contextSupplier, BiFunction<RenderDevice, RenderPassConfiguration<?>, ChunkRenderer> chunkRenderer, int renderDistance, CommandList commandList, int minSection, int maxSection, int requestedThreads) {
|
||||||
this.chunkRenderer = chunkRenderer.apply(RenderDevice.INSTANCE, configuration);
|
this.chunkRenderer = chunkRenderer.apply(RenderDevice.INSTANCE, configuration);
|
||||||
|
|
||||||
@@ -121,6 +130,8 @@ public abstract class RenderSectionManager {
|
|||||||
while ((task = this.asyncSubmittedTasks.poll()) != null) {
|
while ((task = this.asyncSubmittedTasks.poll()) != null) {
|
||||||
task.run();
|
task.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.renderPassDrawTimers.values().forEach(TimerQueryManager::updateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -313,8 +324,14 @@ public abstract class RenderSectionManager {
|
|||||||
RenderDevice device = RenderDevice.INSTANCE;
|
RenderDevice device = RenderDevice.INSTANCE;
|
||||||
CommandList commandList = device.createCommandList();
|
CommandList commandList = device.createCommandList();
|
||||||
|
|
||||||
|
var timer = renderPassDrawTimers.computeIfAbsent(pass, $ -> new TimerQueryManager());
|
||||||
|
|
||||||
|
timer.startProfiling();
|
||||||
|
|
||||||
this.chunkRenderer.render(matrices, commandList, this.getCurrentRenderListManager().getRenderLists(), pass, new CameraTransform(x, y, z));
|
this.chunkRenderer.render(matrices, commandList, this.getCurrentRenderListManager().getRenderLists(), pass, new CameraTransform(x, y, z));
|
||||||
|
|
||||||
|
timer.finishProfiling();
|
||||||
|
|
||||||
commandList.flush();
|
commandList.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -418,6 +435,12 @@ public abstract class RenderSectionManager {
|
|||||||
if (this.shadowRenderListManager != null) {
|
if (this.shadowRenderListManager != null) {
|
||||||
this.shadowRenderListManager.updateVisibilityData(render.getChunkX(), render.getChunkY(), render.getChunkZ(), visibilityData);
|
this.shadowRenderListManager.updateVisibilityData(render.getChunkX(), render.getChunkY(), render.getChunkZ(), visibilityData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(info instanceof MinecraftBuiltRenderSectionData<?, ?> data)) {
|
||||||
|
this.sectionsWithGlobalEntities.remove(render);
|
||||||
|
} else if (!data.globalBlockEntities.isEmpty()) {
|
||||||
|
this.sectionsWithGlobalEntities.add(render);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ChunkBuildOutput> filterChunkBuildResults(ArrayList<ChunkBuildOutput> outputs) {
|
private static List<ChunkBuildOutput> filterChunkBuildResults(ArrayList<ChunkBuildOutput> outputs) {
|
||||||
@@ -547,6 +570,11 @@ public abstract class RenderSectionManager {
|
|||||||
this.regions.delete(commandList);
|
this.regions.delete(commandList);
|
||||||
this.chunkRenderer.delete(commandList);
|
this.chunkRenderer.delete(commandList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.renderPassDrawTimers.values().forEach(TimerQueryManager::close);
|
||||||
|
this.renderPassDrawTimers.clear();
|
||||||
|
|
||||||
|
this.sectionsWithGlobalEntities.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTotalSections() {
|
public int getTotalSections() {
|
||||||
@@ -678,6 +706,16 @@ public abstract class RenderSectionManager {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object2LongMap<TerrainRenderPass> computeRenderPassTimingsMap() {
|
||||||
|
Object2LongOpenHashMap<TerrainRenderPass> map = new Object2LongOpenHashMap<>();
|
||||||
|
for (var entry : renderPassDrawTimers.entrySet()) {
|
||||||
|
map.put(entry.getKey(), entry.getValue().getLastTime());
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final Supplier<Object2LongMap<TerrainRenderPass>> renderPassTimingsDebounced = new ExpiringSupplier<>(this::computeRenderPassTimingsMap, 1, TimeUnit.SECONDS);
|
||||||
|
|
||||||
public Collection<String> getDebugStrings() {
|
public Collection<String> getDebugStrings() {
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
|
|
||||||
@@ -720,7 +758,28 @@ public abstract class RenderSectionManager {
|
|||||||
this.getCurrentRenderListManager().getRebuildLists().hasAdditionalUpdates() ? "(++)" : ""
|
this.getCurrentRenderListManager().getRebuildLists().hasAdditionalUpdates() ? "(++)" : ""
|
||||||
));
|
));
|
||||||
|
|
||||||
list.addAll(this.renderListManager.getRenderListDebugStrings());
|
var debugStats = renderListManager.getDebugStatistics();
|
||||||
|
|
||||||
|
var counts = debugStats.renderPassCounts().object2IntEntrySet().stream().sorted(Comparator.comparingInt(e -> -e.getIntValue())).iterator();
|
||||||
|
|
||||||
|
var timingMap = renderPassTimingsDebounced.get();
|
||||||
|
|
||||||
|
while (counts.hasNext()) {
|
||||||
|
var entry = counts.next();
|
||||||
|
var duration = timingMap.get(entry.getKey());
|
||||||
|
String time;
|
||||||
|
if (duration == 0) {
|
||||||
|
time = "?? ms";
|
||||||
|
} else {
|
||||||
|
time = TimeUtil.stringifyTime(duration, TimeUnit.NANOSECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
list.add(entry.getKey().name() + " - " + entry.getIntValue() + " sections, " + time);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (renderListManager.getRenderLists().getPasses().stream().anyMatch(TerrainRenderPass::isSorted)) {
|
||||||
|
list.add(debugStats.getSortingString());
|
||||||
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -757,4 +816,8 @@ public abstract class RenderSectionManager {
|
|||||||
this.disabledRenderPasses.add(pass);
|
this.disabledRenderPasses.add(pass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final Collection<RenderSection> getSectionsWithGlobalEntities() {
|
||||||
|
return ReferenceSets.unmodifiable(this.sectionsWithGlobalEntities);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+13
-9
@@ -13,6 +13,8 @@ import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
|||||||
import org.embeddedt.embeddium.impl.render.shader.ShaderLoader;
|
import org.embeddedt.embeddium.impl.render.shader.ShaderLoader;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -50,30 +52,32 @@ public abstract class ShaderChunkRenderer implements ChunkRenderer {
|
|||||||
protected GlProgram<ChunkShaderInterface> createShader(String path, ChunkShaderOptions options) {
|
protected GlProgram<ChunkShaderInterface> createShader(String path, ChunkShaderOptions options) {
|
||||||
ShaderConstants constants = options.constants();
|
ShaderConstants constants = options.constants();
|
||||||
|
|
||||||
GlShader vertShader = ShaderLoader.loadShader(ShaderType.VERTEX,
|
List<GlShader> loadedShaders = new ArrayList<>();
|
||||||
"sodium:" + path + ".vsh", constants);
|
|
||||||
|
|
||||||
GlShader fragShader = ShaderLoader.loadShader(ShaderType.FRAGMENT,
|
loadedShaders.add(ShaderLoader.loadShader(ShaderType.VERTEX,
|
||||||
"sodium:" + path + ".fsh", constants);
|
"sodium:" + path + ".vsh", constants));
|
||||||
|
|
||||||
|
loadedShaders.add(ShaderLoader.loadShader(ShaderType.FRAGMENT,
|
||||||
|
"sodium:" + path + ".fsh", constants));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var builder = GlProgram.builder("sodium:chunk_shader").attachShader(vertShader).attachShader(fragShader);
|
var builder = GlProgram.builder("sodium:chunk_shader");
|
||||||
|
loadedShaders.forEach(builder::attachShader);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (var attr : options.vertexType().getVertexFormat().getAttributes()) {
|
for (var attr : options.pass().vertexType().getVertexFormat().getAttributes()) {
|
||||||
builder.bindAttribute(attr.getName(), i++);
|
builder.bindAttribute(attr.getName(), i++);
|
||||||
}
|
}
|
||||||
builder.bindFragmentData("fragColor", ChunkShaderBindingPoints.FRAG_COLOR);
|
builder.bindFragmentData("fragColor", ChunkShaderBindingPoints.FRAG_COLOR);
|
||||||
return builder.link((shader) -> new DefaultChunkShaderInterface(shader, options));
|
return builder.link((shader) -> new DefaultChunkShaderInterface(shader, options));
|
||||||
} finally {
|
} finally {
|
||||||
vertShader.delete();
|
loadedShaders.forEach(GlShader::delete);
|
||||||
fragShader.delete();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void begin(TerrainRenderPass pass) {
|
protected void begin(TerrainRenderPass pass) {
|
||||||
pass.startDrawing();
|
pass.startDrawing();
|
||||||
|
|
||||||
ChunkShaderOptions options = new ChunkShaderOptions(ChunkShaderFogComponent.FOG_SERVICE.getFogMode(), pass, this.renderPassConfiguration.getVertexTypeForPass(pass));
|
ChunkShaderOptions options = new ChunkShaderOptions(ChunkShaderFogComponent.FOG_SERVICE.getFogMode(), pass);
|
||||||
|
|
||||||
this.activeProgram = this.compileProgram(options);
|
this.activeProgram = this.compileProgram(options);
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
package org.embeddedt.embeddium.impl.render.chunk.compile.executor;
|
package org.embeddedt.embeddium.impl.render.chunk.compile.executor;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildContext;
|
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildContext;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderTask;
|
import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderTask;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@@ -110,7 +109,7 @@ public class ChunkBuilder {
|
|||||||
public <TASK extends ChunkBuilderTask<OUTPUT>, OUTPUT> ChunkJobTyped<TASK, OUTPUT> scheduleTask(TASK task, boolean important,
|
public <TASK extends ChunkBuilderTask<OUTPUT>, OUTPUT> ChunkJobTyped<TASK, OUTPUT> scheduleTask(TASK task, boolean important,
|
||||||
Consumer<ChunkJobResult<OUTPUT>> consumer)
|
Consumer<ChunkJobResult<OUTPUT>> consumer)
|
||||||
{
|
{
|
||||||
Preconditions.checkNotNull(task, "Task must be non-null");
|
Objects.requireNonNull(task, "Task must be non-null");
|
||||||
|
|
||||||
if (!this.queue.isRunning()) {
|
if (!this.queue.isRunning()) {
|
||||||
throw new IllegalStateException("Executor is stopped");
|
throw new IllegalStateException("Executor is stopped");
|
||||||
|
|||||||
+3
-2
@@ -1,6 +1,5 @@
|
|||||||
package org.embeddedt.embeddium.impl.render.chunk.compile.executor;
|
package org.embeddedt.embeddium.impl.render.chunk.compile.executor;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -20,7 +19,9 @@ class ChunkJobQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void add(ChunkJob job, boolean important) {
|
public void add(ChunkJob job, boolean important) {
|
||||||
Preconditions.checkArgument(this.isRunning(), "Queue is no longer running");
|
if (!this.isRunning()) {
|
||||||
|
throw new IllegalStateException("Queue is no longer running");
|
||||||
|
}
|
||||||
|
|
||||||
if (important) {
|
if (important) {
|
||||||
this.jobs.addFirst(job);
|
this.jobs.addFirst(job);
|
||||||
|
|||||||
+5
@@ -4,6 +4,7 @@ import org.embeddedt.embeddium.impl.render.chunk.sorting.TranslucentQuadAnalyzer
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface ChunkPrimitiveType {
|
public interface ChunkPrimitiveType {
|
||||||
default int getIndexBufferSize(int numPrimitives) {
|
default int getIndexBufferSize(int numPrimitives) {
|
||||||
@@ -45,4 +46,8 @@ public interface ChunkPrimitiveType {
|
|||||||
* @param z z position of the camera
|
* @param z z position of the camera
|
||||||
*/
|
*/
|
||||||
void generateSortedIndexBuffer(ByteBuffer indexBuffer, int numPrimitives, @Nullable TranslucentQuadAnalyzer.SortState chunkData, float x, float y, float z);
|
void generateSortedIndexBuffer(ByteBuffer indexBuffer, int numPrimitives, @Nullable TranslucentQuadAnalyzer.SortState chunkData, float x, float y, float z);
|
||||||
|
|
||||||
|
default List<String> getDefines() {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+32
-6
@@ -8,17 +8,29 @@ import org.lwjgl.system.MemoryUtil;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
public class QuadPrimitiveType implements ChunkPrimitiveType {
|
public final class QuadPrimitiveType implements ChunkPrimitiveType {
|
||||||
public static final QuadPrimitiveType INSTANCE = new QuadPrimitiveType();
|
/**
|
||||||
|
* Generates index buffers that decompose quads into two triangles (suitable for core profile rendering).
|
||||||
|
*/
|
||||||
|
public static final QuadPrimitiveType TRIANGULATED = new QuadPrimitiveType(true);
|
||||||
|
/**
|
||||||
|
* Generates index buffers suited for working with quad(-like) primitives directly.
|
||||||
|
*/
|
||||||
|
public static final QuadPrimitiveType DIRECT = new QuadPrimitiveType(false);
|
||||||
|
|
||||||
|
private final boolean triangulating;
|
||||||
|
|
||||||
private static final int ELEMENTS_PER_PRIMITIVE = 6;
|
|
||||||
private static final int VERTICES_PER_PRIMITIVE = 4;
|
private static final int VERTICES_PER_PRIMITIVE = 4;
|
||||||
|
|
||||||
private static final int FAKE_STATIC_CAMERA_OFFSET = 1000;
|
private static final int FAKE_STATIC_CAMERA_OFFSET = 1000;
|
||||||
|
|
||||||
|
public QuadPrimitiveType(boolean triangulating) {
|
||||||
|
this.triangulating = triangulating;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getIndexBufferElementsPerPrimitive() {
|
public int getIndexBufferElementsPerPrimitive() {
|
||||||
return ELEMENTS_PER_PRIMITIVE;
|
return triangulating ? 6 : 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -34,17 +46,24 @@ public class QuadPrimitiveType implements ChunkPrimitiveType {
|
|||||||
}
|
}
|
||||||
long ptr = MemoryUtil.memAddress(indexBuffer);
|
long ptr = MemoryUtil.memAddress(indexBuffer);
|
||||||
|
|
||||||
|
int elementsPerPrimitive = this.getIndexBufferElementsPerPrimitive();
|
||||||
|
boolean triangulating = this.triangulating;
|
||||||
|
|
||||||
for (int primitiveIndex = 0; primitiveIndex < numPrimitives; primitiveIndex++) {
|
for (int primitiveIndex = 0; primitiveIndex < numPrimitives; primitiveIndex++) {
|
||||||
int indexOffset = primitiveIndex * ELEMENTS_PER_PRIMITIVE;
|
int indexOffset = primitiveIndex * elementsPerPrimitive;
|
||||||
int vertexOffset = primitiveIndex * VERTICES_PER_PRIMITIVE;
|
int vertexOffset = primitiveIndex * VERTICES_PER_PRIMITIVE;
|
||||||
|
|
||||||
MemoryUtil.memPutInt(ptr + (indexOffset + 0) * 4, vertexOffset + 0);
|
MemoryUtil.memPutInt(ptr + (indexOffset + 0) * 4, vertexOffset + 0);
|
||||||
MemoryUtil.memPutInt(ptr + (indexOffset + 1) * 4, vertexOffset + 1);
|
MemoryUtil.memPutInt(ptr + (indexOffset + 1) * 4, vertexOffset + 1);
|
||||||
MemoryUtil.memPutInt(ptr + (indexOffset + 2) * 4, vertexOffset + 2);
|
MemoryUtil.memPutInt(ptr + (indexOffset + 2) * 4, vertexOffset + 2);
|
||||||
|
|
||||||
|
if (triangulating) {
|
||||||
MemoryUtil.memPutInt(ptr + (indexOffset + 3) * 4, vertexOffset + 2);
|
MemoryUtil.memPutInt(ptr + (indexOffset + 3) * 4, vertexOffset + 2);
|
||||||
MemoryUtil.memPutInt(ptr + (indexOffset + 4) * 4, vertexOffset + 3);
|
MemoryUtil.memPutInt(ptr + (indexOffset + 4) * 4, vertexOffset + 3);
|
||||||
MemoryUtil.memPutInt(ptr + (indexOffset + 5) * 4, vertexOffset + 0);
|
MemoryUtil.memPutInt(ptr + (indexOffset + 5) * 4, vertexOffset + 0);
|
||||||
|
} else {
|
||||||
|
MemoryUtil.memPutInt(ptr + (indexOffset + 3) * 4, vertexOffset + 3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,8 +74,11 @@ public class QuadPrimitiveType implements ChunkPrimitiveType {
|
|||||||
}
|
}
|
||||||
long ptr = MemoryUtil.memAddress(indexBuffer);
|
long ptr = MemoryUtil.memAddress(indexBuffer);
|
||||||
|
|
||||||
|
int elementsPerPrimitive = this.getIndexBufferElementsPerPrimitive();
|
||||||
|
boolean triangulating = this.triangulating;
|
||||||
|
|
||||||
for (int primitiveIndex = 0; primitiveIndex < primitiveMapping.length; primitiveIndex++) {
|
for (int primitiveIndex = 0; primitiveIndex < primitiveMapping.length; primitiveIndex++) {
|
||||||
int indexOffset = primitiveIndex * ELEMENTS_PER_PRIMITIVE;
|
int indexOffset = primitiveIndex * elementsPerPrimitive;
|
||||||
|
|
||||||
// Map to the desired primitive
|
// Map to the desired primitive
|
||||||
int vertexOffset = primitiveMapping[primitiveIndex] * VERTICES_PER_PRIMITIVE;
|
int vertexOffset = primitiveMapping[primitiveIndex] * VERTICES_PER_PRIMITIVE;
|
||||||
@@ -65,9 +87,13 @@ public class QuadPrimitiveType implements ChunkPrimitiveType {
|
|||||||
MemoryUtil.memPutInt(ptr + (indexOffset + 1) * 4, vertexOffset + 1);
|
MemoryUtil.memPutInt(ptr + (indexOffset + 1) * 4, vertexOffset + 1);
|
||||||
MemoryUtil.memPutInt(ptr + (indexOffset + 2) * 4, vertexOffset + 2);
|
MemoryUtil.memPutInt(ptr + (indexOffset + 2) * 4, vertexOffset + 2);
|
||||||
|
|
||||||
|
if (triangulating) {
|
||||||
MemoryUtil.memPutInt(ptr + (indexOffset + 3) * 4, vertexOffset + 2);
|
MemoryUtil.memPutInt(ptr + (indexOffset + 3) * 4, vertexOffset + 2);
|
||||||
MemoryUtil.memPutInt(ptr + (indexOffset + 4) * 4, vertexOffset + 3);
|
MemoryUtil.memPutInt(ptr + (indexOffset + 4) * 4, vertexOffset + 3);
|
||||||
MemoryUtil.memPutInt(ptr + (indexOffset + 5) * 4, vertexOffset + 0);
|
MemoryUtil.memPutInt(ptr + (indexOffset + 5) * 4, vertexOffset + 0);
|
||||||
|
} else {
|
||||||
|
MemoryUtil.memPutInt(ptr + (indexOffset + 3) * 4, vertexOffset + 3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,11 +1,11 @@
|
|||||||
package org.embeddedt.embeddium.impl.render.chunk.data;
|
package org.embeddedt.embeddium.impl.render.chunk.data;
|
||||||
|
|
||||||
import com.google.common.collect.Iterators;
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.lists.ChunkRenderList;
|
import org.embeddedt.embeddium.impl.render.chunk.lists.ChunkRenderList;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.lists.RenderVisualsService;
|
import org.embeddedt.embeddium.impl.render.chunk.lists.RenderVisualsService;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.lists.SortedRenderLists;
|
import org.embeddedt.embeddium.impl.render.chunk.lists.SortedRenderLists;
|
||||||
|
import org.embeddedt.embeddium.impl.util.iterator.ConcatenatedIterator;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -91,7 +91,7 @@ public class MinecraftBuiltRenderSectionData<SPRITE, BLOCKENTITY> extends BuiltR
|
|||||||
if(iterators.isEmpty()) {
|
if(iterators.isEmpty()) {
|
||||||
return Collections.emptyIterator();
|
return Collections.emptyIterator();
|
||||||
} else {
|
} else {
|
||||||
return Iterators.concat(iterators.iterator());
|
return new ConcatenatedIterator<>(iterators.iterator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-3
@@ -3,6 +3,7 @@ package org.embeddedt.embeddium.impl.render.chunk.data;
|
|||||||
import org.embeddedt.embeddium.impl.gl.arena.GlBufferSegment;
|
import org.embeddedt.embeddium.impl.gl.arena.GlBufferSegment;
|
||||||
import org.embeddedt.embeddium.impl.gl.util.VertexRange;
|
import org.embeddedt.embeddium.impl.gl.util.VertexRange;
|
||||||
import org.embeddedt.embeddium.impl.model.quad.properties.ModelQuadFacing;
|
import org.embeddedt.embeddium.impl.model.quad.properties.ModelQuadFacing;
|
||||||
|
import org.embeddedt.embeddium.impl.render.chunk.compile.sorting.ChunkPrimitiveType;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.region.RenderRegion;
|
import org.embeddedt.embeddium.impl.render.chunk.region.RenderRegion;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -13,14 +14,16 @@ public class SectionRenderDataStorage {
|
|||||||
private final GlBufferSegment[] indexAllocations = new GlBufferSegment[RenderRegion.REGION_SIZE];
|
private final GlBufferSegment[] indexAllocations = new GlBufferSegment[RenderRegion.REGION_SIZE];
|
||||||
|
|
||||||
private final long pMeshDataArray;
|
private final long pMeshDataArray;
|
||||||
|
private final ChunkPrimitiveType primitiveType;
|
||||||
|
|
||||||
private int numAllocations;
|
private int numAllocations;
|
||||||
|
|
||||||
public SectionRenderDataStorage() {
|
public SectionRenderDataStorage(ChunkPrimitiveType primitiveType) {
|
||||||
this.pMeshDataArray = SectionRenderDataUnsafe.allocateHeap(RenderRegion.REGION_SIZE);
|
this.pMeshDataArray = SectionRenderDataUnsafe.allocateHeap(RenderRegion.REGION_SIZE);
|
||||||
if (this.pMeshDataArray == 0) {
|
if (this.pMeshDataArray == 0) {
|
||||||
throw new OutOfMemoryError("Failed to allocate mesh data array");
|
throw new OutOfMemoryError("Failed to allocate mesh data array");
|
||||||
}
|
}
|
||||||
|
this.primitiveType = primitiveType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
@@ -50,6 +53,9 @@ public class SectionRenderDataStorage {
|
|||||||
int vertexOffset = allocation.getOffset();
|
int vertexOffset = allocation.getOffset();
|
||||||
int indexOffset = indexAllocation != null ? indexAllocation.getOffset() * 4 : 0;
|
int indexOffset = indexAllocation != null ? indexAllocation.getOffset() * 4 : 0;
|
||||||
|
|
||||||
|
int elementsPerPrimitive = primitiveType.getIndexBufferElementsPerPrimitive();
|
||||||
|
int verticesPerPrimitive = primitiveType.getVerticesPerPrimitive();
|
||||||
|
|
||||||
for (int facingIndex = 0; facingIndex < ModelQuadFacing.COUNT; facingIndex++) {
|
for (int facingIndex = 0; facingIndex < ModelQuadFacing.COUNT; facingIndex++) {
|
||||||
VertexRange vertexRange = ranges[facingIndex];
|
VertexRange vertexRange = ranges[facingIndex];
|
||||||
int vertexCount;
|
int vertexCount;
|
||||||
@@ -60,7 +66,7 @@ public class SectionRenderDataStorage {
|
|||||||
vertexCount = 0;
|
vertexCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int indexCount = (vertexCount >> 2) * 6;
|
int indexCount = (vertexCount / verticesPerPrimitive) * elementsPerPrimitive;
|
||||||
|
|
||||||
SectionRenderDataUnsafe.setVertexOffset(pMeshData, facingIndex, vertexOffset);
|
SectionRenderDataUnsafe.setVertexOffset(pMeshData, facingIndex, vertexOffset);
|
||||||
SectionRenderDataUnsafe.setElementCount(pMeshData, facingIndex, indexCount);
|
SectionRenderDataUnsafe.setElementCount(pMeshData, facingIndex, indexCount);
|
||||||
@@ -133,12 +139,15 @@ public class SectionRenderDataStorage {
|
|||||||
|
|
||||||
var data = this.getDataPointer(sectionIndex);
|
var data = this.getDataPointer(sectionIndex);
|
||||||
|
|
||||||
|
int elementsPerPrimitive = primitiveType.getIndexBufferElementsPerPrimitive();
|
||||||
|
int verticesPerPrimitive = primitiveType.getVerticesPerPrimitive();
|
||||||
|
|
||||||
for (int facing = 0; facing < ModelQuadFacing.COUNT; facing++) {
|
for (int facing = 0; facing < ModelQuadFacing.COUNT; facing++) {
|
||||||
SectionRenderDataUnsafe.setVertexOffset(data, facing, vertexOffset);
|
SectionRenderDataUnsafe.setVertexOffset(data, facing, vertexOffset);
|
||||||
SectionRenderDataUnsafe.setIndexOffset(data, facing, indexOffset);
|
SectionRenderDataUnsafe.setIndexOffset(data, facing, indexOffset);
|
||||||
|
|
||||||
var indexCount = SectionRenderDataUnsafe.getElementCount(data, facing);
|
var indexCount = SectionRenderDataUnsafe.getElementCount(data, facing);
|
||||||
vertexOffset += (indexCount / 6) * 4; // convert elements back into vertices
|
vertexOffset += (indexCount / elementsPerPrimitive) * verticesPerPrimitive; // convert elements back into vertices
|
||||||
indexOffset += indexCount * 4;
|
indexOffset += indexCount * 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-51
@@ -1,6 +1,5 @@
|
|||||||
package org.embeddedt.embeddium.impl.render.chunk.lists;
|
package org.embeddedt.embeddium.impl.render.chunk.lists;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ReferenceMap;
|
import it.unimi.dsi.fastutil.longs.Long2ReferenceMap;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ReferenceOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ReferenceOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||||
@@ -18,10 +17,7 @@ import org.embeddedt.embeddium.impl.util.PositionUtil;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.*;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@@ -58,7 +54,27 @@ public class RenderListManager {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private final SectionTicker sectionTicker;
|
private final SectionTicker sectionTicker;
|
||||||
|
|
||||||
private List<String> renderListDebugStrings;
|
public record RenderListDebugStatistics(Object2IntOpenHashMap<TerrainRenderPass> renderPassCounts, int[] sortingSectionCounts) {
|
||||||
|
public String getSortingString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
sb.append("Sorting: ");
|
||||||
|
TranslucentQuadAnalyzer.Level[] values = TranslucentQuadAnalyzer.Level.VALUES;
|
||||||
|
for (int i = 0; i < values.length; i++) {
|
||||||
|
TranslucentQuadAnalyzer.Level level = values[i];
|
||||||
|
sb.append(level.name());
|
||||||
|
sb.append('=');
|
||||||
|
sb.append(sortingSectionCounts[level.ordinal()]);
|
||||||
|
if((i + 1) < values.length) {
|
||||||
|
sb.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private RenderListDebugStatistics debugStatistics;
|
||||||
|
|
||||||
public RenderListManager(int minSectionY, int maxSectionY, boolean useAsyncGraphSearch, @Nullable SectionTicker sectionTicker) {
|
public RenderListManager(int minSectionY, int maxSectionY, boolean useAsyncGraphSearch, @Nullable SectionTicker sectionTicker) {
|
||||||
this.sectionTicker = sectionTicker;
|
this.sectionTicker = sectionTicker;
|
||||||
@@ -116,7 +132,7 @@ public class RenderListManager {
|
|||||||
this.currentOcclusionFuture = null;
|
this.currentOcclusionFuture = null;
|
||||||
this.lastUpdatedFrame = this.pendingLastUpdatedFrame;
|
this.lastUpdatedFrame = this.pendingLastUpdatedFrame;
|
||||||
|
|
||||||
this.renderListDebugStrings = null;
|
this.debugStatistics = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Runnable task;
|
Runnable task;
|
||||||
@@ -245,17 +261,17 @@ public class RenderListManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getRenderListDebugStrings() {
|
|
||||||
if (this.renderListDebugStrings == null) {
|
public RenderListDebugStatistics getDebugStatistics() {
|
||||||
this.renderListDebugStrings = computeRenderListDebugStrings();
|
if (this.debugStatistics == null) {
|
||||||
|
this.debugStatistics = computeDebugStatistics();
|
||||||
}
|
}
|
||||||
return this.renderListDebugStrings;
|
return this.debugStatistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> computeRenderListDebugStrings() {
|
private RenderListDebugStatistics computeDebugStatistics() {
|
||||||
Object2IntOpenHashMap<TerrainRenderPass> renderPassCounts = new Object2IntOpenHashMap<>();
|
Object2IntOpenHashMap<TerrainRenderPass> renderPassCounts = new Object2IntOpenHashMap<>();
|
||||||
|
|
||||||
|
|
||||||
var iterator = renderLists.iterator();
|
var iterator = renderLists.iterator();
|
||||||
|
|
||||||
int[] sectionCounts = new int[TranslucentQuadAnalyzer.Level.VALUES.length];
|
int[] sectionCounts = new int[TranslucentQuadAnalyzer.Level.VALUES.length];
|
||||||
@@ -307,43 +323,6 @@ public class RenderListManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImmutableList.Builder<String> builder = ImmutableList.builder();
|
return new RenderListDebugStatistics(renderPassCounts, sectionCounts);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder("Passes: ");
|
|
||||||
var iter = renderPassCounts.object2IntEntrySet().stream().sorted(Comparator.comparingInt(e -> -e.getIntValue())).iterator();
|
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
var entry = iter.next();
|
|
||||||
|
|
||||||
sb.append(Character.toUpperCase(entry.getKey().name().charAt(0)));
|
|
||||||
sb.append('=');
|
|
||||||
sb.append(entry.getIntValue());
|
|
||||||
|
|
||||||
if (iter.hasNext()) {
|
|
||||||
sb.append(", ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.add(sb.toString());
|
|
||||||
|
|
||||||
if (isSorting) {
|
|
||||||
sb = new StringBuilder();
|
|
||||||
|
|
||||||
sb.append("Sorting: ");
|
|
||||||
TranslucentQuadAnalyzer.Level[] values = TranslucentQuadAnalyzer.Level.VALUES;
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
TranslucentQuadAnalyzer.Level level = values[i];
|
|
||||||
sb.append(level.name());
|
|
||||||
sb.append('=');
|
|
||||||
sb.append(sectionCounts[level.ordinal()]);
|
|
||||||
if((i + 1) < values.length) {
|
|
||||||
sb.append(", ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.add(sb.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-6
@@ -1,6 +1,5 @@
|
|||||||
package org.embeddedt.embeddium.impl.render.chunk.region;
|
package org.embeddedt.embeddium.impl.render.chunk.region;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
|
||||||
import org.embeddedt.embeddium.impl.gl.arena.GlBufferArena;
|
import org.embeddedt.embeddium.impl.gl.arena.GlBufferArena;
|
||||||
@@ -9,6 +8,7 @@ import org.embeddedt.embeddium.impl.gl.attribute.GlVertexFormat;
|
|||||||
import org.embeddedt.embeddium.impl.gl.buffer.GlBuffer;
|
import org.embeddedt.embeddium.impl.gl.buffer.GlBuffer;
|
||||||
import org.embeddedt.embeddium.impl.gl.device.CommandList;
|
import org.embeddedt.embeddium.impl.gl.device.CommandList;
|
||||||
import org.embeddedt.embeddium.impl.gl.tessellation.GlTessellation;
|
import org.embeddedt.embeddium.impl.gl.tessellation.GlTessellation;
|
||||||
|
import org.embeddedt.embeddium.impl.render.chunk.RenderPassConfiguration;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.data.SectionRenderDataStorage;
|
import org.embeddedt.embeddium.impl.render.chunk.data.SectionRenderDataStorage;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||||
@@ -37,9 +37,9 @@ public class RenderRegion {
|
|||||||
public static final int REGION_SIZE = REGION_WIDTH * REGION_HEIGHT * REGION_LENGTH;
|
public static final int REGION_SIZE = REGION_WIDTH * REGION_HEIGHT * REGION_LENGTH;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Preconditions.checkArgument(MathUtil.isPowerOfTwo(REGION_WIDTH));
|
if(!MathUtil.isPowerOfTwo(REGION_WIDTH) || !MathUtil.isPowerOfTwo(REGION_HEIGHT) || !MathUtil.isPowerOfTwo(REGION_LENGTH)) {
|
||||||
Preconditions.checkArgument(MathUtil.isPowerOfTwo(REGION_HEIGHT));
|
throw new IllegalStateException("Region width/height/length are not powers of two");
|
||||||
Preconditions.checkArgument(MathUtil.isPowerOfTwo(REGION_LENGTH));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final StagingBuffer stagingBuffer;
|
private final StagingBuffer stagingBuffer;
|
||||||
@@ -120,11 +120,11 @@ public class RenderRegion {
|
|||||||
return this.sectionRenderData.get(pass);
|
return this.sectionRenderData.get(pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SectionRenderDataStorage createStorage(TerrainRenderPass pass) {
|
public SectionRenderDataStorage createStorage(TerrainRenderPass pass, RenderPassConfiguration<?> renderPassConfiguration) {
|
||||||
var storage = this.sectionRenderData.get(pass);
|
var storage = this.sectionRenderData.get(pass);
|
||||||
|
|
||||||
if (storage == null) {
|
if (storage == null) {
|
||||||
this.sectionRenderData.put(pass, storage = new SectionRenderDataStorage());
|
this.sectionRenderData.put(pass, storage = new SectionRenderDataStorage(renderPassConfiguration.getPrimitiveTypeForPass(pass)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return storage;
|
return storage;
|
||||||
|
|||||||
+2
-2
@@ -117,7 +117,7 @@ public class RenderRegionManager {
|
|||||||
// Collect the upload results
|
// Collect the upload results
|
||||||
for (var uploads : uploadsByFormat.values()) {
|
for (var uploads : uploadsByFormat.values()) {
|
||||||
for (PendingSectionUpload upload : uploads) {
|
for (PendingSectionUpload upload : uploads) {
|
||||||
var storage = region.createStorage(upload.pass);
|
var storage = region.createStorage(upload.pass, renderPassConfiguration);
|
||||||
storage.setMeshes(upload.section.getSectionIndex(),
|
storage.setMeshes(upload.section.getSectionIndex(),
|
||||||
upload.vertexUpload.getResult(), upload.indexUpload != null ? upload.indexUpload.getResult() : null, upload.meshData.getVertexRanges());
|
upload.vertexUpload.getResult(), upload.indexUpload != null ? upload.indexUpload.getResult() : null, upload.meshData.getVertexRanges());
|
||||||
}
|
}
|
||||||
@@ -172,7 +172,7 @@ public class RenderRegionManager {
|
|||||||
// Collect the upload results
|
// Collect the upload results
|
||||||
for (var uploads : uploadsByFormat.values()) {
|
for (var uploads : uploadsByFormat.values()) {
|
||||||
for (PendingResortUpload upload : uploads) {
|
for (PendingResortUpload upload : uploads) {
|
||||||
var storage = region.createStorage(upload.pass);
|
var storage = region.createStorage(upload.pass, renderPassConfiguration);
|
||||||
storage.replaceIndexBuffer(upload.section.getSectionIndex(), upload.indexUpload.getResult());
|
storage.replaceIndexBuffer(upload.section.getSectionIndex(), upload.indexUpload.getResult());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -1,6 +1,5 @@
|
|||||||
package org.embeddedt.embeddium.impl.render.chunk.shader;
|
package org.embeddedt.embeddium.impl.render.chunk.shader;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext;
|
import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext;
|
||||||
import org.lwjgl.opengl.GL20;
|
import org.lwjgl.opengl.GL20;
|
||||||
|
|
||||||
@@ -8,9 +7,9 @@ import java.util.List;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public enum ChunkFogMode {
|
public enum ChunkFogMode {
|
||||||
NONE(ChunkShaderFogComponent.None::new, ImmutableList.of()),
|
NONE(ChunkShaderFogComponent.None::new, List.of()),
|
||||||
EXP2(ChunkShaderFogComponent.Exp2::new, ImmutableList.of("USE_FOG", "USE_FOG_EXP2")),
|
EXP2(ChunkShaderFogComponent.Exp2::new, List.of("USE_FOG", "USE_FOG_EXP2")),
|
||||||
SMOOTH(ChunkShaderFogComponent.Smooth::new, ImmutableList.of("USE_FOG", "USE_FOG_SMOOTH"));
|
SMOOTH(ChunkShaderFogComponent.Smooth::new, List.of("USE_FOG", "USE_FOG_SMOOTH"));
|
||||||
|
|
||||||
private final Function<ShaderBindingContext, ChunkShaderFogComponent> factory;
|
private final Function<ShaderBindingContext, ChunkShaderFogComponent> factory;
|
||||||
private final List<String> defines;
|
private final List<String> defines;
|
||||||
|
|||||||
+1
-3
@@ -7,9 +7,7 @@ import org.joml.Matrix4fc;
|
|||||||
public interface ChunkShaderInterface {
|
public interface ChunkShaderInterface {
|
||||||
void setupState(TerrainRenderPass pass);
|
void setupState(TerrainRenderPass pass);
|
||||||
default void restoreState() {}
|
default void restoreState() {}
|
||||||
default GlPrimitiveType getPrimitiveType() {
|
GlPrimitiveType getPrimitiveType();
|
||||||
return GlPrimitiveType.TRIANGLES;
|
|
||||||
}
|
|
||||||
void setProjectionMatrix(Matrix4fc matrix);
|
void setProjectionMatrix(Matrix4fc matrix);
|
||||||
void setModelViewMatrix(Matrix4fc matrix);
|
void setModelViewMatrix(Matrix4fc matrix);
|
||||||
void setRegionOffset(float x, float y, float z);
|
void setRegionOffset(float x, float y, float z);
|
||||||
|
|||||||
+9
-6
@@ -2,10 +2,9 @@ package org.embeddedt.embeddium.impl.render.chunk.shader;
|
|||||||
|
|
||||||
import org.embeddedt.embeddium.impl.gl.shader.ShaderConstants;
|
import org.embeddedt.embeddium.impl.gl.shader.ShaderConstants;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
|
||||||
import org.embeddedt.embeddium.impl.render.ShaderModBridge;
|
import org.embeddedt.embeddium.impl.render.ShaderModBridge;
|
||||||
|
|
||||||
public record ChunkShaderOptions(ChunkFogMode fog, TerrainRenderPass pass, ChunkVertexType vertexType) {
|
public record ChunkShaderOptions(ChunkFogMode fog, TerrainRenderPass pass) {
|
||||||
|
|
||||||
public ShaderConstants constants() {
|
public ShaderConstants constants() {
|
||||||
ShaderConstants.Builder constants = ShaderConstants.builder();
|
ShaderConstants.Builder constants = ShaderConstants.builder();
|
||||||
@@ -19,11 +18,15 @@ public record ChunkShaderOptions(ChunkFogMode fog, TerrainRenderPass pass, Chunk
|
|||||||
constants.add("CELERITAS_NO_LIGHTMAP");
|
constants.add("CELERITAS_NO_LIGHTMAP");
|
||||||
}
|
}
|
||||||
|
|
||||||
constants.addAll(this.vertexType.getDefines());
|
var vertexType = pass.vertexType();
|
||||||
|
var primitiveType = pass.primitiveType();
|
||||||
|
|
||||||
constants.add("VERT_POS_SCALE", String.valueOf(this.vertexType.getPositionScale()));
|
constants.addAll(vertexType.getDefines());
|
||||||
constants.add("VERT_POS_OFFSET", String.valueOf(this.vertexType.getPositionOffset()));
|
constants.addAll(primitiveType.getDefines());
|
||||||
constants.add("VERT_TEX_SCALE", String.valueOf(this.vertexType.getTextureScale()));
|
|
||||||
|
constants.add("VERT_POS_SCALE", String.valueOf(vertexType.getPositionScale()));
|
||||||
|
constants.add("VERT_POS_OFFSET", String.valueOf(vertexType.getPositionOffset()));
|
||||||
|
constants.add("VERT_TEX_SCALE", String.valueOf(vertexType.getTextureScale()));
|
||||||
|
|
||||||
if(!ShaderModBridge.emulateLegacyColorBrightnessFormat()) {
|
if(!ShaderModBridge.emulateLegacyColorBrightnessFormat()) {
|
||||||
constants.add("USE_VANILLA_COLOR_FORMAT");
|
constants.add("USE_VANILLA_COLOR_FORMAT");
|
||||||
|
|||||||
+17
@@ -4,6 +4,8 @@ import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext;
|
|||||||
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat3v;
|
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat3v;
|
||||||
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformInt;
|
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformInt;
|
||||||
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix4f;
|
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix4f;
|
||||||
|
import org.embeddedt.embeddium.impl.gl.tessellation.GlPrimitiveType;
|
||||||
|
import org.embeddedt.embeddium.impl.render.chunk.compile.sorting.QuadPrimitiveType;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||||
import org.joml.Matrix4fc;
|
import org.joml.Matrix4fc;
|
||||||
|
|
||||||
@@ -26,6 +28,8 @@ public class DefaultChunkShaderInterface implements ChunkShaderInterface {
|
|||||||
|
|
||||||
private final ChunkShaderTextureService textureService;
|
private final ChunkShaderTextureService textureService;
|
||||||
|
|
||||||
|
private GlPrimitiveType primitiveType;
|
||||||
|
|
||||||
public DefaultChunkShaderInterface(ShaderBindingContext context, ChunkShaderOptions options) {
|
public DefaultChunkShaderInterface(ShaderBindingContext context, ChunkShaderOptions options) {
|
||||||
this.uniformModelViewMatrix = context.bindUniform("u_ModelViewMatrix", GlUniformMatrix4f::new);
|
this.uniformModelViewMatrix = context.bindUniform("u_ModelViewMatrix", GlUniformMatrix4f::new);
|
||||||
this.uniformProjectionMatrix = context.bindUniform("u_ProjectionMatrix", GlUniformMatrix4f::new);
|
this.uniformProjectionMatrix = context.bindUniform("u_ProjectionMatrix", GlUniformMatrix4f::new);
|
||||||
@@ -49,9 +53,22 @@ public class DefaultChunkShaderInterface implements ChunkShaderInterface {
|
|||||||
this.bindTexture(ChunkShaderTextureSlot.LIGHT);
|
this.bindTexture(ChunkShaderTextureSlot.LIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pass.primitiveType() == QuadPrimitiveType.DIRECT) {
|
||||||
|
primitiveType = GlPrimitiveType.LINES_ADJACENCY;
|
||||||
|
} else if (pass.primitiveType() == QuadPrimitiveType.TRIANGULATED) {
|
||||||
|
primitiveType = GlPrimitiveType.TRIANGLES;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unknown primitive type");
|
||||||
|
}
|
||||||
|
|
||||||
this.fogShader.setup();
|
this.fogShader.setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GlPrimitiveType getPrimitiveType() {
|
||||||
|
return primitiveType;
|
||||||
|
}
|
||||||
|
|
||||||
@Deprecated(forRemoval = true) // should be handled properly in GFX instead.
|
@Deprecated(forRemoval = true) // should be handled properly in GFX instead.
|
||||||
private void bindTexture(ChunkShaderTextureSlot slot) {
|
private void bindTexture(ChunkShaderTextureSlot slot) {
|
||||||
var uniform = this.uniformTextures.get(slot);
|
var uniform = this.uniformTextures.get(slot);
|
||||||
|
|||||||
+29
-1
@@ -4,7 +4,12 @@ import lombok.Builder;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
import org.embeddedt.embeddium.impl.render.chunk.compile.sorting.ChunkPrimitiveType;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material;
|
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material;
|
||||||
|
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A terrain render pass corresponds to a draw call to render some subset of terrain geometry. Passes are generally
|
* A terrain render pass corresponds to a draw call to render some subset of terrain geometry. Passes are generally
|
||||||
@@ -46,17 +51,32 @@ public class TerrainRenderPass {
|
|||||||
*/
|
*/
|
||||||
private final boolean hasNoLightmap;
|
private final boolean hasNoLightmap;
|
||||||
|
|
||||||
|
private final @NotNull ChunkPrimitiveType primitiveType;
|
||||||
|
private final @NotNull ChunkVertexType vertexType;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
public TerrainRenderPass(String name, PipelineState pipelineState, boolean useReverseOrder, boolean fragmentDiscard, boolean useTranslucencySorting, boolean hasNoLightmap) {
|
public TerrainRenderPass(String name,
|
||||||
|
PipelineState pipelineState,
|
||||||
|
boolean useReverseOrder,
|
||||||
|
boolean fragmentDiscard,
|
||||||
|
boolean useTranslucencySorting,
|
||||||
|
boolean hasNoLightmap,
|
||||||
|
@NotNull ChunkVertexType vertexType,
|
||||||
|
@NotNull ChunkPrimitiveType primitiveType) {
|
||||||
if(name == null || name.length() == 0) {
|
if(name == null || name.length() == 0) {
|
||||||
throw new IllegalArgumentException("Name not specified for terrain pass");
|
throw new IllegalArgumentException("Name not specified for terrain pass");
|
||||||
}
|
}
|
||||||
|
Objects.requireNonNull(vertexType);
|
||||||
|
Objects.requireNonNull(primitiveType);
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.pipelineState = pipelineState;
|
this.pipelineState = pipelineState;
|
||||||
this.useReverseOrder = useReverseOrder;
|
this.useReverseOrder = useReverseOrder;
|
||||||
this.fragmentDiscard = fragmentDiscard;
|
this.fragmentDiscard = fragmentDiscard;
|
||||||
this.useTranslucencySorting = useTranslucencySorting;
|
this.useTranslucencySorting = useTranslucencySorting;
|
||||||
this.hasNoLightmap = hasNoLightmap;
|
this.hasNoLightmap = hasNoLightmap;
|
||||||
|
this.primitiveType = primitiveType;
|
||||||
|
this.vertexType = vertexType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isReverseOrder() {
|
public boolean isReverseOrder() {
|
||||||
@@ -83,6 +103,14 @@ public class TerrainRenderPass {
|
|||||||
return this.fragmentDiscard;
|
return this.fragmentDiscard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ChunkPrimitiveType primitiveType() {
|
||||||
|
return this.primitiveType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChunkVertexType vertexType() {
|
||||||
|
return this.vertexType;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "TerrainRenderPass[name=" + this.name + "]";
|
return "TerrainRenderPass[name=" + this.name + "]";
|
||||||
|
|||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
package org.embeddedt.embeddium.impl.util.iterator;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
public class ConcatenatedIterator<T> implements Iterator<T> {
|
||||||
|
private final Iterator<Iterator<T>> iterators;
|
||||||
|
|
||||||
|
private Iterator<T> currentIterator;
|
||||||
|
|
||||||
|
public ConcatenatedIterator(Iterator<Iterator<T>> iterators) {
|
||||||
|
this.iterators = iterators;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
if ((currentIterator == null || !currentIterator.hasNext()) && iterators.hasNext()) {
|
||||||
|
currentIterator = iterators.next();
|
||||||
|
}
|
||||||
|
return currentIterator != null && currentIterator.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T next() {
|
||||||
|
// hasNext manages replacing the iterator
|
||||||
|
if (!hasNext()) {
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
} else {
|
||||||
|
return currentIterator.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
package org.embeddedt.embeddium.impl.util.suppliers;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class ExpiringSupplier<T> implements Supplier<@NotNull T> {
|
||||||
|
private final Supplier<@NotNull T> supplier;
|
||||||
|
private final long expiryTime;
|
||||||
|
private long lastTime;
|
||||||
|
private T lastValue;
|
||||||
|
|
||||||
|
public ExpiringSupplier(Supplier<@NotNull T> supplier, long duration, TimeUnit unit) {
|
||||||
|
this.supplier = supplier;
|
||||||
|
this.expiryTime = TimeUnit.NANOSECONDS.convert(duration, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T get() {
|
||||||
|
if (lastValue == null || (System.nanoTime() - lastTime) >= expiryTime) {
|
||||||
|
lastValue = supplier.get();
|
||||||
|
Objects.requireNonNull(lastValue, "Returned value may not be null");
|
||||||
|
lastTime = System.nanoTime();
|
||||||
|
}
|
||||||
|
return lastValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,12 +2,20 @@
|
|||||||
|
|
||||||
#import <sodium:include/fog.glsl>
|
#import <sodium:include/fog.glsl>
|
||||||
|
|
||||||
in vec4 v_Color; // The interpolated vertex color
|
in VS_OUT
|
||||||
in vec2 v_TexCoord; // The interpolated block texture coordinates
|
{
|
||||||
in float v_FragDistance; // The fragment's distance from the camera
|
vec4 v_Color;
|
||||||
|
vec2 v_TexCoord;
|
||||||
|
|
||||||
in float v_MaterialMipBias;
|
float v_MaterialMipBias;
|
||||||
in float v_MaterialAlphaCutoff;
|
#ifdef USE_FRAGMENT_DISCARD
|
||||||
|
float v_MaterialAlphaCutoff;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_FOG
|
||||||
|
float v_FragDistance; // The fragment's distance from the camera
|
||||||
|
#endif
|
||||||
|
} fs_in;
|
||||||
|
|
||||||
uniform sampler2D u_BlockTex; // The block texture
|
uniform sampler2D u_BlockTex; // The block texture
|
||||||
|
|
||||||
@@ -25,31 +33,33 @@ uniform float u_FogDensity; // The density of the shader fog
|
|||||||
out vec4 fragColor; // The output fragment for the color framebuffer
|
out vec4 fragColor; // The output fragment for the color framebuffer
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 diffuseColor = texture(u_BlockTex, v_TexCoord, v_MaterialMipBias);
|
vec4 diffuseColor = texture(u_BlockTex, fs_in.v_TexCoord, fs_in.v_MaterialMipBias);
|
||||||
|
|
||||||
#ifdef USE_FRAGMENT_DISCARD
|
#ifdef USE_FRAGMENT_DISCARD
|
||||||
if (diffuseColor.a < v_MaterialAlphaCutoff) {
|
if (diffuseColor.a < fs_in.v_MaterialAlphaCutoff) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
vec4 m_color = fs_in.v_Color;
|
||||||
|
|
||||||
#ifdef USE_VANILLA_COLOR_FORMAT
|
#ifdef USE_VANILLA_COLOR_FORMAT
|
||||||
// Apply per-vertex color. AO shade is applied ahead of time on the CPU.
|
// Apply per-vertex color. AO shade is applied ahead of time on the CPU.
|
||||||
diffuseColor *= v_Color;
|
diffuseColor *= m_color;
|
||||||
#else
|
#else
|
||||||
// Apply per-vertex color
|
// Apply per-vertex color
|
||||||
diffuseColor.rgb *= v_Color.rgb;
|
diffuseColor.rgb *= m_color.rgb;
|
||||||
|
|
||||||
// Apply ambient occlusion "shade"
|
// Apply ambient occlusion "shade"
|
||||||
diffuseColor.rgb *= v_Color.a;
|
diffuseColor.rgb *= m_color.a;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_FOG
|
#ifdef USE_FOG
|
||||||
#ifdef USE_FOG_EXP2
|
#ifdef USE_FOG_EXP2
|
||||||
fragColor = _exp2Fog(diffuseColor, v_FragDistance, u_FogColor, u_FogDensity);
|
fragColor = _exp2Fog(diffuseColor, fs_in.v_FragDistance, u_FogColor, u_FogDensity);
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_FOG_SMOOTH
|
#ifdef USE_FOG_SMOOTH
|
||||||
fragColor = _linearFog(diffuseColor, v_FragDistance, u_FogColor, u_FogStart, u_FogEnd);
|
fragColor = _linearFog(diffuseColor, fs_in.v_FragDistance, u_FogColor, u_FogStart, u_FogEnd);
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
fragColor = diffuseColor;
|
fragColor = diffuseColor;
|
||||||
|
|||||||
@@ -5,17 +5,20 @@
|
|||||||
#import <sodium:include/chunk_matrices.glsl>
|
#import <sodium:include/chunk_matrices.glsl>
|
||||||
#import <sodium:include/chunk_material.glsl>
|
#import <sodium:include/chunk_material.glsl>
|
||||||
|
|
||||||
out vec4 v_Color;
|
out VS_OUT
|
||||||
out vec2 v_TexCoord;
|
{
|
||||||
|
vec4 v_Color;
|
||||||
|
vec2 v_TexCoord;
|
||||||
|
|
||||||
out float v_MaterialMipBias;
|
float v_MaterialMipBias;
|
||||||
#ifdef USE_FRAGMENT_DISCARD
|
#ifdef USE_FRAGMENT_DISCARD
|
||||||
out float v_MaterialAlphaCutoff;
|
float v_MaterialAlphaCutoff;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_FOG
|
#ifdef USE_FOG
|
||||||
out float v_FragDistance;
|
float v_FragDistance;
|
||||||
#endif
|
#endif
|
||||||
|
} vs_out;
|
||||||
|
|
||||||
uniform int u_FogShape;
|
uniform int u_FogShape;
|
||||||
uniform vec3 u_RegionOffset;
|
uniform vec3 u_RegionOffset;
|
||||||
@@ -45,7 +48,7 @@ void main() {
|
|||||||
vec3 position = _vert_position + translation;
|
vec3 position = _vert_position + translation;
|
||||||
|
|
||||||
#ifdef USE_FOG
|
#ifdef USE_FOG
|
||||||
v_FragDistance = getFragDistance(u_FogShape, position);
|
vs_out.v_FragDistance = getFragDistance(u_FogShape, position);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Transform the vertex position into model-view-projection space
|
// Transform the vertex position into model-view-projection space
|
||||||
@@ -53,14 +56,14 @@ void main() {
|
|||||||
|
|
||||||
// Add the light color to the vertex color, and pass the texture coordinates to the fragment shader
|
// Add the light color to the vertex color, and pass the texture coordinates to the fragment shader
|
||||||
#ifdef CELERITAS_NO_LIGHTMAP
|
#ifdef CELERITAS_NO_LIGHTMAP
|
||||||
v_Color = _vert_color;
|
vs_out.v_Color = _vert_color;
|
||||||
#else
|
#else
|
||||||
v_Color = _vert_color * _sample_lightmap(u_LightTex, _vert_tex_light_coord);
|
vs_out.v_Color = _vert_color * _sample_lightmap(u_LightTex, _vert_tex_light_coord);
|
||||||
#endif
|
#endif
|
||||||
v_TexCoord = _vert_tex_diffuse_coord;
|
vs_out.v_TexCoord = _vert_tex_diffuse_coord;
|
||||||
|
|
||||||
v_MaterialMipBias = _material_mip_bias(_material_params);
|
vs_out.v_MaterialMipBias = _material_mip_bias(_material_params);
|
||||||
#ifdef USE_FRAGMENT_DISCARD
|
#ifdef USE_FRAGMENT_DISCARD
|
||||||
v_MaterialAlphaCutoff = _material_alpha_cutoff(_material_params);
|
vs_out.v_MaterialAlphaCutoff = _material_alpha_cutoff(_material_params);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
-22
@@ -38,7 +38,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public class VintageRenderSectionManager extends RenderSectionManager {
|
public class VintageRenderSectionManager extends RenderSectionManager {
|
||||||
private final WorldClient world;
|
private final WorldClient world;
|
||||||
private final ReferenceSet<RenderSection> sectionsWithGlobalEntities = new ReferenceOpenHashSet<>();
|
|
||||||
@Getter
|
@Getter
|
||||||
private final ClonedChunkSectionCache sectionCache;
|
private final ClonedChunkSectionCache sectionCache;
|
||||||
|
|
||||||
@@ -113,27 +112,6 @@ public class VintageRenderSectionManager extends RenderSectionManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateSectionInfo(RenderSection render, BuiltRenderSectionData info) {
|
|
||||||
super.updateSectionInfo(render, info);
|
|
||||||
|
|
||||||
if (info == null || (info instanceof MinecraftBuiltRenderSectionData<?, ?> mcInfo) && mcInfo.globalBlockEntities.isEmpty()) {
|
|
||||||
this.sectionsWithGlobalEntities.remove(render);
|
|
||||||
} else {
|
|
||||||
this.sectionsWithGlobalEntities.add(render);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() {
|
|
||||||
super.destroy();
|
|
||||||
this.sectionsWithGlobalEntities.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<RenderSection> getSectionsWithGlobalEntities() {
|
|
||||||
return ReferenceSets.unmodifiable(this.sectionsWithGlobalEntities);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void scheduleSectionForRebuild(int x, int y, int z, boolean important) {
|
protected void scheduleSectionForRebuild(int x, int y, int z, boolean important) {
|
||||||
this.sectionCache.invalidate(x, y, z);
|
this.sectionCache.invalidate(x, y, z);
|
||||||
|
|||||||
+7
-4
@@ -7,12 +7,14 @@ import org.embeddedt.embeddium.impl.render.chunk.compile.sorting.QuadPrimitiveTy
|
|||||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material;
|
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.parameters.AlphaCutoffParameter;
|
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.parameters.AlphaCutoffParameter;
|
||||||
|
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkMeshFormats;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ArchaicRenderPassConfigurationBuilder {
|
public class ArchaicRenderPassConfigurationBuilder {
|
||||||
|
|
||||||
public static final TerrainRenderPass SOLID_PASS, CUTOUT_MIPPED_PASS, TRANSLUCENT_PASS;
|
public static final TerrainRenderPass SOLID_PASS, CUTOUT_MIPPED_PASS, TRANSLUCENT_PASS;
|
||||||
public static final Material SOLID_MATERIAL, CUTOUT_MIPPED_MATERIAL, TRANSLUCENT_MATERIAL;
|
public static final Material SOLID_MATERIAL, CUTOUT_MIPPED_MATERIAL, TRANSLUCENT_MATERIAL;
|
||||||
|
|
||||||
@@ -37,7 +39,7 @@ public class ArchaicRenderPassConfigurationBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static TerrainRenderPass.TerrainRenderPassBuilder builderForRenderType(int pass, boolean disableBlend) {
|
private static TerrainRenderPass.TerrainRenderPassBuilder builderForRenderType(int pass, boolean disableBlend) {
|
||||||
return TerrainRenderPass.builder().pipelineState(new ArchaicPipelineState(pass, disableBlend));
|
return TerrainRenderPass.builder().pipelineState(new ArchaicPipelineState(pass, disableBlend)).vertexType(ChunkMeshFormats.VANILLA_LIKE).primitiveType(QuadPrimitiveType.TRIANGULATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -63,6 +65,9 @@ public class ArchaicRenderPassConfigurationBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static RenderPassConfiguration<Integer> build(ChunkVertexType vertexType) {
|
public static RenderPassConfiguration<Integer> build(ChunkVertexType vertexType) {
|
||||||
|
if (vertexType != ChunkMeshFormats.VANILLA_LIKE) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
ImmutableListMultimap.Builder<Integer, TerrainRenderPass> vanillaRenderStages = ImmutableListMultimap.builder();
|
ImmutableListMultimap.Builder<Integer, TerrainRenderPass> vanillaRenderStages = ImmutableListMultimap.builder();
|
||||||
|
|
||||||
vanillaRenderStages.put(1, TRANSLUCENT_PASS);
|
vanillaRenderStages.put(1, TRANSLUCENT_PASS);
|
||||||
@@ -78,10 +83,8 @@ public class ArchaicRenderPassConfigurationBuilder {
|
|||||||
|
|
||||||
var vanillaRenderStageMap = vanillaRenderStages.build();
|
var vanillaRenderStageMap = vanillaRenderStages.build();
|
||||||
|
|
||||||
return new RenderPassConfiguration<>(vertexType,
|
return new RenderPassConfiguration<>(renderTypeToMaterialMap,
|
||||||
renderTypeToMaterialMap,
|
|
||||||
vanillaRenderStageMap.asMap(),
|
vanillaRenderStageMap.asMap(),
|
||||||
type -> QuadPrimitiveType.INSTANCE,
|
|
||||||
CUTOUT_MIPPED_MATERIAL,
|
CUTOUT_MIPPED_MATERIAL,
|
||||||
CUTOUT_MIPPED_MATERIAL,
|
CUTOUT_MIPPED_MATERIAL,
|
||||||
TRANSLUCENT_MATERIAL);
|
TRANSLUCENT_MATERIAL);
|
||||||
|
|||||||
-22
@@ -30,7 +30,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public class ArchaicRenderSectionManager extends RenderSectionManager {
|
public class ArchaicRenderSectionManager extends RenderSectionManager {
|
||||||
private final WorldClient world;
|
private final WorldClient world;
|
||||||
private final ReferenceSet<RenderSection> sectionsWithGlobalEntities = new ReferenceOpenHashSet<>();
|
|
||||||
|
|
||||||
public ArchaicRenderSectionManager(RenderPassConfiguration<?> configuration, WorldClient world, int renderDistance, CommandList commandList, int minSection, int maxSection, int requestedThreads) {
|
public ArchaicRenderSectionManager(RenderPassConfiguration<?> configuration, WorldClient world, int renderDistance, CommandList commandList, int minSection, int maxSection, int requestedThreads) {
|
||||||
super(configuration, () -> new ArchaicChunkBuildContext(world, configuration), DefaultChunkRenderer::new, renderDistance, commandList, minSection, maxSection, requestedThreads);
|
super(configuration, () -> new ArchaicChunkBuildContext(world, configuration), DefaultChunkRenderer::new, renderDistance, commandList, minSection, maxSection, requestedThreads);
|
||||||
@@ -96,27 +95,6 @@ public class ArchaicRenderSectionManager extends RenderSectionManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateSectionInfo(RenderSection render, BuiltRenderSectionData info) {
|
|
||||||
super.updateSectionInfo(render, info);
|
|
||||||
|
|
||||||
if (info == null || (info instanceof MinecraftBuiltRenderSectionData<?, ?> mcInfo) && mcInfo.globalBlockEntities.isEmpty()) {
|
|
||||||
this.sectionsWithGlobalEntities.remove(render);
|
|
||||||
} else {
|
|
||||||
this.sectionsWithGlobalEntities.add(render);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() {
|
|
||||||
super.destroy();
|
|
||||||
this.sectionsWithGlobalEntities.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<RenderSection> getSectionsWithGlobalEntities() {
|
|
||||||
return ReferenceSets.unmodifiable(this.sectionsWithGlobalEntities);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected @Nullable SectionTicker createSectionTicker() {
|
protected @Nullable SectionTicker createSectionTicker() {
|
||||||
return new GenericSectionSpriteTicker<>(SpriteUtil::markSpriteActive);
|
return new GenericSectionSpriteTicker<>(SpriteUtil::markSpriteActive);
|
||||||
|
|||||||
-23
@@ -47,8 +47,6 @@ public class ModernRenderSectionManager extends RenderSectionManager {
|
|||||||
@Getter
|
@Getter
|
||||||
private final ClonedChunkSectionCache sectionCache;
|
private final ClonedChunkSectionCache sectionCache;
|
||||||
|
|
||||||
private final ReferenceSet<RenderSection> sectionsWithGlobalEntities = new ReferenceOpenHashSet<>();
|
|
||||||
|
|
||||||
protected ModernRenderSectionManager(RenderPassConfiguration<RenderType> configuration, ClientLevel world, int renderDistance, CommandList commandList) {
|
protected ModernRenderSectionManager(RenderPassConfiguration<RenderType> configuration, ClientLevel world, int renderDistance, CommandList commandList) {
|
||||||
super(configuration,
|
super(configuration,
|
||||||
() -> new ModernChunkBuildContext(world, configuration),
|
() -> new ModernChunkBuildContext(world, configuration),
|
||||||
@@ -130,27 +128,6 @@ public class ModernRenderSectionManager extends RenderSectionManager {
|
|||||||
return new GenericSectionSpriteTicker<>(SpriteUtil::markSpriteActive);
|
return new GenericSectionSpriteTicker<>(SpriteUtil::markSpriteActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateSectionInfo(RenderSection render, BuiltRenderSectionData info) {
|
|
||||||
super.updateSectionInfo(render, info);
|
|
||||||
|
|
||||||
if (info == null || (info instanceof MinecraftBuiltRenderSectionData<?, ?> mcInfo) && mcInfo.globalBlockEntities.isEmpty()) {
|
|
||||||
this.sectionsWithGlobalEntities.remove(render);
|
|
||||||
} else {
|
|
||||||
this.sectionsWithGlobalEntities.add(render);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() {
|
|
||||||
super.destroy();
|
|
||||||
this.sectionsWithGlobalEntities.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<RenderSection> getSectionsWithGlobalEntities() {
|
|
||||||
return ReferenceSets.unmodifiable(this.sectionsWithGlobalEntities);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean useFogOcclusion() {
|
protected boolean useFogOcclusion() {
|
||||||
return Celeritas.options().performance.useFogOcclusion;
|
return Celeritas.options().performance.useFogOcclusion;
|
||||||
|
|||||||
+8
-10
@@ -39,25 +39,25 @@ public class ModernRenderPassConfigurationBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TerrainRenderPass.TerrainRenderPassBuilder builderForRenderType(RenderType chunkRenderType) {
|
private static TerrainRenderPass.TerrainRenderPassBuilder builderForRenderType(RenderType chunkRenderType, ChunkVertexType vertexType) {
|
||||||
return TerrainRenderPass.builder().pipelineState(new ModernRenderTypePipelineState(chunkRenderType));
|
return TerrainRenderPass.builder().pipelineState(new ModernRenderTypePipelineState(chunkRenderType)).vertexType(vertexType).primitiveType(QuadPrimitiveType.TRIANGULATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RenderPassConfiguration<RenderType> build(ChunkVertexType vertexType) {
|
public static RenderPassConfiguration<RenderType> build(ChunkVertexType vertexType) {
|
||||||
// First, build the main passes
|
// First, build the main passes
|
||||||
TerrainRenderPass solidPass, cutoutMippedPass, translucentPass, tripwirePass;
|
TerrainRenderPass solidPass, cutoutMippedPass, translucentPass, tripwirePass;
|
||||||
|
|
||||||
solidPass = builderForRenderType(RenderType.solid())
|
solidPass = builderForRenderType(RenderType.solid(), vertexType)
|
||||||
.name("solid")
|
.name("solid")
|
||||||
.fragmentDiscard(false)
|
.fragmentDiscard(false)
|
||||||
.useReverseOrder(false)
|
.useReverseOrder(false)
|
||||||
.build();
|
.build();
|
||||||
cutoutMippedPass = builderForRenderType(RenderType.cutoutMipped())
|
cutoutMippedPass = builderForRenderType(RenderType.cutoutMipped(), vertexType)
|
||||||
.name("cutout_mipped")
|
.name("cutout_mipped")
|
||||||
.fragmentDiscard(true)
|
.fragmentDiscard(true)
|
||||||
.useReverseOrder(false)
|
.useReverseOrder(false)
|
||||||
.build();
|
.build();
|
||||||
translucentPass = builderForRenderType(RenderType.translucent())
|
translucentPass = builderForRenderType(RenderType.translucent(), vertexType)
|
||||||
.name("translucent")
|
.name("translucent")
|
||||||
.fragmentDiscard(false)
|
.fragmentDiscard(false)
|
||||||
.useReverseOrder(true)
|
.useReverseOrder(true)
|
||||||
@@ -65,7 +65,7 @@ public class ModernRenderPassConfigurationBuilder {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
//? if >=1.16 {
|
//? if >=1.16 {
|
||||||
tripwirePass = builderForRenderType(RenderType.tripwire())
|
tripwirePass = builderForRenderType(RenderType.tripwire(), vertexType)
|
||||||
.name("tripwire")
|
.name("tripwire")
|
||||||
.fragmentDiscard(true)
|
.fragmentDiscard(true)
|
||||||
.useReverseOrder(true)
|
.useReverseOrder(true)
|
||||||
@@ -95,7 +95,7 @@ public class ModernRenderPassConfigurationBuilder {
|
|||||||
} else {
|
} else {
|
||||||
TerrainRenderPass cutoutPass;
|
TerrainRenderPass cutoutPass;
|
||||||
|
|
||||||
cutoutPass = builderForRenderType(RenderType.cutout())
|
cutoutPass = builderForRenderType(RenderType.cutout(), vertexType)
|
||||||
.name("cutout")
|
.name("cutout")
|
||||||
.fragmentDiscard(true)
|
.fragmentDiscard(true)
|
||||||
.useReverseOrder(false)
|
.useReverseOrder(false)
|
||||||
@@ -126,10 +126,8 @@ public class ModernRenderPassConfigurationBuilder {
|
|||||||
var vanillaRenderStageMap = vanillaRenderStages.build();
|
var vanillaRenderStageMap = vanillaRenderStages.build();
|
||||||
var allPasses = vanillaRenderStageMap.values().stream().distinct().toList();
|
var allPasses = vanillaRenderStageMap.values().stream().distinct().toList();
|
||||||
|
|
||||||
return new RenderPassConfiguration<>(vertexType,
|
return new RenderPassConfiguration<>(renderTypeToMaterialMap,
|
||||||
renderTypeToMaterialMap,
|
|
||||||
vanillaRenderStageMap.asMap(),
|
vanillaRenderStageMap.asMap(),
|
||||||
pass -> QuadPrimitiveType.INSTANCE,
|
|
||||||
solidMaterial,
|
solidMaterial,
|
||||||
cutoutMippedMaterial,
|
cutoutMippedMaterial,
|
||||||
translucentMaterial);
|
translucentMaterial);
|
||||||
|
|||||||
+1
-1
@@ -250,7 +250,7 @@ public class IrisChunkProgramOverrides {
|
|||||||
int handle = ((GlObject) shader).handle();
|
int handle = ((GlObject) shader).handle();
|
||||||
ShaderBindingContext contextExt = shader;
|
ShaderBindingContext contextExt = shader;
|
||||||
GLDebug.nameObject(GL43C.GL_PROGRAM, handle, "sodium-terrain-" + pass.toString().toLowerCase(Locale.ROOT));
|
GLDebug.nameObject(GL43C.GL_PROGRAM, handle, "sodium-terrain-" + pass.toString().toLowerCase(Locale.ROOT));
|
||||||
return new IrisChunkShaderInterface(handle, contextExt, pipeline, new ChunkShaderOptions(ChunkFogMode.SMOOTH, pass.toTerrainPass(configuration), vertexType),
|
return new IrisChunkShaderInterface(handle, contextExt, pipeline, new ChunkShaderOptions(ChunkFogMode.SMOOTH, pass.toTerrainPass(configuration)),
|
||||||
tessCShader != null || tessEShader != null, pass == IrisTerrainPass.SHADOW || pass == IrisTerrainPass.SHADOW_CUTOUT, blendOverride, bufferOverrides, alpha, pipeline.getCustomUniforms());
|
tessCShader != null || tessEShader != null, pass == IrisTerrainPass.SHADOW || pass == IrisTerrainPass.SHADOW_CUTOUT, blendOverride, bufferOverrides, alpha, pipeline.getCustomUniforms());
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
+1
-1
@@ -141,7 +141,7 @@ public class IrisChunkShaderInterface implements ChunkShaderInterface {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GlPrimitiveType getPrimitiveType() {
|
public GlPrimitiveType getPrimitiveType() {
|
||||||
return isTess ? GlPrimitiveType.PATCHES : ChunkShaderInterface.super.getPrimitiveType();
|
return isTess ? GlPrimitiveType.PATCHES : GlPrimitiveType.TRIANGLES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in new issue
Block a user