Skip to content

Commit

Permalink
Build: Replace some preprocessor statements with mappings
Browse files Browse the repository at this point in the history
Now that preprocessor supports manual method mappings with specific
descriptors, we can remap all of these via mappings instead of having to
use preprocessor statements.

The blendEquation one should have been using GlStateManager on
1.12.2 anyway.
  • Loading branch information
Johni0702 committed Aug 5, 2024
1 parent d026776 commit 6841155
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 61 deletions.
67 changes: 6 additions & 61 deletions src/main/java/gg/essential/universal/UGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import gg.essential.universal.vertex.UVertexConsumer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
Expand Down Expand Up @@ -70,19 +71,15 @@

//#if MC>=11502
//$$ import com.mojang.blaze3d.platform.GlStateManager;
//$$ import net.minecraft.client.renderer.BufferBuilder;
//$$ import net.minecraft.client.renderer.texture.NativeImage;
//$$ import java.io.ByteArrayInputStream;
//$$ import java.io.ByteArrayOutputStream;
//#else
import static org.lwjgl.opengl.GL14.glBlendEquation;
//#endif

//#if MC>=11400
//$$ import net.minecraft.client.renderer.texture.Texture;
//#else
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.texture.ITextureObject;
//#endif

Expand Down Expand Up @@ -232,8 +229,6 @@ public static void enableBlend() {
public static void disableTexture2D() {
//#if MC>=11904
//$$ // no-op
//#elseif MC>=11502
//$$ RenderSystem.disableTexture();
//#else
GlStateManager.disableTexture2D();
//#endif
Expand All @@ -242,12 +237,8 @@ public static void disableTexture2D() {

public static void disableAlpha() {
//#if MC<11700
//#if MC>=11502
//$$ RenderSystem.disableAlphaTest();
//#else
GlStateManager.disableAlpha();
//#endif
//#endif
}

public static void shadeModel(int mode) {
Expand All @@ -257,19 +248,15 @@ public static void shadeModel(int mode) {
}

public static void blendEquation(int equation) {
//#if MC>=11500
//$$ RenderSystem.blendEquation(equation);
//#if MC>=10900
//$$ GlStateManager.glBlendEquation(equation);
//#else
glBlendEquation(equation);
org.lwjgl.opengl.GL14.glBlendEquation(equation);
//#endif
}

public static void tryBlendFuncSeparate(int srcFactor, int dstFactor, int srcFactorAlpha, int dstFactorAlpha) {
//#if MC>=11502
//$$ RenderSystem.blendFuncSeparate(srcFactor, dstFactor, srcFactorAlpha, dstFactorAlpha);
//#else
GlStateManager.tryBlendFuncSeparate(srcFactor, dstFactor, srcFactorAlpha, dstFactorAlpha);
//#endif
}

/**
Expand All @@ -284,8 +271,6 @@ public static void tryBlendFuncSeparate(int srcFactor, int dstFactor, int srcFac
public static void enableTexture2D() {
//#if MC>=11904
//$$ // no-op
//#elseif MC>=11502
//$$ RenderSystem.enableTexture();
//#else
GlStateManager.enableTexture2D();
//#endif
Expand All @@ -301,12 +286,8 @@ public static void deleteTexture(int glTextureId) {

public static void enableAlpha() {
//#if MC<11700
//#if MC>=11502
//$$ RenderSystem.enableAlphaTest();
//#else
GlStateManager.enableAlpha();
//#endif
//#endif
}

public static void configureTexture(int glTextureId, Runnable block) {
Expand Down Expand Up @@ -651,31 +632,19 @@ public static String glGetProgramInfoLog(int program, int maxLen) {
}

public static void color4f(float red, float green, float blue, float alpha) {
//#if MC<11502
GlStateManager.color(red, green, blue, alpha);
//#else
//$$ RenderSystem.color4f(red, green, blue, alpha);
//#endif
}

public static void directColor3f(float red, float green, float blue) {
//#if MC>=11700
//$$ color4f(red, green, blue, 1f);
//#else
//#if MC<11502
GlStateManager.color(red, green, blue);
//#else
//$$ RenderSystem.color3f(red, green, blue);
//#endif
//#endif
}

public static void enableDepth() {
//#if MC<11502
GlStateManager.enableDepth();
//#else
//$$ RenderSystem.enableDepthTest();
//#endif
}

public static void depthFunc(int mode) {
Expand All @@ -687,11 +656,7 @@ public static void depthMask(boolean flag) {
}

public static void disableDepth() {
//#if MC<11502
GlStateManager.disableDepth();
//#else
//$$ RenderSystem.disableDepthTest();
//#endif
}

//#if MC>=11700
Expand Down Expand Up @@ -1125,43 +1090,23 @@ public static void popMatrix() {
}

public static void translate(float x, float y, float z) {
//#if MC>=11502
//$$ RenderSystem.translatef(x, y, z);
//#else
translate(x, y, (double) z);
//#endif
GlStateManager.translate(x, y, z);
}

public static void translate(double x, double y, double z) {
//#if MC>=11502
//$$ RenderSystem.translated(x, y, z);
//#else
GlStateManager.translate(x, y, z);
//#endif
}

public static void rotate(float angle, float x, float y, float z) {
//#if MC>=11502
//$$ RenderSystem.rotatef(angle, x, y, z);
//#else
GlStateManager.rotate(angle, x, y, z);
//#endif
}

public static void scale(float x, float y, float z) {
//#if MC>=11502
//$$ RenderSystem.scalef(x, y, z);
//#else
scale(x, y, (double) z);
//#endif
GlStateManager.scale(x, y, z);
}

public static void scale(double x, double y, double z) {
//#if MC>=11502
//$$ RenderSystem.scaled(x, y, z);
//#else
GlStateManager.scale(x, y, z);
//#endif
}
}
//#endif
Expand Down
13 changes: 13 additions & 0 deletions versions/1.16.2-1.12.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ net.minecraft.util.math.vector.Vector3f org.lwjgl.util.vector.Vector3f
net.minecraft.client.gui.screen.Screen net.minecraft.client.gui.GuiScreen
net.minecraft.client.gui.widget.Widget net.minecraft.client.gui.GuiButton
com.mojang.blaze3d.systems.RenderSystem net.minecraft.client.renderer.GlStateManager
com.mojang.blaze3d.systems.RenderSystem translated() translate(DDD)V
com.mojang.blaze3d.systems.RenderSystem translatef() translate(FFF)V
com.mojang.blaze3d.systems.RenderSystem rotatef() rotate(FFFF)V
com.mojang.blaze3d.systems.RenderSystem scalef() scale(FFF)V
com.mojang.blaze3d.systems.RenderSystem scaled() scale(DDD)V
com.mojang.blaze3d.systems.RenderSystem color3f() color(FFF)V
com.mojang.blaze3d.systems.RenderSystem color4f() color(FFFF)V
com.mojang.blaze3d.systems.RenderSystem enableDepthTest() enableDepth()
com.mojang.blaze3d.systems.RenderSystem disableDepthTest() disableDepth()
com.mojang.blaze3d.systems.RenderSystem enableAlphaTest() enableAlpha()
com.mojang.blaze3d.systems.RenderSystem disableAlphaTest() disableAlpha()
com.mojang.blaze3d.systems.RenderSystem blendEquation() glBlendEquation()
com.mojang.blaze3d.systems.RenderSystem blendFuncSeparate() tryBlendFuncSeparate()
com.mojang.blaze3d.systems.RenderSystem activeTexture() net.minecraft.client.renderer.GlStateManager setActiveTexture()
com.mojang.blaze3d.systems.RenderSystem enableTexture() net.minecraft.client.renderer.GlStateManager enableTexture2D()
com.mojang.blaze3d.systems.RenderSystem disableTexture() net.minecraft.client.renderer.GlStateManager disableTexture2D()
Expand Down

0 comments on commit 6841155

Please sign in to comment.