Add cached block item renderer (#1730)

This commit is contained in:
sisyphussy authored and GitHub committed 2026-05-19 08:03:51 -07:00
1 parent 9c1b6c75ff
commit efbca29381
7 files changed
+144 -6

No files matched your search

@@ -130,7 +130,10 @@ public enum Mixins implements IMixins {
ANGELICA_ITEM_RENDERER_OPTIMIZATION(new MixinBuilder("Optimizes in-world item rendering")
.setPhase(Phase.EARLY)
.addClientMixins("angelica.itemrenderer.MixinItemRenderer")
.addClientMixins(
"angelica.itemrenderer.MixinItemRenderer",
"angelica.itemrenderer.MixinRenderBlocks"
)
.setApplyIf(() -> AngelicaConfig.optimizeInWorldItemRendering)),
ANGELICA_OPTIMIZE_GLALLOCATION(new MixinBuilder("Replace HashMap with fastutil Int2IntMap in GLAllocation")
@@ -0,0 +1,74 @@
package com.gtnewhorizons.angelica.rendering.items;
import com.gtnewhorizons.angelica.glsm.DisplayListManager;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.minecraft.block.Block;
import org.lwjgl.opengl.GL11;
public class BlockRenderListManager {
private static final BlockMeta key = new BlockMeta();
private static final Object2IntOpenHashMap<BlockMeta> displayListMap = new Object2IntOpenHashMap<>();
private static final int ISBRH_CUTOFF = 40;
private static final boolean[] notISBRH = new boolean[ISBRH_CUTOFF];
static {
for (int i : new int[]
{ 0, 31, 39, 16, 26, 1, 19, 23, 13, 6, 2, 10, 27, 11, 21, 32, 35, 34, 38 }
) {
notISBRH[i] = true;
}
}
public static boolean isISBRH(int renderType) {
return renderType >= ISBRH_CUTOFF || renderType < 0 || !notISBRH[renderType];
}
public static int getDisplayList(Block block, int meta) {
key.block = block;
key.meta = meta;
return displayListMap.getInt(key);
}
public static int startCompiling() {
final int list = GLStateManager.glGenLists(1);
GLStateManager.glNewList(list, GL11.GL_COMPILE);
return list;
}
public static void endCompiling(int list, Block block, int meta) {
DisplayListManager.discardMatrixTransforms();
GLStateManager.glEndList();
displayListMap.put(new BlockMeta(block, meta), list);
}
private static final class BlockMeta {
private Block block;
private int meta;
public BlockMeta() {
}
public BlockMeta(Block block, int meta) {
this.block = block;
this.meta = meta;
}
@Override
public int hashCode() {
return (block.hashCode() * 31 + meta) * 31;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof BlockMeta other)) return false;
return block == other.block && meta == other.meta;
}
}
}
@@ -23,7 +23,7 @@
* along with FalseTweaks. If not, see <https://www.gnu.org/licenses/>.
*/
package com.gtnewhorizons.angelica.rendering;
package com.gtnewhorizons.angelica.rendering.items;
import com.gtnewhorizon.gtnhlib.client.renderer.DirectTessellator;
import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager;