Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Dec 17, 2024
1 parent c7e8c87 commit 8236dba
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,9 @@ public void drawBuffers(int framebuffer, int[] buffers) {

@Override
public int getTexParameteri(int texture, int target, int pname) {
if (Screen.hasAltDown()) {
return ARBDirectStateAccess.glGetTextureParameteri(texture, pname);
}
bindTextureForSetup(target, texture);
return GL32C.glGetTexParameteri(target, pname);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,59 @@

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.irisshaders.iris.mixinterface.AbstractTextureExtended;
import net.irisshaders.iris.pbr.TextureTracker;
import net.minecraft.client.renderer.texture.AbstractTexture;
import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(AbstractTexture.class)
public class MixinAbstractTexture {
public abstract class MixinAbstractTexture implements AbstractTextureExtended {
@Shadow
protected int id;

@Shadow
public abstract void bind();

@Shadow
private int minFilter;

@Shadow
private int magFilter;

@WrapOperation(method = "getId()I", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/TextureUtil;generateTextureId()I", remap = false))
private int iris$afterGenerateId(Operation<Integer> original) {
int id = original.call();
TextureTracker.INSTANCE.trackTexture(id, (AbstractTexture) (Object) this);
return id;
}

@Override
public void setNearestFilter() {
RenderSystem.assertOnRenderThreadOrInit();
int min;
int mag;
boolean mipmap = minFilter >= 0x2700;
min = mipmap ? GL11.GL_NEAREST_MIPMAP_NEAREST : GL11.GL_NEAREST;
mag = GL11.GL_NEAREST;

boolean bl3 = this.minFilter != min;
boolean bl4 = this.magFilter != mag;
if (bl4 || bl3) {
this.bind();
if (bl3) {
GlStateManager._texParameter(3553, 10241, min);
this.minFilter = min;
}

if (bl4) {
GlStateManager._texParameter(3553, 10240, mag);
this.magFilter = mag;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.irisshaders.iris.mixinterface;

public interface AbstractTextureExtended {
void setNearestFilter();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.irisshaders.iris.pbr.format;

import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.mixinterface.AbstractTextureExtended;
import net.irisshaders.iris.pbr.mipmap.CustomMipmapGenerator;
import net.irisshaders.iris.pbr.texture.PBRType;
import net.minecraft.client.renderer.texture.AbstractTexture;
Expand Down Expand Up @@ -46,12 +47,7 @@ default List<String> getDefines() {

default void setupTextureParameters(PBRType pbrType, AbstractTexture texture) {
if (!canInterpolateValues(pbrType)) {
int minFilter = IrisRenderSystem.getTexParameteri(texture.getId(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER);
// Non-mipped filters begin at 0x2600 whereas mipped filters begin at 0x2700,
// so this bit mask can be used to check if the filter is mipped or not
boolean mipmap = minFilter >= 0x2700;
IrisRenderSystem.texParameteri(texture.getId(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, mipmap ? GL11.GL_NEAREST_MIPMAP_NEAREST : GL11.GL_NEAREST);
IrisRenderSystem.texParameteri(texture.getId(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
((AbstractTextureExtended) texture).setNearestFilter();
}
}

Expand Down

0 comments on commit 8236dba

Please sign in to comment.