mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-02-07 02:34:58 +01:00
A Performance on the (Render)Stage
- Add RenderStage enum for better control over when a Material should be rendered - Add getRenderStage method to Material - Replace RenderLayerEvent with RenderStageEvent - Pass more information to RenderContext including camera and projection matrix - Pass RenderContext instead of Camera to all beginFrame-related methods - Remove RenderContext.CURRENT - Remove FrustumMixin and CameraMixin - Remove default BasicModelSupplier constructor - Convert Material to interface and create SimpleMaterial implementation - Move API instancer classes to instancer package - Organize imports
This commit is contained in:
parent
92c017d680
commit
14d3949134
82 changed files with 451 additions and 627 deletions
|
@ -4,8 +4,8 @@ import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
import com.jozufozu.flywheel.backend.ShadersModHandler;
|
|
||||||
import com.jozufozu.flywheel.backend.RenderWork;
|
import com.jozufozu.flywheel.backend.RenderWork;
|
||||||
|
import com.jozufozu.flywheel.backend.ShadersModHandler;
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||||
import com.jozufozu.flywheel.backend.model.MeshPool;
|
import com.jozufozu.flywheel.backend.model.MeshPool;
|
||||||
import com.jozufozu.flywheel.config.BackendTypeArgument;
|
import com.jozufozu.flywheel.config.BackendTypeArgument;
|
||||||
|
@ -28,7 +28,6 @@ import com.jozufozu.flywheel.event.ForgeEvents;
|
||||||
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
||||||
import com.jozufozu.flywheel.mixin.PausedPartialTickAccessor;
|
import com.jozufozu.flywheel.mixin.PausedPartialTickAccessor;
|
||||||
import com.jozufozu.flywheel.vanilla.VanillaInstances;
|
import com.jozufozu.flywheel.vanilla.VanillaInstances;
|
||||||
import com.jozufozu.flywheel.vanilla.effect.ExampleEffect;
|
|
||||||
import com.mojang.logging.LogUtils;
|
import com.mojang.logging.LogUtils;
|
||||||
|
|
||||||
import net.minecraft.commands.synchronization.ArgumentTypes;
|
import net.minecraft.commands.synchronization.ArgumentTypes;
|
||||||
|
@ -92,6 +91,7 @@ public class Flywheel {
|
||||||
forgeEventBus.addListener(CrumblingRenderer::onReloadRenderers);
|
forgeEventBus.addListener(CrumblingRenderer::onReloadRenderers);
|
||||||
|
|
||||||
forgeEventBus.addListener(InstancedRenderDispatcher::onReloadRenderers);
|
forgeEventBus.addListener(InstancedRenderDispatcher::onReloadRenderers);
|
||||||
|
forgeEventBus.addListener(InstancedRenderDispatcher::onRenderStage);
|
||||||
forgeEventBus.addListener(InstancedRenderDispatcher::onBeginFrame);
|
forgeEventBus.addListener(InstancedRenderDispatcher::onBeginFrame);
|
||||||
forgeEventBus.addListener(InstancedRenderDispatcher::tick);
|
forgeEventBus.addListener(InstancedRenderDispatcher::tick);
|
||||||
|
|
||||||
|
|
16
src/main/java/com/jozufozu/flywheel/api/RenderStage.java
Normal file
16
src/main/java/com/jozufozu/flywheel/api/RenderStage.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package com.jozufozu.flywheel.api;
|
||||||
|
|
||||||
|
public enum RenderStage {
|
||||||
|
BEFORE_SKY,
|
||||||
|
AFTER_SKY,
|
||||||
|
BEFORE_TERRAIN,
|
||||||
|
AFTER_SOLID_TERRAIN,
|
||||||
|
BEFORE_ENTITIES,
|
||||||
|
AFTER_ENTITIES,
|
||||||
|
AFTER_BLOCK_ENTITIES,
|
||||||
|
BEFORE_CRUMBLING,
|
||||||
|
AFTER_FINAL_END_BATCH,
|
||||||
|
AFTER_TRANSLUCENT_TERRAIN,
|
||||||
|
AFTER_PARTICLES,
|
||||||
|
AFTER_WEATHER;
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package com.jozufozu.flywheel.api.instance;
|
package com.jozufozu.flywheel.api.instance;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.Instancer;
|
import com.jozufozu.flywheel.api.instancer.Instancer;
|
||||||
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.jozufozu.flywheel.api.instance;
|
package com.jozufozu.flywheel.api.instance;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.Instancer;
|
import com.jozufozu.flywheel.api.instancer.Instancer;
|
||||||
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.jozufozu.flywheel.api;
|
package com.jozufozu.flywheel.api.instancer;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.jozufozu.flywheel.api;
|
package com.jozufozu.flywheel.api.instancer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An instancer is how you interact with an instanced model.
|
* An instancer is how you interact with an instanced model.
|
|
@ -1,4 +1,4 @@
|
||||||
package com.jozufozu.flywheel.api;
|
package com.jozufozu.flywheel.api.instancer;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.core.model.ModelSupplier;
|
import com.jozufozu.flywheel.core.model.ModelSupplier;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.jozufozu.flywheel.api;
|
package com.jozufozu.flywheel.api.instancer;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
package com.jozufozu.flywheel.api.material;
|
package com.jozufozu.flywheel.api.material;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.RenderStage;
|
||||||
import com.jozufozu.flywheel.core.source.FileResolution;
|
import com.jozufozu.flywheel.core.source.FileResolution;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
|
||||||
public record Material(RenderType renderType, FileResolution vertexShader, FileResolution fragmentShader) {
|
public interface Material {
|
||||||
|
RenderStage getRenderStage();
|
||||||
|
|
||||||
|
RenderType getRenderType();
|
||||||
|
|
||||||
|
FileResolution getVertexShader();
|
||||||
|
|
||||||
|
FileResolution getFragmentShader();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.jozufozu.flywheel.api.struct;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.core.layout.BufferLayout;
|
import com.jozufozu.flywheel.core.layout.BufferLayout;
|
||||||
import com.jozufozu.flywheel.core.model.ModelTransformer;
|
import com.jozufozu.flywheel.core.model.ModelTransformer;
|
||||||
import com.jozufozu.flywheel.core.source.FileResolution;
|
import com.jozufozu.flywheel.core.source.FileResolution;
|
||||||
|
|
|
@ -17,7 +17,7 @@ import net.minecraft.world.level.LevelAccessor;
|
||||||
public class Backend {
|
public class Backend {
|
||||||
public static final Logger LOGGER = LogUtils.getLogger();
|
public static final Logger LOGGER = LogUtils.getLogger();
|
||||||
|
|
||||||
public static boolean DUMP_SHADER_SOURCE = System.getProperty("flw.dumpShaderSource") != null;
|
public static final boolean DUMP_SHADER_SOURCE = System.getProperty("flw.dumpShaderSource") != null;
|
||||||
|
|
||||||
private static BackendType TYPE;
|
private static BackendType TYPE;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package com.jozufozu.flywheel.backend.gl;
|
package com.jozufozu.flywheel.backend.gl;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.RenderWork;
|
|
||||||
|
|
||||||
// Utility class for safely dealing with gl object handles.
|
// Utility class for safely dealing with gl object handles.
|
||||||
public abstract class GlObject {
|
public abstract class GlObject {
|
||||||
private static final int INVALID_HANDLE = Integer.MIN_VALUE;
|
private static final int INVALID_HANDLE = Integer.MIN_VALUE;
|
||||||
|
|
|
@ -10,7 +10,6 @@ import org.lwjgl.opengl.GL43;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.gl.GlStateTracker;
|
import com.jozufozu.flywheel.backend.gl.GlStateTracker;
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
|
|
||||||
public enum GlBufferType {
|
public enum GlBufferType {
|
||||||
ARRAY_BUFFER(GL15C.GL_ARRAY_BUFFER),
|
ARRAY_BUFFER(GL15C.GL_ARRAY_BUFFER),
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class GlShader extends GlObject {
|
||||||
private final List<ResourceLocation> parts;
|
private final List<ResourceLocation> parts;
|
||||||
private final ShaderConstants constants;
|
private final ShaderConstants constants;
|
||||||
|
|
||||||
public GlShader(String source, ShaderType type, List<ResourceLocation> parts, ShaderConstants constants) {
|
public GlShader(String source, ShaderType type, List<ResourceLocation> parts, ShaderConstants constants) throws ShaderCompilationException {
|
||||||
this.parts = parts;
|
this.parts = parts;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.constants = constants;
|
this.constants = constants;
|
||||||
|
|
|
@ -3,10 +3,10 @@ package com.jozufozu.flywheel.backend.instancing;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
|
||||||
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
||||||
import com.jozufozu.flywheel.api.instance.Instance;
|
import com.jozufozu.flywheel.api.instance.Instance;
|
||||||
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstanceManager;
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstanceManager;
|
||||||
import com.jozufozu.flywheel.core.structs.FlatLit;
|
import com.jozufozu.flywheel.core.structs.FlatLit;
|
||||||
import com.jozufozu.flywheel.light.LightListener;
|
import com.jozufozu.flywheel.light.LightListener;
|
||||||
|
|
|
@ -3,8 +3,8 @@ package com.jozufozu.flywheel.backend.instancing;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.Instancer;
|
import com.jozufozu.flywheel.api.instancer.Instancer;
|
||||||
import com.jozufozu.flywheel.api.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
|
|
||||||
public abstract class AbstractInstancer<D extends InstancedPart> implements Instancer<D> {
|
public abstract class AbstractInstancer<D extends InstancedPart> implements Instancer<D> {
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
package com.jozufozu.flywheel.backend.instancing;
|
package com.jozufozu.flywheel.backend.instancing;
|
||||||
|
|
||||||
import java.lang.ref.Cleaner;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.FlywheelMemory;
|
|
||||||
import com.jozufozu.flywheel.backend.model.BufferBuilderExtension;
|
import com.jozufozu.flywheel.backend.model.BufferBuilderExtension;
|
||||||
import com.jozufozu.flywheel.backend.model.DirectVertexConsumer;
|
import com.jozufozu.flywheel.backend.model.DirectVertexConsumer;
|
||||||
import com.mojang.blaze3d.platform.MemoryTracker;
|
import com.mojang.blaze3d.platform.MemoryTracker;
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.instancing;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
|
|
||||||
public interface Engine extends RenderDispatcher, InstancerManager {
|
public interface Engine extends RenderDispatcher, InstancerManager {
|
||||||
void attachManagers(InstanceManager<?>... listener);
|
void attachManagers(InstanceManager<?>... listener);
|
||||||
|
|
|
@ -13,6 +13,7 @@ import com.jozufozu.flywheel.backend.instancing.ratelimit.BandedPrimeLimiter;
|
||||||
import com.jozufozu.flywheel.backend.instancing.ratelimit.DistanceUpdateLimiter;
|
import com.jozufozu.flywheel.backend.instancing.ratelimit.DistanceUpdateLimiter;
|
||||||
import com.jozufozu.flywheel.backend.instancing.ratelimit.NonLimiter;
|
import com.jozufozu.flywheel.backend.instancing.ratelimit.NonLimiter;
|
||||||
import com.jozufozu.flywheel.config.FlwConfig;
|
import com.jozufozu.flywheel.config.FlwConfig;
|
||||||
|
import com.jozufozu.flywheel.core.RenderContext;
|
||||||
import com.jozufozu.flywheel.light.LightUpdater;
|
import com.jozufozu.flywheel.light.LightUpdater;
|
||||||
import com.mojang.math.Vector3f;
|
import com.mojang.math.Vector3f;
|
||||||
|
|
||||||
|
@ -102,19 +103,21 @@ public abstract class InstanceManager<T> {
|
||||||
if (tick.shouldUpdate(dX, dY, dZ)) instance.tick();
|
if (tick.shouldUpdate(dX, dY, dZ)) instance.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void beginFrame(TaskEngine taskEngine, Camera camera) {
|
public void beginFrame(TaskEngine taskEngine, RenderContext context) {
|
||||||
frame.tick();
|
frame.tick();
|
||||||
processQueuedAdditions();
|
processQueuedAdditions();
|
||||||
|
|
||||||
|
Camera camera = context.camera();
|
||||||
Vector3f look = camera.getLookVector();
|
Vector3f look = camera.getLookVector();
|
||||||
float lookX = look.x();
|
float lookX = look.x();
|
||||||
float lookY = look.y();
|
float lookY = look.y();
|
||||||
float lookZ = look.z();
|
float lookZ = look.z();
|
||||||
|
|
||||||
// integer camera pos
|
// integer camera pos
|
||||||
int cX = (int) camera.getPosition().x;
|
BlockPos cameraIntPos = camera.getBlockPosition();
|
||||||
int cY = (int) camera.getPosition().y;
|
int cX = cameraIntPos.getX();
|
||||||
int cZ = (int) camera.getPosition().z;
|
int cY = cameraIntPos.getY();
|
||||||
|
int cZ = cameraIntPos.getZ();
|
||||||
|
|
||||||
var instances = getStorage().getInstancesForUpdate();
|
var instances = getStorage().getInstancesForUpdate();
|
||||||
distributeWork(taskEngine, instances, instance -> updateInstance(instance, lookX, lookY, lookZ, cX, cY, cZ));
|
distributeWork(taskEngine, instances, instance -> updateInstance(instance, lookX, lookY, lookZ, cX, cY, cZ));
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.jozufozu.flywheel.backend.instancing;
|
package com.jozufozu.flywheel.backend.instancing;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.RenderStage;
|
||||||
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
||||||
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
|
@ -13,12 +14,9 @@ import com.jozufozu.flywheel.core.Contexts;
|
||||||
import com.jozufozu.flywheel.core.RenderContext;
|
import com.jozufozu.flywheel.core.RenderContext;
|
||||||
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
||||||
import com.jozufozu.flywheel.util.ClientLevelExtension;
|
import com.jozufozu.flywheel.util.ClientLevelExtension;
|
||||||
import com.jozufozu.flywheel.vanilla.effect.ExampleEffect;
|
|
||||||
|
|
||||||
import net.minecraft.client.Camera;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.multiplayer.ClientLevel;
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
@ -92,18 +90,18 @@ public class InstanceWorld {
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public void beginFrame(BeginFrameEvent event) {
|
public void beginFrame(BeginFrameEvent event) {
|
||||||
Camera camera = event.getCamera();
|
RenderContext context = event.getContext();
|
||||||
boolean shifted = engine.maintainOriginCoordinate(camera);
|
boolean shifted = engine.maintainOriginCoordinate(context.camera());
|
||||||
|
|
||||||
taskEngine.syncPoint();
|
taskEngine.syncPoint();
|
||||||
|
|
||||||
if (!shifted) {
|
if (!shifted) {
|
||||||
blockEntities.beginFrame(taskEngine, camera);
|
blockEntities.beginFrame(taskEngine, context);
|
||||||
entities.beginFrame(taskEngine, camera);
|
entities.beginFrame(taskEngine, context);
|
||||||
effects.beginFrame(taskEngine, camera);
|
effects.beginFrame(taskEngine, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.beginFrame(taskEngine, camera);
|
engine.beginFrame(taskEngine, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,24 +129,13 @@ public class InstanceWorld {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw the given layer.
|
* Draw all instances for the given stage.
|
||||||
*/
|
*/
|
||||||
public void renderSpecificType(RenderContext context, RenderType type) {
|
public void renderStage(RenderContext context, RenderStage stage) {
|
||||||
taskEngine.syncPoint();
|
taskEngine.syncPoint();
|
||||||
context.pushPose();
|
context.pushPose();
|
||||||
context.translateBack(context.camX(), context.camY(), context.camZ());
|
context.translateBack(context.camera().getPosition());
|
||||||
engine.renderSpecificType(taskEngine, context, type);
|
engine.renderStage(taskEngine, context, stage);
|
||||||
context.popPose();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Draw the given layer.
|
|
||||||
*/
|
|
||||||
public void renderAllRemaining(RenderContext context) {
|
|
||||||
taskEngine.syncPoint();
|
|
||||||
context.pushPose();
|
|
||||||
context.translateBack(context.camX(), context.camY(), context.camZ());
|
|
||||||
engine.renderAllRemaining(taskEngine, context);
|
|
||||||
context.popPose();
|
context.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,14 @@ import com.jozufozu.flywheel.backend.Backend;
|
||||||
import com.jozufozu.flywheel.backend.instancing.effect.Effect;
|
import com.jozufozu.flywheel.backend.instancing.effect.Effect;
|
||||||
import com.jozufozu.flywheel.config.FlwCommands;
|
import com.jozufozu.flywheel.config.FlwCommands;
|
||||||
import com.jozufozu.flywheel.config.FlwConfig;
|
import com.jozufozu.flywheel.config.FlwConfig;
|
||||||
import com.jozufozu.flywheel.core.RenderContext;
|
|
||||||
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
||||||
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
||||||
|
import com.jozufozu.flywheel.event.RenderStageEvent;
|
||||||
import com.jozufozu.flywheel.util.AnimationTickHolder;
|
import com.jozufozu.flywheel.util.AnimationTickHolder;
|
||||||
import com.jozufozu.flywheel.util.WorldAttached;
|
import com.jozufozu.flywheel.util.WorldAttached;
|
||||||
import com.jozufozu.flywheel.vanilla.effect.ExampleEffect;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.multiplayer.ClientLevel;
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
@ -89,23 +87,16 @@ public class InstancedRenderDispatcher {
|
||||||
|
|
||||||
public static void onBeginFrame(BeginFrameEvent event) {
|
public static void onBeginFrame(BeginFrameEvent event) {
|
||||||
if (Backend.isGameActive() && Backend.isOn()) {
|
if (Backend.isGameActive() && Backend.isOn()) {
|
||||||
instanceWorlds.get(event.getWorld())
|
instanceWorlds.get(event.getContext().level())
|
||||||
.beginFrame(event);
|
.beginFrame(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void renderSpecificType(RenderContext context, RenderType type) {
|
public static void onRenderStage(RenderStageEvent event) {
|
||||||
ClientLevel world = context.level();
|
ClientLevel world = event.getContext().level();
|
||||||
if (!Backend.canUseInstancing(world)) return;
|
if (!Backend.canUseInstancing(world)) return;
|
||||||
|
|
||||||
instanceWorlds.get(world).renderSpecificType(context, type);
|
instanceWorlds.get(world).renderStage(event.getContext(), event.getStage());
|
||||||
}
|
|
||||||
|
|
||||||
public static void renderAllRemaining(RenderContext context) {
|
|
||||||
ClientLevel world = context.level();
|
|
||||||
if (!Backend.canUseInstancing(world)) return;
|
|
||||||
|
|
||||||
instanceWorlds.get(world).renderAllRemaining(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onReloadRenderers(ReloadRenderersEvent event) {
|
public static void onReloadRenderers(ReloadRenderersEvent event) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import java.util.function.Predicate;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
||||||
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstancingController;
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstancingController;
|
||||||
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityTypeExtension;
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityTypeExtension;
|
||||||
|
|
|
@ -4,13 +4,12 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
|
||||||
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
||||||
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.light.LightUpdater;
|
import com.jozufozu.flywheel.light.LightUpdater;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
package com.jozufozu.flywheel.backend.instancing;
|
package com.jozufozu.flywheel.backend.instancing;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.RenderStage;
|
||||||
import com.jozufozu.flywheel.core.RenderContext;
|
import com.jozufozu.flywheel.core.RenderContext;
|
||||||
|
|
||||||
import net.minecraft.client.Camera;
|
import net.minecraft.client.Camera;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
|
|
||||||
public interface RenderDispatcher {
|
public interface RenderDispatcher {
|
||||||
|
|
||||||
void renderAllRemaining(TaskEngine taskEngine, RenderContext context);
|
void renderStage(TaskEngine taskEngine, RenderContext context, RenderStage stage);
|
||||||
|
|
||||||
void renderSpecificType(TaskEngine taskEngine, RenderContext context, RenderType type);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maintain the integer origin coordinate to be within a certain distance from the camera in all directions,
|
* Maintain the integer origin coordinate to be within a certain distance from the camera in all directions,
|
||||||
|
@ -18,7 +16,7 @@ public interface RenderDispatcher {
|
||||||
*/
|
*/
|
||||||
boolean maintainOriginCoordinate(Camera camera);
|
boolean maintainOriginCoordinate(Camera camera);
|
||||||
|
|
||||||
void beginFrame(TaskEngine taskEngine, Camera info);
|
void beginFrame(TaskEngine taskEngine, RenderContext context);
|
||||||
|
|
||||||
void delete();
|
void delete();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,6 @@ public class BatchLists {
|
||||||
public final Map<RenderType, List<TransformSet<?>>> renderLists = new HashMap<>();
|
public final Map<RenderType, List<TransformSet<?>>> renderLists = new HashMap<>();
|
||||||
|
|
||||||
public void add(TransformSet<?> set) {
|
public void add(TransformSet<?> set) {
|
||||||
renderLists.computeIfAbsent(set.material.renderType(), k -> new ArrayList<>()).add(set);
|
renderLists.computeIfAbsent(set.material.getRenderType(), k -> new ArrayList<>()).add(set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.instancing.batching;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.core.model.ModelSupplier;
|
import com.jozufozu.flywheel.core.model.ModelSupplier;
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,14 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.RenderStage;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.backend.ShadersModHandler;
|
import com.jozufozu.flywheel.backend.ShadersModHandler;
|
||||||
import com.jozufozu.flywheel.backend.instancing.*;
|
import com.jozufozu.flywheel.backend.instancing.BatchDrawingTracker;
|
||||||
|
import com.jozufozu.flywheel.backend.instancing.Engine;
|
||||||
|
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
|
||||||
|
import com.jozufozu.flywheel.backend.instancing.TaskEngine;
|
||||||
import com.jozufozu.flywheel.core.RenderContext;
|
import com.jozufozu.flywheel.core.RenderContext;
|
||||||
import com.jozufozu.flywheel.util.FlwUtil;
|
import com.jozufozu.flywheel.util.FlwUtil;
|
||||||
import com.mojang.blaze3d.platform.Lighting;
|
import com.mojang.blaze3d.platform.Lighting;
|
||||||
|
@ -16,7 +20,6 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.math.Matrix4f;
|
import com.mojang.math.Matrix4f;
|
||||||
|
|
||||||
import net.minecraft.client.Camera;
|
import net.minecraft.client.Camera;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Vec3i;
|
import net.minecraft.core.Vec3i;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
@ -65,13 +68,12 @@ public class BatchingEngine implements Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderSpecificType(TaskEngine taskEngine, RenderContext context, RenderType type) {
|
public void renderStage(TaskEngine taskEngine, RenderContext context, RenderStage stage) {
|
||||||
|
// FIXME: properly support material stages
|
||||||
|
if (stage != RenderStage.AFTER_FINAL_END_BATCH) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renderAllRemaining(TaskEngine taskEngine, RenderContext context) {
|
|
||||||
|
|
||||||
// FIXME: this probably breaks some vanilla stuff but it works much better for flywheel
|
// FIXME: this probably breaks some vanilla stuff but it works much better for flywheel
|
||||||
Matrix4f mat = new Matrix4f();
|
Matrix4f mat = new Matrix4f();
|
||||||
mat.setIdentity();
|
mat.setIdentity();
|
||||||
|
@ -96,15 +98,15 @@ public class BatchingEngine implements Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beginFrame(TaskEngine taskEngine, Camera info) {
|
public void beginFrame(TaskEngine taskEngine, RenderContext context) {
|
||||||
for (var model : uninitializedModels) {
|
for (var model : uninitializedModels) {
|
||||||
model.init(batchLists);
|
model.init(batchLists);
|
||||||
}
|
}
|
||||||
|
|
||||||
uninitializedModels.clear();
|
uninitializedModels.clear();
|
||||||
|
|
||||||
Vec3 cameraPos = info.getPosition();
|
Vec3 cameraPos = context.camera().getPosition();
|
||||||
var stack = FlwUtil.copyPoseStack(RenderContext.CURRENT.stack());
|
var stack = FlwUtil.copyPoseStack(context.stack());
|
||||||
stack.translate(-cameraPos.x, -cameraPos.y, -cameraPos.z);
|
stack.translate(-cameraPos.x, -cameraPos.y, -cameraPos.z);
|
||||||
|
|
||||||
submitTasks(stack, taskEngine);
|
submitTasks(stack, taskEngine);
|
||||||
|
@ -118,7 +120,5 @@ public class BatchingEngine implements Engine {
|
||||||
@Override
|
@Override
|
||||||
public void addDebugInfo(List<String> info) {
|
public void addDebugInfo(List<String> info) {
|
||||||
info.add("Batching");
|
info.add("Batching");
|
||||||
info.add("Instances: " + 0);
|
|
||||||
info.add("Vertices: " + 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.instancing.batching;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstancer;
|
import com.jozufozu.flywheel.backend.instancing.AbstractInstancer;
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.Instancer;
|
import com.jozufozu.flywheel.api.instancer.Instancer;
|
||||||
import com.jozufozu.flywheel.api.InstancerFactory;
|
import com.jozufozu.flywheel.api.instancer.InstancerFactory;
|
||||||
import com.jozufozu.flywheel.api.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.core.model.ModelSupplier;
|
import com.jozufozu.flywheel.core.model.ModelSupplier;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.instancing.batching;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.backend.instancing.TaskEngine;
|
import com.jozufozu.flywheel.backend.instancing.TaskEngine;
|
||||||
import com.jozufozu.flywheel.backend.model.DirectVertexConsumer;
|
import com.jozufozu.flywheel.backend.model.DirectVertexConsumer;
|
||||||
|
|
|
@ -3,11 +3,11 @@ package com.jozufozu.flywheel.backend.instancing.blockentity;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
|
||||||
import com.jozufozu.flywheel.api.InstancerFactory;
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
|
||||||
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
||||||
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancerFactory;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
||||||
import com.jozufozu.flywheel.core.structs.StructTypes;
|
import com.jozufozu.flywheel.core.structs.StructTypes;
|
||||||
import com.jozufozu.flywheel.core.structs.model.TransformedPart;
|
import com.jozufozu.flywheel.core.structs.model.TransformedPart;
|
||||||
|
|
|
@ -2,11 +2,11 @@ package com.jozufozu.flywheel.backend.instancing.blockentity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
|
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
|
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
|
||||||
|
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
|
||||||
import com.jozufozu.flywheel.backend.instancing.One2OneStorage;
|
import com.jozufozu.flywheel.backend.instancing.One2OneStorage;
|
||||||
import com.jozufozu.flywheel.backend.instancing.Storage;
|
import com.jozufozu.flywheel.backend.instancing.Storage;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.jozufozu.flywheel.backend.instancing.blockentity;
|
package com.jozufozu.flywheel.backend.instancing.blockentity;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.jozufozu.flywheel.backend.instancing.blockentity;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.instancing.effect;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
||||||
|
|
||||||
public interface Effect {
|
public interface Effect {
|
||||||
|
|
|
@ -7,9 +7,9 @@ import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.collect.HashMultimap;
|
import com.google.common.collect.HashMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
|
||||||
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
||||||
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
|
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
|
||||||
import com.jozufozu.flywheel.backend.instancing.Storage;
|
import com.jozufozu.flywheel.backend.instancing.Storage;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.jozufozu.flywheel.backend.instancing.entity;
|
package com.jozufozu.flywheel.backend.instancing.entity;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
|
||||||
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
||||||
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
||||||
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstanceManager;
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstanceManager;
|
||||||
import com.jozufozu.flywheel.light.LightListener;
|
import com.jozufozu.flywheel.light.LightListener;
|
||||||
|
|
|
@ -2,11 +2,11 @@ package com.jozufozu.flywheel.backend.instancing.entity;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
|
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
|
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
|
||||||
|
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
|
||||||
import com.jozufozu.flywheel.backend.instancing.One2OneStorage;
|
import com.jozufozu.flywheel.backend.instancing.One2OneStorage;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.jozufozu.flywheel.backend.instancing.entity;
|
package com.jozufozu.flywheel.backend.instancing.entity;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
|
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.jozufozu.flywheel.backend.instancing.entity;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
|
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.Flywheel;
|
import com.jozufozu.flywheel.Flywheel;
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.api.struct.StructWriter;
|
import com.jozufozu.flywheel.api.struct.StructWriter;
|
||||||
import com.jozufozu.flywheel.backend.gl.GlVertexArray;
|
import com.jozufozu.flywheel.backend.gl.GlVertexArray;
|
||||||
|
|
|
@ -4,15 +4,13 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.Instancer;
|
import com.jozufozu.flywheel.api.instancer.Instancer;
|
||||||
import com.jozufozu.flywheel.api.InstancerFactory;
|
import com.jozufozu.flywheel.api.instancer.InstancerFactory;
|
||||||
import com.jozufozu.flywheel.api.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstancer;
|
import com.jozufozu.flywheel.backend.instancing.AbstractInstancer;
|
||||||
import com.jozufozu.flywheel.core.model.ModelSupplier;
|
import com.jozufozu.flywheel.core.model.ModelSupplier;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A collection of Instancers that all have the same format.
|
* A collection of Instancers that all have the same format.
|
||||||
* @param <D>
|
* @param <D>
|
||||||
|
|
|
@ -2,9 +2,8 @@ package com.jozufozu.flywheel.backend.instancing.instancing;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstancer;
|
|
||||||
import com.jozufozu.flywheel.core.model.ModelSupplier;
|
import com.jozufozu.flywheel.core.model.ModelSupplier;
|
||||||
|
|
||||||
public class InstancedModel<D extends InstancedPart> {
|
public class InstancedModel<D extends InstancedPart> {
|
||||||
|
|
|
@ -12,15 +12,16 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import com.google.common.collect.ListMultimap;
|
import com.google.common.collect.ListMultimap;
|
||||||
import com.google.common.collect.Multimaps;
|
import com.google.common.collect.Multimaps;
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.RenderStage;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.api.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexType;
|
import com.jozufozu.flywheel.api.vertex.VertexType;
|
||||||
import com.jozufozu.flywheel.backend.gl.GlVertexArray;
|
import com.jozufozu.flywheel.backend.gl.GlVertexArray;
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
|
import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
|
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
|
|
||||||
import com.jozufozu.flywheel.backend.instancing.Engine;
|
import com.jozufozu.flywheel.backend.instancing.Engine;
|
||||||
|
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||||
import com.jozufozu.flywheel.backend.instancing.TaskEngine;
|
import com.jozufozu.flywheel.backend.instancing.TaskEngine;
|
||||||
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
||||||
|
@ -75,8 +76,6 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
||||||
* The set of instance managers that are attached to this engine.
|
* The set of instance managers that are attached to this engine.
|
||||||
*/
|
*/
|
||||||
private final WeakHashSet<InstanceManager<?>> instanceManagers;
|
private final WeakHashSet<InstanceManager<?>> instanceManagers;
|
||||||
private int vertexCount;
|
|
||||||
private int instanceCount;
|
|
||||||
|
|
||||||
public InstancingEngine(ProgramCompiler<P> context) {
|
public InstancingEngine(ProgramCompiler<P> context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
@ -97,48 +96,62 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderAllRemaining(TaskEngine taskEngine, RenderContext context) {
|
public void renderStage(TaskEngine taskEngine, RenderContext context, RenderStage stage) {
|
||||||
var camX = context.camX() - originCoordinate.getX();
|
if (!renderLists.process(stage)) {
|
||||||
var camY = context.camY() - originCoordinate.getY();
|
|
||||||
var camZ = context.camZ() - originCoordinate.getZ();
|
|
||||||
|
|
||||||
// don't want to mutate viewProjection
|
|
||||||
var vp = context.viewProjection().copy();
|
|
||||||
vp.multiplyWithTranslation((float) -camX, (float) -camY, (float) -camZ);
|
|
||||||
|
|
||||||
for (RenderType renderType : renderLists.drainLayers()) {
|
|
||||||
render(renderType, camX, camY, camZ, vp, context.level());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renderSpecificType(TaskEngine taskEngine, RenderContext context, RenderType type) {
|
|
||||||
if (!renderLists.process(type)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var camX = context.camX() - originCoordinate.getX();
|
var camPos = context.camera().getPosition();
|
||||||
var camY = context.camY() - originCoordinate.getY();
|
var camX = camPos.x - originCoordinate.getX();
|
||||||
var camZ = context.camZ() - originCoordinate.getZ();
|
var camY = camPos.y - originCoordinate.getY();
|
||||||
|
var camZ = camPos.z - originCoordinate.getZ();
|
||||||
|
|
||||||
// don't want to mutate viewProjection
|
// don't want to mutate viewProjection
|
||||||
var vp = context.viewProjection().copy();
|
var vp = context.viewProjection().copy();
|
||||||
vp.multiplyWithTranslation((float) -camX, (float) -camY, (float) -camZ);
|
vp.multiplyWithTranslation((float) -camX, (float) -camY, (float) -camZ);
|
||||||
|
|
||||||
render(type, camX, camY, camZ, vp, context.level());
|
var renderList = renderLists.get(stage);
|
||||||
}
|
for (var entry : renderList.entrySet()) {
|
||||||
|
var multimap = entry.getValue();
|
||||||
protected void render(RenderType type, double camX, double camY, double camZ, Matrix4f viewProjection, ClientLevel level) {
|
|
||||||
vertexCount = 0;
|
|
||||||
instanceCount = 0;
|
|
||||||
|
|
||||||
var multimap = renderLists.get(type);
|
|
||||||
|
|
||||||
if (multimap.isEmpty()) {
|
if (multimap.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
render(type, multimap, camX, camY, camZ, viewProjection, level);
|
render(entry.getKey(), multimap, camX, camY, camZ, vp, context.level());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Is this useful? Should it be added to the base interface? Currently it is only used for the old CrumblingRenderer.
|
||||||
|
@Deprecated
|
||||||
|
public void renderAll(TaskEngine taskEngine, RenderContext context) {
|
||||||
|
if (renderLists.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var camPos = context.camera().getPosition();
|
||||||
|
var camX = camPos.x - originCoordinate.getX();
|
||||||
|
var camY = camPos.y - originCoordinate.getY();
|
||||||
|
var camZ = camPos.z - originCoordinate.getZ();
|
||||||
|
|
||||||
|
// don't want to mutate viewProjection
|
||||||
|
var vp = context.viewProjection().copy();
|
||||||
|
vp.multiplyWithTranslation((float) -camX, (float) -camY, (float) -camZ);
|
||||||
|
|
||||||
|
for (RenderStage stage : renderLists.stagesToProcess) {
|
||||||
|
var renderList = renderLists.get(stage);
|
||||||
|
for (var entry : renderList.entrySet()) {
|
||||||
|
var multimap = entry.getValue();
|
||||||
|
|
||||||
|
if (multimap.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
render(entry.getKey(), multimap, camX, camY, camZ, vp, context.level());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
renderLists.stagesToProcess.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void render(RenderType type, ListMultimap<ShaderState, DrawCall> multimap, double camX, double camY, double camZ, Matrix4f viewProjection, ClientLevel level) {
|
protected void render(RenderType type, ListMultimap<ShaderState, DrawCall> multimap, double camX, double camY, double camZ, Matrix4f viewProjection, ClientLevel level) {
|
||||||
|
@ -176,7 +189,7 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
||||||
Material material = desc.material();
|
Material material = desc.material();
|
||||||
|
|
||||||
P program = context.getProgram(new ProgramCompiler.Context(vertexType, instanceShader,
|
P program = context.getProgram(new ProgramCompiler.Context(vertexType, instanceShader,
|
||||||
material.vertexShader(), material.fragmentShader(), coreShaderInfo.getAdjustedAlphaDiscard(),
|
material.getVertexShader(), material.getFragmentShader(), coreShaderInfo.getAdjustedAlphaDiscard(),
|
||||||
coreShaderInfo.fogType(), ctx));
|
coreShaderInfo.fogType(), ctx));
|
||||||
|
|
||||||
program.bind();
|
program.bind();
|
||||||
|
@ -223,7 +236,7 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beginFrame(TaskEngine taskEngine, Camera info) {
|
public void beginFrame(TaskEngine taskEngine, RenderContext context) {
|
||||||
for (var model : uninitializedModels) {
|
for (var model : uninitializedModels) {
|
||||||
model.init(renderLists);
|
model.init(renderLists);
|
||||||
}
|
}
|
||||||
|
@ -246,8 +259,6 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
||||||
@Override
|
@Override
|
||||||
public void addDebugInfo(List<String> info) {
|
public void addDebugInfo(List<String> info) {
|
||||||
info.add("GL33 Instanced Arrays");
|
info.add("GL33 Instanced Arrays");
|
||||||
info.add("Instances: " + instanceCount);
|
|
||||||
info.add("Vertices: " + vertexCount);
|
|
||||||
info.add("Origin: " + originCoordinate.getX() + ", " + originCoordinate.getY() + ", " + originCoordinate.getZ());
|
info.add("Origin: " + originCoordinate.getX() + ", " + originCoordinate.getY() + ", " + originCoordinate.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,13 +310,13 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
material.renderType().setupRenderState();
|
material.getRenderType().setupRenderState();
|
||||||
|
|
||||||
CoreShaderInfo coreShaderInfo = CoreShaderInfo.get();
|
CoreShaderInfo coreShaderInfo = CoreShaderInfo.get();
|
||||||
|
|
||||||
|
|
||||||
CrumblingProgram program = Contexts.CRUMBLING.getProgram(new ProgramCompiler.Context(Formats.POS_TEX_NORMAL,
|
CrumblingProgram program = Contexts.CRUMBLING.getProgram(new ProgramCompiler.Context(Formats.POS_TEX_NORMAL,
|
||||||
structType.getInstanceShader(), material.vertexShader(), material.fragmentShader(),
|
structType.getInstanceShader(), material.getVertexShader(), material.getFragmentShader(),
|
||||||
coreShaderInfo.getAdjustedAlphaDiscard(), coreShaderInfo.fogType(),
|
coreShaderInfo.getAdjustedAlphaDiscard(), coreShaderInfo.fogType(),
|
||||||
GameStateRegistry.takeSnapshot()));
|
GameStateRegistry.takeSnapshot()));
|
||||||
|
|
||||||
|
@ -332,7 +343,7 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
||||||
for (var blockEntityInstance : entry.getValue()) {
|
for (var blockEntityInstance : entry.getValue()) {
|
||||||
|
|
||||||
for (var part : blockEntityInstance.getCrumblingParts()) {
|
for (var part : blockEntityInstance.getCrumblingParts()) {
|
||||||
if (part.getOwner() instanceof GPUInstancer instancer) {
|
if (part.getOwner() instanceof GPUInstancer<?> instancer) {
|
||||||
|
|
||||||
// queue the instances for copying to the crumbling instance buffer
|
// queue the instances for copying to the crumbling instance buffer
|
||||||
map.computeIfAbsent(instancer.parent.getModel(), k -> new ArrayList<>()).add(part);
|
map.computeIfAbsent(instancer.parent.getModel(), k -> new ArrayList<>()).add(part);
|
||||||
|
|
|
@ -1,49 +1,57 @@
|
||||||
package com.jozufozu.flywheel.backend.instancing.instancing;
|
package com.jozufozu.flywheel.backend.instancing.instancing;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.ListMultimap;
|
import com.google.common.collect.ListMultimap;
|
||||||
|
import com.jozufozu.flywheel.api.RenderStage;
|
||||||
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
|
||||||
public class RenderLists {
|
public class RenderLists {
|
||||||
|
|
||||||
private final Map<RenderType, ListMultimap<ShaderState, DrawCall>> renderLists = new HashMap<>();
|
private final Map<RenderStage, Map<RenderType, ListMultimap<ShaderState, DrawCall>>> renderLists = new EnumMap<>(RenderStage.class);
|
||||||
public final Set<RenderType> layersToProcess = new HashSet<>();
|
public final Set<RenderStage> stagesToProcess = EnumSet.noneOf(RenderStage.class);
|
||||||
|
|
||||||
public ListMultimap<ShaderState, DrawCall> get(RenderType type) {
|
public Map<RenderType, ListMultimap<ShaderState, DrawCall>> get(RenderStage stage) {
|
||||||
return renderLists.computeIfAbsent(type, k -> ArrayListMultimap.create());
|
var renderList = renderLists.get(stage);
|
||||||
|
if (renderList == null) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
return renderList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ShaderState shaderState, DrawCall layer) {
|
public void add(ShaderState shaderState, DrawCall layer) {
|
||||||
RenderType renderType = shaderState.material()
|
Material material = shaderState.material();
|
||||||
.renderType();
|
|
||||||
|
|
||||||
get(renderType).put(shaderState, layer);
|
renderLists
|
||||||
|
.computeIfAbsent(material.getRenderStage(), k -> new HashMap<>())
|
||||||
|
.computeIfAbsent(material.getRenderType(), k -> ArrayListMultimap.create())
|
||||||
|
.put(shaderState, layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void prepare() {
|
public void prepare() {
|
||||||
layersToProcess.clear();
|
stagesToProcess.clear();
|
||||||
|
|
||||||
layersToProcess.addAll(renderLists.keySet());
|
stagesToProcess.addAll(renderLists.keySet());
|
||||||
}
|
|
||||||
|
|
||||||
public Iterable<? extends RenderType> drainLayers() {
|
|
||||||
var out = new HashSet<>(layersToProcess);
|
|
||||||
layersToProcess.clear();
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check and mark a layer as processed.
|
* Check and mark a stage as processed.
|
||||||
* @param type The layer to check.
|
* @param stage The stage to check.
|
||||||
* @return {@code true} if the layer should be processed.
|
* @return {@code true} if the stage should be processed.
|
||||||
*/
|
*/
|
||||||
public boolean process(RenderType type) {
|
public boolean process(RenderStage stage) {
|
||||||
return layersToProcess.remove(type);
|
return stagesToProcess.remove(stage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return stagesToProcess.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.struct;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.api.struct.StructWriter;
|
import com.jozufozu.flywheel.api.struct.StructWriter;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,23 +6,14 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.core.material.MaterialShaders;
|
|
||||||
import com.jozufozu.flywheel.core.model.Mesh;
|
import com.jozufozu.flywheel.core.model.Mesh;
|
||||||
import com.jozufozu.flywheel.core.model.ModelSupplier;
|
import com.jozufozu.flywheel.core.model.ModelSupplier;
|
||||||
import com.jozufozu.flywheel.util.Lazy;
|
import com.jozufozu.flywheel.util.Lazy;
|
||||||
import com.jozufozu.flywheel.util.NonNullSupplier;
|
import com.jozufozu.flywheel.util.NonNullSupplier;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
|
|
||||||
public class BasicModelSupplier implements ModelSupplier {
|
public class BasicModelSupplier implements ModelSupplier {
|
||||||
private static final Material DEFAULT_MATERIAL = new Material(RenderType.solid(), MaterialShaders.DEFAULT_VERTEX, MaterialShaders.DEFAULT_FRAGMENT);
|
|
||||||
|
|
||||||
private Material material;
|
|
||||||
private final Lazy<Mesh> supplier;
|
private final Lazy<Mesh> supplier;
|
||||||
|
private Material material;
|
||||||
public BasicModelSupplier(NonNullSupplier<Mesh> supplier) {
|
|
||||||
this(supplier, DEFAULT_MATERIAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasicModelSupplier(NonNullSupplier<Mesh> supplier, Material material) {
|
public BasicModelSupplier(NonNullSupplier<Mesh> supplier, Material material) {
|
||||||
this.supplier = Lazy.of(supplier);
|
this.supplier = Lazy.of(supplier);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.Map;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.ShadersModHandler;
|
import com.jozufozu.flywheel.backend.ShadersModHandler;
|
||||||
|
import com.jozufozu.flywheel.core.CoreShaderInfoMap.CoreShaderInfo.FogType;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.ShaderInstance;
|
import net.minecraft.client.renderer.ShaderInstance;
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
package com.jozufozu.flywheel.core;
|
|
||||||
|
|
||||||
import net.minecraft.client.Camera;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class tracking which object last had {@link Camera#setup} called on it.
|
|
||||||
*
|
|
||||||
* @see com.jozufozu.flywheel.mixin.CameraMixin
|
|
||||||
*/
|
|
||||||
public class LastActiveCamera {
|
|
||||||
|
|
||||||
private static Camera camera;
|
|
||||||
|
|
||||||
public static void _setActiveCamera(Camera camera) {
|
|
||||||
LastActiveCamera.camera = camera;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Camera getActiveCamera() {
|
|
||||||
return camera;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,23 +4,30 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.RenderStage;
|
||||||
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
|
import com.jozufozu.flywheel.core.material.MaterialShaders;
|
||||||
|
import com.jozufozu.flywheel.core.material.SimpleMaterial;
|
||||||
import com.jozufozu.flywheel.core.model.BlockMesh;
|
import com.jozufozu.flywheel.core.model.BlockMesh;
|
||||||
import com.jozufozu.flywheel.core.model.ModelUtil;
|
import com.jozufozu.flywheel.core.model.ModelUtil;
|
||||||
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
||||||
import com.jozufozu.flywheel.util.Pair;
|
import com.jozufozu.flywheel.util.Pair;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.RenderType;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
public class Models {
|
public class Models {
|
||||||
|
|
||||||
|
public static final Material DEFAULT_MATERIAL = new SimpleMaterial(RenderStage.AFTER_SOLID_TERRAIN, RenderType.cutout(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT);
|
||||||
|
|
||||||
public static BasicModelSupplier block(BlockState state) {
|
public static BasicModelSupplier block(BlockState state) {
|
||||||
return BLOCK_STATE.computeIfAbsent(state, it -> new BasicModelSupplier(() -> new BlockMesh(it)));
|
return BLOCK_STATE.computeIfAbsent(state, it -> new BasicModelSupplier(() -> new BlockMesh(it), DEFAULT_MATERIAL));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BasicModelSupplier partial(PartialModel partial) {
|
public static BasicModelSupplier partial(PartialModel partial) {
|
||||||
return PARTIAL.computeIfAbsent(partial, it -> new BasicModelSupplier(() -> new BlockMesh(it)));
|
return PARTIAL.computeIfAbsent(partial, it -> new BasicModelSupplier(() -> new BlockMesh(it), DEFAULT_MATERIAL));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BasicModelSupplier partial(PartialModel partial, Direction dir) {
|
public static BasicModelSupplier partial(PartialModel partial, Direction dir) {
|
||||||
|
@ -28,7 +35,7 @@ public class Models {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BasicModelSupplier partial(PartialModel partial, Direction dir, Supplier<PoseStack> modelTransform) {
|
public static BasicModelSupplier partial(PartialModel partial, Direction dir, Supplier<PoseStack> modelTransform) {
|
||||||
return PARTIAL_DIR.computeIfAbsent(Pair.of(dir, partial), $ -> new BasicModelSupplier(() -> new BlockMesh(partial, modelTransform.get())));
|
return PARTIAL_DIR.computeIfAbsent(Pair.of(dir, partial), $ -> new BasicModelSupplier(() -> new BlockMesh(partial, modelTransform.get()), DEFAULT_MATERIAL));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onReload(ReloadRenderersEvent ignored) {
|
public static void onReload(ReloadRenderersEvent ignored) {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package com.jozufozu.flywheel.core;
|
package com.jozufozu.flywheel.core;
|
||||||
|
|
||||||
import java.nio.Buffer;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
package com.jozufozu.flywheel.core;
|
package com.jozufozu.flywheel.core;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.util.transform.TransformStack;
|
import com.jozufozu.flywheel.util.transform.TransformStack;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.math.Matrix3f;
|
import com.mojang.math.Matrix3f;
|
||||||
import com.mojang.math.Matrix4f;
|
import com.mojang.math.Matrix4f;
|
||||||
import com.mojang.math.Quaternion;
|
import com.mojang.math.Quaternion;
|
||||||
|
|
||||||
|
import net.minecraft.client.Camera;
|
||||||
import net.minecraft.client.multiplayer.ClientLevel;
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
|
import net.minecraft.client.renderer.LevelRenderer;
|
||||||
import net.minecraft.client.renderer.RenderBuffers;
|
import net.minecraft.client.renderer.RenderBuffers;
|
||||||
|
|
||||||
public record RenderContext(ClientLevel level, PoseStack stack, Matrix4f viewProjection, RenderBuffers buffers,
|
public record RenderContext(LevelRenderer renderer, ClientLevel level, PoseStack stack, Matrix4f viewProjection,
|
||||||
double camX, double camY, double camZ) implements TransformStack {
|
Matrix4f projection, RenderBuffers buffers, Camera camera) implements TransformStack {
|
||||||
|
|
||||||
public static RenderContext CURRENT;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TransformStack multiply(Quaternion quaternion) {
|
public TransformStack multiply(Quaternion quaternion) {
|
||||||
|
@ -50,4 +52,11 @@ public record RenderContext(ClientLevel level, PoseStack stack, Matrix4f viewPro
|
||||||
public TransformStack translate(double x, double y, double z) {
|
public TransformStack translate(double x, double y, double z) {
|
||||||
return TransformStack.cast(stack).translate(x, y, z);
|
return TransformStack.cast(stack).translate(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Matrix4f createViewProjection(PoseStack view, Matrix4f projection) {
|
||||||
|
var viewProjection = projection.copy();
|
||||||
|
viewProjection.multiply(view.last().pose());
|
||||||
|
return viewProjection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,6 @@ import com.jozufozu.flywheel.core.source.FileIndex;
|
||||||
import com.jozufozu.flywheel.core.source.FileResolution;
|
import com.jozufozu.flywheel.core.source.FileResolution;
|
||||||
import com.jozufozu.flywheel.core.source.ShaderField;
|
import com.jozufozu.flywheel.core.source.ShaderField;
|
||||||
import com.jozufozu.flywheel.core.source.SourceFile;
|
import com.jozufozu.flywheel.core.source.SourceFile;
|
||||||
import com.jozufozu.flywheel.core.source.parse.ShaderStruct;
|
|
||||||
import com.jozufozu.flywheel.core.source.parse.StructField;
|
|
||||||
import com.jozufozu.flywheel.core.source.span.Span;
|
import com.jozufozu.flywheel.core.source.span.Span;
|
||||||
import com.jozufozu.flywheel.util.Pair;
|
import com.jozufozu.flywheel.util.Pair;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.jozufozu.flywheel.core.crumbling;
|
package com.jozufozu.flywheel.core.crumbling;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
|
||||||
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstanceManager;
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstanceManager;
|
||||||
|
|
||||||
public class CrumblingInstanceManager extends BlockEntityInstanceManager {
|
public class CrumblingInstanceManager extends BlockEntityInstanceManager {
|
||||||
|
|
|
@ -4,24 +4,25 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
import com.google.common.collect.ListMultimap;
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
import com.jozufozu.flywheel.backend.gl.GlStateTracker;
|
import com.jozufozu.flywheel.backend.gl.GlStateTracker;
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
|
import com.jozufozu.flywheel.backend.instancing.InstanceManager;
|
||||||
import com.jozufozu.flywheel.backend.instancing.SerialTaskEngine;
|
import com.jozufozu.flywheel.backend.instancing.SerialTaskEngine;
|
||||||
|
import com.jozufozu.flywheel.backend.instancing.instancing.DrawCall;
|
||||||
import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine;
|
import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine;
|
||||||
|
import com.jozufozu.flywheel.backend.instancing.instancing.ShaderState;
|
||||||
import com.jozufozu.flywheel.core.Contexts;
|
import com.jozufozu.flywheel.core.Contexts;
|
||||||
import com.jozufozu.flywheel.core.RenderContext;
|
import com.jozufozu.flywheel.core.RenderContext;
|
||||||
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
||||||
import com.jozufozu.flywheel.mixin.LevelRendererAccessor;
|
import com.jozufozu.flywheel.mixin.LevelRendererAccessor;
|
||||||
import com.jozufozu.flywheel.util.Lazy;
|
import com.jozufozu.flywheel.util.Lazy;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.math.Matrix4f;
|
import com.mojang.math.Matrix4f;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||||
import net.minecraft.client.Camera;
|
|
||||||
import net.minecraft.client.multiplayer.ClientLevel;
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
import net.minecraft.client.renderer.LevelRenderer;
|
import net.minecraft.client.renderer.LevelRenderer;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
@ -29,7 +30,6 @@ import net.minecraft.client.resources.model.ModelBakery;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.level.BlockDestructionProgress;
|
import net.minecraft.server.level.BlockDestructionProgress;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
|
|
||||||
// TODO: merge directly into InstancingEngine for efficiency
|
// TODO: merge directly into InstancingEngine for efficiency
|
||||||
/**
|
/**
|
||||||
|
@ -43,45 +43,34 @@ public class CrumblingRenderer {
|
||||||
_init();
|
_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void renderCrumbling(LevelRenderer levelRenderer, ClientLevel level, PoseStack poseStack, Camera camera, Matrix4f projectionMatrix) {
|
public static void renderCrumbling(RenderContext context) {
|
||||||
// TODO: one pass base/crumbling
|
// TODO: one pass base/crumbling
|
||||||
if (true) return;
|
if (true) return;
|
||||||
|
|
||||||
Int2ObjectMap<List<BlockEntity>> activeStages = getActiveStageBlockEntities(levelRenderer, level);
|
Int2ObjectMap<List<BlockEntity>> activeStages = getActiveStageBlockEntities(context.renderer(), context.level());
|
||||||
if (activeStages.isEmpty()) return;
|
if (activeStages.isEmpty()) return;
|
||||||
|
|
||||||
try (var restoreState = GlStateTracker.getRestoreState()) {
|
try (var restoreState = GlStateTracker.getRestoreState()) {
|
||||||
|
|
||||||
Matrix4f viewProjection = poseStack.last()
|
|
||||||
.pose()
|
|
||||||
.copy();
|
|
||||||
viewProjection.multiplyBackward(projectionMatrix);
|
|
||||||
|
|
||||||
State state = STATE.get();
|
State state = STATE.get();
|
||||||
var instanceManager = state.instanceManager;
|
var instanceManager = state.instanceManager;
|
||||||
var engine = state.instancerManager;
|
var engine = state.instancerManager;
|
||||||
|
|
||||||
renderCrumblingInner(activeStages, instanceManager, engine, level, poseStack, camera, viewProjection);
|
renderCrumblingInner(activeStages, instanceManager, engine, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void renderCrumblingInner(Int2ObjectMap<List<BlockEntity>> activeStages, InstanceManager<BlockEntity> instanceManager, CrumblingEngine engine, ClientLevel level, PoseStack stack, Camera camera, Matrix4f viewProjection) {
|
private static void renderCrumblingInner(Int2ObjectMap<List<BlockEntity>> activeStages, InstanceManager<BlockEntity> instanceManager, CrumblingEngine engine, RenderContext ctx) {
|
||||||
Vec3 cameraPos = camera.getPosition();
|
|
||||||
RenderContext ctx = new RenderContext(level, stack, viewProjection, null, cameraPos.x, cameraPos.y, cameraPos.z);
|
|
||||||
|
|
||||||
for (Int2ObjectMap.Entry<List<BlockEntity>> stage : activeStages.int2ObjectEntrySet()) {
|
for (Int2ObjectMap.Entry<List<BlockEntity>> stage : activeStages.int2ObjectEntrySet()) {
|
||||||
RenderType currentLayer = ModelBakery.DESTROY_TYPES.get(stage.getIntKey());
|
RenderType currentLayer = ModelBakery.DESTROY_TYPES.get(stage.getIntKey());
|
||||||
|
|
||||||
// something about when we call this means that the textures are not ready for use on the first frame they should appear
|
// something about when we call this means that the textures are not ready for use on the first frame they should appear
|
||||||
if (currentLayer != null) {
|
if (currentLayer != null) {
|
||||||
engine.currentLayer = currentLayer;
|
|
||||||
|
|
||||||
stage.getValue().forEach(instanceManager::add);
|
stage.getValue().forEach(instanceManager::add);
|
||||||
|
|
||||||
instanceManager.beginFrame(SerialTaskEngine.INSTANCE, camera);
|
instanceManager.beginFrame(SerialTaskEngine.INSTANCE, ctx);
|
||||||
engine.beginFrame(SerialTaskEngine.INSTANCE, camera);
|
engine.beginFrame(SerialTaskEngine.INSTANCE, ctx);
|
||||||
|
|
||||||
engine.renderAllRemaining(SerialTaskEngine.INSTANCE, ctx);
|
engine.renderAll(SerialTaskEngine.INSTANCE, ctx);
|
||||||
|
|
||||||
instanceManager.invalidate();
|
instanceManager.invalidate();
|
||||||
}
|
}
|
||||||
|
@ -154,25 +143,17 @@ public class CrumblingRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class CrumblingEngine extends InstancingEngine<CrumblingProgram> {
|
private static class CrumblingEngine extends InstancingEngine<CrumblingProgram> {
|
||||||
private RenderType currentLayer;
|
|
||||||
|
|
||||||
public CrumblingEngine() {
|
public CrumblingEngine() {
|
||||||
super(Contexts.CRUMBLING);
|
super(Contexts.CRUMBLING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void render(RenderType type, double camX, double camY, double camZ, Matrix4f viewProjection, ClientLevel level) {
|
protected void render(RenderType type, ListMultimap<ShaderState, DrawCall> multimap, double camX, double camY, double camZ, Matrix4f viewProjection, ClientLevel level) {
|
||||||
if (!type.affectsCrumbling()) {
|
if (!type.affectsCrumbling()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var multimap = renderLists.get(type);
|
super.render(type, multimap, camX, camY, camZ, viewProjection, level);
|
||||||
|
|
||||||
if (multimap.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
render(currentLayer, multimap, camX, camY, camZ, viewProjection, level);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import com.jozufozu.flywheel.core.model.Mesh;
|
||||||
import com.jozufozu.flywheel.core.vertex.Formats;
|
import com.jozufozu.flywheel.core.vertex.Formats;
|
||||||
import com.jozufozu.flywheel.core.vertex.PosTexNormalVertex;
|
import com.jozufozu.flywheel.core.vertex.PosTexNormalVertex;
|
||||||
import com.jozufozu.flywheel.core.vertex.PosTexNormalWriterUnsafe;
|
import com.jozufozu.flywheel.core.vertex.PosTexNormalWriterUnsafe;
|
||||||
import com.mojang.blaze3d.platform.MemoryTracker;
|
|
||||||
|
|
||||||
public class ModelPart implements Mesh {
|
public class ModelPart implements Mesh {
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.Instancer;
|
import com.jozufozu.flywheel.api.instancer.Instancer;
|
||||||
|
|
||||||
public class ConditionalInstance<D extends InstancedPart> {
|
public class ConditionalInstance<D extends InstancedPart> {
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.Instancer;
|
import com.jozufozu.flywheel.api.instancer.Instancer;
|
||||||
|
|
||||||
public class GroupInstance<D extends InstancedPart> extends AbstractCollection<D> {
|
public class GroupInstance<D extends InstancedPart> extends AbstractCollection<D> {
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ import java.util.Optional;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.Instancer;
|
import com.jozufozu.flywheel.api.instancer.Instancer;
|
||||||
|
|
||||||
public class SelectInstance<D extends InstancedPart> {
|
public class SelectInstance<D extends InstancedPart> {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.jozufozu.flywheel.core.material;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.RenderStage;
|
||||||
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
|
import com.jozufozu.flywheel.core.source.FileResolution;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
|
||||||
|
public class SimpleMaterial implements Material {
|
||||||
|
protected final RenderStage stage;
|
||||||
|
protected final RenderType type;
|
||||||
|
protected final FileResolution vertexShader;
|
||||||
|
protected final FileResolution fragmentShader;
|
||||||
|
|
||||||
|
public SimpleMaterial(RenderStage stage, RenderType type, FileResolution vertexShader, FileResolution fragmentShader) {
|
||||||
|
this.stage = stage;
|
||||||
|
this.type = type;
|
||||||
|
this.vertexShader = vertexShader;
|
||||||
|
this.fragmentShader = fragmentShader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderStage getRenderStage() {
|
||||||
|
return stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderType getRenderType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileResolution getVertexShader() {
|
||||||
|
return vertexShader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileResolution getFragmentShader() {
|
||||||
|
return fragmentShader;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
package com.jozufozu.flywheel.core.model;
|
package com.jozufozu.flywheel.core.model;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
@ -11,7 +10,6 @@ import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||||
import com.mojang.datafixers.util.Pair;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.jozufozu.flywheel.core.structs;
|
package com.jozufozu.flywheel.core.structs;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
import com.jozufozu.flywheel.api.struct.StructType;
|
import com.jozufozu.flywheel.api.struct.StructType;
|
||||||
import com.jozufozu.flywheel.util.Color;
|
import com.jozufozu.flywheel.util.Color;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.jozufozu.flywheel.core.structs;
|
package com.jozufozu.flywheel.core.structs;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.level.BlockAndTintGetter;
|
import net.minecraft.world.level.BlockAndTintGetter;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.jozufozu.flywheel.core.vertex;
|
package com.jozufozu.flywheel.core.vertex;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.vertex.ShadedVertexList;
|
import com.jozufozu.flywheel.api.vertex.ShadedVertexList;
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexList;
|
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexType;
|
import com.jozufozu.flywheel.api.vertex.VertexType;
|
||||||
import com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder;
|
import com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder;
|
||||||
import com.jozufozu.flywheel.util.RenderMath;
|
import com.jozufozu.flywheel.util.RenderMath;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.jozufozu.flywheel.core.vertex;
|
package com.jozufozu.flywheel.core.vertex;
|
||||||
|
|
||||||
import java.lang.ref.Cleaner;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
|
@ -4,9 +4,7 @@ import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexList;
|
|
||||||
import com.jozufozu.flywheel.api.vertex.VertexType;
|
import com.jozufozu.flywheel.api.vertex.VertexType;
|
||||||
import com.jozufozu.flywheel.backend.FlywheelMemory;
|
|
||||||
import com.jozufozu.flywheel.util.RenderMath;
|
import com.jozufozu.flywheel.util.RenderMath;
|
||||||
|
|
||||||
public class PosTexNormalVertexListUnsafe extends AbstractVertexList {
|
public class PosTexNormalVertexListUnsafe extends AbstractVertexList {
|
||||||
|
|
|
@ -1,35 +1,17 @@
|
||||||
package com.jozufozu.flywheel.event;
|
package com.jozufozu.flywheel.event;
|
||||||
|
|
||||||
import net.minecraft.client.Camera;
|
import com.jozufozu.flywheel.core.RenderContext;
|
||||||
import net.minecraft.client.multiplayer.ClientLevel;
|
|
||||||
import net.minecraft.client.renderer.culling.Frustum;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import net.minecraftforge.eventbus.api.Event;
|
import net.minecraftforge.eventbus.api.Event;
|
||||||
|
|
||||||
public class BeginFrameEvent extends Event {
|
public class BeginFrameEvent extends Event {
|
||||||
private final ClientLevel world;
|
private final RenderContext context;
|
||||||
private final Camera camera;
|
|
||||||
private final Frustum frustum;
|
|
||||||
|
|
||||||
public BeginFrameEvent(ClientLevel world, Camera camera, Frustum frustum) {
|
public BeginFrameEvent(RenderContext context) {
|
||||||
this.world = world;
|
this.context = context;
|
||||||
this.camera = camera;
|
|
||||||
this.frustum = frustum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientLevel getWorld() {
|
public RenderContext getContext() {
|
||||||
return world;
|
return context;
|
||||||
}
|
|
||||||
|
|
||||||
public Camera getCamera() {
|
|
||||||
return camera;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Frustum getFrustum() {
|
|
||||||
return frustum;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vec3 getCameraPos() {
|
|
||||||
return camera.getPosition();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,8 @@ package com.jozufozu.flywheel.event;
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||||
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||||
import net.minecraftforge.event.entity.EntityLeaveWorldEvent;
|
import net.minecraftforge.event.entity.EntityLeaveWorldEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
|
|
||||||
public class EntityWorldHandler {
|
public class EntityWorldHandler {
|
||||||
|
|
||||||
|
|
|
@ -10,25 +10,21 @@ import com.jozufozu.flywheel.light.LightUpdater;
|
||||||
import com.jozufozu.flywheel.util.WorldAttached;
|
import com.jozufozu.flywheel.util.WorldAttached;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||||
import net.minecraftforge.event.TickEvent;
|
import net.minecraftforge.event.TickEvent;
|
||||||
import net.minecraftforge.event.world.WorldEvent;
|
import net.minecraftforge.event.world.WorldEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
|
|
||||||
public class ForgeEvents {
|
public class ForgeEvents {
|
||||||
|
|
||||||
public static void addToDebugScreen(RenderGameOverlayEvent.Text event) {
|
public static void addToDebugScreen(RenderGameOverlayEvent.Text event) {
|
||||||
|
|
||||||
if (Minecraft.getInstance().options.renderDebug) {
|
if (Minecraft.getInstance().options.renderDebug) {
|
||||||
|
|
||||||
ArrayList<String> debug = event.getRight();
|
ArrayList<String> debug = event.getRight();
|
||||||
debug.add("");
|
debug.add("");
|
||||||
debug.add("Flywheel: " + Flywheel.getVersion());
|
debug.add("Flywheel: " + Flywheel.getVersion());
|
||||||
|
|
||||||
InstancedRenderDispatcher.getDebugString(debug);
|
InstancedRenderDispatcher.getDebugString(debug);
|
||||||
|
|
||||||
|
// TODO: compress into one line
|
||||||
debug.add("Memory used:");
|
debug.add("Memory used:");
|
||||||
debug.add("GPU: " + FlywheelMemory.getGPUMemory());
|
debug.add("GPU: " + FlywheelMemory.getGPUMemory());
|
||||||
debug.add("CPU: " + FlywheelMemory.getCPUMemory());
|
debug.add("CPU: " + FlywheelMemory.getCPUMemory());
|
||||||
|
@ -39,8 +35,8 @@ public class ForgeEvents {
|
||||||
WorldAttached.invalidateWorld(event.getWorld());
|
WorldAttached.invalidateWorld(event.getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void tickLight(TickEvent.ClientTickEvent e) {
|
public static void tickLight(TickEvent.ClientTickEvent event) {
|
||||||
if (e.phase == TickEvent.Phase.END && Backend.isGameActive()) {
|
if (event.phase == TickEvent.Phase.END && Backend.isGameActive()) {
|
||||||
LightUpdater.get(Minecraft.getInstance().level)
|
LightUpdater.get(Minecraft.getInstance().level)
|
||||||
.tick();
|
.tick();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,69 +0,0 @@
|
||||||
package com.jozufozu.flywheel.event;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.core.RenderContext;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.math.Matrix4f;
|
|
||||||
|
|
||||||
import net.minecraft.client.multiplayer.ClientLevel;
|
|
||||||
import net.minecraft.client.renderer.RenderBuffers;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraftforge.eventbus.api.Event;
|
|
||||||
|
|
||||||
public class RenderLayerEvent extends Event {
|
|
||||||
public final RenderContext context;
|
|
||||||
public final RenderType type;
|
|
||||||
|
|
||||||
public RenderLayerEvent(RenderContext context, RenderType type) {
|
|
||||||
this.context = context;
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static Matrix4f createViewProjection(PoseStack view) {
|
|
||||||
var viewProjection = view.last()
|
|
||||||
.pose()
|
|
||||||
.copy();
|
|
||||||
viewProjection.multiplyBackward(RenderSystem.getProjectionMatrix());
|
|
||||||
return viewProjection;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "RenderLayerEvent{" + context + "}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClientLevel getWorld() {
|
|
||||||
return context.level();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RenderType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PoseStack getStack() {
|
|
||||||
return context.stack();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Matrix4f getViewProjection() {
|
|
||||||
return context.viewProjection();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RenderBuffers getBuffers() {
|
|
||||||
return context.buffers();
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getCamX() {
|
|
||||||
return context.camX();
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getCamY() {
|
|
||||||
return context.camY();
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getCamZ() {
|
|
||||||
return context.camZ();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.jozufozu.flywheel.event;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.RenderStage;
|
||||||
|
import com.jozufozu.flywheel.core.RenderContext;
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import com.mojang.math.Matrix4f;
|
||||||
|
|
||||||
|
import net.minecraft.client.Camera;
|
||||||
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
|
import net.minecraft.client.renderer.RenderBuffers;
|
||||||
|
import net.minecraftforge.eventbus.api.Event;
|
||||||
|
|
||||||
|
public class RenderStageEvent extends Event {
|
||||||
|
private final RenderContext context;
|
||||||
|
private final RenderStage stage;
|
||||||
|
|
||||||
|
public RenderStageEvent(RenderContext context, RenderStage stage) {
|
||||||
|
this.context = context;
|
||||||
|
this.stage = stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RenderContext getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RenderStage getStage() {
|
||||||
|
return stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientLevel getLevel() {
|
||||||
|
return context.level();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PoseStack getStack() {
|
||||||
|
return context.stack();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Matrix4f getViewProjection() {
|
||||||
|
return context.viewProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RenderBuffers getBuffers() {
|
||||||
|
return context.buffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Camera getCamera() {
|
||||||
|
return context.camera();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "RenderStageEvent{" + context + "}";
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,21 +0,0 @@
|
||||||
package com.jozufozu.flywheel.mixin;
|
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.core.LastActiveCamera;
|
|
||||||
|
|
||||||
import net.minecraft.client.Camera;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.level.BlockGetter;
|
|
||||||
|
|
||||||
@Mixin(Camera.class)
|
|
||||||
public class CameraMixin {
|
|
||||||
|
|
||||||
@Inject(method = "setup", at = @At("TAIL"))
|
|
||||||
private void setup(BlockGetter level, Entity entity, boolean is3rdPerson, boolean isMirrored, float pt, CallbackInfo ci) {
|
|
||||||
LastActiveCamera._setActiveCamera((Camera)(Object) this);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package com.jozufozu.flywheel.mixin;
|
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.ShadersModHandler;
|
|
||||||
import com.jozufozu.flywheel.backend.gl.GlStateTracker;
|
|
||||||
import com.jozufozu.flywheel.core.LastActiveCamera;
|
|
||||||
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.culling.Frustum;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
|
|
||||||
@Mixin(Frustum.class)
|
|
||||||
public class FrustumMixin {
|
|
||||||
|
|
||||||
@Inject(method = "prepare", at = @At("TAIL"))
|
|
||||||
private void onPrepare(double x, double y, double z, CallbackInfo ci) {
|
|
||||||
if (ShadersModHandler.isRenderingShadowPass()) {
|
|
||||||
try (var restoreState = GlStateTracker.getRestoreState()) {
|
|
||||||
MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(Minecraft.getInstance().level, LastActiveCamera.getActiveCamera(), (Frustum) (Object) this));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,183 +0,0 @@
|
||||||
package com.jozufozu.flywheel.mixin;
|
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
|
||||||
import com.jozufozu.flywheel.backend.gl.GlStateTracker;
|
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
|
||||||
import com.jozufozu.flywheel.core.RenderContext;
|
|
||||||
import com.jozufozu.flywheel.event.RenderLayerEvent;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import com.mojang.math.Matrix4f;
|
|
||||||
|
|
||||||
import net.minecraft.client.renderer.LevelRenderer;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.client.renderer.Sheets;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
|
|
||||||
@Mixin(value = LevelRenderer.class, priority = 1001) // Higher priority to go after sodium
|
|
||||||
public class LevelRendererDispatchMixin {
|
|
||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "renderChunkLayer")
|
|
||||||
private void renderChunkLayer(RenderType pRenderType, PoseStack pPoseStack, double pCamX, double pCamY, double pCamZ, Matrix4f pProjectionMatrix, CallbackInfo ci) {
|
|
||||||
try (var restoreState = GlStateTracker.getRestoreState()) {
|
|
||||||
|
|
||||||
// TODO: Is this necessary?
|
|
||||||
InstancedRenderDispatcher.renderSpecificType(RenderContext.CURRENT, pRenderType);
|
|
||||||
MinecraftForge.EVENT_BUS.post(new RenderLayerEvent(RenderContext.CURRENT, pRenderType));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch()V"))
|
|
||||||
private void endBatch(CallbackInfo ci) {
|
|
||||||
if (RenderContext.CURRENT != null && Backend.isGameActive() && Backend.isOn()) {
|
|
||||||
try (var restoreState = GlStateTracker.getRestoreState()) {
|
|
||||||
InstancedRenderDispatcher.renderAllRemaining(RenderContext.CURRENT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Unique
|
|
||||||
private void flywheel$dispatch(RenderType pRenderType) {
|
|
||||||
if (RenderContext.CURRENT != null && Backend.isGameActive() && Backend.isOn()) {
|
|
||||||
try (var restoreState = GlStateTracker.getRestoreState()) {
|
|
||||||
InstancedRenderDispatcher.renderSpecificType(RenderContext.CURRENT, pRenderType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 0, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$entitySolid(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.entitySolid(TextureAtlas.LOCATION_BLOCKS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 1, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$entityCutout(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.entityCutout(TextureAtlas.LOCATION_BLOCKS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 2, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$entityCutoutNoCull(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.entityCutoutNoCull(TextureAtlas.LOCATION_BLOCKS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 3, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$entitySmoothCutout(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.entitySmoothCutout(TextureAtlas.LOCATION_BLOCKS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 4, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$solid(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.solid());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 5, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$endPortal(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.endPortal());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 6, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$endGateway(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.endGateway());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 7, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$solidBlockSheet(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(Sheets.solidBlockSheet());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 8, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$cutoutBlockSheet(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(Sheets.cutoutBlockSheet());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 9, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$bedSheet(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(Sheets.bedSheet());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 10, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$shulkerBoxSheet(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(Sheets.shulkerBoxSheet());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 11, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$signSheet(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(Sheets.signSheet());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 12, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$chestSheet(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(Sheets.chestSheet());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 13, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$translucentCullBlockSheet(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(Sheets.translucentCullBlockSheet());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 14, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$bannerSheet(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(Sheets.bannerSheet());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 15, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$shieldSheet(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(Sheets.shieldSheet());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 16, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$armorGlint(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.armorGlint());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 17, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$armorEntityGlint(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.armorEntityGlint());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 18, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$glint(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.glint());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 19, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$glintDirect(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.glintDirect());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 20, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$glintTranslucent(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.glintTranslucent());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 21, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$entityGlint(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.entityGlint());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 22, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$entityGlintDirect(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.entityGlintDirect());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 23, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$waterMask(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.waterMask());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 24, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$lines1(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.lines());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 25, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V"))
|
|
||||||
private void renderLayer$lines2(CallbackInfo ci) {
|
|
||||||
flywheel$dispatch(RenderType.lines());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.jozufozu.flywheel.mixin;
|
package com.jozufozu.flywheel.mixin;
|
||||||
|
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
@ -9,14 +10,14 @@ import org.spongepowered.asm.mixin.injection.At.Shift;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.RenderStage;
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
import com.jozufozu.flywheel.backend.gl.GlStateTracker;
|
import com.jozufozu.flywheel.backend.gl.GlStateTracker;
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
|
||||||
import com.jozufozu.flywheel.core.RenderContext;
|
import com.jozufozu.flywheel.core.RenderContext;
|
||||||
import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer;
|
import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer;
|
||||||
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
||||||
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
||||||
import com.jozufozu.flywheel.event.RenderLayerEvent;
|
import com.jozufozu.flywheel.event.RenderStageEvent;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.math.Matrix4f;
|
import com.mojang.math.Matrix4f;
|
||||||
|
|
||||||
|
@ -26,13 +27,10 @@ import net.minecraft.client.renderer.GameRenderer;
|
||||||
import net.minecraft.client.renderer.LevelRenderer;
|
import net.minecraft.client.renderer.LevelRenderer;
|
||||||
import net.minecraft.client.renderer.LightTexture;
|
import net.minecraft.client.renderer.LightTexture;
|
||||||
import net.minecraft.client.renderer.RenderBuffers;
|
import net.minecraft.client.renderer.RenderBuffers;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
|
||||||
@Mixin(value = LevelRenderer.class, priority = 1001) // Higher priority to go after sodium
|
@Mixin(value = LevelRenderer.class, priority = 1001) // Higher priority to go after sodium
|
||||||
public class LevelRendererMixin {
|
public class LevelRendererMixin {
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
private ClientLevel level;
|
private ClientLevel level;
|
||||||
|
|
||||||
|
@ -40,19 +38,21 @@ public class LevelRendererMixin {
|
||||||
@Final
|
@Final
|
||||||
private RenderBuffers renderBuffers;
|
private RenderBuffers renderBuffers;
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private RenderContext renderContext;
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "renderLevel")
|
@Inject(at = @At("HEAD"), method = "renderLevel")
|
||||||
private void beginRender(PoseStack pPoseStack, float pPartialTick, long pFinishNanoTime, boolean pRenderBlockOutline, Camera pCamera, GameRenderer pGameRenderer, LightTexture pLightTexture, Matrix4f pProjectionMatrix, CallbackInfo ci) {
|
private void beginRender(PoseStack pPoseStack, float pPartialTick, long pFinishNanoTime, boolean pRenderBlockOutline, Camera pCamera, GameRenderer pGameRenderer, LightTexture pLightTexture, Matrix4f pProjectionMatrix, CallbackInfo ci) {
|
||||||
Vec3 position = pCamera.getPosition();
|
renderContext = new RenderContext((LevelRenderer) (Object) this, level, pPoseStack, RenderContext.createViewProjection(pPoseStack, pProjectionMatrix), pProjectionMatrix, renderBuffers, pCamera);
|
||||||
RenderContext.CURRENT = new RenderContext(level, pPoseStack, RenderLayerEvent.createViewProjection(pPoseStack), renderBuffers, position.x, position.y, position.z);
|
|
||||||
|
|
||||||
try (var restoreState = GlStateTracker.getRestoreState()) {
|
try (var restoreState = GlStateTracker.getRestoreState()) {
|
||||||
MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(level, pCamera, null));
|
MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(renderContext));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "renderLevel")
|
@Inject(at = @At("TAIL"), method = "renderLevel")
|
||||||
private void endRender(PoseStack pPoseStack, float pPartialTick, long pFinishNanoTime, boolean pRenderBlockOutline, Camera pCamera, GameRenderer pGameRenderer, LightTexture pLightTexture, Matrix4f pProjectionMatrix, CallbackInfo ci) {
|
private void endRender(PoseStack pPoseStack, float pPartialTick, long pFinishNanoTime, boolean pRenderBlockOutline, Camera pCamera, GameRenderer pGameRenderer, LightTexture pLightTexture, Matrix4f pProjectionMatrix, CallbackInfo ci) {
|
||||||
RenderContext.CURRENT = null;
|
renderContext = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "allChanged")
|
@Inject(at = @At("TAIL"), method = "allChanged")
|
||||||
|
@ -64,7 +64,90 @@ public class LevelRendererMixin {
|
||||||
|
|
||||||
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderBuffers;crumblingBufferSource()Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;", ordinal = 2, shift = Shift.BY, by = 2 // after the game renders the breaking overlay normally
|
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderBuffers;crumblingBufferSource()Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;", ordinal = 2, shift = Shift.BY, by = 2 // after the game renders the breaking overlay normally
|
||||||
), method = "renderLevel")
|
), method = "renderLevel")
|
||||||
private void renderBlockBreaking(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci) {
|
private void renderCrumbling(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci) {
|
||||||
CrumblingRenderer.renderCrumbling((LevelRenderer) (Object) this, level, poseStack, camera, projectionMatrix);
|
if (renderContext != null) {
|
||||||
|
CrumblingRenderer.renderCrumbling(renderContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// STAGE DISPATCHING
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private void flywheel$dispatch(RenderStage stage) {
|
||||||
|
if (renderContext != null) {
|
||||||
|
try (var restoreState = GlStateTracker.getRestoreState()) {
|
||||||
|
MinecraftForge.EVENT_BUS.post(new RenderStageEvent(renderContext, stage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", args = "ldc=sky"))
|
||||||
|
private void onStage$beforeSky(CallbackInfo ci) {
|
||||||
|
flywheel$dispatch(RenderStage.BEFORE_SKY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", args = "ldc=fog"))
|
||||||
|
private void onStage$afterSky(CallbackInfo ci) {
|
||||||
|
flywheel$dispatch(RenderStage.AFTER_SKY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", args = "ldc=terrain"))
|
||||||
|
private void onStage$beforeTerrain(CallbackInfo ci) {
|
||||||
|
flywheel$dispatch(RenderStage.BEFORE_TERRAIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", args = "ldc=entities"))
|
||||||
|
private void onStage$afterSolidTerrain(CallbackInfo ci) {
|
||||||
|
flywheel$dispatch(RenderStage.AFTER_SOLID_TERRAIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderBuffers;bufferSource()Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;", ordinal = 0))
|
||||||
|
private void onStage$beforeEntities(CallbackInfo ci) {
|
||||||
|
flywheel$dispatch(RenderStage.BEFORE_ENTITIES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", args = "ldc=blockentities"))
|
||||||
|
private void onStage$beforeBlockEntities(CallbackInfo ci) {
|
||||||
|
flywheel$dispatch(RenderStage.AFTER_ENTITIES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/OutlineBufferSource;endOutlineBatch()V", ordinal = 0))
|
||||||
|
private void onStage$afterSolidBlockEntities(CallbackInfo ci) {
|
||||||
|
flywheel$dispatch(RenderStage.AFTER_BLOCK_ENTITIES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch()V", ordinal = 0))
|
||||||
|
private void onStage$beforeCrumbling(CallbackInfo ci) {
|
||||||
|
flywheel$dispatch(RenderStage.BEFORE_CRUMBLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/LevelRenderer;translucentTarget:Lcom/mojang/blaze3d/pipeline/RenderTarget;", opcode = Opcodes.GETFIELD, ordinal = 0))
|
||||||
|
private void onStage$afterFinalEndBatch$fabulous(CallbackInfo ci) {
|
||||||
|
flywheel$dispatch(RenderStage.AFTER_FINAL_END_BATCH);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/LevelRenderer;particlesTarget:Lcom/mojang/blaze3d/pipeline/RenderTarget;", opcode = Opcodes.GETFIELD, ordinal = 0))
|
||||||
|
private void onStage$afterTranslucentTerrain$fabulous(CallbackInfo ci) {
|
||||||
|
flywheel$dispatch(RenderStage.AFTER_TRANSLUCENT_TERRAIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch()V", ordinal = 2, shift = Shift.AFTER))
|
||||||
|
private void onStage$afterFinalEndBatch(CallbackInfo ci) {
|
||||||
|
flywheel$dispatch(RenderStage.AFTER_FINAL_END_BATCH);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLcom/mojang/math/Matrix4f;)V", ordinal = 6, shift = Shift.AFTER))
|
||||||
|
private void onStage$afterTranslucentTerrain(CallbackInfo ci) {
|
||||||
|
flywheel$dispatch(RenderStage.AFTER_TRANSLUCENT_TERRAIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;FLnet/minecraft/client/renderer/culling/Frustum;)V", shift = Shift.AFTER))
|
||||||
|
private void onStage$afterParticles(CallbackInfo ci) {
|
||||||
|
flywheel$dispatch(RenderStage.AFTER_PARTICLES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderSnowAndRain(Lnet/minecraft/client/renderer/LightTexture;FDDD)V", shift = Shift.AFTER))
|
||||||
|
private void onStage$afterWeather(CallbackInfo ci) {
|
||||||
|
flywheel$dispatch(RenderStage.AFTER_WEATHER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,15 @@ import java.util.List;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.RenderStage;
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
|
||||||
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
||||||
import com.jozufozu.flywheel.core.BasicModelSupplier;
|
import com.jozufozu.flywheel.core.BasicModelSupplier;
|
||||||
import com.jozufozu.flywheel.core.hardcoded.ModelPart;
|
import com.jozufozu.flywheel.core.hardcoded.ModelPart;
|
||||||
import com.jozufozu.flywheel.core.material.MaterialShaders;
|
import com.jozufozu.flywheel.core.material.MaterialShaders;
|
||||||
|
import com.jozufozu.flywheel.core.material.SimpleMaterial;
|
||||||
import com.jozufozu.flywheel.core.structs.StructTypes;
|
import com.jozufozu.flywheel.core.structs.StructTypes;
|
||||||
import com.jozufozu.flywheel.core.structs.oriented.OrientedPart;
|
import com.jozufozu.flywheel.core.structs.oriented.OrientedPart;
|
||||||
import com.jozufozu.flywheel.util.AnimationTickHolder;
|
import com.jozufozu.flywheel.util.AnimationTickHolder;
|
||||||
|
@ -26,7 +27,7 @@ import net.minecraft.world.level.block.entity.BellBlockEntity;
|
||||||
|
|
||||||
public class BellInstance extends BlockEntityInstance<BellBlockEntity> implements DynamicInstance {
|
public class BellInstance extends BlockEntityInstance<BellBlockEntity> implements DynamicInstance {
|
||||||
|
|
||||||
private static final BasicModelSupplier MODEL = new BasicModelSupplier(BellInstance::createBellModel, new Material(Sheets.solidBlockSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT));
|
private static final BasicModelSupplier MODEL = new BasicModelSupplier(BellInstance::createBellModel, new SimpleMaterial(RenderStage.AFTER_BLOCK_ENTITIES, Sheets.solidBlockSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT));
|
||||||
|
|
||||||
private final OrientedPart bell;
|
private final OrientedPart bell;
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,15 @@ import java.util.function.BiFunction;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.RenderStage;
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
|
||||||
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
||||||
import com.jozufozu.flywheel.core.BasicModelSupplier;
|
import com.jozufozu.flywheel.core.BasicModelSupplier;
|
||||||
import com.jozufozu.flywheel.core.hardcoded.ModelPart;
|
import com.jozufozu.flywheel.core.hardcoded.ModelPart;
|
||||||
import com.jozufozu.flywheel.core.material.MaterialShaders;
|
import com.jozufozu.flywheel.core.material.MaterialShaders;
|
||||||
|
import com.jozufozu.flywheel.core.material.SimpleMaterial;
|
||||||
import com.jozufozu.flywheel.core.structs.StructTypes;
|
import com.jozufozu.flywheel.core.structs.StructTypes;
|
||||||
import com.jozufozu.flywheel.core.structs.model.TransformedPart;
|
import com.jozufozu.flywheel.core.structs.model.TransformedPart;
|
||||||
import com.jozufozu.flywheel.core.structs.oriented.OrientedPart;
|
import com.jozufozu.flywheel.core.structs.oriented.OrientedPart;
|
||||||
|
@ -37,7 +39,7 @@ import net.minecraft.world.level.block.state.properties.ChestType;
|
||||||
|
|
||||||
public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends BlockEntityInstance<T> implements DynamicInstance {
|
public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends BlockEntityInstance<T> implements DynamicInstance {
|
||||||
|
|
||||||
private static final com.jozufozu.flywheel.api.material.Material CHEST_MATERIAL = new com.jozufozu.flywheel.api.material.Material(Sheets.chestSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT);
|
private static final com.jozufozu.flywheel.api.material.Material CHEST_MATERIAL = new SimpleMaterial(RenderStage.AFTER_BLOCK_ENTITIES, Sheets.chestSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT);
|
||||||
private static final BiFunction<ChestType, Material, BasicModelSupplier> LID = Util.memoize((type, mat) -> new BasicModelSupplier(() -> createLidModel(type, mat.sprite()), CHEST_MATERIAL));
|
private static final BiFunction<ChestType, Material, BasicModelSupplier> LID = Util.memoize((type, mat) -> new BasicModelSupplier(() -> createLidModel(type, mat.sprite()), CHEST_MATERIAL));
|
||||||
private static final BiFunction<ChestType, Material, BasicModelSupplier> BASE = Util.memoize((type, mat) -> new BasicModelSupplier(() -> createBaseModel(type, mat.sprite()), CHEST_MATERIAL));
|
private static final BiFunction<ChestType, Material, BasicModelSupplier> BASE = Util.memoize((type, mat) -> new BasicModelSupplier(() -> createBaseModel(type, mat.sprite()), CHEST_MATERIAL));
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,16 @@ package com.jozufozu.flywheel.vanilla;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
import com.jozufozu.flywheel.api.RenderStage;
|
||||||
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
||||||
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance;
|
import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance;
|
||||||
import com.jozufozu.flywheel.core.BasicModelSupplier;
|
import com.jozufozu.flywheel.core.BasicModelSupplier;
|
||||||
import com.jozufozu.flywheel.core.Models;
|
import com.jozufozu.flywheel.core.Models;
|
||||||
import com.jozufozu.flywheel.core.hardcoded.ModelPart;
|
import com.jozufozu.flywheel.core.hardcoded.ModelPart;
|
||||||
import com.jozufozu.flywheel.core.material.MaterialShaders;
|
import com.jozufozu.flywheel.core.material.MaterialShaders;
|
||||||
|
import com.jozufozu.flywheel.core.material.SimpleMaterial;
|
||||||
import com.jozufozu.flywheel.core.model.Mesh;
|
import com.jozufozu.flywheel.core.model.Mesh;
|
||||||
import com.jozufozu.flywheel.core.structs.StructTypes;
|
import com.jozufozu.flywheel.core.structs.StructTypes;
|
||||||
import com.jozufozu.flywheel.core.structs.model.TransformedPart;
|
import com.jozufozu.flywheel.core.structs.model.TransformedPart;
|
||||||
|
@ -31,7 +32,7 @@ import net.minecraft.world.phys.Vec3;
|
||||||
public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance<T> implements DynamicInstance, TickableInstance {
|
public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance<T> implements DynamicInstance, TickableInstance {
|
||||||
|
|
||||||
private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png");
|
private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png");
|
||||||
private static final BasicModelSupplier MODEL = new BasicModelSupplier(MinecartInstance::getBodyModel, new Material(RenderType.entitySolid(MINECART_LOCATION), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT));
|
private static final BasicModelSupplier MODEL = new BasicModelSupplier(MinecartInstance::getBodyModel, new SimpleMaterial(RenderStage.AFTER_ENTITIES, RenderType.entitySolid(MINECART_LOCATION), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT));
|
||||||
|
|
||||||
private final PoseStack stack = new PoseStack();
|
private final PoseStack stack = new PoseStack();
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,16 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancedPart;
|
import com.jozufozu.flywheel.api.RenderStage;
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
|
||||||
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancedPart;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance;
|
||||||
import com.jozufozu.flywheel.core.BasicModelSupplier;
|
import com.jozufozu.flywheel.core.BasicModelSupplier;
|
||||||
import com.jozufozu.flywheel.core.hardcoded.ModelPart;
|
import com.jozufozu.flywheel.core.hardcoded.ModelPart;
|
||||||
import com.jozufozu.flywheel.core.material.MaterialShaders;
|
import com.jozufozu.flywheel.core.material.MaterialShaders;
|
||||||
|
import com.jozufozu.flywheel.core.material.SimpleMaterial;
|
||||||
import com.jozufozu.flywheel.core.structs.StructTypes;
|
import com.jozufozu.flywheel.core.structs.StructTypes;
|
||||||
import com.jozufozu.flywheel.core.structs.model.TransformedPart;
|
import com.jozufozu.flywheel.core.structs.model.TransformedPart;
|
||||||
import com.jozufozu.flywheel.util.AnimationTickHolder;
|
import com.jozufozu.flywheel.util.AnimationTickHolder;
|
||||||
|
@ -31,7 +33,7 @@ import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
|
||||||
|
|
||||||
public class ShulkerBoxInstance extends BlockEntityInstance<ShulkerBoxBlockEntity> implements DynamicInstance {
|
public class ShulkerBoxInstance extends BlockEntityInstance<ShulkerBoxBlockEntity> implements DynamicInstance {
|
||||||
|
|
||||||
private static final Material SHULKER_BOX_MATERIAL = new Material(RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT);
|
private static final Material SHULKER_BOX_MATERIAL = new SimpleMaterial(RenderStage.AFTER_BLOCK_ENTITIES, RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT);
|
||||||
private static final Function<TextureAtlasSprite, BasicModelSupplier> BASE = Util.memoize(it -> new BasicModelSupplier(() -> makeBaseModel(it), SHULKER_BOX_MATERIAL));
|
private static final Function<TextureAtlasSprite, BasicModelSupplier> BASE = Util.memoize(it -> new BasicModelSupplier(() -> makeBaseModel(it), SHULKER_BOX_MATERIAL));
|
||||||
private static final Function<TextureAtlasSprite, BasicModelSupplier> LID = Util.memoize(it -> new BasicModelSupplier(() -> makeLidModel(it), SHULKER_BOX_MATERIAL));
|
private static final Function<TextureAtlasSprite, BasicModelSupplier> LID = Util.memoize(it -> new BasicModelSupplier(() -> makeLidModel(it), SHULKER_BOX_MATERIAL));
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,9 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.InstancerManager;
|
|
||||||
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
import com.jozufozu.flywheel.api.instance.DynamicInstance;
|
||||||
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
import com.jozufozu.flywheel.api.instance.TickableInstance;
|
||||||
|
import com.jozufozu.flywheel.api.instancer.InstancerManager;
|
||||||
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
|
||||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||||
import com.jozufozu.flywheel.backend.instancing.effect.Effect;
|
import com.jozufozu.flywheel.backend.instancing.effect.Effect;
|
||||||
|
|
|
@ -9,17 +9,14 @@
|
||||||
"BlockEntityTypeMixin",
|
"BlockEntityTypeMixin",
|
||||||
"BufferBuilderMixin",
|
"BufferBuilderMixin",
|
||||||
"BufferUploaderMixin",
|
"BufferUploaderMixin",
|
||||||
"CameraMixin",
|
|
||||||
"ChunkRebuildHooksMixin",
|
"ChunkRebuildHooksMixin",
|
||||||
"ClientLevelMixin",
|
"ClientLevelMixin",
|
||||||
"EntityTypeMixin",
|
"EntityTypeMixin",
|
||||||
"FixFabulousDepthMixin",
|
"FixFabulousDepthMixin",
|
||||||
"FrustumMixin",
|
|
||||||
"GlStateManagerMixin",
|
"GlStateManagerMixin",
|
||||||
"InstanceAddMixin",
|
"InstanceAddMixin",
|
||||||
"InstanceRemoveMixin",
|
"InstanceRemoveMixin",
|
||||||
"LevelRendererAccessor",
|
"LevelRendererAccessor",
|
||||||
"LevelRendererDispatchMixin",
|
|
||||||
"LevelRendererInstanceUpdateMixin",
|
"LevelRendererInstanceUpdateMixin",
|
||||||
"LevelRendererMixin",
|
"LevelRendererMixin",
|
||||||
"PausedPartialTickAccessor",
|
"PausedPartialTickAccessor",
|
||||||
|
|
Loading…
Reference in a new issue