Compare commits

..
Author SHA1 Message Date
Jason Mitchell 78334717e7 Fix TAA:
* Return an immutable view of the underlying camera position to avoid mutating it
* Update Camera Uniforms to utilize the view instead of mutating in place
2025-11-05 09:59:47 -08:00
MalTeeez a77765a2c9 Allow avoiding other mods spash screen handlers (#1080) 2025-10-31 16:06:28 -07:00
sisyphussy 1a9fe45ee9 Add VAO test (#1089) 2025-10-31 10:10:01 -07:00
Jason Mitchell 21ef5905c8 Roll back some of the hacks (#1085) 2025-10-30 20:50:43 -07:00
9 changed files with 138 additions and 39 deletions

No files matched your search

+2
View File
@@ -101,6 +101,8 @@ dependencies {
compileOnly(rfg.deobf("curse.maven:security-craft-64760:2818228"))
runtimeOnlyNonPublishable(rfg.deobf("CoreTweaks:CoreTweaks:0.3.3.2"))
// For testing alternative splash screens, can be sourced from https://github.com/MalTeeez/ModernSplash/releases
//runtimeOnly(rfg.deobf(files("dependencies/modernsplash-1.7.10-1.2.2-dev.jar")))
// Hodgepodge
transformedMod("net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev")
@@ -87,8 +87,7 @@ public class BatchingFontRenderer {
}
this.isSGA = Objects.equals(this.locationFontTexture.getResourcePath(), "textures/font/ascii_sga.png");
// noinspection deprecation
this.isSplash = underlying instanceof SplashProgress.SplashFontRenderer;
this.isSplash = FontStrategist.isSplashFontRendererActive(underlying);
FontProviderMC.get(this.isSGA).charWidth = this.charWidth;
FontProviderMC.get(this.isSGA).locationFontTexture = this.locationFontTexture;
@@ -3,8 +3,10 @@ package com.gtnewhorizons.angelica.client.font;
import com.google.common.collect.HashMultiset;
import com.gtnewhorizons.angelica.config.FontConfig;
import com.gtnewhorizons.angelica.mixins.interfaces.ResourceAccessor;
import cpw.mods.fml.client.SplashProgress;
import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.resources.DefaultResourcePack;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -125,4 +127,17 @@ public class FontStrategist {
}
customFontInUse = (FontConfig.enableCustomFont && (primaryFontFound || fallbackFontFound));
}
public static boolean isSplashFontRendererActive(FontRenderer fontRenderer) {
// noinspection deprecation
boolean active = fontRenderer instanceof SplashProgress.SplashFontRenderer;
try {
Class<?> customSplashClass = Class.forName("gkappa.modernsplash.CustomSplash$SplashFontRenderer");
active = active || customSplashClass.isInstance(fontRenderer);
} catch (ClassNotFoundException ignored) {
}
return active;
}
}
@@ -44,7 +44,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.profiler.Profiler;
import net.minecraft.tileentity.TileEntity;
import org.joml.Matrix4f;
import org.joml.Vector3d;
import org.joml.Vector3dc;
import org.joml.Vector3f;
import org.joml.Vector4f;
import org.lwjgl.BufferUtils;
@@ -141,11 +141,11 @@ public class ShadowRenderer {
public static MatrixStack createShadowModelView(float sunPathRotation, float intervalSize) {
// Determine the camera position
final Vector3d cameraPos = CameraUniforms.getUnshiftedCameraPosition();
final Vector3dc cameraPos = CameraUniforms.getUnshiftedCameraPosition();
final double cameraX = cameraPos.x;
final double cameraY = cameraPos.y;
final double cameraZ = cameraPos.z;
final double cameraX = cameraPos.x();
final double cameraY = cameraPos.y();
final double cameraZ = cameraPos.z();
// Set up our modelview matrix stack
final MatrixStack modelView = new MatrixStack();
@@ -461,7 +461,7 @@ public class ShadowRenderer {
MODELVIEW_BUFFER.clear().rewind();
modelView.peek().getModel().get(MODELVIEW_BUFFER);
GL11.glLoadMatrix(MODELVIEW_BUFFER);
for (TileEntity tileEntity : visibleTileEntities) {
if (hasEntityFrustum && (culler.isCulled(tileEntity.xCoord - 1, tileEntity.yCoord - 1, tileEntity.zCoord - 1, tileEntity.xCoord + 1, tileEntity.yCoord + 1, tileEntity.zCoord + 1))) {
continue;
@@ -475,10 +475,10 @@ public class ShadowRenderer {
continue;
}
renderTileEntity(tileEntity, cameraX, cameraY, cameraZ, partialTicks);
shadowTileEntities++;
}
GLStateManager.glPopMatrix();
renderedShadowTileEntities = shadowTileEntities;
@@ -530,7 +530,7 @@ public class ShadowRenderer {
terrainFrustumHolder = createShadowFrustum(renderDistanceMultiplier, terrainFrustumHolder);
// Determine the player camera position
final Vector3d cameraPos = CameraUniforms.getUnshiftedCameraPosition();
final Vector3dc cameraPos = CameraUniforms.getUnshiftedCameraPosition();
final double cameraX = cameraPos.x();
final double cameraY = cameraPos.y();
@@ -13,13 +13,6 @@ public class BufferFlipper {
}
public void flip(int target) {
// colortex6 carries material/mask data that the gbuffer populates every frame.
// If we allow it to flip, the alternate texture remains empty and later copy-back
// wipes the fresh mask, breaking TAA mask lookups (notably on foliage/transparents).
if (target == 6) {
return;
}
if (!flippedBuffers.remove(target)) {
// If the target wasn't in the set, add it to the set.
flippedBuffers.add(target);
@@ -49,7 +49,6 @@ public class FinalPassRenderer {
@Nullable
private final Pass finalPass;
private final ImmutableList<SwapPass> swapPasses;
private final ImmutableSet<Integer> flippedBuffers;
private final GlFramebuffer baseline;
private final GlFramebuffer colorHolder;
private int lastColorTextureId;
@@ -73,7 +72,6 @@ public class FinalPassRenderer {
this.noiseTexture = noiseTexture;
this.renderTargets = renderTargets;
this.flippedBuffers = flippedBuffers;
this.customUniforms = customUniforms;
this.finalPass = pack.getCompositeFinal().map(source -> {
Pass pass = new Pass();
@@ -103,26 +101,12 @@ public class FinalPassRenderer {
// TODO: We don't actually fully swap the content, we merely copy it from alt to main
// This works for the most part, but it's not perfect. A better approach would be creating secondary
// framebuffers for every other frame, but that would be a lot more complex...
final ImmutableList.Builder<SwapPass> swapPasses = ImmutableList.builder();
// BUG FIX: Swap passes are only needed for NON-flipped buffers that might flip in the future.
// Flipped buffers use ping-pong mechanism - no swap needed.
// Original code created swaps for ALL flippedAtLeastOnce buffers and copied ALT→MAIN,
// which destroyed fresh data in MAIN for currently-flipped buffers (breaking TAA).
// Fixed: Only create swaps for buffers that are in flippedAtLeastOnce but NOT currently flipped.
flippedAtLeastOnce.forEach(i -> {
flippedBuffers.forEach((i) -> {
final int target = i;
// Skip buffer 6 (material mask) - gbuffers always write to MAIN, never flipped
if (target == 6) {
return;
}
// Skip buffers that are currently flipped - they use ping-pong, no swap needed
if (flippedBuffers.contains(target)) {
return;
}
if (buffersToBeCleared.contains(target)) {
return;
}
@@ -5,6 +5,7 @@ import lombok.Getter;
import net.coderbot.iris.gl.uniform.UniformHolder;
import net.minecraft.client.Minecraft;
import org.joml.Vector3d;
import org.joml.Vector3dc;
import static net.coderbot.iris.gl.uniform.UniformUpdateFrequency.ONCE;
import static net.coderbot.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME;
@@ -34,7 +35,7 @@ public class CameraUniforms {
return client.gameSettings.renderDistanceChunks * 16;
}
public static Vector3d getUnshiftedCameraPosition() {
public static Vector3dc getUnshiftedCameraPosition() {
return RenderingState.INSTANCE.getCameraPosition();
}
@@ -59,8 +60,8 @@ public class CameraUniforms {
}
private void update() {
previousCameraPosition = currentCameraPosition;
currentCameraPosition = getUnshiftedCameraPosition().add(shift);
previousCameraPosition.set(currentCameraPosition);
currentCameraPosition.set(getUnshiftedCameraPosition()).add(shift);
updateShift();
}
@@ -0,0 +1,96 @@
package com.gtnewhorizons.angelica.glsm;
import com.gtnewhorizon.gtnhlib.client.opengl.UniversalVAO;
import com.gtnewhorizons.angelica.AngelicaExtension;
import com.gtnewhorizons.angelica.util.GLSMUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL30;
import static com.gtnewhorizons.angelica.util.GLSMUtil.verifyState;
@ExtendWith(AngelicaExtension.class)
public class GLSM_VAO_UnitTest {
@Test
void testDefaultStates() {
verifyState(GL30.GL_VERTEX_ARRAY_BINDING, 0, "GL_VERTEX_ARRAY_BINDING Initial State");
verifyState(GL13.GL_CLIENT_ACTIVE_TEXTURE, GL13.GL_TEXTURE0, "GL_CLIENT_ACTIVE_TEXTURE Initial State");
}
@Test
void testVAOPreservesStates() {
boolean vertexStateEnabled = GL11.glIsEnabled(GL11.GL_VERTEX_ARRAY);
// Stride = vertexSize * byte size of the type (= 4 for both GL_FLOAT and GL_INT)
final int defaultVertexSize = 2;
final int defaultVertexType = GL11.GL_FLOAT;
final int defaultVertexStride = defaultVertexSize * 4;
final int vaoVertexSize = 4;
final int vaoVertexType = GL11.GL_INT;
final int vaoVertexStride = vaoVertexSize * 4;
// Set the vertex attrib to a defined state
int vbo = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
GL11.glVertexPointer(defaultVertexSize, defaultVertexType, defaultVertexStride, 0);
verifyState(GL11.GL_VERTEX_ARRAY_SIZE, defaultVertexSize, "GL_VERTEX_ARRAY_SIZE - Setup");
verifyState(GL11.GL_VERTEX_ARRAY_TYPE, defaultVertexType, "GL_VERTEX_ARRAY_TYPE - Setup");
verifyState(GL11.GL_VERTEX_ARRAY_STRIDE, defaultVertexStride, "GL_VERTEX_ARRAY_STRIDE - Setup");
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
// Verify VAO & VBO creation
int vao = UniversalVAO.genVertexArrays();
Assertions.assertNotEquals(0, vao, "GL_VERTEX_ARRAY_BINDING - VAO Created");
UniversalVAO.bindVertexArray(vao);
verifyState(GL30.GL_VERTEX_ARRAY_BINDING, vao, "GL_VERTEX_ARRAY_BINDING - Bound");
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
verifyState(GL15.GL_ARRAY_BUFFER_BINDING, vbo, "GL_ARRAY_BUFFER_BINDING - Bound");
// Set & Verify the VAO states
GLSMUtil.setClientState(GL11.GL_VERTEX_ARRAY, !vertexStateEnabled);
verifyState(GL11.GL_VERTEX_ARRAY, !vertexStateEnabled, "GL_VERTEX_ARRAY - Set");
GL11.glVertexPointer(vaoVertexSize, vaoVertexType, vaoVertexStride, 0);
verifyState(GL11.GL_VERTEX_ARRAY_SIZE, vaoVertexSize, "GL_VERTEX_ARRAY_SIZE - Set");
verifyState(GL11.GL_VERTEX_ARRAY_TYPE, vaoVertexType, "GL_VERTEX_ARRAY_TYPE - Set");
verifyState(GL11.GL_VERTEX_ARRAY_STRIDE, vaoVertexStride, "GL_VERTEX_ARRAY_STRIDE - Set");
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
// Check if everything got reset to default
UniversalVAO.bindVertexArray(0);
verifyState(GL30.GL_VERTEX_ARRAY_BINDING, 0, "GL_VERTEX_ARRAY_BINDING - Unbound");
verifyState(GL15.GL_ARRAY_BUFFER_BINDING, 0, "GL_ARRAY_BUFFER_BINDING - Unbound");
verifyState(GL11.GL_VERTEX_ARRAY, vertexStateEnabled, "GL_VERTEX_ARRAY - Reset");
verifyState(GL11.GL_VERTEX_ARRAY_SIZE, defaultVertexSize, "GL_VERTEX_ARRAY_SIZE - Reset");
verifyState(GL11.GL_VERTEX_ARRAY_TYPE, defaultVertexType, "GL_VERTEX_ARRAY_TYPE - Reset");
verifyState(GL11.GL_VERTEX_ARRAY_STRIDE, defaultVertexStride, "GL_VERTEX_ARRAY_STRIDE - Reset");
// Check if the VAO states are still valid after re-binding it
UniversalVAO.bindVertexArray(vao);
verifyState(GL11.GL_VERTEX_ARRAY, !vertexStateEnabled, "GL_VERTEX_ARRAY - Rebound");
verifyState(GL11.GL_VERTEX_ARRAY_SIZE, vaoVertexSize, "GL_VERTEX_ARRAY_SIZE - Rebound");
verifyState(GL11.GL_VERTEX_ARRAY_TYPE, vaoVertexType, "GL_VERTEX_ARRAY_TYPE - Rebound");
verifyState(GL11.GL_VERTEX_ARRAY_STRIDE, vaoVertexStride, "GL_VERTEX_ARRAY_STRIDE - Rebound");
UniversalVAO.bindVertexArray(0);
GL15.glDeleteBuffers(vbo);
UniversalVAO.deleteVertexArrays(vao);
}
}
@@ -254,4 +254,13 @@ public class GLSMUtil {
// Reset draw buffer
GLStateManager.glDrawBuffer(GLStateManager.DEFAULT_DRAW_BUFFER);
}
public static void setClientState(int glCap, boolean state) {
if (state) {
GL11.glEnableClientState(glCap);
} else {
GL11.glDisableClientState(glCap);
}
}
}