Bug Cleanup after 2.9RC2 (#2239)

This commit is contained in:
Eclipse-Sol authored and GitHub committed 2026-10-10 13:22:49 -07:00
1 parent 990dadc03f
commit 2f1f380e8e
73 files changed
+3950 -330

No files matched your search

@@ -0,0 +1,18 @@
package com.gtnewhorizons.angelica.client.rendering;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniform;
import java.nio.FloatBuffer;
public class GlUniformFloat3Array extends GlUniform<FloatBuffer> {
public GlUniformFloat3Array(int index) {
super(index);
}
@Override
public void set(FloatBuffer value) {
GLStateManager.glUniform3(this.index, value);
}
}
@@ -0,0 +1,18 @@
package com.gtnewhorizons.angelica.client.rendering;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniform;
import java.nio.FloatBuffer;
public class GlUniformFloat4Array extends GlUniform<FloatBuffer> {
public GlUniformFloat4Array(int index) {
super(index);
}
@Override
public void set(FloatBuffer value) {
GLStateManager.glUniform4(this.index, value);
}
}
@@ -0,0 +1,472 @@
package com.gtnewhorizons.angelica.compat.thaumcraft;
import com.gtnewhorizons.angelica.client.rendering.GlUniformFloat2v;
import com.gtnewhorizons.angelica.client.rendering.GlUniformFloat3Array;
import com.gtnewhorizons.angelica.client.rendering.GlUniformFloat4Array;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import com.gtnewhorizons.angelica.glsm.StateSet;
import com.gtnewhorizons.angelica.glsm.states.FogState;
import com.gtnewhorizons.angelica.glsm.states.TextureUnitArray;
import net.coderbot.iris.gl.framebuffer.GlFramebuffer;
import org.embeddedt.embeddium.impl.gl.shader.GlProgram;
import org.embeddedt.embeddium.impl.gl.shader.GlShader;
import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext;
import org.embeddedt.embeddium.impl.gl.shader.ShaderConstants;
import org.embeddedt.embeddium.impl.gl.shader.ShaderType;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat3v;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat4v;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformInt;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix4f;
import org.embeddedt.embeddium.impl.render.shader.ShaderLoader;
import org.joml.Matrix4f;
import org.joml.Vector4f;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.Arrays;
import java.util.Random;
import static com.gtnewhorizons.angelica.compat.thaumcraft.PortalRenderer.AXIS_X;
import static com.gtnewhorizons.angelica.compat.thaumcraft.PortalRenderer.AXIS_Y;
/**
* GL side of the Thaumcraft portal renderer.
*/
final class PortalDrawer {
static final int LAYERS = 16;
static final int FLOATS_PER_FACE = 16;
static final int ATLAS_SIZE = 2048;
static final int MIN_SLOT = 16;
static final int MAX_SLOT = 512;
private static final int FLOATS_PER_PLANE = LAYERS * 3;
private static final int TUNNEL_UNIT = 0;
private static final int LIGHTMAP_UNIT = 1;
private static final int FIELD_UNIT = 2;
private static final int FACE_BYTES = FLOATS_PER_FACE * Float.BYTES;
private static final double LN2 = Math.log(2.0);
private static final double SQRT_LN2 = Math.sqrt(LN2);
private static final float[] LAYER_DEPTH = new float[LAYERS];
private static final float[] LAYER_SCALE = new float[LAYERS];
private static final float[] LAYER_ANGLE = new float[LAYERS];
private static final float[] FOG_PARAMS = new float[4];
private static int maxPlanes;
static {
for (int i = 0; i < LAYERS; i++) {
LAYER_DEPTH[i] = i == 0 ? 65.0F : 16 - i;
LAYER_SCALE[i] = i == 0 ? 0.125F : i == 1 ? 0.5F : 0.0625F;
// GLStateManager.glRotatef's float radians
LAYER_ANGLE[i] = (float) Math.toRadians((float) (i * i * 4321 + i * 9) * 2.0F);
}
}
private GlProgram<Uniforms> direct;
private GlProgram<Uniforms> directFogged;
private GlProgram<Uniforms> capture;
private FloatBuffer upload;
private FloatBuffer planeUpload;
private int vao, vbo, ebo;
private GlFramebuffer atlasFramebuffer;
private int atlasTexture;
static int maxPlanes() {
if (maxPlanes == 0) {
final int vectors = GLStateManager.glGetInteger(GL20.GL_MAX_VERTEX_UNIFORM_COMPONENTS) / 4;
maxPlanes = Math.clamp((vectors - 128) / 12, 1, 64);
}
return maxPlanes;
}
static void putFace(float[] faces, int index, int axis, int plane, double x0, double y0, double z0, double x1, double y1, double z1, double x3, double y3, double z3) {
int i = index * FLOATS_PER_FACE;
faces[i++] = (float) x0;
faces[i++] = (float) y0;
faces[i++] = (float) z0;
faces[i++] = axis + 4 * plane;
faces[i++] = (float) x1;
faces[i++] = (float) y1;
faces[i++] = (float) z1;
faces[i++] = 0.0F;
faces[i++] = (float) (x1 + x3 - x0);
faces[i++] = (float) (y1 + y3 - y0);
faces[i++] = (float) (z1 + z3 - z0);
faces[i++] = 0.0F;
faces[i++] = (float) x3;
faces[i++] = (float) y3;
faces[i++] = (float) z3;
faces[i] = 0.0F;
}
private static int fogMode() {
if (!GLStateManager.getFogMode().isEnabled()) return 0;
return switch (GLStateManager.getFogState().getFogMode()) {
case GL11.GL_LINEAR -> 1;
case GL11.GL_EXP -> 2;
case GL11.GL_EXP2 -> 3;
default -> 0;
};
}
private static void uploadFog(Uniforms uniforms, int fogMode) {
final FogState fog = GLStateManager.getFogState();
final float start = fog.getStart();
final float end = fog.getEnd();
final float density = fog.getDensity();
final float range = end - start;
FOG_PARAMS[0] = range != 0.0f ? -1.0f / range : 0.0f;
FOG_PARAMS[1] = range != 0.0f ? end / range : 1.0f;
FOG_PARAMS[2] = (float) (density / LN2);
FOG_PARAMS[3] = (float) (density / SQRT_LN2);
uniforms.fogParams.set(FOG_PARAMS);
uniforms.fogColor.set((float) fog.getFogColor().x, (float) fog.getFogColor().y, (float) fog.getFogColor().z);
uniforms.fogMode.setInt(fogMode);
uniforms.fogDistanceMode.setInt(fog.getFogDistanceMode());
}
private static void instanced(int attribute, int size, int floatOffset) {
GLStateManager.glEnableVertexAttribArray(attribute);
GLStateManager.glVertexAttribPointer(attribute, size, GL11.GL_FLOAT, false, FACE_BYTES, (long) floatOffset * Float.BYTES);
GLStateManager.glVertexAttribDivisor(attribute, 1);
}
private static GlProgram<Uniforms> buildProgram(boolean capturing, boolean fogged) {
final ShaderConstants.Builder defines = ShaderConstants.builder().add("MAX_PLANES", Integer.toString(maxPlanes()));
if (capturing) defines.add("CAPTURE");
if (fogged) defines.add("FOG");
final ShaderConstants constants = defines.build();
final GlShader vert = ShaderLoader.loadShader(ShaderType.VERTEX, "angelica:thaumcraft_portal.vert", constants);
final GlShader frag = ShaderLoader.loadShader(ShaderType.FRAGMENT, "angelica:thaumcraft_portal.frag", constants);
final GlProgram<Uniforms> program;
try {
program = GlProgram.builder("angelica:thaumcraft_portal").attachShader(vert).attachShader(frag).link(Uniforms::new);
} finally {
vert.delete();
frag.delete();
}
final int previous = GLStateManager.getActiveProgram();
final int handle = program.handle();
GLStateManager.glUseProgram(handle);
GLStateManager.glUniform1i(GLStateManager.glGetUniformLocation(handle, "u_Tunnel"), TUNNEL_UNIT);
GLStateManager.glUniform1i(GLStateManager.glGetUniformLocation(handle, "u_Lightmap"), LIGHTMAP_UNIT);
GLStateManager.glUniform1i(GLStateManager.glGetUniformLocation(handle, "u_Field"), FIELD_UNIT);
GLStateManager.glUniform4f(GLStateManager.glGetUniformLocation(handle, "u_ObjectPlaneR"), 0.0F, 0.0F, 0.0F, 1.0F);
GLStateManager.glUniform3(GLStateManager.glGetUniformLocation(handle, "u_LayerColor"), floatBuffer(layerColors()));
GLStateManager.glUseProgram(previous);
return program;
}
private static FloatBuffer floatBuffer(float[] values) {
final FloatBuffer buffer = BufferUtils.createFloatBuffer(values.length);
buffer.put(values).flip();
return buffer;
}
static float[] layerColors() {
final float[] colors = new float[LAYERS * 3];
final Random random = new Random(31100L);
for (int i = 0; i < LAYERS; i++) {
final float f7 = i == 0 ? 0.1F : 1.0F / ((float) (16 - i) + 1.0F);
float red = random.nextFloat() * 0.5F + 0.1F;
float green = random.nextFloat() * 0.5F + 0.4F;
float blue = random.nextFloat() * 0.5F + 0.5F;
if (i == 0) red = green = blue = 1.0F;
colors[i * 3] = (int) (red * f7 * 255.0F) / 255.0F;
colors[i * 3 + 1] = (int) (green * f7 * 255.0F) / 255.0F;
colors[i * 3 + 2] = (int) (blue * f7 * 255.0F) / 255.0F;
}
return colors;
}
void drawDirect(float[] faces, int count, int tunnelTexture, int fieldTexture, Frame frame, boolean fogged) {
final int fogMode = fogged ? fogMode() : 0;
final GlProgram<Uniforms> program;
if (fogMode == 0) {
if (direct == null) direct = buildProgram(false, false);
program = direct;
} else {
if (directFogged == null) directFogged = buildProgram(false, true);
program = directFogged;
}
draw(program, faces, 0, count, tunnelTexture, fieldTexture, frame, fogMode);
}
void drawCapture(float[] faces, int first, int count, int tunnelTexture, int fieldTexture, Frame frame) {
if (capture == null) capture = buildProgram(true, false);
draw(capture, faces, first, count, tunnelTexture, fieldTexture, frame, 0);
}
GlFramebuffer atlasFramebuffer() {
if (atlasFramebuffer == null) {
atlasTexture = GLStateManager.glGenTextures();
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, atlasTexture);
GLStateManager.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, ATLAS_SIZE, ATLAS_SIZE, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null);
GLStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GLStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GLStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
GLStateManager.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
atlasFramebuffer = new GlFramebuffer();
atlasFramebuffer.addColorAttachment(0, atlasTexture);
atlasFramebuffer.drawBuffers(new int[]{0});
atlasFramebuffer.readBuffer(0);
if (!atlasFramebuffer.isComplete()) {
atlasFramebuffer.destroy();
GLStateManager.glDeleteTextures(atlasTexture);
atlasFramebuffer = null;
atlasTexture = 0;
throw new IllegalStateException("Incomplete Thaumcraft portal atlas framebuffer");
}
}
return atlasFramebuffer;
}
int atlasTexture() {
return atlasTexture;
}
void destroy() {
if (direct != null) direct.delete();
if (directFogged != null) directFogged.delete();
if (capture != null) capture.delete();
direct = directFogged = capture = null;
if (vao != 0) GLStateManager.glDeleteVertexArrays(vao);
if (vbo != 0) GLStateManager.glDeleteBuffers(vbo);
if (ebo != 0) GLStateManager.glDeleteBuffers(ebo);
vao = vbo = ebo = 0;
if (atlasFramebuffer != null) atlasFramebuffer.destroy();
if (atlasTexture != 0) GLStateManager.glDeleteTextures(atlasTexture);
atlasFramebuffer = null;
atlasTexture = 0;
}
private void draw(GlProgram<Uniforms> program, float[] faces, int first, int count, int tunnelTexture, int fieldTexture, Frame frame, int fogMode) {
final int previousProgram = GLStateManager.getActiveProgram();
final int previousVao = GLStateManager.getBoundVAO();
final int depth = GLStateManager.pushState(StateSet.forMask(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_TEXTURE_BIT));
try {
GLStateManager.disableBlend();
GLStateManager.glUseProgram(program.handle());
final Uniforms uniforms = program.getInterface();
if (uniforms.modelViewProjection != null) uniforms.modelViewProjection.set(frame.modelViewProjection);
if (uniforms.uploadedFrame != frame || uniforms.uploadedVersion != frame.version) {
uniforms.modelView.set(frame.modelView);
uniforms.eyePlane.set(frame.eyePlane);
uniforms.rowS.set(frame.rowS);
uniforms.rowT.set(frame.rowT);
uniforms.uploadedFrame = frame;
uniforms.uploadedVersion = frame.version;
uniforms.uploadedPlanes = 0;
}
if (uniforms.uploadedPlanes != frame.planeCount) {
final int floats = frame.planeCount * FLOATS_PER_PLANE;
if (planeUpload == null || planeUpload.capacity() < floats) planeUpload = BufferUtils.createFloatBuffer(maxPlanes() * FLOATS_PER_PLANE);
planeUpload.clear();
planeUpload.put(frame.planeData, 0, floats).flip();
uniforms.planes.set(planeUpload);
uniforms.uploadedPlanes = frame.planeCount;
}
uniforms.lightmapUv.set(frame.lightmapU, frame.lightmapV);
uniforms.lightmapEnabled.setFloat(frame.lightmapEnabled ? 1.0F : 0.0F);
if (uniforms.atlasSize != null) uniforms.atlasSize.setFloat(ATLAS_SIZE);
if (fogMode != 0) uploadFog(uniforms, fogMode);
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + FIELD_UNIT);
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, fieldTexture);
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + TUNNEL_UNIT);
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, tunnelTexture);
uploadFaces(faces, first, count);
GLStateManager.glDrawElementsInstanced(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_INT, 0L, count);
} finally {
GLStateManager.glBindVertexArray(previousVao);
GLStateManager.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GLStateManager.glUseProgram(previousProgram);
GLStateManager.popStateTo(depth);
}
}
private void uploadFaces(float[] faces, int first, int count) {
if (upload == null || upload.capacity() < count * FLOATS_PER_FACE) {
upload = BufferUtils.createFloatBuffer(Math.max(count, 64) * FLOATS_PER_FACE);
}
upload.clear();
upload.put(faces, first * FLOATS_PER_FACE, count * FLOATS_PER_FACE).flip();
if (vao == 0) createBuffers();
GLStateManager.glBindVertexArray(vao);
GLStateManager.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
GLStateManager.glBufferData(GL15.GL_ARRAY_BUFFER, upload, GL15.GL_STREAM_DRAW);
}
private void createBuffers() {
vao = GLStateManager.glGenVertexArrays();
vbo = GLStateManager.glGenBuffers();
ebo = GLStateManager.glGenBuffers();
GLStateManager.glBindVertexArray(vao);
GLStateManager.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
for (int corner = 0; corner < 4; corner++) {
instanced(corner, 4, corner * 4);
}
final IntBuffer indices = BufferUtils.createIntBuffer(6);
indices.put(0).put(1).put(2).put(0).put(2).put(3).flip();
GLStateManager.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ebo);
GLStateManager.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW);
}
static final class Frame {
final Matrix4f modelViewProjection = new Matrix4f();
final Matrix4f modelView = new Matrix4f();
private final Matrix4f[] layerBase = new Matrix4f[3 * LAYERS];
private final FloatBuffer rowS = BufferUtils.createFloatBuffer(3 * LAYERS * 3);
private final FloatBuffer rowT = BufferUtils.createFloatBuffer(3 * LAYERS * 3);
private final FloatBuffer eyePlane = BufferUtils.createFloatBuffer(3 * 3);
private final Matrix4f translated = new Matrix4f();
private final Matrix4f texGenModelView = new Matrix4f();
private final Matrix4f inverse = new Matrix4f();
private final Vector4f lightmapCoord = new Vector4f();
private final Matrix4f preparedModelView = new Matrix4f();
float cameraX, cameraY, cameraZ;
float viewX, viewY, viewZ;
float time;
float lightmapU, lightmapV;
boolean lightmapEnabled;
private int[] planeAxis = new int[16];
private boolean[] planeNegative = new boolean[16];
private double[] planeValue = new double[16];
private float[] planeData = new float[16 * FLOATS_PER_PLANE];
private int planeCount;
private int version;
private float preparedCameraX, preparedCameraY, preparedCameraZ, preparedViewX, preparedViewY, preparedViewZ, preparedTime;
Frame() {
for (int i = 0; i < layerBase.length; i++) layerBase[i] = new Matrix4f();
}
void prepareLayers() {
if (version != 0 && preparedCameraX == cameraX && preparedCameraY == cameraY && preparedCameraZ == cameraZ && preparedViewX == viewX && preparedViewY == viewY && preparedViewZ == viewZ && preparedTime == time && preparedModelView.equals(modelView))
return;
preparedCameraX = cameraX;
preparedCameraY = cameraY;
preparedCameraZ = cameraZ;
preparedViewX = viewX;
preparedViewY = viewY;
preparedViewZ = viewZ;
preparedTime = time;
preparedModelView.set(modelView);
version++;
planeCount = 0;
for (int axis = 0; axis < 3; axis++) {
final float cameraS = axis == AXIS_X ? cameraZ : cameraX;
final float cameraT = axis == AXIS_Y ? cameraZ : cameraY;
final float cameraAxis = axis == AXIS_X ? cameraX : axis == AXIS_Y ? cameraY : cameraZ;
for (int i = 0; i < LAYERS; i++) {
final float scale = LAYER_SCALE[i];
final Matrix4f base = layerBase[axis * LAYERS + i].identity().translate(0.0F, time, 0.0F).scale(scale, scale, scale).translate(0.5F, 0.5F, 0.0F).rotate(LAYER_ANGLE[i], 0.0F, 0.0F, 1.0F).translate(-0.5F, -0.5F, 0.0F).translate(-cameraS, -cameraT, -cameraAxis);
final int row = (axis * LAYERS + i) * 3;
rowS.put(row, base.m00()).put(row + 1, base.m10()).put(row + 2, base.m20());
rowT.put(row, base.m01()).put(row + 1, base.m11()).put(row + 2, base.m21());
}
}
texGenModelView.set(modelView).translate(cameraX, cameraY, cameraZ).invert(inverse);
eyePlane.put(0, inverse.m00()).put(1, inverse.m10()).put(2, inverse.m20());
eyePlane.put(3, inverse.m01()).put(4, inverse.m11()).put(5, inverse.m21());
eyePlane.put(6, inverse.m02()).put(7, inverse.m12()).put(8, inverse.m22());
}
void readLightmap(int blockLight) {
final TextureUnitArray textures = GLStateManager.getTextures();
lightmapEnabled = textures.getTextureUnitStates(LIGHTMAP_UNIT).isEnabled() && textures.getTextureUnitBindings(LIGHTMAP_UNIT).getBinding() != 0;
textures.getTextureUnitMatrix(LIGHTMAP_UNIT).transform(lightmapCoord.set(blockLight, 0.0F, 0.0F, 1.0F));
lightmapU = lightmapCoord.x / lightmapCoord.w;
lightmapV = lightmapCoord.y / lightmapCoord.w;
}
int plane(int axis, boolean negative, double plane) {
for (int p = 0; p < planeCount; p++) {
if (planeAxis[p] == axis && planeNegative[p] == negative && planeValue[p] == plane) return p;
}
if (planeCount == maxPlanes()) return -1;
if (planeCount == planeAxis.length) {
planeAxis = Arrays.copyOf(planeAxis, planeCount * 2);
planeNegative = Arrays.copyOf(planeNegative, planeCount * 2);
planeValue = Arrays.copyOf(planeValue, planeCount * 2);
planeData = Arrays.copyOf(planeData, planeCount * 2 * FLOATS_PER_PLANE);
}
final int p = planeCount++;
planeAxis[p] = axis;
planeNegative[p] = negative;
planeValue[p] = plane;
final float viewS = axis == AXIS_X ? viewZ : viewX;
final float viewT = axis == AXIS_Y ? viewZ : viewY;
final float viewAxis = axis == AXIS_X ? viewX : axis == AXIS_Y ? viewY : viewZ;
final float cameraAxis = axis == AXIS_X ? cameraX : axis == AXIS_Y ? cameraY : cameraZ;
// TC's drawPlane* arithmetic, in its float order
final float f8 = (float) (negative ? -plane : plane);
final float f9 = negative ? f8 + viewAxis : f8 - viewAxis;
final int base = p * FLOATS_PER_PLANE;
for (int layer = 0; layer < LAYERS; layer++) {
final float f5 = LAYER_DEPTH[layer];
layerBase[axis * LAYERS + layer].translate(viewS * f5 / f9, viewT * f5 / f9, -cameraAxis, translated);
planeData[base + layer * 2] = translated.m30();
planeData[base + layer * 2 + 1] = translated.m31();
final float f10 = negative ? f8 + f5 + viewAxis : f8 + f5 - viewAxis;
float f11 = f9 / f10;
f11 += (float) plane;
// glTexGen stores the Q plane through the inverse of the modelview TC translated just before
texGenModelView.set(modelView).translate(axis == AXIS_X ? f11 : cameraX, axis == AXIS_Y ? f11 : cameraY, axis == AXIS_X || axis == AXIS_Y ? cameraZ : f11).invert(inverse);
planeData[base + LAYERS * 2 + layer] = axis == AXIS_X ? inverse.m30() : axis == AXIS_Y ? inverse.m31() : inverse.m32();
}
return p;
}
void clearPlanes() {
planeCount = 0;
version++;
}
}
private static final class Uniforms {
final GlUniformMatrix4f modelViewProjection;
final GlUniformMatrix4f modelView;
final GlUniformFloat3Array eyePlane;
final GlUniformFloat3Array rowS;
final GlUniformFloat3Array rowT;
final GlUniformFloat4Array planes;
final GlUniformFloat2v lightmapUv;
final GlUniformFloat lightmapEnabled;
final GlUniformFloat atlasSize;
final GlUniformFloat4v fogParams;
final GlUniformFloat3v fogColor;
final GlUniformInt fogMode;
final GlUniformInt fogDistanceMode;
Frame uploadedFrame;
int uploadedVersion;
int uploadedPlanes;
Uniforms(ShaderBindingContext context) {
modelViewProjection = context.bindUniformIfPresent("u_ModelViewProjection", GlUniformMatrix4f::new);
modelView = context.bindUniform("u_ModelView", GlUniformMatrix4f::new);
eyePlane = context.bindUniform("u_EyePlane", GlUniformFloat3Array::new);
rowS = context.bindUniform("u_RowS", GlUniformFloat3Array::new);
rowT = context.bindUniform("u_RowT", GlUniformFloat3Array::new);
planes = context.bindUniform("u_Planes", GlUniformFloat4Array::new);
lightmapUv = context.bindUniform("u_LightmapUv", GlUniformFloat2v::new);
lightmapEnabled = context.bindUniform("u_LightmapEnabled", GlUniformFloat::new);
atlasSize = context.bindUniformIfPresent("u_AtlasSize", GlUniformFloat::new);
fogParams = context.bindUniformIfPresent("u_FogParams", GlUniformFloat4v::new);
fogColor = context.bindUniformIfPresent("u_FogColor", GlUniformFloat3v::new);
fogMode = context.bindUniformIfPresent("u_FogMode", GlUniformInt::new);
fogDistanceMode = context.bindUniformIfPresent("u_FogDistanceMode", GlUniformInt::new);
}
}
}
@@ -0,0 +1,113 @@
package com.gtnewhorizons.angelica.compat.thaumcraft;
import net.minecraft.block.Block;
import net.minecraft.world.IBlockAccess;
import thaumcraft.common.config.ConfigBlocks;
import static com.gtnewhorizons.angelica.compat.thaumcraft.PortalRenderer.AXIS_X;
import static com.gtnewhorizons.angelica.compat.thaumcraft.PortalRenderer.AXIS_Y;
import static com.gtnewhorizons.angelica.compat.thaumcraft.PortalRenderer.AXIS_Z;
/**
* Which of a portable hole's or eldritch nothing's six planes TC draws, and where.
*/
public final class PortalFaces {
public static final int NOT_BUILT = -1;
private static final int UP = 1;
private static final int DOWN = 2;
private static final int NORTH = 4;
private static final int SOUTH = 8;
private static final int WEST = 16;
private static final int EAST = 32;
private static final float HOLE_NEAR = 0.001F;
private static final float HOLE_FAR = 0.999F;
private static final float HOLE_FAR_GRAY = 0.5F;
private static final float NOTHING_FAR_GRAY = 1.0F;
private PortalFaces() {
}
public static int holeMask(IBlockAccess world, int x, int y, int z) {
int mask = 0;
if (isHoleWall(world.getBlock(x, y + 1, z))) mask |= UP;
if (isHoleWall(world.getBlock(x, y - 1, z))) mask |= DOWN;
if (isHoleWall(world.getBlock(x, y, z - 1))) mask |= NORTH;
if (isHoleWall(world.getBlock(x, y, z + 1))) mask |= SOUTH;
if (isHoleWall(world.getBlock(x - 1, y, z))) mask |= WEST;
if (isHoleWall(world.getBlock(x + 1, y, z))) mask |= EAST;
return mask;
}
public static int nothingMask(IBlockAccess world, int x, int y, int z) {
int mask = 0;
if (!world.getBlock(x, y + 1, z).isOpaqueCube()) mask |= UP;
if (!world.getBlock(x, y - 1, z).isOpaqueCube()) mask |= DOWN;
if (!world.getBlock(x, y, z - 1).isOpaqueCube()) mask |= NORTH;
if (!world.getBlock(x, y, z + 1).isOpaqueCube()) mask |= SOUTH;
if (!world.getBlock(x - 1, y, z).isOpaqueCube()) mask |= WEST;
if (!world.getBlock(x + 1, y, z).isOpaqueCube()) mask |= EAST;
return mask;
}
private static boolean isHoleWall(Block block) {
return block.isOpaqueCube() && block != ConfigBlocks.blockHole;
}
public static void addHoleFaces(int mask, boolean layered, double x, double y, double z) {
if ((mask & UP) != 0) {
final double plane = y + HOLE_FAR;
face(layered, HOLE_FAR_GRAY, AXIS_Y, false, plane, x, plane, z + 1.0, x, plane, z, x + 1.0, plane, z + 1.0);
}
if ((mask & DOWN) != 0) {
final double plane = y + HOLE_NEAR;
face(layered, HOLE_FAR_GRAY, AXIS_Y, true, plane, x, plane, z, x, plane, z + 1.0, x + 1.0, plane, z);
}
if ((mask & NORTH) != 0) {
final double plane = z + HOLE_NEAR;
face(layered, HOLE_FAR_GRAY, AXIS_Z, true, plane, x, y + 1.0, plane, x, y, plane, x + 1.0, y + 1.0, plane);
}
if ((mask & SOUTH) != 0) {
final double plane = z + HOLE_FAR;
face(layered, HOLE_FAR_GRAY, AXIS_Z, false, plane, x, y, plane, x, y + 1.0, plane, x + 1.0, y, plane);
}
if ((mask & WEST) != 0) {
final double plane = x + HOLE_NEAR;
face(layered, HOLE_FAR_GRAY, AXIS_X, true, plane, plane, y + 1.0, z, plane, y + 1.0, z + 1.0, plane, y, z);
}
if ((mask & EAST) != 0) {
final double plane = x + HOLE_FAR;
face(layered, HOLE_FAR_GRAY, AXIS_X, false, plane, plane, y, z, plane, y, z + 1.0, plane, y + 1.0, z);
}
}
public static void addNothingFaces(int mask, boolean layered, double x, double y, double z) {
if ((mask & UP) != 0) {
face(layered, NOTHING_FAR_GRAY, AXIS_Y, true, y + 1.0, x, y + 1.0, z, x, y + 1.0, z + 1.0, x + 1.0, y + 1.0, z);
}
if ((mask & DOWN) != 0) {
face(layered, NOTHING_FAR_GRAY, AXIS_Y, false, y, x, y, z + 1.0, x, y, z, x + 1.0, y, z + 1.0);
}
if ((mask & NORTH) != 0) {
face(layered, NOTHING_FAR_GRAY, AXIS_Z, false, z, x, y, z, x, y + 1.0, z, x + 1.0, y, z);
}
if ((mask & SOUTH) != 0) {
face(layered, NOTHING_FAR_GRAY, AXIS_Z, true, z + 1.0, x, y + 1.0, z + 1.0, x, y, z + 1.0, x + 1.0, y + 1.0, z + 1.0);
}
if ((mask & WEST) != 0) {
face(layered, NOTHING_FAR_GRAY, AXIS_X, false, x, x, y, z, x, y, z + 1.0, x, y + 1.0, z);
}
if ((mask & EAST) != 0) {
face(layered, NOTHING_FAR_GRAY, AXIS_X, true, x + 1.0, x + 1.0, y + 1.0, z, x + 1.0, y + 1.0, z + 1.0, x + 1.0, y, z);
}
}
private static void face(boolean layered, float farGray, int axis, boolean negative, double plane, double x0, double y0, double z0, double x1, double y1, double z1, double x3, double y3, double z3) {
if (layered) {
PortalRenderer.addFace(false, axis, negative, plane, x0, y0, z0, x1, y1, z1, x3, y3, z3);
} else {
PortalRenderer.addFarFace(axis, farGray, x0, y0, z0, x1, y1, z1, x3, y3, z3);
}
}
}
@@ -0,0 +1,467 @@
package com.gtnewhorizons.angelica.compat.thaumcraft;
import com.gtnewhorizons.angelica.glsm.DisplayListManager;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import com.gtnewhorizons.angelica.glsm.StateSet;
import com.gtnewhorizons.angelica.glsm.hooks.BatchStateGuard;
import com.gtnewhorizons.angelica.glsm.profiling.Tracy;
import com.gtnewhorizons.angelica.glsm.states.ViewportState;
import com.gtnewhorizons.angelica.rendering.tesr.PendingTesrDraws;
import com.gtnewhorizons.angelica.rendering.tesr.TesrProviderDispatch;
import net.coderbot.iris.Iris;
import net.coderbot.iris.pipeline.DeferredWorldRenderingPipeline;
import net.coderbot.iris.pipeline.ShadowRenderer;
import net.coderbot.iris.uniforms.CapturedRenderingState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.joml.Matrix4f;
import org.joml.Matrix4fc;
import org.joml.Vector4f;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL30;
import thaumcraft.common.tiles.TileEldritchLock;
import thaumcraft.common.tiles.TileEldritchNothing;
import thaumcraft.common.tiles.TileHole;
import java.util.Arrays;
/**
* Draws Thaumcraft's end-portal-style planes (eldritch obelisk, nothing, lock, portable hole, mirror) in one pass.
*/
public final class PortalRenderer implements PendingTesrDraws.Pending {
public static final int AXIS_X = 0;
public static final int AXIS_Y = 1;
public static final int AXIS_Z = 2;
private static final ResourceLocation TUNNEL = new ResourceLocation("thaumcraft", "textures/misc/tunnel.png");
private static final ResourceLocation FIELD = new ResourceLocation("thaumcraft", "textures/misc/particlefield.png");
private static final ResourceLocation FAR_FIELD = new ResourceLocation("thaumcraft", "textures/misc/particlefield32.png");
private static final int FULL_BRIGHT = 240 | (240 << 16);
private static final int TC_BRIGHTNESS = 180;
private static final double LAYERED_RANGE_SQUARED = 512.0D;
private static final Matrix4fc IDENTITY = new Matrix4f();
private static final Tracy.ZoneId Z_FLUSH = Tracy.zoneId("thaumcraftPortals", Tracy.COLOR_CLIENT);
private static final int MODE_DIRECT = 0;
private static final int MODE_CAPTURE = 1;
private static final int MODE_SHADOW = 2;
private static final PortalRenderer INSTANCE = new PortalRenderer();
private static final PortalDrawer drawer = new PortalDrawer();
private static final PortalDrawer.Frame frame = new PortalDrawer.Frame();
private static final Matrix4f modelViewProjection = new Matrix4f();
private static final Matrix4f savedTextureMatrix = new Matrix4f();
private static final Vector4f projected = new Vector4f();
private static final float[] screenX = new float[4];
private static final float[] screenY = new float[4];
private static float[] faces = new float[PortalDrawer.FLOATS_PER_FACE * 64];
private static int[] faceBlockEntity = new int[64];
private static int faceCount;
private static float[] farFaces = new float[PortalDrawer.FLOATS_PER_FACE * 64];
private static float[] farGray = new float[64];
private static int[] farBlockEntity = new int[64];
private static int farCount;
private static int batchMode;
private static boolean batchFogged;
private static int batchModelViewGeneration;
private static int batchProjectionGeneration;
private static boolean skippedPlaneState;
private static int lastPlaneTexture;
private static int tunnelTexture;
private static int fieldTexture;
private static int farTexture;
private PortalRenderer() {
}
public static boolean replacesLayers() {
return !DisplayListManager.isRecording();
}
public static boolean inLayeredRange(TileEntity te) {
return Minecraft.getMinecraft().renderViewEntity.getDistanceSq(te.xCoord + 0.5D, te.yCoord + 0.5D, te.zCoord + 0.5D) < LAYERED_RANGE_SQUARED;
}
public static void addFace(int axis, boolean negative, double plane, double x0, double y0, double z0, double x1, double y1, double z1, double x3, double y3, double z3) {
addFace(GLStateManager.getFogMode().isEnabled(), axis, negative, plane, x0, y0, z0, x1, y1, z1, x3, y3, z3);
}
static void addFace(boolean fogged, int axis, boolean negative, double plane, double x0, double y0, double z0, double x1, double y1, double z1, double x3, double y3, double z3) {
prepareBatch(fogged);
int planeIndex = 0;
if (batchMode != MODE_SHADOW) {
planeIndex = frame.plane(axis, negative, plane);
if (planeIndex < 0) {
flushFaces();
frame.clearPlanes();
planeIndex = frame.plane(axis, negative, plane);
}
}
putLayeredFace(axis, planeIndex, x0, y0, z0, x1, y1, z1, x3, y3, z3);
lastPlaneTexture = fieldTexture;
}
static void addFarFace(int axis, float gray, double x0, double y0, double z0, double x1, double y1, double z1, double x3, double y3, double z3) {
prepareBatch(false);
lastPlaneTexture = farTexture;
if (batchMode == MODE_SHADOW) {
putLayeredFace(axis, 0, x0, y0, z0, x1, y1, z1, x3, y3, z3);
return;
}
if (farCount == farBlockEntity.length) {
farFaces = Arrays.copyOf(farFaces, farFaces.length * 2);
farGray = Arrays.copyOf(farGray, farGray.length * 2);
farBlockEntity = Arrays.copyOf(farBlockEntity, farBlockEntity.length * 2);
}
PortalDrawer.putFace(farFaces, farCount, axis, 0, x0, y0, z0, x1, y1, z1, x3, y3, z3);
farGray[farCount] = gray;
farBlockEntity[farCount] = CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity();
farCount++;
skippedPlaneState = true;
}
public static void drawBuilt(TileEntity te, boolean hole, int mask, double x, double y, double z) {
PendingTesrDraws.beforeTileEntity(te);
if (mask == 0) return;
final CapturedRenderingState rendering = CapturedRenderingState.INSTANCE;
rendering.pushCurrentBlockEntity();
try {
rendering.setCurrentBlockEntity(te.getBlockType(), TesrProviderDispatch.blockMetadata(te));
if (hole) {
PortalFaces.addHoleFaces(mask, inLayeredRange(te), x, y, z);
} else {
PortalFaces.addNothingFaces(mask, inLayeredRange(te), x, y, z);
}
} finally {
rendering.popCurrentBlockEntity();
}
skippedPlaneState = false;
if (PendingTesrDraws.canDefer()) {
PendingTesrDraws.hold(INSTANCE);
} else {
flushFaces();
}
}
public static void endSkippedRender() {
if (!GLStateManager.glIsEnabled(GL11.GL_FOG)) GLStateManager.glEnable(GL11.GL_FOG);
}
private static void prepareBatch(boolean fogged) {
if ((faceCount > 0 || farCount > 0) && fogged != batchFogged) flushFaces();
batchFogged = fogged;
final int modelViewGeneration = GLStateManager.getMvGeneration();
final int projectionGeneration = GLStateManager.getProjGeneration();
final boolean empty = faceCount == 0 && farCount == 0;
if (empty || modelViewGeneration != batchModelViewGeneration || projectionGeneration != batchProjectionGeneration) {
final int mode = currentMode();
GLStateManager.getProjectionMatrix().mul(GLStateManager.getModelViewMatrix(), modelViewProjection);
if (!empty && (mode != batchMode || !modelViewProjection.equals(frame.modelViewProjection))) flushFaces();
if (faceCount == 0 && farCount == 0) startBatch(mode);
batchModelViewGeneration = modelViewGeneration;
batchProjectionGeneration = projectionGeneration;
}
}
private static void putLayeredFace(int axis, int planeIndex, double x0, double y0, double z0, double x1, double y1, double z1, double x3, double y3, double z3) {
if (faceCount == faceBlockEntity.length) {
faces = Arrays.copyOf(faces, faces.length * 2);
faceBlockEntity = Arrays.copyOf(faceBlockEntity, faceBlockEntity.length * 2);
}
PortalDrawer.putFace(faces, faceCount, axis, planeIndex, x0, y0, z0, x1, y1, z1, x3, y3, z3);
faceBlockEntity[faceCount] = CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity();
faceCount++;
skippedPlaneState = true;
}
private static void restoreSkippedPlaneState() {
if (!skippedPlaneState) return;
skippedPlaneState = false;
if (GLStateManager.glIsEnabled(GL11.GL_BLEND)) GLStateManager.disableBlend();
if (GLStateManager.glIsEnabled(GL11.GL_TEXTURE_GEN_S)) GLStateManager.glDisable(GL11.GL_TEXTURE_GEN_S);
if (GLStateManager.glIsEnabled(GL11.GL_TEXTURE_GEN_T)) GLStateManager.glDisable(GL11.GL_TEXTURE_GEN_T);
if (GLStateManager.glIsEnabled(GL11.GL_TEXTURE_GEN_R)) GLStateManager.glDisable(GL11.GL_TEXTURE_GEN_R);
if (GLStateManager.glIsEnabled(GL11.GL_TEXTURE_GEN_Q)) GLStateManager.glDisable(GL11.GL_TEXTURE_GEN_Q);
if (!GLStateManager.glIsEnabled(GL11.GL_LIGHTING)) GLStateManager.enableLighting();
if (GLStateManager.getTextures().getTextureUnitBindings(GLStateManager.getActiveTextureUnit()).getBinding() != lastPlaneTexture) {
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, lastPlaneTexture);
}
}
public static void drawBeforeOverlay() {
restoreSkippedPlaneState();
flushFaces();
}
public static void endTileEntity(boolean canWait) {
restoreSkippedPlaneState();
if (faceCount == 0 && farCount == 0) return;
if (canWait && PendingTesrDraws.canDefer()) {
PendingTesrDraws.hold(INSTANCE);
} else {
flushFaces();
}
}
private static void flushFaces() {
if (faceCount == 0 && farCount == 0) return;
if (Tracy.ENABLED) Tracy.beginZone(Z_FLUSH);
try {
if (faceCount > 0) {
switch (batchMode) {
case MODE_CAPTURE -> captureAndComposite(tunnelTexture, fieldTexture);
case MODE_SHADOW -> drawQuads(tunnelTexture, 0, faceCount, false);
default -> drawer.drawDirect(faces, faceCount, tunnelTexture, fieldTexture, frame, batchFogged);
}
}
if (farCount > 0) drawFarFaces();
} finally {
faceCount = 0;
farCount = 0;
if (Tracy.ENABLED) Tracy.endZone();
}
}
private static int currentMode() {
if (ShadowRenderer.ACTIVE) return MODE_SHADOW;
return capturingPipeline() != null ? MODE_CAPTURE : MODE_DIRECT;
}
private static DeferredWorldRenderingPipeline capturingPipeline() {
if (!Iris.enabled) return null;
return Iris.getPipelineManager().getPipelineNullable() instanceof DeferredWorldRenderingPipeline pipeline && pipeline.shouldOverrideShaders() ? pipeline : null;
}
private static void startBatch(int mode) {
batchMode = mode;
tunnelTexture = textureId(TUNNEL);
fieldTexture = textureId(FIELD);
farTexture = textureId(FAR_FIELD);
frame.modelViewProjection.set(modelViewProjection);
if (mode == MODE_SHADOW) return;
frame.modelView.set(GLStateManager.getModelViewMatrix());
frame.cameraX = (float) TileEntityRendererDispatcher.staticPlayerX;
frame.cameraY = (float) TileEntityRendererDispatcher.staticPlayerY;
frame.cameraZ = (float) TileEntityRendererDispatcher.staticPlayerZ;
frame.viewX = ActiveRenderInfo.objectX;
frame.viewY = ActiveRenderInfo.objectY;
frame.viewZ = ActiveRenderInfo.objectZ;
frame.time = (float) (System.currentTimeMillis() % 700000L) / 250000.0F;
frame.prepareLayers();
frame.readLightmap(TC_BRIGHTNESS);
}
private static void captureAndComposite(int tunnel, int field) {
final DeferredWorldRenderingPipeline pipeline = capturingPipeline();
if (pipeline == null) {
drawer.drawDirect(faces, faceCount, tunnel, field, frame, batchFogged);
return;
}
final ViewportState viewport = GLStateManager.getViewportState();
int first = 0, x = 0, y = 0, rowHeight = 0;
for (int face = 0; face < faceCount; face++) {
final int size = slotSize(face, viewport.width, viewport.height);
if (x + size > PortalDrawer.ATLAS_SIZE) {
x = 0;
y += rowHeight;
rowHeight = 0;
}
if (y + size > PortalDrawer.ATLAS_SIZE) {
capture(pipeline, first, face - first, tunnel, field);
drawQuads(drawer.atlasTexture(), first, face - first, true);
first = face;
x = y = rowHeight = 0;
}
final int i = face * PortalDrawer.FLOATS_PER_FACE;
faces[i + 7] = x;
faces[i + 11] = y;
faces[i + 15] = size;
x += size;
rowHeight = Math.max(rowHeight, size);
}
capture(pipeline, first, faceCount - first, tunnel, field);
drawQuads(drawer.atlasTexture(), first, faceCount - first, true);
}
private static int slotSize(int face, int viewportWidth, int viewportHeight) {
final int i = face * PortalDrawer.FLOATS_PER_FACE;
float largest = 0.0F;
for (int corner = 0; corner < 4; corner++) {
final int c = i + corner * 4;
frame.modelViewProjection.transform(projected.set(faces[c], faces[c + 1], faces[c + 2], 1.0F));
if (projected.w <= 1.0E-4F) return PortalDrawer.MAX_SLOT;
screenX[corner] = projected.x / projected.w * 0.5F * viewportWidth;
screenY[corner] = projected.y / projected.w * 0.5F * viewportHeight;
}
for (int corner = 0; corner < 4; corner++) {
final int next = (corner + 1) & 3;
largest = Math.max(largest, Math.max(Math.abs(screenX[next] - screenX[corner]), Math.abs(screenY[next] - screenY[corner])));
}
final int pixels = (int) Math.ceil(largest);
final int size = pixels <= 1 ? 1 : Integer.highestOneBit(pixels - 1) << 1;
return Math.clamp(size, PortalDrawer.MIN_SLOT, PortalDrawer.MAX_SLOT);
}
private static void capture(DeferredWorldRenderingPipeline pipeline, int first, int count, int tunnel, int field) {
BatchStateGuard.beforeChange();
final int drawFramebuffer = GLStateManager.getDrawFramebuffer();
final int readFramebuffer = GLStateManager.getReadFramebuffer();
pipeline.setIsMainBound(false);
final int depth = GLStateManager.pushState(StateSet.forMask(GL11.GL_VIEWPORT_BIT | GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT));
try {
drawer.atlasFramebuffer().bind();
GLStateManager.glViewport(0, 0, PortalDrawer.ATLAS_SIZE, PortalDrawer.ATLAS_SIZE);
GLStateManager.disableDepthTest();
GLStateManager.disableCull();
GLStateManager.glDisable(GL11.GL_SCISSOR_TEST);
GLStateManager.glDisable(GL11.GL_STENCIL_TEST);
GLStateManager.glColorMask(true, true, true, true);
drawer.drawCapture(faces, first, count, tunnel, field, frame);
} finally {
GLStateManager.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, drawFramebuffer);
GLStateManager.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, readFramebuffer);
GLStateManager.popStateTo(depth);
pipeline.setIsMainBound(true);
pipeline.rebindCurrentPass();
}
}
private static void drawQuads(int texture, int first, int count, boolean fromAtlas) {
final int depth = GLStateManager.pushState(StateSet.forMask(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_CURRENT_BIT | GL11.GL_TEXTURE_BIT));
savedTextureMatrix.set(GLStateManager.getTextures().getTextureUnitMatrix(0));
CapturedRenderingState.INSTANCE.pushCurrentBlockEntity();
try {
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
GLStateManager.enableTexture();
GLStateManager.disableLighting();
GLStateManager.disableBlend();
if (!batchFogged) disableFogUntilPop();
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, texture);
GLStateManager.setTextureMatrix(0, IDENTITY);
final Tessellator tess = Tessellator.instance;
final float texel = 1.0F / PortalDrawer.ATLAS_SIZE;
int runStart = first;
while (runStart < first + count) {
final int blockEntity = faceBlockEntity[runStart];
CapturedRenderingState.INSTANCE.setCurrentBlockEntity(blockEntity);
tess.startDrawingQuads();
tess.setColorOpaque_F(1, 1, 1);
tess.setBrightness(FULL_BRIGHT);
int face = runStart;
for (; face < first + count && faceBlockEntity[face] == blockEntity; face++) {
if (fromAtlas) {
final int i = face * PortalDrawer.FLOATS_PER_FACE;
final float x = faces[i + 7], y = faces[i + 11], size = faces[i + 15];
addQuad(tess, face, (x + 0.5F) * texel, (y + 0.5F) * texel, (x + size - 0.5F) * texel, (y + size - 0.5F) * texel);
} else {
addQuad(tess, face, 0.0F, 0.0F, 1.0F, 1.0F);
}
}
tess.draw();
runStart = face;
}
if (fromAtlas) BatchStateGuard.beforeChange();
} finally {
CapturedRenderingState.INSTANCE.popCurrentBlockEntity();
GLStateManager.setTextureMatrix(0, savedTextureMatrix);
popStateTo(depth);
}
}
private static void drawFarFaces() {
final int depth = GLStateManager.pushState(StateSet.forMask(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_CURRENT_BIT | GL11.GL_TEXTURE_BIT));
CapturedRenderingState.INSTANCE.pushCurrentBlockEntity();
try {
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
GLStateManager.enableTexture();
GLStateManager.disableLighting();
GLStateManager.disableBlend();
disableFogUntilPop();
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, farTexture);
final Tessellator tess = Tessellator.instance;
final float[] f = farFaces;
int runStart = 0;
while (runStart < farCount) {
final int blockEntity = farBlockEntity[runStart];
CapturedRenderingState.INSTANCE.setCurrentBlockEntity(blockEntity);
tess.startDrawingQuads();
tess.setBrightness(TC_BRIGHTNESS);
int face = runStart;
for (; face < farCount && farBlockEntity[face] == blockEntity; face++) {
final int i = face * PortalDrawer.FLOATS_PER_FACE;
tess.setColorRGBA_F(farGray[face], farGray[face], farGray[face], 1.0F);
tess.addVertexWithUV(f[i], f[i + 1], f[i + 2], 1.0D, 1.0D);
tess.addVertexWithUV(f[i + 4], f[i + 5], f[i + 6], 1.0D, 0.0D);
tess.addVertexWithUV(f[i + 8], f[i + 9], f[i + 10], 0.0D, 0.0D);
tess.addVertexWithUV(f[i + 12], f[i + 13], f[i + 14], 0.0D, 1.0D);
}
tess.draw();
runStart = face;
}
} finally {
CapturedRenderingState.INSTANCE.popCurrentBlockEntity();
popStateTo(depth);
}
}
private static void disableFogUntilPop() {
BatchStateGuard.suspend();
try {
GLStateManager.glDisable(GL11.GL_FOG);
} finally {
BatchStateGuard.resume();
}
}
private static void popStateTo(int depth) {
BatchStateGuard.suspend();
try {
GLStateManager.popStateTo(depth);
} finally {
BatchStateGuard.resume();
}
}
private static void addQuad(Tessellator tess, int face, float u0, float v0, float u1, float v1) {
final float[] f = faces;
final int i = face * PortalDrawer.FLOATS_PER_FACE;
final float ax = f[i + 4] - f[i], ay = f[i + 5] - f[i + 1], az = f[i + 6] - f[i + 2];
final float bx = f[i + 12] - f[i], by = f[i + 13] - f[i + 1], bz = f[i + 14] - f[i + 2];
final float nx = ay * bz - az * by, ny = az * bx - ax * bz, nz = ax * by - ay * bx;
final float length = (float) Math.sqrt(nx * nx + ny * ny + nz * nz);
tess.setNormal(nx / length, ny / length, nz / length);
tess.addVertexWithUV(f[i], f[i + 1], f[i + 2], u0, v0);
tess.addVertexWithUV(f[i + 4], f[i + 5], f[i + 6], u1, v0);
tess.addVertexWithUV(f[i + 8], f[i + 9], f[i + 10], u1, v1);
tess.addVertexWithUV(f[i + 12], f[i + 13], f[i + 14], u0, v1);
}
private static int textureId(ResourceLocation location) {
final TextureManager textures = Minecraft.getMinecraft().getTextureManager();
ITextureObject texture = textures.getTexture(location);
if (texture == null) {
texture = new SimpleTexture(location);
textures.loadTexture(location, texture);
}
return texture.getGlTextureId();
}
@Override
public boolean canWaitFor(TileEntity next) {
return next instanceof TileEldritchNothing || next instanceof TileHole || next instanceof TileEldritchLock;
}
@Override
public void flush() {
flushFaces();
}
}
@@ -35,8 +35,8 @@ public class ChunkRebuildManager {
final long packed = CoordinatePacker.pack(x, y, z);
lock.writeLock().lock();
try {
// Reset wait counter if already pending, otherwise add new entry
pendingRebuilds.put(packed, 0);
// An already pending section keeps its wait count
pendingRebuilds.putIfAbsent(packed, 0);
} finally {
lock.writeLock().unlock();
}
@@ -125,11 +125,8 @@ public class ChunkRebuildManager {
int blockY = chunkY << 4;
int blockZ = chunkZ << 4;
// Check if the 16x16x16 chunk section box is visible
return viewport.isBoxVisible(
blockX, blockY, blockZ,
blockX + 16, blockY + 16, blockZ + 16
);
// The integer-origin overload takes a center and half-size, not min/max corners.
return viewport.isBoxVisible(blockX + 8, blockY + 8, blockZ + 8, 8.0f);
}
public void clear() {
@@ -20,6 +20,9 @@ import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
/**
* Records Java-side rendering scopes alongside cached geometry.
*/
@@ -28,24 +31,36 @@ public final class IrisDisplayListState {
private IrisDisplayListState() {}
public static void runProgramTransition(Runnable transition) {
runProgramTransition((run, unused) -> run.run(), transition, null);
}
public static <T> void runProgramTransition(Consumer<T> transition, T argument) {
runProgramTransition(Consumer::accept, transition, argument);
}
public static <A, B> void runProgramTransition(BiConsumer<A, B> transition, A first, B second) {
BatchStateGuard.suspend();
try {
runUnrecorded(transition);
runUnrecorded(transition, first, second);
} finally {
BatchStateGuard.resume();
}
}
public static void runUnrecorded(Runnable transition) {
runUnrecorded((run, unused) -> run.run(), transition, null);
}
private static <A, B> void runUnrecorded(BiConsumer<A, B> transition, A first, B second) {
final DisplayListManager.RecordMode mode = DisplayListManager.getRecordMode();
if (mode == DisplayListManager.RecordMode.COMPILE) return;
if (mode == DisplayListManager.RecordMode.NONE) {
transition.run();
transition.accept(first, second);
return;
}
final CommandRecorder recorder = DisplayListManager.pauseRecording();
try {
transition.run();
transition.accept(first, second);
} finally {
DisplayListManager.resumeRecording(recorder);
}
@@ -7,6 +7,7 @@ import com.gtnewhorizons.angelica.glsm.hooks.DeferredBlendHandler;
import com.gtnewhorizons.angelica.glsm.hooks.DeferredDepthColorHandler;
import com.gtnewhorizons.angelica.glsm.hooks.GLSMConfig;
import com.gtnewhorizons.angelica.glsm.hooks.GLSMHooks;
import com.gtnewhorizons.angelica.glsm.hooks.LineDrawHandler;
import com.gtnewhorizons.angelica.glsm.hooks.ShaderTransformPostProcessor;
import com.gtnewhorizons.angelica.glsm.shader.ShaderType;
import org.taumc.glsl.grammar.GLSLParser;
@@ -103,6 +104,24 @@ public class IrisGLSMBridge {
GLSMConfig.expandVertexFormats = Iris.enabled;
IrisSamplers.initRenderer();
installPostTransformHook();
GLSMHooks.lineDrawHandler = new LineDrawHandler() {
private DeferredWorldRenderingPipeline linePipeline;
@Override
public boolean bindLineProgram() {
if (!Iris.enabled || !(Iris.getPipelineManager().getPipelineNullable() instanceof DeferredWorldRenderingPipeline drp) || !drp.bindLineProgram()) {
return false;
}
linePipeline = drp;
return true;
}
@Override
public void restoreProgram() {
linePipeline.restoreAfterLines();
linePipeline = null;
}
};
GLSMHooks.blendHandler = new DeferredBlendHandler() {
@Override
public boolean isBlendLocked() {
@@ -229,6 +229,20 @@ public enum Mixins implements IMixins {
.addClientMixins("client.thaumcraft.MixinItemThaumometerRenderer")
),
THAUMCRAFT_PORTALS(new MixinBuilder("Draw Thaumcraft's end portal styled planes in a more optimized way, and make it work with shaderpacks")
.setPhase(Phase.LATE)
.addRequiredMod(TargetedMod.THAUMCRAFT)
.addClientMixins(
"client.thaumcraft.MixinTileEldritchObeliskRenderer",
"client.thaumcraft.MixinTileEldritchNothingRenderer",
"client.thaumcraft.MixinTileEldritchLockRenderer",
"client.thaumcraft.MixinTileHoleRenderer",
"client.thaumcraft.MixinTileMirrorRenderer",
"client.thaumcraft.MixinTileHole",
"client.thaumcraft.MixinTileEldritchNothing",
"client.thaumcraft.MixinBlockHole")
),
THAUMCRAFT_TESR_JAR_CACHE(new MixinBuilder("Batch TC4 jar liquid via the retained TESR mesh cache")
.setPhase(Phase.LATE)
.setApplyIf(() -> AngelicaConfig.enableTESRJarCache)
@@ -6,14 +6,13 @@ import com.gtnewhorizon.gtnhlib.client.renderer.vertex.DefaultVertexFormat;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import com.gtnewhorizons.angelica.glsm.states.Color4;
import com.gtnewhorizons.angelica.client.rendering.GlUniformFloat2v;
import com.gtnewhorizons.angelica.glsm.streaming.TessellatorStreamingDrawer;
import net.irisshaders.iris.api.v0.IrisApi;
import net.minecraft.util.AxisAlignedBB;
import org.embeddedt.embeddium.impl.gl.shader.GlProgram;
import org.embeddedt.embeddium.impl.gl.shader.GlShader;
import org.embeddedt.embeddium.impl.gl.shader.ShaderConstants;
import org.embeddedt.embeddium.impl.gl.shader.ShaderType;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat4v;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformMatrix4f;
import org.embeddedt.embeddium.impl.render.shader.ShaderLoader;
@@ -27,6 +26,7 @@ public final class SelectionBoxRenderer {
private static GlProgram<SelectionBoxUniforms> program;
private static IVertexArrayObject vao;
private static ByteBuffer edges;
private static final Matrix4f mvpMatrix = new Matrix4f();
private static final float[] colorBuf = new float[4];
@@ -43,31 +43,17 @@ public final class SelectionBoxRenderer {
private SelectionBoxRenderer() {}
public static void init() {
final boolean needsGS = GLStateManager.wideLineEmulationEnabled && GLStateManager.supportsGeometryShaders();
final GlShader vs = ShaderLoader.loadShader(ShaderType.VERTEX, "angelica:selection_box.vert.glsl", ShaderConstants.EMPTY);
final GlShader fs = ShaderLoader.loadShader(ShaderType.FRAGMENT, "angelica:selection_box.frag.glsl", ShaderConstants.EMPTY);
final GlProgram.Builder builder = GlProgram.builder("SelectionBox").attachShader(vs).attachShader(fs);
GlShader gs = null;
if (needsGS) {
gs = ShaderLoader.loadShader(ShaderType.GEOM, "angelica:selection_box.geom.glsl", ShaderConstants.EMPTY);
builder.attachShader(gs);
}
program = builder.link(ctx -> new SelectionBoxUniforms(
program = GlProgram.builder("SelectionBox").attachShader(vs).attachShader(fs).link(ctx -> new SelectionBoxUniforms(
ctx.bindUniform("u_MVP", GlUniformMatrix4f::new),
ctx.bindUniform("u_Color", GlUniformFloat4v::new),
needsGS ? ctx.bindUniform("u_ViewportSize", GlUniformFloat2v::new) : null,
needsGS ? ctx.bindUniform("u_LineWidth", GlUniformFloat::new) : null));
ctx.bindUniform("u_Color", GlUniformFloat4v::new)));
vs.destroy();
fs.destroy();
if (gs != null) gs.destroy();
final ByteBuffer buf = BufferUtils.createByteBuffer(UNIT_EDGES.length * Float.BYTES);
buf.asFloatBuffer().put(UNIT_EDGES);
vao = VertexBufferType.IMMUTABLE.allocate(DefaultVertexFormat.POSITION, GL11.GL_LINES, buf, VERT_COUNT);
edges = BufferUtils.createByteBuffer(UNIT_EDGES.length * Float.BYTES);
edges.asFloatBuffer().put(UNIT_EDGES);
vao = VertexBufferType.IMMUTABLE.allocate(DefaultVertexFormat.POSITION, GL11.GL_LINES, edges, VERT_COUNT);
}
public static void draw(AxisAlignedBB aabb, int color) {
@@ -78,8 +64,8 @@ public final class SelectionBoxRenderer {
final float extY = (float) (aabb.maxY - aabb.minY);
final float extZ = (float) (aabb.maxZ - aabb.minZ);
if (AngelicaConfig.enableIris && IrisApi.getInstance().isShaderPackInUse()) {
drawThroughShader(minX, minY, minZ, extX, extY, extZ, color);
if (GLStateManager.wideLineEmulationEnabled || (AngelicaConfig.enableIris && IrisApi.getInstance().isShaderPackInUse())) {
drawAsLines(minX, minY, minZ, extX, extY, extZ, color);
} else {
drawFast(minX, minY, minZ, extX, extY, extZ, color);
}
@@ -108,31 +94,29 @@ public final class SelectionBoxRenderer {
}
uniforms.color.set(colorBuf);
if (uniforms.viewportSize != null) {
uniforms.viewportSize.set(GLStateManager.getViewportState().width, GLStateManager.getViewportState().height);
uniforms.lineWidth.setFloat(GLStateManager.getLineState().getWidth());
}
vao.render();
program.unbind();
}
private static void drawThroughShader(float minX, float minY, float minZ, float extX, float extY, float extZ, int color) {
// The streaming drawer's line path widens the edges in the FFP vertex shader or sends them to a pack's gbuffers_line
private static void drawAsLines(float minX, float minY, float minZ, float extX, float extY, float extZ, int color) {
GLStateManager.glPushMatrix();
GLStateManager.glTranslatef(minX, minY, minZ);
GLStateManager.glScalef(extX, extY, extZ);
final Color4 prev = GLStateManager.getColor();
final float prevRed = prev.getRed(), prevGreen = prev.getGreen(), prevBlue = prev.getBlue(), prevAlpha = prev.getAlpha();
final boolean overrideColor = color != -1;
if (overrideColor) {
GLStateManager.glColor4f(((color >> 16) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f, (color & 0xFF) / 255.0f, 1.0f);
}
vao.render();
edges.clear();
TessellatorStreamingDrawer.drawPacked(edges, GL11.GL_LINES, DefaultVertexFormat.POSITION.getVertexFlags(), VERT_COUNT);
if (overrideColor) {
GLStateManager.glColor4f(prev.getRed(), prev.getGreen(), prev.getBlue(), prev.getAlpha());
GLStateManager.glColor4f(prevRed, prevGreen, prevBlue, prevAlpha);
}
GLStateManager.glPopMatrix();
}
@@ -148,7 +132,7 @@ public final class SelectionBoxRenderer {
}
}
private record SelectionBoxUniforms(GlUniformMatrix4f mvp, GlUniformFloat4v color, GlUniformFloat2v viewportSize, GlUniformFloat lineWidth) {
private record SelectionBoxUniforms(GlUniformMatrix4f mvp, GlUniformFloat4v color) {
}
}
@@ -1,5 +1,6 @@
package com.gtnewhorizons.angelica.rendering.celeritas;
import com.gtnewhorizons.angelica.rendering.tesr.SectionBuiltBlockEntity;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
@@ -10,14 +11,24 @@ import java.util.Arrays;
public class AngelicaBuiltRenderSectionData extends MinecraftBuiltRenderSectionData<TextureAtlasSprite, TileEntity> {
public static final float[] EMPTY_BOUNDS = new float[0];
private static final SectionBuiltBlockEntity[] NO_SECTION_BUILT = new SectionBuiltBlockEntity[0];
public float[] culledBlockEntityBounds = EMPTY_BOUNDS;
public SectionBuiltBlockEntity[] sectionBuilt = NO_SECTION_BUILT;
public int[] sectionBuiltResults;
public double maxTeRenderDistSq = Double.POSITIVE_INFINITY;
public int cullEpoch = -1;
public int cullVerdict;
public void applySectionBuilt() {
for (int i = 0; i < sectionBuilt.length; i++) {
sectionBuilt[i].angelica$applySectionResult(sectionBuiltResults[i]);
}
}
public static void packSectionLocalBounds(FloatArrayList out, AxisAlignedBB aabb, int originX, int originY, int originZ) {
out.add((float) (aabb.minX - originX));
out.add((float) (aabb.minY - originY));
@@ -11,10 +11,12 @@ import com.gtnewhorizons.angelica.rendering.celeritas.iris.BlockRenderContext;
import com.gtnewhorizons.angelica.rendering.celeritas.iris.ContextAwareChunkVertexEncoder;
import com.gtnewhorizons.angelica.rendering.celeritas.threading.RenderPassHelper;
import com.gtnewhorizons.angelica.rendering.celeritas.world.WorldSlice;
import com.gtnewhorizons.angelica.rendering.tesr.SectionBuiltBlockEntity;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.utils.NaturalTextureUtils;
import com.prupe.mcpatcher.mal.block.RenderBlocksUtils;
import it.unimi.dsi.fastutil.floats.FloatArrayList;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceMap;
import net.coderbot.iris.block_rendering.BlockMaterialMapping;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
@@ -173,6 +175,8 @@ public abstract class AngelicaChunkBuilderMeshingTask extends ChunkBuilderTask<C
final FloatArrayList culledBounds = buildContext.getTeBoundsScratch();
culledBounds.clear();
List<SectionBuiltBlockEntity> sectionBuilt = null;
IntArrayList sectionBuiltResults = null;
double maxTeRenderDistSq = 0;
final RenderBlocks renderBlocks = new RenderBlocks(region);
@@ -199,6 +203,14 @@ public abstract class AngelicaChunkBuilderMeshingTask extends ChunkBuilderTask<C
if (block.hasTileEntity(meta)) {
final TileEntity tileEntity = region.getTileEntity(x, y, z);
if (tileEntity != null && TileEntityRendererDispatcher.instance.hasSpecialRenderer(tileEntity)) {
if (tileEntity instanceof SectionBuiltBlockEntity built) {
if (sectionBuilt == null) {
sectionBuilt = new ArrayList<>();
sectionBuiltResults = new IntArrayList();
}
sectionBuilt.add(built);
sectionBuiltResults.add(built.angelica$prepareFromSection(region));
}
final boolean isGlobal;
AxisAlignedBB aabb = null;
final byte boundsClass = TileEntityRenderBoundsRegistry.classify(tileEntity);
@@ -279,6 +291,10 @@ public abstract class AngelicaChunkBuilderMeshingTask extends ChunkBuilderTask<C
renderData.visibilityData = occluder.computeVisibilityEncoding();
renderData.culledBlockEntityBounds = culledBounds.isEmpty() ? AngelicaBuiltRenderSectionData.EMPTY_BOUNDS : culledBounds.toFloatArray();
renderData.maxTeRenderDistSq = maxTeRenderDistSq;
if (sectionBuilt != null) {
renderData.sectionBuilt = sectionBuilt.toArray(new SectionBuiltBlockEntity[0]);
renderData.sectionBuiltResults = sectionBuiltResults.toIntArray();
}
if (handoff) {
if (region != buildContext.getWorldSlice()) {
@@ -27,6 +27,7 @@ import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
import org.embeddedt.embeddium.impl.render.chunk.RenderSectionManager;
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildOutput;
import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderTask;
import org.embeddedt.embeddium.impl.render.chunk.data.BuiltRenderSectionData;
import org.embeddedt.embeddium.impl.render.chunk.fog.FogService;
import org.embeddedt.embeddium.impl.render.chunk.lists.SectionTicker;
import org.embeddedt.embeddium.impl.render.chunk.occlusion.AsyncOcclusionMode;
@@ -150,6 +151,12 @@ public class AngelicaRenderSectionManager extends RenderSectionManager {
return array[y] == null || array[y].isEmpty();
}
@Override
protected boolean updateSectionInfo(RenderSection render, @Nullable BuiltRenderSectionData info) {
if (info instanceof AngelicaBuiltRenderSectionData data) data.applySectionBuilt();
return super.updateSectionInfo(render, info);
}
@Override
protected @Nullable ChunkBuilderTask<ChunkBuildOutput> createRebuildTask(RenderSection render, int frame) {
if (isSectionVisuallyEmpty(render.getChunkX(), render.getChunkY(), render.getChunkZ())) {
@@ -57,6 +57,8 @@ import com.gtnewhorizons.angelica.render.WeatherRenderer;
import com.gtnewhorizons.angelica.rendering.culling.GpuTerrainCuller;
import com.gtnewhorizons.angelica.rendering.tesr.AngelicaTesrMeshCache;
import com.gtnewhorizons.angelica.rendering.tesr.ModelPartBatcher;
import com.gtnewhorizons.angelica.rendering.tesr.PendingTesrDraws;
import com.gtnewhorizons.angelica.rendering.tesr.SectionBuiltBlockEntity;
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProvider;
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProviderHolder;
import com.gtnewhorizons.angelica.rendering.tesr.TesrAttribution;
@@ -415,6 +417,7 @@ public class CeleritasWorldRenderer extends SimpleWorldRenderer<WorldClient, Ang
TileEntityRendererDispatcher.staticPlayerY,
TileEntityRendererDispatcher.staticPlayerZ);
ModelPartBatcher.INSTANCE.begin(ModelPartBatcher.Mode.BLOCK_ENTITIES);
PendingTesrDraws.beginPass();
int count = 0;
if (pass == 0) {
teRenderContext.set(partialTicks, pass);
@@ -474,6 +477,7 @@ public class CeleritasWorldRenderer extends SimpleWorldRenderer<WorldClient, Ang
if (Tracy.ENABLED) Tracy.endZone();
}
}
PendingTesrDraws.endPass();
if (Tracy.ENABLED) Tracy.beginZone(Z_TESR_MODEL_PARTS);
try {
ModelPartBatcher.INSTANCE.flush();
@@ -599,6 +603,19 @@ public class CeleritasWorldRenderer extends SimpleWorldRenderer<WorldClient, Ang
}
private void dispatchTE(TileEntity tileEntity, float partialTicks) {
if (tileEntity instanceof SectionBuiltBlockEntity built) {
final TileEntityRendererDispatcher dispatcher = TileEntityRendererDispatcher.instance;
if (!(tileEntity.getDistanceFrom(dispatcher.field_147560_j, dispatcher.field_147561_k, dispatcher.field_147558_l) < tileEntity.getMaxRenderDistanceSquared())) {
return;
}
if (built.angelica$drawBuilt(
tileEntity.xCoord - TileEntityRendererDispatcher.staticPlayerX,
tileEntity.yCoord - TileEntityRendererDispatcher.staticPlayerY,
tileEntity.zCoord - TileEntityRendererDispatcher.staticPlayerZ)) {
return;
}
}
PendingTesrDraws.beforeTileEntity(tileEntity);
try {
final long start = Tracy.ENABLED ? System.nanoTime() : 0L;
final boolean attribute = Tracy.ENABLED && TesrAttribution.currentRenderable == null;
@@ -286,15 +286,6 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
blockBrightness = min;
}
if (chunkLightSources != null && !chunkLightSources.isEmpty() && !getBlock(x, y, z).isOpaqueCube()) {
final int lightmap = skyBrightness << 20 | blockBrightness << 4;
final double dynamicLevel = dynamicLightsInstance.getDynamicLightLevelFromSources(x + 0.5, y + 0.5, z + 0.5, chunkLightSources);
if (dynamicLevel > 0) {
return dynamicLightsInstance.getLightmapWithDynamicLight(dynamicLevel, lightmap);
}
return lightmap;
}
return skyBrightness << 20 | blockBrightness << 4;
}
@@ -0,0 +1,51 @@
package com.gtnewhorizons.angelica.rendering.tesr;
import net.minecraft.tileentity.TileEntity;
/**
* Lets a block entity renderer keep geometry pending across consecutive block entities of its own kind during the
* block entity pass.
*/
public final class PendingTesrDraws {
private static Pending pending;
private static boolean inPass;
private PendingTesrDraws() {
}
public static boolean canDefer() {
return inPass;
}
public static void hold(Pending owner) {
if (pending != owner) flush();
pending = owner;
}
public static void beforeTileEntity(TileEntity next) {
if (pending != null && !pending.canWaitFor(next)) flush();
}
public static void beginPass() {
inPass = true;
}
public static void endPass() {
inPass = false;
flush();
}
public static void flush() {
final Pending owner = pending;
if (owner == null) return;
pending = null;
owner.flush();
}
public interface Pending {
boolean canWaitFor(TileEntity next);
void flush();
}
}
@@ -0,0 +1,12 @@
package com.gtnewhorizons.angelica.rendering.tesr;
import net.minecraft.world.IBlockAccess;
public interface SectionBuiltBlockEntity {
int angelica$prepareFromSection(IBlockAccess world);
void angelica$applySectionResult(int prepared);
boolean angelica$drawBuilt(double x, double y, double z);
}