Skip to content

Commit

Permalink
Tweaks to MixinTextureAtlas
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbot16 committed Sep 14, 2021
1 parent 41a5df1 commit 6b6092d
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/main/java/net/coderbot/iris/mixin/MixinTextureAtlas.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.world.phys.Vec2;
import org.lwjgl.opengl.GL20C;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand All @@ -18,6 +19,7 @@

@Mixin(TextureAtlas.class)
public abstract class MixinTextureAtlas extends AbstractTexture implements TextureAtlasInterface {
@Unique
private Vec2 atlasSize;

@Inject(method = "getLoadedSprites", at = @At("HEAD"))
Expand All @@ -28,23 +30,28 @@ private void getAtlasSize(ResourceManager resourceManager, Stitcher stitcher, in
@Override
public Vec2 getAtlasSize() {
if (this.atlasSize == null) {
// support for DashLoader (and other mods which might mess with the other code path)
int glId = this.getId();
iris$setAtlasSizeFromGlState();
}

return this.atlasSize;
}

// Keep track of what texture was bound before
int existingGlId = GL20C.glGetInteger(GL20C.GL_TEXTURE_BINDING_2D);
@Unique
private void iris$setAtlasSizeFromGlState() {
// support for DashLoader (and other mods which might mess with the other code path)
int glId = this.getId();

// Bind this texture and grab the atlas size from it.
RenderSystem.bindTexture(glId);
int width = GL20C.glGetTexLevelParameteri(GL20C.GL_TEXTURE_2D, 0, GL20C.GL_TEXTURE_WIDTH);
int height = GL20C.glGetTexLevelParameteri(GL20C.GL_TEXTURE_2D, 0, GL20C.GL_TEXTURE_HEIGHT);
this.atlasSize = new Vec2(width, height);
// Keep track of what texture was bound before
int existingGlId = GL20C.glGetInteger(GL20C.GL_TEXTURE_BINDING_2D);

// Make sure to re-bind the previous texture to avoid issues.
RenderSystem.bindTexture(existingGlId);
}
// Bind this texture and grab the atlas size from it.
RenderSystem.bindTexture(glId);
int width = GL20C.glGetTexLevelParameteri(GL20C.GL_TEXTURE_2D, 0, GL20C.GL_TEXTURE_WIDTH);
int height = GL20C.glGetTexLevelParameteri(GL20C.GL_TEXTURE_2D, 0, GL20C.GL_TEXTURE_HEIGHT);
this.atlasSize = new Vec2(width, height);

return this.atlasSize;
// Make sure to re-bind the previous texture to avoid issues.
RenderSystem.bindTexture(existingGlId);
}
}

0 comments on commit 6b6092d

Please sign in to comment.