Bilinear interpolation for quad vertex data via geometry shader #12

Closed
embeddedt wants to merge 18 commits from geotesting into stonecutter
pull from: geotesting
10 changed files with 86 additions and 25 deletions
Showing only changes of commit aa1d71e275 - Show all commits

No files matched your search

-1
View File
@@ -26,7 +26,6 @@ dependencies {
compileOnly "org.jetbrains:annotations:24.1.0"
compileOnly("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-tree:9.6")
compileOnly("org.ow2.asm:asm-util:9.6")
@@ -1,6 +1,5 @@
package org.embeddedt.embeddium.impl.asm;
import com.google.common.base.Suppliers;
import org.objectweb.asm.*;
import org.objectweb.asm.util.CheckClassAdapter;
@@ -10,11 +9,14 @@ import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.function.Supplier;
public class ProxyClassGenerator<DELEGATE, INTERFACE> {
// DEFINE_CLASS is borrowed from FerriteCore under MIT as a small utility
private static final Supplier<Definer> DEFINE_CLASS = Suppliers.memoize(() -> {
private static Definer DEFINER;
private static synchronized Definer getDefiner() {
if (DEFINER != null) {
return DEFINER;
}
try {
// Try to create a Java 9+ style class definer
// 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());
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) {
try {
// If that fails, try a Java 8 style definer
@@ -32,13 +34,14 @@ public class ProxyClassGenerator<DELEGATE, INTERFACE> {
);
defineClass.setAccessible(true);
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) {
// Fail if neither works
throw new RuntimeException(e);
}
}
});
return DEFINER;
}
private final Class<?> delegateClass;
private final Class<?> proxyClass;
@@ -145,7 +148,7 @@ public class ProxyClassGenerator<DELEGATE, INTERFACE> {
private Class<?> createWrapperClass() {
byte[] bytes = createWrapperClassBytecode();
try {
return DEFINE_CLASS.get().define(bytes, this.proxyClassName.replace('/', '.'));
return getDefiner().define(bytes, this.proxyClassName.replace('/', '.'));
} catch(Exception e) {
throw new RuntimeException("Error defining WorldSlice wrapper", e);
}
@@ -1,6 +1,5 @@
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.Long2ReferenceOpenHashMap;
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.render.ShaderModBridge;
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.Nullable;
import org.joml.Vector3d;
@@ -714,7 +714,7 @@ public abstract class RenderSectionManager {
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() {
List<String> list = new ArrayList<>();
@@ -1,6 +1,5 @@
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.tasks.ChunkBuilderTask;
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,
Consumer<ChunkJobResult<OUTPUT>> consumer)
{
Preconditions.checkNotNull(task, "Task must be non-null");
Objects.requireNonNull(task, "Task must be non-null");
if (!this.queue.isRunning()) {
throw new IllegalStateException("Executor is stopped");
@@ -1,6 +1,5 @@
package org.embeddedt.embeddium.impl.render.chunk.compile.executor;
import com.google.common.base.Preconditions;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayDeque;
import java.util.Collection;
@@ -20,7 +19,9 @@ class ChunkJobQueue {
}
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) {
this.jobs.addFirst(job);
@@ -1,11 +1,11 @@
package org.embeddedt.embeddium.impl.render.chunk.data;
import com.google.common.collect.Iterators;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
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.RenderVisualsService;
import org.embeddedt.embeddium.impl.render.chunk.lists.SortedRenderLists;
import org.embeddedt.embeddium.impl.util.iterator.ConcatenatedIterator;
import java.util.*;
import java.util.function.Consumer;
@@ -91,7 +91,7 @@ public class MinecraftBuiltRenderSectionData<SPRITE, BLOCKENTITY> extends BuiltR
if(iterators.isEmpty()) {
return Collections.emptyIterator();
} else {
return Iterators.concat(iterators.iterator());
return new ConcatenatedIterator<>(iterators.iterator());
}
}
@@ -1,6 +1,5 @@
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.objects.Reference2ReferenceOpenHashMap;
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;
static {
Preconditions.checkArgument(MathUtil.isPowerOfTwo(REGION_WIDTH));
Preconditions.checkArgument(MathUtil.isPowerOfTwo(REGION_HEIGHT));
Preconditions.checkArgument(MathUtil.isPowerOfTwo(REGION_LENGTH));
if(!MathUtil.isPowerOfTwo(REGION_WIDTH) || !MathUtil.isPowerOfTwo(REGION_HEIGHT) || !MathUtil.isPowerOfTwo(REGION_LENGTH)) {
throw new IllegalStateException("Region width/height/length are not powers of two");
}
}
private final StagingBuffer stagingBuffer;
@@ -1,6 +1,5 @@
package org.embeddedt.embeddium.impl.render.chunk.shader;
import com.google.common.collect.ImmutableList;
import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext;
import org.lwjgl.opengl.GL20;
@@ -8,9 +7,9 @@ import java.util.List;
import java.util.function.Function;
public enum ChunkFogMode {
NONE(ChunkShaderFogComponent.None::new, ImmutableList.of()),
EXP2(ChunkShaderFogComponent.Exp2::new, ImmutableList.of("USE_FOG", "USE_FOG_EXP2")),
SMOOTH(ChunkShaderFogComponent.Smooth::new, ImmutableList.of("USE_FOG", "USE_FOG_SMOOTH"));
NONE(ChunkShaderFogComponent.None::new, List.of()),
EXP2(ChunkShaderFogComponent.Exp2::new, List.of("USE_FOG", "USE_FOG_EXP2")),
SMOOTH(ChunkShaderFogComponent.Smooth::new, List.of("USE_FOG", "USE_FOG_SMOOTH"));
private final Function<ShaderBindingContext, ChunkShaderFogComponent> factory;
private final List<String> defines;
@@ -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();
}
}
}
@@ -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;
}
}