Skip to content

Commit

Permalink
Potentially fix things
Browse files Browse the repository at this point in the history
  • Loading branch information
PepperCode1 committed Feb 9, 2024
1 parent a3f561b commit 4d7abdd
Show file tree
Hide file tree
Showing 9 changed files with 484 additions and 95 deletions.
6 changes: 3 additions & 3 deletions buildscript/src/main/java/Buildscript.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

public class Buildscript extends SimpleFabricProject {
static final boolean SODIUM = true;
static final boolean CUSTOM_SODIUM = true;
static final boolean CUSTOM_SODIUM = false;
static final String MC_VERSION = "1.20.4";
static final String customSodiumName = "sodium-fabric-mc1.20.3-0.5.6git.7a62284.jar";

Expand Down Expand Up @@ -114,10 +114,10 @@ public void getModDependencies(ModDependencyCollector d) {
if (CUSTOM_SODIUM) {
d.add(new JavaJarDependency(getProjectDir().resolve("custom_sodium").resolve(customSodiumName).toAbsolutePath(), null, new MavenId("me.jellysquid.mods", "sodium-fabric", customSodiumName.replace("sodium-fabric-", ""))), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME);
} else {
d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.5"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME);
d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.4-0.5.8"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME);
}
} else {
d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.3-0.5.5"), ModDependencyFlag.COMPILE);
d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "sodium", "mc1.20.4-0.5.8"), ModDependencyFlag.COMPILE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.VertexConsumer;
import me.jellysquid.mods.sodium.client.render.vertex.buffer.ExtendedBufferBuilder;
import me.jellysquid.mods.sodium.client.render.vertex.buffer.SodiumBufferBuilder;
import net.coderbot.batchedentityrendering.impl.ordering.GraphTranslucencyRenderOrderManager;
import net.coderbot.batchedentityrendering.impl.ordering.RenderOrderManager;
import net.coderbot.iris.fantastic.WrappingMultiBufferSource;
Expand Down Expand Up @@ -90,7 +92,16 @@ public VertexConsumer getBuffer(RenderType renderType) {
affinities.put(renderType, affinity);
}

return builders[affinity].getBuffer(renderType);
VertexConsumer buffer = builders[affinity].getBuffer(renderType);

if (buffer instanceof ExtendedBufferBuilder bufferBuilder) {
SodiumBufferBuilder replacement = bufferBuilder.sodium$getDelegate();
if (replacement != null) {
return replacement;
}
}

return buffer;
}

