mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-26 15:13:01 +00:00
Fix PBR specular & normal textures getting ignored (#874)
* Fix PBR textures not loading - Stack was being overfilled by MemoryStack - Added tons of logging for ignored important exceptions - Added missing interface on mixin (should it be moved to gtnhlib?) * Move PBR debug to angelica config * Free malloc'd memory
This commit is contained in:
1 parent
67c8628aeb
commit
81d03ea552
6 files changed
+26
-8
No files matched your search
@@ -11,6 +11,7 @@ import java.nio.IntBuffer;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack;
|
||||
import com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities;
|
||||
import lombok.Getter;
|
||||
import net.coderbot.iris.Iris;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -61,15 +62,20 @@ public class NativeImage extends BufferedImage {
|
||||
|
||||
// final int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_WIDTH);
|
||||
// final int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_HEIGHT);
|
||||
try (final MemoryStack stack = stackPush()) {
|
||||
final IntBuffer buffer = stack.mallocInt(size);
|
||||
|
||||
final IntBuffer buffer = MemoryUtilities.memAllocInt(size);
|
||||
|
||||
try {
|
||||
GL11.glGetTexImage(GL11.GL_TEXTURE_2D, level, format.glFormat, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, buffer);
|
||||
|
||||
int[] data = new int[size];
|
||||
buffer.get(data);
|
||||
setRGB(0, 0, width, height, data, 0, width);
|
||||
} finally {
|
||||
MemoryUtilities.memFree(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToFile(File file) throws IOException{
|
||||
try {
|
||||
ImageIO.write(this, "png", file);
|
||||
|
||||
@@ -133,6 +133,11 @@ public class AngelicaConfig {
|
||||
@Config.RequiresMcRestart
|
||||
public static boolean enableDebugLogging;
|
||||
|
||||
@Config.Comment("Enables PBR atlas dumping")
|
||||
@Config.DefaultBoolean(false)
|
||||
@Config.Name("Enable PBR Debug")
|
||||
public static boolean enablePBRDebug;
|
||||
|
||||
@Config.Comment("Enable Zoom")
|
||||
@Config.DefaultBoolean(true)
|
||||
@Config.RequiresMcRestart
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package net.coderbot.iris.texture.pbr;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.AutoClosableAbstractTexture;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.TextureAtlasSpriteAccessor;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.TextureMapAccessor;
|
||||
import lombok.Getter;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.texture.util.TextureExporter;
|
||||
import net.coderbot.iris.texture.util.TextureManipulationUtil;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
@@ -88,7 +90,7 @@ public class PBRAtlasTexture extends AutoClosableAbstractTexture {
|
||||
}
|
||||
}
|
||||
|
||||
if (PBRTextureManager.DEBUG) {
|
||||
if (AngelicaConfig.enablePBRDebug) {
|
||||
TextureExporter.exportTextures("pbr_debug/atlas", id.getResourceDomain() + "_" + id.getResourcePath().replaceAll("/", "_"), glId, mipLevel, atlasWidth, atlasHeight);
|
||||
}
|
||||
}
|
||||
@@ -98,6 +100,7 @@ public class PBRAtlasTexture extends AutoClosableAbstractTexture {
|
||||
upload(atlasWidth, atlasHeight, mipLevel, anisotropicFiltering);
|
||||
return true;
|
||||
} catch (Throwable t) {
|
||||
Iris.logger.error("Could not upload PBR texture", t);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ import org.lwjgl.opengl.GL11;
|
||||
public class PBRTextureManager {
|
||||
public static final PBRTextureManager INSTANCE = new PBRTextureManager();
|
||||
|
||||
public static final boolean DEBUG = System.getProperty("iris.pbr.debug") != null;
|
||||
|
||||
// TODO: Figure out how to merge these two.
|
||||
private static Runnable normalTextureChangeListener;
|
||||
private static Runnable specularTextureChangeListener;
|
||||
@@ -85,7 +83,7 @@ public class PBRTextureManager {
|
||||
loader.load(texture, Minecraft.getMinecraft().getResourceManager(), consumer);
|
||||
return consumer.toHolder();
|
||||
} catch (Exception e) {
|
||||
Iris.logger.debug("Failed to load PBR textures for texture " + id, e);
|
||||
Iris.logger.error("Failed to load PBR textures for texture " + id, e);
|
||||
} finally {
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, previousTextureBinding);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package net.coderbot.iris.texture.util;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.NativeImage;
|
||||
import net.coderbot.iris.Iris;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -28,6 +30,8 @@ public class TextureExporter {
|
||||
|
||||
try {
|
||||
nativeImage.writeToFile(file);
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception e) {
|
||||
Iris.logger.error("Could not export texture", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user