Skip to content

Commit

Permalink
"minor changes"
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Oct 3, 2024
1 parent 2c7ceb1 commit 4135f7e
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 41 deletions.
2 changes: 1 addition & 1 deletion common/src/main/java/net/irisshaders/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ private static boolean loadExternalShaderpack(String name) {
}

private static void handleException(Exception e) {
if (lastDimension != null && irisConfig.areDebugOptionsEnabled()) {
if (irisConfig.areDebugOptionsEnabled()) {
Minecraft.getInstance().setScreen(new DebugLoadFailedGridScreen(Minecraft.getInstance().screen, Component.literal(e instanceof ShaderCompileException ? "Failed to compile shaders" : "Exception"), e));
} else {
if (Minecraft.getInstance().player != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.irisshaders.iris.compat.dh;

import com.mojang.blaze3d.systems.RenderSystem;
import com.seibel.distanthorizons.api.DhApi;
import com.seibel.distanthorizons.api.enums.rendering.EDhApiFogDrawMode;
import com.seibel.distanthorizons.api.enums.rendering.EDhApiRenderPass;
Expand Down Expand Up @@ -197,7 +198,7 @@ public void beforeClear(DhApiCancelableEventParam<DhApiRenderParam> event) {
if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) {
event.cancelEvent();
} else if (getInstance().shouldOverride) {
GL43C.glClear(GL43C.GL_DEPTH_BUFFER_BIT);
RenderSystem.clear(GL43C.GL_DEPTH_BUFFER_BIT);
event.cancelEvent();
}
}
Expand Down
13 changes: 13 additions & 0 deletions common/src/main/java/net/irisshaders/iris/gl/IrisRenderSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public static void uniformMatrix4fv(int location, boolean transpose, FloatBuffer
GL32C.glUniformMatrix4fv(location, transpose, matrix);
}

public static void uniformMatrix4fv(int location, boolean transpose, float[] matrix) {
RenderSystem.assertOnRenderThreadOrInit();
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) {
RenderSystem.assertOnRenderThreadOrInit();
GL32C.glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border);
Expand Down Expand Up @@ -454,6 +459,14 @@ public static int createBuffers() {
return dsaState.createBuffers();
}

public static String getStringi(int glEnum, int index) {
return GL46C.glGetStringi(glEnum, index);
}

public static void copyImageSubData(int sourceTexture, int target, int mip, int srcX, int srcY, int srcZ, int destTexture, int dstTarget, int dstMip, int dstX, int dstY, int dstZ, int width, int height, int depth) {
GL46C.glCopyImageSubData(sourceTexture, target, mip, srcX, srcY, srcZ, destTexture, dstTarget, dstMip, dstX, dstY, dstZ, width, height, depth);
}

public interface DSAAccess {
void generateMipmaps(int texture, int target);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void createStatic() {
GlStateManager._glBindBuffer(GL43C.GL_SHADER_STORAGE_BUFFER, getId());
IrisRenderSystem.bufferStorage(GL43C.GL_SHADER_STORAGE_BUFFER, info.size(), content == null ? 0 : GL46C.GL_DYNAMIC_STORAGE_BIT);
if (content != null) {
GL46C.glBufferSubData(GL43C.GL_SHADER_STORAGE_BUFFER, 0, content);
GlStateManager._glBufferSubData(GL43C.GL_SHADER_STORAGE_BUFFER, 0, content);
} else {
IrisRenderSystem.clearBufferSubData(GL43C.GL_SHADER_STORAGE_BUFFER, GL43C.GL_R8, 0, info.size(), GL43C.GL_RED, GL43C.GL_BYTE, new int[]{0});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mojang.blaze3d.platform.GlUtil;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.compat.dh.DHCompat;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.helpers.StringPair;
import net.irisshaders.iris.pathways.HandRenderer;
import net.irisshaders.iris.pbr.format.TextureFormat;
Expand Down Expand Up @@ -317,12 +318,12 @@ public static String getRenderer() {
*/
public static Set<String> getGlExtensions() {
// In OpenGL Core, we must use a new way of retrieving extensions.
int numExtensions = GL30C.glGetInteger(GL30C.GL_NUM_EXTENSIONS);
int numExtensions = GlStateManager._getInteger(GL30C.GL_NUM_EXTENSIONS);

String[] extensions = new String[numExtensions];

for (int i = 0; i < numExtensions; i++) {
extensions[i] = GL30C.glGetStringi(GL30C.GL_EXTENSIONS, i);
extensions[i] = IrisRenderSystem.getStringi(GL30C.GL_EXTENSIONS, i);
}

// TODO note that we do not add extensions based on if the shader uses them and if they are supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public boolean needsDestFramebuffer() {

@Override
public void copy(GlFramebuffer sourceFb, int sourceTexture, GlFramebuffer destFb, int destTexture, int width, int height) {
GL43C.glCopyImageSubData(
IrisRenderSystem.copyImageSubData(
sourceTexture,
GL43C.GL_TEXTURE_2D,
0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.irisshaders.iris.pipeline.programs;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.preprocessor.GlslPreprocessor;
import com.mojang.blaze3d.shaders.CompiledShader;
import com.mojang.blaze3d.shaders.Uniform;
Expand Down Expand Up @@ -144,9 +145,30 @@ public void clear() {
BlendModeOverride.restore();
}

if (intensitySwizzle) {
IrisRenderSystem.texParameteriv(RenderSystem.getShaderTexture(0), TextureType.TEXTURE_2D.getGlType(), ARBTextureSwizzle.GL_TEXTURE_SWIZZLE_RGBA,
new int[]{GL30C.GL_RED, GL30C.GL_GREEN, GL30C.GL_BLUE, GL30C.GL_ALPHA});
}

Minecraft.getInstance().getMainRenderTarget().bindWrite(false);
}

@Override
public void setDefaultUniforms(VertexFormat.Mode mode, Matrix4f modelView, Matrix4f projection, Window window) {
super.setDefaultUniforms(mode, modelView, projection, window);
if (modelViewInverse != null) {
modelViewInverse.set(modelView.invert(tempMatrix4f));
}

if (normalMatrix != null) {
normalMatrix.set(modelView.invert(tempMatrix4f).transpose3x3(tempMatrix3f));
}

if (projectionInverse != null) {
projectionInverse.set(projection.invert(tempMatrix4f));
}
}

@Override
public void apply() {
CapturedRenderingState.INSTANCE.setCurrentAlphaTest(alphaTest);
Expand All @@ -168,26 +190,6 @@ public void apply() {

ImmediateState.usingTessellation = usesTessellation;

if (PROJECTION_MATRIX != null) {
if (projectionInverse != null) {
projectionInverse.set(tempMatrix4f.set(PROJECTION_MATRIX.getFloatBuffer()).invert().get(tempFloats));
}
} else {
if (projectionInverse != null) {
projectionInverse.set(identity);
}
}

if (MODEL_VIEW_MATRIX != null) {
if (modelViewInverse != null) {
modelViewInverse.set(tempMatrix4f.set(MODEL_VIEW_MATRIX.getFloatBuffer()).invert().get(tempFloats));
}

if (normalMatrix != null) {
normalMatrix.set(tempMatrix3f.set(tempMatrix4f.set(MODEL_VIEW_MATRIX.getFloatBuffer())).invert().transpose().get(tempFloats2));
}
}

uploadIfNotNull(projectionInverse);
uploadIfNotNull(modelViewInverse);
uploadIfNotNull(normalMatrix);
Expand All @@ -204,7 +206,7 @@ public void apply() {

images.update();

GL46C.glUniform1i(GlStateManager._glGetUniformLocation(getProgramId(), "iris_overlay"), 1);
//GL46C.glUniform1i(GlStateManager._glGetUniformLocation(getProgramId(), "iris_overlay"), 1);

if (this.blendModeOverride != null) {
this.blendModeOverride.apply();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.irisshaders.iris.pipeline.programs;

import com.mojang.blaze3d.platform.GlStateManager;
import net.caffeinemc.mods.sodium.client.gl.shader.uniform.GlUniform;
import org.joml.Matrix3fc;
import org.lwjgl.opengl.GL30C;
Expand All @@ -16,7 +17,7 @@ public void set(Matrix3fc value) {
try (MemoryStack stack = MemoryStack.stackPush()) {
FloatBuffer buf = stack.callocFloat(9);
value.get(buf);
GL30C.glUniformMatrix3fv(this.index, false, buf);
GlStateManager._glUniformMatrix3(this.index, false, buf);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableSet;
import com.google.common.primitives.Ints;
import com.mojang.blaze3d.platform.GlStateManager;
import net.caffeinemc.mods.sodium.client.gl.GlObject;
import net.caffeinemc.mods.sodium.client.gl.shader.GlProgram;
import net.caffeinemc.mods.sodium.client.gl.shader.GlShader;
Expand Down Expand Up @@ -168,10 +169,10 @@ private GlProgram<ChunkShaderInterface> buildProgram(GlProgram.Builder builder,
int handle = ((GlObject) shader).handle();
GLDebug.nameObject(GL43C.GL_PROGRAM, handle, "sodium-terrain-" + pass.toString().toLowerCase(Locale.ROOT));

if (!hasNormal) hasNormal = GL43C.glGetAttribLocation(handle, "iris_Normal") != -1;
if (!hasMidBlock) hasMidBlock = GL43C.glGetAttribLocation(handle, "at_midBlock") != -1;
if (!hasBlockId) hasBlockId = GL43C.glGetAttribLocation(handle, "mc_Entity") != -1;
if (!hasMidUv) hasMidUv = GL43C.glGetAttribLocation(handle, "mc_midTexCoord") != -1;
if (!hasNormal) hasNormal = GlStateManager._glGetAttribLocation(handle, "iris_Normal") != -1;
if (!hasMidBlock) hasMidBlock = GlStateManager._glGetAttribLocation(handle, "at_midBlock") != -1;
if (!hasBlockId) hasBlockId = GlStateManager._glGetAttribLocation(handle, "mc_Entity") != -1;
if (!hasMidUv) hasMidUv = GlStateManager._glGetAttribLocation(handle, "mc_midTexCoord") != -1;

return new SodiumShader(pipeline, pass, shader, handle, source.getDirectives().getBlendModeOverride().orElse(null),
createBufferBlendOverrides(source), customUniforms, flipState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.irisshaders.iris.uniforms.custom.cached;

import com.mojang.blaze3d.systems.RenderSystem;
import kroppeb.stareval.function.FunctionReturn;
import kroppeb.stareval.function.Type;
import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency;
Expand All @@ -26,7 +27,7 @@ protected boolean doUpdate() {

@Override
public void push(int location) {
GL21.glUniform1i(location, this.cached ? 1 : 0);
RenderSystem.glUniform1i(location, this.cached ? 1 : 0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.irisshaders.iris.uniforms.custom.cached;

import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency;
import net.irisshaders.iris.parsing.VectorType;
import org.joml.Vector2f;
Expand All @@ -20,7 +21,7 @@ protected void setFrom(Vector2f other) {

@Override
public void push(int location) {
GL21.glUniform2f(location, this.cached.x, this.cached.y);
IrisRenderSystem.uniform2f(location, this.cached.x, this.cached.y);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.irisshaders.iris.uniforms.custom.cached;

import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency;
import net.irisshaders.iris.parsing.VectorType;
import org.joml.Vector3f;
Expand All @@ -20,7 +21,7 @@ protected void setFrom(Vector3f other) {

@Override
public void push(int location) {
GL21.glUniform3f(location, this.cached.x, this.cached.y, this.cached.z);
IrisRenderSystem.uniform3f(location, this.cached.x, this.cached.y, this.cached.z);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.irisshaders.iris.uniforms.custom.cached;

import com.mojang.blaze3d.systems.RenderSystem;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency;
import net.irisshaders.iris.parsing.MatrixType;
import org.joml.Matrix4f;
Expand All @@ -24,7 +26,7 @@ protected void setFrom(Matrix4fc other) {
public void push(int location) {
// `gets` the values from the matrix and put's them into a buffer
this.cached.get(buffer);
GL21.glUniformMatrix4fv(location, false, buffer);
IrisRenderSystem.uniformMatrix4fv(location, false, buffer);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.irisshaders.iris.uniforms.custom.cached;

import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency;
import net.irisshaders.iris.parsing.VectorType;
import org.joml.Vector4f;
Expand All @@ -20,7 +21,7 @@ protected void setFrom(Vector4f other) {

@Override
public void push(int location) {
GL21.glUniform4f(location, this.cached.x, this.cached.y, this.cached.z, this.cached.w);
IrisRenderSystem.uniform4f(location, this.cached.x, this.cached.y, this.cached.z, this.cached.w);
}

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

import kroppeb.stareval.function.FunctionReturn;
import kroppeb.stareval.function.Type;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.uniform.FloatSupplier;
import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency;
import org.lwjgl.opengl.GL21;
Expand All @@ -25,7 +26,7 @@ protected boolean doUpdate() {

@Override
public void push(int location) {
GL21.glUniform1f(location, this.cached);
IrisRenderSystem.uniform1f(location, this.cached);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.irisshaders.iris.uniforms.custom.cached;

import kroppeb.stareval.function.FunctionReturn;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency;
import net.irisshaders.iris.parsing.VectorType;
import org.joml.Vector2i;
Expand All @@ -21,7 +22,7 @@ protected void setFrom(Vector2i other) {

@Override
public void push(int location) {
GL21.glUniform2i(location, this.cached.x, this.cached.y);
IrisRenderSystem.uniform2i(location, this.cached.x, this.cached.y);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.irisshaders.iris.uniforms.custom.cached;

import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency;
import net.irisshaders.iris.parsing.VectorType;
import org.joml.Vector3i;
Expand All @@ -20,7 +21,7 @@ protected void setFrom(Vector3i other) {

@Override
public void push(int location) {
GL21.glUniform3i(location, this.cached.x, this.cached.y, this.cached.z);
IrisRenderSystem.uniform3i(location, this.cached.x, this.cached.y, this.cached.z);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.irisshaders.iris.uniforms.custom.cached;

import com.mojang.blaze3d.systems.RenderSystem;
import kroppeb.stareval.function.FunctionReturn;
import kroppeb.stareval.function.Type;
import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency;
Expand All @@ -26,7 +27,7 @@ protected boolean doUpdate() {

@Override
public void push(int location) {
GL21.glUniform1i(location, this.cached);
RenderSystem.glUniform1i(location, this.cached);
}

@Override
Expand Down

0 comments on commit 4135f7e

Please sign in to comment.