Add option for linear filtering of text texture (#7645)

This commit is contained in:
Nightenom authored and GitHub committed 2021-06-08 21:33:31 +02:00
1 parent 65e99f9b58
commit 1d87831773
5 files changed
+136 -3

No files matched your search

@@ -19,18 +19,21 @@
package net.minecraftforge.client;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderState;
import net.minecraft.client.renderer.RenderState.TextureState;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.RenderType.State;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.NonNullLazy;
import net.minecraftforge.common.util.NonNullSupplier;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.renderer.RenderState.TextureState;
import net.minecraft.client.renderer.RenderType.State;
import java.util.function.Supplier;
@SuppressWarnings("deprecation")
public enum ForgeRenderTypes
@@ -43,6 +46,8 @@ public enum ForgeRenderTypes
ITEM_UNLIT_TRANSLUCENT(()-> getUnlitTranslucent(AtlasTexture.LOCATION_BLOCKS)),
ITEM_UNSORTED_UNLIT_TRANSLUCENT(()-> getUnlitTranslucent(AtlasTexture.LOCATION_BLOCKS, false));
public static boolean enableTextTextureLinearFiltering = false;
/**
* @return A RenderType fit for multi-layer solid item rendering.
*/
@@ -110,6 +115,22 @@ public enum ForgeRenderTypes
return Internal.layeredItemCutoutMipped(textureLocation);
}
/**
* @return Replacement of {@link RenderType#getText(ResourceLocation)}, but with optional linear texture filtering.
*/
public static RenderType getText(ResourceLocation locationIn)
{
return Internal.getText(locationIn);
}
/**
* @return Replacement of {@link RenderType#getTextSeeThrough(ResourceLocation)}, but with optional linear texture filtering.
*/
public static RenderType getTextSeeThrough(ResourceLocation locationIn)
{
return Internal.getTextSeeThrough(locationIn);
}
// ----------------------------------------
// Implementation details below this line
// ----------------------------------------
@@ -209,5 +230,43 @@ public enum ForgeRenderTypes
.createCompositeState(true);
return create("forge_item_entity_translucent_cull", DefaultVertexFormats.NEW_ENTITY, 7, 256, true, true, rendertype$state);
}
public static RenderType getText(ResourceLocation locationIn) {
RenderType.State rendertype$state = RenderType.State.builder()
.setTextureState(new CustomizableTextureState(locationIn, () -> ForgeRenderTypes.enableTextTextureLinearFiltering, () -> false))
.setAlphaState(DEFAULT_ALPHA)
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setLightmapState(LIGHTMAP)
.createCompositeState(false);
return create("forge_text", DefaultVertexFormats.POSITION_COLOR_TEX_LIGHTMAP, 7, 256, false, true, rendertype$state);
}
public static RenderType getTextSeeThrough(ResourceLocation locationIn) {
RenderType.State rendertype$state = RenderType.State.builder()
.setTextureState(new CustomizableTextureState(locationIn, () -> ForgeRenderTypes.enableTextTextureLinearFiltering, () -> false))
.setAlphaState(DEFAULT_ALPHA)
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setLightmapState(LIGHTMAP)
.setDepthTestState(NO_DEPTH_TEST)
.setWriteMaskState(COLOR_WRITE)
.createCompositeState(false);
return create("forge_text_see_through", DefaultVertexFormats.POSITION_COLOR_TEX_LIGHTMAP, 7, 256, false, true, rendertype$state);
}
}
private static class CustomizableTextureState extends TextureState
{
private CustomizableTextureState(ResourceLocation resLoc, Supplier<Boolean> blur, Supplier<Boolean> mipmap)
{
super(resLoc, blur.get(), mipmap.get());
this.setupState = () -> {
this.blur = blur.get();
this.mipmap = mipmap.get();
RenderSystem.enableTexture();
TextureManager texturemanager = Minecraft.getInstance().getTextureManager();
texturemanager.bind(resLoc);
texturemanager.getTexture(resLoc).setFilter(this.blur, this.mipmap);
};
}
}
}