Bilinear interpolation for quad vertex data via geometry shader #12
No files matched your search
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,5 @@
|
|||||||
package org.embeddedt.embeddium.impl.render.chunk;
|
package org.embeddedt.embeddium.impl.render.chunk;
|
||||||
|
|
||||||
import com.google.common.base.Suppliers;
|
|
||||||
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.*;
|
import it.unimi.dsi.fastutil.objects.*;
|
||||||
@@ -36,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;
|
||||||
@@ -714,7 +714,7 @@ public abstract class RenderSectionManager {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final Supplier<Object2LongMap<TerrainRenderPass>> renderPassTimingsDebounced = Suppliers.memoizeWithExpiration(this::computeRenderPassTimingsMap, 1, TimeUnit.SECONDS);
|
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<>();
|
||||||
|
|||||||
+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);
|
||||||
|
|||||||
+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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -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;
|
||||||
@@ -38,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;
|
||||||
|
|||||||
+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;
|
||||||
|
|||||||
+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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user