mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-22 05:12:16 +00:00
Angelica 2.0
* GLStateManagerService & RenderSystemService * Wire up Celeritas * Iris working * Dynamic lights working * Goodbye Sodium 0.2 * Add Multi-Threading for check meshing again
This commit is contained in:
1 parent
e5e8250d44
commit
be90a01725
354 files changed
+5257
-15599
No files matched your search
@@ -9,6 +9,8 @@ import com.gtnewhorizons.angelica.utils.AnimationMode;
|
||||
import com.gtnewhorizons.angelica.utils.ManagedEnum;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
@@ -29,6 +31,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
guiFactory = "com.gtnewhorizons.angelica.config.AngelicaGuiConfigFactory")
|
||||
public class AngelicaMod {
|
||||
public static final String MOD_ID = "angelica";
|
||||
public static final Logger LOGGER = LogManager.getLogger("Angelica");
|
||||
|
||||
@SidedProxy(clientSide = "com.gtnewhorizons.angelica.proxy.ClientProxy", serverSide = "com.gtnewhorizons.angelica.proxy.CommonProxy")
|
||||
public static CommonProxy proxy;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.gtnewhorizons.angelica.api;
|
||||
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.IPatchedTextureAtlasSprite;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.ITexturesCache;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.SpriteExtension;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
@@ -20,8 +20,8 @@ public class TextureServices {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void updateTextureAnimation(IIcon icon) {
|
||||
if(icon instanceof IPatchedTextureAtlasSprite patchedSprite) {
|
||||
patchedSprite.markNeedsAnimationUpdate();
|
||||
if (icon instanceof SpriteExtension ext) {
|
||||
ext.celeritas$markActive();
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -27,7 +27,7 @@ public class BetterCrashesCompat implements StateManager.IResettable {
|
||||
@Override
|
||||
public void resetState() {
|
||||
LOGGER.info("Reloading SodiumRenderer");
|
||||
((IRenderGlobalExt) Minecraft.getMinecraft().renderGlobal).reload();
|
||||
((IRenderGlobalExt) Minecraft.getMinecraft().renderGlobal).angelica$reload();
|
||||
LOGGER.info("Resetting GLStateManager");
|
||||
GLStateManager.reset();
|
||||
}
|
||||
|
||||
@@ -34,10 +34,17 @@ public class MatrixStack {
|
||||
public void pop() {
|
||||
this.matrixStack.removeLast();
|
||||
}
|
||||
public boolean clear() {
|
||||
public boolean isEmpty() {
|
||||
return this.matrixStack.size() == 1;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
while (this.matrixStack.size() > 1) {
|
||||
this.matrixStack.removeLast();
|
||||
}
|
||||
loadIdentity();
|
||||
}
|
||||
|
||||
public void translate(double d, double e, double f) {
|
||||
final Entry lv = (Entry)this.matrixStack.getLast();
|
||||
lv.model.translate((float)d, (float)e, (float)f);
|
||||
|
||||
@@ -4,10 +4,21 @@ import com.gtnewhorizon.gtnhlib.config.Config;
|
||||
|
||||
@Config(modid = "angelica", filename = "angelica-modules")
|
||||
public class AngelicaConfig {
|
||||
@Config.Comment("Enable Sodium rendering")
|
||||
@Config.Comment("Enable Celeritas terrain rendering")
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enableSodium;
|
||||
public static boolean enableCeleritas;
|
||||
|
||||
@Config.Comment("Enable multi-threaded chunk building for improved performance [Requires Celeritas]")
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.RequiresWorldRestart
|
||||
public static boolean enableThreadedChunkBuilding;
|
||||
|
||||
@Config.Comment("Number of chunk builder threads. 0 = auto-detect, -1 = use single-threaded fallback")
|
||||
@Config.DefaultInt(0)
|
||||
@Config.RangeInt(min = -1, max = 16)
|
||||
@Config.RequiresWorldRestart
|
||||
public static int chunkBuilderThreadCount;
|
||||
|
||||
@Config.Comment("Enable NotFine Options")
|
||||
@Config.DefaultBoolean(false)
|
||||
@@ -17,11 +28,6 @@ public class AngelicaConfig {
|
||||
@Config.DefaultBoolean(true)
|
||||
public static boolean enableReesesSodiumOptions;
|
||||
|
||||
@Config.Comment("Enable Sodium fluid rendering [Experimental]")
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enableSodiumFluidRendering;
|
||||
|
||||
@Config.Comment("Inject BakedModel rendering into some vanilla blocks")
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.RequiresMcRestart
|
||||
@@ -32,7 +38,7 @@ public class AngelicaConfig {
|
||||
@Config.Ignore()
|
||||
public static boolean enableTestBlocks;
|
||||
|
||||
@Config.Comment("Enable Iris Shaders [Requires Sodium]")
|
||||
@Config.Comment("Enable Iris Shaders [Requires Celeritas]")
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enableIris;
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.gtnewhorizons.angelica.compat.battlegear2.Battlegear2Compat;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
|
||||
import mods.battlegear2.api.core.IBattlePlayer;
|
||||
import net.irisshaders.iris.api.v0.IrisApi;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -34,6 +33,7 @@ import java.util.function.Predicate;
|
||||
|
||||
public class DynamicLights {
|
||||
private static DynamicLights instance;
|
||||
private static IDynamicLightWorldRenderer activeRenderer;
|
||||
public static DynamicLightsMode Mode = DynamicLightsMode.OFF;
|
||||
public static boolean ShaderForce = false;
|
||||
|
||||
@@ -60,12 +60,20 @@ public class DynamicLights {
|
||||
(ShaderForce || !IrisApi.getInstance().isShaderPackInUse());
|
||||
}
|
||||
|
||||
public static IDynamicLightWorldRenderer getActiveRenderer() {
|
||||
return activeRenderer;
|
||||
}
|
||||
|
||||
public static void setActiveRenderer(IDynamicLightWorldRenderer renderer) {
|
||||
activeRenderer = renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all light sources.
|
||||
*
|
||||
* @param renderer the renderer
|
||||
*/
|
||||
public void updateAll(@NotNull SodiumWorldRenderer renderer) {
|
||||
public void updateAll(@NotNull IDynamicLightWorldRenderer renderer) {
|
||||
if (!isEnabled())
|
||||
return;
|
||||
|
||||
@@ -107,8 +115,8 @@ public class DynamicLights {
|
||||
it = dynamicLightSources.next();
|
||||
if (it.equals(lightSource)) {
|
||||
dynamicLightSources.remove();
|
||||
if (SodiumWorldRenderer.getInstance() != null)
|
||||
lightSource.angelica$scheduleTrackedChunksRebuild(SodiumWorldRenderer.getInstance());
|
||||
if (activeRenderer != null)
|
||||
lightSource.angelica$scheduleTrackedChunksRebuild(activeRenderer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -130,10 +138,10 @@ public class DynamicLights {
|
||||
it = dynamicLightSources.next();
|
||||
if (filter.test(it)) {
|
||||
dynamicLightSources.remove();
|
||||
if (SodiumWorldRenderer.getInstance() != null) {
|
||||
if (activeRenderer != null) {
|
||||
if (it.angelica$getLuminance() > 0)
|
||||
it.angelica$resetDynamicLight();
|
||||
it.angelica$scheduleTrackedChunksRebuild(SodiumWorldRenderer.getInstance());
|
||||
it.angelica$scheduleTrackedChunksRebuild(activeRenderer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -153,10 +161,10 @@ public class DynamicLights {
|
||||
while (dynamicLightSources.hasNext()) {
|
||||
it = dynamicLightSources.next();
|
||||
dynamicLightSources.remove();
|
||||
if (SodiumWorldRenderer.getInstance() != null) {
|
||||
if (activeRenderer != null) {
|
||||
if (it.angelica$getLuminance() > 0)
|
||||
it.angelica$resetDynamicLight();
|
||||
it.angelica$scheduleTrackedChunksRebuild(SodiumWorldRenderer.getInstance());
|
||||
it.angelica$scheduleTrackedChunksRebuild(activeRenderer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,6 +211,20 @@ public class DynamicLights {
|
||||
return MathHelper.clamp_double(result, 0, 15);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dynamic light level at an exact world position (for smooth per-vertex lighting).
|
||||
*/
|
||||
public double getDynamicLightLevel(double x, double y, double z) {
|
||||
double result = 0;
|
||||
this.lightSourcesLock.readLock().lock();
|
||||
for (var lightSource : this.dynamicLightSources) {
|
||||
result = maxDynamicLightLevelExact(x, y, z, lightSource, result);
|
||||
}
|
||||
this.lightSourcesLock.readLock().unlock();
|
||||
|
||||
return MathHelper.clamp_double(result, 0, 15);
|
||||
}
|
||||
|
||||
public double getDynamicLightLevel(@NotNull BlockPos pos) {
|
||||
return this.getDynamicLightLevel(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
@@ -229,6 +251,29 @@ public class DynamicLights {
|
||||
return currentLightLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates dynamic light level at an exact position (no block center offset).
|
||||
* Used for smooth per-vertex lighting.
|
||||
*/
|
||||
public static double maxDynamicLightLevelExact(double x, double y, double z, @NotNull IDynamicLightSource lightSource, double currentLightLevel) {
|
||||
int luminance = lightSource.angelica$getLuminance();
|
||||
if (luminance > 0) {
|
||||
double dx = x - lightSource.angelica$getDynamicLightX();
|
||||
double dy = y - lightSource.angelica$getDynamicLightY();
|
||||
double dz = z - lightSource.angelica$getDynamicLightZ();
|
||||
|
||||
double distanceSquared = dx * dx + dy * dy + dz * dz;
|
||||
if (distanceSquared <= MAX_RADIUS_SQUARED) {
|
||||
double multiplier = 1.0 - Math.sqrt(distanceSquared) / MAX_RADIUS;
|
||||
double lightLevel = multiplier * (double) luminance;
|
||||
if (lightLevel > currentLightLevel) {
|
||||
return lightLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
return currentLightLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dynamic light level generated by the light source at the specified position.
|
||||
*
|
||||
@@ -275,7 +320,7 @@ public class DynamicLights {
|
||||
* @param renderer the renderer
|
||||
* @param chunkPos the chunk position
|
||||
*/
|
||||
public static void scheduleChunkRebuild(@NotNull SodiumWorldRenderer renderer, @NotNull IBlockPos chunkPos) {
|
||||
public static void scheduleChunkRebuild(@NotNull IDynamicLightWorldRenderer renderer, @NotNull IBlockPos chunkPos) {
|
||||
scheduleChunkRebuild(renderer, chunkPos.getX(), chunkPos.getY(), chunkPos.getZ());
|
||||
}
|
||||
|
||||
@@ -285,11 +330,11 @@ public class DynamicLights {
|
||||
* @param renderer the renderer
|
||||
* @param chunkPos the packed chunk position
|
||||
*/
|
||||
public static void scheduleChunkRebuild(@NotNull SodiumWorldRenderer renderer, long chunkPos) {
|
||||
public static void scheduleChunkRebuild(@NotNull IDynamicLightWorldRenderer renderer, long chunkPos) {
|
||||
scheduleChunkRebuild(renderer, CoordinatePacker.unpackX(chunkPos), CoordinatePacker.unpackY(chunkPos), CoordinatePacker.unpackZ(chunkPos));
|
||||
}
|
||||
|
||||
public static void scheduleChunkRebuild(@NotNull SodiumWorldRenderer renderer, int x, int y, int z) {
|
||||
public static void scheduleChunkRebuild(@NotNull IDynamicLightWorldRenderer renderer, int x, int y, int z) {
|
||||
renderer.scheduleRebuildForChunk(x, y, z, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.gtnewhorizons.angelica.dynamiclights;
|
||||
|
||||
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -27,11 +26,13 @@ public interface IDynamicLightSource {
|
||||
double angelica$getDynamicLightZ();
|
||||
|
||||
/**
|
||||
* Returns the dynamic light source world.
|
||||
* Returns the dynamic light source world renderer.
|
||||
*
|
||||
* @return the world instance
|
||||
* @return the world renderer instance
|
||||
*/
|
||||
SodiumWorldRenderer angelica$getDynamicLightWorld();
|
||||
default IDynamicLightWorldRenderer angelica$getDynamicLightWorld() {
|
||||
return DynamicLights.getActiveRenderer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the dynamic light is enabled or not.
|
||||
@@ -73,7 +74,7 @@ public interface IDynamicLightSource {
|
||||
*/
|
||||
void angelica$dynamicLightTick();
|
||||
|
||||
boolean angelica$updateDynamicLight(@NotNull SodiumWorldRenderer renderer);
|
||||
boolean angelica$updateDynamicLight(@NotNull IDynamicLightWorldRenderer renderer);
|
||||
|
||||
void angelica$scheduleTrackedChunksRebuild(@NotNull SodiumWorldRenderer renderer);
|
||||
void angelica$scheduleTrackedChunksRebuild(@NotNull IDynamicLightWorldRenderer renderer);
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.gtnewhorizons.angelica.dynamiclights;
|
||||
|
||||
/**
|
||||
* Common interface for world renderers that support dynamic lights chunk rebuilds.
|
||||
* Implemented by CeleritasWorldRenderer.
|
||||
*/
|
||||
public interface IDynamicLightWorldRenderer {
|
||||
/**
|
||||
* Schedules a chunk rebuild for the render section at the given chunk coordinates.
|
||||
*/
|
||||
void scheduleRebuildForChunk(int x, int y, int z, boolean important);
|
||||
|
||||
/**
|
||||
* Returns whether this renderer is currently active (has a world loaded).
|
||||
*/
|
||||
boolean isActive();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.gtnewhorizons.angelica.glsm;
|
||||
|
||||
import org.embeddedt.embeddium.impl.render.chunk.fog.FogService;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkFogMode;
|
||||
|
||||
public class AngelicaFogService implements FogService {
|
||||
private final float[] fogColorArray = new float[4];
|
||||
|
||||
@Override
|
||||
public float getFogEnd() {
|
||||
return GLStateManager.getFogState().getEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFogStart() {
|
||||
return GLStateManager.getFogState().getStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFogDensity() {
|
||||
return GLStateManager.getFogState().getDensity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFogShapeIndex() {
|
||||
return 0; // 1.7.10 only has one fog shape
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFogCutoff() {
|
||||
return getFogEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] getFogColor() {
|
||||
final var fogState = GLStateManager.getFogState();
|
||||
final var color = fogState.getFogColor();
|
||||
fogColorArray[0] = (float) color.x;
|
||||
fogColorArray[1] = (float) color.y;
|
||||
fogColorArray[2] = (float) color.z;
|
||||
fogColorArray[3] = fogState.getFogAlpha();
|
||||
return fogColorArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkFogMode getFogMode() {
|
||||
if (!GLStateManager.getFogMode().isEnabled()) {
|
||||
return ChunkFogMode.NONE;
|
||||
}
|
||||
return ChunkFogMode.fromGLMode(GLStateManager.getFogState().getFogMode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
package com.gtnewhorizons.angelica.glsm;
|
||||
|
||||
import com.mitchej123.glsm.GLStateManagerService;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class AngelicaGLStateManagerService implements GLStateManagerService {
|
||||
|
||||
private IntBuffer intArrayBuffer = BufferUtils.createIntBuffer(16);
|
||||
|
||||
private IntBuffer getIntArrayBuffer(int size) {
|
||||
if (intArrayBuffer.capacity() < size) {
|
||||
intArrayBuffer = BufferUtils.createIntBuffer(size);
|
||||
}
|
||||
intArrayBuffer.clear();
|
||||
return intArrayBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
// ===================== QUERY OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public int glGetInteger(int pname) {
|
||||
return GLStateManager.glGetInteger(pname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String glGetString(int pname) {
|
||||
return GL11.glGetString(pname);
|
||||
}
|
||||
|
||||
// ===================== FRAMEBUFFER OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public int glGenFramebuffers() {
|
||||
return GL30.glGenFramebuffers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDeleteFramebuffers(int framebuffer) {
|
||||
GL30.glDeleteFramebuffers(framebuffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glBindFramebuffer(int target, int framebuffer) {
|
||||
GL30.glBindFramebuffer(target, framebuffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glCheckFramebufferStatus(int target) {
|
||||
return GL30.glCheckFramebufferStatus(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFramebufferTexture2D(int target, int attachment, int textarget, int texture, int level) {
|
||||
GL30.glFramebufferTexture2D(target, attachment, textarget, texture, level);
|
||||
}
|
||||
|
||||
// ===================== SHADER OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public int glCreateShader(int type) {
|
||||
return GL20.glCreateShader(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glCompileShader(int shader) {
|
||||
GL20.glCompileShader(shader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetShaderi(int shader, int pname) {
|
||||
return GL20.glGetShaderi(shader, pname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String glGetShaderInfoLog(int shader, int maxLength) {
|
||||
return GL20.glGetShaderInfoLog(shader, maxLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDeleteShader(int shader) {
|
||||
GL20.glDeleteShader(shader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glCreateProgram() {
|
||||
return GL20.glCreateProgram();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glAttachShader(int program, int shader) {
|
||||
GL20.glAttachShader(program, shader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glLinkProgram(int program) {
|
||||
GL20.glLinkProgram(program);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetProgrami(int program, int pname) {
|
||||
return GL20.glGetProgrami(program, pname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glUseProgram(int program) {
|
||||
GLStateManager.glUseProgram(program);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDeleteProgram(int program) {
|
||||
GL20.glDeleteProgram(program);
|
||||
}
|
||||
|
||||
// ===================== UNIFORM/ATTRIBUTE OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public int glGetUniformLocation(int program, CharSequence name) {
|
||||
return GL20.glGetUniformLocation(program, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glUniform1i(int location, int value) {
|
||||
GL20.glUniform1i(location, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetAttribLocation(int program, CharSequence name) {
|
||||
return GL20.glGetAttribLocation(program, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glBindAttribLocation(int program, int index, CharSequence name) {
|
||||
GL20.glBindAttribLocation(program, index, name);
|
||||
}
|
||||
|
||||
// ===================== VAO OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public int glGenVertexArrays() {
|
||||
return GL30.glGenVertexArrays();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glBindVertexArray(int array) {
|
||||
GL30.glBindVertexArray(array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDeleteVertexArrays(int array) {
|
||||
GL30.glDeleteVertexArrays(array);
|
||||
}
|
||||
|
||||
// ===================== BUFFER OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public int glGenBuffers() {
|
||||
return GL15.glGenBuffers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glBindBuffer(int target, int buffer) {
|
||||
GL15.glBindBuffer(target, buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDeleteBuffers(int buffer) {
|
||||
GL15.glDeleteBuffers(buffer);
|
||||
}
|
||||
|
||||
// ===================== TEXTURE OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public int glGenTextures() {
|
||||
return GL11.glGenTextures();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glGenTextures(int[] textures) {
|
||||
IntBuffer buffer = getIntArrayBuffer(textures.length);
|
||||
GL11.glGenTextures(buffer);
|
||||
buffer.get(textures);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDeleteTextures(int texture) {
|
||||
GLStateManager.glDeleteTextures(texture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDeleteTextures(int[] textures) {
|
||||
IntBuffer buffer = getIntArrayBuffer(textures.length);
|
||||
buffer.put(textures);
|
||||
buffer.flip();
|
||||
GLStateManager.glDeleteTextures(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glActiveTexture(int texture) {
|
||||
GLStateManager.glActiveTexture(texture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetTexLevelParameteri(int target, int level, int pname) {
|
||||
return GLStateManager.glGetTexLevelParameteri(target, level, pname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetTexLevelParameter(int target, int level, int pname) {
|
||||
return GLStateManager.glGetTexLevelParameteri(target, level, pname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glCopyTexSubImage2D(int target, int level, int xoffset, int yoffset, int x, int y, int width, int height) {
|
||||
GL11.glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glPixelStorei(int pname, int param) {
|
||||
GLStateManager.glPixelStorei(pname, param);
|
||||
}
|
||||
|
||||
// ===================== STATE OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public void enableCullFace() {
|
||||
GLStateManager.enableCull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableCullFace() {
|
||||
GLStateManager.disableCull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableBlend() {
|
||||
GLStateManager.enableBlend();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableBlend() {
|
||||
GLStateManager.disableBlend();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glBlendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {
|
||||
GLStateManager.tryBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableDepthTest() {
|
||||
GLStateManager.enableDepthTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableDepthTest() {
|
||||
GLStateManager.disableDepthTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDepthFunc(int func) {
|
||||
GLStateManager.glDepthFunc(func);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDepthMask(boolean flag) {
|
||||
GLStateManager.glDepthMask(flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glViewport(int x, int y, int width, int height) {
|
||||
GLStateManager.glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColorMask(boolean red, boolean green, boolean blue, boolean alpha) {
|
||||
GLStateManager.glColorMask(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor(float red, float green, float blue, float alpha) {
|
||||
GLStateManager.glClearColor(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClear(int mask) {
|
||||
GLStateManager.glClear(mask);
|
||||
}
|
||||
|
||||
// ===================== MOJANG ADDITIONS =====================
|
||||
|
||||
@Override
|
||||
public void clear(int mask, boolean checkError) {
|
||||
GLStateManager.glClear(mask);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindTexture(int texture) {
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, texture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveTexture() {
|
||||
return GLStateManager.getActiveTextureUnit() + GL13.GL_TEXTURE0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveTextureAccessor() {
|
||||
return GLStateManager.getActiveTextureUnit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBoundTexture(int internalUnit) {
|
||||
return GLStateManager.getBoundTextureForServerState(internalUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveBoundTexture() {
|
||||
return GLStateManager.getBoundTextureForServerState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewportWidth() {
|
||||
return GLStateManager.getViewportState().width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewportHeight() {
|
||||
return GLStateManager.getViewportState().height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDepthStateMask() {
|
||||
return GLStateManager.getDepthState().isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlendEnabled() {
|
||||
return GLStateManager.getBlendMode().isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBoundTexture(int unit, int texture) {
|
||||
int currentUnit = GLStateManager.getActiveTextureUnit();
|
||||
if (currentUnit != unit) {
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + unit);
|
||||
}
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, texture);
|
||||
if (currentUnit != unit) {
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + currentUnit);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTextureBinding(int unit) {
|
||||
return GLStateManager.getBoundTextureForServerState(unit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
package com.gtnewhorizons.angelica.glsm;
|
||||
|
||||
import com.mitchej123.glsm.RenderSystemService;
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
public class AngelicaRenderSystemService implements RenderSystemService {
|
||||
|
||||
// Shader state (Mojang-specific, tracked here)
|
||||
private final int[] shaderTextures = new int[16];
|
||||
private final float[] shaderColor = {1f, 1f, 1f, 1f};
|
||||
private final float[] shaderFogColor = {0f, 0f, 0f, 1f};
|
||||
private float shaderFogStart = 0f;
|
||||
private float shaderFogEnd = 0f;
|
||||
private int fogShape = 0;
|
||||
private float shaderLineWidth = 1f;
|
||||
private final Matrix4f projectionMatrix = new Matrix4f();
|
||||
private final FloatBuffer projectionMatrixBuffer = BufferUtils.createFloatBuffer(16);
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
// ===================== TEXTURE OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public void glActiveTexture(int texture) {
|
||||
GLStateManager.glActiveTexture(texture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindTexture(int texture) {
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, texture);
|
||||
}
|
||||
|
||||
// ===================== STATE OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public void enableCullFace() {
|
||||
GLStateManager.enableCull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableCullFace() {
|
||||
GLStateManager.disableCull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableBlend() {
|
||||
GLStateManager.enableBlend();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableBlend() {
|
||||
GLStateManager.disableBlend();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultBlendFunc() {
|
||||
GLStateManager.defaultBlendFunc();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {
|
||||
GLStateManager.tryBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnknownBlendState() {
|
||||
// No-op: Angelica tracks blend state accurately
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableDepthTest() {
|
||||
GLStateManager.enableDepthTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableDepthTest() {
|
||||
GLStateManager.disableDepthTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void depthFunc(int depthFunc) {
|
||||
GLStateManager.glDepthFunc(depthFunc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void depthMask(boolean flag) {
|
||||
GLStateManager.glDepthMask(flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glViewport(int x, int y, int width, int height) {
|
||||
GLStateManager.glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor(float red, float green, float blue, float alpha) {
|
||||
GLStateManager.glClearColor(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(int mask, boolean checkError) {
|
||||
GLStateManager.glClear(mask);
|
||||
}
|
||||
|
||||
// ===================== UNIFORM OPERATIONS =====================
|
||||
|
||||
@Override
|
||||
public void glUniform1i(int location, int value) {
|
||||
GL20.glUniform1i(location, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glUniformMatrix3(int location, boolean transpose, FloatBuffer value) {
|
||||
GL20.glUniformMatrix3(location, transpose, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glUniformMatrix4(int location, boolean transpose, FloatBuffer value) {
|
||||
GL20.glUniformMatrix4(location, transpose, value);
|
||||
}
|
||||
|
||||
// ===================== THREAD ASSERTIONS =====================
|
||||
|
||||
@Override
|
||||
public void assertOnRenderThread() {
|
||||
// No-op: 1.7.10 is single-threaded for rendering
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assertOnRenderThreadOrInit() {
|
||||
// No-op: 1.7.10 is single-threaded for rendering
|
||||
}
|
||||
|
||||
// ===================== SHADER STATE =====================
|
||||
|
||||
@Override
|
||||
public void setShaderTexture(int shaderTexture, int textureId) {
|
||||
if (shaderTexture >= 0 && shaderTexture < 16) {
|
||||
shaderTextures[shaderTexture] = textureId;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getShaderTexture(int shaderTexture) {
|
||||
return (shaderTexture >= 0 && shaderTexture < 16) ? shaderTextures[shaderTexture] : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShaderColor(float red, float green, float blue, float alpha) {
|
||||
shaderColor[0] = red;
|
||||
shaderColor[1] = green;
|
||||
shaderColor[2] = blue;
|
||||
shaderColor[3] = alpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] getShaderColor() {
|
||||
return shaderColor.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShaderLineWidth(float lineWidth) {
|
||||
shaderLineWidth = lineWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getShaderLineWidth() {
|
||||
return shaderLineWidth;
|
||||
}
|
||||
|
||||
// ===================== FOG STATE =====================
|
||||
|
||||
@Override
|
||||
public void setShaderFogColor(float red, float green, float blue, float alpha) {
|
||||
shaderFogColor[0] = red;
|
||||
shaderFogColor[1] = green;
|
||||
shaderFogColor[2] = blue;
|
||||
shaderFogColor[3] = alpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] getShaderFogColor() {
|
||||
return shaderFogColor.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShaderFogStart(float start) {
|
||||
shaderFogStart = start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getShaderFogStart() {
|
||||
return shaderFogStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShaderFogEnd(float end) {
|
||||
shaderFogEnd = end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getShaderFogEnd() {
|
||||
return shaderFogEnd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFogShape(int shape) {
|
||||
fogShape = shape;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFogShape() {
|
||||
return fogShape;
|
||||
}
|
||||
|
||||
// ===================== PROJECTION MATRIX =====================
|
||||
|
||||
@Override
|
||||
public Matrix4f getProjectionMatrix() {
|
||||
return new Matrix4f(projectionMatrix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProjectionMatrixOrth(Matrix4f m) {
|
||||
projectionMatrix.set(m);
|
||||
GLStateManager.glMatrixMode(GL11.GL_PROJECTION);
|
||||
projectionMatrix.get(projectionMatrixBuffer);
|
||||
projectionMatrixBuffer.rewind();
|
||||
GLStateManager.glLoadMatrix(projectionMatrixBuffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProjectionMatrixOrigin(Matrix4f m) {
|
||||
setProjectionMatrixOrth(m);
|
||||
}
|
||||
}
|
||||
@@ -1024,7 +1024,6 @@ public class DisplayListManager {
|
||||
|
||||
final CompiledDisplayList compiled = displayListCache.get(list);
|
||||
if (compiled != null) {
|
||||
GLStateManager.trySyncProgram();
|
||||
final int prevList = currentRenderingList;
|
||||
currentRenderingList = list;
|
||||
compiled.render();
|
||||
@@ -1043,7 +1042,6 @@ public class DisplayListManager {
|
||||
} else {
|
||||
// Positive IDs - fall back to native GL display lists
|
||||
// This happens for lists allocated but never compiled via glNewList
|
||||
GLStateManager.trySyncProgram();
|
||||
GL11.glCallList(list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,9 @@ public final class GLDebug {
|
||||
GL43.glDebugMessageControl(GL11.GL_DONT_CARE, GL11.GL_DONT_CARE, GL43.GL_DEBUG_SEVERITY_NOTIFICATION, null, false);
|
||||
GL43.glDebugMessageCallback(proc);
|
||||
|
||||
// Enable synchronous debug output so errors are reported immediately with accurate stack traces
|
||||
GL11.glEnable(GL43.GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||
|
||||
if ((GL11.glGetInteger(GL30.GL_CONTEXT_FLAGS) & GL43.GL_CONTEXT_FLAG_DEBUG_BIT) == 0) {
|
||||
LOGGER.warn("[GL] Warning: A non-debug context may not produce any debug output.");
|
||||
GL11.glEnable(GL43.GL_DEBUG_OUTPUT);
|
||||
@@ -125,6 +128,9 @@ public final class GLDebug {
|
||||
ARBDebugOutput.glDebugMessageControlARB(GL11.GL_DONT_CARE, GL11.GL_DONT_CARE, GL43.GL_DEBUG_SEVERITY_LOW, null, false);
|
||||
ARBDebugOutput.glDebugMessageControlARB(GL11.GL_DONT_CARE, GL11.GL_DONT_CARE, GL43.GL_DEBUG_SEVERITY_NOTIFICATION, null, false);
|
||||
ARBDebugOutput.glDebugMessageCallbackARB(proc);
|
||||
|
||||
// Enable synchronous debug output so errors are reported immediately with accurate stack traces
|
||||
GL11.glEnable(ARBDebugOutput.GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
||||
return 1;
|
||||
} else if (GLStateManager.capabilities.GL_AMD_debug_output) {
|
||||
LOGGER.info("[GL] Using AMD_debug_output for error logging.");
|
||||
|
||||
@@ -46,8 +46,6 @@ import net.coderbot.iris.gbuffer_overrides.state.StateTracker;
|
||||
import net.coderbot.iris.gl.blending.AlphaTestStorage;
|
||||
import net.coderbot.iris.gl.blending.BlendModeStorage;
|
||||
import net.coderbot.iris.gl.blending.DepthColorStorage;
|
||||
import net.coderbot.iris.gl.state.StateUpdateNotifiers;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
|
||||
import net.coderbot.iris.samplers.IrisSamplers;
|
||||
import net.coderbot.iris.texture.pbr.PBRTextureManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -352,14 +350,6 @@ public class GLStateManager {
|
||||
projectionMatrix.clear();
|
||||
}
|
||||
|
||||
// Iris Listeners
|
||||
private static Runnable blendFuncListener = null;
|
||||
private static Runnable fogToggleListener = null;
|
||||
private static Runnable fogModeListener = null;
|
||||
private static Runnable fogStartListener = null;
|
||||
private static Runnable fogEndListener = null;
|
||||
private static Runnable fogDensityListener = null;
|
||||
|
||||
/**
|
||||
* Check if a display list exists (has been compiled and stored).
|
||||
* Delegates to DisplayListManager.
|
||||
@@ -431,14 +421,6 @@ public class GLStateManager {
|
||||
public static void init() {
|
||||
RenderSystem.initRenderer();
|
||||
|
||||
if (Iris.enabled) {
|
||||
StateUpdateNotifiers.blendFuncNotifier = listener -> blendFuncListener = listener;
|
||||
StateUpdateNotifiers.fogToggleNotifier = listener -> fogToggleListener = listener;
|
||||
StateUpdateNotifiers.fogModeNotifier = listener -> fogModeListener = listener;
|
||||
StateUpdateNotifiers.fogStartNotifier = listener -> fogStartListener = listener;
|
||||
StateUpdateNotifiers.fogEndNotifier = listener -> fogEndListener = listener;
|
||||
StateUpdateNotifiers.fogDensityNotifier = listener -> fogDensityListener = listener;
|
||||
}
|
||||
if(BYPASS_CACHE) {
|
||||
LOGGER.info("GLStateManager cache bypassed");
|
||||
}
|
||||
@@ -1027,9 +1009,6 @@ public class GLStateManager {
|
||||
if (caching) blendState.setSrcDstRgb(srcFactor, dstFactor);
|
||||
GL11.glBlendFunc(srcFactor, dstFactor);
|
||||
}
|
||||
|
||||
// Iris
|
||||
if (blendFuncListener != null) blendFuncListener.run();
|
||||
}
|
||||
|
||||
public static void glBlendEquation(int mode) {
|
||||
@@ -1071,9 +1050,6 @@ public class GLStateManager {
|
||||
if (caching) blendState.setAll(srcRgb, dstRgb, srcAlpha, dstAlpha);
|
||||
OpenGlHelper.glBlendFunc(srcRgb, dstRgb, srcAlpha, dstAlpha);
|
||||
}
|
||||
|
||||
// Iris
|
||||
if (blendFuncListener != null) blendFuncListener.run();
|
||||
}
|
||||
|
||||
public static void checkCompiling() {
|
||||
@@ -1765,12 +1741,6 @@ public class GLStateManager {
|
||||
glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, j);
|
||||
}
|
||||
|
||||
public static void trySyncProgram() {
|
||||
if (Iris.enabled) {
|
||||
Iris.getPipelineManager().getPipeline().ifPresent(WorldRenderingPipeline::syncProgram);
|
||||
}
|
||||
}
|
||||
|
||||
public static void glBegin(int mode) {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
// Record to immediate mode recorder
|
||||
@@ -1780,7 +1750,6 @@ public class GLStateManager {
|
||||
}
|
||||
return; // Don't call actual GL during recording
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glBegin(mode);
|
||||
}
|
||||
|
||||
@@ -1851,7 +1820,6 @@ public class GLStateManager {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glDrawElements in display lists not yet implemented - if you see this, please report!");
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glDrawElements(mode, indices);
|
||||
}
|
||||
|
||||
@@ -1859,7 +1827,6 @@ public class GLStateManager {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glDrawElements in display lists not yet implemented - if you see this, please report!");
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glDrawElements(mode, indices);
|
||||
}
|
||||
|
||||
@@ -1867,7 +1834,6 @@ public class GLStateManager {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glDrawElements in display lists not yet implemented - if you see this, please report!");
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glDrawElements(mode, indices);
|
||||
}
|
||||
|
||||
@@ -1875,7 +1841,6 @@ public class GLStateManager {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glDrawElements in display lists not yet implemented - if you see this, please report!");
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glDrawElements(mode, indices_count, type, indices_buffer_offset);
|
||||
}
|
||||
|
||||
@@ -1883,7 +1848,6 @@ public class GLStateManager {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glDrawElements in display lists not yet implemented - if you see this, please report!");
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glDrawElements(mode, count, type, indices);
|
||||
}
|
||||
|
||||
@@ -1895,7 +1859,6 @@ public class GLStateManager {
|
||||
return;
|
||||
}
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glDrawBuffer(mode);
|
||||
}
|
||||
|
||||
@@ -1910,7 +1873,6 @@ public class GLStateManager {
|
||||
}
|
||||
return;
|
||||
}
|
||||
trySyncProgram();
|
||||
GL11.glDrawArrays(mode, first, count);
|
||||
}
|
||||
|
||||
@@ -2151,9 +2113,6 @@ public class GLStateManager {
|
||||
}
|
||||
}
|
||||
fogMode.enable();
|
||||
if (fogToggleListener != null) {
|
||||
fogToggleListener.run();
|
||||
}
|
||||
}
|
||||
|
||||
public static void disableFog() {
|
||||
@@ -2165,9 +2124,6 @@ public class GLStateManager {
|
||||
}
|
||||
}
|
||||
fogMode.disable();
|
||||
if (fogToggleListener != null) {
|
||||
fogToggleListener.run();
|
||||
}
|
||||
}
|
||||
|
||||
public static void glFog(int pname, FloatBuffer param) {
|
||||
@@ -2233,24 +2189,9 @@ public class GLStateManager {
|
||||
// Only update cached state when caching is enabled
|
||||
if (isCachingEnabled()) {
|
||||
switch (pname) {
|
||||
case GL11.GL_FOG_DENSITY -> {
|
||||
fogState.setDensity(param);
|
||||
if (fogDensityListener != null) {
|
||||
fogDensityListener.run();
|
||||
}
|
||||
}
|
||||
case GL11.GL_FOG_START -> {
|
||||
fogState.setStart(param);
|
||||
if (fogStartListener != null) {
|
||||
fogStartListener.run();
|
||||
}
|
||||
}
|
||||
case GL11.GL_FOG_END -> {
|
||||
fogState.setEnd(param);
|
||||
if (fogEndListener != null) {
|
||||
fogEndListener.run();
|
||||
}
|
||||
}
|
||||
case GL11.GL_FOG_DENSITY -> fogState.setDensity(param);
|
||||
case GL11.GL_FOG_START -> fogState.setStart(param);
|
||||
case GL11.GL_FOG_END -> fogState.setEnd(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2267,9 +2208,6 @@ public class GLStateManager {
|
||||
// Only update cached state when caching is enabled
|
||||
if (isCachingEnabled() && pname == GL11.GL_FOG_MODE) {
|
||||
fogState.setFogMode(param);
|
||||
if (fogModeListener != null) {
|
||||
fogModeListener.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.gtnewhorizons.angelica.glsm.compat;
|
||||
|
||||
/**
|
||||
* Simple holder for fog color values captured from vanilla rendering.
|
||||
* Used by terrain renderers to access fog state.
|
||||
*/
|
||||
public class FogHelper {
|
||||
public static float red;
|
||||
public static float green;
|
||||
public static float blue;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.gtnewhorizons.angelica.glsm.recording;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import com.gtnewhorizons.angelica.glsm.recording.commands.DrawCommand;
|
||||
import me.jellysquid.mods.sodium.client.gl.attribute.BufferVertexFormat;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents recorded geometry from a display list compilation.
|
||||
* Contains the vertex data buffer and metadata about draw commands.
|
||||
*/
|
||||
@Desugar
|
||||
public record RecordedGeometry(ByteBuffer buffer, BufferVertexFormat format, List<DrawCommand> drawCommands, int totalVertexCount) {
|
||||
public int getByteSize() {
|
||||
return buffer.remaining();
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.gl.state.StateUpdateNotifiers;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -17,12 +16,6 @@ public class TextureTracker {
|
||||
|
||||
public static final TextureTracker INSTANCE = new TextureTracker();
|
||||
|
||||
private static Runnable bindTextureListener;
|
||||
|
||||
static {
|
||||
StateUpdateNotifiers.bindTextureNotifier = listener -> bindTextureListener = listener;
|
||||
}
|
||||
|
||||
private final Int2ObjectMap<AbstractTexture> textures = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
private boolean lockBindCallback;
|
||||
@@ -45,9 +38,6 @@ public class TextureTracker {
|
||||
}
|
||||
if (GLStateManager.getActiveTextureUnit() == 0) {
|
||||
lockBindCallback = true;
|
||||
if (bindTextureListener != null) {
|
||||
bindTextureListener.run();
|
||||
}
|
||||
if(Iris.enabled) {
|
||||
final WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
|
||||
if (pipeline != null) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import jss.notfine.asm.AsmTransformers;
|
||||
import jss.notfine.asm.mappings.Namer;
|
||||
import jss.notfine.config.MCPatcherForgeConfig;
|
||||
import jss.notfine.config.NotFineConfig;
|
||||
import com.gtnewhorizons.retrofuturabootstrap.SharedConfig;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -55,6 +56,10 @@ public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader {
|
||||
private String[] transformerClasses;
|
||||
|
||||
public AngelicaTweaker() {
|
||||
if (Launch.blackboard.getOrDefault("angelica.rfbPluginLoaded", Boolean.FALSE) == Boolean.TRUE) {
|
||||
addLwjgl3ifyExclusions();
|
||||
}
|
||||
|
||||
try {
|
||||
// Angelica Config
|
||||
ConfigurationManager.registerConfig(AngelicaConfig.class);
|
||||
@@ -137,9 +142,6 @@ public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader {
|
||||
boolean rfbLoaded = Launch.blackboard.getOrDefault("angelica.rfbPluginLoaded", Boolean.FALSE) == Boolean.TRUE;
|
||||
if (!rfbLoaded) {
|
||||
tweaks.add("com.gtnewhorizons.angelica.loading.fml.tweakers.AngelicaLateTweaker");
|
||||
if (AngelicaConfig.enableSodium) {
|
||||
tweaks.add("com.gtnewhorizons.angelica.loading.fml.tweakers.SodiumLateTweaker");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,6 +170,19 @@ public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader {
|
||||
return IMixins.getEarlyMixins(Mixins.class, loadedCoreMods);
|
||||
}
|
||||
|
||||
private static void addLwjgl3ifyExclusions() {
|
||||
var handle = SharedConfig.getRfbTransformers().stream()
|
||||
.filter(transformer -> transformer.id().equals("lwjgl3ify:redirect"))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (handle != null) {
|
||||
handle.exclusions().add("org.embeddedt.embeddium");
|
||||
handle.exclusions().add("org.taumc.celeritas");
|
||||
handle.exclusions().add("com.mitchej123.lwjgl.lwjgl3");
|
||||
handle.exclusions().add("com.mitchej123.glsm");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if we are in an obfuscated environment, returns false in dev environment.
|
||||
*/
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ public class SodiumBlockTransformer implements IClassTransformer {
|
||||
public SodiumBlockTransformer() {
|
||||
this.inner = new SodiumBlockTransform(AngelicaTweaker.isObfEnv());
|
||||
this.exclusions = inner.getTransformerExclusions();
|
||||
this.inner.setSodiumSetting();
|
||||
this.inner.setCeleritasSetting();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.gtnewhorizons.angelica.loading.fml.tweakers;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLRelaunchLog;
|
||||
import net.minecraft.launchwrapper.ITweaker;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class SodiumLateTweaker implements ITweaker {
|
||||
|
||||
@Override
|
||||
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLaunchTarget() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getLaunchArguments() {
|
||||
String transformer = "com.gtnewhorizons.angelica.loading.fml.transformers.SodiumBlockTransformer";
|
||||
FMLRelaunchLog.finer("Registering transformer %s", transformer);
|
||||
Launch.classLoader.registerTransformer(transformer);
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
+10
-10
@@ -58,22 +58,22 @@ public class SodiumBlockTransform {
|
||||
// Block owners we *shouldn't* redirect because they shadow one of our fields
|
||||
private static final Set<String> blockOwnerExclusions = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
// Needed because the config is loaded in LaunchClassLoader, but we need to access it in the parent system loader.
|
||||
private static final MethodHandle angelicaConfigSodiumEnabledGetter;
|
||||
private static boolean isSodiumEnabled;
|
||||
private static final MethodHandle angelicaConfigCeleritasEnabledGetter;
|
||||
private static boolean isCeleritasEnabled;
|
||||
|
||||
static {
|
||||
try {
|
||||
final Class<?> angelicaConfig = Class.forName("com.gtnewhorizons.angelica.config.AngelicaConfig", true, Launch.classLoader);
|
||||
angelicaConfigSodiumEnabledGetter = MethodHandles.lookup().findStaticGetter(angelicaConfig, "enableSodium", boolean.class);
|
||||
angelicaConfigCeleritasEnabledGetter = MethodHandles.lookup().findStaticGetter(angelicaConfig, "enableCeleritas", boolean.class);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSodiumEnabled() {
|
||||
if (isSodiumEnabled) return true;
|
||||
private static boolean isCeleritasEnabled() {
|
||||
if (isCeleritasEnabled) return true;
|
||||
try {
|
||||
return (boolean) angelicaConfigSodiumEnabledGetter.invokeExact();
|
||||
return (boolean) angelicaConfigCeleritasEnabledGetter.invokeExact();
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -119,7 +119,7 @@ public class SodiumBlockTransform {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("net.minecraft.block.Block".equals(transformedName) && isSodiumEnabled()) {
|
||||
if ("net.minecraft.block.Block".equals(transformedName) && isCeleritasEnabled()) {
|
||||
cn.fields.removeIf(field -> BlockBoundsFields.stream().anyMatch(pair -> field.name.equals(pair.getLeft()) || field.name.equals(pair.getRight())));
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public class SodiumBlockTransform {
|
||||
for (MethodNode mn : cn.methods) {
|
||||
for (AbstractInsnNode node : mn.instructions.toArray()) {
|
||||
if ((node.getOpcode() == Opcodes.GETFIELD || node.getOpcode() == Opcodes.PUTFIELD) && node instanceof FieldInsnNode fNode) {
|
||||
if (!blockOwnerExclusions.contains(fNode.owner) && isBlockSubclass(fNode.owner) && isSodiumEnabled()) {
|
||||
if (!blockOwnerExclusions.contains(fNode.owner) && isBlockSubclass(fNode.owner) && isCeleritasEnabled()) {
|
||||
Pair<String, String> fieldToRedirect = BlockBoundsFields.stream()
|
||||
.filter(pair -> fNode.name.equals(getFieldName(pair)))
|
||||
.findFirst()
|
||||
@@ -206,7 +206,7 @@ public class SodiumBlockTransform {
|
||||
return changed;
|
||||
}
|
||||
|
||||
public void setSodiumSetting() {
|
||||
isSodiumEnabled = true;
|
||||
public void setCeleritasSetting() {
|
||||
isCeleritasEnabled = true;
|
||||
}
|
||||
}
|
||||
@@ -138,36 +138,52 @@ public enum Mixins implements IMixins {
|
||||
)
|
||||
),
|
||||
|
||||
SODIUM(new MixinBuilder()
|
||||
RENDERING_INFRASTRUCTURE(new MixinBuilder()
|
||||
.setPhase(Phase.EARLY)
|
||||
.setApplyIf(() -> AngelicaConfig.enableSodium)
|
||||
.setApplyIf(() -> AngelicaConfig.enableCeleritas)
|
||||
.addClientMixins(
|
||||
"sodium.MixinBlock"
|
||||
, "sodium.MixinBlockFluidBase"
|
||||
, "sodium.AccessorBiomeColorEvent"
|
||||
, "sodium.MixinBiomeGenBase"
|
||||
, "sodium.MixinChunk"
|
||||
, "sodium.MixinChunkProviderServer"
|
||||
, "sodium.MixinClientRegistry"
|
||||
, "sodium.MixinEntity_RenderDist"
|
||||
, "sodium.MixinEntityItem_RenderDist"
|
||||
, "sodium.MixinRenderManager"
|
||||
, "sodium.MixinEntityRenderer"
|
||||
, "sodium.MixinFMLClientHandler"
|
||||
, "sodium.MixinForgeHooksClient"
|
||||
, "sodium.MixinGameSettings"
|
||||
, "sodium.MixinFrustrum"
|
||||
, "sodium.MixinMinecraft"
|
||||
, "sodium.MixinRenderBlocks"
|
||||
, "sodium.MixinRenderGlobal"
|
||||
, "sodium.MixinWorldClient"
|
||||
, "sodium.MixinTileEntity"
|
||||
, "sodium.MixinTileEntityMobSpawner"
|
||||
, "sodium.MixinEffectRenderer"
|
||||
, "sodium.MixinTileEntityRendererDispatcher"
|
||||
, "sodium.MixinLongHashMap"
|
||||
, "sodium.MixinRenderingRegistry"
|
||||
, "sodium.MixinPlayerManager"
|
||||
"rendering.MixinBlock"
|
||||
, "rendering.MixinBlockFluidBase"
|
||||
, "rendering.AccessorBiomeColorEvent"
|
||||
, "rendering.MixinBiomeGenBase"
|
||||
, "rendering.MixinChunk"
|
||||
, "rendering.MixinChunkProviderServer"
|
||||
, "rendering.MixinClientRegistry"
|
||||
, "rendering.MixinEntity_RenderDist"
|
||||
, "rendering.MixinEntityItem_RenderDist"
|
||||
, "rendering.MixinEntityRenderer"
|
||||
, "rendering.MixinFMLClientHandler"
|
||||
, "rendering.MixinGameSettings"
|
||||
, "rendering.MixinLongHashMap"
|
||||
, "rendering.MixinMinecraft"
|
||||
, "rendering.MixinPlayerManager"
|
||||
, "rendering.MixinRenderBlocks"
|
||||
, "rendering.MixinRenderingRegistry"
|
||||
, "rendering.MixinTileEntity"
|
||||
, "rendering.MixinTileEntityMobSpawner"
|
||||
, "rendering.MixinTileEntityRendererDispatcher"
|
||||
)
|
||||
),
|
||||
|
||||
CELERITAS(new MixinBuilder()
|
||||
.setPhase(Phase.EARLY)
|
||||
.setApplyIf(() -> AngelicaConfig.enableCeleritas)
|
||||
.addClientMixins(
|
||||
"celeritas.terrain.MixinChunkProviderClient"
|
||||
, "celeritas.terrain.MixinMinecraft_ChunkUpdates"
|
||||
, "celeritas.terrain.MixinRenderGlobal"
|
||||
, "celeritas.terrain.MixinRenderSectionManager"
|
||||
, "celeritas.terrain.MixinWorldClient"
|
||||
, "celeritas.frustum.MixinFrustrum"
|
||||
, "celeritas.features.culling.MixinEffectRenderer"
|
||||
, "celeritas.features.mipmaps.MixinTextureAtlasSprite"
|
||||
, "celeritas.features.mipmaps.MixinTextureUtil"
|
||||
, "celeritas.features.textures.MixinTextureMap"
|
||||
, "celeritas.features.textures.MixinTextureAtlasSprite"
|
||||
, "celeritas.biome_blending.MixinBlockGrass"
|
||||
, "celeritas.biome_blending.MixinBlockLeaves"
|
||||
, "celeritas.biome_blending.MixinBlockLiquid"
|
||||
, "celeritas.threading.MixinForgeHooksClient"
|
||||
)
|
||||
),
|
||||
|
||||
@@ -209,7 +225,7 @@ public enum Mixins implements IMixins {
|
||||
|
||||
ANGELICA_TEXTURE(new MixinBuilder()
|
||||
.setPhase(Phase.EARLY)
|
||||
.setApplyIf(() -> AngelicaConfig.enableIris || AngelicaConfig.enableSodium)
|
||||
.setApplyIf(() -> AngelicaConfig.enableIris || AngelicaConfig.enableCeleritas)
|
||||
.addClientMixins(
|
||||
"angelica.textures.MixinTextureAtlasSprite"
|
||||
, "angelica.textures.MixinTextureUtil"
|
||||
@@ -250,13 +266,8 @@ public enum Mixins implements IMixins {
|
||||
.addClientMixins(
|
||||
"angelica.animation.MixinTextureAtlasSprite",
|
||||
"angelica.animation.MixinTextureMap",
|
||||
"angelica.animation.MixinBlockFire",
|
||||
"angelica.animation.MixinMinecraftForgeClient",
|
||||
"angelica.animation.MixinChunkCache",
|
||||
"angelica.animation.MixinRenderBlocks",
|
||||
"angelica.animation.MixinRenderBlockFluid",
|
||||
"angelica.animation.MixinWorldRenderer",
|
||||
"angelica.animation.MixinRenderItem")),
|
||||
"angelica.animation.MixinRenderBlocks")),
|
||||
|
||||
SCALED_RESOUTION_UNICODE_FIX(new MixinBuilder("Removes unicode languages gui scaling being forced to even values")
|
||||
.setPhase(Phase.EARLY)
|
||||
@@ -452,12 +463,12 @@ public enum Mixins implements IMixins {
|
||||
),
|
||||
MCPATCHER_FORGE_RENDERPASS_DISPLAYLIST(new MixinBuilder("RenderPass display list allocation increase")
|
||||
.setPhase(Phase.EARLY)
|
||||
.setApplyIf(() -> NotFineConfig.renderPass && !AngelicaConfig.enableSodium)
|
||||
.setApplyIf(() -> NotFineConfig.renderPass && !AngelicaConfig.enableCeleritas)
|
||||
.addClientMixins("mcpatcherforge.renderpass.MixinRenderGlobal_DisplayLists")
|
||||
),
|
||||
MCPATCHER_FORGE_RENDERPASS_FEATURES(new MixinBuilder("RenderPass rendering features")
|
||||
.setPhase(Phase.EARLY)
|
||||
.setApplyIf(() -> NotFineConfig.renderPass && !AngelicaConfig.enableSodium)
|
||||
.setApplyIf(() -> NotFineConfig.renderPass && !AngelicaConfig.enableCeleritas)
|
||||
.addClientMixins("mcpatcherforge.renderpass.MixinRenderGlobal_Features")
|
||||
),
|
||||
MCPATCHER_FORGE_CUSTOM_COLORS(new MixinBuilder()
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package com.gtnewhorizons.angelica.mixins.interfaces;
|
||||
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public interface EntityRendererAccessor {
|
||||
float invokeGetNightVisionBrightness(EntityPlayer entityPlayer, float partialTicks);
|
||||
|
||||
/**
|
||||
* Get the lightmap texture for shader binding.
|
||||
*/
|
||||
DynamicTexture getLightmapTexture();
|
||||
}
|
||||
+1
-4
@@ -1,12 +1,9 @@
|
||||
package com.gtnewhorizons.angelica.mixins.interfaces;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface IPatchedTextureAtlasSprite {
|
||||
|
||||
void markNeedsAnimationUpdate();
|
||||
|
||||
boolean needsAnimationUpdate();
|
||||
|
||||
void unmarkNeedsAnimationUpdate();
|
||||
|
||||
void updateAnimationsDryRun();
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.gtnewhorizons.angelica.mixins.interfaces;
|
||||
|
||||
public interface IRenderGlobalExt {
|
||||
void scheduleTerrainUpdate();
|
||||
void reload();
|
||||
|
||||
void angelica$scheduleTerrainUpdate();
|
||||
void angelica$reload();
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.gtnewhorizons.angelica.mixins.interfaces;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.Long2ReferenceMap;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
|
||||
public interface RenderSectionManagerAccessor {
|
||||
Long2ReferenceMap<RenderSection> angelica$getSectionByPosition();
|
||||
}
|
||||
@@ -20,6 +20,10 @@ import com.gtnewhorizons.angelica.hudcaching.HUDCaching;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.IGameSettingsExt;
|
||||
import com.gtnewhorizons.angelica.render.CloudRenderer;
|
||||
import com.gtnewhorizons.angelica.rendering.AngelicaBlockSafetyRegistry;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.CeleritasDebugScreenHandler;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.threading.ChunkTaskRegistry;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.threading.DefaultChunkTaskProvider;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.threading.ThreadedChunkTaskProvider;
|
||||
import com.gtnewhorizons.angelica.zoom.Zoom;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
@@ -35,7 +39,6 @@ import java.lang.management.ManagementFactory;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import jss.notfine.core.Settings;
|
||||
import me.jellysquid.mods.sodium.client.SodiumDebugScreenHandler;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.client.IrisDebugScreenHandler;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -59,7 +62,9 @@ import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import org.embeddedt.embeddium.impl.gl.device.GLRenderDevice;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
|
||||
public class ClientProxy extends CommonProxy {
|
||||
|
||||
@@ -84,7 +89,11 @@ public class ClientProxy extends CommonProxy {
|
||||
LOGGER.info("World loaded - Enabling GLSM Cache");
|
||||
}
|
||||
|
||||
if (AngelicaConfig.enableSodium) {
|
||||
if (AngelicaConfig.enableCeleritas) {
|
||||
ChunkTaskRegistry.reset();
|
||||
ChunkTaskRegistry.registerProvider(DefaultChunkTaskProvider.INSTANCE);
|
||||
ChunkTaskRegistry.registerProvider(ThreadedChunkTaskProvider.INSTANCE);
|
||||
|
||||
// Register all blocks. Because blockids are unique to a world, this must be done each load
|
||||
GameData.getBlockRegistry().typeSafeIterable().forEach(o -> {
|
||||
AngelicaBlockSafetyRegistry.canBlockRenderOffThread(o, true, true);
|
||||
@@ -102,8 +111,9 @@ public class ClientProxy extends CommonProxy {
|
||||
if (AngelicaConfig.enableHudCaching) {
|
||||
HUDCaching.init();
|
||||
}
|
||||
if (AngelicaConfig.enableSodium) {
|
||||
MinecraftForge.EVENT_BUS.register(SodiumDebugScreenHandler.INSTANCE);
|
||||
if (AngelicaConfig.enableCeleritas) {
|
||||
GLRenderDevice.VANILLA_STATE_RESETTER = () -> GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
MinecraftForge.EVENT_BUS.register(CeleritasDebugScreenHandler.INSTANCE);
|
||||
}
|
||||
if (AngelicaConfig.enableIris) {
|
||||
MinecraftForge.EVENT_BUS.register(IrisDebugScreenHandler.INSTANCE);
|
||||
@@ -145,7 +155,7 @@ public class ClientProxy extends CommonProxy {
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
super.postInit(event);
|
||||
|
||||
if (ModStatus.isLotrLoaded && AngelicaConfig.enableSodium && CompatConfig.fixLotr) {
|
||||
if (ModStatus.isLotrLoaded && AngelicaConfig.enableCeleritas && CompatConfig.fixLotr) {
|
||||
try {
|
||||
Class<?> lotrRendering = Class.forName("lotr.common.coremod.LOTRReplacedMethods$BlockRendering");
|
||||
ReflectionHelper.setPrivateValue(lotrRendering, null, new ConcurrentHashMap<>(), "naturalBlockClassTable");
|
||||
|
||||
@@ -11,6 +11,27 @@ public class AngelicaRenderQueue {
|
||||
private static final Thread MAIN_THREAD = Thread.currentThread();
|
||||
private static final Queue<Runnable> TASKS = new ConcurrentLinkedQueue<>();
|
||||
|
||||
// Metrics
|
||||
private static volatile int lastFrameTasksRan = 0;
|
||||
private static volatile long lastFrameTimeNs = 0;
|
||||
|
||||
public static int getQueueDepth() {
|
||||
return TASKS.size();
|
||||
}
|
||||
|
||||
public static int getLastFrameTasksRan() {
|
||||
return lastFrameTasksRan;
|
||||
}
|
||||
|
||||
public static long getLastFrameTimeNs() {
|
||||
return lastFrameTimeNs;
|
||||
}
|
||||
|
||||
public static void recordFrameStats(int tasksRan, long timeNs) {
|
||||
lastFrameTasksRan = tasksRan;
|
||||
lastFrameTimeNs = timeNs;
|
||||
}
|
||||
|
||||
private static final Executor EXECUTOR = (runnable) -> {
|
||||
if(Thread.currentThread() == MAIN_THREAD) {
|
||||
runnable.run();
|
||||
@@ -27,7 +48,7 @@ public class AngelicaRenderQueue {
|
||||
public static int processTasks(int max) {
|
||||
int tasksRun = 0;
|
||||
while(tasksRun < max) {
|
||||
Runnable r = TASKS.poll();
|
||||
final Runnable r = TASKS.poll();
|
||||
if(r == null)
|
||||
break;
|
||||
r.run();
|
||||
@@ -36,11 +57,7 @@ public class AngelicaRenderQueue {
|
||||
return tasksRun;
|
||||
}
|
||||
|
||||
public static int processTasks() {
|
||||
return processTasks(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
private static final long WAIT_TIME = TimeUnit.MILLISECONDS.toNanos(50);
|
||||
private static final long WAIT_TIME = TimeUnit.MILLISECONDS.toNanos(20);
|
||||
|
||||
public static void managedBlock(BooleanSupplier isDone) {
|
||||
while(!isDone.getAsBoolean()) {
|
||||
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.iris.BlockRenderContext;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.iris.IrisExtendedChunkVertexEncoder;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.WorldSlice;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import org.embeddedt.embeddium.impl.model.quad.properties.ModelQuadFacing;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderPassConfiguration;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildBuffers;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildContext;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.data.MinecraftBuiltRenderSectionData;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.sprite.SpriteTransparencyLevel;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexEncoder;
|
||||
import org.embeddedt.embeddium.impl.util.QuadUtil;
|
||||
|
||||
public class AngelicaChunkBuildContext extends ChunkBuildContext {
|
||||
public static final int NUM_PASSES = 2;
|
||||
|
||||
private final TextureMap textureMap;
|
||||
private final ChunkVertexEncoder.Vertex[] vertices = ChunkVertexEncoder.Vertex.uninitializedQuad();
|
||||
@Getter
|
||||
private final WorldSlice worldSlice;
|
||||
private final BlockRenderContext blockRenderContext = new BlockRenderContext();
|
||||
|
||||
public AngelicaChunkBuildContext(RenderPassConfiguration<?> renderPassConfiguration, WorldClient world) {
|
||||
super(renderPassConfiguration);
|
||||
this.textureMap = Minecraft.getMinecraft().getTextureMapBlocks();
|
||||
this.worldSlice = new WorldSlice(world);
|
||||
}
|
||||
|
||||
public BlockRenderContext getBlockRenderContext() {
|
||||
return this.blockRenderContext;
|
||||
}
|
||||
|
||||
private Material selectMaterial(Material material, TextureAtlasSprite sprite) {
|
||||
if (sprite != null && sprite.getClass() == TextureAtlasSprite.class && !sprite.hasAnimationMetadata()) {
|
||||
final var transparencyLevel = ((SpriteExtension)sprite).celeritas$getTransparencyLevel();
|
||||
if (transparencyLevel == SpriteTransparencyLevel.OPAQUE && material == AngelicaRenderPassConfiguration.CUTOUT_MIPPED_MATERIAL) {
|
||||
// Downgrade to solid
|
||||
return AngelicaRenderPassConfiguration.SOLID_MATERIAL;
|
||||
} else if (material == AngelicaRenderPassConfiguration.TRANSLUCENT_MATERIAL && transparencyLevel != SpriteTransparencyLevel.TRANSLUCENT) {
|
||||
// Downgrade to cutout
|
||||
return AngelicaRenderPassConfiguration.CUTOUT_MIPPED_MATERIAL;
|
||||
}
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void copyRawBuffer(int[] rawBuffer, int vertexCount, ChunkBuildBuffers buffers, Material material,
|
||||
int originX, int originY, int originZ) {
|
||||
if (vertexCount == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final var animatedSprites = ((MinecraftBuiltRenderSectionData<TextureAtlasSprite, TileEntity>)buffers.getSectionContextBundle()).animatedSprites;
|
||||
|
||||
if ((vertexCount & 0x3) != 0) {
|
||||
throw new IllegalStateException("Only quads are supported, got: " + vertexCount);
|
||||
}
|
||||
|
||||
final DynamicLights dynamicLights = DynamicLights.isEnabled() ? DynamicLights.get() : null;
|
||||
|
||||
final var encoder = buffers.get(material).getEncoder();
|
||||
if (encoder instanceof IrisExtendedChunkVertexEncoder iris) {
|
||||
iris.setContext(blockRenderContext);
|
||||
}
|
||||
|
||||
int ptr = 0;
|
||||
final int numQuads = vertexCount / 4;
|
||||
|
||||
for (int quadIdx = 0; quadIdx < numQuads; quadIdx++) {
|
||||
float uSum = 0, vSum = 0;
|
||||
|
||||
for (int vIdx = 0; vIdx < 4; vIdx++) {
|
||||
final var vertex = vertices[vIdx];
|
||||
vertex.x = Float.intBitsToFloat(rawBuffer[ptr++]);
|
||||
vertex.y = Float.intBitsToFloat(rawBuffer[ptr++]);
|
||||
vertex.z = Float.intBitsToFloat(rawBuffer[ptr++]);
|
||||
|
||||
final float u = Float.intBitsToFloat(rawBuffer[ptr++]);
|
||||
final float v = Float.intBitsToFloat(rawBuffer[ptr++]);
|
||||
vertex.u = u;
|
||||
uSum += u;
|
||||
vertex.v = v;
|
||||
vSum += v;
|
||||
|
||||
vertex.color = rawBuffer[ptr++];
|
||||
vertex.vanillaNormal = rawBuffer[ptr++];
|
||||
vertex.light = rawBuffer[ptr++];
|
||||
|
||||
if (dynamicLights != null) {
|
||||
final double dynamicLevel = dynamicLights.getDynamicLightLevel(originX + vertex.x, originY + vertex.y, originZ + vertex.z);
|
||||
if (dynamicLevel > 0) {
|
||||
vertex.light = dynamicLights.getLightmapWithDynamicLight(dynamicLevel, vertex.light);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final int trueNormal = QuadUtil.calculateNormal(vertices);
|
||||
for (int vIdx = 0; vIdx < 4; vIdx++) {
|
||||
vertices[vIdx].trueNormal = trueNormal;
|
||||
}
|
||||
|
||||
final ModelQuadFacing facing = QuadUtil.findNormalFace(trueNormal);
|
||||
final TextureAtlasSprite sprite = ((TextureMapExtension) textureMap).celeritas$findFromUV(uSum * 0.25f, vSum * 0.25f);
|
||||
|
||||
if (sprite != null && sprite.hasAnimationMetadata()) {
|
||||
animatedSprites.add(sprite);
|
||||
}
|
||||
|
||||
final Material correctMaterial = selectMaterial(material, sprite);
|
||||
final var builder = buffers.get(correctMaterial);
|
||||
|
||||
if (correctMaterial != material && builder.getEncoder() instanceof IrisExtendedChunkVertexEncoder iris) {
|
||||
iris.setContext(blockRenderContext);
|
||||
}
|
||||
|
||||
builder.getVertexBuffer(facing).push(vertices, correctMaterial);
|
||||
}
|
||||
}
|
||||
}
|
||||
+287
@@ -0,0 +1,287 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.blockpos.BlockPos;
|
||||
import com.gtnewhorizons.angelica.compat.toremove.RenderLayer;
|
||||
import com.gtnewhorizons.angelica.rendering.AngelicaRenderQueue;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProvider;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProviderHolder;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.iris.BlockRenderContext;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.iris.ContextAwareChunkVertexEncoder;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceMap;
|
||||
import net.coderbot.iris.vertices.ExtendedDataHelper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildBuffers;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildContext;
|
||||
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.BuiltSectionMeshParts;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.data.MinecraftBuiltRenderSectionData;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.occlusion.SectionVisibilityBuilder;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||
import org.embeddedt.embeddium.impl.util.task.CancellationToken;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public abstract class AngelicaChunkBuilderMeshingTask extends ChunkBuilderTask<ChunkBuildOutput> {
|
||||
protected final RenderSection render;
|
||||
protected final int buildTime;
|
||||
protected final Vector3d camera;
|
||||
|
||||
protected record DeferredBlock(int x, int y, int z, Block block, int meta, int pass) {}
|
||||
|
||||
public AngelicaChunkBuilderMeshingTask(RenderSection render, int time, Vector3d camera) {
|
||||
this.render = render;
|
||||
this.buildTime = time;
|
||||
this.camera = camera;
|
||||
}
|
||||
|
||||
protected abstract Tessellator getTessellator();
|
||||
protected abstract void setRenderPass(int pass);
|
||||
protected abstract IBlockAccess getBlockAccess();
|
||||
protected abstract SmoothBiomeColorCache getBiomeColorCache();
|
||||
|
||||
protected boolean isThreaded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean canRenderOffThread(Block block) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void onEnterExecute() {}
|
||||
|
||||
protected void onExitExecute() {}
|
||||
|
||||
protected void addExtraCrashInfo(CrashReportCategory category) {}
|
||||
|
||||
@Override
|
||||
public ChunkBuildOutput execute(ChunkBuildContext context, CancellationToken cancellationToken) {
|
||||
final AngelicaChunkBuildContext buildContext = (AngelicaChunkBuildContext) context;
|
||||
final MinecraftBuiltRenderSectionData<TextureAtlasSprite, TileEntity> renderData = new MinecraftBuiltRenderSectionData<>();
|
||||
final SectionVisibilityBuilder occluder = new SectionVisibilityBuilder();
|
||||
|
||||
final ChunkBuildBuffers buffers = buildContext.buffers;
|
||||
buffers.init(renderData, this.render.getSectionIndex());
|
||||
|
||||
final int minX = this.render.getOriginX();
|
||||
final int minY = this.render.getOriginY();
|
||||
final int minZ = this.render.getOriginZ();
|
||||
|
||||
final int maxX = minX + 16;
|
||||
final int maxY = minY + 16;
|
||||
final int maxZ = minZ + 16;
|
||||
|
||||
final BlockPos blockPos = new BlockPos(minX, minY, minZ);
|
||||
final IBlockAccess region = getBlockAccess();
|
||||
final SmoothBiomeColorCache biomeColorCache = getBiomeColorCache();
|
||||
|
||||
onEnterExecute();
|
||||
|
||||
final Tessellator tessellator = getTessellator();
|
||||
|
||||
try {
|
||||
tessellator.setTranslation(-minX, -minY, -minZ);
|
||||
SmoothBiomeColorCache.setActiveCache(biomeColorCache);
|
||||
|
||||
final IrisShaderProvider provider = IrisShaderProviderHolder.getProvider();
|
||||
final Map<Block, RenderLayer> blockTypeIds = provider != null ? provider.getBlockTypeIds() : null;
|
||||
final BlockRenderContext blockRenderContext = buildContext.getBlockRenderContext();
|
||||
|
||||
final boolean threaded = isThreaded();
|
||||
final List<DeferredBlock> deferredBlocks = threaded ? new ArrayList<>() : null;
|
||||
|
||||
final RenderBlocks renderBlocks = new RenderBlocks(region);
|
||||
|
||||
for (int y = minY; y < maxY; y++) {
|
||||
if (cancellationToken.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int z = minZ; z < maxZ; z++) {
|
||||
for (int x = minX; x < maxX; x++) {
|
||||
blockPos.set(x, y, z);
|
||||
|
||||
final Block block = region.getBlock(x, y, z);
|
||||
|
||||
if (block == Blocks.air) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final int meta = region.getBlockMetadata(x, y, z);
|
||||
|
||||
if (block.hasTileEntity(meta)) {
|
||||
final TileEntity tileEntity = region.getTileEntity(x, y, z);
|
||||
if (TileEntityRendererDispatcher.instance.hasSpecialRenderer(tileEntity)) {
|
||||
renderData.globalBlockEntities.add(tileEntity);
|
||||
}
|
||||
}
|
||||
|
||||
final boolean canRenderOffThread = !threaded || canRenderOffThread(block);
|
||||
|
||||
for (int pass = 0; pass < AngelicaChunkBuildContext.NUM_PASSES; pass++) {
|
||||
boolean canRender = block.canRenderInPass(pass);
|
||||
|
||||
// Shader pack can override render layer via block.properties
|
||||
if (blockTypeIds != null) {
|
||||
final RenderLayer overrideLayer = blockTypeIds.get(block);
|
||||
if (overrideLayer != null) {
|
||||
canRender = switch (pass) {
|
||||
case 0 -> overrideLayer == RenderLayer.cutout();
|
||||
case 1 -> overrideLayer == RenderLayer.translucent();
|
||||
default -> canRender;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (canRender) {
|
||||
if (!canRenderOffThread) {
|
||||
deferredBlocks.add(new DeferredBlock(x, y, z, block, meta, pass));
|
||||
continue;
|
||||
}
|
||||
|
||||
renderBlock(block, x, y, z, pass, tessellator, renderBlocks,
|
||||
buffers, buildContext, blockRenderContext, minX, minY, minZ);
|
||||
}
|
||||
}
|
||||
|
||||
if (block.isOpaqueCube()) {
|
||||
occluder.markOpaque(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process deferred blocks on main thread if any
|
||||
if (deferredBlocks != null && !deferredBlocks.isEmpty()) {
|
||||
processDeferredBlocks(deferredBlocks, buildContext, buffers, region, minX, minY, minZ);
|
||||
}
|
||||
|
||||
final Reference2ReferenceMap<TerrainRenderPass, BuiltSectionMeshParts> meshes =
|
||||
BuiltSectionMeshParts.groupFromBuildBuffers(buffers,
|
||||
(float) camera.x - minX, (float) camera.y - minY, (float) camera.z - minZ);
|
||||
|
||||
if (!meshes.isEmpty()) {
|
||||
renderData.hasBlockGeometry = true;
|
||||
}
|
||||
|
||||
renderData.visibilityData = occluder.computeVisibilityEncoding();
|
||||
|
||||
SmoothBiomeColorCache.clearActiveCache();
|
||||
tessellator.setTranslation(0, 0, 0);
|
||||
|
||||
CeleritasDebug.incrementChunkUpdateCounter();
|
||||
|
||||
return new ChunkBuildOutput(this.render, renderData, meshes, this.buildTime);
|
||||
|
||||
} catch (ReportedException ex) {
|
||||
throw fillCrashInfo(ex.getCrashReport(), region, blockPos);
|
||||
} catch (Throwable ex) {
|
||||
throw fillCrashInfo(CrashReport.makeCrashReport(ex, "Encountered exception while building chunk meshes"), region, blockPos);
|
||||
} finally {
|
||||
SmoothBiomeColorCache.clearActiveCache();
|
||||
onExitExecute();
|
||||
}
|
||||
}
|
||||
|
||||
protected void renderBlock(Block block, int x, int y, int z, int pass, Tessellator tessellator, RenderBlocks renderBlocks, ChunkBuildBuffers buffers, AngelicaChunkBuildContext buildContext, BlockRenderContext blockRenderContext, int originX, int originY, int originZ) {
|
||||
|
||||
final Material blockMaterial = block.getMaterial();
|
||||
final boolean isFluid = blockMaterial == Material.water || blockMaterial == Material.lava;
|
||||
|
||||
// Lava is opaque - use solid to skip unnecessary alpha testing
|
||||
final var passMaterial = blockMaterial == Material.lava ? AngelicaRenderPassConfiguration.SOLID_MATERIAL : buffers.getRenderPassConfiguration().getMaterialForRenderType(BlockRenderLayer.fromVanillaPass(pass));
|
||||
|
||||
final var encoder = buffers.get(passMaterial).getEncoder();
|
||||
final ContextAwareChunkVertexEncoder contextEncoder = (encoder instanceof ContextAwareChunkVertexEncoder) ? (ContextAwareChunkVertexEncoder) encoder : null;
|
||||
|
||||
if (contextEncoder != null) {
|
||||
blockRenderContext.localPosX = x & 15;
|
||||
blockRenderContext.localPosY = y & 15;
|
||||
blockRenderContext.localPosZ = z & 15;
|
||||
final byte lightValue = (byte) block.getLightValue();
|
||||
if (isFluid) {
|
||||
contextEncoder.prepareToRenderFluid(blockRenderContext, block, lightValue);
|
||||
} else {
|
||||
contextEncoder.prepareToRenderBlock(blockRenderContext, block,
|
||||
ExtendedDataHelper.BLOCK_RENDER_TYPE, lightValue);
|
||||
}
|
||||
}
|
||||
|
||||
setRenderPass(pass);
|
||||
tessellator.startDrawingQuads();
|
||||
renderBlocks.renderBlockByRenderType(block, x, y, z);
|
||||
buildContext.copyRawBuffer(tessellator.rawBuffer, tessellator.vertexCount, buffers,
|
||||
passMaterial, originX, originY, originZ);
|
||||
tessellator.reset();
|
||||
tessellator.isDrawing = false;
|
||||
|
||||
if (contextEncoder != null) {
|
||||
contextEncoder.finishRenderingBlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void processDeferredBlocks(List<DeferredBlock> deferredBlocks, AngelicaChunkBuildContext buildContext, ChunkBuildBuffers buffers, IBlockAccess region, int minX, int minY, int minZ) {
|
||||
|
||||
final BlockRenderContext blockRenderContext = buildContext.getBlockRenderContext();
|
||||
|
||||
final CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
|
||||
final RenderBlocks mainThreadRenderBlocks = new RenderBlocks(region);
|
||||
final Tessellator mainTessellator = Tessellator.instance;
|
||||
mainTessellator.setTranslation(-minX, -minY, -minZ);
|
||||
|
||||
for (DeferredBlock deferred : deferredBlocks) {
|
||||
renderBlock(deferred.block(), deferred.x(), deferred.y(), deferred.z(), deferred.pass(),
|
||||
mainTessellator, mainThreadRenderBlocks, buffers, buildContext,
|
||||
blockRenderContext, minX, minY, minZ);
|
||||
}
|
||||
|
||||
mainTessellator.setTranslation(0, 0, 0);
|
||||
}, AngelicaRenderQueue.executor());
|
||||
|
||||
try {
|
||||
future.get();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException("Interrupted during deferred block rendering", e);
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException("Error during main thread deferred block rendering", e);
|
||||
}
|
||||
}
|
||||
|
||||
private ReportedException fillCrashInfo(CrashReport report, IBlockAccess slice, BlockPos pos) {
|
||||
final CrashReportCategory crashReportSection = report.makeCategory("Block being rendered");
|
||||
|
||||
Block block = Blocks.air;
|
||||
int meta = 0;
|
||||
try {
|
||||
block = slice.getBlock(pos.x, pos.y, pos.z);
|
||||
meta = slice.getBlockMetadata(pos.x, pos.y, pos.z);
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
crashReportSection.addCrashSection("Block", block);
|
||||
crashReportSection.addCrashSection("Block location", String.format("World: (%d,%d,%d)", pos.x, pos.y, pos.z));
|
||||
crashReportSection.addCrashSection("Block meta", meta);
|
||||
crashReportSection.addCrashSection("Chunk section", this.render);
|
||||
|
||||
addExtraCrashInfo(crashReportSection);
|
||||
|
||||
return new ReportedException(report);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProvider;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProviderHolder;
|
||||
import org.embeddedt.embeddium.impl.gl.device.RenderDevice;
|
||||
import org.embeddedt.embeddium.impl.gl.shader.GlProgram;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.DefaultChunkRenderer;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderPassConfiguration;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderInterface;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderTextureSlot;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||
|
||||
class AngelicaChunkRenderer extends DefaultChunkRenderer {
|
||||
private GlProgram<? extends ChunkShaderInterface> irisProgram;
|
||||
private boolean usingIrisProgram;
|
||||
|
||||
public AngelicaChunkRenderer(RenderDevice device, RenderPassConfiguration<?> renderPassConfiguration) {
|
||||
super(device, renderPassConfiguration);
|
||||
|
||||
final IrisShaderProvider provider = IrisShaderProviderHolder.getProvider();
|
||||
if (provider != null) {
|
||||
provider.setRenderPassConfiguration(renderPassConfiguration);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void begin(TerrainRenderPass pass) {
|
||||
final IrisShaderProvider provider = IrisShaderProviderHolder.getProvider();
|
||||
|
||||
// Check if Iris shaders are active and we have an override
|
||||
if (provider != null && provider.isShadersEnabled()) {
|
||||
final GlProgram<? extends ChunkShaderInterface> override = provider.getShaderOverride(pass);
|
||||
if (override != null) {
|
||||
pass.startDrawing();
|
||||
override.bind();
|
||||
override.getInterface().setupState(pass);
|
||||
this.activeProgram = (GlProgram<ChunkShaderInterface>) override;
|
||||
this.irisProgram = override;
|
||||
this.usingIrisProgram = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to default shader
|
||||
this.usingIrisProgram = false;
|
||||
this.irisProgram = null;
|
||||
super.begin(pass);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void end(TerrainRenderPass pass) {
|
||||
if (usingIrisProgram && irisProgram != null) {
|
||||
irisProgram.getInterface().restoreState();
|
||||
irisProgram.unbind();
|
||||
irisProgram = null;
|
||||
usingIrisProgram = false;
|
||||
this.activeProgram = null;
|
||||
pass.endDrawing();
|
||||
return;
|
||||
}
|
||||
|
||||
super.end(pass);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean useBlockFaceCulling() {
|
||||
return IrisShaderProviderHolder.shouldUseFaceCulling();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureShaderInterface(ChunkShaderInterface shader) {
|
||||
if (!usingIrisProgram) {
|
||||
shader.setTextureSlot(ChunkShaderTextureSlot.BLOCK, 0);
|
||||
shader.setTextureSlot(ChunkShaderTextureSlot.LIGHT, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.threading.RenderPassHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.world.ChunkCache;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.util.position.SectionPos;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public class AngelicaMainThreadMeshingTask extends AngelicaChunkBuilderMeshingTask {
|
||||
|
||||
private IBlockAccess blockAccess;
|
||||
private SmoothBiomeColorCache biomeColorCache;
|
||||
|
||||
public AngelicaMainThreadMeshingTask(RenderSection render, int time, Vector3d camera) {
|
||||
super(render, time, camera);
|
||||
initBlockAccess();
|
||||
}
|
||||
|
||||
private void initBlockAccess() {
|
||||
final int minX = this.render.getOriginX();
|
||||
final int minY = this.render.getOriginY();
|
||||
final int minZ = this.render.getOriginZ();
|
||||
|
||||
final var world = Minecraft.getMinecraft().theWorld;
|
||||
this.biomeColorCache = ((WorldClientExtension) world).celeritas$getSmoothBiomeColorCache();
|
||||
this.biomeColorCache.update(new SectionPos(this.render.getChunkX(), this.render.getChunkY(), this.render.getChunkZ()));
|
||||
this.blockAccess = new ChunkCache(world, minX - 1, minY - 1, minZ - 1, minX + 17, minY + 17, minZ + 17, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Tessellator getTessellator() {
|
||||
return Tessellator.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setRenderPass(int pass) {
|
||||
RenderPassHelper.setWorldRenderPass(pass);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IBlockAccess getBlockAccess() {
|
||||
return blockAccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SmoothBiomeColorCache getBiomeColorCache() {
|
||||
return biomeColorCache;
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderPassConfiguration;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.sorting.QuadPrimitiveType;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.parameters.AlphaCutoffParameter;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AngelicaRenderPassConfiguration {
|
||||
|
||||
public static TerrainRenderPass SOLID_PASS, CUTOUT_MIPPED_PASS, TRANSLUCENT_PASS;
|
||||
public static Material SOLID_MATERIAL, CUTOUT_MIPPED_MATERIAL, TRANSLUCENT_MATERIAL;
|
||||
|
||||
private record AngelicaPipelineState(int pass, boolean disableAlphaTest) implements TerrainRenderPass.PipelineState {
|
||||
@Override
|
||||
public void setup() {
|
||||
if (pass == 0) {
|
||||
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
|
||||
}
|
||||
if (disableAlphaTest) {
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if (disableAlphaTest) {
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static TerrainRenderPass.TerrainRenderPassBuilder builderForRenderType(int pass, boolean disableAlphaTest, ChunkVertexType vertexType) {
|
||||
return TerrainRenderPass.builder()
|
||||
.pipelineState(new AngelicaPipelineState(pass, disableAlphaTest))
|
||||
.vertexType(vertexType)
|
||||
.primitiveType(QuadPrimitiveType.DIRECT);
|
||||
}
|
||||
|
||||
public static RenderPassConfiguration<BlockRenderLayer> build(ChunkVertexType vertexType) {
|
||||
SOLID_PASS = builderForRenderType(0, true, vertexType)
|
||||
.name("solid")
|
||||
.fragmentDiscard(false)
|
||||
.useReverseOrder(false)
|
||||
.build();
|
||||
|
||||
CUTOUT_MIPPED_PASS = builderForRenderType(0, false, vertexType)
|
||||
.name("cutout_mipped")
|
||||
.fragmentDiscard(true)
|
||||
.useReverseOrder(false)
|
||||
.build();
|
||||
|
||||
TRANSLUCENT_PASS = builderForRenderType(1, false, vertexType)
|
||||
.name("translucent")
|
||||
.fragmentDiscard(false)
|
||||
.useReverseOrder(true)
|
||||
.useTranslucencySorting(true)
|
||||
.build();
|
||||
|
||||
TRANSLUCENT_MATERIAL = new Material(TRANSLUCENT_PASS, AlphaCutoffParameter.ZERO, true);
|
||||
SOLID_MATERIAL = new Material(SOLID_PASS, AlphaCutoffParameter.ZERO, true);
|
||||
CUTOUT_MIPPED_MATERIAL = new Material(CUTOUT_MIPPED_PASS, AlphaCutoffParameter.ONE_TENTH, true);
|
||||
|
||||
final ImmutableListMultimap.Builder<BlockRenderLayer, TerrainRenderPass> vanillaRenderStages = ImmutableListMultimap.builder();
|
||||
vanillaRenderStages.put(BlockRenderLayer.TRANSLUCENT, TRANSLUCENT_PASS);
|
||||
vanillaRenderStages.put(BlockRenderLayer.SOLID, SOLID_PASS);
|
||||
vanillaRenderStages.put(BlockRenderLayer.SOLID, CUTOUT_MIPPED_PASS);
|
||||
|
||||
// Material lookup by terrain layer
|
||||
final Map<BlockRenderLayer, Material> renderTypeToMaterialMap = new Reference2ReferenceOpenHashMap<>(4, Reference2ReferenceOpenHashMap.VERY_FAST_LOAD_FACTOR);
|
||||
renderTypeToMaterialMap.put(BlockRenderLayer.SOLID, CUTOUT_MIPPED_MATERIAL);
|
||||
renderTypeToMaterialMap.put(BlockRenderLayer.TRANSLUCENT, TRANSLUCENT_MATERIAL);
|
||||
|
||||
return new RenderPassConfiguration<>(renderTypeToMaterialMap, vanillaRenderStages.build().asMap(), CUTOUT_MIPPED_MATERIAL, CUTOUT_MIPPED_MATERIAL, TRANSLUCENT_MATERIAL);
|
||||
}
|
||||
}
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizons.angelica.rendering.AngelicaRenderQueue;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProviderHolder;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.threading.ChunkTaskProvider;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.threading.ChunkTaskRegistry;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ClonedChunkSectionCache;
|
||||
import me.jellysquid.mods.sodium.client.SodiumClientMod;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import org.embeddedt.embeddium.impl.gl.device.CommandList;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.ChunkRenderMatrices;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderPassConfiguration;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSectionManager;
|
||||
import org.embeddedt.embeddium.impl.render.viewport.CameraTransform;
|
||||
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.lists.SectionTicker;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.occlusion.AsyncOcclusionMode;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.sprite.GenericSectionSpriteTicker;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
||||
import org.embeddedt.embeddium.impl.render.viewport.Viewport;
|
||||
import org.embeddedt.embeddium.impl.util.PositionUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.RenderSectionManagerAccessor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class AngelicaRenderSectionManager extends RenderSectionManager {
|
||||
private boolean initialCameraSectionReady = false;
|
||||
|
||||
private final WorldClient world;
|
||||
private final ClonedChunkSectionCache sectionCache;
|
||||
private final ChunkTaskProvider taskProvider;
|
||||
|
||||
public AngelicaRenderSectionManager(RenderPassConfiguration<?> configuration, WorldClient world, int renderDistance, CommandList commandList, int minSection, int maxSection, int requestedThreads, ChunkTaskProvider taskProvider) {
|
||||
super(configuration, () -> new AngelicaChunkBuildContext(configuration, world), AngelicaChunkRenderer::new, renderDistance, commandList, minSection, maxSection, requestedThreads, true /* hasShadowPass = true for Iris */);
|
||||
this.world = world;
|
||||
this.sectionCache = new ClonedChunkSectionCache(world);
|
||||
this.taskProvider = taskProvider;
|
||||
}
|
||||
|
||||
public static AngelicaRenderSectionManager create(ChunkVertexType vertexType, WorldClient world, int renderDistance, CommandList commandList) {
|
||||
final ChunkTaskProvider provider = ChunkTaskRegistry.getActiveProvider();
|
||||
return new AngelicaRenderSectionManager(AngelicaRenderPassConfiguration.build(vertexType), world, renderDistance, commandList, 0, 16, provider.threadCount(), provider);
|
||||
}
|
||||
|
||||
public void setCameraPosition(double x, double y, double z) {
|
||||
this.cameraPosition.set(x, y, z);
|
||||
}
|
||||
|
||||
private boolean isChunkNotLoaded(int chunkX, int chunkZ) {
|
||||
return this.world.getChunkFromChunkCoords(chunkX, chunkZ).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSectionAdded(int x, int y, int z) {
|
||||
super.onSectionAdded(x, y, z);
|
||||
|
||||
// If chunk isn't actually loaded (EmptyChunk placeholder), make sections opaque for main pass.
|
||||
// This prevents BFS from traversing through chunks we haven't received from the server.
|
||||
if (isChunkNotLoaded(x, z)) {
|
||||
renderListManager.updateVisibilityData(x, y, z, 0L);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Viewport positionedViewport, int frame, boolean spectator) {
|
||||
if (!isInShadowPass() && !initialCameraSectionReady) {
|
||||
var origin = positionedViewport.getChunkCoord();
|
||||
long key = PositionUtil.packSection(origin.x(), origin.y(), origin.z());
|
||||
if (!((RenderSectionManagerAccessor) this).angelica$getSectionByPosition().containsKey(key)) {
|
||||
return;
|
||||
}
|
||||
initialCameraSectionReady = true;
|
||||
}
|
||||
super.update(positionedViewport, frame, spectator);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AsyncOcclusionMode getAsyncOcclusionMode() {
|
||||
return AsyncOcclusionMode.EVERYTHING;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldRespectUpdateTaskQueueSizeLimit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean useFogOcclusion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDebugInfoShown() {
|
||||
return Minecraft.getMinecraft().gameSettings.showDebugInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldUseOcclusionCulling(Viewport positionedViewport, boolean spectator) {
|
||||
if (!spectator) return true;
|
||||
|
||||
final var camBlockPos = positionedViewport.getBlockCoord();
|
||||
return !this.world.getBlock(camBlockPos.x(), camBlockPos.y(), camBlockPos.z()).isOpaqueCube();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSectionVisuallyEmpty(int x, int y, int z) {
|
||||
final Chunk chunk = this.world.getChunkFromChunkCoords(x, z);
|
||||
if (chunk.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
final var array = chunk.getBlockStorageArray();
|
||||
if (y < 0 || y >= array.length) {
|
||||
return true;
|
||||
}
|
||||
return array[y] == null || array[y].isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable ChunkBuilderTask<ChunkBuildOutput> createRebuildTask(RenderSection render, int frame) {
|
||||
if (isSectionVisuallyEmpty(render.getChunkX(), render.getChunkY(), render.getChunkZ())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.taskProvider.createRebuildTask(render, frame, this.cameraPosition, this.sectionCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void invalidateCachedSectionData(RenderSection section) {
|
||||
super.invalidateCachedSectionData(section);
|
||||
this.sectionCache.invalidate(section.getChunkX(), section.getChunkY(), section.getChunkZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateChunks(boolean updateImmediately) {
|
||||
this.sectionCache.cleanup();
|
||||
super.updateChunks(updateImmediately);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean allowImportantRebuilds() {
|
||||
return !SodiumClientMod.options().performance.alwaysDeferChunkUpdates;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable SectionTicker createSectionTicker() {
|
||||
return new GenericSectionSpriteTicker<>(AngelicaRenderSectionManager::markSpriteActive);
|
||||
}
|
||||
|
||||
private static void markSpriteActive(TextureAtlasSprite sprite) {
|
||||
((SpriteExtension) sprite).celeritas$markActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInShadowPass() {
|
||||
return IrisShaderProviderHolder.isShadowPass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getDebugStrings() {
|
||||
List<String> list = new ArrayList<>(super.getDebugStrings());
|
||||
|
||||
// Add thread info
|
||||
var builder = getBuilder();
|
||||
int busyThreads = builder.getBusyThreadCount();
|
||||
int totalThreads = builder.getTotalThreadCount();
|
||||
|
||||
if (totalThreads > 0) {
|
||||
list.add(String.format("Chunk Workers: %d/%d busy", busyThreads, totalThreads));
|
||||
} else {
|
||||
list.add("Chunk Workers: single-threaded");
|
||||
}
|
||||
|
||||
// Main thread queue metrics
|
||||
final int queueDepth = AngelicaRenderQueue.getQueueDepth();
|
||||
final int tasksRan = AngelicaRenderQueue.getLastFrameTasksRan();
|
||||
final double mtTimeMs = AngelicaRenderQueue.getLastFrameTimeNs() / 1_000_000.0;
|
||||
list.add(String.format("MT Queue: %d, ran %d (%.1fms)", queueDepth, tasksRan, mtTimeMs));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderLayer(ChunkRenderMatrices matrices, TerrainRenderPass pass, CameraTransform occlusionCamera, CameraTransform camera) {
|
||||
// Shadow pass graph update is async - must wait for it to complete before rendering
|
||||
if (IrisShaderProviderHolder.isShadowPass()) {
|
||||
finishAllGraphUpdates();
|
||||
}
|
||||
super.renderLayer(matrices, pass, occlusionCamera, camera);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
public enum BlockRenderLayer {
|
||||
SOLID, // vanilla pass 0
|
||||
TRANSLUCENT; // vanilla pass 1
|
||||
|
||||
private static final BlockRenderLayer[] VALUES = values();
|
||||
|
||||
public static BlockRenderLayer fromVanillaPass(int pass) {
|
||||
return VALUES[pass];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class CeleritasDebug {
|
||||
private static final AtomicInteger chunkUpdateCounter = new AtomicInteger(0);
|
||||
|
||||
public static void incrementChunkUpdateCounter() {
|
||||
chunkUpdateCounter.getAndIncrement();
|
||||
}
|
||||
|
||||
public static int readAndResetChunkUpdateCounter() {
|
||||
return chunkUpdateCounter.getAndSet(0);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizons.angelica.Tags;
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
|
||||
public class CeleritasDebugScreenHandler {
|
||||
public static final CeleritasDebugScreenHandler INSTANCE = new CeleritasDebugScreenHandler();
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOW)
|
||||
public void onRenderGameOverlayTextEvent(RenderGameOverlayEvent.Text event) {
|
||||
final Minecraft mc = Minecraft.getMinecraft();
|
||||
if (!mc.gameSettings.showDebugInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CeleritasWorldRenderer renderer = CeleritasWorldRenderer.getInstance();
|
||||
if (renderer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.right.add("");
|
||||
event.right.add(EnumChatFormatting.GREEN + "Angelica " + Tags.VERSION + " [Celeritas Renderer]");
|
||||
event.right.addAll(renderer.getDebugStrings());
|
||||
event.right.add("");
|
||||
}
|
||||
}
|
||||
+269
@@ -0,0 +1,269 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.IDynamicLightWorldRenderer;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.rendering.RenderingState;
|
||||
import net.coderbot.iris.pipeline.ShadowRenderer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.embeddedt.embeddium.impl.gl.device.CommandList;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.ChunkRenderMatrices;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.data.MinecraftBuiltRenderSectionData;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.lists.ChunkRenderList;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.lists.SortedRenderLists;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkMeshFormats;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProvider;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProviderHolder;
|
||||
import me.jellysquid.mods.sodium.client.SodiumClientMod;
|
||||
import org.embeddedt.embeddium.impl.render.terrain.SimpleWorldRenderer;
|
||||
import org.embeddedt.embeddium.impl.render.viewport.Viewport;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class CeleritasWorldRenderer extends SimpleWorldRenderer<WorldClient, AngelicaRenderSectionManager, BlockRenderLayer, TileEntity, CeleritasWorldRenderer.TileEntityRenderContext> implements IDynamicLightWorldRenderer {
|
||||
private static final Logger LOGGER = LogManager.getLogger("Angelica");
|
||||
private final Minecraft mc;
|
||||
private static CeleritasWorldRenderer instance;
|
||||
|
||||
private final TileEntityRenderContext teRenderContext = new TileEntityRenderContext();
|
||||
private boolean useEntityCulling = true;
|
||||
|
||||
// the volume of a section multiplied by the number of sections to be checked at most
|
||||
private static final double MAX_ENTITY_CHECK_VOLUME = 16 * 16 * 16 * 15;
|
||||
|
||||
private CeleritasWorldRenderer(Minecraft mc) {
|
||||
// Private constructor for singleton
|
||||
this.mc = mc;
|
||||
}
|
||||
|
||||
public static CeleritasWorldRenderer create(Minecraft mc) {
|
||||
instance = new CeleritasWorldRenderer(mc);
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static CeleritasWorldRenderer getInstance() {
|
||||
if (instance == null) {
|
||||
throw new IllegalStateException("CeleritasWorldRenderer not initialized");
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public AngelicaRenderSectionManager getRenderSectionManager() {
|
||||
return this.renderSectionManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return this.world != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadWorld(WorldClient world) {
|
||||
super.loadWorld(world);
|
||||
DynamicLights.setActiveRenderer(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void unloadWorld() {
|
||||
DynamicLights.setActiveRenderer(null);
|
||||
super.unloadWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEffectiveRenderDistance() {
|
||||
return mc.gameSettings.renderDistanceChunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumBuildHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumBuildHeight() {
|
||||
return 256;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChunkRenderMatrices createChunkRenderMatrices() {
|
||||
final boolean shadowPass = renderSectionManager.isInShadowPass();
|
||||
final Matrix4f projection = shadowPass ? ShadowRenderer.PROJECTION : RenderingState.INSTANCE.getProjectionMatrix();
|
||||
final Matrix4f modelView = shadowPass ? ShadowRenderer.MODELVIEW : RenderingState.INSTANCE.getModelViewMatrix();
|
||||
return new ChunkRenderMatrices(projection, modelView);
|
||||
}
|
||||
|
||||
private ChunkVertexType chooseVertexType() {
|
||||
final IrisShaderProvider provider = IrisShaderProviderHolder.getProvider();
|
||||
if (provider != null && provider.isShadersEnabled()) {
|
||||
final ChunkVertexType extended = provider.getVertexType(ChunkMeshFormats.VANILLA_LIKE);
|
||||
if (extended != ChunkMeshFormats.VANILLA_LIKE) {
|
||||
return extended;
|
||||
}
|
||||
}
|
||||
|
||||
if (SodiumClientMod.options().advanced.useCompactVertexFormat) {
|
||||
return ChunkMeshFormats.COMPACT;
|
||||
}
|
||||
return ChunkMeshFormats.VANILLA_LIKE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AngelicaRenderSectionManager createRenderSectionManager(CommandList commandList) {
|
||||
return AngelicaRenderSectionManager.create(chooseVertexType(), this.world, this.renderDistance, commandList);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBlockEntityList(List<TileEntity> list, TileEntityRenderContext context) {
|
||||
for (TileEntity tileEntity : list) {
|
||||
renderTE(tileEntity, context.pass, context.partialTicks);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupTerrain(Viewport viewport, CameraState cameraState, int frame, boolean spectator, boolean updateChunksImmediately) {
|
||||
var transform = viewport.getTransform();
|
||||
|
||||
if (transform.x == 0 && transform.y == 0 && transform.z == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
renderSectionManager.setCameraPosition(transform.x, transform.y, transform.z);
|
||||
|
||||
this.useEntityCulling = true;
|
||||
|
||||
super.setupTerrain(viewport, cameraState, frame, spectator, updateChunksImmediately);
|
||||
|
||||
// Collect tile entities for shadow pass rendering
|
||||
if (renderSectionManager.isInShadowPass() && IrisShaderProviderHolder.isActive()) {
|
||||
collectTileEntitiesForShadow();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentViewport(Viewport viewport) {
|
||||
this.currentViewport = viewport;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void collectTileEntitiesForShadow() {
|
||||
final SortedRenderLists renderLists = renderSectionManager.getRenderLists();
|
||||
final Iterator<ChunkRenderList> renderListIterator = renderLists.iterator();
|
||||
|
||||
while (renderListIterator.hasNext()) {
|
||||
final var renderList = renderListIterator.next();
|
||||
final var renderRegion = renderList.getRegion();
|
||||
final var renderSectionIterator = renderList.sectionsWithEntitiesIterator();
|
||||
|
||||
if (renderSectionIterator == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
while (renderSectionIterator.hasNext()) {
|
||||
final var renderSectionId = renderSectionIterator.nextByteAsInt();
|
||||
final var renderSection = renderRegion.getSection(renderSectionId);
|
||||
|
||||
if (renderSection == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final var context = renderSection.getBuiltContext();
|
||||
if (context instanceof MinecraftBuiltRenderSectionData<?, ?> mcData) {
|
||||
final var culledEntities = (List<TileEntity>) mcData.culledBlockEntities;
|
||||
ShadowRenderer.visibleTileEntities.addAll(culledEntities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var renderSection : renderSectionManager.getSectionsWithGlobalEntities()) {
|
||||
final var context = renderSection.getBuiltContext();
|
||||
if (context instanceof MinecraftBuiltRenderSectionData<?, ?> mcData) {
|
||||
final var globalEntities = (List<TileEntity>) mcData.globalBlockEntities;
|
||||
ShadowRenderer.globalTileEntities.addAll(globalEntities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawChunkLayer(BlockRenderLayer renderLayer, double x, double y, double z) {
|
||||
super.drawChunkLayer(renderLayer, x, y, z);
|
||||
GLStateManager.glColor4f(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
public int renderBlockEntities(float partialTicks) {
|
||||
final int pass = MinecraftForgeClient.getRenderPass();
|
||||
return super.renderBlockEntities(teRenderContext.set(partialTicks, pass));
|
||||
}
|
||||
|
||||
private void renderTE(TileEntity tileEntity, int pass, float partialTicks) {
|
||||
if (!tileEntity.shouldRenderInPass(pass)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final AxisAlignedBB aabb = tileEntity.getRenderBoundingBox();
|
||||
|
||||
if (aabb != TileEntity.INFINITE_EXTENT_AABB && !this.currentViewport.isBoxVisible(aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
TileEntityRendererDispatcher.instance.renderTileEntity(tileEntity, partialTicks);
|
||||
} catch (RuntimeException e) {
|
||||
if (tileEntity.isInvalid()) {
|
||||
LOGGER.warn("Suppressed exception rendering invalid TileEntity {} at ({}, {}, {})", tileEntity.getClass().getName(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isInfiniteExtentsBox(AxisAlignedBB box) {
|
||||
return box == null || Double.isInfinite(box.minX) || Double.isInfinite(box.minY) || Double.isInfinite(box.minZ)
|
||||
|| Double.isInfinite(box.maxX) || Double.isInfinite(box.maxY) || Double.isInfinite(box.maxZ);
|
||||
}
|
||||
|
||||
public boolean isEntityVisible(Entity entity) {
|
||||
// During shadow pass, don't cull entities - shadow rendering uses different frustum
|
||||
if (!this.useEntityCulling || this.renderSectionManager.isInShadowPass()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
AxisAlignedBB box = entity.getBoundingBox();
|
||||
if (box == null) {
|
||||
box = entity.boundingBox;
|
||||
}
|
||||
|
||||
if (isInfiniteExtentsBox(box)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// bail on very large entities to avoid checking many sections
|
||||
final double entityVolume = (box.maxX - box.minX) * (box.maxY - box.minY) * (box.maxZ - box.minZ);
|
||||
if (entityVolume > MAX_ENTITY_CHECK_VOLUME) {
|
||||
// TODO: do a frustum check instead, even large entities aren't visible if they're outside the frustum
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.isBoxVisible(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ);
|
||||
}
|
||||
|
||||
public static class TileEntityRenderContext {
|
||||
public float partialTicks;
|
||||
public int pass;
|
||||
|
||||
public TileEntityRenderContext set(float partialTicks, int pass) {
|
||||
this.partialTicks = partialTicks;
|
||||
this.pass = pass;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import org.embeddedt.embeddium.impl.biome.BiomeColorCache;
|
||||
|
||||
public class SmoothBiomeColorCache extends BiomeColorCache<BiomeGenBase, SmoothBiomeColorCache.ColorType> {
|
||||
private static final ThreadLocal<SmoothBiomeColorCache> activeCache = new ThreadLocal<>();
|
||||
|
||||
public static void setActiveCache(SmoothBiomeColorCache cache) {
|
||||
activeCache.set(cache);
|
||||
}
|
||||
|
||||
public static void clearActiveCache() {
|
||||
activeCache.remove();
|
||||
}
|
||||
|
||||
public static SmoothBiomeColorCache getActiveCache() {
|
||||
return activeCache.get();
|
||||
}
|
||||
|
||||
public SmoothBiomeColorCache(IBlockAccess blockAccess) {
|
||||
super((x, y, z) -> blockAccess.getBiomeGenForCoords(x, z), 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int resolveColor(ColorType type, BiomeGenBase biome, int relativeX, int relativeY, int relativeZ) {
|
||||
return switch (type) {
|
||||
case GRASS -> biome.getBiomeGrassColor(relativeX, relativeY, relativeZ);
|
||||
case FOLIAGE -> biome.getBiomeFoliageColor(relativeX, relativeY, relativeZ);
|
||||
case WATER -> biome.getWaterColorMultiplier();
|
||||
};
|
||||
}
|
||||
|
||||
public enum ColorType {
|
||||
GRASS,
|
||||
FOLIAGE,
|
||||
WATER
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import org.embeddedt.embeddium.impl.render.chunk.sprite.SpriteTransparencyLevel;
|
||||
|
||||
public interface SpriteExtension {
|
||||
SpriteTransparencyLevel celeritas$getTransparencyLevel();
|
||||
|
||||
/** Marks sprite as active for animation. */
|
||||
void celeritas$markActive();
|
||||
|
||||
/** One-shot: returns true if marked, then resets. */
|
||||
boolean celeritas$shouldUpdate();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
|
||||
public interface TextureMapExtension {
|
||||
TextureAtlasSprite celeritas$findFromUV(float u, float v);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas;
|
||||
|
||||
public interface WorldClientExtension {
|
||||
SmoothBiomeColorCache celeritas$getSmoothBiomeColorCache();
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.api;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import net.minecraft.block.Block;
|
||||
import org.embeddedt.embeddium.impl.gl.shader.GlProgram;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderPassConfiguration;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderInterface;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
||||
import com.gtnewhorizons.angelica.compat.toremove.RenderLayer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface IrisShaderProvider {
|
||||
|
||||
boolean isShadersEnabled();
|
||||
|
||||
boolean isShadowPass();
|
||||
|
||||
boolean shouldUseFaceCulling();
|
||||
|
||||
@Nullable GlProgram<? extends ChunkShaderInterface> getShaderOverride(TerrainRenderPass pass);
|
||||
|
||||
ChunkVertexType getVertexType(ChunkVertexType defaultType);
|
||||
|
||||
void setRenderPassConfiguration(RenderPassConfiguration<?> configuration);
|
||||
|
||||
/** Block render layer overrides from shader pack */
|
||||
@Nullable Map<Block, RenderLayer> getBlockTypeIds();
|
||||
|
||||
/** Block ID matches for extended vertex data */
|
||||
@Nullable Object2IntMap<Block> getBlockMatches();
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.api;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class IrisShaderProviderHolder {
|
||||
|
||||
private static IrisShaderProvider provider;
|
||||
|
||||
private IrisShaderProviderHolder() {}
|
||||
|
||||
public static void setProvider(@Nullable IrisShaderProvider provider) {
|
||||
IrisShaderProviderHolder.provider = provider;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IrisShaderProvider getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public static boolean isActive() {
|
||||
return provider != null && provider.isShadersEnabled();
|
||||
}
|
||||
|
||||
public static boolean isShadowPass() {
|
||||
return provider != null && provider.isShadowPass();
|
||||
}
|
||||
|
||||
public static boolean shouldUseFaceCulling() {
|
||||
return provider == null || provider.shouldUseFaceCulling();
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.iris;
|
||||
|
||||
public class BlockRenderContext {
|
||||
public int localPosX, localPosY, localPosZ;
|
||||
public short blockId = -1;
|
||||
public short renderType = -1;
|
||||
public byte lightValue;
|
||||
|
||||
public void set(int localX, int localY, int localZ, short blockId, short renderType, byte lightValue) {
|
||||
this.localPosX = localX;
|
||||
this.localPosY = localY;
|
||||
this.localPosZ = localZ;
|
||||
this.blockId = blockId;
|
||||
this.renderType = renderType;
|
||||
this.lightValue = lightValue;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
blockId = -1;
|
||||
renderType = -1;
|
||||
lightValue = 0;
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.iris;
|
||||
|
||||
import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*;
|
||||
|
||||
import net.coderbot.iris.vertices.IrisQuadView;
|
||||
|
||||
public class CeleritasQuadView implements IrisQuadView {
|
||||
private long writePointer;
|
||||
private int stride;
|
||||
|
||||
public void setup(long ptr, int stride) {
|
||||
this.writePointer = ptr;
|
||||
this.stride = stride;
|
||||
}
|
||||
|
||||
// VANILLA_LIKE format offsets:
|
||||
// Position: floats at 0, 4, 8
|
||||
// Color: int at 12
|
||||
// TexCoord: floats at 16, 20
|
||||
// LightCoord: int at 24
|
||||
|
||||
@Override
|
||||
public float x(int index) {
|
||||
return memGetFloat(writePointer - stride * (3L - index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float y(int index) {
|
||||
return memGetFloat(writePointer + 4 - stride * (3L - index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float z(int index) {
|
||||
return memGetFloat(writePointer + 8 - stride * (3L - index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float u(int index) {
|
||||
return memGetFloat(writePointer + 16 - stride * (3L - index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float v(int index) {
|
||||
return memGetFloat(writePointer + 20 - stride * (3L - index));
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.iris;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexEncoder;
|
||||
|
||||
public interface ContextAwareChunkVertexEncoder extends ChunkVertexEncoder {
|
||||
|
||||
void prepareToRenderBlock(BlockRenderContext ctx, Block block, short renderType, byte lightValue);
|
||||
|
||||
void prepareToRenderFluid(BlockRenderContext ctx, Block block, byte lightValue);
|
||||
|
||||
void finishRenderingBlock();
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.iris;
|
||||
|
||||
import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*;
|
||||
import static com.gtnewhorizons.angelica.rendering.celeritas.iris.IrisExtendedChunkVertexType.STRIDE;
|
||||
import static com.gtnewhorizons.angelica.rendering.celeritas.iris.IrisExtendedChunkVertexType.encodeMidTexture;
|
||||
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProvider;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.api.IrisShaderProviderHolder;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import lombok.Setter;
|
||||
import net.coderbot.iris.vertices.ExtendedDataHelper;
|
||||
import net.coderbot.iris.vertices.NormalHelper;
|
||||
import net.coderbot.iris.vertices.NormI8;
|
||||
import net.minecraft.block.Block;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexEncoder;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
/**
|
||||
* Writes Iris-extended vertices. Delegates base 28 bytes to VANILLA_LIKE encoder.
|
||||
*/
|
||||
public class IrisExtendedChunkVertexEncoder implements ContextAwareChunkVertexEncoder {
|
||||
// Offsets derived from format definition
|
||||
private static final int MID_TEX_OFFSET = IrisExtendedChunkVertexType.VERTEX_FORMAT.getAttribute("mc_midTexCoord").getPointer();
|
||||
private static final int TANGENT_OFFSET = IrisExtendedChunkVertexType.VERTEX_FORMAT.getAttribute("at_tangent").getPointer();
|
||||
private static final int NORMAL_OFFSET = IrisExtendedChunkVertexType.VERTEX_FORMAT.getAttribute("iris_Normal").getPointer();
|
||||
private static final int MC_ENTITY_OFFSET = IrisExtendedChunkVertexType.VERTEX_FORMAT.getAttribute("mc_Entity").getPointer();
|
||||
private static final int MID_BLOCK_OFFSET = IrisExtendedChunkVertexType.VERTEX_FORMAT.getAttribute("at_midBlock").getPointer();
|
||||
|
||||
private final ChunkVertexEncoder baseEncoder = IrisExtendedChunkVertexType.BASE_TYPE.createEncoder();
|
||||
private final CeleritasQuadView quad = new CeleritasQuadView();
|
||||
private final Vector3f normal = new Vector3f();
|
||||
private final Object2IntMap<Block> blockMatches;
|
||||
|
||||
public IrisExtendedChunkVertexEncoder() {
|
||||
final IrisShaderProvider provider = IrisShaderProviderHolder.getProvider();
|
||||
this.blockMatches = provider != null ? provider.getBlockMatches() : null;
|
||||
}
|
||||
|
||||
// Per-quad accumulators
|
||||
private int vertexCount;
|
||||
private float uSum;
|
||||
private float vSum;
|
||||
|
||||
@Setter
|
||||
private BlockRenderContext context;
|
||||
|
||||
@Override
|
||||
public void prepareToRenderBlock(BlockRenderContext ctx, Block block, short renderType, byte lightValue) {
|
||||
this.context = ctx;
|
||||
ctx.blockId = (short) (blockMatches != null ? blockMatches.getOrDefault(block, -1) : -1);
|
||||
ctx.renderType = renderType;
|
||||
ctx.lightValue = lightValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareToRenderFluid(BlockRenderContext ctx, Block block, byte lightValue) {
|
||||
this.context = ctx;
|
||||
ctx.blockId = (short) (blockMatches != null ? blockMatches.getOrDefault(block, -1) : -1);
|
||||
ctx.renderType = ExtendedDataHelper.FLUID_RENDER_TYPE;
|
||||
ctx.lightValue = lightValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishRenderingBlock() {
|
||||
if (context != null) {
|
||||
context.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long write(long ptr, Material material, Vertex vertex, int sectionIndex) {
|
||||
uSum += vertex.u;
|
||||
vSum += vertex.v;
|
||||
vertexCount++;
|
||||
|
||||
final BlockRenderContext ctx = context;
|
||||
|
||||
baseEncoder.write(ptr, material, vertex, sectionIndex);
|
||||
|
||||
// Per-vertex: renderType, midBlock, lightValue
|
||||
memPutShort(ptr + MC_ENTITY_OFFSET + 2, ctx.renderType);
|
||||
final int midBlock = ExtendedDataHelper.computeMidBlock(vertex.x, vertex.y, vertex.z, ctx.localPosX, ctx.localPosY, ctx.localPosZ);
|
||||
memPutInt(ptr + MID_BLOCK_OFFSET, midBlock);
|
||||
memPutByte(ptr + MID_BLOCK_OFFSET + 3, ctx.lightValue);
|
||||
|
||||
// Per-quad: midTexCoord, blockId, normal, tangent
|
||||
if (vertexCount == 4) {
|
||||
vertexCount = 0;
|
||||
|
||||
final float midU = uSum * 0.25f;
|
||||
final float midV = vSum * 0.25f;
|
||||
final int midUV = encodeMidTexture(midU, midV);
|
||||
|
||||
memPutInt(ptr + MID_TEX_OFFSET, midUV);
|
||||
memPutInt(ptr + MID_TEX_OFFSET - STRIDE, midUV);
|
||||
memPutInt(ptr + MID_TEX_OFFSET - STRIDE * 2, midUV);
|
||||
memPutInt(ptr + MID_TEX_OFFSET - STRIDE * 3, midUV);
|
||||
|
||||
memPutShort(ptr + MC_ENTITY_OFFSET, ctx.blockId);
|
||||
memPutShort(ptr + MC_ENTITY_OFFSET - STRIDE, ctx.blockId);
|
||||
memPutShort(ptr + MC_ENTITY_OFFSET - STRIDE * 2, ctx.blockId);
|
||||
memPutShort(ptr + MC_ENTITY_OFFSET - STRIDE * 3, ctx.blockId);
|
||||
|
||||
quad.setup(ptr, STRIDE);
|
||||
NormalHelper.computeFaceNormal(normal, quad);
|
||||
final int packedNormal = NormI8.pack(normal);
|
||||
|
||||
memPutInt(ptr + NORMAL_OFFSET, packedNormal);
|
||||
memPutInt(ptr + NORMAL_OFFSET - STRIDE, packedNormal);
|
||||
memPutInt(ptr + NORMAL_OFFSET - STRIDE * 2, packedNormal);
|
||||
memPutInt(ptr + NORMAL_OFFSET - STRIDE * 3, packedNormal);
|
||||
|
||||
final int tangent = NormalHelper.computeTangent(normal.x, normal.y, normal.z, quad);
|
||||
|
||||
memPutInt(ptr + TANGENT_OFFSET, tangent);
|
||||
memPutInt(ptr + TANGENT_OFFSET - STRIDE, tangent);
|
||||
memPutInt(ptr + TANGENT_OFFSET - STRIDE * 2, tangent);
|
||||
memPutInt(ptr + TANGENT_OFFSET - STRIDE * 3, tangent);
|
||||
|
||||
uSum = 0;
|
||||
vSum = 0;
|
||||
}
|
||||
|
||||
return ptr + STRIDE;
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.iris;
|
||||
|
||||
import org.embeddedt.embeddium.impl.gl.attribute.GlVertexAttributeFormat;
|
||||
import org.embeddedt.embeddium.impl.gl.attribute.GlVertexFormat;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkMeshFormats;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexEncoder;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexType;
|
||||
|
||||
/**
|
||||
* VANILLA_LIKE (28 bytes) + Iris extensions (20 bytes) = 48 bytes total.
|
||||
*
|
||||
* Iris extensions:
|
||||
* mc_midTexCoord ushort[2] - quad center UV (average of 4 vertices)
|
||||
* at_tangent byte[4] - tangent vector, normalized
|
||||
* iris_Normal byte[3]+1 - face normal, normalized
|
||||
* mc_Entity short[2] - (blockId, renderType)
|
||||
* at_midBlock byte[4] - (xyz offset from block center, lightValue)
|
||||
*/
|
||||
public class IrisExtendedChunkVertexType implements ChunkVertexType {
|
||||
public static final ChunkVertexType BASE_TYPE = ChunkMeshFormats.VANILLA_LIKE;
|
||||
public static final int STRIDE = 48;
|
||||
|
||||
public static final GlVertexFormat VERTEX_FORMAT = GlVertexFormat.builder(STRIDE)
|
||||
.addAllElements(BASE_TYPE.getVertexFormat())
|
||||
.addElement("mc_midTexCoord", GlVertexFormat.NEXT_ALIGNED_POINTER, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, false)
|
||||
.addElement("at_tangent", GlVertexFormat.NEXT_ALIGNED_POINTER, GlVertexAttributeFormat.BYTE, 4, true, false)
|
||||
.addElement("iris_Normal", GlVertexFormat.NEXT_ALIGNED_POINTER, GlVertexAttributeFormat.BYTE, 3, true, false)
|
||||
.addElement("mc_Entity", GlVertexFormat.NEXT_ALIGNED_POINTER, GlVertexAttributeFormat.SHORT, 2, false, false)
|
||||
.addElement("at_midBlock", GlVertexFormat.NEXT_ALIGNED_POINTER, GlVertexAttributeFormat.BYTE, 4, false, false)
|
||||
.build();
|
||||
|
||||
private static final int TEXTURE_MAX_VALUE = 32768;
|
||||
public static final float MID_TEX_SCALE = 1.0f / TEXTURE_MAX_VALUE;
|
||||
|
||||
/** Pack UV as two unsigned shorts: low=u, high=v. */
|
||||
public static int encodeMidTexture(float u, float v) {
|
||||
return ((Math.round(u * TEXTURE_MAX_VALUE) & 0xFFFF)) |
|
||||
((Math.round(v * TEXTURE_MAX_VALUE) & 0xFFFF) << 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkVertexEncoder createEncoder() {
|
||||
return new IrisExtendedChunkVertexEncoder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPositionScale() {
|
||||
return BASE_TYPE.getPositionScale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPositionOffset() {
|
||||
return BASE_TYPE.getPositionOffset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTextureScale() {
|
||||
return BASE_TYPE.getTextureScale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlVertexFormat getVertexFormat() {
|
||||
return VERTEX_FORMAT;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.threading;
|
||||
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ClonedChunkSectionCache;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildOutput;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderTask;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public interface ChunkTaskProvider {
|
||||
ChunkBuilderTask<ChunkBuildOutput> createRebuildTask(RenderSection render, int frame, Vector3d cameraPosition);
|
||||
|
||||
default ChunkBuilderTask<ChunkBuildOutput> createRebuildTask(RenderSection render, int frame, Vector3d cameraPosition, ClonedChunkSectionCache sectionCache) {
|
||||
return createRebuildTask(render, frame, cameraPosition);
|
||||
}
|
||||
|
||||
/** @return -1 = single-threaded, 0 = auto-detect, >0 = specific count */
|
||||
int threadCount();
|
||||
|
||||
/** Lower = higher priority */
|
||||
int priority();
|
||||
|
||||
default boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.threading;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public final class ChunkTaskRegistry {
|
||||
private static final Logger LOGGER = LogManager.getLogger("ChunkTaskRegistry");
|
||||
private static final List<ChunkTaskProvider> providers = new ArrayList<>();
|
||||
private static ChunkTaskProvider activeProvider;
|
||||
|
||||
private ChunkTaskRegistry() {}
|
||||
|
||||
public static synchronized void registerProvider(ChunkTaskProvider provider) {
|
||||
providers.add(provider);
|
||||
providers.sort(Comparator.comparingInt(ChunkTaskProvider::priority));
|
||||
activeProvider = null;
|
||||
LOGGER.info("Registered chunk task provider: {} (priority={})",
|
||||
provider.getClass().getSimpleName(), provider.priority());
|
||||
}
|
||||
|
||||
public static synchronized ChunkTaskProvider getActiveProvider() {
|
||||
for (ChunkTaskProvider provider : providers) {
|
||||
if (provider.isEnabled()) {
|
||||
if (activeProvider != provider) {
|
||||
activeProvider = provider;
|
||||
LOGGER.info("Active chunk task provider: {} (threads={})", activeProvider.getClass().getSimpleName(), activeProvider.threadCount());
|
||||
}
|
||||
return activeProvider;
|
||||
}
|
||||
}
|
||||
|
||||
if (activeProvider != DefaultChunkTaskProvider.INSTANCE) {
|
||||
activeProvider = DefaultChunkTaskProvider.INSTANCE;
|
||||
LOGGER.info("Active chunk task provider: single-threaded fallback");
|
||||
}
|
||||
return activeProvider;
|
||||
}
|
||||
|
||||
public static synchronized void reset() {
|
||||
providers.clear();
|
||||
activeProvider = null;
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.threading;
|
||||
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.AngelicaMainThreadMeshingTask;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildOutput;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderTask;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public final class DefaultChunkTaskProvider implements ChunkTaskProvider {
|
||||
public static final DefaultChunkTaskProvider INSTANCE = new DefaultChunkTaskProvider();
|
||||
|
||||
private DefaultChunkTaskProvider() {}
|
||||
|
||||
@Override
|
||||
public ChunkBuilderTask<ChunkBuildOutput> createRebuildTask(RenderSection render, int frame, Vector3d cameraPosition) {
|
||||
return new AngelicaMainThreadMeshingTask(render, frame, cameraPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int threadCount() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.threading;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
|
||||
public final class RenderPassHelper {
|
||||
private static final ThreadLocal<Integer> threadLocalPass = ThreadLocal.withInitial(() -> -1);
|
||||
|
||||
private RenderPassHelper() {}
|
||||
|
||||
public static int getWorldRenderPass() {
|
||||
return GLStateManager.isMainThread() ? ForgeHooksClient.worldRenderPass : threadLocalPass.get();
|
||||
}
|
||||
|
||||
public static void setWorldRenderPass(int pass) {
|
||||
if (GLStateManager.isMainThread()) {
|
||||
ForgeHooksClient.worldRenderPass = pass;
|
||||
} else {
|
||||
threadLocalPass.set(pass);
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetWorldRenderPass() {
|
||||
setWorldRenderPass(-1);
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.threading;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager;
|
||||
import com.gtnewhorizons.angelica.rendering.AngelicaBlockSafetyRegistry;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.AngelicaChunkBuilderMeshingTask;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.SmoothBiomeColorCache;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.WorldClientExtension;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.WorldSlice;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ChunkRenderContext;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.world.ChunkCache;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildContext;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildOutput;
|
||||
import org.embeddedt.embeddium.impl.util.position.SectionPos;
|
||||
import org.embeddedt.embeddium.impl.util.task.CancellationToken;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Vector3d;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.AngelicaChunkBuildContext;
|
||||
|
||||
public class ThreadedAngelicaChunkBuilderMeshingTask extends AngelicaChunkBuilderMeshingTask {
|
||||
/** Vanilla render types (0-41) are thread-safe. ISBRHs (42+) need @ThreadSafeISBRH. */
|
||||
private static final int MAX_VANILLA_RENDER_TYPE = 41;
|
||||
|
||||
private final @Nullable ChunkRenderContext renderContext;
|
||||
|
||||
private IBlockAccess blockAccess;
|
||||
private SmoothBiomeColorCache biomeColorCache;
|
||||
private boolean enteredLocalMode;
|
||||
|
||||
public ThreadedAngelicaChunkBuilderMeshingTask(RenderSection render, @Nullable ChunkRenderContext renderContext, int time, Vector3d camera) {
|
||||
super(render, time, camera);
|
||||
this.renderContext = renderContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkBuildOutput execute(ChunkBuildContext context, CancellationToken cancellationToken) {
|
||||
initBlockAccess((AngelicaChunkBuildContext) context);
|
||||
return super.execute(context, cancellationToken);
|
||||
}
|
||||
|
||||
private void initBlockAccess(AngelicaChunkBuildContext buildContext) {
|
||||
final int minX = this.render.getOriginX();
|
||||
final int minY = this.render.getOriginY();
|
||||
final int minZ = this.render.getOriginZ();
|
||||
|
||||
if (this.renderContext != null) {
|
||||
final WorldSlice worldSlice = buildContext.getWorldSlice();
|
||||
worldSlice.copyData(this.renderContext);
|
||||
this.blockAccess = worldSlice;
|
||||
this.biomeColorCache = new SmoothBiomeColorCache(worldSlice);
|
||||
this.biomeColorCache.update(new SectionPos(this.render.getChunkX(), this.render.getChunkY(), this.render.getChunkZ()));
|
||||
} else {
|
||||
// Fallback: direct world access (main thread only)
|
||||
final var world = Minecraft.getMinecraft().theWorld;
|
||||
this.biomeColorCache = ((WorldClientExtension) world).celeritas$getSmoothBiomeColorCache();
|
||||
this.biomeColorCache.update(new SectionPos(this.render.getChunkX(), this.render.getChunkY(), this.render.getChunkZ()));
|
||||
this.blockAccess = new ChunkCache(world, minX - 1, minY - 1, minZ - 1, minX + 17, minY + 17, minZ + 17, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Tessellator getTessellator() {
|
||||
return Tessellator.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setRenderPass(int pass) {
|
||||
RenderPassHelper.setWorldRenderPass(pass);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IBlockAccess getBlockAccess() {
|
||||
return blockAccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SmoothBiomeColorCache getBiomeColorCache() {
|
||||
return biomeColorCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isThreaded() {
|
||||
return enteredLocalMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canRenderOffThread(Block block) {
|
||||
final int renderType = block.getRenderType();
|
||||
return (renderType >= 0 && renderType <= MAX_VANILLA_RENDER_TYPE)
|
||||
|| AngelicaBlockSafetyRegistry.canBlockRenderOffThread(block, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnterExecute() {
|
||||
enteredLocalMode = !TessellatorManager.isOnMainThread();
|
||||
if (enteredLocalMode) {
|
||||
TessellatorManager.enterLocalMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExitExecute() {
|
||||
if (enteredLocalMode) {
|
||||
RenderPassHelper.resetWorldRenderPass();
|
||||
TessellatorManager.exitLocalMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addExtraCrashInfo(CrashReportCategory category) {
|
||||
category.addCrashSection("Thread", Thread.currentThread().getName());
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.threading;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.WorldSlice;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ChunkRenderContext;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ClonedChunkSectionCache;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkBuildOutput;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.compile.tasks.ChunkBuilderTask;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
public final class ThreadedChunkTaskProvider implements ChunkTaskProvider {
|
||||
public static final ThreadedChunkTaskProvider INSTANCE = new ThreadedChunkTaskProvider();
|
||||
|
||||
private ThreadedChunkTaskProvider() {}
|
||||
|
||||
@Override
|
||||
public ChunkBuilderTask<ChunkBuildOutput> createRebuildTask(RenderSection render, int frame, Vector3d cameraPosition) {
|
||||
return new ThreadedAngelicaChunkBuilderMeshingTask(render, null, frame, cameraPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkBuilderTask<ChunkBuildOutput> createRebuildTask(RenderSection render, int frame, Vector3d cameraPosition, ClonedChunkSectionCache sectionCache) {
|
||||
final ChunkSectionPos origin = ChunkSectionPos.from(render.getChunkX(), render.getChunkY(), render.getChunkZ());
|
||||
final ChunkRenderContext context = WorldSlice.prepare(Minecraft.getMinecraft().theWorld, origin, sectionCache);
|
||||
return context == null ? null : new ThreadedAngelicaChunkBuilderMeshingTask(render, context, frame, cameraPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int threadCount() {
|
||||
return AngelicaConfig.chunkBuilderThreadCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return AngelicaConfig.enableThreadedChunkBuilding;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,471 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.world;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.IBlockAccessExtended;
|
||||
import com.gtnewhorizons.angelica.compat.ModStatus;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.CompatMathHelper;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ChunkRenderContext;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ClonedChunkSection;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.world.cloned.ClonedChunkSectionCache;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import mega.fluidlogged.api.FLBlockAccess;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.EnumSkyBlock;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.NibbleArray;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
import net.minecraft.world.gen.structure.StructureBoundingBox;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Takes a slice of world state (block states, biome and light data arrays) and copies the data for use in off-thread
|
||||
* operations. This allows chunk build tasks to see a consistent snapshot of chunk data at the exact moment the task was
|
||||
* created.
|
||||
*
|
||||
* World slices are not safe to use from multiple threads at once, but the data they contain is safe from modification
|
||||
* by the main client thread.
|
||||
*
|
||||
* Object pooling should be used to avoid huge allocations as this class contains many large arrays.
|
||||
*/
|
||||
@Optional.Interface(iface = "mega.fluidlogged.api.FLBlockAccess", modid = "fluidlogged")
|
||||
public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
|
||||
private static final EnumSkyBlock[] LIGHT_TYPES = EnumSkyBlock.values();
|
||||
|
||||
// The number of blocks on each axis in a section.
|
||||
private static final int SECTION_BLOCK_LENGTH = 16;
|
||||
|
||||
// The number of blocks in a section.
|
||||
private static final int SECTION_BLOCK_COUNT = SECTION_BLOCK_LENGTH * SECTION_BLOCK_LENGTH * SECTION_BLOCK_LENGTH;
|
||||
|
||||
// The radius of blocks around the origin chunk that should be copied.
|
||||
private static final int NEIGHBOR_BLOCK_RADIUS = 2;
|
||||
|
||||
// The radius of chunks around the origin chunk that should be copied.
|
||||
private static final int NEIGHBOR_CHUNK_RADIUS = CompatMathHelper.roundUpToMultiple(NEIGHBOR_BLOCK_RADIUS, 16) >> 4;
|
||||
|
||||
// The number of sections on each axis of this slice.
|
||||
private static final int SECTION_LENGTH = 1 + (NEIGHBOR_CHUNK_RADIUS * 2);
|
||||
|
||||
// The size of the lookup tables used for mapping values to coordinate int pairs. The lookup table size is always
|
||||
// a power of two so that multiplications can be replaced with simple bit shifts in hot code paths.
|
||||
private static final int TABLE_LENGTH = CompatMathHelper.smallestEncompassingPowerOfTwo(SECTION_LENGTH);
|
||||
|
||||
// The number of bits needed for each X/Y/Z component in a lookup table.
|
||||
private static final int TABLE_BITS = Integer.bitCount(TABLE_LENGTH - 1);
|
||||
|
||||
// The array size for the section lookup table.
|
||||
private static final int SECTION_TABLE_ARRAY_SIZE = TABLE_LENGTH * TABLE_LENGTH * TABLE_LENGTH;
|
||||
|
||||
// The world this slice has copied data from
|
||||
private final WorldClient world;
|
||||
|
||||
// Local Section->Block table
|
||||
private final Block[][] blockArrays;
|
||||
private final Fluid[][] fluidArrays;
|
||||
private final int[][] metadataArrays;
|
||||
|
||||
// Local Section->Light table
|
||||
private final NibbleArray[][] lightArrays;
|
||||
|
||||
// Local section copies
|
||||
private ClonedChunkSection[] sections;
|
||||
|
||||
// Biome data for each chunk section
|
||||
private BiomeGenBase[][] biomeData;
|
||||
|
||||
// The starting point from which this slice captures blocks
|
||||
private int baseX, baseY, baseZ;
|
||||
|
||||
private final int worldHeight;
|
||||
private final int[] defaultLightValues;
|
||||
|
||||
// The chunk origin of this slice
|
||||
private ChunkSectionPos origin;
|
||||
private StructureBoundingBox volume;
|
||||
|
||||
public static ChunkRenderContext prepare(World world, ChunkSectionPos origin, ClonedChunkSectionCache sectionCache) {
|
||||
final Chunk chunk = world.getChunkFromChunkCoords(origin.x, origin.z);
|
||||
final ExtendedBlockStorage section = chunk.getBlockStorageArray()[origin.y];
|
||||
|
||||
// If the chunk section is absent or empty, terminate early
|
||||
if (section == null || section.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final StructureBoundingBox volume = new StructureBoundingBox(
|
||||
origin.getMinX() - NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMinY() - NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMinZ() - NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMaxX() + NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMaxY() + NEIGHBOR_BLOCK_RADIUS,
|
||||
origin.getMaxZ() + NEIGHBOR_BLOCK_RADIUS
|
||||
);
|
||||
|
||||
// The min/max bounds of the chunks copied by this slice
|
||||
final int minChunkX = origin.x - NEIGHBOR_CHUNK_RADIUS;
|
||||
final int minChunkY = origin.y - NEIGHBOR_CHUNK_RADIUS;
|
||||
final int minChunkZ = origin.z - NEIGHBOR_CHUNK_RADIUS;
|
||||
|
||||
final int maxChunkX = origin.x + NEIGHBOR_CHUNK_RADIUS;
|
||||
final int maxChunkY = origin.y + NEIGHBOR_CHUNK_RADIUS;
|
||||
final int maxChunkZ = origin.z + NEIGHBOR_CHUNK_RADIUS;
|
||||
|
||||
final ClonedChunkSection[] sections = new ClonedChunkSection[SECTION_TABLE_ARRAY_SIZE];
|
||||
|
||||
for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
|
||||
for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
|
||||
for (int chunkY = minChunkY; chunkY <= maxChunkY; chunkY++) {
|
||||
sections[getLocalSectionIndex(chunkX - minChunkX, chunkY - minChunkY, chunkZ - minChunkZ)] =
|
||||
sectionCache.acquire(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ChunkRenderContext(origin, sections, volume);
|
||||
}
|
||||
|
||||
public WorldSlice(WorldClient world) {
|
||||
this.world = world;
|
||||
this.worldHeight = world.getHeight();
|
||||
this.defaultLightValues = new int[LIGHT_TYPES.length];
|
||||
this.defaultLightValues[EnumSkyBlock.Sky.ordinal()] = world.provider.hasNoSky ? 0 : EnumSkyBlock.Sky.defaultLightValue;
|
||||
this.defaultLightValues[EnumSkyBlock.Block.ordinal()] = EnumSkyBlock.Block.defaultLightValue;
|
||||
|
||||
// Note: sections array is assigned in copyData() from ChunkRenderContext
|
||||
this.blockArrays = new Block[SECTION_TABLE_ARRAY_SIZE][];
|
||||
this.metadataArrays = new int[SECTION_TABLE_ARRAY_SIZE][];
|
||||
this.biomeData = new BiomeGenBase[SECTION_TABLE_ARRAY_SIZE][];
|
||||
this.lightArrays = new NibbleArray[SECTION_TABLE_ARRAY_SIZE][LIGHT_TYPES.length];
|
||||
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
this.fluidArrays = new Fluid[SECTION_TABLE_ARRAY_SIZE][];
|
||||
} else {
|
||||
this.fluidArrays = null;
|
||||
}
|
||||
|
||||
for (int x = 0; x < SECTION_LENGTH; x++) {
|
||||
for (int y = 0; y < SECTION_LENGTH; y++) {
|
||||
for (int z = 0; z < SECTION_LENGTH; z++) {
|
||||
final int i = getLocalSectionIndex(x, y, z);
|
||||
this.blockArrays[i] = new Block[SECTION_BLOCK_COUNT];
|
||||
Arrays.fill(this.blockArrays[i], Blocks.air);
|
||||
this.metadataArrays[i] = new int[SECTION_BLOCK_COUNT];
|
||||
|
||||
if (ModStatus.isFluidLoggedLoaded && this.fluidArrays != null) {
|
||||
this.fluidArrays[i] = new Fluid[SECTION_BLOCK_COUNT];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void copyData(ChunkRenderContext context) {
|
||||
this.origin = context.getOrigin();
|
||||
this.sections = context.getSections();
|
||||
this.volume = context.getVolume();
|
||||
|
||||
this.baseX = (this.origin.x - NEIGHBOR_CHUNK_RADIUS) << 4;
|
||||
this.baseY = (this.origin.y - NEIGHBOR_CHUNK_RADIUS) << 4;
|
||||
this.baseZ = (this.origin.z - NEIGHBOR_CHUNK_RADIUS) << 4;
|
||||
Arrays.fill(this.biomeData, null);
|
||||
|
||||
for (int x = 0; x < SECTION_LENGTH; x++) {
|
||||
for (int y = 0; y < SECTION_LENGTH; y++) {
|
||||
for (int z = 0; z < SECTION_LENGTH; z++) {
|
||||
final int idx = getLocalSectionIndex(x, y, z);
|
||||
final ClonedChunkSection section = this.sections[idx];
|
||||
|
||||
this.unpackBlockData(this.blockArrays[idx], this.metadataArrays[idx], section, context.getVolume());
|
||||
|
||||
if (ModStatus.isFluidLoggedLoaded && this.fluidArrays != null) {
|
||||
this.unpackFluidLoggedData(this.fluidArrays[idx], section, context.getVolume());
|
||||
}
|
||||
|
||||
this.biomeData[idx] = section.getBiomeData();
|
||||
|
||||
this.lightArrays[idx][EnumSkyBlock.Block.ordinal()] = section.getLightArray(EnumSkyBlock.Block);
|
||||
this.lightArrays[idx][EnumSkyBlock.Sky.ordinal()] = section.getLightArray(EnumSkyBlock.Sky);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ChunkSectionPos getOrigin() {
|
||||
return this.origin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightBrightnessForSkyBlocks(int x, int y, int z, int min) {
|
||||
if (y < 0 || y >= 256 || x < -30_000_000 || z < -30_000_000 || x >= 30_000_000 || z >= 30_000_000) {
|
||||
// skyBrightness = 15, blockBrightness = min
|
||||
return (15 << 20) | (min << 4);
|
||||
}
|
||||
|
||||
final int skyBrightness = this.getSkyBlockTypeBrightness(EnumSkyBlock.Sky, x, y, z);
|
||||
int blockBrightness = this.getSkyBlockTypeBrightness(EnumSkyBlock.Block, x, y, z);
|
||||
|
||||
if (blockBrightness < min) {
|
||||
blockBrightness = min;
|
||||
}
|
||||
|
||||
if (DynamicLights.isEnabled() && !getBlock(x, y, z).isOpaqueCube()) {
|
||||
return DynamicLights.get().getLightmapWithDynamicLight(x, y, z, (skyBrightness << 20 | blockBrightness << 4));
|
||||
}
|
||||
|
||||
return skyBrightness << 20 | blockBrightness << 4;
|
||||
}
|
||||
|
||||
private int getSkyBlockTypeBrightness(EnumSkyBlock skyBlock, int x, int y, int z) {
|
||||
if (this.getBlock(x, y, z).getUseNeighborBrightness()) {
|
||||
int yp = this.getLightLevel(skyBlock, x, y + 1, z);
|
||||
final int xp = this.getLightLevel(skyBlock, x + 1, y, z);
|
||||
final int xm = this.getLightLevel(skyBlock, x - 1, y, z);
|
||||
final int zp = this.getLightLevel(skyBlock, x, y, z + 1);
|
||||
final int zm = this.getLightLevel(skyBlock, x, y, z - 1);
|
||||
|
||||
if (xp > yp) yp = xp;
|
||||
if (xm > yp) yp = xm;
|
||||
if (zp > yp) yp = zp;
|
||||
if (zm > yp) yp = zm;
|
||||
|
||||
return yp;
|
||||
}
|
||||
|
||||
return this.getLightLevel(skyBlock, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isBlockProvidingPowerTo(int x, int y, int z, int directionIn) {
|
||||
return this.getBlock(x, y, z).isProvidingStrongPower(this, x, y, z, directionIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAirBlock(int x, int y, int z) {
|
||||
return this.getBlock(x, y, z).isAir(this, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeGenBase getBiomeGenForCoords(int x, int z) {
|
||||
if (!blockBoxContains(this.volume, x, volume.minY, z)) {
|
||||
return BiomeGenBase.plains;
|
||||
}
|
||||
|
||||
final int relX = x - this.baseX;
|
||||
final int relZ = z - this.baseZ;
|
||||
|
||||
final BiomeGenBase biome = this.biomeData[getLocalSectionIndex(relX >> 4, 0, relZ >> 4)]
|
||||
[(x & 15) | (z & 15) << 4];
|
||||
return biome == null ? BiomeGenBase.plains : biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return this.worldHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean extendedLevelsInChunkCache() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideSolid(int x, int y, int z, ForgeDirection side, boolean _default) {
|
||||
return getBlock(x, y, z).isSideSolid(this, x, y, z, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock(int x, int y, int z) {
|
||||
if (!blockBoxContains(this.volume, x, y, z)) {
|
||||
return Blocks.air;
|
||||
}
|
||||
|
||||
final int relX = x - this.baseX;
|
||||
final int relY = y - this.baseY;
|
||||
final int relZ = z - this.baseZ;
|
||||
return this.blockArrays[getLocalSectionIndex(relX >> 4, relY >> 4, relZ >> 4)][getLocalBlockIndex(relX & 15, relY & 15, relZ & 15)];
|
||||
}
|
||||
|
||||
public Block getBlockRelative(int x, int y, int z) {
|
||||
return this.blockArrays[getLocalSectionIndex(x >> 4, y >> 4, z >> 4)][getLocalBlockIndex(x & 15, y & 15, z & 15)];
|
||||
}
|
||||
|
||||
public int getBlockMetadataRelative(int x, int y, int z) {
|
||||
return this.metadataArrays[getLocalSectionIndex(x >> 4, y >> 4, z >> 4)][getLocalBlockIndex(x & 15, y & 15, z & 15)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockMetadata(int x, int y, int z) {
|
||||
if (!blockBoxContains(this.volume, x, y, z)) {
|
||||
return 0;
|
||||
}
|
||||
final int relX = x - this.baseX;
|
||||
final int relY = y - this.baseY;
|
||||
final int relZ = z - this.baseZ;
|
||||
|
||||
return this.metadataArrays[getLocalSectionIndex(relX >> 4, relY >> 4, relZ >> 4)][getLocalBlockIndex(relX & 15, relY & 15, relZ & 15)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity(int x, int y, int z) {
|
||||
if (!blockBoxContains(this.volume, x, y, z)) {
|
||||
return null;
|
||||
}
|
||||
final int relX = x - this.baseX;
|
||||
final int relY = y - this.baseY;
|
||||
final int relZ = z - this.baseZ;
|
||||
|
||||
return this.sections[getLocalSectionIndex(relX >> 4, relY >> 4, relZ >> 4)].getBlockEntity(relX & 15, relY & 15, relZ & 15);
|
||||
}
|
||||
|
||||
public int getLightLevel(EnumSkyBlock type, int x, int y, int z) {
|
||||
if (!blockBoxContains(this.volume, x, y, z)) {
|
||||
return 0;
|
||||
}
|
||||
y = MathHelper.clamp_int(y, 0, 255);
|
||||
|
||||
final int relX = x - this.baseX;
|
||||
final int relY = y - this.baseY;
|
||||
final int relZ = z - this.baseZ;
|
||||
|
||||
final NibbleArray lightArray = this.lightArrays[getLocalSectionIndex(relX >> 4, relY >> 4, relZ >> 4)][type.ordinal()];
|
||||
if (lightArray == null) {
|
||||
return this.defaultLightValues[type.ordinal()];
|
||||
}
|
||||
|
||||
return lightArray.get(relX & 15, relY & 15, relZ & 15);
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
// FluidLogged API support
|
||||
|
||||
public @Nullable Fluid fl$getFluid(int x, int y, int z) {
|
||||
if (!blockBoxContains(this.volume, x, y, z) || this.fluidArrays == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int relX = x - this.baseX;
|
||||
final int relY = y - this.baseY;
|
||||
final int relZ = z - this.baseZ;
|
||||
return this.fluidArrays[getLocalSectionIndex(relX >> 4, relY >> 4, relZ >> 4)][getLocalBlockIndex(relX & 15, relY & 15, relZ & 15)];
|
||||
}
|
||||
|
||||
public void fl$setFluid(int x, int y, int z, @Nullable Fluid fluid) {
|
||||
throw new UnsupportedOperationException("Cannot set fluids in a world slice. WorldSlice is read-only");
|
||||
}
|
||||
|
||||
// Internal helper methods
|
||||
|
||||
private void unpackBlockData(Block[] blocks, int[] metas, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
if (this.origin.equals(section.getPosition())) {
|
||||
this.unpackBlockDataZ(blocks, metas, section);
|
||||
} else {
|
||||
this.unpackBlockDataR(blocks, metas, section, box);
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedData(Fluid[] fluids, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
if (this.origin.equals(section.getPosition())) {
|
||||
this.unpackFluidLoggedDataZ(fluids, section);
|
||||
} else {
|
||||
this.unpackFluidLoggedDataR(fluids, section, box);
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackBlockDataZ(Block[] blocks, int[] metas, ClonedChunkSection section) {
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
for (int y = pos.getMinY(); y <= pos.getMaxY(); y++) {
|
||||
for (int z = pos.getMinZ(); z <= pos.getMaxZ(); z++) {
|
||||
for (int x = pos.getMinX(); x <= pos.getMaxX(); x++) {
|
||||
final int blockIdx = getLocalBlockIndex(x & 15, y & 15, z & 15);
|
||||
blocks[blockIdx] = section.getBlock(x & 15, y & 15, z & 15);
|
||||
metas[blockIdx] = section.getBlockMetadata(x & 15, y & 15, z & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackBlockDataR(Block[] blocks, int[] metas, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
final int minBlockX = Math.max(box.minX, pos.getMinX());
|
||||
final int maxBlockX = Math.min(box.maxX, pos.getMaxX());
|
||||
final int minBlockY = Math.max(box.minY, pos.getMinY());
|
||||
final int maxBlockY = Math.min(box.maxY, pos.getMaxY());
|
||||
final int minBlockZ = Math.max(box.minZ, pos.getMinZ());
|
||||
final int maxBlockZ = Math.min(box.maxZ, pos.getMaxZ());
|
||||
|
||||
for (int y = minBlockY; y <= maxBlockY; y++) {
|
||||
for (int z = minBlockZ; z <= maxBlockZ; z++) {
|
||||
for (int x = minBlockX; x <= maxBlockX; x++) {
|
||||
final int blockIdx = getLocalBlockIndex(x & 15, y & 15, z & 15);
|
||||
blocks[blockIdx] = section.getBlock(x & 15, y & 15, z & 15);
|
||||
metas[blockIdx] = section.getBlockMetadata(x & 15, y & 15, z & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedDataZ(Fluid[] fluids, ClonedChunkSection section) {
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
for (int y = pos.getMinY(); y <= pos.getMaxY(); y++) {
|
||||
for (int z = pos.getMinZ(); z <= pos.getMaxZ(); z++) {
|
||||
for (int x = pos.getMinX(); x <= pos.getMaxX(); x++) {
|
||||
final int blockIdx = getLocalBlockIndex(x & 15, y & 15, z & 15);
|
||||
fluids[blockIdx] = section.getFluid(x & 15, y & 15, z & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedDataR(Fluid[] fluids, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
final int minBlockX = Math.max(box.minX, pos.getMinX());
|
||||
final int maxBlockX = Math.min(box.maxX, pos.getMaxX());
|
||||
final int minBlockY = Math.max(box.minY, pos.getMinY());
|
||||
final int maxBlockY = Math.min(box.maxY, pos.getMaxY());
|
||||
final int minBlockZ = Math.max(box.minZ, pos.getMinZ());
|
||||
final int maxBlockZ = Math.min(box.maxZ, pos.getMaxZ());
|
||||
|
||||
for (int y = minBlockY; y <= maxBlockY; y++) {
|
||||
for (int z = minBlockZ; z <= maxBlockZ; z++) {
|
||||
for (int x = minBlockX; x <= maxBlockX; x++) {
|
||||
final int blockIdx = getLocalBlockIndex(x & 15, y & 15, z & 15);
|
||||
fluids[blockIdx] = section.getFluid(x & 15, y & 15, z & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int getLocalBlockIndex(int x, int y, int z) {
|
||||
return y << 8 | z << 4 | x;
|
||||
}
|
||||
|
||||
public static int getLocalSectionIndex(int x, int y, int z) {
|
||||
return y << TABLE_BITS << TABLE_BITS | z << TABLE_BITS | x;
|
||||
}
|
||||
|
||||
private static boolean blockBoxContains(StructureBoundingBox box, int x, int y, int z) {
|
||||
return x >= box.minX && x <= box.maxX &&
|
||||
y >= box.minY && y <= box.maxY &&
|
||||
z >= box.minZ && z <= box.maxZ;
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.world.cloned;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
|
||||
import net.minecraft.world.gen.structure.StructureBoundingBox;
|
||||
|
||||
public class ChunkRenderContext {
|
||||
|
||||
private final ChunkSectionPos origin;
|
||||
private final ClonedChunkSection[] sections;
|
||||
private final StructureBoundingBox volume;
|
||||
|
||||
public ChunkRenderContext(ChunkSectionPos origin, ClonedChunkSection[] sections, StructureBoundingBox volume) {
|
||||
this.origin = origin;
|
||||
this.sections = sections;
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public ChunkSectionPos getOrigin() {
|
||||
return this.origin;
|
||||
}
|
||||
|
||||
public ClonedChunkSection[] getSections() {
|
||||
return this.sections;
|
||||
}
|
||||
|
||||
public StructureBoundingBox getVolume() {
|
||||
return this.volume;
|
||||
}
|
||||
}
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.world.cloned;
|
||||
|
||||
import com.falsepattern.endlessids.mixin.helpers.ChunkBiomeHook;
|
||||
import com.gtnewhorizons.angelica.compat.ExtendedBlockStorageExt;
|
||||
import com.gtnewhorizons.angelica.compat.ModStatus;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
|
||||
import it.unimi.dsi.fastutil.shorts.Short2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap;
|
||||
import mega.fluidlogged.internal.mixin.hook.FLSubChunk;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.EnumSkyBlock;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.NibbleArray;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
public class ClonedChunkSection {
|
||||
|
||||
private static final ExtendedBlockStorage EMPTY_SECTION = new ExtendedBlockStorage(0, false);
|
||||
|
||||
private final ClonedChunkSectionCache backingCache;
|
||||
private final World world;
|
||||
|
||||
private ChunkSectionPos pos;
|
||||
private ExtendedBlockStorageExt data;
|
||||
private BiomeGenBase[] biomeData;
|
||||
private final Short2ObjectMap<TileEntity> tileEntities;
|
||||
|
||||
private long lastUsedTimestamp = Long.MAX_VALUE;
|
||||
|
||||
ClonedChunkSection(ClonedChunkSectionCache backingCache, World world) {
|
||||
this.backingCache = backingCache;
|
||||
this.world = world;
|
||||
this.tileEntities = new Short2ObjectOpenHashMap<>();
|
||||
}
|
||||
|
||||
public void init(ChunkSectionPos pos) {
|
||||
final Chunk chunk = world.getChunkFromChunkCoords(pos.x, pos.z);
|
||||
|
||||
if (chunk == null) {
|
||||
throw new RuntimeException("Couldn't retrieve chunk at " + pos.toChunkPos());
|
||||
}
|
||||
|
||||
ExtendedBlockStorage section = getChunkSection(chunk, pos);
|
||||
|
||||
if (section == null) {
|
||||
section = EMPTY_SECTION;
|
||||
}
|
||||
|
||||
this.pos = pos;
|
||||
this.data = new ExtendedBlockStorageExt(chunk, section);
|
||||
|
||||
int bArrLength;
|
||||
if (ModStatus.isEIDBiomeLoaded) {
|
||||
bArrLength = ((ChunkBiomeHook) chunk).getBiomeShortArray().length;
|
||||
} else {
|
||||
bArrLength = chunk.getBiomeArray().length;
|
||||
}
|
||||
this.biomeData = new BiomeGenBase[bArrLength];
|
||||
|
||||
this.tileEntities.clear();
|
||||
|
||||
// Check for tile entities
|
||||
for (int y = pos.getMinY(); y <= pos.getMaxY(); y++) {
|
||||
for (int z = pos.getMinZ(); z <= pos.getMaxZ(); z++) {
|
||||
for (int x = pos.getMinX(); x <= pos.getMaxX(); x++) {
|
||||
final int lX = x & 15, lY = y & 15, lZ = z & 15;
|
||||
// We have to use this insanity because in 1.7 the tile entity isn't guaranteed to be created
|
||||
// when the chunk gets scheduled for rendering. So we might have to create it.
|
||||
// Cloning is done on the main thread so this will not introduce threading issues
|
||||
final Block block = data.getBlockByExtId(lX, lY, lZ);
|
||||
if (block.hasTileEntity(data.getExtBlockMetadata(lX, lY, lZ))) {
|
||||
final TileEntity tileEntity = chunk.func_150806_e(x & 15, y, z & 15);
|
||||
if (tileEntity != null) {
|
||||
this.tileEntities.put(ChunkSectionPos.packLocal(tileEntity.xCoord & 15, tileEntity.yCoord & 15, tileEntity.zCoord & 15), tileEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fill biome data
|
||||
for (int z = pos.getMinZ(); z <= pos.getMaxZ(); z++) {
|
||||
for (int x = pos.getMinX(); x <= pos.getMaxX(); x++) {
|
||||
this.biomeData[(x & 15) | ((z & 15) << 4)] = world.getBiomeGenForCoords(x, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Block getBlock(int x, int y, int z) {
|
||||
return data.getBlockByExtId(x, y, z);
|
||||
}
|
||||
|
||||
public int getBlockMetadata(int x, int y, int z) {
|
||||
return data.getExtBlockMetadata(x, y, z);
|
||||
}
|
||||
|
||||
public Fluid getFluid(int x, int y, int z) {
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
return ((FLSubChunk) data).fl$getFluid(x, y, z);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public NibbleArray getLightArray(EnumSkyBlock type) {
|
||||
if (type == EnumSkyBlock.Sky) {
|
||||
return (!world.provider.hasNoSky && data.hasSky) ? data.getSkylightArray() : null;
|
||||
}
|
||||
return data.getBlocklightArray();
|
||||
}
|
||||
|
||||
public BiomeGenBase[] getBiomeData() {
|
||||
return this.biomeData;
|
||||
}
|
||||
|
||||
public BiomeGenBase getBiomeForNoiseGen(int x, int z) {
|
||||
return this.biomeData[(x & 15) | ((z & 15) << 4)];
|
||||
}
|
||||
|
||||
public TileEntity getBlockEntity(int x, int y, int z) {
|
||||
return this.tileEntities.get(ChunkSectionPos.packLocal(x, y, z));
|
||||
}
|
||||
|
||||
public ChunkSectionPos getPosition() {
|
||||
return this.pos;
|
||||
}
|
||||
|
||||
public ExtendedBlockStorageExt getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public ClonedChunkSectionCache getBackingCache() {
|
||||
return this.backingCache;
|
||||
}
|
||||
|
||||
public long getLastUsedTimestamp() {
|
||||
return this.lastUsedTimestamp;
|
||||
}
|
||||
|
||||
public void setLastUsedTimestamp(long timestamp) {
|
||||
this.lastUsedTimestamp = timestamp;
|
||||
}
|
||||
|
||||
public static boolean isOutOfBuildLimitVertically(int y) {
|
||||
return y < 0 || y >= 256;
|
||||
}
|
||||
|
||||
private static ExtendedBlockStorage getChunkSection(Chunk chunk, ChunkSectionPos pos) {
|
||||
if (!isOutOfBuildLimitVertically(ChunkSectionPos.getBlockCoord(pos.y))) {
|
||||
return chunk.getBlockStorageArray()[pos.y];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.gtnewhorizons.angelica.rendering.celeritas.world.cloned;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ReferenceLinkedOpenHashMap;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ClonedChunkSectionCache {
|
||||
private static final int MAX_CACHE_SIZE = 512;
|
||||
private static final long MAX_CACHE_DURATION = TimeUnit.SECONDS.toNanos(5);
|
||||
|
||||
private final World world;
|
||||
private final Long2ReferenceLinkedOpenHashMap<ClonedChunkSection> byPosition = new Long2ReferenceLinkedOpenHashMap<>();
|
||||
private long time;
|
||||
|
||||
public ClonedChunkSectionCache(World world) {
|
||||
this.world = world;
|
||||
this.time = getMonotonicTimeSource();
|
||||
}
|
||||
|
||||
public synchronized void cleanup() {
|
||||
this.time = getMonotonicTimeSource();
|
||||
this.byPosition.values().removeIf(entry -> this.time > (entry.getLastUsedTimestamp() + MAX_CACHE_DURATION));
|
||||
}
|
||||
|
||||
public synchronized ClonedChunkSection acquire(int x, int y, int z) {
|
||||
final long key = ChunkSectionPos.asLong(x, y, z);
|
||||
ClonedChunkSection section = this.byPosition.getAndMoveToLast(key);
|
||||
|
||||
if (section == null) {
|
||||
while (this.byPosition.size() >= MAX_CACHE_SIZE) {
|
||||
this.byPosition.removeFirst();
|
||||
}
|
||||
section = this.createSection(x, y, z);
|
||||
}
|
||||
|
||||
section.setLastUsedTimestamp(this.time);
|
||||
return section;
|
||||
}
|
||||
|
||||
private ClonedChunkSection createSection(int x, int y, int z) {
|
||||
final ClonedChunkSection section = new ClonedChunkSection(this, this.world);
|
||||
final ChunkSectionPos pos = ChunkSectionPos.from(x, y, z);
|
||||
section.init(pos);
|
||||
this.byPosition.putAndMoveToLast(pos.asLong(), section);
|
||||
return section;
|
||||
}
|
||||
|
||||
public synchronized void invalidate(int x, int y, int z) {
|
||||
this.byPosition.remove(ChunkSectionPos.asLong(x, y, z));
|
||||
}
|
||||
|
||||
private static long getMonotonicTimeSource() {
|
||||
return System.nanoTime();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user