-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...rc/main/java/org/vivecraft/mod_compat_vr/iris/mixin/coderbot/IrisCommonUniformsMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.vivecraft.mod_compat_vr.iris.mixin.coderbot; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import net.coderbot.iris.gl.uniform.UniformHolder; | ||
import net.coderbot.iris.gl.uniform.UniformUpdateFrequency; | ||
import org.apache.commons.lang3.tuple.Triple; | ||
import org.joml.Matrix4fc; | ||
import org.joml.Vector3f; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.vivecraft.mod_compat_vr.shaders.ShadersHelper; | ||
|
||
import java.util.function.Supplier; | ||
|
||
@Pseudo | ||
@Mixin(targets = "net.coderbot.iris.uniforms.CommonUniforms", remap = false) | ||
public class IrisCommonUniformsMixin { | ||
@Inject(method = "generalCommonUniforms", at = @At("TAIL")) | ||
private static void vivecraft$addVivecraftUniforms( | ||
CallbackInfo ci, @Local(argsOnly = true) UniformHolder uniforms) | ||
{ | ||
for (Triple<String, ShadersHelper.UniformType, Supplier<?>> uniform : ShadersHelper.getUniforms()) { | ||
switch (uniform.getMiddle()) { | ||
case MATRIX4F -> uniforms.uniformMatrix(UniformUpdateFrequency.PER_FRAME, uniform.getLeft(), | ||
() -> (Matrix4fc) uniform.getRight().get()); | ||
case VECTOR3F -> uniforms.uniform3f(UniformUpdateFrequency.PER_FRAME, uniform.getLeft(), | ||
() -> (Vector3f) uniform.getRight().get()); | ||
case INTEGER -> uniforms.uniform1i(UniformUpdateFrequency.PER_FRAME, uniform.getLeft(), | ||
() -> (int) uniform.getRight().get()); | ||
case BOOLEAN -> uniforms.uniform1b(UniformUpdateFrequency.PER_FRAME, uniform.getLeft(), | ||
() -> (boolean) uniform.getRight().get()); | ||
default -> throw new IllegalStateException("Unexpected uniform type: " + uniform.getMiddle()); | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...rc/main/java/org/vivecraft/mod_compat_vr/iris/mixin/coderbot/IrisStandardMacrosMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.vivecraft.mod_compat_vr.iris.mixin.coderbot; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import net.coderbot.iris.helpers.StringPair; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import org.vivecraft.mod_compat_vr.shaders.ShadersHelper; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Pseudo | ||
@Mixin(targets = "net.coderbot.iris.gl.shader.StandardMacros", remap = false) | ||
public class IrisStandardMacrosMixin { | ||
@Shadow | ||
private static void define(List<StringPair> defines, String key) {} | ||
|
||
@Shadow | ||
private static void define(List<StringPair> defines, String key, String value) {} | ||
|
||
@Inject(method = "createStandardEnvironmentDefines", at = @At(value = "INVOKE", target = "Lnet/coderbot/iris/gl/shader/StandardMacros;define(Ljava/util/List;Ljava/lang/String;Ljava/lang/String;)V", ordinal = 0)) | ||
private static void vivecraft$addVivecraftUniforms( | ||
CallbackInfoReturnable<ImmutableList<StringPair>> cir, @Local ArrayList<StringPair> standardDefines) | ||
{ | ||
ShadersHelper.addMacros( | ||
(string) -> define(standardDefines, string), | ||
(string, value) -> define(standardDefines, string, String.valueOf(value)) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
stubs/src/main/java/net/coderbot/iris/gl/uniform/UniformHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package net.coderbot.iris.gl.uniform; | ||
|
||
import org.joml.Matrix4fc; | ||
import org.joml.Vector3f; | ||
|
||
import java.util.function.BooleanSupplier; | ||
import java.util.function.IntSupplier; | ||
import java.util.function.Supplier; | ||
|
||
public interface UniformHolder { | ||
|
||
UniformHolder uniform1i(UniformUpdateFrequency updateFrequency, String name, IntSupplier value); | ||
|
||
UniformHolder uniform1b(UniformUpdateFrequency updateFrequency, String name, BooleanSupplier value); | ||
|
||
UniformHolder uniform3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector3f> value); | ||
|
||
UniformHolder uniformMatrix(UniformUpdateFrequency updateFrequency, String name, Supplier<Matrix4fc> value); | ||
} |
8 changes: 8 additions & 0 deletions
8
stubs/src/main/java/net/coderbot/iris/gl/uniform/UniformUpdateFrequency.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package net.coderbot.iris.gl.uniform; | ||
|
||
public enum UniformUpdateFrequency { | ||
ONCE, | ||
PER_TICK, | ||
PER_FRAME, | ||
CUSTOM | ||
} |
3 changes: 3 additions & 0 deletions
3
stubs/src/main/java/net/coderbot/iris/helpers/StringPair.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package net.coderbot.iris.helpers; | ||
|
||
public class StringPair {} |