mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-25 22:54:28 +00:00
Entity Shadow Replay (#2294)
This commit is contained in:
1 parent
102c6cad86
commit
713509a87b
39 files changed
+3750
-157
No files matched your search
@@ -15,6 +15,7 @@ import com.gtnewhorizons.angelica.glsm.streaming.PersistentStreamingBuffer;
|
||||
import com.gtnewhorizons.angelica.glsm.streaming.StreamingUploader;
|
||||
import com.gtnewhorizons.angelica.hudcaching.HUDCaching;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.BatchDrawDefaults;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.EntityShadowReplay;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.ModelPartBatcher;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.TesrBatchRenderer;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
@@ -1251,6 +1252,7 @@ public class BatchingFontRenderer {
|
||||
if (string == null || string.length() == 0) {
|
||||
return anchorX + (enableShadow ? 1.0f : 0.0f);
|
||||
}
|
||||
EntityShadowReplay.rejectForeignDraw();
|
||||
final int color = buttonSectionActive
|
||||
? DarkModeUtils.recolorButtonText(inputColor, buttonEnabledColor, buttonHoveredColor, buttonDisabledColor)
|
||||
: inputColor;
|
||||
|
||||
@@ -167,6 +167,20 @@ public class AngelicaConfig {
|
||||
@Config.DefaultBoolean(true)
|
||||
public static boolean enableEntityTextureAtlas;
|
||||
|
||||
@Config.Comment("Replay entity draws recorded in the shader shadow pass in the main view instead of running each entity renderer again (experimental, requires entity batching)")
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enableEntityShadowReplay;
|
||||
|
||||
@Config.Comment("Entity classes that run their renderer again in the main view instead of replaying shadow pass draws. Players are always excluded.")
|
||||
@Config.DefaultStringList({
|
||||
"chylex.hee.entity.boss.EntityBossDragon",
|
||||
"twilightforest.entity.passive.EntityTFMobileFirefly",
|
||||
"gregtech.common.entity.EntityDrone"
|
||||
})
|
||||
@Config.RequiresMcRestart
|
||||
public static String[] entityShadowReplayExcludedClasses;
|
||||
|
||||
@Config.Comment("Skip the end-of-frame shader buffer copy by ping-ponging buffers. Disable if a shader pack misrenders.")
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.RequiresMcRestart
|
||||
@@ -548,6 +562,10 @@ public class AngelicaConfig {
|
||||
return enableEntityBatching && enableCubeInstancing;
|
||||
}
|
||||
|
||||
public static boolean entityShadowReplayEnabled() {
|
||||
return enableEntityBatching && enableEntityShadowReplay;
|
||||
}
|
||||
|
||||
public static boolean sdlGpuConfigured() {
|
||||
return renderBackend == RenderBackendChoice.SDL_GPU;
|
||||
}
|
||||
|
||||
@@ -67,8 +67,15 @@ public class IrisGLSMBridge {
|
||||
public static void installImmediateExtendedHandler() {
|
||||
GLSMHooks.immediateExtendedHandler = new ImmediateExtendedAttribs();
|
||||
final CapturedRenderingState state = CapturedRenderingState.INSTANCE;
|
||||
state.setEntityIdsListener(() -> GLStateManager.setEntityIds(
|
||||
state.getCurrentRenderedEntity(), state.getCurrentRenderedBlockEntity(), state.getCurrentRenderedItem()));
|
||||
state.setEntityIdsListener(() -> {
|
||||
final boolean suspended = GLStateManager.suspendExitCapture();
|
||||
try {
|
||||
GLStateManager.setEntityIds(
|
||||
state.getCurrentRenderedEntity(), state.getCurrentRenderedBlockEntity(), state.getCurrentRenderedItem());
|
||||
} finally {
|
||||
GLStateManager.resumeExitCapture(suspended);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void installPostTransformHook() {
|
||||
|
||||
@@ -207,6 +207,15 @@ public enum Mixins implements IMixins {
|
||||
)
|
||||
),
|
||||
|
||||
ANGELICA_ENTITY_SHADOW_REPLAY(new MixinBuilder("Replay entity draws recorded in the shader shadow pass in the main view instead of running each entity renderer again")
|
||||
.setPhase(Phase.EARLY)
|
||||
.setApplyIf(() -> AngelicaConfig.enableIris && AngelicaConfig.entityShadowReplayEnabled())
|
||||
.addClientMixins(
|
||||
"angelica.entity.MixinBossStatus_EntityReplay",
|
||||
"angelica.entity.MixinRenderGlobal_EntityReplay"
|
||||
)
|
||||
),
|
||||
|
||||
ANGELICA_CUBE_INSTANCING(new MixinBuilder("Capture cuboid parameters so model cubes can be drawn from a shared unit cube")
|
||||
.setPhase(Phase.EARLY)
|
||||
.setApplyIf(AngelicaConfig::cubeInstancingEnabled)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.gtnewhorizons.angelica.rendering;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.EntityShadowReplay;
|
||||
import lombok.Getter;
|
||||
import net.coderbot.iris.layer.GbufferPrograms;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
@@ -8,6 +9,8 @@ import net.coderbot.iris.uniforms.EntityIdHelper;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.entity.RendererLivingEntity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Matrix4fc;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@@ -37,6 +40,7 @@ public class DeferredEntityOverlay {
|
||||
private static final List<DeferredEntry> pool = new ArrayList<>(INITIAL_CAPACITY);
|
||||
|
||||
private static final FloatBuffer MATRIX_BUF = BufferUtils.createFloatBuffer(16);
|
||||
private static final Matrix4f replayMatrix = new Matrix4f();
|
||||
|
||||
// Set by the shouldRenderPass inject, consumed by the doRender WrapOperation.
|
||||
@Getter
|
||||
@@ -68,6 +72,9 @@ public class DeferredEntityOverlay {
|
||||
|
||||
public static void clearStaleOverlayFlag() {
|
||||
overlayPassActive = false;
|
||||
pendingShouldRenderPass = null;
|
||||
pendingRenderer = null;
|
||||
pendingEntity = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,21 +83,23 @@ public class DeferredEntityOverlay {
|
||||
*/
|
||||
public static void deferRender(float limbSwing, float limbSwingAmount, float ageInTicks,
|
||||
float headYaw, float headPitch, float scale) {
|
||||
overlayPassActive = false;
|
||||
|
||||
DeferredEntry entry = acquireEntry();
|
||||
entry.set(pendingShouldRenderPass, pendingRenderer, pendingEntity, pendingPartialTick,
|
||||
limbSwing, limbSwingAmount, ageInTicks, headYaw, headPitch, scale);
|
||||
|
||||
MATRIX_BUF.clear();
|
||||
GLStateManager.glGetFloat(GL11.GL_MODELVIEW_MATRIX, MATRIX_BUF);
|
||||
MATRIX_BUF.get(entry.matrix);
|
||||
GLStateManager.getModelViewMatrix().get(entry.matrix);
|
||||
|
||||
deferred.add(entry);
|
||||
EntityShadowReplay.recordDeferredOverlay(entry);
|
||||
|
||||
pendingShouldRenderPass = null;
|
||||
pendingRenderer = null;
|
||||
pendingEntity = null;
|
||||
clearStaleOverlayFlag();
|
||||
}
|
||||
|
||||
public static void queueReplay(DeferredEntry captured, Matrix4fc mainFromShadow) {
|
||||
final DeferredEntry entry = acquireEntry();
|
||||
entry.set(captured);
|
||||
replayMatrix.set(captured.matrix).mulLocal(mainFromShadow).get(entry.matrix);
|
||||
deferred.add(entry);
|
||||
}
|
||||
|
||||
private static DeferredEntry acquireEntry() {
|
||||
@@ -103,9 +112,7 @@ public class DeferredEntityOverlay {
|
||||
|
||||
private static void recycle() {
|
||||
for (DeferredEntry entry : deferred) {
|
||||
entry.shouldRenderPass = null;
|
||||
entry.renderer = null;
|
||||
entry.entity = null;
|
||||
entry.clear();
|
||||
pool.add(entry);
|
||||
}
|
||||
deferred.clear();
|
||||
@@ -113,7 +120,7 @@ public class DeferredEntityOverlay {
|
||||
|
||||
public static void clear() {
|
||||
recycle();
|
||||
overlayPassActive = false;
|
||||
clearStaleOverlayFlag();
|
||||
replaying = false;
|
||||
}
|
||||
|
||||
@@ -138,7 +145,7 @@ public class DeferredEntityOverlay {
|
||||
|
||||
// Restore the entity's lightmap coords
|
||||
int brightness = entity.getBrightnessForRender(entry.partialTick);
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,
|
||||
GLStateManager.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,
|
||||
brightness % 65536, (float) brightness / 65536);
|
||||
|
||||
// Restore the saved modelview matrix
|
||||
@@ -183,7 +190,7 @@ public class DeferredEntityOverlay {
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeferredEntry {
|
||||
public static final class DeferredEntry {
|
||||
final float[] matrix = new float[16];
|
||||
ShouldRenderPassFn shouldRenderPass;
|
||||
RendererLivingEntity renderer;
|
||||
@@ -196,6 +203,22 @@ public class DeferredEntityOverlay {
|
||||
float headPitch;
|
||||
float scale;
|
||||
|
||||
public void copyFrom(DeferredEntry source) {
|
||||
set(source);
|
||||
System.arraycopy(source.matrix, 0, matrix, 0, matrix.length);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
shouldRenderPass = null;
|
||||
renderer = null;
|
||||
entity = null;
|
||||
}
|
||||
|
||||
private void set(DeferredEntry source) {
|
||||
set(source.shouldRenderPass, source.renderer, source.entity, source.partialTick,
|
||||
source.limbSwing, source.limbSwingAmount, source.ageInTicks, source.headYaw, source.headPitch, source.scale);
|
||||
}
|
||||
|
||||
void set(ShouldRenderPassFn shouldRenderPass, RendererLivingEntity renderer,
|
||||
EntityLivingBase entity, float partialTick,
|
||||
float limbSwing, float limbSwingAmount, float ageInTicks,
|
||||
|
||||
@@ -32,22 +32,23 @@ public final class SkippedGlintBlock {
|
||||
}
|
||||
|
||||
private static void applyExitState(float red, float green, float blue, float alpha, int srcRgb, int dstRgb, int srcAlpha, int dstAlpha, boolean resetTextureMatrix, boolean restoreDepthMask) {
|
||||
final boolean recording = GLStateManager.isExitCaptureActive();
|
||||
final Color4 color = GLStateManager.getColor();
|
||||
if (color.getRed() != red || color.getGreen() != green || color.getBlue() != blue || color.getAlpha() != alpha) {
|
||||
if (recording || color.getRed() != red || color.getGreen() != green || color.getBlue() != blue || color.getAlpha() != alpha) {
|
||||
GLStateManager.glColor4f(red, green, blue, alpha);
|
||||
}
|
||||
if (resetTextureMatrix && !MatrixHelper.isIdentity(GLStateManager.getTextures().getTextureUnitMatrix(0))) {
|
||||
if (resetTextureMatrix && (recording || !MatrixHelper.isIdentity(GLStateManager.getTextures().getTextureUnitMatrix(0)))) {
|
||||
GLStateManager.glMatrixMode(GL11.GL_TEXTURE);
|
||||
GLStateManager.glLoadIdentity();
|
||||
}
|
||||
if (GLStateManager.getMatrixMode().getMode() != GL11.GL_MODELVIEW) GLStateManager.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
if (restoreDepthMask && !GLStateManager.isEffectiveDepthMaskEnabled()) GLStateManager.glDepthMask(true);
|
||||
if (!GLStateManager.getLightingState().isEnabled()) GLStateManager.glEnable(GL11.GL_LIGHTING);
|
||||
if (recording || GLStateManager.getMatrixMode().getMode() != GL11.GL_MODELVIEW) GLStateManager.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
if (restoreDepthMask && (recording || !GLStateManager.isEffectiveDepthMaskEnabled())) GLStateManager.glDepthMask(true);
|
||||
if (recording || !GLStateManager.getLightingState().isEnabled()) GLStateManager.glEnable(GL11.GL_LIGHTING);
|
||||
GLStateManager.getEffectiveBlendState(blend);
|
||||
if (GLStateManager.getBlendState().isFuncUnknown() || blend.getSrcRgb() != srcRgb || blend.getDstRgb() != dstRgb || blend.getSrcAlpha() != srcAlpha || blend.getDstAlpha() != dstAlpha) {
|
||||
if (recording || GLStateManager.getBlendState().isFuncUnknown() || blend.getSrcRgb() != srcRgb || blend.getDstRgb() != dstRgb || blend.getSrcAlpha() != srcAlpha || blend.getDstAlpha() != dstAlpha) {
|
||||
GLStateManager.tryBlendFuncSeparate(srcRgb, dstRgb, srcAlpha, dstAlpha);
|
||||
}
|
||||
if (GLStateManager.isEffectiveBlendEnabled()) GLStateManager.glDisable(GL11.GL_BLEND);
|
||||
if (GLStateManager.getDepthState().getFunc() != GL11.GL_LEQUAL) GLStateManager.glDepthFunc(GL11.GL_LEQUAL);
|
||||
if (recording || GLStateManager.isEffectiveBlendEnabled()) GLStateManager.glDisable(GL11.GL_BLEND);
|
||||
if (recording || GLStateManager.getDepthState().getFunc() != GL11.GL_LEQUAL) GLStateManager.glDepthFunc(GL11.GL_LEQUAL);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import com.gtnewhorizons.angelica.rendering.tesr.BatchEligibility;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.EntityMaterials;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.GlintCapture;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.ModelPartBatcher;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.EntityShadowReplay;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.TemplateBuffer;
|
||||
import com.gtnewhorizons.angelica.utils.AnimationsRenderUtils;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
@@ -149,6 +150,7 @@ public final class DroppedItemInstancer {
|
||||
}
|
||||
final boolean allowed = BatchEligibility.batchingAllowed();
|
||||
if (allowed && ModelPartBatcher.INSTANCE.isShadowPass()) {
|
||||
EntityShadowReplay.rejectShadowOnly();
|
||||
BatchEligibility.onPartQueued();
|
||||
return SKIP;
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@ public final class BatchEligibility {
|
||||
static boolean insideRenderer() { return depth != 0; }
|
||||
|
||||
static void onUncapturedState() {
|
||||
EntityShadowReplay.rejectUncapturedState();
|
||||
if (depth == 0) return;
|
||||
uncapturedState = true;
|
||||
allowed = false;
|
||||
@@ -125,6 +126,7 @@ public final class BatchEligibility {
|
||||
}
|
||||
|
||||
static void onBail(ModelPartBatcher.BailReason reason) {
|
||||
EntityShadowReplay.rejectBatcherBail();
|
||||
if (depth == 0 || !allowed) return;
|
||||
if (reason == ModelPartBatcher.BailReason.INACTIVE) {
|
||||
allowed = false;
|
||||
@@ -138,6 +140,7 @@ public final class BatchEligibility {
|
||||
}
|
||||
|
||||
public static void onPartFallback(long drawsBefore, long drawsNow) {
|
||||
EntityShadowReplay.rejectPartFallback();
|
||||
parts++;
|
||||
if (!allowed) {
|
||||
expectedDraws += drawsNow - drawsBefore;
|
||||
|
||||
@@ -44,6 +44,7 @@ public final class EntityMaterials {
|
||||
}
|
||||
|
||||
static TesrMaterial fromCurrentState(boolean texIdentity) {
|
||||
GLStateManager.requireExitDrawState(true);
|
||||
final boolean textured = GLStateManager.getTextures().getTextureUnitStates(0).isEnabled();
|
||||
final AlphaState alpha = GLStateManager.getEffectiveAlphaState(effectiveAlpha);
|
||||
final ColorMask colorMask = GLStateManager.getEffectiveColorMask(effectiveColorMask);
|
||||
@@ -58,6 +59,7 @@ public final class EntityMaterials {
|
||||
}
|
||||
|
||||
public static TesrMaterial itemFromCurrentState(boolean unfilteredAtlas) {
|
||||
GLStateManager.requireExitDrawState(true);
|
||||
final BlendState blend = GLStateManager.getEffectiveBlendState(effectiveBlend);
|
||||
final AlphaState alpha = GLStateManager.getEffectiveAlphaState(effectiveAlpha);
|
||||
return itemFromState(unfilteredAtlas, GLStateManager.isEffectiveBlendEnabled(), blend.getSrcRgb(), blend.getDstRgb(),
|
||||
|
||||
@@ -0,0 +1,387 @@
|
||||
package com.gtnewhorizons.angelica.rendering.tesr;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.util.ModelQuadUtil;
|
||||
import com.gtnewhorizons.angelica.api.tesr.TesrMaterial;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.RenderLayer;
|
||||
import com.gtnewhorizons.angelica.glsm.ffp.CubeParams;
|
||||
import com.gtnewhorizons.angelica.glsm.profiling.Tracy;
|
||||
import com.gtnewhorizons.angelica.rendering.DeferredEntityOverlay;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.EntityShadowReplay.Rejection;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.RetainedTesrGroups.InstanceColumns;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.RetainedTesrGroups.InstanceRange;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.coderbot.iris.layer.PassOverride;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Matrix4fc;
|
||||
import org.joml.Vector4fc;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.gtnewhorizons.angelica.rendering.items.ItemGlint.canResetStencil;
|
||||
|
||||
/**
|
||||
* Ordered, pooled submissions captured before the main entity pass.
|
||||
*/
|
||||
final class EntityRenderCommands {
|
||||
private final ObjectArrayList<Command> commands = new ObjectArrayList<>();
|
||||
private final Pool<Model> models = new Pool<>(Model::new, Model::clear);
|
||||
private final Pool<ModelGlint> modelGlints = new Pool<>(ModelGlint::new, ModelGlint::clear);
|
||||
private final Pool<ItemGlint> itemGlints = new Pool<>(ItemGlint::new, ItemGlint::clear);
|
||||
private final Pool<Stream> streams = new Pool<>(Stream::new, Stream::clear);
|
||||
private final Pool<Overlay> overlays = new Pool<>(Overlay::new, Overlay::clear);
|
||||
private final Pool<InstanceRange> ranges = new Pool<>(InstanceRange::new, InstanceRange::clear);
|
||||
private final Matrix4f glintPose = new Matrix4f();
|
||||
long sharedParts, sharedRanges, streamEntries;
|
||||
private int mergeStart;
|
||||
|
||||
int size() {
|
||||
return commands.size();
|
||||
}
|
||||
|
||||
int split() {
|
||||
mergeStart = size();
|
||||
return mergeStart;
|
||||
}
|
||||
|
||||
Model model(int recordStart, InstanceColumns source, RenderLayer layer, DrawInputs inputs, int entityId, boolean cubesInsideTexture, Matrix4fc modelView, Matrix4fc texMatrix) {
|
||||
if (source != null && size() > recordStart && size() > mergeStart && commands.get(size() - 1) instanceof Model previous) {
|
||||
if (previous.source == source && previous.sourceVersion == source.version && previous.end == source.size - 1 && previous.shadowLayer == layer && previous.inputs.matches(inputs) && previous.entityId == entityId
|
||||
&& previous.cubesInsideTexture == cubesInsideTexture && previous.glint == null && (texMatrix == null ? !previous.hasTextureMatrix : previous.hasTextureMatrix && previous.textureMatrix.equals(texMatrix))) {
|
||||
previous.end = source.size;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
final Model model = models.acquire();
|
||||
commands.add(model);
|
||||
model.inputs.copyFrom(inputs);
|
||||
model.entityId = entityId;
|
||||
model.cubesInsideTexture = cubesInsideTexture;
|
||||
model.hasTextureMatrix = texMatrix != null;
|
||||
if (texMatrix != null) model.textureMatrix.set(texMatrix);
|
||||
model.source = source;
|
||||
model.shadowLayer = layer;
|
||||
if (source == null) {
|
||||
model.modelView.set(modelView);
|
||||
} else {
|
||||
model.sourceVersion = source.version;
|
||||
model.start = source.size - 1;
|
||||
model.end = source.size;
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
ModelGlint modelGlint(int start, int end, DrawInputs inputs) {
|
||||
for (int i = start; i < end; i++) {
|
||||
if (!(commands.get(i) instanceof Model model) || model.cannotAddGlint()) return null;
|
||||
}
|
||||
final ModelGlint glint = modelGlints.acquire();
|
||||
commands.add(glint);
|
||||
glint.inputs.copyFrom(inputs);
|
||||
glint.base = (Model) commands.get(start);
|
||||
Model previous = null;
|
||||
for (int i = start; i < end; i++) {
|
||||
final Model model = (Model) commands.get(i);
|
||||
addGlint(model, glint, true);
|
||||
if (previous != null) previous.nextGlintBase = model;
|
||||
previous = model;
|
||||
}
|
||||
return glint;
|
||||
}
|
||||
|
||||
ItemGlint itemGlint(Matrix4fc modelView, DrawInputs inputs) {
|
||||
if (!(commands.get(size() - 1) instanceof Model base) || base.cannotAddGlint() || base.drawsCubes() || base.sharedRangeChanged()) return null;
|
||||
final Matrix4fc pose = base.source != null ? base.source.pose(base.end - 1, glintPose) : base.modelView;
|
||||
if (!pose.equals(modelView)) return null;
|
||||
final ItemGlint glint = itemGlints.acquire();
|
||||
commands.add(glint);
|
||||
glint.inputs.copyFrom(inputs);
|
||||
glint.base = base;
|
||||
addGlint(base, glint, false);
|
||||
return glint;
|
||||
}
|
||||
|
||||
private void addGlint(Model base, Glint glint, boolean reuseUpload) {
|
||||
base.glint = glint;
|
||||
base.replayed = ranges.acquire();
|
||||
base.replayed.reuseUpload = reuseUpload;
|
||||
}
|
||||
|
||||
void stream(Matrix4fc modelView, int[] vertices, int vertexCount, int entityId, DrawInputs inputs) {
|
||||
final Stream stream = streams.acquire();
|
||||
commands.add(stream);
|
||||
stream.inputs.copyFrom(inputs);
|
||||
stream.modelView.set(modelView);
|
||||
stream.entityId = entityId;
|
||||
stream.capture(vertices, vertexCount);
|
||||
}
|
||||
|
||||
void overlay(DeferredEntityOverlay.DeferredEntry source) {
|
||||
final Overlay overlay = overlays.acquire();
|
||||
commands.add(overlay);
|
||||
// The shadow overlay queue is recycled before main-view entity
|
||||
overlay.captured.copyFrom(source);
|
||||
}
|
||||
|
||||
Rejection validate(int start, int end) {
|
||||
for (int i = start; i < end; i++) {
|
||||
final Rejection reason = commands.get(i).validate();
|
||||
if (reason != null) return reason;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void replay(int start, int end) {
|
||||
for (int i = start; i < end; i++) {
|
||||
final Command command = commands.get(i);
|
||||
command.replay();
|
||||
if (Tracy.ENABLED) {
|
||||
if (command instanceof Model model && model.source != null) {
|
||||
sharedParts += model.end - model.start;
|
||||
sharedRanges++;
|
||||
} else if (command instanceof Stream) {
|
||||
streamEntries++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clear() {
|
||||
commands.clear();
|
||||
models.clear();
|
||||
modelGlints.clear();
|
||||
itemGlints.clear();
|
||||
streams.clear();
|
||||
overlays.clear();
|
||||
ranges.clear();
|
||||
mergeStart = 0;
|
||||
}
|
||||
|
||||
void release() {
|
||||
clear();
|
||||
models.release();
|
||||
modelGlints.release();
|
||||
itemGlints.release();
|
||||
streams.release();
|
||||
overlays.release();
|
||||
ranges.release();
|
||||
}
|
||||
|
||||
abstract static class Command {
|
||||
Rejection validate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
abstract void replay();
|
||||
}
|
||||
|
||||
static final class DrawInputs {
|
||||
ResourceLocation texture;
|
||||
TesrMaterial material;
|
||||
PassOverride pass;
|
||||
int textureId, glintSlot, cull;
|
||||
float offsetFactor, offsetUnits;
|
||||
boolean offsetEnabled, lit, lightmap, afterGlint;
|
||||
boolean inheritedOffsetEnable, inheritedOffsetValues, inheritedLighting;
|
||||
|
||||
DrawInputs set(ResourceLocation texture, int textureId, TesrMaterial material, PassOverride pass, boolean offsetEnabled, float offsetFactor, float offsetUnits, int glintSlot, int cull, boolean lit, boolean lightmap, boolean afterGlint) {
|
||||
this.texture = texture;
|
||||
this.textureId = textureId;
|
||||
this.material = material;
|
||||
this.pass = pass;
|
||||
this.offsetEnabled = offsetEnabled;
|
||||
this.offsetFactor = offsetFactor;
|
||||
this.offsetUnits = offsetUnits;
|
||||
this.glintSlot = glintSlot;
|
||||
this.cull = cull;
|
||||
this.lit = lit;
|
||||
this.lightmap = lightmap;
|
||||
this.afterGlint = afterGlint;
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean offsetValuesUsed() {
|
||||
return !inheritedOffsetValues && (offsetEnabled || inheritedOffsetEnable);
|
||||
}
|
||||
|
||||
boolean matches(DrawInputs other) {
|
||||
return textureId == other.textureId && Objects.equals(texture, other.texture) && material == other.material && pass == other.pass && (!offsetValuesUsed() || Float.floatToIntBits(offsetFactor)
|
||||
== Float.floatToIntBits(other.offsetFactor) && Float.floatToIntBits(offsetUnits) == Float.floatToIntBits(other.offsetUnits)) && offsetEnabled == other.offsetEnabled && glintSlot == other.glintSlot && cull == other.cull
|
||||
&& lit == other.lit && lightmap == other.lightmap && afterGlint == other.afterGlint && inheritedOffsetEnable == other.inheritedOffsetEnable && inheritedOffsetValues == other.inheritedOffsetValues && inheritedLighting
|
||||
== other.inheritedLighting;
|
||||
}
|
||||
|
||||
void copyFrom(DrawInputs other) {
|
||||
set(other.texture, other.textureId, other.material, other.pass, other.offsetEnabled, other.offsetFactor, other.offsetUnits, other.glintSlot, other.cull, other.lit, other.lightmap, other.afterGlint);
|
||||
inheritedOffsetEnable = other.inheritedOffsetEnable;
|
||||
inheritedOffsetValues = other.inheritedOffsetValues;
|
||||
inheritedLighting = other.inheritedLighting;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
texture = null;
|
||||
material = null;
|
||||
pass = null;
|
||||
}
|
||||
}
|
||||
|
||||
static final class Instance {
|
||||
TemplateBuffer template;
|
||||
int light, color, overlay;
|
||||
long entityInfo;
|
||||
|
||||
void set(TemplateBuffer template, int light, int color, int overlay, long entityInfo) {
|
||||
this.template = template;
|
||||
this.light = light;
|
||||
this.color = color;
|
||||
this.overlay = overlay;
|
||||
this.entityInfo = entityInfo;
|
||||
}
|
||||
}
|
||||
|
||||
abstract static class Draw extends Command {
|
||||
final DrawInputs inputs = new DrawInputs();
|
||||
int entityId;
|
||||
|
||||
void clear() {
|
||||
inputs.clear();
|
||||
}
|
||||
}
|
||||
|
||||
static final class Model extends Draw {
|
||||
final Matrix4f modelView = new Matrix4f();
|
||||
final Matrix4f textureMatrix = new Matrix4f();
|
||||
final Instance instance = new Instance();
|
||||
InstanceColumns source;
|
||||
long sourceVersion;
|
||||
int start, end;
|
||||
RenderLayer shadowLayer;
|
||||
CubeParams[] cubes;
|
||||
boolean cubesInsideTexture, hasTextureMatrix;
|
||||
float scale;
|
||||
Glint glint;
|
||||
Model nextGlintBase;
|
||||
InstanceRange replayed;
|
||||
|
||||
boolean cannotAddGlint() {
|
||||
final TesrMaterial material = inputs.material;
|
||||
return material == null || !material.isStream() || material.shader() != null || glint != null;
|
||||
}
|
||||
|
||||
boolean drawsCubes() {
|
||||
return source != null ? !source.cubes.isEmpty() : cubes != null;
|
||||
}
|
||||
|
||||
boolean sharedRangeChanged() {
|
||||
return source != null && (source.version != sourceVersion || end > source.size);
|
||||
}
|
||||
|
||||
@Override
|
||||
Rejection validate() {
|
||||
if (sharedRangeChanged()) return Rejection.SHARED_RANGE_CHANGED;
|
||||
if (glint != null && !ModelPartBatcher.INSTANCE.canInstanceBaseAndGlint(this, glint.inputs.lightmap)) return Rejection.NOT_READY;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
void replay() {
|
||||
ModelPartBatcher.INSTANCE.replay(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
void clear() {
|
||||
super.clear();
|
||||
source = null;
|
||||
shadowLayer = null;
|
||||
instance.template = null;
|
||||
cubes = null;
|
||||
glint = null;
|
||||
nextGlintBase = null;
|
||||
replayed = null;
|
||||
}
|
||||
}
|
||||
|
||||
abstract static class Glint extends Draw {
|
||||
Model base;
|
||||
|
||||
@Override
|
||||
Rejection validate() {
|
||||
if (!ModelPartBatcher.INSTANCE.canReplayGlint(inputs.material)) return Rejection.NOT_READY;
|
||||
return inputs.material == EntityMaterials.ITEM_GLINT && !canResetStencil() ? Rejection.UNCAPTURED_STATE : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
void clear() {
|
||||
super.clear();
|
||||
base = null;
|
||||
}
|
||||
}
|
||||
|
||||
static final class ModelGlint extends Glint {
|
||||
@Override
|
||||
void replay() {
|
||||
ModelPartBatcher.INSTANCE.replay(this);
|
||||
}
|
||||
}
|
||||
|
||||
static final class ItemGlint extends Glint {
|
||||
final Instance instance = new Instance();
|
||||
|
||||
@Override
|
||||
void replay() {
|
||||
ModelPartBatcher.INSTANCE.replay(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
void clear() {
|
||||
super.clear();
|
||||
instance.template = null;
|
||||
}
|
||||
}
|
||||
|
||||
static final class Stream extends Draw {
|
||||
final Matrix4f modelView = new Matrix4f();
|
||||
int[] vertices;
|
||||
int vertexCount, entity, blockEntity, item;
|
||||
float red, green, blue, alpha;
|
||||
|
||||
void capture(int[] vertices, int vertexCount) {
|
||||
final int length = vertexCount * ModelQuadUtil.VERTEX_SIZE;
|
||||
if (this.vertices == null) {
|
||||
this.vertices = new int[length];
|
||||
} else if (this.vertices.length < length) {
|
||||
this.vertices = new int[Math.max(length, this.vertices.length << 1)];
|
||||
}
|
||||
System.arraycopy(vertices, 0, this.vertices, 0, length);
|
||||
this.vertexCount = vertexCount;
|
||||
final CapturedRenderingState state = CapturedRenderingState.INSTANCE;
|
||||
entity = state.getCurrentRenderedEntity();
|
||||
blockEntity = state.getCurrentRenderedBlockEntity();
|
||||
item = state.getCurrentRenderedItem();
|
||||
final Vector4fc color = state.getCurrentEntityColor();
|
||||
red = color.x();
|
||||
green = color.y();
|
||||
blue = color.z();
|
||||
alpha = color.w();
|
||||
}
|
||||
|
||||
@Override
|
||||
void replay() {
|
||||
ModelPartBatcher.INSTANCE.replay(this);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class Overlay extends Command {
|
||||
final DeferredEntityOverlay.DeferredEntry captured = new DeferredEntityOverlay.DeferredEntry();
|
||||
|
||||
@Override
|
||||
void replay() {
|
||||
DeferredEntityOverlay.queueReplay(captured, ModelPartBatcher.INSTANCE.replayTransform);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
captured.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,409 @@
|
||||
package com.gtnewhorizons.angelica.rendering.tesr;
|
||||
|
||||
import com.gtnewhorizons.angelica.AngelicaMod;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.RenderLayer;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import com.gtnewhorizons.angelica.config.SystemProperties;
|
||||
import com.gtnewhorizons.angelica.glsm.ExitState;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.profiling.Tracy;
|
||||
import com.gtnewhorizons.angelica.rendering.DeferredEntityOverlay;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.EntityRenderCommands.DrawInputs;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.RetainedTesrGroups.InstanceColumns;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
|
||||
import lombok.Setter;
|
||||
import net.coderbot.iris.pipeline.ShadowRenderer;
|
||||
import net.minecraft.client.renderer.culling.Frustrum;
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.boss.BossStatus;
|
||||
import net.minecraft.entity.boss.IBossDisplayData;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Matrix4fc;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Records a shadow-pass entity call, then submits its models, fire, and deferred overlays in the main pass.
|
||||
*/
|
||||
public final class EntityShadowReplay {
|
||||
private static final Tracy.ZoneId Z_REPLAY = Tracy.zoneId("entityReplay", Tracy.COLOR_CLIENT);
|
||||
private static final long P_REPLAYED = Tracy.plotHandle("entityReplay.replayed");
|
||||
private static final long P_SHARED_PARTS = Tracy.plotHandle("entityReplay.sharedParts");
|
||||
private static final long P_SHARED_RANGES = Tracy.plotHandle("entityReplay.sharedRanges");
|
||||
private static final long P_STREAM_ENTRIES = Tracy.plotHandle("entityReplay.streamEntries");
|
||||
private static final long P_RECORDED = Tracy.plotHandle("entityReplay.recorded");
|
||||
private static final long P_OUTSIDE_MAIN_VIEW = Tracy.plotHandle("entityReplay.outsideMainView");
|
||||
private static final Rejection[] REJECTIONS = Rejection.values();
|
||||
private static final long[] rejected = new long[REJECTIONS.length];
|
||||
private static final Reference2ObjectOpenHashMap<Entity, Record> records = new Reference2ObjectOpenHashMap<>();
|
||||
private static final Reference2ObjectOpenHashMap<Class<?>, Boolean> excluded = new Reference2ObjectOpenHashMap<>();
|
||||
private static final Reference2ObjectOpenHashMap<Class<?>, Reference2IntOpenHashMap<Class<?>>> loggedRejections = new Reference2ObjectOpenHashMap<>();
|
||||
private static final Pool<Record> recordPool = new Pool<>(Record::new, Record::clear);
|
||||
private static final EntityRenderCommands commands = new EntityRenderCommands();
|
||||
private static final Matrix4f shadowInverse = new Matrix4f();
|
||||
private static final Matrix4f mainFromShadow = new Matrix4f();
|
||||
private static Record recording;
|
||||
@Setter private static Frustrum mainView;
|
||||
private static Class<?> lastType;
|
||||
private static boolean lastExcluded;
|
||||
private static long drawsAtStart, replayed, outsideMainView;
|
||||
private static boolean shadowViewValid, shadowAvailable, mainReady, logRejections;
|
||||
private static double shadowX, shadowY, shadowZ;
|
||||
private static float shadowYaw, shadowPitch;
|
||||
private static float capturedBossHealthScale;
|
||||
private static int capturedBossBarTime;
|
||||
private static String capturedBossName;
|
||||
private static boolean capturedBossColorModifier;
|
||||
|
||||
private EntityShadowReplay() {
|
||||
}
|
||||
|
||||
public static void beginFrame() {
|
||||
if (Tracy.ENABLED) {
|
||||
Tracy.plotInt(P_REPLAYED, replayed);
|
||||
Tracy.plotInt(P_SHARED_PARTS, commands.sharedParts);
|
||||
Tracy.plotInt(P_SHARED_RANGES, commands.sharedRanges);
|
||||
Tracy.plotInt(P_STREAM_ENTRIES, commands.streamEntries);
|
||||
Tracy.plotInt(P_RECORDED, recordPool.size());
|
||||
Tracy.plotInt(P_OUTSIDE_MAIN_VIEW, outsideMainView);
|
||||
for (Rejection reason : REJECTIONS) Tracy.plotInt(reason.plot, rejected[reason.ordinal()]);
|
||||
}
|
||||
replayed = outsideMainView = 0;
|
||||
commands.sharedParts = commands.sharedRanges = commands.streamEntries = 0;
|
||||
Arrays.fill(rejected, 0);
|
||||
resetRecords();
|
||||
mainView = null;
|
||||
logRejections = SystemProperties.debugTooling();
|
||||
}
|
||||
|
||||
private static void resetRecords() {
|
||||
if (recording != null && recording.capturingState) GLStateManager.cancelExitCapture();
|
||||
records.clear();
|
||||
commands.clear();
|
||||
recordPool.clear();
|
||||
recording = null;
|
||||
capturedBossName = null;
|
||||
shadowViewValid = shadowAvailable = mainReady = false;
|
||||
}
|
||||
|
||||
static void beginPass(boolean shadow, int renderPass) {
|
||||
if (shadow) {
|
||||
resetRecords();
|
||||
shadowInverse.set(GLStateManager.getModelViewMatrix()).invert();
|
||||
shadowViewValid = shadowInverse.isFinite();
|
||||
shadowX = RenderManager.renderPosX;
|
||||
shadowY = RenderManager.renderPosY;
|
||||
shadowZ = RenderManager.renderPosZ;
|
||||
shadowYaw = RenderManager.instance.playerViewY;
|
||||
shadowPitch = RenderManager.instance.playerViewX;
|
||||
} else {
|
||||
mainReady = shadowAvailable && renderPass == 0;
|
||||
if (mainReady) {
|
||||
mainFromShadow.set(GLStateManager.getModelViewMatrix()).translate(
|
||||
(float) (shadowX - RenderManager.renderPosX), (float) (shadowY - RenderManager.renderPosY),
|
||||
(float) (shadowZ - RenderManager.renderPosZ)).mul(shadowInverse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean beginEntity(Entity entity, float partialTicks) {
|
||||
if (recording != null) {
|
||||
reject(Rejection.FOREIGN_DRAW);
|
||||
return false;
|
||||
}
|
||||
if (!shadowViewValid || !ShadowRenderer.ACTIVE || !ModelPartBatcher.INSTANCE.entitiesActive()) return false;
|
||||
shadowAvailable = true;
|
||||
// replay() rejects these without a record
|
||||
if (isExcluded(entity.getClass()) || entity.shouldRenderInPass(1)) return false;
|
||||
if (!inMainView(entity)) {
|
||||
outsideMainView++;
|
||||
return false;
|
||||
}
|
||||
final Record record = recordPool.acquire();
|
||||
record.start = record.end = commands.size();
|
||||
record.entity = entity;
|
||||
record.partialTicks = partialTicks;
|
||||
record.hasBossStatus = false;
|
||||
record.bossColorModifier = false;
|
||||
record.rejection = null;
|
||||
records.put(entity, record);
|
||||
recording = record;
|
||||
record.capturingState = true;
|
||||
GLStateManager.beginExitCapture(record.exitState);
|
||||
drawsAtStart = GLStateManager.drawCalls;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void endEntity(boolean completed) {
|
||||
if (recording == null) return;
|
||||
if (recording.capturingState) {
|
||||
recording.capturingState = false;
|
||||
if (!GLStateManager.finishExitCapture(recording.exitState)) reject(Rejection.EXIT_STATE_UNSUPPORTED);
|
||||
}
|
||||
if (GLStateManager.drawCalls != drawsAtStart) reject(Rejection.FOREIGN_DRAW);
|
||||
if (recording.renderer == null) reject(Rejection.UNSAFE_RENDERER);
|
||||
if (!completed) reject(Rejection.RENDER_FAILED);
|
||||
if (recording.entity instanceof IBossDisplayData && (!recording.hasBossStatus || bossStatusChanged())) {
|
||||
reject(Rejection.UNCAPTURED_STATE);
|
||||
}
|
||||
recording.end = commands.size();
|
||||
if (recording.start == recording.end) reject(Rejection.EMPTY_RECORD);
|
||||
if (recording.rejection == null) recording.texture.capture();
|
||||
recording = null;
|
||||
capturedBossName = null;
|
||||
}
|
||||
|
||||
public static boolean beginRenderer(Render renderer, Entity entity, float partialTicks, byte batchState) {
|
||||
if (recording == null) return false;
|
||||
if (recording.renderer != null || recording.entity != entity) {
|
||||
reject(Rejection.FOREIGN_DRAW);
|
||||
return false;
|
||||
}
|
||||
recording.renderer = renderer;
|
||||
if (recording.partialTicks != partialTicks) reject(Rejection.PARTIAL_TICKS_CHANGED);
|
||||
if (batchState != BatchEligibility.SAFE) reject(Rejection.UNSAFE_RENDERER);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void endRenderer(boolean completed, byte batchState) {
|
||||
if (!completed) reject(Rejection.RENDER_FAILED);
|
||||
if (batchState != BatchEligibility.SAFE) reject(Rejection.UNSAFE_RENDERER);
|
||||
}
|
||||
|
||||
private static boolean inMainView(Entity entity) {
|
||||
return mainView == null || entity.isInRangeToRender3d(mainView.xPosition, mainView.yPosition, mainView.zPosition)
|
||||
&& (entity.ignoreFrustumCheck || mainView.isBoundingBoxInFrustum(entity.boundingBox));
|
||||
}
|
||||
|
||||
static boolean isExcluded(Class<?> type) {
|
||||
if (type == lastType) return lastExcluded;
|
||||
Boolean result = excluded.get(type);
|
||||
if (result == null) {
|
||||
result = EntityPlayer.class.isAssignableFrom(type);
|
||||
for (Class<?> parent = type; !result && parent != null; parent = parent.getSuperclass()) {
|
||||
final String[] names = AngelicaConfig.entityShadowReplayExcludedClasses;
|
||||
if (names != null) for (String name : names) {
|
||||
if (parent.getName().equals(name)) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
excluded.put(type, result);
|
||||
}
|
||||
lastType = type;
|
||||
lastExcluded = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean replay(RenderManager manager, Entity entity, float partialTicks, int renderPass) {
|
||||
if (!shadowAvailable || ShadowRenderer.ACTIVE) return false;
|
||||
final Record record = records.get(entity);
|
||||
if (record == null && !Tracy.ENABLED && !logRejections) return false;
|
||||
Rejection reason = renderPass != 0 ? Rejection.RENDER_PASS
|
||||
: record != null ? record.rejection
|
||||
: isExcluded(entity.getClass()) ? Rejection.EXCLUDED
|
||||
: entity.shouldRenderInPass(1) ? Rejection.RENDER_PASS : Rejection.NOT_IN_SHADOW_PASS;
|
||||
if (reason == null) {
|
||||
if (!mainReady || !ModelPartBatcher.INSTANCE.canReplayEntity()) reason = Rejection.NOT_READY;
|
||||
else if (record.renderer != manager.getEntityRenderObject(entity)) reason = Rejection.RENDERER_CHANGED;
|
||||
else if (record.partialTicks != partialTicks) reason = Rejection.PARTIAL_TICKS_CHANGED;
|
||||
else if (shadowYaw != RenderManager.instance.playerViewY || shadowPitch != RenderManager.instance.playerViewX) reason = Rejection.VIEW_CHANGED;
|
||||
else if (!GLStateManager.canApplyExitState(record.exitState)) reason = Rejection.ENTRY_STATE_CHANGED;
|
||||
else if (GLStateManager.getPolygonState().getOffsetClamp() != 0) reason = Rejection.UNCAPTURED_STATE;
|
||||
}
|
||||
if (reason == null) {
|
||||
reason = commands.validate(record.start, record.end);
|
||||
}
|
||||
if (reason != null) {
|
||||
rejected[reason.ordinal()]++;
|
||||
logRejection(entity.getClass(), record == null || record.renderer == null ? null : record.renderer.getClass(), reason);
|
||||
return false;
|
||||
}
|
||||
replayed++;
|
||||
if (Tracy.FINE_ZONES) Tracy.beginZone(Z_REPLAY);
|
||||
try {
|
||||
if (record.hasBossStatus) BossStatus.setBossStatus((IBossDisplayData) record.entity, record.bossColorModifier);
|
||||
ModelPartBatcher.INSTANCE.beginReplay(mainFromShadow);
|
||||
commands.replay(record.start, record.end);
|
||||
GLStateManager.applyExitState(record.exitState);
|
||||
record.texture.apply();
|
||||
} finally {
|
||||
if (Tracy.FINE_ZONES) Tracy.endZone();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void logRejection(Class<?> entity, Class<?> renderer, Rejection reason) {
|
||||
if (!logRejections) return;
|
||||
Reference2IntOpenHashMap<Class<?>> reasons = loggedRejections.get(entity);
|
||||
if (reasons == null) {
|
||||
reasons = new Reference2IntOpenHashMap<>();
|
||||
loggedRejections.put(entity, reasons);
|
||||
}
|
||||
final int bit = 1 << reason.ordinal();
|
||||
final int logged = reasons.getInt(renderer);
|
||||
if ((logged & bit) != 0) return;
|
||||
reasons.put(renderer, logged | bit);
|
||||
AngelicaMod.LOGGER.info("Entity shadow replay fallback: entity={} capturedRenderer={} reason={}: {}",
|
||||
entity.getName(), renderer == null ? "<not captured>" : renderer.getName(), reason.label, reason.description);
|
||||
}
|
||||
|
||||
static EntityRenderCommands.Model recordModel(InstanceColumns source, RenderLayer layer, DrawInputs inputs, int entityId,
|
||||
boolean cubesInsideTexture, Matrix4fc modelView, Matrix4fc texMatrix) {
|
||||
return captureInheritedState(inputs)
|
||||
? commands.model(recording.start, source, layer, inputs, entityId, cubesInsideTexture, modelView, texMatrix) : null;
|
||||
}
|
||||
|
||||
static void recordStream(Matrix4fc modelView, int[] vertices, int vertexCount, int groupId, DrawInputs inputs) {
|
||||
if (captureInheritedState(inputs)) commands.stream(modelView, vertices, vertexCount, groupId, inputs);
|
||||
}
|
||||
|
||||
static EntityRenderCommands.ModelGlint recordArmorGlint(int start, int end, DrawInputs inputs) {
|
||||
return captureInheritedState(inputs) && start >= recording.start && end > start && end <= commands.size()
|
||||
? commands.modelGlint(start, end, inputs) : null;
|
||||
}
|
||||
|
||||
static EntityRenderCommands.ItemGlint recordItemGlint(Matrix4fc modelView, DrawInputs inputs) {
|
||||
return captureInheritedState(inputs) && commands.size() > recording.start ? commands.itemGlint(modelView, inputs) : null;
|
||||
}
|
||||
|
||||
private static boolean captureInheritedState(DrawInputs inputs) {
|
||||
if (GLStateManager.getPolygonState().getOffsetClamp() != 0) reject(Rejection.UNCAPTURED_STATE);
|
||||
if (!isRecording()) return false;
|
||||
final int offsetWrites = GLStateManager.getExitPolygonOffsetWrites();
|
||||
inputs.inheritedOffsetEnable = (offsetWrites & ExitState.POLYGON_OFFSET_ENABLE_WRITTEN) == 0;
|
||||
inputs.inheritedOffsetValues = (offsetWrites & ExitState.POLYGON_OFFSET_VALUES_WRITTEN) == 0;
|
||||
inputs.inheritedLighting = !GLStateManager.isExitLightingWritten();
|
||||
return true;
|
||||
}
|
||||
|
||||
static boolean isRecording() {
|
||||
return recording != null && recording.rejection == null;
|
||||
}
|
||||
|
||||
static int splitCommands() {
|
||||
return isRecording() ? commands.split() : -1;
|
||||
}
|
||||
|
||||
public static void recordDeferredOverlay(DeferredEntityOverlay.DeferredEntry overlay) {
|
||||
if (isRecording()) commands.overlay(overlay);
|
||||
}
|
||||
|
||||
public static void recordBossStatus(IBossDisplayData boss, boolean colorModifier) {
|
||||
if (!isRecording()) return;
|
||||
if (boss != recording.entity || recording.hasBossStatus) {
|
||||
reject(Rejection.UNCAPTURED_STATE);
|
||||
return;
|
||||
}
|
||||
recording.hasBossStatus = true;
|
||||
recording.bossColorModifier = colorModifier;
|
||||
capturedBossHealthScale = BossStatus.healthScale;
|
||||
capturedBossBarTime = BossStatus.statusBarTime;
|
||||
capturedBossName = BossStatus.bossName;
|
||||
capturedBossColorModifier = BossStatus.hasColorModifier;
|
||||
}
|
||||
|
||||
private static boolean bossStatusChanged() {
|
||||
return Float.floatToIntBits(capturedBossHealthScale) != Float.floatToIntBits(BossStatus.healthScale)
|
||||
|| capturedBossBarTime != BossStatus.statusBarTime
|
||||
|| !Objects.equals(capturedBossName, BossStatus.bossName)
|
||||
|| capturedBossColorModifier != BossStatus.hasColorModifier;
|
||||
}
|
||||
|
||||
private static void reject(Rejection reason) {
|
||||
if (recording != null && recording.rejection == null) {
|
||||
recording.rejection = reason;
|
||||
if (recording.capturingState) {
|
||||
GLStateManager.cancelExitCapture();
|
||||
recording.capturingState = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void rejectForeignDraw() {
|
||||
reject(Rejection.FOREIGN_DRAW);
|
||||
}
|
||||
|
||||
public static void rejectRenderFailed() {
|
||||
reject(Rejection.RENDER_FAILED);
|
||||
}
|
||||
|
||||
public static void rejectShadowOnly() {
|
||||
reject(Rejection.SHADOW_ONLY_SKIP);
|
||||
}
|
||||
|
||||
static void rejectUncapturedState() {
|
||||
reject(Rejection.UNCAPTURED_STATE);
|
||||
}
|
||||
|
||||
static void rejectPartFallback() {
|
||||
reject(Rejection.PART_FALLBACK);
|
||||
}
|
||||
|
||||
static void rejectBatcherBail() {
|
||||
reject(Rejection.BATCHER_BAIL);
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
resetRecords();
|
||||
mainView = null;
|
||||
commands.release();
|
||||
recordPool.release();
|
||||
excluded.clear();
|
||||
lastType = null;
|
||||
loggedRejections.clear();
|
||||
}
|
||||
|
||||
enum Rejection {
|
||||
EXCLUDED( "excluded", "Player or configured excluded class."),
|
||||
FOREIGN_DRAW( "foreignDraw", "Uncaptured draw or nested entity rendering."),
|
||||
SHADOW_ONLY_SKIP( "shadowOnlySkip", "Shadow rendering skipped work needed in the main view."),
|
||||
RENDER_PASS( "renderPass", "Entity requires a render pass outside the supported pass 0."),
|
||||
NOT_IN_SHADOW_PASS( "notInShadowPass", "No shadow record this frame; shadow range or culling can cause this!"),
|
||||
UNSAFE_RENDERER( "unsafeRenderer", "Renderer is not marked safe for batching, or no renderer ran."),
|
||||
EMPTY_RECORD( "emptyRecord", "No replayable rendering commands were captured."),
|
||||
UNCAPTURED_STATE( "uncapturedState", "Unsupported render state or boss HUD side effects."),
|
||||
PART_FALLBACK( "partFallback", "A model part used the live rendering path."),
|
||||
BATCHER_BAIL( "batcherBail", "A draw could not use the model batcher."),
|
||||
RENDER_FAILED( "renderFailed", "The captured renderer call did not complete successfully."),
|
||||
NOT_READY( "notReady", "Main-pass batching is inactive or a required instanced shader variant is missing."),
|
||||
RENDERER_CHANGED( "rendererChanged", "The main renderer differs from the captured renderer."),
|
||||
PARTIAL_TICKS_CHANGED( "partialTicksChanged", "Animation time differs from the one the shadow pass recorded."),
|
||||
VIEW_CHANGED( "viewChanged", "Camera angles changed between shadow and main views."),
|
||||
EXIT_STATE_UNSUPPORTED( "exitStateUnsupported", "Renderer state includes an unsupported operation, state query, or unbalanced stack."),
|
||||
ENTRY_STATE_CHANGED( "entryStateChanged", "Main renderer entry state differs from a captured dependency, or a texture was deleted."),
|
||||
SHARED_RANGE_CHANGED( "sharedRangeChanged", "Captured instance storage was rebuilt or shortened.");
|
||||
|
||||
final long plot;
|
||||
final String label, description;
|
||||
|
||||
Rejection(String name, String description) {
|
||||
plot = Tracy.plotHandle("entityReplay." + name);
|
||||
label = name;
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
|
||||
static final class Record {
|
||||
final ExitState exitState = new ExitState();
|
||||
final ModelPartBatcher.BoundTexture texture = new ModelPartBatcher.BoundTexture();
|
||||
int start, end;
|
||||
Render renderer;
|
||||
Entity entity;
|
||||
float partialTicks;
|
||||
boolean hasBossStatus, bossColorModifier, capturingState;
|
||||
Rejection rejection;
|
||||
|
||||
void clear() {
|
||||
renderer = null;
|
||||
entity = null;
|
||||
texture.location = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,9 +247,10 @@ public final class EntityTextureAtlas {
|
||||
private Page newPage() {
|
||||
if (pages.size() == MAX_PAGES) return null;
|
||||
final int previous = GLStateManager.getBoundTextureForServerState();
|
||||
final int texture = GLStateManager.glGenTextures();
|
||||
final int texture;
|
||||
BatchStateGuard.suspend();
|
||||
try {
|
||||
texture = GLStateManager.glGenTextures();
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, texture);
|
||||
GLStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
|
||||
GLStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
@@ -269,15 +270,15 @@ public final class EntityTextureAtlas {
|
||||
}
|
||||
|
||||
private void copy(int texture, Slot slot) {
|
||||
if (readFbo == 0) {
|
||||
readFbo = GLStateManager.glGenFramebuffers();
|
||||
drawFbo = GLStateManager.glGenFramebuffers();
|
||||
}
|
||||
final int previousRead = GLStateManager.getReadFramebuffer();
|
||||
final int previousDraw = GLStateManager.getDrawFramebuffer();
|
||||
final boolean scissor = GLStateManager.glIsEnabled(GL11.GL_SCISSOR_TEST);
|
||||
final boolean scissor = GLStateManager.getScissorTest().isEnabled();
|
||||
BatchStateGuard.suspend();
|
||||
try {
|
||||
if (readFbo == 0) {
|
||||
readFbo = GLStateManager.glGenFramebuffers();
|
||||
drawFbo = GLStateManager.glGenFramebuffers();
|
||||
}
|
||||
if (scissor) GLStateManager.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
GLStateManager.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, readFbo);
|
||||
GLStateManager.attachTextureForReading(GL30.GL_COLOR_ATTACHMENT0, texture);
|
||||
|
||||
@@ -36,6 +36,7 @@ public final class GlintCapture {
|
||||
private boolean poseRestored;
|
||||
private int restoredGeneration;
|
||||
private boolean uniformLight;
|
||||
private int replayStart = -1, replayEnd = -1;
|
||||
|
||||
public void reset() {
|
||||
if (owner != null && owner.glintCapture == this) owner.glintCapture = null;
|
||||
@@ -51,6 +52,7 @@ public final class GlintCapture {
|
||||
base = false;
|
||||
trusted = false;
|
||||
poseRestored = false;
|
||||
replayStart = replayEnd = -1;
|
||||
}
|
||||
|
||||
boolean begin(RetainedTesrGroups groups) {
|
||||
@@ -79,6 +81,10 @@ public final class GlintCapture {
|
||||
return true;
|
||||
}
|
||||
|
||||
void beginShadowReplay() {
|
||||
replayStart = EntityShadowReplay.splitCommands();
|
||||
}
|
||||
|
||||
/** For records queued without running model or mod code; the caller replays before any GL state changes. */
|
||||
boolean beginTrusted(RetainedTesrGroups groups) {
|
||||
if (!open(groups)) return false;
|
||||
@@ -101,6 +107,7 @@ public final class GlintCapture {
|
||||
void invalidate() { valid = false; }
|
||||
void allowBase() { base = true; }
|
||||
boolean capturesBase() { return base && valid; }
|
||||
boolean keepsBaseUpload() { return capturesBase() && replayStart < 0; }
|
||||
|
||||
void record(RetainedTesrGroups.Group group, RetainedTesrGroups.InstanceColumns columns, RetainedTesrGroups.TexRun source, int start, int end, int instances) {
|
||||
if (!valid) return;
|
||||
@@ -144,6 +151,7 @@ public final class GlintCapture {
|
||||
valid &= GLStateManager.drawCalls == draws && used > 0;
|
||||
this.poseRestored = poseRestored;
|
||||
restoredGeneration = GLStateManager.getMvGeneration();
|
||||
if (replayStart >= 0) replayEnd = EntityShadowReplay.splitCommands();
|
||||
}
|
||||
|
||||
private boolean sameParentPose() {
|
||||
@@ -165,7 +173,7 @@ public final class GlintCapture {
|
||||
}
|
||||
for (int i = 0; i < used; i++) {
|
||||
final Range range = ranges.get(i);
|
||||
range.group.replayRange(range.columns, range.source, range.start, range.end, range.instances, textureMatrix);
|
||||
groups.replayRange(range.group, range.columns, range.source, range.start, range.end, range.instances, textureMatrix);
|
||||
}
|
||||
valid = false;
|
||||
return true;
|
||||
@@ -184,12 +192,23 @@ public final class GlintCapture {
|
||||
|
||||
boolean queueBothLayers(ModelPartBatcher batcher, RetainedTesrGroups groups, ResourceLocation glintTexture) {
|
||||
if (!baseStillValid(groups) || !sameLightAndOverlay(batcher.currentOverlay()) || !batcher.prepareSkippedArmorGlint(glintTexture)) return false;
|
||||
queueLayers(batcher);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean recordBothLayers(ModelPartBatcher batcher, RetainedTesrGroups groups, ResourceLocation glintTexture) {
|
||||
if (!baseStillValid(groups) || !sameLightAndOverlay(batcher.currentOverlay())
|
||||
|| !batcher.recordArmorGlint(replayStart, replayEnd, glintTexture)) return false;
|
||||
valid = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void queueLayers(ModelPartBatcher batcher) {
|
||||
for (int i = 0; i < used; i++) {
|
||||
final Range range = ranges.get(i);
|
||||
batcher.queueArmorGlintLayers(range.columns, range.source, range.start, range.end);
|
||||
}
|
||||
valid = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean baseStillValid(RetainedTesrGroups groups) {
|
||||
|
||||
@@ -35,6 +35,8 @@ import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
|
||||
import net.coderbot.batchedentityrendering.impl.AngelicaBufferSource;
|
||||
import net.coderbot.batchedentityrendering.impl.TransparencyType;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.gbuffer_overrides.matching.InputAvailability;
|
||||
import net.coderbot.iris.gbuffer_overrides.matching.RenderCondition;
|
||||
import net.coderbot.iris.layer.GbufferPrograms;
|
||||
import net.coderbot.iris.layer.PassOverride;
|
||||
import net.coderbot.iris.pipeline.DeferredWorldRenderingPipeline;
|
||||
@@ -50,12 +52,14 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Matrix4fc;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.ToLongFunction;
|
||||
|
||||
public final class ModelPartBatcher {
|
||||
|
||||
@@ -91,6 +95,8 @@ public final class ModelPartBatcher {
|
||||
private final RetainedTesrGroups groups = new RetainedTesrGroups(bufferSource);
|
||||
private final RetainedTesrGroups entityGroups = new RetainedTesrGroups(entitySource);
|
||||
private final RetainedTesrGroups shadowGroups = new RetainedTesrGroups(bufferSource);
|
||||
private final RetainedTesrGroups shadowEntityGroups = new RetainedTesrGroups(bufferSource);
|
||||
private final RetainedTesrGroups[] allGroups = {groups, entityGroups, shadowGroups, shadowEntityGroups};
|
||||
private RetainedTesrGroups activeGroups = groups;
|
||||
private AngelicaBufferSource activeSource = bufferSource;
|
||||
private boolean entityTranslucentsHeld;
|
||||
@@ -99,6 +105,12 @@ public final class ModelPartBatcher {
|
||||
private final Matrix4f identity = new Matrix4f();
|
||||
private final Matrix4f modelView = new Matrix4f();
|
||||
private final Matrix4f texMatrixScratch = new Matrix4f();
|
||||
private final Matrix4f replayView = new Matrix4f();
|
||||
private final EntityRenderCommands.DrawInputs drawInputs = new EntityRenderCommands.DrawInputs();
|
||||
Matrix4fc replayTransform;
|
||||
private boolean replayOffsetEnabled;
|
||||
private float replayOffsetFactor, replayOffsetUnits;
|
||||
private boolean loggedDroppedGlint;
|
||||
private int lastMvGeneration;
|
||||
private boolean mvCaptured;
|
||||
private int texGeneration;
|
||||
@@ -127,11 +139,17 @@ public final class ModelPartBatcher {
|
||||
public long statArmorLoopSkips() { return armorLoopSkips; }
|
||||
public long statArmorSectionSkips() { return armorSectionSkips; }
|
||||
public long statLiveFallbacks() { return liveFallbacks; }
|
||||
public long statInstancedDraws() { return groups.instancedDraws + entityGroups.instancedDraws + shadowGroups.instancedDraws; }
|
||||
public long statInstancedInstances() { return groups.instancedInstances + entityGroups.instancedInstances + shadowGroups.instancedInstances; }
|
||||
public long statCubeInstances() { return groups.cubeInstances + entityGroups.cubeInstances + shadowGroups.cubeInstances; }
|
||||
public long statRedrawnInstances() { return groups.redrawnInstances + entityGroups.redrawnInstances + shadowGroups.redrawnInstances; }
|
||||
public long statTexMatrixRuns() { return groups.texMatrixRuns + entityGroups.texMatrixRuns + shadowGroups.texMatrixRuns; }
|
||||
public long statInstancedDraws() { return sumGroups(g -> g.instancedDraws); }
|
||||
public long statInstancedInstances() { return sumGroups(g -> g.instancedInstances); }
|
||||
public long statCubeInstances() { return sumGroups(g -> g.cubeInstances); }
|
||||
public long statRedrawnInstances() { return sumGroups(g -> g.redrawnInstances); }
|
||||
public long statTexMatrixRuns() { return sumGroups(g -> g.texMatrixRuns); }
|
||||
|
||||
private long sumGroups(ToLongFunction<RetainedTesrGroups> stat) {
|
||||
long sum = 0;
|
||||
for (RetainedTesrGroups group : allGroups) sum += stat.applyAsLong(group);
|
||||
return sum;
|
||||
}
|
||||
public long statBail(BailReason reason) { return bails[reason.ordinal()]; }
|
||||
public long statShadowQuads() { return shadows.statQuads(); }
|
||||
public long statShadowDraws() { return shadows.statDraws(); }
|
||||
@@ -220,6 +238,24 @@ public final class ModelPartBatcher {
|
||||
private static int lastBoundGlId = -1;
|
||||
private static int lastBoundGlintSlot = ShaderGlint.NO_TINT;
|
||||
|
||||
static final class BoundTexture {
|
||||
ResourceLocation location;
|
||||
int id, glintSlot;
|
||||
|
||||
void capture() {
|
||||
id = GLStateManager.getBoundTextureForServerState(0);
|
||||
location = id == lastBoundGlId ? lastBoundLocation : null;
|
||||
glintSlot = id == lastBoundGlId ? lastBoundGlintSlot : ShaderGlint.NO_TINT;
|
||||
}
|
||||
|
||||
void apply() {
|
||||
if (GLStateManager.getBoundTextureForServerState(0) != id) return;
|
||||
lastBoundLocation = location;
|
||||
lastBoundGlId = id;
|
||||
lastBoundGlintSlot = glintSlot;
|
||||
}
|
||||
}
|
||||
|
||||
private ModelPartBatcher() {}
|
||||
|
||||
public static void onTextureSwap(int glId, int glintSlot) {
|
||||
@@ -258,17 +294,17 @@ public final class ModelPartBatcher {
|
||||
final long nowMs = System.currentTimeMillis();
|
||||
mvCaptured = false;
|
||||
texCaptured = false;
|
||||
activeGroups = shadow ? shadowGroups : entityPass ? entityGroups : groups;
|
||||
final boolean replayEntities = mode == Mode.ENTITIES && AngelicaConfig.entityShadowReplayEnabled();
|
||||
activeGroups = shadow ? (replayEntities ? shadowEntityGroups : shadowGroups) : entityPass ? entityGroups : groups;
|
||||
activeSource = entityPass ? entitySource : bufferSource;
|
||||
activeSource.setIdKind(mode == Mode.ENTITIES ? AngelicaBufferSource.GroupIdKind.ENTITY : AngelicaBufferSource.GroupIdKind.BLOCK_ENTITY);
|
||||
activeSource.capturePassLighting();
|
||||
BatchDrawDefaults.capturePassFramebuffer();
|
||||
activeGroups.beginPass(identity, 0, 0, 0, instancedThisCycle ? TesrBatchRenderer.INSTANCE.instancedRenderer : null, shaderPipeline);
|
||||
if (replayEntities && shaderPipeline != null) EntityShadowReplay.beginPass(shadow, MinecraftForgeClient.getRenderPass());
|
||||
if (nowMs - lastSweepMs >= SWEEP_INTERVAL_MS) {
|
||||
lastSweepMs = nowMs;
|
||||
groups.sweep(nowMs);
|
||||
entityGroups.sweep(nowMs);
|
||||
shadowGroups.sweep(nowMs);
|
||||
for (RetainedTesrGroups group : allGroups) group.sweep(nowMs);
|
||||
sweepTemplates(nowMs);
|
||||
}
|
||||
}
|
||||
@@ -402,8 +438,19 @@ public final class ModelPartBatcher {
|
||||
|
||||
/** Skipped glint blocks queue each layer as its own instanced draw, so a shader pack only needs its pass program current. */
|
||||
public boolean canQueueGlint() {
|
||||
return active && instancedThisCycle && !shadow && BatchEligibility.batchingAllowed() && !GLStateManager.isRecordingDisplayList()
|
||||
&& GLStateManager.getActiveProgram() == (shaderPipeline != null ? shaderPipeline.getActivePassProgramId() : 0);
|
||||
return !shadow && canBatchGlint();
|
||||
}
|
||||
|
||||
private boolean cannotQueueOrRecordGlint() {
|
||||
return shadow && (mode != Mode.ENTITIES || !EntityShadowReplay.isRecording()) || !canBatchGlint();
|
||||
}
|
||||
|
||||
private boolean canBatchGlint() {
|
||||
return active && instancedThisCycle && BatchEligibility.batchingAllowed() && !GLStateManager.isRecordingDisplayList() && passProgramBound();
|
||||
}
|
||||
|
||||
private boolean passProgramBound() {
|
||||
return GLStateManager.getActiveProgram() == (shaderPipeline != null ? shaderPipeline.getActivePassProgramId() : 0);
|
||||
}
|
||||
|
||||
public boolean replayGlint(GlintCapture capture) {
|
||||
@@ -426,7 +473,25 @@ public final class ModelPartBatcher {
|
||||
}
|
||||
|
||||
public boolean beginArmorCapture(GlintCapture capture) {
|
||||
return canQueueGlint() && capture.beginBase(activeGroups, currentOverlay());
|
||||
if (cannotQueueOrRecordGlint() || !capture.beginBase(activeGroups, currentOverlay())) return false;
|
||||
if (shadow) capture.beginShadowReplay();
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean canReplayGlint(TesrMaterial material) {
|
||||
return entityPassActive() && instancedThisCycle && activeGroups.glintCapture == null
|
||||
&& activeGroups.canCopyInstances(material);
|
||||
}
|
||||
|
||||
boolean canInstanceBaseAndGlint(EntityRenderCommands.Model base, boolean glintLightmap) {
|
||||
final EntityRenderCommands.DrawInputs inputs = base.inputs;
|
||||
if (!activeGroups.canCopyInstances(inputs.material)) return false;
|
||||
if (shaderPipeline == null) return true;
|
||||
final RenderCondition condition = inputs.pass.entityCondition(inputs.material.transparency() == TesrMaterial.Transparency.TRANSLUCENT);
|
||||
if (condition == null) return false;
|
||||
final Instancing kind = base.drawsCubes() ? Instancing.CUBE : Instancing.TEMPLATE;
|
||||
return shaderPipeline.hasInstancedVariant(condition, InputAvailability.of(inputs.texture != null, inputs.lightmap), kind)
|
||||
&& shaderPipeline.hasInstancedVariant(RenderCondition.GLINT, InputAvailability.of(true, glintLightmap), kind);
|
||||
}
|
||||
|
||||
public boolean reuseArmorBase(GlintCapture base, GlintCapture glint) {
|
||||
@@ -446,20 +511,29 @@ public final class ModelPartBatcher {
|
||||
}
|
||||
|
||||
public boolean queueSkippedArmorGlint(GlintCapture base, ResourceLocation glintTexture) {
|
||||
if (!canQueueGlint() || GLStateManager.getActiveTextureUnit() != 0 || !GLStateManager.getTextures().getTextureUnitStates(0).isEnabled() || !base.queueBothLayers(this, activeGroups, glintTexture)) return false;
|
||||
armorBaseReuses++;
|
||||
glintPassReuses++;
|
||||
armorSectionSkips++;
|
||||
if (cannotQueueOrRecordGlint() || GLStateManager.getActiveTextureUnit() != 0 || !GLStateManager.getTextures().getTextureUnitStates(0).isEnabled()) return false;
|
||||
if (!(shadow ? base.recordBothLayers(this, activeGroups, glintTexture) : base.queueBothLayers(this, activeGroups, glintTexture))) return false;
|
||||
if (!shadow) {
|
||||
armorBaseReuses++;
|
||||
glintPassReuses++;
|
||||
armorSectionSkips++;
|
||||
}
|
||||
BatchEligibility.onPartQueued();
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean queueSkippedItemGlint(TemplateBuffer template, TesrMaterial material) {
|
||||
if (!canQueueGlint() || GLStateManager.getActiveTextureUnit() != 0 || !activeGroups.canCopyInstances(material) || !MatrixHelper.isIdentity(GLStateManager.getTextures().getTextureUnitMatrix(0))) return false;
|
||||
final boolean offset = GLStateManager.glIsEnabled(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
final PolygonState polygon = GLStateManager.getPolygonState();
|
||||
final int cullCode = DrawState.liveCull(material);
|
||||
final RenderLayer layer = layerFor(ItemGlint.texture(), material, PassOverride.NONE, offset ? polygon.getOffsetFactor() : 0, offset ? polygon.getOffsetUnits() : 0, ShaderGlint.NO_TINT, cullCode, false, DrawState.liveLightmap());
|
||||
if (cannotQueueOrRecordGlint() || GLStateManager.getActiveTextureUnit() != 0 || !activeGroups.canCopyInstances(material) || !MatrixHelper.isIdentity(GLStateManager.getTextures().getTextureUnitMatrix(0))) return false;
|
||||
final EntityRenderCommands.DrawInputs inputs = glintInputs(ItemGlint.texture(), material, ShaderGlint.NO_TINT, false);
|
||||
if (shadow) {
|
||||
if (material == EntityMaterials.ITEM_GLINT && !ItemGlint.canResetStencil()) return false;
|
||||
final EntityRenderCommands.ItemGlint entry = EntityShadowReplay.recordItemGlint(currentModelView(), inputs);
|
||||
if (entry == null) return false;
|
||||
GLStateManager.requireExitDrawState(false);
|
||||
entry.instance.set(template, GLSMConfig.packedLastBrightness(), VANILLA_GLINT_COLOR, currentOverlay(), currentEntityInfo(0));
|
||||
return true;
|
||||
}
|
||||
final RenderLayer layer = layerFor(ItemGlint.texture(), inputs);
|
||||
activeGroups.queueGlintLayers(template, layer, material, currentModelView(), GLSMConfig.packedLastBrightness(), VANILLA_GLINT_COLOR, currentOverlay(), currentEntityInfo(0),
|
||||
ItemGlint.firstMatrix(), ItemGlint.secondMatrix());
|
||||
parts++;
|
||||
@@ -467,6 +541,23 @@ public final class ModelPartBatcher {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean recordArmorGlint(int start, int end, ResourceLocation texture) {
|
||||
if (EntityShadowReplay.recordArmorGlint(start, end, glintInputs(texture, EntityMaterials.GLINT, ShaderGlint.NO_TINT, false)) == null) return false;
|
||||
GLStateManager.requireExitDrawState(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private EntityRenderCommands.DrawInputs glintInputs(ResourceLocation texture, TesrMaterial material, int glintSlot, boolean lit) {
|
||||
return liveInputs(texture, 0, material, PassOverride.NONE, glintSlot, DrawState.liveCull(material), lit, DrawState.liveLightmap(), false);
|
||||
}
|
||||
|
||||
private EntityRenderCommands.DrawInputs liveInputs(ResourceLocation texture, int textureId, TesrMaterial material, PassOverride pass,
|
||||
int glintSlot, int cull, boolean lit, boolean lightmap, boolean afterGlint) {
|
||||
final PolygonState polygon = GLStateManager.getPolygonState();
|
||||
return drawInputs.set(texture, textureId, material, pass, GLStateManager.getPolygonOffsetFillState().isEnabled(),
|
||||
polygon.getOffsetFactor(), polygon.getOffsetUnits(), glintSlot, cull, lit, lightmap, afterGlint);
|
||||
}
|
||||
|
||||
private Matrix4f currentModelView() {
|
||||
final int mvGen = GLStateManager.getMvGeneration();
|
||||
if (!mvCaptured || mvGen != lastMvGeneration) {
|
||||
@@ -500,10 +591,7 @@ public final class ModelPartBatcher {
|
||||
}
|
||||
|
||||
private void setArmorGlint(ResourceLocation texture, int glintSlot, boolean lit, Matrix4f textureMatrix, int color) {
|
||||
final boolean offset = GLStateManager.glIsEnabled(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
final PolygonState polygon = GLStateManager.getPolygonState();
|
||||
final int cullCode = DrawState.liveCull(EntityMaterials.GLINT);
|
||||
armorGlintLayer = layerFor(texture, EntityMaterials.GLINT, PassOverride.NONE, offset ? polygon.getOffsetFactor() : 0, offset ? polygon.getOffsetUnits() : 0, glintSlot, cullCode, lit, DrawState.liveLightmap());
|
||||
armorGlintLayer = layerFor(texture, glintInputs(texture, EntityMaterials.GLINT, glintSlot, lit));
|
||||
armorGlintTexture.set(textureMatrix);
|
||||
armorGlintColor = color;
|
||||
armorGlintLight = GLSMConfig.packedLastBrightness();
|
||||
@@ -528,6 +616,10 @@ public final class ModelPartBatcher {
|
||||
return entitiesActive() && !shadow;
|
||||
}
|
||||
|
||||
boolean canReplayEntity() {
|
||||
return entityPassActive() && passProgramBound();
|
||||
}
|
||||
|
||||
public boolean entitiesActive() {
|
||||
return active && mode == Mode.ENTITIES;
|
||||
}
|
||||
@@ -536,6 +628,10 @@ public final class ModelPartBatcher {
|
||||
return active && shadow;
|
||||
}
|
||||
|
||||
boolean recordsEntitySubmissions(RetainedTesrGroups groups) {
|
||||
return active && shadow && mode == Mode.ENTITIES && activeGroups == groups;
|
||||
}
|
||||
|
||||
public static boolean recordShadow(World world, Entity entity, double x, double y, double z, float shadowAlpha, float partialTicks, float shadowSize) {
|
||||
return INSTANCE.shadows.record(world, entity, x, y, z, shadowAlpha, partialTicks, shadowSize);
|
||||
}
|
||||
@@ -568,6 +664,7 @@ public final class ModelPartBatcher {
|
||||
return true;
|
||||
}
|
||||
if (shadow && isDepthEqualDecalState()) {
|
||||
EntityShadowReplay.rejectShadowOnly();
|
||||
return true;
|
||||
}
|
||||
return queueTemplate(entry.template, entry.cubes, entry.cubesInsideTexture, scale, null, false);
|
||||
@@ -619,17 +716,14 @@ public final class ModelPartBatcher {
|
||||
return false;
|
||||
}
|
||||
|
||||
GLStateManager.requireExitDrawState(false);
|
||||
final Matrix4f texMatrix = texture != null && !unitTexIdentity() ? texMatrixScratch : null;
|
||||
final PassOverride pass = shaderPipeline != null ? PassOverride.capture() : PassOverride.NONE;
|
||||
final boolean offset = GLStateManager.glIsEnabled(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
final PolygonState polygon = GLStateManager.getPolygonState();
|
||||
final float offsetFactor = offset ? polygon.getOffsetFactor() : 0.0f;
|
||||
final float offsetUnits = offset ? polygon.getOffsetUnits() : 0.0f;
|
||||
final int glintSlot = material.special().isGlint() ? lastBoundGlintSlot : ShaderGlint.NO_TINT;
|
||||
final int cullCode = DrawState.liveCull(material);
|
||||
final boolean lit = DrawState.liveLit(material);
|
||||
final EntityRenderCommands.DrawInputs inputs = liveInputs(texture, lastBoundGlId, material, pass, glintSlot,
|
||||
DrawState.liveCull(material), DrawState.liveLit(material), DrawState.liveLightmap(), afterGlint);
|
||||
final EntityTextureAtlas.Slot atlasSlot = texMatrix == null && cubesInsideTexture ? atlasSlotFor(material) : null;
|
||||
final RenderLayer layer = layerFor(atlasSlot != null ? Objects.requireNonNull(atlasSlot.page).location : texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, DrawState.liveLightmap(), afterGlint);
|
||||
final RenderLayer layer = layerFor(atlasSlot != null ? Objects.requireNonNull(atlasSlot.page).location : texture, inputs);
|
||||
// Entities nested inside a TESR (mob spawner, OpenBlocks trophy) run in the block entity pass but carry an entity id
|
||||
final int entityId = groupId(shaderPipeline != null, mode == Mode.ENTITIES || pass.isEntityPhase(), CapturedRenderingState.INSTANCE.getCurrentRenderedEntity(), CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity());
|
||||
final Color4 color = GLStateManager.getColor();
|
||||
@@ -637,18 +731,110 @@ public final class ModelPartBatcher {
|
||||
final int overlayABGR = currentOverlay();
|
||||
final long entityInfo = currentEntityInfo(CapturedRenderingState.INSTANCE.getCurrentRenderedItem());
|
||||
final int packedLight = GLSMConfig.packedLastBrightness();
|
||||
activeGroups.queue(0L, template, cubes, scale, layer, material, currentModelView(), packedLight, colorABGR, overlayABGR, entityInfo, entityId, texMatrix, atlasSlot);
|
||||
final Matrix4f modelView = currentModelView();
|
||||
activeGroups.queueAndRecord(template, cubes, scale, layer, modelView, packedLight, colorABGR, overlayABGR, entityInfo,
|
||||
entityId, texMatrix, atlasSlot, cubesInsideTexture, inputs);
|
||||
parts++;
|
||||
return true;
|
||||
}
|
||||
|
||||
private EntityTextureAtlas.Slot atlasSlotFor(TesrMaterial material) {
|
||||
return atlasSlotFor(material, lastBoundGlId);
|
||||
}
|
||||
|
||||
private EntityTextureAtlas.Slot atlasSlotFor(TesrMaterial material, int textureId) {
|
||||
if (!AngelicaConfig.enableEntityTextureAtlas) return null;
|
||||
// Glint, overlay and custom shaders sample their own textures
|
||||
if (material.special() != TesrMaterial.SpecialRender.NONE || material.shader() != null || material.isUnfilteredAtlas() || material == EntityMaterials.OVERLAY) return null;
|
||||
if (!activeGroups.instancesCubes(material)) return null;
|
||||
if (shaderPipeline != null && !shaderPipeline.hasInstancedVariant(Instancing.CUBE)) return null;
|
||||
return EntityTextureAtlas.INSTANCE.slotFor(lastBoundGlId, shaderPipeline != null);
|
||||
return EntityTextureAtlas.INSTANCE.slotFor(textureId, shaderPipeline != null);
|
||||
}
|
||||
|
||||
void beginReplay(Matrix4fc mainFromShadow) {
|
||||
replayTransform = mainFromShadow;
|
||||
final PolygonState polygon = GLStateManager.getPolygonState();
|
||||
replayOffsetEnabled = GLStateManager.getPolygonOffsetFillState().isEnabled();
|
||||
replayOffsetFactor = polygon.getOffsetFactor();
|
||||
replayOffsetUnits = polygon.getOffsetUnits();
|
||||
}
|
||||
|
||||
private RenderLayer replayLayer(EntityRenderCommands.Draw entry, EntityTextureAtlas.Slot slot) {
|
||||
final EntityRenderCommands.DrawInputs inputs = entry.inputs;
|
||||
final boolean enabled = inputs.inheritedOffsetEnable ? replayOffsetEnabled : inputs.offsetEnabled;
|
||||
final float factor = inputs.inheritedOffsetValues ? replayOffsetFactor : inputs.offsetFactor;
|
||||
final float units = inputs.inheritedOffsetValues ? replayOffsetUnits : inputs.offsetUnits;
|
||||
final boolean lit = inputs.inheritedLighting ? DrawState.liveLit(inputs.material) : inputs.lit;
|
||||
return layerFor(slot != null ? Objects.requireNonNull(slot.page).location : inputs.texture,
|
||||
inputs.material, inputs.pass, enabled, factor, units, inputs.glintSlot, inputs.cull, lit, inputs.lightmap, inputs.afterGlint);
|
||||
}
|
||||
|
||||
void replay(EntityRenderCommands.Model entry) {
|
||||
final RetainedTesrGroups.InstanceRange replayed = entry.glint != null ? entry.replayed : null;
|
||||
final TesrMaterial material = entry.inputs.material;
|
||||
// begin() may have recycled the shadow pass's atlas region.
|
||||
// A reused base upload must keep the original UVs for the glint texture.
|
||||
final EntityTextureAtlas.Slot slot = (replayed == null || !replayed.reuseUpload) && !entry.hasTextureMatrix && entry.cubesInsideTexture
|
||||
? atlasSlotFor(material, entry.inputs.textureId) : null;
|
||||
final RenderLayer layer = replayLayer(entry, slot);
|
||||
final Matrix4f texMatrix = entry.hasTextureMatrix ? entry.textureMatrix : null;
|
||||
if (entry.source != null) {
|
||||
activeGroups.replayInstances(entry.source, entry.start, entry.end, layer, material, entry.entityId,
|
||||
replayTransform, texMatrix, slot, replayed);
|
||||
parts += entry.end - entry.start;
|
||||
} else {
|
||||
replayTransform.mul(entry.modelView, replayView);
|
||||
final EntityRenderCommands.Instance instance = entry.instance;
|
||||
activeGroups.queueReplay(instance.template, entry.cubes, entry.scale, layer, material, replayView,
|
||||
instance.light, instance.color, instance.overlay, instance.entityInfo, entry.entityId, texMatrix, slot, replayed);
|
||||
parts++;
|
||||
}
|
||||
}
|
||||
|
||||
void replay(EntityRenderCommands.ModelGlint entry) {
|
||||
final RenderLayer layer = replayLayer(entry, null);
|
||||
for (EntityRenderCommands.Model base = entry.base; base != null; base = base.nextGlintBase) {
|
||||
final RetainedTesrGroups.InstanceRange range = base.replayed;
|
||||
if (glintBaseMissing(range)) continue;
|
||||
activeGroups.referenceGlintLayers(range.columns, range.run, range.start, range.end, layer, entry.inputs.material,
|
||||
VANILLA_GLINT_COLOR, GlintClock.firstArmorMatrix(), GlintClock.secondArmorMatrix());
|
||||
parts += range.end - range.start;
|
||||
}
|
||||
}
|
||||
|
||||
void replay(EntityRenderCommands.ItemGlint entry) {
|
||||
final RetainedTesrGroups.InstanceRange base = entry.base.replayed;
|
||||
if (glintBaseMissing(base)) return;
|
||||
final RenderLayer layer = replayLayer(entry, null);
|
||||
base.columns.pose(base.end - 1, replayView);
|
||||
final EntityRenderCommands.Instance instance = entry.instance;
|
||||
activeGroups.queueGlintLayers(instance.template, layer, entry.inputs.material, replayView,
|
||||
instance.light, instance.color, instance.overlay, instance.entityInfo, ItemGlint.firstMatrix(), ItemGlint.secondMatrix());
|
||||
parts++;
|
||||
}
|
||||
|
||||
private boolean glintBaseMissing(RetainedTesrGroups.InstanceRange base) {
|
||||
if (base.columns != null) return false;
|
||||
if (!loggedDroppedGlint) {
|
||||
loggedDroppedGlint = true;
|
||||
AngelicaMod.LOGGER.warn("Entity shadow replay dropped a glint render because its base was not drawn instanced");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void replay(EntityRenderCommands.Stream entry) {
|
||||
final RenderLayer layer = replayLayer(entry, null);
|
||||
replayTransform.mul(entry.modelView, replayView);
|
||||
final CapturedRenderingState state = CapturedRenderingState.INSTANCE;
|
||||
state.pushEntityState();
|
||||
try {
|
||||
state.setCurrentEntityAndItem(entry.entity, entry.item);
|
||||
state.setCurrentBlockEntity(entry.blockEntity);
|
||||
state.setCurrentEntityColor(entry.red, entry.green, entry.blue, entry.alpha);
|
||||
activeGroups.streamVertices(layer, entry.entityId, entry.vertices, entry.vertexCount, replayView);
|
||||
} finally {
|
||||
state.popEntityState();
|
||||
}
|
||||
}
|
||||
|
||||
private enum TessellatorRoute { DRAW_NOW, DRAW_NOW_EXPECTED, QUEUE }
|
||||
@@ -684,23 +870,27 @@ public final class ModelPartBatcher {
|
||||
if (!entityFire && (mode != Mode.BLOCK_ENTITIES || !BatchEligibility.insideRenderer())) return TessellatorRoute.DRAW_NOW;
|
||||
if (!tess.isDrawing || tess.drawMode != GL11.GL_QUADS || tess.vertexCount == 0 || (tess.vertexCount & 3) != 0) return TessellatorRoute.DRAW_NOW;
|
||||
if (shaderPipeline != null && TessellatorEntityIds.hasIdChanges(tess)) return TessellatorRoute.DRAW_NOW;
|
||||
if (DisplayListManager.isRecording() || !GLStateManager.glIsEnabled(GL11.GL_DEPTH_TEST) || !unitTexIdentity()) return TessellatorRoute.DRAW_NOW;
|
||||
if (GLStateManager.getActiveProgram() != (shaderPipeline != null ? shaderPipeline.getActivePassProgramId() : 0)) return TessellatorRoute.DRAW_NOW;
|
||||
if (DisplayListManager.isRecording() || !GLStateManager.getDepthTest().isEnabled() || !unitTexIdentity()) return TessellatorRoute.DRAW_NOW;
|
||||
if (!passProgramBound()) return TessellatorRoute.DRAW_NOW;
|
||||
final TesrMaterial material = EntityMaterials.fromCurrentState(true);
|
||||
if (material == null || material == EntityMaterials.OVERLAY) return TessellatorRoute.DRAW_NOW;
|
||||
if (lastBoundLocation == null || GLStateManager.getBoundTextureForServerState() != lastBoundGlId) return TessellatorRoute.DRAW_NOW;
|
||||
if (!entityFire && !BatchEligibility.batchingAllowed()) return TessellatorRoute.DRAW_NOW_EXPECTED;
|
||||
|
||||
GLStateManager.requireExitDrawState(false);
|
||||
final PassOverride pass = shaderPipeline != null ? PassOverride.capture() : PassOverride.NONE;
|
||||
final boolean offset = GLStateManager.glIsEnabled(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
final PolygonState polygon = GLStateManager.getPolygonState();
|
||||
final int cullCode = DrawState.liveCull(material);
|
||||
final RenderLayer layer = layerFor(lastBoundLocation, material, pass, offset ? polygon.getOffsetFactor() : 0.0f, offset ? polygon.getOffsetUnits() : 0.0f,
|
||||
ShaderGlint.NO_TINT, cullCode, DrawState.liveLit(material), DrawState.liveLightmap());
|
||||
final EntityRenderCommands.DrawInputs inputs = liveInputs(lastBoundLocation, lastBoundGlId, material, pass, ShaderGlint.NO_TINT,
|
||||
DrawState.liveCull(material), DrawState.liveLit(material), DrawState.liveLightmap(), false);
|
||||
final RenderLayer layer = layerFor(lastBoundLocation, inputs);
|
||||
// Flames carry entity_flame, which some packs may voxelize as a light source in the shadow pass
|
||||
final int groupId = groupId(shaderPipeline != null, mode == Mode.ENTITIES || pass.isEntityPhase(), CapturedRenderingState.INSTANCE.getCurrentRenderedEntity(), CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity());
|
||||
TessellatorStreamingDrawer.fillMissingAttributes(tess);
|
||||
activeGroups.streamVertices(layer, groupId, tess.rawBuffer, tess.vertexCount, currentModelView());
|
||||
final Matrix4f modelView = currentModelView();
|
||||
if (entityFire) {
|
||||
activeGroups.streamAndRecord(layer, groupId, tess.rawBuffer, tess.vertexCount, modelView, inputs);
|
||||
} else {
|
||||
activeGroups.streamVertices(layer, groupId, tess.rawBuffer, tess.vertexCount, modelView);
|
||||
}
|
||||
return TessellatorRoute.QUEUE;
|
||||
}
|
||||
|
||||
@@ -793,8 +983,13 @@ public final class ModelPartBatcher {
|
||||
entry.cubesInsideTexture = CubeParams.allInsideTexture(cubes);
|
||||
}
|
||||
|
||||
private RenderLayer layerFor(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cullCode, boolean lit, boolean lightmap) {
|
||||
return layerFor(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, lightmap, false);
|
||||
private RenderLayer layerFor(ResourceLocation texture, EntityRenderCommands.DrawInputs inputs) {
|
||||
return layerFor(texture, inputs.material, inputs.pass, inputs.offsetEnabled, inputs.offsetFactor, inputs.offsetUnits,
|
||||
inputs.glintSlot, inputs.cull, inputs.lit, inputs.lightmap, inputs.afterGlint);
|
||||
}
|
||||
|
||||
private RenderLayer layerFor(ResourceLocation texture, TesrMaterial material, PassOverride pass, boolean offsetEnabled, float offsetFactor, float offsetUnits, int glintSlot, int cullCode, boolean lit, boolean lightmap, boolean afterGlint) {
|
||||
return layerFor(texture, material, pass, offsetEnabled ? offsetFactor : 0, offsetEnabled ? offsetUnits : 0, glintSlot, cullCode, lit, lightmap, afterGlint);
|
||||
}
|
||||
|
||||
private RenderLayer layerFor(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cullCode, boolean lit, boolean lightmap, boolean afterGlint) {
|
||||
@@ -827,11 +1022,10 @@ public final class ModelPartBatcher {
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
if (AngelicaConfig.entityShadowReplayEnabled()) EntityShadowReplay.clear();
|
||||
entityFireDepth = 0;
|
||||
shadows.reset();
|
||||
groups.clear();
|
||||
entityGroups.clear();
|
||||
shadowGroups.clear();
|
||||
for (RetainedTesrGroups group : allGroups) group.clear();
|
||||
templates.clear();
|
||||
entitySource.discard();
|
||||
bufferSource.discard();
|
||||
@@ -852,7 +1046,7 @@ public final class ModelPartBatcher {
|
||||
}
|
||||
|
||||
public String getDebugString() {
|
||||
final String line = String.format("Parts: %d grp, inst %d, live %d", groups.groupCount() + entityGroups.groupCount() + shadowGroups.groupCount(), parts - lastParts, liveFallbacks - lastLiveFallbacks);
|
||||
final String line = String.format("Parts: %d grp, inst %d, live %d", sumGroups(RetainedTesrGroups::groupCount), parts - lastParts, liveFallbacks - lastLiveFallbacks);
|
||||
lastParts = parts;
|
||||
lastLiveFallbacks = liveFallbacks;
|
||||
return line;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.gtnewhorizons.angelica.rendering.tesr;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/** Reuses per-frame objects. */
|
||||
final class Pool<T> {
|
||||
private final ObjectArrayList<T> entries = new ObjectArrayList<>();
|
||||
private final Supplier<T> factory;
|
||||
private final Consumer<T> reset;
|
||||
private int used;
|
||||
|
||||
Pool(Supplier<T> factory, Consumer<T> reset) {
|
||||
this.factory = factory;
|
||||
this.reset = reset;
|
||||
}
|
||||
|
||||
T acquire() {
|
||||
if (used == entries.size()) entries.add(factory.get());
|
||||
return entries.get(used++);
|
||||
}
|
||||
|
||||
int size() { return used; }
|
||||
|
||||
void clear() {
|
||||
for (int i = 0; i < used; i++) reset.accept(entries.get(i));
|
||||
used = 0;
|
||||
}
|
||||
|
||||
void release() {
|
||||
clear();
|
||||
entries.clear();
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,7 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
private final Matrix4f baseMV = new Matrix4f();
|
||||
private final Matrix4f baseMVInv = new Matrix4f();
|
||||
private final Matrix4f scratchMat = new Matrix4f();
|
||||
private final Matrix4f replayModelView = new Matrix4f();
|
||||
private final Vector3f scratchVec = new Vector3f();
|
||||
private final Matrix4f drawMV = new Matrix4f();
|
||||
private final Matrix4f savedMV = new Matrix4f();
|
||||
@@ -95,6 +96,31 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
final IntArrayList uploadCounts = new IntArrayList();
|
||||
}
|
||||
|
||||
static final class InstanceRange {
|
||||
InstanceColumns columns;
|
||||
TexRun run;
|
||||
int start, end;
|
||||
boolean reuseUpload;
|
||||
|
||||
void set(InstanceColumns columns, TexRun run, int start, int end) {
|
||||
this.columns = columns;
|
||||
this.run = run;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
columns = null;
|
||||
run = null;
|
||||
start = end = 0;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
reset();
|
||||
reuseUpload = false;
|
||||
}
|
||||
}
|
||||
|
||||
static final class InstanceColumns {
|
||||
final ObjectArrayList<TemplateBuffer> templates = new ObjectArrayList<>();
|
||||
final ObjectArrayList<CubeParams[]> cubes = new ObjectArrayList<>();
|
||||
@@ -109,17 +135,20 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
float[] matrices = new float[16 * 64];
|
||||
int size;
|
||||
int referencedParts;
|
||||
long version;
|
||||
|
||||
boolean hasInstances() {
|
||||
return size > 0 || referencedParts > 0;
|
||||
}
|
||||
|
||||
private void reserveMatrices(int count) {
|
||||
final int need = (size + count) * 16;
|
||||
if (need > matrices.length) matrices = Arrays.copyOf(matrices, Math.max(need, matrices.length << 1));
|
||||
}
|
||||
|
||||
void add(TemplateBuffer templateOrNull, Matrix4fc mv, int light, int color, int overlay, long info) {
|
||||
final int base = size * 16;
|
||||
if (base + 16 > matrices.length) {
|
||||
matrices = Arrays.copyOf(matrices, matrices.length << 1);
|
||||
}
|
||||
mv.get(matrices, base);
|
||||
reserveMatrices(1);
|
||||
mv.get(matrices, size * 16);
|
||||
if (templateOrNull != null) templates.add(templateOrNull);
|
||||
lights.add(light);
|
||||
colors.add(color);
|
||||
@@ -136,6 +165,10 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
return run.source != null ? null : atlasSlot(i);
|
||||
}
|
||||
|
||||
Matrix4f pose(int i, Matrix4f dest) {
|
||||
return dest.set(matrices, i * 16);
|
||||
}
|
||||
|
||||
void addCubes(TemplateBuffer templateOrNull, CubeParams[] cubeParams, float scale, Matrix4fc mv, int light, int color, int overlay, long info, EntityTextureAtlas.Slot atlasSlot) {
|
||||
cubes.add(cubeParams);
|
||||
atlasSlots.add(atlasSlot);
|
||||
@@ -146,17 +179,14 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
|
||||
void appendRange(InstanceColumns src, int start, int end, int light, int color, int overlay) {
|
||||
final int n = end - start;
|
||||
final int need = (size + n) * 16;
|
||||
if (need > matrices.length) {
|
||||
matrices = Arrays.copyOf(matrices, Math.max(need, matrices.length << 1));
|
||||
}
|
||||
reserveMatrices(n);
|
||||
System.arraycopy(src.matrices, start * 16, matrices, size * 16, n * 16);
|
||||
if (src.templates.size() == src.size) {
|
||||
for (int i = start; i < end; i++) templates.add(src.templates.get(i));
|
||||
}
|
||||
if (src.cubes.size() == src.size) {
|
||||
for (int i = start; i < end; i++) cubes.add(src.cubes.get(i));
|
||||
atlasSlots.size(atlasSlots.size() + n);
|
||||
atlasSlots.size(size + n);
|
||||
scales.addElements(scales.size(), src.scales.elements(), start, n);
|
||||
}
|
||||
fill(lights, n, light);
|
||||
@@ -166,6 +196,52 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
size += n;
|
||||
}
|
||||
|
||||
void appendReplayRange(InstanceColumns src, int start, int end, Matrix4fc transform, EntityTextureAtlas.Slot atlasSlot) {
|
||||
final int n = end - start;
|
||||
reserveMatrices(n);
|
||||
// Modelview matrices are affine, so only the 3x4 upper part needs multiplying.
|
||||
// Also, JOML would copy each matrix into a Matrix4f and back out, so this is faster to do by hand
|
||||
final float t00 = transform.m00(), t01 = transform.m01(), t02 = transform.m02();
|
||||
final float t10 = transform.m10(), t11 = transform.m11(), t12 = transform.m12();
|
||||
final float t20 = transform.m20(), t21 = transform.m21(), t22 = transform.m22();
|
||||
final float t30 = transform.m30(), t31 = transform.m31(), t32 = transform.m32();
|
||||
final float[] s = src.matrices;
|
||||
final float[] d = matrices;
|
||||
for (int in = start * 16, out = size * 16, stop = end * 16; in < stop; in += 16, out += 16) {
|
||||
for (int c = 0; c < 12; c += 4) {
|
||||
final float x = s[in + c], y = s[in + c + 1], z = s[in + c + 2];
|
||||
d[out + c] = t00 * x + t10 * y + t20 * z;
|
||||
d[out + c + 1] = t01 * x + t11 * y + t21 * z;
|
||||
d[out + c + 2] = t02 * x + t12 * y + t22 * z;
|
||||
d[out + c + 3] = 0.0f;
|
||||
}
|
||||
final float x = s[in + 12], y = s[in + 13], z = s[in + 14];
|
||||
d[out + 12] = t00 * x + t10 * y + t20 * z + t30;
|
||||
d[out + 13] = t01 * x + t11 * y + t21 * z + t31;
|
||||
d[out + 14] = t02 * x + t12 * y + t22 * z + t32;
|
||||
d[out + 15] = 1.0f;
|
||||
}
|
||||
appendObjects(templates, src.templates, start, n);
|
||||
lights.addElements(lights.size(), src.lights.elements(), start, n);
|
||||
colors.addElements(colors.size(), src.colors.elements(), start, n);
|
||||
overlays.addElements(overlays.size(), src.overlays.elements(), start, n);
|
||||
infos.addElements(infos.size(), src.infos.elements(), start, n);
|
||||
if (!src.cubes.isEmpty()) {
|
||||
appendObjects(cubes, src.cubes, start, n);
|
||||
scales.addElements(scales.size(), src.scales.elements(), start, n);
|
||||
atlasSlots.size(size + n);
|
||||
if (atlasSlot != null) {
|
||||
Arrays.fill(atlasSlots.elements(), size, size + n, atlasSlot);
|
||||
anyAtlasSlot = true;
|
||||
}
|
||||
}
|
||||
size += n;
|
||||
}
|
||||
|
||||
private static <T> void appendObjects(ObjectArrayList<T> dst, ObjectArrayList<T> src, int start, int count) {
|
||||
dst.addElements(dst.size(), src.elements(), start, count);
|
||||
}
|
||||
|
||||
private static void fill(IntArrayList list, int n, int value) {
|
||||
final int from = list.size();
|
||||
list.size(from + n);
|
||||
@@ -173,6 +249,7 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
}
|
||||
|
||||
void clear() {
|
||||
version++;
|
||||
templates.clear();
|
||||
cubes.clear();
|
||||
atlasSlots.clear();
|
||||
@@ -464,11 +541,7 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
return head;
|
||||
}
|
||||
|
||||
void replayRange(InstanceColumns cols, TexRun original, int start, int end, int instances, Matrix4f matrix) {
|
||||
replayRange(cols, original, start, end, instances, matrix, false);
|
||||
}
|
||||
|
||||
void replayRange(InstanceColumns cols, TexRun original, int start, int end, int instances, Matrix4f matrix, boolean stableMatrix) {
|
||||
private void replayRange(InstanceColumns cols, TexRun original, int start, int end, int instances, Matrix4f matrix, boolean stableMatrix) {
|
||||
TexRun head = null;
|
||||
for (int i = cols.runs.size() - 1; i >= 0; i--) {
|
||||
final TexRun candidate = cols.runs.get(i);
|
||||
@@ -680,6 +753,17 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
}
|
||||
|
||||
void streamVertices(RenderLayer layer, int id, int[] packed, int vertexCount, Matrix4fc mv) {
|
||||
EntityShadowReplay.rejectForeignDraw();
|
||||
storeVertices(layer, id, packed, vertexCount, mv);
|
||||
}
|
||||
|
||||
void streamAndRecord(RenderLayer layer, int id, int[] packed, int vertexCount, Matrix4fc mv, EntityRenderCommands.DrawInputs inputs) {
|
||||
final boolean record = recordsEntitySubmission(inputs);
|
||||
storeVertices(layer, id, packed, vertexCount, mv);
|
||||
if (record) EntityShadowReplay.recordStream(mv, packed, vertexCount, id, inputs);
|
||||
}
|
||||
|
||||
private void storeVertices(RenderLayer layer, int id, int[] packed, int vertexCount, Matrix4fc mv) {
|
||||
if (glintCapture != null) glintCapture.invalidate();
|
||||
source.getBuffer(layer, id).addPackedVertices(packed, vertexCount, mv, scratchVec);
|
||||
streamedInstances++;
|
||||
@@ -694,6 +778,42 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
}
|
||||
|
||||
void queue(long scope, TemplateBuffer template, CubeParams[] cubes, float scale, RenderLayer layer, TesrMaterial material, Matrix4f currentMV, int packedLight, int colorABGR, int overlayABGR, long entityInfo, int id, Matrix4f texMatrix, EntityTextureAtlas.Slot atlasSlot) {
|
||||
EntityShadowReplay.rejectForeignDraw();
|
||||
storeModel(scope, template, cubes, scale, layer, material, currentMV, packedLight, colorABGR, overlayABGR, entityInfo, id, texMatrix, atlasSlot, null);
|
||||
}
|
||||
|
||||
void queueAndRecord(TemplateBuffer template, CubeParams[] cubes, float scale, RenderLayer layer, Matrix4f currentMV,
|
||||
int packedLight, int colorABGR, int overlayABGR, long entityInfo, int id, Matrix4f texMatrix,
|
||||
EntityTextureAtlas.Slot atlasSlot, boolean cubesInsideTexture, EntityRenderCommands.DrawInputs inputs) {
|
||||
final boolean record = recordsEntitySubmission(inputs);
|
||||
final InstanceColumns captured = storeModel(0, template, cubes, scale, layer, inputs.material, currentMV, packedLight,
|
||||
colorABGR, overlayABGR, entityInfo, id, texMatrix, atlasSlot, null);
|
||||
if (!record) return;
|
||||
// Replay copies templates by index, so a range can only be shared when every instance has one.
|
||||
final InstanceColumns source = captured != null && captured.templates.size() == captured.size ? captured : null;
|
||||
final EntityRenderCommands.Model entry = EntityShadowReplay.recordModel(source, layer, inputs, id, cubesInsideTexture, currentMV, texMatrix);
|
||||
if (entry != null && source == null) {
|
||||
entry.instance.set(template, packedLight, colorABGR, overlayABGR, entityInfo);
|
||||
entry.cubes = cubes;
|
||||
entry.scale = scale;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean recordsEntitySubmission(EntityRenderCommands.DrawInputs inputs) {
|
||||
if (!EntityShadowReplay.isRecording()) return false;
|
||||
if (!ModelPartBatcher.INSTANCE.recordsEntitySubmissions(this)) {
|
||||
EntityShadowReplay.rejectForeignDraw();
|
||||
return false;
|
||||
}
|
||||
GLStateManager.requireExitTextureFilter(inputs.textureId, inputs.material.isUnfilteredAtlas());
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean keepsBaseUpload(InstanceRange replayed) {
|
||||
return replayed != null && replayed.reuseUpload || glintCapture != null && glintCapture.keepsBaseUpload();
|
||||
}
|
||||
|
||||
private InstanceColumns storeModel(long scope, TemplateBuffer template, CubeParams[] cubes, float scale, RenderLayer layer, TesrMaterial material, Matrix4f currentMV, int packedLight, int colorABGR, int overlayABGR, long entityInfo, int id, Matrix4f texMatrix, EntityTextureAtlas.Slot atlasSlot, InstanceRange replayed) {
|
||||
final Group group = groupFor(layer, material, id);
|
||||
touch(group, layer);
|
||||
if (group.couplable) linkDepthScope(group, scope);
|
||||
@@ -704,7 +824,7 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
if (group.probe != null && group.probe.probing && (instancedPath || segments)) {
|
||||
probe(group, template, currentMV, packedLight, colorABGR, texMatrix);
|
||||
}
|
||||
final boolean capturingBase = glintCapture != null && glintCapture.capturesBase();
|
||||
final boolean capturingBase = keepsBaseUpload(replayed);
|
||||
if (instancedPath && cubes != null && material.shader() == null) {
|
||||
final TexRun run = group.openOrExtendRun(group.cubeColumns, texMatrix, false, capturingBase && group.opaque);
|
||||
group.cubeColumns.addCubes(deferred != null ? template : null, cubes, scale, currentMV, packedLight, colorABGR, overlayABGR, entityInfo, atlasSlot);
|
||||
@@ -712,7 +832,8 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
run.parts++;
|
||||
run.instances += cubes.length;
|
||||
if (glintCapture != null) glintCapture.record(group, group.cubeColumns, run, group.cubeColumns.size - 1, group.cubeColumns.size, cubes.length);
|
||||
return;
|
||||
if (replayed != null) replayed.set(group.cubeColumns, run, group.cubeColumns.size - 1, group.cubeColumns.size);
|
||||
return deferred != null ? group.cubeColumns : null;
|
||||
}
|
||||
if (instancedPath) {
|
||||
final TexRun run = group.openOrExtendRun(group.templateColumns, texMatrix, false, capturingBase && group.opaque);
|
||||
@@ -721,13 +842,14 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
run.parts++;
|
||||
run.instances++;
|
||||
if (glintCapture != null) glintCapture.record(group, group.templateColumns, run, group.templateColumns.size - 1, group.templateColumns.size, 1);
|
||||
return;
|
||||
if (replayed != null) replayed.set(group.templateColumns, run, group.templateColumns.size - 1, group.templateColumns.size);
|
||||
return group.templateColumns;
|
||||
}
|
||||
if (group.stream && glintCapture != null) glintCapture.invalidate();
|
||||
if (segments) {
|
||||
source.getBuffer(layer, id).addTemplateInstance(template, currentMV, scratchVec, colorABGR, packedLight, texMatrix);
|
||||
streamedInstances++;
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (!group.stream) {
|
||||
final DepthEqualSet set = activeDepthEqualSet(group);
|
||||
@@ -747,6 +869,62 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
if (!group.dirty && !group.snapshot.matches(index, template, cols.matrices, index * 16, packedLight, colorABGR, bakedTexMatrix)) {
|
||||
group.dirty = true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void replayInstances(InstanceColumns src, int start, int end, RenderLayer layer, TesrMaterial material, int id,
|
||||
Matrix4fc transform, Matrix4f texMatrix, EntityTextureAtlas.Slot atlasSlot, InstanceRange replayed) {
|
||||
if (replayed != null) replayed.reset();
|
||||
final boolean cubes = !src.cubes.isEmpty();
|
||||
final Group group = streamsInstanced(material) && (!cubes || material.shader() == null) ? groupFor(layer, material, id) : null;
|
||||
if (group != null) touch(group, layer);
|
||||
if (group != null && drawsInstanced(group) && (group.probe == null || !group.probe.probing)) {
|
||||
group.queuedThisFrame = true;
|
||||
final InstanceColumns dst = cubes ? group.cubeColumns : group.templateColumns;
|
||||
final TexRun run = group.openOrExtendRun(dst, texMatrix, false, keepsBaseUpload(replayed) && group.opaque);
|
||||
final int first = dst.size;
|
||||
dst.appendReplayRange(src, start, end, transform, atlasSlot);
|
||||
run.last.end = dst.size;
|
||||
run.parts += end - start;
|
||||
final int instances = instanceCount(src, start, end, cubes);
|
||||
run.instances += instances;
|
||||
if (glintCapture != null) glintCapture.record(group, dst, run, first, dst.size, instances);
|
||||
if (replayed != null) replayed.set(dst, run, first, dst.size);
|
||||
} else {
|
||||
final CapturedRenderingState state = CapturedRenderingState.INSTANCE;
|
||||
state.pushEntityState();
|
||||
try {
|
||||
for (int i = start; i < end; i++) {
|
||||
transform.mul(src.pose(i, replayModelView), replayModelView);
|
||||
storeReplay(src.templates.get(i), cubes ? src.cubes.get(i) : null, cubes ? src.scales.getFloat(i) : 1,
|
||||
layer, material, replayModelView, src.lights.getInt(i), src.colors.getInt(i), src.overlays.getInt(i),
|
||||
src.infos.getLong(i), id, texMatrix, atlasSlot, null);
|
||||
}
|
||||
} finally {
|
||||
state.popEntityState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void queueReplay(TemplateBuffer template, CubeParams[] cubes, float scale, RenderLayer layer, TesrMaterial material,
|
||||
Matrix4f modelView, int light, int color, int overlay, long entityInfo, int id, Matrix4f texMatrix, EntityTextureAtlas.Slot atlasSlot, InstanceRange replayed) {
|
||||
if (replayed != null) replayed.reset();
|
||||
final CapturedRenderingState state = CapturedRenderingState.INSTANCE;
|
||||
state.pushEntityState();
|
||||
try {
|
||||
storeReplay(template, cubes, scale, layer, material, modelView, light, color, overlay, entityInfo, id, texMatrix, atlasSlot, replayed);
|
||||
} finally {
|
||||
state.popEntityState();
|
||||
}
|
||||
}
|
||||
|
||||
private void storeReplay(TemplateBuffer template, CubeParams[] cubes, float scale, RenderLayer layer, TesrMaterial material,
|
||||
Matrix4f modelView, int light, int color, int overlay, long entityInfo, int id, Matrix4f texMatrix, EntityTextureAtlas.Slot atlasSlot, InstanceRange replayed) {
|
||||
final CapturedRenderingState state = CapturedRenderingState.INSTANCE;
|
||||
state.setCurrentEntityAndItem(InstancedAttribs.unpackId(entityInfo, 0), InstancedAttribs.unpackId(entityInfo, 32));
|
||||
state.setCurrentBlockEntity(InstancedAttribs.unpackId(entityInfo, 16));
|
||||
AngelicaBufferSource.setEntityColor(overlay);
|
||||
storeModel(0, template, cubes, scale, layer, material, modelView, light, color, overlay, entityInfo, id, texMatrix, atlasSlot, replayed);
|
||||
}
|
||||
|
||||
private void linkDepthScope(Group group, long scope) {
|
||||
@@ -888,6 +1066,7 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
}
|
||||
|
||||
void copyInstances(InstanceColumns src, int start, int end, RenderLayer layer, TesrMaterial material, int packedLight, int colorABGR, int overlayABGR, Matrix4f texMatrix) {
|
||||
EntityShadowReplay.rejectForeignDraw();
|
||||
final Group group = groupFor(layer, material, 0);
|
||||
touch(group, layer);
|
||||
final boolean cubes = !src.cubes.isEmpty();
|
||||
@@ -907,6 +1086,7 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
}
|
||||
|
||||
void referenceInstances(InstanceColumns src, int start, int end, RenderLayer layer, TesrMaterial material, int colorABGR, Matrix4f texMatrix) {
|
||||
EntityShadowReplay.rejectForeignDraw();
|
||||
final Group group = groupFor(layer, material, 0);
|
||||
touch(group, layer);
|
||||
final boolean cubes = !src.cubes.isEmpty();
|
||||
@@ -921,6 +1101,7 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
}
|
||||
|
||||
void referenceGlintLayers(InstanceColumns src, TexRun sourceRun, int start, int end, RenderLayer layer, TesrMaterial material, int colorABGR, Matrix4f first, Matrix4f second) {
|
||||
EntityShadowReplay.rejectForeignDraw();
|
||||
final Group group = groupFor(layer, material, 0);
|
||||
touch(group, layer);
|
||||
final boolean cubes = !src.cubes.isEmpty();
|
||||
@@ -935,6 +1116,7 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
}
|
||||
|
||||
void queueGlintLayers(TemplateBuffer template, RenderLayer layer, TesrMaterial material, Matrix4f currentMV, int packedLight, int colorABGR, int overlayABGR, long entityInfo, Matrix4f first, Matrix4f second) {
|
||||
EntityShadowReplay.rejectForeignDraw();
|
||||
final Group group = groupFor(layer, material, 0);
|
||||
touch(group, layer);
|
||||
final InstanceColumns dst = group.templateColumns;
|
||||
@@ -947,6 +1129,11 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
group.replayRange(dst, run, index, index + 1, 1, second, true);
|
||||
}
|
||||
|
||||
void replayRange(Group group, InstanceColumns columns, TexRun original, int start, int end, int instances, Matrix4f matrix) {
|
||||
EntityShadowReplay.rejectForeignDraw();
|
||||
group.replayRange(columns, original, start, end, instances, matrix, false);
|
||||
}
|
||||
|
||||
private static int instanceCount(InstanceColumns src, int start, int end, boolean cubes) {
|
||||
if (!cubes) return end - start;
|
||||
int instances = 0;
|
||||
@@ -1439,6 +1626,7 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
void clear() {
|
||||
for (final ObjectArrayList<Group> list : byLayer.values()) {
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
list.get(i).clearInstances();
|
||||
list.get(i).mesh.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.gtnewhorizons.angelica.glsm.hooks.GLSMHooks;
|
||||
import com.gtnewhorizons.angelica.glsm.hooks.GlintColorHandler;
|
||||
import com.gtnewhorizons.angelica.iris.IrisDisplayListState;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.ModelPartBatcher;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.EntityShadowReplay;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntLinkedOpenHashMap;
|
||||
import net.coderbot.iris.pipeline.ShadowRenderer;
|
||||
import net.irisshaders.iris.api.v0.IrisApi;
|
||||
@@ -58,6 +59,7 @@ public final class ShaderGlint {
|
||||
private ShaderGlint() {}
|
||||
|
||||
public static void beginGlint() {
|
||||
if (ShadowRenderer.ACTIVE) EntityShadowReplay.rejectShadowOnly();
|
||||
IrisDisplayListState.recordGlintSpan(true);
|
||||
|
||||
// If a glint span is already active, keep the outer span's saved state and
|
||||
@@ -120,7 +122,12 @@ public final class ShaderGlint {
|
||||
}
|
||||
|
||||
public static void bindTintedGlint(int slot) {
|
||||
if (slot < 0 || ShadowRenderer.ACTIVE || !IrisApi.getInstance().isShaderPackInUse()) return;
|
||||
if (slot < 0) return;
|
||||
if (ShadowRenderer.ACTIVE) {
|
||||
EntityShadowReplay.rejectShadowOnly();
|
||||
return;
|
||||
}
|
||||
if (!IrisApi.getInstance().isShaderPackInUse()) return;
|
||||
final ITextureObject mask = Minecraft.getMinecraft().getTextureManager().getTexture(GLINT_MASK);
|
||||
if (mask == null || GLStateManager.getBoundTextureForServerState() != mask.getGlTextureId()) return;
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, slotTextures[slot]);
|
||||
|
||||
Reference in new issue
Block a user