diff --git a/src/main/java/com/gtnewhorizons/angelica/client/renderer/CapturingTessellator.java b/src/main/java/com/gtnewhorizons/angelica/client/renderer/CapturingTessellator.java new file mode 100644 index 000000000..5aec749cd --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/client/renderer/CapturingTessellator.java @@ -0,0 +1,94 @@ +package com.gtnewhorizons.angelica.client.renderer; + +import com.gtnewhorizons.angelica.compat.mojang.BlockPos; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; +import com.gtnewhorizons.angelica.compat.nd.Quad; +import com.gtnewhorizons.angelica.compat.nd.RecyclingList; +import me.jellysquid.mods.sodium.client.render.pipeline.BlockRenderer; +import net.minecraft.client.renderer.Tessellator; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.GL11; + +import java.nio.ByteBuffer; +import java.util.List; + +/* + * To be used in conjunction with the TessellatorManager + * + * Used to capture the quads generated by the Tessellator across multiple draw calls and make the quad + * list available for usage. + * + * NOTE: This will _not_ (currently) capture, integrate, or stop any GL calls made around the tessellator draw calls. + * + */ +@SuppressWarnings("unused") +public class CapturingTessellator extends Tessellator { + private final BlockRenderer.Flags FLAGS = new BlockRenderer.Flags(true, true, true, true); + private final RecyclingList quadBuf = new RecyclingList<>(Quad::new); + + // Any offset we need to the Tesselator's offset! + private final BlockPos offset = new BlockPos(); + + public void setOffset(BlockPos pos) { + this.offset.set(pos); + } + + @Override + public int draw() { + // Adapted from Neodymium + + FLAGS.hasBrightness = this.hasBrightness; + FLAGS.hasColor = this.hasColor; + FLAGS.hasNormals = this.hasNormals; + + // TODO: Support GL_TRIANGLES + if(this.drawMode != GL11.GL_QUADS) { + throw new IllegalStateException("Currently only supports GL_QUADS"); + + } + final int verticesPerPrimitive = this.drawMode == GL11.GL_QUADS ? 4 : 3; + + + for(int quadI = 0; quadI < this.vertexCount / verticesPerPrimitive; quadI++) { + final Quad quad = quadBuf.next(); + quad.setState(this.rawBuffer, quadI * (verticesPerPrimitive * 8), FLAGS, this.drawMode, -offset.x, -offset.y, -offset.z); + + if(quad.deleted) { + quadBuf.remove(); + } + } + + final int i = this.rawBufferIndex * 4; + this.reset(); + this.isDrawing = false; + return i; + } + + @Override + public void reset() { + super.reset(); + this.offset.zero(); + } + + public List getQuads() { + return quadBuf.getAsList(); + } + + public void clearQuads() { + this.quadBuf.reset(); + } + + public static ByteBuffer quadsToBuffer(List quads, VertexFormat format) { + if(!format.canWriteQuads()) { + throw new IllegalStateException("Vertex format has no quad writer: " + format); + } + final ByteBuffer byteBuffer = BufferUtils.createByteBuffer(format.getVertexSize() * quads.size() * 4); + // noinspection ForLoopReplaceableByForEach + for (int i = 0, quadsSize = quads.size(); i < quadsSize; i++) { + format.writeQuad(quads.get(i), byteBuffer); + } + byteBuffer.rewind(); + return byteBuffer; + } + +} diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/toremove/DefaultVertexFormat.java b/src/main/java/com/gtnewhorizons/angelica/compat/mojang/DefaultVertexFormat.java similarity index 63% rename from src/main/java/com/gtnewhorizons/angelica/compat/toremove/DefaultVertexFormat.java rename to src/main/java/com/gtnewhorizons/angelica/compat/mojang/DefaultVertexFormat.java index d6a25f259..a292e0d94 100644 --- a/src/main/java/com/gtnewhorizons/angelica/compat/toremove/DefaultVertexFormat.java +++ b/src/main/java/com/gtnewhorizons/angelica/compat/mojang/DefaultVertexFormat.java @@ -1,32 +1,36 @@ -package com.gtnewhorizons.angelica.compat.toremove; +package com.gtnewhorizons.angelica.compat.mojang; import com.google.common.collect.ImmutableList; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import com.gtnewhorizons.angelica.compat.mojang.VertexFormatElement; 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 net.minecraft.client.renderer.OpenGlHelper; public class DefaultVertexFormat { public static final VertexFormatElement POSITION_ELEMENT = new VertexFormatElement(0, Type.FLOAT, Usage.POSITION, 3); public static final VertexFormatElement COLOR_ELEMENT = new VertexFormatElement(0, Type.UBYTE, Usage.COLOR, 4); - public static final VertexFormatElement TEXTURE_0_ELEMENT = new VertexFormatElement(0, Type.FLOAT, Usage.UV, 2); + public static final VertexFormatElement TEXTURE_ELEMENT = new VertexFormatElement(OpenGlHelper.defaultTexUnit, Type.FLOAT, Usage.UV, 2); + public static final VertexFormatElement LIGHT_ELEMENT = new VertexFormatElement(OpenGlHelper.lightmapTexUnit, Type.SHORT, Usage.UV, 2); + // TODO: The overlay element index is wrong, need to find a 1.7.10 equivalent public static final VertexFormatElement OVERLAY_ELEMENT = new VertexFormatElement(1, Type.SHORT, Usage.UV, 2); - public static final VertexFormatElement LIGHT_ELEMENT = new VertexFormatElement(2, 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 POSITION_COLOR_TEXTURE_LIGHT_NORMAL = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(COLOR_ELEMENT).add(TEXTURE_0_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_0_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_0_ELEMENT).add(COLOR_ELEMENT).add(LIGHT_ELEMENT).build()); + 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_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()); 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_0_ELEMENT).build()); - public static final VertexFormat POSITION_COLOR_TEXTURE = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(COLOR_ELEMENT).add(TEXTURE_0_ELEMENT).build()); - public static final VertexFormat POSITION_TEXTURE_COLOR = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(TEXTURE_0_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_0_ELEMENT).add(LIGHT_ELEMENT).build()); - public static final VertexFormat POSITION_TEXTURE_LIGHT_COLOR = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(TEXTURE_0_ELEMENT).add(LIGHT_ELEMENT).add(COLOR_ELEMENT).build()); - public static final VertexFormat POSITION_TEXTURE_COLOR_NORMAL = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(TEXTURE_0_ELEMENT).add(COLOR_ELEMENT).add(NORMAL_ELEMENT).add(PADDING_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_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()); + public static final VertexFormat POSITION_TEXTURE_LIGHT_COLOR = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(TEXTURE_ELEMENT).add(LIGHT_ELEMENT).add(COLOR_ELEMENT).build()); + public static final VertexFormat POSITION_TEXTURE_COLOR_NORMAL = new VertexFormat(new ImmutableList.Builder().add(POSITION_ELEMENT).add(TEXTURE_ELEMENT).add(COLOR_ELEMENT).add(NORMAL_ELEMENT).add(PADDING_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 a72452e39..7db861d41 100644 --- a/src/main/java/com/gtnewhorizons/angelica/compat/mojang/VertexBuffer.java +++ b/src/main/java/com/gtnewhorizons/angelica/compat/mojang/VertexBuffer.java @@ -1,5 +1,8 @@ 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; @@ -23,6 +26,47 @@ public class VertexBuffer implements AutoCloseable { GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); } + public void upload(Tessellator tessellator, VertexFormat format) { + try { + this.upload(tessellatorToBuffer(tessellator, format), tessellator.vertexCount); + } catch(Exception e) { + throw new RuntimeException("Failed to upload vertex buffer", e); + } finally { + ((ITessellatorInstance) tessellator).discard(); + } + } + + public ByteBuffer tessellatorToBuffer(Tessellator tessellator, VertexFormat format) { + + final int verticesPerPrimitive = tessellator.drawMode == GL11.GL_QUADS ? 4 : 3; + + final int[] rawBuffer = tessellator.rawBuffer; + final int byteSize = format.getVertexSize() * tessellator.vertexCount; + final ByteBuffer byteBuffer = BufferUtils.createByteBuffer(byteSize); + + + + for(int quadI = 0 ; quadI < tessellator.vertexCount / verticesPerPrimitive ; quadI++) { + for(int vertexI = 0 ; vertexI < 4 ; vertexI++) { + final int i = (quadI * 4 * 8 ) + (vertexI * 8); + + // Position + byteBuffer.putFloat(Float.intBitsToFloat(rawBuffer[i + 0])); + byteBuffer.putFloat(Float.intBitsToFloat(rawBuffer[i + 1])); + byteBuffer.putFloat(Float.intBitsToFloat(rawBuffer[i + 2])); + + // Texture + byteBuffer.putFloat(Float.intBitsToFloat(rawBuffer[i + 3])); + byteBuffer.putFloat(Float.intBitsToFloat(rawBuffer[i + 4])); + + // Normals + byteBuffer.putInt(rawBuffer[i + 6]); + } + } + + return (ByteBuffer) byteBuffer.rewind(); + } + public void upload(ByteBuffer buffer, int vertexCount) { if (this.id == -1) return; this.vertexCount = vertexCount; @@ -42,7 +86,11 @@ public class VertexBuffer implements AutoCloseable { GL11.glPushMatrix(); GL11.glLoadIdentity(); GL11.glMultMatrix(floatBuffer); - GL11.glDrawArrays(mode, 0, this.vertexCount); + draw(mode); GL11.glPopMatrix(); } + + public void draw(int mode) { + GL11.glDrawArrays(mode, 0, this.vertexCount); + } } diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/toremove/VertexFormat.java b/src/main/java/com/gtnewhorizons/angelica/compat/mojang/VertexFormat.java similarity index 75% rename from src/main/java/com/gtnewhorizons/angelica/compat/toremove/VertexFormat.java rename to src/main/java/com/gtnewhorizons/angelica/compat/mojang/VertexFormat.java index 5efd8b511..f5cd1c8d6 100644 --- a/src/main/java/com/gtnewhorizons/angelica/compat/toremove/VertexFormat.java +++ b/src/main/java/com/gtnewhorizons/angelica/compat/mojang/VertexFormat.java @@ -1,7 +1,8 @@ -package com.gtnewhorizons.angelica.compat.toremove; +package com.gtnewhorizons.angelica.compat.mojang; import com.google.common.collect.ImmutableList; -import com.gtnewhorizons.angelica.compat.mojang.VertexFormatElement; +import com.gtnewhorizons.angelica.compat.nd.IWriteQuads; +import com.gtnewhorizons.angelica.compat.nd.Quad; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; import lombok.Getter; @@ -9,6 +10,7 @@ import net.coderbot.iris.block_rendering.BlockRenderingSettings; import net.coderbot.iris.vertices.ImmediateState; import net.coderbot.iris.vertices.IrisVertexFormats; +import java.nio.ByteBuffer; import java.util.List; public class VertexFormat { @@ -18,7 +20,13 @@ public class VertexFormat { @Getter protected final int vertexSize; + protected IWriteQuads quadWriter; + public VertexFormat(ImmutableList elements) { + this(elements, null); + } + + public VertexFormat(ImmutableList elements, IWriteQuads quadWriter) { this.elements = elements; int i = 0; for (VertexFormatElement element : elements) { @@ -26,9 +34,9 @@ public class VertexFormat { i += element.getByteSize(); } vertexSize = i; + this.quadWriter = quadWriter; } - @Deprecated public void setupBufferState(long l) { if (BlockRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat() && ImmediateState.renderWithExtendedVertexFormat) { if (this == DefaultVertexFormat.POSITION_COLOR_TEXTURE_LIGHT_NORMAL || this == DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP) { @@ -44,11 +52,10 @@ public class VertexFormat { final List list = this.getElements(); for(int j = 0; j < list.size(); ++j) { - ((VertexFormatElement)list.get(j)).setupBufferState(l + (long)this.offsets.getInt(j), i); + list.get(j).setupBufferState(l + this.offsets.getInt(j), i); } } - @Deprecated public void clearBufferState() { if (BlockRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat() && ImmediateState.renderWithExtendedVertexFormat) { if (this == DefaultVertexFormat.POSITION_COLOR_TEXTURE_LIGHT_NORMAL || this == DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP) { @@ -64,4 +71,14 @@ public class VertexFormat { } } + public boolean canWriteQuads() { + return quadWriter != null; + } + + public void writeQuad(Quad quad, ByteBuffer byteBuffer) { + if(quadWriter == null) { + throw new IllegalStateException("No quad writer set"); + } + quadWriter.writeQuad(quad, byteBuffer); + } } diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/nd/IWriteQuads.java b/src/main/java/com/gtnewhorizons/angelica/compat/nd/IWriteQuads.java new file mode 100644 index 000000000..b33d71b08 --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/compat/nd/IWriteQuads.java @@ -0,0 +1,7 @@ +package com.gtnewhorizons.angelica.compat.nd; + +import java.nio.ByteBuffer; + +public interface IWriteQuads { + void writeQuad(Quad quad, ByteBuffer buf); +} diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/nd/Quad.java b/src/main/java/com/gtnewhorizons/angelica/compat/nd/Quad.java index 7d155a736..671406d86 100644 --- a/src/main/java/com/gtnewhorizons/angelica/compat/nd/Quad.java +++ b/src/main/java/com/gtnewhorizons/angelica/compat/nd/Quad.java @@ -31,7 +31,8 @@ public class Quad implements ModelQuadView { public float[] vs = new float[4]; public int[] bs = new int[4]; public int[] cs = new int[4]; - // TODO normals? + public int[] ns = new int[4]; + public boolean deleted; public ModelQuadFacing normal; @@ -51,6 +52,7 @@ public class Quad implements ModelQuadView { private boolean hasColor; private boolean hasShade; + private boolean hasNormals; public boolean hasColor() { return this.hasColor; @@ -64,6 +66,10 @@ public class Quad implements ModelQuadView { return this.hasShade; } + public boolean hasNormals() { + return this.hasNormals; + } + public ForgeDirection getFace() { // TODO: Sodium/Quad Facing return ForgeDirection.UP; @@ -111,7 +117,7 @@ public class Quad implements ModelQuadView { @Override public int getNormal(int idx) { - return 0; + return ns[idx]; } @Override @@ -136,10 +142,14 @@ public class Quad implements ModelQuadView { us[vi] = Float.intBitsToFloat(rawBuffer[i + 3]); vs[vi] = Float.intBitsToFloat(rawBuffer[i + 4]); - bs[vi] = flags.hasBrightness ? rawBuffer[i + 7] : DEFAULT_BRIGHTNESS; cs[vi] = flags.hasColor ? rawBuffer[i + 5] : DEFAULT_COLOR; + ns[vi] = flags.hasNormals ? rawBuffer[i + 6] : 0; + bs[vi] = flags.hasBrightness ? rawBuffer[i + 7] : DEFAULT_BRIGHTNESS; + this.hasColor |= flags.hasColor; this.hasShade |= flags.hasBrightness; + this.hasNormals |= flags.hasNormals; + i += 8; } @@ -155,6 +165,7 @@ public class Quad implements ModelQuadView { bs[3] = bs[2]; cs[3] = cs[2]; + ns[3] = ns[2]; } } @@ -205,39 +216,6 @@ public class Quad implements ModelQuadView { Arrays.fill(quadCountByDirection, 1); } - public void writeToBuffer(BufferWriter out) throws IOException { - for(int vertexI = 0; vertexI < 4; vertexI++) { - int vi = vertexI; - int provokingI = 3; - - float x = xs[vi]; - float y = ys[vi]; - float z = zs[vi]; - - out.writeFloat(x); - out.writeFloat(y); - out.writeFloat(z); - - float u = us[vi]; - float v = vs[vi]; - - out.writeFloat(u); - out.writeFloat(v); - - int b = bs[vi]; - - out.writeInt(b); - - int c = cs[vi]; - - out.writeInt(c); - - assert out.position() % getStride() == 0; - - //System.out.println("[" + vertexI + "] x: " + x + ", y: " + y + " z: " + z + ", u: " + u + ", v: " + v + ", b: " + b + ", c: " + c); - } - } - public int quadCountByUVDirection(boolean v) { if(v) { return quadCountByDirection[uDirectionIs01 ? 0 : 1]; @@ -285,6 +263,7 @@ public class Quad implements ModelQuadView { vs[dest] = o.vs[src]; bs[dest] = o.bs[src]; cs[dest] = o.cs[src]; + ns[dest] = o.ns[src]; updateMinMaxXYZ(); // TODO isn't doing this a waste? I should get rid of the min/maxXYZ variables entirely. } diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/nd/writers/ItemVBOQuadWriter.java b/src/main/java/com/gtnewhorizons/angelica/compat/nd/writers/ItemVBOQuadWriter.java new file mode 100644 index 000000000..d13b10866 --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/compat/nd/writers/ItemVBOQuadWriter.java @@ -0,0 +1,47 @@ +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 ItemVBOQuadWriter implements IWriteQuads { + private boolean direct; + + public ItemVBOQuadWriter() { + 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)); + + // Normals + Padding + buf.putInt(quad.getNormal(idx)); + } + } +} diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/toremove/DrawState.java b/src/main/java/com/gtnewhorizons/angelica/compat/toremove/DrawState.java index 756e23e3e..76aa2221e 100644 --- a/src/main/java/com/gtnewhorizons/angelica/compat/toremove/DrawState.java +++ b/src/main/java/com/gtnewhorizons/angelica/compat/toremove/DrawState.java @@ -1,5 +1,6 @@ package com.gtnewhorizons.angelica.compat.toremove; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import lombok.Getter; @Deprecated diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/toremove/RenderLayer.java b/src/main/java/com/gtnewhorizons/angelica/compat/toremove/RenderLayer.java index 38045148e..690b84662 100644 --- a/src/main/java/com/gtnewhorizons/angelica/compat/toremove/RenderLayer.java +++ b/src/main/java/com/gtnewhorizons/angelica/compat/toremove/RenderLayer.java @@ -1,6 +1,8 @@ package com.gtnewhorizons.angelica.compat.toremove; import com.google.common.collect.ImmutableList; +import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import it.unimi.dsi.fastutil.Hash; import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet; import lombok.Getter; diff --git a/src/main/java/com/gtnewhorizons/angelica/glsm/TessellatorManager.java b/src/main/java/com/gtnewhorizons/angelica/glsm/TessellatorManager.java index 09d1ac56c..f065417f1 100644 --- a/src/main/java/com/gtnewhorizons/angelica/glsm/TessellatorManager.java +++ b/src/main/java/com/gtnewhorizons/angelica/glsm/TessellatorManager.java @@ -1,15 +1,29 @@ package com.gtnewhorizons.angelica.glsm; +import com.gtnewhorizons.angelica.client.renderer.CapturingTessellator; +import com.gtnewhorizons.angelica.compat.nd.Quad; +import com.gtnewhorizons.angelica.mixins.interfaces.ITessellatorInstance; import net.minecraft.client.renderer.Tessellator; +import java.util.List; + +@SuppressWarnings("unused") public class TessellatorManager { - private static final ThreadLocal theTessellator = ThreadLocal.withInitial(Tessellator::new); + private static final ThreadLocal capturingTessellator = ThreadLocal.withInitial(CapturingTessellator::new); + + private static final ThreadLocal currentlyCapturing = ThreadLocal.withInitial(() -> Boolean.FALSE); private static final Thread mainThread = Thread.currentThread(); public static Tessellator get() { - if(isOnMainThread()) + if(currentlyCapturing.get()) { + return capturingTessellator.get(); + } else if(isOnMainThread()) { return Tessellator.instance; - return theTessellator.get(); + } else { + // TODO: Verify this works correctly and nothing unexpected is grabbing a tessellator off the main thread + // when not capturing + throw new IllegalStateException("Tried to get the Tessellator off the main thread when not capturing!"); + } } public static boolean isOnMainThread() { @@ -20,7 +34,38 @@ public class TessellatorManager { return instance == Tessellator.instance || isOnMainThread(); } + public static void startCapturing() { + if(currentlyCapturing.get()) throw new IllegalStateException("Tried to start capturing when already capturing!"); + currentlyCapturing.set(true); + } + + + public static List stopCapturing() { + if(!currentlyCapturing.get()) throw new IllegalStateException("Tried to stop capturing when not capturing!"); + currentlyCapturing.set(false); + final CapturingTessellator tess = capturingTessellator.get(); + + // Be sure we got all the quads + if(tess.isDrawing) tess.draw(); + + final List quads = tess.getQuads(); + ((ITessellatorInstance)tess).discard(); + + tess.clearQuads(); + return quads; + } + static { System.out.println("[TessellatorManager] Initialized on thread " + mainThread.getName()); } + + 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(); + } + } } diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java b/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java index a4316d002..5881487a8 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java @@ -27,6 +27,7 @@ public enum Mixins { .setPhase(Phase.EARLY).addMixinClasses( "angelica.MixinActiveRenderInfo" ,"angelica.MixinEntityRenderer" + ,"angelica.vbo.MixinWavefrontObject" ) ), 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 new file mode 100644 index 000000000..b35ee2e0b --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/vbo/MixinWavefrontObject.java @@ -0,0 +1,55 @@ +package com.gtnewhorizons.angelica.mixins.early.angelica.vbo; + +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.mixins.interfaces.IModelCustomExt; +import net.minecraft.client.renderer.Tessellator; +import net.minecraftforge.client.model.obj.GroupObject; +import net.minecraftforge.client.model.obj.WavefrontObject; +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; + +@Mixin(value = WavefrontObject.class, remap = false) +public abstract class MixinWavefrontObject implements IModelCustomExt { + @Unique private VertexBuffer vertexBuffer; + + @Shadow private GroupObject currentGroupObject; + + @Shadow public abstract void tessellateAll(Tessellator tessellator); + + @Unique VertexFormat format = DefaultVertexFormat.ITEM_VBO; + + @Override + public void rebuildVBO() { + if(currentGroupObject == null) { + throw new RuntimeException("No group object selected"); + } + if (this.vertexBuffer != null) { + this.vertexBuffer.close(); + } + final Tessellator tessellator = Tessellator.instance; + tessellator.startDrawing(currentGroupObject.glDrawingMode); + tessellateAll(tessellator); + + this.vertexBuffer = new VertexBuffer(); + this.vertexBuffer.bind(); + this.vertexBuffer.upload(tessellator, format); + this.vertexBuffer.unbind(); + } + + @Override + public void renderAllVBO() { + if(vertexBuffer == null) { + rebuildVBO(); + } + vertexBuffer.bind(); + format.setupBufferState(0L); + vertexBuffer.draw(GL11.GL_QUADS); + format.clearBufferState(); + vertexBuffer.unbind(); + } + +} diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinTessellator.java b/src/main/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinTessellator.java index b4507c8d7..ce9bf962e 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinTessellator.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinTessellator.java @@ -1,5 +1,6 @@ package com.gtnewhorizons.angelica.mixins.early.sodium; +import com.gtnewhorizons.angelica.client.renderer.CapturingTessellator; import com.gtnewhorizons.angelica.glsm.TessellatorManager; import com.gtnewhorizons.angelica.mixins.interfaces.ITessellatorInstance; import net.minecraft.client.renderer.Tessellator; @@ -85,6 +86,4 @@ public abstract class MixinTessellator implements ITessellatorInstance { return angelica$midTextureV; } - - } diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/interfaces/IModelCustomExt.java b/src/main/java/com/gtnewhorizons/angelica/mixins/interfaces/IModelCustomExt.java new file mode 100644 index 000000000..ebf4b73f1 --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/interfaces/IModelCustomExt.java @@ -0,0 +1,14 @@ +package com.gtnewhorizons.angelica.mixins.interfaces; + +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraftforge.client.model.IModelCustom; + +import static cpw.mods.fml.relauncher.Side.CLIENT; + +public interface IModelCustomExt extends IModelCustom { + @SideOnly(CLIENT) + void rebuildVBO(); + + @SideOnly(CLIENT) + void renderAllVBO(); +} diff --git a/src/main/java/com/gtnewhorizons/angelica/rendering/AngelicaBlockSafetyRegistry.java b/src/main/java/com/gtnewhorizons/angelica/rendering/AngelicaBlockSafetyRegistry.java index b857a97b7..31c8d312c 100644 --- a/src/main/java/com/gtnewhorizons/angelica/rendering/AngelicaBlockSafetyRegistry.java +++ b/src/main/java/com/gtnewhorizons/angelica/rendering/AngelicaBlockSafetyRegistry.java @@ -11,7 +11,7 @@ public class AngelicaBlockSafetyRegistry { private static final StampedLock LOCK = new StampedLock(); public static boolean canBlockRenderOffThread(Block block) { - long stamp = LOCK.readLock(); + final long stamp = LOCK.readLock(); boolean isOffThread, shouldPopulate; try { isOffThread = SAFETY_MAP.getBoolean(block); @@ -32,9 +32,9 @@ public class AngelicaBlockSafetyRegistry { } private static boolean populateCanRenderOffThread(Block block) { - boolean canBeOffThread = !(block.getClass().getName().startsWith("gregtech.")); + final boolean canBeOffThread = !(block.getClass().getName().startsWith("gregtech.")); - long stamp = LOCK.writeLock(); + final long stamp = LOCK.writeLock(); try { SAFETY_MAP.put(block, canBeOffThread); diff --git a/src/main/java/me/jellysquid/mods/sodium/client/gl/attribute/BufferVertexFormat.java b/src/main/java/me/jellysquid/mods/sodium/client/gl/attribute/BufferVertexFormat.java index c29582ca8..e5c05565d 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/gl/attribute/BufferVertexFormat.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/gl/attribute/BufferVertexFormat.java @@ -1,6 +1,6 @@ package me.jellysquid.mods.sodium.client.gl.attribute; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; public interface BufferVertexFormat { static BufferVertexFormat from(VertexFormat format) { diff --git a/src/main/java/me/jellysquid/mods/sodium/client/gl/attribute/GlVertexFormat.java b/src/main/java/me/jellysquid/mods/sodium/client/gl/attribute/GlVertexFormat.java index 93465e1d0..655abbe55 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/gl/attribute/GlVertexFormat.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/gl/attribute/GlVertexFormat.java @@ -1,5 +1,6 @@ package me.jellysquid.mods.sodium.client.gl.attribute; +import lombok.Getter; import me.jellysquid.mods.sodium.client.render.chunk.format.ChunkMeshAttribute; import java.util.EnumMap; @@ -18,6 +19,12 @@ public class GlVertexFormat> implements BufferVertexFormat { private final EnumMap attributesKeyed; private final GlVertexAttribute[] attributesArray; + /** + * -- GETTER -- + * + * The stride (or the size of) the vertex format in bytes + */ + @Getter private final int stride; public GlVertexFormat(Class attributeEnum, EnumMap attributesKeyed, int stride) { @@ -36,7 +43,7 @@ public class GlVertexFormat> implements BufferVertexFormat { * @throws NullPointerException If the attribute does not exist in this format */ public GlVertexAttribute getAttribute(T name) { - GlVertexAttribute attr = this.attributesKeyed.get(name); + final GlVertexAttribute attr = this.attributesKeyed.get(name); if (attr == null) { throw new NullPointerException("No attribute exists for " + name.toString()); @@ -45,13 +52,6 @@ public class GlVertexFormat> implements BufferVertexFormat { return attr; } - /** - * @return The stride (or the size of) the vertex format in bytes - */ - public int getStride() { - return this.stride; - } - @Override public String toString() { return String.format("GlVertexFormat<%s>{attributes=%d,stride=%d}", this.attributeEnum.getName(), diff --git a/src/main/java/me/jellysquid/mods/sodium/client/gl/device/GLRenderDevice.java b/src/main/java/me/jellysquid/mods/sodium/client/gl/device/GLRenderDevice.java index d7158596c..4da3b6a2e 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/gl/device/GLRenderDevice.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/gl/device/GLRenderDevice.java @@ -131,7 +131,7 @@ public class GLRenderDevice implements RenderDevice { @Override public void deleteBuffer(GlBuffer buffer) { - int handle = buffer.handle(); + final int handle = buffer.handle(); buffer.invalidateHandle(); GL15.glDeleteBuffers(handle); @@ -139,7 +139,7 @@ public class GLRenderDevice implements RenderDevice { @Override public void deleteVertexArray(GlVertexArray array) { - int handle = array.handle(); + final int handle = array.handle(); array.invalidateHandle(); GlFunctions.VERTEX_ARRAY.glDeleteVertexArrays(handle); @@ -176,7 +176,7 @@ public class GLRenderDevice implements RenderDevice { @Override public GlTessellation createTessellation(GlPrimitiveType primitiveType, TessellationBinding[] bindings) { if (GlVertexArrayTessellation.isSupported()) { - GlVertexArrayTessellation tessellation = new GlVertexArrayTessellation(new GlVertexArray(GLRenderDevice.this), primitiveType, bindings); + final GlVertexArrayTessellation tessellation = new GlVertexArrayTessellation(new GlVertexArray(GLRenderDevice.this), primitiveType, bindings); tessellation.init(this); return tessellation; @@ -193,13 +193,13 @@ public class GLRenderDevice implements RenderDevice { @Override public void multiDrawArrays(IntBuffer first, IntBuffer count) { - GlPrimitiveType primitiveType = GLRenderDevice.this.activeTessellation.getPrimitiveType(); + final GlPrimitiveType primitiveType = GLRenderDevice.this.activeTessellation.getPrimitiveType(); GL14.glMultiDrawArrays(primitiveType.getId(), first, count); } @Override public void multiDrawArraysIndirect(long pointer, int count, int stride) { - GlPrimitiveType primitiveType = GLRenderDevice.this.activeTessellation.getPrimitiveType(); + final GlPrimitiveType primitiveType = GLRenderDevice.this.activeTessellation.getPrimitiveType(); GlFunctions.INDIRECT_DRAW.glMultiDrawArraysIndirect(primitiveType.getId(), pointer, count, stride); } diff --git a/src/main/java/me/jellysquid/mods/sodium/client/gl/tessellation/TessellationBinding.java b/src/main/java/me/jellysquid/mods/sodium/client/gl/tessellation/TessellationBinding.java index b383d74e6..33accfc69 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/gl/tessellation/TessellationBinding.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/gl/tessellation/TessellationBinding.java @@ -1,11 +1,14 @@ package me.jellysquid.mods.sodium.client.gl.tessellation; +import lombok.Getter; import me.jellysquid.mods.sodium.client.gl.attribute.GlVertexAttributeBinding; import me.jellysquid.mods.sodium.client.gl.buffer.GlBuffer; public class TessellationBinding { + @Getter private final GlBuffer buffer; private final GlVertexAttributeBinding[] bindings; + @Getter private final boolean instanced; public TessellationBinding(GlBuffer buffer, GlVertexAttributeBinding[] bindings, boolean instanced) { @@ -14,15 +17,8 @@ public class TessellationBinding { this.instanced = instanced; } - public GlBuffer getBuffer() { - return this.buffer; - } - public GlVertexAttributeBinding[] getAttributeBindings() { return this.bindings; } - public boolean isInstanced() { - return this.instanced; - } } diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/buffer/VertexBufferBuilder.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/buffer/VertexBufferBuilder.java index d1bd26fec..89b98a358 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/buffer/VertexBufferBuilder.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/buffer/VertexBufferBuilder.java @@ -22,10 +22,10 @@ public class VertexBufferBuilder implements VertexBufferView { private void grow(int len) { // The new capacity will at least as large as the write it needs to service - int cap = Math.max(this.capacity * 2, this.capacity + len); + final int cap = Math.max(this.capacity * 2, this.capacity + len); // Allocate a new buffer and copy the old buffer's contents into it - ByteBuffer buffer = BufferUtils.createByteBuffer(cap); + final ByteBuffer buffer = BufferUtils.createByteBuffer(cap); this.buffer.rewind(); buffer.put(this.buffer); buffer.position(0); diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/glyph/GlyphVertexSink.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/glyph/GlyphVertexSink.java index 99f6dc181..2e64f800c 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/glyph/GlyphVertexSink.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/glyph/GlyphVertexSink.java @@ -1,7 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.glyph; -import com.gtnewhorizons.angelica.compat.toremove.DefaultVertexFormat; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import me.jellysquid.mods.sodium.client.model.vertex.VertexSink; import me.jellysquid.mods.sodium.client.util.math.Matrix4fExtended; import me.jellysquid.mods.sodium.client.util.math.MatrixUtil; diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/glyph/GlyphVertexType.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/glyph/GlyphVertexType.java index 8e51e6c7b..03ff6e52d 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/glyph/GlyphVertexType.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/glyph/GlyphVertexType.java @@ -1,7 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.glyph; import com.gtnewhorizons.angelica.compat.toremove.VertexConsumer; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.formats.glyph.writer.GlyphVertexBufferWriterNio; import me.jellysquid.mods.sodium.client.model.vertex.formats.glyph.writer.GlyphVertexBufferWriterUnsafe; diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/line/LineVertexSink.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/line/LineVertexSink.java index f0170431c..ea8f06945 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/line/LineVertexSink.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/line/LineVertexSink.java @@ -1,7 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.line; -import com.gtnewhorizons.angelica.compat.toremove.DefaultVertexFormat; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import me.jellysquid.mods.sodium.client.model.vertex.VertexSink; import me.jellysquid.mods.sodium.client.util.color.ColorABGR; diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/line/LineVertexType.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/line/LineVertexType.java index eca743691..b3bc12167 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/line/LineVertexType.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/line/LineVertexType.java @@ -1,7 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.line; import com.gtnewhorizons.angelica.compat.toremove.VertexConsumer; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.formats.line.writer.LineVertexBufferWriterNio; import me.jellysquid.mods.sodium.client.model.vertex.formats.line.writer.LineVertexBufferWriterUnsafe; diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/particle/ParticleVertexSink.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/particle/ParticleVertexSink.java index 3e9b68465..c0f975818 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/particle/ParticleVertexSink.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/particle/ParticleVertexSink.java @@ -1,7 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.particle; -import com.gtnewhorizons.angelica.compat.toremove.DefaultVertexFormat; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import me.jellysquid.mods.sodium.client.model.vertex.VertexSink; diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/particle/ParticleVertexType.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/particle/ParticleVertexType.java index b333f1534..11bce31ab 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/particle/ParticleVertexType.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/particle/ParticleVertexType.java @@ -1,7 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.particle; import com.gtnewhorizons.angelica.compat.toremove.VertexConsumer; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.formats.particle.writer.ParticleVertexBufferWriterNio; import me.jellysquid.mods.sodium.client.model.vertex.formats.particle.writer.ParticleVertexBufferWriterUnsafe; diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/QuadVertexSink.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/QuadVertexSink.java index f34a41d1a..44658758e 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/QuadVertexSink.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/QuadVertexSink.java @@ -1,8 +1,8 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.quad; -import com.gtnewhorizons.angelica.compat.toremove.DefaultVertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; import com.gtnewhorizons.angelica.compat.toremove.MatrixStack; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import me.jellysquid.mods.sodium.client.model.vertex.VertexSink; import me.jellysquid.mods.sodium.client.util.math.Matrix4fExtended; import me.jellysquid.mods.sodium.client.util.math.MatrixUtil; diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/QuadVertexType.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/QuadVertexType.java index eae76e6ff..a73c01ad4 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/QuadVertexType.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/QuadVertexType.java @@ -1,7 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.quad; import com.gtnewhorizons.angelica.compat.toremove.VertexConsumer; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.formats.quad.writer.QuadVertexBufferWriterNio; import me.jellysquid.mods.sodium.client.model.vertex.formats.quad.writer.QuadVertexBufferWriterUnsafe; diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/writer/QuadVertexBufferWriterNio.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/writer/QuadVertexBufferWriterNio.java index ef26488a4..d70b4e669 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/writer/QuadVertexBufferWriterNio.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/writer/QuadVertexBufferWriterNio.java @@ -14,9 +14,9 @@ public class QuadVertexBufferWriterNio extends VertexBufferWriterNio implements @Override public void writeQuad(float x, float y, float z, int color, float u, float v, int light, int overlay, int normal) { - int i = this.writeOffset; + final int i = this.writeOffset; - ByteBuffer buf = this.byteBuffer; + final ByteBuffer buf = this.byteBuffer; buf.putFloat(i, x); buf.putFloat(i + 4, y); buf.putFloat(i + 8, z); diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/writer/QuadVertexBufferWriterUnsafe.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/writer/QuadVertexBufferWriterUnsafe.java index 641b9bb71..f38c56d94 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/writer/QuadVertexBufferWriterUnsafe.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/quad/writer/QuadVertexBufferWriterUnsafe.java @@ -13,7 +13,7 @@ public class QuadVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe imple @Override public void writeQuad(float x, float y, float z, int color, float u, float v, int light, int overlay, int normal) { - long i = this.writePointer; + final long i = this.writePointer; CompatMemoryUtil.memPutFloat(i, x); CompatMemoryUtil.memPutFloat(i + 4, y); diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/screen_quad/BasicScreenQuadVertexSink.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/screen_quad/BasicScreenQuadVertexSink.java index 84bea99f8..e0d7836d2 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/screen_quad/BasicScreenQuadVertexSink.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/screen_quad/BasicScreenQuadVertexSink.java @@ -1,7 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad; -import com.gtnewhorizons.angelica.compat.toremove.DefaultVertexFormat; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import me.jellysquid.mods.sodium.client.model.vertex.VertexSink; import me.jellysquid.mods.sodium.client.util.math.Matrix4fExtended; import me.jellysquid.mods.sodium.client.util.math.MatrixUtil; diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/screen_quad/BasicScreenQuadVertexType.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/screen_quad/BasicScreenQuadVertexType.java index 1b2527ccc..769d4f52b 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/screen_quad/BasicScreenQuadVertexType.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/formats/screen_quad/BasicScreenQuadVertexType.java @@ -1,7 +1,7 @@ package me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad; import com.gtnewhorizons.angelica.compat.toremove.VertexConsumer; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad.writer.BasicScreenQuadVertexBufferWriterNio; import me.jellysquid.mods.sodium.client.model.vertex.formats.screen_quad.writer.BasicScreenQuadVertexBufferWriterUnsafe; diff --git a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/type/VanillaVertexType.java b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/type/VanillaVertexType.java index e6b510ceb..50aa85301 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/type/VanillaVertexType.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/model/vertex/type/VanillaVertexType.java @@ -1,6 +1,6 @@ package me.jellysquid.mods.sodium.client.model.vertex.type; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import me.jellysquid.mods.sodium.client.gl.attribute.BufferVertexFormat; import me.jellysquid.mods.sodium.client.model.vertex.VertexSink; diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/MultidrawChunkRenderBackend.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/MultidrawChunkRenderBackend.java index 0705b9695..98d800674 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/MultidrawChunkRenderBackend.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/backends/multidraw/MultidrawChunkRenderBackend.java @@ -3,6 +3,7 @@ package me.jellysquid.mods.sodium.client.render.chunk.backends.multidraw; import com.gtnewhorizons.angelica.config.AngelicaConfig; import it.unimi.dsi.fastutil.objects.ObjectArrayFIFOQueue; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import lombok.Setter; import me.jellysquid.mods.sodium.client.gl.arena.GlBufferArena; import me.jellysquid.mods.sodium.client.gl.arena.GlBufferSegment; import me.jellysquid.mods.sodium.client.gl.attribute.GlVertexAttribute; @@ -123,20 +124,20 @@ public class MultidrawChunkRenderBackend extends ChunkRenderShaderBackend region = this.pendingUploads.dequeue(); + final ChunkRegion region = this.pendingUploads.dequeue(); - GlBufferArena arena = region.getBufferArena(); - GlBuffer buffer = arena.getBuffer(); + final GlBufferArena arena = region.getBufferArena(); + final GlBuffer buffer = arena.getBuffer(); - ObjectArrayList> uploadQueue = region.getUploadQueue(); + final ObjectArrayList> uploadQueue = region.getUploadQueue(); arena.prepareBuffer(commandList, getUploadQueuePayloadSize(uploadQueue)); for (ChunkBuildResult result : uploadQueue) { - ChunkRenderContainer render = result.render; - ChunkRenderData data = result.data; + final ChunkRenderContainer render = result.render; + final ChunkRenderData data = result.data; for (BlockRenderPass pass : result.passesToUpload) { - MultidrawGraphicsState graphics = render.getGraphicsState(pass); + final MultidrawGraphicsState graphics = render.getGraphicsState(pass); // De-allocate the existing buffer arena for this render // This will allow it to be cheaply re-allocated just below @@ -144,16 +145,16 @@ public class MultidrawChunkRenderBackend extends ChunkRenderShaderBackend renders, ChunkCameraContext camera) { this.bufferManager.cleanup(); @@ -242,7 +241,7 @@ public class MultidrawChunkRenderBackend extends ChunkRenderShaderBackend region : this.pendingBatches) { - ChunkDrawCallBatcher batch = region.getDrawBatcher(); + final ChunkDrawCallBatcher batch = region.getDrawBatcher(); if (!batch.isEmpty()) { try (DrawCommandList drawCommandList = commandList.beginTessellating(region.getTessellation())) { @@ -262,11 +261,11 @@ public class MultidrawChunkRenderBackend extends ChunkRenderShaderBackend region : this.pendingBatches) { - float x = camera.getChunkModelOffset(region.getCenterBlockX(), camera.blockOriginX, camera.originX); - float y = camera.getChunkModelOffset(region.getCenterBlockY(), camera.blockOriginY, camera.originY); - float z = camera.getChunkModelOffset(region.getCenterBlockZ(), camera.blockOriginZ, camera.originZ); + final float x = camera.getChunkModelOffset(region.getCenterBlockX(), camera.blockOriginX, camera.originX); + final float y = camera.getChunkModelOffset(region.getCenterBlockY(), camera.blockOriginY, camera.originY); + final float z = camera.getChunkModelOffset(region.getCenterBlockZ(), camera.blockOriginZ, camera.originZ); region.camDistance = x * x + y * y + z * z; } @@ -274,7 +273,7 @@ public class MultidrawChunkRenderBackend extends ChunkRenderShaderBackend region : this.pendingBatches) { - ChunkDrawCallBatcher batcher = region.getDrawBatcher(); + final ChunkDrawCallBatcher batcher = region.getDrawBatcher(); batcher.end(); this.commandClientBufferBuilder.pushCommandBuffer(batcher); @@ -285,13 +284,13 @@ public class MultidrawChunkRenderBackend extends ChunkRenderShaderBackend> renders) { while (renders.hasNext()) { - ChunkBuildResult result = renders.next(); + final ChunkBuildResult result = renders.next(); if(result == null) { continue; } - ChunkRenderContainer render = result.render; + final ChunkRenderContainer render = result.render; ChunkRegion region = this.bufferManager.getRegion(render.getChunkX(), render.getChunkY(), render.getChunkZ()); @@ -304,7 +303,7 @@ public class MultidrawChunkRenderBackend extends ChunkRenderShaderBackend> uploadQueue = region.getUploadQueue(); + final ObjectArrayList> uploadQueue = region.getUploadQueue(); if (uploadQueue.isEmpty()) { this.pendingUploads.enqueue(region); @@ -321,18 +320,18 @@ public class MultidrawChunkRenderBackend extends ChunkRenderShaderBackend region = state.getRegion(); - ChunkDrawCallBatcher batch = region.getDrawBatcher(); + final ChunkRegion region = state.getRegion(); + final ChunkDrawCallBatcher batch = region.getDrawBatcher(); if (!batch.isBuilding()) { batch.begin(); @@ -440,7 +439,7 @@ public class MultidrawChunkRenderBackend extends ChunkRenderShaderBackend getDebugStrings() { - List list = new ArrayList<>(); + final List list = new ArrayList<>(); list.add(String.format("Active Buffers: %s", this.bufferManager.getAllocatedRegionCount())); list.add(String.format("Submission Mode: %s", this.commandBuffer != null ? EnumChatFormatting.AQUA + "Buffer" : EnumChatFormatting.LIGHT_PURPLE + "Client Memory")); diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/hfp/HFPModelVertexBufferWriterNio.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/hfp/HFPModelVertexBufferWriterNio.java index b06868e28..de9df0993 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/hfp/HFPModelVertexBufferWriterNio.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/hfp/HFPModelVertexBufferWriterNio.java @@ -27,9 +27,9 @@ public class HFPModelVertexBufferWriterNio extends VertexBufferWriterNio impleme } private void writeQuadInternal(short x, short y, short z, int color, short u, short v, int light) { - int i = this.writeOffset; + final int i = this.writeOffset; - ByteBuffer buffer = this.byteBuffer; + final ByteBuffer buffer = this.byteBuffer; buffer.putShort(i, x); buffer.putShort(i + 2, y); buffer.putShort(i + 4, z); diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/hfp/HFPModelVertexType.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/hfp/HFPModelVertexType.java index 5bb9db6ec..3437f85cc 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/hfp/HFPModelVertexType.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/format/hfp/HFPModelVertexType.java @@ -8,27 +8,20 @@ import me.jellysquid.mods.sodium.client.model.vertex.type.BlittableVertexType; import me.jellysquid.mods.sodium.client.model.vertex.type.ChunkVertexType; import me.jellysquid.mods.sodium.client.render.chunk.format.ChunkMeshAttribute; import me.jellysquid.mods.sodium.client.render.chunk.format.ModelVertexSink; -import net.coderbot.iris.sodium.vertex_format.IrisGlVertexAttributeFormat; /** * Uses half-precision floating point numbers to represent position coordinates and normalized unsigned shorts for * texture coordinates. All texel positions in the block diffuse texture atlas can be exactly mapped (including - * their centering offset), as the + * their centering offset). */ public class HFPModelVertexType implements ChunkVertexType { - // TODO Iris? - public static final int STRIDE = 44; // 20 + public static final int STRIDE = 20; public static final GlVertexFormat VERTEX_FORMAT = GlVertexFormat.builder(ChunkMeshAttribute.class, STRIDE) .addElement(ChunkMeshAttribute.POSITION, 0, GlVertexAttributeFormat.UNSIGNED_SHORT, 3, false) .addElement(ChunkMeshAttribute.COLOR, 8, GlVertexAttributeFormat.UNSIGNED_BYTE, 4, true) .addElement(ChunkMeshAttribute.TEXTURE, 12, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false) .addElement(ChunkMeshAttribute.LIGHT, 16, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, true) - .addElement(ChunkMeshAttribute.MID_TEX_COORD, 20, GlVertexAttributeFormat.FLOAT, 2, false) - .addElement(ChunkMeshAttribute.TANGENT, 28, IrisGlVertexAttributeFormat.BYTE, 4, true) - .addElement(ChunkMeshAttribute.NORMAL, 32, IrisGlVertexAttributeFormat.BYTE, 3, true) - .addElement(ChunkMeshAttribute.BLOCK_ID, 36, IrisGlVertexAttributeFormat.SHORT, 2, false) - .addElement(ChunkMeshAttribute.MID_BLOCK, 40, IrisGlVertexAttributeFormat.BYTE, 3, false) .build(); diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/tasks/ChunkRenderRebuildTask.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/tasks/ChunkRenderRebuildTask.java index 23a19dccf..ab4983585 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/tasks/ChunkRenderRebuildTask.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/tasks/ChunkRenderRebuildTask.java @@ -3,7 +3,6 @@ package me.jellysquid.mods.sodium.client.render.chunk.tasks; import com.gtnewhorizons.angelica.compat.mojang.BlockPos; import com.gtnewhorizons.angelica.compat.mojang.ChunkOcclusionDataBuilder; import com.gtnewhorizons.angelica.config.AngelicaConfig; -import com.gtnewhorizons.angelica.glsm.TessellatorManager; import com.gtnewhorizons.angelica.rendering.AngelicaBlockSafetyRegistry; import com.gtnewhorizons.angelica.rendering.AngelicaRenderQueue; import me.jellysquid.mods.sodium.client.SodiumClientMod; @@ -20,12 +19,10 @@ import me.jellysquid.mods.sodium.client.util.MathUtil; import me.jellysquid.mods.sodium.client.util.task.CancellationSource; import me.jellysquid.mods.sodium.client.world.WorldSlice; import me.jellysquid.mods.sodium.client.world.cloned.ChunkRenderContext; -import me.jellysquid.mods.sodium.common.config.SodiumConfig; 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.tileentity.TileEntityRendererDispatcher; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; @@ -88,16 +85,16 @@ public class ChunkRenderRebuildTask extends ChunkR } private boolean rendersOffThread(Block block) { - int type = block.getRenderType(); + final int type = block.getRenderType(); return type < 42 && type != 22 && AngelicaBlockSafetyRegistry.canBlockRenderOffThread(block); } @Override public ChunkBuildResult performBuild(ChunkRenderCacheLocal cache, ChunkBuildBuffers buffers, CancellationSource cancellationSource) { // COMPATIBLITY NOTE: Oculus relies on the LVT of this method being unchanged, at least in 16.5 - ChunkRenderData.Builder renderData = new ChunkRenderData.Builder(); - ChunkOcclusionDataBuilder occluder = new ChunkOcclusionDataBuilder(); - ChunkRenderBounds.Builder bounds = new ChunkRenderBounds.Builder(); + final ChunkRenderData.Builder renderData = new ChunkRenderData.Builder(); + final ChunkOcclusionDataBuilder occluder = new ChunkOcclusionDataBuilder(); + final ChunkRenderBounds.Builder bounds = new ChunkRenderBounds.Builder(); buffers.init(renderData); @@ -106,13 +103,12 @@ public class ChunkRenderRebuildTask extends ChunkR final WorldSlice slice = cache.getWorldSlice(); final RenderBlocks renderBlocks = new RenderBlocks(slice); - int baseX = this.render.getOriginX(); - int baseY = this.render.getOriginY(); - int baseZ = this.render.getOriginZ(); + final int baseX = this.render.getOriginX(); + final int baseY = this.render.getOriginY(); + final int baseZ = this.render.getOriginZ(); - BlockPos.Mutable pos = new BlockPos.Mutable(); - BlockPos renderOffset = this.offset; - final Tessellator tessellator = TessellatorManager.get(); + final BlockPos.Mutable pos = new BlockPos.Mutable(); + final BlockPos renderOffset = this.offset; boolean hasMainThreadBlocks = false; @@ -123,7 +119,7 @@ public class ChunkRenderRebuildTask extends ChunkR for (int relZ = 0; relZ < 16; relZ++) { for (int relX = 0; relX < 16; relX++) { - Block block = slice.getBlockRelative(relX + 16, relY + 16, relZ + 16); + final Block block = slice.getBlockRelative(relX + 16, relY + 16, relZ + 16); // If the block is vanilla air, assume it renders nothing. Don't use isAir because mods // can abuse it for all sorts of things @@ -131,7 +127,7 @@ public class ChunkRenderRebuildTask extends ChunkR continue; } - int meta = slice.getBlockMetadataRelative(relX + 16, relY + 16, relZ + 16); + final int meta = slice.getBlockMetadataRelative(relX + 16, relY + 16, relZ + 16); pos.set(baseX + relX, baseY + relY, baseZ + relZ); buffers.setRenderOffset(pos.x - renderOffset.getX(), pos.y - renderOffset.getY(), pos.z - renderOffset.getZ()); @@ -142,10 +138,10 @@ public class ChunkRenderRebuildTask extends ChunkR // Do regular block rendering for (BlockRenderPass pass : BlockRenderPass.VALUES) { if (block.canRenderInPass(pass.ordinal()) && (!AngelicaConfig.enableSodiumFluidRendering || !(block instanceof IFluidBlock))) { - long seed = MathUtil.hashPos(pos.x, pos.y, pos.z); + final long seed = MathUtil.hashPos(pos.x, pos.y, pos.z); if(AngelicaConfig.enableIris) buffers.iris$setMaterialId(block, ExtendedDataHelper.BLOCK_RENDER_TYPE); - if (cache.getBlockRenderer().renderModel(cache.getWorldSlice(), tessellator, renderBlocks, block, meta, pos, buffers.get(pass), true, seed)) { + if (cache.getBlockRenderer().renderModel(cache.getWorldSlice(), renderBlocks, block, meta, pos, buffers.get(pass), true, seed)) { bounds.addBlock(relX, relY, relZ); } } @@ -170,7 +166,7 @@ public class ChunkRenderRebuildTask extends ChunkR if(AngelicaConfig.enableIris) buffers.iris$resetBlockContext(); if (block.hasTileEntity(meta)) { - TileEntity entity = slice.getTileEntity(pos.x, pos.y, pos.z); + final TileEntity entity = slice.getTileEntity(pos.x, pos.y, pos.z); final TileEntitySpecialRenderer renderer = TileEntityRendererDispatcher.instance.getSpecialRenderer(entity); if (entity != null && renderer != null) { @@ -202,7 +198,7 @@ public class ChunkRenderRebuildTask extends ChunkR render.setRebuildForTranslucents(false); for (BlockRenderPass pass : BlockRenderPass.VALUES) { - ChunkMeshData mesh = buffers.createMesh(pass, (float)camera.x - offset.getX(), (float)camera.y - offset.getY(), (float)camera.z - offset.getZ(), this.translucencySorting); + final ChunkMeshData mesh = buffers.createMesh(pass, (float)camera.x - offset.getX(), (float)camera.y - offset.getY(), (float)camera.z - offset.getZ(), this.translucencySorting); if (mesh != null) { renderData.setMesh(pass, mesh); @@ -223,20 +219,20 @@ public class ChunkRenderRebuildTask extends ChunkR * TODO: Deduplicate this with the main method above. */ private void performMainBuild(ChunkRenderCacheLocal cache, ChunkBuildBuffers buffers, CancellationSource cancellationSource, ChunkRenderBounds.Builder bounds) { - WorldSlice slice = cache.getWorldSlice(); - BlockPos.Mutable pos = new BlockPos.Mutable(); - int baseX = this.render.getOriginX(); - int baseY = this.render.getOriginY(); - int baseZ = this.render.getOriginZ(); - BlockPos renderOffset = this.offset; - RenderBlocks rb = new RenderBlocks(slice.getWorld()); + final WorldSlice slice = cache.getWorldSlice(); + final BlockPos.Mutable pos = new BlockPos.Mutable(); + final int baseX = this.render.getOriginX(); + final int baseY = this.render.getOriginY(); + final int baseZ = this.render.getOriginZ(); + final BlockPos renderOffset = this.offset; + final RenderBlocks rb = new RenderBlocks(slice.getWorld()); for (int relY = 0; relY < 16; relY++) { if (cancellationSource.isCancelled()) { return; } for (int relZ = 0; relZ < 16; relZ++) { for (int relX = 0; relX < 16; relX++) { - Block block = slice.getBlockRelative(relX + 16, relY + 16, relZ + 16); + final Block block = slice.getBlockRelative(relX + 16, relY + 16, relZ + 16); // Only render blocks that need main thread assistance if (block.getMaterial() == Material.air || rendersOffThread(block)) { @@ -246,7 +242,7 @@ public class ChunkRenderRebuildTask extends ChunkR // TODO: Collect data on which render types are hitting this code path most often // so mods can be updated slowly - int meta = slice.getBlockMetadataRelative(relX + 16, relY + 16, relZ + 16); + final int meta = slice.getBlockMetadataRelative(relX + 16, relY + 16, relZ + 16); pos.set(baseX + relX, baseY + relY, baseZ + relZ); buffers.setRenderOffset(pos.x - renderOffset.getX(), pos.y - renderOffset.getY(), pos.z - renderOffset.getZ()); @@ -255,10 +251,10 @@ public class ChunkRenderRebuildTask extends ChunkR // Do regular block rendering for (BlockRenderPass pass : BlockRenderPass.VALUES) { if (block.canRenderInPass(pass.ordinal()) && (!AngelicaConfig.enableSodiumFluidRendering || !(block instanceof IFluidBlock))) { - long seed = MathUtil.hashPos(pos.x, pos.y, pos.z); + final long seed = MathUtil.hashPos(pos.x, pos.y, pos.z); if(AngelicaConfig.enableIris) buffers.iris$setMaterialId(block, ExtendedDataHelper.BLOCK_RENDER_TYPE); - if (cache.getBlockRenderer().renderModel(slice.getWorld(), Tessellator.instance, rb, block, meta, pos, buffers.get(pass), true, seed)) { + if (cache.getBlockRenderer().renderModel(slice.getWorld(), rb, block, meta, pos, buffers.get(pass), true, seed)) { bounds.addBlock(relX, relY, relZ); } } 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 39bb9e67d..f6987a11f 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 @@ -1,11 +1,11 @@ package me.jellysquid.mods.sodium.client.render.pipeline; +import com.gtnewhorizons.angelica.client.renderer.CapturingTessellator; import com.gtnewhorizons.angelica.compat.mojang.BlockPos; -import com.gtnewhorizons.angelica.compat.toremove.MatrixStack; import com.gtnewhorizons.angelica.compat.nd.Quad; import com.gtnewhorizons.angelica.compat.nd.RecyclingList; import com.gtnewhorizons.angelica.config.AngelicaConfig; -import com.gtnewhorizons.angelica.mixins.interfaces.ITessellatorInstance; +import com.gtnewhorizons.angelica.glsm.TessellatorManager; import me.jellysquid.mods.sodium.client.model.light.LightMode; import me.jellysquid.mods.sodium.client.model.light.LightPipeline; import me.jellysquid.mods.sodium.client.model.light.LightPipelineProvider; @@ -21,12 +21,9 @@ import net.coderbot.iris.block_rendering.BlockRenderingSettings; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.world.IBlockAccess; import net.minecraftforge.common.util.ForgeDirection; -import org.joml.Vector3d; -import org.lwjgl.opengl.GL11; import java.util.List; import java.util.Random; @@ -52,7 +49,7 @@ public class BlockRenderer { this.useAmbientOcclusion = Minecraft.getMinecraft().gameSettings.ambientOcclusion > 0; } - public boolean renderModel(IBlockAccess world, Tessellator tessellator, RenderBlocks renderBlocks, Block block, int meta, BlockPos pos, ChunkModelBuffers buffers, boolean cull, long seed) { + public boolean renderModel(IBlockAccess world, RenderBlocks renderBlocks, Block block, int meta, BlockPos pos, ChunkModelBuffers buffers, boolean cull, long seed) { final LightMode mode = this.getLightingMode(block); final LightPipeline lighter = this.lighters.getLighter(mode); @@ -61,85 +58,29 @@ public class BlockRenderer { boolean rendered = false; try { - tessellator.startDrawingQuads(); + TessellatorManager.startCapturing(); + final CapturingTessellator tess = (CapturingTessellator) TessellatorManager.get(); + tess.startDrawingQuads(); + // RenderBlocks adds the subchunk-relative coordinates as the offset, cancel it out here + tess.setOffset(pos); + renderBlocks.renderBlockByRenderType(block, pos.x, pos.y, pos.z); - - - final List all = tessellatorToQuadList(tessellator, pos); + final List quads = TessellatorManager.stopCapturing(); for (ModelQuadFacing facing : ModelQuadFacing.VALUES) { this.random.setSeed(seed); - this.renderQuadList(pos, lighter, buffers, all, facing); + this.renderQuadList(pos, lighter, buffers, quads, facing); } - if (!all.isEmpty()) rendered = true; + if (!quads.isEmpty()) rendered = true; } finally { - ((ITessellatorInstance) tessellator).discard(); + TessellatorManager.cleanup(); } return rendered; } - private int tesselatorDataCount; - private List tessellatorToQuadList(Tessellator t, BlockPos pos) { - // Adapted from Neodymium - tesselatorDataCount++; - -// List errors = new ArrayList<>(); -// List warnings = new ArrayList<>(); -// if(t.drawMode != GL11.GL_QUADS && t.drawMode != GL11.GL_TRIANGLES) { -// errors.add("Unsupported draw mode: " + t.drawMode); -// } -// if(!t.hasTexture) { -// errors.add("Texture data is missing."); -// } -// if(!t.hasBrightness) { -// warnings.add("Brightness data is missing"); -// } -// if(!t.hasColor) { -// warnings.add("Color data is missing"); -// } -// if(t.hasNormals && GL11.glIsEnabled(GL11.GL_LIGHTING)) { -// errors.add("Chunk uses GL lighting, this is not implemented."); -// } - FLAGS.hasBrightness = t.hasBrightness; - FLAGS.hasColor = t.hasColor; - - int verticesPerPrimitive = t.drawMode == GL11.GL_QUADS ? 4 : 3; - - for(int quadI = 0; quadI < t.vertexCount / verticesPerPrimitive; quadI++) { - final Quad quad = quadBuf.next(); - // RenderBlocks adds the subchunk-relative coordinates as the offset, cancel it out here - quad.setState(t.rawBuffer, quadI * (verticesPerPrimitive * 8), FLAGS, t.drawMode, -pos.x, -pos.y, -pos.z); - - if(quad.deleted) { - quadBuf.remove(); - } - } -// final boolean silenceErrors = false; -// -// if(!quadBuf.isEmpty() && (!errors.isEmpty() || !warnings.isEmpty()) && /*!Config.silenceErrors*/!silenceErrors) { -// for(String error : errors) { -// LOGGER.error("Error: " + error); -// } -// for(String warning : warnings) { -// LOGGER.error("Warning: " + warning); -// } -// LOGGER.error("(Tessellator pos: ({}, {}, {}), Tessellation count: {}", t.xOffset, t.yOffset, t.zOffset, tesselatorDataCount); -// LOGGER.error("Stack trace:"); -// try { -// // Generate a stack trace -// throw new IllegalArgumentException(); -// } catch(IllegalArgumentException e) { -// e.printStackTrace(); -// } -// } - final List quads = quadBuf.getAsList(); - quadBuf.reset(); - return quads; - } - private void renderQuadList(BlockPos pos, LightPipeline lighter, ChunkModelBuffers buffers, List quads, ModelQuadFacing facing) { final ModelVertexSink sink = buffers.getSink(facing); @@ -191,7 +132,7 @@ public class BlockRenderer { final float u = quad.getTexU(srcIndex); final float v = quad.getTexV(srcIndex); - int quadLight = quad.getLight(srcIndex); + final int quadLight = quad.getLight(srcIndex); final int lm = useSeparateAo ? ModelQuadUtil.mergeBakedLight(quadLight, light.lm[srcIndex]) : quadLight; sink.writeQuad(x, y, z, color, u, v, lm); @@ -214,7 +155,7 @@ public class BlockRenderer { boolean hasTexture; public boolean hasBrightness; public boolean hasColor; - boolean hasNormals; + public boolean hasNormals; public Flags(byte flags) { hasTexture = (flags & 1) != 0; diff --git a/src/main/java/net/coderbot/iris/pipeline/HorizonRenderer.java b/src/main/java/net/coderbot/iris/pipeline/HorizonRenderer.java index 5c98e7af8..6f8659638 100644 --- a/src/main/java/net/coderbot/iris/pipeline/HorizonRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/HorizonRenderer.java @@ -1,13 +1,11 @@ package net.coderbot.iris.pipeline; import com.gtnewhorizons.angelica.compat.mojang.VertexBuffer; -import com.gtnewhorizons.angelica.mixins.interfaces.ITessellatorInstance; +import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Tessellator; -import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; -import java.nio.ByteBuffer; import java.nio.FloatBuffer; /** @@ -59,33 +57,13 @@ public class HorizonRenderer { // Build the horizon quads into a buffer tessellator.startDrawingQuads(); //(GL11.GL_QUADS, DefaultVertexFormat.POSITION); buildHorizon(currentRenderDistance * 16, tessellator); - final ByteBuffer buf = tessellatorToBuffer(tessellator); - ((ITessellatorInstance) tessellator).discard(); this.vertexBuffer = new VertexBuffer(); this.vertexBuffer.bind(); - this.vertexBuffer.upload(buf, tessellator.vertexCount); + this.vertexBuffer.upload(tessellator, DefaultVertexFormat.POSITION); this.vertexBuffer.unbind(); } - /* Convert the tessellator's data into a buffer that can be uploaded to the GPU. */ - private ByteBuffer tessellatorToBuffer(Tessellator tessellator) { - final int[] rawBuffer = tessellator.rawBuffer; - final int byteSize = (tessellator.vertexCount * 3) << 2; - ByteBuffer byteBuffer = BufferUtils.createByteBuffer(byteSize); - - for(int quadI = 0 ; quadI < tessellator.vertexCount / 4 ; quadI++) { - for(int vertexI = 0 ; vertexI < 4 ; vertexI++) { - int i = (quadI * 4 * 8 ) + (vertexI * 8); - byteBuffer.putFloat(Float.intBitsToFloat(rawBuffer[i + 0])); - byteBuffer.putFloat(Float.intBitsToFloat(rawBuffer[i + 1])); - byteBuffer.putFloat(Float.intBitsToFloat(rawBuffer[i + 2])); - } - } - - return (ByteBuffer) byteBuffer.rewind(); - } - private void buildQuad(Tessellator consumer, double x1, double z1, double x2, double z2) { consumer.addVertex(x1, BOTTOM, z1); consumer.addVertex(x1, TOP, z1); diff --git a/src/main/java/net/coderbot/iris/postprocess/FullScreenQuadRenderer.java b/src/main/java/net/coderbot/iris/postprocess/FullScreenQuadRenderer.java index c79d797bc..d7dcb844a 100644 --- a/src/main/java/net/coderbot/iris/postprocess/FullScreenQuadRenderer.java +++ b/src/main/java/net/coderbot/iris/postprocess/FullScreenQuadRenderer.java @@ -2,7 +2,7 @@ package net.coderbot.iris.postprocess; import com.gtnewhorizons.angelica.glsm.GLStateManager; import net.coderbot.iris.gl.IrisRenderSystem; -import com.gtnewhorizons.angelica.compat.toremove.DefaultVertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL15; diff --git a/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java b/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java index 38c8d4303..2177ca3b3 100644 --- a/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java +++ b/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java @@ -10,16 +10,17 @@ import net.coderbot.iris.rendertarget.RenderTarget; import net.coderbot.iris.rendertarget.RenderTargets; import net.coderbot.iris.shaderpack.PackRenderTargetDirectives; import net.coderbot.iris.shadows.ShadowRenderTargets; +import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.texture.AbstractTexture; import java.util.function.IntSupplier; import java.util.function.Supplier; public class IrisSamplers { - public static final int ALBEDO_TEXTURE_UNIT = 0; + public static final int ALBEDO_TEXTURE_UNIT = OpenGlHelper.defaultTexUnit; // TODO: Find equivalent in 1.7.10 public static final int OVERLAY_TEXTURE_UNIT = 1; - public static final int LIGHTMAP_TEXTURE_UNIT = 1; + public static final int LIGHTMAP_TEXTURE_UNIT = OpenGlHelper.lightmapTexUnit; public static final ImmutableSet WORLD_RESERVED_TEXTURE_UNITS = ImmutableSet.of(0, 1, 2); diff --git a/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/ExtendedGlyphVertexType.java b/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/ExtendedGlyphVertexType.java index 2961eb041..8fc801a51 100644 --- a/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/ExtendedGlyphVertexType.java +++ b/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/ExtendedGlyphVertexType.java @@ -1,7 +1,7 @@ package net.coderbot.iris.sodium.vertex_format.entity_xhfp; import com.gtnewhorizons.angelica.compat.toremove.VertexConsumer; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.formats.glyph.GlyphVertexSink; import me.jellysquid.mods.sodium.client.model.vertex.formats.glyph.writer.GlyphVertexWriterFallback; diff --git a/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/ExtendedQuadVertexType.java b/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/ExtendedQuadVertexType.java index e2c128bd0..4d89a429f 100644 --- a/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/ExtendedQuadVertexType.java +++ b/src/main/java/net/coderbot/iris/sodium/vertex_format/entity_xhfp/ExtendedQuadVertexType.java @@ -1,7 +1,7 @@ package net.coderbot.iris.sodium.vertex_format.entity_xhfp; import com.gtnewhorizons.angelica.compat.toremove.VertexConsumer; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; import me.jellysquid.mods.sodium.client.model.vertex.formats.quad.QuadVertexSink; import me.jellysquid.mods.sodium.client.model.vertex.formats.quad.writer.QuadVertexWriterFallback; diff --git a/src/main/java/net/coderbot/iris/vertices/ExtendingBufferBuilder.java b/src/main/java/net/coderbot/iris/vertices/ExtendingBufferBuilder.java index 6814a49a0..15cab7a6a 100644 --- a/src/main/java/net/coderbot/iris/vertices/ExtendingBufferBuilder.java +++ b/src/main/java/net/coderbot/iris/vertices/ExtendingBufferBuilder.java @@ -1,6 +1,6 @@ package net.coderbot.iris.vertices; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; public interface ExtendingBufferBuilder { void iris$beginWithoutExtending(int drawMode, VertexFormat vertexFormat); diff --git a/src/main/java/net/coderbot/iris/vertices/IrisVertexFormats.java b/src/main/java/net/coderbot/iris/vertices/IrisVertexFormats.java index 4b7edf3f5..5b33847ee 100644 --- a/src/main/java/net/coderbot/iris/vertices/IrisVertexFormats.java +++ b/src/main/java/net/coderbot/iris/vertices/IrisVertexFormats.java @@ -1,8 +1,8 @@ package net.coderbot.iris.vertices; import com.google.common.collect.ImmutableList; -import com.gtnewhorizons.angelica.compat.toremove.DefaultVertexFormat; -import com.gtnewhorizons.angelica.compat.toremove.VertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; +import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; import com.gtnewhorizons.angelica.compat.mojang.VertexFormatElement; public class IrisVertexFormats { @@ -25,7 +25,7 @@ public class IrisVertexFormats { terrainElements.add(DefaultVertexFormat.POSITION_ELEMENT); // 12 terrainElements.add(DefaultVertexFormat.COLOR_ELEMENT); // 16 - terrainElements.add(DefaultVertexFormat.TEXTURE_0_ELEMENT); // 24 + terrainElements.add(DefaultVertexFormat.TEXTURE_ELEMENT); // 24 terrainElements.add(DefaultVertexFormat.LIGHT_ELEMENT); // 28 terrainElements.add(DefaultVertexFormat.NORMAL_ELEMENT); // 31 terrainElements.add(DefaultVertexFormat.PADDING_ELEMENT); // 32 @@ -37,7 +37,7 @@ public class IrisVertexFormats { entityElements.add(DefaultVertexFormat.POSITION_ELEMENT); // 12 entityElements.add(DefaultVertexFormat.COLOR_ELEMENT); // 16 - entityElements.add(DefaultVertexFormat.TEXTURE_0_ELEMENT); // 24 + entityElements.add(DefaultVertexFormat.TEXTURE_ELEMENT); // 24 entityElements.add(DefaultVertexFormat.OVERLAY_ELEMENT); // 28 entityElements.add(DefaultVertexFormat.LIGHT_ELEMENT); // 32 entityElements.add(DefaultVertexFormat.NORMAL_ELEMENT); // 35