mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-19 03:49:22 +00:00
TESR state and batching leak fixes (#2162)
This commit is contained in:
1 parent
9814a96b10
commit
1f274a64ea
24 files changed
+806
-139
No files matched your search
@@ -17,6 +17,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.mixins.interfaces.FontRendererAccessor;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.BatchDrawDefaults;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.ModelPartBatcher;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.TesrBatchRenderer;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
@@ -153,6 +154,7 @@ public class BatchingFontRenderer {
|
||||
|
||||
/** {@code OpenGlHelper.lightmapTexUnit} */
|
||||
private static final int LIGHTMAP_TEX_UNIT = 1;
|
||||
private static final int FULL_BRIGHT_LIGHT = GLSMConfig.packBrightness(240.0f, 240.0f);
|
||||
private static int rawCapacity = INITIAL_BATCH_SIZE * VERTEX_SIZE;
|
||||
private static ByteBuffer vertexData = memAlloc(rawCapacity);
|
||||
private static long vertexDataAddress = memAddress0(vertexData);
|
||||
@@ -188,6 +190,7 @@ public class BatchingFontRenderer {
|
||||
private float lightmapV = 0.0f;
|
||||
private boolean lightmapActive = false;
|
||||
private int lightmapTextureId = 0;
|
||||
private int lightmapPackedLight = -1;
|
||||
|
||||
private final Vector3f lightingFactor = new Vector3f(1.0f, 1.0f, 1.0f);
|
||||
private boolean lightingFactorActive = false;
|
||||
@@ -214,7 +217,8 @@ public class BatchingFontRenderer {
|
||||
private void captureLightmapState() {
|
||||
final int unitBinding = GLStateManager.getTextures().getTextureUnitBindings(LIGHTMAP_TEX_UNIT).getBinding();
|
||||
|
||||
final boolean active = isWorldSpaceText() && unitBinding != 0;
|
||||
final boolean active = isWorldSpaceText() && unitBinding != 0
|
||||
&& GLStateManager.getTextures().getTextureUnitStates(LIGHTMAP_TEX_UNIT).isEnabled();
|
||||
|
||||
float u = 0.0f;
|
||||
float v = 0.0f;
|
||||
@@ -226,8 +230,9 @@ public class BatchingFontRenderer {
|
||||
v = scratchLightmapUv.y;
|
||||
texture = unitBinding;
|
||||
}
|
||||
final int packedLight = active ? GLSMConfig.packedLastBrightness() : FULL_BRIGHT_LIGHT;
|
||||
|
||||
if (active == lightmapActive && u == lightmapU && v == lightmapV && texture == lightmapTextureId) {
|
||||
if (active == lightmapActive && u == lightmapU && v == lightmapV && texture == lightmapTextureId && packedLight == lightmapPackedLight) {
|
||||
return;
|
||||
}
|
||||
sealBatchSegment();
|
||||
@@ -235,6 +240,7 @@ public class BatchingFontRenderer {
|
||||
lightmapU = u;
|
||||
lightmapV = v;
|
||||
lightmapTextureId = texture;
|
||||
lightmapPackedLight = packedLight;
|
||||
}
|
||||
|
||||
private static final class TextSegment {
|
||||
@@ -261,6 +267,7 @@ public class BatchingFontRenderer {
|
||||
|
||||
private int deferredCmdWatermark;
|
||||
private static final ObjectArrayList<TextSegment> deferredSegments = ObjectArrayList.wrap(new TextSegment[16], 0);
|
||||
private static final BatchDrawDefaults DEFERRED_DRAW_DEFAULTS = new BatchDrawDefaults();
|
||||
private static final ObjectArrayList<TextSegment> deferredSegmentPool = ObjectArrayList.wrap(new TextSegment[16], 0);
|
||||
|
||||
private final Matrix4f batchProj = new Matrix4f();
|
||||
@@ -532,7 +539,7 @@ public class BatchingFontRenderer {
|
||||
segment.lightmapU = lightmapU;
|
||||
segment.lightmapV = lightmapV;
|
||||
segment.lightmapTexture = lightmapTextureId;
|
||||
segment.packedLight = GLSMConfig.packedLastBrightness();
|
||||
segment.packedLight = lightmapPackedLight;
|
||||
final Vector3f normal = ShaderManager.getCurrentNormal();
|
||||
segment.normalX = normal.x;
|
||||
segment.normalY = normal.y;
|
||||
@@ -617,21 +624,26 @@ public class BatchingFontRenderer {
|
||||
public static void flushDeferredText() {
|
||||
if (deferredSegments.isEmpty()) return;
|
||||
|
||||
if (deferredSegments.getFirst().owner.shouldDrawThroughPipeline()) {
|
||||
flushDeferredThroughPipeline();
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean locked = GLStateManager.acquireDrawLock();
|
||||
DEFERRED_DRAW_DEFAULTS.apply();
|
||||
try {
|
||||
GLStateManager.beginForeignDraw();
|
||||
if (deferredSegments.getFirst().owner.shouldDrawThroughPipeline()) {
|
||||
flushDeferredThroughPipeline();
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean locked = GLStateManager.acquireDrawLock();
|
||||
try {
|
||||
flushDeferredTextInner();
|
||||
GLStateManager.beginForeignDraw();
|
||||
try {
|
||||
flushDeferredTextInner();
|
||||
} finally {
|
||||
GLStateManager.endForeignDraw();
|
||||
}
|
||||
} finally {
|
||||
GLStateManager.endForeignDraw();
|
||||
if (locked) GLStateManager.releaseDrawLock();
|
||||
}
|
||||
} finally {
|
||||
if (locked) GLStateManager.releaseDrawLock();
|
||||
DEFERRED_DRAW_DEFAULTS.restore();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -641,6 +653,7 @@ public class BatchingFontRenderer {
|
||||
|
||||
final int d = GLStateManager.pushState(StateSet.FONT_PIPELINE);
|
||||
try {
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
GLStateManager.enableTexture();
|
||||
GLStateManager.enableAlphaTest();
|
||||
GLStateManager.enableBlend();
|
||||
@@ -688,6 +701,7 @@ public class BatchingFontRenderer {
|
||||
|
||||
final int d = GLStateManager.pushState(StateSet.FONT);
|
||||
try {
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
deferredSegments.get(0).owner.setupFontDrawState();
|
||||
GLStateManager.glDepthMask(false);
|
||||
flushLastTexture = DUMMY_RESOURCE_LOCATION;
|
||||
@@ -997,7 +1011,7 @@ public class BatchingFontRenderer {
|
||||
CapturedRenderingState.INSTANCE.setCurrentBlockEntity(prevBlockEntityId);
|
||||
final Vector3f normal = ShaderManager.getCurrentNormal();
|
||||
emitRangeThroughPipeline(this, cmdsData, batchSealedEnd, cmdCount,
|
||||
GLSMConfig.packedLastBrightness(), normal.x, normal.y, normal.z);
|
||||
lightmapPackedLight, normal.x, normal.y, normal.z);
|
||||
}
|
||||
} finally {
|
||||
GLStateManager.glPopMatrix();
|
||||
@@ -1091,6 +1105,7 @@ public class BatchingFontRenderer {
|
||||
lightmapU = 0.0f;
|
||||
lightmapV = 0.0f;
|
||||
lightmapTextureId = 0;
|
||||
lightmapPackedLight = -1;
|
||||
}
|
||||
|
||||
// === Actual text mesh generation
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.gtnewhorizon.gtnhlib.client.renderer.vertex.VertexFormat;
|
||||
import com.gtnewhorizons.angelica.api.tesr.TesrMaterial;
|
||||
import com.gtnewhorizons.angelica.api.tesr.TesrShader;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.hooks.TextureUtilHooks;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.DrawState;
|
||||
import com.gtnewhorizons.angelica.shadercompat.ShaderGlint;
|
||||
import it.unimi.dsi.fastutil.Hash;
|
||||
@@ -18,7 +19,6 @@ import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition;
|
||||
import net.coderbot.iris.layer.GbufferPrograms;
|
||||
import net.coderbot.iris.layer.PassOverride;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@@ -86,20 +86,20 @@ public final class RenderLayer implements BlendingStateHolder {
|
||||
this.hash = h;
|
||||
}
|
||||
|
||||
public static RenderLayer tesr(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cull, boolean lit) {
|
||||
return tesr(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cull, lit, false);
|
||||
public static RenderLayer tesr(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cull, boolean lit, boolean lightmap) {
|
||||
return tesr(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cull, lit, lightmap, false);
|
||||
}
|
||||
|
||||
public static RenderLayer tesr(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cull, boolean lit, boolean afterGlint) {
|
||||
return build(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cull, lit, false, afterGlint);
|
||||
public static RenderLayer tesr(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cull, boolean lit, boolean lightmap, boolean afterGlint) {
|
||||
return build(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cull, lit, lightmap, false, afterGlint);
|
||||
}
|
||||
|
||||
public static RenderLayer tesrNoPass(ResourceLocation texture, TesrMaterial material, int cull, boolean lit) {
|
||||
return build(texture, material, PassOverride.NONE, 0.0f, 0.0f, ShaderGlint.NO_TINT, cull, lit, true, false);
|
||||
public static RenderLayer tesrNoPass(ResourceLocation texture, TesrMaterial material, int cull, boolean lit, boolean lightmap) {
|
||||
return build(texture, material, PassOverride.NONE, 0.0f, 0.0f, ShaderGlint.NO_TINT, cull, lit, lightmap, true, false);
|
||||
}
|
||||
|
||||
private static RenderLayer build(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cull, boolean lit, boolean noPass, boolean afterGlint) {
|
||||
final DrawState state = DrawState.forMaterial(material, cull, lit, offsetFactor, offsetUnits);
|
||||
private static RenderLayer build(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cull, boolean lit, boolean lightmap, boolean noPass, boolean afterGlint) {
|
||||
final DrawState state = DrawState.forMaterial(material, cull, lit, lightmap, offsetFactor, offsetUnits);
|
||||
final Hook hook = hookFor(material, noPass ? PassOverride.NONE : pass, glintSlot);
|
||||
final TransparencyType transparency = afterGlint ? TransparencyType.AFTER_GLINT : transparencyFor(state.getBlend());
|
||||
final RenderLayer candidate = new RenderLayer(null, BatchVertexFormats.POSITION_COLOR_TEXTURE_LIGHTF_NORMAL,
|
||||
@@ -110,7 +110,7 @@ public final class RenderLayer implements BlendingStateHolder {
|
||||
retained.name = "angelica_tesr_" + (noPass ? "nopass_" : "")
|
||||
+ material.transparency().name().toLowerCase(Locale.ROOT) + (noPass ? "" : pass.nameSuffix())
|
||||
+ (offsetFactor == 0.0f && offsetUnits == 0.0f ? "" : "_offset" + offsetFactor + "_" + offsetUnits)
|
||||
+ "_cull" + state.getCull() + (state.isLit() ? "_lit" : "")
|
||||
+ "_cull" + state.getCull() + (state.isLit() ? "_lit" : "") + (state.isLightmap() ? "" : "_nolightmap")
|
||||
+ (glintSlot == ShaderGlint.NO_TINT ? "" : "_tint" + glintSlot) + (afterGlint ? "_after_glint" : "");
|
||||
}
|
||||
return retained;
|
||||
@@ -204,7 +204,7 @@ public final class RenderLayer implements BlendingStateHolder {
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(textureId);
|
||||
if (unfilteredAtlas) {
|
||||
filtering = true;
|
||||
TextureUtil.func_152777_a(false, false, 1.0F);
|
||||
TextureUtilHooks.forceNearestFilter();
|
||||
}
|
||||
} else {
|
||||
GLStateManager.disableTexture();
|
||||
@@ -223,7 +223,7 @@ public final class RenderLayer implements BlendingStateHolder {
|
||||
}
|
||||
if (filtering) {
|
||||
try {
|
||||
TextureUtil.func_147945_b();
|
||||
TextureUtilHooks.restoreFilterAfterNearest();
|
||||
} catch (Throwable cleanup) {
|
||||
RenderFailures.suppress(failure, cleanup);
|
||||
}
|
||||
@@ -241,7 +241,7 @@ public final class RenderLayer implements BlendingStateHolder {
|
||||
} finally {
|
||||
if (textureId != null && unfilteredAtlas) {
|
||||
try {
|
||||
TextureUtil.func_147945_b();
|
||||
TextureUtilHooks.restoreFilterAfterNearest();
|
||||
} catch (Throwable cleanup) {
|
||||
failure = RenderFailures.suppress(failure, cleanup);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.gtnewhorizons.angelica.rendering.tesr;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.MatrixHelper;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.hooks.TextureUtilHooks;
|
||||
import net.coderbot.iris.gl.blending.DepthColorStorage;
|
||||
import net.coderbot.iris.gl.program.Program;
|
||||
import net.coderbot.iris.layer.GbufferPrograms;
|
||||
import net.coderbot.iris.layer.PassOverride;
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
public final class BatchDrawDefaults {
|
||||
private static final Matrix4f IDENTITY = new Matrix4f();
|
||||
private static int passFramebuffer = -1;
|
||||
|
||||
private final Matrix4f callerTextureMatrix = new Matrix4f();
|
||||
private int callerFramebuffer = -1;
|
||||
private int callerProgram;
|
||||
private boolean textureMatrixReset;
|
||||
private boolean filterPaused;
|
||||
private boolean overridesCleared;
|
||||
|
||||
public static void capturePassFramebuffer() {
|
||||
passFramebuffer = GLStateManager.getDrawFramebuffer();
|
||||
}
|
||||
|
||||
public void apply() {
|
||||
if (passFramebuffer >= 0 && TesrBatchRenderer.deferredPipeline() == null) {
|
||||
final int framebuffer = GLStateManager.getDrawFramebuffer();
|
||||
if (framebuffer != passFramebuffer) {
|
||||
callerFramebuffer = framebuffer;
|
||||
GLStateManager.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, passFramebuffer);
|
||||
}
|
||||
}
|
||||
final int program = GLStateManager.getActiveProgram();
|
||||
if (program != 0 && !Program.isManagedBind(program) && !DepthColorStorage.isOwnedProgram(program)) {
|
||||
callerProgram = program;
|
||||
GLStateManager.glUseProgram(0);
|
||||
}
|
||||
final Matrix4f textureMatrix = GLStateManager.getTextures().getTextureUnitMatrix(0);
|
||||
if (!MatrixHelper.isIdentity(textureMatrix)) {
|
||||
callerTextureMatrix.set(textureMatrix);
|
||||
GLStateManager.setTextureMatrix(0, IDENTITY);
|
||||
textureMatrixReset = true;
|
||||
}
|
||||
filterPaused = TextureUtilHooks.pauseTemporaryFilter();
|
||||
if (GbufferPrograms.getSpecialCondition() != null || GbufferPrograms.getDeclaredTranslucency() != null
|
||||
|| GbufferPrograms.getOverridePhase() != null) {
|
||||
PassOverride.NONE.apply();
|
||||
overridesCleared = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void restore() {
|
||||
if (overridesCleared) {
|
||||
overridesCleared = false;
|
||||
PassOverride.NONE.clear();
|
||||
}
|
||||
if (filterPaused) {
|
||||
filterPaused = false;
|
||||
TextureUtilHooks.resumeTemporaryFilter();
|
||||
}
|
||||
if (textureMatrixReset) {
|
||||
textureMatrixReset = false;
|
||||
GLStateManager.setTextureMatrix(0, callerTextureMatrix);
|
||||
}
|
||||
if (callerProgram != 0) {
|
||||
final int program = callerProgram;
|
||||
callerProgram = 0;
|
||||
GLStateManager.glUseProgram(program);
|
||||
}
|
||||
if (callerFramebuffer >= 0) {
|
||||
final int framebuffer = callerFramebuffer;
|
||||
callerFramebuffer = -1;
|
||||
GLStateManager.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, framebuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.gtnewhorizons.angelica.rendering.tesr;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.tesr.TesrMaterial;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.states.PolygonState;
|
||||
import it.unimi.dsi.fastutil.Hash;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet;
|
||||
import lombok.Getter;
|
||||
@@ -15,6 +16,8 @@ public final class DrawState {
|
||||
public static final int CULL_BACK = 1;
|
||||
public static final int CULL_FRONT = 2;
|
||||
public static final int CULL_BOTH = 3;
|
||||
public static final int FRONT_FACE_CLOCKWISE = 4;
|
||||
private static final int CULL_FACE_MASK = 3;
|
||||
|
||||
public static final int OPAQUE = 0;
|
||||
public static final int TRANSLUCENT = 1;
|
||||
@@ -22,6 +25,8 @@ public final class DrawState {
|
||||
public static final int ADDITIVE_ALPHA = 3;
|
||||
public static final int GLINT = 4;
|
||||
|
||||
private static final int LIGHTMAP_UNIT = 1;
|
||||
|
||||
private static final ObjectOpenCustomHashSet<DrawState> CACHE = new ObjectOpenCustomHashSet<>(HashStrategy.INSTANCE);
|
||||
|
||||
static void clearInterning() {
|
||||
@@ -39,11 +44,12 @@ public final class DrawState {
|
||||
@Getter private final boolean colorWrite;
|
||||
@Getter private final float alphaCutoff;
|
||||
@Getter private final boolean lit;
|
||||
@Getter private final boolean lightmap;
|
||||
@Getter private final float offsetFactor;
|
||||
@Getter private final float offsetUnits;
|
||||
private final int hash;
|
||||
|
||||
private DrawState(int cull, int blend, boolean depthEqual, boolean depthWrite, boolean colorWrite, float alphaCutoff, boolean lit, float offsetFactor, float offsetUnits) {
|
||||
private DrawState(int cull, int blend, boolean depthEqual, boolean depthWrite, boolean colorWrite, float alphaCutoff, boolean lit, boolean lightmap, float offsetFactor, float offsetUnits) {
|
||||
this.cull = cull;
|
||||
this.blend = blend;
|
||||
this.depthEqual = depthEqual;
|
||||
@@ -51,6 +57,7 @@ public final class DrawState {
|
||||
this.colorWrite = colorWrite;
|
||||
this.alphaCutoff = alphaCutoff;
|
||||
this.lit = lit;
|
||||
this.lightmap = lightmap;
|
||||
this.offsetFactor = offsetFactor;
|
||||
this.offsetUnits = offsetUnits;
|
||||
int h = cull;
|
||||
@@ -60,16 +67,17 @@ public final class DrawState {
|
||||
h = h * 31 + (colorWrite ? 1 : 0);
|
||||
h = h * 31 + Float.floatToIntBits(alphaCutoff);
|
||||
h = h * 31 + (lit ? 1 : 0);
|
||||
h = h * 31 + (lightmap ? 1 : 0);
|
||||
h = h * 31 + Float.floatToIntBits(offsetFactor);
|
||||
h = h * 31 + Float.floatToIntBits(offsetUnits);
|
||||
this.hash = h;
|
||||
}
|
||||
|
||||
public static DrawState of(int cull, int blend, boolean depthEqual, boolean depthWrite, boolean colorWrite, float alphaCutoff, boolean lit, float offsetFactor, float offsetUnits) {
|
||||
return CACHE.addOrGet(new DrawState(cull, blend, depthEqual, depthWrite, colorWrite, alphaCutoff, lit, offsetFactor, offsetUnits));
|
||||
public static DrawState of(int cull, int blend, boolean depthEqual, boolean depthWrite, boolean colorWrite, float alphaCutoff, boolean lit, boolean lightmap, float offsetFactor, float offsetUnits) {
|
||||
return CACHE.addOrGet(new DrawState(cull, blend, depthEqual, depthWrite, colorWrite, alphaCutoff, lit, lightmap, offsetFactor, offsetUnits));
|
||||
}
|
||||
|
||||
public static DrawState forMaterial(TesrMaterial material, int cull, boolean lit, float offsetFactor, float offsetUnits) {
|
||||
public static DrawState forMaterial(TesrMaterial material, int cull, boolean lit, boolean lightmap, float offsetFactor, float offsetUnits) {
|
||||
return of(material.isNoCull() ? DISABLED : cull,
|
||||
blendFor(material.transparency()),
|
||||
material.isDepthEqual(),
|
||||
@@ -77,6 +85,7 @@ public final class DrawState {
|
||||
!material.isDepthOnly(),
|
||||
material.cutoutAlpha(),
|
||||
lit && !material.isUnlit(),
|
||||
lightmap,
|
||||
offsetFactor, offsetUnits);
|
||||
}
|
||||
|
||||
@@ -100,13 +109,19 @@ public final class DrawState {
|
||||
}
|
||||
|
||||
public static int liveCull() {
|
||||
return packCull(GLStateManager.getCullState().isEnabled(), GLStateManager.getPolygonState().getCullFaceMode());
|
||||
final PolygonState polygon = GLStateManager.getPolygonState();
|
||||
final int cull = packCull(GLStateManager.getCullState().isEnabled(), polygon.getCullFaceMode());
|
||||
return cull != DISABLED && polygon.getFrontFace() == GL11.GL_CW ? cull | FRONT_FACE_CLOCKWISE : cull;
|
||||
}
|
||||
|
||||
public static boolean liveLit(TesrMaterial material) {
|
||||
return GLStateManager.getLightingState().isEnabled() && !material.isUnlit();
|
||||
}
|
||||
|
||||
public static boolean liveLightmap() {
|
||||
return GLStateManager.getTextures().getTextureUnitStates(LIGHTMAP_UNIT).isEnabled();
|
||||
}
|
||||
|
||||
public void apply() {
|
||||
switch (blend) {
|
||||
case TRANSLUCENT -> {
|
||||
@@ -145,8 +160,9 @@ public final class DrawState {
|
||||
} else {
|
||||
GLStateManager.disableLighting();
|
||||
}
|
||||
GLStateManager.getTextures().getTextureUnitStates(LIGHTMAP_UNIT).setEnabled(lightmap);
|
||||
|
||||
switch (cull) {
|
||||
switch (cull & CULL_FACE_MASK) {
|
||||
case CULL_BACK -> {
|
||||
GLStateManager.enableCull();
|
||||
GLStateManager.glCullFace(GL11.GL_BACK);
|
||||
@@ -161,6 +177,7 @@ public final class DrawState {
|
||||
}
|
||||
default -> GLStateManager.disableCull();
|
||||
}
|
||||
GLStateManager.glFrontFace((cull & FRONT_FACE_CLOCKWISE) != 0 ? GL11.GL_CW : GL11.GL_CCW);
|
||||
|
||||
if (offsetFactor != 0.0f || offsetUnits != 0.0f) {
|
||||
GLStateManager.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
@@ -183,7 +200,7 @@ public final class DrawState {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DrawState[cull=" + cull + ", blend=" + blend + ", depthEqual=" + depthEqual + ", depthWrite=" + depthWrite + ", colorWrite=" + colorWrite + ", alphaCutoff=" + alphaCutoff + ", lit=" + lit + ", offset=" + offsetFactor + '/' + offsetUnits + ']';
|
||||
return "DrawState[cull=" + cull + ", blend=" + blend + ", depthEqual=" + depthEqual + ", depthWrite=" + depthWrite + ", colorWrite=" + colorWrite + ", alphaCutoff=" + alphaCutoff + ", lit=" + lit + ", lightmap=" + lightmap + ", offset=" + offsetFactor + '/' + offsetUnits + ']';
|
||||
}
|
||||
|
||||
private enum HashStrategy implements Hash.Strategy<DrawState> {
|
||||
@@ -198,7 +215,7 @@ public final class DrawState {
|
||||
public boolean equals(@Nullable DrawState a, @Nullable DrawState b) {
|
||||
if (a == b) return true;
|
||||
if (a == null || b == null) return false;
|
||||
return a.cull == b.cull && a.blend == b.blend && a.depthEqual == b.depthEqual && a.depthWrite == b.depthWrite && a.colorWrite == b.colorWrite && Float.floatToIntBits(a.alphaCutoff) == Float.floatToIntBits(b.alphaCutoff) && a.lit == b.lit && Float.floatToIntBits(a.offsetFactor) == Float.floatToIntBits(b.offsetFactor) && Float.floatToIntBits(a.offsetUnits) == Float.floatToIntBits(b.offsetUnits);
|
||||
return a.cull == b.cull && a.blend == b.blend && a.depthEqual == b.depthEqual && a.depthWrite == b.depthWrite && a.colorWrite == b.colorWrite && Float.floatToIntBits(a.alphaCutoff) == Float.floatToIntBits(b.alphaCutoff) && a.lit == b.lit && a.lightmap == b.lightmap && Float.floatToIntBits(a.offsetFactor) == Float.floatToIntBits(b.offsetFactor) && Float.floatToIntBits(a.offsetUnits) == Float.floatToIntBits(b.offsetUnits);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,7 +164,7 @@ final class EntityShadowBatcher {
|
||||
private RenderLayer layer() {
|
||||
RenderLayer l = layer;
|
||||
if (l == null) {
|
||||
l = RenderLayer.tesr(SHADOW_TEXTURE, EntityMaterials.SHADOW, PassOverride.NONE, 0.0F, 0.0F, ShaderGlint.NO_TINT, DrawState.CULL_BACK, false);
|
||||
l = RenderLayer.tesr(SHADOW_TEXTURE, EntityMaterials.SHADOW, PassOverride.NONE, 0.0F, 0.0F, ShaderGlint.NO_TINT, DrawState.CULL_BACK, false, true);
|
||||
layer = l;
|
||||
}
|
||||
return l;
|
||||
|
||||
@@ -155,14 +155,16 @@ public final class ModelPartBatcher {
|
||||
int glintSlot;
|
||||
int cull;
|
||||
boolean lit;
|
||||
boolean lightmap;
|
||||
boolean afterGlint;
|
||||
|
||||
boolean matches(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cull, boolean lit, boolean afterGlint) {
|
||||
boolean matches(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cull, boolean lit, boolean lightmap, boolean afterGlint) {
|
||||
return this.texture == texture && this.material == material && pass.equals(this.pass) && this.offsetFactor == offsetFactor
|
||||
&& this.offsetUnits == offsetUnits && this.glintSlot == glintSlot && this.cull == cull && this.lit == lit && this.afterGlint == afterGlint;
|
||||
&& this.offsetUnits == offsetUnits && this.glintSlot == glintSlot && this.cull == cull && this.lit == lit && this.lightmap == lightmap
|
||||
&& this.afterGlint == afterGlint;
|
||||
}
|
||||
|
||||
LayerKey set(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cull, boolean lit, boolean afterGlint) {
|
||||
LayerKey set(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cull, boolean lit, boolean lightmap, boolean afterGlint) {
|
||||
this.texture = texture;
|
||||
this.material = material;
|
||||
this.pass = pass;
|
||||
@@ -171,6 +173,7 @@ public final class ModelPartBatcher {
|
||||
this.glintSlot = glintSlot;
|
||||
this.cull = cull;
|
||||
this.lit = lit;
|
||||
this.lightmap = lightmap;
|
||||
this.afterGlint = afterGlint;
|
||||
return this;
|
||||
}
|
||||
@@ -182,7 +185,7 @@ public final class ModelPartBatcher {
|
||||
&& Objects.equals(pass, other.pass)
|
||||
&& Float.floatToIntBits(offsetFactor) == Float.floatToIntBits(other.offsetFactor)
|
||||
&& Float.floatToIntBits(offsetUnits) == Float.floatToIntBits(other.offsetUnits)
|
||||
&& glintSlot == other.glintSlot && cull == other.cull && lit == other.lit && afterGlint == other.afterGlint;
|
||||
&& glintSlot == other.glintSlot && cull == other.cull && lit == other.lit && lightmap == other.lightmap && afterGlint == other.afterGlint;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -193,6 +196,7 @@ public final class ModelPartBatcher {
|
||||
h = h * 31 + glintSlot;
|
||||
h = h * 31 + cull;
|
||||
h = h * 31 + (lit ? 1 : 0);
|
||||
h = h * 31 + (lightmap ? 1 : 0);
|
||||
h = h * 31 + (afterGlint ? 1 : 0);
|
||||
return h;
|
||||
}
|
||||
@@ -249,6 +253,8 @@ public final class ModelPartBatcher {
|
||||
activeGroups = shadow ? 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 (nowMs - lastSweepMs >= SWEEP_INTERVAL_MS) {
|
||||
lastSweepMs = nowMs;
|
||||
@@ -440,7 +446,7 @@ public final class ModelPartBatcher {
|
||||
final boolean offset = GLStateManager.glIsEnabled(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
final PolygonState polygon = GLStateManager.getPolygonState();
|
||||
final int cullCode = EntityMaterials.ITEM_GLINT.isNoCull() ? DrawState.DISABLED : DrawState.liveCull();
|
||||
final RenderLayer layer = layerFor(HeldItemGlint.texture(), EntityMaterials.ITEM_GLINT, PassOverride.NONE, offset ? polygon.getOffsetFactor() : 0, offset ? polygon.getOffsetUnits() : 0, ShaderGlint.NO_TINT, cullCode, false);
|
||||
final RenderLayer layer = layerFor(HeldItemGlint.texture(), EntityMaterials.ITEM_GLINT, PassOverride.NONE, offset ? polygon.getOffsetFactor() : 0, offset ? polygon.getOffsetUnits() : 0, ShaderGlint.NO_TINT, cullCode, false, DrawState.liveLightmap());
|
||||
activeGroups.queueGlintLayers(template, layer, EntityMaterials.ITEM_GLINT, currentModelView(), GLSMConfig.packedLastBrightness(), VANILLA_GLINT_COLOR, currentOverlay(), currentEntityInfo(0),
|
||||
HeldItemGlint.firstMatrix(), HeldItemGlint.secondMatrix());
|
||||
parts++;
|
||||
@@ -484,7 +490,7 @@ public final class ModelPartBatcher {
|
||||
final boolean offset = GLStateManager.glIsEnabled(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
final PolygonState polygon = GLStateManager.getPolygonState();
|
||||
final int cullCode = EntityMaterials.GLINT.isNoCull() ? DrawState.DISABLED : DrawState.liveCull();
|
||||
armorGlintLayer = layerFor(texture, EntityMaterials.GLINT, PassOverride.NONE, offset ? polygon.getOffsetFactor() : 0, offset ? polygon.getOffsetUnits() : 0, glintSlot, cullCode, lit);
|
||||
armorGlintLayer = layerFor(texture, EntityMaterials.GLINT, PassOverride.NONE, offset ? polygon.getOffsetFactor() : 0, offset ? polygon.getOffsetUnits() : 0, glintSlot, cullCode, lit, DrawState.liveLightmap());
|
||||
armorGlintTexture.set(textureMatrix);
|
||||
armorGlintColor = color;
|
||||
armorGlintLight = GLSMConfig.packedLastBrightness();
|
||||
@@ -605,7 +611,7 @@ public final class ModelPartBatcher {
|
||||
final int glintSlot = material.special() == TesrMaterial.SpecialRender.GLINT ? lastBoundGlintSlot : ShaderGlint.NO_TINT;
|
||||
final int cullCode = material.isNoCull() ? DrawState.DISABLED : DrawState.liveCull();
|
||||
final boolean lit = DrawState.liveLit(material);
|
||||
final RenderLayer layer = layerFor(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, afterGlint);
|
||||
final RenderLayer layer = layerFor(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, DrawState.liveLightmap(), afterGlint);
|
||||
// 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();
|
||||
@@ -705,24 +711,24 @@ public final class ModelPartBatcher {
|
||||
entry.cubes = cubes;
|
||||
}
|
||||
|
||||
private RenderLayer layerFor(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cullCode, boolean lit) {
|
||||
return layerFor(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, false);
|
||||
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, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cullCode, boolean lit, boolean afterGlint) {
|
||||
private RenderLayer layerFor(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int glintSlot, int cullCode, boolean lit, boolean lightmap, boolean afterGlint) {
|
||||
for (int i = 0; i < RECENT_LAYERS; i++) {
|
||||
final RenderLayer recent = recentLayers[i];
|
||||
if (recent != null && recentKeys[i].matches(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, afterGlint)) {
|
||||
if (recent != null && recentKeys[i].matches(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, lightmap, afterGlint)) {
|
||||
return lastLayer = recent;
|
||||
}
|
||||
}
|
||||
RenderLayer layer = layers.get(scratchKey.set(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, afterGlint));
|
||||
RenderLayer layer = layers.get(scratchKey.set(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, lightmap, afterGlint));
|
||||
if (layer == null) {
|
||||
layer = RenderLayer.tesr(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, afterGlint);
|
||||
layers.put(new LayerKey().set(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, afterGlint), layer);
|
||||
layer = RenderLayer.tesr(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, lightmap, afterGlint);
|
||||
layers.put(new LayerKey().set(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, lightmap, afterGlint), layer);
|
||||
}
|
||||
if (recentKeys[recentNext] == null) recentKeys[recentNext] = new LayerKey();
|
||||
recentKeys[recentNext].set(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, afterGlint);
|
||||
recentKeys[recentNext].set(texture, material, pass, offsetFactor, offsetUnits, glintSlot, cullCode, lit, lightmap, afterGlint);
|
||||
recentLayers[recentNext] = layer;
|
||||
recentNext = (recentNext + 1) % RECENT_LAYERS;
|
||||
return lastLayer = layer;
|
||||
@@ -754,7 +760,7 @@ public final class ModelPartBatcher {
|
||||
active = false;
|
||||
shaderPipeline = null;
|
||||
layers.clear();
|
||||
scratchKey.set(null, null, null, 0.0f, 0.0f, ShaderGlint.NO_TINT, DrawState.DISABLED, false, false);
|
||||
scratchKey.set(null, null, null, 0.0f, 0.0f, ShaderGlint.NO_TINT, DrawState.DISABLED, false, false, false);
|
||||
Arrays.fill(recentLayers, null);
|
||||
recentNext = 0;
|
||||
lastLayer = null;
|
||||
|
||||
@@ -88,6 +88,8 @@ public final class TesrBatchRenderer {
|
||||
discardDeferred();
|
||||
}
|
||||
activePass = passKey;
|
||||
bufferSource.capturePassLighting();
|
||||
BatchDrawDefaults.capturePassFramebuffer();
|
||||
retained[passKey].beginPass(baseMV, camX, camY, camZ, instancedCapable() ? instancedRenderer : null, deferredPipeline());
|
||||
if (passKey == PASS_MAIN_0) {
|
||||
final long now = System.currentTimeMillis();
|
||||
@@ -175,7 +177,7 @@ public final class TesrBatchRenderer {
|
||||
final int cullCode = material.isNoCull() ? DrawState.DISABLED : DrawState.liveCull();
|
||||
final boolean lit = DrawState.liveLit(material);
|
||||
final RenderLayer layer = layerFor(texture, material, pass,
|
||||
offset ? polygon.getOffsetFactor() : 0.0f, offset ? polygon.getOffsetUnits() : 0.0f, cullCode, lit);
|
||||
offset ? polygon.getOffsetFactor() : 0.0f, offset ? polygon.getOffsetUnits() : 0.0f, cullCode, lit, DrawState.liveLightmap());
|
||||
final int blockEntityId = pass.isEntityPhase()
|
||||
? CapturedRenderingState.INSTANCE.getCurrentRenderedEntity()
|
||||
: CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity();
|
||||
@@ -209,8 +211,9 @@ public final class TesrBatchRenderer {
|
||||
float offsetUnits;
|
||||
int cull;
|
||||
boolean lit;
|
||||
boolean lightmap;
|
||||
|
||||
LayerKey set(ResourceLocation texture, TesrMaterial.Transparency transparency, boolean noCull, boolean unlit, boolean noDepthWrite, boolean depthOnly, float cutoutAlpha, boolean depthEqual, TesrMaterial.SpecialRender special, TesrShader shader, boolean noPass, PassOverride pass, float offsetFactor, float offsetUnits, int cull, boolean lit) {
|
||||
LayerKey set(ResourceLocation texture, TesrMaterial.Transparency transparency, boolean noCull, boolean unlit, boolean noDepthWrite, boolean depthOnly, float cutoutAlpha, boolean depthEqual, TesrMaterial.SpecialRender special, TesrShader shader, boolean noPass, PassOverride pass, float offsetFactor, float offsetUnits, int cull, boolean lit, boolean lightmap) {
|
||||
this.texture = texture;
|
||||
this.transparency = transparency;
|
||||
this.noCull = noCull;
|
||||
@@ -227,11 +230,12 @@ public final class TesrBatchRenderer {
|
||||
this.offsetUnits = offsetUnits;
|
||||
this.cull = cull;
|
||||
this.lit = lit;
|
||||
this.lightmap = lightmap;
|
||||
return this;
|
||||
}
|
||||
|
||||
LayerKey copy() {
|
||||
return new LayerKey().set(texture, transparency, noCull, unlit, noDepthWrite, depthOnly, cutoutAlpha, depthEqual, special, shader, noPass, pass, offsetFactor, offsetUnits, cull, lit);
|
||||
return new LayerKey().set(texture, transparency, noCull, unlit, noDepthWrite, depthOnly, cutoutAlpha, depthEqual, special, shader, noPass, pass, offsetFactor, offsetUnits, cull, lit, lightmap);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -245,7 +249,7 @@ public final class TesrBatchRenderer {
|
||||
&& Objects.equals(pass, other.pass)
|
||||
&& Float.floatToIntBits(offsetFactor) == Float.floatToIntBits(other.offsetFactor)
|
||||
&& Float.floatToIntBits(offsetUnits) == Float.floatToIntBits(other.offsetUnits)
|
||||
&& cull == other.cull && lit == other.lit;
|
||||
&& cull == other.cull && lit == other.lit && lightmap == other.lightmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -266,6 +270,7 @@ public final class TesrBatchRenderer {
|
||||
h = h * 31 + Float.floatToIntBits(offsetUnits);
|
||||
h = h * 31 + cull;
|
||||
h = h * 31 + (lit ? 1 : 0);
|
||||
h = h * 31 + (lightmap ? 1 : 0);
|
||||
return h;
|
||||
}
|
||||
}
|
||||
@@ -279,19 +284,22 @@ public final class TesrBatchRenderer {
|
||||
private float lastLayerOffsetUnits;
|
||||
private int lastLayerCull;
|
||||
private boolean lastLayerLit;
|
||||
private boolean lastLayerLightmap;
|
||||
private RenderLayer lastLayer;
|
||||
private ResourceLocation lastImmediateTexture;
|
||||
private TesrMaterial lastImmediateMaterial;
|
||||
private int lastImmediateCull;
|
||||
private boolean lastImmediateLit;
|
||||
private boolean lastImmediateLightmap;
|
||||
private RenderLayer lastImmediateLayer;
|
||||
|
||||
private RenderLayer layerFor(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int cullCode, boolean lit) {
|
||||
private RenderLayer layerFor(ResourceLocation texture, TesrMaterial material, PassOverride pass, float offsetFactor, float offsetUnits, int cullCode, boolean lit, boolean lightmap) {
|
||||
if (texture == lastLayerTexture && material == lastLayerMaterial && pass.equals(lastLayerPass)
|
||||
&& offsetFactor == lastLayerOffsetFactor && offsetUnits == lastLayerOffsetUnits && cullCode == lastLayerCull && lit == lastLayerLit) {
|
||||
&& offsetFactor == lastLayerOffsetFactor && offsetUnits == lastLayerOffsetUnits && cullCode == lastLayerCull && lit == lastLayerLit
|
||||
&& lightmap == lastLayerLightmap) {
|
||||
return lastLayer;
|
||||
}
|
||||
final RenderLayer layer = layerLookup(texture, material, false, pass, offsetFactor, offsetUnits, cullCode, lit);
|
||||
final RenderLayer layer = layerLookup(texture, material, false, pass, offsetFactor, offsetUnits, cullCode, lit, lightmap);
|
||||
lastLayerTexture = texture;
|
||||
lastLayerMaterial = material;
|
||||
lastLayerPass = pass;
|
||||
@@ -299,6 +307,7 @@ public final class TesrBatchRenderer {
|
||||
lastLayerOffsetUnits = offsetUnits;
|
||||
lastLayerCull = cullCode;
|
||||
lastLayerLit = lit;
|
||||
lastLayerLightmap = lightmap;
|
||||
lastLayer = layer;
|
||||
return layer;
|
||||
}
|
||||
@@ -306,23 +315,26 @@ public final class TesrBatchRenderer {
|
||||
private RenderLayer noPassLayerFor(ResourceLocation texture, TesrMaterial material) {
|
||||
final int cullCode = material.isNoCull() ? DrawState.DISABLED : DrawState.liveCull();
|
||||
final boolean lit = DrawState.liveLit(material);
|
||||
if (texture == lastImmediateTexture && material == lastImmediateMaterial && cullCode == lastImmediateCull && lit == lastImmediateLit) {
|
||||
final boolean lightmap = DrawState.liveLightmap();
|
||||
if (texture == lastImmediateTexture && material == lastImmediateMaterial && cullCode == lastImmediateCull && lit == lastImmediateLit
|
||||
&& lightmap == lastImmediateLightmap) {
|
||||
return lastImmediateLayer;
|
||||
}
|
||||
final RenderLayer layer = layerLookup(texture, material, true, PassOverride.NONE, 0.0f, 0.0f, cullCode, lit);
|
||||
final RenderLayer layer = layerLookup(texture, material, true, PassOverride.NONE, 0.0f, 0.0f, cullCode, lit, lightmap);
|
||||
lastImmediateTexture = texture;
|
||||
lastImmediateMaterial = material;
|
||||
lastImmediateCull = cullCode;
|
||||
lastImmediateLit = lit;
|
||||
lastImmediateLightmap = lightmap;
|
||||
lastImmediateLayer = layer;
|
||||
return layer;
|
||||
}
|
||||
|
||||
private RenderLayer layerLookup(ResourceLocation texture, TesrMaterial material, boolean noPass, PassOverride pass, float offsetFactor, float offsetUnits, int cullCode, boolean lit) {
|
||||
final LayerKey key = scratchKey.set(texture, material.transparency(), material.isNoCull(), material.isUnlit(), material.isNoDepthWrite(), material.isDepthOnly(), material.cutoutAlpha(), material.isDepthEqual(), material.special(), material.shader(), noPass, pass, offsetFactor, offsetUnits, cullCode, lit);
|
||||
private RenderLayer layerLookup(ResourceLocation texture, TesrMaterial material, boolean noPass, PassOverride pass, float offsetFactor, float offsetUnits, int cullCode, boolean lit, boolean lightmap) {
|
||||
final LayerKey key = scratchKey.set(texture, material.transparency(), material.isNoCull(), material.isUnlit(), material.isNoDepthWrite(), material.isDepthOnly(), material.cutoutAlpha(), material.isDepthEqual(), material.special(), material.shader(), noPass, pass, offsetFactor, offsetUnits, cullCode, lit, lightmap);
|
||||
RenderLayer layer = layers.get(key);
|
||||
if (layer == null) {
|
||||
layer = noPass ? RenderLayer.tesrNoPass(texture, material, cullCode, lit) : RenderLayer.tesr(texture, material, pass, offsetFactor, offsetUnits, ShaderGlint.NO_TINT, cullCode, lit);
|
||||
layer = noPass ? RenderLayer.tesrNoPass(texture, material, cullCode, lit, lightmap) : RenderLayer.tesr(texture, material, pass, offsetFactor, offsetUnits, ShaderGlint.NO_TINT, cullCode, lit, lightmap);
|
||||
layers.put(key.copy(), layer);
|
||||
}
|
||||
return layer;
|
||||
|
||||
@@ -2,7 +2,9 @@ package net.coderbot.batchedentityrendering.impl;
|
||||
|
||||
import com.gtnewhorizons.angelica.rendering.RenderFailures;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.RenderLayer;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.BatchDrawDefaults;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.LightingSnapshot;
|
||||
import com.gtnewhorizons.angelica.glsm.StateSet;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
@@ -45,6 +47,8 @@ public class AngelicaBufferSource implements Groupable {
|
||||
private int drawStateDepth = -1;
|
||||
private boolean irisStateSaved;
|
||||
private GroupIdKind idKind = GroupIdKind.BLOCK_ENTITY;
|
||||
private LightingSnapshot passLighting;
|
||||
private final BatchDrawDefaults drawDefaults = new BatchDrawDefaults();
|
||||
|
||||
public AngelicaBufferSource() {
|
||||
for (int i = 0; i < builders.length; i++) {
|
||||
@@ -53,6 +57,11 @@ public class AngelicaBufferSource implements Groupable {
|
||||
affinities.defaultReturnValue(-1);
|
||||
}
|
||||
|
||||
public void capturePassLighting() {
|
||||
if (passLighting == null) passLighting = new LightingSnapshot();
|
||||
GLStateManager.captureLighting(passLighting);
|
||||
}
|
||||
|
||||
public SegmentedBufferBuilder getBuffer(RenderLayer type, int blockEntityId) {
|
||||
renderOrderManager.begin(type);
|
||||
int affinity = affinities.getAndMoveToLast(type);
|
||||
@@ -188,6 +197,7 @@ public class AngelicaBufferSource implements Groupable {
|
||||
|
||||
private void restoreDrawState() {
|
||||
if (drawStateDepth >= 0) {
|
||||
drawDefaults.restore();
|
||||
GLStateManager.popStateTo(drawStateDepth);
|
||||
drawStateDepth = -1;
|
||||
}
|
||||
@@ -221,6 +231,8 @@ public class AngelicaBufferSource implements Groupable {
|
||||
if (drawStateDepth < 0) {
|
||||
drawStateDepth = GLStateManager.pushState(StateSet.BATCH);
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
if (passLighting != null) GLStateManager.applyLighting(passLighting);
|
||||
drawDefaults.apply();
|
||||
}
|
||||
saveIrisState();
|
||||
layer.startDrawing();
|
||||
|
||||
Reference in new issue
Block a user