Common and version specific shader packages #10

Merged
embeddedt merged 24 commits from mitchej123/celeritas:common-shaders-and-enhancements into stonecutter 2025-03-31 19:52:28 -04:00
440 changed files with 3736 additions and 1506 deletions

No files matched your search

+88
View File
@@ -0,0 +1,88 @@
plugins {
id 'java-library'
id 'maven-publish'
}
group = "org.embeddedt.celeritas"
version = rootProject.version
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
withSourcesJar()
}
repositories {
mavenCentral()
maven {
url = "https://maven.taumc.org/releases"
}
}
dependencies {
implementation(project(":common"))
def lwjglVersion = "3.3.1"
compileOnly "org.lwjgl:lwjgl:${lwjglVersion}"
compileOnly "org.lwjgl:lwjgl-opengl:${lwjglVersion}"
compileOnly "org.joml:joml:1.10.5"
compileOnly "it.unimi.dsi:fastutil:8.5.9"
compileOnly "org.apache.logging.log4j:log4j-api:2.0-beta9"
compileOnly "org.jetbrains:annotations:24.1.0"
compileOnly("org.projectlombok:lombok:1.18.30")
annotationProcessor("org.projectlombok:lombok:1.18.30")
compileOnly("com.google.guava:guava:31.1-jre")
compileOnly("org.ow2.asm:asm:9.6")
compileOnly("org.ow2.asm:asm-tree:9.6")
implementation("org.apache.commons:commons-compress:1.26.0")
def glslTransformLib = "org.taumc:glsl-transformation-lib:${glsl_transformation_lib_version}:fat"
def jcpp = "org.anarres:jcpp:1.4.14"
def shaderDeps = [glslTransformLib, jcpp]
shaderDeps.forEach {
implementation(it)
// TODO: Shadow
// shadow(it) {
// transitive = false
// }
}
}
// TODO: Make this depend also on :common
evaluationDependsOn(":common")
publishing {
publications {
mavenJava(MavenPublication) {
artifactId 'celeritas-common-shaders'
from components.java
}
}
repositories {
maven {
name = "taumcRepository"
url = uri("https://maven.taumc.org/releases")
credentials {
username = System.getenv("MAVEN_USERNAME")
password = System.getenv("MAVEN_SECRET")
}
authentication {
basic(BasicAuthentication)
}
}
}
}
tasks.withType(Jar).configureEach {
from(rootProject.file("COPYING"))
from(rootProject.file("COPYING.LESSER"))
}
jar {
manifest {
attributes([
"Lwjgl3ify-Aware": "true"
])
}
}
@@ -0,0 +1,92 @@
package com.mitchej123.glsm;
import net.irisshaders.iris.gl.blending.BlendMode;
import net.irisshaders.iris.gl.blending.ColorMask;
import java.util.ServiceLoader;
public interface GLStateManagerService {
GLStateManagerService GL_STATE_MANAGER = ServiceLoader.load(GLStateManagerService.class).findFirst().orElseThrow();
int glGetInteger(int pname);
String glGetString(int pname);
void glBindFramebuffer(int target, int framebuffer);
int glCheckFramebufferStatus(int target);
void glDeleteFramebuffers(int framebuffer);
int glGenFramebuffers();
int glGetProgrami(int program, int pname);
void glAttachShader(int program, int shader);
void glDeleteShader(int shader);
int glCreateShader(int type);
void glCompileShader(int shader);
int glGetShaderi(int shader, int pname);
void glUseProgram(int program);
int glCreateProgram();
void glDeleteProgram(int program);
void glLinkProgram(int program);
int glGetUniformLocation(int program, CharSequence name);
void glUniform1i(int location, int value);
int glGetAttribLocation(int program, CharSequence name);
void glBindAttribLocation(int program, int index, CharSequence name);
int glGenVertexArrays();
void glBindVertexArray(int array);
void glCopyTexSubImage2D(int target, int level, int xoffset, int yoffset, int x, int y, int width, int height);
void enableCullFace();
void disableCullFace();
void enableBlend();
void disableBlend();
void glBlendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha, int dstAlpha);
void enableDepthTest();
void disableDepthTest();
void glDepthFunc(int func);
void glDepthMask(boolean flag);
void glViewport(int x, int y, int width, int height);
void glColorMask(boolean red, boolean green, boolean blue, boolean alpha);
void glClearColor(float red, float green, float blue, float alpha);
int glGetTexLevelParameteri(int target, int level, int pname);
void glFramebufferTexture2D(int target, int attachment, int textarget, int texture, int level);
int glGenTextures();
void glGenTextures(int[] textures);
void glDeleteTextures(int texture);
void glDeleteTextures(int[] textures);
void glActiveTexture(int texture);
int glGenBuffers();
void glBindBuffer(int target, int buffer);
void glPixelStorei(int pname, int param);
// Mojang & Non-Standard
void clear(int mask, boolean checkError); // Non-standard signature
void bindTexture(int texture); // Non-standard signature
int getActiveTexture(); // Mojang Addition
int getActiveTextureAccessor(); // Mojang Addition
int getBoundTexture(int internalUnit); // Mojang Addition
int getActiveBoundTexture(); // Mojang Addition
int getViewportWidth(); // Mojang Addition
int getViewportHeight(); // Mojang Addition
boolean getDepthStateMask();
boolean isBlendEnabled();
BlendMode getBlendMode();
ColorMask getColorMask();
void setBoundTexture(int unit, int texture);
}
@@ -0,0 +1,63 @@
package com.mitchej123.glsm;
import java.nio.FloatBuffer;
import java.util.ServiceLoader;
import org.joml.Matrix4f;
public interface RenderSystemService {
RenderSystemService RENDER_SYSTEM = ServiceLoader.load(RenderSystemService.class).findFirst().orElseThrow();
void glActiveTexture(int texture);
void enableCullFace();
void disableCullFace();
void enableBlend();
void disableBlend();
void setUnknownBlendState(); // Mojang Addition
void enableDepthTest();
void disableDepthTest();
void depthFunc(int depthFunc);
void depthMask(boolean flag);
void glViewport(int x, int y, int width, int height);
void bindTexture(int texture); // Non-standard
void glUniform1i(int location, int value);
void glUniformMatrix3(int location, boolean transpose, FloatBuffer value);
void glUniformMatrix4(int location, boolean transpose, FloatBuffer value);
void glClearColor(float red, float green, float blue, float alpha);
// Mojang Implementations
void clear(int mask, boolean checkError); // Non-standard
void assertOnRenderThread();
void assertOnRenderThreadOrInit();
// TODO: Figure out ResourceLocation, etc
// void setShaderTexture(int shaderTexture, ResourceLocation textureId)
void setShaderTexture(int shaderTexture, int textureId);
int getShaderTexture(int shaderTexture);
void setShaderColor(float red, float green, float blue, float alpha);
float[] getShaderFogColor();
float getShaderFogStart();
float getShaderFogEnd();
int getFogShape();
float getShaderLineWidth();
Matrix4f getProjectionMatrix();
void setProjectionMatrixOrth(Matrix4f projectionMatrix);
void setProjectionMatrixOrigin(Matrix4f projectionMatrix);
// TODO: Figure out VertexSorting type
// void setProjectionMatrix(Matrix4f projectionMatrix, VertexSorting vertexSorting)
// TODO: Figure out FogShape
// FogShape getShaderFogShape()
}
@@ -0,0 +1,18 @@
package net.irisshaders.iris;
import java.nio.file.Path;
import static org.embeddedt.embeddium.compat.mc.PlatformUtilService.PLATFORM_UTIL;
public class IrisCommon {
public static final float DEGREES_TO_RADIANS = (float)Math.PI / 180.0F;
private static Path shaderpacksDirectory;
public static Path getShaderpacksDirectory() {
if (shaderpacksDirectory == null) {
shaderpacksDirectory = PLATFORM_UTIL.getGameDir().resolve("shaderpacks");
}
return shaderpacksDirectory;
}
}
@@ -0,0 +1,18 @@
package net.irisshaders.iris;
public class IrisConstants {
public static final String MODID = "embeddium";
/**
* The user-facing name of the mod. Moved into a constant to facilitate
* easy branding changes (for forks). You'll still need to change this
* separately in mixin plugin classes & the language files.
*/
public static final String MODNAME = "Celeritas";
public static final float DEPTH = 0.125F;
// Bump this up if you want more shadow color buffers!
// This is currently set at 2 for ShadersMod / OptiFine parity but can theoretically be bumped up to 8.
// TODO: Make this configurable?
public static final int MAX_SHADOW_COLOR_BUFFERS_IRIS = 8;
public static final int MAX_SHADOW_COLOR_BUFFERS_OF = 2;
}
@@ -1,24 +1,29 @@
package net.irisshaders.iris; package net.irisshaders.iris;
import com.mojang.logging.LogUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
public class IrisLogging { public class IrisLogging {
public static final IrisLogging IRIS_LOGGER = new IrisLogging(IrisConstants.MODNAME);
public static boolean ENABLE_SPAM = false; // FabricLoader.getInstance().isDevelopmentEnvironment(); public static boolean ENABLE_SPAM = false; // FabricLoader.getInstance().isDevelopmentEnvironment();
public static final Marker FATAL_MARKER = MarkerFactory.getMarker("FATAL");
private final Logger logger; private final Logger logger;
public IrisLogging(String loggerName) { private IrisLogging(String loggerName) {
this.logger = LoggerFactory.getLogger(loggerName); this.logger = LoggerFactory.getLogger(loggerName);
} }
public void fatal(String fatal) { public void fatal(String fatal) {
this.logger.error(LogUtils.FATAL_MARKER, fatal); this.logger.error(FATAL_MARKER, fatal);
} }
public void fatal(String fatal, Throwable t) { public void fatal(String fatal, Throwable t) {
this.logger.error(LogUtils.FATAL_MARKER, fatal, t); this.logger.error(FATAL_MARKER, fatal, t);
} }
public void error(String error) { public void error(String error) {
@@ -2,7 +2,6 @@ package net.irisshaders.iris.config;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.gui.option.IrisVideoSettings; import net.irisshaders.iris.gui.option.IrisVideoSettings;
import net.irisshaders.iris.pathways.colorspace.ColorSpace; import net.irisshaders.iris.pathways.colorspace.ColorSpace;
@@ -14,6 +13,8 @@ import java.nio.file.Path;
import java.util.Optional; import java.util.Optional;
import java.util.Properties; import java.util.Properties;
import static net.irisshaders.iris.IrisLogging.IRIS_LOGGER;
/** /**
* A class dedicated to storing the config values of shaderpacks. Right now it only stores the path to the current shaderpack * A class dedicated to storing the config values of shaderpacks. Right now it only stores the path to the current shaderpack
*/ */
@@ -154,7 +155,7 @@ public class IrisConfig {
IrisVideoSettings.shadowDistance = Integer.parseInt(properties.getProperty("maxShadowRenderDistance", "32")); IrisVideoSettings.shadowDistance = Integer.parseInt(properties.getProperty("maxShadowRenderDistance", "32"));
IrisVideoSettings.colorSpace = ColorSpace.valueOf(properties.getProperty("colorSpace", "SRGB")); IrisVideoSettings.colorSpace = ColorSpace.valueOf(properties.getProperty("colorSpace", "SRGB"));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Iris.logger.error("Shadow distance setting reset; value is invalid."); IRIS_LOGGER.error("Shadow distance setting reset; value is invalid.");
IrisVideoSettings.shadowDistance = 32; IrisVideoSettings.shadowDistance = 32;
IrisVideoSettings.colorSpace = ColorSpace.SRGB; IrisVideoSettings.colorSpace = ColorSpace.SRGB;
save(); save();
@@ -1,13 +1,14 @@
package net.irisshaders.iris.features; package net.irisshaders.iris.features;
import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.IrisRenderSystem;
import net.minecraft.client.resources.language.I18n;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
public enum FeatureFlags { public enum FeatureFlags {
SEPARATE_HARDWARE_SAMPLERS(() -> true, () -> true), SEPARATE_HARDWARE_SAMPLERS(() -> true, () -> true),
HIGHER_SHADOWCOLOR(() -> true, () -> true), HIGHER_SHADOWCOLOR(() -> true, () -> true),
@@ -39,12 +40,12 @@ public enum FeatureFlags {
if (unsupportedIris) { if (unsupportedIris) {
if (unsupportedHardware) { if (unsupportedHardware) {
return I18n.get("iris.unsupported.irisorpc"); return MINECRAFT_SHIM.translate("iris.unsupported.irisorpc");
} }
return I18n.get("iris.unsupported.iris"); return MINECRAFT_SHIM.translate("iris.unsupported.iris");
} else if (unsupportedHardware) { } else if (unsupportedHardware) {
return I18n.get("iris.unsupported.pc"); return MINECRAFT_SHIM.translate("iris.unsupported.pc");
} else { } else {
return null; return null;
} }
@@ -1,32 +1,21 @@
package net.irisshaders.iris.gl; package net.irisshaders.iris.gl;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.gl.sampler.SamplerLimits;
import net.irisshaders.iris.mixin.GlStateManagerAccessor;
import net.minecraft.client.Minecraft;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.joml.Vector3i;
import org.lwjgl.opengl.ARBDirectStateAccess;
import org.lwjgl.opengl.ARBDrawBuffersBlend;
import org.lwjgl.opengl.EXTShaderImageLoadStore;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL30C;
import org.lwjgl.opengl.GL32C;
import org.lwjgl.opengl.GL33C;
import org.lwjgl.opengl.GL42C;
import org.lwjgl.opengl.GL43C;
import org.lwjgl.opengl.GL45C;
import org.lwjgl.opengl.GL46C;
import org.lwjgl.opengl.NVXGPUMemoryInfo;
import org.lwjgl.system.MemoryUtil;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
import static net.irisshaders.iris.IrisLogging.IRIS_LOGGER;
import net.irisshaders.iris.gl.sampler.SamplerLimits;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.joml.Vector3i;
import org.lwjgl.opengl.*;
import org.lwjgl.system.MemoryUtil;
/** /**
* This class is responsible for abstracting calls to OpenGL and asserting that calls are run on the render thread. * This class is responsible for abstracting calls to OpenGL and asserting that calls are run on the render thread.
*/ */
@@ -44,13 +33,13 @@ public class IrisRenderSystem {
public static void initRenderer() { public static void initRenderer() {
if (GL.getCapabilities().OpenGL45) { if (GL.getCapabilities().OpenGL45) {
dsaState = new DSACore(); dsaState = new DSACore();
Iris.logger.info("OpenGL 4.5 detected, enabling DSA."); IRIS_LOGGER.info("OpenGL 4.5 detected, enabling DSA.");
} else if (GL.getCapabilities().GL_ARB_direct_state_access) { } else if (GL.getCapabilities().GL_ARB_direct_state_access) {
dsaState = new DSAARB(); dsaState = new DSAARB();
Iris.logger.info("ARB_direct_state_access detected, enabling DSA."); IRIS_LOGGER.info("ARB_direct_state_access detected, enabling DSA.");
} else { } else {
dsaState = new DSAUnsupported(); dsaState = new DSAUnsupported();
Iris.logger.info("DSA support not detected."); IRIS_LOGGER.info("DSA support not detected.");
} }
hasMultibind = GL.getCapabilities().OpenGL45 || GL.getCapabilities().GL_ARB_multi_bind; hasMultibind = GL.getCapabilities().OpenGL45 || GL.getCapabilities().GL_ARB_multi_bind;
@@ -62,90 +51,90 @@ public class IrisRenderSystem {
} }
public static void getIntegerv(int pname, int[] params) { public static void getIntegerv(int pname, int[] params) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glGetIntegerv(pname, params); GL32C.glGetIntegerv(pname, params);
} }
public static void getFloatv(int pname, float[] params) { public static void getFloatv(int pname, float[] params) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glGetFloatv(pname, params); GL32C.glGetFloatv(pname, params);
} }
public static void generateMipmaps(int texture, int mipmapTarget) { public static void generateMipmaps(int texture, int mipmapTarget) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
dsaState.generateMipmaps(texture, mipmapTarget); dsaState.generateMipmaps(texture, mipmapTarget);
} }
public static void bindAttributeLocation(int program, int index, CharSequence name) { public static void bindAttributeLocation(int program, int index, CharSequence name) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glBindAttribLocation(program, index, name); GL32C.glBindAttribLocation(program, index, name);
} }
public static void texImage1D(int texture, int target, int level, int internalformat, int width, int border, int format, int type, @Nullable ByteBuffer pixels) { public static void texImage1D(int texture, int target, int level, int internalformat, int width, int border, int format, int type, @Nullable ByteBuffer pixels) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
IrisRenderSystem.bindTextureForSetup(target, texture); IrisRenderSystem.bindTextureForSetup(target, texture);
GL30C.glTexImage1D(target, level, internalformat, width, border, format, type, pixels); GL30C.glTexImage1D(target, level, internalformat, width, border, format, type, pixels);
} }
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) { 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.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
IrisRenderSystem.bindTextureForSetup(target, texture); IrisRenderSystem.bindTextureForSetup(target, texture);
GL32C.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); GL32C.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
} }
public static void texImage3D(int texture, int target, int level, int internalformat, int width, int height, int depth, int border, int format, int type, @Nullable ByteBuffer pixels) { public static void texImage3D(int texture, int target, int level, int internalformat, int width, int height, int depth, int border, int format, int type, @Nullable ByteBuffer pixels) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
IrisRenderSystem.bindTextureForSetup(target, texture); IrisRenderSystem.bindTextureForSetup(target, texture);
GL30C.glTexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels); GL30C.glTexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
} }
public static void uniformMatrix4fv(int location, boolean transpose, FloatBuffer matrix) { public static void uniformMatrix4fv(int location, boolean transpose, FloatBuffer matrix) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glUniformMatrix4fv(location, transpose, matrix); GL32C.glUniformMatrix4fv(location, transpose, matrix);
} }
public static void copyTexImage2D(int target, int level, int internalFormat, int x, int y, int width, int height, int border) { public static void copyTexImage2D(int target, int level, int internalFormat, int x, int y, int width, int height, int border) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border); GL32C.glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border);
} }
public static void uniform1f(int location, float v0) { public static void uniform1f(int location, float v0) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glUniform1f(location, v0); GL32C.glUniform1f(location, v0);
} }
public static void uniform2f(int location, float v0, float v1) { public static void uniform2f(int location, float v0, float v1) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glUniform2f(location, v0, v1); GL32C.glUniform2f(location, v0, v1);
} }
public static void uniform2i(int location, int v0, int v1) { public static void uniform2i(int location, int v0, int v1) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glUniform2i(location, v0, v1); GL32C.glUniform2i(location, v0, v1);
} }
public static void uniform3f(int location, float v0, float v1, float v2) { public static void uniform3f(int location, float v0, float v1, float v2) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glUniform3f(location, v0, v1, v2); GL32C.glUniform3f(location, v0, v1, v2);
} }
public static void uniform3i(int location, int v0, int v1, int v2) { public static void uniform3i(int location, int v0, int v1, int v2) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glUniform3i(location, v0, v1, v2); GL32C.glUniform3i(location, v0, v1, v2);
} }
public static void uniform4f(int location, float v0, float v1, float v2, float v3) { public static void uniform4f(int location, float v0, float v1, float v2, float v3) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glUniform4f(location, v0, v1, v2, v3); GL32C.glUniform4f(location, v0, v1, v2, v3);
} }
public static void uniform4i(int location, int v0, int v1, int v2, int v3) { public static void uniform4i(int location, int v0, int v1, int v2, int v3) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glUniform4i(location, v0, v1, v2, v3); GL32C.glUniform4i(location, v0, v1, v2, v3);
} }
public static void texParameteriv(int texture, int target, int pname, int[] params) { public static void texParameteriv(int texture, int target, int pname, int[] params) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
dsaState.texParameteriv(texture, target, pname, params); dsaState.texParameteriv(texture, target, pname, params);
} }
@@ -153,7 +142,7 @@ public class IrisRenderSystem {
* Internal API for use when you don't know the target texture. Should use {@link IrisRenderSystem#texParameteriv(int, int, int, int[])} instead unless you know what you're doing! * Internal API for use when you don't know the target texture. Should use {@link IrisRenderSystem#texParameteriv(int, int, int, int[])} instead unless you know what you're doing!
*/ */
public static void texParameterivDirect(int target, int pname, int[] params) { public static void texParameterivDirect(int target, int pname, int[] params) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glTexParameteriv(target, pname, params); GL32C.glTexParameteriv(target, pname, params);
} }
@@ -162,73 +151,73 @@ public class IrisRenderSystem {
} }
public static void texParameteri(int texture, int target, int pname, int param) { public static void texParameteri(int texture, int target, int pname, int param) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
dsaState.texParameteri(texture, target, pname, param); dsaState.texParameteri(texture, target, pname, param);
} }
public static void texParameterf(int texture, int target, int pname, float param) { public static void texParameterf(int texture, int target, int pname, float param) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
dsaState.texParameterf(texture, target, pname, param); dsaState.texParameterf(texture, target, pname, param);
} }
public static String getProgramInfoLog(int program) { public static String getProgramInfoLog(int program) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
return GL32C.glGetProgramInfoLog(program); return GL32C.glGetProgramInfoLog(program);
} }
public static String getShaderInfoLog(int shader) { public static String getShaderInfoLog(int shader) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
return GL32C.glGetShaderInfoLog(shader); return GL32C.glGetShaderInfoLog(shader);
} }
public static void drawBuffers(int framebuffer, int[] buffers) { public static void drawBuffers(int framebuffer, int[] buffers) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
dsaState.drawBuffers(framebuffer, buffers); dsaState.drawBuffers(framebuffer, buffers);
} }
public static void readBuffer(int framebuffer, int buffer) { public static void readBuffer(int framebuffer, int buffer) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
dsaState.readBuffer(framebuffer, buffer); dsaState.readBuffer(framebuffer, buffer);
} }
public static String getActiveUniform(int program, int index, int size, IntBuffer type, IntBuffer name) { public static String getActiveUniform(int program, int index, int size, IntBuffer type, IntBuffer name) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
return GL32C.glGetActiveUniform(program, index, size, type, name); return GL32C.glGetActiveUniform(program, index, size, type, name);
} }
public static void readPixels(int x, int y, int width, int height, int format, int type, float[] pixels) { public static void readPixels(int x, int y, int width, int height, int format, int type, float[] pixels) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glReadPixels(x, y, width, height, format, type, pixels); GL32C.glReadPixels(x, y, width, height, format, type, pixels);
} }
public static void bufferData(int target, float[] data, int usage) { public static void bufferData(int target, float[] data, int usage) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glBufferData(target, data, usage); GL32C.glBufferData(target, data, usage);
} }
public static int bufferStorage(int target, float[] data, int usage) { public static int bufferStorage(int target, float[] data, int usage) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
return dsaState.bufferStorage(target, data, usage); return dsaState.bufferStorage(target, data, usage);
} }
public static void bufferStorage(int target, long size, int flags) { public static void bufferStorage(int target, long size, int flags) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
// The ARB version is identical to GL44 and redirects, so this should work on ARB as well. // The ARB version is identical to GL44 and redirects, so this should work on ARB as well.
GL45C.glBufferStorage(target, size, flags); GL45C.glBufferStorage(target, size, flags);
} }
public static void bindBufferBase(int target, Integer index, int buffer) { public static void bindBufferBase(int target, Integer index, int buffer) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL43C.glBindBufferBase(target, index, buffer); GL43C.glBindBufferBase(target, index, buffer);
} }
public static void vertexAttrib4f(int index, float v0, float v1, float v2, float v3) { public static void vertexAttrib4f(int index, float v0, float v1, float v2, float v3) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glVertexAttrib4f(index, v0, v1, v2, v3); GL32C.glVertexAttrib4f(index, v0, v1, v2, v3);
} }
public static void detachShader(int program, int shader) { public static void detachShader(int program, int shader) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glDetachShader(program, shader); GL32C.glDetachShader(program, shader);
} }
@@ -237,12 +226,12 @@ public class IrisRenderSystem {
} }
public static int getTexParameteri(int texture, int target, int pname) { public static int getTexParameteri(int texture, int target, int pname) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
return dsaState.getTexParameteri(texture, target, pname); return dsaState.getTexParameteri(texture, target, pname);
} }
public static void bindImageTexture(int unit, int texture, int level, boolean layered, int layer, int access, int format) { public static void bindImageTexture(int unit, int texture, int level, boolean layered, int layer, int access, int format) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
if (GL.getCapabilities().OpenGL42 || GL.getCapabilities().GL_ARB_shader_image_load_store) { if (GL.getCapabilities().OpenGL42 || GL.getCapabilities().GL_ARB_shader_image_load_store) {
GL42C.glBindImageTexture(unit, texture, level, layered, layer, access, format); GL42C.glBindImageTexture(unit, texture, level, layered, layer, access, format);
} else { } else {
@@ -252,9 +241,9 @@ public class IrisRenderSystem {
public static int getMaxImageUnits() { public static int getMaxImageUnits() {
if (GL.getCapabilities().OpenGL42 || GL.getCapabilities().GL_ARB_shader_image_load_store) { if (GL.getCapabilities().OpenGL42 || GL.getCapabilities().GL_ARB_shader_image_load_store) {
return GlStateManager._getInteger(GL42C.GL_MAX_IMAGE_UNITS); return GL_STATE_MANAGER.glGetInteger(GL42C.GL_MAX_IMAGE_UNITS);
} else if (GL.getCapabilities().GL_EXT_shader_image_load_store) { } else if (GL.getCapabilities().GL_EXT_shader_image_load_store) {
return GlStateManager._getInteger(EXTShaderImageLoadStore.GL_MAX_IMAGE_UNITS_EXT); return GL_STATE_MANAGER.glGetInteger(EXTShaderImageLoadStore.GL_MAX_IMAGE_UNITS_EXT);
} else { } else {
return 0; return 0;
} }
@@ -289,7 +278,7 @@ public class IrisRenderSystem {
} }
public static void memoryBarrier(int barriers) { public static void memoryBarrier(int barriers) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
if (supportsCompute) { if (supportsCompute) {
GL45C.glMemoryBarrier(barriers); GL45C.glMemoryBarrier(barriers);
@@ -301,19 +290,19 @@ public class IrisRenderSystem {
} }
public static void disableBufferBlend(int buffer) { public static void disableBufferBlend(int buffer) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glDisablei(GL32C.GL_BLEND, buffer); GL32C.glDisablei(GL32C.GL_BLEND, buffer);
((BooleanStateExtended) GlStateManagerAccessor.getBLEND().mode).setUnknownState(); RENDER_SYSTEM.setUnknownBlendState();
} }
public static void enableBufferBlend(int buffer) { public static void enableBufferBlend(int buffer) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glEnablei(GL32C.GL_BLEND, buffer); GL32C.glEnablei(GL32C.GL_BLEND, buffer);
((BooleanStateExtended) GlStateManagerAccessor.getBLEND().mode).setUnknownState(); RENDER_SYSTEM.setUnknownBlendState();
} }
public static void blendFuncSeparatei(int buffer, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) { public static void blendFuncSeparatei(int buffer, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
ARBDrawBuffersBlend.glBlendFuncSeparateiARB(buffer, srcRGB, dstRGB, srcAlpha, dstAlpha); ARBDrawBuffersBlend.glBlendFuncSeparateiARB(buffer, srcRGB, dstRGB, srcAlpha, dstAlpha);
} }
@@ -324,22 +313,22 @@ public class IrisRenderSystem {
} }
public static int getUniformBlockIndex(int program, String uniformBlockName) { public static int getUniformBlockIndex(int program, String uniformBlockName) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
return GL32C.glGetUniformBlockIndex(program, uniformBlockName); return GL32C.glGetUniformBlockIndex(program, uniformBlockName);
} }
public static void uniformBlockBinding(int program, int uniformBlockIndex, int uniformBlockBinding) { public static void uniformBlockBinding(int program, int uniformBlockIndex, int uniformBlockBinding) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glUniformBlockBinding(program, uniformBlockIndex, uniformBlockBinding); GL32C.glUniformBlockBinding(program, uniformBlockIndex, uniformBlockBinding);
} }
public static void setShadowProjection(Matrix4f shadowProjection) { public static void setShadowProjection(Matrix4f shadowProjection) {
backupProjection = RenderSystem.getProjectionMatrix(); backupProjection = RENDER_SYSTEM.getProjectionMatrix();
RenderSystem.setProjectionMatrix(shadowProjection/*? if >=1.20 {*/, com.mojang.blaze3d.vertex.VertexSorting.ORTHOGRAPHIC_Z/*?}*/); RENDER_SYSTEM.setProjectionMatrixOrth(shadowProjection);
} }
public static void restorePlayerProjection() { public static void restorePlayerProjection() {
RenderSystem.setProjectionMatrix(backupProjection/*? if >=1.20 {*/, com.mojang.blaze3d.vertex.VertexSorting.DISTANCE_TO_ORIGIN/*?}*/); RENDER_SYSTEM.setProjectionMatrixOrigin(backupProjection);
backupProjection = null; backupProjection = null;
} }
@@ -421,7 +410,7 @@ public class IrisRenderSystem {
} }
public static void deleteBuffers(int glId) { public static void deleteBuffers(int glId) {
RenderSystem.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL43C.glDeleteBuffers(glId); GL43C.glDeleteBuffers(glId);
} }
@@ -457,12 +446,12 @@ public class IrisRenderSystem {
private static boolean cullingState; private static boolean cullingState;
public static void backupAndDisableCullingState(boolean b) { public static void backupAndDisableCullingState(boolean b) {
cullingState = Minecraft.getInstance().smartCull; cullingState = MINECRAFT_SHIM.getSmartCull();
Minecraft.getInstance().smartCull = Minecraft.getInstance().smartCull && !b; MINECRAFT_SHIM.setSmartCull(cullingState && !b);
} }
public static void restoreCullingState() { public static void restoreCullingState() {
Minecraft.getInstance().smartCull = cullingState; MINECRAFT_SHIM.setSmartCull(cullingState);
cullingState = true; cullingState = true;
} }
@@ -546,14 +535,14 @@ public class IrisRenderSystem {
@Override @Override
public void bindTextureToUnit(int target, int unit, int texture) { public void bindTextureToUnit(int target, int unit, int texture) {
if (GlStateManagerAccessor.getTEXTURES()[unit].binding == texture) { if (GL_STATE_MANAGER.getBoundTexture(unit) == texture) {
return; return;
} }
ARBDirectStateAccess.glBindTextureUnit(unit, texture); ARBDirectStateAccess.glBindTextureUnit(unit, texture);
// Manually fix GLStateManager bindings... // Manually fix GLStateManager bindings...
GlStateManagerAccessor.getTEXTURES()[unit].binding = texture; GL_STATE_MANAGER.setBoundTexture(unit, texture);
} }
@Override @Override
@@ -592,7 +581,7 @@ public class IrisRenderSystem {
public static class DSAUnsupported implements DSAAccess { public static class DSAUnsupported implements DSAAccess {
@Override @Override
public void generateMipmaps(int texture, int target) { public void generateMipmaps(int texture, int target) {
GlStateManager._bindTexture(texture); GL_STATE_MANAGER.bindTexture(texture);
GL32C.glGenerateMipmap(target); GL32C.glGenerateMipmap(target);
} }
@@ -616,13 +605,13 @@ public class IrisRenderSystem {
@Override @Override
public void readBuffer(int framebuffer, int buffer) { public void readBuffer(int framebuffer, int buffer) {
GlStateManager._glBindFramebuffer(GL32C.GL_FRAMEBUFFER, framebuffer); GL_STATE_MANAGER.glBindFramebuffer(GL32C.GL_FRAMEBUFFER, framebuffer);
GL32C.glReadBuffer(buffer); GL32C.glReadBuffer(buffer);
} }
@Override @Override
public void drawBuffers(int framebuffer, int[] buffers) { public void drawBuffers(int framebuffer, int[] buffers) {
GlStateManager._glBindFramebuffer(GL32C.GL_FRAMEBUFFER, framebuffer); GL_STATE_MANAGER.glBindFramebuffer(GL32C.GL_FRAMEBUFFER, framebuffer);
GL32C.glDrawBuffers(buffers); GL32C.glDrawBuffers(buffers);
} }
@@ -634,60 +623,60 @@ public class IrisRenderSystem {
@Override @Override
public void copyTexSubImage2D(int destTexture, int target, int i, int i1, int i2, int i3, int i4, int width, int height) { public void copyTexSubImage2D(int destTexture, int target, int i, int i1, int i2, int i3, int i4, int width, int height) {
int previous = GlStateManagerAccessor.getTEXTURES()[GlStateManagerAccessor.getActiveTexture()].binding; int previous = GL_STATE_MANAGER.getActiveBoundTexture();
GlStateManager._bindTexture(destTexture); GL_STATE_MANAGER.bindTexture(destTexture);
GL32C.glCopyTexSubImage2D(target, i, i1, i2, i3, i4, width, height); GL32C.glCopyTexSubImage2D(target, i, i1, i2, i3, i4, width, height);
GlStateManager._bindTexture(previous); GL_STATE_MANAGER.bindTexture(previous);
} }
@Override @Override
public void bindTextureToUnit(int target, int unit, int texture) { public void bindTextureToUnit(int target, int unit, int texture) {
int activeTexture = GlStateManager._getActiveTexture(); int activeTexture = GL_STATE_MANAGER.getActiveTexture();
GlStateManager._activeTexture(GL30C.GL_TEXTURE0 + unit); GL_STATE_MANAGER.glActiveTexture(GL30C.GL_TEXTURE0 + unit);
bindTextureForSetup(target, texture); bindTextureForSetup(target, texture);
GlStateManager._activeTexture(activeTexture); GL_STATE_MANAGER.glActiveTexture(activeTexture);
} }
@Override @Override
public int bufferStorage(int target, float[] data, int usage) { public int bufferStorage(int target, float[] data, int usage) {
int buffer = GlStateManager._glGenBuffers(); int buffer = GL_STATE_MANAGER.glGenBuffers();
GlStateManager._glBindBuffer(target, buffer); GL_STATE_MANAGER.glBindBuffer(target, buffer);
bufferData(target, data, usage); bufferData(target, data, usage);
GlStateManager._glBindBuffer(target, 0); GL_STATE_MANAGER.glBindBuffer(target, 0);
return buffer; return buffer;
} }
@Override @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) { 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(GL32C.GL_READ_FRAMEBUFFER, source); GL_STATE_MANAGER.glBindFramebuffer(GL32C.GL_READ_FRAMEBUFFER, source);
GlStateManager._glBindFramebuffer(GL32C.GL_DRAW_FRAMEBUFFER, dest); GL_STATE_MANAGER.glBindFramebuffer(GL32C.GL_DRAW_FRAMEBUFFER, dest);
GL32C.glBlitFramebuffer(offsetX, offsetY, width, height, offsetX2, offsetY2, width2, height2, bufferChoice, filter); GL32C.glBlitFramebuffer(offsetX, offsetY, width, height, offsetX2, offsetY2, width2, height2, bufferChoice, filter);
} }
@Override @Override
public void framebufferTexture2D(int fb, int fbtarget, int attachment, int target, int texture, int levels) { public void framebufferTexture2D(int fb, int fbtarget, int attachment, int target, int texture, int levels) {
GlStateManager._glBindFramebuffer(fbtarget, fb); GL_STATE_MANAGER.glBindFramebuffer(fbtarget, fb);
GL32C.glFramebufferTexture2D(fbtarget, attachment, target, texture, levels); GL32C.glFramebufferTexture2D(fbtarget, attachment, target, texture, levels);
} }
@Override @Override
public int createFramebuffer() { public int createFramebuffer() {
int framebuffer = GlStateManager.glGenFramebuffers(); int framebuffer = GL_STATE_MANAGER.glGenFramebuffers();
GlStateManager._glBindFramebuffer(GL32C.GL_FRAMEBUFFER, framebuffer); GL_STATE_MANAGER.glBindFramebuffer(GL32C.GL_FRAMEBUFFER, framebuffer);
return framebuffer; return framebuffer;
} }
@Override @Override
public int createTexture(int target) { public int createTexture(int target) {
int texture = GlStateManager._genTexture(); int texture = GL_STATE_MANAGER.glGenTextures();
GlStateManager._bindTexture(texture); GL_STATE_MANAGER.bindTexture(texture);
return texture; return texture;
} }
@Override @Override
public int createBuffers() { public int createBuffers() {
int value = GlStateManager._glGenBuffers(); int value = GL_STATE_MANAGER.glGenBuffers();
return value; return value;
} }
} }
@@ -703,8 +692,8 @@ public class IrisRenderSystem {
} }
} else { } else {
for (int binding : bindings) { for (int binding : bindings) {
GlStateManager._activeTexture(startingTexture); GL_STATE_MANAGER.glActiveTexture(startingTexture);
GlStateManager._bindTexture(binding); GL_STATE_MANAGER.bindTexture(binding);
startingTexture++; startingTexture++;
} }
} }
@@ -1,10 +1,11 @@
package net.irisshaders.iris.gl.blending; package net.irisshaders.iris.gl.blending;
import net.irisshaders.iris.Iris;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import java.util.Optional; import java.util.Optional;
import static net.irisshaders.iris.IrisLogging.IRIS_LOGGER;
public enum BlendModeFunction { public enum BlendModeFunction {
ZERO(GL11.GL_ZERO), ZERO(GL11.GL_ZERO),
ONE(GL11.GL_ONE), ONE(GL11.GL_ONE),
@@ -28,7 +29,7 @@ public enum BlendModeFunction {
try { try {
return Optional.of(BlendModeFunction.valueOf(name)); return Optional.of(BlendModeFunction.valueOf(name));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Iris.logger.warn("Invalid blend mode! " + name); IRIS_LOGGER.warn("Invalid blend mode! " + name);
return Optional.empty(); return Optional.empty();
} }
} }
@@ -1,9 +1,8 @@
package net.irisshaders.iris.gl.blending; package net.irisshaders.iris.gl.blending;
import com.mojang.blaze3d.platform.GlStateManager; import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.mixin.GlStateManagerAccessor;
import net.irisshaders.iris.mixin.statelisteners.BooleanStateAccessor;
public class BlendModeStorage { public class BlendModeStorage {
private static boolean originalBlendEnable; private static boolean originalBlendEnable;
@@ -17,19 +16,18 @@ public class BlendModeStorage {
public static void overrideBlend(BlendMode override) { public static void overrideBlend(BlendMode override) {
if (!blendLocked) { if (!blendLocked) {
// Only save the previous state if the blend mode wasn't already locked // Only save the previous state if the blend mode wasn't already locked
GlStateManager.BlendState blendState = GlStateManagerAccessor.getBLEND();
originalBlendEnable = ((BooleanStateAccessor) blendState.mode).isEnabled(); originalBlendEnable = GL_STATE_MANAGER.isBlendEnabled();
originalBlend = new BlendMode(blendState.srcRgb, blendState.dstRgb, blendState.srcAlpha, blendState.dstAlpha); originalBlend = GL_STATE_MANAGER.getBlendMode();
} }
blendLocked = false; blendLocked = false;
if (override == null) { if (override == null) {
GlStateManager._disableBlend(); GL_STATE_MANAGER.disableBlend();
} else { } else {
GlStateManager._enableBlend(); GL_STATE_MANAGER.enableBlend();
GlStateManager._blendFuncSeparate(override.srcRgb(), override.dstRgb(), override.srcAlpha(), override.dstAlpha()); GL_STATE_MANAGER.glBlendFuncSeparate(override.srcRgb(), override.dstRgb(), override.srcAlpha(), override.dstAlpha());
} }
blendLocked = true; blendLocked = true;
@@ -38,10 +36,8 @@ public class BlendModeStorage {
public static void overrideBufferBlend(int index, BlendMode override) { public static void overrideBufferBlend(int index, BlendMode override) {
if (!blendLocked) { if (!blendLocked) {
// Only save the previous state if the blend mode wasn't already locked // Only save the previous state if the blend mode wasn't already locked
GlStateManager.BlendState blendState = GlStateManagerAccessor.getBLEND(); originalBlendEnable = GL_STATE_MANAGER.isBlendEnabled();
originalBlend = GL_STATE_MANAGER.getBlendMode();
originalBlendEnable = ((BooleanStateAccessor) blendState.mode).isEnabled();
originalBlend = new BlendMode(blendState.srcRgb, blendState.dstRgb, blendState.srcAlpha, blendState.dstAlpha);
} }
if (override == null) { if (override == null) {
@@ -70,12 +66,12 @@ public class BlendModeStorage {
blendLocked = false; blendLocked = false;
if (originalBlendEnable) { if (originalBlendEnable) {
GlStateManager._enableBlend(); GL_STATE_MANAGER.enableBlend();
} else { } else {
GlStateManager._disableBlend(); GL_STATE_MANAGER.disableBlend();
} }
GlStateManager._blendFuncSeparate(originalBlend.srcRgb(), originalBlend.dstRgb(), GL_STATE_MANAGER.glBlendFuncSeparate(originalBlend.srcRgb(), originalBlend.dstRgb(),
originalBlend.srcAlpha(), originalBlend.dstAlpha()); originalBlend.srcAlpha(), originalBlend.dstAlpha());
} }
} }
@@ -1,7 +1,6 @@
package net.irisshaders.iris.gl.blending; package net.irisshaders.iris.gl.blending;
import com.mojang.blaze3d.platform.GlStateManager; import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import net.irisshaders.iris.mixin.GlStateManagerAccessor;
public class DepthColorStorage { public class DepthColorStorage {
private static boolean originalDepthEnable; private static boolean originalDepthEnable;
@@ -15,17 +14,15 @@ public class DepthColorStorage {
public static void disableDepthColor() { public static void disableDepthColor() {
if (!depthColorLocked) { if (!depthColorLocked) {
// Only save the previous state if the depth and color mask wasn't already locked // Only save the previous state if the depth and color mask wasn't already locked
GlStateManager.ColorMask colorMask = GlStateManagerAccessor.getCOLOR_MASK();
GlStateManager.DepthState depthState = GlStateManagerAccessor.getDEPTH();
originalDepthEnable = depthState.mask; originalDepthEnable = GL_STATE_MANAGER.getDepthStateMask();
originalColor = new ColorMask(colorMask.red, colorMask.green, colorMask.blue, colorMask.alpha); originalColor = GL_STATE_MANAGER.getColorMask();
} }
depthColorLocked = false; depthColorLocked = false;
GlStateManager._depthMask(false); GL_STATE_MANAGER.glDepthMask(false);
GlStateManager._colorMask(false, false, false, false); GL_STATE_MANAGER.glColorMask(false, false, false, false);
depthColorLocked = true; depthColorLocked = true;
} }
@@ -45,8 +42,8 @@ public class DepthColorStorage {
depthColorLocked = false; depthColorLocked = false;
GlStateManager._depthMask(originalDepthEnable); GL_STATE_MANAGER.glDepthMask(originalDepthEnable);
GlStateManager._colorMask(originalColor.isRedMasked(), originalColor.isGreenMasked(), originalColor.isBlueMasked(), originalColor.isAlphaMasked()); GL_STATE_MANAGER.glColorMask(originalColor.isRedMasked(), originalColor.isGreenMasked(), originalColor.isBlueMasked(), originalColor.isAlphaMasked());
} }
} }
@@ -1,8 +1,8 @@
package net.irisshaders.iris.gl.buffer; package net.irisshaders.iris.gl.buffer;
import com.mojang.blaze3d.platform.GlStateManager; import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.IrisRenderSystem;
import org.embeddedt.embeddium.impl.gl.debug.GLDebug;
import org.lwjgl.opengl.GL43C; import org.lwjgl.opengl.GL43C;
// Do not extend GlResource, this is immutable. // Do not extend GlResource, this is immutable.
@@ -13,7 +13,7 @@ public class ShaderStorageBuffer {
public ShaderStorageBuffer(int index, ShaderStorageInfo info) { public ShaderStorageBuffer(int index, ShaderStorageInfo info) {
this.id = IrisRenderSystem.createBuffers(); this.id = IrisRenderSystem.createBuffers();
GLDebug.nameObject(GL43C.GL_BUFFER, id, "SSBO " + index); // GLDebug.nameObject(GL43C.GL_BUFFER, id, "SSBO " + index);
this.index = index; this.index = index;
this.info = info; this.info = info;
} }
@@ -40,8 +40,8 @@ public class ShaderStorageBuffer {
if (!info.relative()) return; if (!info.relative()) return;
IrisRenderSystem.deleteBuffers(id); IrisRenderSystem.deleteBuffers(id);
int newId = GlStateManager._glGenBuffers(); int newId = GL_STATE_MANAGER.glGenBuffers();
GlStateManager._glBindBuffer(GL43C.GL_SHADER_STORAGE_BUFFER, newId); GL_STATE_MANAGER.glBindBuffer(GL43C.GL_SHADER_STORAGE_BUFFER, newId);
// Calculation time // Calculation time
int newWidth = (int) (width * info.scaleX()); int newWidth = (int) (width * info.scaleX());
@@ -1,13 +1,14 @@
package net.irisshaders.iris.gl.buffer; package net.irisshaders.iris.gl.buffer;
import com.mojang.blaze3d.platform.GlStateManager; import java.util.Collections;
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.sampler.SamplerLimits; import net.irisshaders.iris.gl.sampler.SamplerLimits;
import org.lwjgl.opengl.GL43C; import org.lwjgl.opengl.GL43C;
import java.util.Collections;
public class ShaderStorageBufferHolder { public class ShaderStorageBufferHolder {
private int cachedWidth; private int cachedWidth;
private int cachedHeight; private int cachedHeight;
@@ -34,13 +35,13 @@ public class ShaderStorageBufferHolder {
if (bufferInfo.relative()) { if (bufferInfo.relative()) {
buffers[index].resizeIfRelative(width, height); buffers[index].resizeIfRelative(width, height);
} else { } else {
GlStateManager._glBindBuffer(GL43C.GL_SHADER_STORAGE_BUFFER, buffer); GL_STATE_MANAGER.glBindBuffer(GL43C.GL_SHADER_STORAGE_BUFFER, buffer);
IrisRenderSystem.bufferStorage(GL43C.GL_SHADER_STORAGE_BUFFER, bufferInfo.size(), 0); IrisRenderSystem.bufferStorage(GL43C.GL_SHADER_STORAGE_BUFFER, bufferInfo.size(), 0);
IrisRenderSystem.clearBufferSubData(GL43C.GL_SHADER_STORAGE_BUFFER, GL43C.GL_R8, 0, bufferInfo.size(), GL43C.GL_RED, GL43C.GL_BYTE, new int[]{0}); IrisRenderSystem.clearBufferSubData(GL43C.GL_SHADER_STORAGE_BUFFER, GL43C.GL_R8, 0, bufferInfo.size(), GL43C.GL_RED, GL43C.GL_BYTE, new int[]{0});
IrisRenderSystem.bindBufferBase(GL43C.GL_SHADER_STORAGE_BUFFER, index, buffer); IrisRenderSystem.bindBufferBase(GL43C.GL_SHADER_STORAGE_BUFFER, index, buffer);
} }
}); });
GlStateManager._glBindBuffer(GL43C.GL_SHADER_STORAGE_BUFFER, 0); GL_STATE_MANAGER.glBindBuffer(GL43C.GL_SHADER_STORAGE_BUFFER, 0);
} }
private static long toMib(long x) { private static long toMib(long x) {
@@ -1,6 +1,7 @@
package net.irisshaders.iris.gl.framebuffer; package net.irisshaders.iris.gl.framebuffer;
import com.mojang.blaze3d.platform.GlStateManager; import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import it.unimi.dsi.fastutil.ints.Int2IntArrayMap; import it.unimi.dsi.fastutil.ints.Int2IntArrayMap;
import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntMap;
import net.irisshaders.iris.gl.GlResource; import net.irisshaders.iris.gl.GlResource;
@@ -19,8 +20,8 @@ public class GlFramebuffer extends GlResource {
super(IrisRenderSystem.createFramebuffer()); super(IrisRenderSystem.createFramebuffer());
this.attachments = new Int2IntArrayMap(); this.attachments = new Int2IntArrayMap();
this.maxDrawBuffers = GlStateManager._getInteger(GL30C.GL_MAX_DRAW_BUFFERS); this.maxDrawBuffers = GL_STATE_MANAGER.glGetInteger(GL30C.GL_MAX_DRAW_BUFFERS);
this.maxColorAttachments = GlStateManager._getInteger(GL30C.GL_MAX_COLOR_ATTACHMENTS); this.maxColorAttachments = GL_STATE_MANAGER.glGetInteger(GL30C.GL_MAX_COLOR_ATTACHMENTS);
this.hasDepthAttachment = false; this.hasDepthAttachment = false;
} }
@@ -82,25 +83,25 @@ public class GlFramebuffer extends GlResource {
} }
public void bind() { public void bind() {
GlStateManager._glBindFramebuffer(GL30C.GL_FRAMEBUFFER, getGlId()); GL_STATE_MANAGER.glBindFramebuffer(GL30C.GL_FRAMEBUFFER, getGlId());
} }
public void bindAsReadBuffer() { public void bindAsReadBuffer() {
GlStateManager._glBindFramebuffer(GL30C.GL_READ_FRAMEBUFFER, getGlId()); GL_STATE_MANAGER.glBindFramebuffer(GL30C.GL_READ_FRAMEBUFFER, getGlId());
} }
public void bindAsDrawBuffer() { public void bindAsDrawBuffer() {
GlStateManager._glBindFramebuffer(GL30C.GL_DRAW_FRAMEBUFFER, getGlId()); GL_STATE_MANAGER.glBindFramebuffer(GL30C.GL_DRAW_FRAMEBUFFER, getGlId());
} }
protected void destroyInternal() { protected void destroyInternal() {
GlStateManager._glDeleteFramebuffers(getGlId()); GL_STATE_MANAGER.glDeleteFramebuffers(getGlId());
} }
public int getStatus() { public int getStatus() {
bind(); bind();
return GlStateManager.glCheckFramebufferStatus(GL30C.GL_FRAMEBUFFER); return GL_STATE_MANAGER.glCheckFramebufferStatus(GL30C.GL_FRAMEBUFFER);
} }
public int getId() { public int getId() {
@@ -1,19 +1,14 @@
package net.irisshaders.iris.gl.image; package net.irisshaders.iris.gl.image;
import com.mojang.blaze3d.platform.GlStateManager; import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import net.irisshaders.iris.gl.GlResource; import net.irisshaders.iris.gl.GlResource;
import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.texture.InternalTextureFormat; import net.irisshaders.iris.gl.texture.InternalTextureFormat;
import net.irisshaders.iris.gl.texture.PixelFormat; import net.irisshaders.iris.gl.texture.PixelFormat;
import net.irisshaders.iris.gl.texture.PixelType; import net.irisshaders.iris.gl.texture.PixelType;
import net.irisshaders.iris.gl.texture.TextureType; import net.irisshaders.iris.gl.texture.TextureType;
import org.embeddedt.embeddium.impl.gl.debug.GLDebug; import org.lwjgl.opengl.*;
import org.lwjgl.opengl.ARBClearTexture;
import org.lwjgl.opengl.GL11C;
import org.lwjgl.opengl.GL13C;
import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GL30C;
import org.lwjgl.opengl.GL43C;
public class GlImage extends GlResource { public class GlImage extends GlResource {
protected final String name; protected final String name;
@@ -35,7 +30,7 @@ public class GlImage extends GlResource {
this.pixelType = pixelType; this.pixelType = pixelType;
this.clear = clear; this.clear = clear;
GLDebug.nameObject(GL43C.GL_TEXTURE, getGlId(), name); // GLDebug.nameObject(GL43C.GL_TEXTURE, getGlId(), name);
IrisRenderSystem.bindTextureForSetup(target.getGlType(), getGlId()); IrisRenderSystem.bindTextureForSetup(target.getGlType(), getGlId());
target.apply(getGlId(), width, height, depth, internalFormat.getGlFormat(), format.getGlFormat(), pixelType.getGlFormat(), null); target.apply(getGlId(), width, height, depth, internalFormat.getGlFormat(), format.getGlFormat(), pixelType.getGlFormat(), null);
@@ -101,7 +96,7 @@ public class GlImage extends GlResource {
@Override @Override
protected void destroyInternal() { protected void destroyInternal() {
GlStateManager._deleteTexture(getGlId()); GL_STATE_MANAGER.glDeleteTextures(getGlId());
} }
public InternalTextureFormat getInternalFormat() { public InternalTextureFormat getInternalFormat() {
@@ -1,11 +1,10 @@
package net.irisshaders.iris.gl.program; package net.irisshaders.iris.gl.program;
import com.mojang.blaze3d.platform.GlStateManager; import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import com.mojang.blaze3d.shaders.ProgramManager; import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.gl.GlResource; import net.irisshaders.iris.gl.GlResource;
import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.pipeline.WorldRenderingPipeline;
import net.irisshaders.iris.shaderpack.FilledIndirectPointer; import net.irisshaders.iris.shaderpack.FilledIndirectPointer;
import org.joml.Vector2f; import org.joml.Vector2f;
import org.joml.Vector3i; import org.joml.Vector3i;
@@ -36,7 +35,7 @@ public final class ComputeProgram extends GlResource {
public static void unbind() { public static void unbind() {
ProgramUniforms.clearActiveUniforms(); ProgramUniforms.clearActiveUniforms();
ProgramManager.glUseProgram(0); GL_STATE_MANAGER.glUseProgram(0);
} }
public void setWorkGroupInfo(Vector2f relativeWorkGroups, Vector3i absoluteWorkGroups, FilledIndirectPointer indirectPointer) { public void setWorkGroupInfo(Vector2f relativeWorkGroups, Vector3i absoluteWorkGroups, FilledIndirectPointer indirectPointer) {
@@ -65,7 +64,7 @@ public final class ComputeProgram extends GlResource {
} }
public void use() { public void use() {
ProgramManager.glUseProgram(getGlId()); GL_STATE_MANAGER.glUseProgram(getGlId());
uniforms.update(); uniforms.update();
samplers.update(); samplers.update();
@@ -73,7 +72,7 @@ public final class ComputeProgram extends GlResource {
} }
public void dispatch(float width, float height) { public void dispatch(float width, float height) {
if (!Iris.getPipelineManager().getPipeline().map(WorldRenderingPipeline::allowConcurrentCompute).orElse(false)) { if (!MINECRAFT_SHIM.irisAllowConcurrentUpdate()) {
embeddedt marked this conversation as resolved
Review

Weird... making a note to look at later.

Weird... making a note to look at later.
IrisRenderSystem.memoryBarrier(GL43C.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL43C.GL_TEXTURE_FETCH_BARRIER_BIT | GL43C.GL_SHADER_STORAGE_BARRIER_BIT); IrisRenderSystem.memoryBarrier(GL43C.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL43C.GL_TEXTURE_FETCH_BARRIER_BIT | GL43C.GL_SHADER_STORAGE_BARRIER_BIT);
} }
@@ -86,7 +85,7 @@ public final class ComputeProgram extends GlResource {
} }
public void destroyInternal() { public void destroyInternal() {
GlStateManager.glDeleteProgram(getGlId()); GL_STATE_MANAGER.glDeleteProgram(getGlId());
} }
/** /**
@@ -1,7 +1,7 @@
package net.irisshaders.iris.gl.program; package net.irisshaders.iris.gl.program;
import com.mojang.blaze3d.platform.GlStateManager; import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import com.mojang.blaze3d.shaders.ProgramManager;
import net.irisshaders.iris.gl.GlResource; import net.irisshaders.iris.gl.GlResource;
import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.IrisRenderSystem;
import org.lwjgl.opengl.GL43C; import org.lwjgl.opengl.GL43C;
@@ -22,12 +22,12 @@ public final class Program extends GlResource {
public static void unbind() { public static void unbind() {
ProgramUniforms.clearActiveUniforms(); ProgramUniforms.clearActiveUniforms();
ProgramSamplers.clearActiveSamplers(); ProgramSamplers.clearActiveSamplers();
ProgramManager.glUseProgram(0); GL_STATE_MANAGER.glUseProgram(0);
} }
public void use() { public void use() {
IrisRenderSystem.memoryBarrier(GL43C.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL43C.GL_TEXTURE_FETCH_BARRIER_BIT | GL43C.GL_SHADER_STORAGE_BARRIER_BIT); IrisRenderSystem.memoryBarrier(GL43C.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL43C.GL_TEXTURE_FETCH_BARRIER_BIT | GL43C.GL_SHADER_STORAGE_BARRIER_BIT);
ProgramManager.glUseProgram(getGlId()); GL_STATE_MANAGER.glUseProgram(getGlId());
uniforms.update(); uniforms.update();
samplers.update(); samplers.update();
@@ -35,7 +35,7 @@ public final class Program extends GlResource {
} }
public void destroyInternal() { public void destroyInternal() {
GlStateManager.glDeleteProgram(getGlId()); GL_STATE_MANAGER.glDeleteProgram(getGlId());
} }
/** /**
@@ -1,7 +1,10 @@
package net.irisshaders.iris.gl.program; package net.irisshaders.iris.gl.program;
import java.util.function.IntSupplier;
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.mojang.blaze3d.systems.RenderSystem;
import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.image.ImageHolder; import net.irisshaders.iris.gl.image.ImageHolder;
import net.irisshaders.iris.gl.sampler.GlSampler; import net.irisshaders.iris.gl.sampler.GlSampler;
@@ -15,8 +18,6 @@ import net.irisshaders.iris.gl.texture.InternalTextureFormat;
import net.irisshaders.iris.gl.texture.TextureType; import net.irisshaders.iris.gl.texture.TextureType;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.function.IntSupplier;
public class ProgramBuilder extends ProgramUniforms.Builder implements SamplerHolder, ImageHolder { public class ProgramBuilder extends ProgramUniforms.Builder implements SamplerHolder, ImageHolder {
private final int program; private final int program;
private final ProgramSamplers.Builder samplers; private final ProgramSamplers.Builder samplers;
@@ -32,7 +33,7 @@ public class ProgramBuilder extends ProgramUniforms.Builder implements SamplerHo
public static ProgramBuilder begin(String name, @Nullable String vertexSource, @Nullable String geometrySource, public static ProgramBuilder begin(String name, @Nullable String vertexSource, @Nullable String geometrySource,
@Nullable String fragmentSource, ImmutableSet<Integer> reservedTextureUnits) { @Nullable String fragmentSource, ImmutableSet<Integer> reservedTextureUnits) {
RenderSystem.assertOnRenderThread(); RENDER_SYSTEM.assertOnRenderThread();
GlShader vertex; GlShader vertex;
GlShader geometry; GlShader geometry;
@@ -68,7 +69,7 @@ public class ProgramBuilder extends ProgramUniforms.Builder implements SamplerHo
} }
public static ProgramBuilder beginCompute(String name, @Nullable String source, ImmutableSet<Integer> reservedTextureUnits) { public static ProgramBuilder beginCompute(String name, @Nullable String source, ImmutableSet<Integer> reservedTextureUnits) {
RenderSystem.assertOnRenderThread(); RENDER_SYSTEM.assertOnRenderThread();
if (!IrisRenderSystem.supportsCompute()) { if (!IrisRenderSystem.supportsCompute()) {
throw new IllegalStateException("This PC does not support compute shaders, but it's attempting to be used???"); throw new IllegalStateException("This PC does not support compute shaders, but it's attempting to be used???");
@@ -1,17 +1,18 @@
package net.irisshaders.iris.gl.program; package net.irisshaders.iris.gl.program;
import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.irisshaders.iris.gl.image.ImageBinding;
import net.irisshaders.iris.gl.image.ImageHolder;
import net.irisshaders.iris.gl.image.ImageLimits;
import net.irisshaders.iris.gl.texture.InternalTextureFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.IntSupplier; import java.util.function.IntSupplier;
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
import com.google.common.collect.ImmutableList;
import net.irisshaders.iris.gl.image.ImageBinding;
import net.irisshaders.iris.gl.image.ImageHolder;
import net.irisshaders.iris.gl.image.ImageLimits;
import net.irisshaders.iris.gl.texture.InternalTextureFormat;
public class ProgramImages { public class ProgramImages {
private final ImmutableList<ImageBinding> imageBindings; private final ImmutableList<ImageBinding> imageBindings;
private List<GlUniform1iCall> initializer; private List<GlUniform1iCall> initializer;
@@ -28,7 +29,7 @@ public class ProgramImages {
public void update() { public void update() {
if (initializer != null) { if (initializer != null) {
for (GlUniform1iCall call : initializer) { for (GlUniform1iCall call : initializer) {
RenderSystem.glUniform1i(call.location(), call.value()); RENDER_SYSTEM.glUniform1i(call.location(), call.value());
} }
initializer = null; initializer = null;
@@ -60,12 +61,12 @@ public class ProgramImages {
@Override @Override
public boolean hasImage(String name) { public boolean hasImage(String name) {
return GlStateManager._glGetUniformLocation(program, name) != -1; return GL_STATE_MANAGER.glGetUniformLocation(program, name) != -1;
} }
@Override @Override
public void addTextureImage(IntSupplier textureID, InternalTextureFormat internalFormat, String name) { public void addTextureImage(IntSupplier textureID, InternalTextureFormat internalFormat, String name) {
int location = GlStateManager._glGetUniformLocation(program, name); int location = GL_STATE_MANAGER.glGetUniformLocation(program, name);
if (location == -1) { if (location == -1) {
return; return;
@@ -1,9 +1,15 @@
package net.irisshaders.iris.gl.program; package net.irisshaders.iris.gl.program;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.IntSupplier;
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; 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 it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.sampler.GlSampler; import net.irisshaders.iris.gl.sampler.GlSampler;
@@ -13,15 +19,9 @@ import net.irisshaders.iris.gl.sampler.SamplerLimits;
import net.irisshaders.iris.gl.state.ValueUpdateNotifier; import net.irisshaders.iris.gl.state.ValueUpdateNotifier;
import net.irisshaders.iris.gl.texture.TextureAccess; import net.irisshaders.iris.gl.texture.TextureAccess;
import net.irisshaders.iris.gl.texture.TextureType; import net.irisshaders.iris.gl.texture.TextureType;
import net.irisshaders.iris.mixin.GlStateManagerAccessor;
import net.irisshaders.iris.shaderpack.properties.PackRenderTargetDirectives; import net.irisshaders.iris.shaderpack.properties.PackRenderTargetDirectives;
import org.lwjgl.opengl.GL20C; import org.lwjgl.opengl.GL20C;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.IntSupplier;
public class ProgramSamplers { public class ProgramSamplers {
private static ProgramSamplers active; private static ProgramSamplers active;
private final ImmutableList<SamplerBinding> samplerBindings; private final ImmutableList<SamplerBinding> samplerBindings;
@@ -63,7 +63,7 @@ public class ProgramSamplers {
if (initializer != null) { if (initializer != null) {
for (GlUniform1iCall call : initializer) { for (GlUniform1iCall call : initializer) {
RenderSystem.glUniform1i(call.location(), call.value()); RENDER_SYSTEM.glUniform1i(call.location(), call.value());
} }
initializer = null; initializer = null;
@@ -71,13 +71,13 @@ public class ProgramSamplers {
// We need to keep the active texture intact, since if we mess it up // We need to keep the active texture intact, since if we mess it up
// in the middle of RenderType setup, bad things will happen. // in the middle of RenderType setup, bad things will happen.
int activeTexture = GlStateManagerAccessor.getActiveTexture(); int activeTexture = GL_STATE_MANAGER.getActiveTextureAccessor();
for (SamplerBinding samplerBinding : samplerBindings) { for (SamplerBinding samplerBinding : samplerBindings) {
samplerBinding.update(); samplerBinding.update();
} }
RenderSystem.activeTexture(GL20C.GL_TEXTURE0 + activeTexture); RENDER_SYSTEM.glActiveTexture(GL20C.GL_TEXTURE0 + activeTexture);
} }
public void removeListeners() { public void removeListeners() {
@@ -132,7 +132,7 @@ public class ProgramSamplers {
} }
for (String name : names) { for (String name : names) {
int location = GlStateManager._glGetUniformLocation(program, name); int location = GL_STATE_MANAGER.glGetUniformLocation(program, name);
if (location == -1) { if (location == -1) {
// There's no active sampler with this particular name in the program. // There's no active sampler with this particular name in the program.
@@ -147,7 +147,7 @@ public class ProgramSamplers {
@Override @Override
public boolean hasSampler(String name) { public boolean hasSampler(String name) {
return GlStateManager._glGetUniformLocation(program, name) != -1; return GL_STATE_MANAGER.glGetUniformLocation(program, name) != -1;
} }
@Override @Override
@@ -186,7 +186,7 @@ public class ProgramSamplers {
} }
for (String name : names) { for (String name : names) {
int location = GlStateManager._glGetUniformLocation(program, name); int location = GL_STATE_MANAGER.glGetUniformLocation(program, name);
if (location == -1) { if (location == -1) {
// There's no active sampler with this particular name in the program. // There's no active sampler with this particular name in the program.
@@ -1,8 +1,13 @@
package net.irisshaders.iris.gl.program; package net.irisshaders.iris.gl.program;
import java.nio.IntBuffer;
import java.util.*;
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import static net.irisshaders.iris.IrisLogging.IRIS_LOGGER;
import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.platform.GlStateManager;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.state.ValueUpdateNotifier; import net.irisshaders.iris.gl.state.ValueUpdateNotifier;
import net.irisshaders.iris.gl.uniform.DynamicLocationalUniformHolder; import net.irisshaders.iris.gl.uniform.DynamicLocationalUniformHolder;
@@ -11,20 +16,11 @@ import net.irisshaders.iris.gl.uniform.UniformHolder;
import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency; import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency;
import net.irisshaders.iris.parsing.UniformType; import net.irisshaders.iris.parsing.UniformType;
import net.irisshaders.iris.uniforms.SystemTimeUniforms; import net.irisshaders.iris.uniforms.SystemTimeUniforms;
import net.minecraft.client.Minecraft;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.ARBShaderImageLoadStore; import org.lwjgl.opengl.ARBShaderImageLoadStore;
import org.lwjgl.opengl.GL20C; import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GL30C; import org.lwjgl.opengl.GL30C;
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;
public class ProgramUniforms { public class ProgramUniforms {
private static ProgramUniforms active; private static ProgramUniforms active;
private final ImmutableList<Uniform> perTick; private final ImmutableList<Uniform> perTick;
@@ -45,11 +41,7 @@ public class ProgramUniforms {
} }
private static long getCurrentTick() { private static long getCurrentTick() {
if (Minecraft.getInstance().level == null) { return MINECRAFT_SHIM.getCurrentTick();
return 0L;
} else {
return Minecraft.getInstance().level.getGameTime();
}
} }
public static void clearActiveUniforms() { public static void clearActiveUniforms() {
@@ -291,7 +283,7 @@ public class ProgramUniforms {
@Override @Override
public OptionalInt location(String name, UniformType type) { public OptionalInt location(String name, UniformType type) {
int id = GlStateManager._glGetUniformLocation(program, name); int id = GL_STATE_MANAGER.glGetUniformLocation(program, name);
if (id == -1) { if (id == -1) {
return OptionalInt.empty(); return OptionalInt.empty();
@@ -301,7 +293,7 @@ public class ProgramUniforms {
locations.put(id, name); locations.put(id, name);
uniformNames.put(name, type); uniformNames.put(name, type);
} else { } else {
Iris.logger.warn("[" + this.name + "] Duplicate uniform: " + type.toString().toLowerCase() + " " + name); IRIS_LOGGER.warn("[" + this.name + "] Duplicate uniform: " + type.toString().toLowerCase() + " " + name);
return OptionalInt.empty(); return OptionalInt.empty();
} }
@@ -312,7 +304,7 @@ public class ProgramUniforms {
public ProgramUniforms buildUniforms() { public ProgramUniforms buildUniforms() {
// Check for any unsupported uniforms and warn about them so that we can easily figure out what uniforms we // Check for any unsupported uniforms and warn about them so that we can easily figure out what uniforms we
// need to add. // need to add.
int activeUniforms = GlStateManager.glGetProgrami(program, GL20C.GL_ACTIVE_UNIFORMS); int activeUniforms = GL_STATE_MANAGER.glGetProgrami(program, GL20C.GL_ACTIVE_UNIFORMS);
IntBuffer sizeBuf = BufferUtils.createIntBuffer(1); IntBuffer sizeBuf = BufferUtils.createIntBuffer(1);
IntBuffer typeBuf = BufferUtils.createIntBuffer(1); IntBuffer typeBuf = BufferUtils.createIntBuffer(1);
@@ -339,7 +331,7 @@ public class ProgramUniforms {
expectedName = "(unsupported type: " + getTypeName(type) + ")"; expectedName = "(unsupported type: " + getTypeName(type) + ")";
} }
Iris.logger.error("[" + this.name + "] Wrong uniform type for " + name + ": Iris is providing " + provided + " but the program expects " + expectedName + ". Disabling that uniform."); IRIS_LOGGER.error("[" + this.name + "] Wrong uniform type for " + name + ": Iris is providing " + provided + " but the program expects " + expectedName + ". Disabling that uniform.");
once.remove(name); once.remove(name);
perTick.remove(name); perTick.remove(name);
Loaded 100 of 440 files, more files were not shown because too many files have changed in this diff. Show more