Skip to content

Commit

Permalink
Only Rescale when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
UselessBullets committed Nov 6, 2023
1 parent acbea95 commit 1169deb
Showing 1 changed file with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,23 @@ private void initDynamicTextures(CallbackInfo ci) {
}
@Inject(method = "setupTexture(Ljava/awt/image/BufferedImage;IZ)V", at = @At("HEAD"), cancellable = true)
private void adjustAtlasSize(BufferedImage img, int id, boolean mipmap, CallbackInfo ci){
boolean doResize = false;
for (String key : textureMap.keySet()) {
if (key.equals("/terrain.png") || key.equals("/gui/items.png")) {
doResize = textureMap.get(key) == id;
if (doResize) {
break;
}
}
}
// boolean doResize = false;
// for (String key : textureMap.keySet()) {
// if (key.equals("/terrain.png") || key.equals("/gui/items.png")) {
// doResize = textureMap.get(key) == id;
// if (doResize) {
// break;
// }
// }
// }
if (mipmap){
BufferedImage testImage = new BufferedImage((img.getWidth()/32) * Global.TEXTURE_ATLAS_WIDTH_TILES, (img.getHeight()/32) * Global.TEXTURE_ATLAS_WIDTH_TILES, img.getType());
BufferedImage resizedAtlas = new BufferedImage((img.getWidth()/32) * Global.TEXTURE_ATLAS_WIDTH_TILES, (img.getHeight()/32) * Global.TEXTURE_ATLAS_WIDTH_TILES, img.getType());
if (img.getWidth() == resizedAtlas.getWidth() && img.getHeight() == resizedAtlas.getHeight()){
return; // Don't scale and transfer image if they're the same size
}
for (int x = 0; x < img.getWidth(); x++) {
for (int y = 0; y < img.getHeight(); y++) {
testImage.setRGB(x, y, img.getRGB(x, y));
resizedAtlas.setRGB(x, y, img.getRGB(x, y));
}
}

Expand All @@ -86,12 +89,12 @@ private void adjustAtlasSize(BufferedImage img, int id, boolean mipmap, Callback
GL11.glTexParameteri(3553, 10242, 10497);
GL11.glTexParameteri(3553, 10243, 10497);
}
int w = testImage.getWidth();
int h = testImage.getHeight();
Buffer.put(testImage);
int w = resizedAtlas.getWidth();
int h = resizedAtlas.getHeight();
Buffer.put(resizedAtlas);
GL11.glTexImage2D(3553, 0, 6408, w, h, 0, 6408, 5121, Buffer.buffer);
if (mipmap) {
this.generateMipmaps(Buffer.buffer, testImage, this.minecraft.gameSettings.mipmapLevels.value, this.minecraft.gameSettings.mipmapType.value == MipmapType.SMOOTH);
this.generateMipmaps(Buffer.buffer, resizedAtlas, this.minecraft.gameSettings.mipmapLevels.value, this.minecraft.gameSettings.mipmapType.value == MipmapType.SMOOTH);
}
ci.cancel();
}
Expand Down

0 comments on commit 1169deb

Please sign in to comment.