diff --git a/build.gradle b/build.gradle index 8127d9874a..ca582e1ba7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,37 +1,39 @@ plugins { - id 'dev.architectury.loom' version '0.10.0-SNAPSHOT' + id "java-library" + id "com.gtnewhorizons.retrofuturagradle" version "1.3.26" id 'com.github.johnrengelman.shadow' version '7.1.2' - id 'maven-publish' } -loom { - silentMojangMappingsLicense() - - forge { - mixinConfigs = [ - "mixins.oculus.json", - "mixins.oculus.fantastic.json", - "mixins.oculus.vertexformat.json", - "mixins.oculus.bettermipmaps.json", - "mixins.oculus.fixes.maxfpscrash.json", - "mixins.oculus.optimized-stitching.json", - "oculus-batched-entity-rendering.mixins.json", - "mixins.oculus.compat.sodium.json", - "mixins.oculus.compat.json" - ] - } - mixin.defaultRefmapName = "oculus-mixins-refmap.json" +archivesBaseName = "${project.mod_id}-mc${project.minecraft_version}-${project.mod_version}" + +// Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(8)) + // Azul covers the most platforms for Java 8 toolchains, crucially including MacOS arm64 + vendor.set(org.gradle.jvm.toolchain.JvmVendorSpec.AZUL) + } } -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 +minecraft { + mcVersion.set(minecraft_version) + username.set("Developer") -archivesBaseName = "${project.archives_base_name}-mc${project.minecraft_version}" -version = project.mod_version -group = project.maven_group + injectedTags.put("MOD_VERSION", mod_version) + injectedTags.put("MOD_NAME", "Vintagium") +} + +tasks.injectTags.outputClassName.set("${mod_base_package}.Tags") + +tasks.deobfuscateMergedJarToSrg.configure {accessTransformerFiles.from("src/main/resources/META-INF/oculus_at.cfg")} repositories { mavenLocal() + maven { url "https://maven.cleanroommc.com" } + maven { + name 'SpongePowered Maven' + url 'https://repo.spongepowered.org/maven' + } maven { name = "CurseForge" url = "https://cursemaven.com" @@ -49,15 +51,18 @@ repositories { } dependencies { - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings loom.officialMojangMappings() - forge "net.minecraftforge:forge:${minecraft_version}-${forge_version}" - - modCompileOnly "maven.modrinth:rubidium:0.2.13" - //modCompileOnly "me.jellysquid.mods:Rubidium:0.2.13" - modCompileOnly "curse.maven:epic-fight-mod-405076:4029362" - - modRuntimeOnly "curse.maven:lazydfu-460819:3249059" + def mixinBooter = modUtils.enableMixins("zone.rong:mixinbooter:8.9", "oculus-mixins-refmap.json") + api (mixinBooter) { + transitive = false + } + annotationProcessor "org.ow2.asm:asm-debug-all:5.2" + annotationProcessor "com.google.guava:guava:32.1.2-jre" + annotationProcessor "com.google.code.gson:gson:2.8.9" + annotationProcessor (mixinBooter) { + transitive = false + } + + //modCompileOnly "maven.modrinth:rubidium:0.2.13" implementation(shadow(project(path: ":glsl-relocated", configuration: "bundledJar"))) { transitive = false @@ -66,27 +71,20 @@ dependencies { transitive = false } shadow("org.slf4j:slf4j-api:1.7.12") // for jcpp -} - -processResources { - inputs.property "version", project.version - - filesMatching("META-INF/mods.toml") { - expand "version": project.version - } -} - -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" - def targetVersion = 8 - if (JavaVersion.current().isJava9Compatible()) { - it.options.release = targetVersion - } + implementation fileTree(dir: 'libs', include: ['*.jar']) } -java { - withSourcesJar() +processResources { + filesMatching("mcmod.info") { fcd -> + fcd.expand( + 'mod_id': project.mod_id, + 'mod_name': project.mod_name, + 'mod_version': project.mod_version, + 'mod_description': project.mod_description, + 'minecraft_version': project.minecraft_version + ) + } } shadowJar { @@ -105,25 +103,4 @@ shadowJar { 'Main-Class': 'net.coderbot.iris.LaunchWarn' ) } -} - -remapJar { - input.set shadowJar.archiveFile - dependsOn shadowJar -} - -publishing { - publications { - mavenJava(MavenPublication) { - artifact(remapJar) { - builtBy remapJar - } - artifact(sourcesJar) { - builtBy remapSourcesJar - } - } - } - - repositories { - } -} +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 9575a4edb4..3c2fedb02b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,17 @@ # Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx6G +org.gradle.jvmargs=-Xmx3G -# Fabric Properties - minecraft_version=1.16.5 - yarn_mappings=1.16.5+build.10 - loader_version=0.13.2 +minecraft_version=1.12.2 +minecraft_version_range=[1.12,1.13) +forge_version=14.23.5.2860 +forge_version_range=[23,) +loader_version_range=[23,) +mappings_channel=stable +mappings_version=39-1.12 # Mod Properties - mod_version = 1.4.8 - maven_group = net.coderbot - archives_base_name = oculus - - forge_version=36.2.29 - - loom.platform=forge - -# Dependencies - fabric_version=0.42.0+1.16 +mod_id=oculus +mod_name=Oculus +mod_main_class=Iris +mod_version = 1.4.7 +mod_base_package = net.coderbot.iris \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b5..a595206642 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/libs/vintagium-mc1.12.2-0.1-dev.jar b/libs/vintagium-mc1.12.2-0.1-dev.jar new file mode 100644 index 0000000000..2b92427a9c Binary files /dev/null and b/libs/vintagium-mc1.12.2-0.1-dev.jar differ diff --git a/settings.gradle b/settings.gradle index 791921254c..568a68ea6c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,13 +1,25 @@ pluginManagement { repositories { + gradlePluginPortal() + maven { url = 'https://gitlab.com/api/v4/projects/26758973/packages/maven' } maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' + // RetroFuturaGradle + name = "GTNH Maven" + url = uri("http://jenkins.usrv.eu:8081/nexus/content/groups/public/") + allowInsecureProtocol = true + mavenContent { + includeGroup("com.gtnewhorizons") + includeGroup("com.gtnewhorizons.retrofuturagradle") + } } - maven { url "https://maven.architectury.dev/" } - maven { url "https://files.minecraftforge.net/maven/" } - gradlePluginPortal() } } -include("glsl-relocated") \ No newline at end of file +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0' // Provides java toolchains +} + + +rootProject.name = "${mod_name}" + +include("glsl-relocated") diff --git a/src/main/java/it/unimi/dsi/fastutil/SafeMath.java b/src/main/java/it/unimi/dsi/fastutil/SafeMath.java new file mode 100644 index 0000000000..ec1e9ba8b9 --- /dev/null +++ b/src/main/java/it/unimi/dsi/fastutil/SafeMath.java @@ -0,0 +1,79 @@ +package it.unimi.dsi.fastutil; + +public final class SafeMath { + private SafeMath() { + } + + public static char safeIntToChar(int value) { + if (value >= 0 && 65535 >= value) { + return (char)value; + } else { + throw new IllegalArgumentException(value + " can't be represented as char"); + } + } + + public static byte safeIntToByte(int value) { + if (value >= -128 && 127 >= value) { + return (byte)value; + } else { + throw new IllegalArgumentException(value + " can't be represented as byte (out of range)"); + } + } + + public static short safeIntToShort(int value) { + if (value >= -32768 && 32767 >= value) { + return (short)value; + } else { + throw new IllegalArgumentException(value + " can't be represented as short (out of range)"); + } + } + + public static char safeLongToChar(long value) { + if (value >= 0L && 65535L >= value) { + return (char)((int)value); + } else { + throw new IllegalArgumentException(value + " can't be represented as int (out of range)"); + } + } + + public static byte safeLongToByte(long value) { + if (value >= -128L && 127L >= value) { + return (byte)((int)value); + } else { + throw new IllegalArgumentException(value + " can't be represented as int (out of range)"); + } + } + + public static short safeLongToShort(long value) { + if (value >= -32768L && 32767L >= value) { + return (short)((int)value); + } else { + throw new IllegalArgumentException(value + " can't be represented as int (out of range)"); + } + } + + public static int safeLongToInt(long value) { + if (value >= -2147483648L && 2147483647L >= value) { + return (int)value; + } else { + throw new IllegalArgumentException(value + " can't be represented as int (out of range)"); + } + } + + public static float safeDoubleToFloat(double value) { + if (Double.isNaN(value)) { + return Float.NaN; + } else if (Double.isInfinite(value)) { + return value < 0.0 ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY; + } else if (!(value < -Float.MAX_VALUE) && !(Float.MAX_VALUE < value)) { + float floatValue = (float)value; + if ((double)floatValue != value) { + throw new IllegalArgumentException(value + " can't be represented as float (imprecise)"); + } else { + return floatValue; + } + } else { + throw new IllegalArgumentException(value + " can't be represented as float (out of range)"); + } + } +} diff --git a/src/main/java/it/unimi/dsi/fastutil/booleans/BooleanConsumer.java b/src/main/java/it/unimi/dsi/fastutil/booleans/BooleanConsumer.java new file mode 100644 index 0000000000..fb7682f4fd --- /dev/null +++ b/src/main/java/it/unimi/dsi/fastutil/booleans/BooleanConsumer.java @@ -0,0 +1,22 @@ +package it.unimi.dsi.fastutil.booleans; + +import java.util.Objects; +import java.util.function.Consumer; + +@FunctionalInterface +public interface BooleanConsumer extends Consumer { + void accept(boolean var1); + + @Deprecated + default void accept(Boolean t) { + this.accept(t.booleanValue()); + } + + default BooleanConsumer andThen(BooleanConsumer after) { + Objects.requireNonNull(after); + return t -> { + this.accept(t); + after.accept(t); + }; + } +} diff --git a/src/main/java/it/unimi/dsi/fastutil/floats/FloatConsumer.java b/src/main/java/it/unimi/dsi/fastutil/floats/FloatConsumer.java new file mode 100644 index 0000000000..1893e02653 --- /dev/null +++ b/src/main/java/it/unimi/dsi/fastutil/floats/FloatConsumer.java @@ -0,0 +1,33 @@ +package it.unimi.dsi.fastutil.floats; + +import it.unimi.dsi.fastutil.SafeMath; +import java.util.Objects; +import java.util.function.Consumer; +import java.util.function.DoubleConsumer; + +@FunctionalInterface +public interface FloatConsumer extends Consumer, DoubleConsumer { + void accept(float var1); + + @Deprecated + default void accept(double t) { + this.accept(SafeMath.safeDoubleToFloat(t)); + } + + @Deprecated + default void accept(Float t) { + this.accept(t.floatValue()); + } + + default FloatConsumer andThen(FloatConsumer after) { + Objects.requireNonNull(after); + return t -> { + this.accept(t); + after.accept(t); + }; + } + + default FloatConsumer andThen(DoubleConsumer after) { + return this.andThen(after instanceof FloatConsumer ? (FloatConsumer)after : after::accept); + } +} diff --git a/src/main/java/nanolive/compat/CompatMemoryUtil.java b/src/main/java/nanolive/compat/CompatMemoryUtil.java new file mode 100644 index 0000000000..0abc4586d1 --- /dev/null +++ b/src/main/java/nanolive/compat/CompatMemoryUtil.java @@ -0,0 +1,103 @@ +// From Angelica under LGPL-3.0 +package nanolive.compat; + +import org.lwjgl.BufferUtils; + +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; + +public class CompatMemoryUtil { + public static ByteBuffer memReallocDirect(ByteBuffer old, int capacity) { + ByteBuffer newBuf = BufferUtils.createByteBuffer(capacity); + int oldPos = old.position(); + old.rewind(); + newBuf.put(old); + newBuf.position(Math.min(capacity, oldPos)); + return newBuf; + } + + public static IntBuffer memReallocDirect(IntBuffer old, int capacity) { + IntBuffer newBuf = BufferUtils.createIntBuffer(capacity); + int oldPos = old.position(); + old.rewind(); + newBuf.put(old); + newBuf.position(Math.min(capacity, oldPos)); + return newBuf; + } + + public static FloatBuffer memReallocDirect(FloatBuffer old, int capacity) { + FloatBuffer newBuf = BufferUtils.createFloatBuffer(capacity); + int oldPos = old.position(); + old.rewind(); + newBuf.put(old); + newBuf.position(Math.min(capacity, oldPos)); + return newBuf; + } + + /** + * Backported from LWJGL3 under the BSD 3-Clause "New" or "Revised" License license + * + *

This class provides functionality for managing native memory. + * + *

All methods in this class will make use of {@link sun.misc.Unsafe} if it's available, for performance. If Unsafe is not available, the fallback + * implementations make use of reflection and, in the worst-case, JNI.

+ * + *

Method names in this class are prefixed with {@code mem} to avoid ambiguities when used with static imports.

+ */ + + static final sun.misc.Unsafe UNSAFE; + + static { + UNSAFE = getUnsafeInstance(); + } + + private static sun.misc.Unsafe getUnsafeInstance() { + java.lang.reflect.Field[] fields = sun.misc.Unsafe.class.getDeclaredFields(); + + /* + Different runtimes use different names for the Unsafe singleton, + so we cannot use .getDeclaredField and we scan instead. For example: + + Oracle: theUnsafe + PERC : m_unsafe_instance + Android: THE_ONE + */ + for (java.lang.reflect.Field field : fields) { + if (!field.getType().equals(sun.misc.Unsafe.class)) { + continue; + } + + int modifiers = field.getModifiers(); + if (!(java.lang.reflect.Modifier.isStatic(modifiers) && java.lang.reflect.Modifier.isFinal(modifiers))) { + continue; + } + + try { + field.setAccessible(true); + return (sun.misc.Unsafe)field.get(null); + } catch (Exception ignored) { + } + break; + } + + throw new UnsupportedOperationException("LWJGL requires sun.misc.Unsafe to be available."); + } + + + public static void memPutByte(long ptr, byte value) { UNSAFE.putByte(null, ptr, value); } + public static void memPutShort(long ptr, short value) { UNSAFE.putShort(null, ptr, value); } + public static void memPutInt(long ptr, int value) { UNSAFE.putInt(null, ptr, value); } + public static void memPutLong(long ptr, long value) { UNSAFE.putLong(null, ptr, value); } + public static void memPutFloat(long ptr, float value) { UNSAFE.putFloat(null, ptr, value); } + public static void memPutDouble(long ptr, double value) { UNSAFE.putDouble(null, ptr, value); } + + public static boolean memGetBoolean(long ptr) { return UNSAFE.getByte(null, ptr) != 0; } + public static byte memGetByte(long ptr) { return UNSAFE.getByte(null, ptr); } + public static short memGetShort(long ptr) { return UNSAFE.getShort(null, ptr); } + public static int memGetInt(long ptr) { return UNSAFE.getInt(null, ptr); } + public static long memGetLong(long ptr) { return UNSAFE.getLong(null, ptr); } + public static float memGetFloat(long ptr) { return UNSAFE.getFloat(null, ptr); } + public static double memGetDouble(long ptr) { return UNSAFE.getDouble(null, ptr); } + +} \ No newline at end of file diff --git a/src/main/java/nanolive/compat/NativeImage.java b/src/main/java/nanolive/compat/NativeImage.java new file mode 100644 index 0000000000..e014049a97 --- /dev/null +++ b/src/main/java/nanolive/compat/NativeImage.java @@ -0,0 +1,431 @@ +package nanolive.compat; + +import com.google.common.base.Charsets; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.channels.Channels; +import java.nio.channels.WritableByteChannel; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.util.Base64; +import java.util.EnumSet; +import java.util.Set; +import javax.annotation.Nullable; + +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.TextureUtil; +import org.apache.commons.io.IOUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public final class NativeImage implements AutoCloseable { + private static final Logger LOGGER = LogManager.getLogger(); + private static final Set OPEN_OPTIONS; + private final Format format; + private final int width; + private final int height; + private final boolean useStbFree; + public long pixels; + private final long size; + + public NativeImage(int i, int j, boolean bl) { + this(NativeImage.Format.RGBA, i, j, bl); + } + + public NativeImage(Format arg, int i, int j, boolean bl) { + this.format = arg; + this.width = i; + this.height = j; + this.size = (long)i * (long)j * (long)arg.components(); + this.useStbFree = false; + if (bl) { + this.pixels = MemoryUtil.nmemCalloc(1L, this.size); + } else { + this.pixels = MemoryUtil.nmemAlloc(this.size); + } + + } + + private NativeImage(Format arg, int i, int j, boolean bl, long l) { + this.format = arg; + this.width = i; + this.height = j; + this.useStbFree = bl; + this.pixels = l; + this.size = (long) i * j * arg.components(); + } + + @Override + public String toString() { + return "NativeImage[" + this.format + " " + this.width + "x" + this.height + "@" + this.pixels + (this.useStbFree ? "S" : "N") + "]"; + } + + public static NativeImage read(InputStream inputStream) throws IOException { + return read(NativeImage.Format.RGBA, inputStream); + } + + public static NativeImage read(@Nullable Format arg, InputStream inputStream) throws IOException { + ByteBuffer bytebuffer = null; + + NativeImage nativeimage; + try { + bytebuffer = TextureUtil.readResource(inputStream); + bytebuffer.rewind(); + nativeimage = read(arg, bytebuffer); + } finally { + MemoryUtil.memFree(bytebuffer); + IOUtils.closeQuietly(inputStream); + } + + return nativeimage; + } + + public static NativeImage read(ByteBuffer byteBuffer) throws IOException { + return read(NativeImage.Format.RGBA, byteBuffer); + } + + public static NativeImage read(@Nullable Format arg, ByteBuffer byteBuffer) throws IOException { + if (arg != null && !arg.supportedByStb()) { + throw new UnsupportedOperationException("Don't know how to read format " + arg); + } else if (MemoryUtil.memAddress(byteBuffer) == 0L) { + throw new IllegalArgumentException("Invalid buffer"); + } else { + MemoryStack memorystack = MemoryStack.stackPush(); + Throwable var4 = null; + + NativeImage nativeimage; + try { + IntBuffer intbuffer = memorystack.mallocInt(1); + IntBuffer intbuffer1 = memorystack.mallocInt(1); + IntBuffer intbuffer2 = memorystack.mallocInt(1); + ByteBuffer bytebuffer = STBImage.stbi_load_from_memory(byteBuffer, intbuffer, intbuffer1, intbuffer2, arg == null ? 0 : arg.components); + if (bytebuffer == null) { + throw new IOException("Could not load image: " + STBImage.stbi_failure_reason()); + } + + nativeimage = new NativeImage(arg == null ? NativeImage.Format.getStbFormat(intbuffer2.get(0)) : arg, intbuffer.get(0), intbuffer1.get(0), true, MemoryUtil.memAddress(bytebuffer)); + } catch (Throwable var16) { + var4 = var16; + throw var16; + } finally { + if (memorystack != null) { + if (var4 != null) { + try { + memorystack.close(); + } catch (Throwable var15) { + var4.addSuppressed(var15); + } + } else { + memorystack.close(); + } + } + + } + + return nativeimage; + } + } + + private static void setClamp(boolean bl) { + if (bl) { + GlStateManager.glTexParameteri(3553, 10242, 10496); + GlStateManager.glTexParameteri(3553, 10243, 10496); + } else { + GlStateManager.glTexParameteri(3553, 10242, 10497); + GlStateManager.glTexParameteri(3553, 10243, 10497); + } + + } + + private static void setFilter(boolean bl, boolean bl2) { + if (bl) { + GlStateManager.glTexParameteri(3553, 10241, bl2 ? 9987 : 9729); + GlStateManager.glTexParameteri(3553, 10240, 9729); + } else { + GlStateManager.glTexParameteri(3553, 10241, bl2 ? 9986 : 9728); + GlStateManager.glTexParameteri(3553, 10240, 9728); + } + + } + + private void checkAllocated() { + if (this.pixels == 0L) { + throw new IllegalStateException("Image is not allocated."); + } + } + + public void close() { + if (this.pixels != 0L) { + if (this.useStbFree) { + STBImage.nstbi_image_free(this.pixels); + } else { + MemoryUtil.nmemFree(this.pixels); + } + } + + this.pixels = 0L; + } + + public int getWidth() { + return this.width; + } + + public int getHeight() { + return this.height; + } + + public Format format() { + return this.format; + } + + public int getPixelRGBA(int j, int k) { + if (this.format != NativeImage.Format.RGBA) { + throw new IllegalArgumentException(String.format("getPixelRGBA only works on RGBA images; have %s", this.format)); + } else if (j >= 0 && k >= 0 && j < this.width && k < this.height) { + this.checkAllocated(); + long i = (j + (long) k * this.width) * 4; + return CompatMemoryUtil.memGetInt(this.pixels + i); + } else { + throw new IllegalArgumentException(String.format("(%s, %s) outside of image bounds (%s, %s)", j, k, this.width, this.height)); + } + } + + public void setPixelRGBA(int j, int k, int l) { + if (this.format != NativeImage.Format.RGBA) { + throw new IllegalArgumentException(String.format("getPixelRGBA only works on RGBA images; have %s", this.format)); + } else if (j >= 0 && k >= 0 && j < this.width && k < this.height) { + this.checkAllocated(); + long i = (j + (long) k * this.width) * 4; + CompatMemoryUtil.memPutInt(this.pixels + i, l); + } else { + throw new IllegalArgumentException(String.format("(%s, %s) outside of image bounds (%s, %s)", j, k, this.width, this.height)); + } + } + + @Deprecated + public int[] makePixelArray() { + if (this.format != NativeImage.Format.RGBA) { + throw new UnsupportedOperationException("can only call makePixelArray for RGBA images."); + } else { + this.checkAllocated(); + int[] aint = new int[this.getWidth() * this.getHeight()]; + + for(int i = 0; i < this.getHeight(); ++i) { + for(int j = 0; j < this.getWidth(); ++j) { + int k = this.getPixelRGBA(j, i); + int l = getA(k); + int i1 = getB(k); + int j1 = getG(k); + int k1 = getR(k); + int l1 = l << 24 | k1 << 16 | j1 << 8 | i1; + aint[j + i * this.getWidth()] = l1; + } + } + + return aint; + } + } + + public void upload(int i, int j, int k, boolean bl) { + this.upload(i, j, k, 0, 0, this.width, this.height, false, bl); + } + + public void upload(int i, int j, int k, int l, int m, int n, int o, boolean bl, boolean bl2) { + this.upload(i, j, k, l, m, n, o, false, false, bl, bl2); + } + + public void upload(int i, int j, int k, int l, int m, int n, int o, boolean bl, boolean bl2, boolean bl3, boolean bl4) { + this._upload(i, j, k, l, m, n, o, bl, bl2, bl3, bl4); + } + + private void _upload(int i, int j, int k, int l, int m, int n, int o, boolean bl, boolean bl2, boolean bl3, boolean bl4) { + this.checkAllocated(); + setFilter(bl, bl3); + setClamp(bl2); + if (n == this.getWidth()) { + GlStateManager.glPixelStorei(3314, 0); + } else { + GlStateManager.glPixelStorei(3314, this.getWidth()); + } + + GlStateManager.glPixelStorei(3316, l); + GlStateManager.glPixelStorei(3315, m); + this.format.setUnpackPixelStoreState(); + GlStateManager.glTexSubImage2D(3553, i, j, k, n, o, this.format.glFormat(), 5121, this.pixels); + if (bl4) { + this.close(); + } + + } + + public void downloadTexture(int k, boolean bl) { + this.checkAllocated(); + this.format.setPackPixelStoreState(); + GlStateManager._getTexImage(3553, k, this.format.glFormat(), 5121, this.pixels); + if (bl && this.format.hasAlpha()) { + for(int i = 0; i < this.getHeight(); ++i) { + for(int j = 0; j < this.getWidth(); ++j) { + this.setPixelRGBA(j, i, this.getPixelRGBA(j, i) | 255 << this.format.alphaOffset()); + } + } + } + + } + + public void fillRect(int k, int l, int m, int n, int o) { + for(int i = l; i < l + n; ++i) { + for(int j = k; j < k + m; ++j) { + this.setPixelRGBA(j, i, o); + } + } + + } + + public void copyRect(int m, int n, int o, int p, int q, int r, boolean bl, boolean bl2) { + for(int i = 0; i < r; ++i) { + for(int j = 0; j < q; ++j) { + int k = bl ? q - 1 - j : j; + int l = bl2 ? r - 1 - i : i; + int i1 = this.getPixelRGBA(m + j, n + i); + this.setPixelRGBA(m + o + k, n + p + l, i1); + } + } + + } + + public static int getA(int i) { + return i >> 24 & 255; + } + + public static int getR(int i) { + return i & 255; + } + + public static int getG(int i) { + return i >> 8 & 255; + } + + public static int getB(int i) { + return i >> 16 & 255; + } + + public static int combine(int i, int j, int k, int l) { + return (i & 255) << 24 | (j & 255) << 16 | (k & 255) << 8 | (l & 255); + } + + static { + OPEN_OPTIONS = EnumSet.of(StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); + } + + @OnlyIn(Dist.CLIENT) + public static enum InternalGlFormat { + RGBA(6408), + RGB(6407), + LUMINANCE_ALPHA(6410), + LUMINANCE(6409), + INTENSITY(32841); + + private final int glFormat; + + private InternalGlFormat(int j) { + this.glFormat = j; + } + + int glFormat() { + return this.glFormat; + } + } + + @OnlyIn(Dist.CLIENT) + public static enum Format { + RGBA(4, 6408, true, true, true, false, true, 0, 8, 16, 255, 24, true), + RGB(3, 6407, true, true, true, false, false, 0, 8, 16, 255, 255, true), + LUMINANCE_ALPHA(2, 6410, false, false, false, true, true, 255, 255, 255, 0, 8, true), + LUMINANCE(1, 6409, false, false, false, true, false, 0, 0, 0, 0, 255, true); + + private final int components; + private final int glFormat; + private final boolean hasRed; + private final boolean hasGreen; + private final boolean hasBlue; + private final boolean hasLuminance; + private final boolean hasAlpha; + private final int redOffset; + private final int greenOffset; + private final int blueOffset; + private final int luminanceOffset; + private final int alphaOffset; + private final boolean supportedByStb; + + private Format(int j, int k, boolean bl, boolean bl2, boolean bl3, boolean bl4, boolean bl5, int l, int m, int n, int o, int p, boolean bl6) { + this.components = j; + this.glFormat = k; + this.hasRed = bl; + this.hasGreen = bl2; + this.hasBlue = bl3; + this.hasLuminance = bl4; + this.hasAlpha = bl5; + this.redOffset = l; + this.greenOffset = m; + this.blueOffset = n; + this.luminanceOffset = o; + this.alphaOffset = p; + this.supportedByStb = bl6; + } + + public int components() { + return this.components; + } + + public void setPackPixelStoreState() { + GlStateManager.glPixelStorei(3333, this.components()); + } + + public void setUnpackPixelStoreState() { + GlStateManager.glPixelStorei(3317, this.components()); + } + + public int glFormat() { + return this.glFormat; + } + + public boolean hasAlpha() { + return this.hasAlpha; + } + + public int alphaOffset() { + return this.alphaOffset; + } + + public boolean hasLuminanceOrAlpha() { + return this.hasLuminance || this.hasAlpha; + } + + public int luminanceOrAlphaOffset() { + return this.hasLuminance ? this.luminanceOffset : this.alphaOffset; + } + + public boolean supportedByStb() { + return this.supportedByStb; + } + + private static Format getStbFormat(int i) { + switch (i) { + case 1: + return LUMINANCE; + case 2: + return LUMINANCE_ALPHA; + case 3: + return RGB; + case 4: + default: + return RGBA; + } + } + } +} diff --git a/src/main/java/nanolive/compat/VertexUtils.java b/src/main/java/nanolive/compat/VertexUtils.java new file mode 100644 index 0000000000..7778010956 --- /dev/null +++ b/src/main/java/nanolive/compat/VertexUtils.java @@ -0,0 +1,24 @@ +package nanolive.compat; + +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.VertexFormat; +import net.minecraft.client.renderer.vertex.VertexFormatElement; + +public class VertexUtils { + + public static void setupBufferState(VertexFormat format, long offset) { + for(int i = 0; i < format.getElements().size(); i++) { + VertexFormatElement element = format.getElements().get(i); + // TODO Not sure + element.getUsage().preDraw(format, (int) (offset + i), format.getSize(), Tessellator.getInstance().getBuffer().getByteBuffer()); + } + } + + public static void clearBufferState(VertexFormat format) { + for(int i = 0; i < format.getElements().size(); i++) { + VertexFormatElement element = format.getElements().get(i); + element.getUsage().postDraw(format, i, 0, null); + } + } + +} diff --git a/src/main/java/nanolive/utils/RenderGlobalExtended.java b/src/main/java/nanolive/utils/RenderGlobalExtended.java new file mode 100644 index 0000000000..c124bfa03d --- /dev/null +++ b/src/main/java/nanolive/utils/RenderGlobalExtended.java @@ -0,0 +1,11 @@ +package nanolive.utils; + +import net.coderbot.iris.pipeline.WorldRenderingPipeline; + +public interface RenderGlobalExtended { + + WorldRenderingPipeline getPipeline(); + + void setPipeline(WorldRenderingPipeline pipeline); + +} diff --git a/src/main/java/net/coderbot/batchedentityrendering/impl/BufferSegmentRenderer.java b/src/main/java/net/coderbot/batchedentityrendering/impl/BufferSegmentRenderer.java index 2db40959b4..931fef3294 100644 --- a/src/main/java/net/coderbot/batchedentityrendering/impl/BufferSegmentRenderer.java +++ b/src/main/java/net/coderbot/batchedentityrendering/impl/BufferSegmentRenderer.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.BufferUploader; +import net.minecraft.client.renderer.BufferBuilder; public class BufferSegmentRenderer { private final BufferBuilder fakeBufferBuilder; diff --git a/src/main/java/net/coderbot/batchedentityrendering/impl/RenderTypeUtil.java b/src/main/java/net/coderbot/batchedentityrendering/impl/RenderTypeUtil.java index dae1280837..06dabb14be 100644 --- a/src/main/java/net/coderbot/batchedentityrendering/impl/RenderTypeUtil.java +++ b/src/main/java/net/coderbot/batchedentityrendering/impl/RenderTypeUtil.java @@ -1,11 +1,10 @@ package net.coderbot.batchedentityrendering.impl; -import org.lwjgl.opengl.GL11C; - import net.minecraft.client.renderer.RenderType; +import org.lwjgl.opengl.GL11; public class RenderTypeUtil { public static boolean isTriangleStripDrawMode(RenderType renderType) { - return renderType.mode() == GL11C.GL_TRIANGLE_STRIP; + return renderType.mode() == GL11.GL_TRIANGLE_STRIP; } } diff --git a/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinBufferBuilder_SegmentRendering.java b/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinBufferBuilder_SegmentRendering.java index bba161c01f..a30f7f0288 100644 --- a/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinBufferBuilder_SegmentRendering.java +++ b/src/main/java/net/coderbot/batchedentityrendering/mixin/MixinBufferBuilder_SegmentRendering.java @@ -3,6 +3,8 @@ import java.nio.ByteBuffer; import java.util.List; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.vertex.VertexFormat; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -110,7 +112,7 @@ public void splitStrip() { private boolean dupeNextVertex; private void duplicateLastVertex() { - int i = this.format.getVertexSize(); + int i = this.format.getSize(); this.buffer.position(this.nextElementByte); ByteBuffer byteBuffer = this.buffer.duplicate(); byteBuffer.position(this.nextElementByte - i).limit(this.nextElementByte); diff --git a/src/main/java/net/coderbot/iris/Iris.java b/src/main/java/net/coderbot/iris/Iris.java index 35507bad4b..18b6f0e4db 100644 --- a/src/main/java/net/coderbot/iris/Iris.java +++ b/src/main/java/net/coderbot/iris/Iris.java @@ -1,37 +1,8 @@ package net.coderbot.iris; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.FileSystem; -import java.nio.file.FileSystemNotFoundException; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.InvalidPathException; -import java.nio.file.NoSuchFileException; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.Properties; -import java.util.stream.Stream; -import java.util.zip.ZipError; -import java.util.zip.ZipException; - -import net.coderbot.iris.shaderpack.materialmap.NamespacedId; -import net.minecraftforge.client.event.InputEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.ExtensionPoint; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.network.FMLNetworkConstants; -import org.apache.commons.lang3.tuple.Pair; -import org.jetbrains.annotations.NotNull; -import org.lwjgl.glfw.GLFW; - import com.google.common.base.Throwables; import com.mojang.blaze3d.platform.GlDebug; -import com.mojang.blaze3d.platform.InputConstants; - +import com.mojang.realmsclient.gui.ChatFormatting; import net.coderbot.iris.config.IrisConfig; import net.coderbot.iris.gl.GLDebug; import net.coderbot.iris.gl.shader.StandardMacros; @@ -45,24 +16,39 @@ import net.coderbot.iris.shaderpack.ProgramSet; import net.coderbot.iris.shaderpack.ShaderPack; import net.coderbot.iris.shaderpack.discovery.ShaderpackDirectoryManager; +import net.coderbot.iris.shaderpack.materialmap.NamespacedId; import net.coderbot.iris.shaderpack.option.OptionSet; import net.coderbot.iris.shaderpack.option.Profile; import net.coderbot.iris.shaderpack.option.values.MutableOptionValues; import net.coderbot.iris.shaderpack.option.values.OptionValues; import net.coderbot.iris.texture.pbr.PBRTextureManager; -import net.minecraft.ChatFormatting; -import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.util.text.TextComponentTranslation; +import net.minecraftforge.client.settings.KeyConflictContext; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.client.registry.ClientRegistry; +import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.gameevent.InputEvent; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.fml.loading.FMLLoader; -import net.minecraftforge.fml.loading.FMLPaths; +import org.lwjgl.input.Keyboard; + +import javax.annotation.Nonnull; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.*; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.Properties; +import java.util.stream.Stream; +import java.util.zip.ZipError; +import java.util.zip.ZipException; @Mod(Iris.MODID) public class Iris { @@ -82,15 +68,15 @@ public class Iris { private static ShaderPack currentPack; private static String currentPackName; - private static final boolean sodiumInstalled = FMLLoader.getLoadingModList().getModFileById("rubidium") != null; + private static final boolean sodiumInstalled = Loader.isModLoaded("vintagium"); private static boolean initialized; private static PipelineManager pipelineManager; private static IrisConfig irisConfig; private static FileSystem zipFileSystem; - private static KeyMapping reloadKeybind; - private static KeyMapping toggleShadersKeybind; - private static KeyMapping shaderpackScreenKeybind; + private static KeyBinding reloadKeybind; + private static KeyBinding toggleShadersKeybind; + private static KeyBinding shaderpackScreenKeybind; private static final Map shaderPackOptionQueue = new HashMap<>(); // Flag variable used when reloading @@ -106,8 +92,6 @@ public Iris() { try { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onInitializeClient); MinecraftForge.EVENT_BUS.addListener(this::onKeyInput); - - ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> Pair.of(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true)); }catch(Exception ignored) {} } @@ -130,7 +114,7 @@ public void onEarlyInitialize() { logger.warn("", e); } - irisConfig = new IrisConfig(FMLPaths.CONFIGDIR.get().resolve(MODID + ".properties")); + irisConfig = new IrisConfig(Minecraft.getMinecraft().gameDir.toPath().resolve("config").resolve(MODID + ".properties")); try { irisConfig.initialize(); @@ -139,9 +123,9 @@ public void onEarlyInitialize() { logger.error("", e); } - reloadKeybind = new KeyMapping("iris.keybind.reload", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_R, "iris.keybinds"); - toggleShadersKeybind = new KeyMapping("iris.keybind.toggleShaders", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_K, "iris.keybinds"); - shaderpackScreenKeybind = new KeyMapping("iris.keybind.shaderPackSelection", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_O, "iris.keybinds"); + reloadKeybind = new KeyBinding("iris.keybind.reload", KeyConflictContext.IN_GAME, Keyboard.KEY_R, "iris.keybinds"); + toggleShadersKeybind = new KeyBinding("iris.keybind.toggleShaders", KeyConflictContext.IN_GAME, Keyboard.KEY_K, "iris.keybinds"); + shaderpackScreenKeybind = new KeyBinding("iris.keybind.shaderPackSelection", KeyConflictContext.IN_GAME, Keyboard.KEY_O, "iris.keybinds"); initialized = true; } @@ -154,7 +138,7 @@ public void onInitializeClient(final FMLClientSetupEvent event) { } public void onKeyInput(InputEvent.KeyInputEvent event) { - handleKeybinds(Minecraft.getInstance()); + handleKeybinds(Minecraft.getMinecraft()); } /** @@ -193,35 +177,35 @@ public static void onLoadingComplete() { } public static void handleKeybinds(Minecraft minecraft) { - if (reloadKeybind.consumeClick()) { + if (reloadKeybind.isPressed()) { try { reload(); if (minecraft.player != null) { - minecraft.player.displayClientMessage(new TranslatableComponent("iris.shaders.reloaded"), false); + minecraft.player.sendMessage(new TextComponentTranslation("iris.shaders.reloaded")); } } catch (Exception e) { logger.error("Error while reloading Shaders for " + MODNAME + "!", e); if (minecraft.player != null) { - minecraft.player.displayClientMessage(new TranslatableComponent("iris.shaders.reloaded.failure", Throwables.getRootCause(e).getMessage()).withStyle(ChatFormatting.RED), false); + minecraft.player.sendMessage(new TextComponentTranslation("iris.shaders.reloaded.failure", Throwables.getRootCause(e).getMessage()).withStyle(ChatFormatting.RED)); } } - } else if (toggleShadersKeybind.consumeClick()) { + } else if (toggleShadersKeybind.isPressed()) { try { toggleShaders(minecraft, !irisConfig.areShadersEnabled()); } catch (Exception e) { logger.error("Error while toggling shaders!", e); if (minecraft.player != null) { - minecraft.player.displayClientMessage(new TranslatableComponent("iris.shaders.toggled.failure", Throwables.getRootCause(e).getMessage()).withStyle(ChatFormatting.RED), false); + minecraft.player.sendMessage(new TextComponentTranslation("iris.shaders.toggled.failure", Throwables.getRootCause(e).getMessage()).withStyle(ChatFormatting.RED)); } setShadersDisabled(); fallback = true; } - } else if (shaderpackScreenKeybind.consumeClick()) { - minecraft.setScreen(new ShaderPackScreen(null)); + } else if (shaderpackScreenKeybind.isPressed()) { + minecraft.displayGuiScreen(new ShaderPackScreen(null)); } } @@ -231,7 +215,7 @@ public static void toggleShaders(Minecraft minecraft, boolean enabled) throws IO reload(); if (minecraft.player != null) { - minecraft.player.displayClientMessage(enabled ? new TranslatableComponent("iris.shaders.toggled", currentPackName) : new TranslatableComponent("iris.shaders.disabled"), false); + minecraft.player.sendMessage(enabled ? new TextComponentTranslation("iris.shaders.toggled", currentPackName) : new TextComponentTranslation("iris.shaders.disabled")); } } @@ -410,15 +394,15 @@ private static void setDebug(boolean enable) { if (enable) { success = GLDebug.setupDebugMessageCallback(); } else { - GlDebug.enableDebugCallback(Minecraft.getInstance().options.glDebugVerbosity, false); + GlDebug.enableDebugCallback(Minecraft.getMinecraft().gameSettings.glDebugVerbosity, false); success = 1; } logger.info("Debug functionality is " + (enable ? "enabled, logging will be more verbose!" : "disabled.")); - if (Minecraft.getInstance().player != null) { - Minecraft.getInstance().player.displayClientMessage(new TranslatableComponent(success != 0 ? (enable ? "iris.shaders.debug.enabled" : "iris.shaders.debug.disabled") : "iris.shaders.debug.failure"), false); + if (Minecraft.getMinecraft().player != null) { + Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation(success != 0 ? (enable ? "iris.shaders.debug.enabled" : "iris.shaders.debug.disabled") : "iris.shaders.debug.failure")); if (success == 2) { - Minecraft.getInstance().player.displayClientMessage(new TranslatableComponent("iris.shaders.debug.restart"), false); + Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("iris.shaders.debug.restart")); } } @@ -570,7 +554,7 @@ public static void reload() throws IOException { // Very important - we need to re-create the pipeline straight away. // https://github.com/IrisShaders/Iris/issues/1330 - if (Minecraft.getInstance().level != null) { + if (Minecraft.getMinecraft().world != null) { Iris.getPipelineManager().preparePipeline(Iris.getCurrentDimension()); } } @@ -601,7 +585,7 @@ private static void destroyEverything() { public static NamespacedId lastDimension = null; public static NamespacedId getCurrentDimension() { - ClientLevel level = Minecraft.getInstance().level; + WorldClient level = Minecraft.getMinecraft().world; if (level != null) { return new NamespacedId(level.dimension().location().getNamespace(), level.dimension().location().getPath()); @@ -632,7 +616,7 @@ private static WorldRenderingPipeline createPipeline(NamespacedId dimensionId) { } } - @NotNull + @Nonnull public static PipelineManager getPipelineManager() { if (pipelineManager == null) { pipelineManager = new PipelineManager(Iris::createPipeline); @@ -641,7 +625,7 @@ public static PipelineManager getPipelineManager() { return pipelineManager; } - @NotNull + @Nonnull public static Optional getCurrentPack() { return Optional.ofNullable(currentPack); } @@ -690,7 +674,7 @@ public static boolean isSodiumInstalled() { public static Path getShaderpacksDirectory() { if (shaderpacksDirectory == null) { - shaderpacksDirectory = FMLPaths.GAMEDIR.get().resolve("shaderpacks"); + shaderpacksDirectory = Minecraft.getMinecraft().gameDir.toPath().resolve("shaderpacks"); } return shaderpacksDirectory; diff --git a/src/main/java/net/coderbot/iris/JomlConversions.java b/src/main/java/net/coderbot/iris/JomlConversions.java index 89fb8209d8..df71147d41 100644 --- a/src/main/java/net/coderbot/iris/JomlConversions.java +++ b/src/main/java/net/coderbot/iris/JomlConversions.java @@ -2,11 +2,12 @@ import net.coderbot.iris.vendored.joml.Vector3d; import net.coderbot.iris.vendored.joml.Vector4f; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.phys.Vec3; public class JomlConversions { - public static Vector3d fromVec3(Vec3 vec) { - return new Vector3d(vec.x(), vec.y(), vec.z()); + public static Vector3d fromVec3(Vec3d vec) { + return new Vector3d(vec.x, vec.y, vec.z); } public static Vector4f toJoml(com.mojang.math.Vector4f v) { diff --git a/src/main/java/net/coderbot/iris/LaunchWarn.java b/src/main/java/net/coderbot/iris/LaunchWarn.java index 7dc49a7993..7ab022ae45 100644 --- a/src/main/java/net/coderbot/iris/LaunchWarn.java +++ b/src/main/java/net/coderbot/iris/LaunchWarn.java @@ -12,8 +12,8 @@ public class LaunchWarn { public static void main(String[] args) { // TODO: make this translatable - String message = "This file is the Forge version of Oculus, meant to be installed as a mod. Would you like to get the Forge Installer instead?"; - String fallback = "This file is the Forge version of Oculus, meant to be installed as a mod. Please download the Forge Installer from https://files.minecraftforge.net"; + String message = "This file is the Fabric version of Iris, meant to be installed as a mod. Would you like to get the Iris Installer instead?"; + String fallback = "This file is the Fabric version of Iris, meant to be installed as a mod. Please download the Iris Installer from https://irisshaders.net."; if (GraphicsEnvironment.isHeadless()) { System.err.println(fallback); } else { @@ -24,11 +24,11 @@ public static void main(String[] args) { } if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { - int option = JOptionPane.showOptionDialog(null, message, "Oculus Installer", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null); + int option = JOptionPane.showOptionDialog(null, message, "Iris Installer", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null); if (option == JOptionPane.YES_OPTION) { try { - Desktop.getDesktop().browse(URI.create("https://files.minecraftforge.net")); + Desktop.getDesktop().browse(URI.create("https://irisshaders.net")); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/net/coderbot/iris/apiimpl/IrisApiV0Impl.java b/src/main/java/net/coderbot/iris/apiimpl/IrisApiV0Impl.java index 53cf90588d..4e25620a8c 100644 --- a/src/main/java/net/coderbot/iris/apiimpl/IrisApiV0Impl.java +++ b/src/main/java/net/coderbot/iris/apiimpl/IrisApiV0Impl.java @@ -12,7 +12,7 @@ import net.irisshaders.iris.api.v0.IrisApi; import net.irisshaders.iris.api.v0.IrisApiConfig; import net.irisshaders.iris.api.v0.IrisTextVertexSink; -import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.GuiScreen; public class IrisApiV0Impl implements IrisApi { public static final IrisApiV0Impl INSTANCE = new IrisApiV0Impl(); @@ -41,7 +41,7 @@ public boolean isRenderingShadowPass() { @Override public Object openMainIrisScreenObj(Object parent) { - return new ShaderPackScreen((Screen) parent); + return new ShaderPackScreen((GuiScreen) parent); } @Override diff --git a/src/main/java/net/coderbot/iris/block_rendering/BlockMaterialMapping.java b/src/main/java/net/coderbot/iris/block_rendering/BlockMaterialMapping.java index 85f1dbac0f..4dfc5d5b88 100644 --- a/src/main/java/net/coderbot/iris/block_rendering/BlockMaterialMapping.java +++ b/src/main/java/net/coderbot/iris/block_rendering/BlockMaterialMapping.java @@ -1,33 +1,30 @@ package net.coderbot.iris.block_rendering; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap; import net.coderbot.iris.Iris; import net.coderbot.iris.shaderpack.materialmap.BlockEntry; import net.coderbot.iris.shaderpack.materialmap.BlockRenderType; import net.coderbot.iris.shaderpack.materialmap.NamespacedId; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.Property; -import net.minecraftforge.registries.ForgeRegistries; +import net.minecraft.block.Block; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.registry.ForgeRegistries; import net.minecraftforge.registries.IRegistryDelegate; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class BlockMaterialMapping { - public static Object2IntMap createBlockStateIdMap(Int2ObjectMap> blockPropertiesMap) { - Object2IntMap blockStateIds = new Object2IntOpenHashMap<>(); + public static Object2IntMap createBlockStateIdMap(Int2ObjectMap> blockPropertiesMap) { + Object2IntMap blockStateIds = new Object2IntOpenHashMap<>(); blockPropertiesMap.forEach((intId, entries) -> { for (BlockEntry entry : entries) { @@ -38,8 +35,8 @@ public static Object2IntMap createBlockStateIdMap(Int2ObjectMap, RenderType> createBlockTypeMap(Map blockPropertiesMap) { - Map, RenderType> blockTypeIds = new Object2ObjectOpenHashMap<>(); + public static Map, BlockRenderLayer> createBlockTypeMap(Map blockPropertiesMap) { + Map, BlockRenderLayer> blockTypeIds = new Object2ObjectOpenHashMap<>(); blockPropertiesMap.forEach((id, blockType) -> { ResourceLocation resourceLocation = new ResourceLocation(id.getNamespace(), id.getName()); @@ -56,29 +53,29 @@ public static Map, RenderType> createBlockTypeMap(Map idMap, int intId) { + private static void addBlockStates(BlockEntry entry, Object2IntMap idMap, int intId) { NamespacedId id = entry.getId(); ResourceLocation resourceLocation = new ResourceLocation(id.getNamespace(), id.getName()); - Block block = Registry.BLOCK.get(resourceLocation); + Block block = ForgeRegistries.BLOCKS.getValue(resourceLocation); // If the block doesn't exist, by default the registry will return AIR. That probably isn't what we want. // TODO: Assuming that Registry.BLOCK.getDefaultId() == "minecraft:air" here - if (block == Blocks.AIR) { + if (block == null || block == Blocks.AIR) { return; } @@ -86,7 +83,7 @@ private static void addBlockStates(BlockEntry entry, Object2IntMap i if (propertyPredicates.isEmpty()) { // Just add all the states if there aren't any predicates - for (BlockState state : block.getStateDefinition().getPossibleStates()) { + for (IBlockState state : block.getBlockState().getValidStates()) { // NB: Using putIfAbsent means that the first successful mapping takes precedence // Needed for OptiFine parity: // https://github.com/IrisShaders/Iris/issues/1327 @@ -99,11 +96,11 @@ private static void addBlockStates(BlockEntry entry, Object2IntMap i // As a result, we first collect each key=value pair in order to determine what properties we need to filter on. // We already get this from BlockEntry, but we convert the keys to `Property`s to ensure they exist and to avoid // string comparisons later. - Map, String> properties = new HashMap<>(); - StateDefinition stateManager = block.getStateDefinition(); + Map, String> properties = new HashMap<>(); + BlockStateContainer stateManager = block.getBlockState(); propertyPredicates.forEach((key, value) -> { - Property property = stateManager.getProperty(key); + IProperty property = stateManager.getProperty(key); if (property == null) { Iris.logger.warn("Error while parsing the block ID map entry for \"" + "block." + intId + "\":"); @@ -117,7 +114,7 @@ private static void addBlockStates(BlockEntry entry, Object2IntMap i // Once we have a list of properties and their expected values, we iterate over every possible state of this // block and check for ones that match the filters. This isn't particularly efficient, but it works! - for (BlockState state : stateManager.getPossibleStates()) { + for (IBlockState state : stateManager.getValidStates()) { if (checkState(state, properties)) { // NB: Using putIfAbsent means that the first successful mapping takes precedence // Needed for OptiFine parity: @@ -133,9 +130,9 @@ private static void addBlockStates(BlockEntry entry, Object2IntMap i // If you're able to rewrite this function without SuppressWarnings, feel free. // But otherwise it works fine. @SuppressWarnings({"rawtypes", "unchecked"}) - private static boolean checkState(BlockState state, Map, String> expectedValues) { - for (Map.Entry, String> condition : expectedValues.entrySet()) { - Property property = condition.getKey(); + private static boolean checkState(IBlockState state, Map, String> expectedValues) { + for (Map.Entry, String> condition : expectedValues.entrySet()) { + IProperty property = condition.getKey(); String expectedValue = condition.getValue(); String actualValue = property.getName(state.getValue(property)); diff --git a/src/main/java/net/coderbot/iris/block_rendering/BlockRenderingSettings.java b/src/main/java/net/coderbot/iris/block_rendering/BlockRenderingSettings.java index d47a56c750..29e11ffad4 100644 --- a/src/main/java/net/coderbot/iris/block_rendering/BlockRenderingSettings.java +++ b/src/main/java/net/coderbot/iris/block_rendering/BlockRenderingSettings.java @@ -2,22 +2,23 @@ import java.util.Map; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.BlockRenderLayer; import net.minecraftforge.registries.IRegistryDelegate; -import org.jetbrains.annotations.Nullable; import it.unimi.dsi.fastutil.objects.Object2IntFunction; import it.unimi.dsi.fastutil.objects.Object2IntMap; import net.coderbot.iris.shaderpack.materialmap.NamespacedId; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; + +import javax.annotation.Nullable; public class BlockRenderingSettings { public static final BlockRenderingSettings INSTANCE = new BlockRenderingSettings(); private boolean reloadRequired; - private Object2IntMap blockStateIds; - private Map, RenderType> blockTypeIds; + private Object2IntMap blockStateIds; + private Map, BlockRenderLayer> blockTypeIds; private Object2IntFunction entityIds; private float ambientOcclusionLevel; private boolean disableDirectionalShading; @@ -43,12 +44,12 @@ public void clearReloadRequired() { } @Nullable - public Object2IntMap getBlockStateIds() { + public Object2IntMap getBlockStateIds() { return blockStateIds; } @Nullable - public Map, RenderType> getBlockTypeIds() { + public Map, BlockRenderLayer> getBlockTypeIds() { return blockTypeIds; } @@ -58,7 +59,7 @@ public Object2IntFunction getEntityIds() { return entityIds; } - public void setBlockStateIds(Object2IntMap blockStateIds) { + public void setBlockStateIds(Object2IntMap blockStateIds) { if (this.blockStateIds != null && this.blockStateIds.equals(blockStateIds)) { return; } @@ -67,7 +68,7 @@ public void setBlockStateIds(Object2IntMap blockStateIds) { this.blockStateIds = blockStateIds; } - public void setBlockTypeIds(Map, RenderType> blockTypeIds) { + public void setBlockTypeIds(Map, BlockRenderLayer> blockTypeIds) { if (this.blockTypeIds != null && this.blockTypeIds.equals(blockTypeIds)) { return; } diff --git a/src/main/java/net/coderbot/iris/colorspace/ColorSpaceComputeConverter.java b/src/main/java/net/coderbot/iris/colorspace/ColorSpaceComputeConverter.java index a653f77a39..1517748817 100644 --- a/src/main/java/net/coderbot/iris/colorspace/ColorSpaceComputeConverter.java +++ b/src/main/java/net/coderbot/iris/colorspace/ColorSpaceComputeConverter.java @@ -8,12 +8,11 @@ import net.coderbot.iris.shaderpack.StringPair; import net.coderbot.iris.shaderpack.preprocessor.JcppProcessor; import org.apache.commons.io.IOUtils; -import org.lwjgl.opengl.GL43C; +import org.lwjgl.opengl.GL42; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -64,7 +63,7 @@ public void process(int targetImage) { this.target = targetImage; program.use(); IrisRenderSystem.dispatchCompute(width / 8, height / 8, 1); - IrisRenderSystem.memoryBarrier(GL43C.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL43C.GL_TEXTURE_FETCH_BARRIER_BIT); + IrisRenderSystem.memoryBarrier(GL42.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL42.GL_TEXTURE_FETCH_BARRIER_BIT); ComputeProgram.unbind(); } } \ No newline at end of file diff --git a/src/main/java/net/coderbot/iris/colorspace/ColorSpaceFragmentConverter.java b/src/main/java/net/coderbot/iris/colorspace/ColorSpaceFragmentConverter.java index 2fd4640e61..2876054319 100644 --- a/src/main/java/net/coderbot/iris/colorspace/ColorSpaceFragmentConverter.java +++ b/src/main/java/net/coderbot/iris/colorspace/ColorSpaceFragmentConverter.java @@ -1,7 +1,6 @@ package net.coderbot.iris.colorspace; import com.google.common.collect.ImmutableSet; -import com.mojang.blaze3d.platform.GlStateManager; import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.framebuffer.GlFramebuffer; import net.coderbot.iris.gl.program.Program; @@ -11,13 +10,15 @@ import net.coderbot.iris.shaderpack.StringPair; import net.coderbot.iris.shaderpack.preprocessor.JcppProcessor; import net.coderbot.iris.vendored.joml.Matrix4f; +import net.minecraft.client.renderer.GlStateManager; import org.apache.commons.io.IOUtils; -import org.lwjgl.opengl.GL11C; -import org.lwjgl.opengl.GL30C; +import org.lwjgl.opengl.GL11; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; public class ColorSpaceFragmentConverter implements ColorSpaceConverter { private int width; @@ -38,7 +39,7 @@ public void rebuildProgram(int width, int height, ColorSpace colorSpace) { program = null; framebuffer.destroy(); framebuffer = null; - GlStateManager._deleteTexture(swapTexture); + GlStateManager.deleteTexture(swapTexture); swapTexture = 0; } @@ -68,8 +69,8 @@ public void rebuildProgram(int width, int height, ColorSpace colorSpace) { builder.uniformJomlMatrix(UniformUpdateFrequency.ONCE, "projection", () -> new Matrix4f(2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, -1, -1, 0, 1)); builder.addDynamicSampler(() -> target, "readImage"); - swapTexture = GlStateManager._genTexture(); - IrisRenderSystem.texImage2D(swapTexture, GL30C.GL_TEXTURE_2D, 0, GL30C.GL_RGBA8, width, height, 0, GL30C.GL_RGBA, GL30C.GL_UNSIGNED_BYTE, null); + swapTexture = GlStateManager.generateTexture(); + IrisRenderSystem.texImage2D(swapTexture, GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, null); this.framebuffer = new GlFramebuffer(); framebuffer.addColorAttachment(0, swapTexture); @@ -85,6 +86,6 @@ public void process(int targetImage) { FullScreenQuadRenderer.INSTANCE.render(); Program.unbind(); framebuffer.bindAsReadBuffer(); - IrisRenderSystem.copyTexSubImage2D(targetImage, GL11C.GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height); + IrisRenderSystem.copyTexSubImage2D(targetImage, GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height); } } \ No newline at end of file diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/block_context/BlockContextHolder.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/block_context/BlockContextHolder.java index 15b7ae1bdd..a9252f30e5 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/block_context/BlockContextHolder.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/block_context/BlockContextHolder.java @@ -2,10 +2,10 @@ import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntMaps; -import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.block.state.IBlockState; public class BlockContextHolder { - private final Object2IntMap blockStateIds; + private final Object2IntMap blockStateIds; public int localPosX; public int localPosY; @@ -20,7 +20,7 @@ public BlockContextHolder() { this.renderType = -1; } - public BlockContextHolder(Object2IntMap idMap) { + public BlockContextHolder(Object2IntMap idMap) { this.blockStateIds = idMap; this.blockId = -1; this.renderType = -1; @@ -32,8 +32,8 @@ public void setLocalPos(int localPosX, int localPosY, int localPosZ) { this.localPosZ = localPosZ; } - public void set(BlockState state, short renderType) { - this.blockId = (short) this.blockStateIds.getOrDefault(state, -1); + public void set(IBlockState state, short renderType) { + this.blockId = (short) this.blockStateIds.getOrDefault(state, -1).intValue(); this.renderType = renderType; } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/block_context/ChunkBuildBuffersExt.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/block_context/ChunkBuildBuffersExt.java index 19f5f578e7..d3b46d87bb 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/block_context/ChunkBuildBuffersExt.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/block_context/ChunkBuildBuffersExt.java @@ -1,11 +1,11 @@ package net.coderbot.iris.compat.sodium.impl.block_context; -import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.block.state.IBlockState; public interface ChunkBuildBuffersExt { void iris$setLocalPos(int localPosX, int localPosY, int localPosZ); - void iris$setMaterialId(BlockState state, short renderType); + void iris$setMaterialId(IBlockState state, short renderType); void iris$resetBlockContext(); } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/options/IrisSodiumOptions.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/options/IrisSodiumOptions.java index 6888b656f4..a80b37fe5c 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/options/IrisSodiumOptions.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/options/IrisSodiumOptions.java @@ -2,7 +2,6 @@ import java.io.IOException; -import me.jellysquid.mods.sodium.client.gui.options.OptionFlag; import me.jellysquid.mods.sodium.client.gui.options.OptionImpact; import me.jellysquid.mods.sodium.client.gui.options.OptionImpl; import me.jellysquid.mods.sodium.client.gui.options.control.ControlValueFormatter; @@ -12,16 +11,16 @@ import net.coderbot.iris.Iris; import net.coderbot.iris.colorspace.ColorSpace; import net.coderbot.iris.gui.option.IrisVideoSettings; -import net.minecraft.client.Options; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.client.settings.GameSettings; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextComponentTranslation; public class IrisSodiumOptions { - public static OptionImpl createMaxShadowDistanceSlider(MinecraftOptionsStorage vanillaOpts) { - OptionImpl maxShadowDistanceSlider = OptionImpl.createBuilder(int.class, vanillaOpts) - .setName(new TranslatableComponent("options.iris.shadowDistance")) - .setTooltip(new TranslatableComponent("options.iris.shadowDistance.sodium_tooltip")) + public static OptionImpl createMaxShadowDistanceSlider(MinecraftOptionsStorage vanillaOpts) { + OptionImpl maxShadowDistanceSlider = OptionImpl.createBuilder(int.class, vanillaOpts) + .setName(new TextComponentTranslation("options.iris.shadowDistance")) + .setTooltip(new TextComponentTranslation("options.iris.shadowDistance.sodium_tooltip")) .setControl(option -> new SliderControl(option, 0, 32, 1, ControlValueFormatter.quantity("options.chunks"))) .setBinding((options, value) -> { IrisVideoSettings.shadowDistance = value; @@ -41,12 +40,12 @@ public static OptionImpl createMaxShadowDistanceSlider(Minecra return maxShadowDistanceSlider; } - public static OptionImpl createColorSpaceButton(MinecraftOptionsStorage vanillaOpts) { - OptionImpl colorSpace = OptionImpl.createBuilder(ColorSpace.class, vanillaOpts) - .setName(new TranslatableComponent("options.iris.colorSpace")) - .setTooltip(new TranslatableComponent("options.iris.colorSpace.sodium_tooltip")) + public static OptionImpl createColorSpaceButton(MinecraftOptionsStorage vanillaOpts) { + OptionImpl colorSpace = OptionImpl.createBuilder(ColorSpace.class, vanillaOpts) + .setName(new TextComponentTranslation("options.iris.colorSpace")) + .setTooltip(new TextComponentTranslation("options.iris.colorSpace.sodium_tooltip")) .setControl(option -> new CyclingControl<>(option, ColorSpace.class, - new Component[] { new TextComponent("SRGB"), new TextComponent("DCI_P3"), new TextComponent("Display P3"), new TextComponent("REC2020"), new TextComponent("Adobe RGB") })) + new ITextComponent[] { new TextComponentString("SRGB"), new TextComponentString("DCI_P3"), new TextComponentString("Display P3"), new TextComponentString("REC2020"), new TextComponentString("Adobe RGB") })) .setBinding((options, value) -> { IrisVideoSettings.colorSpace = value; try { @@ -63,17 +62,4 @@ public static OptionImpl createColorSpaceButton(MinecraftOp return colorSpace; } - - public static OptionImpl createLimitedVideoSettingsButton(MinecraftOptionsStorage vanillaOpts) { - return OptionImpl.createBuilder(SupportedGraphicsMode.class, vanillaOpts) - .setName(new TranslatableComponent("options.graphics")) - .setTooltip(new TranslatableComponent("sodium.options.graphics_quality.tooltip")) - .setControl(option -> new CyclingControl<>(option, SupportedGraphicsMode.class, new Component[] { new TranslatableComponent("options.graphics.fast"), new TranslatableComponent("options.graphics.fancy") })) - .setBinding( - (opts, value) -> opts.graphicsMode = value.toVanilla(), - opts -> SupportedGraphicsMode.fromVanilla(opts.graphicsMode)) - .setImpact(OptionImpact.HIGH) - .setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD) - .build(); - } } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/options/SupportedGraphicsMode.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/options/SupportedGraphicsMode.java deleted file mode 100644 index ae0cd05119..0000000000 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/options/SupportedGraphicsMode.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.coderbot.iris.compat.sodium.impl.options; - -import net.minecraft.client.GraphicsStatus; - -public enum SupportedGraphicsMode { - FAST, FANCY; - - public static SupportedGraphicsMode fromVanilla(GraphicsStatus vanilla) { - if (vanilla == GraphicsStatus.FAST) { - return FAST; - } else { - return FANCY; - } - } - - public GraphicsStatus toVanilla() { - if (this == FAST) { - return GraphicsStatus.FAST; - } else { - return GraphicsStatus.FANCY; - } - } -} diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/ChunkRenderBackendExt.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/ChunkRenderBackendExt.java index f53fca0a66..1cb7893509 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/ChunkRenderBackendExt.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/ChunkRenderBackendExt.java @@ -1,9 +1,7 @@ package net.coderbot.iris.compat.sodium.impl.shader_overrides; -import com.mojang.blaze3d.vertex.PoseStack; - import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass; public interface ChunkRenderBackendExt { - void iris$begin(PoseStack poseStack, BlockRenderPass pass); + void iris$begin(BlockRenderPass pass); } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgram.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgram.java index 5e303490c7..343cdb0c9a 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgram.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgram.java @@ -2,6 +2,8 @@ import java.nio.FloatBuffer; +import me.jellysquid.mods.sodium.client.render.GameRendererContext; +import net.minecraft.util.ResourceLocation; import org.jetbrains.annotations.Nullable; import org.lwjgl.system.MemoryStack; @@ -17,6 +19,8 @@ import net.coderbot.iris.gl.program.ProgramUniforms; import net.minecraft.resources.ResourceLocation; +import javax.annotation.Nullable; + public class IrisChunkProgram extends ChunkProgram { // Uniform variable binding indexes private final int uModelViewMatrix; @@ -42,8 +46,9 @@ public IrisChunkProgram(RenderDevice owner, ResourceLocation name, int handle, this.irisProgramImages = irisProgramImages; } - public void setup(PoseStack poseStack, float modelScale, float textureScale) { - super.setup(poseStack, modelScale, textureScale); + @Override + public void setup(float modelScale, float textureScale) { + super.setup(modelScale, textureScale); if (irisProgramUniforms != null) { irisProgramUniforms.update(); @@ -57,12 +62,11 @@ public void setup(PoseStack poseStack, float modelScale, float textureScale) { irisProgramImages.update(); } - Matrix4f modelViewMatrix = poseStack.last().pose(); Matrix4f normalMatrix = poseStack.last().pose().copy(); normalMatrix.invert(); normalMatrix.transpose(); - uniformMatrix(uModelViewMatrix, modelViewMatrix); + uniformMatrix(uModelViewMatrix, GameRendererContext.getModelViewProjectionMatrix()); uniformMatrix(uNormalMatrix, normalMatrix); } @@ -84,17 +88,11 @@ public int getUniformLocation(String name) { } } - private void uniformMatrix(int location, Matrix4f matrix) { + private void uniformMatrix(int location, FloatBuffer buffer) { if (location == -1) { return; } - try (MemoryStack memoryStack = MemoryStack.stackPush()) { - FloatBuffer buffer = memoryStack.mallocFloat(16); - - matrix.store(buffer); - - IrisRenderSystem.uniformMatrix4fv(location, false, buffer); - } + IrisRenderSystem.uniformMatrix4fv(location, false, buffer); } } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java index 82573cc9cb..7623b4f398 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java @@ -4,7 +4,7 @@ import java.util.Locale; import java.util.Optional; -import org.jetbrains.annotations.Nullable; +import net.minecraft.util.ResourceLocation; import me.jellysquid.mods.sodium.client.gl.device.RenderDevice; import me.jellysquid.mods.sodium.client.gl.shader.GlProgram; @@ -22,7 +22,8 @@ import net.coderbot.iris.pipeline.SodiumTerrainPipeline; import net.coderbot.iris.pipeline.WorldRenderingPipeline; import net.coderbot.iris.shadows.ShadowRenderingState; -import net.minecraft.resources.ResourceLocation; + +import javax.annotation.Nullable; public class IrisChunkProgramOverrides { private static final ShaderConstants EMPTY_CONSTANTS = ShaderConstants.builder().build(); diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisGlVertexAttributeFormat.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisGlVertexAttributeFormat.java index 6ff5cf8f5f..38c17ab97c 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisGlVertexAttributeFormat.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/IrisGlVertexAttributeFormat.java @@ -1,12 +1,12 @@ package net.coderbot.iris.compat.sodium.impl.vertex_format; -import org.lwjgl.opengl.GL20C; +import org.lwjgl.opengl.GL11; import me.jellysquid.mods.sodium.client.gl.attribute.GlVertexAttributeFormat; import net.coderbot.iris.compat.sodium.mixin.vertex_format.GlVertexAttributeFormatAccessor; public class IrisGlVertexAttributeFormat { public static final GlVertexAttributeFormat BYTE = - GlVertexAttributeFormatAccessor.createGlVertexAttributeFormat(GL20C.GL_BYTE, 1); - public static final GlVertexAttributeFormat SHORT = GlVertexAttributeFormatAccessor.createGlVertexAttributeFormat(GL20C.GL_SHORT, 2); + GlVertexAttributeFormatAccessor.createGlVertexAttributeFormat(GL11.GL_BYTE, 1); + public static final GlVertexAttributeFormat SHORT = GlVertexAttributeFormatAccessor.createGlVertexAttributeFormat(GL11.GL_SHORT, 2); } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertexBufferWriterNio.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertexBufferWriterNio.java index 4d2bd9b65b..9d52ad1853 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertexBufferWriterNio.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertexBufferWriterNio.java @@ -13,7 +13,7 @@ import net.minecraft.client.renderer.texture.OverlayTexture; public class EntityVertexBufferWriterNio extends VertexBufferWriterNio implements QuadVertexSink, GlyphVertexSink { - private static final int STRIDE = IrisVertexFormats.ENTITY.getVertexSize(); + private static final int STRIDE = IrisVertexFormats.ENTITY.getSize(); private final QuadViewEntity.QuadViewEntityNio quad = new QuadViewEntity.QuadViewEntityNio(); private final Vector3f saveNormal = new Vector3f(); @@ -53,7 +53,7 @@ public void writeQuad(float x, float y, float z, int color, float u, float v, in @Override public void writeGlyph(float x, float y, float z, int color, float u, float v, int light) { - writeQuad(x, y, z, color, u, v, light, OverlayTexture.NO_OVERLAY, 0); + writeQuad(x, y, z, color, u, v, light, 0, 0); } private void endQuad(int normal) { diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertexBufferWriterUnsafe.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertexBufferWriterUnsafe.java index cceb78d3cc..92c97c9f1f 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertexBufferWriterUnsafe.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/EntityVertexBufferWriterUnsafe.java @@ -1,5 +1,6 @@ package net.coderbot.iris.compat.sodium.impl.vertex_format.entity_xhfp; +import me.jellysquid.mods.sodium.client.util.CompatMemoryUtil; import org.lwjgl.system.MemoryUtil; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; @@ -13,7 +14,7 @@ import net.minecraft.client.renderer.texture.OverlayTexture; public class EntityVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe implements QuadVertexSink, GlyphVertexSink { - private static final int STRIDE = IrisVertexFormats.ENTITY.getVertexSize(); + private static final int STRIDE = IrisVertexFormats.ENTITY.getSize(); private final QuadViewEntity.QuadViewEntityUnsafe quad = new QuadViewEntity.QuadViewEntityUnsafe(); private final Vector3f saveNormal = new Vector3f(); @@ -34,14 +35,14 @@ public void writeQuad(float x, float y, float z, int color, float u, float v, in uSum += u; vSum += v; - MemoryUtil.memPutFloat(i, x); - MemoryUtil.memPutFloat(i + 4, y); - MemoryUtil.memPutFloat(i + 8, z); - MemoryUtil.memPutInt(i + 12, color); - MemoryUtil.memPutFloat(i + 16, u); - MemoryUtil.memPutFloat(i + 20, v); - MemoryUtil.memPutInt(i + 24, overlay); - MemoryUtil.memPutInt(i + 28, light); + CompatMemoryUtil.memPutFloat(i, x); + CompatMemoryUtil.memPutFloat(i + 4, y); + CompatMemoryUtil.memPutFloat(i + 8, z); + CompatMemoryUtil.memPutInt(i + 12, color); + CompatMemoryUtil.memPutFloat(i + 16, u); + CompatMemoryUtil.memPutFloat(i + 20, v); + CompatMemoryUtil.memPutInt(i + 24, overlay); + CompatMemoryUtil.memPutInt(i + 28, light); if (vertexCount == 4) { this.endQuad(normal); @@ -82,10 +83,10 @@ private void endQuad(int normal) { int tangent = NormalHelper.computeTangent(normalX, normalY, normalZ, quad); for (long vertex = 0; vertex < 4; vertex++) { - MemoryUtil.memPutFloat(i + 36 - STRIDE * vertex, uSum); - MemoryUtil.memPutFloat(i + 40 - STRIDE * vertex, vSum); - MemoryUtil.memPutInt(i + 32 - STRIDE * vertex, normal); - MemoryUtil.memPutInt(i + 44 - STRIDE * vertex, tangent); + CompatMemoryUtil.memPutFloat(i + 36 - STRIDE * vertex, uSum); + CompatMemoryUtil.memPutFloat(i + 40 - STRIDE * vertex, vSum); + CompatMemoryUtil.memPutInt(i + 32 - STRIDE * vertex, normal); + CompatMemoryUtil.memPutInt(i + 44 - STRIDE * vertex, tangent); } uSum = 0; diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/ExtendedGlyphVertexType.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/ExtendedGlyphVertexType.java index 881ecd7996..352b44f234 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/ExtendedGlyphVertexType.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/ExtendedGlyphVertexType.java @@ -1,20 +1,19 @@ package net.coderbot.iris.compat.sodium.impl.vertex_format.entity_xhfp; -import com.mojang.blaze3d.vertex.VertexConsumer; -import com.mojang.blaze3d.vertex.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; import me.jellysquid.mods.sodium.client.model.vertex.type.BlittableVertexType; import me.jellysquid.mods.sodium.client.model.vertex.type.VanillaVertexType; import net.coderbot.iris.vertices.IrisVertexFormats; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.vertex.VertexFormat; public class ExtendedGlyphVertexType implements VanillaVertexType, BlittableVertexType { public static final ExtendedGlyphVertexType INSTANCE = new ExtendedGlyphVertexType(); @Override - public GlyphVertexSink createFallbackWriter(VertexConsumer vertexConsumer) { + public GlyphVertexSink createFallbackWriter(BufferBuilder vertexConsumer) { return new GlyphVertexWriterFallback(vertexConsumer); } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/ExtendedQuadVertexType.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/ExtendedQuadVertexType.java index 87e6335b32..183987e69c 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/ExtendedQuadVertexType.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/ExtendedQuadVertexType.java @@ -1,20 +1,19 @@ package net.coderbot.iris.compat.sodium.impl.vertex_format.entity_xhfp; -import com.mojang.blaze3d.vertex.VertexConsumer; -import com.mojang.blaze3d.vertex.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; import me.jellysquid.mods.sodium.client.model.vertex.type.BlittableVertexType; import me.jellysquid.mods.sodium.client.model.vertex.type.VanillaVertexType; import net.coderbot.iris.vertices.IrisVertexFormats; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.vertex.VertexFormat; public class ExtendedQuadVertexType implements VanillaVertexType, BlittableVertexType { public static final ExtendedQuadVertexType INSTANCE = new ExtendedQuadVertexType(); @Override - public QuadVertexSink createFallbackWriter(VertexConsumer vertexConsumer) { + public QuadVertexSink createFallbackWriter(BufferBuilder vertexConsumer) { return new QuadVertexWriterFallback(vertexConsumer); } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexBufferWriterNio.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexBufferWriterNio.java index 0b84c21705..05280b97a8 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexBufferWriterNio.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexBufferWriterNio.java @@ -10,10 +10,9 @@ import net.coderbot.iris.vendored.joml.Vector3f; import net.coderbot.iris.vertices.IrisVertexFormats; import net.coderbot.iris.vertices.NormalHelper; -import net.minecraft.client.renderer.texture.OverlayTexture; public class GlyphVertexBufferWriterNio extends VertexBufferWriterNio implements QuadVertexSink, GlyphVertexSink { - private static final int STRIDE = IrisVertexFormats.TERRAIN.getVertexSize(); + private static final int STRIDE = IrisVertexFormats.TERRAIN.getSize(); private final QuadViewEntity.QuadViewEntityNio quad = new QuadViewEntity.QuadViewEntityNio(); private final Vector3f saveNormal = new Vector3f(); @@ -52,7 +51,7 @@ public void writeQuad(float x, float y, float z, int color, float u, float v, in @Override public void writeGlyph(float x, float y, float z, int color, float u, float v, int light) { - writeQuad(x, y, z, color, u, v, light, OverlayTexture.NO_OVERLAY, 0); + writeQuad(x, y, z, color, u, v, light, 0, 0); } private void endQuad(int normal) { diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexBufferWriterUnsafe.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexBufferWriterUnsafe.java index 67ffe72653..df00d22f64 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexBufferWriterUnsafe.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/GlyphVertexBufferWriterUnsafe.java @@ -1,5 +1,6 @@ package net.coderbot.iris.compat.sodium.impl.vertex_format.entity_xhfp; +import me.jellysquid.mods.sodium.client.util.CompatMemoryUtil; import org.lwjgl.system.MemoryUtil; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; @@ -13,7 +14,7 @@ import net.minecraft.client.renderer.texture.OverlayTexture; public class GlyphVertexBufferWriterUnsafe extends VertexBufferWriterUnsafe implements QuadVertexSink, GlyphVertexSink { - private static final int STRIDE = IrisVertexFormats.TERRAIN.getVertexSize(); + private static final int STRIDE = IrisVertexFormats.TERRAIN.getSize(); private final QuadViewEntity.QuadViewEntityUnsafe quad = new QuadViewEntity.QuadViewEntityUnsafe(); private final Vector3f saveNormal = new Vector3f(); @@ -34,13 +35,13 @@ public void writeQuad(float x, float y, float z, int color, float u, float v, in uSum += u; vSum += v; - MemoryUtil.memPutFloat(i, x); - MemoryUtil.memPutFloat(i + 4, y); - MemoryUtil.memPutFloat(i + 8, z); - MemoryUtil.memPutInt(i + 12, color); - MemoryUtil.memPutFloat(i + 16, u); - MemoryUtil.memPutFloat(i + 20, v); - MemoryUtil.memPutInt(i + 24, light); + CompatMemoryUtil.memPutFloat(i, x); + CompatMemoryUtil.memPutFloat(i + 4, y); + CompatMemoryUtil.memPutFloat(i + 8, z); + CompatMemoryUtil.memPutInt(i + 12, color); + CompatMemoryUtil.memPutFloat(i + 16, u); + CompatMemoryUtil.memPutFloat(i + 20, v); + CompatMemoryUtil.memPutInt(i + 24, light); if (vertexCount == 4) { this.endQuad(normal); @@ -81,10 +82,10 @@ private void endQuad(int normal) { int tangent = NormalHelper.computeTangent(normalX, normalY, normalZ, quad); for (long vertex = 0; vertex < 4; vertex++) { - MemoryUtil.memPutFloat(i + 36 - STRIDE * vertex, uSum); - MemoryUtil.memPutFloat(i + 40 - STRIDE * vertex, vSum); - MemoryUtil.memPutInt(i + 28 - STRIDE * vertex, normal); - MemoryUtil.memPutInt(i + 44 - STRIDE * vertex, tangent); + CompatMemoryUtil.memPutFloat(i + 36 - STRIDE * vertex, uSum); + CompatMemoryUtil.memPutFloat(i + 40 - STRIDE * vertex, vSum); + CompatMemoryUtil.memPutInt(i + 28 - STRIDE * vertex, normal); + CompatMemoryUtil.memPutInt(i + 44 - STRIDE * vertex, tangent); } uSum = 0; diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/QuadViewEntity.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/QuadViewEntity.java index 5493f5154e..d92fbfd049 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/QuadViewEntity.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/entity_xhfp/QuadViewEntity.java @@ -2,7 +2,7 @@ import java.nio.ByteBuffer; -import org.lwjgl.system.MemoryUtil; +import me.jellysquid.mods.sodium.client.util.CompatMemoryUtil; import net.coderbot.iris.vertices.QuadView; @@ -45,7 +45,7 @@ public void setup(long writePointer, int stride) { @Override float getFloat(long writePointer) { - return MemoryUtil.memGetFloat(writePointer); + return CompatMemoryUtil.memGetFloat(writePointer); } } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/QuadViewTerrain.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/QuadViewTerrain.java index 4adc181ee6..d11e30c393 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/QuadViewTerrain.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/QuadViewTerrain.java @@ -2,7 +2,7 @@ import java.nio.ByteBuffer; -import org.lwjgl.system.MemoryUtil; +import me.jellysquid.mods.sodium.client.util.CompatMemoryUtil; import net.coderbot.iris.vertices.QuadView; @@ -53,7 +53,7 @@ public void setup(long writePointer, int stride) { @Override short getShort(long writePointer) { - return MemoryUtil.memGetShort(writePointer); + return CompatMemoryUtil.memGetShort(writePointer); } } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexBufferWriterUnsafe.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexBufferWriterUnsafe.java index 8ef3f7c57c..0441a395d0 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexBufferWriterUnsafe.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexBufferWriterUnsafe.java @@ -4,13 +4,13 @@ import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferWriterUnsafe; import me.jellysquid.mods.sodium.client.render.chunk.format.ModelVertexSink; import me.jellysquid.mods.sodium.client.render.chunk.format.ModelVertexUtil; +import me.jellysquid.mods.sodium.client.util.CompatMemoryUtil; import net.coderbot.iris.compat.sodium.impl.block_context.BlockContextHolder; import net.coderbot.iris.compat.sodium.impl.block_context.ContextAwareVertexWriter; import net.coderbot.iris.compat.sodium.impl.vertex_format.IrisModelVertexFormats; import net.coderbot.iris.vendored.joml.Vector3f; import net.coderbot.iris.vertices.ExtendedDataHelper; import net.coderbot.iris.vertices.NormalHelper; -import org.lwjgl.system.MemoryUtil; import static net.coderbot.iris.compat.sodium.impl.vertex_format.terrain_xhfp.XHFPModelVertexType.STRIDE; @@ -54,21 +54,21 @@ private void writeQuadInternal(short x, short y, short z, int color, short u, sh vertexCount++; // NB: uSum and vSum must already be incremented outside of this function. - MemoryUtil.memPutShort(i, x); - MemoryUtil.memPutShort(i + 2, y); - MemoryUtil.memPutShort(i + 4, z); - MemoryUtil.memPutInt(i + 8, color); - MemoryUtil.memPutShort(i + 12, u); - MemoryUtil.memPutShort(i + 14, v); - MemoryUtil.memPutShort(i + 16, (short) (light & 0xFFFF)); - MemoryUtil.memPutShort(i + 18, (short) (light >> 16 & 0xFFFF)); + CompatMemoryUtil.memPutShort(i, x); + CompatMemoryUtil.memPutShort(i + 2, y); + CompatMemoryUtil.memPutShort(i + 4, z); + CompatMemoryUtil.memPutInt(i + 8, color); + CompatMemoryUtil.memPutShort(i + 12, u); + CompatMemoryUtil.memPutShort(i + 14, v); + CompatMemoryUtil.memPutShort(i + 16, (short) (light & 0xFFFF)); + CompatMemoryUtil.memPutShort(i + 18, (short) (light >> 16 & 0xFFFF)); // NB: We don't set midTexCoord, normal, and tangent here, they will be filled in later. // block ID: We only set the first 2 values, any legacy shaders using z or w will get filled in based on the GLSL spec // https://www.khronos.org/opengl/wiki/Vertex_Specification#Vertex_format // TODO: can we pack this into one short? - MemoryUtil.memPutShort(i + 36, materialId); - MemoryUtil.memPutShort(i + 38, renderType); - MemoryUtil.memPutInt(i + 40, packedMidBlock); + CompatMemoryUtil.memPutShort(i + 36, materialId); + CompatMemoryUtil.memPutShort(i + 38, renderType); + CompatMemoryUtil.memPutInt(i + 40, packedMidBlock); if (vertexCount == 4) { vertexCount = 0; @@ -103,15 +103,15 @@ private void writeQuadInternal(short x, short y, short z, int color, short u, sh uSum *= 0.25f; vSum *= 0.25f; - MemoryUtil.memPutFloat(i + 20, uSum); - MemoryUtil.memPutFloat(i + 20 - STRIDE, uSum); - MemoryUtil.memPutFloat(i + 20 - STRIDE * 2, uSum); - MemoryUtil.memPutFloat(i + 20 - STRIDE * 3, uSum); + CompatMemoryUtil.memPutFloat(i + 20, uSum); + CompatMemoryUtil.memPutFloat(i + 20 - STRIDE, uSum); + CompatMemoryUtil.memPutFloat(i + 20 - STRIDE * 2, uSum); + CompatMemoryUtil.memPutFloat(i + 20 - STRIDE * 3, uSum); - MemoryUtil.memPutFloat(i + 24, vSum); - MemoryUtil.memPutFloat(i + 24 - STRIDE, vSum); - MemoryUtil.memPutFloat(i + 24 - STRIDE * 2, vSum); - MemoryUtil.memPutFloat(i + 24 - STRIDE * 3, vSum); + CompatMemoryUtil.memPutFloat(i + 24, vSum); + CompatMemoryUtil.memPutFloat(i + 24 - STRIDE, vSum); + CompatMemoryUtil.memPutFloat(i + 24 - STRIDE * 2, vSum); + CompatMemoryUtil.memPutFloat(i + 24 - STRIDE * 3, vSum); uSum = 0; vSum = 0; @@ -124,17 +124,17 @@ private void writeQuadInternal(short x, short y, short z, int color, short u, sh NormalHelper.computeFaceNormal(normal, quad); int packedNormal = NormalHelper.packNormal(normal, 0.0f); - MemoryUtil.memPutInt(i + 32, packedNormal); - MemoryUtil.memPutInt(i + 32 - STRIDE, packedNormal); - MemoryUtil.memPutInt(i + 32 - STRIDE * 2, packedNormal); - MemoryUtil.memPutInt(i + 32 - STRIDE * 3, packedNormal); + CompatMemoryUtil.memPutInt(i + 32, packedNormal); + CompatMemoryUtil.memPutInt(i + 32 - STRIDE, packedNormal); + CompatMemoryUtil.memPutInt(i + 32 - STRIDE * 2, packedNormal); + CompatMemoryUtil.memPutInt(i + 32 - STRIDE * 3, packedNormal); int tangent = NormalHelper.computeTangent(normal.x, normal.y, normal.z, quad); - MemoryUtil.memPutInt(i + 28, tangent); - MemoryUtil.memPutInt(i + 28 - STRIDE, tangent); - MemoryUtil.memPutInt(i + 28 - STRIDE * 2, tangent); - MemoryUtil.memPutInt(i + 28 - STRIDE * 3, tangent); + CompatMemoryUtil.memPutInt(i + 28, tangent); + CompatMemoryUtil.memPutInt(i + 28 - STRIDE, tangent); + CompatMemoryUtil.memPutInt(i + 28 - STRIDE * 2, tangent); + CompatMemoryUtil.memPutInt(i + 28 - STRIDE * 3, tangent); } this.advance(); diff --git a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java index d7f08b86e6..4261106428 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java @@ -1,7 +1,5 @@ package net.coderbot.iris.compat.sodium.impl.vertex_format.terrain_xhfp; -import com.mojang.blaze3d.vertex.VertexConsumer; - import me.jellysquid.mods.sodium.client.gl.attribute.GlVertexAttributeFormat; import me.jellysquid.mods.sodium.client.gl.attribute.GlVertexFormat; import me.jellysquid.mods.sodium.client.model.vertex.buffer.VertexBufferView; @@ -11,6 +9,7 @@ import me.jellysquid.mods.sodium.client.render.chunk.format.ModelVertexSink; import net.coderbot.iris.compat.sodium.impl.vertex_format.IrisChunkMeshAttributes; import net.coderbot.iris.compat.sodium.impl.vertex_format.IrisGlVertexAttributeFormat; +import net.minecraft.client.renderer.BufferBuilder; /** * Like HFPModelVertexType, but extended to support Iris. The extensions aren't particularly efficient right now. @@ -33,7 +32,7 @@ public class XHFPModelVertexType implements ChunkVertexType { public static final float TEXTURE_SCALE = (1.0f / 32768.0f); @Override - public ModelVertexSink createFallbackWriter(VertexConsumer consumer) { + public ModelVertexSink createFallbackWriter(BufferBuilder consumer) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/IrisSodiumCompatMixinPlugin.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/IrisSodiumCompatMixinPlugin.java index 07df2aceb8..28b5a5e412 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/IrisSodiumCompatMixinPlugin.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/IrisSodiumCompatMixinPlugin.java @@ -3,12 +3,11 @@ import java.util.List; import java.util.Set; +import net.minecraftforge.fml.common.Loader; import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; -import net.minecraftforge.fml.loading.FMLLoader; - /** * Semi-critical mixin config plugin, disables mixins if Sodium isn't present, * since on 1.18+ we have mixins into Iris classes that crash the game instead of just @@ -16,11 +15,11 @@ */ public class IrisSodiumCompatMixinPlugin implements IMixinConfigPlugin { - public static boolean isRubidiumLoaded; + public static boolean isVintagiumLoaded; @Override public void onLoad(String mixinPackage) { - isRubidiumLoaded = FMLLoader.getLoadingModList().getModFileById("rubidium") != null; + isVintagiumLoaded = Loader.isModLoaded("vintagium"); } @Override @@ -30,7 +29,7 @@ public String getRefMapperConfig() { @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return isRubidiumLoaded; + return isVintagiumLoaded; } @Override diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkBuildBuffers.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkBuildBuffers.java index ce073dcefe..67c8829dae 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkBuildBuffers.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkBuildBuffers.java @@ -1,5 +1,6 @@ package net.coderbot.iris.compat.sodium.mixin.block_id; +import net.minecraft.block.state.IBlockState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -17,7 +18,6 @@ import net.coderbot.iris.compat.sodium.impl.block_context.BlockContextHolder; import net.coderbot.iris.compat.sodium.impl.block_context.ChunkBuildBuffersExt; import net.coderbot.iris.compat.sodium.impl.block_context.ContextAwareVertexWriter; -import net.minecraft.world.level.block.state.BlockState; /** * Associates the block context holder with the chunk build buffers, allowing {@link MixinChunkRenderRebuildTask} to pass @@ -30,7 +30,7 @@ public class MixinChunkBuildBuffers implements ChunkBuildBuffersExt { @Inject(method = "", at = @At("RETURN"), remap = false) private void iris$onConstruct(ChunkVertexType vertexType, BlockRenderPassManager renderPassManager, CallbackInfo ci) { - Object2IntMap blockStateIds = BlockRenderingSettings.INSTANCE.getBlockStateIds(); + Object2IntMap blockStateIds = BlockRenderingSettings.INSTANCE.getBlockStateIds(); if (blockStateIds != null) { this.contextHolder = new BlockContextHolder(blockStateIds); @@ -61,7 +61,7 @@ public class MixinChunkBuildBuffers implements ChunkBuildBuffersExt { } @Override - public void iris$setMaterialId(BlockState state, short renderType) { + public void iris$setMaterialId(IBlockState state, short renderType) { this.contextHolder.set(state, renderType); } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkRenderRebuildTask.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkRenderRebuildTask.java index 19d74de28e..ef0a853534 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkRenderRebuildTask.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkRenderRebuildTask.java @@ -3,9 +3,11 @@ import me.jellysquid.mods.sodium.client.render.chunk.compile.buffers.ChunkModelBuffers; import me.jellysquid.mods.sodium.client.render.pipeline.FluidRenderer; import net.coderbot.iris.vertices.ExtendedDataHelper; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.FluidState; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.BlockModelShapes; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -23,7 +25,6 @@ import me.jellysquid.mods.sodium.client.world.WorldSlice; import net.coderbot.iris.compat.sodium.impl.block_context.ChunkBuildBuffersExt; import net.minecraft.client.renderer.chunk.VisGraph; -import net.minecraft.core.BlockPos; /** * Passes additional information indirectly to the vertex writer to support the mc_Entity and at_midBlock parts of the vertex format. @@ -31,8 +32,7 @@ @Mixin(ChunkRenderRebuildTask.class) public class MixinChunkRenderRebuildTask { @Inject(method = "performBuild", at = @At(value = "INVOKE", - target = "net/minecraft/world/level/block/state/BlockState.getRenderShape()" + - "Lnet/minecraft/world/level/block/RenderShape;"), + target = "Lme/jellysquid/mods/sodium/common/util/WorldUtil;toFluidBlock(Lnet/minecraft/block/Block;)Lnet/minecraftforge/fluids/IFluidBlock;", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD) private void iris$setLocalPos(ChunkRenderCacheLocal cache, ChunkBuildBuffers buffers, CancellationSource cancellationSource, CallbackInfoReturnable> cir, @@ -46,27 +46,27 @@ public class MixinChunkRenderRebuildTask { } @Redirect(method = "performBuild", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/level/block/state/BlockState;getSeed(Lnet/minecraft/core/BlockPos;)J")) - private long iris$wrapGetBlockLayer(BlockState blockState, BlockPos pos, ChunkRenderCacheLocal cache, ChunkBuildBuffers buffers) { + target = "Lnet/minecraft/client/renderer/BlockModelShapes;getModelForState(Lnet/minecraft/block/state/IBlockState;)Lnet/minecraft/client/renderer/block/model/IBakedModel;")) + private IBakedModel iris$wrapGetBlockLayer(BlockModelShapes instance, IBlockState blockState, ChunkRenderCacheLocal cache, ChunkBuildBuffers buffers) { if (buffers instanceof ChunkBuildBuffersExt) { ((ChunkBuildBuffersExt) buffers).iris$setMaterialId(blockState, ExtendedDataHelper.BLOCK_RENDER_TYPE); } - return blockState.getSeed(pos); + return instance.getModelForState(blockState); } @Redirect(method = "performBuild", at = @At(value = "INVOKE", - target = "Lme/jellysquid/mods/sodium/client/render/pipeline/FluidRenderer;render(Lnet/minecraft/world/level/BlockAndTintGetter;Lnet/minecraft/world/level/material/FluidState;Lnet/minecraft/core/BlockPos;Lme/jellysquid/mods/sodium/client/render/chunk/compile/buffers/ChunkModelBuffers;)Z")) - private boolean iris$wrapGetFluidLayer(FluidRenderer renderer, BlockAndTintGetter world, FluidState fluidState, BlockPos pos, ChunkModelBuffers modelBuffers, ChunkRenderCacheLocal cache, ChunkBuildBuffers buffers) { + target = "Lme/jellysquid/mods/sodium/client/render/pipeline/FluidRenderer;render(Lnet/minecraft/world/IBlockAccess;Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/util/math/BlockPos;Lme/jellysquid/mods/sodium/client/render/chunk/compile/buffers/ChunkModelBuffers;)Z")) + private boolean iris$wrapGetFluidLayer(FluidRenderer renderer, IBlockAccess world, IBlockState fluidState, BlockPos pos, ChunkModelBuffers modelBuffers, ChunkRenderCacheLocal cache, ChunkBuildBuffers buffers) { if (buffers instanceof ChunkBuildBuffersExt) { - ((ChunkBuildBuffersExt) buffers).iris$setMaterialId(fluidState.createLegacyBlock(), ExtendedDataHelper.FLUID_RENDER_TYPE); + ((ChunkBuildBuffersExt) buffers).iris$setMaterialId(fluidState, ExtendedDataHelper.FLUID_RENDER_TYPE); } return renderer.render(world, fluidState, pos, modelBuffers); } @Inject(method = "performBuild", - at = @At(value = "INVOKE", target = "net/minecraft/world/level/block/state/BlockState.hasTileEntity()Z")) + at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;hasTileEntity(Lnet/minecraft/block/state/IBlockState;)Z")) private void iris$resetContext(ChunkRenderCacheLocal cache, ChunkBuildBuffers buffers, CancellationSource cancellationSource, CallbackInfoReturnable> cir) { if (buffers instanceof ChunkBuildBuffersExt) { diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/directional_shading/MixinFlatLightPipeline.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/directional_shading/MixinFlatLightPipeline.java index 570868b5e3..cf2ea1b4cc 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/directional_shading/MixinFlatLightPipeline.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/directional_shading/MixinFlatLightPipeline.java @@ -1,23 +1,23 @@ package net.coderbot.iris.compat.sodium.mixin.directional_shading; +import me.jellysquid.mods.sodium.client.world.WorldSlice; +import net.minecraft.util.EnumFacing; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; import me.jellysquid.mods.sodium.client.model.light.flat.FlatLightPipeline; import net.coderbot.iris.block_rendering.BlockRenderingSettings; -import net.minecraft.core.Direction; -import net.minecraft.world.level.BlockAndTintGetter; @Mixin(FlatLightPipeline.class) public class MixinFlatLightPipeline { @Redirect(method = "calculate", at = @At(value = "INVOKE", - target = "net/minecraft/world/level/BlockAndTintGetter.getShade (Lnet/minecraft/core/Direction;Z)F")) - private float iris$getBrightness(BlockAndTintGetter level, Direction direction, boolean shaded) { + target = "Lme/jellysquid/mods/sodium/client/world/WorldSlice;getBrightness(Lnet/minecraft/util/EnumFacing;Z)F")) + private float iris$getBrightness(WorldSlice level, EnumFacing direction, boolean shaded) { if (BlockRenderingSettings.INSTANCE.shouldDisableDirectionalShading()) { return 1.0F; } else { - return level.getShade(direction, shaded); + return level.getBrightness(direction, shaded); } } } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/directional_shading/MixinSmoothLightPipeline.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/directional_shading/MixinSmoothLightPipeline.java index 34c67ecd61..c3e140f42f 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/directional_shading/MixinSmoothLightPipeline.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/directional_shading/MixinSmoothLightPipeline.java @@ -1,5 +1,6 @@ package net.coderbot.iris.compat.sodium.mixin.directional_shading; +import net.minecraft.util.EnumFacing; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -8,12 +9,11 @@ import me.jellysquid.mods.sodium.client.model.light.data.QuadLightData; import me.jellysquid.mods.sodium.client.model.light.smooth.SmoothLightPipeline; import net.coderbot.iris.block_rendering.BlockRenderingSettings; -import net.minecraft.core.Direction; @Mixin(SmoothLightPipeline.class) public class MixinSmoothLightPipeline { @Inject(method = "applySidedBrightness", at = @At("HEAD"), cancellable = true, remap = false) - private void iris$disableDirectionalShading(QuadLightData out, Direction face, boolean shade, CallbackInfo ci) { + private void iris$disableDirectionalShading(QuadLightData out, EnumFacing face, boolean shade, CallbackInfo ci) { if (BlockRenderingSettings.INSTANCE.shouldDisableDirectionalShading()) { ci.cancel(); } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumGameOptionPages.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumGameOptionPages.java index f3b6b16f14..586dbca009 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumGameOptionPages.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumGameOptionPages.java @@ -1,22 +1,17 @@ package net.coderbot.iris.compat.sodium.mixin.options; +import me.jellysquid.mods.sodium.client.gui.SodiumGameOptionPages; +import me.jellysquid.mods.sodium.client.gui.options.Option; +import me.jellysquid.mods.sodium.client.gui.options.OptionGroup; +import me.jellysquid.mods.sodium.client.gui.options.storage.MinecraftOptionsStorage; +import net.coderbot.iris.compat.sodium.impl.options.IrisSodiumOptions; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Slice; -import com.mojang.blaze3d.platform.GlStateManager; - -import me.jellysquid.mods.sodium.client.gui.SodiumGameOptionPages; -import me.jellysquid.mods.sodium.client.gui.options.Option; -import me.jellysquid.mods.sodium.client.gui.options.OptionGroup; -import me.jellysquid.mods.sodium.client.gui.options.storage.MinecraftOptionsStorage; -import net.coderbot.iris.Iris; -import net.coderbot.iris.compat.sodium.impl.options.IrisSodiumOptions; - /** * Adds the Iris-specific options / option changes to the Sodium game options pages. */ @@ -44,22 +39,4 @@ public class MixinSodiumGameOptionPages { return builder; } - - @ModifyArg(method = "quality", remap = false, - slice = @Slice( - from = @At(value = "CONSTANT", args = "stringValue=options.graphics"), - to = @At(value = "CONSTANT", args = "stringValue=options.renderClouds") - ), - at = @At(value = "INVOKE", remap = false, - target = "me/jellysquid/mods/sodium/client/gui/options/OptionGroup$Builder.add (" + - "Lme/jellysquid/mods/sodium/client/gui/options/Option;" + - ")Lme/jellysquid/mods/sodium/client/gui/options/OptionGroup$Builder;"), - allow = 1) - private static Option iris$replaceGraphicsQualityButton(Option candidate) { - if (!Iris.getIrisConfig().areShadersEnabled() && GlStateManager.supportsFramebufferBlit()) { - return candidate; - } else { - return IrisSodiumOptions.createLimitedVideoSettingsButton(vanillaOpts); - } - } } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumOptionsGUI.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumOptionsGUI.java index 11bc99642c..ba2fc4ffbd 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumOptionsGUI.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/options/MixinSodiumOptionsGUI.java @@ -2,6 +2,8 @@ import java.util.List; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.util.text.TextComponentTranslation; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -15,15 +17,12 @@ import me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI; import me.jellysquid.mods.sodium.client.gui.options.OptionPage; import net.coderbot.iris.gui.screen.ShaderPackScreen; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TranslatableComponent; /** * Adds our Shader Packs button to the Sodium options GUI. */ @Mixin(SodiumOptionsGUI.class) -public class MixinSodiumOptionsGUI extends Screen { +public class MixinSodiumOptionsGUI extends GuiScreen { @Shadow(remap = false) @Final private List pages; @@ -31,21 +30,16 @@ public class MixinSodiumOptionsGUI extends Screen { @Unique private OptionPage shaderPacks; - // make compiler happy - protected MixinSodiumOptionsGUI(Component title) { - super(title); - } - @Inject(method = "", at = @At("RETURN")) - private void iris$onInit(Screen prevScreen, CallbackInfo ci) { - shaderPacks = new OptionPage(new TranslatableComponent("options.iris.shaderPackSelection"), ImmutableList.of()); + private void iris$onInit(GuiScreen prevScreen, CallbackInfo ci) { + shaderPacks = new OptionPage(new TextComponentTranslation("options.iris.shaderPackSelection"), ImmutableList.of()); pages.add(shaderPacks); } @Inject(method = "setPage", at = @At("HEAD"), remap = false, cancellable = true) private void iris$onSetPage(OptionPage page, CallbackInfo ci) { if (page == shaderPacks) { - minecraft.setScreen(new ShaderPackScreen(this)); + mc.displayGuiScreen(new ShaderPackScreen(this)); ci.cancel(); } } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/pbr_animation/MixinTextureAtlasSprite.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/pbr_animation/MixinTextureAtlasSprite.java index 2e24051e7b..4b6f8d4b15 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/pbr_animation/MixinTextureAtlasSprite.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/pbr_animation/MixinTextureAtlasSprite.java @@ -10,10 +10,11 @@ import net.coderbot.iris.texture.pbr.TextureAtlasSpriteExtension; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +// Took from CensoredASM, not sure @Mixin(TextureAtlasSprite.class) public class MixinTextureAtlasSprite { - @Inject(method = "markActive()V", at = @At("TAIL"), remap = false) - private void iris$onTailMarkActive(CallbackInfo ci) { + @Inject(method = "setActive(Z)V", at = @At("TAIL"), remap = false) + private void iris$onTailMarkActive(boolean active, CallbackInfo ci) { PBRSpriteHolder pbrHolder = ((TextureAtlasSpriteExtension) this).getPBRHolder(); if (pbrHolder != null) { TextureAtlasSprite normalSprite = pbrHolder.getNormalSprite(); diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinBlockRenderer.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinBlockRenderer.java index ee8aa8c948..f3287e29c7 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinBlockRenderer.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinBlockRenderer.java @@ -1,5 +1,13 @@ package net.coderbot.iris.compat.sodium.mixin.separate_ao; +import me.jellysquid.mods.sodium.client.render.chunk.compile.buffers.ChunkModelBuffers; +import me.jellysquid.mods.sodium.client.render.pipeline.BlockRenderer; +import me.jellysquid.mods.sodium.client.util.color.ColorABGR; +import net.coderbot.iris.block_rendering.BlockRenderingSettings; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -7,16 +15,6 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import me.jellysquid.mods.sodium.client.render.chunk.compile.buffers.ChunkModelBuffers; -import me.jellysquid.mods.sodium.client.render.pipeline.BlockRenderer; -import me.jellysquid.mods.sodium.client.util.color.ColorABGR; -import net.coderbot.iris.block_rendering.BlockRenderingSettings; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.client.model.data.IModelData; - /** * Allows vertex AO to be optionally passed in the alpha channel of the vertex color instead of being multiplied * through into the RGB values. @@ -27,8 +25,7 @@ public class MixinBlockRenderer { private boolean useSeparateAo; @Inject(method = "renderModel", remap = false, at = @At("HEAD")) - private void renderModel(BlockAndTintGetter level, BlockState state, BlockPos pos, BakedModel model, - ChunkModelBuffers buffers, boolean cull, long seed, IModelData modelData, CallbackInfoReturnable cir) { + private void renderModel(IBlockAccess world, IBlockState state, BlockPos pos, IBakedModel model, ChunkModelBuffers buffers, boolean cull, long seed, CallbackInfoReturnable cir) { this.useSeparateAo = BlockRenderingSettings.INSTANCE.shouldUseSeparateAo(); } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinBufferBuilder_IntrinsicSeparateAo.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinBufferBuilder_IntrinsicSeparateAo.java index 502bc1d64f..dc6c5ac657 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinBufferBuilder_IntrinsicSeparateAo.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinBufferBuilder_IntrinsicSeparateAo.java @@ -14,6 +14,7 @@ import me.jellysquid.mods.sodium.client.util.color.ColorU8; import me.jellysquid.mods.sodium.client.util.math.MatrixUtil; import net.coderbot.iris.block_rendering.BlockRenderingSettings; +import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.block.model.BakedQuad; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinFluidRenderer.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinFluidRenderer.java index 5fc0073442..de50731983 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinFluidRenderer.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinFluidRenderer.java @@ -1,5 +1,12 @@ package net.coderbot.iris.compat.sodium.mixin.separate_ao; +import me.jellysquid.mods.sodium.client.render.chunk.compile.buffers.ChunkModelBuffers; +import me.jellysquid.mods.sodium.client.render.pipeline.FluidRenderer; +import me.jellysquid.mods.sodium.client.util.color.ColorABGR; +import net.coderbot.iris.block_rendering.BlockRenderingSettings; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -7,14 +14,6 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import me.jellysquid.mods.sodium.client.render.chunk.compile.buffers.ChunkModelBuffers; -import me.jellysquid.mods.sodium.client.render.pipeline.FluidRenderer; -import me.jellysquid.mods.sodium.client.util.color.ColorABGR; -import net.coderbot.iris.block_rendering.BlockRenderingSettings; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.level.material.FluidState; - /** * Basically the same as {@link MixinBlockRenderer}, but for fluid rendering. */ @@ -24,8 +23,7 @@ public class MixinFluidRenderer { private boolean useSeparateAo; @Inject(method = "render", remap = false, at = @At("HEAD")) - private void iris$cacheSeparateAoSetting(BlockAndTintGetter level, FluidState fluidState, BlockPos pos, - ChunkModelBuffers buffers, CallbackInfoReturnable cir) { + private void iris$cacheSeparateAoSetting(IBlockAccess world, IBlockState fluidState, BlockPos pos, ChunkModelBuffers buffers, CallbackInfoReturnable cir) { this.useSeparateAo = BlockRenderingSettings.INSTANCE.shouldUseSeparateAo(); } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkProgram.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkProgram.java index ee62ade918..9997a9c5d6 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkProgram.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkProgram.java @@ -15,7 +15,7 @@ @Mixin(ChunkProgram.class) public class MixinChunkProgram { @Redirect(method = "setup", remap = false, - at = @At(value = "INVOKE", target = "com/mojang/blaze3d/platform/GlStateManager.func_227718_f_ (II)V", remap = false)) + at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL20;glUniform1i(II)V", remap = false)) private void iris$redirectUniform1i(int location, int value) { if (location == -1) { return; @@ -25,7 +25,7 @@ public class MixinChunkProgram { } @Redirect(method = "setup", remap = false, - at = @At(value = "INVOKE", target = "org/lwjgl/opengl/GL20C.glUniform3f (IFFF)V", remap = false)) + at = @At(value = "INVOKE", target = "org/lwjgl/opengl/GL20.glUniform3f (IFFF)V", remap = false)) private void iris$redirectUniform3f(int location, float v1, float v2, float v3) { if (location == -1) { return; @@ -35,7 +35,7 @@ public class MixinChunkProgram { } @Redirect(method = "setup", remap = false, - at = @At(value = "INVOKE", target = "org/lwjgl/opengl/GL20C.glUniform2f (IFF)V", remap = false)) + at = @At(value = "INVOKE", target = "org/lwjgl/opengl/GL20.glUniform2f (IFF)V", remap = false)) private void iris$redirectUniform2f(int location, float v1, float v2) { if (location == -1) { return; @@ -46,7 +46,7 @@ public class MixinChunkProgram { @Redirect(method = "setup", remap = false, at = @At(value = "INVOKE", - target = "com/mojang/blaze3d/platform/GlStateManager.func_227698_c_ (IZLjava/nio/FloatBuffer;)V", + target = "Lorg/lwjgl/opengl/GL20;glUniformMatrix4(IZLjava/nio/FloatBuffer;)V", remap = false)) private void iris$redirectUniformMatrix4fv(int location, boolean transpose, FloatBuffer buffer) { if (location == -1) { diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkRenderManager.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkRenderManager.java index efcba1bdd0..41466e82a7 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkRenderManager.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkRenderManager.java @@ -4,8 +4,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import com.mojang.blaze3d.vertex.PoseStack; - import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderBackend; import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderManager; import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass; @@ -15,15 +13,12 @@ public class MixinChunkRenderManager { @Redirect(method = "renderLayer", at = @At(value = "INVOKE", - target = "me/jellysquid/mods/sodium/client/render/chunk/ChunkRenderBackend.begin (" + - "Lcom/mojang/blaze3d/vertex/PoseStack;" + - ")V")) - private void iris$backendBeginExt(ChunkRenderBackend backend, PoseStack poseStack, - PoseStack poseStackArg, BlockRenderPass pass, double x, double y, double z) { + target = "me/jellysquid/mods/sodium/client/render/chunk/ChunkRenderBackend.begin ()V")) + private void iris$backendBeginExt(ChunkRenderBackend backend, BlockRenderPass pass, double x, double y, double z) { if (backend instanceof ChunkRenderBackendExt) { - ((ChunkRenderBackendExt) backend).iris$begin(poseStack, pass); + ((ChunkRenderBackendExt) backend).iris$begin(pass); } else { - backend.begin(poseStack); + backend.begin(); } } } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkRenderShaderBackend.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkRenderShaderBackend.java index 43d19ef689..4e42f00abd 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkRenderShaderBackend.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinChunkRenderShaderBackend.java @@ -1,27 +1,10 @@ package net.coderbot.iris.compat.sodium.mixin.shader_overrides; +import me.jellysquid.mods.sodium.client.gl.device.RenderDevice; import me.jellysquid.mods.sodium.client.gl.shader.GlShader; import me.jellysquid.mods.sodium.client.gl.shader.ShaderConstants; import me.jellysquid.mods.sodium.client.gl.shader.ShaderLoader; import me.jellysquid.mods.sodium.client.gl.shader.ShaderType; -import net.coderbot.iris.compat.sodium.impl.vertex_format.IrisModelVertexFormats; -import net.coderbot.iris.shaderpack.transform.StringTransformations; -import net.coderbot.iris.shaderpack.transform.Transformations; -import net.minecraft.resources.ResourceLocation; -import org.apache.commons.io.IOUtils; -import org.spongepowered.asm.mixin.Final; -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.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; - -import me.jellysquid.mods.sodium.client.gl.device.RenderDevice; import me.jellysquid.mods.sodium.client.model.vertex.type.ChunkVertexType; import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass; import me.jellysquid.mods.sodium.client.render.chunk.shader.ChunkProgram; @@ -29,11 +12,25 @@ import net.coderbot.iris.Iris; import net.coderbot.iris.compat.sodium.impl.shader_overrides.ChunkRenderBackendExt; import net.coderbot.iris.compat.sodium.impl.shader_overrides.IrisChunkProgramOverrides; +import net.coderbot.iris.compat.sodium.impl.vertex_format.IrisModelVertexFormats; import net.coderbot.iris.gl.program.ProgramSamplers; import net.coderbot.iris.gl.program.ProgramUniforms; import net.coderbot.iris.pipeline.SodiumTerrainPipeline; import net.coderbot.iris.pipeline.WorldRenderingPipeline; +import net.coderbot.iris.shaderpack.transform.StringTransformations; +import net.coderbot.iris.shaderpack.transform.Transformations; import net.coderbot.iris.shadows.ShadowRenderingState; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; +import org.apache.commons.io.IOUtils; +import org.spongepowered.asm.mixin.Final; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.io.IOException; import java.io.InputStream; @@ -58,7 +55,7 @@ public class MixinChunkRenderShaderBackend implements ChunkRenderBackendExt { protected ChunkProgram activeProgram; @Shadow - public void begin(PoseStack poseStack) { + public void begin() { throw new AssertionError(); } @@ -71,7 +68,7 @@ public void begin(PoseStack poseStack) { irisChunkProgramOverrides = new IrisChunkProgramOverrides(); } - @Redirect(method = "createShader", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/gl/shader/ShaderLoader;loadShader(Lme/jellysquid/mods/sodium/client/gl/device/RenderDevice;Lme/jellysquid/mods/sodium/client/gl/shader/ShaderType;Lnet/minecraft/resources/ResourceLocation;Ljava/util/List;)Lme/jellysquid/mods/sodium/client/gl/shader/GlShader;", ordinal = 0)) + @Redirect(method = "createShader", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/gl/shader/ShaderLoader;loadShader(Lme/jellysquid/mods/sodium/client/gl/device/RenderDevice;Lme/jellysquid/mods/sodium/client/gl/shader/ShaderType;Lnet/minecraft/util/ResourceLocation;Ljava/util/List;)Lme/jellysquid/mods/sodium/client/gl/shader/GlShader;", ordinal = 0)) private GlShader iris$redirectOriginalShader(RenderDevice device, ShaderType type, ResourceLocation name, List constants) { if (this.vertexType == IrisModelVertexFormats.MODEL_VERTEX_XHFP) { String shader = getShaderSource(getShaderPath(name)); @@ -142,17 +139,17 @@ private static String getShaderSource(String path) { } @Override - public void iris$begin(PoseStack poseStack, BlockRenderPass pass) { + public void iris$begin(BlockRenderPass pass) { if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) { // No back face culling during the shadow pass // TODO: Hopefully this won't be necessary in the future... - RenderSystem.disableCull(); + GlStateManager.disableCull(); } this.override = irisChunkProgramOverrides.getProgramOverride(device, pass); Iris.getPipelineManager().getPipeline().ifPresent(WorldRenderingPipeline::beginSodiumTerrainRendering); - begin(poseStack); + begin(); } @Inject(method = "begin", @@ -162,14 +159,14 @@ private static String getShaderSource(String path) { args = "opcode=PUTFIELD", remap = false, shift = At.Shift.AFTER)) - private void iris$applyOverride(PoseStack poseStack, CallbackInfo ci) { + private void iris$applyOverride(CallbackInfo ci) { if (override != null) { this.activeProgram = override; } } @Inject(method = "end", at = @At("RETURN")) - private void iris$onEnd(PoseStack poseStack, CallbackInfo ci) { + private void iris$onEnd(CallbackInfo ci) { ProgramUniforms.clearActiveUniforms(); ProgramSamplers.clearActiveSamplers(); Iris.getPipelineManager().getPipeline().ifPresent(WorldRenderingPipeline::endSodiumTerrainRendering); diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinShaderType.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinShaderType.java index 0f6b81909a..dffbd61238 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinShaderType.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinShaderType.java @@ -1,7 +1,7 @@ package net.coderbot.iris.compat.sodium.mixin.shader_overrides; import org.apache.commons.lang3.ArrayUtils; -import org.lwjgl.opengl.GL32C; +import org.lwjgl.opengl.GL32; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -22,7 +22,7 @@ public class MixinShaderType { int baseOrdinal = $VALUES.length; IrisShaderTypes.GEOMETRY - = ShaderTypeAccessor.createShaderType("GEOMETRY", baseOrdinal, GL32C.GL_GEOMETRY_SHADER); + = ShaderTypeAccessor.createShaderType("GEOMETRY", baseOrdinal, GL32.GL_GEOMETRY_SHADER); $VALUES = ArrayUtils.addAll($VALUES, IrisShaderTypes.GEOMETRY); } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/shadow_map/MixinChunkRenderManager.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/shadow_map/MixinChunkRenderManager.java index a7d86df12e..384f198dad 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/shadow_map/MixinChunkRenderManager.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/shadow_map/MixinChunkRenderManager.java @@ -1,5 +1,7 @@ package net.coderbot.iris.compat.sodium.mixin.shadow_map; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.tileentity.TileEntity; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -24,8 +26,6 @@ import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPassManager; import net.coderbot.iris.compat.sodium.impl.shadow_map.SwappableChunkRenderManager; import net.coderbot.iris.shadows.ShadowRenderingState; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.world.level.block.entity.BlockEntity; /** * Modifies {@link ChunkRenderManager} to support maintaining a separate visibility list for the shadow camera, as well @@ -54,7 +54,7 @@ public class MixinChunkRenderManager implements SwappableChunkRenderManager { @Shadow(remap = false) @Final @Mutable - private ObjectList visibleBlockEntities; + private ObjectList visibleBlockEntities; @Shadow(remap = false) private boolean dirty; @@ -69,7 +69,7 @@ public class MixinChunkRenderManager implements SwappableChunkRenderManager { private ObjectList> tickableChunksSwap; @Unique - private ObjectList visibleBlockEntitiesSwap; + private ObjectList visibleBlockEntitiesSwap; @Unique private int visibleChunkCountSwap; @@ -82,7 +82,7 @@ public class MixinChunkRenderManager implements SwappableChunkRenderManager { @Inject(method = "", at = @At("RETURN")) private void iris$onInit(SodiumWorldRenderer renderer, ChunkRenderBackend backend, - BlockRenderPassManager renderPassManager, ClientLevel level, int renderDistance, + BlockRenderPassManager renderPassManager, WorldClient level, int renderDistance, CallbackInfo ci) { this.chunkRenderListsSwap = new ChunkRenderList[BlockRenderPass.COUNT]; this.tickableChunksSwap = new ObjectArrayList<>(); @@ -105,7 +105,7 @@ public class MixinChunkRenderManager implements SwappableChunkRenderManager { tickableChunks = tickableChunksSwap; tickableChunksSwap = tickableChunksTmp; - ObjectList visibleBlockEntitiesTmp = visibleBlockEntities; + ObjectList visibleBlockEntitiesTmp = visibleBlockEntities; visibleBlockEntities = visibleBlockEntitiesSwap; visibleBlockEntitiesSwap = visibleBlockEntitiesTmp; diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/shadow_map/MixinSodiumWorldRenderer.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/shadow_map/MixinSodiumWorldRenderer.java index 3dd1b2a46e..86d0840b05 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/shadow_map/MixinSodiumWorldRenderer.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/shadow_map/MixinSodiumWorldRenderer.java @@ -1,5 +1,12 @@ package net.coderbot.iris.compat.sodium.mixin.shadow_map; +import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer; +import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderManager; +import net.coderbot.iris.compat.sodium.impl.shadow_map.SwappableChunkRenderManager; +import net.coderbot.iris.pipeline.ShadowRenderer; +import net.coderbot.iris.shadows.ShadowRenderingState; +import net.minecraft.client.renderer.culling.Frustum; +import net.minecraft.util.BlockRenderLayer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -8,17 +15,6 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.vertex.PoseStack; - -import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer; -import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderManager; -import net.coderbot.iris.compat.sodium.impl.shadow_map.SwappableChunkRenderManager; -import net.coderbot.iris.pipeline.ShadowRenderer; -import net.coderbot.iris.shadows.ShadowRenderingState; -import net.minecraft.client.Camera; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.culling.Frustum; - /** * Ensures that the state of the chunk render visibility graph gets properly swapped when in the shadow map pass, * because we must maintain one visibility graph for the shadow camera and one visibility graph for the player camera. @@ -86,7 +82,7 @@ private void swapCachedCameraPositions() { } @Inject(method = "updateChunks", at = @At("RETURN")) - private void iris$captureVisibleBlockEntities(Camera camera, Frustum frustum, boolean hasForcedFrustum, int frame, boolean spectator, CallbackInfo ci) { + private void iris$captureVisibleBlockEntities(Frustum frustum, float ticks, boolean hasForcedFrustum, int frame, boolean spectator, CallbackInfo ci) { if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) { ShadowRenderer.visibleBlockEntities.addAll(this.chunkRenderManager.getVisibleBlockEntities()); } @@ -107,8 +103,7 @@ private void swapCachedCameraPositions() { target = "me/jellysquid/mods/sodium/client/render/SodiumWorldRenderer.lastCameraX : D", ordinal = 0, remap = false)) - private void iris$ensureStateSwappedInUpdateChunks(Camera camera, Frustum frustum, boolean hasForcedFrustum, - int frame, boolean spectator, CallbackInfo ci) { + private void iris$ensureStateSwappedInUpdateChunks(Frustum frustum, float ticks, boolean hasForcedFrustum, int frame, boolean spectator, CallbackInfo ci) { iris$ensureStateSwapped(); } @@ -131,8 +126,7 @@ private void swapCachedCameraPositions() { } @Inject(method = "drawChunkLayer", remap = false, at = @At("HEAD")) - private void iris$beforeDrawChunkLayer(RenderType renderType, PoseStack poseStack, double x, double y, - double z, CallbackInfo ci) { + private void iris$beforeDrawChunkLayer(BlockRenderLayer renderLayer, double x, double y, double z, CallbackInfo ci) { iris$ensureStateSwapped(); } } diff --git a/src/main/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinBufferBuilder_ExtendedVertexFormatCompat.java b/src/main/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinBufferBuilder_ExtendedVertexFormatCompat.java index 12a6912fe6..6c6499769c 100644 --- a/src/main/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinBufferBuilder_ExtendedVertexFormatCompat.java +++ b/src/main/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/entity/MixinBufferBuilder_ExtendedVertexFormatCompat.java @@ -1,13 +1,12 @@ package net.coderbot.iris.compat.sodium.mixin.vertex_format.entity; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.vertex.VertexFormat; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.VertexFormat; - import me.jellysquid.mods.sodium.client.model.vertex.VanillaVertexTypes; import me.jellysquid.mods.sodium.client.model.vertex.type.VertexType; import net.coderbot.iris.compat.sodium.impl.vertex_format.entity_xhfp.ExtendedGlyphVertexType; @@ -22,17 +21,17 @@ @Mixin(value = BufferBuilder.class, priority = 1010) public class MixinBufferBuilder_ExtendedVertexFormatCompat { @Shadow - private VertexFormat format; + private VertexFormat vertexFormat; @SuppressWarnings("target") @ModifyVariable(method = "createSink(Lme/jellysquid/mods/sodium/client/model/vertex/type/VertexType;)Lme/jellysquid/mods/sodium/client/model/vertex/VertexSink;", at = @At("HEAD"), remap = false) private VertexType iris$createSink(VertexType type) { - if (format == IrisVertexFormats.ENTITY) { + if (vertexFormat == IrisVertexFormats.ENTITY) { if (type == VanillaVertexTypes.QUADS) { return ExtendedQuadVertexType.INSTANCE; } - } else if (format == IrisVertexFormats.TERRAIN) { + } else if (vertexFormat == IrisVertexFormats.TERRAIN) { if (type == VanillaVertexTypes.GLYPHS) { return ExtendedGlyphVertexType.INSTANCE; } diff --git a/src/main/java/net/coderbot/iris/features/FeatureFlags.java b/src/main/java/net/coderbot/iris/features/FeatureFlags.java index 269848a888..27f2d8c8f9 100644 --- a/src/main/java/net/coderbot/iris/features/FeatureFlags.java +++ b/src/main/java/net/coderbot/iris/features/FeatureFlags.java @@ -3,10 +3,10 @@ import java.util.List; import java.util.function.BooleanSupplier; +import net.minecraft.client.resources.I18n; import org.apache.commons.lang3.text.WordUtils; import net.coderbot.iris.gl.IrisRenderSystem; -import net.minecraft.client.resources.language.I18n; public enum FeatureFlags { SEPARATE_HARDWARE_SAMPLERS(() -> true, () -> true), @@ -33,12 +33,12 @@ public static String getInvalidStatus(List invalidFeatureFlags) { if (unsupportedIris) { if (unsupportedHardware) { - return I18n.get("iris.unsupported.irisorpc"); + return I18n.format("iris.unsupported.irisorpc"); } - return I18n.get("iris.unsupported.iris"); + return I18n.format("iris.unsupported.iris"); } else if (unsupportedHardware) { - return I18n.get("iris.unsupported.pc"); + return I18n.format("iris.unsupported.pc"); } else { return null; } diff --git a/src/main/java/net/coderbot/iris/gl/GLDebug.java b/src/main/java/net/coderbot/iris/gl/GLDebug.java index 79231628a7..ca2940a04b 100644 --- a/src/main/java/net/coderbot/iris/gl/GLDebug.java +++ b/src/main/java/net/coderbot/iris/gl/GLDebug.java @@ -8,15 +8,13 @@ import java.io.PrintStream; import java.util.function.Consumer; -import org.lwjgl.opengl.AMDDebugOutput; -import org.lwjgl.opengl.ARBDebugOutput; +import org.lwjgl.opengl.*; import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GL43C; import org.lwjgl.opengl.GLCapabilities; import org.lwjgl.opengl.GLDebugMessageAMDCallback; import org.lwjgl.opengl.GLDebugMessageARBCallback; import org.lwjgl.opengl.GLDebugMessageCallback; -import org.lwjgl.opengl.KHRDebug; import org.lwjgl.system.APIUtil; import net.coderbot.iris.Iris; @@ -74,7 +72,7 @@ public void accept(String str) { } public static int setupDebugMessageCallback(PrintStream stream) { - GLCapabilities caps = GL.getCapabilities(); + ContextCapabilities caps = GLContext.getCapabilities(); if (caps.OpenGL43) { Iris.logger.info("[GL] Using OpenGL 4.3 for error logging."); GLDebugMessageCallback proc = GLDebugMessageCallback.create((source, type, id, severity, length, message, userParam) -> { @@ -159,7 +157,7 @@ public static int setupDebugMessageCallback(PrintStream stream) { } public static int disableDebugMessages() { - GLCapabilities caps = GL.getCapabilities(); + ContextCapabilities caps = GLContext.getCapabilities(); if (caps.OpenGL43) { GL43C.glDebugMessageCallback(null, 0L); return 1; @@ -381,7 +379,7 @@ public void popGroup() { } public static void initRenderer() { - if (GL.getCapabilities().GL_KHR_debug || GL.getCapabilities().OpenGL43) { + if (GLContext.getCapabilities().GL_KHR_debug || GLContext.getCapabilities().OpenGL43) { debugState = new KHRDebugState(); } else { debugState = new UnsupportedDebugState(); diff --git a/src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java b/src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java index e18dae93ab..f08dd510fe 100644 --- a/src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java +++ b/src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java @@ -5,12 +5,11 @@ import java.nio.IntBuffer; import net.coderbot.iris.mixin.GlStateManagerAccessor; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; import org.jetbrains.annotations.Nullable; -import org.lwjgl.opengl.ARBDirectStateAccess; -import org.lwjgl.opengl.EXTShaderImageLoadStore; +import org.lwjgl.opengl.*; import org.lwjgl.opengl.GL; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL30C; import org.lwjgl.opengl.GL40C; import org.lwjgl.opengl.GL45C; @@ -31,10 +30,10 @@ public class IrisRenderSystem { private static boolean supportsCompute; public static void initRenderer() { - if (GL.getCapabilities().OpenGL45) { + if (GLContext.getCapabilities().OpenGL45) { dsaState = new DSACore(); Iris.logger.info("OpenGL 4.5 detected, enabling DSA."); - } else if (GL.getCapabilities().GL_ARB_direct_state_access) { + } else if (GLContext.getCapabilities().GL_ARB_direct_state_access) { dsaState = new DSAARB(); Iris.logger.info("ARB_direct_state_access detected, enabling DSA."); } else { @@ -42,7 +41,7 @@ public static void initRenderer() { Iris.logger.info("DSA support not detected."); } - if (GL.getCapabilities().OpenGL45 || GL.getCapabilities().GL_ARB_multi_bind) { + if (GLContext.getCapabilities().OpenGL45 || GLContext.getCapabilities().GL_ARB_multi_bind) { hasMultibind = true; } else { hasMultibind = false; @@ -52,88 +51,71 @@ public static void initRenderer() { } public static void getIntegerv(int pname, int[] params) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glGetIntegerv(pname, params); } public static void getFloatv(int pname, float[] params) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glGetFloatv(pname, params); } public static void generateMipmaps(int texture, int mipmapTarget) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); dsaState.generateMipmaps(texture, mipmapTarget); } public static void bindAttributeLocation(int program, int index, CharSequence name) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glBindAttribLocation(program, index, name); } public static void texImage2D(int texture, int target, int level, int internalformat, int width, int height, int border, int format, int type, @Nullable ByteBuffer pixels) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); - GlStateManager._bindTexture(texture); + GlStateManager.bindTexture(texture); GL30C.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); } public static void uniformMatrix4fv(int location, boolean transpose, FloatBuffer matrix) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glUniformMatrix4fv(location, transpose, matrix); } public static void copyTexImage2D(int target, int level, int internalFormat, int x, int y, int width, int height, int border) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border); } public static void uniform1f(int location, float v0) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glUniform1f(location, v0); } public static void uniform1i(int location, int v0) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glUniform1i(location, v0); } public static void uniform2f(int location, float v0, float v1) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glUniform2f(location, v0, v1); } public static void uniform2i(int location, int v0, int v1) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glUniform2i(location, v0, v1); } public static void uniform3f(int location, float v0, float v1, float v2) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glUniform3f(location, v0, v1, v2); } public static void uniform4f(int location, float v0, float v1, float v2, float v3) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glUniform4f(location, v0, v1, v2, v3); } public static void uniform4i(int location, int v0, int v1, int v2, int v3) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glUniform4i(location, v0, v1, v2, v3); } public static int getAttribLocation(int programId, String name) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); return GL30C.glGetAttribLocation(programId, name); } public static int getUniformLocation(int programId, String name) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); return GL30C.glGetUniformLocation(programId, name); } public static void texParameteriv(int texture, int target, int pname, int[] params) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); dsaState.texParameteriv(texture, target, pname, params); } @@ -142,62 +124,50 @@ public static void copyTexSubImage2D(int destTexture, int target, int i, int i1, } public static void texParameteri(int texture, int target, int pname, int param) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); dsaState.texParameteri(texture, target, pname, param); } public static void texParameterf(int texture, int target, int pname, float param) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); dsaState.texParameterf(texture, target, pname, param); } public static String getProgramInfoLog(int program) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); return GL30C.glGetProgramInfoLog(program); } public static String getShaderInfoLog(int shader) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); return GL30C.glGetShaderInfoLog(shader); } public static void drawBuffers(int framebuffer, int[] buffers) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); dsaState.drawBuffers(framebuffer, buffers); } public static void readBuffer(int framebuffer, int buffer) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); dsaState.readBuffer(framebuffer, buffer); } public static String getActiveUniform(int program, int index, int size, IntBuffer type, IntBuffer name) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); return GL30C.glGetActiveUniform(program, index, size, type, name); } public static void readPixels(int x, int y, int width, int height, int format, int type, float[] pixels) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glReadPixels(x, y, width, height, format, type, pixels); } public static void bufferData(int target, float[] data, int usage) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glBufferData(target, data, usage); } public static int bufferStorage(int target, float[] data, int usage) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); return dsaState.bufferStorage(target, data, usage); } public static void vertexAttrib4f(int index, float v0, float v1, float v2, float v3) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glVertexAttrib4f(index, v0, v1, v2, v3); } public static void detachShader(int program, int shader) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL30C.glDetachShader(program, shader); } @@ -206,13 +176,11 @@ public static void framebufferTexture2D(int fb, int fbtarget, int attachment, in } public static int getTexParameteri(int texture, int target, int pname) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); return dsaState.getTexParameteri(texture, target, pname); } public static void bindImageTexture(int unit, int texture, int level, boolean layered, int layer, int access, int format) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); - if (GL.getCapabilities().OpenGL42) { + if (GLContext.getCapabilities().OpenGL42) { GL45C.glBindImageTexture(unit, texture, level, layered, layer, access, format); } else { EXTShaderImageLoadStore.glBindImageTextureEXT(unit, texture, level, layered, layer, access, format); @@ -220,10 +188,10 @@ public static void bindImageTexture(int unit, int texture, int level, boolean la } public static int getMaxImageUnits() { - if (GL.getCapabilities().OpenGL42) { - return GlStateManager._getInteger(GL45C.GL_MAX_IMAGE_UNITS); - } else if (GL.getCapabilities().GL_EXT_shader_image_load_store) { - return GlStateManager._getInteger(EXTShaderImageLoadStore.GL_MAX_IMAGE_UNITS_EXT); + if (GLContext.getCapabilities().OpenGL42) { + return GlStateManager.glGetInteger(GL45C.GL_MAX_IMAGE_UNITS); + } else if (GLContext.getCapabilities().GL_EXT_shader_image_load_store) { + return GlStateManager.glGetInteger(EXTShaderImageLoadStore.GL_MAX_IMAGE_UNITS_EXT); } else { return 0; } @@ -248,21 +216,18 @@ public static void memoryBarrier(int barriers) { } public static boolean supportsBufferBlending() { - return GL.getCapabilities().GL_ARB_draw_buffers_blend || GL.getCapabilities().OpenGL40; + return GLContext.getCapabilities().GL_ARB_draw_buffers_blend || GLContext.getCapabilities().OpenGL40; } public static void disableBufferBlend(int buffer) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); - GL30C.glDisablei(GL30C.GL_BLEND, buffer); + GL30C.glDisablei(GL11.GL_BLEND, buffer); } public static void enableBufferBlend(int buffer) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); - GL30C.glEnablei(GL30C.GL_BLEND, buffer); + GL30C.glEnablei(GL11.GL_BLEND, buffer); } public static void blendFuncSeparatei(int buffer, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); GL40C.glBlendFuncSeparatei(buffer, srcRGB, dstRGB, srcAlpha, dstAlpha); } @@ -274,18 +239,17 @@ public static void bindTextureToUnit(int unit, int texture) { @Deprecated public static void setupProjectionMatrix(float[] matrix) { - RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit); - RenderSystem.matrixMode(GL11.GL_PROJECTION); - RenderSystem.pushMatrix(); + GlStateManager.matrixMode(GL11.GL_PROJECTION); + GlStateManager.pushMatrix(); GL20.glLoadMatrixf(matrix); - RenderSystem.matrixMode(GL11.GL_MODELVIEW); + GlStateManager.matrixMode(GL11.GL_MODELVIEW); } @Deprecated public static void restoreProjectionMatrix() { - RenderSystem.matrixMode(GL11.GL_PROJECTION); - RenderSystem.popMatrix(); - RenderSystem.matrixMode(GL11.GL_MODELVIEW); + GlStateManager.matrixMode(GL11.GL_PROJECTION); + GlStateManager.popMatrix(); + GlStateManager.matrixMode(GL11.GL_MODELVIEW); } public static void blitFramebuffer(int source, int dest, int offsetX, int offsetY, int width, int height, int offsetX2, int offsetY2, int width2, int height2, int bufferChoice, int filter) { @@ -387,8 +351,8 @@ public void bindTextureToUnit(int unit, int texture) { @Override public int bufferStorage(int target, float[] data, int usage) { - int buffer = GL45C.glCreateBuffers(); - GL45C.glNamedBufferData(buffer, data, usage); + int buffer = GL45.glCreateBuffers(); + GL45.glNamedBufferData(buffer, data, usage); return buffer; } @@ -416,94 +380,94 @@ public int createTexture(int target) { public static class DSAUnsupported implements DSAAccess { @Override public void generateMipmaps(int texture, int target) { - GlStateManager._bindTexture(texture); - GL30C.glGenerateMipmap(target); + GlStateManager.bindTexture(texture); + GL30.glGenerateMipmap(target); } @Override public void texParameteri(int texture, int target, int pname, int param) { - GlStateManager._bindTexture(texture); + GlStateManager.bindTexture(texture); GL30C.glTexParameteri(target, pname, param); } @Override public void texParameterf(int texture, int target, int pname, float param) { - GlStateManager._bindTexture(texture); + GlStateManager.bindTexture(texture); GL30C.glTexParameterf(target, pname, param); } @Override public void texParameteriv(int texture, int target, int pname, int[] params) { - GlStateManager._bindTexture(texture); + GlStateManager.bindTexture(texture); GL30C.glTexParameteriv(target, pname, params); } @Override public void readBuffer(int framebuffer, int buffer) { - GlStateManager._glBindFramebuffer(GL30C.GL_FRAMEBUFFER, framebuffer); + GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer); GL30C.glReadBuffer(buffer); } @Override public void drawBuffers(int framebuffer, int[] buffers) { - GlStateManager._glBindFramebuffer(GL30C.GL_FRAMEBUFFER, framebuffer); + GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer); GL30C.glDrawBuffers(buffers); } @Override public int getTexParameteri(int texture, int target, int pname) { - GlStateManager._bindTexture(texture); + GlStateManager.bindTexture(texture); return GL30C.glGetTexParameteri(target, pname); } @Override public void copyTexSubImage2D(int destTexture, int target, int i, int i1, int i2, int i3, int i4, int width, int height) { int previous = GlStateManager.getActiveTextureName(); - GlStateManager._bindTexture(destTexture); - GL30C.glCopyTexSubImage2D(target, i, i1, i2, i3, i4, width, height); - GlStateManager._bindTexture(previous); + GlStateManager.bindTexture(destTexture); + GlStateManager.glCopyTexSubImage2D(target, i, i1, i2, i3, i4, width, height); + GlStateManager.bindTexture(previous); } @Override public void bindTextureToUnit(int unit, int texture) { - GlStateManager._activeTexture(GL30C.GL_TEXTURE0 + unit); - GlStateManager._bindTexture(texture); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0 + unit); + GlStateManager.bindTexture(texture); } @Override public int bufferStorage(int target, float[] data, int usage) { - int buffer = GlStateManager._glGenBuffers(); - GlStateManager._glBindBuffer(target, buffer); + int buffer = GL15.glGenBuffers(); + GL15.glBindBuffer(target, buffer); bufferData(target, data, usage); - GlStateManager._glBindBuffer(target, 0); + GL15.glBindBuffer(target, 0); return buffer; } @Override public void blitFramebuffer(int source, int dest, int offsetX, int offsetY, int width, int height, int offsetX2, int offsetY2, int width2, int height2, int bufferChoice, int filter) { - GlStateManager._glBindFramebuffer(GL30C.GL_READ_FRAMEBUFFER, source); - GlStateManager._glBindFramebuffer(GL30C.GL_DRAW_FRAMEBUFFER, dest); - GL30C.glBlitFramebuffer(offsetX, offsetY, width, height, offsetX2, offsetY2, width2, height2, bufferChoice, filter); + GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, source); + GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, dest); + GL30.glBlitFramebuffer(offsetX, offsetY, width, height, offsetX2, offsetY2, width2, height2, bufferChoice, filter); } @Override public void framebufferTexture2D(int fb, int fbtarget, int attachment, int target, int texture, int levels) { - GlStateManager._glBindFramebuffer(fbtarget, fb); - GL30C.glFramebufferTexture2D(fbtarget, attachment, target, texture, levels); + GL30.glBindFramebuffer(fbtarget, fb); + GL30.glFramebufferTexture2D(fbtarget, attachment, target, texture, levels); } @Override public int createFramebuffer() { - int framebuffer = GlStateManager.glGenFramebuffers(); - GlStateManager._glBindFramebuffer(GL30C.GL_FRAMEBUFFER, framebuffer); + int framebuffer = GL30.glGenFramebuffers(); + GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer); return framebuffer; } @Override public int createTexture(int target) { - int texture = GlStateManager._genTexture(); - GlStateManager._bindTexture(texture); + int texture = GlStateManager.generateTexture(); + GlStateManager.bindTexture(texture); return texture; } } diff --git a/src/main/java/net/coderbot/iris/gl/blending/AlphaTestStorage.java b/src/main/java/net/coderbot/iris/gl/blending/AlphaTestStorage.java index de67f91328..ca1dfac25c 100644 --- a/src/main/java/net/coderbot/iris/gl/blending/AlphaTestStorage.java +++ b/src/main/java/net/coderbot/iris/gl/blending/AlphaTestStorage.java @@ -1,9 +1,8 @@ package net.coderbot.iris.gl.blending; -import com.mojang.blaze3d.platform.GlStateManager; - import net.coderbot.iris.mixin.GlStateManagerAccessor; import net.coderbot.iris.mixin.statelisteners.BooleanStateAccessor; +import net.minecraft.client.renderer.GlStateManager; public class AlphaTestStorage { private static boolean originalAlphaTestEnable; @@ -19,17 +18,17 @@ public static void overrideAlphaTest(AlphaTest override) { // Only save the previous state if the alpha test wasn't already locked GlStateManager.AlphaState alphaState = GlStateManagerAccessor.getALPHA_TEST(); - originalAlphaTestEnable = ((BooleanStateAccessor) alphaState.mode).isEnabled(); - originalAlphaTest = new AlphaTest(AlphaTestFunction.fromGlId(alphaState.func).get(), alphaState.reference); + originalAlphaTestEnable = ((BooleanStateAccessor) alphaState.alphaTest).isEnabled(); + originalAlphaTest = new AlphaTest(AlphaTestFunction.fromGlId(alphaState.func).get(), alphaState.ref); } alphaTestLocked = false; if (override == null) { - GlStateManager._disableAlphaTest(); + GlStateManager.disableAlpha(); } else { - GlStateManager._enableAlphaTest(); - GlStateManager._alphaFunc(override.getFunction().getGlId(), override.getReference()); + GlStateManager.enableAlpha(); + GlStateManager.alphaFunc(override.getFunction().getGlId(), override.getReference()); } alphaTestLocked = true; @@ -51,11 +50,11 @@ public static void restoreAlphaTest() { alphaTestLocked = false; if (originalAlphaTestEnable) { - GlStateManager._enableAlphaTest(); + GlStateManager.enableAlpha(); } else { - GlStateManager._disableAlphaTest(); + GlStateManager.disableAlpha(); } - GlStateManager._alphaFunc(originalAlphaTest.getFunction().getGlId(), originalAlphaTest.getReference()); + GlStateManager.alphaFunc(originalAlphaTest.getFunction().getGlId(), originalAlphaTest.getReference()); } } diff --git a/src/main/java/net/coderbot/iris/gl/blending/BlendModeStorage.java b/src/main/java/net/coderbot/iris/gl/blending/BlendModeStorage.java index b7bf78f402..2d2f43f437 100644 --- a/src/main/java/net/coderbot/iris/gl/blending/BlendModeStorage.java +++ b/src/main/java/net/coderbot/iris/gl/blending/BlendModeStorage.java @@ -5,6 +5,7 @@ import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.mixin.GlStateManagerAccessor; import net.coderbot.iris.mixin.statelisteners.BooleanStateAccessor; +import net.minecraft.client.renderer.GlStateManager; public class BlendModeStorage { private static boolean originalBlendEnable; @@ -21,16 +22,16 @@ public static void overrideBlend(BlendMode override) { GlStateManager.BlendState blendState = GlStateManagerAccessor.getBLEND(); originalBlendEnable = ((BooleanStateAccessor) blendState.mode).isEnabled(); - originalBlend = new BlendMode(blendState.srcRgb, blendState.dstRgb, blendState.srcAlpha, blendState.dstAlpha); + originalBlend = new BlendMode(blendState.srcFactor, blendState.dstFactor, blendState.srcFactorAlpha, blendState.dstFactorAlpha); } blendLocked = false; if (override == null) { - GlStateManager._disableBlend(); + GlStateManager.disableBlend(); } else { - GlStateManager._enableBlend(); - GlStateManager._blendFuncSeparate(override.getSrcRgb(), override.getDstRgb(), override.getSrcAlpha(), override.getDstAlpha()); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(override.getSrcRgb(), override.getDstRgb(), override.getSrcAlpha(), override.getDstAlpha()); } blendLocked = true; @@ -42,7 +43,7 @@ public static void overrideBufferBlend(int index, BlendMode override) { GlStateManager.BlendState blendState = GlStateManagerAccessor.getBLEND(); originalBlendEnable = ((BooleanStateAccessor) blendState.mode).isEnabled(); - originalBlend = new BlendMode(blendState.srcRgb, blendState.dstRgb, blendState.srcAlpha, blendState.dstAlpha); + originalBlend = new BlendMode(blendState.srcFactor, blendState.dstFactor, blendState.srcFactorAlpha, blendState.dstFactorAlpha); } if (override == null) { @@ -71,12 +72,12 @@ public static void restoreBlend() { blendLocked = false; if (originalBlendEnable) { - GlStateManager._enableBlend(); + GlStateManager.enableBlend(); } else { - GlStateManager._disableBlend(); + GlStateManager.disableBlend(); } - GlStateManager._blendFuncSeparate(originalBlend.getSrcRgb(), originalBlend.getDstRgb(), + GlStateManager.tryBlendFuncSeparate(originalBlend.getSrcRgb(), originalBlend.getDstRgb(), originalBlend.getSrcAlpha(), originalBlend.getDstAlpha()); } } diff --git a/src/main/java/net/coderbot/iris/gl/blending/DepthColorStorage.java b/src/main/java/net/coderbot/iris/gl/blending/DepthColorStorage.java index 8bcd9155bd..ff5537a487 100644 --- a/src/main/java/net/coderbot/iris/gl/blending/DepthColorStorage.java +++ b/src/main/java/net/coderbot/iris/gl/blending/DepthColorStorage.java @@ -3,6 +3,7 @@ import com.mojang.blaze3d.platform.GlStateManager; import net.coderbot.iris.mixin.GlStateManagerAccessor; +import net.minecraft.client.renderer.GlStateManager; public class DepthColorStorage { private static boolean originalDepthEnable; @@ -25,8 +26,8 @@ public static void disableDepthColor() { depthColorLocked = false; - GlStateManager._depthMask(false); - GlStateManager._colorMask(false, false, false, false); + GlStateManager.depthMask(false); + GlStateManager.colorMask(false, false, false, false); depthColorLocked = true; } @@ -47,11 +48,11 @@ public static void unlockDepthColor() { depthColorLocked = false; if (originalDepthEnable) { - GlStateManager._depthMask(true); + GlStateManager.depthMask(true); } else { - GlStateManager._depthMask(false); + GlStateManager.depthMask(false); } - GlStateManager._colorMask(originalColor.isRedMasked(), originalColor.isGreenMasked(), originalColor.isBlueMasked(), originalColor.isAlphaMasked()); + GlStateManager.colorMask(originalColor.isRedMasked(), originalColor.isGreenMasked(), originalColor.isBlueMasked(), originalColor.isAlphaMasked()); } } diff --git a/src/main/java/net/coderbot/iris/gl/framebuffer/GlFramebuffer.java b/src/main/java/net/coderbot/iris/gl/framebuffer/GlFramebuffer.java index bd1a63a601..87156339a5 100644 --- a/src/main/java/net/coderbot/iris/gl/framebuffer/GlFramebuffer.java +++ b/src/main/java/net/coderbot/iris/gl/framebuffer/GlFramebuffer.java @@ -1,15 +1,16 @@ package net.coderbot.iris.gl.framebuffer; -import org.lwjgl.opengl.GL30C; - -import com.mojang.blaze3d.platform.GlStateManager; - import it.unimi.dsi.fastutil.ints.Int2IntArrayMap; import it.unimi.dsi.fastutil.ints.Int2IntMap; import net.coderbot.iris.gl.GlResource; import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.texture.DepthBufferFormat; import net.coderbot.iris.texture.TextureInfoCache; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL20; +import org.lwjgl.opengl.GL30; public class GlFramebuffer extends GlResource { private final Int2IntMap attachments; @@ -21,8 +22,8 @@ public GlFramebuffer() { super(IrisRenderSystem.createFramebuffer()); this.attachments = new Int2IntArrayMap(); - this.maxDrawBuffers = GlStateManager._getInteger(GL30C.GL_MAX_DRAW_BUFFERS); - this.maxColorAttachments = GlStateManager._getInteger(GL30C.GL_MAX_COLOR_ATTACHMENTS); + this.maxDrawBuffers = GlStateManager.glGetInteger(GL20.GL_MAX_DRAW_BUFFERS); + this.maxColorAttachments = GlStateManager.glGetInteger(GL30.GL_MAX_COLOR_ATTACHMENTS); this.hasDepthAttachment = false; } @@ -33,9 +34,9 @@ public void addDepthAttachment(int texture) { int fb = getGlId(); if (depthBufferFormat.isCombinedStencil()) { - IrisRenderSystem.framebufferTexture2D(fb, GL30C.GL_FRAMEBUFFER, GL30C.GL_DEPTH_STENCIL_ATTACHMENT, GL30C.GL_TEXTURE_2D, texture, 0); + IrisRenderSystem.framebufferTexture2D(fb, GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_STENCIL_ATTACHMENT, GL11.GL_TEXTURE_2D, texture, 0); } else { - IrisRenderSystem.framebufferTexture2D(fb, GL30C.GL_FRAMEBUFFER, GL30C.GL_DEPTH_ATTACHMENT, GL30C.GL_TEXTURE_2D, texture, 0); + IrisRenderSystem.framebufferTexture2D(fb, GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL11.GL_TEXTURE_2D, texture, 0); } this.hasDepthAttachment = true; @@ -44,12 +45,12 @@ public void addDepthAttachment(int texture) { public void addColorAttachment(int index, int texture) { int fb = getGlId(); - IrisRenderSystem.framebufferTexture2D(fb, GL30C.GL_FRAMEBUFFER, GL30C.GL_COLOR_ATTACHMENT0 + index, GL30C.GL_TEXTURE_2D, texture, 0); + IrisRenderSystem.framebufferTexture2D(fb, GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0 + index, GL11.GL_TEXTURE_2D, texture, 0); attachments.put(index, texture); } public void noDrawBuffers() { - IrisRenderSystem.drawBuffers(getGlId(), new int[] { GL30C.GL_NONE }); + IrisRenderSystem.drawBuffers(getGlId(), new int[] { GL11.GL_NONE }); } public void drawBuffers(int[] buffers) { @@ -65,14 +66,14 @@ public void drawBuffers(int[] buffers) { throw new IllegalArgumentException("Only " + maxColorAttachments + " color attachments are supported on this GPU, but an attempt was made to write to a color attachment with index " + buffer); } - glBuffers[index++] = GL30C.GL_COLOR_ATTACHMENT0 + buffer; + glBuffers[index++] = GL30.GL_COLOR_ATTACHMENT0 + buffer; } IrisRenderSystem.drawBuffers(getGlId(), glBuffers); } public void readBuffer(int buffer) { - IrisRenderSystem.readBuffer(getGlId(), GL30C.GL_COLOR_ATTACHMENT0 + buffer); + IrisRenderSystem.readBuffer(getGlId(), GL30.GL_COLOR_ATTACHMENT0 + buffer); } public int getColorAttachment(int index) { @@ -84,26 +85,26 @@ public boolean hasDepthAttachment() { } public void bind() { - GlStateManager._glBindFramebuffer(GL30C.GL_FRAMEBUFFER, getGlId()); + OpenGlHelper.glBindFramebuffer(GL30.GL_FRAMEBUFFER, getGlId()); } public void bindAsReadBuffer() { - GlStateManager._glBindFramebuffer(GL30C.GL_READ_FRAMEBUFFER, getGlId()); + OpenGlHelper.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, getGlId()); } public void bindAsDrawBuffer() { - GlStateManager._glBindFramebuffer(GL30C.GL_DRAW_FRAMEBUFFER, getGlId()); + OpenGlHelper.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, getGlId()); } protected void destroyInternal() { - GlStateManager._glDeleteFramebuffers(getGlId()); + OpenGlHelper.glDeleteFramebuffers(getGlId()); } public boolean isComplete() { bind(); - int status = GlStateManager.glCheckFramebufferStatus(GL30C.GL_FRAMEBUFFER); + int status = OpenGlHelper.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER); - return status == GL30C.GL_FRAMEBUFFER_COMPLETE; + return status == GL30.GL_FRAMEBUFFER_COMPLETE; } public int getId() { diff --git a/src/main/java/net/coderbot/iris/gl/image/ImageBinding.java b/src/main/java/net/coderbot/iris/gl/image/ImageBinding.java index 85e6758eae..a8cd7ac411 100644 --- a/src/main/java/net/coderbot/iris/gl/image/ImageBinding.java +++ b/src/main/java/net/coderbot/iris/gl/image/ImageBinding.java @@ -2,7 +2,7 @@ import java.util.function.IntSupplier; -import org.lwjgl.opengl.GL42C; +import org.lwjgl.opengl.GL15; import net.coderbot.iris.gl.IrisRenderSystem; @@ -21,6 +21,6 @@ public void update() { // We can assume that image bindings are supported here as either the EXT extension or 4.2 core, as otherwise ImageLimits // would report that zero image units are supported. // RRe36: I'm not sure if its perfectly fine to always have it be layered, but according to Balint its *probably* fine. Still might need to verify that though. - IrisRenderSystem.bindImageTexture(imageUnit, textureID.getAsInt(), 0, true, 0, GL42C.GL_READ_WRITE, internalFormat); + IrisRenderSystem.bindImageTexture(imageUnit, textureID.getAsInt(), 0, true, 0, GL15.GL_READ_WRITE, internalFormat); } } diff --git a/src/main/java/net/coderbot/iris/gl/program/ComputeProgram.java b/src/main/java/net/coderbot/iris/gl/program/ComputeProgram.java index ef68c0de9b..c0a094ef14 100644 --- a/src/main/java/net/coderbot/iris/gl/program/ComputeProgram.java +++ b/src/main/java/net/coderbot/iris/gl/program/ComputeProgram.java @@ -1,9 +1,7 @@ package net.coderbot.iris.gl.program; -import org.lwjgl.opengl.GL43C; - -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.shaders.ProgramManager; +import net.minecraft.client.renderer.OpenGlHelper; +import org.lwjgl.opengl.GL43; import net.coderbot.iris.Iris; import net.coderbot.iris.gl.GlResource; @@ -27,7 +25,7 @@ public final class ComputeProgram extends GlResource { super(program); localSize = new int[3]; - IrisRenderSystem.getProgramiv(program, GL43C.GL_COMPUTE_WORK_GROUP_SIZE, localSize); + IrisRenderSystem.getProgramiv(program, GL43.GL_COMPUTE_WORK_GROUP_SIZE, localSize); this.uniforms = uniforms; this.samplers = samplers; this.images = images; @@ -57,7 +55,7 @@ public Vector3i getWorkGroups(float width, float height) { } public void use() { - ProgramManager.glUseProgram(getGlId()); + OpenGlHelper.glUseProgram(getGlId()); uniforms.update(); samplers.update(); @@ -65,7 +63,7 @@ public void use() { } public void dispatch(float width, float height) { - ProgramManager.glUseProgram(getGlId()); + OpenGlHelper.glUseProgram(getGlId()); uniforms.update(); samplers.update(); images.update(); @@ -79,11 +77,11 @@ public void dispatch(float width, float height) { public static void unbind() { ProgramUniforms.clearActiveUniforms(); - ProgramManager.glUseProgram(0); + OpenGlHelper.glUseProgram(0); } public void destroyInternal() { - GlStateManager.glDeleteProgram(getGlId()); + OpenGlHelper.glDeleteProgram(getGlId()); } /** diff --git a/src/main/java/net/coderbot/iris/gl/program/Program.java b/src/main/java/net/coderbot/iris/gl/program/Program.java index 3891595fd0..df3a7a33b4 100644 --- a/src/main/java/net/coderbot/iris/gl/program/Program.java +++ b/src/main/java/net/coderbot/iris/gl/program/Program.java @@ -1,9 +1,7 @@ package net.coderbot.iris.gl.program; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.shaders.ProgramManager; - import net.coderbot.iris.gl.GlResource; +import net.minecraft.client.renderer.OpenGlHelper; public final class Program extends GlResource { private final ProgramUniforms uniforms; @@ -19,7 +17,7 @@ public final class Program extends GlResource { } public void use() { - ProgramManager.glUseProgram(getGlId()); + OpenGlHelper.glUseProgram(getGlId()); uniforms.update(); samplers.update(); @@ -29,11 +27,11 @@ public void use() { public static void unbind() { ProgramUniforms.clearActiveUniforms(); ProgramSamplers.clearActiveSamplers(); - ProgramManager.glUseProgram(0); + OpenGlHelper.glUseProgram(0); } public void destroyInternal() { - GlStateManager.glDeleteProgram(getGlId()); + OpenGlHelper.glDeleteProgram(getGlId()); } /** diff --git a/src/main/java/net/coderbot/iris/gl/program/ProgramBuilder.java b/src/main/java/net/coderbot/iris/gl/program/ProgramBuilder.java index dfdd6b4e70..1e6f86c603 100644 --- a/src/main/java/net/coderbot/iris/gl/program/ProgramBuilder.java +++ b/src/main/java/net/coderbot/iris/gl/program/ProgramBuilder.java @@ -2,10 +2,7 @@ import java.util.function.IntSupplier; -import org.jetbrains.annotations.Nullable; - import com.google.common.collect.ImmutableSet; -import com.mojang.blaze3d.systems.RenderSystem; import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.image.ImageHolder; @@ -16,6 +13,8 @@ import net.coderbot.iris.gl.state.ValueUpdateNotifier; import net.coderbot.iris.gl.texture.InternalTextureFormat; +import javax.annotation.Nullable; + public class ProgramBuilder extends ProgramUniforms.Builder implements SamplerHolder, ImageHolder { private final int program; private final ProgramSamplers.Builder samplers; @@ -35,8 +34,6 @@ public void bindAttributeLocation(int index, String name) { public static ProgramBuilder begin(String name, @Nullable String vertexSource, @Nullable String geometrySource, @Nullable String fragmentSource, ImmutableSet reservedTextureUnits) { - RenderSystem.assertThread(RenderSystem::isOnRenderThread); - GlShader vertex; GlShader geometry; GlShader fragment; @@ -71,8 +68,6 @@ public static ProgramBuilder begin(String name, @Nullable String vertexSource, @ } public static ProgramBuilder beginCompute(String name, @Nullable String source, ImmutableSet reservedTextureUnits) { - RenderSystem.assertThread(RenderSystem::isOnRenderThread); - if (!IrisRenderSystem.supportsCompute()) { throw new IllegalStateException("This PC does not support compute shaders, but it's attempting to be used???"); } diff --git a/src/main/java/net/coderbot/iris/gl/program/ProgramImages.java b/src/main/java/net/coderbot/iris/gl/program/ProgramImages.java index 89e46aabb6..eb88bc9e50 100644 --- a/src/main/java/net/coderbot/iris/gl/program/ProgramImages.java +++ b/src/main/java/net/coderbot/iris/gl/program/ProgramImages.java @@ -5,13 +5,13 @@ import java.util.function.IntSupplier; import com.google.common.collect.ImmutableList; -import com.mojang.blaze3d.platform.GlStateManager; import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.image.ImageBinding; import net.coderbot.iris.gl.image.ImageHolder; import net.coderbot.iris.gl.image.ImageLimits; import net.coderbot.iris.gl.texture.InternalTextureFormat; +import net.minecraft.client.renderer.OpenGlHelper; public class ProgramImages { private final ImmutableList imageBindings; @@ -61,12 +61,12 @@ private Builder(int program) { @Override public boolean hasImage(String name) { - return GlStateManager._glGetUniformLocation(program, name) != -1; + return OpenGlHelper.glGetUniformLocation(program, name) != -1; } @Override public void addTextureImage(IntSupplier textureID, InternalTextureFormat internalFormat, String name) { - int location = GlStateManager._glGetUniformLocation(program, name); + int location = OpenGlHelper.glGetUniformLocation(program, name); if (location == -1) { return; diff --git a/src/main/java/net/coderbot/iris/gl/program/ProgramSamplers.java b/src/main/java/net/coderbot/iris/gl/program/ProgramSamplers.java index b2bc0d6bef..9dc49d78bf 100644 --- a/src/main/java/net/coderbot/iris/gl/program/ProgramSamplers.java +++ b/src/main/java/net/coderbot/iris/gl/program/ProgramSamplers.java @@ -1,16 +1,7 @@ package net.coderbot.iris.gl.program; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.function.IntSupplier; - -import org.lwjgl.opengl.GL20C; - import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.mojang.blaze3d.systems.RenderSystem; - import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.sampler.SamplerBinding; @@ -19,6 +10,13 @@ import net.coderbot.iris.gl.state.ValueUpdateNotifier; import net.coderbot.iris.mixin.GlStateManagerAccessor; import net.coderbot.iris.shaderpack.PackRenderTargetDirectives; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL13; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.function.IntSupplier; public class ProgramSamplers { private static ProgramSamplers active; @@ -55,7 +53,7 @@ public void update() { samplerBinding.update(); } - RenderSystem.activeTexture(GL20C.GL_TEXTURE0 + activeTexture); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0 + activeTexture); } public void removeListeners() { diff --git a/src/main/java/net/coderbot/iris/gl/program/ProgramUniforms.java b/src/main/java/net/coderbot/iris/gl/program/ProgramUniforms.java index 7d22a9f238..4d326aee7c 100644 --- a/src/main/java/net/coderbot/iris/gl/program/ProgramUniforms.java +++ b/src/main/java/net/coderbot/iris/gl/program/ProgramUniforms.java @@ -1,31 +1,18 @@ package net.coderbot.iris.gl.program; -import java.nio.IntBuffer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.OptionalInt; - -import org.lwjgl.BufferUtils; -import org.lwjgl.opengl.ARBShaderImageLoadStore; -import org.lwjgl.opengl.GL20C; -import org.lwjgl.opengl.GL30C; - import com.google.common.collect.ImmutableList; -import com.mojang.blaze3d.platform.GlStateManager; - import net.coderbot.iris.Iris; import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.state.ValueUpdateNotifier; -import net.coderbot.iris.gl.uniform.DynamicLocationalUniformHolder; -import net.coderbot.iris.gl.uniform.Uniform; -import net.coderbot.iris.gl.uniform.UniformHolder; -import net.coderbot.iris.gl.uniform.UniformType; -import net.coderbot.iris.gl.uniform.UniformUpdateFrequency; +import net.coderbot.iris.gl.uniform.*; import net.coderbot.iris.uniforms.SystemTimeUniforms; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.OpenGlHelper; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.*; + +import java.nio.IntBuffer; +import java.util.*; public class ProgramUniforms { private static ProgramUniforms active; @@ -54,7 +41,7 @@ private void updateStage(ImmutableList uniforms) { } private static long getCurrentTick() { - return Objects.requireNonNull(Minecraft.getInstance().level).getGameTime(); + return Objects.requireNonNull(Minecraft.getMinecraft().world).getTotalWorldTime(); } public void update() { @@ -182,7 +169,7 @@ public OptionalInt location(String name, UniformType type) { public ProgramUniforms buildUniforms() { // Check for any unsupported uniforms and warn about them so that we can easily figure out what uniforms we // need to add. - int activeUniforms = GlStateManager.glGetProgrami(program, GL20C.GL_ACTIVE_UNIFORMS); + int activeUniforms = OpenGlHelper.glGetProgrami(program, GL20.GL_ACTIVE_UNIFORMS); IntBuffer sizeBuf = BufferUtils.createIntBuffer(1); IntBuffer typeBuf = BufferUtils.createIntBuffer(1); @@ -286,39 +273,39 @@ public UniformHolder externallyManagedUniform(String name, UniformType type) { private static String getTypeName(int type) { String typeName; - if (type == GL20C.GL_FLOAT) { + if (type == GL11.GL_FLOAT) { typeName = "float"; - } else if (type == GL20C.GL_INT) { + } else if (type == GL11.GL_INT) { typeName = "int"; - } else if (type == GL20C.GL_FLOAT_MAT4) { + } else if (type == GL20.GL_FLOAT_MAT4) { typeName = "mat4"; - } else if (type == GL20C.GL_FLOAT_VEC4) { + } else if (type == GL20.GL_FLOAT_VEC4) { typeName = "vec4"; - } else if (type == GL20C.GL_FLOAT_MAT3) { + } else if (type == GL20.GL_FLOAT_MAT3) { typeName = "mat3"; - } else if (type == GL20C.GL_FLOAT_VEC3) { + } else if (type == GL20.GL_FLOAT_VEC3) { typeName = "vec3"; - } else if (type == GL20C.GL_FLOAT_MAT2) { + } else if (type == GL20.GL_FLOAT_MAT2) { typeName = "mat2"; - } else if (type == GL20C.GL_FLOAT_VEC2) { + } else if (type == GL20.GL_FLOAT_VEC2) { typeName = "vec2"; - } else if (type == GL20C.GL_INT_VEC2) { + } else if (type == GL20.GL_INT_VEC2) { typeName = "ivec2"; - } else if (type == GL20C.GL_INT_VEC4) { + } else if (type == GL20.GL_INT_VEC4) { typeName = "ivec4"; - } else if (type == GL20C.GL_SAMPLER_3D) { + } else if (type == GL20.GL_SAMPLER_3D) { typeName = "sampler3D"; - } else if (type == GL20C.GL_SAMPLER_2D) { + } else if (type == GL20.GL_SAMPLER_2D) { typeName = "sampler2D"; - } else if (type == GL30C.GL_UNSIGNED_INT_SAMPLER_2D) { + } else if (type == GL30.GL_UNSIGNED_INT_SAMPLER_2D) { typeName = "usampler2D"; - } else if (type == GL30C.GL_UNSIGNED_INT_SAMPLER_3D) { + } else if (type == GL30.GL_UNSIGNED_INT_SAMPLER_3D) { typeName = "usampler3D"; - } else if (type == GL20C.GL_SAMPLER_1D) { + } else if (type == GL20.GL_SAMPLER_1D) { typeName = "sampler1D"; - } else if (type == GL20C.GL_SAMPLER_2D_SHADOW) { + } else if (type == GL20.GL_SAMPLER_2D_SHADOW) { typeName = "sampler2DShadow"; - } else if (type == GL20C.GL_SAMPLER_1D_SHADOW) { + } else if (type == GL20.GL_SAMPLER_1D_SHADOW) { typeName = "sampler1DShadow"; } else if (type == ARBShaderImageLoadStore.GL_IMAGE_2D) { typeName = "image2D"; @@ -332,41 +319,41 @@ private static String getTypeName(int type) { } private static UniformType getExpectedType(int type) { - if (type == GL20C.GL_FLOAT) { + if (type == GL11.GL_FLOAT) { return UniformType.FLOAT; - } else if (type == GL20C.GL_INT) { + } else if (type == GL11.GL_INT) { return UniformType.INT; - } else if (type == GL20C.GL_FLOAT_MAT4) { + } else if (type == GL20.GL_FLOAT_MAT4) { return UniformType.MAT4; - } else if (type == GL20C.GL_FLOAT_VEC4) { + } else if (type == GL20.GL_FLOAT_VEC4) { return UniformType.VEC4; - } else if (type == GL20C.GL_INT_VEC4) { + } else if (type == GL20.GL_INT_VEC4) { return UniformType.VEC4I; - } else if (type == GL20C.GL_FLOAT_MAT3) { + } else if (type == GL20.GL_FLOAT_MAT3) { return null; - } else if (type == GL20C.GL_FLOAT_VEC3) { + } else if (type == GL20.GL_FLOAT_VEC3) { return UniformType.VEC3; - } else if (type == GL20C.GL_INT_VEC3) { + } else if (type == GL20.GL_INT_VEC3) { return null; - } else if (type == GL20C.GL_FLOAT_MAT2) { + } else if (type == GL20.GL_FLOAT_MAT2) { return null; - } else if (type == GL20C.GL_FLOAT_VEC2) { + } else if (type == GL20.GL_FLOAT_VEC2) { return UniformType.VEC2; - } else if (type == GL20C.GL_INT_VEC2) { + } else if (type == GL20.GL_INT_VEC2) { return UniformType.VEC2I; - } else if (type == GL20C.GL_SAMPLER_3D) { + } else if (type == GL20.GL_SAMPLER_3D) { return UniformType.INT; - } else if (type == GL20C.GL_SAMPLER_2D) { + } else if (type == GL20.GL_SAMPLER_2D) { return UniformType.INT; - } else if (type == GL30C.GL_UNSIGNED_INT_SAMPLER_2D) { + } else if (type == GL30.GL_UNSIGNED_INT_SAMPLER_2D) { return UniformType.INT; - } else if (type == GL30C.GL_UNSIGNED_INT_SAMPLER_3D) { + } else if (type == GL30.GL_UNSIGNED_INT_SAMPLER_3D) { return UniformType.INT; - } else if (type == GL20C.GL_SAMPLER_1D) { + } else if (type == GL20.GL_SAMPLER_1D) { return UniformType.INT; - } else if (type == GL20C.GL_SAMPLER_2D_SHADOW) { + } else if (type == GL20.GL_SAMPLER_2D_SHADOW) { return UniformType.INT; - } else if (type == GL20C.GL_SAMPLER_1D_SHADOW) { + } else if (type == GL20.GL_SAMPLER_1D_SHADOW) { return UniformType.INT; } else { return null; @@ -374,13 +361,13 @@ private static UniformType getExpectedType(int type) { } private static boolean isSampler(int type) { - return type == GL20C.GL_SAMPLER_1D - || type == GL20C.GL_SAMPLER_2D - || type == GL30C.GL_UNSIGNED_INT_SAMPLER_2D - || type == GL30C.GL_UNSIGNED_INT_SAMPLER_3D - || type == GL20C.GL_SAMPLER_3D - || type == GL20C.GL_SAMPLER_1D_SHADOW - || type == GL20C.GL_SAMPLER_2D_SHADOW; + return type == GL20.GL_SAMPLER_1D + || type == GL20.GL_SAMPLER_2D + || type == GL30.GL_UNSIGNED_INT_SAMPLER_2D + || type == GL30.GL_UNSIGNED_INT_SAMPLER_3D + || type == GL20.GL_SAMPLER_3D + || type == GL20.GL_SAMPLER_1D_SHADOW + || type == GL20.GL_SAMPLER_2D_SHADOW; } private static boolean isImage(int type) { diff --git a/src/main/java/net/coderbot/iris/gl/sampler/SamplerLimits.java b/src/main/java/net/coderbot/iris/gl/sampler/SamplerLimits.java index 8f44e5eb48..af98399933 100644 --- a/src/main/java/net/coderbot/iris/gl/sampler/SamplerLimits.java +++ b/src/main/java/net/coderbot/iris/gl/sampler/SamplerLimits.java @@ -1,8 +1,7 @@ package net.coderbot.iris.gl.sampler; -import org.lwjgl.opengl.GL20C; - -import com.mojang.blaze3d.platform.GlStateManager; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL20; public class SamplerLimits { private final int maxTextureUnits; @@ -10,8 +9,8 @@ public class SamplerLimits { private static SamplerLimits instance; private SamplerLimits() { - this.maxTextureUnits = GlStateManager._getInteger(GL20C.GL_MAX_TEXTURE_IMAGE_UNITS); - this.maxDrawBuffers = GlStateManager._getInteger(GL20C.GL_MAX_DRAW_BUFFERS); + this.maxTextureUnits = GlStateManager.glGetInteger(GL20.GL_MAX_TEXTURE_IMAGE_UNITS); + this.maxDrawBuffers = GlStateManager.glGetInteger(GL20.GL_MAX_DRAW_BUFFERS); } public int getMaxTextureUnits() { diff --git a/src/main/java/net/coderbot/iris/gl/shader/GlShader.java b/src/main/java/net/coderbot/iris/gl/shader/GlShader.java index 22920cbca1..1f62703537 100644 --- a/src/main/java/net/coderbot/iris/gl/shader/GlShader.java +++ b/src/main/java/net/coderbot/iris/gl/shader/GlShader.java @@ -2,18 +2,17 @@ package net.coderbot.iris.gl.shader; -import java.util.Locale; - +import net.coderbot.iris.gl.GLDebug; +import net.coderbot.iris.gl.GlResource; +import net.coderbot.iris.gl.IrisRenderSystem; +import net.minecraft.client.renderer.OpenGlHelper; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.lwjgl.opengl.GL20C; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.KHRDebug; -import com.mojang.blaze3d.platform.GlStateManager; - -import net.coderbot.iris.gl.GLDebug; -import net.coderbot.iris.gl.GlResource; -import net.coderbot.iris.gl.IrisRenderSystem; +import java.util.Locale; /** * A compiled OpenGL shader object. @@ -30,9 +29,9 @@ public GlShader(ShaderType type, String name, String src) { } private static int createShader(ShaderType type, String name, String src) { - int handle = GlStateManager.glCreateShader(type.id); + int handle = OpenGlHelper.glCreateShader(type.id); ShaderWorkarounds.safeShaderSource(handle, src); - GlStateManager.glCompileShader(handle); + OpenGlHelper.glCompileShader(handle); GLDebug.nameObject(KHRDebug.GL_SHADER, handle, name + "(" + type.name().toLowerCase(Locale.ROOT) + ")"); @@ -42,9 +41,9 @@ private static int createShader(ShaderType type, String name, String src) { LOGGER.warn("Shader compilation log for " + name + ": " + log); } - int result = GlStateManager.glGetShaderi(handle, GL20C.GL_COMPILE_STATUS); + int result = OpenGlHelper.glGetShaderi(handle, GL20.GL_COMPILE_STATUS); - if (result != GL20C.GL_TRUE) { + if (result != GL11.GL_TRUE) { throw new RuntimeException("Shader compilation failed, see log for details"); } @@ -61,6 +60,6 @@ public int getHandle() { @Override protected void destroyInternal() { - GlStateManager.glDeleteShader(this.getGlId()); + OpenGlHelper.glDeleteShader(this.getGlId()); } } diff --git a/src/main/java/net/coderbot/iris/gl/shader/ProgramCreator.java b/src/main/java/net/coderbot/iris/gl/shader/ProgramCreator.java index 0093a5c16f..07d9b0c790 100644 --- a/src/main/java/net/coderbot/iris/gl/shader/ProgramCreator.java +++ b/src/main/java/net/coderbot/iris/gl/shader/ProgramCreator.java @@ -2,21 +2,20 @@ package net.coderbot.iris.gl.shader; +import net.coderbot.iris.gl.GLDebug; +import net.coderbot.iris.gl.IrisRenderSystem; +import net.minecraft.client.renderer.OpenGlHelper; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.lwjgl.opengl.GL20C; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.KHRDebug; -import com.mojang.blaze3d.platform.GlStateManager; - -import net.coderbot.iris.gl.GLDebug; -import net.coderbot.iris.gl.IrisRenderSystem; - public class ProgramCreator { private static final Logger LOGGER = LogManager.getLogger(ProgramCreator.class); public static int create(String name, GlShader... shaders) { - int program = GlStateManager.glCreateProgram(); + int program = OpenGlHelper.glCreateProgram(); // TODO: This is *really* hardcoded, we need to refactor this to support external calls // to glBindAttribLocation @@ -26,10 +25,10 @@ public static int create(String name, GlShader... shaders) { IrisRenderSystem.bindAttributeLocation(program, 14, "at_midBlock"); for (GlShader shader : shaders) { - GlStateManager.glAttachShader(program, shader.getHandle()); + OpenGlHelper.glAttachShader(program, shader.getHandle()); } - GlStateManager.glLinkProgram(program); + OpenGlHelper.glLinkProgram(program); GLDebug.nameObject(KHRDebug.GL_PROGRAM, program, name); @@ -44,9 +43,9 @@ public static int create(String name, GlShader... shaders) { LOGGER.warn("Program link log for " + name + ": " + log); } - int result = GlStateManager.glGetProgrami(program, GL20C.GL_LINK_STATUS); + int result = OpenGlHelper.glGetProgrami(program, GL20.GL_LINK_STATUS); - if (result != GL20C.GL_TRUE) { + if (result != GL11.GL_TRUE) { throw new RuntimeException("Shader program linking failed, see log for details"); } diff --git a/src/main/java/net/coderbot/iris/gl/shader/ShaderType.java b/src/main/java/net/coderbot/iris/gl/shader/ShaderType.java index 8368c41b22..49d621f11f 100644 --- a/src/main/java/net/coderbot/iris/gl/shader/ShaderType.java +++ b/src/main/java/net/coderbot/iris/gl/shader/ShaderType.java @@ -3,17 +3,17 @@ package net.coderbot.iris.gl.shader; import org.lwjgl.opengl.GL20; -import org.lwjgl.opengl.GL32C; -import org.lwjgl.opengl.GL43C; +import org.lwjgl.opengl.GL32; +import org.lwjgl.opengl.GL43; /** * An enumeration over the supported OpenGL shader types. */ public enum ShaderType { VERTEX(GL20.GL_VERTEX_SHADER), - GEOMETRY(GL32C.GL_GEOMETRY_SHADER), + GEOMETRY(GL32.GL_GEOMETRY_SHADER), FRAGMENT(GL20.GL_FRAGMENT_SHADER), - COMPUTE(GL43C.GL_COMPUTE_SHADER); + COMPUTE(GL43.GL_COMPUTE_SHADER); public final int id; diff --git a/src/main/java/net/coderbot/iris/gl/shader/ShaderWorkarounds.java b/src/main/java/net/coderbot/iris/gl/shader/ShaderWorkarounds.java index a3526aed0d..99b5eacfc4 100644 --- a/src/main/java/net/coderbot/iris/gl/shader/ShaderWorkarounds.java +++ b/src/main/java/net/coderbot/iris/gl/shader/ShaderWorkarounds.java @@ -35,12 +35,11 @@ public class ShaderWorkarounds { * *

Hat tip to fewizz for the find and the fix. */ - public static void safeShaderSource(int glId, CharSequence source) { + public static void safeShaderSource(int glId, ByteBuffer sourceBuffer) { final MemoryStack stack = MemoryStack.stackGet(); final int stackPointer = stack.getPointer(); try { - final ByteBuffer sourceBuffer = MemoryUtil.memUTF8(source, true); final PointerBuffer pointers = stack.mallocPointer(1); pointers.put(sourceBuffer); diff --git a/src/main/java/net/coderbot/iris/gl/shader/StandardMacros.java b/src/main/java/net/coderbot/iris/gl/shader/StandardMacros.java index ea2bece1a3..d37f419e34 100644 --- a/src/main/java/net/coderbot/iris/gl/shader/StandardMacros.java +++ b/src/main/java/net/coderbot/iris/gl/shader/StandardMacros.java @@ -1,31 +1,20 @@ package net.coderbot.iris.gl.shader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL20C; - import com.google.common.collect.ImmutableList; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.platform.GlUtil; - import net.coderbot.iris.pipeline.HandRenderer; import net.coderbot.iris.pipeline.WorldRenderingPhase; import net.coderbot.iris.shaderpack.StringPair; import net.coderbot.iris.texture.format.TextureFormat; import net.coderbot.iris.texture.format.TextureFormatLoader; -import net.minecraft.SharedConstants; -import net.minecraft.Util; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.Util; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL20; + +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; public class StandardMacros { private static final Pattern SEMVER_PATTERN = Pattern.compile("(?\\d+)\\.(?\\d+)\\.*(?\\d*)(.*)"); @@ -42,8 +31,8 @@ public static Iterable createStandardEnvironmentDefines() { ArrayList standardDefines = new ArrayList<>(); define(standardDefines, "MC_VERSION", getMcVersion()); - define(standardDefines, "MC_GL_VERSION", getGlVersion(GL20C.GL_VERSION)); - define(standardDefines, "MC_GLSL_VERSION", getGlVersion(GL20C.GL_SHADING_LANGUAGE_VERSION)); + define(standardDefines, "MC_GL_VERSION", getGlVersion(GL11.GL_VERSION)); + define(standardDefines, "MC_GLSL_VERSION", getGlVersion(GL20.GL_SHADING_LANGUAGE_VERSION)); define(standardDefines, getOsString()); define(standardDefines, getVendor()); define(standardDefines, getRenderer()); @@ -81,16 +70,12 @@ public static Iterable createStandardEnvironmentDefines() { * @see Optifine Doc */ public static String getMcVersion() { - String version = SharedConstants.getCurrentVersion().getReleaseTarget(); + String version = "1.12.2"; // release target so snapshots are set to the higher version // // For example if we were running iris on 21w07a, getReleaseTarget() would return 1.17 - if (version == null) { - throw new IllegalStateException("Could not get the current minecraft version!"); - } - - String[] splitVersion = version.split("\\."); + String[] splitVersion = version.split("\\."); if (splitVersion.length < 2) { throw new IllegalStateException("Could not parse game version \"" + version + "\""); @@ -125,7 +110,7 @@ public static String getMcVersion() { * @see Optifine Doc for GLSL Version */ public static String getGlVersion(int name) { - String info = GlStateManager._getString(name); + String info = GlStateManager.glGetString(name); Matcher matcher = SEMVER_PATTERN.matcher(Objects.requireNonNull(info)); @@ -172,7 +157,7 @@ public static String group(Matcher matcher, String name) { * @see Optifine Doc */ public static String getOsString() { - switch (Util.getPlatform()) { + switch (Util.getOSType()) { case OSX: return "MC_OS_MAC"; case LINUX: @@ -193,7 +178,7 @@ public static String getOsString() { * @see Optifine Doc */ public static String getVendor() { - String vendor = Objects.requireNonNull(GlUtil.getVendor()).toLowerCase(Locale.ROOT); + String vendor = Objects.requireNonNull(GlStateManager.glGetString(GL11.GL_VENDOR)).toLowerCase(Locale.ROOT); if (vendor.startsWith("ati")) { return "MC_GL_VENDOR_ATI"; } else if (vendor.startsWith("intel")) { @@ -215,7 +200,7 @@ public static String getVendor() { * @see Optifine Doc */ public static String getRenderer() { - String renderer = Objects.requireNonNull(GlUtil.getRenderer()).toLowerCase(Locale.ROOT); + String renderer = Objects.requireNonNull(GlStateManager.glGetString(GL11.GL_RENDERER)).toLowerCase(Locale.ROOT); if (renderer.startsWith("amd")) { return "MC_GL_RENDERER_RADEON"; } else if (renderer.startsWith("ati")) { @@ -248,7 +233,7 @@ public static String getRenderer() { * @see Optifine Doc */ public static Set getGlExtensions() { - String[] extensions = Objects.requireNonNull(GlStateManager._getString(GL11.GL_EXTENSIONS)).split("\\s+"); + String[] extensions = Objects.requireNonNull(GlStateManager.glGetString(GL11.GL_EXTENSIONS)).split("\\s+"); // TODO note that we do not add extensions based on if the shader uses them and if they are supported // see https://github.com/sp614x/optifine/blob/master/OptiFineDoc/doc/shaders.txt#L738 diff --git a/src/main/java/net/coderbot/iris/gl/texture/DepthBufferFormat.java b/src/main/java/net/coderbot/iris/gl/texture/DepthBufferFormat.java index c3e7db5c5b..952c00b98d 100644 --- a/src/main/java/net/coderbot/iris/gl/texture/DepthBufferFormat.java +++ b/src/main/java/net/coderbot/iris/gl/texture/DepthBufferFormat.java @@ -1,8 +1,10 @@ package net.coderbot.iris.gl.texture; -import org.jetbrains.annotations.Nullable; -import org.lwjgl.opengl.GL30C; -import org.lwjgl.opengl.GL43C; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; +import org.lwjgl.opengl.GL30; + +import javax.annotation.Nullable; public enum DepthBufferFormat { DEPTH(false), @@ -23,14 +25,14 @@ public enum DepthBufferFormat { @Nullable public static DepthBufferFormat fromGlEnum(int glenum) { switch (glenum) { - case GL30C.GL_DEPTH_COMPONENT: return DepthBufferFormat.DEPTH; - case GL30C.GL_DEPTH_COMPONENT16: return DepthBufferFormat.DEPTH16; - case GL30C.GL_DEPTH_COMPONENT24: return DepthBufferFormat.DEPTH24; - case GL30C.GL_DEPTH_COMPONENT32: return DepthBufferFormat.DEPTH32; - case GL30C.GL_DEPTH_COMPONENT32F: return DepthBufferFormat.DEPTH32F; - case GL30C.GL_DEPTH_STENCIL: return DepthBufferFormat.DEPTH_STENCIL; - case GL30C.GL_DEPTH24_STENCIL8: return DepthBufferFormat.DEPTH24_STENCIL8; - case GL30C.GL_DEPTH32F_STENCIL8: return DepthBufferFormat.DEPTH32F_STENCIL8; + case GL11.GL_DEPTH_COMPONENT: return DepthBufferFormat.DEPTH; + case GL14.GL_DEPTH_COMPONENT16: return DepthBufferFormat.DEPTH16; + case GL14.GL_DEPTH_COMPONENT24: return DepthBufferFormat.DEPTH24; + case GL14.GL_DEPTH_COMPONENT32: return DepthBufferFormat.DEPTH32; + case GL30.GL_DEPTH_COMPONENT32F: return DepthBufferFormat.DEPTH32F; + case GL30.GL_DEPTH_STENCIL: return DepthBufferFormat.DEPTH_STENCIL; + case GL30.GL_DEPTH24_STENCIL8: return DepthBufferFormat.DEPTH24_STENCIL8; + case GL30.GL_DEPTH32F_STENCIL8: return DepthBufferFormat.DEPTH32F_STENCIL8; default: return null; } } @@ -47,45 +49,45 @@ public static DepthBufferFormat fromGlEnumOrDefault(int glenum) { public int getGlInternalFormat() { switch (this) { case DEPTH: - return GL30C.GL_DEPTH_COMPONENT; + return GL11.GL_DEPTH_COMPONENT; case DEPTH16: - return GL30C.GL_DEPTH_COMPONENT16; + return GL14.GL_DEPTH_COMPONENT16; case DEPTH24: - return GL30C.GL_DEPTH_COMPONENT24; + return GL14.GL_DEPTH_COMPONENT24; case DEPTH32: - return GL30C.GL_DEPTH_COMPONENT32; + return GL14.GL_DEPTH_COMPONENT32; case DEPTH32F: - return GL30C.GL_DEPTH_COMPONENT32F; + return GL30.GL_DEPTH_COMPONENT32F; case DEPTH_STENCIL: - return GL30C.GL_DEPTH_STENCIL; + return GL30.GL_DEPTH_STENCIL; case DEPTH24_STENCIL8: - return GL30C.GL_DEPTH24_STENCIL8; + return GL30.GL_DEPTH24_STENCIL8; case DEPTH32F_STENCIL8: - return GL30C.GL_DEPTH32F_STENCIL8; + return GL30.GL_DEPTH32F_STENCIL8; } throw new AssertionError("unreachable"); } public int getGlType() { - return isCombinedStencil() ? GL30C.GL_DEPTH_STENCIL : GL30C.GL_DEPTH_COMPONENT; + return isCombinedStencil() ? GL30.GL_DEPTH_STENCIL : GL11.GL_DEPTH_COMPONENT; } public int getGlFormat() { switch (this) { case DEPTH: case DEPTH16: - return GL43C.GL_UNSIGNED_SHORT; + return GL11.GL_UNSIGNED_SHORT; case DEPTH24: case DEPTH32: - return GL43C.GL_UNSIGNED_INT; + return GL11.GL_UNSIGNED_INT; case DEPTH32F: - return GL30C.GL_FLOAT; + return GL11.GL_FLOAT; case DEPTH_STENCIL: case DEPTH24_STENCIL8: - return GL30C.GL_UNSIGNED_INT_24_8; + return GL30.GL_UNSIGNED_INT_24_8; case DEPTH32F_STENCIL8: - return GL30C.GL_FLOAT_32_UNSIGNED_INT_24_8_REV; + return GL30.GL_FLOAT_32_UNSIGNED_INT_24_8_REV; } throw new AssertionError("unreachable"); diff --git a/src/main/java/net/coderbot/iris/gl/texture/DepthCopyStrategy.java b/src/main/java/net/coderbot/iris/gl/texture/DepthCopyStrategy.java index 80bd844b2c..7376fed1aa 100644 --- a/src/main/java/net/coderbot/iris/gl/texture/DepthCopyStrategy.java +++ b/src/main/java/net/coderbot/iris/gl/texture/DepthCopyStrategy.java @@ -1,13 +1,11 @@ package net.coderbot.iris.gl.texture; -import org.lwjgl.opengl.GL; -import org.lwjgl.opengl.GL20C; -import org.lwjgl.opengl.GL30C; -import org.lwjgl.opengl.GL43C; -import org.lwjgl.system.MemoryUtil; - import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.framebuffer.GlFramebuffer; +import org.lwjgl.opengl.GL; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL43; +import org.lwjgl.system.MemoryUtil; public interface DepthCopyStrategy { // FB -> T @@ -28,7 +26,7 @@ public void copy(GlFramebuffer sourceFb, int sourceTexture, GlFramebuffer destFb IrisRenderSystem.copyTexSubImage2D( destTexture, // target - GL20C.GL_TEXTURE_2D, + GL11.GL_TEXTURE_2D, // level 0, // xoffset, yoffset @@ -57,8 +55,8 @@ public boolean needsDestFramebuffer() { public void copy(GlFramebuffer sourceFb, int sourceTexture, GlFramebuffer destFb, int destTexture, int width, int height) { IrisRenderSystem.blitFramebuffer(sourceFb.getId(), destFb.getId(), 0, 0, width, height, 0, 0, width, height, - GL30C.GL_DEPTH_BUFFER_BIT | GL30C.GL_STENCIL_BUFFER_BIT, - GL30C.GL_NEAREST); + GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT, + GL11.GL_NEAREST); } } @@ -76,15 +74,15 @@ public boolean needsDestFramebuffer() { @Override public void copy(GlFramebuffer sourceFb, int sourceTexture, GlFramebuffer destFb, int destTexture, int width, int height) { - GL43C.glCopyImageSubData( + GL43.glCopyImageSubData( sourceTexture, - GL43C.GL_TEXTURE_2D, + GL11.GL_TEXTURE_2D, 0, 0, 0, 0, destTexture, - GL43C.GL_TEXTURE_2D, + GL11.GL_TEXTURE_2D, 0, 0, 0, diff --git a/src/main/java/net/coderbot/iris/gl/texture/InternalTextureFormat.java b/src/main/java/net/coderbot/iris/gl/texture/InternalTextureFormat.java index dd12354ea3..5989fd543e 100644 --- a/src/main/java/net/coderbot/iris/gl/texture/InternalTextureFormat.java +++ b/src/main/java/net/coderbot/iris/gl/texture/InternalTextureFormat.java @@ -1,83 +1,82 @@ package net.coderbot.iris.gl.texture; -import java.util.Optional; - -import org.lwjgl.opengl.GL11C; -import org.lwjgl.opengl.GL30C; -import org.lwjgl.opengl.GL31C; - import net.coderbot.iris.gl.GlVersion; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL30; +import org.lwjgl.opengl.GL31; + +import java.util.Optional; public enum InternalTextureFormat { // Default // TODO: This technically shouldn't be exposed to shaders since it's not in the specification, it's the default anyways - RGBA(GL11C.GL_RGBA, GlVersion.GL_11, PixelFormat.RGBA), + RGBA(GL11.GL_RGBA, GlVersion.GL_11, PixelFormat.RGBA), // 8-bit normalized - R8(GL30C.GL_R8, GlVersion.GL_30, PixelFormat.RED), - RG8(GL30C.GL_RG8, GlVersion.GL_30, PixelFormat.RG), - RGB8(GL11C.GL_RGB8, GlVersion.GL_11, PixelFormat.RGB), - RGBA8(GL11C.GL_RGBA8, GlVersion.GL_11, PixelFormat.RGBA), + R8(GL30.GL_R8, GlVersion.GL_30, PixelFormat.RED), + RG8(GL30.GL_RG8, GlVersion.GL_30, PixelFormat.RG), + RGB8(GL11.GL_RGB8, GlVersion.GL_11, PixelFormat.RGB), + RGBA8(GL11.GL_RGBA8, GlVersion.GL_11, PixelFormat.RGBA), // 8-bit signed normalized - R8_SNORM(GL31C.GL_R8_SNORM, GlVersion.GL_31, PixelFormat.RED), - RG8_SNORM(GL31C.GL_RG8_SNORM, GlVersion.GL_31, PixelFormat.RG), - RGB8_SNORM(GL31C.GL_RGB8_SNORM, GlVersion.GL_31, PixelFormat.RGB), - RGBA8_SNORM(GL31C.GL_RGBA8_SNORM, GlVersion.GL_31, PixelFormat.RGBA), + R8_SNORM(GL31.GL_R8_SNORM, GlVersion.GL_31, PixelFormat.RED), + RG8_SNORM(GL31.GL_RG8_SNORM, GlVersion.GL_31, PixelFormat.RG), + RGB8_SNORM(GL31.GL_RGB8_SNORM, GlVersion.GL_31, PixelFormat.RGB), + RGBA8_SNORM(GL31.GL_RGBA8_SNORM, GlVersion.GL_31, PixelFormat.RGBA), // 16-bit normalized - R16(GL30C.GL_R16, GlVersion.GL_30, PixelFormat.RED), - RG16(GL30C.GL_RG16, GlVersion.GL_30, PixelFormat.RG), - RGB16(GL11C.GL_RGB16, GlVersion.GL_11, PixelFormat.RGB), - RGBA16(GL11C.GL_RGBA16, GlVersion.GL_11, PixelFormat.RGBA), + R16(GL30.GL_R16, GlVersion.GL_30, PixelFormat.RED), + RG16(GL30.GL_RG16, GlVersion.GL_30, PixelFormat.RG), + RGB16(GL11.GL_RGB16, GlVersion.GL_11, PixelFormat.RGB), + RGBA16(GL11.GL_RGBA16, GlVersion.GL_11, PixelFormat.RGBA), // 16-bit signed normalized - R16_SNORM(GL31C.GL_R16_SNORM, GlVersion.GL_31, PixelFormat.RED), - RG16_SNORM(GL31C.GL_RG16_SNORM, GlVersion.GL_31, PixelFormat.RG), - RGB16_SNORM(GL31C.GL_RGB16_SNORM, GlVersion.GL_31, PixelFormat.RGB), - RGBA16_SNORM(GL31C.GL_RGBA16_SNORM, GlVersion.GL_31, PixelFormat.RGBA), + R16_SNORM(GL31.GL_R16_SNORM, GlVersion.GL_31, PixelFormat.RED), + RG16_SNORM(GL31.GL_RG16_SNORM, GlVersion.GL_31, PixelFormat.RG), + RGB16_SNORM(GL31.GL_RGB16_SNORM, GlVersion.GL_31, PixelFormat.RGB), + RGBA16_SNORM(GL31.GL_RGBA16_SNORM, GlVersion.GL_31, PixelFormat.RGBA), // 16-bit float - R16F(GL30C.GL_R16F, GlVersion.GL_30, PixelFormat.RED), - RG16F(GL30C.GL_RG16F, GlVersion.GL_30, PixelFormat.RG), - RGB16F(GL30C.GL_RGB16F, GlVersion.GL_30, PixelFormat.RGB), - RGBA16F(GL30C.GL_RGBA16F, GlVersion.GL_30, PixelFormat.RGBA), + R16F(GL30.GL_R16F, GlVersion.GL_30, PixelFormat.RED), + RG16F(GL30.GL_RG16F, GlVersion.GL_30, PixelFormat.RG), + RGB16F(GL30.GL_RGB16F, GlVersion.GL_30, PixelFormat.RGB), + RGBA16F(GL30.GL_RGBA16F, GlVersion.GL_30, PixelFormat.RGBA), // 32-bit float - R32F(GL30C.GL_R32F, GlVersion.GL_30, PixelFormat.RED), - RG32F(GL30C.GL_RG32F, GlVersion.GL_30, PixelFormat.RG), - RGB32F(GL30C.GL_RGB32F, GlVersion.GL_30, PixelFormat.RGB), - RGBA32F(GL30C.GL_RGBA32F, GlVersion.GL_30, PixelFormat.RGBA), + R32F(GL30.GL_R32F, GlVersion.GL_30, PixelFormat.RED), + RG32F(GL30.GL_RG32F, GlVersion.GL_30, PixelFormat.RG), + RGB32F(GL30.GL_RGB32F, GlVersion.GL_30, PixelFormat.RGB), + RGBA32F(GL30.GL_RGBA32F, GlVersion.GL_30, PixelFormat.RGBA), // 8-bit integer - R8I(GL30C.GL_R8I, GlVersion.GL_30, PixelFormat.RED_INTEGER), - RG8I(GL30C.GL_RG8I, GlVersion.GL_30, PixelFormat.RG_INTEGER), - RGB8I(GL30C.GL_RGB8I, GlVersion.GL_30, PixelFormat.RGB_INTEGER), - RGBA8I(GL30C.GL_RGBA8I, GlVersion.GL_30, PixelFormat.RGBA_INTEGER), + R8I(GL30.GL_R8I, GlVersion.GL_30, PixelFormat.RED_INTEGER), + RG8I(GL30.GL_RG8I, GlVersion.GL_30, PixelFormat.RG_INTEGER), + RGB8I(GL30.GL_RGB8I, GlVersion.GL_30, PixelFormat.RGB_INTEGER), + RGBA8I(GL30.GL_RGBA8I, GlVersion.GL_30, PixelFormat.RGBA_INTEGER), // 8-bit unsigned integer - R8UI(GL30C.GL_R8UI, GlVersion.GL_30, PixelFormat.RED_INTEGER), - RG8UI(GL30C.GL_RG8UI, GlVersion.GL_30, PixelFormat.RG_INTEGER), - RGB8UI(GL30C.GL_RGB8UI, GlVersion.GL_30, PixelFormat.RGB_INTEGER), - RGBA8UI(GL30C.GL_RGBA8UI, GlVersion.GL_30, PixelFormat.RGBA_INTEGER), + R8UI(GL30.GL_R8UI, GlVersion.GL_30, PixelFormat.RED_INTEGER), + RG8UI(GL30.GL_RG8UI, GlVersion.GL_30, PixelFormat.RG_INTEGER), + RGB8UI(GL30.GL_RGB8UI, GlVersion.GL_30, PixelFormat.RGB_INTEGER), + RGBA8UI(GL30.GL_RGBA8UI, GlVersion.GL_30, PixelFormat.RGBA_INTEGER), // 16-bit integer - R16I(GL30C.GL_R16I, GlVersion.GL_30, PixelFormat.RED_INTEGER), - RG16I(GL30C.GL_RG16I, GlVersion.GL_30, PixelFormat.RG_INTEGER), - RGB16I(GL30C.GL_RGB16I, GlVersion.GL_30, PixelFormat.RGB_INTEGER), - RGBA16I(GL30C.GL_RGBA16I, GlVersion.GL_30, PixelFormat.RGBA_INTEGER), + R16I(GL30.GL_R16I, GlVersion.GL_30, PixelFormat.RED_INTEGER), + RG16I(GL30.GL_RG16I, GlVersion.GL_30, PixelFormat.RG_INTEGER), + RGB16I(GL30.GL_RGB16I, GlVersion.GL_30, PixelFormat.RGB_INTEGER), + RGBA16I(GL30.GL_RGBA16I, GlVersion.GL_30, PixelFormat.RGBA_INTEGER), // 16-bit unsigned integer - R16UI(GL30C.GL_R16UI, GlVersion.GL_30, PixelFormat.RED_INTEGER), - RG16UI(GL30C.GL_RG16UI, GlVersion.GL_30, PixelFormat.RG_INTEGER), - RGB16UI(GL30C.GL_RGB16UI, GlVersion.GL_30, PixelFormat.RGB_INTEGER), - RGBA16UI(GL30C.GL_RGBA16UI, GlVersion.GL_30, PixelFormat.RGBA_INTEGER), + R16UI(GL30.GL_R16UI, GlVersion.GL_30, PixelFormat.RED_INTEGER), + RG16UI(GL30.GL_RG16UI, GlVersion.GL_30, PixelFormat.RG_INTEGER), + RGB16UI(GL30.GL_RGB16UI, GlVersion.GL_30, PixelFormat.RGB_INTEGER), + RGBA16UI(GL30.GL_RGBA16UI, GlVersion.GL_30, PixelFormat.RGBA_INTEGER), // 32-bit integer - R32I(GL30C.GL_R32I, GlVersion.GL_30, PixelFormat.RED_INTEGER), - RG32I(GL30C.GL_RG32I, GlVersion.GL_30, PixelFormat.RG_INTEGER), - RGB32I(GL30C.GL_RGB32I, GlVersion.GL_30, PixelFormat.RGB_INTEGER), - RGBA32I(GL30C.GL_RGBA32I, GlVersion.GL_30, PixelFormat.RGBA_INTEGER), + R32I(GL30.GL_R32I, GlVersion.GL_30, PixelFormat.RED_INTEGER), + RG32I(GL30.GL_RG32I, GlVersion.GL_30, PixelFormat.RG_INTEGER), + RGB32I(GL30.GL_RGB32I, GlVersion.GL_30, PixelFormat.RGB_INTEGER), + RGBA32I(GL30.GL_RGBA32I, GlVersion.GL_30, PixelFormat.RGBA_INTEGER), // 32-bit unsigned integer - R32UI(GL30C.GL_R32UI, GlVersion.GL_30, PixelFormat.RED_INTEGER), - RG32UI(GL30C.GL_RG32UI, GlVersion.GL_30, PixelFormat.RG_INTEGER), - RGB32UI(GL30C.GL_RGB32UI, GlVersion.GL_30, PixelFormat.RGB_INTEGER), - RGBA32UI(GL30C.GL_RGBA32UI, GlVersion.GL_30, PixelFormat.RGBA_INTEGER), + R32UI(GL30.GL_R32UI, GlVersion.GL_30, PixelFormat.RED_INTEGER), + RG32UI(GL30.GL_RG32UI, GlVersion.GL_30, PixelFormat.RG_INTEGER), + RGB32UI(GL30.GL_RGB32UI, GlVersion.GL_30, PixelFormat.RGB_INTEGER), + RGBA32UI(GL30.GL_RGBA32UI, GlVersion.GL_30, PixelFormat.RGBA_INTEGER), // Mixed - R3_G3_B2(GL11C.GL_R3_G3_B2, GlVersion.GL_11, PixelFormat.RGB), - RGB5_A1(GL11C.GL_RGB5_A1, GlVersion.GL_11, PixelFormat.RGBA), - RGB10_A2(GL11C.GL_RGB10_A2, GlVersion.GL_11, PixelFormat.RGBA), - R11F_G11F_B10F(GL30C.GL_R11F_G11F_B10F, GlVersion.GL_30, PixelFormat.RGB), - RGB9_E5(GL30C.GL_RGB9_E5, GlVersion.GL_30, PixelFormat.RGB); + R3_G3_B2(GL11.GL_R3_G3_B2, GlVersion.GL_11, PixelFormat.RGB), + RGB5_A1(GL11.GL_RGB5_A1, GlVersion.GL_11, PixelFormat.RGBA), + RGB10_A2(GL11.GL_RGB10_A2, GlVersion.GL_11, PixelFormat.RGBA), + R11F_G11F_B10F(GL30.GL_R11F_G11F_B10F, GlVersion.GL_30, PixelFormat.RGB), + RGB9_E5(GL30.GL_RGB9_E5, GlVersion.GL_30, PixelFormat.RGB); private final int glFormat; private final GlVersion minimumGlVersion; diff --git a/src/main/java/net/coderbot/iris/gl/texture/PixelFormat.java b/src/main/java/net/coderbot/iris/gl/texture/PixelFormat.java index 31bbe0d1e1..338dd3f7c8 100644 --- a/src/main/java/net/coderbot/iris/gl/texture/PixelFormat.java +++ b/src/main/java/net/coderbot/iris/gl/texture/PixelFormat.java @@ -1,26 +1,25 @@ package net.coderbot.iris.gl.texture; -import java.util.Optional; - -import org.lwjgl.opengl.GL11C; -import org.lwjgl.opengl.GL12C; -import org.lwjgl.opengl.GL30C; - import net.coderbot.iris.gl.GlVersion; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import org.lwjgl.opengl.GL30; + +import java.util.Optional; public enum PixelFormat { - RED(GL11C.GL_RED, GlVersion.GL_11, false), - RG(GL30C.GL_RG, GlVersion.GL_30, false), - RGB(GL11C.GL_RGB, GlVersion.GL_11, false), - BGR(GL12C.GL_BGR, GlVersion.GL_12, false), - RGBA(GL11C.GL_RGBA, GlVersion.GL_11, false), - BGRA(GL12C.GL_BGRA, GlVersion.GL_12, false), - RED_INTEGER(GL30C.GL_RED_INTEGER, GlVersion.GL_30, true), - RG_INTEGER(GL30C.GL_RG_INTEGER, GlVersion.GL_30, true), - RGB_INTEGER(GL30C.GL_RGB_INTEGER, GlVersion.GL_30, true), - BGR_INTEGER(GL30C.GL_BGR_INTEGER, GlVersion.GL_30, true), - RGBA_INTEGER(GL30C.GL_RGBA_INTEGER, GlVersion.GL_30, true), - BGRA_INTEGER(GL30C.GL_BGRA_INTEGER, GlVersion.GL_30, true); + RED(GL11.GL_RED, GlVersion.GL_11, false), + RG(GL30.GL_RG, GlVersion.GL_30, false), + RGB(GL11.GL_RGB, GlVersion.GL_11, false), + BGR(GL12.GL_BGR, GlVersion.GL_12, false), + RGBA(GL11.GL_RGBA, GlVersion.GL_11, false), + BGRA(GL12.GL_BGRA, GlVersion.GL_12, false), + RED_INTEGER(GL30.GL_RED_INTEGER, GlVersion.GL_30, true), + RG_INTEGER(GL30.GL_RG_INTEGER, GlVersion.GL_30, true), + RGB_INTEGER(GL30.GL_RGB_INTEGER, GlVersion.GL_30, true), + BGR_INTEGER(GL30.GL_BGR_INTEGER, GlVersion.GL_30, true), + RGBA_INTEGER(GL30.GL_RGBA_INTEGER, GlVersion.GL_30, true), + BGRA_INTEGER(GL30.GL_BGRA_INTEGER, GlVersion.GL_30, true); private final int glFormat; private final GlVersion minimumGlVersion; diff --git a/src/main/java/net/coderbot/iris/gl/texture/PixelType.java b/src/main/java/net/coderbot/iris/gl/texture/PixelType.java index 7247825fc3..7457b2faf0 100644 --- a/src/main/java/net/coderbot/iris/gl/texture/PixelType.java +++ b/src/main/java/net/coderbot/iris/gl/texture/PixelType.java @@ -1,34 +1,33 @@ package net.coderbot.iris.gl.texture; -import java.util.Optional; - -import org.lwjgl.opengl.GL11C; -import org.lwjgl.opengl.GL12C; -import org.lwjgl.opengl.GL30C; - import net.coderbot.iris.gl.GlVersion; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import org.lwjgl.opengl.GL30; + +import java.util.Optional; public enum PixelType { - BYTE(GL11C.GL_BYTE, GlVersion.GL_11), - SHORT(GL11C.GL_SHORT, GlVersion.GL_11), - INT(GL11C.GL_INT, GlVersion.GL_11), - HALF_FLOAT(GL30C.GL_HALF_FLOAT, GlVersion.GL_30), - FLOAT(GL11C.GL_FLOAT, GlVersion.GL_11), - UNSIGNED_BYTE(GL11C.GL_UNSIGNED_BYTE, GlVersion.GL_11), - UNSIGNED_BYTE_3_3_2(GL12C.GL_UNSIGNED_BYTE_3_3_2, GlVersion.GL_12), - UNSIGNED_BYTE_2_3_3_REV(GL12C.GL_UNSIGNED_BYTE_2_3_3_REV, GlVersion.GL_12), - UNSIGNED_SHORT(GL11C.GL_UNSIGNED_SHORT, GlVersion.GL_11), - UNSIGNED_SHORT_5_6_5(GL12C.GL_UNSIGNED_SHORT_5_6_5, GlVersion.GL_12), - UNSIGNED_SHORT_5_6_5_REV(GL12C.GL_UNSIGNED_SHORT_5_6_5_REV, GlVersion.GL_12), - UNSIGNED_SHORT_4_4_4_4(GL12C.GL_UNSIGNED_SHORT_4_4_4_4, GlVersion.GL_12), - UNSIGNED_SHORT_4_4_4_4_REV(GL12C.GL_UNSIGNED_SHORT_4_4_4_4_REV, GlVersion.GL_12), - UNSIGNED_SHORT_5_5_5_1(GL12C.GL_UNSIGNED_SHORT_5_5_5_1, GlVersion.GL_12), - UNSIGNED_SHORT_1_5_5_5_REV(GL12C.GL_UNSIGNED_SHORT_1_5_5_5_REV, GlVersion.GL_12), - UNSIGNED_INT(GL11C.GL_UNSIGNED_BYTE, GlVersion.GL_11), - UNSIGNED_INT_8_8_8_8(GL12C.GL_UNSIGNED_INT_8_8_8_8, GlVersion.GL_12), - UNSIGNED_INT_8_8_8_8_REV(GL12C.GL_UNSIGNED_INT_8_8_8_8_REV, GlVersion.GL_12), - UNSIGNED_INT_10_10_10_2(GL12C.GL_UNSIGNED_INT_10_10_10_2, GlVersion.GL_12), - UNSIGNED_INT_2_10_10_10_REV(GL12C.GL_UNSIGNED_INT_2_10_10_10_REV, GlVersion.GL_12); + BYTE(GL11.GL_BYTE, GlVersion.GL_11), + SHORT(GL11.GL_SHORT, GlVersion.GL_11), + INT(GL11.GL_INT, GlVersion.GL_11), + HALF_FLOAT(GL30.GL_HALF_FLOAT, GlVersion.GL_30), + FLOAT(GL11.GL_FLOAT, GlVersion.GL_11), + UNSIGNED_BYTE(GL11.GL_UNSIGNED_BYTE, GlVersion.GL_11), + UNSIGNED_BYTE_3_3_2(GL12.GL_UNSIGNED_BYTE_3_3_2, GlVersion.GL_12), + UNSIGNED_BYTE_2_3_3_REV(GL12.GL_UNSIGNED_BYTE_2_3_3_REV, GlVersion.GL_12), + UNSIGNED_SHORT(GL11.GL_UNSIGNED_SHORT, GlVersion.GL_11), + UNSIGNED_SHORT_5_6_5(GL12.GL_UNSIGNED_SHORT_5_6_5, GlVersion.GL_12), + UNSIGNED_SHORT_5_6_5_REV(GL12.GL_UNSIGNED_SHORT_5_6_5_REV, GlVersion.GL_12), + UNSIGNED_SHORT_4_4_4_4(GL12.GL_UNSIGNED_SHORT_4_4_4_4, GlVersion.GL_12), + UNSIGNED_SHORT_4_4_4_4_REV(GL12.GL_UNSIGNED_SHORT_4_4_4_4_REV, GlVersion.GL_12), + UNSIGNED_SHORT_5_5_5_1(GL12.GL_UNSIGNED_SHORT_5_5_5_1, GlVersion.GL_12), + UNSIGNED_SHORT_1_5_5_5_REV(GL12.GL_UNSIGNED_SHORT_1_5_5_5_REV, GlVersion.GL_12), + UNSIGNED_INT(GL11.GL_UNSIGNED_BYTE, GlVersion.GL_11), + UNSIGNED_INT_8_8_8_8(GL12.GL_UNSIGNED_INT_8_8_8_8, GlVersion.GL_12), + UNSIGNED_INT_8_8_8_8_REV(GL12.GL_UNSIGNED_INT_8_8_8_8_REV, GlVersion.GL_12), + UNSIGNED_INT_10_10_10_2(GL12.GL_UNSIGNED_INT_10_10_10_2, GlVersion.GL_12), + UNSIGNED_INT_2_10_10_10_REV(GL12.GL_UNSIGNED_INT_2_10_10_10_REV, GlVersion.GL_12); private final int glFormat; private final GlVersion minimumGlVersion; diff --git a/src/main/java/net/coderbot/iris/gl/texture/TextureUploadHelper.java b/src/main/java/net/coderbot/iris/gl/texture/TextureUploadHelper.java index d7dd5dbc3f..79dc683ad4 100644 --- a/src/main/java/net/coderbot/iris/gl/texture/TextureUploadHelper.java +++ b/src/main/java/net/coderbot/iris/gl/texture/TextureUploadHelper.java @@ -1,8 +1,7 @@ package net.coderbot.iris.gl.texture; -import org.lwjgl.opengl.GL20C; - -import com.mojang.blaze3d.platform.GlStateManager; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL11; public class TextureUploadHelper { private TextureUploadHelper() { @@ -16,9 +15,9 @@ public static void resetTextureUploadState() { // It is likely that this also avoids the crashes on AMD that I previously experienced with texture creation. // // This code is from Canvas: https://github.com/grondag/canvas/commit/f0ab652d7a8b7cc9febf0209bee15cffce9eac83 - GlStateManager._pixelStore(GL20C.GL_UNPACK_ROW_LENGTH, 0); - GlStateManager._pixelStore(GL20C.GL_UNPACK_SKIP_ROWS, 0); - GlStateManager._pixelStore(GL20C.GL_UNPACK_SKIP_PIXELS, 0); - GlStateManager._pixelStore(GL20C.GL_UNPACK_ALIGNMENT, 4); + GlStateManager.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, 0); + GlStateManager.glPixelStorei(GL11.GL_UNPACK_SKIP_ROWS, 0); + GlStateManager.glPixelStorei(GL11.GL_UNPACK_SKIP_PIXELS, 0); + GlStateManager.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 4); } } diff --git a/src/main/java/net/coderbot/iris/gui/FeatureMissingErrorScreen.java b/src/main/java/net/coderbot/iris/gui/FeatureMissingErrorScreen.java index 8ad5ec8718..4658d269eb 100644 --- a/src/main/java/net/coderbot/iris/gui/FeatureMissingErrorScreen.java +++ b/src/main/java/net/coderbot/iris/gui/FeatureMissingErrorScreen.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.MultiLineLabel; import net.minecraft.client.gui.screens.ErrorScreen; @@ -10,27 +11,27 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; -public class FeatureMissingErrorScreen extends Screen { - private final Screen parent; +public class FeatureMissingErrorScreen extends GuiScreen { + private final GuiScreen parent; private MultiLineLabel message; private final FormattedText messageTemp; - public FeatureMissingErrorScreen(Screen parent, Component title, Component message) { + public FeatureMissingErrorScreen(GuiScreen parent, Component title, Component message) { super(title); this.parent = parent; this.messageTemp = message; } @Override - protected void init() { - super.init(); + public void initGui() { + super.initGui(); this.message = MultiLineLabel.create(this.font, messageTemp, this.width - 50); this.addButton(new Button(this.width / 2 - 100, 140, 200, 20, CommonComponents.GUI_BACK, arg -> this.minecraft.setScreen(parent))); } @Override - public void render(PoseStack poseStack, int mouseX, int mouseY, float delta) { - this.renderBackground(poseStack); + public void render(int mouseX, int mouseY, float delta) { + this.drawBackground(0); ErrorScreen.drawCenteredString(poseStack, this.font, this.title, this.width / 2, 90, 0xFFFFFF); message.renderCentered(poseStack, this.width / 2, 110, 9, 0xFFFFFF); super.render(poseStack, mouseX, mouseY, delta); diff --git a/src/main/java/net/coderbot/iris/gui/GuiUtil.java b/src/main/java/net/coderbot/iris/gui/GuiUtil.java index 668cf0868c..3f0e7a00e8 100644 --- a/src/main/java/net/coderbot/iris/gui/GuiUtil.java +++ b/src/main/java/net/coderbot/iris/gui/GuiUtil.java @@ -4,16 +4,24 @@ import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.resources.language.I18n; import net.minecraft.client.resources.sounds.SimpleSoundInstance; +import net.minecraft.init.SoundEvents; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; /** * Class serving as abstraction and @@ -26,12 +34,12 @@ */ public final class GuiUtil { public static final ResourceLocation IRIS_WIDGETS_TEX = new ResourceLocation("iris", "textures/gui/widgets.png"); - private static final Component ELLIPSIS = new TextComponent("..."); + private static final ITextComponent ELLIPSIS = new TextComponentString("..."); private GuiUtil() {} private static Minecraft client() { - return Minecraft.getInstance(); + return Minecraft.getMinecraft(); } /** @@ -39,7 +47,7 @@ private static Minecraft client() { * used for succeeding draw calls. */ public static void bindIrisWidgetsTexture() { - client().getTextureManager().bind(IRIS_WIDGETS_TEX); + client().getTextureManager().bindTexture(IRIS_WIDGETS_TEX); } /** @@ -53,7 +61,7 @@ public static void bindIrisWidgetsTexture() { * @param hovered Whether the button is being hovered over with the mouse * @param disabled Whether the button should use the "disabled" texture */ - public static void drawButton(PoseStack poseStack, int x, int y, int width, int height, boolean hovered, boolean disabled) { + public static void drawButton(int x, int y, int width, int height, boolean hovered, boolean disabled) { // Create variables for half of the width and height. // Will not be exact when width and height are odd, but // that case is handled within the draw calls. @@ -65,19 +73,19 @@ public static void drawButton(PoseStack poseStack, int x, int y, int width, int // Sets RenderSystem to use solid white as the tint color for blend mode, and enables blend mode RenderSystem.blendColor(1.0f, 1.0f, 1.0f, 1.0f); - RenderSystem.enableBlend(); + GlStateManager.enableBlend(); // Sets RenderSystem to be able to use textures when drawing - RenderSystem.enableTexture(); + GlStateManager.enableTexture2D(); // Top left section - GuiComponent.blit(poseStack, x, y, 0, vOffset, halfWidth, halfHeight, 256, 256); + GuiComponent.blit(x, y, 0, vOffset, halfWidth, halfHeight, 256, 256); // Top right section - GuiComponent.blit(poseStack, x + halfWidth, y, 200 - (width - halfWidth), vOffset, width - halfWidth, halfHeight, 256, 256); + GuiComponent.blit(x + halfWidth, y, 200 - (width - halfWidth), vOffset, width - halfWidth, halfHeight, 256, 256); // Bottom left section - GuiComponent.blit(poseStack, x, y + halfHeight, 0, vOffset + (20 - (height - halfHeight)), halfWidth, height - halfHeight, 256, 256); + GuiComponent.blit(x, y + halfHeight, 0, vOffset + (20 - (height - halfHeight)), halfWidth, height - halfHeight, 256, 256); // Bottom right section - GuiComponent.blit(poseStack, x + halfWidth, y + halfHeight, 200 - (width - halfWidth), vOffset + (20 - (height - halfHeight)), width - halfWidth, height - halfHeight, 256, 256); + GuiComponent.blit(x + halfWidth, y + halfHeight, 200 - (width - halfWidth), vOffset + (20 - (height - halfHeight)), width - halfWidth, height - halfHeight, 256, 256); } /** @@ -89,20 +97,20 @@ public static void drawButton(PoseStack poseStack, int x, int y, int width, int * @param width The width of the panel * @param height The height of the panel */ - public static void drawPanel(PoseStack poseStack, int x, int y, int width, int height) { + public static void drawPanel(int x, int y, int width, int height) { int borderColor = 0xDEDEDEDE; int innerColor = 0xDE000000; // Top border section - GuiComponent.fill(poseStack, x, y, x + width, y + 1, borderColor); + Gui.drawRect(x, y, x + width, y + 1, borderColor); // Bottom border section - GuiComponent.fill(poseStack, x, (y + height) - 1, x + width, y + height, borderColor); + Gui.drawRect(x, (y + height) - 1, x + width, y + height, borderColor); // Left border section - GuiComponent.fill(poseStack, x, y + 1, x + 1, (y + height) - 1, borderColor); + Gui.drawRect(x, y + 1, x + 1, (y + height) - 1, borderColor); // Right border section - GuiComponent.fill(poseStack, (x + width) - 1, y + 1, x + width, (y + height) - 1, borderColor); + Gui.drawRect((x + width) - 1, y + 1, x + width, (y + height) - 1, borderColor); // Inner section - GuiComponent.fill(poseStack, x + 1, y + 1, (x + width) - 1, (y + height) - 1, innerColor); + Gui.drawRect(x + 1, y + 1, (x + width) - 1, (y + height) - 1, innerColor); } /** @@ -112,9 +120,9 @@ public static void drawPanel(PoseStack poseStack, int x, int y, int width, int h * @param x The x position of the panel * @param y The y position of the panel */ - public static void drawTextPanel(Font font, PoseStack poseStack, Component text, int x, int y) { - drawPanel(poseStack, x, y, font.width(text) + 8, 16); - font.drawShadow(poseStack, text, x + 4, y + 4, 0xFFFFFF); + public static void drawTextPanel(FontRenderer font, String text, int x, int y) { + drawPanel(x, y, font.getStringWidth(text) + 8, 16); + font.drawStringWithShadow(text, x + 4, y + 4, 0xFFFFFF); } /** @@ -128,7 +136,7 @@ public static void drawTextPanel(Font font, PoseStack poseStack, Component text, * @param width Width to shorten text to * @return a shortened text */ - public static MutableComponent shortenText(Font font, MutableComponent text, int width) { + public static MutableComponent shortenText(FontRenderer font, MutableComponent text, int width) { if (font.width(text) > width) { return new TextComponent(font.plainSubstrByWidth(text.getString(), width - font.width(ELLIPSIS))).append(ELLIPSIS).setStyle(text.getStyle()); } @@ -160,7 +168,7 @@ public static MutableComponent translateOrDefault(MutableComponent defaultText, * or other action. */ public static void playButtonClickSound() { - client().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1)); + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1.0F)); } /** @@ -194,16 +202,16 @@ public Icon(int u, int v, int width, int height) { * @param x The x position to draw the icon at (left) * @param y The y position to draw the icon at (top) */ - public void draw(PoseStack poseStack, int x, int y) { + public void draw(int x, int y) { // Sets RenderSystem to use solid white as the tint color for blend mode, and enables blend mode RenderSystem.blendColor(1.0f, 1.0f, 1.0f, 1.0f); - RenderSystem.enableBlend(); + GlStateManager.enableBlend(); // Sets RenderSystem to be able to use textures when drawing - RenderSystem.enableTexture(); + GlStateManager.enableTexture2D(); // Draw the texture to the screen - GuiComponent.blit(poseStack, x, y, u, v, width, height, 256, 256); + GuiComponent.blit(x, y, u, v, width, height, 256, 256); } public int getWidth() { diff --git a/src/main/java/net/coderbot/iris/gui/NavigationController.java b/src/main/java/net/coderbot/iris/gui/NavigationController.java index 5e3d08ec7f..b7376bef0b 100644 --- a/src/main/java/net/coderbot/iris/gui/NavigationController.java +++ b/src/main/java/net/coderbot/iris/gui/NavigationController.java @@ -18,10 +18,10 @@ public NavigationController(OptionMenuContainer container) { } public void back() { - if (history.size() > 0) { + if (!history.isEmpty()) { history.removeLast(); - if (history.size() > 0) { + if (!history.isEmpty()) { currentScreen = history.getLast(); } else { currentScreen = null; @@ -53,7 +53,7 @@ public void refresh() { } public boolean hasHistory() { - return this.history.size() > 0; + return !this.history.isEmpty(); } public void setActiveOptionList(ShaderPackOptionList optionList) { diff --git a/src/main/java/net/coderbot/iris/gui/element/IrisElementRow.java b/src/main/java/net/coderbot/iris/gui/element/IrisElementRow.java index 4577481a28..ea9348d9e7 100644 --- a/src/main/java/net/coderbot/iris/gui/element/IrisElementRow.java +++ b/src/main/java/net/coderbot/iris/gui/element/IrisElementRow.java @@ -1,20 +1,13 @@ package net.coderbot.iris.gui.element; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.function.Function; - -import org.lwjgl.glfw.GLFW; - -import com.mojang.blaze3d.vertex.PoseStack; - import net.coderbot.iris.gui.GuiUtil; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.network.chat.Component; +import org.lwjgl.glfw.GLFW; + +import java.util.*; +import java.util.function.Function; /** * Intended to make very simple rows of buttons easier to make @@ -73,7 +66,7 @@ public void setWidth(Element element, int width) { /** * Renders the row, with the anchor point being the top left. */ - public void render(PoseStack poseStack, int x, int y, int height, int mouseX, int mouseY, float tickDelta, boolean rowHovered) { + public void render(int x, int y, int height, int mouseX, int mouseY, float tickDelta, boolean rowHovered) { this.x = x; this.y = y; this.height = height; @@ -83,7 +76,7 @@ public void render(PoseStack poseStack, int x, int y, int height, int mouseX, in for (Element element : this.orderedElements) { int currentWidth = this.elements.get(element); - element.render(poseStack, currentX, y, currentWidth, height, mouseX, mouseY, tickDelta, + element.render(currentX, y, currentWidth, height, mouseX, mouseY, tickDelta, rowHovered && sectionHovered(currentX, currentWidth, mouseX, mouseY)); currentX += currentWidth + this.spacing; @@ -93,8 +86,8 @@ public void render(PoseStack poseStack, int x, int y, int height, int mouseX, in /** * Renders the row, with the anchor point being the top right. */ - public void renderRightAligned(PoseStack poseStack, int x, int y, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { - render(poseStack, x - this.width, y, height, mouseX, mouseY, tickDelta, hovered); + public void renderRightAligned(int x, int y, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { + render(x - this.width, y, height, mouseX, mouseY, tickDelta, hovered); } private boolean sectionHovered(int sectionX, int sectionWidth, double mx, double my) { @@ -130,15 +123,15 @@ public static abstract class Element { public boolean disabled = false; private boolean hovered = false; - public void render(PoseStack poseStack, int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { + public void render(int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { GuiUtil.bindIrisWidgetsTexture(); - GuiUtil.drawButton(poseStack, x, y, width, height, hovered, this.disabled); + GuiUtil.drawButton(x, y, width, height, hovered, this.disabled); this.hovered = hovered; - this.renderLabel(poseStack, x, y, width, height, mouseX, mouseY, tickDelta, hovered); + this.renderLabel(x, y, width, height, mouseX, mouseY, tickDelta, hovered); } - public abstract void renderLabel(PoseStack poseStack, int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered); + public abstract void renderLabel(int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered); public boolean mouseClicked(double mx, double my, int button) { return false; @@ -192,15 +185,15 @@ public IconButtonElement(GuiUtil.Icon icon, Function } @Override - public void renderLabel(PoseStack poseStack, int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { + public void renderLabel(int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { int iconX = x + (int)((width - this.icon.getWidth()) * 0.5); int iconY = y + (int)((height - this.icon.getHeight()) * 0.5); GuiUtil.bindIrisWidgetsTexture(); if (!this.disabled && hovered) { - this.hoveredIcon.draw(poseStack, iconX, iconY); + this.hoveredIcon.draw(iconX, iconY); } else { - this.icon.draw(poseStack, iconX, iconY); + this.icon.draw(iconX, iconY); } } } @@ -209,22 +202,22 @@ public void renderLabel(PoseStack poseStack, int x, int y, int width, int height * A clickable button element that uses a text component as its label. */ public static class TextButtonElement extends ButtonElement { - protected final Font font; - public Component text; + protected final FontRenderer font; + public String text; - public TextButtonElement(Component text, Function onClick) { + public TextButtonElement(String text, Function onClick) { super(onClick); - this.font = Minecraft.getInstance().font; + this.font = Minecraft.getMinecraft().fontRenderer; this.text = text; } @Override - public void renderLabel(PoseStack poseStack, int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { - int textX = x + (int)((width - this.font.width(this.text)) * 0.5); + public void renderLabel(int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { + int textX = x + (int)((width - this.font.getStringWidth(this.text)) * 0.5); int textY = y + (int)((height - 8) * 0.5); - this.font.drawShadow(poseStack, this.text, textX, textY, 0xFFFFFF); + this.font.drawStringWithShadow(this.text, textX, textY, 0xFFFFFF); } } } diff --git a/src/main/java/net/coderbot/iris/gui/element/IrisGuiSlot.java b/src/main/java/net/coderbot/iris/gui/element/IrisGuiSlot.java new file mode 100644 index 0000000000..5fc492f789 --- /dev/null +++ b/src/main/java/net/coderbot/iris/gui/element/IrisGuiSlot.java @@ -0,0 +1,215 @@ +package net.coderbot.iris.gui.element; + +import lombok.Getter; +import lombok.Setter; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiSlot; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.Tessellator; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +// TODO: look into GuiListExtended & GuiSelectStringEntries +public abstract class IrisGuiSlot extends GuiSlot { + @Setter @Getter protected boolean renderBackground = true; + boolean scrolling = false; + + protected IrisGuiSlot(Minecraft mc, int width, int height, int top, int bottom, int slotHeight) { + super(mc, width, height, top, bottom, slotHeight); + // Set Center Vertically to false + this.centerListVertically = false; + + } + + @Override + protected void drawContainerBackground(Tessellator tessellator) { + if (this.renderBackground) { + super.drawContainerBackground(tessellator); + } + } + + @Override + protected int getScrollBarX() { + // Position the scrollbar at the rightmost edge of the screen. + // By default, the scrollbar is positioned moderately offset from the center. + return this.width - 6; + } + + @Override + protected void drawSelectionBox(int x, int y, int mouseX, int mouseY, float partialTicks) { + final int oldPadding = this.headerPadding; + this.headerPadding = 2; + super.drawSelectionBox(x, y, mouseX, mouseY, partialTicks); + this.headerPadding = oldPadding; + } + + @Override + protected void elementClicked(int index, boolean doubleClick, int mouseX, int mouseY) { + // Do nothing + } + + protected boolean elementClicked(int index, boolean doubleClick, int mouseX, int mouseY, int button) { + return false; + } + + public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) { + if (!this.getEnabled/*enabled*/()) { + return false; + } + final int size = this.getSize(); + final int scrollBarX = this.getScrollBarX(); + final int rightEdge = scrollBarX + 6; + final int elementLeft = this.width / 2 - this.getListWidth() / 2; + final int elementRight = this.width / 2 + this.getListWidth() / 2; + final int relativeY = mouseY - this.top - this.headerPadding + (int) this.amountScrolled - 4; + boolean handled = false; + final boolean leftMouseDown = Mouse.isButtonDown(0); + final boolean rightMouseDown = Mouse.isButtonDown(1); + + if (mouseX <= this.left || mouseX >= this.right || mouseY <= this.top || mouseY >= this.bottom) { + return handled; + } + if (leftMouseDown && mouseX >= scrollBarX && mouseX <= rightEdge) { + scrolling = true; + this.initialClickY = mouseY; + } else if ((leftMouseDown || rightMouseDown)) { + final int index = relativeY / this.slotHeight; + + if (mouseX >= elementLeft && mouseX <= elementRight && index >= 0 && relativeY >= 0 && index < size) { + final boolean doubleCLick = index == this.selectedElement && Minecraft.getSystemTime() - this.lastClicked < 250L; + + handled = this.elementClicked(index, doubleCLick, mouseX, mouseY, mouseButton); + this.selectedElement = index; + this.lastClicked = Minecraft.getSystemTime(); + } else if (mouseX >= elementLeft && mouseX <= elementRight && relativeY < 0) { + this.clickedHeader(mouseX - elementLeft, mouseY - this.top + (int) this.amountScrolled - 4); + } + } + + return handled; + } + + public boolean mouseReleased(int mouseX, int mouseY, int button) { + scrolling = false; + return false; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + this.mouseX = mouseX; + this.mouseY = mouseY; + this.drawBackground(); + final int scrollBarX = this.getScrollBarX(); + final int rightEdge = scrollBarX + 6; + final byte offset = 4; + + + // Scrollbar nonsense + if (scrolling) { + this.amountScrolled += ((float) mouseY - this.initialClickY); + this.initialClickY = mouseY; + } else { + for (; !this.mc.gameSettings.touchscreen && Mouse.next(); this.mc.currentScreen.handleMouseInput()) { + int dWheel = Mouse.getEventDWheel(); + + if (dWheel != 0) { + if (dWheel > 0) { + dWheel = -1; + } else { + dWheel = 1; + } + + this.amountScrolled += (dWheel * this.slotHeight / 2.0f); + } + } + } + + + this.bindAmountScrolled(); + GlStateManager.disableLighting(); + GlStateManager.disableFog(); + final Tessellator tessellator = Tessellator.getInstance(); + drawContainerBackground(tessellator); + final int elementRight = this.left + this.width / 2 - this.getListWidth() / 2 + 2; + final int relativeY = this.top + 4 - (int) this.amountScrolled; + + if (this.hasListHeader) { + this.drawListHeader(elementRight, relativeY, tessellator); + } + + this.drawSelectionBox(elementRight, relativeY, mouseX, mouseY); + GlStateManager.disableDepth(); + this.overlayBackground(0, this.top, 255, 255); + this.overlayBackground(this.bottom, this.height, 255, 255); + GlStateManager.enableBlend(); + OpenGlHelper.glBlendFunc(770, 771, 0, 1); + GlStateManager.disableAlpha(); + GlStateManager.shadeModel(GL11.GL_SMOOTH); + GlStateManager.disableTexture2D(); + tessellator.startDrawingQuads(); + tessellator.setColorRGBA_I(0, 0); + tessellator.addVertexWithUV(this.left, (this.top + offset), 0.0D, 0.0D, 1.0D); + tessellator.addVertexWithUV(this.right, (this.top + offset), 0.0D, 1.0D, 1.0D); + tessellator.setColorRGBA_I(0, 255); + tessellator.addVertexWithUV(this.right, this.top, 0.0D, 1.0D, 0.0D); + tessellator.addVertexWithUV(this.left, this.top, 0.0D, 0.0D, 0.0D); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setColorRGBA_I(0, 255); + tessellator.addVertexWithUV(this.left, this.bottom, 0.0D, 0.0D, 1.0D); + tessellator.addVertexWithUV(this.right, this.bottom, 0.0D, 1.0D, 1.0D); + tessellator.setColorRGBA_I(0, 0); + tessellator.addVertexWithUV(this.right, (this.bottom - offset), 0.0D, 1.0D, 0.0D); + tessellator.addVertexWithUV(this.left, (this.bottom - offset), 0.0D, 0.0D, 0.0D); + tessellator.draw(); + + // Draw scrollbar if needed + final int contentOverflow = this.getMaxScroll(); + if (contentOverflow > 0) { + registerScrollButtons(7, 8); + int scrollPosSize = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight(); + + if (scrollPosSize < 32) { + scrollPosSize = 32; + } + + if (scrollPosSize > this.bottom - this.top - 8) { + scrollPosSize = this.bottom - this.top - 8; + } + + int scrollPos = (int) this.amountScrolled * (this.bottom - this.top - scrollPosSize) / contentOverflow + this.top; + + if (scrollPos < this.top) { + scrollPos = this.top; + } + + tessellator.startDrawingQuads(); + tessellator.setColorRGBA_I(0, 255); + tessellator.addVertexWithUV(scrollBarX, this.bottom, 0.0D, 0.0D, 1.0D); + tessellator.addVertexWithUV(rightEdge, this.bottom, 0.0D, 1.0D, 1.0D); + tessellator.addVertexWithUV(rightEdge, this.top, 0.0D, 1.0D, 0.0D); + tessellator.addVertexWithUV(scrollBarX, this.top, 0.0D, 0.0D, 0.0D); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setColorRGBA_I(8421504, 255); + tessellator.addVertexWithUV(scrollBarX, (scrollPos + scrollPosSize), 0.0D, 0.0D, 1.0D); + tessellator.addVertexWithUV(rightEdge, (scrollPos + scrollPosSize), 0.0D, 1.0D, 1.0D); + tessellator.addVertexWithUV(rightEdge, scrollPos, 0.0D, 1.0D, 0.0D); + tessellator.addVertexWithUV(scrollBarX, scrollPos, 0.0D, 0.0D, 0.0D); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setColorRGBA_I(12632256, 255); + tessellator.addVertexWithUV(scrollBarX, (scrollPos + scrollPosSize - 1), 0.0D, 0.0D, 1.0D); + tessellator.addVertexWithUV((rightEdge - 1), (scrollPos + scrollPosSize - 1), 0.0D, 1.0D, 1.0D); + tessellator.addVertexWithUV((rightEdge - 1), scrollPos, 0.0D, 1.0D, 0.0D); + tessellator.addVertexWithUV(scrollBarX, scrollPos, 0.0D, 0.0D, 0.0D); + tessellator.draw(); + } + + GlStateManager.enableTexture2D(); + GlStateManager.shadeModel(GL11.GL_FLAT); + GlStateManager.enableAlpha(); + GlStateManager.disableBlend(); + } +} \ No newline at end of file diff --git a/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java b/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java index 37ef840fbd..81614d1580 100644 --- a/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java +++ b/src/main/java/net/coderbot/iris/gui/element/ShaderPackOptionList.java @@ -1,47 +1,29 @@ package net.coderbot.iris.gui.element; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import org.jetbrains.annotations.Nullable; - -import com.mojang.blaze3d.vertex.PoseStack; - -import net.coderbot.iris.Iris; -import net.coderbot.iris.gui.FileDialogUtil; -import net.coderbot.iris.gui.GuiUtil; import net.coderbot.iris.gui.NavigationController; +import net.coderbot.iris.gui.element.shaderoptions.BaseEntry; +import net.coderbot.iris.gui.element.shaderoptions.ElementRowEntry; +import net.coderbot.iris.gui.element.shaderoptions.HeaderEntry; import net.coderbot.iris.gui.element.widget.AbstractElementWidget; import net.coderbot.iris.gui.element.widget.OptionMenuConstructor; import net.coderbot.iris.gui.screen.ShaderPackScreen; import net.coderbot.iris.shaderpack.ShaderPack; import net.coderbot.iris.shaderpack.option.menu.OptionMenuContainer; -import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.components.ObjectSelectionList; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.network.chat.TextColor; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.util.Mth; -public class ShaderPackOptionList extends IrisObjectSelectionList { +import java.util.ArrayList; +import java.util.List; + +public class ShaderPackOptionList extends IrisGuiSlot { private final List> elementWidgets = new ArrayList<>(); private final ShaderPackScreen screen; + @Getter private final NavigationController navigation; private OptionMenuContainer container; + private final List entries = new ArrayList<>(); public ShaderPackOptionList(ShaderPackScreen screen, NavigationController navigation, ShaderPack pack, Minecraft client, int width, int height, int top, int bottom, int left, int right) { - super(client, width, height, top, bottom, left, right, 24); + super(client, width, height, top, bottom, 20); this.navigation = navigation; this.screen = screen; @@ -53,8 +35,8 @@ public void applyShaderPack(ShaderPack pack) { } public void rebuild() { - this.clearEntries(); - this.setScrollAmount(0); + this.entries.clear(); + this.amountScrolled = 0; OptionMenuConstructor.constructAndApplyToScreen(this.container, this.screen, this, navigation); } @@ -63,11 +45,15 @@ public void refresh() { } @Override - public int getRowWidth() { + public int getListWidth() { return Math.min(400, width - 12); } - public void addHeader(Component text, boolean backButton) { + protected void addEntry(BaseEntry entry) { + this.entries.add(entry); + } + + public void addHeader(String text, boolean backButton) { this.addEntry(new HeaderEntry(this.screen, this.navigation, text, backButton)); } @@ -84,7 +70,7 @@ public void addWidgets(int columns, List> elements) { } } - if (row.size() > 0) { + if (!row.isEmpty()) { while (row.size() < columns) { row.add(AbstractElementWidget.EMPTY); } @@ -93,284 +79,34 @@ public void addWidgets(int columns, List> elements) { } } - public NavigationController getNavigation() { - return navigation; + @Override + protected int getSize() { + return entries.size(); } - public abstract static class BaseEntry extends ObjectSelectionList.Entry { - protected final NavigationController navigation; - - protected BaseEntry(NavigationController navigation) { - this.navigation = navigation; - } + @Override + protected boolean elementClicked(int index, boolean doubleClick, int mouseX, int mouseY, int mouseButton) { + final BaseEntry entry = this.entries.get(index); + return entry.mouseClicked(mouseX, mouseY, mouseButton); } - public static class HeaderEntry extends BaseEntry { - public static final Component BACK_BUTTON_TEXT = new TextComponent("< ").append(new TranslatableComponent("options.iris.back").withStyle(ChatFormatting.ITALIC)); - public static final MutableComponent RESET_BUTTON_TEXT_INACTIVE = new TranslatableComponent("options.iris.reset").withStyle(ChatFormatting.GRAY); - public static final MutableComponent RESET_BUTTON_TEXT_ACTIVE = new TranslatableComponent("options.iris.reset").withStyle(ChatFormatting.YELLOW); - - public static final MutableComponent RESET_HOLD_SHIFT_TOOLTIP = new TranslatableComponent("options.iris.reset.tooltip.holdShift").withStyle(ChatFormatting.GOLD); - public static final MutableComponent RESET_TOOLTIP = new TranslatableComponent("options.iris.reset.tooltip").withStyle(ChatFormatting.RED); - public static final MutableComponent IMPORT_TOOLTIP = new TranslatableComponent("options.iris.importSettings.tooltip") - .withStyle(style -> style.withColor(TextColor.fromRgb(0x4da6ff))); - public static final MutableComponent EXPORT_TOOLTIP = new TranslatableComponent("options.iris.exportSettings.tooltip") - .withStyle(style -> style.withColor(TextColor.fromRgb(0xfc7d3d))); - - private static final int MIN_SIDE_BUTTON_WIDTH = 42; - private static final int BUTTON_HEIGHT = 16; - - private final ShaderPackScreen screen; - private final @Nullable IrisElementRow backButton; - private final IrisElementRow utilityButtons = new IrisElementRow(); - private final IrisElementRow.TextButtonElement resetButton; - private final IrisElementRow.IconButtonElement importButton; - private final IrisElementRow.IconButtonElement exportButton; - private final Component text; - - public HeaderEntry(ShaderPackScreen screen, NavigationController navigation, Component text, boolean hasBackButton) { - super(navigation); - - if (hasBackButton) { - this.backButton = new IrisElementRow().add( - new IrisElementRow.TextButtonElement(BACK_BUTTON_TEXT, this::backButtonClicked), - Math.max(MIN_SIDE_BUTTON_WIDTH, Minecraft.getInstance().font.width(BACK_BUTTON_TEXT) + 8) - ); - } else { - this.backButton = null; - } - - this.resetButton = new IrisElementRow.TextButtonElement( - RESET_BUTTON_TEXT_INACTIVE, this::resetButtonClicked); - this.importButton = new IrisElementRow.IconButtonElement( - GuiUtil.Icon.IMPORT, GuiUtil.Icon.IMPORT_COLORED, this::importSettingsButtonClicked); - this.exportButton = new IrisElementRow.IconButtonElement( - GuiUtil.Icon.EXPORT, GuiUtil.Icon.EXPORT_COLORED, this::exportSettingsButtonClicked); - - this.utilityButtons - .add(this.importButton, 15) - .add(this.exportButton, 15) - .add(this.resetButton, Math.max(MIN_SIDE_BUTTON_WIDTH, Minecraft.getInstance().font.width(RESET_BUTTON_TEXT_INACTIVE) + 8)); - - this.screen = screen; - this.text = text; - } - - @Override - public void render(PoseStack poseStack, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - // Draw dividing line - fill(poseStack, x - 3, (y + entryHeight) - 2, x + entryWidth, (y + entryHeight) - 1, 0x66BEBEBE); - - Font font = Minecraft.getInstance().font; - - // Draw header text - drawCenteredString(poseStack, font, text, x + (int)(entryWidth * 0.5), y + 5, 0xFFFFFF); - - GuiUtil.bindIrisWidgetsTexture(); - - // Draw back button if present - if (this.backButton != null) { - backButton.render(poseStack, x, y, BUTTON_HEIGHT, mouseX, mouseY, tickDelta, hovered); - } - - boolean shiftDown = Screen.hasShiftDown(); - - // Set the appearance of the reset button - this.resetButton.disabled = !shiftDown; - this.resetButton.text = shiftDown ? RESET_BUTTON_TEXT_ACTIVE : RESET_BUTTON_TEXT_INACTIVE; - - // Draw the utility buttons - this.utilityButtons.renderRightAligned(poseStack, (x + entryWidth) - 3, y, BUTTON_HEIGHT, mouseX, mouseY, tickDelta, hovered); - - // Draw the reset button's tooltip - if (this.resetButton.isHovered()) { - Component tooltip = shiftDown ? RESET_TOOLTIP : RESET_HOLD_SHIFT_TOOLTIP; - queueBottomRightAnchoredTooltip(poseStack, mouseX, mouseY, font, tooltip); - } - // Draw the import/export button tooltips - if (this.importButton.isHovered()) { - queueBottomRightAnchoredTooltip(poseStack, mouseX, mouseY, font, IMPORT_TOOLTIP); - } - if (this.exportButton.isHovered()) { - queueBottomRightAnchoredTooltip(poseStack, mouseX, mouseY, font, EXPORT_TOOLTIP); - } - } - - private void queueBottomRightAnchoredTooltip(PoseStack poseStack, int x, int y, Font font, Component text) { - ShaderPackScreen.TOP_LAYER_RENDER_QUEUE.add(() -> GuiUtil.drawTextPanel( - font, poseStack, text, - x - (font.width(text) + 10), y - 16 - )); - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - boolean backButtonResult = backButton != null && backButton.mouseClicked(mouseX, mouseY, button); - boolean utilButtonResult = utilityButtons.mouseClicked(mouseX, mouseY, button); - - return backButtonResult || utilButtonResult; - } - - private boolean backButtonClicked(IrisElementRow.TextButtonElement button) { - this.navigation.back(); - GuiUtil.playButtonClickSound(); - - return true; - } - - private boolean resetButtonClicked(IrisElementRow.TextButtonElement button) { - if (Screen.hasShiftDown()) { - Iris.resetShaderPackOptionsOnNextReload(); - this.screen.applyChanges(); - GuiUtil.playButtonClickSound(); - - return true; - } - - return false; - } - - private boolean importSettingsButtonClicked(IrisElementRow.IconButtonElement button) { - GuiUtil.playButtonClickSound(); - - // Invalid state to be in - if (!Iris.getCurrentPack().isPresent()) { - return false; - } - - // Displaying a dialog when the game is full-screened can cause severe issues - // https://github.com/IrisShaders/Iris/issues/1258 - if (Minecraft.getInstance().getWindow().isFullscreen()) { - this.screen.displayNotification( - new TranslatableComponent("options.iris.mustDisableFullscreen") - .withStyle(ChatFormatting.RED).withStyle(ChatFormatting.BOLD)); - return false; - } - - final ShaderPackScreen originalScreen = this.screen; // Also used to prevent invalid state - - FileDialogUtil.fileSelectDialog( - FileDialogUtil.DialogType.OPEN, "Import Shader Settings from File", - Iris.getShaderpacksDirectory().resolve(Iris.getCurrentPackName() + ".txt"), - "Shader Pack Settings (.txt)", "*.txt") - .whenComplete((path, err) -> { - if (err != null) { - Iris.logger.error("Error selecting shader settings from file", err); - - return; - } - - if (Minecraft.getInstance().screen == originalScreen) { - path.ifPresent(originalScreen::importPackOptions); - } - }); - - return true; - } - - private boolean exportSettingsButtonClicked(IrisElementRow.IconButtonElement button) { - GuiUtil.playButtonClickSound(); - - // Invalid state to be in - if (!Iris.getCurrentPack().isPresent()) { - return false; - } - - // Displaying a dialog when the game is full-screened can cause severe issues - // https://github.com/IrisShaders/Iris/issues/1258 - if (Minecraft.getInstance().getWindow().isFullscreen()) { - this.screen.displayNotification( - new TranslatableComponent("options.iris.mustDisableFullscreen") - .withStyle(ChatFormatting.RED).withStyle(ChatFormatting.BOLD)); - return false; - } - - FileDialogUtil.fileSelectDialog( - FileDialogUtil.DialogType.SAVE, "Export Shader Settings to File", - Iris.getShaderpacksDirectory().resolve(Iris.getCurrentPackName() + ".txt"), - "Shader Pack Settings (.txt)", "*.txt") - .whenComplete((path, err) -> { - if (err != null) { - Iris.logger.error("Error selecting file to export shader settings", err); - - return; - } - - path.ifPresent(p -> { - Properties toSave = new Properties(); - - // Dirty way of getting the currently applied settings as a Properties, directly - // opens and copies out of the saved settings file if it is present - Path sourceTxtPath = Iris.getShaderpacksDirectory().resolve(Iris.getCurrentPackName() + ".txt"); - if (Files.exists(sourceTxtPath)) { - try (InputStream in = Files.newInputStream(sourceTxtPath)) { - toSave.load(in); - } catch (IOException ignored) {} - } - - // Save properties to user determined file - try (OutputStream out = Files.newOutputStream(p)) { - toSave.store(out, null); - } catch (IOException e) { - Iris.logger.error("Error saving properties to \"" + p + "\"", e); - } - }); - }); - - return true; - } + @Override + protected boolean isSelected(int idx) { + return false;//return this.entries.get(idx).equals(this.selected); } - public static class ElementRowEntry extends BaseEntry { - private final List> widgets; - private final ShaderPackScreen screen; - - private int cachedWidth; - private int cachedPosX; - - public ElementRowEntry(ShaderPackScreen screen, NavigationController navigation, List> widgets) { - super(navigation); - - this.screen = screen; - this.widgets = widgets; - } - - @Override - public void render(PoseStack poseStack, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - this.cachedWidth = entryWidth; - this.cachedPosX = x; - - // The amount of space widgets will occupy, excluding margins. Will be divided up between widgets. - int totalWidthWithoutMargins = entryWidth - (2 * (widgets.size() - 1)); - - totalWidthWithoutMargins -= 3; // Centers it for some reason - - // Width of a single widget - float singleWidgetWidth = (float) totalWidthWithoutMargins / widgets.size(); - - for (int i = 0; i < widgets.size(); i++) { - AbstractElementWidget widget = widgets.get(i); - boolean widgetHovered = hovered && (getHoveredWidget(mouseX) == i); - widget.render(poseStack, x + (int)((singleWidgetWidth + 2) * i), y, (int) singleWidgetWidth, entryHeight + 2, mouseX, mouseY, tickDelta, widgetHovered); - - screen.setElementHoveredStatus(widget, widgetHovered); - } - } + @Override + protected void drawBackground() { + // noop + } - public int getHoveredWidget(int mouseX) { - float positionAcrossWidget = ((float) Mth.clamp(mouseX - cachedPosX, 0, cachedWidth)) / cachedWidth; + @Override + protected void drawSlot(int index, int x, int y, int i1, int mouseX, int mouseY, float partialTicks) { + final BaseEntry entry = this.entries.get(index); + final boolean isMouseOver = this.getSlotIndexFromScreenCoords(mouseX, mouseY) == index; + entry.drawEntry(screen, index, x - 2, y + 4, this.getListWidth(), this.slotHeight, mouseX, mouseY, isMouseOver); + } - return Mth.clamp((int) Math.floor(widgets.size() * positionAcrossWidget), 0, widgets.size() - 1); - } - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - return this.widgets.get(getHoveredWidget((int) mouseX)).mouseClicked(mouseX, mouseY, button); - } - @Override - public boolean mouseReleased(double mouseX, double mouseY, int button) { - return this.widgets.get(getHoveredWidget((int) mouseX)).mouseReleased(mouseX, mouseY, button); - } - } -} +} \ No newline at end of file diff --git a/src/main/java/net/coderbot/iris/gui/element/shaderoptions/BaseEntry.java b/src/main/java/net/coderbot/iris/gui/element/shaderoptions/BaseEntry.java new file mode 100644 index 0000000000..be7116bb3c --- /dev/null +++ b/src/main/java/net/coderbot/iris/gui/element/shaderoptions/BaseEntry.java @@ -0,0 +1,17 @@ +package net.coderbot.iris.gui.element.shaderoptions; + +import net.coderbot.iris.gui.NavigationController; +import net.coderbot.iris.gui.screen.ShaderPackScreen; + +public abstract class BaseEntry { + protected final NavigationController navigation; + + protected BaseEntry(NavigationController navigation) { + this.navigation = navigation; + } + + public abstract boolean mouseClicked(int mouseX, int mouseY, int button); + + + public abstract void drawEntry(ShaderPackScreen screen, int index, int x, int y, int slotWidth, int slotHeight, int mouseX, int mouseY, boolean isMouseOver); +} \ No newline at end of file diff --git a/src/main/java/net/coderbot/iris/gui/element/shaderoptions/ElementRowEntry.java b/src/main/java/net/coderbot/iris/gui/element/shaderoptions/ElementRowEntry.java new file mode 100644 index 0000000000..db4c09ce42 --- /dev/null +++ b/src/main/java/net/coderbot/iris/gui/element/shaderoptions/ElementRowEntry.java @@ -0,0 +1,61 @@ +package net.coderbot.iris.gui.element.shaderoptions; + +import net.coderbot.iris.gui.NavigationController; +import net.coderbot.iris.gui.element.widget.AbstractElementWidget; +import net.coderbot.iris.gui.screen.ShaderPackScreen; +import net.minecraft.util.math.MathHelper; + +import java.util.List; + +public class ElementRowEntry extends BaseEntry { + + private final List> widgets; + private final ShaderPackScreen screen; + + private int cachedWidth; + private int cachedPosX; + + public ElementRowEntry(ShaderPackScreen screen, NavigationController navigation, List> widgets) { + super(navigation); + + this.screen = screen; + this.widgets = widgets; + } + + @Override + public void drawEntry(ShaderPackScreen screen, int index, int x, int y, int slotWidth, int slotHeight, int mouseX, int mouseY, boolean isMouseOver) { + this.cachedWidth = slotWidth; + this.cachedPosX = x; + + // The amount of space widgets will occupy, excluding margins. Will be divided up between widgets. + int totalWidthWithoutMargins = slotWidth - (2 * (widgets.size() - 1)); + + totalWidthWithoutMargins -= 3; // Centers it for some reason + + // Width of a single widget + final float singleWidgetWidth = (float) totalWidthWithoutMargins / widgets.size(); + + for (int i = 0; i < widgets.size(); i++) { + final AbstractElementWidget widget = widgets.get(i); + final boolean widgetHovered = isMouseOver && (getHoveredWidget(mouseX) == i); + widget.render(x + (int) ((singleWidgetWidth + 2) * i), y, (int) singleWidgetWidth, slotHeight + 2, mouseX, mouseY, 0, widgetHovered); + + screen.setElementHoveredStatus(widget, widgetHovered); + } + } + + public int getHoveredWidget(int mouseX) { + final float positionAcrossWidget = ((float) MathHelper.clamp(mouseX - cachedPosX, 0, cachedWidth)) / cachedWidth; + + return MathHelper.clamp((int) Math.floor(widgets.size() * positionAcrossWidget), 0, widgets.size() - 1); + } + + public boolean mouseClicked(int mouseX, int mouseY, int button) { + return this.widgets.get(getHoveredWidget(mouseX)).mouseClicked(mouseX, mouseY, button); + } + + public boolean mouseReleased(int mouseX, int mouseY, int button) { + return this.widgets.get(getHoveredWidget(mouseX)).mouseReleased(mouseX, mouseY, button); + } + +} \ No newline at end of file diff --git a/src/main/java/net/coderbot/iris/gui/element/shaderoptions/HeaderEntry.java b/src/main/java/net/coderbot/iris/gui/element/shaderoptions/HeaderEntry.java new file mode 100644 index 0000000000..ba8ef38eea --- /dev/null +++ b/src/main/java/net/coderbot/iris/gui/element/shaderoptions/HeaderEntry.java @@ -0,0 +1,217 @@ +package net.coderbot.iris.gui.element.shaderoptions; + +import com.mojang.realmsclient.gui.ChatFormatting; +import net.coderbot.iris.Iris; +import net.coderbot.iris.gui.GuiUtil; +import net.coderbot.iris.gui.NavigationController; +import net.coderbot.iris.gui.element.IrisElementRow; +import net.coderbot.iris.gui.screen.ShaderPackScreen; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.resources.I18n; + +public class HeaderEntry extends BaseEntry { + + public static final String BACK_BUTTON_TEXT = ChatFormatting.ITALIC + "< " + I18n.format("options.iris.back"); + public static final String RESET_BUTTON_TEXT_INACTIVE = ChatFormatting.GRAY + I18n.format("options.iris.reset"); + public static final String RESET_BUTTON_TEXT_ACTIVE = ChatFormatting.YELLOW + I18n.format("options.iris.reset"); + + public static final String RESET_HOLD_SHIFT_TOOLTIP = ChatFormatting.BOLD + I18n.format("options.iris.reset.tooltip.holdShift"); + public static final String RESET_TOOLTIP = ChatFormatting.RED + I18n.format("options.iris.reset.tooltip"); + public static final String IMPORT_TOOLTIP = I18n.format("options.iris.importSettings.tooltip"); + // .withStyle(style -> style.withColor(TextColor.fromRgb(0x4da6ff))); + public static final String EXPORT_TOOLTIP = I18n.format("options.iris.exportSettings.tooltip"); + // .withStyle(style -> style.withColor(TextColor.fromRgb(0xfc7d3d))); + + private static final int MIN_SIDE_BUTTON_WIDTH = 42; + private static final int BUTTON_HEIGHT = 16; + + private final ShaderPackScreen screen; + private final IrisElementRow backButton; + private final IrisElementRow utilityButtons = new IrisElementRow(); + private final IrisElementRow.TextButtonElement resetButton; + private final IrisElementRow.IconButtonElement importButton; + private final IrisElementRow.IconButtonElement exportButton; + private final String text; + + public HeaderEntry(ShaderPackScreen screen, NavigationController navigation, String text, boolean hasBackButton) { + super(navigation); + + if (hasBackButton) { + this.backButton = new IrisElementRow().add(new IrisElementRow.TextButtonElement(BACK_BUTTON_TEXT, this::backButtonClicked), + Math.max(MIN_SIDE_BUTTON_WIDTH, Minecraft.getMinecraft().fontRenderer.getStringWidth(BACK_BUTTON_TEXT) + 8)); + } else { + this.backButton = null; + } + + this.resetButton = new IrisElementRow.TextButtonElement(RESET_BUTTON_TEXT_INACTIVE, this::resetButtonClicked); + this.importButton = new IrisElementRow.IconButtonElement(GuiUtil.Icon.IMPORT, GuiUtil.Icon.IMPORT_COLORED, this::importSettingsButtonClicked); + this.exportButton = new IrisElementRow.IconButtonElement(GuiUtil.Icon.EXPORT, GuiUtil.Icon.EXPORT_COLORED, this::exportSettingsButtonClicked); + + this.utilityButtons.add(this.importButton, 15).add(this.exportButton, 15) + .add(this.resetButton, Math.max(MIN_SIDE_BUTTON_WIDTH, Minecraft.getMinecraft().fontRenderer.getStringWidth((RESET_BUTTON_TEXT_INACTIVE) + 8))); + + this.screen = screen; + this.text = text; + } + + @Override + public void drawEntry(ShaderPackScreen screen, int index, int x, int y, int slotWidth, int slotHeight, int mouseX, int mouseY, boolean isMouseOver) { + // Draw dividing line + // fill(x - 3, (y + slotHeight) - 2, x + slotWidth, (y + slotHeight) - 1, 0x66BEBEBE); + final int tickDelta = 0; + final FontRenderer font = Minecraft.getMinecraft().fontRenderer; + + // Draw header text + this.screen.drawCenteredString(font, text, x + (int) (slotWidth * 0.5), y + 5, 0xFFFFFF); + + GuiUtil.bindIrisWidgetsTexture(); + + // Draw back button if present + if (this.backButton != null) { + backButton.render(x, y, BUTTON_HEIGHT, mouseX, mouseY, tickDelta, isMouseOver); + } + + final boolean shiftDown = GuiScreen.isShiftKeyDown(); + + // Set the appearance of the reset button + this.resetButton.disabled = !shiftDown; + this.resetButton.text = shiftDown ? RESET_BUTTON_TEXT_ACTIVE : RESET_BUTTON_TEXT_INACTIVE; + + // Draw the utility buttons + this.utilityButtons.renderRightAligned((x + slotWidth) - 3, y, BUTTON_HEIGHT, mouseX, mouseY, tickDelta, isMouseOver); + + // Draw the reset button's tooltip + if (this.resetButton.isHovered()) { + final String tooltip = shiftDown ? RESET_TOOLTIP : RESET_HOLD_SHIFT_TOOLTIP; + queueBottomRightAnchoredTooltip(mouseX, mouseY, font, tooltip); + } + // Draw the import/export button tooltips + if (this.importButton.isHovered()) { + queueBottomRightAnchoredTooltip(mouseX, mouseY, font, IMPORT_TOOLTIP); + } + if (this.exportButton.isHovered()) { + queueBottomRightAnchoredTooltip(mouseX, mouseY, font, EXPORT_TOOLTIP); + } + } + + private void queueBottomRightAnchoredTooltip(int x, int y, FontRenderer font, String text) { + ShaderPackScreen.TOP_LAYER_RENDER_QUEUE.add(() -> GuiUtil.drawTextPanel(font, text, x - (font.getStringWidth(text) + 10), y - 16)); + } + + public boolean mouseClicked(int mouseX, int mouseY, int button) { + final boolean backButtonResult = backButton != null && backButton.mouseClicked(mouseX, mouseY, button); + final boolean utilButtonResult = utilityButtons.mouseClicked(mouseX, mouseY, button); + + return backButtonResult || utilButtonResult; + } + + private boolean backButtonClicked(IrisElementRow.TextButtonElement button) { + this.navigation.back(); + GuiUtil.playButtonClickSound(); + + return true; + } + + private boolean resetButtonClicked(IrisElementRow.TextButtonElement button) { + if (GuiScreen.isShiftKeyDown()) { + Iris.resetShaderPackOptionsOnNextReload(); + this.screen.applyChanges(); + GuiUtil.playButtonClickSound(); + + return true; + } + + return false; + } + + private boolean importSettingsButtonClicked(IrisElementRow.IconButtonElement button) { + // GuiUtil.playButtonClickSound(); + // + // // Invalid state to be in + // if (!Iris.getCurrentPack().isPresent()) { + // return false; + // } + // + // // Displaying a dialog when the game is full-screened can cause severe issues + // // https://github.com/IrisShaders/Iris/issues/1258 + // if (Minecraft.getMinecraft().isFullScreen()) { + // this.screen.displayNotification( + // "" + EnumChatFormatting.RED + EnumChatFormatting.BOLD + I18n.format("options.iris.mustDisableFullscreen"); + // return false; + // } + // + // final ShaderPackScreen originalScreen = this.screen; // Also used to prevent invalid state + // + // FileDialogUtil.fileSelectDialog( + // FileDialogUtil.DialogType.OPEN, "Import Shader Settings from File", + // Iris.getShaderpacksDirectory().resolve(Iris.getCurrentPackName() + ".txt"), + // "Shader Pack Settings (.txt)", "*.txt") + // .whenComplete((path, err) -> { + // if (err != null) { + // Iris.logger.error("Error selecting shader settings from file", err); + // + // return; + // } + // + // if (Minecraft.getInstance().screen == originalScreen) { + // path.ifPresent(originalScreen::importPackOptions); + // } + // }); + // + return true; + } + + private boolean exportSettingsButtonClicked(IrisElementRow.IconButtonElement button) { + // GuiUtil.playButtonClickSound(); + // + // // Invalid state to be in + // if (!Iris.getCurrentPack().isPresent()) { + // return false; + // } + // + // // Displaying a dialog when the game is full-screened can cause severe issues + // // https://github.com/IrisShaders/Iris/issues/1258 + // if (Minecraft.getInstance().getWindow().isFullscreen()) { + // this.screen.displayNotification( + // I18n.format("options.iris.mustDisableFullscreen") + // .withStyle(ChatFormatting.RED).withStyle(ChatFormatting.BOLD)); + // return false; + // } + // + // FileDialogUtil.fileSelectDialog( + // FileDialogUtil.DialogType.SAVE, "Export Shader Settings to File", + // Iris.getShaderpacksDirectory().resolve(Iris.getCurrentPackName() + ".txt"), + // "Shader Pack Settings (.txt)", "*.txt") + // .whenComplete((path, err) -> { + // if (err != null) { + // Iris.logger.error("Error selecting file to export shader settings", err); + // + // return; + // } + // + // path.ifPresent(p -> { + // Properties toSave = new Properties(); + // + // // Dirty way of getting the currently applied settings as a Properties, directly + // // opens and copies out of the saved settings file if it is present + // Path sourceTxtPath = Iris.getShaderpacksDirectory().resolve(Iris.getCurrentPackName() + ".txt"); + // if (Files.exists(sourceTxtPath)) { + // try (InputStream in = Files.newInputStream(sourceTxtPath)) { + // toSave.load(in); + // } catch (IOException ignored) {} + // } + // + // // Save properties to user determined file + // try (OutputStream out = Files.newOutputStream(p)) { + // toSave.store(out, null); + // } catch (IOException e) { + // Iris.logger.error("Error saving properties to \"" + p + "\"", e); + // } + // }); + // }); + + return true; + } +} \ No newline at end of file diff --git a/src/main/java/net/coderbot/iris/gui/element/widget/AbstractElementWidget.java b/src/main/java/net/coderbot/iris/gui/element/widget/AbstractElementWidget.java index 2070db7311..b72a3df791 100644 --- a/src/main/java/net/coderbot/iris/gui/element/widget/AbstractElementWidget.java +++ b/src/main/java/net/coderbot/iris/gui/element/widget/AbstractElementWidget.java @@ -1,7 +1,5 @@ package net.coderbot.iris.gui.element.widget; -import com.mojang.blaze3d.vertex.PoseStack; - import net.coderbot.iris.gui.NavigationController; import net.coderbot.iris.gui.screen.ShaderPackScreen; import net.coderbot.iris.shaderpack.option.menu.OptionMenuElement; @@ -11,7 +9,7 @@ public abstract class AbstractElementWidget { public static final AbstractElementWidget EMPTY = new AbstractElementWidget(null) { @Override - public void render(PoseStack poseStack, int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) {} + public void render(int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) {} }; public AbstractElementWidget(T element) { @@ -20,7 +18,7 @@ public AbstractElementWidget(T element) { public void init(ShaderPackScreen screen, NavigationController navigation) {} - public abstract void render(PoseStack poseStack, int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered); + public abstract void render(int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered); public boolean mouseClicked(double mx, double my, int button) { return false; diff --git a/src/main/java/net/coderbot/iris/gui/element/widget/BaseOptionElementWidget.java b/src/main/java/net/coderbot/iris/gui/element/widget/BaseOptionElementWidget.java index bab4991c65..8f1e1d7efb 100644 --- a/src/main/java/net/coderbot/iris/gui/element/widget/BaseOptionElementWidget.java +++ b/src/main/java/net/coderbot/iris/gui/element/widget/BaseOptionElementWidget.java @@ -2,6 +2,8 @@ import java.util.Optional; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiScreen; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -22,6 +24,8 @@ import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; +import javax.annotation.Nullable; + public abstract class BaseOptionElementWidget extends CommentedElementWidget { protected static final Component SET_TO_DEFAULT = new TranslatableComponent("options.iris.setToDefault").withStyle(ChatFormatting.GREEN); protected static final Component DIVIDER = new TextComponent(": "); @@ -62,7 +66,7 @@ protected final void updateRenderParams(int width, int minValueSectionWidth) { } // Determine the width of the value box - Font font = Minecraft.getInstance().font; + FontRenderer font = Minecraft.getMinecraft().fontRenderer; this.valueSectionWidth = Math.max(minValueSectionWidth, font.width(this.valueLabel) + 8); // Determine maximum width of trimmed label @@ -77,14 +81,14 @@ protected final void updateRenderParams(int width, int minValueSectionWidth) { this.isLabelTrimmed = font.width(this.label) > this.maxLabelWidth; } - protected final void renderOptionWithValue(PoseStack poseStack, int x, int y, int width, int height, boolean hovered, float sliderPosition, int sliderWidth) { + protected final void renderOptionWithValue(int x, int y, int width, int height, boolean hovered, float sliderPosition, int sliderWidth) { GuiUtil.bindIrisWidgetsTexture(); // Draw button background - GuiUtil.drawButton(poseStack, x, y, width, height, hovered, false); + GuiUtil.drawButton(x, y, width, height, hovered, false); // Draw the value box - GuiUtil.drawButton(poseStack, (x + width) - (this.valueSectionWidth + 2), y + 2, this.valueSectionWidth, height - 4, false, true); + GuiUtil.drawButton((x + width) - (this.valueSectionWidth + 2), y + 2, this.valueSectionWidth, height - 4, false, true); // Draw the preview slider if (sliderPosition >= 0) { @@ -94,32 +98,32 @@ protected final void renderOptionWithValue(PoseStack poseStack, int x, int y, in // Position of slider int sliderPos = ((x + width) - this.valueSectionWidth) + (int)(sliderPosition * sliderSpace); - GuiUtil.drawButton(poseStack, sliderPos, y + 4, sliderWidth, height - 8, false, false); + GuiUtil.drawButton(sliderPos, y + 4, sliderWidth, height - 8, false, false); } - Font font = Minecraft.getInstance().font; + FontRenderer font = Minecraft.getMinecraft().fontRenderer; // Draw the label - font.drawShadow(poseStack, this.trimmedLabel, x + 6, y + 7, 0xFFFFFF); + font.drawShadow(this.trimmedLabel, x + 6, y + 7, 0xFFFFFF); // Draw the value label - font.drawShadow(poseStack, this.valueLabel, (x + (width - 2)) - (int)(this.valueSectionWidth * 0.5) - (int)(font.width(this.valueLabel) * 0.5), y + 7, 0xFFFFFF); + font.drawShadow(this.valueLabel, (x + (width - 2)) - (int)(this.valueSectionWidth * 0.5) - (int)(font.width(this.valueLabel) * 0.5), y + 7, 0xFFFFFF); } - protected final void renderOptionWithValue(PoseStack poseStack, int x, int y, int width, int height, boolean hovered) { - this.renderOptionWithValue(poseStack, x, y, width, height, hovered, -1, 0); + protected final void renderOptionWithValue(int x, int y, int width, int height, boolean hovered) { + this.renderOptionWithValue(x, y, width, height, hovered, -1, 0); } - protected final void tryRenderTooltip(PoseStack poseStack, int mouseX, int mouseY, boolean hovered) { - if (Screen.hasShiftDown()) { - renderTooltip(poseStack, SET_TO_DEFAULT, mouseX, mouseY, hovered); + protected final void tryRenderTooltip(int mouseX, int mouseY, boolean hovered) { + if (GuiScreen.isShiftKeyDown()) { + renderTooltip(SET_TO_DEFAULT, mouseX, mouseY, hovered); } else if (this.isLabelTrimmed && !this.screen.isDisplayingComment()) { - renderTooltip(poseStack, this.unmodifiedLabel, mouseX, mouseY, hovered); + renderTooltip(this.unmodifiedLabel, mouseX, mouseY, hovered); } } - protected final void renderTooltip(PoseStack poseStack, Component text, int mouseX, int mouseY, boolean hovered) { + protected final void renderTooltip(Component text, int mouseX, int mouseY, boolean hovered) { if (hovered) { - ShaderPackScreen.TOP_LAYER_RENDER_QUEUE.add(() -> GuiUtil.drawTextPanel(Minecraft.getInstance().font, poseStack, text, mouseX + 2, mouseY - 16)); + ShaderPackScreen.TOP_LAYER_RENDER_QUEUE.add(() -> GuiUtil.drawTextPanel(Minecraft.getMinecraft().fontRenderer, text, mouseX + 2, mouseY - 16)); } } @@ -130,7 +134,7 @@ protected final void updateLabels() { protected final Component createTrimmedLabel() { MutableComponent label = GuiUtil.shortenText( - Minecraft.getInstance().font, + Minecraft.getMinecraft().fontRenderer, this.label.copy(), this.maxLabelWidth); @@ -168,7 +172,7 @@ public boolean mouseClicked(double mx, double my, int button) { if (button == GLFW.GLFW_MOUSE_BUTTON_1 || button == GLFW.GLFW_MOUSE_BUTTON_2) { boolean refresh = false; - if (Screen.hasShiftDown()) { + if (GuiScreen.isShiftKeyDown()) { refresh = applyOriginalValue(); } if (!refresh) { diff --git a/src/main/java/net/coderbot/iris/gui/element/widget/BooleanElementWidget.java b/src/main/java/net/coderbot/iris/gui/element/widget/BooleanElementWidget.java index fbf07c8f07..2902190907 100644 --- a/src/main/java/net/coderbot/iris/gui/element/widget/BooleanElementWidget.java +++ b/src/main/java/net/coderbot/iris/gui/element/widget/BooleanElementWidget.java @@ -49,11 +49,11 @@ public void init(ShaderPackScreen screen, NavigationController navigation) { } @Override - public void render(PoseStack poseStack, int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { + public void render(int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { this.updateRenderParams(width, 28); - this.renderOptionWithValue(poseStack, x, y, width, height, hovered); - this.tryRenderTooltip(poseStack, mouseX, mouseY, hovered); + this.renderOptionWithValue(x, y, width, height, hovered); + this.tryRenderTooltip(mouseX, mouseY, hovered); } @Override diff --git a/src/main/java/net/coderbot/iris/gui/element/widget/LinkElementWidget.java b/src/main/java/net/coderbot/iris/gui/element/widget/LinkElementWidget.java index 850dde3b36..736e6efddf 100644 --- a/src/main/java/net/coderbot/iris/gui/element/widget/LinkElementWidget.java +++ b/src/main/java/net/coderbot/iris/gui/element/widget/LinkElementWidget.java @@ -2,6 +2,7 @@ import java.util.Optional; +import net.minecraft.client.gui.FontRenderer; import org.lwjgl.glfw.GLFW; import com.mojang.blaze3d.vertex.PoseStack; @@ -41,11 +42,11 @@ public void init(ShaderPackScreen screen, NavigationController navigation) { } @Override - public void render(PoseStack poseStack, int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { + public void render(int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { GuiUtil.bindIrisWidgetsTexture(); - GuiUtil.drawButton(poseStack, x, y, width, height, hovered, false); + GuiUtil.drawButton(x, y, width, height, hovered, false); - Font font = Minecraft.getInstance().font; + FontRenderer font = Minecraft.getMinecraft().fontRenderer; int maxLabelWidth = width - 9; @@ -59,12 +60,12 @@ public void render(PoseStack poseStack, int x, int y, int width, int height, int int labelWidth = font.width(this.trimmedLabel); - font.drawShadow(poseStack, this.trimmedLabel, x + (int)(width * 0.5) - (int)(labelWidth * 0.5) - (int)(0.5 * Math.max(labelWidth - (width - 18), 0)), y + 7, 0xFFFFFF); - font.draw(poseStack, ARROW, (x + width) - 9, y + 7, 0xFFFFFF); + font.drawShadow(this.trimmedLabel, x + (int)(width * 0.5) - (int)(labelWidth * 0.5) - (int)(0.5 * Math.max(labelWidth - (width - 18), 0)), y + 7, 0xFFFFFF); + font.draw(ARROW, (x + width) - 9, y + 7, 0xFFFFFF); if (hovered && this.isLabelTrimmed) { // To prevent other elements from being drawn on top of the tooltip - ShaderPackScreen.TOP_LAYER_RENDER_QUEUE.add(() -> GuiUtil.drawTextPanel(font, poseStack, this.label, mouseX + 2, mouseY - 16)); + ShaderPackScreen.TOP_LAYER_RENDER_QUEUE.add(() -> GuiUtil.drawTextPanel(font, this.label, mouseX + 2, mouseY - 16)); } } diff --git a/src/main/java/net/coderbot/iris/gui/element/widget/ProfileElementWidget.java b/src/main/java/net/coderbot/iris/gui/element/widget/ProfileElementWidget.java index 1bf475cc04..64e7c86c27 100644 --- a/src/main/java/net/coderbot/iris/gui/element/widget/ProfileElementWidget.java +++ b/src/main/java/net/coderbot/iris/gui/element/widget/ProfileElementWidget.java @@ -51,10 +51,10 @@ public void init(ShaderPackScreen screen, NavigationController navigation) { } @Override - public void render(PoseStack poseStack, int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { - this.updateRenderParams(width, width - (Minecraft.getInstance().font.width(PROFILE_LABEL) + 16)); + public void render(int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { + this.updateRenderParams(width, width - (Minecraft.getMinecraft().fontRenderer.width(PROFILE_LABEL) + 16)); - this.renderOptionWithValue(poseStack, x, y, width, height, hovered); + this.renderOptionWithValue(x, y, width, height, hovered); } @Override diff --git a/src/main/java/net/coderbot/iris/gui/element/widget/SliderElementWidget.java b/src/main/java/net/coderbot/iris/gui/element/widget/SliderElementWidget.java index 4db7daa0b2..65399c8d9e 100644 --- a/src/main/java/net/coderbot/iris/gui/element/widget/SliderElementWidget.java +++ b/src/main/java/net/coderbot/iris/gui/element/widget/SliderElementWidget.java @@ -1,5 +1,8 @@ package net.coderbot.iris.gui.element.widget; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.util.math.MathHelper; import org.lwjgl.glfw.GLFW; import com.mojang.blaze3d.vertex.PoseStack; @@ -22,19 +25,19 @@ public SliderElementWidget(OptionMenuStringOptionElement element) { } @Override - public void render(PoseStack poseStack, int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { + public void render(int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { this.updateRenderParams(width, 35); if (!hovered) { - this.renderOptionWithValue(poseStack, x, y, width, height, false, (float)valueIndex / (valueCount - 1), PREVIEW_SLIDER_WIDTH); + this.renderOptionWithValue(x, y, width, height, false, (float)valueIndex / (valueCount - 1), PREVIEW_SLIDER_WIDTH); } else { - this.renderSlider(poseStack, x, y, width, height, mouseX, mouseY, tickDelta); + this.renderSlider(x, y, width, height, mouseX, mouseY, tickDelta); } - if (Screen.hasShiftDown()) { - renderTooltip(poseStack, SET_TO_DEFAULT, mouseX, mouseY, hovered); + if (GuiScreen.isShiftKeyDown()) { + renderTooltip(SET_TO_DEFAULT, mouseX, mouseY, hovered); } else if (!this.screen.isDisplayingComment()) { - renderTooltip(poseStack, this.unmodifiedLabel, mouseX, mouseY, hovered); + renderTooltip(this.unmodifiedLabel, mouseX, mouseY, hovered); } if (this.mouseDown) { @@ -47,28 +50,28 @@ public void render(PoseStack poseStack, int x, int y, int width, int height, int } } - private void renderSlider(PoseStack poseStack, int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta) { + private void renderSlider(int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta) { GuiUtil.bindIrisWidgetsTexture(); // Draw background button - GuiUtil.drawButton(poseStack, x, y, width, height, false, false); + GuiUtil.drawButton(x, y, width, height, false, false); // Draw slider area - GuiUtil.drawButton(poseStack, x + 2, y + 2, width - 4, height - 4, false, true); + GuiUtil.drawButton(x + 2, y + 2, width - 4, height - 4, false, true); // Range of x values the slider can occupy int sliderSpace = (width - 8) - ACTIVE_SLIDER_WIDTH; // Position of slider int sliderPos = (x + 4) + (int)(((float)valueIndex / (valueCount - 1)) * sliderSpace); // Draw slider - GuiUtil.drawButton(poseStack, sliderPos, y + 4, ACTIVE_SLIDER_WIDTH, height - 8, this.mouseDown, false); + GuiUtil.drawButton(sliderPos, y + 4, ACTIVE_SLIDER_WIDTH, height - 8, this.mouseDown, false); // Draw value label - Font font = Minecraft.getInstance().font; + FontRenderer font = Minecraft.getMinecraft().fontRenderer; font.drawShadow(poseStack, this.valueLabel, (int)(x + (width * 0.5)) - (int)(font.width(this.valueLabel) * 0.5), y + 7, 0xFFFFFF); } private void whileDragging(int x, int width, int mouseX) { - float mousePositionAcrossWidget = Mth.clamp((float)(mouseX - (x + 4)) / (width - 8), 0, 1); + float mousePositionAcrossWidget = MathHelper.clamp((float)(mouseX - (x + 4)) / (width - 8), 0, 1); int newValueIndex = Math.min(valueCount - 1, (int)(mousePositionAcrossWidget * valueCount)); @@ -91,7 +94,7 @@ private void onReleased() { @Override public boolean mouseClicked(double mx, double my, int button) { if (button == GLFW.GLFW_MOUSE_BUTTON_1) { - if (Screen.hasShiftDown()) { + if (GuiScreen.isShiftKeyDown()) { if (this.applyOriginalValue()) { this.navigation.refresh(); } diff --git a/src/main/java/net/coderbot/iris/gui/element/widget/StringElementWidget.java b/src/main/java/net/coderbot/iris/gui/element/widget/StringElementWidget.java index 58e2e4756a..faa83077d0 100644 --- a/src/main/java/net/coderbot/iris/gui/element/widget/StringElementWidget.java +++ b/src/main/java/net/coderbot/iris/gui/element/widget/StringElementWidget.java @@ -47,11 +47,11 @@ public void init(ShaderPackScreen screen, NavigationController navigation) { } @Override - public void render(PoseStack poseStack, int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { + public void render(int x, int y, int width, int height, int mouseX, int mouseY, float tickDelta, boolean hovered) { this.updateRenderParams(width, 0); - this.renderOptionWithValue(poseStack, x, y, width, height, hovered); - this.tryRenderTooltip(poseStack, mouseX, mouseY, hovered); + this.renderOptionWithValue(x, y, width, height, hovered); + this.tryRenderTooltip(mouseX, mouseY, hovered); } private void increment(int amount) { diff --git a/src/main/java/net/coderbot/iris/gui/option/IrisVideoSettings.java b/src/main/java/net/coderbot/iris/gui/option/IrisVideoSettings.java index 047386a0be..93986cd1d1 100644 --- a/src/main/java/net/coderbot/iris/gui/option/IrisVideoSettings.java +++ b/src/main/java/net/coderbot/iris/gui/option/IrisVideoSettings.java @@ -9,13 +9,15 @@ import net.minecraft.client.ProgressOption; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentTranslation; public class IrisVideoSettings { public static int shadowDistance = 32; // TODO: Tell the user to check in the shader options once that's supported. - private static final Component DISABLED_TOOLTIP = new TranslatableComponent("options.iris.shadowDistance.disabled"); - private static final Component ENABLED_TOOLTIP = new TranslatableComponent("options.iris.shadowDistance.enabled"); + private static final ITextComponent DISABLED_TOOLTIP = new TextComponentTranslation("options.iris.shadowDistance.disabled"); + private static final ITextComponent ENABLED_TOOLTIP = new TextComponentTranslation("options.iris.shadowDistance.enabled"); public static ColorSpace colorSpace = ColorSpace.SRGB; public static int getOverriddenShadowDistance(int base) { @@ -59,14 +61,14 @@ public static boolean isShadowDistanceSliderEnabled() { tooltip = ENABLED_TOOLTIP; } - option.setTooltip(Minecraft.getInstance().font.split(tooltip, 200)); + option.setTooltip(Minecraft.getMinecraft().fontRenderer.split(tooltip, 200)); if (d <= 0.0) { - return new TranslatableComponent("options.generic_value", new TranslatableComponent("options.iris.shadowDistance"), "0 (disabled)"); + return new TextComponentTranslation("options.generic_value", new TextComponentTranslation("options.iris.shadowDistance"), "0 (disabled)"); } else { - return new TranslatableComponent("options.generic_value", - new TranslatableComponent("options.iris.shadowDistance"), - new TranslatableComponent("options.chunks", d)); + return new TextComponentTranslation("options.generic_value", + new TextComponentTranslation("options.iris.shadowDistance"), + new TextComponentTranslation("options.chunks", d)); } }); } diff --git a/src/main/java/net/coderbot/iris/gui/option/ShaderPackSelectionButtonOption.java b/src/main/java/net/coderbot/iris/gui/option/ShaderPackSelectionButtonOption.java index 998773f86f..c697e792d5 100644 --- a/src/main/java/net/coderbot/iris/gui/option/ShaderPackSelectionButtonOption.java +++ b/src/main/java/net/coderbot/iris/gui/option/ShaderPackSelectionButtonOption.java @@ -4,16 +4,17 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.Option; import net.minecraft.client.Options; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.OptionButton; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.TranslatableComponent; public class ShaderPackSelectionButtonOption extends Option { - private final Screen parent; + private final GuiScreen parent; private final Minecraft client; - public ShaderPackSelectionButtonOption(Screen parent, Minecraft client) { + public ShaderPackSelectionButtonOption(GuiScreen parent, Minecraft client) { super("options.iris.shaderPackSelection"); this.parent = parent; this.client = client; diff --git a/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java b/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java index 09cf9faf5c..051d05aa09 100644 --- a/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java +++ b/src/main/java/net/coderbot/iris/gui/screen/ShaderPackScreen.java @@ -15,6 +15,12 @@ import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.util.Util; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentBase; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextFormatting; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -41,18 +47,20 @@ import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.util.FormattedCharSequence; -public class ShaderPackScreen extends Screen implements HudHideable { +import javax.annotation.Nullable; + +public class ShaderPackScreen extends GuiScreen implements HudHideable { /** * Queue rendering to happen on top of all elements. Useful for tooltips or dialogs. */ public static final Set TOP_LAYER_RENDER_QUEUE = new HashSet<>(); - private static final Component SELECT_TITLE = new TranslatableComponent("pack.iris.select.title").withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC); - private static final Component CONFIGURE_TITLE = new TranslatableComponent("pack.iris.configure.title").withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC); + private static final ITextComponent SELECT_TITLE = new TranslatableComponent("pack.iris.select.title").withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC); + private static final ITextComponent CONFIGURE_TITLE = new TranslatableComponent("pack.iris.configure.title").withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC); private static final int COMMENT_PANEL_WIDTH = 314; - private final Screen parent; - private final MutableComponent irisTextComponent; + private final GuiScreen parent; + private final TextComponentBase irisTextComponent; private ShaderPackSelectionList shaderPackList; @@ -60,25 +68,25 @@ public class ShaderPackScreen extends Screen implements HudHideable { private @Nullable NavigationController navigation = null; private Button screenSwitchButton; - private Component notificationDialog = null; + private ITextComponent notificationDialog = null; private int notificationDialogTimer = 0; private @Nullable AbstractElementWidget hoveredElement = null; - private Optional hoveredElementCommentTitle = Optional.empty(); + private Optional hoveredElementCommentTitle = Optional.empty(); private List hoveredElementCommentBody = new ArrayList<>(); private int hoveredElementCommentTimer = 0; private boolean optionMenuOpen = false; private boolean dropChanges = false; - private static String development = "Development Environment"; - private MutableComponent developmentComponent; - private MutableComponent updateComponent; + private static final String development = "Development Environment"; + private TextComponentBase developmentComponent; + private TextComponentBase updateComponent; private boolean guiHidden = false; private float guiButtonHoverTimer = 0.0f; - public ShaderPackScreen(Screen parent) { + public ShaderPackScreen(GuiScreen parent) { super(new TranslatableComponent("options.iris.shaderPackSelection.title")); this.parent = parent; @@ -86,7 +94,7 @@ public ShaderPackScreen(Screen parent) { String irisName = Iris.MODNAME + " " + Iris.getVersion(); if (irisName.contains("-development-environment")) { - this.developmentComponent = new TextComponent("Development Environment").withStyle(ChatFormatting.GOLD); + this.developmentComponent = new TextComponentString(TextFormatting.GOLD + development); irisName = irisName.replace("-development-environment", ""); } @@ -96,37 +104,37 @@ public ShaderPackScreen(Screen parent) { } @Override - public void render(PoseStack poseStack, int mouseX, int mouseY, float delta) { - if (this.minecraft.level == null) { - this.renderBackground(poseStack); + public void render(int mouseX, int mouseY, float delta) { + if (this.mc.world == null) { + this.drawDefaultBackground(); } else if (!this.guiHidden) { - this.fillGradient(poseStack, 0, 0, width, height, 0x4F232323, 0x4F232323); + this.fillGradient(0, 0, width, height, 0x4F232323, 0x4F232323); } if (!this.guiHidden) { if (optionMenuOpen && this.shaderOptionList != null) { - this.shaderOptionList.render(poseStack, mouseX, mouseY, delta); + this.shaderOptionList.render(mouseX, mouseY, delta); } else { - this.shaderPackList.render(poseStack, mouseX, mouseY, delta); + this.shaderPackList.render(mouseX, mouseY, delta); } } float previousHoverTimer = this.guiButtonHoverTimer; - super.render(poseStack, mouseX, mouseY, delta); + super.render(mouseX, mouseY, delta); if (previousHoverTimer == this.guiButtonHoverTimer) { this.guiButtonHoverTimer = 0.0f; } if (!this.guiHidden) { - drawCenteredString(poseStack, this.font, this.title, (int) (this.width * 0.5), 8, 0xFFFFFF); + drawCenteredString(this.fontRenderer, this.title, (int) (this.width * 0.5), 8, 0xFFFFFF); if (notificationDialog != null && notificationDialogTimer > 0) { - drawCenteredString(poseStack, this.font, notificationDialog, (int) (this.width * 0.5), 21, 0xFFFFFF); + drawCenteredString(this.fontRenderer, notificationDialog, (int) (this.width * 0.5), 21, 0xFFFFFF); } else { if (optionMenuOpen) { - drawCenteredString(poseStack, this.font, CONFIGURE_TITLE, (int) (this.width * 0.5), 21, 0xFFFFFF); + drawCenteredString(this.fontRenderer, CONFIGURE_TITLE, (int) (this.width * 0.5), 21, 0xFFFFFF); } else { - drawCenteredString(poseStack, this.font, SELECT_TITLE, (int) (this.width * 0.5), 21, 0xFFFFFF); + drawCenteredString(this.fontRenderer, SELECT_TITLE, (int) (this.width * 0.5), 21, 0xFFFFFF); } } @@ -137,11 +145,11 @@ public void render(PoseStack poseStack, int mouseX, int mouseY, float delta) { int x = (int) (0.5 * this.width) - 157; int y = this.height - (panelHeight + 4); // Draw panel - GuiUtil.drawPanel(poseStack, x, y, COMMENT_PANEL_WIDTH, panelHeight); + GuiUtil.drawPanel(x, y, COMMENT_PANEL_WIDTH, panelHeight); // Draw text - this.font.drawShadow(poseStack, this.hoveredElementCommentTitle.orElse(TextComponent.EMPTY), x + 4, y + 4, 0xFFFFFF); + this.fontRenderer.drawShadow(this.hoveredElementCommentTitle.orElse(TextComponent.EMPTY), x + 4, y + 4, 0xFFFFFF); for (int i = 0; i < this.hoveredElementCommentBody.size(); i++) { - this.font.drawShadow(poseStack, this.hoveredElementCommentBody.get(i), x + 4, (y + 16) + (i * 10), 0xFFFFFF); + this.fontRenderer.drawShadow(this.hoveredElementCommentBody.get(i), x + 4, (y + 16) + (i * 10), 0xFFFFFF); } } } @@ -153,32 +161,32 @@ public void render(PoseStack poseStack, int mouseX, int mouseY, float delta) { TOP_LAYER_RENDER_QUEUE.clear(); if (this.developmentComponent != null) { - this.font.drawShadow(poseStack, developmentComponent, 2, this.height - 10, 0xFFFFFF); - this.font.drawShadow(poseStack, irisTextComponent, 2, this.height - 20, 0xFFFFFF); + this.fontRenderer.drawShadow(developmentComponent, 2, this.height - 10, 0xFFFFFF); + this.fontRenderer.drawShadow(irisTextComponent, 2, this.height - 20, 0xFFFFFF); } else if (this.updateComponent != null) { - this.font.drawShadow(poseStack, updateComponent, 2, this.height - 10, 0xFFFFFF); - this.font.drawShadow(poseStack, irisTextComponent, 2, this.height - 20, 0xFFFFFF); + this.fontRenderer.drawShadow(updateComponent, 2, this.height - 10, 0xFFFFFF); + this.fontRenderer.drawShadow(irisTextComponent, 2, this.height - 20, 0xFFFFFF); } else { - this.font.drawShadow(poseStack, irisTextComponent, 2, this.height - 10, 0xFFFFFF); + this.fontRenderer.drawShadow(irisTextComponent, 2, this.height - 10, 0xFFFFFF); } } @Override - protected void init() { - super.init(); + public void initGui() { + super.initGui(); int bottomCenter = this.width / 2 - 50; int topCenter = this.width / 2 - 76; - boolean inWorld = this.minecraft.level != null; + boolean inWorld = this.mc.world != null; this.children.remove(this.shaderPackList); this.children.remove(this.shaderOptionList); - this.shaderPackList = new ShaderPackSelectionList(this, this.minecraft, this.width, this.height, 32, this.height - 58, 0, this.width); + this.shaderPackList = new ShaderPackSelectionList(this, this.mc, this.width, this.height, 32, this.height - 58, 0, this.width); if (Iris.getCurrentPack().isPresent() && this.navigation != null) { ShaderPack currentPack = Iris.getCurrentPack().get(); - this.shaderOptionList = new ShaderPackOptionList(this, this.navigation, currentPack, this.minecraft, this.width, this.height, 32, this.height - 58, 0, this.width); + this.shaderOptionList = new ShaderPackOptionList(this, this.navigation, currentPack, this.mc, this.width, this.height, 32, this.height - 58, 0, this.width); this.navigation.setActiveOptionList(this.shaderOptionList); this.shaderOptionList.rebuild(); @@ -227,7 +235,7 @@ protected void init() { // than opening the settings for the selected (but not applied) pack. this.applyChanges(); - this.init(); + this.initGui(); } )); @@ -261,7 +269,7 @@ protected void init() { this.init(); }, (button, poseStack, i, j) -> { - this.guiButtonHoverTimer += this.minecraft.getDeltaFrameTime(); + this.guiButtonHoverTimer += this.mc.getTickLength(); if (this.guiButtonHoverTimer >= 10.0f) { TOP_LAYER_RENDER_QUEUE.add(() -> this.renderTooltip(poseStack, showOrHide, i, j)); } @@ -324,7 +332,7 @@ public boolean keyPressed(int key, int j, int k) { if (key == GLFW.GLFW_KEY_ESCAPE) { if (this.guiHidden) { this.guiHidden = false; - this.init(); + this.initGui(); return true; } else if (this.navigation != null && this.navigation.hasHistory()) { @@ -333,7 +341,7 @@ public boolean keyPressed(int key, int j, int k) { return true; } else if (this.optionMenuOpen) { this.optionMenuOpen = false; - this.init(); + this.initGui(); return true; } @@ -387,7 +395,7 @@ public void onPackListFilesDrop(List paths) { // After copying the relevant files over to the folder, make sure to refresh the shader pack list. this.shaderPackList.refresh(); - if (packs.size() == 0) { + if (packs.isEmpty()) { // If zero packs were added, then notify the user that the files that they added weren't actually shader // packs. @@ -482,19 +490,19 @@ public void importPackOptions(Path settingFile) { } @Override - public void onClose() { + public void onGuiClosed() { if (!dropChanges) { applyChanges(); } else { discardChanges(); } - this.minecraft.setScreen(parent); + this.mc.displayGuiScreen(parent); } private void dropChangesAndClose() { dropChanges = true; - onClose(); + onGuiClosed(); } public void applyChanges() { @@ -534,7 +542,30 @@ private void discardChanges() { } private void openShaderPackFolder() { - CompletableFuture.runAsync(() -> Util.getPlatform().openUri(Iris.getShaderpacksDirectoryManager().getDirectoryUri())); + CompletableFuture.runAsync(() -> open(Iris.getShaderpacksDirectoryManager().getDirectoryUri())); + } + + private static String[] getURLOpenCommand(String url) { + switch (Util.getOSType()) { + case WINDOWS: + return new String[]{"rundll32", "url.dll,FileProtocolHandler", url}; + case OSX: + return new String[]{"open", url}; + case UNKNOWN: + case LINUX: + case SOLARIS: + return new String[]{"xdg-open", url}; + default: + throw new IllegalArgumentException("Unexpected OS Type"); + } + } + + public static void open(String url) { + try { + Runtime.getRuntime().exec(getURLOpenCommand(url)); + } catch (IOException exception) { + Iris.logger.error("Couldn't open url '{}'", url, exception); + } } // Let the screen know if an element is hovered or not, allowing for accurately updating which element is hovered @@ -560,7 +591,7 @@ public void setElementHoveredStatus(AbstractElementWidget widget, boolean hov // Line wrap this.hoveredElementCommentBody = new ArrayList<>(); for (MutableComponent text : splitByPeriods) { - this.hoveredElementCommentBody.addAll(this.font.split(text, COMMENT_PANEL_WIDTH - 8)); + this.hoveredElementCommentBody.addAll(this.fontRenderer.split(text, COMMENT_PANEL_WIDTH - 8)); } } } else { diff --git a/src/main/java/net/coderbot/iris/helpers/ColorSRGB.java b/src/main/java/net/coderbot/iris/helpers/ColorSRGB.java index a6dc604b5b..d52120648b 100644 --- a/src/main/java/net/coderbot/iris/helpers/ColorSRGB.java +++ b/src/main/java/net/coderbot/iris/helpers/ColorSRGB.java @@ -1,7 +1,6 @@ package net.coderbot.iris.helpers; - -import com.mojang.blaze3d.platform.NativeImage; +import nanolive.compat.NativeImage; /** * This is a port of the fast-srgb8 library from thomcc on GitHub. diff --git a/src/main/java/net/coderbot/iris/layer/OuterWrappedRenderType.java b/src/main/java/net/coderbot/iris/layer/OuterWrappedRenderType.java index a212905861..3264847b77 100644 --- a/src/main/java/net/coderbot/iris/layer/OuterWrappedRenderType.java +++ b/src/main/java/net/coderbot/iris/layer/OuterWrappedRenderType.java @@ -10,6 +10,8 @@ import net.minecraft.client.renderer.RenderStateShard; import net.minecraft.client.renderer.RenderType; +import javax.annotation.Nullable; + public class OuterWrappedRenderType extends RenderType implements WrappableRenderType { private final RenderStateShard extra; private final RenderType wrapped; diff --git a/src/main/java/net/coderbot/iris/mixin/GlStateManagerAccessor.java b/src/main/java/net/coderbot/iris/mixin/GlStateManagerAccessor.java index b2e4d9f967..3b344b8c70 100644 --- a/src/main/java/net/coderbot/iris/mixin/GlStateManagerAccessor.java +++ b/src/main/java/net/coderbot/iris/mixin/GlStateManagerAccessor.java @@ -1,43 +1,42 @@ package net.coderbot.iris.mixin; +import net.minecraft.client.renderer.GlStateManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -import com.mojang.blaze3d.platform.GlStateManager; - @Mixin(GlStateManager.class) public interface GlStateManagerAccessor { - @Accessor("activeTexture") + @Accessor("activeTextureUnit") static int getActiveTexture() { throw new AssertionError(); } - @Accessor("ALPHA_TEST") + @Accessor("alphaState") static GlStateManager.AlphaState getALPHA_TEST() { throw new UnsupportedOperationException("Not accessed"); } - @Accessor("BLEND") + @Accessor("blendState") static GlStateManager.BlendState getBLEND() { throw new UnsupportedOperationException("Not accessed"); } - @Accessor("COLOR_MASK") + @Accessor("colorMaskState") static GlStateManager.ColorMask getCOLOR_MASK() { throw new UnsupportedOperationException("Not accessed"); } - @Accessor("DEPTH") + @Accessor("depthState") static GlStateManager.DepthState getDEPTH() { throw new UnsupportedOperationException("Not accessed"); } - @Accessor("FOG") + @Accessor("fogState") static GlStateManager.FogState getFOG() { throw new UnsupportedOperationException("Not accessed"); } - @Accessor("TEXTURES") + @Accessor("textureState") static GlStateManager.TextureState[] getTEXTURES() { throw new UnsupportedOperationException("Not accessed"); } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinBlockStateBehavior.java b/src/main/java/net/coderbot/iris/mixin/MixinBlockStateBehavior.java index bf69183043..095a624123 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinBlockStateBehavior.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinBlockStateBehavior.java @@ -1,15 +1,13 @@ package net.coderbot.iris.mixin; +import net.minecraft.block.Block; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import net.coderbot.iris.block_rendering.BlockRenderingSettings; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; /** * This Mixin implements support for the ambientOcclusionLevel value. This injection point was chosen because it's @@ -28,22 +26,19 @@ * this method. * */ -@Mixin(value = BlockBehaviour.BlockStateBase.class, priority = 990) +@Mixin(value = BlockStateContainer.StateImplementation.class, priority = 990) public abstract class MixinBlockStateBehavior { @Shadow public abstract Block getBlock(); - @Shadow - protected abstract BlockState asState(); - /** * @author IMS * @reason ambientOcclusionLevel support. Semantically, we're completely changing the meaning of the method. */ @Overwrite @SuppressWarnings("deprecation") - public float getShadeBrightness(BlockGetter blockGetter, BlockPos blockPos) { - float originalValue = this.getBlock().getShadeBrightness(this.asState(), blockGetter, blockPos); + public float getAmbientOcclusionLightValue() { + float originalValue = this.getBlock().getAmbientOcclusionLightValue(((IBlockState) this)); float aoLightValue = BlockRenderingSettings.INSTANCE.getAmbientOcclusionLevel(); return 1.0F - aoLightValue * (1.0F - originalValue); } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinCrashReport.java b/src/main/java/net/coderbot/iris/mixin/MixinCrashReport.java index 9ae0e841ef..a04e579055 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinCrashReport.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinCrashReport.java @@ -1,28 +1,27 @@ package net.coderbot.iris.mixin; +import net.coderbot.iris.Iris; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import net.coderbot.iris.Iris; -import net.minecraft.CrashReport; -import net.minecraft.CrashReportCategory; - /** * Adds the current shaderpack and number of changed options to crash reports */ @Mixin(CrashReport.class) public abstract class MixinCrashReport { @Shadow - public abstract CrashReportCategory getSystemDetails(); + public abstract CrashReportCategory getCategory(); - @Inject(at = @At("RETURN"), method = "initDetails") + @Inject(at = @At("RETURN"), method = "populateEnvironment") private void fillSystemDetails(CallbackInfo info) { if (Iris.getCurrentPackName() == null) return; // this also gets called at startup for some reason - getSystemDetails().setDetail("Loaded Shaderpack", () -> { + getCategory().addDetail("Loaded Shaderpack", () -> { StringBuilder sb = new StringBuilder(Iris.getCurrentPackName() + (Iris.isFallback() ? " (fallback)" : "")); Iris.getCurrentPack().ifPresent(pack -> { sb.append("\n\t\t"); diff --git a/src/main/java/net/coderbot/iris/mixin/MixinDebugScreenOverlay.java b/src/main/java/net/coderbot/iris/mixin/MixinDebugScreenOverlay.java index 37f63d0a1b..0d84e61ec1 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinDebugScreenOverlay.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinDebugScreenOverlay.java @@ -8,6 +8,8 @@ import java.util.Objects; import net.coderbot.iris.gui.option.IrisVideoSettings; +import net.minecraft.client.gui.GuiOverlayDebug; +import net.minecraft.util.text.TextFormatting; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -15,10 +17,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import net.coderbot.iris.Iris; -import net.minecraft.ChatFormatting; -import net.minecraft.client.gui.components.DebugScreenOverlay; -@Mixin(DebugScreenOverlay.class) +@Mixin(GuiOverlayDebug.class) public abstract class MixinDebugScreenOverlay { @Unique private static final List iris$pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class); @@ -39,7 +39,7 @@ public abstract class MixinDebugScreenOverlay { iris$directPool = Objects.requireNonNull(found); } - @Inject(method = "getSystemInformation", at = @At("RETURN")) + @Inject(method = "getDebugInfoRight", at = @At("RETURN")) private void iris$appendShaderPackText(CallbackInfoReturnable> cir) { List messages = cir.getReturnValue(); @@ -64,13 +64,13 @@ public abstract class MixinDebugScreenOverlay { } } - @Inject(method = "getGameInformation", at = @At("RETURN")) + @Inject(method = "call", at = @At("RETURN")) private void iris$appendShadowDebugText(CallbackInfoReturnable> cir) { List messages = cir.getReturnValue(); if (!Iris.isSodiumInstalled() && Iris.getCurrentPack().isPresent()) { - messages.add(1, ChatFormatting.YELLOW + "[" + Iris.MODNAME + "] Rubidium isn't installed; you will have poor performance."); - messages.add(2, ChatFormatting.YELLOW + "[" + Iris.MODNAME + "] Install Rubidium if you want to run benchmarks or get higher FPS!"); + messages.add(1, TextFormatting.YELLOW + "[" + Iris.MODNAME + "] Vintagium isn't installed; you will have poor performance."); + messages.add(2, TextFormatting.YELLOW + "[" + Iris.MODNAME + "] Install Vintagium if you want to run benchmarks or get higher FPS!"); } Iris.getPipelineManager().getPipeline().ifPresent(pipeline -> pipeline.addDebugText(messages)); diff --git a/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderDispatcher.java b/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderDispatcher.java index d61668d1f3..873a742a0b 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderDispatcher.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderDispatcher.java @@ -1,52 +1,28 @@ package net.coderbot.iris.mixin; +import net.coderbot.iris.Iris; +import net.coderbot.iris.pipeline.WorldRenderingPipeline; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.VertexConsumer; - -import net.coderbot.iris.Iris; -import net.coderbot.iris.pipeline.WorldRenderingPipeline; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.entity.EntityRenderDispatcher; -import net.minecraft.core.BlockPos; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.LevelReader; -import net.minecraft.world.phys.Vec3; - -@Mixin(EntityRenderDispatcher.class) +@Mixin(Render.class) public class MixinEntityRenderDispatcher { - private static final String RENDER_SHADOW = - "renderShadow(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/world/entity/Entity;FFLnet/minecraft/world/level/LevelReader;F)V"; - private static final String RENDER_BLOCK_SHADOW = - "renderBlockShadow(Lcom/mojang/blaze3d/vertex/PoseStack$Pose;Lcom/mojang/blaze3d/vertex/VertexConsumer;Lnet/minecraft/world/level/LevelReader;Lnet/minecraft/core/BlockPos;DDDFF)V"; - @Inject(method = RENDER_SHADOW, at = @At("HEAD"), cancellable = true) - private static void iris$maybeSuppressEntityShadow(PoseStack poseStack, MultiBufferSource bufferSource, - Entity entity, float opacity, float tickDelta, LevelReader level, - float radius, CallbackInfo ci) { + @Inject(method = "renderShadow", at = @At("HEAD"), cancellable = true) + private void iris$maybeSuppressEntityShadow(Entity entityIn, double x, double y, double z, float shadowAlpha, float partialTicks, CallbackInfo ci) { iris$maybeSuppressShadow(ci); } // The underlying method called by renderShadow. - @Inject(method = RENDER_BLOCK_SHADOW, at = @At("HEAD"), cancellable = true) - private static void renderBlockShadow(PoseStack.Pose pose, VertexConsumer vc, LevelReader level, BlockPos pos, - double d, double e, double f, float g, float h, CallbackInfo ci) { - iris$maybeSuppressShadow(ci); - } - - // First Person Model by tr7zw compatibility, this is a method added by First Person Model: - // https://github.com/tr7zw/FirstPersonModel/blob/172ab05368832df82e34ca9f9b06814672f69f59/FPShared/src/main/java/dev/tr7zw/firstperson/mixins/RenderDispatcherMixin.java#L68 - // The renderBlockShadow injection will handle this, but it's easier to suppress it before all of the other calculations. - @SuppressWarnings("target") - @Inject(method = "renderOffsetShadow", at = @At("HEAD"), cancellable = true, require = 0, remap=false) - private static void iris$maybeSuppressEntityShadow(PoseStack poseStack, MultiBufferSource bufferSource, - Entity entity, float opacity, float tickDelta, LevelReader level, - float radius, Vec3 offset, CallbackInfo ci) { + @Inject(method = "renderShadowSingle", at = @At("HEAD"), cancellable = true) + private void renderBlockShadow(IBlockState state, double x, double y, double z, BlockPos pos, float shadowAlpha, float shadowSize, double x2, double y2, double z2, CallbackInfo ci) { iris$maybeSuppressShadow(ci); } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderer.java new file mode 100644 index 0000000000..c7fba78b61 --- /dev/null +++ b/src/main/java/net/coderbot/iris/mixin/MixinEntityRenderer.java @@ -0,0 +1,114 @@ +package net.coderbot.iris.mixin; + +import nanolive.utils.RenderGlobalExtended; +import net.coderbot.iris.Iris; +import net.coderbot.iris.gl.program.Program; +import net.coderbot.iris.pipeline.HandRenderer; +import net.coderbot.iris.pipeline.WorldRenderingPhase; +import net.coderbot.iris.uniforms.CapturedRenderingState; +import net.coderbot.iris.uniforms.SystemTimeUniforms; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.client.settings.GameSettings; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.Slice; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(EntityRenderer.class) +public class MixinEntityRenderer { + + @Shadow + @Final + private Minecraft mc; + + // Begin shader rendering after buffers have been cleared. + // At this point we've ensured that Minecraft's main framebuffer is cleared. + // This is important or else very odd issues will happen with shaders that have a final pass that doesn't write to + // all pixels. + @Inject(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;clear(I)V", ordinal = 0, shift = At.Shift.AFTER)) + private void iris$beginLevelRender(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + CapturedRenderingState.INSTANCE.setGbufferModelView(poseStack.last().pose()); + CapturedRenderingState.INSTANCE.setGbufferProjection(projection); + CapturedRenderingState.INSTANCE.setTickDelta(partialTicks); + SystemTimeUniforms.COUNTER.beginFrame(); + SystemTimeUniforms.TIMER.beginFrame(finishTimeNano); + + Program.unbind(); + + RenderGlobalExtended renderGlobalExtended = (RenderGlobalExtended) this.mc.renderGlobal; + renderGlobalExtended.setPipeline(Iris.getPipelineManager().preparePipeline(Iris.getCurrentDimension())); + + renderGlobalExtended.getPipeline().beginLevelRendering(); + } + + // Inject a bit early so that we can end our rendering before mods like VoxelMap (which inject at RETURN) + // render their waypoint beams. + @Inject(method = "renderWorldPass", at = @At(value = "RETURN", shift = At.Shift.BEFORE)) + private void iris$endLevelRender(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + HandRenderer.INSTANCE.renderTranslucent(poseStack, tickDelta, camera, gameRenderer, pipeline); + mc.profiler.endStartSection("iris_final"); + + RenderGlobalExtended renderGlobalExtended = (RenderGlobalExtended) this.mc.renderGlobal; + renderGlobalExtended.getPipeline().finalizeLevelRendering(); + renderGlobalExtended.setPipeline(null); + + Program.unbind(); + } + + @Redirect(method = "renderWorldPass", at = @At(value = "FIELD", target = "Lnet/minecraft/client/settings/GameSettings;renderDistanceChunks:I"), + slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/culling/ICamera;setPosition(DDD)V"))) + private int iris$alwaysRenderSky(GameSettings instance) { + return Math.max(instance.renderDistanceChunks, 4); + } + + @Inject(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;renderSky(FI)V", shift = At.Shift.AFTER)) + private void iris$endSky(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + ((RenderGlobalExtended) this.mc.renderGlobal).getPipeline().setPhase(WorldRenderingPhase.NONE); + } + + @Inject(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;renderCloudsCheck(Lnet/minecraft/client/renderer/RenderGlobal;FIDDD)V")) + private void iris$beginClouds(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + ((RenderGlobalExtended) this.mc.renderGlobal).getPipeline().setPhase(WorldRenderingPhase.CLOUDS); + } + + @Inject(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;renderCloudsCheck(Lnet/minecraft/client/renderer/RenderGlobal;FIDDD)V", shift = At.Shift.AFTER)) + private void iris$endClouds(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + ((RenderGlobalExtended) this.mc.renderGlobal).getPipeline().setPhase(WorldRenderingPhase.NONE); + } + + @Inject(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;renderWorldBorder(Lnet/minecraft/entity/Entity;F)V")) + private void iris$beginWorldBorder(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + ((RenderGlobalExtended) this.mc.renderGlobal).getPipeline().setPhase(WorldRenderingPhase.WORLD_BORDER); + } + + @Inject(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;renderWorldBorder(Lnet/minecraft/entity/Entity;F)V", shift = At.Shift.AFTER)) + private void iris$endWorldBorder(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + ((RenderGlobalExtended) this.mc.renderGlobal).getPipeline().setPhase(WorldRenderingPhase.NONE); + } + + @Inject(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/debug/DebugRenderer;renderDebug(FJ)V")) + private void iris$setDebugRenderStage(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + ((RenderGlobalExtended) this.mc.renderGlobal).getPipeline().setPhase(WorldRenderingPhase.DEBUG); + } + + @Inject(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/debug/DebugRenderer;renderDebug(FJ)V", shift = At.Shift.AFTER)) + private void iris$resetDebugRenderStage(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + ((RenderGlobalExtended) this.mc.renderGlobal).getPipeline().setPhase(WorldRenderingPhase.NONE); + } + + @Inject(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;renderRainSnow(F)V")) + private void iris$beginWeather(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + ((RenderGlobalExtended) this.mc.renderGlobal).getPipeline().setPhase(WorldRenderingPhase.RAIN_SNOW); + } + + @Inject(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;renderRainSnow(F)V", shift = At.Shift.AFTER)) + private void iris$endWeather(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + ((RenderGlobalExtended) this.mc.renderGlobal).getPipeline().setPhase(WorldRenderingPhase.NONE); + } + +} diff --git a/src/main/java/net/coderbot/iris/mixin/MixinFogRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinFogRenderer.java index 54aa0222ae..eb616e9305 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinFogRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinFogRenderer.java @@ -1,21 +1,19 @@ package net.coderbot.iris.mixin; +import net.coderbot.iris.uniforms.CapturedRenderingState; +import net.minecraft.client.renderer.EntityRenderer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import net.coderbot.iris.uniforms.CapturedRenderingState; -import net.minecraft.client.Camera; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.FogRenderer; - -@Mixin(FogRenderer.class) +@Mixin(EntityRenderer.class) public class MixinFogRenderer { - @Shadow private static float fogRed, fogGreen, fogBlue; - @Inject(method = "setupColor", at = @At("TAIL")) - private static void render(Camera camera, float tickDelta, ClientLevel level, int i, float f, CallbackInfo ci) { - CapturedRenderingState.INSTANCE.setFogColor(fogRed, fogGreen, fogBlue); + @Shadow private float fogColorRed, fogColorGreen, fogColorBlue; + + @Inject(method = "updateFogColor", at = @At("TAIL")) + private void render(float partialTicks, CallbackInfo ci) { + CapturedRenderingState.INSTANCE.setFogColor(fogColorRed, fogColorGreen, fogColorBlue); } } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java index c1588de8dd..9649bf33b0 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java @@ -1,46 +1,38 @@ package net.coderbot.iris.mixin; +import net.coderbot.iris.Iris; +import net.irisshaders.iris.api.v0.IrisApi; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.resources.IResourceManager; +import org.lwjgl.opengl.GL11; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.platform.GlUtil; -import com.mojang.blaze3d.vertex.PoseStack; - -import net.coderbot.iris.Iris; -import net.irisshaders.iris.api.v0.IrisApi; -import net.minecraft.client.Minecraft; -import net.minecraft.client.player.LocalPlayer; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.client.renderer.ItemInHandRenderer; -import net.minecraft.client.renderer.MultiBufferSource.BufferSource; -import net.minecraft.client.renderer.RenderBuffers; -import net.minecraft.server.packs.resources.ResourceManager; - -@Mixin(GameRenderer.class) +@Mixin(EntityRenderer.class) public class MixinGameRenderer { - @Shadow - private boolean renderHand; @Inject(method = "", at = @At("TAIL")) - private void iris$logSystem(Minecraft client, ResourceManager resourceManager, RenderBuffers bufferBuilderStorage, - CallbackInfo ci) { + private void iris$logSystem(Minecraft client, IResourceManager resourceManager, CallbackInfo ci) { Iris.logger.info("Hardware information:"); - Iris.logger.info("CPU: " + GlUtil.getCpuInfo()); - Iris.logger.info("GPU: " + GlUtil.getRenderer() + " (Supports OpenGL " + GlUtil.getOpenGLVersion() + ")"); + Iris.logger.info("CPU: " + OpenGlHelper.getCpu()); + Iris.logger.info("GPU: " + GlStateManager.glGetString(GL11.GL_RENDERER) + " (Supports OpenGL " + GlStateManager.glGetString(GL11.GL_VERSION) + ")"); Iris.logger.info("OS: " + System.getProperty("os.name") + " (" + System.getProperty("os.version") + ")"); } - @Redirect(method = "renderItemInHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ItemInHandRenderer;renderHandsWithItems(FLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/player/LocalPlayer;I)V")) - private void disableVanillaHandRendering(ItemInHandRenderer itemInHandRenderer, float tickDelta, PoseStack poseStack, BufferSource bufferSource, LocalPlayer localPlayer, int light) { + @Redirect(method = "renderHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ItemRenderer;renderItemInFirstPerson(F)V")) + private void disableVanillaHandRendering(ItemRenderer instance, float partialTicks) { if (IrisApi.getInstance().isShaderPackInUse()) { return; } - itemInHandRenderer.renderHandsWithItems(tickDelta, poseStack, bufferSource, localPlayer, light); + instance.renderItemInFirstPerson(partialTicks); } } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer_NightVisionCompat.java b/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer_NightVisionCompat.java index 099fa97284..6f6047bb8c 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer_NightVisionCompat.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGameRenderer_NightVisionCompat.java @@ -1,29 +1,28 @@ package net.coderbot.iris.mixin; +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.init.MobEffects; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.LivingEntity; - // Priority of 1010 (> 1000) to run after other mod mixins. In particular, Night Vision Flash Be Gone overwrites this // method, so we need to run after it so that our injection silently fails instead of crashing the game. -@Mixin(value = GameRenderer.class, priority = 1010) +@Mixin(value = EntityRenderer.class, priority = 1010) public class MixinGameRenderer_NightVisionCompat { // Origins compatibility: Allows us to call getNightVisionScale even if the entity does not have night vision. // This injection gives a chance for mods injecting at HEAD to return a modified night vision value. // // It's optional because of Night Vision Flash Be Gone overwriting this method, but having this injection // succeed avoids a lot of spurious (but silently caught) NullPointerExceptions. - @Inject(method = "getNightVisionScale", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/effect/MobEffectInstance;getDuration()I"), cancellable = true, + @Inject(method = "getNightVisionBrightness", at = @At(value = "INVOKE", + target = "Lnet/minecraft/potion/PotionEffect;getDuration()I"), cancellable = true, require = 0) - private static void iris$safecheckNightvisionStrength(LivingEntity livingEntity, float partialTicks, - CallbackInfoReturnable cir){ - if (livingEntity.getEffect(MobEffects.NIGHT_VISION) == null) { + private void iris$safecheckNightvisionStrength(EntityLivingBase livingEntity, float partialTicks, + CallbackInfoReturnable cir){ + if (livingEntity.getActivePotionEffect(MobEffects.NIGHT_VISION) == null) { cir.setReturnValue(0.0f); } } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager.java b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager.java index 006d99bcee..10a8f0bba0 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager.java @@ -4,7 +4,7 @@ import org.spongepowered.asm.mixin.injection.Constant; import org.spongepowered.asm.mixin.injection.ModifyConstant; -import com.mojang.blaze3d.platform.GlStateManager; +import net.minecraft.client.renderer.GlStateManager; import net.coderbot.iris.gl.sampler.SamplerLimits; diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_AlphaTestOverride.java b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_AlphaTestOverride.java index c306619cf2..98461bbd7f 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_AlphaTestOverride.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_AlphaTestOverride.java @@ -1,17 +1,16 @@ package net.coderbot.iris.mixin; +import net.minecraft.client.renderer.GlStateManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.platform.GlStateManager; - import net.coderbot.iris.gl.blending.AlphaTestStorage; @Mixin(GlStateManager.class) public class MixinGlStateManager_AlphaTestOverride { - @Inject(method = "_disableAlphaTest", at = @At("HEAD"), cancellable = true) + @Inject(method = "disableAlpha", at = @At("HEAD"), cancellable = true) private static void iris$alphaTestDisableLock(CallbackInfo ci) { if (AlphaTestStorage.isAlphaTestLocked()) { AlphaTestStorage.deferAlphaTestToggle(false); @@ -19,7 +18,7 @@ public class MixinGlStateManager_AlphaTestOverride { } } - @Inject(method = "_enableAlphaTest", at = @At("HEAD"), cancellable = true) + @Inject(method = "enableAlpha", at = @At("HEAD"), cancellable = true) private static void iris$alphaTestEnableLock(CallbackInfo ci) { if (AlphaTestStorage.isAlphaTestLocked()) { AlphaTestStorage.deferAlphaTestToggle(true); @@ -27,7 +26,7 @@ public class MixinGlStateManager_AlphaTestOverride { } } - @Inject(method = "_alphaFunc", at = @At("HEAD"), cancellable = true) + @Inject(method = "alphaFunc", at = @At("HEAD"), cancellable = true) private static void iris$alphaFuncLock(int function, float reference, CallbackInfo ci) { if (AlphaTestStorage.isAlphaTestLocked()) { AlphaTestStorage.deferAlphaFunc(function, reference); diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_AmdCrashFix.java b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_AmdCrashFix.java index 397a50fb2b..4f351b5833 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_AmdCrashFix.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_AmdCrashFix.java @@ -1,24 +1,32 @@ package net.coderbot.iris.mixin; +import net.minecraft.client.renderer.OpenGlHelper; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import com.mojang.blaze3d.platform.GlStateManager; - import net.coderbot.iris.gl.shader.ShaderWorkarounds; +import java.nio.ByteBuffer; + /** * Works around a bug in AMD drivers that causes crashes with glShaderSource. * - * See {@link ShaderWorkarounds#safeShaderSource(int, CharSequence)} for more details. + * See {@link ShaderWorkarounds#safeShaderSource(int, ByteBuffer)} for more details. */ -@Mixin(GlStateManager.class) +@Mixin(OpenGlHelper.class) public class MixinGlStateManager_AmdCrashFix { - @Redirect(method = "glShaderSource(ILjava/lang/CharSequence;)V", + @Redirect(method = "glShaderSource", + at = @At(value = "INVOKE", + target = "Lorg/lwjgl/opengl/GL20;glShaderSource(ILjava/nio/ByteBuffer;)V")) + private static void iris$safeShaderSource(int glId, ByteBuffer source) { + ShaderWorkarounds.safeShaderSource(glId, source); + } + + @Redirect(method = "glShaderSource", at = @At(value = "INVOKE", - target = "org/lwjgl/opengl/GL20.glShaderSource (ILjava/lang/CharSequence;)V")) - private static void iris$safeShaderSource(int glId, CharSequence source) { + target = "Lorg/lwjgl/opengl/ARBShaderObjects;glShaderSourceARB(ILjava/nio/ByteBuffer;)V")) + private static void iris$arbSafeShaderSource(int glId, ByteBuffer source) { ShaderWorkarounds.safeShaderSource(glId, source); } } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_BlendOverride.java b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_BlendOverride.java index 249b980c8d..af1d63aa68 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_BlendOverride.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_BlendOverride.java @@ -1,17 +1,16 @@ package net.coderbot.iris.mixin; +import net.minecraft.client.renderer.GlStateManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.platform.GlStateManager; - import net.coderbot.iris.gl.blending.BlendModeStorage; @Mixin(GlStateManager.class) public class MixinGlStateManager_BlendOverride { - @Inject(method = "_disableBlend", at = @At("HEAD"), cancellable = true) + @Inject(method = "disableBlend", at = @At("HEAD"), cancellable = true) private static void iris$blendDisableLock(CallbackInfo ci) { if (BlendModeStorage.isBlendLocked()) { BlendModeStorage.deferBlendModeToggle(false); @@ -19,7 +18,7 @@ public class MixinGlStateManager_BlendOverride { } } - @Inject(method = "_enableBlend", at = @At("HEAD"), cancellable = true) + @Inject(method = "enableBlend", at = @At("HEAD"), cancellable = true) private static void iris$blendEnableLock(CallbackInfo ci) { if(BlendModeStorage.isBlendLocked()) { BlendModeStorage.deferBlendModeToggle(true); @@ -27,7 +26,7 @@ public class MixinGlStateManager_BlendOverride { } } - @Inject(method = "_blendFunc", at = @At("HEAD"), cancellable = true) + @Inject(method = "blendFunc(II)V", at = @At("HEAD"), cancellable = true) private static void iris$blendFuncLock(int srcFactor, int dstFactor, CallbackInfo ci) { if(BlendModeStorage.isBlendLocked()) { BlendModeStorage.deferBlendFunc(srcFactor, dstFactor, srcFactor, dstFactor); @@ -35,7 +34,7 @@ public class MixinGlStateManager_BlendOverride { } } - @Inject(method = "_blendFuncSeparate", at = @At("HEAD"), cancellable = true) + @Inject(method = "tryBlendFuncSeparate(IIII)V", at = @At("HEAD"), cancellable = true) private static void iris$blendFuncSeparateLock(int srcRgb, int dstRgb, int srcAlpha, int dstAlpha, CallbackInfo ci) { if(BlendModeStorage.isBlendLocked()) { BlendModeStorage.deferBlendFunc(srcRgb, dstRgb, srcAlpha, dstAlpha); diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_DepthColorOverride.java b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_DepthColorOverride.java index 755be54fb5..114e3b380f 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_DepthColorOverride.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_DepthColorOverride.java @@ -1,17 +1,16 @@ package net.coderbot.iris.mixin; +import net.minecraft.client.renderer.GlStateManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.platform.GlStateManager; - import net.coderbot.iris.gl.blending.DepthColorStorage; @Mixin(GlStateManager.class) public class MixinGlStateManager_DepthColorOverride { - @Inject(method = "_colorMask", at = @At("HEAD"), cancellable = true) + @Inject(method = "colorMask", at = @At("HEAD"), cancellable = true) private static void iris$colorMaskLock(boolean red, boolean green, boolean blue, boolean alpha, CallbackInfo ci) { if (DepthColorStorage.isDepthColorLocked()) { DepthColorStorage.deferColorMask(red, green, blue, alpha); @@ -19,7 +18,7 @@ public class MixinGlStateManager_DepthColorOverride { } } - @Inject(method = "_depthMask", at = @At("HEAD"), cancellable = true) + @Inject(method = "depthMask", at = @At("HEAD"), cancellable = true) private static void iris$depthMaskLock(boolean enable, CallbackInfo ci) { if (DepthColorStorage.isDepthColorLocked()) { DepthColorStorage.deferDepthEnable(enable); diff --git a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_FramebufferBinding.java b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_FramebufferBinding.java index 776f3f6ca5..9b479b3d75 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_FramebufferBinding.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_FramebufferBinding.java @@ -1,39 +1,37 @@ package net.coderbot.iris.mixin; -import org.lwjgl.opengl.GL30C; +import net.minecraft.client.renderer.OpenGlHelper; +import org.lwjgl.opengl.GL30; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.platform.GlConst; -import com.mojang.blaze3d.platform.GlStateManager; - /** * A simple optimization to avoid redundant glBindFramebuffer calls, works in principle the same as things like * glBindTexture in GlStateManager. */ -@Mixin(GlStateManager.class) +@Mixin(OpenGlHelper.class) public class MixinGlStateManager_FramebufferBinding { private static int iris$drawFramebuffer = 0; private static int iris$readFramebuffer = 0; - @Inject(method = "_glBindFramebuffer(II)V", at = @At("HEAD"), cancellable = true) + @Inject(method = "glBindFramebuffer(II)V", at = @At("HEAD"), cancellable = true) private static void iris$avoidRedundantBind(int target, int framebuffer, CallbackInfo ci) { - if (target == GlConst.GL_FRAMEBUFFER) { + if (target == OpenGlHelper.GL_FRAMEBUFFER) { if (iris$drawFramebuffer == target && iris$readFramebuffer == target) { ci.cancel(); } else { iris$drawFramebuffer = framebuffer; iris$readFramebuffer = framebuffer; } - } else if (target == GL30C.GL_DRAW_FRAMEBUFFER) { + } else if (target == GL30.GL_DRAW_FRAMEBUFFER) { if (iris$drawFramebuffer == target) { ci.cancel(); } else { iris$drawFramebuffer = framebuffer; } - } else if (target == GL30C.GL_READ_FRAMEBUFFER) { + } else if (target == GL30.GL_READ_FRAMEBUFFER) { if (iris$readFramebuffer == target) { ci.cancel(); } else { @@ -44,7 +42,7 @@ public class MixinGlStateManager_FramebufferBinding { } } - @Inject(method = "_glDeleteFramebuffers(I)V", at = @At("HEAD")) + @Inject(method = "glDeleteFramebuffers(I)V", at = @At("HEAD")) private static void iris$trackFramebufferDelete(int framebuffer, CallbackInfo ci) { if (iris$drawFramebuffer == framebuffer) { iris$drawFramebuffer = 0; diff --git a/src/main/java/net/coderbot/iris/mixin/MixinItem.java b/src/main/java/net/coderbot/iris/mixin/MixinItem.java index fe0c981178..ba77a2eecd 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinItem.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinItem.java @@ -1,9 +1,9 @@ package net.coderbot.iris.mixin; +import net.minecraft.item.Item; import org.spongepowered.asm.mixin.Mixin; import net.irisshaders.iris.api.v0.item.IrisItemLightProvider; -import net.minecraft.world.item.Item; @Mixin(Item.class) public class MixinItem implements IrisItemLightProvider { diff --git a/src/main/java/net/coderbot/iris/mixin/MixinItemBlockRenderTypes.java b/src/main/java/net/coderbot/iris/mixin/MixinItemBlockRenderTypes.java index 9110a5aaa9..3850ddae11 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinItemBlockRenderTypes.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinItemBlockRenderTypes.java @@ -1,41 +1,26 @@ package net.coderbot.iris.mixin; -import java.util.Map; - +import net.coderbot.iris.block_rendering.BlockRenderingSettings; +import net.minecraft.block.Block; +import net.minecraft.util.BlockRenderLayer; import net.minecraftforge.registries.IRegistryDelegate; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.coderbot.iris.block_rendering.BlockRenderingSettings; -import net.minecraft.client.renderer.ItemBlockRenderTypes; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; +import java.util.Map; -@Mixin(ItemBlockRenderTypes.class) +@Mixin(Block.class) public class MixinItemBlockRenderTypes { - @Inject(method = "getChunkRenderType", at = @At("HEAD"), cancellable = true) - private static void iris$setCustomRenderType(BlockState arg, CallbackInfoReturnable cir) { - Map, RenderType> idMap = BlockRenderingSettings.INSTANCE.getBlockTypeIds(); + @Inject(method = "getRenderLayer", at = @At("HEAD"), cancellable = true) + private void iris$setCustomRenderType(CallbackInfoReturnable cir) { + Map, BlockRenderLayer> idMap = BlockRenderingSettings.INSTANCE.getBlockTypeIds(); if (idMap != null) { - RenderType type = idMap.get(arg.getBlock().delegate); + BlockRenderLayer type = idMap.get(((Block) (Object) this).delegate); if (type != null) { cir.setReturnValue(type); } } } - - @Inject(method = "canRenderInLayer(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/client/renderer/RenderType;)Z", at = @At("HEAD"), cancellable = true) - private static void iris$checkCustomRenderType(BlockState arg, RenderType type, CallbackInfoReturnable cir) { - Map, RenderType> idMap = BlockRenderingSettings.INSTANCE.getBlockTypeIds(); - if (idMap != null) { - RenderType irisType = idMap.get(arg.getBlock().delegate); - if (irisType != null) { - // If we have an override registered for this block, only allow rendering precisely that type - cir.setReturnValue(type.equals(irisType)); - } - } - } } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinItemInHandRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinItemInHandRenderer.java index dc8be6e4a7..9f1341e1bd 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinItemInHandRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinItemInHandRenderer.java @@ -1,28 +1,24 @@ package net.coderbot.iris.mixin; +import net.coderbot.iris.pipeline.HandRenderer; +import net.irisshaders.iris.api.v0.IrisApi; +import net.minecraft.client.entity.AbstractClientPlayer; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.vertex.PoseStack; - -import net.coderbot.iris.pipeline.HandRenderer; -import net.irisshaders.iris.api.v0.IrisApi; -import net.minecraft.client.player.AbstractClientPlayer; -import net.minecraft.client.renderer.ItemInHandRenderer; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.item.ItemStack; - -@Mixin(ItemInHandRenderer.class) +@Mixin(ItemRenderer.class) public class MixinItemInHandRenderer { - @Inject(method = "renderArmWithItem", at = @At("HEAD"), cancellable = true) - private void iris$skipTranslucentHands(AbstractClientPlayer abstractClientPlayer, float f, float g, InteractionHand interactionHand, float h, ItemStack itemStack, float i, PoseStack poseStack, MultiBufferSource multiBufferSource, int j, CallbackInfo ci) { + @Inject(method = "renderItemInFirstPerson(Lnet/minecraft/client/entity/AbstractClientPlayer;FFLnet/minecraft/util/EnumHand;FLnet/minecraft/item/ItemStack;F)V", at = @At("HEAD"), cancellable = true) + private void iris$skipTranslucentHands(AbstractClientPlayer player, float p_187457_2_, float p_187457_3_, EnumHand hand, float p_187457_5_, ItemStack stack, float p_187457_7_, CallbackInfo ci) { if (IrisApi.getInstance().isShaderPackInUse()) { - if (HandRenderer.INSTANCE.isRenderingSolid() && HandRenderer.INSTANCE.isHandTranslucent(interactionHand)) { + if (HandRenderer.INSTANCE.isRenderingSolid() && HandRenderer.INSTANCE.isHandTranslucent(hand)) { ci.cancel(); - } else if (!HandRenderer.INSTANCE.isRenderingSolid() && !HandRenderer.INSTANCE.isHandTranslucent(interactionHand)) { + } else if (!HandRenderer.INSTANCE.isRenderingSolid() && !HandRenderer.INSTANCE.isHandTranslucent(hand)) { ci.cancel(); } } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java index 54df901987..4173ec1dfd 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java @@ -1,5 +1,9 @@ package net.coderbot.iris.mixin; +import nanolive.utils.RenderGlobalExtended; +import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.entity.Entity; +import net.minecraft.util.BlockRenderLayer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -31,55 +35,15 @@ import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.RenderBuffers; import net.minecraft.client.renderer.RenderType; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(LevelRenderer.class) -public class MixinLevelRenderer { - private static final String RENDER_LEVEL = "Lnet/minecraft/client/renderer/LevelRenderer;renderLevel(Lcom/mojang/blaze3d/vertex/PoseStack;FJZLnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/GameRenderer;Lnet/minecraft/client/renderer/LightTexture;Lcom/mojang/math/Matrix4f;)V"; - private static final String CLEAR = "Lcom/mojang/blaze3d/systems/RenderSystem;clear(IZ)V"; - private static final String RENDER_SKY = "Lnet/minecraft/client/renderer/LevelRenderer;renderSky(Lcom/mojang/blaze3d/vertex/PoseStack;F)V"; - private static final String RENDER_LAYER = "Lnet/minecraft/client/renderer/LevelRenderer;renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDD)V"; - private static final String RENDER_CLOUDS = "Lnet/minecraft/client/renderer/LevelRenderer;renderClouds(Lcom/mojang/blaze3d/vertex/PoseStack;FDDD)V"; +@Mixin(RenderGlobal.class) +public class MixinLevelRenderer implements RenderGlobalExtended { private static final String RENDER_WEATHER = "Lnet/minecraft/client/renderer/LevelRenderer;renderSnowAndRain(Lnet/minecraft/client/renderer/LightTexture;FDDD)V"; - private static final String RENDER_WORLD_BOUNDS = "Lnet/minecraft/client/renderer/LevelRenderer;renderWorldBounds(Lnet/minecraft/client/Camera;)V"; @Unique private WorldRenderingPipeline pipeline; - @Shadow - private RenderBuffers renderBuffers; - - // Begin shader rendering after buffers have been cleared. - // At this point we've ensured that Minecraft's main framebuffer is cleared. - // This is important or else very odd issues will happen with shaders that have a final pass that doesn't write to - // all pixels. - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = CLEAR, shift = At.Shift.AFTER)) - private void iris$beginLevelRender(PoseStack poseStack, float tickDelta, long startTime, boolean renderBlockOutline, - Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, - Matrix4f projection, CallbackInfo callback) { - CapturedRenderingState.INSTANCE.setGbufferModelView(poseStack.last().pose()); - CapturedRenderingState.INSTANCE.setGbufferProjection(projection); - CapturedRenderingState.INSTANCE.setTickDelta(tickDelta); - SystemTimeUniforms.COUNTER.beginFrame(); - SystemTimeUniforms.TIMER.beginFrame(startTime); - - Program.unbind(); - - pipeline = Iris.getPipelineManager().preparePipeline(Iris.getCurrentDimension()); - - pipeline.beginLevelRendering(); - } - - // Inject a bit early so that we can end our rendering before mods like VoxelMap (which inject at RETURN) - // render their waypoint beams. - @Inject(method = RENDER_LEVEL, at = @At(value = "RETURN", shift = At.Shift.BEFORE)) - private void iris$endLevelRender(PoseStack poseStack, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projection, CallbackInfo callback) { - HandRenderer.INSTANCE.renderTranslucent(poseStack, tickDelta, camera, gameRenderer, pipeline); - Minecraft.getInstance().getProfiler().popPush("iris_final"); - pipeline.finalizeLevelRendering(); - pipeline = null; - Program.unbind(); - } - // Setup shadow terrain & render shadows before the main terrain setup. We need to do things in this order to // avoid breaking other mods such as Light Overlay: https://github.com/IrisShaders/Iris/issues/1356 @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "net/minecraft/client/renderer/LevelRenderer.setupRender (Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/culling/Frustum;ZIZ)V")) @@ -87,88 +51,61 @@ public class MixinLevelRenderer { pipeline.renderShadows((LevelRendererAccessor) this, camera); } - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = RENDER_SKY)) + /*@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = RENDER_SKY)) private void iris$beginSky(PoseStack poseStack, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projection, CallbackInfo callback) { // Use CUSTOM_SKY until levelFogColor is called as a heuristic to catch FabricSkyboxes. pipeline.setPhase(WorldRenderingPhase.CUSTOM_SKY); - } - - @Redirect(method = "renderLevel", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Options;renderDistance:I"), - slice = @Slice(from = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;clear(IZ)V"))) - private int iris$alwaysRenderSky(Options options) { - return Math.max(options.renderDistance, 4); - } + }*/ - @Inject(method = "renderSky", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/FogRenderer;levelFogColor()V")) - private void iris$renderSky$beginNormalSky(PoseStack poseStack, float tickDelta, CallbackInfo callback) { + @Inject(method = "renderSky(FI)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;color(FFF)V", ordinal = 0)) + private void iris$renderSky$beginNormalSky(float partialTicks, int pass, CallbackInfo ci) { // None of the vanilla sky is rendered until after this call, so if anything is rendered before, it's // CUSTOM_SKY. pipeline.setPhase(WorldRenderingPhase.SKY); } - @Inject(method = "renderSky", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/LevelRenderer;SUN_LOCATION:Lnet/minecraft/resources/ResourceLocation;")) - private void iris$setSunRenderStage(PoseStack poseStack, float f, CallbackInfo ci) { + @Inject(method = "renderSky(FI)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/RenderGlobal;SUN_TEXTURES:Lnet/minecraft/util/ResourceLocation;")) + private void iris$setSunRenderStage(float partialTicks, int pass, CallbackInfo ci) { pipeline.setPhase(WorldRenderingPhase.SUN); } - @Inject(method = "renderSky", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/DimensionSpecialEffects;getSunriseColor(FF)[F")) - private void iris$setSunsetRenderStage(PoseStack poseStack, float f, CallbackInfo ci) { + @Inject(method = "renderSky(FI)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/WorldProvider;calcSunriseSunsetColors(FF)[F")) + private void iris$setSunsetRenderStage(float partialTicks, int pass, CallbackInfo ci) { pipeline.setPhase(WorldRenderingPhase.SUNSET); } - @Inject(method = "renderSky", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/LevelRenderer;MOON_LOCATION:Lnet/minecraft/resources/ResourceLocation;")) - private void iris$setMoonRenderStage(PoseStack poseStack, float f, CallbackInfo ci) { + @Inject(method = "renderSky(FI)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/RenderGlobal;MOON_PHASES_TEXTURES:Lnet/minecraft/util/ResourceLocation;")) + private void iris$setMoonRenderStage(float partialTicks, int pass, CallbackInfo ci) { pipeline.setPhase(WorldRenderingPhase.MOON); } - @Inject(method = "renderSky", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientLevel;getStarBrightness(F)F")) - private void iris$setStarRenderStage(PoseStack poseStack, float f, CallbackInfo ci) { + @Inject(method = "renderSky(FI)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/WorldClient;getStarBrightness(F)F")) + private void iris$setStarRenderStage(float partialTicks, int pass, CallbackInfo ci) { pipeline.setPhase(WorldRenderingPhase.STARS); } - @Inject(method = "renderSky", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;getEyePosition(F)Lnet/minecraft/world/phys/Vec3;")) - private void iris$setVoidRenderStage(PoseStack poseStack, float f, CallbackInfo ci) { + @Inject(method = "renderSky(FI)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;getPositionEyes(F)Lnet/minecraft/util/math/Vec3d;")) + private void iris$setVoidRenderStage(float partialTicks, int pass, CallbackInfo ci) { pipeline.setPhase(WorldRenderingPhase.VOID); } - @Inject(method = "renderSky", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientLevel;getTimeOfDay(F)F"), + @Inject(method = "renderSky(FI)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientLevel;getTimeOfDay(F)F"), slice = @Slice(from = @At(value = "FIELD", target = "com/mojang/math/Vector3f.YP : Lcom/mojang/math/Vector3f;"))) - private void iris$renderSky$tiltSun(PoseStack poseStack, float tickDelta, CallbackInfo callback) { + private void iris$renderSky$tiltSun(float partialTicks, int pass, CallbackInfo ci) { poseStack.mulPose(Vector3f.ZP.rotationDegrees(pipeline.getSunPathRotation())); } - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = RENDER_SKY, shift = At.Shift.AFTER)) - private void iris$endSky(PoseStack poseStack, float f, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projection, CallbackInfo ci) { - pipeline.setPhase(WorldRenderingPhase.NONE); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = RENDER_CLOUDS)) - private void iris$beginClouds(PoseStack poseStack, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projection, CallbackInfo callback) { - pipeline.setPhase(WorldRenderingPhase.CLOUDS); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = RENDER_CLOUDS, shift = At.Shift.AFTER)) - private void iris$endClouds(PoseStack poseStack, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projection, CallbackInfo callback) { - pipeline.setPhase(WorldRenderingPhase.NONE); - } - - - @Inject(method = RENDER_LAYER, at = @At("HEAD")) - private void iris$beginTerrainLayer(RenderType renderType, PoseStack poseStack, double cameraX, double cameraY, double cameraZ, CallbackInfo callback) { - pipeline.setPhase(WorldRenderingPhase.fromTerrainRenderType(renderType)); + @Inject(method = "renderBlockLayer(Lnet/minecraft/util/BlockRenderLayer;DILnet/minecraft/entity/Entity;)I", at = @At("HEAD")) + private void iris$beginTerrainLayer(BlockRenderLayer renderLayer, double partialTicks, int pass, Entity entityIn, CallbackInfoReturnable cir) { + pipeline.setPhase(WorldRenderingPhase.fromTerrainRenderType(renderLayer)); } - @Inject(method = RENDER_LAYER, at = @At("RETURN")) - private void iris$endTerrainLayer(RenderType renderType, PoseStack poseStack, double cameraX, double cameraY, double cameraZ, CallbackInfo callback) { + @Inject(method = "renderBlockLayer(Lnet/minecraft/util/BlockRenderLayer;DILnet/minecraft/entity/Entity;)I", at = @At("RETURN")) + private void iris$endTerrainLayer(BlockRenderLayer renderLayer, double partialTicks, int pass, Entity entityIn, CallbackInfoReturnable cir) { pipeline.setPhase(WorldRenderingPhase.NONE); } - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = RENDER_WEATHER)) - private void iris$beginWeather(PoseStack poseStack, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projection, CallbackInfo callback) { - pipeline.setPhase(WorldRenderingPhase.RAIN_SNOW); - } - @ModifyArg(method = RENDER_WEATHER, at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;depthMask(Z)V", ordinal = 0)) private boolean iris$writeRainAndSnowToDepthBuffer(boolean depthMaskEnabled) { if (pipeline.shouldWriteRainAndSnowToDepthBuffer()) { @@ -178,31 +115,6 @@ public class MixinLevelRenderer { return depthMaskEnabled; } - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = RENDER_WEATHER, shift = At.Shift.AFTER)) - private void iris$endWeather(PoseStack poseStack, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projection, CallbackInfo callback) { - pipeline.setPhase(WorldRenderingPhase.NONE); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = RENDER_WORLD_BOUNDS)) - private void iris$beginWorldBorder(PoseStack poseStack, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projection, CallbackInfo callback) { - pipeline.setPhase(WorldRenderingPhase.WORLD_BORDER); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = RENDER_WORLD_BOUNDS, shift = At.Shift.AFTER)) - private void iris$endWorldBorder(PoseStack poseStack, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projection, CallbackInfo callback) { - pipeline.setPhase(WorldRenderingPhase.NONE); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/debug/DebugRenderer;render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;DDD)V")) - private void iris$setDebugRenderStage(PoseStack poseStack, float f, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, CallbackInfo ci) { - pipeline.setPhase(WorldRenderingPhase.DEBUG); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/debug/DebugRenderer;render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;DDD)V", shift = At.Shift.AFTER)) - private void iris$resetDebugRenderStage(PoseStack poseStack, float f, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, CallbackInfo ci) { - pipeline.setPhase(WorldRenderingPhase.NONE); - } - @ModifyArg(method = "renderLevel", at = @At(value = "INVOKE", target = "net/minecraft/client/renderer/MultiBufferSource$BufferSource.getBuffer (Lnet/minecraft/client/renderer/RenderType;)Lcom/mojang/blaze3d/vertex/VertexConsumer;"), slice = @Slice( @@ -223,4 +135,14 @@ public class MixinLevelRenderer { Minecraft.getInstance().getProfiler().popPush("iris_pre_translucent"); pipeline.beginTranslucents(); } + + @Override + public WorldRenderingPipeline getPipeline() { + return pipeline; + } + + @Override + public void setPipeline(WorldRenderingPipeline pipeline) { + this.pipeline = pipeline; + } } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinMaxFpsCrashFix.java b/src/main/java/net/coderbot/iris/mixin/MixinMaxFpsCrashFix.java index b8cdab387b..6485f99afa 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinMaxFpsCrashFix.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinMaxFpsCrashFix.java @@ -1,21 +1,20 @@ package net.coderbot.iris.mixin; +import net.minecraft.client.settings.GameSettings; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Slice; -import net.minecraft.client.Options; - /** * A workaround for when OptiFine has set the maxFps to zero in options.txt * * Fun. */ -@Mixin(Options.class) +@Mixin(GameSettings.class) public abstract class MixinMaxFpsCrashFix { @Redirect( - method = "load", + method = "loadOptions", at = @At(value = "INVOKE", target = "Ljava/lang/Integer;parseInt(Ljava/lang/String;)I"), slice = @Slice(from = @At(value = "CONSTANT", args = "stringValue=maxFps"), to = @At(value = "CONSTANT", args = "stringValue=difficulty")), allow = 1 diff --git a/src/main/java/net/coderbot/iris/mixin/MixinMinecraft_PipelineManagement.java b/src/main/java/net/coderbot/iris/mixin/MixinMinecraft_PipelineManagement.java index 0d4db82147..c5cf4c2814 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinMinecraft_PipelineManagement.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinMinecraft_PipelineManagement.java @@ -1,32 +1,30 @@ package net.coderbot.iris.mixin; -import org.jetbrains.annotations.Nullable; +import net.coderbot.iris.Iris; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.WorldClient; +import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import net.coderbot.iris.Iris; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.multiplayer.ClientLevel; - @Mixin(Minecraft.class) public class MixinMinecraft_PipelineManagement { /** * Should run before the Minecraft.level field is updated after disconnecting from a server or leaving a singleplayer world */ - @Inject(method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD")) + /*@Inject(method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD")) public void iris$trackLastDimensionOnLeave(Screen arg, CallbackInfo ci) { Iris.lastDimension = Iris.getCurrentDimension(); - } + }*/ /** * Should run before the Minecraft.level field is updated after receiving a login or respawn packet * NB: Not on leave, another inject is used for that */ - @Inject(method = "setLevel", at = @At("HEAD")) - private void iris$trackLastDimensionOnLevelChange(@Nullable ClientLevel level, CallbackInfo ci) { + @Inject(method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", at = @At("HEAD")) + private void iris$trackLastDimensionOnLevelChange(WorldClient worldClient, String loadingMessage, CallbackInfo ci) { Iris.lastDimension = Iris.getCurrentDimension(); } @@ -44,8 +42,8 @@ public class MixinMinecraft_PipelineManagement { * * See: https://github.com/IrisShaders/Iris/issues/1330 */ - @Inject(method = "updateLevelInEngines", at = @At("HEAD")) - private void iris$resetPipeline(@Nullable ClientLevel level, CallbackInfo ci) { + @Inject(method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;world:Lnet/minecraft/client/multiplayer/WorldClient;", opcode = Opcodes.PUTFIELD)) + private void iris$resetPipeline(WorldClient level, String loadingMessage, CallbackInfo ci) { if (Iris.getCurrentDimension() != Iris.lastDimension) { Iris.logger.info("Reloading pipeline on dimension change: " + Iris.lastDimension + " => " + Iris.getCurrentDimension()); // Destroy pipelines when changing dimensions. diff --git a/src/main/java/net/coderbot/iris/mixin/MixinModelViewBobbing.java b/src/main/java/net/coderbot/iris/mixin/MixinModelViewBobbing.java index 4b7768801c..fb05628602 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinModelViewBobbing.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinModelViewBobbing.java @@ -1,6 +1,7 @@ package net.coderbot.iris.mixin; import net.irisshaders.iris.api.v0.IrisApi; +import net.minecraft.client.renderer.EntityRenderer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -23,7 +24,7 @@ * * This mixin makes use of the matrix stack in order to make these changes without more invasive changes. */ -@Mixin(GameRenderer.class) +@Mixin(EntityRenderer.class) public class MixinModelViewBobbing { @Unique private Matrix4f bobbingEffectsModel; @@ -31,8 +32,8 @@ public class MixinModelViewBobbing { @Unique private boolean areShadersOn; - @Inject(method = "renderLevel", at = @At("HEAD")) - private void iris$saveShadersOn(float pGameRenderer0, long pLong1, PoseStack pPoseStack2, CallbackInfo ci) { + @Inject(method = "renderWorld", at = @At("HEAD")) + private void iris$saveShadersOn(float partialTicks, long finishTimeNano, CallbackInfo ci) { areShadersOn = IrisApi.getInstance().isShaderPackInUse(); } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinOptions_Entrypoint.java b/src/main/java/net/coderbot/iris/mixin/MixinOptions_Entrypoint.java index b4aeef4f00..73f88e48aa 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinOptions_Entrypoint.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinOptions_Entrypoint.java @@ -1,5 +1,6 @@ package net.coderbot.iris.mixin; +import net.minecraft.client.settings.GameSettings; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -7,14 +8,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.coderbot.iris.Iris; -import net.minecraft.client.Options; -@Mixin(value = Options.class, priority = 990) +@Mixin(value = GameSettings.class, priority = 990) public class MixinOptions_Entrypoint { @Unique private static boolean iris$initialized; - @Inject(method = "load()V", at = @At("HEAD")) + @Inject(method = "loadOptions", at = @At("HEAD")) private void iris$beforeLoadOptions(CallbackInfo ci) { if (iris$initialized) { return; diff --git a/src/main/java/net/coderbot/iris/mixin/MixinParticleEngine.java b/src/main/java/net/coderbot/iris/mixin/MixinParticleEngine.java index aa97e91081..ee41e124d6 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinParticleEngine.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinParticleEngine.java @@ -1,39 +1,26 @@ package net.coderbot.iris.mixin; +import net.coderbot.iris.Iris; +import net.coderbot.iris.pipeline.WorldRenderingPhase; +import net.minecraft.client.renderer.EntityRenderer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.vertex.PoseStack; - -import net.coderbot.iris.Iris; -import net.coderbot.iris.pipeline.WorldRenderingPhase; -import net.minecraft.client.Camera; -import net.minecraft.client.particle.ParticleEngine; -import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.culling.Frustum; - /** * Ensures that all particles are rendered with the textured_lit shader program. */ -@Mixin(ParticleEngine.class) +// TODO not sure about lit +@Mixin(EntityRenderer.class) public class MixinParticleEngine { - private static final String RENDER = - "Lnet/minecraft/client/particle/ParticleEngine;renderParticles(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;FLnet/minecraft/client/renderer/culling/Frustum;)V"; - - @Inject(method = RENDER, at = @At("HEAD")) - private void iris$beginDrawingParticles(PoseStack poseStack, MultiBufferSource.BufferSource bufferSource, - LightTexture lightTexture, Camera camera, float f, Frustum frustum, - CallbackInfo ci) { + @Inject(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleManager;renderLitParticles(Lnet/minecraft/entity/Entity;F)V", shift = At.Shift.BEFORE)) + private void iris$beginDrawingParticles(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { Iris.getPipelineManager().getPipeline().ifPresent(pipeline -> pipeline.setPhase(WorldRenderingPhase.PARTICLES)); } - @Inject(method = RENDER, at = @At("RETURN")) - private void iris$finishDrawingParticles(PoseStack poseStack, MultiBufferSource.BufferSource bufferSource, - LightTexture lightTexture, Camera camera, float f, Frustum frustum, - CallbackInfo ci) { + @Inject(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleManager;renderParticles(Lnet/minecraft/entity/Entity;F)V", shift = At.Shift.AFTER)) + private void iris$finishDrawingParticles(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { Iris.getPipelineManager().getPipeline().ifPresent(pipeline -> pipeline.setPhase(WorldRenderingPhase.NONE)); } } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinRenderSystem.java b/src/main/java/net/coderbot/iris/mixin/MixinRenderSystem.java index 7be98a9a08..4316011107 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinRenderSystem.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinRenderSystem.java @@ -1,20 +1,19 @@ package net.coderbot.iris.mixin; +import net.minecraft.client.renderer.OpenGlHelper; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.systems.RenderSystem; - import net.coderbot.iris.Iris; import net.coderbot.iris.gl.GLDebug; import net.coderbot.iris.gl.IrisRenderSystem; -@Mixin(RenderSystem.class) +@Mixin(OpenGlHelper.class) public class MixinRenderSystem { - @Inject(method = "initRenderer", at = @At("RETURN")) - private static void iris$onRendererInit(int debugVerbosity, boolean alwaysFalse, CallbackInfo ci) { + @Inject(method = "initializeTextures", at = @At("RETURN")) + private static void iris$onRendererInit(CallbackInfo ci) { GLDebug.initRenderer(); IrisRenderSystem.initRenderer(); Iris.onRenderSystemInit(); diff --git a/src/main/java/net/coderbot/iris/mixin/MixinRenderTarget.java b/src/main/java/net/coderbot/iris/mixin/MixinRenderTarget.java index c301c1080a..526e076d3c 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinRenderTarget.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinRenderTarget.java @@ -1,28 +1,24 @@ package net.coderbot.iris.mixin; +import net.minecraft.client.shader.Framebuffer; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.pipeline.RenderTarget; - import net.coderbot.iris.rendertarget.Blaze3dRenderTargetExt; /** * Allows Iris to detect when the depth texture was re-created, so we can re-attach it * to the shader framebuffers. See DeferredWorldRenderingPipeline and RenderTargets. */ -@Mixin(RenderTarget.class) +@Mixin(Framebuffer.class) public class MixinRenderTarget implements Blaze3dRenderTargetExt { - @Shadow - private int depthBufferId; private int iris$depthBufferVersion; private int iris$colorBufferVersion; - @Inject(method = "destroyBuffers()V", at = @At("HEAD")) + @Inject(method = "deleteFramebuffer", at = @At("HEAD")) private void iris$onDestroyBuffers(CallbackInfo ci) { iris$depthBufferVersion++; iris$colorBufferVersion++; diff --git a/src/main/java/net/coderbot/iris/mixin/MixinScreenEffectRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinScreenEffectRenderer.java index 9bd59b8a3c..8e845cff54 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinScreenEffectRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinScreenEffectRenderer.java @@ -1,21 +1,17 @@ package net.coderbot.iris.mixin; +import net.coderbot.iris.Iris; +import net.coderbot.iris.pipeline.WorldRenderingPipeline; +import net.minecraft.client.renderer.ItemRenderer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.vertex.PoseStack; - -import net.coderbot.iris.Iris; -import net.coderbot.iris.pipeline.WorldRenderingPipeline; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.ScreenEffectRenderer; - -@Mixin(ScreenEffectRenderer.class) +@Mixin(ItemRenderer.class) public abstract class MixinScreenEffectRenderer { - @Inject(method = "renderWater", at = @At(value = "HEAD"), cancellable = true) - private static void iris$disableUnderWaterOverlayRendering(Minecraft minecraft, PoseStack poseStack, CallbackInfo ci) { + @Inject(method = "renderWaterOverlayTexture", at = @At(value = "HEAD"), cancellable = true) + private void iris$disableUnderWaterOverlayRendering(float partialTicks, CallbackInfo ci) { WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); if (pipeline != null && !pipeline.shouldRenderUnderwaterOverlay()) { diff --git a/src/main/java/net/coderbot/iris/mixin/MixinTheEndPortalRenderer.java b/src/main/java/net/coderbot/iris/mixin/MixinTheEndPortalRenderer.java index b02f172823..43b1ea4849 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinTheEndPortalRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinTheEndPortalRenderer.java @@ -1,5 +1,9 @@ package net.coderbot.iris.mixin; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.tileentity.TileEntityEndPortalRenderer; +import net.minecraft.tileentity.TileEntityEndPortal; +import net.minecraft.util.EnumFacing; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -20,7 +24,7 @@ import net.minecraft.core.Direction; import net.minecraft.world.level.block.entity.TheEndPortalBlockEntity; -@Mixin(TheEndPortalRenderer.class) +@Mixin(TileEntityEndPortalRenderer.class) public class MixinTheEndPortalRenderer { @Unique private static final float RED = 0.075f; @@ -46,8 +50,8 @@ protected float getOffsetDown() { return 0.0F; } - @Inject(method = "render", at = @At("HEAD"), cancellable = true) - public void iris$onRender(TheEndPortalBlockEntity entity, float tickDelta, PoseStack poseStack, MultiBufferSource multiBufferSource, int light, int overlay, CallbackInfo ci) { + @Inject(method = "render(Lnet/minecraft/tileentity/TileEntityEndPortal;DDDFIF)V", at = @At("HEAD"), cancellable = true) + public void iris$onRender(TileEntityEndPortal entity, double x, double y, double z, float tickDelta, int destroyStage, float alpha, CallbackInfo ci) { if (!Iris.getCurrentPack().isPresent()) { return; } @@ -67,37 +71,37 @@ protected float getOffsetDown() { float topHeight = getOffsetUp(); float bottomHeight = getOffsetDown(); - quad(entity, vertexConsumer, pose, normal, Direction.UP, progress, overlay, light, + quad(entity, vertexConsumer, pose, normal, EnumFacing.UP, progress, overlay, light, 0.0f, topHeight, 1.0f, 1.0f, topHeight, 1.0f, 1.0f, topHeight, 0.0f, 0.0f, topHeight, 0.0f); - quad(entity, vertexConsumer, pose, normal, Direction.DOWN, progress, overlay, light, + quad(entity, vertexConsumer, pose, normal, EnumFacing.DOWN, progress, overlay, light, 0.0f, bottomHeight, 1.0f, 0.0f, bottomHeight, 0.0f, 1.0f, bottomHeight, 0.0f, 1.0f, bottomHeight, 1.0f); - quad(entity, vertexConsumer, pose, normal, Direction.NORTH, progress, overlay, light, + quad(entity, vertexConsumer, pose, normal, EnumFacing.NORTH, progress, overlay, light, 0.0f, topHeight, 0.0f, 1.0f, topHeight, 0.0f, 1.0f, bottomHeight, 0.0f, 0.0f, bottomHeight, 0.0f); - quad(entity, vertexConsumer, pose, normal, Direction.WEST, progress, overlay, light, + quad(entity, vertexConsumer, pose, normal, EnumFacing.WEST, progress, overlay, light, 0.0f, topHeight, 1.0f, 0.0f, topHeight, 0.0f, 0.0f, bottomHeight, 0.0f, 0.0f, bottomHeight, 1.0f); - quad(entity, vertexConsumer, pose, normal, Direction.SOUTH, progress, overlay, light, + quad(entity, vertexConsumer, pose, normal, EnumFacing.SOUTH, progress, overlay, light, 0.0f, topHeight, 1.0f, 0.0f, bottomHeight, 1.0f, 1.0f, bottomHeight, 1.0f, 1.0f, topHeight, 1.0f); - quad(entity, vertexConsumer, pose, normal, Direction.EAST, progress, overlay, light, + quad(entity, vertexConsumer, pose, normal, EnumFacing.EAST, progress, overlay, light, 1.0f, topHeight, 1.0f, 1.0f, bottomHeight, 1.0f, 1.0f, bottomHeight, 0.0f, @@ -105,33 +109,33 @@ protected float getOffsetDown() { } @Unique - private void quad(TheEndPortalBlockEntity entity, VertexConsumer vertexConsumer, Matrix4f pose, Matrix3f normal, - Direction direction, float progress, int overlay, int light, + private void quad(TileEntityEndPortal entity, BufferBuilder vertexConsumer, Matrix4f pose, Matrix3f normal, + EnumFacing direction, float progress, int overlay, int light, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, - float x4,float y4, float z4) { + float x4, float y4, float z4) { if (!entity.shouldRenderFace(direction)) { return; } - float nx = direction.getStepX(); - float ny = direction.getStepY(); - float nz = direction.getStepZ(); + float nx = direction.getXOffset(); + float ny = direction.getYOffset(); + float nz = direction.getZOffset(); - vertexConsumer.vertex(pose, x1, y1, z1).color(RED, GREEN, BLUE, 1.0f) + vertexConsumer.pos(pose, x1, y1, z1).color(RED, GREEN, BLUE, 1.0f) .uv(0.0F + progress, 0.0F + progress).overlayCoords(overlay).uv2(light) .normal(normal, nx, ny, nz).endVertex(); - vertexConsumer.vertex(pose, x2, y2, z2).color(RED, GREEN, BLUE, 1.0f) + vertexConsumer.pos(pose, x2, y2, z2).color(RED, GREEN, BLUE, 1.0f) .uv(0.0F + progress, 0.2F + progress).overlayCoords(overlay).uv2(light) .normal(normal, nx, ny, nz).endVertex(); - vertexConsumer.vertex(pose, x3, y3, z3).color(RED, GREEN, BLUE, 1.0f) + vertexConsumer.pos(pose, x3, y3, z3).color(RED, GREEN, BLUE, 1.0f) .uv(0.2F + progress, 0.2F + progress).overlayCoords(overlay).uv2(light) .normal(normal, nx, ny, nz).endVertex(); - vertexConsumer.vertex(pose, x4, y4, z4).color(RED, GREEN, BLUE, 1.0f) + vertexConsumer.pos(pose, x4, y4, z4).color(RED, GREEN, BLUE, 1.0f) .uv(0.2F + progress, 0.0F + progress).overlayCoords(overlay).uv2(light) .normal(normal, nx, ny, nz).endVertex(); } diff --git a/src/main/java/net/coderbot/iris/mixin/MixinTitleScreen.java b/src/main/java/net/coderbot/iris/mixin/MixinTitleScreen.java deleted file mode 100644 index 2f9ab6fda6..0000000000 --- a/src/main/java/net/coderbot/iris/mixin/MixinTitleScreen.java +++ /dev/null @@ -1,66 +0,0 @@ -package net.coderbot.iris.mixin; - -import java.net.URI; -import java.net.URISyntaxException; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import net.coderbot.iris.Iris; -import net.coderbot.iris.compat.sodium.SodiumVersionCheck; -import net.minecraft.ChatFormatting; -import net.minecraft.Util; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.ConfirmScreen; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.TitleScreen; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraftforge.fml.loading.FMLLoader; - -@Mixin(TitleScreen.class) -public class MixinTitleScreen extends Screen { - private static boolean iris$hasFirstInit; - - protected MixinTitleScreen(Component arg) { - super(arg); - } - - @Inject(method = "init", at = @At("RETURN")) - public void iris$showSodiumIncompatScreen(CallbackInfo ci) { - if (iris$hasFirstInit) { - return; - } - - iris$hasFirstInit = true; - - String reason; - - if (!Iris.isSodiumInstalled() && FMLLoader.isProduction()) { - reason = "iris.sodium.failure.reason.notFound"; - } else { - Iris.onLoadingComplete(); - - return; - } - - Minecraft.getInstance().setScreen(new ConfirmScreen( - (boolean accepted) -> { - if (accepted) { - try { - Util.getPlatform().openUri(new URI(SodiumVersionCheck.getDownloadLink())); - } catch (URISyntaxException e) { - throw new IllegalStateException(e); - } - } else { - Minecraft.getInstance().stop(); - } - }, - new TranslatableComponent("iris.sodium.failure.title").withStyle(ChatFormatting.RED), - new TranslatableComponent(reason), - new TranslatableComponent("iris.sodium.failure.download"), - new TranslatableComponent("menu.quit"))); - } -} diff --git a/src/main/java/net/coderbot/iris/mixin/MixinTweakFarPlane.java b/src/main/java/net/coderbot/iris/mixin/MixinTweakFarPlane.java index 4125e570a9..d1d4abd4f5 100644 --- a/src/main/java/net/coderbot/iris/mixin/MixinTweakFarPlane.java +++ b/src/main/java/net/coderbot/iris/mixin/MixinTweakFarPlane.java @@ -1,18 +1,17 @@ package net.coderbot.iris.mixin; -import org.lwjgl.opengl.GL; +import net.coderbot.iris.Iris; +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.util.math.MathHelper; +import org.lwjgl.opengl.GLContext; 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.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.vertex.PoseStack; - -import net.coderbot.iris.Iris; -import net.minecraft.client.renderer.GameRenderer; - /** * Tweaks the far plane of the projection matrix to match OptiFine. * @@ -34,47 +33,83 @@ * * Fun. */ -@Mixin(GameRenderer.class) +// TODO Partially was made from Optifine patches, partially from Iris. NOT SURE +@Mixin(EntityRenderer.class) public class MixinTweakFarPlane { @Shadow - private float renderDistance; + private float farPlaneDistance; + + @Unique + private float clipDistanceSqrt = 128.0F; + @Unique + private float clipDistanceTwo = 128.0F; - @Redirect(method = "getProjectionMatrix", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/GameRenderer;renderDistance:F")) - private float iris$tweakViewDistanceToMatchOptiFine(GameRenderer renderer) { + @Inject(method = "setupCameraTransform", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/EntityRenderer;farPlaneDistance:F", shift = At.Shift.AFTER)) + private void iris$tweakViewDistanceBasedOnFog(float partialTicks, int pass, CallbackInfo ci) { if (!Iris.getCurrentPack().isPresent()) { // Don't mess with the far plane if no shaderpack is loaded - return this.renderDistance * 4.0F; + return; } - float tweakedViewDistance = this.renderDistance; + // Tweak the view distance based on the fog setting + // + // Coefficient values: 0.83 for fast fog, 0.95 for fancy fog, 1.0 for no fog + // + // On 1.16, we select the value based on if GL_NV_fog_distance is supported, and on 1.17+ only fancy fog is supported. - // Halve the distance of the far plane in the projection matrix from vanilla. Normally, the far plane is 4 times - // the view distance, but this makes it so that it is only two times the view distance. - tweakedViewDistance *= 0.5; + farPlaneDistance *= GLContext.getCapabilities().GL_NV_fog_distance ? 0.95F : 0.83F; - // Use a minimum distance for the far plane - // The real far plane will be 4 times this, so this will result in a far plane of 173 meters. - // - // Math.max returns the maximum of the two values, so whenever tweakedViewDistance falls below 43.25F, this code - // forces it to take on a value of 43.25F. - tweakedViewDistance = Math.max(43.25F, tweakedViewDistance); - return tweakedViewDistance; - } - @Inject(method = "renderLevel", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/GameRenderer;renderDistance:F", shift = At.Shift.AFTER)) - private void iris$tweakViewDistanceBasedOnFog(float tickDelta, long limitTime, PoseStack matrix, CallbackInfo ci) { if (!Iris.getCurrentPack().isPresent()) { // Don't mess with the far plane if no shaderpack is loaded + this.clipDistanceSqrt = this.farPlaneDistance * MathHelper.SQRT_2; + this.clipDistanceTwo = this.farPlaneDistance * 2.0F; return; } - // Tweak the view distance based on the fog setting - // - // Coefficient values: 0.83 for fast fog, 0.95 for fancy fog, 1.0 for no fog + float tweakedViewDistance = this.farPlaneDistance; + + // Halve the distance of the far plane in the projection matrix from vanilla. Normally, the far plane is MathHelper.SQRT_2 times + // the view distance, but this makes it so that it is only two times the view distance. + tweakedViewDistance *= 0.5; + + // Use a minimum distance for the far plane + // The real far plane will be MathHelper.SQRT_2 times this, so this will result in a far plane of 173 meters. // - // On 1.16, we select the value based on if GL_NV_fog_distance is supported, and on 1.17+ only fancy fog is supported. + // Math.max returns the maximum of the two values, so whenever tweakedViewDistance falls below 122.3294731455404F, this code + // forces it to take on a value of 122.3294731455404F. + this.clipDistanceSqrt = Math.max(122.3294731455404F, tweakedViewDistance); + this.clipDistanceTwo = Math.max(86.5F, tweakedViewDistance); + } + + @Redirect(method = "setupCameraTransform", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/EntityRenderer;farPlaneDistance:F", ordinal = 1)) + private float iris$tweakViewDistanceToMatchOptiFine(EntityRenderer instance) { + return this.clipDistanceSqrt; + } + + @Redirect(method = "renderHand", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/EntityRenderer;farPlaneDistance:F")) + private float iris$tweakViewDistanceToMatchOptiFineHand(EntityRenderer instance) { + return this.clipDistanceTwo; + } + + @Redirect(method = "renderWorldPass", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/EntityRenderer;farPlaneDistance:F", ordinal = 0)) + private float iris$tweakViewDistanceToMatchOptiFineWorld1(EntityRenderer instance) { + return this.clipDistanceTwo; + } + + @Redirect(method = "renderWorldPass", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/EntityRenderer;farPlaneDistance:F", ordinal = 1)) + private float iris$tweakViewDistanceToMatchOptiFineWorld2(EntityRenderer instance) { + return this.clipDistanceSqrt; + } + + @Redirect(method = "renderCloudsCheck", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/EntityRenderer;farPlaneDistance:F", ordinal = 0)) + private float iris$tweakViewDistanceToMatchOptiFineClouds1(EntityRenderer instance) { + return this.clipDistanceTwo * 2; + } - renderDistance *= GL.getCapabilities().GL_NV_fog_distance ? 0.95 : 0.83F; + @Redirect(method = "renderCloudsCheck", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/EntityRenderer;farPlaneDistance:F", ordinal = 1)) + private float iris$tweakViewDistanceToMatchOptiFineClouds2(EntityRenderer instance) { + return this.clipDistanceSqrt; } } diff --git a/src/main/java/net/coderbot/iris/mixin/bettermipmaps/MixinTextureAtlasSprite.java b/src/main/java/net/coderbot/iris/mixin/bettermipmaps/MixinTextureAtlasSprite.java index 2fd99692b6..9910dcb0c7 100644 --- a/src/main/java/net/coderbot/iris/mixin/bettermipmaps/MixinTextureAtlasSprite.java +++ b/src/main/java/net/coderbot/iris/mixin/bettermipmaps/MixinTextureAtlasSprite.java @@ -1,60 +1,48 @@ package net.coderbot.iris.mixin.bettermipmaps; -import java.util.Locale; -import java.util.Objects; - +import nanolive.compat.CompatMemoryUtil; +import nanolive.compat.NativeImage; import net.coderbot.iris.helpers.ColorSRGB; -import org.lwjgl.system.MemoryUtil; -import org.spongepowered.asm.mixin.Final; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureUtil; +import net.minecraft.client.resources.IResource; +import net.minecraft.util.ResourceLocation; 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.ModifyVariable; - -import com.mojang.blaze3d.platform.NativeImage; +import org.spongepowered.asm.mixin.injection.Redirect; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.resources.ResourceLocation; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.util.Locale; +import java.util.Objects; @Mixin(TextureAtlasSprite.class) public class MixinTextureAtlasSprite { // Generate some color tables for gamma correction. private static final float[] SRGB_TO_LINEAR = new float[256]; - @Shadow - @Final - private TextureAtlasSprite.Info info; - static { for (int i = 0; i < 256; i++) { SRGB_TO_LINEAR[i] = (float) Math.pow(i / 255.0, 2.2); } } - // While Fabric allows us to @Inject into the constructor here, that's just a specific detail of FabricMC's mixin - // fork. Upstream Mixin doesn't allow arbitrary @Inject usage in constructor. However, we can use @ModifyVariable - // just fine, in a way that hopefully doesn't conflict with other mods. - // - // By doing this, we can work with upstream Mixin as well, as is used on Forge. While we don't officially - // support Forge, since this works well on Fabric too, it's fine to ensure that the diff between Fabric and Forge - // can remain minimal. Being less dependent on specific details of Fabric is good, since it means we can be more - // cross-platform. - @ModifyVariable(method = "", at = @At(value = "FIELD", - target = "Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;metadata:Lnet/minecraft/client/resources/metadata/animation/AnimationMetadataSection;"), argsOnly = true) - private NativeImage iris$beforeGenerateMipLevels(NativeImage nativeImage) { + @Redirect(method = "loadSpriteFrames", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/texture/TextureUtil;readBufferedImage(Ljava/io/InputStream;)Ljava/awt/image/BufferedImage;")) + private BufferedImage iris$beforeGenerateMipLevels(InputStream stream, IResource resource, int mipmaplevels) throws IOException { // We're injecting after the "info" field has been set, so this is safe even though we're in a constructor. - ResourceLocation name = Objects.requireNonNull(info).name(); + ResourceLocation name = Objects.requireNonNull(resource).getResourceLocation(); + BufferedImage image = TextureUtil.readBufferedImage(stream); if (name.getPath().contains("leaves")) { // Don't ruin the textures of leaves on fast graphics, since they're supposed to have black pixels // apparently. - return nativeImage; + return image; } - iris$fillInTransparentPixelColors(nativeImage); - - return nativeImage; + iris$fillInTransparentPixelColors(image); + return null; } /** @@ -66,7 +54,7 @@ public class MixinTextureAtlasSprite { * black color does not leak over into sampling. */ @Unique - private static void iris$fillInTransparentPixelColors(NativeImage nativeImage) { + private static void iris$fillInTransparentPixelColors(BufferedImage nativeImage) { final long ppPixel = getPointerRGBA(nativeImage); final int pixelCount = nativeImage.getHeight() * nativeImage.getWidth(); // Calculate an average color from all pixels that are not completely transparent. @@ -80,7 +68,7 @@ public class MixinTextureAtlasSprite { for (int pixelIndex = 0; pixelIndex < pixelCount; pixelIndex++) { long pPixel = ppPixel + (pixelIndex * 4); - int color = MemoryUtil.memGetInt(pPixel); + int color = CompatMemoryUtil.memGetInt(pPixel); int alpha = NativeImage.getA(color); // Ignore all fully-transparent pixels for the purposes of computing an average color. @@ -112,17 +100,17 @@ public class MixinTextureAtlasSprite { for (int pixelIndex = 0; pixelIndex < pixelCount; pixelIndex++) { long pPixel = ppPixel + (pixelIndex * 4); - int color = MemoryUtil.memGetInt(pPixel); + int color = CompatMemoryUtil.memGetInt(pPixel); int alpha = NativeImage.getA(color); // Replace the color values of pixels which are fully transparent, since they have no color data. if (alpha == 0) { - MemoryUtil.memPutInt(pPixel, averageColor); + CompatMemoryUtil.memPutInt(pPixel, averageColor); } } } - private static long getPointerRGBA(NativeImage nativeImage) { + private static long getPointerRGBA(BufferedImage nativeImage) { if (nativeImage.format() != NativeImage.Format.RGBA) { throw new IllegalArgumentException(String.format(Locale.ROOT, "Tried to get pointer to RGBA pixel data on NativeImage of wrong format; have %s", nativeImage.format())); diff --git a/src/main/java/net/coderbot/iris/mixin/compat/CompatMixinPlugin.java b/src/main/java/net/coderbot/iris/mixin/compat/CompatMixinPlugin.java deleted file mode 100644 index 2dcab33cc7..0000000000 --- a/src/main/java/net/coderbot/iris/mixin/compat/CompatMixinPlugin.java +++ /dev/null @@ -1,49 +0,0 @@ -package net.coderbot.iris.mixin.compat; - -import net.minecraftforge.fml.loading.FMLLoader; -import org.objectweb.asm.tree.ClassNode; -import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; -import org.spongepowered.asm.mixin.extensibility.IMixinInfo; - -import java.util.List; -import java.util.Set; - -public class CompatMixinPlugin implements IMixinConfigPlugin { - @Override - public void onLoad(String mixinPackage) { - - } - - @Override - public String getRefMapperConfig() { - return null; - } - - @Override - public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - int startIndex = mixinClassName.indexOf("compat.") + "compat.".length(); - int endIndex = mixinClassName.indexOf(".", startIndex); - String modid = mixinClassName.substring(startIndex, endIndex); - return FMLLoader.getLoadingModList().getModFileById(modid) != null; - } - - @Override - public void acceptTargets(Set myTargets, Set otherTargets) { - - } - - @Override - public List getMixins() { - return null; - } - - @Override - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - - } - - @Override - public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - - } -} diff --git a/src/main/java/net/coderbot/iris/mixin/compat/epicfight/MixinEpicFightRenderTypes.java b/src/main/java/net/coderbot/iris/mixin/compat/epicfight/MixinEpicFightRenderTypes.java deleted file mode 100644 index 76d14cb6ac..0000000000 --- a/src/main/java/net/coderbot/iris/mixin/compat/epicfight/MixinEpicFightRenderTypes.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.coderbot.iris.mixin.compat.epicfight; - -import com.mojang.blaze3d.vertex.VertexConsumer; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.RenderType; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import yesman.epicfight.client.renderer.EpicFightRenderTypes; - -@Mixin(EpicFightRenderTypes.class) -public class MixinEpicFightRenderTypes { - @Inject(method = "getArmorVertexBuilder", at = @At("HEAD"), cancellable = true) - private static void getArmorVertexBuilder(MultiBufferSource buffer, RenderType renderType, boolean withGlint, CallbackInfoReturnable cir) { - if(EpicFightRenderTypes.enchantedAnimatedArmor() == renderType) cir.setReturnValue(buffer.getBuffer(renderType)); - } -} diff --git a/src/main/java/net/coderbot/iris/mixin/compat/pixelmon/MixinNormalizedFace.java b/src/main/java/net/coderbot/iris/mixin/compat/pixelmon/MixinNormalizedFace.java deleted file mode 100644 index 8e24b31063..0000000000 --- a/src/main/java/net/coderbot/iris/mixin/compat/pixelmon/MixinNormalizedFace.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.coderbot.iris.mixin.compat.pixelmon; - -import com.mojang.blaze3d.vertex.BufferBuilder; -import org.objectweb.asm.Opcodes; -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.Coerce; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Pseudo -@Mixin(targets = {"com/pixelmonmod/pixelmon/client/models/smd/NormalizedFace"}) -public class MixinNormalizedFace { - /** - * @author embeddedt (original idea by NanoLive) - * @reason Pixelmon manipulates the buffer of a {@link BufferBuilder} directly which causes problems. - * We bypass that code path. - */ - @Redirect(method = "addFaceForRender", at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Lcom/pixelmonmod/pixelmon/client/models/smd/DeformVertex;id2:I")) - public int hideBufferBuilderId(@Coerce Object instance) { - return -1; // prevent using "optimized" code path - } -} diff --git a/src/main/java/net/coderbot/iris/mixin/fabulous/MixinDisableFabulousGraphics.java b/src/main/java/net/coderbot/iris/mixin/fabulous/MixinDisableFabulousGraphics.java deleted file mode 100644 index 59ebcadad5..0000000000 --- a/src/main/java/net/coderbot/iris/mixin/fabulous/MixinDisableFabulousGraphics.java +++ /dev/null @@ -1,43 +0,0 @@ -package net.coderbot.iris.mixin.fabulous; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import net.coderbot.iris.Iris; -import net.minecraft.client.GraphicsStatus; -import net.minecraft.client.Minecraft; -import net.minecraft.client.Options; -import net.minecraft.client.renderer.LevelRenderer; - -@Mixin(LevelRenderer.class) -public class MixinDisableFabulousGraphics { - @Inject(method = "onResourceManagerReload", at = @At("HEAD")) - private void iris$disableFabulousGraphicsOnResourceReload(CallbackInfo ci) { - iris$disableFabulousGraphics(); - } - - // This method is called whenever the user tries to change the graphics mode. - // We can still revert / intercept the change at the head of the method. - @Inject(method = "allChanged", at = @At("HEAD")) - private void iris$disableFabulousGraphicsOnLevelRendererReload(CallbackInfo ci) { - iris$disableFabulousGraphics(); - } - - @Unique - private void iris$disableFabulousGraphics() { - Options options = Minecraft.getInstance().options; - - if (!Iris.getIrisConfig().areShadersEnabled()) { - // Nothing to do here, shaders are disabled. - return; - } - - if (options.graphicsMode == GraphicsStatus.FABULOUS) { - // Disable fabulous graphics when shaders are enabled. - options.graphicsMode = GraphicsStatus.FANCY; - } - } -} diff --git a/src/main/java/net/coderbot/iris/mixin/gui/MixinGui.java b/src/main/java/net/coderbot/iris/mixin/gui/MixinGui.java index 98bdc50ccf..4ab782d609 100644 --- a/src/main/java/net/coderbot/iris/mixin/gui/MixinGui.java +++ b/src/main/java/net/coderbot/iris/mixin/gui/MixinGui.java @@ -1,76 +1,25 @@ package net.coderbot.iris.mixin.gui; -import java.util.ArrayList; -import java.util.List; - -import org.spongepowered.asm.mixin.Final; +import net.coderbot.iris.Iris; +import net.coderbot.iris.pipeline.WorldRenderingPipeline; +import net.minecraft.client.gui.GuiIngame; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; - -import net.coderbot.iris.Iris; -import net.coderbot.iris.gui.screen.HudHideable; -import net.coderbot.iris.pipeline.WorldRenderingPipeline; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiComponent; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.world.entity.Entity; - -@Mixin(Gui.class) +@Mixin(GuiIngame.class) public class MixinGui { - @Shadow @Final private Minecraft minecraft; - - @Inject(method = "render", at = @At("HEAD"), cancellable = true) - public void iris$handleHudHidingScreens(PoseStack poseStack, float tickDelta, CallbackInfo ci) { - Screen screen = this.minecraft.screen; - - if (screen instanceof HudHideable) { - ci.cancel(); - } - } - - // TODO: Move this to a more appropriate mixin - @Inject(method = "render", at = @At("RETURN")) - public void iris$displayBigSodiumWarning(PoseStack poseStack, float tickDelta, CallbackInfo ci) { - if (Iris.isSodiumInstalled() - || Minecraft.getInstance().options.renderDebug - || !Iris.getCurrentPack().isPresent()) { - return; - } - - Font font = Minecraft.getInstance().font; - - List warningLines = new ArrayList<>(); - warningLines.add("[" + Iris.MODNAME + "] Sodium isn't installed; you will have poor performance."); - warningLines.add("[" + Iris.MODNAME + "] Install Sodium if you want to run benchmarks or get higher FPS!"); - - for (int i = 0; i < warningLines.size(); ++i) { - String string = warningLines.get(i); - - final int lineHeight = 9; - final int lineWidth = font.width(string); - final int y = 2 + lineHeight * i; - - GuiComponent.fill(poseStack, 1, y - 1, 2 + lineWidth + 1, y + lineHeight - 1, 0x9050504E); - font.draw(poseStack, string, 2.0F, y, 0xFFFF55); - } - } - @Inject(method = "renderVignette", at = @At("HEAD"), cancellable = true) - private void iris$disableVignetteRendering(Entity entity, CallbackInfo ci) { + private void iris$disableVignetteRendering(float lightLevel, ScaledResolution scaledRes, CallbackInfo ci) { WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); if (pipeline != null && !pipeline.shouldRenderVignette()) { // we need to set up the GUI render state ourselves if we cancel the vignette - RenderSystem.enableDepthTest(); - RenderSystem.defaultBlendFunc(); + GlStateManager.enableDepth(); + GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); ci.cancel(); } diff --git a/src/main/java/net/coderbot/iris/mixin/gui/MixinGuiIngameForge.java b/src/main/java/net/coderbot/iris/mixin/gui/MixinGuiIngameForge.java new file mode 100644 index 0000000000..66869efb97 --- /dev/null +++ b/src/main/java/net/coderbot/iris/mixin/gui/MixinGuiIngameForge.java @@ -0,0 +1,57 @@ +package net.coderbot.iris.mixin.gui; + +import net.coderbot.iris.Iris; +import net.coderbot.iris.gui.screen.HudHideable; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.client.GuiIngameForge; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.ArrayList; +import java.util.List; + +@Mixin(GuiIngameForge.class) +public class MixinGuiIngameForge { + + @Inject(method = "renderGameOverlay", at = @At("HEAD"), cancellable = true) + public void iris$handleHudHidingScreens(float partialTicks, CallbackInfo ci) { + GuiScreen screen = Minecraft.getMinecraft().currentScreen; + + if (screen instanceof HudHideable) { + ci.cancel(); + } + } + + // TODO: Move this to a more appropriate mixin + @Inject(method = "renderGameOverlay", at = @At("RETURN")) + public void iris$displayBigSodiumWarning(float partialTicks, CallbackInfo ci) { + if (Iris.isSodiumInstalled() + || Minecraft.getMinecraft().gameSettings.showDebugInfo + || !Iris.getCurrentPack().isPresent()) { + return; + } + + FontRenderer font = Minecraft.getMinecraft().fontRenderer; + + List warningLines = new ArrayList<>(); + warningLines.add("[" + Iris.MODNAME + "] Vintagium isn't installed; you will have poor performance."); + warningLines.add("[" + Iris.MODNAME + "] Install Vintagium if you want to run benchmarks or get higher FPS!"); + + for (int i = 0; i < warningLines.size(); ++i) { + String string = warningLines.get(i); + + final int lineHeight = 9; + final int lineWidth = font.getStringWidth(string); + final int y = 2 + lineHeight * i; + + Gui.drawRect(1, y - 1, 2 + lineWidth + 1, y + lineHeight - 1, 0x9050504E); + font.drawString(string, 2, y, 0xFFFF55); + } + } + +} diff --git a/src/main/java/net/coderbot/iris/mixin/integrationtest/MixinRenderTarget_StencilBufferTest.java b/src/main/java/net/coderbot/iris/mixin/integrationtest/MixinRenderTarget_StencilBufferTest.java deleted file mode 100644 index 700534ddc7..0000000000 --- a/src/main/java/net/coderbot/iris/mixin/integrationtest/MixinRenderTarget_StencilBufferTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package net.coderbot.iris.mixin.integrationtest; - - -import org.lwjgl.opengl.GL30; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArgs; -import org.spongepowered.asm.mixin.injection.Slice; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; - -import com.mojang.blaze3d.pipeline.RenderTarget; - -/** - * Tests switching the depth texture of the main Minecraft render target to use a stencil buffer, to ensure that - * Iris remains compatible. Iris should continue to have good performance & should not spam the log with errors. - * - * This mixin is not enabled by default. To enable integration tests, add the mixins.iris.integrationtest.json file - * to the fabric.mod.json mixins list. Note that you'll also want to test if this works with the GL 3.0 framebuffer - * blit path, by manually disabling the GL 4.3 copy path. - * - * Previous issues: - * - *

    - *
  • Log spam when copying depth buffer content
  • - *
  • Extreme low FPS caused by hitting a driver slow path. We're talking ~13 FPS on an RTX 2070 Super with - * Sildur's Vibrant Medium.
  • - *
- * - * Based on https://gist.github.com/burgerguy/8233170683ad93eea6aa27ee02a5c4d1 - */ -@Mixin (RenderTarget.class) -public class MixinRenderTarget_StencilBufferTest { - private static final boolean STENCIL = true; - - @ModifyArgs (method = "createBuffers", - at = @At (value = "INVOKE", - target = "Lcom/mojang/blaze3d/platform/GlStateManager;_texImage2D(IIIIIIIILjava/nio/IntBuffer;)V", - ordinal = 0)) - public void init(Args args) { - if (STENCIL) { - // internalformat - // NB: The original Gist sets this to 3, but that is incorrect. Arguments are zero-indexed. - args.set(2, GL30.GL_DEPTH32F_STENCIL8); - - // format - args.set(6, GL30.GL_DEPTH_STENCIL); - - // type - args.set(7, GL30.GL_FLOAT_32_UNSIGNED_INT_24_8_REV); - } - } - - @ModifyArgs (method = "createBuffers", - at = @At (value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;_glFramebufferTexture2D(IIIII)V"), - slice = @Slice (from = @At (value = "FIELD", target = "Lcom/mojang/blaze3d/pipeline/RenderTarget;useDepth:Z", ordinal = 1))) - public void init2(Args args) { - if (STENCIL) { - // attachment - args.set(1, GL30.GL_DEPTH_STENCIL_ATTACHMENT); - } - } -} diff --git a/src/main/java/net/coderbot/iris/mixin/optimized_stitching/MixinStitcher.java b/src/main/java/net/coderbot/iris/mixin/optimized_stitching/MixinStitcher.java index 5181379da4..bbf3993b3e 100644 --- a/src/main/java/net/coderbot/iris/mixin/optimized_stitching/MixinStitcher.java +++ b/src/main/java/net/coderbot/iris/mixin/optimized_stitching/MixinStitcher.java @@ -2,6 +2,7 @@ import java.util.List; +import net.minecraft.util.math.MathHelper; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -9,18 +10,16 @@ import net.minecraft.client.renderer.texture.Stitcher; import net.minecraft.client.renderer.texture.Stitcher.Holder; -import net.minecraft.client.renderer.texture.Stitcher.Region; -import net.minecraft.util.Mth; @Mixin(Stitcher.class) public class MixinStitcher { @Shadow @Final - private List storage; + private List stitchSlots; @Shadow - private int storageX; + private int currentWidth; @Shadow - private int storageY; + private int currentHeight; @Shadow @Final private int maxWidth; @@ -35,9 +34,9 @@ public class MixinStitcher { * @reason Optimize region creation to allow for a smaller atlas */ @Overwrite - private boolean expand(Holder holder) { - int newEffectiveWidth = Mth.smallestEncompassingPowerOfTwo(storageX + holder.width); - int newEffectiveHeight = Mth.smallestEncompassingPowerOfTwo(storageY + holder.height); + private boolean expandAndAllocateSlot(Holder holder) { + int newEffectiveWidth = MathHelper.smallestEncompassingPowerOfTwo(currentWidth + holder.getWidth()); + int newEffectiveHeight = MathHelper.smallestEncompassingPowerOfTwo(currentHeight + holder.getHeight()); boolean canFitWidth = newEffectiveWidth <= maxWidth; boolean canFitHeight = newEffectiveHeight <= maxHeight; @@ -56,8 +55,8 @@ private boolean expand(Holder holder) { */ if (canFitWidth & canFitHeight) { // Effective size calculation moved from head to be inside if block - int effectiveWidth = Mth.smallestEncompassingPowerOfTwo(storageX); - int effectiveHeight = Mth.smallestEncompassingPowerOfTwo(storageY); + int effectiveWidth = MathHelper.smallestEncompassingPowerOfTwo(currentWidth); + int effectiveHeight = MathHelper.smallestEncompassingPowerOfTwo(currentHeight); boolean wouldGrowEffectiveWidth = effectiveWidth != newEffectiveWidth; boolean wouldGrowEffectiveHeight = effectiveHeight != newEffectiveHeight; @@ -112,7 +111,7 @@ private boolean expand(Holder holder) { * * Vanilla does not perform this check. */ - growWidth = holder.width > storageX; + growWidth = holder.getWidth() > currentWidth; } } else { if (wouldGrowEffectiveHeight) { @@ -141,21 +140,21 @@ private boolean expand(Holder holder) { } // Iris end - Region region; + Stitcher.Slot region; if (growWidth) { - if (storageY == 0) { - storageY = holder.height; + if (currentHeight == 0) { + currentHeight = holder.getHeight(); } - region = new Region(storageX, 0, holder.width, storageY); - storageX += holder.width; + region = new Stitcher.Slot(currentWidth, 0, holder.getWidth(), currentHeight); + currentWidth += holder.getWidth(); } else { - region = new Region(0, storageY, storageX, holder.height); - storageY += holder.height; + region = new Stitcher.Slot(0, currentHeight, currentWidth, holder.getHeight()); + currentHeight += holder.getHeight(); } - region.add(holder); - storage.add(region); + region.addSlot(holder); + stitchSlots.add(region); return true; } } diff --git a/src/main/java/net/coderbot/iris/mixin/shadows/MixinBeaconRenderer.java b/src/main/java/net/coderbot/iris/mixin/shadows/MixinBeaconRenderer.java index 41699e6bd2..ab3fbfd5da 100644 --- a/src/main/java/net/coderbot/iris/mixin/shadows/MixinBeaconRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/shadows/MixinBeaconRenderer.java @@ -1,24 +1,20 @@ package net.coderbot.iris.mixin.shadows; +import net.coderbot.iris.shadows.ShadowRenderingState; +import net.minecraft.client.renderer.tileentity.TileEntityBeaconRenderer; +import net.minecraft.tileentity.TileEntityBeacon; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.vertex.PoseStack; - -import net.coderbot.iris.shadows.ShadowRenderingState; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.blockentity.BeaconRenderer; -import net.minecraft.resources.ResourceLocation; +import java.util.List; -@Mixin(BeaconRenderer.class) +@Mixin(TileEntityBeaconRenderer.class) public class MixinBeaconRenderer { - @Inject(method = "renderBeaconBeam(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/resources/ResourceLocation;FFJII[FFF)V", + @Inject(method = "renderBeacon", at = @At("HEAD"), cancellable = true) - private static void iris$noLightBeamInShadowPass(PoseStack poseStack, MultiBufferSource multiBufferSource, - ResourceLocation resourceLocation, float f, float g, long l, int i, int j, - float[] fs, float h, float k, CallbackInfo ci) { + private void iris$noLightBeamInShadowPass(double x, double y, double z, double partialTicks, double textureScale, List beamSegments, double totalWorldTime, CallbackInfo ci) { if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) { // TODO: Don't do this if we're doing the "Unified Entity Rendering" optimization // TODO: This isn't necessary on most shaderpacks if we support blockEntityId diff --git a/src/main/java/net/coderbot/iris/mixin/shadows/MixinLevelRenderer.java b/src/main/java/net/coderbot/iris/mixin/shadows/MixinLevelRenderer.java index 9d1029a056..3738ac71f2 100644 --- a/src/main/java/net/coderbot/iris/mixin/shadows/MixinLevelRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/shadows/MixinLevelRenderer.java @@ -1,46 +1,46 @@ package net.coderbot.iris.mixin.shadows; -import org.spongepowered.asm.mixin.Final; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.coderbot.iris.shadows.CullingDataCache; +import net.minecraft.client.renderer.RenderGlobal; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import it.unimi.dsi.fastutil.objects.ObjectList; -import net.coderbot.iris.shadows.CullingDataCache; -import net.minecraft.client.renderer.LevelRenderer; +import java.util.List; -@Mixin(LevelRenderer.class) +@Mixin(RenderGlobal.class) public class MixinLevelRenderer implements CullingDataCache { + + // TODO Let's replace with FastUtils' collection @Shadow - @Final @Mutable - private ObjectList renderChunks; + private List renderInfos = new ObjectArrayList<>(69696); @Unique - private ObjectList savedRenderChunks = new ObjectArrayList<>(69696); + private List savedRenderChunks = new ObjectArrayList<>(69696); @Shadow - private boolean needsUpdate; + private boolean displayListEntitiesDirty; @Unique private boolean savedNeedsTerrainUpdate; @Shadow - private double lastCameraX; + private double frustumUpdatePosX; @Shadow - private double lastCameraY; + private double frustumUpdatePosY; @Shadow - private double lastCameraZ; + private double frustumUpdatePosZ; @Shadow - private double prevCamRotX; + private double lastViewEntityPitch; @Shadow - private double prevCamRotY; + private double lastViewEntityYaw; @Unique private double savedLastCameraX; @@ -69,36 +69,36 @@ public void restoreState() { @Unique private void swap() { - ObjectList tmpList = renderChunks; - renderChunks = savedRenderChunks; + List tmpList = renderInfos; + renderInfos = savedRenderChunks; savedRenderChunks = tmpList; // TODO: If the normal chunks need a terrain update, these chunks probably do too... // We probably should copy it over - boolean tmpBool = needsUpdate; - needsUpdate = savedNeedsTerrainUpdate; + boolean tmpBool = displayListEntitiesDirty; + displayListEntitiesDirty = savedNeedsTerrainUpdate; savedNeedsTerrainUpdate = tmpBool; double tmp; - tmp = lastCameraX; - lastCameraX = savedLastCameraX; + tmp = frustumUpdatePosX; + frustumUpdatePosX = savedLastCameraX; savedLastCameraX = tmp; - tmp = lastCameraY; - lastCameraY = savedLastCameraY; + tmp = frustumUpdatePosY; + frustumUpdatePosY = savedLastCameraY; savedLastCameraY = tmp; - tmp = lastCameraZ; - lastCameraZ = savedLastCameraZ; + tmp = frustumUpdatePosZ; + frustumUpdatePosZ = savedLastCameraZ; savedLastCameraZ = tmp; - tmp = prevCamRotX; - prevCamRotX = savedLastCameraPitch; + tmp = lastViewEntityPitch; + lastViewEntityPitch = savedLastCameraPitch; savedLastCameraPitch = tmp; - tmp = prevCamRotY; - prevCamRotY = savedLastCameraYaw; + tmp = lastViewEntityYaw; + lastViewEntityYaw = savedLastCameraYaw; savedLastCameraYaw = tmp; } } diff --git a/src/main/java/net/coderbot/iris/mixin/sky/MixinClientLevelData_DisableVoidPlane.java b/src/main/java/net/coderbot/iris/mixin/sky/MixinClientLevelData_DisableVoidPlane.java index 5a9bc2793e..c572e8a1a8 100644 --- a/src/main/java/net/coderbot/iris/mixin/sky/MixinClientLevelData_DisableVoidPlane.java +++ b/src/main/java/net/coderbot/iris/mixin/sky/MixinClientLevelData_DisableVoidPlane.java @@ -1,14 +1,19 @@ package net.coderbot.iris.mixin.sky; +import net.minecraft.block.Block; +import net.minecraft.block.BlockLiquid; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ActiveRenderInfo; +import net.minecraft.entity.Entity; +import net.minecraft.world.World; +import net.minecraft.world.WorldType; +import net.minecraftforge.fluids.IFluidBlock; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.world.level.material.FluidState; - /** * Disables void plane rendering when submerged in a fluid, to avoid breaking the fog illusion in oceans * and lava. @@ -17,13 +22,17 @@ * takes a far more conservative approach and only disables specific parts of sky rendering in high-fog * situations. */ -@Mixin(ClientLevel.ClientLevelData.class) +@Mixin(WorldType.class) public class MixinClientLevelData_DisableVoidPlane { - @Inject(method = "getHorizonHeight()D", at = @At("HEAD"), cancellable = true) - private void iris$getHorizonHeight(CallbackInfoReturnable cir) { - FluidState submergedFluid = Minecraft.getInstance().gameRenderer.getMainCamera().getFluidInCamera(); + @Inject(method = "getHorizon", at = @At("HEAD"), cancellable = true) + private void iris$getHorizonHeight(World world, CallbackInfoReturnable cir) { + Minecraft mc = Minecraft.getMinecraft(); + Entity cameraEntity = mc.getRenderViewEntity(); + // TODO getBlockStateAtEntityViewpoint is not adapted to Forge's IFluidBlock, maybe it's better to use ForgeHooks.isInsideOfMaterial? + IBlockState submergedFluid = ActiveRenderInfo.getBlockStateAtEntityViewpoint(mc.world, cameraEntity, mc.timer.renderPartialTicks); + Block block = submergedFluid.getBlock(); - if (!submergedFluid.isEmpty()) { + if (block instanceof BlockLiquid || block instanceof IFluidBlock) { cir.setReturnValue(Double.NEGATIVE_INFINITY); } } diff --git a/src/main/java/net/coderbot/iris/mixin/sky/MixinDimensionSpecialEffects.java b/src/main/java/net/coderbot/iris/mixin/sky/MixinDimensionSpecialEffects.java index fdadc573d4..765d5da81d 100644 --- a/src/main/java/net/coderbot/iris/mixin/sky/MixinDimensionSpecialEffects.java +++ b/src/main/java/net/coderbot/iris/mixin/sky/MixinDimensionSpecialEffects.java @@ -1,17 +1,20 @@ package net.coderbot.iris.mixin.sky; +import net.minecraft.block.Block; +import net.minecraft.block.BlockLiquid; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ActiveRenderInfo; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.init.MobEffects; +import net.minecraft.world.WorldProvider; +import net.minecraftforge.fluids.IFluidBlock; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.DimensionSpecialEffects; -import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.level.material.FluidState; - /** * Disables the sunrise / sunset effect when blindness is active or when submerged in a fluid. * @@ -19,21 +22,24 @@ * takes a far more conservative approach and only disables specific parts of sky rendering in high-fog * situations. */ -@Mixin(DimensionSpecialEffects.class) +@Mixin(WorldProvider.class) public class MixinDimensionSpecialEffects { - @Inject(method = "getSunriseColor", at = @At("HEAD"), cancellable = true) + @Inject(method = "calcSunriseSunsetColors", at = @At("HEAD"), cancellable = true) private void iris$getSunriseColor(float timeOfDay, float partialTicks, CallbackInfoReturnable cir) { - Entity cameraEntity = Minecraft.getInstance().getCameraEntity(); - boolean hasBlindness = cameraEntity instanceof LivingEntity - && ((LivingEntity) cameraEntity).hasEffect(MobEffects.BLINDNESS); + Minecraft mc = Minecraft.getMinecraft(); + Entity cameraEntity = mc.getRenderViewEntity(); + boolean hasBlindness = cameraEntity instanceof EntityLivingBase + && ((EntityLivingBase) cameraEntity).getActivePotionEffect(MobEffects.BLINDNESS) != null; if (hasBlindness) { cir.setReturnValue(null); } - FluidState submergedFluid = Minecraft.getInstance().gameRenderer.getMainCamera().getFluidInCamera(); + // TODO getBlockStateAtEntityViewpoint is not adapted to Forge's IFluidBlock, maybe it's better to use ForgeHooks.isInsideOfMaterial? + IBlockState submergedFluid = ActiveRenderInfo.getBlockStateAtEntityViewpoint(mc.world, cameraEntity, partialTicks); + Block block = submergedFluid.getBlock(); - if (!submergedFluid.isEmpty()) { + if (block instanceof BlockLiquid || block instanceof IFluidBlock) { cir.setReturnValue(null); } } diff --git a/src/main/java/net/coderbot/iris/mixin/sky/MixinLevelRenderer_SunMoonToggle.java b/src/main/java/net/coderbot/iris/mixin/sky/MixinLevelRenderer_SunMoonToggle.java index 236334cd06..9af8f80b09 100644 --- a/src/main/java/net/coderbot/iris/mixin/sky/MixinLevelRenderer_SunMoonToggle.java +++ b/src/main/java/net/coderbot/iris/mixin/sky/MixinLevelRenderer_SunMoonToggle.java @@ -1,5 +1,10 @@ package net.coderbot.iris.mixin.sky; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11C; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @@ -20,7 +25,7 @@ /** * Allows pipelines to disable the sun, moon, or both. */ -@Mixin(LevelRenderer.class) +@Mixin(RenderGlobal.class) public class MixinLevelRenderer_SunMoonToggle { /** * This is a convenient way to disable rendering the sun / moon, since this clears the sun's vertices from @@ -29,32 +34,32 @@ public class MixinLevelRenderer_SunMoonToggle { */ @Unique private void iris$emptyBuilder() { - BufferBuilder builder = Tesselator.getInstance().getBuilder(); + BufferBuilder builder = Tessellator.getInstance().getBuffer(); builder.discard(); - builder.begin(GL11C.GL_QUADS, DefaultVertexFormat.POSITION); + builder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); builder.end(); } - @Inject(method = "renderSky", + @Inject(method = "renderSky(FI)V", at = @At(value = "INVOKE", target = "com/mojang/blaze3d/vertex/BufferUploader.end (Lcom/mojang/blaze3d/vertex/BufferBuilder;)V"), slice = @Slice( from = @At(value = "FIELD", target = "net/minecraft/client/renderer/LevelRenderer.SUN_LOCATION : Lnet/minecraft/resources/ResourceLocation;"), to = @At(value = "FIELD", target = "net/minecraft/client/renderer/LevelRenderer.MOON_LOCATION : Lnet/minecraft/resources/ResourceLocation;")), allow = 1) - private void iris$beforeDrawSun(PoseStack arg, float partialTicks, CallbackInfo ci) { + private void iris$beforeDrawSun(float partialTicks, int pass, CallbackInfo ci) { if (!Iris.getPipelineManager().getPipeline().map(WorldRenderingPipeline::shouldRenderSun).orElse(true)) { iris$emptyBuilder(); } } - @Inject(method = "renderSky", + @Inject(method = "renderSky(FI)V", at = @At(value = "INVOKE", target = "com/mojang/blaze3d/vertex/BufferUploader.end (Lcom/mojang/blaze3d/vertex/BufferBuilder;)V"), slice = @Slice( from = @At(value = "FIELD", target = "net/minecraft/client/renderer/LevelRenderer.MOON_LOCATION : Lnet/minecraft/resources/ResourceLocation;"), to = @At(value = "INVOKE", target = "net/minecraft/client/multiplayer/ClientLevel.getStarBrightness (F)F")), allow = 1) - private void iris$beforeDrawMoon(PoseStack arg, float partialTicks, CallbackInfo ci) { + private void iris$beforeDrawMoon(float partialTicks, int pass, CallbackInfo ci) { if (!Iris.getPipelineManager().getPipeline().map(WorldRenderingPipeline::shouldRenderMoon).orElse(true)) { iris$emptyBuilder(); } diff --git a/src/main/java/net/coderbot/iris/mixin/sky/MixinOptions_CloudsOverride.java b/src/main/java/net/coderbot/iris/mixin/sky/MixinOptions_CloudsOverride.java index a8bed2ca8e..cd80b078ef 100644 --- a/src/main/java/net/coderbot/iris/mixin/sky/MixinOptions_CloudsOverride.java +++ b/src/main/java/net/coderbot/iris/mixin/sky/MixinOptions_CloudsOverride.java @@ -1,32 +1,30 @@ package net.coderbot.iris.mixin.sky; +import net.coderbot.iris.Iris; +import net.coderbot.iris.shaderpack.CloudSetting; +import net.minecraft.client.settings.GameSettings; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.coderbot.iris.Iris; -import net.coderbot.iris.shaderpack.CloudSetting; -import net.minecraft.client.CloudStatus; -import net.minecraft.client.Options; - /** * Allows the current pipeline to override the cloud video mode setting. * * Uses a priority of 1010 to apply after Sodium's MixinGameOptions, which overwrites getCloudsType, so that we can * override its behavior. */ -@Mixin(value = Options.class, priority = 1010) +@Mixin(value = GameSettings.class, priority = 1010) public class MixinOptions_CloudsOverride { @Shadow - public int renderDistance; + public int renderDistanceChunks; - @Inject(method = "getCloudsType", at = @At("HEAD"), cancellable = true) - private void iris$overrideCloudsType(CallbackInfoReturnable cir) { + @Inject(method = "shouldRenderClouds", at = @At("HEAD"), cancellable = true) + private void iris$overrideCloudsType(CallbackInfoReturnable cir) { // Vanilla does not render clouds on low render distances, we have to mirror that check // when injecting at the head. - if (renderDistance < 4) { + if (renderDistanceChunks < 4) { return; } @@ -35,13 +33,13 @@ public class MixinOptions_CloudsOverride { switch (setting) { case OFF: - cir.setReturnValue(CloudStatus.OFF); + cir.setReturnValue(0); return; case FAST: - cir.setReturnValue(CloudStatus.FAST); + cir.setReturnValue(1); return; case FANCY: - cir.setReturnValue(CloudStatus.FANCY); + cir.setReturnValue(2); } }); } diff --git a/src/main/java/net/coderbot/iris/mixin/state_tracking/MixinGlStateManager.java b/src/main/java/net/coderbot/iris/mixin/state_tracking/MixinGlStateManager.java index 332402d3d3..0b60aa3cdc 100644 --- a/src/main/java/net/coderbot/iris/mixin/state_tracking/MixinGlStateManager.java +++ b/src/main/java/net/coderbot/iris/mixin/state_tracking/MixinGlStateManager.java @@ -1,13 +1,12 @@ package net.coderbot.iris.mixin.state_tracking; +import net.minecraft.client.renderer.GlStateManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.platform.GlStateManager; - import net.coderbot.iris.Iris; import net.coderbot.iris.gbuffer_overrides.state.StateTracker; import net.coderbot.iris.pipeline.WorldRenderingPipeline; @@ -16,15 +15,15 @@ @Mixin(GlStateManager.class) public class MixinGlStateManager { @Shadow - private static int activeTexture; + private static int activeTextureUnit; - @Inject(method = "_enableTexture()V", at = @At("HEAD")) + @Inject(method = "enableTexture2D", at = @At("HEAD")) private static void iris$onEnableTexture(CallbackInfo ci) { - if (activeTexture == IrisSamplers.ALBEDO_TEXTURE_UNIT) { + if (activeTextureUnit == IrisSamplers.ALBEDO_TEXTURE_UNIT) { StateTracker.INSTANCE.albedoSampler = true; - } else if (activeTexture == IrisSamplers.LIGHTMAP_TEXTURE_UNIT) { + } else if (activeTextureUnit == IrisSamplers.LIGHTMAP_TEXTURE_UNIT) { StateTracker.INSTANCE.lightmapSampler = true; - } else if (activeTexture == IrisSamplers.OVERLAY_TEXTURE_UNIT) { + } else if (activeTextureUnit == IrisSamplers.OVERLAY_TEXTURE_UNIT) { StateTracker.INSTANCE.overlaySampler = true; } else { return; @@ -33,13 +32,13 @@ public class MixinGlStateManager { Iris.getPipelineManager().getPipeline().ifPresent(p -> p.setInputs(StateTracker.INSTANCE.getInputs())); } - @Inject(method = "_disableTexture()V", at = @At("HEAD")) + @Inject(method = "disableTexture2D", at = @At("HEAD")) private static void iris$onDisableTexture(CallbackInfo ci) { - if (activeTexture == IrisSamplers.ALBEDO_TEXTURE_UNIT) { + if (activeTextureUnit == IrisSamplers.ALBEDO_TEXTURE_UNIT) { StateTracker.INSTANCE.albedoSampler = false; - } else if (activeTexture == IrisSamplers.LIGHTMAP_TEXTURE_UNIT) { + } else if (activeTextureUnit == IrisSamplers.LIGHTMAP_TEXTURE_UNIT) { StateTracker.INSTANCE.lightmapSampler = false; - } else if (activeTexture == IrisSamplers.OVERLAY_TEXTURE_UNIT) { + } else if (activeTextureUnit == IrisSamplers.OVERLAY_TEXTURE_UNIT) { StateTracker.INSTANCE.overlaySampler = false; } else { return; @@ -48,7 +47,7 @@ public class MixinGlStateManager { Iris.getPipelineManager().getPipeline().ifPresent(p -> p.setInputs(StateTracker.INSTANCE.getInputs())); } - @Inject(method = "_drawArrays(III)V", at = @At("HEAD")) + @Inject(method = "glDrawArrays", at = @At("HEAD")) private static void iris$beforeDrawArrays(int mode, int first, int count, CallbackInfo ci) { Iris.getPipelineManager().getPipeline().ifPresent(WorldRenderingPipeline::syncProgram); } diff --git a/src/main/java/net/coderbot/iris/mixin/state_tracking/MixinPostChain.java b/src/main/java/net/coderbot/iris/mixin/state_tracking/MixinPostChain.java index e4875160c6..14a8c32353 100644 --- a/src/main/java/net/coderbot/iris/mixin/state_tracking/MixinPostChain.java +++ b/src/main/java/net/coderbot/iris/mixin/state_tracking/MixinPostChain.java @@ -1,21 +1,21 @@ package net.coderbot.iris.mixin.state_tracking; +import net.minecraft.client.shader.ShaderGroup; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.coderbot.iris.Iris; -import net.minecraft.client.renderer.PostChain; -@Mixin(PostChain.class) +@Mixin(ShaderGroup.class) public class MixinPostChain { - @Inject(method = "process(F)V", at = @At("HEAD")) + @Inject(method = "render(F)V", at = @At("HEAD")) private void iris$beforeProcess(float f, CallbackInfo ci) { Iris.getPipelineManager().getPipeline().ifPresent(pipeline -> pipeline.getRenderTargetStateListener().beginPostChain()); } - @Inject(method = "process(F)V", at = @At("RETURN")) + @Inject(method = "render(F)V", at = @At("RETURN")) private void iris$afterProcess(float f, CallbackInfo ci) { Iris.getPipelineManager().getPipeline().ifPresent(pipeline -> pipeline.getRenderTargetStateListener().endPostChain()); } diff --git a/src/main/java/net/coderbot/iris/mixin/state_tracking/MixinRenderTarget.java b/src/main/java/net/coderbot/iris/mixin/state_tracking/MixinRenderTarget.java index e02162a2fa..a5cb697605 100644 --- a/src/main/java/net/coderbot/iris/mixin/state_tracking/MixinRenderTarget.java +++ b/src/main/java/net/coderbot/iris/mixin/state_tracking/MixinRenderTarget.java @@ -1,12 +1,11 @@ package net.coderbot.iris.mixin.state_tracking; +import net.minecraft.client.shader.Framebuffer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.pipeline.RenderTarget; - import net.coderbot.iris.Iris; import net.minecraft.client.Minecraft; @@ -38,12 +37,12 @@ * once the world has finished rendering. * */ -@Mixin(RenderTarget.class) +@Mixin(Framebuffer.class) public class MixinRenderTarget { - @Inject(method = "bindWrite(Z)V", at = @At("RETURN")) + @Inject(method = "bindFramebuffer", at = @At("RETURN")) private void iris$onBindFramebuffer(boolean bl, CallbackInfo ci) { // IntelliJ is wrong here. It doesn't understand how Mixin works. - boolean mainBound = this == (Object) Minecraft.getInstance().getMainRenderTarget(); + boolean mainBound = this == (Object) Minecraft.getMinecraft().getFramebuffer(); Iris.getPipelineManager().getPipeline() .ifPresent(pipeline -> pipeline.getRenderTargetStateListener().setIsMainBound(mainBound)); diff --git a/src/main/java/net/coderbot/iris/mixin/statelisteners/BooleanStateAccessor.java b/src/main/java/net/coderbot/iris/mixin/statelisteners/BooleanStateAccessor.java index 8490c1741b..c809def4de 100644 --- a/src/main/java/net/coderbot/iris/mixin/statelisteners/BooleanStateAccessor.java +++ b/src/main/java/net/coderbot/iris/mixin/statelisteners/BooleanStateAccessor.java @@ -5,6 +5,6 @@ @Mixin(targets = "com/mojang/blaze3d/platform/GlStateManager$BooleanState") public interface BooleanStateAccessor { - @Accessor("enabled") + @Accessor("currentState") boolean isEnabled(); } diff --git a/src/main/java/net/coderbot/iris/mixin/statelisteners/MixinGlStateManager.java b/src/main/java/net/coderbot/iris/mixin/statelisteners/MixinGlStateManager.java index b244f889a7..1d43e46cfd 100644 --- a/src/main/java/net/coderbot/iris/mixin/statelisteners/MixinGlStateManager.java +++ b/src/main/java/net/coderbot/iris/mixin/statelisteners/MixinGlStateManager.java @@ -1,12 +1,11 @@ package net.coderbot.iris.mixin.statelisteners; +import net.minecraft.client.renderer.GlStateManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.platform.GlStateManager; - import net.coderbot.iris.gl.state.StateUpdateNotifiers; @Mixin(GlStateManager.class) @@ -18,49 +17,49 @@ public class MixinGlStateManager { private static Runnable fogDensityListener; private static Runnable blendFuncListener; - @Inject(method = { "_enableFog", "_disableFog()V" }, at = @At("RETURN")) + @Inject(method = { "enableFog", "disableFog" }, at = @At("RETURN")) private static void iris$onFogToggle(CallbackInfo ci) { if (fogToggleListener != null) { fogToggleListener.run(); } } - @Inject(method = "_fogMode(I)V", at = @At(value = "FIELD", target = "com/mojang/blaze3d/platform/GlStateManager$FogState.mode : I", shift = At.Shift.AFTER)) + @Inject(method = "setFog(I)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/GlStateManager$FogState;mode:I", shift = At.Shift.AFTER)) private static void iris$onFogMode(int mode, CallbackInfo ci) { if (fogModeListener != null) { fogModeListener.run(); } } - @Inject(method = "_fogDensity(F)V", at = @At(value = "FIELD", target = "com/mojang/blaze3d/platform/GlStateManager$FogState.density : F", shift = At.Shift.AFTER)) + @Inject(method = "setFogDensity", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/GlStateManager$FogState;density:F", shift = At.Shift.AFTER)) private static void iris$onFogDensity(float density, CallbackInfo ci) { if (fogDensityListener != null) { fogDensityListener.run(); } } - @Inject(method = "_fogStart(F)V", at = @At(value = "FIELD", target = "Lcom/mojang/blaze3d/platform/GlStateManager$FogState;start:F", shift = At.Shift.AFTER)) + @Inject(method = "setFogStart", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/GlStateManager$FogState;start:F", shift = At.Shift.AFTER)) private static void iris$onFogStart(float density, CallbackInfo ci) { if (fogStartListener != null) { fogStartListener.run(); } } - @Inject(method = "_fogEnd(F)V", at = @At(value = "FIELD", target = "Lcom/mojang/blaze3d/platform/GlStateManager$FogState;end:F", shift = At.Shift.AFTER)) + @Inject(method = "setFogEnd", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/GlStateManager$FogState;end:F", shift = At.Shift.AFTER)) private static void iris$onFogEnd(float density, CallbackInfo ci) { if (fogEndListener != null) { fogEndListener.run(); } } - @Inject(method = "_blendFunc", at = @At("RETURN")) + @Inject(method = "blendFunc(II)V", at = @At("RETURN")) private static void iris$onBlendFunc(int srcRgb, int dstRgb, CallbackInfo ci) { if (blendFuncListener != null) { blendFuncListener.run(); } } - @Inject(method = "_blendFuncSeparate", at = @At("RETURN")) + @Inject(method = "tryBlendFuncSeparate(IIII)V", at = @At("RETURN")) private static void iris$onBlendFuncSeparate(int srcRgb, int dstRgb, int srcAlpha, int dstAlpha, CallbackInfo ci) { if (blendFuncListener != null) { blendFuncListener.run(); diff --git a/src/main/java/net/coderbot/iris/mixin/texture/MixinAbstractTexture.java b/src/main/java/net/coderbot/iris/mixin/texture/MixinAbstractTexture.java index 63a51d7b96..663b049215 100644 --- a/src/main/java/net/coderbot/iris/mixin/texture/MixinAbstractTexture.java +++ b/src/main/java/net/coderbot/iris/mixin/texture/MixinAbstractTexture.java @@ -13,11 +13,11 @@ @Mixin(AbstractTexture.class) public class MixinAbstractTexture { @Shadow - protected int id; + protected int glTextureId; // Inject after the newly-generated texture ID has been stored into the id field - @Inject(method = "getId()I", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/TextureUtil;generateTextureId()I", shift = Shift.BY, by = 2)) + @Inject(method = "getGlTextureId", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/texture/TextureUtil;glGenTextures()I", shift = Shift.BY, by = 2)) private void iris$afterGenerateId(CallbackInfoReturnable cir) { - TextureTracker.INSTANCE.trackTexture(id, (AbstractTexture) (Object) this); + TextureTracker.INSTANCE.trackTexture(glTextureId, (AbstractTexture) (Object) this); } } diff --git a/src/main/java/net/coderbot/iris/mixin/texture/MixinGlStateManager.java b/src/main/java/net/coderbot/iris/mixin/texture/MixinGlStateManager.java index a676ab40ab..6140c9a802 100644 --- a/src/main/java/net/coderbot/iris/mixin/texture/MixinGlStateManager.java +++ b/src/main/java/net/coderbot/iris/mixin/texture/MixinGlStateManager.java @@ -2,7 +2,7 @@ import java.nio.IntBuffer; -import org.jetbrains.annotations.Nullable; +import net.minecraft.client.renderer.GlStateManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -10,36 +10,36 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.platform.GlStateManager; - import net.coderbot.iris.texture.TextureInfoCache; import net.coderbot.iris.texture.TextureTracker; import net.coderbot.iris.texture.pbr.PBRTextureManager; +import javax.annotation.Nullable; + @Mixin(GlStateManager.class) public class MixinGlStateManager { - @Inject(method = "_bindTexture(I)V", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glBindTexture(II)V", shift = Shift.AFTER, remap = false)) + @Inject(method = "bindTexture", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glBindTexture(II)V", shift = Shift.AFTER, remap = false)) private static void iris$onBindTexture(int id, CallbackInfo ci) { TextureTracker.INSTANCE.onBindTexture(id); } - @Inject(method = "_texImage2D(IIIIIIIILjava/nio/IntBuffer;)V", at = @At("TAIL")) + @Inject(method = "glTexImage2D(IIIIIIIILjava/nio/IntBuffer;)V", at = @At("TAIL")) private static void iris$onTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, @Nullable IntBuffer pixels, CallbackInfo ci) { TextureInfoCache.INSTANCE.onTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); } - @Inject(method = "_deleteTexture(I)V", at = @At("TAIL")) + @Inject(method = "deleteTexture(I)V", at = @At("TAIL")) private static void iris$onDeleteTexture(int id, CallbackInfo ci) { iris$onDeleteTexture(id); } - @Inject(method = "_deleteTextures([I)V", at = @At("TAIL")) + /*@Inject(method = "_deleteTextures([I)V", at = @At("TAIL")) private static void iris$onDeleteTextures(int[] ids, CallbackInfo ci) { for (int id : ids) { iris$onDeleteTexture(id); } - } + }*/ @Unique private static void iris$onDeleteTexture(int id) { diff --git a/src/main/java/net/coderbot/iris/mixin/texture/MixinResourceLocation.java b/src/main/java/net/coderbot/iris/mixin/texture/MixinResourceLocation.java deleted file mode 100644 index 57c0bcfb36..0000000000 --- a/src/main/java/net/coderbot/iris/mixin/texture/MixinResourceLocation.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.coderbot.iris.mixin.texture; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.resources.ResourceLocation; - -@Mixin(value = ResourceLocation.class, priority = 1010) -public class MixinResourceLocation { - @Inject(method = "isValidPath", at = @At("HEAD"), cancellable = true) - private static void iris$blockDUMMY(String string, CallbackInfoReturnable cir) { - if (string.equals("DUMMY")) { - cir.setReturnValue(false); - } - } - - @Inject(method = "validPathChar", at = @At("HEAD"), cancellable = true) - private static void iris$allowInvalidPaths(char c, CallbackInfoReturnable cir) { - if (c >= 'A' && c <= 'Z') { - cir.setReturnValue(true); - } - } -} diff --git a/src/main/java/net/coderbot/iris/mixin/texture/MixinTextureManager.java b/src/main/java/net/coderbot/iris/mixin/texture/MixinTextureManager.java index 9f0854c52b..07d2d02eeb 100644 --- a/src/main/java/net/coderbot/iris/mixin/texture/MixinTextureManager.java +++ b/src/main/java/net/coderbot/iris/mixin/texture/MixinTextureManager.java @@ -1,21 +1,18 @@ package net.coderbot.iris.mixin.texture; -import java.util.concurrent.Executor; - +import net.coderbot.iris.texture.format.TextureFormatLoader; +import net.coderbot.iris.texture.pbr.PBRTextureManager; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.resources.IResourceManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import net.coderbot.iris.texture.format.TextureFormatLoader; -import net.coderbot.iris.texture.pbr.PBRTextureManager; -import net.minecraft.client.renderer.texture.TextureManager; -import net.minecraft.server.packs.resources.ResourceManager; - @Mixin(TextureManager.class) public class MixinTextureManager { - @Inject(method = "lambda$reload$4(Lnet/minecraft/server/packs/resources/ResourceManager;Ljava/util/concurrent/Executor;Ljava/lang/Void;)V", at = @At("TAIL")) - private void iris$onTailReloadLambda(ResourceManager resourceManager, Executor applyExecutor, Void void1, CallbackInfo ci) { + @Inject(method = "onResourceManagerReload", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/ProgressManager;pop(Lnet/minecraftforge/fml/common/ProgressManager$ProgressBar;)V", shift = At.Shift.BEFORE)) + private void iris$onTailReloadLambda(IResourceManager resourceManager, CallbackInfo ci) { TextureFormatLoader.reload(resourceManager); PBRTextureManager.INSTANCE.clear(); } diff --git a/src/main/java/net/coderbot/iris/mixin/texture/SimpleTextureAccessor.java b/src/main/java/net/coderbot/iris/mixin/texture/SimpleTextureAccessor.java index f59cffa6b7..a3a16c1883 100644 --- a/src/main/java/net/coderbot/iris/mixin/texture/SimpleTextureAccessor.java +++ b/src/main/java/net/coderbot/iris/mixin/texture/SimpleTextureAccessor.java @@ -1,10 +1,10 @@ package net.coderbot.iris.mixin.texture; +import net.minecraft.util.ResourceLocation; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import net.minecraft.client.renderer.texture.SimpleTexture; -import net.minecraft.resources.ResourceLocation; @Mixin(SimpleTexture.class) public interface SimpleTextureAccessor { diff --git a/src/main/java/net/coderbot/iris/mixin/texture/TextureAtlasAccessor.java b/src/main/java/net/coderbot/iris/mixin/texture/TextureAtlasAccessor.java index c118d847f3..a8494ab0be 100644 --- a/src/main/java/net/coderbot/iris/mixin/texture/TextureAtlasAccessor.java +++ b/src/main/java/net/coderbot/iris/mixin/texture/TextureAtlasAccessor.java @@ -2,6 +2,7 @@ import java.util.Map; +import net.minecraft.client.renderer.texture.TextureMap; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Invoker; @@ -10,10 +11,10 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.resources.ResourceLocation; -@Mixin(TextureAtlas.class) +@Mixin(TextureMap.class) public interface TextureAtlasAccessor { - @Accessor("texturesByName") - Map getTexturesByName(); + @Accessor("mapUploadedSprites") + Map getTexturesByName(); @Invoker("getResourceLocation") ResourceLocation callGetResourceLocation(ResourceLocation location); diff --git a/src/main/java/net/coderbot/iris/mixin/texture/TextureAtlasSpriteAccessor.java b/src/main/java/net/coderbot/iris/mixin/texture/TextureAtlasSpriteAccessor.java index 6254bb77b9..097ec14e1a 100644 --- a/src/main/java/net/coderbot/iris/mixin/texture/TextureAtlasSpriteAccessor.java +++ b/src/main/java/net/coderbot/iris/mixin/texture/TextureAtlasSpriteAccessor.java @@ -1,5 +1,6 @@ package net.coderbot.iris.mixin.texture; +import net.minecraft.client.resources.data.AnimationMetadataSection; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Invoker; @@ -11,7 +12,7 @@ @Mixin(TextureAtlasSprite.class) public interface TextureAtlasSpriteAccessor { - @Accessor("metadata") + @Accessor("animationMetadata") AnimationMetadataSection getMetadata(); @Accessor("mainImage") diff --git a/src/main/java/net/coderbot/iris/mixin/texture/pbr/MixinTextureAtlas.java b/src/main/java/net/coderbot/iris/mixin/texture/pbr/MixinTextureAtlas.java index 31227cbe49..feb6fe4e71 100644 --- a/src/main/java/net/coderbot/iris/mixin/texture/pbr/MixinTextureAtlas.java +++ b/src/main/java/net/coderbot/iris/mixin/texture/pbr/MixinTextureAtlas.java @@ -1,5 +1,6 @@ package net.coderbot.iris.mixin.texture.pbr; +import net.minecraft.client.renderer.texture.TextureMap; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -9,14 +10,13 @@ import net.coderbot.iris.texture.pbr.PBRAtlasHolder; import net.coderbot.iris.texture.pbr.TextureAtlasExtension; import net.minecraft.client.renderer.texture.AbstractTexture; -import net.minecraft.client.renderer.texture.TextureAtlas; -@Mixin(TextureAtlas.class) +@Mixin(TextureMap.class) public abstract class MixinTextureAtlas extends AbstractTexture implements TextureAtlasExtension { @Unique private PBRAtlasHolder pbrHolder; - @Inject(method = "cycleAnimationFrames()V", at = @At("TAIL")) + @Inject(method = "updateAnimations()V", at = @At("TAIL")) private void iris$onTailCycleAnimationFrames(CallbackInfo ci) { if (pbrHolder != null) { pbrHolder.cycleAnimationFrames(); diff --git a/src/main/java/net/coderbot/iris/mixin/texture/pbr/MixinTextureAtlasSprite.java b/src/main/java/net/coderbot/iris/mixin/texture/pbr/MixinTextureAtlasSprite.java index 94549abf7a..4517c69b06 100644 --- a/src/main/java/net/coderbot/iris/mixin/texture/pbr/MixinTextureAtlasSprite.java +++ b/src/main/java/net/coderbot/iris/mixin/texture/pbr/MixinTextureAtlasSprite.java @@ -1,27 +1,16 @@ package net.coderbot.iris.mixin.texture.pbr; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - import net.coderbot.iris.texture.pbr.PBRSpriteHolder; import net.coderbot.iris.texture.pbr.TextureAtlasSpriteExtension; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; @Mixin(TextureAtlasSprite.class) public class MixinTextureAtlasSprite implements TextureAtlasSpriteExtension { @Unique private PBRSpriteHolder pbrHolder; - @Inject(method = "close()V", at = @At("TAIL"), remap = false) - private void iris$onTailClose(CallbackInfo ci) { - if (pbrHolder != null) { - pbrHolder.close(); - } - } - @Override public PBRSpriteHolder getPBRHolder() { return pbrHolder; diff --git a/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java b/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java index efb677b219..ea74111aaa 100644 --- a/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java +++ b/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java @@ -3,6 +3,9 @@ import java.nio.ByteBuffer; import net.coderbot.iris.vertices.*; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.client.renderer.vertex.VertexFormat; import org.jetbrains.annotations.Nullable; import org.lwjgl.opengl.GL11; import org.spongepowered.asm.mixin.Mixin; @@ -21,6 +24,8 @@ import net.coderbot.iris.block_rendering.BlockRenderingSettings; import net.coderbot.iris.vendored.joml.Vector3f; +import javax.annotation.Nullable; + /** * Dynamically and transparently extends the vanilla vertex formats with additional data */ @@ -105,19 +110,19 @@ public abstract class MixinBufferBuilder implements BufferVertexConsumer, BlockS @Inject(method = "begin", at = @At("HEAD")) private void iris$onBegin(int 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); + extending = shouldExtend && (format == DefaultVertexFormats.BLOCK || format == DefaultVertexFormats.NEW_ENTITY + || format == DefaultVertexFormats.POSITION_COLOR_TEX_LIGHTMAP); vertexCount = 0; if (extending) { - injectNormal = format == DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP; + injectNormal = format == DefaultVertexFormats.POSITION_COLOR_TEX_LIGHTMAP; } } @Inject(method = "begin", at = @At("RETURN")) private void iris$afterBegin(int drawMode, VertexFormat format, CallbackInfo ci) { if (extending) { - if (format == DefaultVertexFormat.NEW_ENTITY) { + if (format == DefaultVertexFormats.NEW_ENTITY) { this.switchFormat(IrisVertexFormats.ENTITY); this.iris$isTerrain = false; } else { @@ -192,7 +197,7 @@ public abstract class MixinBufferBuilder implements BufferVertexConsumer, BlockS private void fillExtendedData(int vertexAmount) { vertexCount = 0; - int stride = format.getVertexSize(); + int stride = format.getSize(); polygon.setup(buffer, nextElementByte, stride, vertexAmount); diff --git a/src/main/java/net/coderbot/iris/mixin/vertices/MixinGlStateManager.java b/src/main/java/net/coderbot/iris/mixin/vertices/MixinGlStateManager.java deleted file mode 100644 index a9e932c745..0000000000 --- a/src/main/java/net/coderbot/iris/mixin/vertices/MixinGlStateManager.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.coderbot.iris.mixin.vertices; - -import org.lwjgl.opengl.GL20C; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; - -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; - -/** - * Fixes a copy-paste error relevant with generic vertex attributes - */ -@Mixin(GlStateManager.class) -public class MixinGlStateManager { - /** - * @author coderbot16 - * @reason Fix mojang copy-paste error - */ - @Overwrite - public static void _disableVertexAttribArray(int index) { - RenderSystem.assertThread(RenderSystem::isOnRenderThread); - GL20C.glDisableVertexAttribArray(index); - } -} diff --git a/src/main/java/net/coderbot/iris/mixin/vertices/MixinVertexFormatElement.java b/src/main/java/net/coderbot/iris/mixin/vertices/MixinVertexFormatElement.java index 53f255a75a..f8b74594d4 100644 --- a/src/main/java/net/coderbot/iris/mixin/vertices/MixinVertexFormatElement.java +++ b/src/main/java/net/coderbot/iris/mixin/vertices/MixinVertexFormatElement.java @@ -1,20 +1,19 @@ package net.coderbot.iris.mixin.vertices; +import net.minecraft.client.renderer.vertex.VertexFormatElement; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.mojang.blaze3d.vertex.VertexFormatElement; - /** * Fixes generic vertex attributes, previously it was only possible to use a vertex attribute with a location of 0. */ @Mixin(VertexFormatElement.class) public class MixinVertexFormatElement { - @Inject(method = "supportsUsage", at = @At("HEAD"), cancellable = true) - private void iris$fixGenericAttributes(int index, VertexFormatElement.Usage type, CallbackInfoReturnable cir) { - if (type == VertexFormatElement.Usage.GENERIC) { + @Inject(method = "isFirstOrUV", at = @At("HEAD"), cancellable = true) + private void iris$fixGenericAttributes(int index, VertexFormatElement.EnumUsage type, CallbackInfoReturnable cir) { + if (type == VertexFormatElement.EnumUsage.GENERIC) { cir.setReturnValue(true); } } diff --git a/src/main/java/net/coderbot/iris/mixin/vertices/immediate/MixinLevelRenderer.java b/src/main/java/net/coderbot/iris/mixin/vertices/immediate/MixinLevelRenderer.java index 7ccd04c18d..ead89cd9bb 100644 --- a/src/main/java/net/coderbot/iris/mixin/vertices/immediate/MixinLevelRenderer.java +++ b/src/main/java/net/coderbot/iris/mixin/vertices/immediate/MixinLevelRenderer.java @@ -1,29 +1,22 @@ package net.coderbot.iris.mixin.vertices.immediate; +import net.coderbot.iris.vertices.ImmediateState; +import net.minecraft.client.renderer.EntityRenderer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Matrix4f; - -import net.coderbot.iris.vertices.ImmediateState; -import net.minecraft.client.Camera; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.client.renderer.LightTexture; - // Uses a priority of 999 to apply before the main Iris mixins to draw entities before deferred runs. -@Mixin(value = LevelRenderer.class, priority = 999) +@Mixin(value = EntityRenderer.class, priority = 999) public class MixinLevelRenderer { - @Inject(method = "renderLevel", at = @At("HEAD")) - private void iris$immediateStateBeginLevelRender(PoseStack poseStack, float f, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, CallbackInfo ci) { + @Inject(method = "renderWorld", at = @At("HEAD")) + private void iris$immediateStateBeginLevelRender(float partialTicks, long finishTimeNano, CallbackInfo ci) { ImmediateState.isRenderingLevel = true; } - @Inject(method = "renderLevel", at = @At("RETURN")) - private void iris$immediateStateEndLevelRender(PoseStack poseStack, float f, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, CallbackInfo ci) { + @Inject(method = "renderWorld", at = @At("RETURN")) + private void iris$immediateStateEndLevelRender(float partialTicks, long finishTimeNano, CallbackInfo ci) { ImmediateState.isRenderingLevel = false; } } diff --git a/src/main/java/net/coderbot/iris/pipeline/ClearPass.java b/src/main/java/net/coderbot/iris/pipeline/ClearPass.java index 0ef600d258..09c45dbb67 100644 --- a/src/main/java/net/coderbot/iris/pipeline/ClearPass.java +++ b/src/main/java/net/coderbot/iris/pipeline/ClearPass.java @@ -1,13 +1,11 @@ package net.coderbot.iris.pipeline; -import java.util.Objects; -import java.util.function.IntSupplier; - -import com.mojang.blaze3d.systems.RenderSystem; - import net.coderbot.iris.gl.framebuffer.GlFramebuffer; import net.coderbot.iris.vendored.joml.Vector4f; -import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; + +import java.util.Objects; +import java.util.function.IntSupplier; public class ClearPass { private final Vector4f color; @@ -25,7 +23,7 @@ public ClearPass(Vector4f color, IntSupplier viewportX, IntSupplier viewportY, G } public void execute(Vector4f defaultClearColor) { - RenderSystem.viewport(0, 0, viewportX.getAsInt(), viewportY.getAsInt()); + GlStateManager.viewport(0, 0, viewportX.getAsInt(), viewportY.getAsInt()); framebuffer.bind(); Vector4f color = Objects.requireNonNull(defaultClearColor); @@ -34,8 +32,8 @@ public void execute(Vector4f defaultClearColor) { color = this.color; } - RenderSystem.clearColor(color.x, color.y, color.z, color.w); - RenderSystem.clear(clearFlags, Minecraft.ON_OSX); + GlStateManager.clearColor(color.x, color.y, color.z, color.w); + GlStateManager.clear(clearFlags); } public GlFramebuffer getFramebuffer() { diff --git a/src/main/java/net/coderbot/iris/pipeline/ClearPassCreator.java b/src/main/java/net/coderbot/iris/pipeline/ClearPassCreator.java index 3450f74360..7793c83243 100644 --- a/src/main/java/net/coderbot/iris/pipeline/ClearPassCreator.java +++ b/src/main/java/net/coderbot/iris/pipeline/ClearPassCreator.java @@ -5,10 +5,11 @@ import java.util.List; import java.util.Map; -import org.lwjgl.opengl.GL21C; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL20; import com.google.common.collect.ImmutableList; -import com.mojang.blaze3d.platform.GlStateManager; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; @@ -23,7 +24,7 @@ public class ClearPassCreator { public static ImmutableList createClearPasses(RenderTargets renderTargets, boolean fullClear, PackRenderTargetDirectives renderTargetDirectives) { - final int maxDrawBuffers = GlStateManager._getInteger(GL21C.GL_MAX_DRAW_BUFFERS); + final int maxDrawBuffers = GlStateManager.glGetInteger(GL20.GL_MAX_DRAW_BUFFERS); // Sort buffers by their clear color so we can group up glClear calls. Map> clearByColor = new HashMap<>(); @@ -71,10 +72,10 @@ public static ImmutableList createClearPasses(RenderTargets renderTar // No need to clear the depth buffer, since we're using Minecraft's depth buffer. clearPasses.add(new ClearPass(clearInfo.getColor(), clearInfo::getWidth, clearInfo::getHeight, - renderTargets.createClearFramebuffer(true, clearBuffers), GL21C.GL_COLOR_BUFFER_BIT)); + renderTargets.createClearFramebuffer(true, clearBuffers), GL11.GL_COLOR_BUFFER_BIT)); clearPasses.add(new ClearPass(clearInfo.getColor(), clearInfo::getWidth, clearInfo::getHeight, - renderTargets.createClearFramebuffer(false, clearBuffers), GL21C.GL_COLOR_BUFFER_BIT)); + renderTargets.createClearFramebuffer(false, clearBuffers), GL11.GL_COLOR_BUFFER_BIT)); } }); }); @@ -84,7 +85,7 @@ public static ImmutableList createClearPasses(RenderTargets renderTar public static ImmutableList createShadowClearPasses(ShadowRenderTargets renderTargets, boolean fullClear, PackShadowDirectives renderTargetDirectives) { - final int maxDrawBuffers = GlStateManager._getInteger(GL21C.GL_MAX_DRAW_BUFFERS); + final int maxDrawBuffers = GlStateManager.glGetInteger(GL20.GL_MAX_DRAW_BUFFERS); // Sort buffers by their clear color so we can group up glClear calls. Map clearByColor = new HashMap<>(); @@ -118,10 +119,10 @@ public static ImmutableList createShadowClearPasses(ShadowRenderTarge // No need to clear the depth buffer, since we're using Minecraft's depth buffer. clearPasses.add(new ClearPass(clearColor, renderTargets::getResolution, renderTargets::getResolution, - renderTargets.createFramebufferWritingToAlt(clearBuffers), GL21C.GL_COLOR_BUFFER_BIT)); + renderTargets.createFramebufferWritingToAlt(clearBuffers), GL11.GL_COLOR_BUFFER_BIT)); clearPasses.add(new ClearPass(clearColor, renderTargets::getResolution, renderTargets::getResolution, - renderTargets.createFramebufferWritingToMain(clearBuffers), GL21C.GL_COLOR_BUFFER_BIT)); + renderTargets.createFramebufferWritingToMain(clearBuffers), GL11.GL_COLOR_BUFFER_BIT)); } }); diff --git a/src/main/java/net/coderbot/iris/pipeline/CustomTextureManager.java b/src/main/java/net/coderbot/iris/pipeline/CustomTextureManager.java index 1abdf74317..53e4c23fee 100644 --- a/src/main/java/net/coderbot/iris/pipeline/CustomTextureManager.java +++ b/src/main/java/net/coderbot/iris/pipeline/CustomTextureManager.java @@ -7,10 +7,13 @@ import java.util.Optional; import java.util.function.IntSupplier; +import net.coderbot.iris.mixin.GlStateManagerAccessor; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.ITextureObject; +import net.minecraft.client.renderer.texture.TextureUtil; +import net.minecraft.util.ResourceLocation; import org.apache.commons.io.FilenameUtils; -import com.mojang.blaze3d.platform.GlStateManager; - import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectMaps; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; @@ -26,12 +29,9 @@ import net.coderbot.iris.texture.pbr.PBRTextureHolder; import net.coderbot.iris.texture.pbr.PBRTextureManager; import net.coderbot.iris.texture.pbr.PBRType; -import net.minecraft.ResourceLocationException; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.AbstractTexture; -import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureManager; -import net.minecraft.resources.ResourceLocation; public class CustomTextureManager { private final EnumMap> customTextureIdMap = new EnumMap<>(TextureStage.class); @@ -53,7 +53,7 @@ public CustomTextureManager(PackDirectives packDirectives, customTextureStageDataMap.forEach((samplerName, textureData) -> { try { customTextureIds.put(samplerName, createCustomTexture(textureData)); - } catch (IOException | ResourceLocationException e) { + } catch (IOException e) { Iris.logger.error("Unable to parse the image data for the custom texture on stage " + textureStage + ", sampler " + samplerName, e); } @@ -65,7 +65,7 @@ public CustomTextureManager(PackDirectives packDirectives, noise = customNoiseTextureData.flatMap(textureData -> { try { return Optional.of(createCustomTexture(textureData)); - } catch (IOException | ResourceLocationException e) { + } catch (IOException e) { Iris.logger.error("Unable to parse the image data for the custom noise texture", e); return Optional.empty(); @@ -76,16 +76,16 @@ public CustomTextureManager(PackDirectives packDirectives, AbstractTexture texture = new NativeImageBackedNoiseTexture(noiseTextureResolution); ownedTextures.add(texture); - return texture::getId; + return texture::getGlTextureId; }); } - private IntSupplier createCustomTexture(CustomTextureData textureData) throws IOException, ResourceLocationException { + private IntSupplier createCustomTexture(CustomTextureData textureData) throws IOException { if (textureData instanceof CustomTextureData.PngData) { AbstractTexture texture = new NativeImageBackedCustomTexture((CustomTextureData.PngData) textureData); ownedTextures.add(texture); - return texture::getId; + return texture::getGlTextureId; } else if (textureData instanceof CustomTextureData.LightmapMarker) { // Special code path for the light texture. While shader packs hardcode the primary light texture, it's // possible that a mod will create a different light texture, so this code path is robust to that. @@ -106,7 +106,7 @@ private IntSupplier createCustomTexture(CustomTextureData textureData) throws IO } PBRType pbrType = PBRType.fromFileLocation(withoutExtension); - TextureManager textureManager = Minecraft.getInstance().getTextureManager(); + TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); if (pbrType == null) { ResourceLocation textureLocation = new ResourceLocation(namespace, location); @@ -117,20 +117,20 @@ private IntSupplier createCustomTexture(CustomTextureData textureData) throws IO // reloads. Re-fetching the texture from the TextureManager every time is the most robust approach for // now. return () -> { - AbstractTexture texture = textureManager.getTexture(textureLocation); + ITextureObject texture = textureManager.getTexture(textureLocation); // TODO: Should we give something else if the texture isn't there? This will need some thought - return texture != null ? texture.getId() : MissingTextureAtlasSprite.getTexture().getId(); + return texture != null ? texture.getGlTextureId() : TextureUtil.MISSING_TEXTURE.getGlTextureId(); }; } else { location = location.substring(0, extensionIndex - pbrType.getSuffix().length()) + location.substring(extensionIndex); ResourceLocation textureLocation = new ResourceLocation(namespace, location); return () -> { - AbstractTexture texture = textureManager.getTexture(textureLocation); + ITextureObject texture = textureManager.getTexture(textureLocation); if (texture != null) { - int id = texture.getId(); + int id = texture.getGlTextureId(); PBRTextureHolder pbrHolder = PBRTextureManager.INSTANCE.getOrLoadHolder(id); AbstractTexture pbrTexture; switch (pbrType) { @@ -146,16 +146,16 @@ private IntSupplier createCustomTexture(CustomTextureData textureData) throws IO TextureFormat textureFormat = TextureFormatLoader.getFormat(); if (textureFormat != null) { - int previousBinding = GlStateManager.getActiveTextureName(); - GlStateManager._bindTexture(pbrTexture.getId()); + int previousBinding = GlStateManagerAccessor.getTEXTURES()[GlStateManagerAccessor.getActiveTexture()].textureName; + GlStateManager.bindTexture(pbrTexture.getGlTextureId()); textureFormat.setupTextureParameters(pbrType, pbrTexture); - GlStateManager._bindTexture(previousBinding); + GlStateManager.bindTexture(previousBinding); } - return pbrTexture.getId(); + return pbrTexture.getGlTextureId(); } - return MissingTextureAtlasSprite.getTexture().getId(); + return TextureUtil.MISSING_TEXTURE.getGlTextureId(); }; } } else { diff --git a/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java b/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java index 67fe37d6b0..44be73695a 100644 --- a/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java @@ -1,55 +1,29 @@ package net.coderbot.iris.pipeline; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.OptionalInt; -import java.util.Set; -import java.util.function.IntFunction; -import java.util.function.Supplier; - -import net.coderbot.iris.colorspace.ColorSpace; -import net.coderbot.iris.colorspace.ColorSpaceComputeConverter; -import net.coderbot.iris.colorspace.ColorSpaceConverter; -import net.coderbot.iris.colorspace.ColorSpaceFragmentConverter; -import net.coderbot.iris.gl.IrisRenderSystem; -import net.coderbot.iris.gui.option.IrisVideoSettings; -import org.jetbrains.annotations.Nullable; -import org.lwjgl.opengl.GL15C; -import org.lwjgl.opengl.GL20C; -import org.lwjgl.opengl.GL21C; -import org.lwjgl.opengl.GL30C; - import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.primitives.Ints; -import com.mojang.blaze3d.pipeline.RenderTarget; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.datafixers.util.Pair; - +import com.mojang.realmsclient.util.Pair; import net.coderbot.iris.Iris; import net.coderbot.iris.block_rendering.BlockMaterialMapping; import net.coderbot.iris.block_rendering.BlockRenderingSettings; +import net.coderbot.iris.colorspace.ColorSpace; +import net.coderbot.iris.colorspace.ColorSpaceComputeConverter; +import net.coderbot.iris.colorspace.ColorSpaceConverter; +import net.coderbot.iris.colorspace.ColorSpaceFragmentConverter; import net.coderbot.iris.gbuffer_overrides.matching.InputAvailability; import net.coderbot.iris.gbuffer_overrides.matching.ProgramTable; import net.coderbot.iris.gbuffer_overrides.matching.RenderCondition; import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition; import net.coderbot.iris.gbuffer_overrides.state.RenderTargetStateListener; +import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.blending.AlphaTestOverride; import net.coderbot.iris.gl.blending.BlendModeOverride; import net.coderbot.iris.gl.blending.BufferBlendOverride; import net.coderbot.iris.gl.framebuffer.GlFramebuffer; -import net.coderbot.iris.gl.program.ComputeProgram; -import net.coderbot.iris.gl.program.Program; -import net.coderbot.iris.gl.program.ProgramBuilder; -import net.coderbot.iris.gl.program.ProgramImages; -import net.coderbot.iris.gl.program.ProgramSamplers; +import net.coderbot.iris.gl.program.*; import net.coderbot.iris.gl.texture.DepthBufferFormat; +import net.coderbot.iris.gui.option.IrisVideoSettings; import net.coderbot.iris.layer.GbufferPrograms; import net.coderbot.iris.mixin.GlStateManagerAccessor; import net.coderbot.iris.mixin.LevelRendererAccessor; @@ -64,16 +38,7 @@ import net.coderbot.iris.rendertarget.RenderTargets; import net.coderbot.iris.samplers.IrisImages; import net.coderbot.iris.samplers.IrisSamplers; -import net.coderbot.iris.shaderpack.CloudSetting; -import net.coderbot.iris.shaderpack.ComputeSource; -import net.coderbot.iris.shaderpack.IdMap; -import net.coderbot.iris.shaderpack.OptionalBoolean; -import net.coderbot.iris.shaderpack.PackDirectives; -import net.coderbot.iris.shaderpack.PackShadowDirectives; -import net.coderbot.iris.shaderpack.ProgramDirectives; -import net.coderbot.iris.shaderpack.ProgramFallbackResolver; -import net.coderbot.iris.shaderpack.ProgramSet; -import net.coderbot.iris.shaderpack.ProgramSource; +import net.coderbot.iris.shaderpack.*; import net.coderbot.iris.shaderpack.loading.ProgramId; import net.coderbot.iris.shaderpack.texture.TextureStage; import net.coderbot.iris.shadows.ShadowRenderTargets; @@ -88,10 +53,20 @@ import net.coderbot.iris.uniforms.FrameUpdateNotifier; import net.coderbot.iris.vendored.joml.Vector3d; import net.coderbot.iris.vendored.joml.Vector4f; -import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.DimensionSpecialEffects; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.culling.ICamera; import net.minecraft.client.renderer.texture.AbstractTexture; +import net.minecraft.client.shader.Framebuffer; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; +import org.lwjgl.opengl.GL30; + +import javax.annotation.Nullable; +import java.util.*; +import java.util.function.IntFunction; +import java.util.function.Supplier; /** * Encapsulates the compiled shader program objects for the currently loaded shaderpack. @@ -181,13 +156,13 @@ public DeferredWorldRenderingPipeline(ProgramSet programs) { this.packDirectives = programs.getPackDirectives(); - RenderTarget mainTarget = Minecraft.getInstance().getMainRenderTarget(); + Framebuffer mainTarget = Minecraft.getMinecraft().getFramebuffer(); - int depthTextureId = mainTarget.getDepthTextureId(); + int depthTextureId = mainTarget.depthBuffer; int internalFormat = TextureInfoCache.INSTANCE.getInfo(depthTextureId).getInternalFormat(); DepthBufferFormat depthBufferFormat = DepthBufferFormat.fromGlEnumOrDefault(internalFormat); - this.renderTargets = new RenderTargets(mainTarget.width, mainTarget.height, depthTextureId, + this.renderTargets = new RenderTargets(mainTarget.framebufferWidth, mainTarget.framebufferHeight, depthTextureId, ((Blaze3dRenderTargetExt) mainTarget).iris$getDepthBufferVersion(), depthBufferFormat, programs.getPackDirectives().getRenderTargetDirectives().getRenderTargetSettings(), programs.getPackDirectives()); @@ -218,13 +193,13 @@ public DeferredWorldRenderingPipeline(ProgramSet programs) { BlockRenderingSettings.INSTANCE.setUseExtendedVertexFormat(true); // Don't clobber anything in texture unit 0. It probably won't cause issues, but we're just being cautious here. - GlStateManager._activeTexture(GL20C.GL_TEXTURE2); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE2); customTextureManager = new CustomTextureManager(programs.getPackDirectives(), programs.getPack().getCustomTextureDataMap(), programs.getPack().getCustomNoiseTexture()); whitePixel = new NativeImageBackedSingleColorTexture(255, 255, 255, 255); - GlStateManager._activeTexture(GL20C.GL_TEXTURE0); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0); this.flippedBeforeShadow = ImmutableSet.of(); @@ -318,8 +293,8 @@ public DeferredWorldRenderingPipeline(ProgramSet programs) { ProgramId finalId = id; - return cachedPasses.computeIfAbsent(new Pair<>(id, availability), p -> { - ProgramSource source = resolver.resolveNullable(p.getFirst()); + return cachedPasses.computeIfAbsent(Pair.of(id, availability), p -> { + ProgramSource source = resolver.resolveNullable(p.first()); if (condition == RenderCondition.SHADOW) { if (!shadowDirectives.isShadowEnabled().orElse(shadowRenderTargets != null)) { @@ -454,9 +429,9 @@ public void process(int target) { }; } else { if (IrisRenderSystem.supportsCompute()) { - colorSpaceConverter = new ColorSpaceComputeConverter(mainTarget.width, mainTarget.height, IrisVideoSettings.colorSpace); + colorSpaceConverter = new ColorSpaceComputeConverter(mainTarget.framebufferWidth, mainTarget.framebufferHeight, IrisVideoSettings.colorSpace); } else { - colorSpaceConverter = new ColorSpaceFragmentConverter(mainTarget.width, mainTarget.height, IrisVideoSettings.colorSpace); + colorSpaceConverter = new ColorSpaceFragmentConverter(mainTarget.framebufferWidth, mainTarget.framebufferHeight, IrisVideoSettings.colorSpace); } } @@ -469,7 +444,7 @@ private RenderTargets getRenderTargets() { private void checkWorld() { // If we're not in a world, then obviously we cannot possibly be rendering a world. - if (Minecraft.getInstance().level == null) { + if (Minecraft.getMinecraft().world == null) { isRenderingWorld = false; current = null; } @@ -565,7 +540,7 @@ private RenderCondition getCondition(WorldRenderingPhase phase) { case TERRAIN_CUTOUT_MIPPED: return RenderCondition.TERRAIN_OPAQUE; case ENTITIES: - if (GlStateManagerAccessor.getBLEND().srcRgb == GlStateManager.SourceFactor.SRC_ALPHA.value && GlStateManagerAccessor.getBLEND().dstRgb == GlStateManager.SourceFactor.ONE_MINUS_SRC_ALPHA.value && GlStateManagerAccessor.getBLEND().srcAlpha == GlStateManager.SourceFactor.ONE.value && GlStateManagerAccessor.getBLEND().dstAlpha == GlStateManager.SourceFactor.ONE_MINUS_SRC_ALPHA.value) { + if (GlStateManagerAccessor.getBLEND().srcFactor == GlStateManager.SourceFactor.SRC_ALPHA.factor && GlStateManagerAccessor.getBLEND().dstFactor == GlStateManager.SourceFactor.ONE_MINUS_SRC_ALPHA.factor && GlStateManagerAccessor.getBLEND().srcFactorAlpha == GlStateManager.SourceFactor.ONE.factor && GlStateManagerAccessor.getBLEND().dstFactorAlpha == GlStateManager.SourceFactor.ONE_MINUS_SRC_ALPHA.factor) { return RenderCondition.ENTITIES_TRANSLUCENT; } else { return RenderCondition.ENTITIES; @@ -577,7 +552,6 @@ private RenderCondition getCondition(WorldRenderingPhase phase) { case HAND_SOLID: return RenderCondition.HAND_OPAQUE; case TERRAIN_TRANSLUCENT: - case TRIPWIRE: return RenderCondition.TERRAIN_TRANSLUCENT; case CLOUDS: return RenderCondition.CLOUDS; @@ -798,10 +772,10 @@ public void use() { } if (shadowViewport) { - RenderSystem.viewport(0, 0, shadowMapResolution, shadowMapResolution); + GlStateManager.viewport(0, 0, shadowMapResolution, shadowMapResolution); } else { - RenderTarget main = Minecraft.getInstance().getMainRenderTarget(); - RenderSystem.viewport(0, 0, main.width, main.height); + Framebuffer main = Minecraft.getMinecraft().getFramebuffer(); + GlStateManager.viewport(0, 0, main.framebufferWidth, main.framebufferHeight); } if (program != null && !sodiumTerrainRendering) { @@ -867,11 +841,11 @@ public void destroy() { horizonRenderer.destroy(); // Make sure that any custom framebuffers are not bound before destroying render targets - GlStateManager._glBindFramebuffer(GL30C.GL_READ_FRAMEBUFFER, 0); - GlStateManager._glBindFramebuffer(GL30C.GL_DRAW_FRAMEBUFFER, 0); - GlStateManager._glBindFramebuffer(GL30C.GL_FRAMEBUFFER, 0); + OpenGlHelper.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, 0); + OpenGlHelper.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, 0); + OpenGlHelper.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); - Minecraft.getInstance().getMainRenderTarget().bindWrite(false); + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); // Destroy our render targets // @@ -886,7 +860,7 @@ public void destroy() { // Destroy custom textures and the static samplers (normals, specular, and noise) customTextureManager.destroy(); - whitePixel.releaseId(); + whitePixel.deleteGlTexture(); } private static void destroyPasses(ProgramTable table) { @@ -908,7 +882,7 @@ private static void destroyPasses(ProgramTable table) { private void prepareRenderTargets() { // Make sure we're using texture unit 0 for this. - RenderSystem.activeTexture(GL15C.GL_TEXTURE0); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0); Vector4f emptyClearColor = new Vector4f(1.0F); if (shadowRenderTargets != null) { @@ -922,7 +896,7 @@ private void prepareRenderTargets() { } else { // Clear depth first, regardless of any color clearing. shadowRenderTargets.getDepthSourceFb().bind(); - RenderSystem.clear(GL21C.GL_DEPTH_BUFFER_BIT, Minecraft.ON_OSX); + GlStateManager.clear(GL11.GL_DEPTH_BUFFER_BIT); ImmutableList passes; @@ -945,15 +919,15 @@ private void prepareRenderTargets() { } } - RenderTarget main = Minecraft.getInstance().getMainRenderTarget(); + Framebuffer main = Minecraft.getMinecraft().getFramebuffer(); Blaze3dRenderTargetExt mainExt = (Blaze3dRenderTargetExt) main; - int depthTextureId = main.getDepthTextureId(); + int depthTextureId = main.depthBuffer; int internalFormat = TextureInfoCache.INSTANCE.getInfo(depthTextureId).getInternalFormat(); DepthBufferFormat depthBufferFormat = DepthBufferFormat.fromGlEnumOrDefault(internalFormat); - boolean changed = renderTargets.resizeIfNeeded(mainExt.iris$getDepthBufferVersion(), depthTextureId, main.width, - main.height, depthBufferFormat, packDirectives); + boolean changed = renderTargets.resizeIfNeeded(mainExt.iris$getDepthBufferVersion(), depthTextureId, main.framebufferWidth, + main.framebufferHeight, depthBufferFormat, packDirectives); if (changed) { prepareRenderer.recalculateSizes(); @@ -972,7 +946,7 @@ private void prepareRenderTargets() { if (changed || IrisVideoSettings.colorSpace != currentColorSpace) { currentColorSpace = IrisVideoSettings.colorSpace; - colorSpaceConverter.rebuildProgram(main.width, main.height, currentColorSpace); + colorSpaceConverter.rebuildProgram(main.framebufferWidth, main.framebufferHeight, currentColorSpace); } final ImmutableList passes; @@ -995,7 +969,7 @@ private void prepareRenderTargets() { } // Reset framebuffer and viewport - Minecraft.getInstance().getMainRenderTarget().bindWrite(true); + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true); } private ComputeProgram[] createShadowComputes(ComputeSource[] compute, ProgramSet programSet) { @@ -1073,8 +1047,8 @@ public void beginTranslucents() { deferredRenderer.renderAll(); - RenderSystem.enableBlend(); - RenderSystem.enableAlphaTest(); + GlStateManager.enableBlend(); + GlStateManager.enableAlpha(); // note: we are careful not to touch the lightmap texture unit or overlay color texture unit here, // so we don't need to do anything to restore them if needed. @@ -1089,7 +1063,7 @@ public void beginTranslucents() { } @Override - public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCamera) { + public void renderShadows(LevelRendererAccessor levelRenderer, ICamera playerCamera) { if (shouldRenderPrepareBeforeShadow) { isRenderingFullScreenPass = true; @@ -1170,19 +1144,18 @@ public void beginLevelRendering() { // while rendering the sky. // // A lot of dimension mods touch sky rendering, FabricSkyboxes injects at HEAD and cancels, etc. - DimensionSpecialEffects.SkyType skyType = Minecraft.getInstance().level.effects().skyType(); - - if (skyType == DimensionSpecialEffects.SkyType.NORMAL) { - RenderSystem.disableTexture(); - RenderSystem.depthMask(false); + // TODO Not sure + if (Minecraft.getMinecraft().world.provider.hasSkyLight()) { + GlStateManager.disableTexture2D(); + GlStateManager.depthMask(false); Vector3d fogColor = CapturedRenderingState.INSTANCE.getFogColor(); - RenderSystem.color3f((float) fogColor.x, (float) fogColor.y, (float) fogColor.z); + GlStateManager.color((float) fogColor.x, (float) fogColor.y, (float) fogColor.z); horizonRenderer.renderHorizon(CapturedRenderingState.INSTANCE.getGbufferModelView()); - RenderSystem.depthMask(true); - RenderSystem.enableTexture(); + GlStateManager.depthMask(true); + GlStateManager.enableTexture2D(); } } @@ -1207,7 +1180,7 @@ public void finalizeLevelRendering() { compositeRenderer.renderAll(); finalPassRenderer.renderFinalPass(); - colorSpaceConverter.process(Minecraft.getInstance().getMainRenderTarget().getColorTextureId()); + colorSpaceConverter.process(Minecraft.getMinecraft().getFramebuffer().framebufferTexture); isRenderingFullScreenPass = false; } @@ -1295,8 +1268,8 @@ public int getCurrentSpecularTexture() { public void onBindTexture(int id) { if (shouldBindPBR && isRenderingWorld) { PBRTextureHolder pbrHolder = PBRTextureManager.INSTANCE.getOrLoadHolder(id); - currentNormalTexture = pbrHolder.getNormalTexture().getId(); - currentSpecularTexture = pbrHolder.getSpecularTexture().getId(); + currentNormalTexture = pbrHolder.getNormalTexture().getGlTextureId(); + currentSpecularTexture = pbrHolder.getSpecularTexture().getGlTextureId(); TextureFormat textureFormat = TextureFormatLoader.getFormat(); if (textureFormat != null) { diff --git a/src/main/java/net/coderbot/iris/pipeline/FixedFunctionWorldRenderingPipeline.java b/src/main/java/net/coderbot/iris/pipeline/FixedFunctionWorldRenderingPipeline.java index b81ca27df4..82b8cf7e00 100644 --- a/src/main/java/net/coderbot/iris/pipeline/FixedFunctionWorldRenderingPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/FixedFunctionWorldRenderingPipeline.java @@ -14,6 +14,8 @@ import net.coderbot.iris.uniforms.FrameUpdateNotifier; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.culling.ICamera; public class FixedFunctionWorldRenderingPipeline implements WorldRenderingPipeline { public FixedFunctionWorldRenderingPipeline() { @@ -27,12 +29,12 @@ public FixedFunctionWorldRenderingPipeline() { @Override public void beginLevelRendering() { // Use the default Minecraft framebuffer and ensure that no programs are in use - Minecraft.getInstance().getMainRenderTarget().bindWrite(true); - GlStateManager._glUseProgram(0); + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true); + OpenGlHelper.glUseProgram(0); } @Override - public void renderShadows(LevelRendererAccessor levelRenderer, Camera camera) { + public void renderShadows(LevelRendererAccessor levelRenderer, ICamera camera) { // stub: nothing to do here } diff --git a/src/main/java/net/coderbot/iris/pipeline/HandRenderer.java b/src/main/java/net/coderbot/iris/pipeline/HandRenderer.java index 24869389e1..a043a2952e 100644 --- a/src/main/java/net/coderbot/iris/pipeline/HandRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/HandRenderer.java @@ -7,11 +7,16 @@ import net.coderbot.iris.mixin.GameRendererAccessor; import net.coderbot.iris.uniforms.CapturedRenderingState; import net.irisshaders.iris.api.v0.IrisApi; +import net.minecraft.block.Block; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumHand; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; @@ -42,7 +47,7 @@ private void setupGlState(GameRenderer gameRenderer, Camera camera, PoseStack po ((GameRendererAccessor) gameRenderer).invokeBobHurt(poseStack, tickDelta); - if (Minecraft.getInstance().options.bobView) { + if (Minecraft.getMinecraft().gameSettings.viewBobbing) { ((GameRendererAccessor) gameRenderer).invokeBobView(poseStack, tickDelta); } } @@ -57,18 +62,19 @@ private boolean canRender(Camera camera, GameRenderer gameRenderer) { || Minecraft.getInstance().gameMode.getPlayerMode() == GameType.SPECTATOR); } - public boolean isHandTranslucent(InteractionHand hand) { - Item item = Minecraft.getInstance().player.getItemBySlot(hand == InteractionHand.OFF_HAND ? EquipmentSlot.OFFHAND : EquipmentSlot.MAINHAND).getItem(); + public boolean isHandTranslucent(EnumHand hand) { + Item item = Minecraft.getMinecraft().player.getHeldItem(hand).getItem(); - if (item instanceof BlockItem) { - return ItemBlockRenderTypes.getChunkRenderType(((BlockItem) item).getBlock().defaultBlockState()) == RenderType.translucent(); + if (item instanceof ItemBlock) { + Block block = ((ItemBlock) item).getBlock(); + return block.getRenderLayer() == BlockRenderLayer.TRANSLUCENT; } return false; } public boolean isAnyHandTranslucent() { - return isHandTranslucent(InteractionHand.MAIN_HAND) || isHandTranslucent(InteractionHand.OFF_HAND); + return isHandTranslucent(EnumHand.MAIN_HAND) || isHandTranslucent(EnumHand.OFF_HAND); } public void renderSolid(PoseStack poseStack, float tickDelta, Camera camera, GameRenderer gameRenderer, WorldRenderingPipeline pipeline) { @@ -116,15 +122,15 @@ public void renderTranslucent(PoseStack poseStack, float tickDelta, Camera camer poseStack.pushPose(); - Minecraft.getInstance().getProfiler().push("iris_hand_translucent"); + Minecraft.getMinecraft().getProfiler().push("iris_hand_translucent"); setupGlState(gameRenderer, camera, poseStack, tickDelta); - Minecraft.getInstance().getItemInHandRenderer().renderHandsWithItems(tickDelta, poseStack, bufferSource, Minecraft.getInstance().player, Minecraft.getInstance().getEntityRenderDispatcher().getPackedLightCoords(camera.getEntity(), tickDelta)); + Minecraft.getMinecraft().getItemInHandRenderer().renderHandsWithItems(tickDelta, poseStack, bufferSource, Minecraft.getMinecraft().player, Minecraft.getInstance().getEntityRenderDispatcher().getPackedLightCoords(camera.getEntity(), tickDelta)); poseStack.popPose(); - Minecraft.getInstance().getProfiler().pop(); + Minecraft.getMinecraft().getProfiler().pop(); gameRenderer.resetProjectionMatrix(CapturedRenderingState.INSTANCE.getGbufferProjection()); diff --git a/src/main/java/net/coderbot/iris/pipeline/HorizonRenderer.java b/src/main/java/net/coderbot/iris/pipeline/HorizonRenderer.java index 4c9b7a6507..32a869d617 100644 --- a/src/main/java/net/coderbot/iris/pipeline/HorizonRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/HorizonRenderer.java @@ -1,12 +1,12 @@ package net.coderbot.iris.pipeline; +import nanolive.compat.VertexUtils; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.client.renderer.vertex.VertexBuffer; import org.lwjgl.opengl.GL11; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.blaze3d.vertex.VertexBuffer; -import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.math.Matrix4f; import net.minecraft.client.Minecraft; @@ -46,41 +46,41 @@ public class HorizonRenderer { private int currentRenderDistance; public HorizonRenderer() { - currentRenderDistance = Minecraft.getInstance().options.renderDistance; + currentRenderDistance = Minecraft.getMinecraft().gameSettings.renderDistanceChunks; rebuildBuffer(); } private void rebuildBuffer() { if (this.buffer != null) { - this.buffer.close(); + this.buffer.deleteGlBuffers(); } - BufferBuilder buffer = Tesselator.getInstance().getBuilder(); + BufferBuilder buffer = Tessellator.getInstance().getBuffer(); // Build the horizon quads into a buffer - buffer.begin(GL11.GL_QUADS, DefaultVertexFormat.POSITION); + buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); buildHorizon(currentRenderDistance * 16, buffer); - buffer.end(); + buffer.finishDrawing(); - this.buffer = new VertexBuffer(DefaultVertexFormat.POSITION); - this.buffer.bind(); + this.buffer = new VertexBuffer(DefaultVertexFormats.POSITION); + this.buffer.bindBuffer(); this.buffer.upload(buffer); - VertexBuffer.unbind(); + this.buffer.unbindBuffer(); } - private void buildQuad(VertexConsumer consumer, double x1, double z1, double x2, double z2) { - consumer.vertex(x1, BOTTOM, z1); + private void buildQuad(BufferBuilder consumer, double x1, double z1, double x2, double z2) { + consumer.pos(x1, BOTTOM, z1); consumer.endVertex(); - consumer.vertex(x1, TOP, z1); + consumer.pos(x1, TOP, z1); consumer.endVertex(); - consumer.vertex(x2, TOP, z2); + consumer.pos(x2, TOP, z2); consumer.endVertex(); - consumer.vertex(x2, BOTTOM, z2); + consumer.pos(x2, BOTTOM, z2); consumer.endVertex(); } - private void buildHalf(VertexConsumer consumer, double adjacent, double opposite, boolean invert) { + private void buildHalf(BufferBuilder consumer, double adjacent, double opposite, boolean invert) { if (invert) { adjacent = -adjacent; opposite = -opposite; @@ -106,49 +106,49 @@ private void buildHalf(VertexConsumer consumer, double adjacent, double opposite * @param opposite the opposite side length of the a triangle with a hypotenuse extending from the center of the * octagon to a given vertex on the perimeter. */ - private void buildOctagonalPrism(VertexConsumer consumer, double adjacent, double opposite) { + private void buildOctagonalPrism(BufferBuilder consumer, double adjacent, double opposite) { buildHalf(consumer, adjacent, opposite, false); buildHalf(consumer, adjacent, opposite, true); } - private void buildRegularOctagonalPrism(VertexConsumer consumer, double radius) { + private void buildRegularOctagonalPrism(BufferBuilder consumer, double radius) { buildOctagonalPrism(consumer, radius * COS_22_5, radius * SIN_22_5); } - private void buildBottomPlane(VertexConsumer consumer, int radius) { + private void buildBottomPlane(BufferBuilder consumer, int radius) { for (int x = -radius; x <= radius; x += 64) { for (int z = -radius; z <= radius; z += 64) { - consumer.vertex(x + 64, BOTTOM, z); + consumer.pos(x + 64, BOTTOM, z); consumer.endVertex(); - consumer.vertex(x, BOTTOM, z); + consumer.pos(x, BOTTOM, z); consumer.endVertex(); - consumer.vertex(x, BOTTOM, z + 64); + consumer.pos(x, BOTTOM, z + 64); consumer.endVertex(); - consumer.vertex(x + 64, BOTTOM, z + 64); + consumer.pos(x + 64, BOTTOM, z + 64); consumer.endVertex(); } } } - private void buildTopPlane(VertexConsumer consumer, int radius) { + private void buildTopPlane(BufferBuilder consumer, int radius) { // You might be tempted to try to combine this with buildBottomPlane to avoid code duplication, // but that won't work since the winding order has to be reversed or else one of the planes will be // discarded by back face culling. for (int x = -radius; x <= radius; x += 64) { for (int z = -radius; z <= radius; z += 64) { - consumer.vertex(x + 64, TOP, z); + consumer.pos(x + 64, TOP, z); consumer.endVertex(); - consumer.vertex(x + 64, TOP, z + 64); + consumer.pos(x + 64, TOP, z + 64); consumer.endVertex(); - consumer.vertex(x, TOP, z + 64); + consumer.pos(x, TOP, z + 64); consumer.endVertex(); - consumer.vertex(x, TOP, z); + consumer.pos(x, TOP, z); consumer.endVertex(); } } } - private void buildHorizon(int radius, VertexConsumer consumer) { + private void buildHorizon(int radius, BufferBuilder consumer) { if (radius > 256) { // Prevent the prism from getting too large, this causes issues on some shader packs that modify the vanilla // sky if we don't do this. @@ -166,19 +166,19 @@ private void buildHorizon(int radius, VertexConsumer consumer) { } public void renderHorizon(Matrix4f matrix) { - if (currentRenderDistance != Minecraft.getInstance().options.renderDistance) { - currentRenderDistance = Minecraft.getInstance().options.renderDistance; + if (currentRenderDistance != Minecraft.getMinecraft().gameSettings.renderDistanceChunks) { + currentRenderDistance = Minecraft.getMinecraft().gameSettings.renderDistanceChunks; rebuildBuffer(); } - buffer.bind(); - DefaultVertexFormat.POSITION.setupBufferState(0L); - buffer.draw(matrix, GL11.GL_QUADS); - DefaultVertexFormat.POSITION.clearBufferState(); - VertexBuffer.unbind(); + buffer.bindBuffer(); + VertexUtils.setupBufferState(DefaultVertexFormats.POSITION, 0L); + buffer.drawArrays(matrix, GL11.GL_QUADS); + VertexUtils.clearBufferState(DefaultVertexFormats.POSITION); + buffer.unbindBuffer(); } public void destroy() { - buffer.close(); + buffer.deleteGlBuffers(); } } diff --git a/src/main/java/net/coderbot/iris/pipeline/PipelineManager.java b/src/main/java/net/coderbot/iris/pipeline/PipelineManager.java index de8dc15ec5..497fcd575f 100644 --- a/src/main/java/net/coderbot/iris/pipeline/PipelineManager.java +++ b/src/main/java/net/coderbot/iris/pipeline/PipelineManager.java @@ -6,16 +6,15 @@ import java.util.function.Function; import net.coderbot.iris.shaderpack.materialmap.NamespacedId; -import org.jetbrains.annotations.Nullable; -import org.lwjgl.opengl.GL20C; - -import com.mojang.blaze3d.platform.GlStateManager; import net.coderbot.iris.Iris; import net.coderbot.iris.block_rendering.BlockRenderingSettings; -import net.coderbot.iris.shaderpack.DimensionId; import net.coderbot.iris.uniforms.SystemTimeUniforms; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL13; + +import javax.annotation.Nullable; public class PipelineManager { private static PipelineManager instance; @@ -38,8 +37,8 @@ public WorldRenderingPipeline preparePipeline(NamespacedId currentDimension) { pipelinesPerDimension.put(currentDimension, pipeline); if (BlockRenderingSettings.INSTANCE.isReloadRequired()) { - if (Minecraft.getInstance().levelRenderer != null) { - Minecraft.getInstance().levelRenderer.allChanged(); + if (Minecraft.getMinecraft().renderGlobal != null) { + Minecraft.getMinecraft().renderGlobal.loadRenderers(); } BlockRenderingSettings.INSTANCE.clearReloadRequired(); @@ -105,13 +104,13 @@ private void resetTextureState() { // // Without this code, there will be weird issues when reloading certain shaderpacks. for (int i = 0; i < 16; i++) { - GlStateManager.glActiveTexture(GL20C.GL_TEXTURE0 + i); - GlStateManager._bindTexture(0); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0 + i); + GlStateManager.bindTexture(0); } // Set the active texture unit to unit 0 // // This seems to be what most code expects. It's a sane default in any case. - GlStateManager.glActiveTexture(GL20C.GL_TEXTURE0); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0); } } diff --git a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java index a16d65c955..0e0073dc9c 100644 --- a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java @@ -5,7 +5,15 @@ import java.util.List; import java.util.Objects; -import org.lwjgl.opengl.ARBTextureSwizzle; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.culling.ICamera; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.profiler.Profiler; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import org.lwjgl.opengl.*; import org.lwjgl.opengl.GL20C; import org.lwjgl.opengl.GL30C; @@ -58,7 +66,7 @@ public class ShadowRenderer { public static Matrix4f MODELVIEW; public static Matrix4f PROJECTION; - public static List visibleBlockEntities; + public static List visibleBlockEntities; public static boolean ACTIVE = false; private final float halfPlaneLength; private final float renderDistanceMultiplier; @@ -84,12 +92,12 @@ public class ShadowRenderer { private String debugStringTerrain = "(unavailable)"; private int renderedShadowEntities = 0; private int renderedShadowBlockEntities = 0; - private ProfilerFiller profiler; + private Profiler profiler; public ShadowRenderer(ProgramSource shadow, PackDirectives directives, ShadowRenderTargets shadowRenderTargets) { - this.profiler = Minecraft.getInstance().getProfiler(); + this.profiler = Minecraft.getMinecraft().profiler; final PackShadowDirectives shadowDirectives = directives.getShadowDirectives(); @@ -154,12 +162,12 @@ public static PoseStack createShadowModelView(float sunPathRotation, float inter return modelView; } - private static ClientLevel getLevel() { - return Objects.requireNonNull(Minecraft.getInstance().level); + private static WorldClient getLevel() { + return Objects.requireNonNull(Minecraft.getMinecraft().world); } private static float getSkyAngle() { - return getLevel().getTimeOfDay(CapturedRenderingState.INSTANCE.getTickDelta()); + return getLevel().getCelestialAngle(CapturedRenderingState.INSTANCE.getTickDelta()); } private static float getSunAngle() { @@ -189,7 +197,7 @@ private void configureSamplingSettings(PackShadowDirectives shadowDirectives) { final ImmutableList colorSamplingSettings = shadowDirectives.getColorSamplingSettings(); - RenderSystem.activeTexture(GL20C.GL_TEXTURE4); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE4); configureDepthSampler(targets.getDepthTexture().getTextureId(), depthSamplingSettings.get(0)); @@ -201,53 +209,53 @@ private void configureSamplingSettings(PackShadowDirectives shadowDirectives) { configureSampler(glTextureId, colorSamplingSettings.get(i)); } - RenderSystem.activeTexture(GL20C.GL_TEXTURE0); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0); } private void configureDepthSampler(int glTextureId, PackShadowDirectives.DepthSamplingSettings settings) { if (settings.getHardwareFiltering()) { // We have to do this or else shadow hardware filtering breaks entirely! - IrisRenderSystem.texParameteri(glTextureId, GL20C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_COMPARE_MODE, GL30C.GL_COMPARE_REF_TO_TEXTURE); + IrisRenderSystem.texParameteri(glTextureId, GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_COMPARE_MODE, GL30.GL_COMPARE_REF_TO_TEXTURE); } // Workaround for issues with old shader packs like Chocapic v4. // They expected the driver to put the depth value in z, but it's supposed to only // be available in r. So we set up the swizzle to fix that. - IrisRenderSystem.texParameteriv(glTextureId, GL20C.GL_TEXTURE_2D, ARBTextureSwizzle.GL_TEXTURE_SWIZZLE_RGBA, - new int[] { GL30C.GL_RED, GL30C.GL_RED, GL30C.GL_RED, GL30C.GL_ONE }); + IrisRenderSystem.texParameteriv(glTextureId, GL11.GL_TEXTURE_2D, ARBTextureSwizzle.GL_TEXTURE_SWIZZLE_RGBA, + new int[] { GL11.GL_RED, GL11.GL_RED, GL11.GL_RED, GL11.GL_ONE }); configureSampler(glTextureId, settings); } private void configureSampler(int glTextureId, PackShadowDirectives.SamplingSettings settings) { if (settings.getMipmap()) { - int filteringMode = settings.getNearest() ? GL20C.GL_NEAREST_MIPMAP_NEAREST : GL20C.GL_LINEAR_MIPMAP_LINEAR; + int filteringMode = settings.getNearest() ? GL11.GL_NEAREST_MIPMAP_NEAREST : GL11.GL_LINEAR_MIPMAP_LINEAR; mipmapPasses.add(new MipmapPass(glTextureId, filteringMode)); } if (!settings.getNearest()) { // Make sure that things are smoothed - IrisRenderSystem.texParameteri(glTextureId, GL20C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_MIN_FILTER, GL20C.GL_LINEAR); - IrisRenderSystem.texParameteri(glTextureId, GL20C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_MAG_FILTER, GL20C.GL_LINEAR); + IrisRenderSystem.texParameteri(glTextureId, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); + IrisRenderSystem.texParameteri(glTextureId, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); } else { - IrisRenderSystem.texParameteri(glTextureId, GL20C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_MIN_FILTER, GL20C.GL_NEAREST); - IrisRenderSystem.texParameteri(glTextureId, GL20C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_MAG_FILTER, GL20C.GL_NEAREST); + IrisRenderSystem.texParameteri(glTextureId, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); + IrisRenderSystem.texParameteri(glTextureId, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); } } private void generateMipmaps() { - RenderSystem.activeTexture(GL20C.GL_TEXTURE4); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE4); for (MipmapPass mipmapPass : mipmapPasses) { setupMipmappingForTexture(mipmapPass.getTexture(), mipmapPass.getTargetFilteringMode()); } - RenderSystem.activeTexture(GL20C.GL_TEXTURE0); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0); } private void setupMipmappingForTexture(int texture, int filteringMode) { - IrisRenderSystem.generateMipmaps(texture, GL20C.GL_TEXTURE_2D); - IrisRenderSystem.texParameteri(texture, GL20C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_MIN_FILTER, filteringMode); + IrisRenderSystem.generateMipmaps(texture, GL11.GL_TEXTURE_2D); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filteringMode); } private FrustumHolder createShadowFrustum(float renderMultiplier, FrustumHolder holder) { @@ -265,8 +273,8 @@ private FrustumHolder createShadowFrustum(float renderMultiplier, FrustumHolder reason = "(voxelization detected)"; } - if (distance <= 0 || distance > Minecraft.getInstance().options.renderDistance * 16) { - distanceInfo = Minecraft.getInstance().options.renderDistance * 16 + if (distance <= 0 || distance > Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16) { + distanceInfo = Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16 + " blocks (capped by normal render distance)"; cullingInfo = "disabled " + reason; return holder.setInfo(new NonCullingFrustum(), distanceInfo, cullingInfo); @@ -287,8 +295,8 @@ private FrustumHolder createShadowFrustum(float renderMultiplier, FrustumHolder setter = "(set by user)"; } - if (distance >= Minecraft.getInstance().options.renderDistance * 16) { - distanceInfo = Minecraft.getInstance().options.renderDistance * 16 + if (distance >= Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16) { + distanceInfo = Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16 + " blocks (capped by normal render distance)"; boxCuller = null; } else { @@ -330,19 +338,19 @@ private void setupGlState(float[] projMatrix) { // However, it only partially resolves issues of light leaking into caves. // // TODO: Better way of preventing light from leaking into places where it shouldn't - RenderSystem.disableCull(); + GlStateManager.disableCull(); } private void restoreGlState() { // Restore backface culling - RenderSystem.enableCull(); + GlStateManager.enableCull(); // Make sure to unload the projection matrix IrisRenderSystem.restoreProjectionMatrix(); } private void copyPreTranslucentDepth() { - profiler.popPush("translucent depth copy"); + profiler.endStartSection("translucent depth copy"); targets.copyPreTranslucentDepth(); } @@ -352,25 +360,26 @@ private void renderEntities(LevelRendererAccessor levelRenderer, Frustum frustum int shadowEntities = 0; - profiler.push("cull"); + profiler.startSection("cull"); List renderedEntities = new ArrayList<>(32); // TODO: I'm sure that this can be improved / optimized. for (Entity entity : getLevel().entitiesForRendering()) { - if (!dispatcher.shouldRender(entity, frustum, cameraX, cameraY, cameraZ) || entity.isSpectator()) { + if (!dispatcher.shouldRender(entity, frustum, cameraX, cameraY, cameraZ) || (entity instanceof EntityPlayer && ((EntityPlayer) entity).isSpectator())) { continue; } renderedEntities.add(entity); } - profiler.popPush("sort"); + profiler.endStartSection("sort"); // Sort the entities by type first in order to allow vanilla's entity batching system to work better. - renderedEntities.sort(Comparator.comparingInt(entity -> entity.getType().hashCode())); + // TODO not sure + renderedEntities.sort(Comparator.comparingInt(entity -> entity.getClass().hashCode())); - profiler.popPush("build geometry"); + profiler.endStartSection("build geometry"); for (Entity entity : renderedEntities) { levelRenderer.invokeRenderEntity(entity, cameraX, cameraY, cameraZ, tickDelta, modelView, bufferSource); @@ -379,21 +388,21 @@ private void renderEntities(LevelRendererAccessor levelRenderer, Frustum frustum renderedShadowEntities = shadowEntities; - profiler.pop(); + profiler.endSection(); } private void renderPlayerEntity(LevelRendererAccessor levelRenderer, Frustum frustum, MultiBufferSource.BufferSource bufferSource, PoseStack modelView, double cameraX, double cameraY, double cameraZ, float tickDelta) { EntityRenderDispatcher dispatcher = levelRenderer.getEntityRenderDispatcher(); - profiler.push("cull"); + profiler.startSection("cull"); - Entity player = Minecraft.getInstance().player; + EntityPlayer player = Minecraft.getMinecraft().player; if (!dispatcher.shouldRender(player, frustum, cameraX, cameraY, cameraZ) || player.isSpectator()) { return; } - profiler.popPush("build geometry"); + profiler.endStartSection("build geometry"); int shadowEntities = 0; @@ -415,11 +424,11 @@ private void renderPlayerEntity(LevelRendererAccessor levelRenderer, Frustum fru renderedShadowEntities = shadowEntities; - profiler.pop(); + profiler.endSection(); } private void renderBlockEntities(MultiBufferSource.BufferSource bufferSource, PoseStack modelView, double cameraX, double cameraY, double cameraZ, float tickDelta, boolean hasEntityFrustum) { - profiler.push("build blockentities"); + profiler.startSection("build blockentities"); int shadowBlockEntities = 0; BoxCuller culler = null; @@ -428,8 +437,8 @@ private void renderBlockEntities(MultiBufferSource.BufferSource bufferSource, Po culler.setPosition(cameraX, cameraY, cameraZ); } - for (BlockEntity entity : visibleBlockEntities) { - BlockPos pos = entity.getBlockPos(); + for (TileEntity entity : visibleBlockEntities) { + BlockPos pos = entity.getPos(); if (hasEntityFrustum) { if (culler.isCulled(pos.getX() - 1, pos.getY() - 1, pos.getZ() - 1, pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1)) { continue; @@ -445,21 +454,21 @@ private void renderBlockEntities(MultiBufferSource.BufferSource bufferSource, Po renderedShadowBlockEntities = shadowBlockEntities; - profiler.pop(); + profiler.endSection(); } - public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCamera) { + public void renderShadows(LevelRendererAccessor levelRenderer, ICamera playerCamera) { if (IrisVideoSettings.getOverriddenShadowDistance(IrisVideoSettings.shadowDistance) == 0) { return; } // We have to re-query this each frame since this changes based on whether the profiler is active // If the profiler is inactive, it will return InactiveProfiler.INSTANCE - this.profiler = Minecraft.getInstance().getProfiler(); + this.profiler = Minecraft.getMinecraft().profiler; - Minecraft client = Minecraft.getInstance(); + Minecraft client = Minecraft.getMinecraft(); - profiler.popPush("shadows"); + profiler.startSection("shadows"); ACTIVE = true; // NB: We store the previous player buffers in order to be able to allow mods rendering entities in the shadow pass (Flywheel) to use the shadow buffers instead. @@ -482,13 +491,13 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame PROJECTION = new Matrix4f(); ((Matrix4fAccess) (Object) PROJECTION).copyFromArray(projMatrix); - profiler.push("terrain_setup"); + profiler.endStartSection("terrain_setup"); if (levelRenderer instanceof CullingDataCache) { ((CullingDataCache) levelRenderer).saveState(); } - profiler.push("initialize frustum"); + profiler.endStartSection("initialize frustum"); terrainFrustumHolder = createShadowFrustum(renderDistanceMultiplier, terrainFrustumHolder); @@ -500,16 +509,16 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame double cameraZ = cameraPos.z(); // Center the frustum on the player camera position - terrainFrustumHolder.getFrustum().prepare(cameraX, cameraY, cameraZ); + terrainFrustumHolder.getFrustum().setPosition(cameraX, cameraY, cameraZ); - profiler.pop(); + profiler.endSection(); // Disable chunk occlusion culling - it's a bit complex to get this properly working with shadow rendering // as-is, however in the future it will be good to work on restoring it for a nice performance boost. // // TODO: Get chunk occlusion working with shadows - boolean wasChunkCullingEnabled = client.smartCull; - client.smartCull = false; + boolean wasChunkCullingEnabled = client.renderChunksMany; + client.renderChunksMany = false; // Always schedule a terrain update // TODO: Only schedule a terrain update if the sun / moon is moving, or the shadow map camera moved. @@ -527,9 +536,9 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame // chunks during traversal, and break rendering in concerning ways. levelRenderer.setFrameId(levelRenderer.getFrameId() + 1); - client.smartCull = wasChunkCullingEnabled; + client.renderChunksMany = wasChunkCullingEnabled; - profiler.popPush("terrain"); + profiler.endStartSection("terrain"); setupGlState(projMatrix); @@ -540,7 +549,7 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame levelRenderer.invokeRenderChunkLayer(RenderType.cutoutMipped(), modelView, cameraX, cameraY, cameraZ); } - profiler.popPush("entities"); + profiler.endStartSection("entities"); // Get the current tick delta. Normally this is the same as client.getTickDelta(), but when the game is paused, // it is set to a fixed value. @@ -558,7 +567,7 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame } Frustum entityShadowFrustum = entityFrustumHolder.getFrustum(); - entityShadowFrustum.prepare(cameraX, cameraY, cameraZ); + entityShadowFrustum.setPosition(cameraX, cameraY, cameraZ); // Render nearby entities // @@ -584,7 +593,7 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame renderBlockEntities(bufferSource, modelView, cameraX, cameraY, cameraZ, tickDelta, hasEntityFrustum); } - profiler.popPush("draw entities"); + profiler.endStartSection("draw entities"); // NB: Don't try to draw the translucent parts of entities afterwards. It'll cause problems since some // shader packs assume that everything drawn afterwards is actually translucent and should cast a colored @@ -593,7 +602,7 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame copyPreTranslucentDepth(); - profiler.popPush("translucent terrain"); + profiler.endStartSection("translucent terrain"); // TODO: Prevent these calls from scheduling translucent sorting... // It doesn't matter a ton, since this just means that they won't be sorted in the normal rendering pass. @@ -611,11 +620,11 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame debugStringTerrain = ((LevelRenderer) levelRenderer).getChunkStatistics(); - profiler.popPush("generate mipmaps"); + profiler.endStartSection("generate mipmaps"); generateMipmaps(); - profiler.popPush("restore gl state"); + profiler.endStartSection("restore gl state"); restoreGlState(); @@ -626,8 +635,8 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame levelRenderer.setRenderBuffers(playerBuffers); ACTIVE = false; - profiler.pop(); - profiler.popPush("updatechunks"); + profiler.endSection(); + profiler.endStartSection("updatechunks"); } public void addDebugText(List messages) { @@ -651,11 +660,11 @@ public void addDebugText(List messages) { } private String getEntitiesDebugString() { - return (shouldRenderEntities || shouldRenderPlayer) ? (renderedShadowEntities + "/" + Minecraft.getInstance().level.getEntityCount()) : "disabled by pack"; + return (shouldRenderEntities || shouldRenderPlayer) ? (renderedShadowEntities + "/" + Minecraft.getMinecraft().world.getLoadedEntityList().size()) : "disabled by pack"; } private String getBlockEntitiesDebugString() { - return shouldRenderBlockEntities ? (renderedShadowBlockEntities + "/" + Minecraft.getInstance().level.blockEntityList.size()) : "disabled by pack"; + return shouldRenderBlockEntities ? (renderedShadowBlockEntities + "/" + Minecraft.getMinecraft().world.loadedTileEntityList.size()) : "disabled by pack"; } private static class MipmapPass { diff --git a/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPhase.java b/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPhase.java index 8d7ec48d24..c8011de042 100644 --- a/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPhase.java +++ b/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPhase.java @@ -1,6 +1,6 @@ package net.coderbot.iris.pipeline; -import net.minecraft.client.renderer.RenderType; +import net.minecraft.util.BlockRenderLayer; public enum WorldRenderingPhase { NONE, @@ -21,24 +21,21 @@ public enum WorldRenderingPhase { DEBUG, HAND_SOLID, TERRAIN_TRANSLUCENT, - TRIPWIRE, PARTICLES, CLOUDS, RAIN_SNOW, WORLD_BORDER, HAND_TRANSLUCENT; - public static WorldRenderingPhase fromTerrainRenderType(RenderType renderType) { - if (renderType == RenderType.solid()) { + public static WorldRenderingPhase fromTerrainRenderType(BlockRenderLayer renderType) { + if (renderType == BlockRenderLayer.SOLID) { return WorldRenderingPhase.TERRAIN_SOLID; - } else if (renderType == RenderType.cutout()) { + } else if (renderType == BlockRenderLayer.CUTOUT) { return WorldRenderingPhase.TERRAIN_CUTOUT; - } else if (renderType == RenderType.cutoutMipped()) { + } else if (renderType == BlockRenderLayer.CUTOUT_MIPPED) { return WorldRenderingPhase.TERRAIN_CUTOUT_MIPPED; - } else if (renderType == RenderType.translucent()) { + } else if (renderType == BlockRenderLayer.TRANSLUCENT) { return WorldRenderingPhase.TERRAIN_TRANSLUCENT; - } else if (renderType == RenderType.tripwire()) { - return WorldRenderingPhase.TRIPWIRE; } else { throw new IllegalStateException("Illegal render type!"); } diff --git a/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPipeline.java b/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPipeline.java index 927d55a863..d632cdc76d 100644 --- a/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPipeline.java @@ -10,10 +10,11 @@ import net.coderbot.iris.shaderpack.CloudSetting; import net.coderbot.iris.uniforms.FrameUpdateNotifier; import net.minecraft.client.Camera; +import net.minecraft.client.renderer.culling.ICamera; public interface WorldRenderingPipeline { void beginLevelRendering(); - void renderShadows(LevelRendererAccessor levelRenderer, Camera camera); + void renderShadows(LevelRendererAccessor levelRenderer, ICamera camera); void addDebugText(List messages); OptionalInt getForcedShadowRenderDistanceChunksForDisplay(); diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/CompositeTransformer.java b/src/main/java/net/coderbot/iris/pipeline/transform/CompositeTransformer.java index b13f04de37..d09d4e0618 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/CompositeTransformer.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/CompositeTransformer.java @@ -21,8 +21,7 @@ public static void transform( && Stream.concat( root.identifierIndex.getStream("texture2DLod"), root.identifierIndex.getStream("texture3DLod")) - .filter(id -> id.getParent() instanceof FunctionCallExpression) - .findAny().isPresent()) { + .anyMatch(id -> id.getParent() instanceof FunctionCallExpression)) { tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "#extension GL_ARB_shader_texture_lod : require\n"); } diff --git a/src/main/java/net/coderbot/iris/postprocess/CenterDepthSampler.java b/src/main/java/net/coderbot/iris/postprocess/CenterDepthSampler.java index 3b0cb25ebe..46abf334ba 100644 --- a/src/main/java/net/coderbot/iris/postprocess/CenterDepthSampler.java +++ b/src/main/java/net/coderbot/iris/postprocess/CenterDepthSampler.java @@ -1,18 +1,6 @@ package net.coderbot.iris.postprocess; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Objects; -import java.util.function.IntSupplier; - -import org.apache.commons.io.IOUtils; -import org.lwjgl.opengl.GL; -import org.lwjgl.opengl.GL21C; - import com.google.common.collect.ImmutableSet; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; - import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.framebuffer.GlFramebuffer; import net.coderbot.iris.gl.program.Program; @@ -25,6 +13,16 @@ import net.coderbot.iris.gl.uniform.UniformUpdateFrequency; import net.coderbot.iris.uniforms.SystemTimeUniforms; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import org.apache.commons.io.IOUtils; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import org.lwjgl.opengl.GLContext; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Objects; +import java.util.function.IntSupplier; public class CenterDepthSampler { private static final double LN2 = Math.log(2); @@ -37,15 +35,15 @@ public class CenterDepthSampler { private boolean destroyed; public CenterDepthSampler(IntSupplier depthSupplier, float halfLife) { - this.texture = GlStateManager._genTexture(); - this.altTexture = GlStateManager._genTexture(); + this.texture = GlStateManager.generateTexture(); + this.altTexture = GlStateManager.generateTexture(); this.framebuffer = new GlFramebuffer(); // Fall back to a less precise format if the system doesn't support OpenGL 3 - InternalTextureFormat format = GL.getCapabilities().OpenGL32 ? InternalTextureFormat.R32F : InternalTextureFormat.RGB16; + InternalTextureFormat format = GLContext.getCapabilities().OpenGL32 ? InternalTextureFormat.R32F : InternalTextureFormat.RGB16; setupColorTexture(texture, format); setupColorTexture(altTexture, format); - RenderSystem.bindTexture(0); + GlStateManager.bindTexture(0); this.framebuffer.addColorAttachment(0, texture); ProgramBuilder builder; @@ -53,7 +51,7 @@ public CenterDepthSampler(IntSupplier depthSupplier, float halfLife) { try { String fsh = new String(IOUtils.toByteArray(Objects.requireNonNull(getClass().getResourceAsStream("/centerDepth.fsh"))), StandardCharsets.UTF_8); - if (GL.getCapabilities().OpenGL32) { + if (GLContext.getCapabilities().OpenGL32) { fsh = fsh.replace("VERSIONPLACEHOLDER", "150 compatibility"); } else { fsh = fsh.replace("#define IS_GL3", ""); @@ -85,7 +83,7 @@ public void sampleCenterDepth() { this.framebuffer.bind(); this.program.use(); - RenderSystem.viewport(0, 0, 1, 1); + GlStateManager.viewport(0, 0, 1, 1); FullScreenQuadRenderer.INSTANCE.render(); @@ -96,16 +94,16 @@ public void sampleCenterDepth() { DepthCopyStrategy.fastest(false).copy(this.framebuffer, texture, null, altTexture, 1, 1); //Reset viewport - Minecraft.getInstance().getMainRenderTarget().bindWrite(true); + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true); } public void setupColorTexture(int texture, InternalTextureFormat format) { - IrisRenderSystem.texImage2D(texture, GL21C.GL_TEXTURE_2D, 0, format.getGlFormat(), 1, 1, 0, format.getPixelFormat().getGlFormat(), PixelType.FLOAT.getGlFormat(), null); + IrisRenderSystem.texImage2D(texture, GL11.GL_TEXTURE_2D, 0, format.getGlFormat(), 1, 1, 0, format.getPixelFormat().getGlFormat(), PixelType.FLOAT.getGlFormat(), null); - IrisRenderSystem.texParameteri(texture, GL21C.GL_TEXTURE_2D, GL21C.GL_TEXTURE_MIN_FILTER, GL21C.GL_LINEAR); - IrisRenderSystem.texParameteri(texture, GL21C.GL_TEXTURE_2D, GL21C.GL_TEXTURE_MAG_FILTER, GL21C.GL_LINEAR); - IrisRenderSystem.texParameteri(texture, GL21C.GL_TEXTURE_2D, GL21C.GL_TEXTURE_WRAP_S, GL21C.GL_CLAMP_TO_EDGE); - IrisRenderSystem.texParameteri(texture, GL21C.GL_TEXTURE_2D, GL21C.GL_TEXTURE_WRAP_T, GL21C.GL_CLAMP_TO_EDGE); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); } public int getCenterDepthTexture() { @@ -117,8 +115,8 @@ public void setUsage(boolean usage) { } public void destroy() { - GlStateManager._deleteTexture(texture); - GlStateManager._deleteTexture(altTexture); + GlStateManager.deleteTexture(texture); + GlStateManager.deleteTexture(altTexture); framebuffer.destroy(); program.destroy(); destroyed = true; diff --git a/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java b/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java index df3dc6f605..2c526a3958 100644 --- a/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java +++ b/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java @@ -1,28 +1,12 @@ package net.coderbot.iris.postprocess; -import java.util.Map; -import java.util.Objects; -import java.util.function.IntSupplier; -import java.util.function.Supplier; - -import org.lwjgl.opengl.GL15C; -import org.lwjgl.opengl.GL20C; -import org.lwjgl.opengl.GL30C; - import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; - import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.framebuffer.GlFramebuffer; -import net.coderbot.iris.gl.program.ComputeProgram; -import net.coderbot.iris.gl.program.Program; -import net.coderbot.iris.gl.program.ProgramBuilder; -import net.coderbot.iris.gl.program.ProgramSamplers; -import net.coderbot.iris.gl.program.ProgramUniforms; +import net.coderbot.iris.gl.program.*; import net.coderbot.iris.gl.sampler.SamplerLimits; import net.coderbot.iris.pipeline.PatchedShaderPrinter; import net.coderbot.iris.pipeline.transform.PatchShaderType; @@ -31,15 +15,22 @@ import net.coderbot.iris.rendertarget.RenderTargets; import net.coderbot.iris.samplers.IrisImages; import net.coderbot.iris.samplers.IrisSamplers; -import net.coderbot.iris.shaderpack.ComputeSource; -import net.coderbot.iris.shaderpack.PackDirectives; -import net.coderbot.iris.shaderpack.PackRenderTargetDirectives; -import net.coderbot.iris.shaderpack.ProgramDirectives; -import net.coderbot.iris.shaderpack.ProgramSource; +import net.coderbot.iris.shaderpack.*; import net.coderbot.iris.shadows.ShadowRenderTargets; import net.coderbot.iris.uniforms.CommonUniforms; import net.coderbot.iris.uniforms.FrameUpdateNotifier; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.shader.Framebuffer; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; +import org.lwjgl.opengl.GL30; + +import java.util.Map; +import java.util.Objects; +import java.util.function.IntSupplier; +import java.util.function.Supplier; public class CompositeRenderer { private final RenderTargets renderTargets; @@ -143,7 +134,7 @@ public CompositeRenderer(PackDirectives packDirectives, ProgramSource[] sources, this.passes = passes.build(); this.flippedAtLeastOnceFinal = flippedAtLeastOnce.build(); - GlStateManager._glBindFramebuffer(GL30C.GL_READ_FRAMEBUFFER, 0); + OpenGlHelper.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, 0); } public ImmutableSet getFlippedAtLeastOnceFinal() { @@ -206,8 +197,8 @@ protected void destroy() { } public void renderAll() { - RenderSystem.disableBlend(); - RenderSystem.disableAlphaTest(); + GlStateManager.disableBlend(); + GlStateManager.disableAlpha(); FullScreenQuadRenderer.INSTANCE.begin(); @@ -216,8 +207,8 @@ public void renderAll() { for (ComputeProgram computeProgram : renderPass.computes) { if (computeProgram != null) { ranCompute = true; - com.mojang.blaze3d.pipeline.RenderTarget main = Minecraft.getInstance().getMainRenderTarget(); - computeProgram.dispatch(main.width, main.height); + Framebuffer main = Minecraft.getMinecraft().getFramebuffer(); + computeProgram.dispatch(main.framebufferWidth, main.framebufferHeight); } } @@ -232,7 +223,7 @@ public void renderAll() { } if (!renderPass.mipmappedBuffers.isEmpty()) { - RenderSystem.activeTexture(GL15C.GL_TEXTURE0); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0); for (int index : renderPass.mipmappedBuffers) { setupMipmapping(CompositeRenderer.this.renderTargets.get(index), renderPass.stageReadsFromAlt.contains(index)); @@ -241,7 +232,7 @@ public void renderAll() { float scaledWidth = renderPass.viewWidth * renderPass.viewportScale; float scaledHeight = renderPass.viewHeight * renderPass.viewportScale; - RenderSystem.viewport(0, 0, (int) scaledWidth, (int) scaledHeight); + GlStateManager.viewport(0, 0, (int) scaledWidth, (int) scaledHeight); renderPass.framebuffer.bind(); renderPass.program.use(); @@ -253,20 +244,20 @@ public void renderAll() { // Make sure to reset the viewport to how it was before... Otherwise weird issues could occur. // Also bind the "main" framebuffer if it isn't already bound. - Minecraft.getInstance().getMainRenderTarget().bindWrite(true); + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true); ProgramUniforms.clearActiveUniforms(); ProgramSamplers.clearActiveSamplers(); - GlStateManager._glUseProgram(0); + OpenGlHelper.glUseProgram(0); // NB: Unbinding all of these textures is necessary for proper shaderpack reloading. for (int i = 0; i < SamplerLimits.get().getMaxTextureUnits(); i++) { // Unbind all textures that we may have used. // NB: This is necessary for shader pack reloading to work propely - RenderSystem.activeTexture(GL15C.GL_TEXTURE0 + i); - RenderSystem.bindTexture(0); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0 + i); + GlStateManager.bindTexture(0); } - RenderSystem.activeTexture(GL15C.GL_TEXTURE0); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0); } private static void setupMipmapping(net.coderbot.iris.rendertarget.RenderTarget target, boolean readFromAlt) { @@ -283,14 +274,14 @@ private static void setupMipmapping(net.coderbot.iris.rendertarget.RenderTarget // // Also note that this only applies to one of the two buffers in a render target buffer pair - making it // unlikely that this issue occurs in practice with most shader packs. - IrisRenderSystem.generateMipmaps(texture, GL20C.GL_TEXTURE_2D); + IrisRenderSystem.generateMipmaps(texture, GL11.GL_TEXTURE_2D); - int filter = GL20C.GL_LINEAR_MIPMAP_LINEAR; + int filter = GL11.GL_LINEAR_MIPMAP_LINEAR; if (target.getInternalFormat().getPixelFormat().isInteger()) { - filter = GL20C.GL_NEAREST_MIPMAP_NEAREST; + filter = GL11.GL_NEAREST_MIPMAP_NEAREST; } - IrisRenderSystem.texParameteri(texture, GL20C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_MIN_FILTER, filter); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter); } // TODO: Don't just copy this from DeferredWorldRenderingPipeline diff --git a/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java b/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java index d1d82e2b07..af4d74895d 100644 --- a/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java +++ b/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java @@ -1,30 +1,12 @@ package net.coderbot.iris.postprocess; -import java.util.Map; -import java.util.Objects; -import java.util.function.IntSupplier; -import java.util.function.Supplier; - -import org.jetbrains.annotations.Nullable; -import org.lwjgl.opengl.GL11C; -import org.lwjgl.opengl.GL15C; -import org.lwjgl.opengl.GL20C; -import org.lwjgl.opengl.GL30C; - import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; - import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.framebuffer.GlFramebuffer; -import net.coderbot.iris.gl.program.ComputeProgram; -import net.coderbot.iris.gl.program.Program; -import net.coderbot.iris.gl.program.ProgramBuilder; -import net.coderbot.iris.gl.program.ProgramSamplers; -import net.coderbot.iris.gl.program.ProgramUniforms; +import net.coderbot.iris.gl.program.*; import net.coderbot.iris.gl.sampler.SamplerLimits; import net.coderbot.iris.pipeline.PatchedShaderPrinter; import net.coderbot.iris.pipeline.transform.PatchShaderType; @@ -34,15 +16,23 @@ import net.coderbot.iris.rendertarget.RenderTargets; import net.coderbot.iris.samplers.IrisImages; import net.coderbot.iris.samplers.IrisSamplers; -import net.coderbot.iris.shaderpack.ComputeSource; -import net.coderbot.iris.shaderpack.PackRenderTargetDirectives; -import net.coderbot.iris.shaderpack.ProgramDirectives; -import net.coderbot.iris.shaderpack.ProgramSet; -import net.coderbot.iris.shaderpack.ProgramSource; +import net.coderbot.iris.shaderpack.*; import net.coderbot.iris.shadows.ShadowRenderTargets; import net.coderbot.iris.uniforms.CommonUniforms; import net.coderbot.iris.uniforms.FrameUpdateNotifier; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.shader.Framebuffer; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; +import org.lwjgl.opengl.GL30; + +import javax.annotation.Nullable; +import java.util.Map; +import java.util.Objects; +import java.util.function.IntSupplier; +import java.util.function.Supplier; public class FinalPassRenderer { private final RenderTargets renderTargets; @@ -96,8 +86,8 @@ public FinalPassRenderer(ProgramSet pack, RenderTargets renderTargets, IntSuppli // passes that write to framebuffers). this.baseline = renderTargets.createGbufferFramebuffer(flippedBuffers, new int[] {0}); this.colorHolder = new GlFramebuffer(); - this.lastColorTextureId = Minecraft.getInstance().getMainRenderTarget().getColorTextureId(); - this.lastColorTextureVersion = ((Blaze3dRenderTargetExt) Minecraft.getInstance().getMainRenderTarget()).iris$getColorBufferVersion(); + this.lastColorTextureId = Minecraft.getMinecraft().getFramebuffer().framebufferTexture; + this.lastColorTextureVersion = ((Blaze3dRenderTargetExt) Minecraft.getMinecraft().getFramebuffer()).iris$getColorBufferVersion(); this.colorHolder.addColorAttachment(0, lastColorTextureId); // TODO: We don't actually fully swap the content, we merely copy it from alt to main @@ -127,7 +117,7 @@ public FinalPassRenderer(ProgramSet pack, RenderTargets renderTargets, IntSuppli this.swapPasses = swapPasses.build(); - GlStateManager._glBindFramebuffer(GL30C.GL_READ_FRAMEBUFFER, 0); + OpenGlHelper.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, 0); } private static final class Pass { @@ -150,13 +140,13 @@ private static final class SwapPass { } public void renderFinalPass() { - RenderSystem.disableBlend(); - RenderSystem.disableAlphaTest(); - RenderSystem.depthMask(false); + GlStateManager.disableBlend(); + GlStateManager.disableAlpha(); + GlStateManager.depthMask(false); - final com.mojang.blaze3d.pipeline.RenderTarget main = Minecraft.getInstance().getMainRenderTarget(); - final int baseWidth = main.width; - final int baseHeight = main.height; + final Framebuffer main = Minecraft.getMinecraft().getFramebuffer(); + final int baseWidth = main.framebufferWidth; + final int baseHeight = main.framebufferHeight; // Note that since DeferredWorldRenderingPipeline uses the depth texture of the main Minecraft framebuffer, // we'll be writing to that depth buffer directly automatically and won't need to futz around with copying @@ -171,9 +161,9 @@ public void renderFinalPass() { // // This is not a concern for depthtex1 / depthtex2 since the copy call extracts the depth values, and the // shader pack only ever uses them to read the depth values. - if (((Blaze3dRenderTargetExt) main).iris$getColorBufferVersion() != lastColorTextureVersion || main.getColorTextureId() != lastColorTextureId) { + if (((Blaze3dRenderTargetExt) main).iris$getColorBufferVersion() != lastColorTextureVersion || main.framebufferTexture != lastColorTextureId) { lastColorTextureVersion = ((Blaze3dRenderTargetExt) main).iris$getColorBufferVersion(); - this.lastColorTextureId = main.getColorTextureId(); + this.lastColorTextureId = main.framebufferTexture; colorHolder.addColorAttachment(0, lastColorTextureId); } @@ -194,7 +184,7 @@ public void renderFinalPass() { IrisRenderSystem.memoryBarrier(40); if (!finalPass.mipmappedBuffers.isEmpty()) { - RenderSystem.activeTexture(GL15C.GL_TEXTURE0); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0); for (int index : finalPass.mipmappedBuffers) { setupMipmapping(renderTargets.get(index), finalPass.stageReadsFromAlt.contains(index)); @@ -218,10 +208,10 @@ public void renderFinalPass() { // https://stackoverflow.com/a/23994979/18166885 this.baseline.bindAsReadBuffer(); - IrisRenderSystem.copyTexSubImage2D(main.getColorTextureId(), GL11C.GL_TEXTURE_2D, 0, 0, 0, 0, 0, baseWidth, baseHeight); + IrisRenderSystem.copyTexSubImage2D(main.framebufferTexture, GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, baseWidth, baseHeight); } - RenderSystem.activeTexture(GL15C.GL_TEXTURE0); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0); for (int i = 0; i < renderTargets.getRenderTargetCount(); i++) { // Reset mipmapping states at the end of the frame. @@ -239,25 +229,25 @@ public void renderFinalPass() { // Also note that RenderTargets already calls readBuffer(0) for us. swapPass.from.bind(); - RenderSystem.bindTexture(swapPass.targetTexture); - GlStateManager._glCopyTexSubImage2D(GL20C.GL_TEXTURE_2D, 0, 0, 0, 0, 0, swapPass.width, swapPass.height); + GlStateManager.bindTexture(swapPass.targetTexture); + GlStateManager.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, swapPass.width, swapPass.height); } // Make sure to reset the viewport to how it was before... Otherwise weird issues could occur. // Also bind the "main" framebuffer if it isn't already bound. - main.bindWrite(true); + main.bindFramebuffer(true); ProgramUniforms.clearActiveUniforms(); ProgramSamplers.clearActiveSamplers(); - GlStateManager._glUseProgram(0); + OpenGlHelper.glUseProgram(0); for (int i = 0; i < SamplerLimits.get().getMaxTextureUnits(); i++) { // Unbind all textures that we may have used. // NB: This is necessary for shader pack reloading to work properly - RenderSystem.activeTexture(GL15C.GL_TEXTURE0 + i); - RenderSystem.bindTexture(0); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0 + i); + GlStateManager.bindTexture(0); } - RenderSystem.activeTexture(GL15C.GL_TEXTURE0); + GlStateManager.setActiveTexture(GL13.GL_TEXTURE0); } public void recalculateSwapPassSize() { @@ -285,28 +275,28 @@ private static void setupMipmapping(RenderTarget target, boolean readFromAlt) { // // Also note that this only applies to one of the two buffers in a render target buffer pair - making it // unlikely that this issue occurs in practice with most shader packs. - IrisRenderSystem.generateMipmaps(texture, GL20C.GL_TEXTURE_2D); + IrisRenderSystem.generateMipmaps(texture, GL11.GL_TEXTURE_2D); - int filter = GL20C.GL_LINEAR_MIPMAP_LINEAR; + int filter = GL11.GL_LINEAR_MIPMAP_LINEAR; if (target.getInternalFormat().getPixelFormat().isInteger()) { - filter = GL20C.GL_NEAREST_MIPMAP_NEAREST; + filter = GL11.GL_NEAREST_MIPMAP_NEAREST; } - IrisRenderSystem.texParameteri(texture, GL20C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_MIN_FILTER, filter); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter); } private static void resetRenderTarget(RenderTarget target) { // Resets the sampling mode of the given render target and then unbinds it to prevent accidental sampling of it // elsewhere. - int filter = GL20C.GL_LINEAR; + int filter = GL11.GL_LINEAR; if (target.getInternalFormat().getPixelFormat().isInteger()) { - filter = GL20C.GL_NEAREST; + filter = GL11.GL_NEAREST; } - IrisRenderSystem.texParameteri(target.getMainTexture(), GL20C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_MIN_FILTER, filter); - IrisRenderSystem.texParameteri(target.getAltTexture(), GL20C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_MIN_FILTER, filter); + IrisRenderSystem.texParameteri(target.getMainTexture(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter); + IrisRenderSystem.texParameteri(target.getAltTexture(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter); - RenderSystem.bindTexture(0); + GlStateManager.bindTexture(0); } // TODO: Don't just copy this from DeferredWorldRenderingPipeline diff --git a/src/main/java/net/coderbot/iris/postprocess/FullScreenQuadRenderer.java b/src/main/java/net/coderbot/iris/postprocess/FullScreenQuadRenderer.java index e1d4917b96..7d85619f42 100644 --- a/src/main/java/net/coderbot/iris/postprocess/FullScreenQuadRenderer.java +++ b/src/main/java/net/coderbot/iris/postprocess/FullScreenQuadRenderer.java @@ -1,13 +1,12 @@ package net.coderbot.iris.postprocess; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL20C; - -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; - +import nanolive.compat.VertexUtils; import net.coderbot.iris.gl.IrisRenderSystem; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL15; /** * Renders a full-screen textured quad to the screen. Used in composite / deferred rendering. @@ -31,40 +30,41 @@ public void render() { @SuppressWarnings("deprecation") public void begin() { - RenderSystem.disableDepthTest(); + GlStateManager.disableDepth(); - RenderSystem.matrixMode(GL11.GL_PROJECTION); - RenderSystem.pushMatrix(); - RenderSystem.loadIdentity(); + GlStateManager.matrixMode(GL11.GL_PROJECTION); + GlStateManager.pushMatrix(); + GlStateManager.loadIdentity(); // scale the quad from [0, 1] to [-1, 1] - RenderSystem.translatef(-1.0F, -1.0F, 0.0F); - RenderSystem.scalef(2.0F, 2.0F, 0.0F); + GlStateManager.translate(-1.0F, -1.0F, 0.0F); + GlStateManager.scale(2.0F, 2.0F, 0.0F); + + GlStateManager.matrixMode(GL11.GL_MODELVIEW); + GlStateManager.pushMatrix(); + GlStateManager.loadIdentity(); - RenderSystem.matrixMode(GL11.GL_MODELVIEW); - RenderSystem.pushMatrix(); - RenderSystem.loadIdentity(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); + OpenGlHelper.glBindBuffer(GL15.GL_ARRAY_BUFFER, quadBuffer); - GlStateManager._glBindBuffer(GL20C.GL_ARRAY_BUFFER, quadBuffer); - DefaultVertexFormat.POSITION_TEX.setupBufferState(0L); + VertexUtils.setupBufferState(DefaultVertexFormats.POSITION_TEX, 0L); } public void renderQuad() { - GlStateManager._drawArrays(GL20C.GL_TRIANGLE_STRIP, 0, 4); + GlStateManager.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 4); } @SuppressWarnings("deprecation") public static void end() { - DefaultVertexFormat.POSITION_TEX.clearBufferState(); - GlStateManager._glBindBuffer(GL20C.GL_ARRAY_BUFFER, 0); + VertexUtils.clearBufferState(DefaultVertexFormats.POSITION_TEX); + OpenGlHelper.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); - RenderSystem.enableDepthTest(); + GlStateManager.enableDepth(); - RenderSystem.matrixMode(GL11.GL_PROJECTION); - RenderSystem.popMatrix(); - RenderSystem.matrixMode(GL11.GL_MODELVIEW); - RenderSystem.popMatrix(); + GlStateManager.matrixMode(GL11.GL_PROJECTION); + GlStateManager.popMatrix(); + GlStateManager.matrixMode(GL11.GL_MODELVIEW); + GlStateManager.popMatrix(); } /** @@ -86,6 +86,6 @@ private static int createQuad() { 0.0F, 0.0F }; - return IrisRenderSystem.bufferStorage(GL20C.GL_ARRAY_BUFFER, vertices, GL20C.GL_STATIC_DRAW); + return IrisRenderSystem.bufferStorage(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW); } } diff --git a/src/main/java/net/coderbot/iris/rendertarget/DepthTexture.java b/src/main/java/net/coderbot/iris/rendertarget/DepthTexture.java index 8bfc4556c0..df543c479f 100644 --- a/src/main/java/net/coderbot/iris/rendertarget/DepthTexture.java +++ b/src/main/java/net/coderbot/iris/rendertarget/DepthTexture.java @@ -1,31 +1,29 @@ package net.coderbot.iris.rendertarget; -import org.lwjgl.opengl.GL11C; -import org.lwjgl.opengl.GL13C; - -import com.mojang.blaze3d.platform.GlStateManager; - import net.coderbot.iris.gl.GlResource; import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.texture.DepthBufferFormat; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; public class DepthTexture extends GlResource { public DepthTexture(int width, int height, DepthBufferFormat format) { - super(IrisRenderSystem.createTexture(GL11C.GL_TEXTURE_2D)); + super(IrisRenderSystem.createTexture(GL11.GL_TEXTURE_2D)); int texture = getGlId(); resize(width, height, format); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MIN_FILTER, GL11C.GL_NEAREST); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MAG_FILTER, GL11C.GL_NEAREST); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_S, GL13C.GL_CLAMP_TO_EDGE); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_T, GL13C.GL_CLAMP_TO_EDGE); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); - GlStateManager._bindTexture(0); + GlStateManager.bindTexture(0); } void resize(int width, int height, DepthBufferFormat format) { - IrisRenderSystem.texImage2D(getTextureId(), GL11C.GL_TEXTURE_2D, 0, format.getGlInternalFormat(), width, height, 0, + IrisRenderSystem.texImage2D(getTextureId(), GL11.GL_TEXTURE_2D, 0, format.getGlInternalFormat(), width, height, 0, format.getGlType(), format.getGlFormat(), null); } @@ -35,6 +33,6 @@ public int getTextureId() { @Override protected void destroyInternal() { - GlStateManager._deleteTexture(getGlId()); + GlStateManager.deleteTexture(getGlId()); } } diff --git a/src/main/java/net/coderbot/iris/rendertarget/NativeImageBackedCustomTexture.java b/src/main/java/net/coderbot/iris/rendertarget/NativeImageBackedCustomTexture.java index 51e801b708..2399bbd8b7 100644 --- a/src/main/java/net/coderbot/iris/rendertarget/NativeImageBackedCustomTexture.java +++ b/src/main/java/net/coderbot/iris/rendertarget/NativeImageBackedCustomTexture.java @@ -4,10 +4,9 @@ import java.nio.ByteBuffer; import java.util.Objects; -import org.lwjgl.opengl.GL11C; -import org.lwjgl.opengl.GL13C; - -import com.mojang.blaze3d.platform.NativeImage; +import nanolive.compat.NativeImage; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.shaderpack.texture.CustomTextureData; @@ -20,13 +19,13 @@ public NativeImageBackedCustomTexture(CustomTextureData.PngData textureData) thr // By default, images are unblurred and not clamped. if (textureData.getFilteringData().shouldBlur()) { - IrisRenderSystem.texParameteri(getId(), GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MIN_FILTER, GL11C.GL_LINEAR); - IrisRenderSystem.texParameteri(getId(), GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MAG_FILTER, GL11C.GL_LINEAR); + IrisRenderSystem.texParameteri(getGlTextureId(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); + IrisRenderSystem.texParameteri(getGlTextureId(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); } if (textureData.getFilteringData().shouldClamp()) { - IrisRenderSystem.texParameteri(getId(), GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_S, GL13C.GL_CLAMP_TO_EDGE); - IrisRenderSystem.texParameteri(getId(), GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_T, GL13C.GL_CLAMP_TO_EDGE); + IrisRenderSystem.texParameteri(getGlTextureId(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); + IrisRenderSystem.texParameteri(getGlTextureId(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); } } diff --git a/src/main/java/net/coderbot/iris/rendertarget/NativeImageBackedNoiseTexture.java b/src/main/java/net/coderbot/iris/rendertarget/NativeImageBackedNoiseTexture.java index 5ba7645a63..ae65928cc5 100644 --- a/src/main/java/net/coderbot/iris/rendertarget/NativeImageBackedNoiseTexture.java +++ b/src/main/java/net/coderbot/iris/rendertarget/NativeImageBackedNoiseTexture.java @@ -3,8 +3,7 @@ import java.util.Objects; import java.util.Random; -import com.mojang.blaze3d.platform.NativeImage; - +import nanolive.compat.NativeImage; import net.minecraft.client.renderer.texture.DynamicTexture; public class NativeImageBackedNoiseTexture extends DynamicTexture { diff --git a/src/main/java/net/coderbot/iris/rendertarget/NativeImageBackedSingleColorTexture.java b/src/main/java/net/coderbot/iris/rendertarget/NativeImageBackedSingleColorTexture.java index d4b0ba4559..fac28d07fa 100644 --- a/src/main/java/net/coderbot/iris/rendertarget/NativeImageBackedSingleColorTexture.java +++ b/src/main/java/net/coderbot/iris/rendertarget/NativeImageBackedSingleColorTexture.java @@ -1,7 +1,6 @@ package net.coderbot.iris.rendertarget; -import com.mojang.blaze3d.platform.NativeImage; - +import nanolive.compat.NativeImage; import net.minecraft.client.renderer.texture.DynamicTexture; public class NativeImageBackedSingleColorTexture extends DynamicTexture { diff --git a/src/main/java/net/coderbot/iris/rendertarget/NoiseTexture.java b/src/main/java/net/coderbot/iris/rendertarget/NoiseTexture.java index 635dac04a4..7db12f2136 100644 --- a/src/main/java/net/coderbot/iris/rendertarget/NoiseTexture.java +++ b/src/main/java/net/coderbot/iris/rendertarget/NoiseTexture.java @@ -3,7 +3,10 @@ import java.nio.ByteBuffer; import java.util.Random; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11C; +import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL13C; import org.lwjgl.opengl.GL20C; @@ -22,21 +25,21 @@ public class NoiseTexture extends GlResource { int height; public NoiseTexture(int width, int height) { - super(IrisRenderSystem.createTexture(GL11C.GL_TEXTURE_2D)); + super(IrisRenderSystem.createTexture(GL11.GL_TEXTURE_2D)); int texture = getGlId(); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MIN_FILTER, GL11C.GL_LINEAR); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MAG_FILTER, GL11C.GL_LINEAR); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_S, GL13C.GL_REPEAT); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_T, GL13C.GL_REPEAT); - - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_MAX_LEVEL, 0); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_MIN_LOD, 0); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_MAX_LOD,0); - IrisRenderSystem.texParameterf(texture, GL11C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_LOD_BIAS, 0.0F); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); + + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 0); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MIN_LOD, 0); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD,0); + IrisRenderSystem.texParameterf(texture, GL11.GL_TEXTURE_2D, GL20C.GL_TEXTURE_LOD_BIAS, 0.0F); resize(texture, width, height); - GlStateManager._bindTexture(0); + GlStateManager.bindTexture(0); } void resize(int texture, int width, int height) { @@ -48,10 +51,10 @@ void resize(int texture, int width, int height) { TextureUploadHelper.resetTextureUploadState(); // Since we're using tightly-packed RGB data, we must use an alignment of 1 byte instead of the usual 4 bytes. - GlStateManager._pixelStore(GL20C.GL_UNPACK_ALIGNMENT, 1); - IrisRenderSystem.texImage2D(texture, GL11C.GL_TEXTURE_2D, 0, GL11C.GL_RGB, width, height, 0, GL11C.GL_RGB, GL11C.GL_UNSIGNED_BYTE, pixels); + GlStateManager.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); + IrisRenderSystem.texImage2D(texture, GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, width, height, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, pixels); - GlStateManager._bindTexture(0); + GlStateManager.bindTexture(0); } private ByteBuffer generateNoise() { @@ -73,6 +76,6 @@ public int getTextureId() { @Override protected void destroyInternal() { - GlStateManager._deleteTexture(getGlId()); + GlStateManager.deleteTexture(getGlId()); } } diff --git a/src/main/java/net/coderbot/iris/rendertarget/RenderTarget.java b/src/main/java/net/coderbot/iris/rendertarget/RenderTarget.java index 873dc8f579..f801f0de1d 100644 --- a/src/main/java/net/coderbot/iris/rendertarget/RenderTarget.java +++ b/src/main/java/net/coderbot/iris/rendertarget/RenderTarget.java @@ -2,7 +2,10 @@ import java.nio.ByteBuffer; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11C; +import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL13C; import com.mojang.blaze3d.platform.GlStateManager; @@ -48,20 +51,20 @@ public RenderTarget(Builder builder) { // Clean up after ourselves // This is strictly defensive to ensure that other buggy code doesn't tamper with our textures - GlStateManager._bindTexture(0); + GlStateManager.bindTexture(0); } private void setupTexture(int texture, int width, int height, boolean allowsLinear) { resizeTexture(texture, width, height); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MIN_FILTER, allowsLinear ? GL11C.GL_LINEAR : GL11C.GL_NEAREST); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MAG_FILTER, allowsLinear ? GL11C.GL_LINEAR : GL11C.GL_NEAREST); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_S, GL13C.GL_CLAMP_TO_EDGE); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_T, GL13C.GL_CLAMP_TO_EDGE); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, allowsLinear ? GL11.GL_LINEAR : GL11.GL_NEAREST); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, allowsLinear ? GL11.GL_LINEAR : GL11.GL_NEAREST); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); } private void resizeTexture(int texture, int width, int height) { - IrisRenderSystem.texImage2D(texture, GL11C.GL_TEXTURE_2D, 0, internalFormat.getGlFormat(), width, height, 0, format.getGlFormat(), type.getGlFormat(), NULL_BUFFER); + IrisRenderSystem.texImage2D(texture, GL11.GL_TEXTURE_2D, 0, internalFormat.getGlFormat(), width, height, 0, format.getGlFormat(), type.getGlFormat(), NULL_BUFFER); } void resize(Vector2i textureScaleOverride) { @@ -108,7 +111,8 @@ public void destroy() { requireValid(); isValid = false; - GlStateManager._deleteTextures(new int[]{mainTexture, altTexture}); + GlStateManager.deleteTexture(mainTexture); + GlStateManager.deleteTexture(altTexture); } private void requireValid() { diff --git a/src/main/java/net/coderbot/iris/rendertarget/RenderTargets.java b/src/main/java/net/coderbot/iris/rendertarget/RenderTargets.java index b019bb8711..81ddda599d 100644 --- a/src/main/java/net/coderbot/iris/rendertarget/RenderTargets.java +++ b/src/main/java/net/coderbot/iris/rendertarget/RenderTargets.java @@ -4,10 +4,10 @@ import java.util.List; import java.util.Map; -import org.lwjgl.opengl.GL20C; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL11; import com.google.common.collect.ImmutableSet; -import com.mojang.blaze3d.systems.RenderSystem; import net.coderbot.iris.gl.IrisRenderSystem; import net.coderbot.iris.gl.framebuffer.GlFramebuffer; @@ -175,9 +175,9 @@ public boolean resizeIfNeeded(int newDepthBufferVersion, int newDepthTextureId, public void copyPreTranslucentDepth() { if (translucentDepthDirty) { translucentDepthDirty = false; - RenderSystem.bindTexture(noTranslucents.getTextureId()); + GlStateManager.bindTexture(noTranslucents.getTextureId()); depthSourceFb.bindAsReadBuffer(); - IrisRenderSystem.copyTexImage2D(GL20C.GL_TEXTURE_2D, 0, currentDepthFormat.getGlInternalFormat(), 0, 0, cachedWidth, cachedHeight, 0); + IrisRenderSystem.copyTexImage2D(GL11.GL_TEXTURE_2D, 0, currentDepthFormat.getGlInternalFormat(), 0, 0, cachedWidth, cachedHeight, 0); } else { copyStrategy.copy(depthSourceFb, getDepthTexture(), noTranslucentsDestFb, noTranslucents.getTextureId(), getCurrentWidth(), getCurrentHeight()); @@ -187,9 +187,9 @@ public void copyPreTranslucentDepth() { public void copyPreHandDepth() { if (handDepthDirty) { handDepthDirty = false; - RenderSystem.bindTexture(noHand.getTextureId()); + GlStateManager.bindTexture(noHand.getTextureId()); depthSourceFb.bindAsReadBuffer(); - IrisRenderSystem.copyTexImage2D(GL20C.GL_TEXTURE_2D, 0, currentDepthFormat.getGlInternalFormat(), 0, 0, cachedWidth, cachedHeight, 0); + IrisRenderSystem.copyTexImage2D(GL11.GL_TEXTURE_2D, 0, currentDepthFormat.getGlInternalFormat(), 0, 0, cachedWidth, cachedHeight, 0); } else { copyStrategy.copy(depthSourceFb, getDepthTexture(), noHandDestFb, noHand.getTextureId(), getCurrentWidth(), getCurrentHeight()); diff --git a/src/main/java/net/coderbot/iris/rendertarget/SingleColorTexture.java b/src/main/java/net/coderbot/iris/rendertarget/SingleColorTexture.java index e9469c7712..164586d089 100644 --- a/src/main/java/net/coderbot/iris/rendertarget/SingleColorTexture.java +++ b/src/main/java/net/coderbot/iris/rendertarget/SingleColorTexture.java @@ -2,11 +2,9 @@ import java.nio.ByteBuffer; +import net.minecraft.client.renderer.GlStateManager; import org.lwjgl.BufferUtils; -import org.lwjgl.opengl.GL11C; -import org.lwjgl.opengl.GL13C; - -import com.mojang.blaze3d.platform.GlStateManager; +import org.lwjgl.opengl.GL11; import net.coderbot.iris.gl.GlResource; import net.coderbot.iris.gl.IrisRenderSystem; @@ -14,7 +12,7 @@ public class SingleColorTexture extends GlResource { public SingleColorTexture(int red, int green, int blue, int alpha) { - super(IrisRenderSystem.createTexture(GL11C.GL_TEXTURE_2D)); + super(IrisRenderSystem.createTexture(GL11.GL_TEXTURE_2D)); ByteBuffer pixel = BufferUtils.createByteBuffer(4); pixel.put((byte) red); pixel.put((byte) green); @@ -24,13 +22,13 @@ public SingleColorTexture(int red, int green, int blue, int alpha) { int texture = getGlId(); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MIN_FILTER, GL11C.GL_LINEAR); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MAG_FILTER, GL11C.GL_LINEAR); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_S, GL13C.GL_REPEAT); - IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_T, GL13C.GL_REPEAT); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); + IrisRenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); TextureUploadHelper.resetTextureUploadState(); - IrisRenderSystem.texImage2D(texture, GL11C.GL_TEXTURE_2D, 0, GL11C.GL_RGBA, 1, 1, 0, GL11C.GL_RGBA, GL11C.GL_UNSIGNED_BYTE, pixel); + IrisRenderSystem.texImage2D(texture, GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, 1, 1, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, pixel); } public int getTextureId() { @@ -39,6 +37,6 @@ public int getTextureId() { @Override protected void destroyInternal() { - GlStateManager._deleteTexture(getGlId()); + GlStateManager.deleteTexture(getGlId()); } } diff --git a/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java b/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java index 73953d7e3a..9093b58900 100644 --- a/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java +++ b/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java @@ -130,20 +130,20 @@ public static void addLevelSamplers(SamplerHolder samplers, WorldRenderingPipeli samplers.addExternalSampler(ALBEDO_TEXTURE_UNIT, "tex", "texture", "gtexture"); } else { // TODO: Rebind unbound sampler IDs instead of hardcoding a list... - samplers.addDynamicSampler(whitePixel::getId, "tex", "texture", "gtexture", + samplers.addDynamicSampler(whitePixel::getGlTextureId, "tex", "texture", "gtexture", "gcolor", "colortex0"); } if (availability.lightmap) { samplers.addExternalSampler(LIGHTMAP_TEXTURE_UNIT, "lightmap"); } else { - samplers.addDynamicSampler(whitePixel::getId, "lightmap"); + samplers.addDynamicSampler(whitePixel::getGlTextureId, "lightmap"); } if (availability.overlay) { samplers.addExternalSampler(OVERLAY_TEXTURE_UNIT, "iris_overlay"); } else { - samplers.addDynamicSampler(whitePixel::getId, "iris_overlay"); + samplers.addDynamicSampler(whitePixel::getGlTextureId, "iris_overlay"); } samplers.addDynamicSampler(pipeline::getCurrentNormalTexture, StateUpdateNotifiers.normalTextureChangeNotifier, "normals"); diff --git a/src/main/java/net/coderbot/iris/shaderpack/ProgramDirectives.java b/src/main/java/net/coderbot/iris/shaderpack/ProgramDirectives.java index 27ff9383b3..f41205ce77 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ProgramDirectives.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ProgramDirectives.java @@ -7,8 +7,6 @@ import java.util.Optional; import java.util.Set; -import org.jetbrains.annotations.Nullable; - import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -18,6 +16,8 @@ import net.coderbot.iris.gl.blending.BlendModeOverride; import net.coderbot.iris.gl.blending.BufferBlendInformation; +import javax.annotation.Nullable; + public class ProgramDirectives { private static final ImmutableList LEGACY_RENDER_TARGETS = PackRenderTargetDirectives.LEGACY_RENDER_TARGETS; diff --git a/src/main/java/net/coderbot/iris/shaderpack/ProgramFallbackResolver.java b/src/main/java/net/coderbot/iris/shaderpack/ProgramFallbackResolver.java index 3580076727..b45feddf86 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ProgramFallbackResolver.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ProgramFallbackResolver.java @@ -4,10 +4,10 @@ import java.util.Map; import java.util.Optional; -import org.jetbrains.annotations.Nullable; - import net.coderbot.iris.shaderpack.loading.ProgramId; +import javax.annotation.Nullable; + public class ProgramFallbackResolver { private final ProgramSet programs; private final Map cache; diff --git a/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java b/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java index e720287837..42833a1c72 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java @@ -16,7 +16,7 @@ import net.coderbot.iris.colorspace.ColorSpace; import net.coderbot.iris.shaderpack.materialmap.NamespacedId; import net.coderbot.iris.shaderpack.preprocessor.PropertiesPreprocessor; -import org.jetbrains.annotations.Nullable; +import net.minecraft.util.text.TextComponentTranslation; import com.google.common.collect.ImmutableList; import com.google.gson.Gson; @@ -45,7 +45,8 @@ import net.coderbot.iris.shaderpack.texture.TextureStage; import net.irisshaders.iris.api.v0.IrisApi; import net.minecraft.client.Minecraft; -import net.minecraft.network.chat.TranslatableComponent; + +import javax.annotation.Nullable; public class ShaderPack { private static final Gson GSON = new Gson(); @@ -97,7 +98,7 @@ public ShaderPack(Path root, Map changedConfigs, Iterable dimensionIdCreator = loadProperties(root, "dimension.properties", environmentDefines).map(dimensionProperties -> { - hasDimensionIds[0] = dimensionProperties.size() > 0; + hasDimensionIds[0] = !dimensionProperties.isEmpty(); dimensionMap = parseDimensionMap(dimensionProperties, "dimension.", "dimension.properties"); return parseDimensionIds(dimensionProperties, "dimension."); }).orElse(new ArrayList<>()); @@ -131,9 +132,7 @@ public ShaderPack(Path root, Map changedConfigs, Iterable { - Iris.logger.error("{}", error.toString()); - }); + graph.getFailures().forEach((path, error) -> Iris.logger.error("{}", error.toString())); throw new IOException("Failed to resolve some #include directives, see previous messages for details"); } @@ -153,8 +152,8 @@ public ShaderPack(Path root, Map changedConfigs, Iterable invalidFeatureFlags = invalidFlagList.stream().map(FeatureFlags::getHumanReadableName).collect(Collectors.toList()); if (!invalidFeatureFlags.isEmpty()) { - if (Minecraft.getInstance().screen instanceof ShaderPackScreen) { - Minecraft.getInstance().setScreen(new FeatureMissingErrorScreen(Minecraft.getInstance().screen, new TranslatableComponent("iris.unsupported.pack"), new TranslatableComponent("iris.unsupported.pack.description", FeatureFlags.getInvalidStatus(invalidFlagList), invalidFeatureFlags.stream() + if (Minecraft.getMinecraft().currentScreen instanceof ShaderPackScreen) { + Minecraft.getMinecraft().displayGuiScreen(new FeatureMissingErrorScreen(Minecraft.getMinecraft().currentScreen, new TextComponentTranslation("iris.unsupported.pack"), new TextComponentTranslation("iris.unsupported.pack.description", FeatureFlags.getInvalidStatus(invalidFlagList), invalidFeatureFlags.stream() .collect(Collectors.joining(", ", ": ", "."))))); } IrisApi.getInstance().getConfig().setShadersEnabledAndApply(false); diff --git a/src/main/java/net/coderbot/iris/shaderpack/StringPair.java b/src/main/java/net/coderbot/iris/shaderpack/StringPair.java index 84a61dbd89..046a0f3682 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/StringPair.java +++ b/src/main/java/net/coderbot/iris/shaderpack/StringPair.java @@ -2,7 +2,7 @@ import java.util.Objects; -import org.jetbrains.annotations.NotNull; +import javax.annotation.Nonnull; /** * An absurdly simple class for storing pairs of strings because Java lacks pair / tuple types. @@ -11,17 +11,17 @@ public class StringPair { private final String key; private final String value; - public StringPair(@NotNull String key, @NotNull String value) { + public StringPair(@Nonnull String key, @Nonnull String value) { this.key = Objects.requireNonNull(key); this.value = Objects.requireNonNull(value); } - @NotNull + @Nonnull public String getKey() { return key; } - @NotNull + @Nonnull public String getValue() { return value; } diff --git a/src/main/java/net/coderbot/iris/shaderpack/materialmap/BlockEntry.java b/src/main/java/net/coderbot/iris/shaderpack/materialmap/BlockEntry.java index e1e462d878..9e1b00df0b 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/materialmap/BlockEntry.java +++ b/src/main/java/net/coderbot/iris/shaderpack/materialmap/BlockEntry.java @@ -5,10 +5,10 @@ import java.util.Map; import java.util.Objects; -import org.jetbrains.annotations.NotNull; - import net.coderbot.iris.Iris; +import javax.annotation.Nonnull; + public class BlockEntry { private final NamespacedId id; private final Map propertyPredicates; @@ -23,8 +23,8 @@ public BlockEntry(NamespacedId id, Map propertyPredicates) { * * @param entry The string representation of the entry. Must not be empty. */ - @NotNull - public static BlockEntry parse(@NotNull String entry) { + @Nonnull + public static BlockEntry parse(@Nonnull String entry) { if (entry.isEmpty()) { throw new IllegalArgumentException("Called BlockEntry::parse with an empty string"); } diff --git a/src/main/java/net/coderbot/iris/shaderpack/parsing/ParsedString.java b/src/main/java/net/coderbot/iris/shaderpack/parsing/ParsedString.java index 222a54a516..5b54797884 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/parsing/ParsedString.java +++ b/src/main/java/net/coderbot/iris/shaderpack/parsing/ParsedString.java @@ -1,6 +1,6 @@ package net.coderbot.iris.shaderpack.parsing; -import org.jetbrains.annotations.Nullable; +import javax.annotation.Nullable; public class ParsedString { private String text; diff --git a/src/main/java/net/coderbot/iris/shadows/ShadowRenderTargets.java b/src/main/java/net/coderbot/iris/shadows/ShadowRenderTargets.java index 53f807ac1f..f936405eab 100644 --- a/src/main/java/net/coderbot/iris/shadows/ShadowRenderTargets.java +++ b/src/main/java/net/coderbot/iris/shadows/ShadowRenderTargets.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import java.util.List; -import org.lwjgl.opengl.GL30C; +import org.lwjgl.opengl.GL11; import com.google.common.collect.ImmutableSet; @@ -127,8 +127,8 @@ public void copyPreTranslucentDepth() { translucentDepthDirty = false; IrisRenderSystem.blitFramebuffer(depthSourceFb.getId(), noTranslucentsDestFb.getId(), 0, 0, resolution, resolution, 0, 0, resolution, resolution, - GL30C.GL_DEPTH_BUFFER_BIT, - GL30C.GL_NEAREST); + GL11.GL_DEPTH_BUFFER_BIT, + GL11.GL_NEAREST); } else { DepthCopyStrategy.fastest(false).copy(depthSourceFb, mainDepth.getTextureId(), noTranslucentsDestFb, noTranslucents.getTextureId(), resolution, resolution); diff --git a/src/main/java/net/coderbot/iris/shadows/frustum/BoxCuller.java b/src/main/java/net/coderbot/iris/shadows/frustum/BoxCuller.java index 494de192ec..685edd6f07 100644 --- a/src/main/java/net/coderbot/iris/shadows/frustum/BoxCuller.java +++ b/src/main/java/net/coderbot/iris/shadows/frustum/BoxCuller.java @@ -1,6 +1,6 @@ package net.coderbot.iris.shadows.frustum; -import net.minecraft.world.phys.AABB; +import net.minecraft.util.math.AxisAlignedBB; public class BoxCuller { private final double maxDistance; @@ -25,12 +25,12 @@ public void setPosition(double cameraX, double cameraY, double cameraZ) { this.maxAllowedZ = cameraZ + maxDistance; } - public boolean isCulled(AABB aabb) { + public boolean isCulled(AxisAlignedBB aabb) { return isCulled((float) aabb.minX, (float) aabb.minY, (float) aabb.minZ, (float) aabb.maxX, (float) aabb.maxY, (float) aabb.maxZ); } - public boolean isCulled(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) { + public boolean isCulled(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { if (maxX < this.minAllowedX || minX > this.maxAllowedX) { return true; } @@ -39,10 +39,6 @@ public boolean isCulled(float minX, float minY, float minZ, float maxX, float ma return true; } - if (maxZ < this.minAllowedZ || minZ > this.maxAllowedZ) { - return true; - } - - return false; - } + return maxZ < this.minAllowedZ || minZ > this.maxAllowedZ; + } } diff --git a/src/main/java/net/coderbot/iris/shadows/frustum/CullEverythingFrustum.java b/src/main/java/net/coderbot/iris/shadows/frustum/CullEverythingFrustum.java index 3a45bdbfea..4b479d432e 100644 --- a/src/main/java/net/coderbot/iris/shadows/frustum/CullEverythingFrustum.java +++ b/src/main/java/net/coderbot/iris/shadows/frustum/CullEverythingFrustum.java @@ -1,13 +1,10 @@ package net.coderbot.iris.shadows.frustum; -import com.mojang.math.Matrix4f; - import net.minecraft.client.renderer.culling.Frustum; -import net.minecraft.world.phys.AABB; public class CullEverythingFrustum extends Frustum { public CullEverythingFrustum() { - super(new Matrix4f(), new Matrix4f()); + super(null); } // for Sodium @@ -22,7 +19,7 @@ public boolean canDetermineInvisible(double minX, double minY, double minZ, doub } @Override - public boolean isVisible(AABB aabb) { + public boolean isBoxInFrustum(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { return false; } } diff --git a/src/main/java/net/coderbot/iris/shadows/frustum/advanced/AdvancedShadowCullingFrustum.java b/src/main/java/net/coderbot/iris/shadows/frustum/advanced/AdvancedShadowCullingFrustum.java index c9d3ea6f23..d168f04faf 100644 --- a/src/main/java/net/coderbot/iris/shadows/frustum/advanced/AdvancedShadowCullingFrustum.java +++ b/src/main/java/net/coderbot/iris/shadows/frustum/advanced/AdvancedShadowCullingFrustum.java @@ -6,7 +6,6 @@ import net.coderbot.iris.vendored.joml.Vector3f; import net.coderbot.iris.vendored.joml.Vector4f; import net.minecraft.client.renderer.culling.Frustum; -import net.minecraft.world.phys.AABB; /** * A Frustum implementation that derives a tightly-fitted shadow pass frustum based on the player's camera frustum and @@ -73,7 +72,7 @@ public class AdvancedShadowCullingFrustum extends Frustum { public AdvancedShadowCullingFrustum(Matrix4f playerView, Matrix4f playerProjection, Vector3f shadowLightVectorFromOrigin, BoxCuller boxCuller) { // We're overriding all of the methods, don't pass any matrices down. - super(new com.mojang.math.Matrix4f(), new com.mojang.math.Matrix4f()); + super(null); this.shadowLightVectorFromOrigin = shadowLightVectorFromOrigin; BaseClippingPlanes baseClippingPlanes = new BaseClippingPlanes(playerView, playerProjection); @@ -268,7 +267,7 @@ private void addEdgePlane(Vector4f backPlane4, Vector4f frontPlane4) { // Note: These functions are copied & modified from the vanilla Frustum class. @Override - public void prepare(double cameraX, double cameraY, double cameraZ) { + public void setPosition(double cameraX, double cameraY, double cameraZ) { if (this.boxCuller != null) { boxCuller.setPosition(cameraX, cameraY, cameraZ); } @@ -279,12 +278,12 @@ public void prepare(double cameraX, double cameraY, double cameraZ) { } @Override - public boolean isVisible(AABB aabb) { - if (boxCuller != null && boxCuller.isCulled(aabb)) { + public boolean isBoxInFrustum(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { + if (boxCuller != null && boxCuller.isCulled(minX, minY, minZ, maxX, maxY, maxZ)) { return false; } - return this.isVisible(aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ); + return this.isVisible(minX, minY, minZ, maxX, maxY, maxZ); } // For Sodium diff --git a/src/main/java/net/coderbot/iris/shadows/frustum/fallback/BoxCullingFrustum.java b/src/main/java/net/coderbot/iris/shadows/frustum/fallback/BoxCullingFrustum.java index 15116692a6..77d7f37353 100644 --- a/src/main/java/net/coderbot/iris/shadows/frustum/fallback/BoxCullingFrustum.java +++ b/src/main/java/net/coderbot/iris/shadows/frustum/fallback/BoxCullingFrustum.java @@ -1,22 +1,19 @@ package net.coderbot.iris.shadows.frustum.fallback; -import com.mojang.math.Matrix4f; - import net.coderbot.iris.shadows.frustum.BoxCuller; import net.minecraft.client.renderer.culling.Frustum; -import net.minecraft.world.phys.AABB; public class BoxCullingFrustum extends Frustum { private final BoxCuller boxCuller; public BoxCullingFrustum(BoxCuller boxCuller) { - super(new Matrix4f(), new Matrix4f()); + super(null); this.boxCuller = boxCuller; } @Override - public void prepare(double cameraX, double cameraY, double cameraZ) { + public void setPosition(double cameraX, double cameraY, double cameraZ) { boxCuller.setPosition(cameraX, cameraY, cameraZ); } @@ -35,7 +32,7 @@ public boolean canDetermineInvisible(double minX, double minY, double minZ, doub } @Override - public boolean isVisible(AABB aabb) { - return !boxCuller.isCulled(aabb); + public boolean isBoxInFrustum(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { + return !boxCuller.isCulled(minX, minY, minZ, maxX, maxY, maxZ); } } diff --git a/src/main/java/net/coderbot/iris/shadows/frustum/fallback/NonCullingFrustum.java b/src/main/java/net/coderbot/iris/shadows/frustum/fallback/NonCullingFrustum.java index 161464510d..8d32fcade4 100644 --- a/src/main/java/net/coderbot/iris/shadows/frustum/fallback/NonCullingFrustum.java +++ b/src/main/java/net/coderbot/iris/shadows/frustum/fallback/NonCullingFrustum.java @@ -1,13 +1,10 @@ package net.coderbot.iris.shadows.frustum.fallback; -import com.mojang.math.Matrix4f; - import net.minecraft.client.renderer.culling.Frustum; -import net.minecraft.world.phys.AABB; public class NonCullingFrustum extends Frustum { public NonCullingFrustum() { - super(new Matrix4f(), new Matrix4f()); + super(null); } // for Sodium @@ -24,7 +21,7 @@ public boolean canDetermineInvisible(double minX, double minY, double minZ, doub } @Override - public boolean isVisible(AABB aabb) { + public boolean isBoxInFrustum(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { return true; } } diff --git a/src/main/java/net/coderbot/iris/texture/TextureInfoCache.java b/src/main/java/net/coderbot/iris/texture/TextureInfoCache.java index fb9394ba9d..d46b04e7cb 100644 --- a/src/main/java/net/coderbot/iris/texture/TextureInfoCache.java +++ b/src/main/java/net/coderbot/iris/texture/TextureInfoCache.java @@ -1,14 +1,13 @@ package net.coderbot.iris.texture; -import java.nio.IntBuffer; - -import org.jetbrains.annotations.Nullable; -import org.lwjgl.opengl.GL20C; - -import com.mojang.blaze3d.platform.GlStateManager; - import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import net.coderbot.iris.mixin.GlStateManagerAccessor; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL11; + +import javax.annotation.Nullable; +import java.nio.IntBuffer; public class TextureInfoCache { public static final TextureInfoCache INSTANCE = new TextureInfoCache(); @@ -30,7 +29,7 @@ public TextureInfo getInfo(int id) { public void onTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, @Nullable IntBuffer pixels) { if (level == 0) { - int id = GlStateManager.getActiveTextureName(); + int id = GlStateManagerAccessor.getTEXTURES()[GlStateManagerAccessor.getActiveTexture()].textureName; TextureInfo info = getInfo(id); info.internalFormat = internalformat; info.width = width; @@ -58,35 +57,35 @@ public int getId() { public int getInternalFormat() { if (internalFormat == -1) { - internalFormat = fetchLevelParameter(GL20C.GL_TEXTURE_INTERNAL_FORMAT); + internalFormat = fetchLevelParameter(GL11.GL_TEXTURE_INTERNAL_FORMAT); } return internalFormat; } public int getWidth() { if (width == -1) { - width = fetchLevelParameter(GL20C.GL_TEXTURE_WIDTH); + width = fetchLevelParameter(GL11.GL_TEXTURE_WIDTH); } return width; } public int getHeight() { if (height == -1) { - height = fetchLevelParameter(GL20C.GL_TEXTURE_HEIGHT); + height = fetchLevelParameter(GL11.GL_TEXTURE_HEIGHT); } return height; } private int fetchLevelParameter(int pname) { // Keep track of what texture was bound before - int previousTextureBinding = GlStateManager._getInteger(GL20C.GL_TEXTURE_BINDING_2D); + int previousTextureBinding = GlStateManager.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); // Bind this texture and grab the parameter from it. - GlStateManager._bindTexture(id); - int parameter = GlStateManager._getTexLevelParameter(GL20C.GL_TEXTURE_2D, 0, pname); + GlStateManager.bindTexture(id); + int parameter = GlStateManager.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, pname); // Make sure to re-bind the previous texture to avoid issues. - GlStateManager._bindTexture(previousTextureBinding); + GlStateManager.bindTexture(previousTextureBinding); return parameter; } diff --git a/src/main/java/net/coderbot/iris/texture/TextureTracker.java b/src/main/java/net/coderbot/iris/texture/TextureTracker.java index eed57540b3..d9fb7b26dd 100644 --- a/src/main/java/net/coderbot/iris/texture/TextureTracker.java +++ b/src/main/java/net/coderbot/iris/texture/TextureTracker.java @@ -1,7 +1,5 @@ package net.coderbot.iris.texture; -import org.jetbrains.annotations.Nullable; - import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import net.coderbot.iris.Iris; @@ -11,6 +9,8 @@ import net.coderbot.iris.pipeline.WorldRenderingPipeline; import net.minecraft.client.renderer.texture.AbstractTexture; +import javax.annotation.Nullable; + public class TextureTracker { public static final TextureTracker INSTANCE = new TextureTracker(); diff --git a/src/main/java/net/coderbot/iris/texture/format/LabPBRTextureFormat.java b/src/main/java/net/coderbot/iris/texture/format/LabPBRTextureFormat.java index 2155cb4b23..30dad26580 100644 --- a/src/main/java/net/coderbot/iris/texture/format/LabPBRTextureFormat.java +++ b/src/main/java/net/coderbot/iris/texture/format/LabPBRTextureFormat.java @@ -2,14 +2,14 @@ import java.util.Objects; -import org.jetbrains.annotations.Nullable; - import net.coderbot.iris.texture.mipmap.ChannelMipmapGenerator; import net.coderbot.iris.texture.mipmap.CustomMipmapGenerator; import net.coderbot.iris.texture.mipmap.DiscreteBlendFunction; import net.coderbot.iris.texture.mipmap.LinearBlendFunction; import net.coderbot.iris.texture.pbr.PBRType; +import javax.annotation.Nullable; + public class LabPBRTextureFormat implements TextureFormat { public static final ChannelMipmapGenerator SPECULAR_MIPMAP_GENERATOR = new ChannelMipmapGenerator( LinearBlendFunction.INSTANCE, diff --git a/src/main/java/net/coderbot/iris/texture/format/TextureFormat.java b/src/main/java/net/coderbot/iris/texture/format/TextureFormat.java index 778b6393ef..f3350e84eb 100644 --- a/src/main/java/net/coderbot/iris/texture/format/TextureFormat.java +++ b/src/main/java/net/coderbot/iris/texture/format/TextureFormat.java @@ -4,7 +4,6 @@ import java.util.List; import java.util.Locale; -import org.jetbrains.annotations.Nullable; import org.lwjgl.opengl.GL11; import net.coderbot.iris.gl.IrisRenderSystem; @@ -12,6 +11,8 @@ import net.coderbot.iris.texture.pbr.PBRType; import net.minecraft.client.renderer.texture.AbstractTexture; +import javax.annotation.Nullable; + public interface TextureFormat { String getName(); @@ -47,12 +48,12 @@ default List getDefines() { default void setupTextureParameters(PBRType pbrType, AbstractTexture texture) { if (!canInterpolateValues(pbrType)) { - int minFilter = IrisRenderSystem.getTexParameteri(texture.getId(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER); + int minFilter = IrisRenderSystem.getTexParameteri(texture.getGlTextureId(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER); // Non-mipped filters begin at 0x2600 whereas mipped filters begin at 0x2700, // so this bit mask can be used to check if the filter is mipped or not boolean mipmap = (minFilter & 1 << 8) == 1; - IrisRenderSystem.texParameteri(texture.getId(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, mipmap ? GL11.GL_NEAREST_MIPMAP_NEAREST : GL11.GL_NEAREST); - IrisRenderSystem.texParameteri(texture.getId(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + IrisRenderSystem.texParameteri(texture.getGlTextureId(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, mipmap ? GL11.GL_NEAREST_MIPMAP_NEAREST : GL11.GL_NEAREST); + IrisRenderSystem.texParameteri(texture.getGlTextureId(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); } } diff --git a/src/main/java/net/coderbot/iris/texture/format/TextureFormatLoader.java b/src/main/java/net/coderbot/iris/texture/format/TextureFormatLoader.java index 31e03a4ff9..805aefe3ec 100644 --- a/src/main/java/net/coderbot/iris/texture/format/TextureFormatLoader.java +++ b/src/main/java/net/coderbot/iris/texture/format/TextureFormatLoader.java @@ -1,17 +1,16 @@ package net.coderbot.iris.texture.format; +import net.coderbot.iris.Iris; +import net.minecraft.client.resources.IResource; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nullable; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Objects; import java.util.Properties; -import org.jetbrains.annotations.Nullable; - -import net.coderbot.iris.Iris; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.resources.Resource; -import net.minecraft.server.packs.resources.ResourceManager; - public class TextureFormatLoader { public static final ResourceLocation LOCATION = new ResourceLocation("optifine/texture.properties"); @@ -22,7 +21,7 @@ public static TextureFormat getFormat() { return format; } - public static void reload(ResourceManager resourceManager) { + public static void reload(IResourceManager resourceManager) { TextureFormat newFormat = loadFormat(resourceManager); boolean didFormatChange = !Objects.equals(format, newFormat); format = newFormat; @@ -32,8 +31,8 @@ public static void reload(ResourceManager resourceManager) { } @Nullable - private static TextureFormat loadFormat(ResourceManager resourceManager) { - try (Resource resource = resourceManager.getResource(LOCATION)) { + private static TextureFormat loadFormat(IResourceManager resourceManager) { + try (IResource resource = resourceManager.getResource(LOCATION)) { Properties properties = new Properties(); properties.load(resource.getInputStream()); String format = properties.getProperty("format"); diff --git a/src/main/java/net/coderbot/iris/texture/format/TextureFormatRegistry.java b/src/main/java/net/coderbot/iris/texture/format/TextureFormatRegistry.java index 9eea2744fd..933e340791 100644 --- a/src/main/java/net/coderbot/iris/texture/format/TextureFormatRegistry.java +++ b/src/main/java/net/coderbot/iris/texture/format/TextureFormatRegistry.java @@ -3,7 +3,7 @@ import java.util.HashMap; import java.util.Map; -import org.jetbrains.annotations.Nullable; +import javax.annotation.Nullable; public class TextureFormatRegistry { public static final TextureFormatRegistry INSTANCE = new TextureFormatRegistry(); diff --git a/src/main/java/net/coderbot/iris/texture/mipmap/AbstractMipmapGenerator.java b/src/main/java/net/coderbot/iris/texture/mipmap/AbstractMipmapGenerator.java index 1636e2a0ab..eb2a786ff0 100644 --- a/src/main/java/net/coderbot/iris/texture/mipmap/AbstractMipmapGenerator.java +++ b/src/main/java/net/coderbot/iris/texture/mipmap/AbstractMipmapGenerator.java @@ -1,6 +1,6 @@ package net.coderbot.iris.texture.mipmap; -import com.mojang.blaze3d.platform.NativeImage; +import nanolive.compat.NativeImage; public abstract class AbstractMipmapGenerator implements CustomMipmapGenerator { @Override @@ -16,9 +16,9 @@ public NativeImage[] generateMipLevels(NativeImage image, int mipLevel) { for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { mipmap.setPixelRGBA(x, y, blend( - prevMipmap.getPixelRGBA(x * 2 + 0, y * 2 + 0), - prevMipmap.getPixelRGBA(x * 2 + 1, y * 2 + 0), - prevMipmap.getPixelRGBA(x * 2 + 0, y * 2 + 1), + prevMipmap.getPixelRGBA(x * 2, y * 2), + prevMipmap.getPixelRGBA(x * 2 + 1, y * 2), + prevMipmap.getPixelRGBA(x * 2, y * 2 + 1), prevMipmap.getPixelRGBA(x * 2 + 1, y * 2 + 1) )); } diff --git a/src/main/java/net/coderbot/iris/texture/mipmap/ChannelMipmapGenerator.java b/src/main/java/net/coderbot/iris/texture/mipmap/ChannelMipmapGenerator.java index 0739bb19dd..3f693be113 100644 --- a/src/main/java/net/coderbot/iris/texture/mipmap/ChannelMipmapGenerator.java +++ b/src/main/java/net/coderbot/iris/texture/mipmap/ChannelMipmapGenerator.java @@ -1,6 +1,6 @@ package net.coderbot.iris.texture.mipmap; -import com.mojang.blaze3d.platform.NativeImage; +import nanolive.compat.NativeImage; public class ChannelMipmapGenerator extends AbstractMipmapGenerator { protected final BlendFunction redFunc; diff --git a/src/main/java/net/coderbot/iris/texture/mipmap/CustomMipmapGenerator.java b/src/main/java/net/coderbot/iris/texture/mipmap/CustomMipmapGenerator.java index cc9b97c309..2867a74f0d 100644 --- a/src/main/java/net/coderbot/iris/texture/mipmap/CustomMipmapGenerator.java +++ b/src/main/java/net/coderbot/iris/texture/mipmap/CustomMipmapGenerator.java @@ -1,11 +1,10 @@ package net.coderbot.iris.texture.mipmap; -import org.jetbrains.annotations.Nullable; - -import com.mojang.blaze3d.platform.NativeImage; - +import nanolive.compat.NativeImage; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import javax.annotation.Nullable; + public interface CustomMipmapGenerator { NativeImage[] generateMipLevels(NativeImage image, int mipLevel); diff --git a/src/main/java/net/coderbot/iris/texture/pbr/PBRAtlasHolder.java b/src/main/java/net/coderbot/iris/texture/pbr/PBRAtlasHolder.java index 49e781712a..4cf6356c59 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/PBRAtlasHolder.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/PBRAtlasHolder.java @@ -1,6 +1,6 @@ package net.coderbot.iris.texture.pbr; -import org.jetbrains.annotations.Nullable; +import javax.annotation.Nullable; public class PBRAtlasHolder { protected PBRAtlasTexture normalAtlas; diff --git a/src/main/java/net/coderbot/iris/texture/pbr/PBRAtlasTexture.java b/src/main/java/net/coderbot/iris/texture/pbr/PBRAtlasTexture.java index afe1fcff1a..87fac0c903 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/PBRAtlasTexture.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/PBRAtlasTexture.java @@ -1,35 +1,33 @@ package net.coderbot.iris.texture.pbr; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.jetbrains.annotations.Nullable; - -import com.mojang.blaze3d.platform.TextureUtil; - import net.coderbot.iris.mixin.texture.TextureAtlasSpriteAccessor; import net.coderbot.iris.texture.util.TextureExporter; import net.coderbot.iris.texture.util.TextureManipulationUtil; -import net.minecraft.CrashReport; -import net.minecraft.CrashReportCategory; -import net.minecraft.ReportedException; import net.minecraft.client.renderer.texture.AbstractTexture; -import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.resources.metadata.animation.AnimationMetadataSection; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.renderer.texture.TextureUtil; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.client.resources.data.AnimationMetadataSection; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.util.ReportedException; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nullable; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; public class PBRAtlasTexture extends AbstractTexture { - protected final TextureAtlas atlasTexture; + protected final TextureMap atlasTexture; protected final PBRType type; protected final ResourceLocation id; protected final Map sprites = new HashMap<>(); protected final Set animatedSprites = new HashSet<>(); - public PBRAtlasTexture(TextureAtlas atlasTexture, PBRType type) { + public PBRAtlasTexture(TextureMap atlasTexture, PBRType type) { this.atlasTexture = atlasTexture; this.type = type; id = type.appendToFileLocation(atlasTexture.location()); @@ -44,8 +42,8 @@ public ResourceLocation getAtlasId() { } public void addSprite(TextureAtlasSprite sprite) { - sprites.put(sprite.getName(), sprite); - if (sprite.isAnimation()) { + sprites.put(new ResourceLocation(sprite.getIconName()), sprite); + if (sprite.hasAnimationMetadata()) { animatedSprites.add(sprite); } } @@ -61,18 +59,18 @@ public void clear() { } public void upload(int atlasWidth, int atlasHeight, int mipLevel) { - int glId = getId(); - TextureUtil.prepareImage(glId, mipLevel, atlasWidth, atlasHeight); + int glId = getGlTextureId(); + TextureUtil.allocateTextureImpl(glId, mipLevel, atlasWidth, atlasHeight); TextureManipulationUtil.fillWithColor(glId, mipLevel, type.getDefaultValue()); for (TextureAtlasSprite sprite : sprites.values()) { try { uploadSprite(sprite); } catch (Throwable throwable) { - CrashReport crashReport = CrashReport.forThrowable(throwable, "Stitching texture atlas"); - CrashReportCategory crashReportCategory = crashReport.addCategory("Texture being stitched together"); - crashReportCategory.setDetail("Atlas path", id); - crashReportCategory.setDetail("Sprite", sprite); + CrashReport crashReport = CrashReport.makeCrashReport(throwable, "Stitching texture atlas"); + CrashReportCategory crashReportCategory = crashReport.makeCategory("Texture being stitched together"); + crashReportCategory.addCrashSection("Atlas path", id); + crashReportCategory.addCrashSection("Sprite", sprite); throw new ReportedException(crashReport); } } @@ -104,7 +102,7 @@ public boolean tryUpload(int atlasWidth, int atlasHeight, int mipLevel) { } protected void uploadSprite(TextureAtlasSprite sprite) { - if (sprite.isAnimation()) { + if (sprite.hasAnimationMetadata()) { TextureAtlasSpriteAccessor accessor = (TextureAtlasSpriteAccessor) sprite; AnimationMetadataSection metadata = accessor.getMetadata(); @@ -124,7 +122,7 @@ protected void uploadSprite(TextureAtlasSprite sprite) { public void cycleAnimationFrames() { bind(); for (TextureAtlasSprite sprite : animatedSprites) { - sprite.cycleFrames(); + sprite.updateAnimation(); } } @@ -144,6 +142,6 @@ public void close() { } @Override - public void load(ResourceManager manager) { + public void loadTexture(IResourceManager manager) { } } diff --git a/src/main/java/net/coderbot/iris/texture/pbr/PBRSpriteHolder.java b/src/main/java/net/coderbot/iris/texture/pbr/PBRSpriteHolder.java index 622e4190a4..898a9eda48 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/PBRSpriteHolder.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/PBRSpriteHolder.java @@ -1,9 +1,9 @@ package net.coderbot.iris.texture.pbr; -import org.jetbrains.annotations.Nullable; - import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import javax.annotation.Nullable; + public class PBRSpriteHolder { protected TextureAtlasSprite normalSprite; protected TextureAtlasSprite specularSprite; @@ -25,13 +25,4 @@ public void setNormalSprite(TextureAtlasSprite sprite) { public void setSpecularSprite(TextureAtlasSprite sprite) { specularSprite = sprite; } - - public void close() { - if (normalSprite != null) { - normalSprite.close(); - } - if (specularSprite != null) { - specularSprite.close(); - } - } } diff --git a/src/main/java/net/coderbot/iris/texture/pbr/PBRTextureHolder.java b/src/main/java/net/coderbot/iris/texture/pbr/PBRTextureHolder.java index c58ecf8c63..ec211e6657 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/PBRTextureHolder.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/PBRTextureHolder.java @@ -1,13 +1,13 @@ package net.coderbot.iris.texture.pbr; -import org.jetbrains.annotations.NotNull; - import net.minecraft.client.renderer.texture.AbstractTexture; +import javax.annotation.Nonnull; + public interface PBRTextureHolder { - @NotNull + @Nonnull AbstractTexture getNormalTexture(); - @NotNull + @Nonnull AbstractTexture getSpecularTexture(); } diff --git a/src/main/java/net/coderbot/iris/texture/pbr/PBRTextureManager.java b/src/main/java/net/coderbot/iris/texture/pbr/PBRTextureManager.java index 2f4e7f5919..73946a4dc0 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/PBRTextureManager.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/PBRTextureManager.java @@ -1,21 +1,21 @@ package net.coderbot.iris.texture.pbr; -import org.jetbrains.annotations.NotNull; - -import com.mojang.blaze3d.platform.GlStateManager; - import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import net.coderbot.iris.Iris; import net.coderbot.iris.gl.state.StateUpdateNotifiers; +import net.coderbot.iris.mixin.GlStateManagerAccessor; import net.coderbot.iris.rendertarget.NativeImageBackedSingleColorTexture; import net.coderbot.iris.texture.TextureTracker; import net.coderbot.iris.texture.pbr.loader.PBRTextureLoader; import net.coderbot.iris.texture.pbr.loader.PBRTextureLoader.PBRTextureConsumer; import net.coderbot.iris.texture.pbr.loader.PBRTextureLoaderRegistry; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.texture.AbstractTexture; +import javax.annotation.Nonnull; + public class PBRTextureManager { public static final PBRTextureManager INSTANCE = new PBRTextureManager(); @@ -38,12 +38,12 @@ public class PBRTextureManager { // Not PBRTextureHolderImpl to directly reference fields private final PBRTextureHolder defaultHolder = new PBRTextureHolder() { @Override - public @NotNull AbstractTexture getNormalTexture() { + public @Nonnull AbstractTexture getNormalTexture() { return defaultNormalTexture; } @Override - public @NotNull AbstractTexture getSpecularTexture() { + public @Nonnull AbstractTexture getSpecularTexture() { return defaultSpecularTexture; } }; @@ -80,15 +80,15 @@ private PBRTextureHolder loadHolder(int id) { Class clazz = texture.getClass(); PBRTextureLoader loader = PBRTextureLoaderRegistry.INSTANCE.getLoader(clazz); if (loader != null) { - int previousTextureBinding = GlStateManager.getActiveTextureName(); + int previousTextureBinding = GlStateManagerAccessor.getTEXTURES()[GlStateManagerAccessor.getActiveTexture()].textureName; consumer.clear(); try { - loader.load(texture, Minecraft.getInstance().getResourceManager(), consumer); + loader.load(texture, Minecraft.getMinecraft().getResourceManager(), consumer); return consumer.toHolder(); } catch (Exception e) { Iris.logger.debug("Failed to load PBR textures for texture " + id, e); } finally { - GlStateManager._bindTexture(previousTextureBinding); + GlStateManager.bindTexture(previousTextureBinding); } } } @@ -134,7 +134,7 @@ private static void closeTexture(AbstractTexture texture) { } catch (Exception e) { // } - texture.releaseId(); + texture.deleteGlTexture(); } public static void notifyPBRTexturesChanged() { @@ -153,13 +153,13 @@ private class PBRTextureConsumerImpl implements PBRTextureConsumer { private boolean changed; @Override - public void acceptNormalTexture(@NotNull AbstractTexture texture) { + public void acceptNormalTexture(@Nonnull AbstractTexture texture) { normalTexture = texture; changed = true; } @Override - public void acceptSpecularTexture(@NotNull AbstractTexture texture) { + public void acceptSpecularTexture(@Nonnull AbstractTexture texture) { specularTexture = texture; changed = true; } @@ -189,12 +189,12 @@ public PBRTextureHolderImpl(AbstractTexture normalTexture, AbstractTexture specu } @Override - public @NotNull AbstractTexture getNormalTexture() { + public @Nonnull AbstractTexture getNormalTexture() { return normalTexture; } @Override - public @NotNull AbstractTexture getSpecularTexture() { + public @Nonnull AbstractTexture getSpecularTexture() { return specularTexture; } } diff --git a/src/main/java/net/coderbot/iris/texture/pbr/PBRType.java b/src/main/java/net/coderbot/iris/texture/pbr/PBRType.java index ceef6f0709..89d0c07209 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/PBRType.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/PBRType.java @@ -1,9 +1,9 @@ package net.coderbot.iris.texture.pbr; +import net.minecraft.util.ResourceLocation; import org.apache.commons.io.FilenameUtils; -import org.jetbrains.annotations.Nullable; -import net.minecraft.resources.ResourceLocation; +import javax.annotation.Nullable; public enum PBRType { NORMAL("_n", 0x7F7FFFFF), diff --git a/src/main/java/net/coderbot/iris/texture/pbr/TextureAtlasExtension.java b/src/main/java/net/coderbot/iris/texture/pbr/TextureAtlasExtension.java index d8ce9fcbab..0ba755c6c3 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/TextureAtlasExtension.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/TextureAtlasExtension.java @@ -1,6 +1,6 @@ package net.coderbot.iris.texture.pbr; -import org.jetbrains.annotations.Nullable; +import javax.annotation.Nullable; public interface TextureAtlasExtension { @Nullable diff --git a/src/main/java/net/coderbot/iris/texture/pbr/TextureAtlasSpriteExtension.java b/src/main/java/net/coderbot/iris/texture/pbr/TextureAtlasSpriteExtension.java index 7a46ba5bcc..92d71a0d5e 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/TextureAtlasSpriteExtension.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/TextureAtlasSpriteExtension.java @@ -1,6 +1,6 @@ package net.coderbot.iris.texture.pbr; -import org.jetbrains.annotations.Nullable; +import javax.annotation.Nullable; public interface TextureAtlasSpriteExtension { @Nullable diff --git a/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java b/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java index 2fa54fc9b0..52275e4c39 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java @@ -3,9 +3,14 @@ import java.io.FileNotFoundException; import java.io.IOException; +import nanolive.compat.NativeImage; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.resources.IResource; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.client.resources.data.AnimationMetadataSection; +import net.minecraft.util.ResourceLocation; import org.jetbrains.annotations.Nullable; -import com.mojang.blaze3d.platform.NativeImage; import com.mojang.datafixers.util.Pair; import net.coderbot.iris.Iris; @@ -32,7 +37,9 @@ import net.minecraft.server.packs.resources.Resource; import net.minecraft.server.packs.resources.ResourceManager; -public class AtlasPBRLoader implements PBRTextureLoader { +import javax.annotation.Nullable; + +public class AtlasPBRLoader implements PBRTextureLoader { public static final ChannelMipmapGenerator LINEAR_MIPMAP_GENERATOR = new ChannelMipmapGenerator( LinearBlendFunction.INSTANCE, LinearBlendFunction.INSTANCE, @@ -41,8 +48,8 @@ public class AtlasPBRLoader implements PBRTextureLoader { ); @Override - public void load(TextureAtlas atlas, ResourceManager resourceManager, PBRTextureConsumer pbrTextureConsumer) { - TextureInfo textureInfo = TextureInfoCache.INSTANCE.getInfo(atlas.getId()); + public void load(TextureMap atlas, IResourceManager resourceManager, PBRTextureConsumer pbrTextureConsumer) { + TextureInfo textureInfo = TextureInfoCache.INSTANCE.getInfo(atlas.getGlTextureId()); int atlasWidth = textureInfo.getWidth(); int atlasHeight = textureInfo.getHeight(); int mipLevel = fetchAtlasMipLevel(atlas); @@ -50,7 +57,7 @@ public void load(TextureAtlas atlas, ResourceManager resourceManager, PBRTexture PBRAtlasTexture normalAtlas = null; PBRAtlasTexture specularAtlas = null; for (TextureAtlasSprite sprite : ((TextureAtlasAccessor) atlas).getTexturesByName().values()) { - if (!(sprite instanceof MissingTextureAtlasSprite)) { + if (!sprite.getIconName().equals("missingno")) { TextureAtlasSprite normalSprite = createPBRSprite(sprite, resourceManager, atlas, atlasWidth, atlasHeight, mipLevel, PBRType.NORMAL); TextureAtlasSprite specularSprite = createPBRSprite(sprite, resourceManager, atlas, atlasWidth, atlasHeight, mipLevel, PBRType.SPECULAR); if (normalSprite != null) { @@ -84,19 +91,18 @@ public void load(TextureAtlas atlas, ResourceManager resourceManager, PBRTexture } } - protected static int fetchAtlasMipLevel(TextureAtlas atlas) { - TextureAtlasSprite missingSprite = atlas.getSprite(MissingTextureAtlasSprite.getLocation()); - return ((TextureAtlasSpriteAccessor) missingSprite).getMainImage().length - 1; + protected static int fetchAtlasMipLevel(TextureMap atlas) { + return atlas.getMipmapLevels(); } @Nullable - protected TextureAtlasSprite createPBRSprite(TextureAtlasSprite sprite, ResourceManager resourceManager, TextureAtlas atlas, int atlasWidth, int atlasHeight, int mipLevel, PBRType pbrType) { + protected TextureAtlasSprite createPBRSprite(TextureAtlasSprite sprite, IResourceManager resourceManager, TextureMap atlas, int atlasWidth, int atlasHeight, int mipLevel, PBRType pbrType) { ResourceLocation spriteName = sprite.getName(); ResourceLocation imageLocation = ((TextureAtlasAccessor) atlas).callGetResourceLocation(spriteName); ResourceLocation pbrImageLocation = pbrType.appendToFileLocation(imageLocation); TextureAtlasSprite pbrSprite = null; - try (Resource resource = resourceManager.getResource(pbrImageLocation)) { + try (IResource resource = resourceManager.getResource(pbrImageLocation)) { NativeImage nativeImage = NativeImage.read(resource.getInputStream()); AnimationMetadataSection animationMetadata = resource.getMetadata(AnimationMetadataSection.SERIALIZER); if (animationMetadata == null) { @@ -161,7 +167,7 @@ protected TextureAtlasSprite createPBRSprite(TextureAtlasSprite sprite, Resource } protected void syncAnimation(TextureAtlasSprite source, TextureAtlasSprite target) { - if (!source.isAnimation() || !target.isAnimation()) { + if (!source.hasAnimationMetadata() || !target.hasAnimationMetadata()) { return; } diff --git a/src/main/java/net/coderbot/iris/texture/pbr/loader/PBRTextureLoader.java b/src/main/java/net/coderbot/iris/texture/pbr/loader/PBRTextureLoader.java index 68fd110425..50c24fbfa2 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/loader/PBRTextureLoader.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/loader/PBRTextureLoader.java @@ -1,10 +1,11 @@ package net.coderbot.iris.texture.pbr.loader; -import org.jetbrains.annotations.NotNull; +import net.minecraft.client.resources.IResourceManager; import org.lwjgl.opengl.GL11; import net.minecraft.client.renderer.texture.AbstractTexture; -import net.minecraft.server.packs.resources.ResourceManager; + +import javax.annotation.Nonnull; public interface PBRTextureLoader { /** @@ -14,11 +15,11 @@ public interface PBRTextureLoader { * @param resourceManager The resource manager. * @param pbrTextureConsumer The consumer that accepts resulting PBR textures. */ - void load(T texture, ResourceManager resourceManager, PBRTextureConsumer pbrTextureConsumer); + void load(T texture, IResourceManager resourceManager, PBRTextureConsumer pbrTextureConsumer); interface PBRTextureConsumer { - void acceptNormalTexture(@NotNull AbstractTexture texture); + void acceptNormalTexture(@Nonnull AbstractTexture texture); - void acceptSpecularTexture(@NotNull AbstractTexture texture); + void acceptSpecularTexture(@Nonnull AbstractTexture texture); } } diff --git a/src/main/java/net/coderbot/iris/texture/pbr/loader/PBRTextureLoaderRegistry.java b/src/main/java/net/coderbot/iris/texture/pbr/loader/PBRTextureLoaderRegistry.java index 7a89f5655d..ae2e4f0554 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/loader/PBRTextureLoaderRegistry.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/loader/PBRTextureLoaderRegistry.java @@ -3,18 +3,19 @@ import java.util.HashMap; import java.util.Map; -import org.jetbrains.annotations.Nullable; - import net.minecraft.client.renderer.texture.AbstractTexture; import net.minecraft.client.renderer.texture.SimpleTexture; import net.minecraft.client.renderer.texture.TextureAtlas; +import net.minecraft.client.renderer.texture.TextureMap; + +import javax.annotation.Nullable; public class PBRTextureLoaderRegistry { public static final PBRTextureLoaderRegistry INSTANCE = new PBRTextureLoaderRegistry(); static { INSTANCE.register(SimpleTexture.class, new SimplePBRLoader()); - INSTANCE.register(TextureAtlas.class, new AtlasPBRLoader()); + INSTANCE.register(TextureMap.class, new AtlasPBRLoader()); } private final Map, PBRTextureLoader> loaderMap = new HashMap<>(); diff --git a/src/main/java/net/coderbot/iris/texture/pbr/loader/SimplePBRLoader.java b/src/main/java/net/coderbot/iris/texture/pbr/loader/SimplePBRLoader.java index 75ba1fe19f..e3b8abd0fa 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/loader/SimplePBRLoader.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/loader/SimplePBRLoader.java @@ -2,18 +2,19 @@ import java.io.IOException; -import org.jetbrains.annotations.Nullable; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.util.ResourceLocation; import net.coderbot.iris.mixin.texture.SimpleTextureAccessor; import net.coderbot.iris.texture.pbr.PBRType; import net.minecraft.client.renderer.texture.AbstractTexture; import net.minecraft.client.renderer.texture.SimpleTexture; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.resources.ResourceManager; + +import javax.annotation.Nullable; public class SimplePBRLoader implements PBRTextureLoader { @Override - public void load(SimpleTexture texture, ResourceManager resourceManager, PBRTextureConsumer pbrTextureConsumer) { + public void load(SimpleTexture texture, IResourceManager resourceManager, PBRTextureConsumer pbrTextureConsumer) { ResourceLocation location = ((SimpleTextureAccessor) texture).getLocation(); AbstractTexture normalTexture = createPBRTexture(location, resourceManager, PBRType.NORMAL); @@ -28,12 +29,12 @@ public void load(SimpleTexture texture, ResourceManager resourceManager, PBRText } @Nullable - protected AbstractTexture createPBRTexture(ResourceLocation imageLocation, ResourceManager resourceManager, PBRType pbrType) { + protected AbstractTexture createPBRTexture(ResourceLocation imageLocation, IResourceManager resourceManager, PBRType pbrType) { ResourceLocation pbrImageLocation = pbrType.appendToFileLocation(imageLocation); SimpleTexture pbrTexture = new SimpleTexture(pbrImageLocation); try { - pbrTexture.load(resourceManager); + pbrTexture.loadTexture(resourceManager); } catch (IOException e) { return null; } diff --git a/src/main/java/net/coderbot/iris/texture/util/ImageManipulationUtil.java b/src/main/java/net/coderbot/iris/texture/util/ImageManipulationUtil.java index 4e604a0d19..5149048ce9 100644 --- a/src/main/java/net/coderbot/iris/texture/util/ImageManipulationUtil.java +++ b/src/main/java/net/coderbot/iris/texture/util/ImageManipulationUtil.java @@ -1,6 +1,6 @@ package net.coderbot.iris.texture.util; -import com.mojang.blaze3d.platform.NativeImage; +import nanolive.compat.NativeImage; public class ImageManipulationUtil { public static NativeImage scaleNearestNeighbor(NativeImage image, int newWidth, int newHeight) { diff --git a/src/main/java/net/coderbot/iris/texture/util/TextureExporter.java b/src/main/java/net/coderbot/iris/texture/util/TextureExporter.java index 3ce1a8bf95..1f3409e17b 100644 --- a/src/main/java/net/coderbot/iris/texture/util/TextureExporter.java +++ b/src/main/java/net/coderbot/iris/texture/util/TextureExporter.java @@ -2,12 +2,9 @@ import java.io.File; +import nanolive.compat.NativeImage; +import net.minecraft.client.renderer.GlStateManager; import org.apache.commons.io.FilenameUtils; - -import com.mojang.blaze3d.platform.NativeImage; -import com.mojang.blaze3d.systems.RenderSystem; - -import net.minecraft.Util; import net.minecraft.client.Minecraft; public class TextureExporter { @@ -21,10 +18,10 @@ public static void exportTextures(String directory, String filename, int texture public static void exportTexture(String directory, String filename, int textureId, int level, int width, int height) { NativeImage nativeImage = new NativeImage(width, height, false); - RenderSystem.bindTexture(textureId); + GlStateManager.bindTexture(textureId); nativeImage.downloadTexture(level, false); - File dir = new File(Minecraft.getInstance().gameDirectory, directory); + File dir = new File(Minecraft.getMinecraft().gameDir, directory); dir.mkdirs(); File file = new File(dir, filename); diff --git a/src/main/java/net/coderbot/iris/texture/util/TextureManipulationUtil.java b/src/main/java/net/coderbot/iris/texture/util/TextureManipulationUtil.java index 9878d8b74a..1d155b81f7 100644 --- a/src/main/java/net/coderbot/iris/texture/util/TextureManipulationUtil.java +++ b/src/main/java/net/coderbot/iris/texture/util/TextureManipulationUtil.java @@ -1,48 +1,46 @@ package net.coderbot.iris.texture.util; +import net.coderbot.iris.gl.IrisRenderSystem; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL30; -import com.mojang.blaze3d.platform.GlStateManager; - -import net.coderbot.iris.gl.IrisRenderSystem; -import net.minecraft.client.Minecraft; - public class TextureManipulationUtil { private static int colorFillFBO = -1; public static void fillWithColor(int textureId, int maxLevel, int rgba) { if (colorFillFBO == -1) { - colorFillFBO = GlStateManager.glGenFramebuffers(); + colorFillFBO = OpenGlHelper.glGenFramebuffers(); } - int previousFramebufferId = GlStateManager._getInteger(GL30.GL_FRAMEBUFFER_BINDING); + int previousFramebufferId = GlStateManager.glGetInteger(GL30.GL_FRAMEBUFFER_BINDING); float[] previousClearColor = new float[4]; IrisRenderSystem.getFloatv(GL11.GL_COLOR_CLEAR_VALUE, previousClearColor); - int previousTextureId = GlStateManager._getInteger(GL11.GL_TEXTURE_BINDING_2D); + int previousTextureId = GlStateManager.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); int[] previousViewport = new int[4]; IrisRenderSystem.getIntegerv(GL11.GL_VIEWPORT, previousViewport); - GlStateManager._glBindFramebuffer(GL30.GL_FRAMEBUFFER, colorFillFBO); - GlStateManager._clearColor( + OpenGlHelper.glBindFramebuffer(GL30.GL_FRAMEBUFFER, colorFillFBO); + GlStateManager.clearColor( (rgba >> 24 & 0xFF) / 255.0f, (rgba >> 16 & 0xFF) / 255.0f, (rgba >> 8 & 0xFF) / 255.0f, (rgba & 0xFF) / 255.0f ); - GlStateManager._bindTexture(textureId); + GlStateManager.bindTexture(textureId); for (int level = 0; level <= maxLevel; ++level) { - int width = GlStateManager._getTexLevelParameter(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_WIDTH); - int height = GlStateManager._getTexLevelParameter(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_HEIGHT); - GlStateManager._viewport(0, 0, width, height); - GlStateManager._glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, textureId, level); - GlStateManager._clear(GL11.GL_COLOR_BUFFER_BIT, Minecraft.ON_OSX); - GlStateManager._glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, 0, level); + int width = GlStateManager.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_WIDTH); + int height = GlStateManager.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_HEIGHT); + GlStateManager.viewport(0, 0, width, height); + OpenGlHelper.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, textureId, level); + GlStateManager.clear(GL11.GL_COLOR_BUFFER_BIT); + OpenGlHelper.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, 0, level); } - GlStateManager._glBindFramebuffer(GL30.GL_FRAMEBUFFER, previousFramebufferId); - GlStateManager._clearColor(previousClearColor[0], previousClearColor[1], previousClearColor[2], previousClearColor[3]); - GlStateManager._bindTexture(previousTextureId); - GlStateManager._viewport(previousViewport[0], previousViewport[1], previousViewport[2], previousViewport[3]); + OpenGlHelper.glBindFramebuffer(GL30.GL_FRAMEBUFFER, previousFramebufferId); + GlStateManager.clearColor(previousClearColor[0], previousClearColor[1], previousClearColor[2], previousClearColor[3]); + GlStateManager.bindTexture(previousTextureId); + GlStateManager.viewport(previousViewport[0], previousViewport[1], previousViewport[2], previousViewport[3]); } } diff --git a/src/main/java/net/coderbot/iris/uniforms/CameraUniforms.java b/src/main/java/net/coderbot/iris/uniforms/CameraUniforms.java index 24c3dc6e8e..ea1b76b2bc 100644 --- a/src/main/java/net/coderbot/iris/uniforms/CameraUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/CameraUniforms.java @@ -12,7 +12,7 @@ * @see Uniforms: Camera */ public class CameraUniforms { - private static final Minecraft client = Minecraft.getInstance(); + private static final Minecraft client = Minecraft.getMinecraft(); private CameraUniforms() { } @@ -30,7 +30,7 @@ public static void addCameraUniforms(UniformHolder uniforms, FrameUpdateNotifier private static int getRenderDistanceInBlocks() { // TODO: Should we ask the game renderer for this? - return client.options.renderDistance * 16; + return client.gameSettings.renderDistanceChunks * 16; } public static Vector3d getUnshiftedCameraPosition() { diff --git a/src/main/java/net/coderbot/iris/uniforms/CapturedRenderingState.java b/src/main/java/net/coderbot/iris/uniforms/CapturedRenderingState.java index f726e0858d..2fa88ef6d8 100644 --- a/src/main/java/net/coderbot/iris/uniforms/CapturedRenderingState.java +++ b/src/main/java/net/coderbot/iris/uniforms/CapturedRenderingState.java @@ -41,7 +41,7 @@ public void setGbufferProjection(Matrix4f gbufferProjection) { } public Vector3d getFogColor() { - if (Minecraft.getInstance().level == null || fogColor == null) { + if (Minecraft.getMinecraft().world == null || fogColor == null) { return ZERO_VECTOR_3d; } diff --git a/src/main/java/net/coderbot/iris/uniforms/CelestialUniforms.java b/src/main/java/net/coderbot/iris/uniforms/CelestialUniforms.java index 4f11463315..a4ee8f26e1 100644 --- a/src/main/java/net/coderbot/iris/uniforms/CelestialUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/CelestialUniforms.java @@ -12,6 +12,7 @@ import net.coderbot.iris.vendored.joml.Vector4f; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.multiplayer.WorldClient; /** * @see Uniforms: Celestial bodies @@ -104,7 +105,7 @@ private Vector4f getCelestialPosition(float y) { } private static Vector4f getUpPosition() { - com.mojang.math.Vector4f upVector = new com.mojang.math.Vector4f(0.0F, 100.0F, 0.0F, 0.0F); + Vector4f upVector = new Vector4f(0.0F, 100.0F, 0.0F, 0.0F); // Get the current GBuffer model view matrix, since that is the basis of the celestial model view matrix Matrix4f preCelestial = CapturedRenderingState.INSTANCE.getGbufferModelView().copy(); @@ -126,11 +127,11 @@ public static boolean isDay() { return getSunAngle() <= 0.5; } - private static ClientLevel getWorld() { - return Objects.requireNonNull(Minecraft.getInstance().level); + private static WorldClient getWorld() { + return Objects.requireNonNull(Minecraft.getMinecraft().world); } private static float getSkyAngle() { - return getWorld().getTimeOfDay(CapturedRenderingState.INSTANCE.getTickDelta()); + return getWorld().getCelestialAngle(CapturedRenderingState.INSTANCE.getTickDelta()); } } diff --git a/src/main/java/net/coderbot/iris/uniforms/CommonUniforms.java b/src/main/java/net/coderbot/iris/uniforms/CommonUniforms.java index ec3c908650..3b28c69fc7 100644 --- a/src/main/java/net/coderbot/iris/uniforms/CommonUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/CommonUniforms.java @@ -28,13 +28,25 @@ import net.coderbot.iris.vendored.joml.Vector3d; import net.coderbot.iris.vendored.joml.Vector4f; import net.coderbot.iris.vendored.joml.Vector4i; +import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.player.LocalPlayer; +import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.texture.AbstractTexture; import net.minecraft.client.renderer.texture.TextureAtlas; +import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.core.BlockPos; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.init.MobEffects; +import net.minecraft.potion.PotionEffect; import net.minecraft.tags.FluidTags; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.EnumSkyBlock; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; @@ -44,7 +56,7 @@ import net.minecraft.world.phys.Vec3; public final class CommonUniforms { - private static final Minecraft client = Minecraft.getInstance(); + private static final Minecraft client = Minecraft.getMinecraft(); private static final Vector2i ZERO_VECTOR_2i = new Vector2i(); private static final Vector4i ZERO_VECTOR_4i = new Vector4i(0, 0, 0, 0); private static final Vector3d ZERO_VECTOR_3d = new Vector3d(); @@ -69,10 +81,10 @@ public static void addCommonUniforms(DynamicUniformHolder uniforms, IdMap idMap, // TODO: OptiFine doesn't think that atlasSize is a "dynamic" uniform, // but we do. How will custom uniforms depending on atlasSize work? uniforms.uniform2i("atlasSize", () -> { - int glId = GlStateManagerAccessor.getTEXTURES()[0].binding; + int glId = GlStateManagerAccessor.getTEXTURES()[0].textureName; AbstractTexture texture = TextureTracker.INSTANCE.getTexture(glId); - if (texture instanceof TextureAtlas) { + if (texture instanceof TextureMap) { TextureInfo info = TextureInfoCache.INSTANCE.getInfo(glId); return new Vector2i(info.getWidth(), info.getHeight()); } @@ -81,7 +93,7 @@ public static void addCommonUniforms(DynamicUniformHolder uniforms, IdMap idMap, }, StateUpdateNotifiers.bindTextureNotifier); uniforms.uniform2i("gtextureSize", () -> { - int glId = GlStateManagerAccessor.getTEXTURES()[0].binding; + int glId = GlStateManagerAccessor.getTEXTURES()[0].textureName; TextureInfo info = TextureInfoCache.INSTANCE.getInfo(glId); return new Vector2i(info.getWidth(), info.getHeight()); @@ -91,8 +103,8 @@ public static void addCommonUniforms(DynamicUniformHolder uniforms, IdMap idMap, uniforms.uniform4i("blendFunc", () -> { GlStateManager.BlendState blend = GlStateManagerAccessor.getBLEND(); - if (((BooleanStateAccessor) blend.mode).isEnabled()) { - return new Vector4i(blend.srcRgb, blend.dstRgb, blend.srcAlpha, blend.dstAlpha); + if (((BooleanStateAccessor) blend.blend).isEnabled()) { + return new Vector4i(blend.srcFactor, blend.dstFactor, blend.srcFactorAlpha, blend.dstFactorAlpha); } else { return ZERO_VECTOR_4i; } @@ -109,7 +121,7 @@ public static void generalCommonUniforms(UniformHolder uniforms, FrameUpdateNoti SmoothedVec2f eyeBrightnessSmooth = new SmoothedVec2f(directives.getEyeBrightnessHalfLife(), directives.getEyeBrightnessHalfLife(), CommonUniforms::getEyeBrightness, updateNotifier); uniforms - .uniform1b(PER_FRAME, "hideGUI", () -> client.options.hideGui) + .uniform1b(PER_FRAME, "hideGUI", () -> client.gameSettings.hideGUI) .uniform1i(PER_FRAME, "isEyeInWater", CommonUniforms::isEyeInWater) .uniform1f(PER_FRAME, "blindness", CommonUniforms::getBlindness) .uniform1f(PER_FRAME, "nightVision", CommonUniforms::getNightVision) @@ -121,7 +133,7 @@ public static void generalCommonUniforms(UniformHolder uniforms, FrameUpdateNoti .uniform1b(PER_FRAME, "is_on_ground", CommonUniforms::isOnGround) // TODO: Do we need to clamp this to avoid fullbright breaking shaders? Or should shaders be able to detect // that the player is trying to turn on fullbright? - .uniform1f(PER_FRAME, "screenBrightness", () -> client.options.gamma) + .uniform1f(PER_FRAME, "screenBrightness", () -> client.gameSettings.gammaSetting) // just a dummy value for shaders where entityColor isn't supplied through a vertex attribute (and thus is // not available) - suppresses warnings. See AttributeShaderTransformer for the actual entityColor code. .uniform4f(ONCE, "entityColor", () -> new Vector4f(0, 0, 0, 0)) @@ -139,7 +151,7 @@ public static void generalCommonUniforms(UniformHolder uniforms, FrameUpdateNoti } private static boolean isOnGround() { - return client.player != null && client.player.isOnGround(); + return client.player != null && client.player.onGround; } private static boolean isHurt() { @@ -160,7 +172,7 @@ private static boolean isInvisible() { private static boolean isBurning() { if (client.player != null) { - return client.player.isOnFire(); + return client.player.isBurning(); } else { return false; } @@ -168,7 +180,7 @@ private static boolean isBurning() { private static boolean isSneaking() { if (client.player != null) { - return client.player.isCrouching(); + return client.player.isSneaking(); } else { return false; } @@ -183,19 +195,19 @@ private static boolean isSprinting() { } private static Vector3d getSkyColor() { - if (client.level == null || client.cameraEntity == null) { + if (client.world == null || client.getRenderViewEntity() == null) { return ZERO_VECTOR_3d; } - return JomlConversions.fromVec3(client.level.getSkyColor(client.cameraEntity.blockPosition(), + return JomlConversions.fromVec3(client.world.getSkyColor(client.getRenderViewEntity(), CapturedRenderingState.INSTANCE.getTickDelta())); } static float getBlindness() { - Entity cameraEntity = client.getCameraEntity(); + Entity cameraEntity = client.getRenderViewEntity(); - if (cameraEntity instanceof LivingEntity) { - MobEffectInstance blindness = ((LivingEntity) cameraEntity).getEffect(MobEffects.BLINDNESS); + if (cameraEntity instanceof EntityLiving) { + PotionEffect blindness = ((EntityLiving) cameraEntity).getActivePotionEffect(MobEffects.BLINDNESS); if (blindness != null) { // Guessing that this is what OF uses, based on how vanilla calculates the fog value in BackgroundRenderer @@ -208,44 +220,44 @@ static float getBlindness() { } private static float getPlayerMood() { - if (!(client.cameraEntity instanceof LocalPlayer)) { + if (!(client.getRenderViewEntity() instanceof EntityPlayerSP)) { return 0.0F; } // This should always be 0 to 1 anyways but just making sure - return Math.clamp(0.0F, 1.0F, ((LocalPlayer) client.cameraEntity).getCurrentMood()); + return Math.clamp(0.0F, 1.0F, ((EntityPlayerSP) client.getRenderViewEntity()).getCurrentMood()); } static float getRainStrength() { - if (client.level == null) { + if (client.world == null) { return 0f; } // Note: Ensure this is in the range of 0 to 1 - some custom servers send out of range values. return Math.clamp(0.0F, 1.0F, - client.level.getRainLevel(CapturedRenderingState.INSTANCE.getTickDelta())); + client.world.getRainStrength(CapturedRenderingState.INSTANCE.getTickDelta())); } private static Vector2i getEyeBrightness() { - if (client.cameraEntity == null || client.level == null) { + if (client.getRenderViewEntity() == null || client.world == null) { return ZERO_VECTOR_2i; } - Vec3 feet = client.cameraEntity.position(); - Vec3 eyes = new Vec3(feet.x, client.cameraEntity.getEyeY(), feet.z); + Vec3d feet = client.getRenderViewEntity().getPositionVector(); + Vec3d eyes = new Vec3d(feet.x, client.getRenderViewEntity().getEyeHeight(), feet.z); BlockPos eyeBlockPos = new BlockPos(eyes); - int blockLight = client.level.getBrightness(LightLayer.BLOCK, eyeBlockPos); - int skyLight = client.level.getBrightness(LightLayer.SKY, eyeBlockPos); + int blockLight = client.world.getLightFor(EnumSkyBlock.BLOCK, eyeBlockPos); + int skyLight = client.world.getLightFor(EnumSkyBlock.SKY, eyeBlockPos); return new Vector2i(blockLight * 16, skyLight * 16); } private static float getNightVision() { - Entity cameraEntity = client.getCameraEntity(); + Entity cameraEntity = client.getRenderViewEntity(); - if (cameraEntity instanceof LivingEntity) { - LivingEntity livingEntity = (LivingEntity) cameraEntity; + if (cameraEntity instanceof EntityLiving) { + EntityLiving livingEntity = (EntityLiving) cameraEntity; try { // See MixinGameRenderer#iris$safecheckNightvisionStrength. @@ -256,7 +268,7 @@ private static float getNightVision() { // // See: https://github.com/apace100/apoli/blob/320b0ef547fbbf703de7154f60909d30366f6500/src/main/java/io/github/apace100/apoli/mixin/GameRendererMixin.java#L153 float nightVisionStrength = - GameRenderer.getNightVisionScale(livingEntity, CapturedRenderingState.INSTANCE.getTickDelta()); + Minecraft.getMinecraft().entityRenderer.getNightVisionBrightness(livingEntity, CapturedRenderingState.INSTANCE.getTickDelta()); if (nightVisionStrength > 0) { // Just protecting against potential weird mod behavior @@ -273,6 +285,7 @@ private static float getNightVision() { // This lets existing shaderpacks be compatible with conduit power automatically. // // Yes, this should be the player entity, to match LightmapTextureManager. + // TODO took from mod Oceanic Expanse if (client.player != null && client.player.hasEffect(MobEffects.CONDUIT_POWER)) { float underwaterVisibility = client.player.getWaterVision(); @@ -292,11 +305,9 @@ static int isEyeInWater() { // I'm not sure what the best way to deal with this is, but the current approach seems to be an acceptable one - // after all, disabling the overlay results in the intended effect of it not really looking like you're // underwater on most shaderpacks. For now, I will leave this as-is, but it is something to keep in mind. - FluidState submergedFluid = client.gameRenderer.getMainCamera().getFluidInCamera(); - - if (submergedFluid.is(FluidTags.WATER)) { + if (client.player.isInsideOfMaterial(Material.WATER)) { return 1; - } else if (submergedFluid.is(FluidTags.LAVA)) { + } else if (client.player.isInsideOfMaterial(Material.LAVA)) { return 2; } else { return 0; diff --git a/src/main/java/net/coderbot/iris/uniforms/FogUniforms.java b/src/main/java/net/coderbot/iris/uniforms/FogUniforms.java index 46e112dd00..e7fc5b8607 100644 --- a/src/main/java/net/coderbot/iris/uniforms/FogUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/FogUniforms.java @@ -1,11 +1,10 @@ package net.coderbot.iris.uniforms; -import com.mojang.blaze3d.platform.GlStateManager; - import net.coderbot.iris.gl.state.StateUpdateNotifiers; import net.coderbot.iris.gl.uniform.DynamicUniformHolder; import net.coderbot.iris.mixin.GlStateManagerAccessor; import net.coderbot.iris.mixin.statelisteners.BooleanStateAccessor; +import net.minecraft.client.renderer.GlStateManager; public class FogUniforms { private FogUniforms() { @@ -16,7 +15,7 @@ public static void addFogUniforms(DynamicUniformHolder uniforms) { uniforms.uniform1i("fogMode", () -> { GlStateManager.FogState fog = GlStateManagerAccessor.getFOG(); - if (!((BooleanStateAccessor) fog.enable).isEnabled()) { + if (!((BooleanStateAccessor) fog.fog).isEnabled()) { return 0; } diff --git a/src/main/java/net/coderbot/iris/uniforms/HardcodedCustomUniforms.java b/src/main/java/net/coderbot/iris/uniforms/HardcodedCustomUniforms.java index 93016fd629..c0a56cd344 100644 --- a/src/main/java/net/coderbot/iris/uniforms/HardcodedCustomUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/HardcodedCustomUniforms.java @@ -2,29 +2,29 @@ import net.coderbot.iris.gl.uniform.UniformHolder; import net.coderbot.iris.gl.uniform.UniformUpdateFrequency; -import net.coderbot.iris.mixin.DimensionTypeAccessor; import net.coderbot.iris.uniforms.transforms.SmoothedFloat; import net.coderbot.iris.vendored.joml.Math; import net.minecraft.client.Minecraft; -import net.minecraft.core.BlockPos; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LightLayer; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.phys.Vec3; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.EnumSkyBlock; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BiomeSwamp; // These expressions are copied directly from BSL and Complementary. // TODO: Remove once custom uniforms are actually supported, this is just a temporary thing to get BSL & Complementary // mostly working under Iris. public class HardcodedCustomUniforms { - private static final Minecraft client = Minecraft.getInstance(); + private static final Minecraft client = Minecraft.getMinecraft(); private static Biome storedBiome; public static void addHardcodedCustomUniforms(UniformHolder holder, FrameUpdateNotifier updateNotifier) { updateNotifier.addListener(() -> { - if (Minecraft.getInstance().level != null) { - storedBiome = Minecraft.getInstance().level.getBiome(Minecraft.getInstance().getCameraEntity().blockPosition()); + if (Minecraft.getMinecraft().world != null) { + storedBiome = Minecraft.getMinecraft().world.getBiome(Minecraft.getMinecraft().getRenderViewEntity().getPosition()); } else { storedBiome = null; } @@ -62,14 +62,15 @@ public static void addHardcodedCustomUniforms(UniformHolder holder, FrameUpdateN if (storedBiome == null) { return 0; } else { - return storedBiome.getBiomeCategory() == Biome.BiomeCategory.SWAMP ? 1 : 0; + // TODO Maybe it's possible to make better check + return storedBiome instanceof BiomeSwamp ? 1 : 0; } }, updateNotifier)); holder.uniform1f(UniformUpdateFrequency.PER_FRAME, "BiomeTemp", () -> { if (storedBiome == null) { return 0; } else { - return storedBiome.getTemperature(Minecraft.getInstance().getCameraEntity().blockPosition()); + return storedBiome.getTemperature(Minecraft.getMinecraft().getRenderViewEntity().getPosition()); } }); @@ -93,20 +94,20 @@ private static float getHyperSpeedStrength(SmoothedFloat smoothSpeed) { } private static float getBurnFactor() { - return Minecraft.getInstance().player.isOnFire() ? 1.0f : 0f; + return Minecraft.getMinecraft().player.isBurning() ? 1.0f : 0f; } private static float getSneakFactor() { - return Minecraft.getInstance().player.isCrouching() ? 1.0f : 0f; + return Minecraft.getMinecraft().player.isSneaking() ? 1.0f : 0f; } private static float getHurtFactor() { - Player player = Minecraft.getInstance().player; + EntityPlayerSP player = Minecraft.getMinecraft().player; return player.hurtTime > 0 || player.deathTime > 0 ? 0.4f : 0f; } private static float getEyeInCave() { - if (client.getCameraEntity().getEyeY() < 5.0) { + if (client.getRenderViewEntity().getEyeHeight() < 5.0) { return 1.0f - getEyeSkyBrightness() / 240F; } return 0.0f; @@ -117,15 +118,15 @@ private static float getEyeBrightnessM() { } private static float getEyeSkyBrightness() { - if (client.cameraEntity == null || client.level == null) { + if (client.getRenderViewEntity() == null || client.world == null) { return 0; } - Vec3 feet = client.cameraEntity.position(); - Vec3 eyes = new Vec3(feet.x, client.cameraEntity.getEyeY(), feet.z); + Vec3d feet = client.getRenderViewEntity().getPositionVector(); + Vec3d eyes = new Vec3d(feet.x, client.getRenderViewEntity().getEyeHeight(), feet.z); BlockPos eyeBlockPos = new BlockPos(eyes); - int skyLight = client.level.getBrightness(LightLayer.SKY, eyeBlockPos); + int skyLight = client.world.getLightFor(EnumSkyBlock.SKY, eyeBlockPos); return skyLight * 16; } @@ -154,9 +155,10 @@ private static float getTimeAngle() { } private static int getWorldDayTime() { - Level level = Minecraft.getInstance().level; - long timeOfDay = level.getDayTime(); - long dayTime = ((DimensionTypeAccessor) level.dimensionType()).getFixedTime().orElse(timeOfDay % 24000L); + WorldClient level = Minecraft.getMinecraft().world; + long timeOfDay = level.getWorldTime(); + // TODO based on Optifine 1.12 logic + long dayTime = timeOfDay % 24000L/*((DimensionTypeAccessor) level.dimensionType()).getFixedTime().orElse(timeOfDay % 24000L)*/; return (int) dayTime; } @@ -181,14 +183,12 @@ private static float getRawPrecipitation() { if (storedBiome == null) { return 0; } - Biome.Precipitation precipitation = storedBiome.getPrecipitation(); - switch (precipitation) { - case RAIN: - return 1; - case SNOW: - return 2; - default: - return 0; + if(storedBiome.canRain()) { + return 1; + } else if(storedBiome.getEnableSnow()) { + return 2; + } else { + return 0; } } diff --git a/src/main/java/net/coderbot/iris/uniforms/IdMapUniforms.java b/src/main/java/net/coderbot/iris/uniforms/IdMapUniforms.java index 3c46baeaeb..6d191909d7 100644 --- a/src/main/java/net/coderbot/iris/uniforms/IdMapUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/IdMapUniforms.java @@ -1,22 +1,24 @@ package net.coderbot.iris.uniforms; -import static net.coderbot.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME; - -import org.jetbrains.annotations.NotNull; - import it.unimi.dsi.fastutil.objects.Object2IntFunction; import net.coderbot.iris.gl.uniform.DynamicUniformHolder; import net.coderbot.iris.gl.uniform.UniformUpdateFrequency; import net.coderbot.iris.shaderpack.IdMap; import net.coderbot.iris.shaderpack.materialmap.NamespacedId; +import net.coderbot.iris.vendored.joml.Vector3f; import net.irisshaders.iris.api.v0.item.IrisItemLightProvider; import net.minecraft.client.Minecraft; -import net.minecraft.client.player.LocalPlayer; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.registry.ForgeRegistries; + +import javax.annotation.Nonnull; + +import static net.coderbot.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME; public final class IdMapUniforms { @@ -24,8 +26,8 @@ private IdMapUniforms() { } public static void addIdMapUniforms(FrameUpdateNotifier notifier, DynamicUniformHolder uniforms, IdMap idMap, boolean isOldHandLight) { - HeldItemSupplier mainHandSupplier = new HeldItemSupplier(InteractionHand.MAIN_HAND, idMap.getItemIdMap(), isOldHandLight); - HeldItemSupplier offHandSupplier = new HeldItemSupplier(InteractionHand.OFF_HAND, idMap.getItemIdMap(), false); + HeldItemSupplier mainHandSupplier = new HeldItemSupplier(EnumHand.MAIN_HAND, idMap.getItemIdMap(), isOldHandLight); + HeldItemSupplier offHandSupplier = new HeldItemSupplier(EnumHand.OFF_HAND, idMap.getItemIdMap(), false); notifier.addListener(mainHandSupplier::update); notifier.addListener(offHandSupplier::update); @@ -50,17 +52,17 @@ public static void addIdMapUniforms(FrameUpdateNotifier notifier, DynamicUniform * to an integer, and the old hand light value to map offhand to main hand. */ private static class HeldItemSupplier { - private final InteractionHand hand; + private final EnumHand hand; private final Object2IntFunction itemIdMap; private final boolean applyOldHandLight; private int intID; private int lightValue; - private com.mojang.math.Vector3f lightColor; + private Vector3f lightColor; - HeldItemSupplier(InteractionHand hand, Object2IntFunction itemIdMap, boolean shouldApplyOldHandLight) { + HeldItemSupplier(EnumHand hand, Object2IntFunction itemIdMap, boolean shouldApplyOldHandLight) { this.hand = hand; this.itemIdMap = itemIdMap; - this.applyOldHandLight = shouldApplyOldHandLight && hand == InteractionHand.MAIN_HAND; + this.applyOldHandLight = shouldApplyOldHandLight && hand == EnumHand.MAIN_HAND; } private void invalidate() { @@ -70,7 +72,7 @@ private void invalidate() { } public void update() { - LocalPlayer player = Minecraft.getInstance().player; + EntityPlayerSP player = Minecraft.getMinecraft().player; if (player == null) { // Not valid when the player doesn't exist @@ -78,48 +80,49 @@ public void update() { return; } - ItemStack heldStack = player.getItemInHand(hand); + ItemStack heldStack = player.getHeldItem(hand); - if (heldStack == null) { + if (heldStack.isEmpty()) { invalidate(); return; } Item heldItem = heldStack.getItem(); - if (heldItem == null) { + if (heldItem == Items.AIR) { invalidate(); return; } - ResourceLocation heldItemId = Registry.ITEM.getKey(heldItem); - intID = itemIdMap.applyAsInt(new NamespacedId(heldItemId.getNamespace(), heldItemId.getPath())); + // TODO, maybe it will be better to rewrite on Integer ID's system like it was done in Optifine on 1.12? + ResourceLocation heldItemId = ForgeRegistries.ITEMS.getKey(heldItem); + intID = itemIdMap.getInt(new NamespacedId(heldItemId.getNamespace(), heldItemId.getPath())); IrisItemLightProvider lightProvider = (IrisItemLightProvider) heldItem; - lightValue = lightProvider.getLightEmission(Minecraft.getInstance().player, heldStack); + lightValue = lightProvider.getLightEmission(Minecraft.getMinecraft().player, heldStack); if (applyOldHandLight) { lightProvider = applyOldHandLighting(player, lightProvider); } - lightColor = lightProvider.getLightColor(Minecraft.getInstance().player, heldStack); + lightColor = lightProvider.getLightColor(Minecraft.getMinecraft().player, heldStack); } - private IrisItemLightProvider applyOldHandLighting(@NotNull LocalPlayer player, IrisItemLightProvider existing) { - ItemStack offHandStack = player.getItemInHand(InteractionHand.OFF_HAND); + private IrisItemLightProvider applyOldHandLighting(@Nonnull EntityPlayerSP player, IrisItemLightProvider existing) { + ItemStack offHandStack = player.getHeldItem(EnumHand.OFF_HAND); - if (offHandStack == null) { + if (offHandStack.isEmpty()) { return existing; } Item offHandItem = offHandStack.getItem(); - if (offHandItem == null) { + if (offHandItem == Items.AIR) { return existing; } IrisItemLightProvider lightProvider = (IrisItemLightProvider) offHandItem; - int newEmission = lightProvider.getLightEmission(Minecraft.getInstance().player, offHandStack); + int newEmission = lightProvider.getLightEmission(Minecraft.getMinecraft().player, offHandStack); if (lightValue < newEmission) { lightValue = newEmission; @@ -137,7 +140,7 @@ public int getLightValue() { return lightValue; } - public com.mojang.math.Vector3f getLightColor() { + public Vector3f getLightColor() { return lightColor; } } diff --git a/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java b/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java index 30effdca04..74b02706ae 100644 --- a/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/IrisExclusiveUniforms.java @@ -1,21 +1,19 @@ package net.coderbot.iris.uniforms; -import java.util.Objects; -import java.util.stream.StreamSupport; - import net.coderbot.iris.JomlConversions; import net.coderbot.iris.gl.uniform.UniformHolder; import net.coderbot.iris.gl.uniform.UniformUpdateFrequency; import net.coderbot.iris.gui.option.IrisVideoSettings; -import net.coderbot.iris.mixin.DimensionTypeAccessor; import net.coderbot.iris.vendored.joml.Math; import net.coderbot.iris.vendored.joml.Vector3d; import net.coderbot.iris.vendored.joml.Vector4f; import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.world.entity.LightningBolt; -import net.minecraft.world.level.GameType; -import net.minecraft.world.phys.Vec3; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.GameType; + +import java.util.Objects; public class IrisExclusiveUniforms { public static void addIrisExclusiveUniforms(UniformHolder uniforms) { @@ -35,14 +33,14 @@ public static void addIrisExclusiveUniforms(UniformHolder uniforms) { uniforms.uniform1b(UniformUpdateFrequency.PER_TICK, "isSpectator", IrisExclusiveUniforms::isSpectator); uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "eyePosition", IrisExclusiveUniforms::getEyePosition); uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "relativeEyePosition", () -> CameraUniforms.getUnshiftedCameraPosition().sub(getEyePosition())); - uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "playerLookVector", () -> JomlConversions.fromVec3(Minecraft.getInstance().getCameraEntity().getLookAngle())); - uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "playerBodyVector", () -> JomlConversions.fromVec3(Minecraft.getInstance().getCameraEntity().getForward())); + uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "playerLookVector", () -> JomlConversions.fromVec3(Minecraft.getMinecraft().getRenderViewEntity().getLookVec())); + uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "playerBodyVector", () -> JomlConversions.fromVec3(Minecraft.getMinecraft().getRenderViewEntity().getForward())); Vector4f zero = new Vector4f(0, 0, 0, 0); uniforms.uniform4f(UniformUpdateFrequency.PER_TICK, "lightningBoltPosition", () -> { - if (Minecraft.getInstance().level != null) { - return StreamSupport.stream(Minecraft.getInstance().level.entitiesForRendering().spliterator(), false).filter(bolt -> bolt instanceof LightningBolt).findAny().map(bolt -> { + if (Minecraft.getMinecraft().world != null) { + return Minecraft.getMinecraft().world.loadedEntityList.stream().filter(bolt -> bolt instanceof EntityLightningBolt).findAny().map(bolt -> { Vector3d unshiftedCameraPosition = CameraUniforms.getUnshiftedCameraPosition(); - Vec3 vec3 = bolt.getPosition(Minecraft.getInstance().getDeltaFrameTime()); + Vec3d vec3 = bolt.getPositionVector(); return new Vector4f((float) (vec3.x - unshiftedCameraPosition.x), (float) (vec3.y - unshiftedCameraPosition.y), (float) (vec3.z - unshiftedCameraPosition.z), 1); }).orElse(zero); } else { @@ -54,112 +52,109 @@ public static void addIrisExclusiveUniforms(UniformHolder uniforms) { private static float getThunderStrength() { // Note: Ensure this is in the range of 0 to 1 - some custom servers send out of range values. return Math.clamp(0.0F, 1.0F, - Minecraft.getInstance().level.getThunderLevel(CapturedRenderingState.INSTANCE.getTickDelta())); + Minecraft.getMinecraft().world.getThunderStrength(CapturedRenderingState.INSTANCE.getTickDelta())); } private static float getCurrentHealth() { - if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) { + if (Minecraft.getMinecraft().player == null || !Minecraft.getMinecraft().playerController.getCurrentGameType().isSurvivalOrAdventure()) { return -1; } - return Minecraft.getInstance().player.getHealth() / Minecraft.getInstance().player.getMaxHealth(); + return Minecraft.getMinecraft().player.getHealth() / Minecraft.getMinecraft().player.getMaxHealth(); } private static float getCurrentHunger() { - if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) { + if (Minecraft.getMinecraft().player == null || !Minecraft.getMinecraft().playerController.getCurrentGameType().isSurvivalOrAdventure()) { return -1; } - return Minecraft.getInstance().player.getFoodData().getFoodLevel() / 20f; + return Minecraft.getMinecraft().player.getFoodStats().getFoodLevel() / 20f; } private static float getCurrentAir() { - if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) { + if (Minecraft.getMinecraft().player == null || !Minecraft.getMinecraft().playerController.getCurrentGameType().isSurvivalOrAdventure()) { return -1; } - return (float) Minecraft.getInstance().player.getAirSupply() / (float) Minecraft.getInstance().player.getMaxAirSupply(); + return (float) Minecraft.getMinecraft().player.getAir() / 300F/*(float) Minecraft.getMinecraft().player.getMaxAirSupply()*/; } private static float getMaxAir() { - if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) { + if (Minecraft.getMinecraft().player == null || !Minecraft.getMinecraft().playerController.getCurrentGameType().isSurvivalOrAdventure()) { return -1; } - return Minecraft.getInstance().player.getMaxAirSupply(); + return 300F/*Minecraft.getMinecraft().player.getMaxAirSupply()*/; } private static float getMaxHealth() { - if (Minecraft.getInstance().player == null || !Minecraft.getInstance().gameMode.getPlayerMode().isSurvival()) { + if (Minecraft.getMinecraft().player == null || !Minecraft.getMinecraft().playerController.getCurrentGameType().isSurvivalOrAdventure()) { return -1; } - return Minecraft.getInstance().player.getMaxHealth(); + return Minecraft.getMinecraft().player.getMaxHealth(); } private static boolean isFirstPersonCamera() { - // If camera type is not explicitly third-person, assume it's first-person. - switch (Minecraft.getInstance().options.getCameraType()) { - case THIRD_PERSON_BACK: - case THIRD_PERSON_FRONT: - return false; - default: return true; - } + return Minecraft.getMinecraft().gameSettings.thirdPersonView == 0; } private static boolean isSpectator() { - return Minecraft.getInstance().gameMode.getPlayerMode() == GameType.SPECTATOR; + return Minecraft.getMinecraft().playerController.getCurrentGameType() == GameType.SPECTATOR; } private static Vector3d getEyePosition() { - Objects.requireNonNull(Minecraft.getInstance().getCameraEntity()); - Vec3 pos = Minecraft.getInstance().getCameraEntity().getEyePosition(CapturedRenderingState.INSTANCE.getTickDelta()); + Objects.requireNonNull(Minecraft.getMinecraft().getRenderViewEntity()); + Vec3d pos = Minecraft.getMinecraft().getRenderViewEntity().getPositionEyes(CapturedRenderingState.INSTANCE.getTickDelta()); return new Vector3d(pos.x, pos.y, pos.z); } public static class WorldInfoUniforms { public static void addWorldInfoUniforms(UniformHolder uniforms) { - ClientLevel level = Minecraft.getInstance().level; + WorldClient level = Minecraft.getMinecraft().world; // TODO: Use level.dimensionType() coordinates for 1.18! uniforms.uniform1i(UniformUpdateFrequency.PER_FRAME, "bedrockLevel", () -> 0); uniforms.uniform1f(UniformUpdateFrequency.PER_FRAME, "cloudHeight", () -> { if (level != null) { - return level.effects().getCloudHeight(); + return level.provider.getCloudHeight(); } else { return 192.0; } }); uniforms.uniform1i(UniformUpdateFrequency.PER_FRAME, "heightLimit", () -> { if (level != null) { - return level.getMaxBuildHeight(); + return level.getHeight(); } else { return 256; } }); uniforms.uniform1i(UniformUpdateFrequency.PER_FRAME, "logicalHeightLimit", () -> { if (level != null) { - return level.dimensionType().logicalHeight(); + // TODO Correct? + return level.getActualHeight(); } else { return 256; } }); uniforms.uniform1b(UniformUpdateFrequency.PER_FRAME, "hasCeiling", () -> { if (level != null) { - return level.dimensionType().hasCeiling(); + // TODO Not sure, was taken from Angelica, but it seems like we have no other choice + return level.provider.isNether(); } else { return false; } }); uniforms.uniform1b(UniformUpdateFrequency.PER_FRAME, "hasSkylight", () -> { if (level != null) { - return level.dimensionType().hasSkyLight(); + return level.provider.hasSkyLight(); } else { return true; } }); uniforms.uniform1f(UniformUpdateFrequency.PER_FRAME, "ambientLight", () -> { if (level != null) { - return ((DimensionTypeAccessor) level.dimensionType()).getAmbientLight(); + // TODO Not sure, was taken from Angelica + return level.provider.getLightBrightnessTable()[0]; } else { return 0f; } diff --git a/src/main/java/net/coderbot/iris/uniforms/MatrixUniforms.java b/src/main/java/net/coderbot/iris/uniforms/MatrixUniforms.java index f2c15b9aec..ea20b01121 100644 --- a/src/main/java/net/coderbot/iris/uniforms/MatrixUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/MatrixUniforms.java @@ -5,12 +5,11 @@ import java.nio.FloatBuffer; import java.util.function.Supplier; -import com.mojang.math.Matrix4f; - import net.coderbot.iris.gl.uniform.UniformHolder; import net.coderbot.iris.pipeline.ShadowRenderer; import net.coderbot.iris.shaderpack.PackDirectives; import net.coderbot.iris.shadow.ShadowMatrices; +import net.coderbot.iris.vendored.joml.Matrix4f; public final class MatrixUniforms { private MatrixUniforms() { @@ -55,7 +54,7 @@ private static class Inverted implements Supplier { @Override public Matrix4f get() { // PERF: Don't copy + allocate these matrices every time? - Matrix4f copy = parent.get().copy(); - Matrix4f previous = this.previous.copy(); + final Matrix4f copy = new Matrix4f(parent.get()); + final Matrix4f prev = new Matrix4f(this.previous); this.previous = copy; - return previous; + return prev; } } } diff --git a/src/main/java/net/coderbot/iris/uniforms/ViewportUniforms.java b/src/main/java/net/coderbot/iris/uniforms/ViewportUniforms.java index 088676ea56..5284eb819f 100644 --- a/src/main/java/net/coderbot/iris/uniforms/ViewportUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/ViewportUniforms.java @@ -24,8 +24,8 @@ public static void addViewportUniforms(UniformHolder uniforms) { // TODO: What about the custom scale.composite3 property? // NB: It is not safe to cache the render target due to mods like Resolution Control modifying the render target field. uniforms - .uniform1f(PER_FRAME, "viewHeight", () -> Minecraft.getInstance().getMainRenderTarget().height) - .uniform1f(PER_FRAME, "viewWidth", () -> Minecraft.getInstance().getMainRenderTarget().width) + .uniform1f(PER_FRAME, "viewHeight", () -> Minecraft.getMinecraft().getFramebuffer().framebufferHeight) + .uniform1f(PER_FRAME, "viewWidth", () -> Minecraft.getMinecraft().getFramebuffer().framebufferWidth) .uniform1f(PER_FRAME, "aspectRatio", ViewportUniforms::getAspectRatio); } @@ -33,6 +33,6 @@ public static void addViewportUniforms(UniformHolder uniforms) { * @return the current viewport aspect ratio, calculated from the current Minecraft window size */ private static float getAspectRatio() { - return ((float) Minecraft.getInstance().getMainRenderTarget().width) / ((float) Minecraft.getInstance().getMainRenderTarget().height); + return ((float) Minecraft.getMinecraft().getFramebuffer().framebufferWidth) / ((float) Minecraft.getMinecraft().getFramebuffer().framebufferHeight); } } diff --git a/src/main/java/net/coderbot/iris/uniforms/WorldTimeUniforms.java b/src/main/java/net/coderbot/iris/uniforms/WorldTimeUniforms.java index 56896cfa9b..36ea411f3e 100644 --- a/src/main/java/net/coderbot/iris/uniforms/WorldTimeUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/WorldTimeUniforms.java @@ -1,15 +1,14 @@ package net.coderbot.iris.uniforms; -import static net.coderbot.iris.gl.uniform.UniformUpdateFrequency.PER_TICK; - -import java.util.Objects; - import net.coderbot.iris.Iris; import net.coderbot.iris.gl.uniform.UniformHolder; -import net.coderbot.iris.mixin.DimensionTypeAccessor; import net.coderbot.iris.shaderpack.DimensionId; import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.multiplayer.WorldClient; + +import java.util.Objects; + +import static net.coderbot.iris.gl.uniform.UniformUpdateFrequency.PER_TICK; public final class WorldTimeUniforms { private WorldTimeUniforms() { @@ -28,7 +27,7 @@ public static void addWorldTimeUniforms(UniformHolder uniforms) { } static int getWorldDayTime() { - long timeOfDay = getWorld().getDayTime(); + long timeOfDay = getWorld().getWorldTime(); if (Iris.getCurrentDimension() == DimensionId.END || Iris.getCurrentDimension() == DimensionId.NETHER) { // If the dimension is the nether or the end, don't override the fixed time. @@ -36,20 +35,21 @@ static int getWorldDayTime() { return (int) (timeOfDay % 24000L); } - long dayTime = ((DimensionTypeAccessor) getWorld().dimensionType()).getFixedTime() - .orElse(timeOfDay % 24000L); + // TODO Was taken from Optifine 1.12 + long dayTime = timeOfDay % 24000L;/*((DimensionTypeAccessor) getWorld().dimensionType()).getFixedTime() + .orElse(timeOfDay % 24000L);*/ return (int) dayTime; } private static int getWorldDay() { - long timeOfDay = getWorld().getDayTime(); + long timeOfDay = getWorld().getWorldTime(); long day = timeOfDay / 24000L; return (int) day; } - private static ClientLevel getWorld() { - return Objects.requireNonNull(Minecraft.getInstance().level); + private static WorldClient getWorld() { + return Objects.requireNonNull(Minecraft.getMinecraft().world); } } diff --git a/src/main/java/net/coderbot/iris/vertices/ExtendingBufferBuilder.java b/src/main/java/net/coderbot/iris/vertices/ExtendingBufferBuilder.java index 7f811a0373..0847b8b6bd 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.mojang.blaze3d.vertex.VertexFormat; +import net.minecraft.client.renderer.vertex.VertexFormat; public interface ExtendingBufferBuilder { void iris$beginWithoutExtending(int drawMode, VertexFormat vertexFormat); diff --git a/src/main/java/net/coderbot/iris/vertices/IrisTextVertexSinkImpl.java b/src/main/java/net/coderbot/iris/vertices/IrisTextVertexSinkImpl.java index 752266b3f1..7bfdd261f7 100644 --- a/src/main/java/net/coderbot/iris/vertices/IrisTextVertexSinkImpl.java +++ b/src/main/java/net/coderbot/iris/vertices/IrisTextVertexSinkImpl.java @@ -1,28 +1,27 @@ package net.coderbot.iris.vertices; -import java.nio.ByteBuffer; -import java.util.function.IntFunction; - -import org.lwjgl.system.MemoryUtil; - -import com.mojang.blaze3d.vertex.VertexFormat; - +import nanolive.compat.CompatMemoryUtil; import net.coderbot.iris.vendored.joml.Vector3f; import net.irisshaders.iris.api.v0.IrisTextVertexSink; +import net.minecraft.client.renderer.vertex.VertexFormat; +import org.lwjgl.system.MemoryUtil; + +import java.nio.ByteBuffer; +import java.util.function.IntFunction; public class IrisTextVertexSinkImpl implements IrisTextVertexSink { static VertexFormat format = IrisVertexFormats.TERRAIN; private final ByteBuffer buffer; private final TextQuadView quad = new TextQuadView(); private final Vector3f saveNormal = new Vector3f(); - private static final int STRIDE = IrisVertexFormats.TERRAIN.getVertexSize(); + private static final int STRIDE = IrisVertexFormats.TERRAIN.getSize(); private int vertexCount; private long elementOffset; private float uSum; private float vSum; public IrisTextVertexSinkImpl(int maxQuadCount, IntFunction buffer) { - this.buffer = buffer.apply(format.getVertexSize() * 4 * maxQuadCount); + this.buffer = buffer.apply(format.getSize() * 4 * maxQuadCount); this.elementOffset = MemoryUtil.memAddress(this.buffer); } @@ -51,20 +50,20 @@ private void vertex(float x, float y, float z, int color, float u, float v, int long i = elementOffset; - MemoryUtil.memPutFloat(i, x); - MemoryUtil.memPutFloat(i + 4, y); - MemoryUtil.memPutFloat(i + 8, z); - MemoryUtil.memPutInt(i + 12, color); - MemoryUtil.memPutFloat(i + 16, u); - MemoryUtil.memPutFloat(i + 20, v); - MemoryUtil.memPutInt(i + 24, light); + CompatMemoryUtil.memPutFloat(i, x); + CompatMemoryUtil.memPutFloat(i + 4, y); + CompatMemoryUtil.memPutFloat(i + 8, z); + CompatMemoryUtil.memPutInt(i + 12, color); + CompatMemoryUtil.memPutFloat(i + 16, u); + CompatMemoryUtil.memPutFloat(i + 20, v); + CompatMemoryUtil.memPutInt(i + 24, light); if (vertexCount == 4) { // TODO: compute this at the head of quad() vertexCount = 0; - uSum *= 0.25; - vSum *= 0.25; - quad.setup(elementOffset, IrisVertexFormats.TERRAIN.getVertexSize()); + uSum *= 0.25F; + vSum *= 0.25F; + quad.setup(elementOffset, IrisVertexFormats.TERRAIN.getSize()); NormalHelper.computeFaceNormal(saveNormal, quad); float normalX = saveNormal.x; @@ -75,10 +74,10 @@ private void vertex(float x, float y, float z, int color, float u, float v, int int tangent = NormalHelper.computeTangent(normalX, normalY, normalZ, quad); for (long vertex = 0; vertex < 4; vertex++) { - MemoryUtil.memPutFloat(i + 36 - STRIDE * vertex, uSum); - MemoryUtil.memPutFloat(i + 40 - STRIDE * vertex, vSum); - MemoryUtil.memPutInt(i + 28 - STRIDE * vertex, normal); - MemoryUtil.memPutInt(i + 44 - STRIDE * vertex, tangent); + CompatMemoryUtil.memPutFloat(i + 36 - STRIDE * vertex, uSum); + CompatMemoryUtil.memPutFloat(i + 40 - STRIDE * vertex, vSum); + CompatMemoryUtil.memPutInt(i + 28 - STRIDE * vertex, normal); + CompatMemoryUtil.memPutInt(i + 44 - STRIDE * vertex, tangent); } uSum = 0; @@ -103,23 +102,23 @@ public void setup(long writePointer, int stride) { } public float x(int index) { - return MemoryUtil.memGetFloat(writePointer - stride * (3L - index)); + return CompatMemoryUtil.memGetFloat(writePointer - stride * (3L - index)); } public float y(int index) { - return MemoryUtil.memGetFloat(writePointer + 4 - stride * (3L - index)); + return CompatMemoryUtil.memGetFloat(writePointer + 4 - stride * (3L - index)); } public float z(int index) { - return MemoryUtil.memGetFloat(writePointer + 8 - stride * (3L - index)); + return CompatMemoryUtil.memGetFloat(writePointer + 8 - stride * (3L - index)); } public float u(int index) { - return MemoryUtil.memGetFloat(writePointer + 16 - stride * (3L - index)); + return CompatMemoryUtil.memGetFloat(writePointer + 16 - stride * (3L - index)); } public float v(int index) { - return MemoryUtil.memGetFloat(writePointer + 20 - stride * (3L - index)); + return CompatMemoryUtil.memGetFloat(writePointer + 20 - stride * (3L - index)); } } } diff --git a/src/main/java/net/coderbot/iris/vertices/IrisVertexFormats.java b/src/main/java/net/coderbot/iris/vertices/IrisVertexFormats.java index cdc76e2404..00c469d4f1 100644 --- a/src/main/java/net/coderbot/iris/vertices/IrisVertexFormats.java +++ b/src/main/java/net/coderbot/iris/vertices/IrisVertexFormats.java @@ -4,6 +4,8 @@ import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.blaze3d.vertex.VertexFormatElement; +import net.minecraft.client.renderer.vertex.VertexFormat; +import net.minecraft.client.renderer.vertex.VertexFormatElement; public class IrisVertexFormats { public static final VertexFormatElement ENTITY_ELEMENT; @@ -15,10 +17,10 @@ public class IrisVertexFormats { public static final VertexFormat ENTITY; static { - ENTITY_ELEMENT = new VertexFormatElement(11, VertexFormatElement.Type.SHORT, VertexFormatElement.Usage.GENERIC, 2); - MID_TEXTURE_ELEMENT = new VertexFormatElement(12, VertexFormatElement.Type.FLOAT, VertexFormatElement.Usage.GENERIC, 2); - TANGENT_ELEMENT = new VertexFormatElement(13, VertexFormatElement.Type.BYTE, VertexFormatElement.Usage.GENERIC, 4); - MID_BLOCK_ELEMENT = new VertexFormatElement(14, VertexFormatElement.Type.BYTE, VertexFormatElement.Usage.GENERIC, 3); + ENTITY_ELEMENT = new VertexFormatElement(11, VertexFormatElement.EnumType.SHORT, VertexFormatElement.EnumUsage.GENERIC, 2); + MID_TEXTURE_ELEMENT = new VertexFormatElement(12, VertexFormatElement.EnumType.FLOAT, VertexFormatElement.EnumUsage.GENERIC, 2); + TANGENT_ELEMENT = new VertexFormatElement(13, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.GENERIC, 4); + MID_BLOCK_ELEMENT = new VertexFormatElement(14, VertexFormatElement.EnumType.BYTE, VertexFormatElement.EnumUsage.GENERIC, 3); ImmutableList.Builder terrainElements = ImmutableList.builder(); ImmutableList.Builder entityElements = ImmutableList.builder(); diff --git a/src/main/java/net/coderbot/iris/vertices/NormI8.java b/src/main/java/net/coderbot/iris/vertices/NormI8.java index d383290ca1..a1de61a4f2 100644 --- a/src/main/java/net/coderbot/iris/vertices/NormI8.java +++ b/src/main/java/net/coderbot/iris/vertices/NormI8.java @@ -1,7 +1,7 @@ package net.coderbot.iris.vertices; import com.mojang.math.Vector3f; -import net.minecraft.util.Mth; +import net.minecraft.util.math.MathHelper; /** * Provides some utilities for working with packed normal vectors. Each normal component provides 8 bits of @@ -60,7 +60,7 @@ public static int packColor(float x, float y, float z, float w) { */ private static int encode(float comp) { // TODO: is the clamp necessary here? our inputs should always be normalized vector components - return ((int) (Mth.clamp(comp, -1.0F, 1.0F) * COMPONENT_RANGE) & 255); + return ((int) (MathHelper.clamp(comp, -1.0F, 1.0F) * COMPONENT_RANGE) & 255); } /** diff --git a/src/main/java/net/coderbot/iris/vertices/NormalHelper.java b/src/main/java/net/coderbot/iris/vertices/NormalHelper.java index ca7f9f80d9..9028028aa9 100644 --- a/src/main/java/net/coderbot/iris/vertices/NormalHelper.java +++ b/src/main/java/net/coderbot/iris/vertices/NormalHelper.java @@ -1,7 +1,5 @@ package net.coderbot.iris.vertices; -import org.jetbrains.annotations.NotNull; - /* * Copyright (c) 2016, 2017, 2018, 2019 FabricMC * @@ -19,7 +17,9 @@ */ import net.coderbot.iris.vendored.joml.Vector3f; -import net.minecraft.util.Mth; +import net.minecraft.util.math.MathHelper; + +import javax.annotation.Nonnull; public abstract class NormalHelper { private NormalHelper() { } @@ -30,10 +30,10 @@ private NormalHelper() { } * The extra value is for use by shaders. */ public static int packNormal(float x, float y, float z, float w) { - x = Mth.clamp(x, -1, 1); - y = Mth.clamp(y, -1, 1); - z = Mth.clamp(z, -1, 1); - w = Mth.clamp(w, -1, 1); + x = MathHelper.clamp(x, -1, 1); + y = MathHelper.clamp(y, -1, 1); + z = MathHelper.clamp(z, -1, 1); + w = MathHelper.clamp(w, -1, 1); return ((int) (x * 127) & 0xFF) | (((int) (y * 127) & 0xFF) << 8) | (((int) (z * 127) & 0xFF) << 16) | (((int) (w * 127) & 0xFF) << 24); } @@ -60,7 +60,7 @@ public static float getPackedNormalComponent(int packedNormal, int component) { *

Assumes counter-clockwise winding order, which is the norm. * Expects convex quads with all points co-planar. */ - public static void computeFaceNormal(@NotNull Vector3f saveTo, QuadView q) { + public static void computeFaceNormal(@Nonnull Vector3f saveTo, QuadView q) { // final Direction nominalFace = q.nominalFace(); // // if (GeometryHelper.isQuadParallelToFace(nominalFace, q)) { @@ -109,7 +109,7 @@ public static void computeFaceNormal(@NotNull Vector3f saveTo, QuadView q) { * *

Assumes counter-clockwise winding order, which is the norm. */ - public static void computeFaceNormalTri(@NotNull Vector3f saveTo, TriView t) { + public static void computeFaceNormalTri(@Nonnull Vector3f saveTo, TriView t) { // final Direction nominalFace = q.nominalFace(); // // if (GeometryHelper.isQuadParallelToFace(nominalFace, q)) { diff --git a/src/main/java/net/irisshaders/iris/api/v0/IrisTextVertexSink.java b/src/main/java/net/irisshaders/iris/api/v0/IrisTextVertexSink.java index d3a940ab4b..bd28bf0a6f 100644 --- a/src/main/java/net/irisshaders/iris/api/v0/IrisTextVertexSink.java +++ b/src/main/java/net/irisshaders/iris/api/v0/IrisTextVertexSink.java @@ -2,7 +2,7 @@ import java.nio.ByteBuffer; -import com.mojang.blaze3d.vertex.VertexFormat; +import net.minecraft.client.renderer.vertex.VertexFormat; public interface IrisTextVertexSink { /** diff --git a/src/main/java/net/irisshaders/iris/api/v0/item/IrisItemLightProvider.java b/src/main/java/net/irisshaders/iris/api/v0/item/IrisItemLightProvider.java index 6609eaeba2..c3c3d780ca 100644 --- a/src/main/java/net/irisshaders/iris/api/v0/item/IrisItemLightProvider.java +++ b/src/main/java/net/irisshaders/iris/api/v0/item/IrisItemLightProvider.java @@ -1,26 +1,27 @@ package net.irisshaders.iris.api.v0.item; -import com.mojang.math.Vector3f; - -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.ItemStack; +import net.coderbot.iris.vendored.joml.Vector3f; +import net.minecraft.block.Block; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; public interface IrisItemLightProvider { Vector3f DEFAULT_LIGHT_COLOR = new Vector3f(1, 1, 1); - default int getLightEmission(Player player, ItemStack stack) { - if (stack.getItem() instanceof BlockItem) { - BlockItem item = (BlockItem)stack.getItem(); + default int getLightEmission(EntityPlayerSP player, ItemStack stack) { + if (stack.getItem() instanceof ItemBlock) { + ItemBlock item = (ItemBlock) stack.getItem(); + Block block = item.getBlock(); - return item.getBlock().defaultBlockState().getLightEmission(); + return block.getDefaultState().getLightValue(); } return 0; } - default Vector3f getLightColor(Player player, ItemStack stack) { + default Vector3f getLightColor(EntityPlayerSP player, ItemStack stack) { return DEFAULT_LIGHT_COLOR; } } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg deleted file mode 100644 index 197cf28f64..0000000000 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ /dev/null @@ -1,35 +0,0 @@ -public com.mojang.blaze3d.platform.GlStateManager$AlphaState -public com.mojang.blaze3d.platform.GlStateManager$BlendState -public com.mojang.blaze3d.platform.GlStateManager$FogState -public com.mojang.blaze3d.platform.GlStateManager$TextureState -public com.mojang.blaze3d.platform.GlStateManager$ColorMask -public com.mojang.blaze3d.platform.GlStateManager$DepthState -public net.minecraft.client.renderer.texture.Stitcher$Holder -public net.minecraft.client.renderer.WorldRenderer$LocalRenderInformationContainer -public-f net.minecraft.client.renderer.WorldRenderer field_228415_m_ # renderBuffers -public-f net.minecraft.client.renderer.texture.TextureAtlasSprite$Info - -public net.minecraft.util.math.vector.Matrix4f field_226575_a_ # m00 -public net.minecraft.util.math.vector.Matrix4f field_226576_b_ # m01 -public net.minecraft.util.math.vector.Matrix4f field_226577_c_ # m02 -public net.minecraft.util.math.vector.Matrix4f field_226578_d_ # m03 -public net.minecraft.util.math.vector.Matrix4f field_226579_e_ # m10 -public net.minecraft.util.math.vector.Matrix4f field_226580_f_ # m11 -public net.minecraft.util.math.vector.Matrix4f field_226581_g_ # m12 -public net.minecraft.util.math.vector.Matrix4f field_226582_h_ # m13 -public net.minecraft.util.math.vector.Matrix4f field_226583_i_ # m20 -public net.minecraft.util.math.vector.Matrix4f field_226584_j_ # m21 -public net.minecraft.util.math.vector.Matrix4f field_226585_k_ # m22 -public net.minecraft.util.math.vector.Matrix4f field_226586_l_ # m23 - -public net.minecraft.util.math.vector.Matrix3f field_226097_a_ # m00 -public net.minecraft.util.math.vector.Matrix3f field_226098_b_ # m01 -public net.minecraft.util.math.vector.Matrix3f field_226099_c_ # m02 -public net.minecraft.util.math.vector.Matrix3f field_226100_d_ # m10 -public net.minecraft.util.math.vector.Matrix3f field_226101_e_ # m11 -public net.minecraft.util.math.vector.Matrix3f field_226102_f_ # m12 -public net.minecraft.util.math.vector.Matrix3f field_226103_g_ # m20 -public net.minecraft.util.math.vector.Matrix3f field_226104_h_ # m21 -public net.minecraft.util.math.vector.Matrix3f field_226105_i_ # m22 - -public net.minecraft.client.renderer.texture.NativeImage field_195722_d # pixels \ No newline at end of file diff --git a/src/main/resources/META-INF/oculus_at.cfg b/src/main/resources/META-INF/oculus_at.cfg new file mode 100644 index 0000000000..4a2b57742c --- /dev/null +++ b/src/main/resources/META-INF/oculus_at.cfg @@ -0,0 +1,12 @@ +public net.minecraft.client.Minecraft field_71428_T # timer + +public net.minecraft.client.renderer.EntityRenderer func_180438_a(Lnet/minecraft/entity/EntityLivingBase;F)F # getNightVisionBrightness + +public net.minecraft.client.renderer.GlStateManager$BooleanState +public net.minecraft.client.renderer.GlStateManager$AlphaState +public net.minecraft.client.renderer.GlStateManager$BlendState +public net.minecraft.client.renderer.GlStateManager$ColorMask +public net.minecraft.client.renderer.GlStateManager$DepthState +public net.minecraft.client.renderer.GlStateManager$FogState +public net.minecraft.client.renderer.GlStateManager$TextureState +public net.minecraft.client.renderer.RenderGlobal$ContainerLocalRenderInformation \ No newline at end of file diff --git a/src/main/resources/mixins.oculus.json b/src/main/resources/mixins.oculus.json index 72da01fdd1..34dd12db39 100644 --- a/src/main/resources/mixins.oculus.json +++ b/src/main/resources/mixins.oculus.json @@ -11,15 +11,16 @@ "LightTextureAccessor", "MixinBlockStateBehavior", "MixinClientLanguage", + "MixinCrashReport", "MixinDebugScreenOverlay", "MixinEntityRenderDispatcher", + "MixinEntityRenderer", "MixinFogRenderer", "MixinGameRenderer", "MixinGameRenderer_NightVisionCompat", - "MixinScreenEffectRenderer", "MixinGlStateManager", - "MixinGlStateManager_AmdCrashFix", "MixinGlStateManager_AlphaTestOverride", + "MixinGlStateManager_AmdCrashFix", "MixinGlStateManager_BlendOverride", "MixinGlStateManager_DepthColorOverride", "MixinGlStateManager_FramebufferBinding", @@ -33,14 +34,13 @@ "MixinParticleEngine", "MixinRenderSystem", "MixinRenderTarget", + "MixinScreenEffectRenderer", "MixinTheEndPortalRenderer", - "MixinTitleScreen", "MixinTweakFarPlane", - "MixinCrashReport", "entity_render_context.MixinBlockEntityRenderDispatcher", "entity_render_context.MixinEntityRenderDispatcher", - "fabulous.MixinDisableFabulousGraphics", "gui.MixinGui", + "gui.MixinGuiIngameForge", "gui.MixinVideoSettingsScreen", "math.MixinMatrix4f", "rendertype.MixinRenderStateShard_Tagging", @@ -55,22 +55,21 @@ "sky.MixinDimensionSpecialEffects", "sky.MixinLevelRenderer_SunMoonToggle", "sky.MixinOptions_CloudsOverride", + "state_tracking.MixinGlStateManager", + "state_tracking.MixinPostChain", + "state_tracking.MixinRenderTarget", "statelisteners.BooleanStateAccessor", "statelisteners.MixinGlStateManager", "texture.AnimationMetadataSectionAccessor", "texture.MixinAbstractTexture", "texture.MixinGlStateManager", - "texture.MixinResourceLocation", "texture.MixinTextureAtlasSprite", "texture.MixinTextureManager", "texture.SimpleTextureAccessor", "texture.TextureAtlasAccessor", "texture.TextureAtlasSpriteAccessor", "texture.pbr.MixinTextureAtlas", - "texture.pbr.MixinTextureAtlasSprite", - "state_tracking.MixinGlStateManager", - "state_tracking.MixinPostChain", - "state_tracking.MixinRenderTarget" + "texture.pbr.MixinTextureAtlasSprite" ], "injectors": { "defaultRequire": 1, diff --git a/src/main/resources/mixins.oculus.vertexformat.json b/src/main/resources/mixins.oculus.vertexformat.json index 38de4a772c..ee1e2e95ae 100644 --- a/src/main/resources/mixins.oculus.vertexformat.json +++ b/src/main/resources/mixins.oculus.vertexformat.json @@ -6,7 +6,6 @@ "client": [ "MixinBufferBuilder", "MixinVertexFormatElement", - "MixinGlStateManager", "MixinVertexBuffer", "MixinVertexFormat", "block_rendering.MixinBufferBuilder_SeparateAo",