mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-18 11:29:08 +00:00
Fix Iris issues with instancing and batching (#2158)
This commit is contained in:
1 parent
7bb5bfd45c
commit
af599f292e
103 files changed
+4691
-535
No files matched your search
@@ -43,7 +43,7 @@ public class AngelicaBufferSource implements Groupable {
|
||||
private boolean prepared;
|
||||
private final List<RenderLayer> order = new ArrayList<>();
|
||||
private int drawStateDepth = -1;
|
||||
private boolean anyIdSet;
|
||||
private boolean irisStateSaved;
|
||||
private GroupIdKind idKind = GroupIdKind.BLOCK_ENTITY;
|
||||
|
||||
public AngelicaBufferSource() {
|
||||
@@ -65,7 +65,7 @@ public class AngelicaBufferSource implements Groupable {
|
||||
affinities.put(type, affinity);
|
||||
}
|
||||
final SegmentedBufferBuilder builder = builders[affinity];
|
||||
builder.begin(type, blockEntityId);
|
||||
builder.begin(type, blockEntityId, effectiveIdKind() == GroupIdKind.ENTITY);
|
||||
return builder;
|
||||
}
|
||||
|
||||
@@ -73,6 +73,10 @@ public class AngelicaBufferSource implements Groupable {
|
||||
renderOrderManager.begin(type);
|
||||
}
|
||||
|
||||
public boolean hasPendingLayers() {
|
||||
return prepared ? !order.isEmpty() : !renderOrderManager.getRenderOrder().isEmpty();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
for (SegmentedBufferBuilder builder : builders) {
|
||||
if (!builder.isEmpty()) return false;
|
||||
@@ -112,7 +116,6 @@ public class AngelicaBufferSource implements Groupable {
|
||||
}
|
||||
}
|
||||
affinities.clear();
|
||||
anyIdSet = false;
|
||||
}
|
||||
|
||||
List<RenderLayer> prepare() {
|
||||
@@ -148,9 +151,16 @@ public class AngelicaBufferSource implements Groupable {
|
||||
public void endBatch(LayerDrawHook hook) {
|
||||
ensurePrepared();
|
||||
try {
|
||||
int lastGlint = -1;
|
||||
for (int i = 0, n = order.size(); i < n; i++) {
|
||||
drawLayer(order.get(i), hook);
|
||||
if (getTransparencyType(order.get(i)) == TransparencyType.DECAL) lastGlint = i;
|
||||
}
|
||||
for (int i = 0, n = order.size(); i < n; i++) {
|
||||
final RenderLayer layer = order.get(i);
|
||||
if (getTransparencyType(layer) != TransparencyType.AFTER_GLINT) drawLayer(layer, hook);
|
||||
if (i == lastGlint) drawAfterGlintLayers(hook);
|
||||
}
|
||||
if (lastGlint < 0) drawAfterGlintLayers(hook);
|
||||
} catch (Throwable t) {
|
||||
discardAfterFailure(t);
|
||||
throw t;
|
||||
@@ -159,9 +169,16 @@ public class AngelicaBufferSource implements Groupable {
|
||||
finish();
|
||||
}
|
||||
|
||||
private void drawAfterGlintLayers(LayerDrawHook hook) {
|
||||
for (int i = 0, n = order.size(); i < n; i++) {
|
||||
final RenderLayer layer = order.get(i);
|
||||
if (getTransparencyType(layer) == TransparencyType.AFTER_GLINT) drawLayer(layer, hook);
|
||||
}
|
||||
}
|
||||
|
||||
public void pauseBatch() {
|
||||
restoreDrawState();
|
||||
clearCurrentId();
|
||||
restoreIrisState();
|
||||
}
|
||||
|
||||
public void discard() {
|
||||
@@ -176,13 +193,20 @@ public class AngelicaBufferSource implements Groupable {
|
||||
}
|
||||
}
|
||||
|
||||
private void clearCurrentId() {
|
||||
if (!anyIdSet) return;
|
||||
// A pass can set either kind: nested entities inside a TESR write the entity id during a block entity pass
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntityAndItem(-1, 0);
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntityColor(0f, 0f, 0f, 0f);
|
||||
CapturedRenderingState.INSTANCE.setCurrentBlockEntity(0);
|
||||
anyIdSet = false;
|
||||
private void restoreIrisState() {
|
||||
if (!irisStateSaved) return;
|
||||
CapturedRenderingState.INSTANCE.popCurrentEntityColor();
|
||||
CapturedRenderingState.INSTANCE.popCurrentBlockEntity();
|
||||
CapturedRenderingState.INSTANCE.popCurrentEntityAndItem();
|
||||
irisStateSaved = false;
|
||||
}
|
||||
|
||||
private void saveIrisState() {
|
||||
if (irisStateSaved) return;
|
||||
CapturedRenderingState.INSTANCE.pushCurrentEntityAndItem();
|
||||
CapturedRenderingState.INSTANCE.pushCurrentBlockEntity();
|
||||
CapturedRenderingState.INSTANCE.pushCurrentEntityColor();
|
||||
irisStateSaved = true;
|
||||
}
|
||||
|
||||
public GroupIdKind effectiveIdKind() {
|
||||
@@ -198,6 +222,7 @@ public class AngelicaBufferSource implements Groupable {
|
||||
drawStateDepth = GLStateManager.pushState(StateSet.BATCH);
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
}
|
||||
saveIrisState();
|
||||
layer.startDrawing();
|
||||
Throwable failure = null;
|
||||
try {
|
||||
@@ -205,7 +230,6 @@ public class AngelicaBufferSource implements Groupable {
|
||||
drawDynamic(segments);
|
||||
}
|
||||
if (hasRetained) {
|
||||
anyIdSet = true;
|
||||
hook.drawLayer(layer);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
@@ -221,7 +245,6 @@ public class AngelicaBufferSource implements Groupable {
|
||||
}
|
||||
|
||||
private void drawDynamic(List<BufferSegment> segments) {
|
||||
anyIdSet = true;
|
||||
boolean matrixPushed = false;
|
||||
SegmentedBufferBuilder.LayerBuffer bound = null;
|
||||
boolean boundSetup = false;
|
||||
@@ -230,20 +253,24 @@ public class AngelicaBufferSource implements Groupable {
|
||||
GLStateManager.glPushMatrix();
|
||||
matrixPushed = true;
|
||||
GLStateManager.glLoadIdentity();
|
||||
final boolean entityKind = effectiveIdKind() == GroupIdKind.ENTITY;
|
||||
int currentId = Integer.MIN_VALUE;
|
||||
int currentEntity = Integer.MIN_VALUE;
|
||||
int currentBlock = Integer.MIN_VALUE;
|
||||
int currentItem = Integer.MIN_VALUE;
|
||||
int currentColor = 0;
|
||||
boolean colorSet = false;
|
||||
for (int i = 0, n = segments.size(); i < n; i++) {
|
||||
final BufferSegment segment = segments.get(i);
|
||||
if (entityKind && (!colorSet || segment.getEntityColor() != currentColor)) {
|
||||
if (!colorSet || segment.getEntityColor() != currentColor) {
|
||||
colorSet = true;
|
||||
currentColor = segment.getEntityColor();
|
||||
setEntityColor(currentColor);
|
||||
}
|
||||
if (segment.getBlockEntityId() != currentId) {
|
||||
currentId = segment.getBlockEntityId();
|
||||
applyIdAndRebind(currentId);
|
||||
if (segment.getEntityId() != currentEntity || segment.getRenderedBlockEntityId() != currentBlock
|
||||
|| segment.getItemId() != currentItem) {
|
||||
currentEntity = segment.getEntityId();
|
||||
currentBlock = segment.getRenderedBlockEntityId();
|
||||
currentItem = segment.getItemId();
|
||||
applyIdsAndRebind(currentEntity, currentBlock, currentItem);
|
||||
}
|
||||
final SegmentedBufferBuilder.LayerBuffer owner = segment.getOwner();
|
||||
if (owner != bound) {
|
||||
@@ -298,7 +325,7 @@ public class AngelicaBufferSource implements Groupable {
|
||||
failure = RenderFailures.suppress(failure, t);
|
||||
}
|
||||
try {
|
||||
clearCurrentId();
|
||||
restoreIrisState();
|
||||
} catch (Throwable t) {
|
||||
failure = RenderFailures.suppress(failure, t);
|
||||
}
|
||||
@@ -328,6 +355,8 @@ public class AngelicaBufferSource implements Groupable {
|
||||
}
|
||||
|
||||
public void freeBuffers() {
|
||||
restoreDrawState();
|
||||
restoreIrisState();
|
||||
for (SegmentedBufferBuilder builder : builders) {
|
||||
builder.freeAll();
|
||||
}
|
||||
@@ -361,14 +390,11 @@ public class AngelicaBufferSource implements Groupable {
|
||||
this.idKind = kind;
|
||||
}
|
||||
|
||||
public void applyIdAndRebind(int id) {
|
||||
anyIdSet = true;
|
||||
if (effectiveIdKind() == GroupIdKind.ENTITY) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntityAndItem(id, 0);
|
||||
rebindPass();
|
||||
} else {
|
||||
setBlockEntityAndRebind(id);
|
||||
}
|
||||
public void applyIdsAndRebind(int entityId, int blockEntityId, int itemId) {
|
||||
saveIrisState();
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntityAndItem(entityId, itemId);
|
||||
CapturedRenderingState.INSTANCE.setCurrentBlockEntity(blockEntityId);
|
||||
rebindPass();
|
||||
}
|
||||
|
||||
public static int packEntityColor(Vector4fc c) {
|
||||
@@ -387,11 +413,6 @@ public class AngelicaBufferSource implements Groupable {
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntityColor((abgr & 0xFF) / 255f, ((abgr >>> 8) & 0xFF) / 255f, ((abgr >>> 16) & 0xFF) / 255f, (abgr >>> 24) / 255f);
|
||||
}
|
||||
|
||||
public static void setBlockEntityAndRebind(int blockEntityId) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentBlockEntity(blockEntityId);
|
||||
rebindPass();
|
||||
}
|
||||
|
||||
public static void rebindPass() {
|
||||
if (Iris.enabled) {
|
||||
final WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
|
||||
|
||||
@@ -1,18 +1,33 @@
|
||||
package net.coderbot.batchedentityrendering.impl;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.RenderLayer;
|
||||
import lombok.Getter;
|
||||
|
||||
public class BufferSegment {
|
||||
private final RenderLayer type;
|
||||
@Getter
|
||||
private final int blockEntityId;
|
||||
@Getter
|
||||
private final int itemId;
|
||||
@Getter
|
||||
private final int entityId;
|
||||
@Getter
|
||||
private final int renderedBlockEntityId;
|
||||
@Getter
|
||||
private final int entityColor;
|
||||
@Getter
|
||||
private final int firstVertex;
|
||||
@Getter
|
||||
private final int vertexCount;
|
||||
@Getter
|
||||
private final SegmentedBufferBuilder.LayerBuffer owner;
|
||||
|
||||
public BufferSegment(RenderLayer type, int blockEntityId, int entityColor, int firstVertex, int vertexCount, SegmentedBufferBuilder.LayerBuffer owner) {
|
||||
public BufferSegment(RenderLayer type, int blockEntityId, int entityId, int renderedBlockEntityId, int itemId, int entityColor, int firstVertex, int vertexCount, SegmentedBufferBuilder.LayerBuffer owner) {
|
||||
this.type = type;
|
||||
this.blockEntityId = blockEntityId;
|
||||
this.itemId = itemId;
|
||||
this.entityId = entityId;
|
||||
this.renderedBlockEntityId = renderedBlockEntityId;
|
||||
this.entityColor = entityColor;
|
||||
this.firstVertex = firstVertex;
|
||||
this.vertexCount = vertexCount;
|
||||
@@ -23,23 +38,4 @@ public class BufferSegment {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getBlockEntityId() {
|
||||
return blockEntityId;
|
||||
}
|
||||
|
||||
public int getEntityColor() {
|
||||
return entityColor;
|
||||
}
|
||||
|
||||
public int getFirstVertex() {
|
||||
return firstVertex;
|
||||
}
|
||||
|
||||
public int getVertexCount() {
|
||||
return vertexCount;
|
||||
}
|
||||
|
||||
public SegmentedBufferBuilder.LayerBuffer getOwner() {
|
||||
return owner;
|
||||
}
|
||||
}
|
||||
@@ -74,13 +74,26 @@ public class SegmentedBufferBuilder {
|
||||
private LayerBuffer current;
|
||||
private RenderLayer currentType;
|
||||
private int currentBlockEntityId;
|
||||
private int currentItemId;
|
||||
private int currentEntityId;
|
||||
private int currentRenderedBlockEntityId;
|
||||
private int currentEntityColor;
|
||||
private int segmentStartVertex;
|
||||
private long allocatedBytes;
|
||||
|
||||
public void begin(RenderLayer type, int blockEntityId) {
|
||||
begin(type, blockEntityId, false);
|
||||
}
|
||||
|
||||
public void begin(RenderLayer type, int blockEntityId, boolean entityKind) {
|
||||
final CapturedRenderingState state = CapturedRenderingState.INSTANCE;
|
||||
final int entityId = entityKind ? blockEntityId : state.getCurrentRenderedEntity();
|
||||
final int renderedBlockEntityId = entityKind ? state.getCurrentRenderedBlockEntity() : blockEntityId;
|
||||
final int entityColor = AngelicaBufferSource.packEntityColor(CapturedRenderingState.INSTANCE.getCurrentEntityColor());
|
||||
if (type == currentType && blockEntityId == currentBlockEntityId && entityColor == currentEntityColor && current != null) {
|
||||
final int itemId = CapturedRenderingState.INSTANCE.getCurrentRenderedItem();
|
||||
if (type == currentType && blockEntityId == currentBlockEntityId && entityId == currentEntityId
|
||||
&& renderedBlockEntityId == currentRenderedBlockEntityId && itemId == currentItemId
|
||||
&& entityColor == currentEntityColor && current != null) {
|
||||
return;
|
||||
}
|
||||
endSegment();
|
||||
@@ -94,6 +107,9 @@ public class SegmentedBufferBuilder {
|
||||
current = buffer;
|
||||
currentType = type;
|
||||
currentBlockEntityId = blockEntityId;
|
||||
currentItemId = itemId;
|
||||
currentEntityId = entityId;
|
||||
currentRenderedBlockEntityId = renderedBlockEntityId;
|
||||
currentEntityColor = entityColor;
|
||||
segmentStartVertex = current.vertexCount;
|
||||
}
|
||||
@@ -142,7 +158,7 @@ public class SegmentedBufferBuilder {
|
||||
|
||||
private void endSegment() {
|
||||
if (current != null && current.vertexCount > segmentStartVertex) {
|
||||
segments.add(new BufferSegment(currentType, currentBlockEntityId, currentEntityColor, segmentStartVertex,
|
||||
segments.add(new BufferSegment(currentType, currentBlockEntityId, currentEntityId, currentRenderedBlockEntityId, currentItemId, currentEntityColor, segmentStartVertex,
|
||||
current.vertexCount - segmentStartVertex, current));
|
||||
}
|
||||
segmentStartVertex = current == null ? 0 : current.vertexCount;
|
||||
|
||||
@@ -14,6 +14,10 @@ public enum TransparencyType {
|
||||
* These *must* be rendered after their corresponding opaque / transparent parts.
|
||||
*/
|
||||
DECAL,
|
||||
/**
|
||||
* Opaque item passes vanilla draws after an earlier pass's glint, such as a potion's bottle over its glinted liquid.
|
||||
*/
|
||||
AFTER_GLINT,
|
||||
/**
|
||||
* Water mask, should be drawn after pretty much everything except for translucent terrain and lines.
|
||||
* Prevents water from appearing inside of boats.
|
||||
|
||||
@@ -10,6 +10,12 @@ import org.lwjgl.opengl.GL43;
|
||||
|
||||
public final class Program extends GlResource {
|
||||
|
||||
private static int managedBindProgram;
|
||||
|
||||
public static boolean isManagedBind(int program) {
|
||||
return program != 0 && managedBindProgram == program;
|
||||
}
|
||||
|
||||
@Getter
|
||||
private final ProgramUniforms uniforms;
|
||||
|
||||
@@ -31,13 +37,23 @@ public final class Program extends GlResource {
|
||||
|
||||
public void use() {
|
||||
RenderSystem.memoryBarrier(GL42.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL42.GL_TEXTURE_FETCH_BARRIER_BIT | GL43.GL_SHADER_STORAGE_BARRIER_BIT);
|
||||
GLStateManager.glUseProgram(getGlId());
|
||||
bindManaged(getGlId());
|
||||
|
||||
uniforms.update();
|
||||
samplers.update();
|
||||
images.update();
|
||||
}
|
||||
|
||||
static void bindManaged(int program) {
|
||||
final int previousManagedBind = managedBindProgram;
|
||||
managedBindProgram = program;
|
||||
try {
|
||||
GLStateManager.glUseProgram(program);
|
||||
} finally {
|
||||
managedBindProgram = previousManagedBind;
|
||||
}
|
||||
}
|
||||
|
||||
public static void unbind() {
|
||||
ProgramUniforms.clearActiveUniforms();
|
||||
ProgramSamplers.clearActiveSamplers();
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package net.coderbot.iris.gl.program;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.gtnewhorizons.angelica.glsm.DisplayListManager;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import com.gtnewhorizons.angelica.glsm.recording.CommandRecorder;
|
||||
import net.coderbot.iris.gl.image.ImageHolder;
|
||||
import net.coderbot.iris.gl.sampler.GlSampler;
|
||||
import net.coderbot.iris.gl.sampler.SamplerHolder;
|
||||
@@ -54,6 +57,7 @@ public class ProgramBuilder extends ProgramUniforms.Builder implements SamplerHo
|
||||
shaders.add(fragment);
|
||||
|
||||
int programId = ProgramCreator.create(name, shaders.toArray(new GlShader[0]));
|
||||
initializeFallbackUniforms(programId);
|
||||
|
||||
for (GlShader shader : shaders) {
|
||||
shader.destroy();
|
||||
@@ -62,6 +66,42 @@ public class ProgramBuilder extends ProgramUniforms.Builder implements SamplerHo
|
||||
return new ProgramBuilder(name, programId, reservedTextureUnits);
|
||||
}
|
||||
|
||||
/** Initialize alpha and color uniforms to neutral values until the first pass update. */
|
||||
private static void initializeFallbackUniforms(int programId) {
|
||||
final int previous = GLStateManager.getActiveProgram();
|
||||
final CommandRecorder recorder = DisplayListManager.isRecording() ? DisplayListManager.pauseRecording() : null;
|
||||
try {
|
||||
Program.bindManaged(programId);
|
||||
seedUniform1i(programId, "iris_currentAlphaFunc", 7);
|
||||
seedUniform1f(programId, "iris_currentAlphaTest", -1.0f);
|
||||
seedUniform1f(programId, "alphaTestRef", -1.0f);
|
||||
final int modulator = GLStateManager.glGetUniformLocation(programId, "iris_ColorModulator");
|
||||
if (modulator != -1) {
|
||||
RenderSystem.uniform4f(modulator, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
Program.bindManaged(previous);
|
||||
} finally {
|
||||
if (recorder != null) DisplayListManager.resumeRecording(recorder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void seedUniform1i(int programId, String name, int value) {
|
||||
final int location = GLStateManager.glGetUniformLocation(programId, name);
|
||||
if (location != -1) {
|
||||
RenderSystem.uniform1i(location, value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void seedUniform1f(int programId, String name, float value) {
|
||||
final int location = GLStateManager.glGetUniformLocation(programId, name);
|
||||
if (location != -1) {
|
||||
RenderSystem.uniform1f(location, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static ProgramBuilder beginCompute(String name, @Nullable String source, ImmutableSet<Integer> reservedTextureUnits) {
|
||||
if (!RenderSystem.supportsCompute()) {
|
||||
throw new IllegalStateException("This PC does not support compute shaders, but it's attempting to be used???");
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.coderbot.iris.gl.program;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.DisplayListManager;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.ArrayList;
|
||||
@@ -11,7 +12,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
@@ -23,7 +23,6 @@ import net.coderbot.iris.gl.uniform.UniformUpdateFrequency;
|
||||
import net.coderbot.iris.uniforms.SystemTimeUniforms;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import org.joml.Vector3i;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.ARBShaderImageLoadStore;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -32,6 +31,7 @@ import org.lwjgl.opengl.GL30;
|
||||
|
||||
public class ProgramUniforms {
|
||||
private static ProgramUniforms active;
|
||||
private final int program;
|
||||
private final ImmutableList<Uniform> perTick;
|
||||
private final ImmutableList<Uniform> perFrame;
|
||||
private final ImmutableList<Uniform> dynamic;
|
||||
@@ -40,9 +40,11 @@ public class ProgramUniforms {
|
||||
private ImmutableList<Uniform> once;
|
||||
long lastTick = -1;
|
||||
int lastFrame = -1;
|
||||
private boolean hasDeferredUploads;
|
||||
|
||||
public ProgramUniforms(ImmutableList<Uniform> once, ImmutableList<Uniform> perTick, ImmutableList<Uniform> perFrame,
|
||||
public ProgramUniforms(int program, ImmutableList<Uniform> once, ImmutableList<Uniform> perTick, ImmutableList<Uniform> perFrame,
|
||||
ImmutableList<Uniform> dynamic, ImmutableList<ValueUpdateNotifier> notifiersToReset) {
|
||||
this.program = program;
|
||||
this.once = once;
|
||||
this.perTick = perTick;
|
||||
this.perFrame = perFrame;
|
||||
@@ -68,11 +70,18 @@ public class ProgramUniforms {
|
||||
}
|
||||
|
||||
public void update() {
|
||||
// glUseProgram is only recorded during GL_COMPILE
|
||||
if (DisplayListManager.getRecordMode() == DisplayListManager.RecordMode.COMPILE
|
||||
|| GLStateManager.getActiveProgram() != program) {
|
||||
hasDeferredUploads = true;
|
||||
return;
|
||||
}
|
||||
if (active != null) {
|
||||
active.removeListeners();
|
||||
}
|
||||
|
||||
active = this;
|
||||
hasDeferredUploads = false;
|
||||
|
||||
updateStage(dynamic);
|
||||
|
||||
@@ -118,6 +127,19 @@ public class ProgramUniforms {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isActiveProgramBound() {
|
||||
return active != null && GLStateManager.getActiveProgram() == active.program;
|
||||
}
|
||||
|
||||
public static void markActiveDeferred() {
|
||||
if (active != null) {
|
||||
active.hasDeferredUploads = true;
|
||||
}
|
||||
}
|
||||
public static boolean activeHasDeferredUploads() {
|
||||
return active != null && active.hasDeferredUploads;
|
||||
}
|
||||
|
||||
public static Builder builder(String name, int program) {
|
||||
return new Builder(name, program);
|
||||
}
|
||||
@@ -263,7 +285,7 @@ public class ProgramUniforms {
|
||||
}
|
||||
}
|
||||
|
||||
return new ProgramUniforms(ImmutableList.copyOf(once.values()), ImmutableList.copyOf(perTick.values()), ImmutableList.copyOf(perFrame.values()),
|
||||
return new ProgramUniforms(program, ImmutableList.copyOf(once.values()), ImmutableList.copyOf(perTick.values()), ImmutableList.copyOf(perFrame.values()),
|
||||
ImmutableList.copyOf(dynamic.values()), ImmutableList.copyOf(notifiersToReset));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
|
||||
public class FloatUniform extends Uniform {
|
||||
private final Runnable updateListener = this::updateValue;
|
||||
private final Runnable updateListener = uploadWhileBound(this::updateValue);
|
||||
private float cachedValue;
|
||||
private final FloatSupplier value;
|
||||
|
||||
@@ -31,8 +31,9 @@ public class FloatUniform extends Uniform {
|
||||
private void updateValue() {
|
||||
float newValue = value.getAsFloat();
|
||||
|
||||
if (cachedValue != newValue) {
|
||||
if (dirty || cachedValue != newValue) {
|
||||
cachedValue = newValue;
|
||||
dirty = false;
|
||||
RenderSystem.uniform1f(location, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
public class IntUniform extends Uniform {
|
||||
private final Runnable updateListener = this::updateValue;
|
||||
private final Runnable updateListener = uploadWhileBound(this::updateValue);
|
||||
private int cachedValue;
|
||||
private final IntSupplier value;
|
||||
|
||||
@@ -33,8 +33,9 @@ public class IntUniform extends Uniform {
|
||||
private void updateValue() {
|
||||
int newValue = value.getAsInt();
|
||||
|
||||
if (cachedValue != newValue) {
|
||||
if (dirty || cachedValue != newValue) {
|
||||
cachedValue = newValue;
|
||||
dirty = false;
|
||||
RenderSystem.uniform1i(location, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package net.coderbot.iris.gl.uniform;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.DisplayListManager;
|
||||
import net.coderbot.iris.gl.program.ProgramUniforms;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
|
||||
public abstract class Uniform {
|
||||
protected final int location;
|
||||
protected final ValueUpdateNotifier notifier;
|
||||
protected boolean dirty = true;
|
||||
|
||||
Uniform(int location) {
|
||||
this(location, null);
|
||||
@@ -17,6 +20,18 @@ public abstract class Uniform {
|
||||
|
||||
public abstract void update();
|
||||
|
||||
protected final Runnable uploadWhileBound(Runnable upload) {
|
||||
return () -> {
|
||||
if (DisplayListManager.getRecordMode() != DisplayListManager.RecordMode.COMPILE
|
||||
&& ProgramUniforms.isActiveProgramBound()) {
|
||||
upload.run();
|
||||
} else {
|
||||
dirty = true;
|
||||
ProgramUniforms.markActiveDeferred();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public final int getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.joml.Vector2ic;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Vector2IntegerJomlUniform extends Uniform {
|
||||
private final Runnable updateListener = this::updateValue;
|
||||
private final Runnable updateListener = uploadWhileBound(this::updateValue);
|
||||
private final Vector2i cachedValue;
|
||||
private final Supplier<Vector2ic> value;
|
||||
|
||||
@@ -35,7 +35,8 @@ public class Vector2IntegerJomlUniform extends Uniform {
|
||||
private void updateValue() {
|
||||
Vector2ic newValue = value.get();
|
||||
|
||||
if (!newValue.equals(cachedValue)) {
|
||||
if (dirty || !newValue.equals(cachedValue)) {
|
||||
dirty = false;
|
||||
cachedValue.set(newValue.x(), newValue.y());
|
||||
RenderSystem.uniform2i(this.location, cachedValue.x, cachedValue.y);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.joml.Vector3ic;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Vector3IntegerJomlUniform extends Uniform {
|
||||
private final Runnable updateListener = this::updateValue;
|
||||
private final Runnable updateListener = uploadWhileBound(this::updateValue);
|
||||
private final Vector3i cachedValue;
|
||||
private final Supplier<Vector3ic> value;
|
||||
|
||||
@@ -35,7 +35,8 @@ public class Vector3IntegerJomlUniform extends Uniform {
|
||||
private void updateValue() {
|
||||
Vector3ic newValue = value.get();
|
||||
|
||||
if (!newValue.equals(cachedValue)) {
|
||||
if (dirty || !newValue.equals(cachedValue)) {
|
||||
dirty = false;
|
||||
cachedValue.set(newValue.x(), newValue.y(), newValue.z());
|
||||
RenderSystem.uniform3i(this.location, cachedValue.x(), cachedValue.y(), cachedValue.z());
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.Arrays;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Vector4ArrayUniform extends Uniform {
|
||||
private final Runnable updateListener = this::updateValue;
|
||||
private final Runnable updateListener = uploadWhileBound(this::updateValue);
|
||||
private final Supplier<float[]> value;
|
||||
private float[] cachedValue;
|
||||
|
||||
@@ -34,7 +34,8 @@ public class Vector4ArrayUniform extends Uniform {
|
||||
private void updateValue() {
|
||||
float[] newValue = value.get();
|
||||
|
||||
if (!Arrays.equals(newValue, cachedValue)) {
|
||||
if (dirty || !Arrays.equals(newValue, cachedValue)) {
|
||||
dirty = false;
|
||||
cachedValue = newValue;
|
||||
RenderSystem.uniform4f(location, cachedValue[0], cachedValue[1], cachedValue[2], cachedValue[3]);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.joml.Vector4ic;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Vector4IntegerJomlUniform extends Uniform {
|
||||
private final Runnable updateListener = this::updateValue;
|
||||
private final Runnable updateListener = uploadWhileBound(this::updateValue);
|
||||
private final Vector4i cachedValue;
|
||||
private final Supplier<Vector4ic> value;
|
||||
|
||||
@@ -35,7 +35,8 @@ public class Vector4IntegerJomlUniform extends Uniform {
|
||||
private void updateValue() {
|
||||
Vector4ic newValue = value.get();
|
||||
|
||||
if (!newValue.equals(cachedValue)) {
|
||||
if (dirty || !newValue.equals(cachedValue)) {
|
||||
dirty = false;
|
||||
cachedValue.set(newValue.x(), newValue.y(), newValue.z(), newValue.w());
|
||||
RenderSystem.uniform4i(this.location, cachedValue.x, cachedValue.y, cachedValue.z, cachedValue.w);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.joml.Vector4fc;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Vector4Uniform extends Uniform {
|
||||
private final Runnable updateListener = this::updateValue;
|
||||
private final Runnable updateListener = uploadWhileBound(this::updateValue);
|
||||
private final Vector4f cachedValue;
|
||||
private final Supplier<Vector4fc> value;
|
||||
|
||||
@@ -35,7 +35,8 @@ public class Vector4Uniform extends Uniform {
|
||||
private void updateValue() {
|
||||
Vector4fc newValue = value.get();
|
||||
|
||||
if (!newValue.equals(cachedValue)) {
|
||||
if (dirty || !newValue.equals(cachedValue)) {
|
||||
dirty = false;
|
||||
cachedValue.set(newValue.x(), newValue.y(), newValue.z(), newValue.w());
|
||||
RenderSystem.uniform4f(location, cachedValue.x(), cachedValue.y(), cachedValue.z(), cachedValue.w());
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package net.coderbot.iris.layer;
|
||||
|
||||
import lombok.Getter;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.ffp.FfpExtendedAttribs;
|
||||
import com.gtnewhorizons.angelica.iris.IrisDisplayListState;
|
||||
import net.coderbot.iris.gl.shader.ProgramCreator;
|
||||
import net.coderbot.iris.gl.state.StateUpdateNotifiers;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPhase;
|
||||
@@ -179,20 +181,48 @@ public class GbufferPrograms {
|
||||
}
|
||||
|
||||
public static boolean beginNestedEntityPhase() {
|
||||
IrisDisplayListState.recordNestedEntityScope(true);
|
||||
if (getCurrentPhase() != WorldRenderingPhase.BLOCK_ENTITIES) {
|
||||
return false;
|
||||
}
|
||||
setOverridePhase(WorldRenderingPhase.ENTITIES);
|
||||
applyPushOverridePhase(WorldRenderingPhase.ENTITIES);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void endNestedEntityPhase(boolean pushed) {
|
||||
IrisDisplayListState.recordNestedEntityScope(false);
|
||||
if (pushed) {
|
||||
setOverridePhase(null);
|
||||
applyPopOverridePhase();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setOverridePhase(WorldRenderingPhase phase) {
|
||||
IrisDisplayListState.recordOverridePhase(phase);
|
||||
applyOverridePhase(phase);
|
||||
}
|
||||
|
||||
private static final ObjectArrayList<WorldRenderingPhase> phaseStack = new ObjectArrayList<>();
|
||||
|
||||
public static void pushOverridePhase(WorldRenderingPhase phase) {
|
||||
IrisDisplayListState.recordPhaseScope(phase, true);
|
||||
applyPushOverridePhase(phase);
|
||||
}
|
||||
|
||||
private static void applyPushOverridePhase(WorldRenderingPhase phase) {
|
||||
phaseStack.add(overridePhase);
|
||||
applyOverridePhase(phase);
|
||||
}
|
||||
|
||||
public static void popOverridePhase() {
|
||||
IrisDisplayListState.recordPhaseScope(null, false);
|
||||
applyPopOverridePhase();
|
||||
}
|
||||
|
||||
private static void applyPopOverridePhase() {
|
||||
applyOverridePhase(phaseStack.pop());
|
||||
}
|
||||
|
||||
private static void applyOverridePhase(WorldRenderingPhase phase) {
|
||||
overridePhase = phase;
|
||||
|
||||
final WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
|
||||
@@ -206,6 +236,7 @@ public class GbufferPrograms {
|
||||
private static WorldRenderingPhase overridePhase;
|
||||
|
||||
public static Boolean beginTranslucencyDeclaration(Boolean translucent) {
|
||||
IrisDisplayListState.recordTranslucencyScope(translucent, true);
|
||||
final Boolean previous = declaredTranslucent;
|
||||
declaredTranslucent = translucent;
|
||||
applyTranslucencyDeclaration();
|
||||
@@ -213,11 +244,13 @@ public class GbufferPrograms {
|
||||
}
|
||||
|
||||
public static void endTranslucencyDeclaration(Boolean previous) {
|
||||
IrisDisplayListState.recordTranslucencyScope(null, false);
|
||||
declaredTranslucent = previous;
|
||||
applyTranslucencyDeclaration();
|
||||
}
|
||||
|
||||
public static void setTranslucencyDeclaration(Boolean translucent) {
|
||||
IrisDisplayListState.recordTranslucency(translucent);
|
||||
declaredTranslucent = translucent;
|
||||
applyTranslucencyDeclaration();
|
||||
}
|
||||
@@ -233,6 +266,7 @@ public class GbufferPrograms {
|
||||
}
|
||||
|
||||
private static SpecialCondition currentSpecial;
|
||||
private static final ObjectArrayList<SpecialCondition> specialStack = new ObjectArrayList<>();
|
||||
|
||||
public static SpecialCondition getSpecialCondition() {
|
||||
return currentSpecial;
|
||||
@@ -243,6 +277,12 @@ public class GbufferPrograms {
|
||||
}
|
||||
|
||||
public static void setupSpecialRenderCondition(SpecialCondition override) {
|
||||
IrisDisplayListState.recordSpecialCondition(override, true);
|
||||
specialStack.add(currentSpecial);
|
||||
applySpecialCondition(override);
|
||||
}
|
||||
|
||||
private static void applySpecialCondition(SpecialCondition override) {
|
||||
currentSpecial = override;
|
||||
final WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
|
||||
|
||||
@@ -252,12 +292,8 @@ public class GbufferPrograms {
|
||||
}
|
||||
|
||||
public static void teardownSpecialRenderCondition() {
|
||||
currentSpecial = null;
|
||||
final WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
|
||||
|
||||
if (pipeline != null) {
|
||||
pipeline.setSpecialCondition(null);
|
||||
}
|
||||
IrisDisplayListState.recordSpecialCondition(null, false);
|
||||
applySpecialCondition(specialStack.pop());
|
||||
}
|
||||
|
||||
public static void runPhaseChangeNotifier() {
|
||||
|
||||
@@ -13,6 +13,7 @@ public record PassOverride(SpecialCondition special, Boolean translucent, WorldR
|
||||
public static final PassOverride NONE = new PassOverride(null, null, null);
|
||||
|
||||
private static final ObjectArrayList<PassOverride> INTERNED = new ObjectArrayList<>();
|
||||
private static final ObjectArrayList<Boolean> translucencyStack = new ObjectArrayList<>();
|
||||
|
||||
public PassOverride(SpecialCondition special, Boolean translucent) {
|
||||
this(special, translucent, null);
|
||||
@@ -38,14 +39,14 @@ public record PassOverride(SpecialCondition special, Boolean translucent, WorldR
|
||||
|
||||
public void apply() {
|
||||
GbufferPrograms.setupSpecialRenderCondition(special);
|
||||
GbufferPrograms.setTranslucencyDeclaration(translucent);
|
||||
GbufferPrograms.setOverridePhase(phase);
|
||||
translucencyStack.add(GbufferPrograms.beginTranslucencyDeclaration(translucent));
|
||||
GbufferPrograms.pushOverridePhase(phase);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
GbufferPrograms.setupSpecialRenderCondition(null);
|
||||
GbufferPrograms.setTranslucencyDeclaration(null);
|
||||
GbufferPrograms.setOverridePhase(null);
|
||||
GbufferPrograms.popOverridePhase();
|
||||
GbufferPrograms.endTranslucencyDeclaration(translucencyStack.pop());
|
||||
GbufferPrograms.teardownSpecialRenderCondition();
|
||||
}
|
||||
|
||||
public boolean isEntityPhase() {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package net.coderbot.iris.pipeline;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.DisplayListManager;
|
||||
import com.gtnewhorizons.angelica.iris.IrisDisplayListState;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.primitives.Ints;
|
||||
@@ -10,10 +13,10 @@ import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix3f;
|
||||
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix4f;
|
||||
import org.joml.Matrix3f;
|
||||
import org.joml.Matrix4fc;
|
||||
import com.gtnewhorizons.angelica.glsm.backend.BackendManager;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import com.gtnewhorizons.angelica.glsm.ffp.Instancing;
|
||||
import com.gtnewhorizons.angelica.glsm.hooks.BatchStateGuard;
|
||||
import com.gtnewhorizons.angelica.glsm.hooks.GLSMHooks;
|
||||
import com.gtnewhorizons.angelica.glsm.hooks.PendingProgramSelection;
|
||||
import com.gtnewhorizons.angelica.glsm.texture.TextureInfoCache;
|
||||
@@ -113,7 +116,6 @@ import org.taumc.glsl.ShaderParser;
|
||||
import org.taumc.glsl.Transformer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumMap;
|
||||
@@ -837,6 +839,10 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
return shouldRenderParticlesBeforeDeferred;
|
||||
}
|
||||
|
||||
public boolean shouldSeparateEntityDraws() {
|
||||
return packDirectives.shouldUseSeparateEntityDraws();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowConcurrentCompute() {
|
||||
return allowConcurrentCompute;
|
||||
@@ -991,6 +997,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
private boolean matchingBlend;
|
||||
|
||||
private void requestMatch() {
|
||||
if (DisplayListManager.getRecordMode() == DisplayListManager.RecordMode.COMPILE) return;
|
||||
if (GLStateManager.isForeignDraw() || BatchEligibility.batchingAllowed()) {
|
||||
GLSMHooks.pendingProgramSelection = this;
|
||||
return;
|
||||
@@ -1022,6 +1029,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
}
|
||||
|
||||
private void matchPass(RenderCondition condition) {
|
||||
if (DisplayListManager.getRecordMode() == DisplayListManager.RecordMode.COMPILE) return;
|
||||
currentCondition = condition;
|
||||
beginPass(table.match(condition, inputs));
|
||||
}
|
||||
@@ -1041,6 +1049,10 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
}
|
||||
|
||||
public void beginPass(Pass pass) {
|
||||
IrisDisplayListState.runProgramTransition(() -> beginPassNow(pass));
|
||||
}
|
||||
|
||||
private void beginPassNow(Pass pass) {
|
||||
if (current == pass) {
|
||||
return;
|
||||
}
|
||||
@@ -1064,9 +1076,11 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
}
|
||||
|
||||
private boolean drivingProgram;
|
||||
private Instancing activeInstancing = Instancing.NONE;
|
||||
|
||||
@Override
|
||||
public void rebindCurrentPass() {
|
||||
activeInstancing = Instancing.NONE;
|
||||
GLSMHooks.resolvePendingProgram();
|
||||
final Pass pass = this.current;
|
||||
if (pass == null) {
|
||||
@@ -1353,6 +1367,10 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
}
|
||||
|
||||
public void use() {
|
||||
IrisDisplayListState.runProgramTransition(this::useNow);
|
||||
}
|
||||
|
||||
private void useNow() {
|
||||
DepthColorStorage.unlockDepthColor();
|
||||
|
||||
if (isBeforeTranslucent) {
|
||||
@@ -1388,11 +1406,12 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
bufferBlendOverrides.forEach(BufferBlendOverride::apply);
|
||||
}
|
||||
|
||||
if (program != null) {
|
||||
program.use();
|
||||
if (activeInstancing != Instancing.NONE && program != null) {
|
||||
DeferredWorldRenderingPipeline.this.bindInstancedVariant(activeInstancing);
|
||||
} else {
|
||||
if (program != null) program.use();
|
||||
DeferredWorldRenderingPipeline.this.customUniforms.push(this);
|
||||
}
|
||||
|
||||
DeferredWorldRenderingPipeline.this.customUniforms.push(this);
|
||||
}
|
||||
|
||||
public void stopUsing() {
|
||||
@@ -1483,6 +1502,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
|
||||
@Override
|
||||
public void bindInstancedVariant(Instancing kind) {
|
||||
activeInstancing = kind;
|
||||
final Program variant = current.instancedVariant(kind);
|
||||
variant.use();
|
||||
this.customUniforms.push(variant);
|
||||
@@ -2265,13 +2285,18 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
currentNormalTexture = pbrHolder.getNormalTexture().getGlTextureId();
|
||||
currentSpecularTexture = pbrHolder.getSpecularTexture().getGlTextureId();
|
||||
|
||||
final TextureFormat textureFormat = TextureFormatLoader.getFormat();
|
||||
if (textureFormat != null) {
|
||||
textureFormat.setupTextureParameters(PBRType.NORMAL, pbrHolder.getNormalTexture());
|
||||
textureFormat.setupTextureParameters(PBRType.SPECULAR, pbrHolder.getSpecularTexture());
|
||||
}
|
||||
BatchStateGuard.suspend();
|
||||
try {
|
||||
final TextureFormat textureFormat = TextureFormatLoader.getFormat();
|
||||
if (textureFormat != null) {
|
||||
textureFormat.setupTextureParameters(PBRType.NORMAL, pbrHolder.getNormalTexture());
|
||||
textureFormat.setupTextureParameters(PBRType.SPECULAR, pbrHolder.getSpecularTexture());
|
||||
}
|
||||
|
||||
PBRTextureManager.notifyPBRTexturesChanged();
|
||||
PBRTextureManager.notifyPBRTexturesChanged();
|
||||
} finally {
|
||||
BatchStateGuard.resume();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,11 +32,11 @@ class EntityPatcher {
|
||||
|
||||
switch (parameters.type) {
|
||||
case VERTEX -> {
|
||||
if (!transformer.hasVariable("iris_Entity")) {
|
||||
transformer.injectVariable("layout(location = " + InstancedAttribs.LOC_ENTITY + ") in ivec4 iris_Entity;");
|
||||
}
|
||||
removeIfDeclared(transformer, "iris_Entity");
|
||||
transformer.injectVariable("layout(location = " + InstancedAttribs.LOC_ENTITY + ") in uvec4 iris_Entity;");
|
||||
transformer.injectVariable("flat out ivec3 iris_entityInfo;");
|
||||
transformer.prependMain("iris_entityInfo = iris_Entity.xyz;");
|
||||
transformer.prependMain("iris_entityInfo = ivec3(iris_Entity.x == 65535u ? -1 : int(iris_Entity.x), "
|
||||
+ "iris_Entity.y == 65535u ? -1 : int(iris_Entity.y), iris_Entity.z == 65535u ? -1 : int(iris_Entity.z));");
|
||||
}
|
||||
case TESSELATION_CONTROL -> {
|
||||
transformer.injectVariable("flat out ivec3 iris_entityInfoTCS[];");
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
package net.coderbot.iris.uniforms;
|
||||
|
||||
import com.gtnewhorizons.angelica.iris.IrisDisplayListState;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.floats.FloatArrayList;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
|
||||
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import org.joml.Vector4f;
|
||||
|
||||
@@ -26,9 +35,13 @@ public class CapturedRenderingState {
|
||||
@Getter
|
||||
private int currentRenderedItem = -1;
|
||||
private Runnable itemIdListener = null;
|
||||
private final IntArrayList itemStack = new IntArrayList();
|
||||
private final IntArrayList entityStack = new IntArrayList();
|
||||
private final IntArrayList blockEntityStack = new IntArrayList();
|
||||
private final FloatArrayList entityColorStack = new FloatArrayList();
|
||||
|
||||
@Getter
|
||||
private final Vector4f currentEntityColor = new Vector4f();
|
||||
private final Vector4f currentEntityColor = new Vector4f(0f);
|
||||
private Runnable entityColorListener = null;
|
||||
|
||||
private CapturedRenderingState() {
|
||||
@@ -47,6 +60,29 @@ public class CapturedRenderingState {
|
||||
}
|
||||
|
||||
public void setCurrentBlockEntity(int entity) {
|
||||
IrisDisplayListState.recordBlockEntity(entity);
|
||||
applyCurrentBlockEntity(entity);
|
||||
}
|
||||
|
||||
public void setCurrentBlockEntity(Block block, int metadata) {
|
||||
IrisDisplayListState.recordBlockEntity(block, metadata);
|
||||
final var matches = BlockRenderingSettings.INSTANCE.getBlockMetaMatches();
|
||||
final var meta = matches == null || block == null ? null : matches.get(block);
|
||||
applyCurrentBlockEntity(meta == null ? 0 : Math.max(0, meta.get(metadata)));
|
||||
}
|
||||
|
||||
public void pushCurrentBlockEntity() {
|
||||
IrisDisplayListState.recordBlockEntityScope(true);
|
||||
blockEntityStack.push(currentRenderedBlockEntity);
|
||||
}
|
||||
|
||||
public void popCurrentBlockEntity() {
|
||||
IrisDisplayListState.recordBlockEntityScope(false);
|
||||
applyCurrentBlockEntity(blockEntityStack.popInt());
|
||||
}
|
||||
|
||||
private void applyCurrentBlockEntity(int entity) {
|
||||
if (currentRenderedBlockEntity == entity) return;
|
||||
this.currentRenderedBlockEntity = entity;
|
||||
|
||||
if (this.blockEntityIdListener != null) {
|
||||
@@ -55,6 +91,7 @@ public class CapturedRenderingState {
|
||||
}
|
||||
|
||||
private void setCurrentEntity(int entity) {
|
||||
if (currentRenderedEntity == entity) return;
|
||||
this.currentRenderedEntity = entity;
|
||||
|
||||
if (this.entityIdListener != null) {
|
||||
@@ -66,11 +103,59 @@ public class CapturedRenderingState {
|
||||
* I should have done this a while ago, better solution to not forget these exist in tandem.
|
||||
*/
|
||||
public void setCurrentEntityAndItem(int entity, int item) {
|
||||
IrisDisplayListState.recordEntityAndItem(entity, item);
|
||||
setCurrentEntity(entity);
|
||||
setCurrentRenderedItem(item);
|
||||
applyCurrentRenderedItem(item);
|
||||
}
|
||||
|
||||
public void setCurrentNamedEntity(NamespacedId entity) {
|
||||
IrisDisplayListState.recordNamedEntity(entity);
|
||||
final var ids = BlockRenderingSettings.INSTANCE.getEntityIds();
|
||||
setCurrentEntity(ids == null ? -1 : ids.applyAsInt(entity));
|
||||
applyCurrentRenderedItem(0);
|
||||
}
|
||||
|
||||
public void pushCurrentEntityAndItem() {
|
||||
IrisDisplayListState.recordEntityScope(true);
|
||||
entityStack.push(currentRenderedEntity);
|
||||
itemStack.push(currentRenderedItem);
|
||||
}
|
||||
|
||||
public void setCurrentRenderedEntity(Entity entity) {
|
||||
IrisDisplayListState.recordEntity(entity);
|
||||
setCurrentEntity(EntityIdHelper.getEntityId(entity));
|
||||
applyCurrentRenderedItem(0);
|
||||
}
|
||||
|
||||
public void popCurrentEntityAndItem() {
|
||||
IrisDisplayListState.recordEntityScope(false);
|
||||
// Restore the playback caller, never the IDs seen while compiling the list.
|
||||
setCurrentEntity(entityStack.popInt());
|
||||
applyCurrentRenderedItem(itemStack.popInt());
|
||||
}
|
||||
|
||||
public void setCurrentEntityColor(float r, float g, float b, float a) {
|
||||
IrisDisplayListState.recordEntityColor(r, g, b, a);
|
||||
applyCurrentEntityColor(r, g, b, a);
|
||||
}
|
||||
|
||||
public void pushCurrentEntityColor() {
|
||||
IrisDisplayListState.recordEntityColorScope(true);
|
||||
entityColorStack.push(currentEntityColor.x);
|
||||
entityColorStack.push(currentEntityColor.y);
|
||||
entityColorStack.push(currentEntityColor.z);
|
||||
entityColorStack.push(currentEntityColor.w);
|
||||
}
|
||||
|
||||
public void popCurrentEntityColor() {
|
||||
IrisDisplayListState.recordEntityColorScope(false);
|
||||
final float a = entityColorStack.popFloat(), b = entityColorStack.popFloat();
|
||||
final float g = entityColorStack.popFloat(), r = entityColorStack.popFloat();
|
||||
applyCurrentEntityColor(r, g, b, a);
|
||||
}
|
||||
|
||||
private void applyCurrentEntityColor(float r, float g, float b, float a) {
|
||||
if (currentEntityColor.equals(r, g, b, a)) return;
|
||||
this.currentEntityColor.set(r, g, b, a);
|
||||
|
||||
if (this.entityColorListener != null) {
|
||||
@@ -79,6 +164,42 @@ public class CapturedRenderingState {
|
||||
}
|
||||
|
||||
public void setCurrentRenderedItem(int item) {
|
||||
IrisDisplayListState.recordItemId(item);
|
||||
applyCurrentRenderedItem(item);
|
||||
}
|
||||
|
||||
public void pushCurrentRenderedItem() {
|
||||
IrisDisplayListState.recordItemScope(true);
|
||||
itemStack.push(currentRenderedItem);
|
||||
}
|
||||
|
||||
public void setCurrentRenderedItem(ItemStack item) {
|
||||
IrisDisplayListState.recordItem(item);
|
||||
applyCurrentRenderedItem(ItemMaterialHelper.getMaterialId(item));
|
||||
}
|
||||
|
||||
public void setCurrentRenderedItem(Item item, int metadata) {
|
||||
IrisDisplayListState.recordItem(item, metadata);
|
||||
applyCurrentRenderedItem(ItemMaterialHelper.getMaterialId(item, metadata));
|
||||
}
|
||||
|
||||
public void setCurrentNamedItem(NamespacedId item) {
|
||||
IrisDisplayListState.recordNamedItem(item);
|
||||
final var ids = BlockRenderingSettings.INSTANCE.getItemIds();
|
||||
applyCurrentRenderedItem(ids == null ? 0 : ids.applyAsInt(item));
|
||||
}
|
||||
|
||||
public void setCurrentRenderedBlockItem(Block block, int metadata) {
|
||||
IrisDisplayListState.recordBlockItem(block, metadata);
|
||||
applyCurrentRenderedItem(ItemMaterialHelper.getMaterialId(block, metadata));
|
||||
}
|
||||
|
||||
public void popCurrentRenderedItem() {
|
||||
IrisDisplayListState.recordItemScope(false);
|
||||
applyCurrentRenderedItem(itemStack.popInt());
|
||||
}
|
||||
|
||||
private void applyCurrentRenderedItem(int item) {
|
||||
if (this.currentRenderedItem == item) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,21 +55,12 @@ public final class EntityIdHelper {
|
||||
* @return The entity ID, or -1 if no mapping exists
|
||||
*/
|
||||
public static int getEntityId(Entity entity) {
|
||||
Object2IntFunction<NamespacedId> entityIdMap = BlockRenderingSettings.INSTANCE.getEntityIds();
|
||||
if (entity == null) return -1;
|
||||
final Object2IntFunction<NamespacedId> entityIdMap = currentEntityIds();
|
||||
if (entityIdMap == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Invalidate caches if the map changed (shader reload)
|
||||
if (entityIdMap != cachedEntityIdMap) {
|
||||
entityIdCache.clear();
|
||||
entityNameCache.clear();
|
||||
entityNbtCache.clear();
|
||||
cachedEntityIdMap = entityIdMap;
|
||||
cachedCurrentPlayerId = entityIdMap.applyAsInt(CURRENT_PLAYER);
|
||||
cachedConvertingVillagerId = entityIdMap.applyAsInt(CONVERTING_VILLAGER);
|
||||
}
|
||||
|
||||
// Check NBT-conditional match first
|
||||
final NbtConditionalIdMap<NamespacedId> entityNbtMap = BlockRenderingSettings.INSTANCE.getEntityNbtMap();
|
||||
if (entityNbtMap != null && !entityNbtMap.isEmpty() && entity.worldObj != null) {
|
||||
@@ -100,7 +91,7 @@ public final class EntityIdHelper {
|
||||
}
|
||||
|
||||
// Normal entity type lookup
|
||||
final int normalId = getNormalEntityId(entity, entityIdMap);
|
||||
final int normalId = getNormalEntityId(entity.getClass(), getCachedEntityName(entity), entityIdMap);
|
||||
|
||||
// Check for special entity type overrides
|
||||
final int specialId = getSpecialEntityId(entity);
|
||||
@@ -111,6 +102,52 @@ public final class EntityIdHelper {
|
||||
return normalId;
|
||||
}
|
||||
|
||||
/** A display list retains the entity's material identity without retaining its world. */
|
||||
public record EntityIdentity(Class<?> type, NamespacedId registeredName, boolean currentPlayer,
|
||||
boolean convertingVillager, NBTTagCompound nbt) {
|
||||
public int resolve() {
|
||||
final Object2IntFunction<NamespacedId> ids = currentEntityIds();
|
||||
if (ids == null) return -1;
|
||||
final NbtConditionalIdMap<NamespacedId> conditions = BlockRenderingSettings.INSTANCE.getEntityNbtMap();
|
||||
if (nbt != null && registeredName != null && conditions != null && !conditions.isEmpty()
|
||||
&& conditions.hasConditions(registeredName)) {
|
||||
final int conditional = conditions.resolve(registeredName, nbt);
|
||||
if (conditional != -1) return conditional;
|
||||
}
|
||||
final int special = currentPlayer ? cachedCurrentPlayerId
|
||||
: convertingVillager ? cachedConvertingVillagerId : -1;
|
||||
return special != -1 ? special : getNormalEntityId(type, registeredName, ids);
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityIdentity snapshot(Entity entity) {
|
||||
if (entity == null) return null;
|
||||
NBTTagCompound nbt = null;
|
||||
if (entity.worldObj != null) {
|
||||
nbt = new NBTTagCompound();
|
||||
entity.writeToNBT(nbt);
|
||||
// Entity serializers can attach live item tags to the output compound.
|
||||
nbt = (NBTTagCompound) nbt.copy();
|
||||
}
|
||||
final String registeredName = EntityList.getEntityString(entity);
|
||||
return new EntityIdentity(entity.getClass(), registeredName == null ? null : new NamespacedId(registeredName),
|
||||
entity instanceof EntityPlayer && entity == Minecraft.getMinecraft().renderViewEntity,
|
||||
entity instanceof EntityZombie zombie && zombie.isConverting(), nbt);
|
||||
}
|
||||
|
||||
private static Object2IntFunction<NamespacedId> currentEntityIds() {
|
||||
final Object2IntFunction<NamespacedId> ids = BlockRenderingSettings.INSTANCE.getEntityIds();
|
||||
if (ids != cachedEntityIdMap) {
|
||||
entityIdCache.clear();
|
||||
entityNameCache.clear();
|
||||
entityNbtCache.clear();
|
||||
cachedEntityIdMap = ids;
|
||||
cachedCurrentPlayerId = ids == null ? -1 : ids.applyAsInt(CURRENT_PLAYER);
|
||||
cachedConvertingVillagerId = ids == null ? -1 : ids.applyAsInt(CONVERTING_VILLAGER);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the entity should use a special hardcoded entity ID.
|
||||
*/
|
||||
@@ -134,10 +171,7 @@ public final class EntityIdHelper {
|
||||
* Get the normal entity ID based on entity type, with caching.
|
||||
* Uses Class<?> as cache key for fast reference-equality lookups.
|
||||
*/
|
||||
private static int getNormalEntityId(Entity entity, Object2IntFunction<NamespacedId> entityIdMap) {
|
||||
// Use entity class as cache key
|
||||
Class<?> entityClass = entity.getClass();
|
||||
|
||||
private static int getNormalEntityId(Class<?> entityClass, NamespacedId entityName, Object2IntFunction<NamespacedId> entityIdMap) {
|
||||
// Check cache first
|
||||
int cached = entityIdCache.getInt(entityClass);
|
||||
if (cached != Integer.MIN_VALUE) {
|
||||
@@ -145,7 +179,7 @@ public final class EntityIdHelper {
|
||||
}
|
||||
|
||||
// Cache miss, store for next lookup
|
||||
int resolvedId = resolveEntityId(entity, entityClass, entityIdMap);
|
||||
int resolvedId = resolveEntityId(entityClass, entityName, entityIdMap);
|
||||
entityIdCache.put(entityClass, resolvedId);
|
||||
|
||||
return resolvedId;
|
||||
@@ -158,11 +192,10 @@ public final class EntityIdHelper {
|
||||
* 3. Fully qualified class name (e.g., "net.minecraft.entity.effect.EntityLightningBolt")
|
||||
* 4. Special hardcoded cases (e.g., "minecraft:lightning_bolt")
|
||||
*/
|
||||
private static int resolveEntityId(Entity entity, Class<?> entityClass, Object2IntFunction<NamespacedId> entityIdMap) {
|
||||
private static int resolveEntityId(Class<?> entityClass, NamespacedId entityType, Object2IntFunction<NamespacedId> entityIdMap) {
|
||||
// Try registered entity name first (most common)
|
||||
String entityType = EntityList.getEntityString(entity);
|
||||
if (entityType != null) {
|
||||
return entityIdMap.applyAsInt(new NamespacedId(entityType));
|
||||
return entityIdMap.applyAsInt(entityType);
|
||||
}
|
||||
|
||||
String simpleClassName = entityClass.getSimpleName();
|
||||
@@ -173,7 +206,7 @@ public final class EntityIdHelper {
|
||||
id = entityIdMap.applyAsInt(new NamespacedId(className));
|
||||
}
|
||||
|
||||
if (id == -1 && entity instanceof EntityLightningBolt) {
|
||||
if (id == -1 && EntityLightningBolt.class.isAssignableFrom(entityClass)) {
|
||||
// Shaderpacks use "minecraft:lightning_bolt" so we should continue to provide it here
|
||||
// Even if we can just use EntityLightningBolt
|
||||
id = entityIdMap.applyAsInt(LIGHTNING_BOLT_ID);
|
||||
@@ -188,12 +221,13 @@ public final class EntityIdHelper {
|
||||
private static NamespacedId getCachedEntityName(Entity entity) {
|
||||
Class<?> entityClass = entity.getClass();
|
||||
NamespacedId cached = entityNameCache.get(entityClass);
|
||||
if (cached != null) {
|
||||
if (cached != null || entityNameCache.containsKey(entityClass)) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
String entityType = EntityList.getEntityString(entity);
|
||||
if (entityType == null) {
|
||||
entityNameCache.put(entityClass, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,14 @@ import net.minecraft.item.ItemStack;
|
||||
* Helper class to manage the currentRenderedItem ID uniform.
|
||||
*/
|
||||
public class ItemIdManager {
|
||||
public static void pushItemId() {
|
||||
CapturedRenderingState.INSTANCE.pushCurrentRenderedItem();
|
||||
}
|
||||
|
||||
public static void popItemId() {
|
||||
CapturedRenderingState.INSTANCE.popCurrentRenderedItem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the item ID for an armor piece or held item.
|
||||
* If the ItemStack is null/empty, resets to 0.
|
||||
@@ -18,20 +26,14 @@ public class ItemIdManager {
|
||||
* @param itemStack The armor or item being rendered
|
||||
*/
|
||||
public static void setItemId(ItemStack itemStack) {
|
||||
if (itemStack == null || itemStack.getItem() == null) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
return;
|
||||
}
|
||||
|
||||
int id = ItemMaterialHelper.getMaterialId(itemStack);
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(id);
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the item ID for a Block rendered outside of terrain.
|
||||
*/
|
||||
public static void setBlockId(Block block, int metadata) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(ItemMaterialHelper.getMaterialId(block, metadata));
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedBlockItem(block, metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user