mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-19 20:09:39 +00:00
Render pass and state stack optimizations (#2124)
This commit is contained in:
1 parent
87c83f0645
commit
9dd60f6a75
151 files changed
+9242
-3156
No files matched your search
@@ -5,8 +5,6 @@ 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.glsm.states.AlphaState;
|
||||
import com.gtnewhorizons.angelica.glsm.states.BlendState;
|
||||
import net.coderbot.iris.gl.shader.ProgramCreator;
|
||||
import net.coderbot.iris.gl.state.StateUpdateNotifiers;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPhase;
|
||||
@@ -156,89 +154,6 @@ public class GbufferPrograms {
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + previousUnit);
|
||||
}
|
||||
|
||||
public static long pushCutoutDefaults() {
|
||||
final long saved = packCutoutState();
|
||||
setCutoutDefaults();
|
||||
return saved;
|
||||
}
|
||||
|
||||
public static void popCutoutDefaults(long saved) {
|
||||
if ((saved & ALPHA_ENABLED_BIT) != 0) {
|
||||
GLStateManager.enableAlphaTest();
|
||||
} else {
|
||||
GLStateManager.disableAlphaTest();
|
||||
}
|
||||
GLStateManager.glAlphaFunc((int) ((saved >>> 32) & 0xFFFF), Float.intBitsToFloat((int) saved));
|
||||
|
||||
if ((saved & LIGHTMAP_ENABLED_BIT) == 0) {
|
||||
final int previousUnit = GLStateManager.getActiveTextureUnitForServerState();
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE1);
|
||||
GLStateManager.disableTexture();
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + previousUnit);
|
||||
}
|
||||
}
|
||||
|
||||
public static int pushBlendState() {
|
||||
if (blendDepth == blendSaves.length) {
|
||||
blendSaves = Arrays.copyOf(blendSaves, blendDepth * 2);
|
||||
blendEnabledSaves = Arrays.copyOf(blendEnabledSaves, blendDepth * 2);
|
||||
}
|
||||
|
||||
BlendState saved = blendSaves[blendDepth];
|
||||
if (saved == null) {
|
||||
saved = new BlendState();
|
||||
blendSaves[blendDepth] = saved;
|
||||
}
|
||||
|
||||
GLStateManager.getEffectiveBlendState(saved);
|
||||
blendEnabledSaves[blendDepth] = GLStateManager.isEffectiveBlendEnabled();
|
||||
|
||||
return blendDepth++;
|
||||
}
|
||||
public static void popBlendState(int depth) {
|
||||
blendDepth = depth;
|
||||
|
||||
final boolean enabled = blendEnabledSaves[depth];
|
||||
if (enabled != GLStateManager.isEffectiveBlendEnabled()) {
|
||||
if (enabled) {
|
||||
GLStateManager.enableBlend();
|
||||
} else {
|
||||
GLStateManager.disableBlend();
|
||||
}
|
||||
}
|
||||
|
||||
final BlendState saved = blendSaves[depth];
|
||||
GLStateManager.getEffectiveBlendState(blendScratch);
|
||||
if (blendScratch.getSrcRgb() != saved.getSrcRgb() || blendScratch.getDstRgb() != saved.getDstRgb()
|
||||
|| blendScratch.getSrcAlpha() != saved.getSrcAlpha() || blendScratch.getDstAlpha() != saved.getDstAlpha()) {
|
||||
GLStateManager.tryBlendFuncSeparate(saved.getSrcRgb(), saved.getDstRgb(), saved.getSrcAlpha(), saved.getDstAlpha());
|
||||
}
|
||||
}
|
||||
|
||||
public static void popBlendStateTop() {
|
||||
if (blendDepth > 0) {
|
||||
popBlendState(blendDepth - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private static BlendState[] blendSaves = new BlendState[4];
|
||||
private static boolean[] blendEnabledSaves = new boolean[4];
|
||||
private static int blendDepth;
|
||||
private static final BlendState blendScratch = new BlendState();
|
||||
|
||||
private static final long ALPHA_ENABLED_BIT = 1L << 48;
|
||||
private static final long LIGHTMAP_ENABLED_BIT = 1L << 49;
|
||||
private static final AlphaState alphaScratch = new AlphaState();
|
||||
|
||||
private static long packCutoutState() {
|
||||
GLStateManager.getEffectiveAlphaState(alphaScratch);
|
||||
|
||||
return (Float.floatToRawIntBits(alphaScratch.getReference()) & 0xFFFFFFFFL)
|
||||
| ((long) (alphaScratch.getFunction() & 0xFFFF) << 32)
|
||||
| (GLStateManager.isEffectiveAlphaTestEnabled() ? ALPHA_ENABLED_BIT : 0L)
|
||||
| (GLStateManager.getTextures().getTextureUnitStates(1).isEnabled() ? LIGHTMAP_ENABLED_BIT : 0L);
|
||||
}
|
||||
|
||||
public static void setBlockEntityDefaults() {
|
||||
GLStateManager.glVertexAttrib2s(ProgramCreator.MC_ENTITY, (short)-1, (short)-1);
|
||||
FfpExtendedAttribs.setNeutralCurrentValues();
|
||||
|
||||
Reference in new issue
Block a user