diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/mojang/DefaultVertexFormat.java b/src/main/java/com/gtnewhorizons/angelica/compat/mojang/DefaultVertexFormat.java index a280624a2..a0f8aac17 100644 --- a/src/main/java/com/gtnewhorizons/angelica/compat/mojang/DefaultVertexFormat.java +++ b/src/main/java/com/gtnewhorizons/angelica/compat/mojang/DefaultVertexFormat.java @@ -5,7 +5,7 @@ import com.gtnewhorizons.angelica.compat.mojang.VertexFormatElement.Type; import com.gtnewhorizons.angelica.compat.mojang.VertexFormatElement.Usage; import com.gtnewhorizons.angelica.compat.nd.writers.ItemVBOQuadWriter; import com.gtnewhorizons.angelica.compat.nd.writers.PositionQuadWriter; -import net.minecraft.client.renderer.OpenGlHelper; +import com.gtnewhorizons.angelica.compat.nd.writers.PositionTextureQuadWriter; public class DefaultVertexFormat { @@ -17,14 +17,14 @@ public class DefaultVertexFormat { public static final VertexFormatElement OVERLAY_ELEMENT = new VertexFormatElement(1, Type.SHORT, Usage.UV, 2); public static final VertexFormatElement NORMAL_ELEMENT = new VertexFormatElement(0, Type.BYTE, Usage.NORMAL, 3); public static final VertexFormatElement PADDING_ELEMENT = new VertexFormatElement(0, Type.BYTE, Usage.PADDING, 1); - public static final VertexFormat ITEM_VBO = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(TEXTURE_ELEMENT).add(NORMAL_ELEMENT).add(PADDING_ELEMENT).build(), new ItemVBOQuadWriter()); + public static final VertexFormat POSITION_TEXTURE_NORMAL = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(TEXTURE_ELEMENT).add(NORMAL_ELEMENT).add(PADDING_ELEMENT).build(), new ItemVBOQuadWriter()); public static final VertexFormat POSITION_COLOR_TEXTURE_LIGHT_NORMAL = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(COLOR_ELEMENT).add(TEXTURE_ELEMENT).add(LIGHT_ELEMENT).add(NORMAL_ELEMENT).add(PADDING_ELEMENT).build()); public static final VertexFormat POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(COLOR_ELEMENT).add(TEXTURE_ELEMENT).add(OVERLAY_ELEMENT).add(LIGHT_ELEMENT).add(NORMAL_ELEMENT).add(PADDING_ELEMENT).build()); public static final VertexFormat POSITION_TEXTURE_COLOR_LIGHT = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(TEXTURE_ELEMENT).add(COLOR_ELEMENT).add(LIGHT_ELEMENT).build()); public static final VertexFormat POSITION = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).build(), new PositionQuadWriter()); public static final VertexFormat POSITION_COLOR = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(COLOR_ELEMENT).build()); public static final VertexFormat POSITION_COLOR_LIGHT = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(COLOR_ELEMENT).add(LIGHT_ELEMENT).build()); - public static final VertexFormat POSITION_TEXTURE = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(TEXTURE_ELEMENT).build()); + public static final VertexFormat POSITION_TEXTURE = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(TEXTURE_ELEMENT).build(), new PositionTextureQuadWriter()); public static final VertexFormat POSITION_COLOR_TEXTURE = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(COLOR_ELEMENT).add(TEXTURE_ELEMENT).build()); public static final VertexFormat POSITION_TEXTURE_COLOR = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(TEXTURE_ELEMENT).add(COLOR_ELEMENT).build()); public static final VertexFormat POSITION_COLOR_TEX_LIGHTMAP = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(COLOR_ELEMENT).add(TEXTURE_ELEMENT).add(LIGHT_ELEMENT).build()); diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/mojang/VertexBuffer.java b/src/main/java/com/gtnewhorizons/angelica/compat/mojang/VertexBuffer.java index a890eb301..ec0f0f9cd 100644 --- a/src/main/java/com/gtnewhorizons/angelica/compat/mojang/VertexBuffer.java +++ b/src/main/java/com/gtnewhorizons/angelica/compat/mojang/VertexBuffer.java @@ -1,8 +1,5 @@ package com.gtnewhorizons.angelica.compat.mojang; -import com.gtnewhorizons.angelica.mixins.interfaces.ITessellatorInstance; -import net.minecraft.client.renderer.Tessellator; -import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL15; @@ -13,11 +10,17 @@ import java.nio.FloatBuffer; public class VertexBuffer implements AutoCloseable { private int id; private int vertexCount; + private VertexFormat format; public VertexBuffer() { this.id = GL15.glGenBuffers(); } + public VertexBuffer(VertexFormat format) { + this(); + this.format = format; + } + public void bind() { GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.id); } @@ -34,6 +37,12 @@ public class VertexBuffer implements AutoCloseable { this.unbind(); } + public VertexBuffer upload(ByteBuffer buffer) { + if(format == null) throw new IllegalStateException("No format specified for VBO upload"); + upload(buffer, buffer.capacity() / format.getVertexSize()); + return this; + } + public void close() { if (this.id >= 0) { GL15.glDeleteBuffers(this.id); @@ -52,4 +61,13 @@ public class VertexBuffer implements AutoCloseable { public void draw(int mode) { GL11.glDrawArrays(mode, 0, this.vertexCount); } + + public void render(int mode) { + if(format == null) throw new IllegalStateException("No format specified for VBO render"); + bind(); + format.setupBufferState(0L); + draw(mode); + format.clearBufferState(); + unbind(); + } } diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/nd/writers/PositionTextureQuadWriter.java b/src/main/java/com/gtnewhorizons/angelica/compat/nd/writers/PositionTextureQuadWriter.java new file mode 100644 index 000000000..ce44c9e64 --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/compat/nd/writers/PositionTextureQuadWriter.java @@ -0,0 +1,44 @@ +package com.gtnewhorizons.angelica.compat.nd.writers; + +import com.gtnewhorizons.angelica.compat.nd.IWriteQuads; +import com.gtnewhorizons.angelica.compat.nd.Quad; + +import java.nio.ByteBuffer; + +public class PositionTextureQuadWriter implements IWriteQuads { + private boolean direct; + + public PositionTextureQuadWriter() { + init(false); + } + + public void init(boolean direct) { + // This would need to be re-initialized if the direct vs indirect changes + this.direct = direct; + } + @Override + public void writeQuad(Quad quad, ByteBuffer buf) { + if(direct) { + writeQuadDirect(quad, buf); + } else { + writeQuadIndirect(quad, buf); + } + } + + protected void writeQuadDirect(Quad quad, ByteBuffer buf) { + throw new UnsupportedOperationException("Direct mode not supported yet"); + } + + protected void writeQuadIndirect(Quad quad, ByteBuffer buf) { + for(int idx = 0; idx < 4; ++idx) { + // Position + buf.putFloat(quad.getX(idx)); + buf.putFloat(quad.getY(idx)); + buf.putFloat(quad.getZ(idx)); + + // Texture + buf.putFloat(quad.getTexU(idx)); + buf.putFloat(quad.getTexV(idx)); + } + } +} diff --git a/src/main/java/com/gtnewhorizons/angelica/glsm/TessellatorManager.java b/src/main/java/com/gtnewhorizons/angelica/glsm/TessellatorManager.java index 6eaa1a7a7..798a07546 100644 --- a/src/main/java/com/gtnewhorizons/angelica/glsm/TessellatorManager.java +++ b/src/main/java/com/gtnewhorizons/angelica/glsm/TessellatorManager.java @@ -1,10 +1,13 @@ package com.gtnewhorizons.angelica.glsm; import com.gtnewhorizons.angelica.client.renderer.CapturingTessellator; +import com.gtnewhorizons.angelica.compat.mojang.VertexBuffer; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import com.gtnewhorizons.angelica.compat.nd.Quad; import com.gtnewhorizons.angelica.mixins.interfaces.ITessellatorInstance; import net.minecraft.client.renderer.Tessellator; +import java.nio.ByteBuffer; import java.util.List; @SuppressWarnings("unused") @@ -36,11 +39,16 @@ public class TessellatorManager { public static void startCapturing() { if(currentlyCapturing.get()) throw new IllegalStateException("Tried to start capturing when already capturing!"); + if(capturingTessellator.get().getQuads().size() > 0) throw new IllegalStateException("Tried to start capturing with existing collected Quads!"); + currentlyCapturing.set(true); } - - public static List stopCapturing() { + /* + * Stop the CapturingTessellator and return the pooled quads. The quads are valid until clearQuads() is + * called on the CapturingTesselator, which must be done before starting capturing again. + */ + public static List stopCapturingToPooledQuads() { if(!currentlyCapturing.get()) throw new IllegalStateException("Tried to stop capturing when not capturing!"); currentlyCapturing.set(false); final CapturingTessellator tess = capturingTessellator.get(); @@ -54,8 +62,22 @@ public class TessellatorManager { return quads; } - public static void clearQuads() { + /* + * Stops the CapturingTessellator, stores the quads in a buffer (based on the VertexFormat provided), + * and clears the quads. + */ + public static ByteBuffer stopCapturingToBuffer(VertexFormat format) { + final ByteBuffer buf = CapturingTessellator.quadsToBuffer(stopCapturingToPooledQuads(), format); capturingTessellator.get().clearQuads(); + return buf; + } + + /* + * Stops the CapturingTessellator, stores the quads in a buffer (based on the VertexFormat provided), + * uploads the buffer to a new VertexBuffer, and clears the quads. + */ + public static VertexBuffer stopCapturingToVBO(VertexFormat format) { + return new VertexBuffer(format).upload(stopCapturingToBuffer(format)); } static { @@ -64,11 +86,10 @@ public class TessellatorManager { public static void cleanup() { // Ensure we've cleaned everything up - if(currentlyCapturing.get()) { - currentlyCapturing.set(false); - final CapturingTessellator tess = capturingTessellator.get(); - ((ITessellatorInstance)tess).discard(); - tess.clearQuads(); - } + final CapturingTessellator tessellator = capturingTessellator.get(); + + currentlyCapturing.set(false); + ((ITessellatorInstance)tessellator).discard(); + tessellator.clearQuads(); } } diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java b/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java index 863c4713e..2a954d130 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java @@ -27,10 +27,16 @@ public enum Mixins { .setPhase(Phase.EARLY).addMixinClasses( "angelica.MixinActiveRenderInfo" ,"angelica.MixinEntityRenderer" - ,"angelica.vbo.MixinWavefrontObject" ) ), - + ANGELICA_VBO( + new Builder("Angelica VBO").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT) + .setPhase(Phase.EARLY).addMixinClasses( + "angelica.vbo.MixinWavefrontObject" + ,"angelica.vbo.MixinRenderGlobal" + ,"angelica.vbo.MixinModelRenderer" + ) + ), ANGELICA_FONT_RENDERER(new Builder("Angelica Font Renderer").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT) .setPhase(Phase.EARLY).setApplyIf(() -> AngelicaConfig.enableFontRenderer).addMixinClasses( "angelica.fontrenderer.MixinGuiIngameForge" diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/vbo/MixinModelRenderer.java b/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/vbo/MixinModelRenderer.java new file mode 100644 index 000000000..74e2b2c2b --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/vbo/MixinModelRenderer.java @@ -0,0 +1,47 @@ +package com.gtnewhorizons.angelica.mixins.early.angelica.vbo; + +import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexBuffer; +import com.gtnewhorizons.angelica.glsm.TessellatorManager; +import net.minecraft.client.model.ModelRenderer; +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.ArrayList; + +@Mixin(ModelRenderer.class) +public class MixinModelRenderer { + @Shadow + public int displayList; + private static int nextDisplayList = 0; + private static int getNextDisplayList() { + return nextDisplayList++; + } + private static ArrayList vertexBuffers = new ArrayList<>(); + + @Redirect(method = "compileDisplayList", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GLAllocation;generateDisplayLists(I)I")) + public int generateDisplayLists(int range) { + return getNextDisplayList(); + } + + @Redirect(method = "compileDisplayList", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glNewList(II)V", remap = false)) + public void startCapturingVBO(int list, int mode) { + TessellatorManager.startCapturing(); + } + @Redirect(method = "compileDisplayList", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glEndList()V", remap = false)) + public void stopCapturingVBO() { + vertexBuffers.add(this.displayList, TessellatorManager.stopCapturingToVBO(DefaultVertexFormat.POSITION_TEXTURE_NORMAL)); + } + + @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glCallList(I)V", remap = false)) + public void renderVBO(int list) { + vertexBuffers.get(list).render(GL11.GL_QUADS); + } + @Redirect(method = "renderWithRotation", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glCallList(I)V", remap = false)) + public void renderWithRotationVBO(int list) { + vertexBuffers.get(list).render(GL11.GL_QUADS); + } +} diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/vbo/MixinRenderGlobal.java b/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/vbo/MixinRenderGlobal.java new file mode 100644 index 000000000..6fa9b52fb --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/vbo/MixinRenderGlobal.java @@ -0,0 +1,83 @@ +package com.gtnewhorizons.angelica.mixins.early.angelica.vbo; + +import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexBuffer; +import com.gtnewhorizons.angelica.glsm.TessellatorManager; +import com.gtnewhorizons.angelica.mixins.interfaces.IRenderGlobalVBOCapture; +import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.client.renderer.Tessellator; +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(value = RenderGlobal.class, remap = false) +public class MixinRenderGlobal implements IRenderGlobalVBOCapture { + @Unique private VertexBuffer starVBO; + @Unique private VertexBuffer skyVBO; + @Unique private VertexBuffer sky2VBO; + + private static final int MAGIC_NUMER = -1000; + private static final int STARS = MAGIC_NUMER; + private static final int SKY = MAGIC_NUMER + 1; + private static final int SKY2 = MAGIC_NUMER + 2; + @Redirect(method="", at = @At(value="INVOKE", target="Lnet/minecraft/client/renderer/GLAllocation;generateDisplayLists(I)I")) + private int generateDisplayLists(int range) { + // Don't allocate the display lists, we'll be making VBOs instead. Return a magic number for identification below. + return MAGIC_NUMER; + } + + @Override + @Redirect(method="", at = @At(value="INVOKE", target="Lorg/lwjgl/opengl/GL11;glNewList(II)V", ordinal = 0)) + public void startStarsVBO(int list, int mode) { + TessellatorManager.startCapturing(); + } + + @Override + @Redirect(method="", at = @At(value="INVOKE", target="Lorg/lwjgl/opengl/GL11;glEndList()V", ordinal = 0)) + public void finishStarsVBO() { + this.starVBO = TessellatorManager.stopCapturingToVBO(DefaultVertexFormat.POSITION); + } + + @Redirect(method="", at = @At(value="FIELD", target="Lnet/minecraft/client/renderer/Tessellator;instance:Lnet/minecraft/client/renderer/Tessellator;")) + private Tessellator redirectTessellator() { + TessellatorManager.startCapturing(); + return TessellatorManager.get(); + } + + @Override + @Redirect(method="", at = @At(value="INVOKE", target="Lorg/lwjgl/opengl/GL11;glNewList(II)V", ordinal = 1)) + public void startSkyVBO(int list, int mode) { + // Do nothing, we'll be making a VBO instead. + } + + @Override + @Redirect(method="", at = @At(value="INVOKE", target="Lorg/lwjgl/opengl/GL11;glEndList()V", ordinal = 1)) + public void finishSkyVBO() { + this.skyVBO = TessellatorManager.stopCapturingToVBO(DefaultVertexFormat.POSITION); + } + + @Override + @Redirect(method="", at = @At(value="INVOKE", target="Lorg/lwjgl/opengl/GL11;glNewList(II)V", ordinal = 2)) + public void startSky2VBO(int list, int mode) { + TessellatorManager.startCapturing(); + } + + @Override + @Redirect(method="", at = @At(value="INVOKE", target="Lorg/lwjgl/opengl/GL11;glEndList()V", ordinal = 2)) + public void finishSky2VBO() { + this.sky2VBO = TessellatorManager.stopCapturingToVBO(DefaultVertexFormat.POSITION); + } + + @Redirect(method="renderSky(F)V", at = @At(value="INVOKE", target="Lorg/lwjgl/opengl/GL11;glCallList(I)V")) + public void renderSky(int list) { + VertexBuffer vbo = switch (list) { + case STARS -> this.starVBO; + case SKY -> this.skyVBO; + case SKY2 -> this.sky2VBO; + default -> throw new RuntimeException("Unexpected display list: " + list); + }; + vbo.render(GL11.GL_QUADS); + } +} diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/vbo/MixinWavefrontObject.java b/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/vbo/MixinWavefrontObject.java index 29caaea27..719f305c5 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/vbo/MixinWavefrontObject.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/vbo/MixinWavefrontObject.java @@ -1,10 +1,9 @@ package com.gtnewhorizons.angelica.mixins.early.angelica.vbo; import com.gtnewhorizons.angelica.client.renderer.CapturingTessellator; +import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; import com.gtnewhorizons.angelica.compat.mojang.VertexBuffer; import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; -import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; -import com.gtnewhorizons.angelica.compat.nd.Quad; import com.gtnewhorizons.angelica.glsm.TessellatorManager; import com.gtnewhorizons.angelica.mixins.interfaces.IModelCustomExt; import net.minecraft.client.renderer.Tessellator; @@ -15,9 +14,6 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; -import java.nio.ByteBuffer; -import java.util.List; - @Mixin(value = WavefrontObject.class, remap = false) public abstract class MixinWavefrontObject implements IModelCustomExt { @Unique private VertexBuffer vertexBuffer; @@ -26,7 +22,7 @@ public abstract class MixinWavefrontObject implements IModelCustomExt { @Shadow public abstract void tessellateAll(Tessellator tessellator); - @Unique VertexFormat format = DefaultVertexFormat.ITEM_VBO; + @Unique VertexFormat format = DefaultVertexFormat.POSITION_TEXTURE_NORMAL; @Override public void rebuildVBO() { @@ -40,13 +36,8 @@ public abstract class MixinWavefrontObject implements IModelCustomExt { final CapturingTessellator tess = (CapturingTessellator) TessellatorManager.get(); tess.startDrawing(currentGroupObject.glDrawingMode); tessellateAll(tess); - List quads = TessellatorManager.stopCapturing(); - final ByteBuffer byteBuffer = CapturingTessellator.quadsToBuffer(quads, format); - this.vertexBuffer = new VertexBuffer(); - this.vertexBuffer.bind(); - vertexBuffer.upload(byteBuffer, quads.size() * 4); - this.vertexBuffer.unbind(); + this.vertexBuffer = TessellatorManager.stopCapturingToVBO(format); } @Override @@ -54,11 +45,7 @@ public abstract class MixinWavefrontObject implements IModelCustomExt { if(vertexBuffer == null) { rebuildVBO(); } - vertexBuffer.bind(); - format.setupBufferState(0L); - vertexBuffer.draw(GL11.GL_QUADS); - format.clearBufferState(); - vertexBuffer.unbind(); + vertexBuffer.render(GL11.GL_QUADS); } } diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/early/sodium/AccessorBiomeColorEvent.java b/src/main/java/com/gtnewhorizons/angelica/mixins/early/sodium/AccessorBiomeColorEvent.java index e6400814b..2742ec63b 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/early/sodium/AccessorBiomeColorEvent.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/early/sodium/AccessorBiomeColorEvent.java @@ -6,6 +6,6 @@ import org.spongepowered.asm.mixin.gen.Accessor; @Mixin(BiomeEvent.BiomeColor.class) public interface AccessorBiomeColorEvent { - @Accessor("originalColor") + @Accessor(value = "originalColor", remap = false) void setOriginalColor(int value); } diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/interfaces/IRenderGlobalVBOCapture.java b/src/main/java/com/gtnewhorizons/angelica/mixins/interfaces/IRenderGlobalVBOCapture.java new file mode 100644 index 000000000..4cea94ae2 --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/interfaces/IRenderGlobalVBOCapture.java @@ -0,0 +1,14 @@ +package com.gtnewhorizons.angelica.mixins.interfaces; + +public interface IRenderGlobalVBOCapture { + void startStarsVBO(int list, int mode); + void finishStarsVBO(); + + void startSkyVBO(int list, int mode); + void finishSkyVBO(); + + void startSky2VBO(int list, int mode); + void finishSky2VBO(); + + +} diff --git a/src/main/java/jss/notfine/render/RenderStars.java b/src/main/java/jss/notfine/render/RenderStars.java index fe76673eb..53104a490 100644 --- a/src/main/java/jss/notfine/render/RenderStars.java +++ b/src/main/java/jss/notfine/render/RenderStars.java @@ -1,5 +1,6 @@ package jss.notfine.render; +import com.gtnewhorizons.angelica.mixins.interfaces.IRenderGlobalVBOCapture; import jss.notfine.core.Settings; import jss.util.RandomXoshiro256StarStar; import net.minecraft.client.renderer.RenderGlobal; @@ -11,11 +12,9 @@ public class RenderStars { //private static final ResourceLocation locationStarsPng = new ResourceLocation("textures/colormap/stars.png"); public static void reloadStarRenderList(RenderGlobal render) { - GL11.glPushMatrix(); - GL11.glNewList(render.starGLCallList, GL11.GL_COMPILE); + ((IRenderGlobalVBOCapture)render).startStarsVBO(render.starGLCallList, GL11.GL_COMPILE); renderStars(); - GL11.glEndList(); - GL11.glPopMatrix(); + ((IRenderGlobalVBOCapture)render).finishStarsVBO(); } public static void renderStars() { diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/pipeline/BlockRenderer.java b/src/main/java/me/jellysquid/mods/sodium/client/render/pipeline/BlockRenderer.java index 5544e59ed..13fc18395 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/pipeline/BlockRenderer.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/pipeline/BlockRenderer.java @@ -61,7 +61,7 @@ public class BlockRenderer { tess.setOffset(pos); renderBlocks.renderBlockByRenderType(block, pos.x, pos.y, pos.z); - final List quads = TessellatorManager.stopCapturing(); + final List quads = TessellatorManager.stopCapturingToPooledQuads(); for (ModelQuadFacing facing : ModelQuadFacing.VALUES) { this.random.setSeed(seed); @@ -69,8 +69,6 @@ public class BlockRenderer { } if (!quads.isEmpty()) rendered = true; - - TessellatorManager.clearQuads(); } finally { TessellatorManager.cleanup(); } diff --git a/src/main/java/net/coderbot/iris/pipeline/HorizonRenderer.java b/src/main/java/net/coderbot/iris/pipeline/HorizonRenderer.java index 0aef4773b..5be2c4072 100644 --- a/src/main/java/net/coderbot/iris/pipeline/HorizonRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/HorizonRenderer.java @@ -1,17 +1,14 @@ package net.coderbot.iris.pipeline; import com.gtnewhorizons.angelica.client.renderer.CapturingTessellator; -import com.gtnewhorizons.angelica.compat.mojang.VertexBuffer; import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; -import com.gtnewhorizons.angelica.compat.nd.Quad; +import com.gtnewhorizons.angelica.compat.mojang.VertexBuffer; import com.gtnewhorizons.angelica.glsm.TessellatorManager; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Tessellator; import org.lwjgl.opengl.GL11; -import java.nio.ByteBuffer; import java.nio.FloatBuffer; -import java.util.List; /** * Renders the sky horizon. Vanilla Minecraft simply uses the "clear color" for its horizon, and then draws a plane @@ -63,13 +60,8 @@ public class HorizonRenderer { // Build the horizon quads into a buffer tessellator.startDrawingQuads(); //(GL11.GL_QUADS, DefaultVertexFormat.POSITION); buildHorizon(currentRenderDistance * 16, tessellator); - List quads = TessellatorManager.stopCapturing(); - final ByteBuffer byteBuffer = CapturingTessellator.quadsToBuffer(quads, DefaultVertexFormat.POSITION); - this.vertexBuffer = new VertexBuffer(); - this.vertexBuffer.bind(); - this.vertexBuffer.upload(byteBuffer, quads.size() * 4); - this.vertexBuffer.unbind(); + this.vertexBuffer = TessellatorManager.stopCapturingToVBO(DefaultVertexFormat.POSITION); } private void buildQuad(Tessellator consumer, double x1, double z1, double x2, double z2) { diff --git a/src/main/java/net/coderbot/iris/uniforms/MatrixUniforms.java b/src/main/java/net/coderbot/iris/uniforms/MatrixUniforms.java index 34862d742..1ab96f1d3 100644 --- a/src/main/java/net/coderbot/iris/uniforms/MatrixUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/MatrixUniforms.java @@ -55,21 +55,6 @@ public final class MatrixUniforms { } } - private static class InvertedArrayMatrix implements Supplier { - private final Supplier parent; - - InvertedArrayMatrix(Supplier parent) { - this.parent = parent; - } - - @Override - public Matrix4f get() { - final Matrix4f matrix4f = new Matrix4f().set(parent.get()); - matrix4f.invert(); - - return matrix4f; - } - } private static class Previous implements Supplier { private final Supplier parent; diff --git a/src/main/java/net/coderbot/iris/uniforms/builtin/BuiltinReplacementUniforms.java b/src/main/java/net/coderbot/iris/uniforms/builtin/BuiltinReplacementUniforms.java index 7a3450abe..ca6587527 100644 --- a/src/main/java/net/coderbot/iris/uniforms/builtin/BuiltinReplacementUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/builtin/BuiltinReplacementUniforms.java @@ -9,15 +9,11 @@ public class BuiltinReplacementUniforms { private static final Matrix4f lightmapTextureMatrix; static { - // This mimics the transformations done in LightmapTextureManager to the GL_TEXTURE matrix. - lightmapTextureMatrix = new Matrix4f(); - lightmapTextureMatrix.identity(); - lightmapTextureMatrix.scale(0.00390625f); - - // TODO: Iris-Shaders - Is this logic correct? - final Matrix4f translateMatrix = new Matrix4f(); - translateMatrix.translate(8.0f, 8.0f, 8.0f); - lightmapTextureMatrix.mul(translateMatrix); + // This mimics the transformations done in LightTexture to the GL_TEXTURE matrix. + lightmapTextureMatrix = new Matrix4f(0.00390625f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.00390625f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.00390625f, 0.0f, + 0.03125f, 0.03125f, 0.03125f, 1.0f); } public static void addBuiltinReplacementUniforms(UniformHolder uniforms) {