Skip to content

Commit

Permalink
Don't depend on reflection to OpenGL, use custom enum
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Oct 1, 2021
1 parent 5a82ed6 commit dc4d306
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
39 changes: 39 additions & 0 deletions src/main/java/net/coderbot/iris/gl/blending/BlendModeFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.coderbot.iris.gl.blending;

import java.util.Optional;

import net.coderbot.iris.Iris;
import org.lwjgl.opengl.GL11;

public enum BlendModeFunction {
ZERO(GL11.GL_ZERO),
ONE(GL11.GL_ONE),
SRC_COLOR(GL11.GL_SRC_COLOR),
ONE_MINUS_SRC_COLOR(GL11.GL_ONE_MINUS_SRC_COLOR),
DST_COLOR(GL11.GL_DST_COLOR),
ONE_MINUS_DST_COLOR(GL11.GL_ONE_MINUS_DST_COLOR),
SRC_ALPHA(GL11.GL_SRC_ALPHA),
ONE_MINUS_SRC_ALPHA(GL11.GL_ONE_MINUS_SRC_ALPHA),
DST_ALPHA(GL11.GL_DST_ALPHA),
ONE_MINUS_DST_ALPHA(GL11.GL_ONE_MINUS_DST_ALPHA),
SRC_ALPHA_SATURATE(GL11.GL_SRC_ALPHA_SATURATE);

private final int glId;

BlendModeFunction(int glFormat) {
this.glId = glFormat;
}

public static Optional<BlendModeFunction> fromString(String name) {
try {
return Optional.of(BlendModeFunction.valueOf(name));
} catch (IllegalArgumentException e) {
Iris.logger.warn("Invalid blend mode! " + name);
return Optional.empty();
}
}

public int getGlId() {
return glId;
}
}
13 changes: 2 additions & 11 deletions src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package net.coderbot.iris.shaderpack;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.function.Consumer;
Expand All @@ -16,7 +13,7 @@
import net.coderbot.iris.Iris;
import net.coderbot.iris.gl.blending.AlphaTestFunction;
import net.coderbot.iris.gl.blending.AlphaTestOverride;
import org.lwjgl.opengl.GL11C;
import net.coderbot.iris.gl.blending.BlendModeFunction;

public class ShaderProperties {
private boolean enableClouds = true;
Expand Down Expand Up @@ -160,13 +157,7 @@ public ShaderProperties(Properties properties) {

int i = 0;
for (String modeName : modeArray) {
try {
modes[i] = (int) GL11C.class.getDeclaredField("GL_" + modeName).get(null);
} catch (IllegalAccessException e) {
Iris.logger.error("Unable to get GL constant " + modeName, e);
} catch (NoSuchFieldException e) {
Iris.logger.error("Invalid GL constant " + modeName, e);
}
modes[i] = BlendModeFunction.fromString(modeName).get().getGlId();
i++;
}
blendModeOverrides.put(pass, modes);
Expand Down

0 comments on commit dc4d306

Please sign in to comment.