Only a few moves left

- flywheel stuff only barely depends on create
 - start drafting what multiple backends could look like
This commit is contained in:
JozsefA 2021-05-11 11:02:43 -07:00
parent 70401e4ac4
commit f6937ffb0c
46 changed files with 460 additions and 84 deletions

View file

@ -20,19 +20,17 @@ import org.lwjgl.opengl.GLCapabilities;
import com.jozufozu.flywheel.backend.core.BasicProgram;
import com.jozufozu.flywheel.backend.core.CrumblingRenderer;
import com.jozufozu.flywheel.backend.core.EffectsContext;
import com.jozufozu.flywheel.backend.core.WorldContext;
import com.jozufozu.flywheel.backend.core.WorldTileRenderer;
import com.jozufozu.flywheel.backend.effects.EffectsHandler;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import com.jozufozu.flywheel.backend.gl.shader.ProgramSpec;
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
import com.jozufozu.flywheel.backend.instancing.IFlywheelWorld;
import com.jozufozu.flywheel.backend.instancing.InstancedModel;
import com.jozufozu.flywheel.backend.instancing.MaterialSpec;
import com.jozufozu.flywheel.util.WorldAttached;
import com.simibubi.create.content.contraptions.KineticDebugger;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.utility.WorldAttached;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import net.minecraft.client.Minecraft;
@ -65,7 +63,6 @@ public class Backend {
public static GLCapabilities capabilities;
public static GlCompat compat;
public static EffectsHandler effects;
public static WorldAttached<WorldTileRenderer<BasicProgram>> tileRenderer = new WorldAttached<>(() -> new WorldTileRenderer<>(WorldContext.INSTANCE));
public static LazyValue<Vector<CrumblingRenderer>> blockBreaking = new LazyValue<>(() -> {
Vector<CrumblingRenderer> renderers = new Vector<>(10);
@ -86,7 +83,6 @@ public class Backend {
static {
register(WorldContext.INSTANCE);
register(WorldContext.CRUMBLING);
register(EffectsContext.INSTANCE);
listeners.refreshListener(world -> {
if (canUseInstancing() && world != null) {
@ -191,11 +187,6 @@ public class Backend {
compat.instancedArraysSupported();
enabled = AllConfigs.CLIENT.experimentalRendering.get() && !OptifineHandler.usingShaders();
if (enabled) {
if (effects != null) effects.delete();
effects = new EffectsHandler();
}
}
public static void tick() {
@ -211,7 +202,6 @@ public class Backend {
public static void renderLayer(ClientWorld world, RenderType layer, Matrix4f viewProjection, double cameraX, double cameraY, double cameraZ) {
if (!canUseInstancing(world)) return;
WorldTileRenderer<BasicProgram> renderer = tileRenderer.get(world);
if (renderer == null) return;
layer.startDrawing();

View file

@ -2,8 +2,8 @@ package com.jozufozu.flywheel.backend.core.materials;
import java.nio.ByteBuffer;
import com.jozufozu.flywheel.backend.RenderUtil;
import com.jozufozu.flywheel.backend.instancing.InstancedModel;
import com.jozufozu.flywheel.util.RenderUtil;
import com.mojang.blaze3d.matrix.MatrixStack;
public class ModelData extends BasicData {

View file

@ -17,9 +17,9 @@ import static org.lwjgl.opengl.GL20.glUseProgram;
import java.util.Collection;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.RenderUtil;
import com.jozufozu.flywheel.backend.gl.GlObject;
import com.jozufozu.flywheel.backend.gl.attrib.IVertexAttrib;
import com.jozufozu.flywheel.util.RenderUtil;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Matrix4f;

View file

@ -1,31 +1,42 @@
package com.jozufozu.flywheel.backend.instancing;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.Pair;
import org.lwjgl.opengl.GL11;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.RenderUtil;
import com.jozufozu.flywheel.backend.core.BasicProgram;
import com.jozufozu.flywheel.backend.core.PartialModel;
import com.jozufozu.flywheel.backend.gl.shader.ProgramSpec;
import com.jozufozu.flywheel.backend.gl.shader.ShaderCallback;
import com.jozufozu.flywheel.util.BakedQuadWrapper;
import com.jozufozu.flywheel.util.RenderUtil;
import com.jozufozu.flywheel.util.VirtualEmptyModelData;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.foundation.render.SuperByteBufferCache;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockModelRenderer;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.model.BakedQuad;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraftforge.client.model.data.IModelData;
public class RenderMaterial<P extends BasicProgram, MODEL extends InstancedModel<?>> {
@ -120,9 +131,37 @@ public class RenderMaterial<P extends BasicProgram, MODEL extends InstancedModel
}
private MODEL buildModel(IBakedModel model, BlockState referenceState, MatrixStack ms) {
BufferBuilder builder = SuperByteBufferCache.getBufferBuilder(model, referenceState, ms);
BufferBuilder builder = getBufferBuilder(model, referenceState, ms);
return factory.makeModel(renderer, builder);
}
private static final Direction[] dirs;
static {
Direction[] directions = Direction.values();
dirs = Arrays.copyOf(directions, directions.length + 1);
}
public static BufferBuilder getBufferBuilder(IBakedModel model, BlockState referenceState, MatrixStack ms) {
Minecraft mc = Minecraft.getInstance();
BlockRendererDispatcher dispatcher = mc.getBlockRendererDispatcher();
BlockModelRenderer blockRenderer = dispatcher.getBlockModelRenderer();
BufferBuilder builder = new BufferBuilder(512);
BakedQuadWrapper quadReader = new BakedQuadWrapper();
IModelData modelData = model.getModelData(mc.world, BlockPos.ZERO.up(255), referenceState, VirtualEmptyModelData.INSTANCE);
List<BakedQuad> quads = Arrays.stream(dirs)
.flatMap(dir -> model.getQuads(referenceState, dir, mc.world.rand, modelData).stream())
.collect(Collectors.toList());
builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
blockRenderer.renderModel(mc.world, model, referenceState, BlockPos.ZERO.up(255), ms, builder, true,
mc.world.rand, 42, OverlayTexture.DEFAULT_UV, VirtualEmptyModelData.INSTANCE);
builder.finishDrawing();
return builder;
}
}

View file

@ -1,8 +1,8 @@
package com.jozufozu.flywheel.backend.light;
import static com.jozufozu.flywheel.backend.RenderUtil.isPowerOf2;
import static com.jozufozu.flywheel.util.RenderUtil.isPowerOf2;
import com.jozufozu.flywheel.backend.RenderUtil;
import com.jozufozu.flywheel.util.RenderUtil;
import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB;

View file

@ -3,7 +3,7 @@ package com.jozufozu.flywheel.backend.light;
import java.util.WeakHashMap;
import java.util.function.LongConsumer;
import com.simibubi.create.foundation.utility.WeakHashSet;
import com.jozufozu.flywheel.util.WeakHashSet;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;

View file

@ -0,0 +1,216 @@
package com.jozufozu.flywheel.util;
import net.minecraft.client.renderer.model.BakedQuad;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.math.vector.Vector3f;
public class BakedQuadWrapper {
private final FormatCache formatCache = new FormatCache();
private BakedQuad quad;
private int[] vertexData;
public BakedQuadWrapper() {
}
public BakedQuadWrapper(BakedQuad quad) {
this.quad = quad;
this.vertexData = quad.getVertexData();
}
public void setQuad(BakedQuad quad) {
this.quad = quad;
this.vertexData = this.quad.getVertexData();
}
public static BakedQuadWrapper of(BakedQuad quad) {
return new BakedQuadWrapper(quad);
}
public void refreshFormat() {
formatCache.refresh();
}
public BakedQuad getQuad() {
return quad;
}
public void clear() {
quad = null;
vertexData = null;
}
// Getters
public float getPosX(int vertexIndex) {
return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.position]);
}
public float getPosY(int vertexIndex) {
return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.position + 1]);
}
public float getPosZ(int vertexIndex) {
return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.position + 2]);
}
public Vector3f getPos(int vertexIndex) {
return new Vector3f(getPosX(vertexIndex), getPosY(vertexIndex), getPosZ(vertexIndex));
}
public void copyPos(int vertexIndex, Vector3f pos) {
pos.set(getPosX(vertexIndex), getPosY(vertexIndex), getPosZ(vertexIndex));
}
public int getColor(int vertexIndex) {
return vertexData[vertexIndex * formatCache.vertexSize + formatCache.color];
}
public float getTexU(int vertexIndex) {
return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.texture]);
}
public float getTexV(int vertexIndex) {
return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.texture + 1]);
}
public Vector2f getTex(int vertexIndex) {
return new Vector2f(getTexU(vertexIndex), getTexV(vertexIndex));
}
public int getLight(int vertexIndex) {
return vertexData[vertexIndex * formatCache.vertexSize + formatCache.light];
}
public float getNormalX(int vertexIndex) {
return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.normal]);
}
public float getNormalY(int vertexIndex) {
return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.normal + 1]);
}
public float getNormalZ(int vertexIndex) {
return Float.intBitsToFloat(vertexData[vertexIndex * formatCache.vertexSize + formatCache.normal + 2]);
}
public Vector3f getNormal(int vertexIndex) {
return new Vector3f(getNormalX(vertexIndex), getNormalY(vertexIndex), getNormalZ(vertexIndex));
}
public void copyNormal(int vertexIndex, Vector3f normal) {
normal.set(getNormalX(vertexIndex), getNormalY(vertexIndex), getNormalZ(vertexIndex));
}
// Setters
public void setPosX(int vertexIndex, float x) {
vertexData[vertexIndex * formatCache.vertexSize + formatCache.position] = Float.floatToRawIntBits(x);
}
public void setPosY(int vertexIndex, float y) {
vertexData[vertexIndex * formatCache.vertexSize + formatCache.position + 1] = Float.floatToRawIntBits(y);
}
public void setPosZ(int vertexIndex, float z) {
vertexData[vertexIndex * formatCache.vertexSize + formatCache.position + 2] = Float.floatToRawIntBits(z);
}
public void setPos(int vertexIndex, float x, float y, float z) {
setPosX(vertexIndex, x);
setPosY(vertexIndex, y);
setPosZ(vertexIndex, z);
}
public void setPos(int vertexIndex, Vector3f pos) {
setPos(vertexIndex, pos.getX(), pos.getY(), pos.getZ());
}
public void setColor(int vertexIndex, int color) {
vertexData[vertexIndex * formatCache.vertexSize + formatCache.color] = color;
}
public void setTexU(int vertexIndex, float u) {
vertexData[vertexIndex * formatCache.vertexSize + formatCache.texture] = Float.floatToRawIntBits(u);
}
public void setTexV(int vertexIndex, float v) {
vertexData[vertexIndex * formatCache.vertexSize + formatCache.texture + 1] = Float.floatToRawIntBits(v);
}
public void setTex(int vertexIndex, float u, float v) {
setTexU(vertexIndex, u);
setTexV(vertexIndex, v);
}
public void setTex(int vertexIndex, Vector2f tex) {
setTex(vertexIndex, tex.x, tex.y);
}
public void setLight(int vertexIndex, int light) {
vertexData[vertexIndex * formatCache.vertexSize + formatCache.light] = light;
}
public void setNormalX(int vertexIndex, float normalX) {
vertexData[vertexIndex * formatCache.vertexSize + formatCache.normal] = Float.floatToRawIntBits(normalX);
}
public void setNormalY(int vertexIndex, float normalY) {
vertexData[vertexIndex * formatCache.vertexSize + formatCache.normal + 1] = Float.floatToRawIntBits(normalY);
}
public void setNormalZ(int vertexIndex, float normalZ) {
vertexData[vertexIndex * formatCache.vertexSize + formatCache.normal + 2] = Float.floatToRawIntBits(normalZ);
}
public void setNormal(int vertexIndex, float normalX, float normalY, float normalZ) {
setNormalX(vertexIndex, normalX);
setNormalY(vertexIndex, normalY);
setNormalZ(vertexIndex, normalZ);
}
public void setNormal(int vertexIndex, Vector3f normal) {
setNormal(vertexIndex, normal.getX(), normal.getY(), normal.getZ());
}
private static class FormatCache {
private static final VertexFormat FORMAT = DefaultVertexFormats.BLOCK;
public FormatCache() {
refresh();
}
// Integer size
public int vertexSize;
// Element integer offsets
public int position;
public int color;
public int texture;
public int light;
public int normal;
public void refresh() {
vertexSize = FORMAT.getIntegerSize();
for (int elementId = 0; elementId < FORMAT.getElements().size(); elementId++) {
VertexFormatElement element = FORMAT.getElements().get(elementId);
int intOffset = FORMAT.getOffset(elementId) / Integer.BYTES;
if (element.getUsage() == VertexFormatElement.Usage.POSITION) {
position = intOffset;
} else if (element.getUsage() == VertexFormatElement.Usage.COLOR) {
color = intOffset;
} else if (element.getUsage() == VertexFormatElement.Usage.UV) {
if (element.getIndex() == 0) {
texture = intOffset;
} else if (element.getIndex() == 2) {
light = intOffset;
}
} else if (element.getUsage() == VertexFormatElement.Usage.NORMAL) {
normal = intOffset;
}
}
}
}
}