private void removeReady() {
Expand Down
198 changes: 110 additions & 88 deletions src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.VertexFormatElement;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import org.joml.Vector3f;
import net.coderbot.iris.vertices.NormI8;
import org.jetbrains.annotations.NotNull;
import net.coderbot.iris.uniforms.CapturedRenderingState;
import net.coderbot.iris.vertices.BlockSensitiveBufferBuilder;
import net.coderbot.iris.vertices.BufferBuilderPolygonView;
import net.coderbot.iris.vertices.ExtendedDataHelper;
import net.coderbot.iris.vertices.ExtendingBufferBuilder;
import net.coderbot.iris.vertices.IrisExtendedBufferBuilder;
import net.coderbot.iris.vertices.IrisVertexFormats;
import net.coderbot.iris.vertices.NormI8;
import net.coderbot.iris.vertices.NormalHelper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.nio.ByteBuffer;
Expand All @@ -33,33 +34,27 @@
* Dynamically and transparently extends the vanilla vertex formats with additional data
*/
@Mixin(BufferBuilder.class)
public abstract class MixinBufferBuilder extends DefaultedVertexConsumer implements BufferVertexConsumer, BlockSensitiveBufferBuilder, ExtendingBufferBuilder {
public abstract class MixinBufferBuilder extends DefaultedVertexConsumer implements BufferVertexConsumer, BlockSensitiveBufferBuilder, ExtendingBufferBuilder, IrisExtendedBufferBuilder {
@Unique
private boolean extending;

@Unique
private boolean iris$shouldNotExtend = false;
private boolean iris$shouldNotExtend;

@Unique
private boolean iris$isTerrain = false;

@Unique
private int vertexCount;
private boolean extending;

@Unique
private final BufferBuilderPolygonView polygon = new BufferBuilderPolygonView();
private boolean iris$isTerrain;

@Unique
private final Vector3f normal = new Vector3f();
private boolean injectNormalAndUV1;

@Unique
private boolean injectNormalAndUV1;
private int vertexCount;

@Unique
private short currentBlock;
private short currentBlock = -1;

@Unique
private short currentRenderType;
private short currentRenderType = -1;

@Unique
private int currentLocalPosX;
Expand All @@ -70,11 +65,11 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme
@Unique
private int currentLocalPosZ;

@Shadow
private boolean fastFormat;
@Unique
private final BufferBuilderPolygonView polygon = new BufferBuilderPolygonView();

@Shadow
private boolean fullFormat;
@Unique
private final Vector3f normal = new Vector3f();

@Shadow
private ByteBuffer buffer;
Expand All @@ -97,9 +92,6 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme
@Shadow
public abstract void putShort(int i, short s);

@Shadow
protected abstract void switchFormat(VertexFormat arg);

@Shadow
public abstract void nextElement();

Expand All @@ -110,75 +102,40 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme
iris$shouldNotExtend = false;
}

@Inject(method = "begin", at = @At("HEAD"))
private void iris$onBegin(VertexFormat.Mode drawMode, VertexFormat format, CallbackInfo ci) {
boolean shouldExtend = (!iris$shouldNotExtend) && BlockRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat();
extending = shouldExtend && (format == DefaultVertexFormat.BLOCK || format == DefaultVertexFormat.NEW_ENTITY
|| format == DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP);
vertexCount = 0;

if (extending) {
injectNormalAndUV1 = format == DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP;
}
}

@Inject(method = "begin", at = @At("RETURN"))
private void iris$afterBegin(VertexFormat.Mode drawMode, VertexFormat format, CallbackInfo ci) {
if (extending) {
if (format == DefaultVertexFormat.BLOCK) {
this.switchFormat(IrisVertexFormats.TERRAIN);
this.iris$isTerrain = true;
} else if (format == DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP) {
this.switchFormat(IrisVertexFormats.GLYPH);
this.iris$isTerrain = false;
} else {
this.switchFormat(IrisVertexFormats.ENTITY);
this.iris$isTerrain = false;
}
this.currentElement = this.format.getElements().get(0);
}
}

@Override
public @NotNull VertexConsumer uv2(int pBufferVertexConsumer0, int pInt1) {

return BufferVertexConsumer.super.uv2(pBufferVertexConsumer0, pInt1);
}

@ModifyArg(method = "begin", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/BufferBuilder;switchFormat(Lcom/mojang/blaze3d/vertex/VertexFormat;)V"))
private VertexFormat iris$afterBeginSwitchFormat(VertexFormat arg) {
if (extending) {
if (format == DefaultVertexFormat.BLOCK) {
this.switchFormat(IrisVertexFormats.TERRAIN);
this.iris$isTerrain = true;
} else if (format == DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP) {
this.switchFormat(IrisVertexFormats.GLYPH);
this.iris$isTerrain = false;
} else {
this.switchFormat(IrisVertexFormats.ENTITY);
this.iris$isTerrain = false;
}
@ModifyVariable(method = "begin", at = @At("HEAD"), argsOnly = true)
private VertexFormat iris$extendFormat(VertexFormat format) {
if (iris$shouldNotExtend || !BlockRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat()) {
return format;
}
return arg;
}


if (format == DefaultVertexFormat.BLOCK) {
extending = true;
iris$isTerrain = true;
injectNormalAndUV1 = false;
return IrisVertexFormats.TERRAIN;
} else if (format == DefaultVertexFormat.NEW_ENTITY) {
extending = true;
iris$isTerrain = false;
injectNormalAndUV1 = false;
return IrisVertexFormats.ENTITY;
} else if (format == DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP) {
extending = true;
iris$isTerrain = false;
injectNormalAndUV1 = true;
return IrisVertexFormats.GLYPH;
}

@Inject(method = "discard()V", at = @At("HEAD"))
private void iris$onDiscard(CallbackInfo ci) {
extending = false;
injectNormalAndUV1 = false;
vertexCount = 0;
return format;
}

@Inject(method = "switchFormat", at = @At("RETURN"))
private void iris$preventHardcodedVertexWriting(VertexFormat format, CallbackInfo ci) {
if (!extending) {
return;
}

fastFormat = false;
fullFormat = false;
@Inject(method = "reset()V", at = @At("HEAD"))
private void iris$onReset(CallbackInfo ci) {
vertexCount = 0;
}

@Inject(method = "endVertex", at = @At("HEAD"))
Expand All @@ -197,7 +154,7 @@ public abstract class MixinBufferBuilder extends DefaultedVertexConsumer impleme
this.putShort(0, currentBlock);
this.putShort(2, currentRenderType);
} else {
// ENTITY_ELEMENT
// ENTITY_ID_ELEMENT
this.putShort(0, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedEntity());
this.putShort(2, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedBlockEntity());
this.putShort(4, (short) CapturedRenderingState.INSTANCE.getCurrentRenderedItem());
Expand Down Expand Up @@ -290,6 +247,11 @@ private void fillExtendedData(int vertexAmount) {
}
}

@Unique
private void putInt(int i, int value) {
this.buffer.putInt(this.nextElementByte + i, value);
}

@Override
public void beginBlock(short block, short renderType, int localPosX, int localPosY, int localPosZ) {
this.currentBlock = block;
Expand All @@ -308,8 +270,68 @@ public void endBlock() {
this.currentLocalPosZ = 0;
}

@Unique
private void putInt(int i, int value) {
this.buffer.putInt(this.nextElementByte + i, value);
@Override
public VertexFormat iris$format() {
return format;
}

@Override
public VertexFormat.Mode iris$mode() {
return mode;
}

@Override
public boolean iris$extending() {
return extending;
}

@Override
public boolean iris$isTerrain() {
return iris$isTerrain;
}

@Override
public boolean iris$injectNormalAndUV1() {
return injectNormalAndUV1;
}

@Override
public int iris$vertexCount() {
return vertexCount;
}

@Override
public void iris$incrementVertexCount() {
vertexCount++;
}

@Override
public void iris$resetVertexCount() {
vertexCount = 0;
}

@Override
public short iris$currentBlock() {
return currentBlock;
}

@Override
public short iris$currentRenderType() {
return currentRenderType;
}

@Override
public int iris$currentLocalPosX() {
return currentLocalPosX;
}

@Override
public int iris$currentLocalPosY() {
return currentLocalPosY;
}

@Override
public int iris$currentLocalPosZ() {
return currentLocalPosZ;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.coderbot.iris.vertices;

import com.mojang.blaze3d.vertex.VertexFormat;

public interface IrisExtendedBufferBuilder {
VertexFormat iris$format();

VertexFormat.Mode iris$mode();

boolean iris$extending();

boolean iris$isTerrain();

boolean iris$injectNormalAndUV1();

int iris$vertexCount();

void iris$incrementVertexCount();

void iris$resetVertexCount();

short iris$currentBlock();

short iris$currentRenderType();

int iris$currentLocalPosX();

int iris$currentLocalPosY();

int iris$currentLocalPosZ();
}
6 changes: 3 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "iris",
"version": "1.6.14-development-environment",
"version": "1.6.15-development-environment",

"name": "Iris",
"description": "A modern shaders mod for Minecraft intended to be compatible with existing OptiFine shader packs",
Expand Down Expand Up @@ -45,8 +45,8 @@

"depends": {
"fabricloader": ">=0.12.3",
"minecraft": ["1.20.3", "1.20.4"],
"sodium": "0.5.6"
"minecraft": ["1.20.4"],
"sodium": "0.5.8"
},

"breaks": {
Expand Down
Loading

0 comments on commit 4d7abdd

Please sign in to comment.