View file

@ -1,14 +1,14 @@
package com.jozufozu.flywheel.backend;
package com.jozufozu.flywheel.util;
import java.util.function.Supplier;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.MatrixStacker;
import net.minecraft.util.Direction;
import net.minecraft.util.math.vector.Matrix3f;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.math.vector.Vector3f;
public class RenderUtil {
public static int nextPowerOf2(int a) {
@ -88,11 +88,15 @@ public class RenderUtil {
public static Supplier<MatrixStack> rotateToFace(Direction facing) {
return () -> {
MatrixStack stack = new MatrixStack();
MatrixStacker.of(stack)
.centre()
.rotateY(AngleHelper.horizontalAngle(facing))
.rotateX(AngleHelper.verticalAngle(facing))
.unCentre();
// MatrixStacker.of(stack)
// .centre()
// .rotateY(AngleHelper.horizontalAngle(facing))
// .rotateX(AngleHelper.verticalAngle(facing))
// .unCentre();
stack.peek().getModel().setTranslation(0.5f, 0.5f, 0.5f);
stack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(AngleHelper.horizontalAngle(facing)));
stack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(AngleHelper.verticalAngle(facing)));
stack.translate(-0.5f, -0.5f, -0.5f);
return stack;
};
}

View file

@ -1,4 +1,4 @@
package com.simibubi.create.foundation.utility;
package com.jozufozu.flywheel.util;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.model.data.ModelProperty;

View file

@ -1,4 +1,4 @@
package com.simibubi.create.foundation.utility;
package com.jozufozu.flywheel.util;
import java.util.AbstractSet;
import java.util.Collection;

View file

@ -0,0 +1,41 @@
package com.jozufozu.flywheel.util;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import javax.annotation.Nonnull;
import net.minecraft.world.IWorld;
import net.minecraftforge.common.util.NonNullSupplier;
public class WorldAttached<T> {
Map<IWorld, T> attached;
private final NonNullSupplier<T> factory;
public WorldAttached(NonNullSupplier<T> factory) {
this.factory = factory;
attached = new HashMap<>();
}
@Nonnull
public T get(IWorld world) {
T t = attached.get(world);
if (t != null)
return t;
T entry = factory.get();
put(world, entry);
return entry;
}
public void put(IWorld world, T entry) {
attached.put(world, entry);
}
public void forEach(Consumer<T> consumer) {
attached.values()
.forEach(consumer);
}
}

View file

@ -28,6 +28,7 @@ import com.simibubi.create.foundation.ponder.content.PonderIndex;
import com.simibubi.create.foundation.ponder.elements.WorldSectionElement;
import com.simibubi.create.foundation.render.AllMaterialSpecs;
import com.simibubi.create.foundation.render.AllProgramSpecs;
import com.simibubi.create.foundation.render.CreateFlywheelHandler;
import com.simibubi.create.foundation.render.SuperByteBufferCache;
import com.simibubi.create.foundation.utility.ghost.GhostBlocks;
import com.simibubi.create.foundation.utility.outliner.Outliner;
@ -81,7 +82,7 @@ public class CreateClient {
modEventBus.addListener(AllParticleTypes::registerFactories);
Backend.init();
ContraptionRenderDispatcher.init();
CreateFlywheelHandler.init();
OptifineHandler.init();
}

View file

@ -26,7 +26,6 @@ import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair;
import com.jozufozu.flywheel.backend.instancing.IFlywheelWorld;
import com.jozufozu.flywheel.backend.light.EmptyLighter;
import com.jozufozu.flywheel.backend.light.GridAlignedBB;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllMovementBehaviours;
@ -50,6 +49,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.pul
import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock;
import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock;
import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity;
import com.simibubi.create.content.contraptions.components.structureMovement.render.EmptyLighter;
import com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity;
import com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock;
import com.simibubi.create.content.contraptions.relays.belt.BeltBlock;

View file

@ -132,7 +132,7 @@ public class ControlledContraptionEntity extends AbstractContraptionEntity {
protected void tickContraption() {
prevAngle = angle;
tickActors();
if (controllerPos == null)
return;
if (!world.isBlockPresent(controllerPos))

View file

@ -30,4 +30,4 @@ public class DirectionalExtenderScrollOptionSlot extends CenteredSideValueBoxTra
MatrixStacker.of(ms).rotateY(AngleHelper.horizontalAngle(state.get(BlockStateProperties.FACING)) - 90);
super.rotate(state, ms);
}
}
}

View file

@ -1,8 +1,8 @@
package com.jozufozu.flywheel.backend.core;
package com.simibubi.create.content.contraptions.components.structureMovement.render;
import com.jozufozu.flywheel.backend.ShaderLoader;
import com.jozufozu.flywheel.backend.core.WorldContext;
import com.jozufozu.flywheel.backend.gl.shader.FogSensitiveProgram;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionProgram;
import com.simibubi.create.foundation.render.AllProgramSpecs;
import net.minecraft.util.ResourceLocation;

View file

@ -7,7 +7,6 @@ import javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.Pair;
import com.jozufozu.flywheel.backend.core.ContraptionContext;
import com.jozufozu.flywheel.backend.instancing.InstancedModel;
import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer;
import com.jozufozu.flywheel.backend.instancing.RenderMaterial;

View file

@ -9,7 +9,6 @@ import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL40;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.core.ContraptionContext;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllMovementBehaviours;
import com.simibubi.create.CreateClient;
@ -57,13 +56,6 @@ public class ContraptionRenderDispatcher {
public static final Compartment<Pair<Contraption, Integer>> CONTRAPTION = new Compartment<>();
protected static PlacementSimulationWorld renderWorld;
public static void init() {
Backend.register(ContraptionContext.INSTANCE);
Backend.listeners.renderLayerListener(ContraptionRenderDispatcher::renderLayer);
Backend.listeners.setupFrameListener(ContraptionRenderDispatcher::beginFrame);
Backend.listeners.refreshListener($ -> ContraptionRenderDispatcher.invalidateAll());
}
public static void tick() {
if (Minecraft.getInstance().isGamePaused()) return;

View file

@ -1,5 +1,6 @@
package com.jozufozu.flywheel.backend.light;
package com.simibubi.create.content.contraptions.components.structureMovement.render;
import com.jozufozu.flywheel.backend.light.GridAlignedBB;
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter;

View file

@ -1,9 +1,9 @@
package com.jozufozu.flywheel.backend.light;
package com.simibubi.create.content.contraptions.components.structureMovement.render;
import java.util.ArrayList;
import com.jozufozu.flywheel.backend.light.GridAlignedBB;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher;
import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.Pair;

View file

@ -86,9 +86,9 @@ public class BasinRenderer extends SmartTileEntityRenderer<BasinTileEntity> {
for (int i = 0; i <= stack.getCount() / 8; i++) {
ms.push();
Vector3d vec = VecHelper.offsetRandomly(Vector3d.ZERO, r, 1 / 16f);
ms.translate(vec.x, vec.y, vec.z);
renderItem(ms, buffer, light, overlay, stack);
ms.pop();
@ -114,13 +114,13 @@ public class BasinRenderer extends SmartTileEntityRenderer<BasinTileEntity> {
.getBlockState(basin.getPos()
.offset(direction))
.getBlock() instanceof BasinBlock;
for (IntAttached<ItemStack> intAttached : basin.visualizedOutputItems) {
float progress = 1 - (intAttached.getFirst() - partialTicks) / BasinTileEntity.OUTPUT_ANIMATION_TIME;
if (!outToBasin && progress > .35f)
continue;
ms.push();
MatrixStacker.of(ms)
.translate(outVec)

View file

@ -4,8 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import com.jozufozu.flywheel.util.VirtualEmptyModelData;
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
import com.simibubi.create.foundation.utility.VirtualEmptyModelData;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;

View file

@ -1,9 +1,9 @@
package com.simibubi.create.content.curiosities.projector;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.IDynamicInstance;
import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer;
import com.jozufozu.flywheel.backend.instancing.TileEntityInstance;
import com.simibubi.create.foundation.render.effects.EffectsHandler;
public class ChromaticProjectorInstance extends TileEntityInstance<ChromaticProjectorTileEntity> implements IDynamicInstance {
@ -13,7 +13,7 @@ public class ChromaticProjectorInstance extends TileEntityInstance<ChromaticProj
@Override
public void beginFrame() {
Backend.effects.addSphere(tile.getFilter());
EffectsHandler.getInstance().addSphere(tile.getFilter());
}
@Override

View file

@ -2,8 +2,8 @@ package com.simibubi.create.content.curiosities.projector;
import java.util.Vector;
import com.jozufozu.flywheel.backend.effects.FilterSphere;
import com.jozufozu.flywheel.backend.instancing.IInstanceRendered;
import com.simibubi.create.foundation.render.effects.FilterSphere;
import com.simibubi.create.foundation.tileEntity.SyncedTileEntity;
import net.minecraft.block.BlockState;

View file

@ -6,8 +6,8 @@ import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import com.jozufozu.flywheel.backend.effects.ColorMatrices;
import com.simibubi.create.foundation.gui.AllGuiTextures;
import com.simibubi.create.foundation.render.effects.ColorMatrices;
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueBehaviour;
import com.simibubi.create.foundation.utility.Lang;

View file

@ -3,7 +3,7 @@ package com.simibubi.create.content.curiosities.projector;
import java.util.Iterator;
import java.util.Vector;
import com.jozufozu.flywheel.backend.effects.ColorMatrices;
import com.simibubi.create.foundation.render.effects.ColorMatrices;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;

View file

@ -213,7 +213,7 @@ public class SchematicTransformation {
z.start(pos.getZ());
moveTo(pos);
}
public void moveTo(BlockPos pos) {
moveTo(pos.getX(), pos.getY(), pos.getZ());
}

View file

@ -3,6 +3,7 @@ package com.simibubi.create.foundation.gui;
import javax.annotation.Nullable;
import com.jozufozu.flywheel.backend.core.PartialModel;
import com.jozufozu.flywheel.util.VirtualEmptyModelData;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
@ -12,7 +13,6 @@ import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.simibubi.create.foundation.fluid.FluidRenderer;
import com.simibubi.create.foundation.utility.ColorHelper;
import com.simibubi.create.foundation.utility.VecHelper;
import com.simibubi.create.foundation.utility.VirtualEmptyModelData;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;

View file

@ -11,6 +11,7 @@ import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.OptifineHandler;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.simibubi.create.foundation.render.effects.EffectsHandler;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.ActiveRenderInfo;
@ -100,7 +101,9 @@ public class RenderHooksMixin {
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/WorldRenderer;renderChunkDebugInfo(Lnet/minecraft/client/renderer/ActiveRenderInfo;)V"))
private void applyFilters(MatrixStack stack, float p_228426_2_, long p_228426_3_, boolean p_228426_5_, ActiveRenderInfo p_228426_6_, GameRenderer p_228426_7_, LightTexture p_228426_8_, Matrix4f p_228426_9_, CallbackInfo ci) {
Backend.effects.render(stack.peek().getModel());
EffectsHandler instance = EffectsHandler.getInstance();
if (instance != null)
instance.render(stack.peek().getModel());
}
// Instancing

View file

@ -10,8 +10,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.effects.EffectsHandler;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.foundation.render.effects.EffectsHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ActiveRenderInfo;

View file

@ -524,4 +524,4 @@ public class PonderScene {
this.finished = finished;
}
}
}

View file

@ -261,7 +261,7 @@ public class WorldSectionElement extends AnimatedSceneElement {
((ITickableTileEntity) te).tick();
});
}
@Override
public void whileSkipping(PonderScene scene) {
if (redraw)

View file

@ -0,0 +1,16 @@
package com.simibubi.create.foundation.render;
import com.jozufozu.flywheel.backend.Backend;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionContext;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher;
import com.simibubi.create.foundation.render.effects.EffectsContext;
public class CreateFlywheelHandler {
public static void init() {
Backend.register(ContraptionContext.INSTANCE);
Backend.register(EffectsContext.INSTANCE);
Backend.listeners.renderLayerListener(ContraptionRenderDispatcher::renderLayer);
Backend.listeners.setupFrameListener(ContraptionRenderDispatcher::beginFrame);
Backend.listeners.refreshListener($ -> ContraptionRenderDispatcher.invalidateAll());
}
}

View file

@ -12,8 +12,8 @@ import org.lwjgl.opengl.GL11;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.jozufozu.flywheel.backend.core.PartialModel;
import com.jozufozu.flywheel.util.VirtualEmptyModelData;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.foundation.utility.VirtualEmptyModelData;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;

View file

@ -13,15 +13,19 @@ public class TemplateBuffer {
protected int formatSize;
protected int vertexCount;
public TemplateBuffer() {
}
public TemplateBuffer(BufferBuilder buf) {
Pair<BufferBuilder.DrawState, ByteBuffer> state = buf.popData();
ByteBuffer rendered = state.getSecond();
rendered.order(ByteOrder.nativeOrder()); // Vanilla bug, endianness does not carry over into sliced buffers
formatSize = buf.getVertexFormat()
.getSize();
.getSize();
vertexCount = state.getFirst()
.getCount();
.getCount();
int size = vertexCount * formatSize;
template = ByteBuffer.allocate(size);

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.effects;
package com.simibubi.create.foundation.render.effects;
import com.simibubi.create.foundation.utility.AngleHelper;

View file

@ -1,8 +1,7 @@
package com.jozufozu.flywheel.backend.core;
package com.simibubi.create.foundation.render.effects;
import com.jozufozu.flywheel.backend.ShaderContext;
import com.jozufozu.flywheel.backend.ShaderLoader;
import com.jozufozu.flywheel.backend.effects.SphereFilterProgram;
import com.jozufozu.flywheel.backend.gl.shader.ShaderSpecLoader;
import com.jozufozu.flywheel.backend.gl.shader.SingleProgram;
import com.simibubi.create.foundation.render.AllProgramSpecs;

View file

@ -1,18 +1,19 @@
package com.jozufozu.flywheel.backend.effects;
package com.simibubi.create.foundation.render.effects;
import java.util.ArrayList;
import javax.annotation.Nullable;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.RenderUtil;
import com.jozufozu.flywheel.backend.core.EffectsContext;
import com.jozufozu.flywheel.backend.gl.GlBuffer;
import com.jozufozu.flywheel.backend.gl.GlPrimitiveType;
import com.jozufozu.flywheel.backend.gl.GlVertexArray;
import com.jozufozu.flywheel.util.RenderUtil;
import com.simibubi.create.foundation.render.AllProgramSpecs;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
@ -27,6 +28,22 @@ import net.minecraft.util.math.vector.Vector3d;
public class EffectsHandler {
private static EffectsHandler instance;
@Nullable
public static EffectsHandler getInstance() {
if (Backend.available() && instance == null) {
instance = new EffectsHandler();
}
if (!Backend.available() && instance != null) {
instance.delete();
instance = null;
}
return instance;
}
public static float getNearPlane() {
return 0.05f;
}

View file

@ -1,8 +1,8 @@
package com.jozufozu.flywheel.backend.effects;
package com.simibubi.create.foundation.render.effects;
import java.nio.FloatBuffer;
import com.jozufozu.flywheel.backend.RenderUtil;
import com.jozufozu.flywheel.util.RenderUtil;
import net.minecraft.util.math.vector.Matrix4f;

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.effects;
package com.simibubi.create.foundation.render.effects;
import com.jozufozu.flywheel.backend.gl.attrib.CommonAttributes;
import com.jozufozu.flywheel.backend.gl.attrib.IAttribSpec;

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.effects;
package com.simibubi.create.foundation.render.effects;
import java.nio.FloatBuffer;
import java.util.ArrayList;

View file

@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;
import javax.annotation.Nullable;
@ -41,9 +40,4 @@ public class WorldAttached<T> {
attached.put(world, entry);
}
public void forEach(Consumer<T> consumer) {
attached.values()
.forEach(consumer);
}
}

View file

@ -10,10 +10,10 @@ import javax.annotation.Nullable;
import org.lwjgl.system.MemoryStack;
import com.jozufozu.flywheel.util.VirtualEmptyModelData;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer;
import com.simibubi.create.foundation.utility.VirtualEmptyModelData;
import com.simibubi.create.foundation.utility.placement.PlacementHelpers;
import net.minecraft.block.BlockState;

View file

@ -51,7 +51,7 @@ public abstract class Outline {
float lineWidth = params.getLineWidth();
if (lineWidth == 0)
return;
IVertexBuilder builder = buffer.getBuffer(RenderTypes.getOutlineSolid());
Vector3d diff = end.subtract(start);

View file

@ -0,0 +1,17 @@
#version 110
#FLWPrefixFields(FLWVertexData, attribute __a_)
#FLWPrefixFields(FLWInstanceData, attribute __a_)
#FLWPrefixFields(FLWOut, varying __v2f_)
void main() {
FLWVertexData v;
#FLWAssignToFields(FLWVertexData, v, a_)
FLWInstanceData i;
#FLWAssignToFields(FLWInstanceData, i, a_)
FLWOut o = FLWMain(v, i);
#FLWAssignFromFields(FLWOut, o, v2f_)
}

View file

@ -0,0 +1,43 @@
#version 450
#extension GL_NV_mesh_shader : require
layout(local_size_x=32) in;
layout(max_vertices=64, max_primitives=32) out;
layout (std430, binding = 1) buffer _vertices {
FLWVertexData vertices[];
} vb;
struct s_meshlet {
uint vertices[64];
uint indices[96];
uint vertex_count;
uint index_count;
};
layout (std430, binding = 2) buffer _meshlets {
s_meshlet meshlets[];
} mbuf;
layout (location = 0) out PerVertexData {
vec4 color;
} v_out[];// [max_vertices]
void main() {
uint mi = gl_WorkGroupID.x;
uint thread_id = gl_LocalInvocationID.x;
uint primIdx = thread_id * 3;
uint vertStartIdx = thread_id * 2;
gl_MeshVerticesNV[vertStartIdx + 0].gl_Position;
gl_MeshVerticesNV[vertStartIdx + 1].gl_Position;
gl_PrimitiveIndicesNV[primIdx + 0] = mbuf.meshlets[mi].indices[primIdx + 0];
gl_PrimitiveIndicesNV[primIdx + 1] = mbuf.meshlets[mi].indices[primIdx + 1];
gl_PrimitiveIndicesNV[primIdx + 2] = mbuf.meshlets[mi].indices[primIdx + 2];
gl_PrimitiveCountNV = mbuf.meshlets[mi].vertex_count / 2;
}