Custom images, textures, SSBO, and ShaderPack/ShaderProperties backports

This commit is contained in:
Jason Mitchell authored and Jason Mitchell committed 2026-01-22 16:32:15 -08:00
1 parent 6d60477b93
commit bb52476d27
54 files changed
+2210 -494

No files matched your search

@@ -3,12 +3,20 @@ package net.coderbot.iris.shaderpack;
import com.gtnewhorizons.angelica.glsm.RenderSystem;
import com.gtnewhorizons.angelica.glsm.states.BlendState;
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.coderbot.iris.gl.buffer.ShaderStorageInfo;
import net.coderbot.iris.gl.framebuffer.ViewportData;
import net.coderbot.iris.gl.image.ImageInformation;
import net.coderbot.iris.gl.texture.InternalTextureFormat;
import net.coderbot.iris.gl.texture.PixelFormat;
import net.coderbot.iris.gl.texture.PixelType;
import net.coderbot.iris.gl.texture.TextureDefinition;
import net.coderbot.iris.gl.texture.TextureType;
import lombok.Getter;
import net.coderbot.iris.Iris;
import net.coderbot.iris.gl.blending.AlphaTest;
@@ -18,6 +26,7 @@ import net.coderbot.iris.gl.blending.BlendModeFunction;
import net.coderbot.iris.gl.blending.BlendModeOverride;
import net.coderbot.iris.gl.blending.BufferBlendInformation;
import net.coderbot.iris.gl.texture.TextureScaleOverride;
import net.coderbot.iris.helpers.Tri;
import net.coderbot.iris.pipeline.PatchedShaderPrinter;
import net.coderbot.iris.shaderpack.option.ShaderPackOptions;
import net.coderbot.iris.shaderpack.preprocessor.PropertiesPreprocessor;
@@ -35,6 +44,7 @@ import java.util.EnumMap;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
@@ -47,16 +57,19 @@ import java.util.function.Consumer;
* values in here & the values parsed from shader source code.
*/
public class ShaderProperties {
@Getter private final CustomUniforms.Builder customUniforms = new CustomUniforms.Builder();
@Getter private final CustomUniforms.Builder customUniforms = new CustomUniforms.Builder();
@Getter private CloudSetting cloudSetting = CloudSetting.DEFAULT;
@Getter private CloudSetting dhCloudSetting = CloudSetting.DEFAULT;
@Getter private OptionalBoolean oldHandLight = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean dynamicHandLight = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean supportsColorCorrection = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean oldLighting = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean shadowTerrain = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean shadowTranslucent = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean shadowEntities = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean shadowPlayer = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean shadowBlockEntities = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean shadowLightBlockEntities = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean underwaterOverlay = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean sun = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean moon = OptionalBoolean.DEFAULT;
@@ -69,10 +82,14 @@ public class ShaderProperties {
@Getter private OptionalBoolean concurrentCompute = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean beaconBeamDepth = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean separateAo = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean voxelizeLightBlocks = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean separateEntityDraws = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean frustumCulling = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean shadowCulling = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean occlusionCulling = OptionalBoolean.DEFAULT;
@Getter private ShadowCullState shadowCulling = ShadowCullState.DEFAULT;
@Getter private OptionalBoolean shadowEnabled = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean particlesBeforeDeferred = OptionalBoolean.DEFAULT;
@Getter private OptionalBoolean dhShadowEnabled = OptionalBoolean.DEFAULT;
private Optional<ParticleRenderingSettings> particleRenderingSettings = Optional.empty();
@Getter private OptionalBoolean prepareBeforeShadow = OptionalBoolean.DEFAULT;
@Getter private List<String> sliderOptions = new ArrayList<>();
@Getter private final Map<String, List<String>> profiles = new LinkedHashMap<>();
@@ -80,19 +97,26 @@ public class ShaderProperties {
@Getter private final Map<String, List<String>> subScreenOptions = new HashMap<>();
private Integer mainScreenColumnCount = null;
@Getter private final Map<String, Integer> subScreenColumnCount = new HashMap<>();
@Getter private int fallbackTex = 0;
// TODO: private Map<String, String> optifineVersionRequirements;
// TODO: Parse custom uniforms / variables
@Getter private final Object2ObjectMap<String, AlphaTestOverride> alphaTestOverrides = new Object2ObjectOpenHashMap<>();
@Getter private final Object2FloatMap<String> viewportScaleOverrides = new Object2FloatOpenHashMap<>();
@Getter private final Object2ObjectMap<String, ViewportData> viewportScaleOverrides = new Object2ObjectOpenHashMap<>();
@Getter private final Object2ObjectMap<String, TextureScaleOverride> textureScaleOverrides = new Object2ObjectOpenHashMap<>();
@Getter private final Object2ObjectMap<String, BlendModeOverride> blendModeOverrides = new Object2ObjectOpenHashMap<>();
@Getter private final Object2ObjectMap<String, IndirectPointer> indirectPointers = new Object2ObjectOpenHashMap<>();
@Getter private final Object2ObjectMap<String, ArrayList<BufferBlendInformation>> bufferBlendOverrides = new Object2ObjectOpenHashMap<>();
@Getter private final EnumMap<TextureStage, Object2ObjectMap<String, String>> customTextures = new EnumMap<>(TextureStage.class);
@Getter private final EnumMap<TextureStage, Object2ObjectMap<String, TextureDefinition>> customTextures = new EnumMap<>(TextureStage.class);
@Getter private final Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> customTexturePatching = new Object2ObjectOpenHashMap<>();
@Getter private final Object2ObjectMap<String, Object2BooleanMap<String>> explicitFlips = new Object2ObjectOpenHashMap<>();
private String noiseTexturePath = null;
@Getter private Object2ObjectMap<String, String> conditionallyEnabledPrograms = new Object2ObjectOpenHashMap<>();
@Getter private List<String> requiredFeatureFlags = new ArrayList<>();
@Getter private List<String> optionalFeatureFlags = new ArrayList<>();
@Getter private final Object2ObjectMap<String, ImageInformation> customImages = new Object2ObjectOpenHashMap<>();
@Getter private final Int2ObjectMap<ShaderStorageInfo> bufferObjects = new Int2ObjectOpenHashMap<>();
@Getter private final Object2ObjectMap<String, TextureDefinition> irisCustomTextures = new Object2ObjectOpenHashMap<>();
private int customTexAmount;
private ShaderProperties() {
// empty
@@ -139,6 +163,32 @@ public class ShaderProperties {
} else {
Iris.logger.error("Unrecognized clouds setting: " + value);
}
if (dhCloudSetting == CloudSetting.DEFAULT) {
dhCloudSetting = cloudSetting;
}
}
if ("dhClouds".equals(key)) {
if ("off".equals(value)) {
dhCloudSetting = CloudSetting.OFF;
} else if ("on".equals(value) || "fancy".equals(value)) {
dhCloudSetting = CloudSetting.FANCY;
} else {
Iris.logger.error("Unrecognized DH clouds setting (need off, on): " + value);
}
}
if ("shadow.culling".equals(key)) {
if ("false".equals(value)) {
shadowCulling = ShadowCullState.DISTANCE;
} else if ("true".equals(value)) {
shadowCulling = ShadowCullState.ADVANCED;
} else if ("reversed".equals(value)) {
shadowCulling = ShadowCullState.REVERSED;
} else {
Iris.logger.error("Unrecognized shadow culling setting: " + value);
}
}
handleBooleanDirective(key, value, "oldHandLight", bool -> oldHandLight = bool);
@@ -149,6 +199,7 @@ public class ShaderProperties {
handleBooleanDirective(key, value, "shadowEntities", bool -> shadowEntities = bool);
handleBooleanDirective(key, value, "shadowPlayer", bool -> shadowPlayer = bool);
handleBooleanDirective(key, value, "shadowBlockEntities", bool -> shadowBlockEntities = bool);
handleBooleanDirective(key, value, "shadowLightBlockEntities", bool -> shadowLightBlockEntities = bool);
handleBooleanDirective(key, value, "underwaterOverlay", bool -> underwaterOverlay = bool);
handleBooleanDirective(key, value, "sun", bool -> sun = bool);
handleBooleanDirective(key, value, "moon", bool -> moon = bool);
@@ -161,25 +212,50 @@ public class ShaderProperties {
handleBooleanDirective(key, value, "allowConcurrentCompute", bool -> concurrentCompute = bool);
handleBooleanDirective(key, value, "beacon.beam.depth", bool -> beaconBeamDepth = bool);
handleBooleanDirective(key, value, "separateAo", bool -> separateAo = bool);
handleBooleanDirective(key, value, "voxelizeLightBlocks", bool -> voxelizeLightBlocks = bool);
handleBooleanDirective(key, value, "separateEntityDraws", bool -> separateEntityDraws = bool);
handleBooleanDirective(key, value, "frustum.culling", bool -> frustumCulling = bool);
handleBooleanDirective(key, value, "shadow.culling", bool -> shadowCulling = bool);
handleBooleanDirective(key, value, "particles.before.deferred", bool -> particlesBeforeDeferred = bool);
handleBooleanDirective(key, value, "occlusion.culling", bool -> occlusionCulling = bool);
handleBooleanDirective(key, value, "shadow.enabled", bool -> shadowEnabled = bool);
handleBooleanDirective(key, value, "dhShadow.enabled", bool -> dhShadowEnabled = bool);
handleBooleanDirective(key, value, "particles.before.deferred", bool -> {
if (bool.orElse(false) && particleRenderingSettings.isEmpty()) {
particleRenderingSettings = Optional.of(ParticleRenderingSettings.BEFORE);
}
});
handleBooleanDirective(key, value, "prepareBeforeShadow", bool -> prepareBeforeShadow = bool);
handleBooleanDirective(key, value, "supportsColorCorrection", bool -> supportsColorCorrection = bool);
handleIntDirective(key, value, "fallbackTex", val -> fallbackTex = val);
if (key.startsWith("particles.ordering")) {
Optional<ParticleRenderingSettings> settings = ParticleRenderingSettings.fromString(value.trim().toUpperCase(Locale.ROOT));
if (settings.isPresent()) {
particleRenderingSettings = settings;
} else {
throw new RuntimeException("Failed to parse particle rendering order! " + value);
}
}
// TODO: Min optifine versions, shader options layout / appearance / profiles
// TODO: Custom uniforms
handlePassDirective("scale.", key, value, pass -> {
final float scale;
float scale, offsetX = 0.0f, offsetY = 0.0f;
String[] parts = value.split(" ");
try {
scale = Float.parseFloat(value);
} catch (NumberFormatException e) {
scale = Float.parseFloat(parts[0]);
if (parts.length > 1) {
offsetX = Float.parseFloat(parts[1]);
offsetY = Float.parseFloat(parts[2]);
}
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
Iris.logger.error("Unable to parse scale directive for " + pass + ": " + value, e);
return;
}
viewportScaleOverrides.put(pass, scale);
viewportScaleOverrides.put(pass, new ViewportData(scale, offsetX, offsetY));
});
handlePassDirective("size.buffer.", key, value, pass -> {
@@ -291,26 +367,76 @@ public class ShaderProperties {
conditionallyEnabledPrograms.put(program, value);
});
handleTwoArgDirective("texture.", key, value, (stageName, samplerName) -> {
final String[] parts = value.split(" ");
// TODO: Support raw textures
if (parts.length > 1) {
Iris.logger.warn("Custom texture directive for stage " + stageName + ", sampler " + samplerName + " contains more parts than we expected: " + value);
return;
handlePassDirective("indirect.", key, value, pass -> {
try {
String[] locations = value.split(" ");
indirectPointers.put(pass, new IndirectPointer(Integer.parseInt(locations[0]), Long.parseLong(locations[1])));
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
Iris.logger.fatal("Failed to parse indirect command for " + pass + "! " + value);
}
});
final Optional<TextureStage> optionalTextureStage = TextureStage.parse(stageName);
handleTwoArgDirective("texture.", key, value, (stageName, samplerName) -> {
String[] parts = value.split(" ");
// Handle sampler names with dots by taking only the first part
samplerName = samplerName.split("\\.")[0];
final Optional<TextureStage> optionalTextureStage = TextureStage.parse(stageName);
if (!optionalTextureStage.isPresent()) {
Iris.logger.warn("Unknown texture stage " + "\"" + stageName + "\"," + " ignoring custom texture directive for " + key);
return;
}
final TextureStage stage = optionalTextureStage.get();
final TextureStage stage = optionalTextureStage.get();
if (parts.length > 1) {
// Raw texture - create internal sampler name and store mapping
String newSamplerName = "customtex" + customTexAmount;
customTexAmount++;
TextureType type = null;
// Raw texture handling based on number of parts
if (parts.length == 6) {
// 1D texture handling
type = TextureType.TEXTURE_1D;
irisCustomTextures.put(newSamplerName, new TextureDefinition.RawDefinition(parts[0],
TextureType.valueOf(parts[1].toUpperCase(Locale.ROOT)),
InternalTextureFormat.fromString(parts[2]).orElseThrow(IllegalArgumentException::new),
Integer.parseInt(parts[3]), 0, 0,
PixelFormat.fromString(parts[4]).orElseThrow(IllegalArgumentException::new),
PixelType.fromString(parts[5]).orElseThrow(IllegalArgumentException::new)));
} else if (parts.length == 7) {
// 2D texture handling
type = TextureType.valueOf(parts[1].toUpperCase(Locale.ROOT));
irisCustomTextures.put(newSamplerName, new TextureDefinition.RawDefinition(parts[0],
TextureType.valueOf(parts[1].toUpperCase(Locale.ROOT)),
InternalTextureFormat.fromString(parts[2]).orElseThrow(IllegalArgumentException::new),
Integer.parseInt(parts[3]), Integer.parseInt(parts[4]), 0,
PixelFormat.fromString(parts[5]).orElseThrow(IllegalArgumentException::new),
PixelType.fromString(parts[6]).orElseThrow(IllegalArgumentException::new)));
} else if (parts.length == 8) {
// 3D texture handling
type = TextureType.TEXTURE_3D;
irisCustomTextures.put(newSamplerName, new TextureDefinition.RawDefinition(parts[0],
TextureType.valueOf(parts[1].toUpperCase(Locale.ROOT)),
InternalTextureFormat.fromString(parts[2]).orElseThrow(IllegalArgumentException::new),
Integer.parseInt(parts[3]), Integer.parseInt(parts[4]), Integer.parseInt(parts[5]),
PixelFormat.fromString(parts[6]).orElseThrow(IllegalArgumentException::new),
PixelType.fromString(parts[7]).orElseThrow(IllegalArgumentException::new)));
} else {
Iris.logger.warn("Unknown texture directive for " + key + ": " + value);
}
if (type != null) {
customTexturePatching.put(new Tri<>(samplerName, type, stage), newSamplerName);
}
return;
}
// PNG texture
customTextures.computeIfAbsent(stage, _stage -> new Object2ObjectOpenHashMap<>())
.put(samplerName, value);
.put(samplerName, new TextureDefinition.PNGDefinition(value));
});
handleTwoArgDirective("flip.", key, value, (pass, buffer) -> {
@@ -324,6 +450,25 @@ public class ShaderProperties {
handleWhitespacedListDirective(key, value, "iris.features.required", options -> requiredFeatureFlags = options);
handleWhitespacedListDirective(key, value, "iris.features.optional", options -> optionalFeatureFlags = options);
// Parse custom images: image.<name> = <sampler> <pixelFormat> <internalFormat> <pixelType> <clear> <relative> [dimensions...]
handlePassDirective("image.", key, value, imageName -> {
parseCustomImage(imageName, value);
});
// Parse buffer objects: bufferObject.<index> = <size> [relative <scaleX> <scaleY>]
handlePassDirective("bufferObject.", key, value, indexStr -> {
parseBufferObject(indexStr, value);
});
// Parse custom textures: customTexture.<name> = <path> [type format sizeX [sizeY [sizeZ]] pixelFormat pixelType]
handlePassDirective("customTexture.", key, value, samplerName -> {
final TextureDefinition definition = parseTextureDefinition("customTexture." + samplerName, value);
if (definition != null) {
irisCustomTextures.put(samplerName, definition);
Iris.logger.debug("[CustomTextures] Parsed customTexture.{} = {}", samplerName, value);
}
});
handlePassDirective("variable.", key, value, pass -> {
String[] parts = pass.split("\\.");
if (parts.length != 2) {
@@ -497,4 +642,258 @@ public class ShaderProperties {
return Optional.ofNullable(mainScreenColumnCount);
}
public Optional<ParticleRenderingSettings> getParticleRenderingSettings() {
// MIXED is implied if separateEntityDraws is true.
if (separateEntityDraws == OptionalBoolean.TRUE) {
return Optional.of(ParticleRenderingSettings.MIXED);
}
return particleRenderingSettings;
}
/**
* Parses a custom image directive.
* Format: image.<name> = <sampler_name> <pixel_format> <internal_format> <pixel_type> <clear> <relative> [width height [depth]] | [relativeX relativeY]
*/
private void parseCustomImage(String imageName, String value) {
if (customImages.size() >= 16) {
Iris.logger.error("Maximum of 16 custom images exceeded, cannot add: " + imageName);
return;
}
final String[] parts = value.split("\\s+");
if (parts.length < 6) {
Iris.logger.error("Invalid custom image directive for " + imageName + ": expected at least 6 parts, got " + parts.length);
return;
}
try {
String samplerName = parts[0];
if (samplerName.equals("none") || samplerName.equals("null") || samplerName.isEmpty()) {
samplerName = null;
}
final Optional<PixelFormat> pixelFormatOpt = PixelFormat.fromString(parts[1].toUpperCase());
if (!pixelFormatOpt.isPresent()) {
Iris.logger.error("Invalid pixel format for custom image {}: {}", imageName, parts[1]);
return;
}
final PixelFormat pixelFormat = pixelFormatOpt.get();
final Optional<InternalTextureFormat> internalFormatOpt = InternalTextureFormat.fromString(parts[2].toUpperCase());
if (!internalFormatOpt.isPresent()) {
Iris.logger.error("Invalid internal format for custom image {}: {}", imageName, parts[2]);
return;
}
final InternalTextureFormat internalFormat = internalFormatOpt.get();
final Optional<PixelType> pixelTypeOpt = PixelType.fromString(parts[3].toUpperCase());
if (!pixelTypeOpt.isPresent()) {
Iris.logger.error("Invalid pixel type for custom image {}: {}", imageName, parts[3]);
return;
}
final PixelType pixelType = pixelTypeOpt.get();
final boolean clear = Boolean.parseBoolean(parts[4]);
final boolean relative = Boolean.parseBoolean(parts[5]);
ImageInformation imageInfo;
if (parts.length == 7) {
// 1D texture: width only
int width = Integer.parseInt(parts[6]);
imageInfo = new ImageInformation(imageName, samplerName, TextureType.TEXTURE_1D, pixelFormat, internalFormat, pixelType, width, 1, 1, clear, false, 1.0f, 1.0f);
} else if (parts.length == 8) {
if (relative) {
// Relative 2D: relativeWidth relativeHeight
float relativeWidth = Float.parseFloat(parts[6]);
float relativeHeight = Float.parseFloat(parts[7]);
imageInfo = new ImageInformation(imageName, samplerName, TextureType.TEXTURE_2D, pixelFormat, internalFormat, pixelType, 0, 0, 1, clear, true, relativeWidth, relativeHeight);
} else {
// Absolute 2D: width height
int width = Integer.parseInt(parts[6]);
int height = Integer.parseInt(parts[7]);
imageInfo = new ImageInformation(imageName, samplerName, TextureType.TEXTURE_2D, pixelFormat, internalFormat, pixelType, width, height, 1, clear, false, 1.0f, 1.0f);
}
} else if (parts.length >= 9) {
// 3D texture: width height depth
int width = Integer.parseInt(parts[6]);
int height = Integer.parseInt(parts[7]);
int depth = Integer.parseInt(parts[8]);
imageInfo = new ImageInformation(imageName, samplerName, TextureType.TEXTURE_3D, pixelFormat, internalFormat, pixelType, width, height, depth, clear, false, 1.0f, 1.0f);
} else {
Iris.logger.error("Invalid custom image directive for {}: expected dimensions", imageName);
return;
}
customImages.put(imageName, imageInfo);
Iris.logger.debug("[CustomImages] Parsed custom image: {} -> {}", imageName, imageInfo);
} catch (NumberFormatException e) {
Iris.logger.error("Failed to parse dimensions for custom image {}: {}", imageName, e.getMessage());
}
}
/**
* Parses a buffer object directive.
* Format: bufferObject.<index> = <size> [relative <scaleX> <scaleY>]
*/
private void parseBufferObject(String indexStr, String value) {
try {
final int index = Integer.parseInt(indexStr);
if (index > 8) {
Iris.logger.error("SSBO index " + index + " exceeds maximum of 8, buffers 9+ are reserved");
return;
}
final String[] parts = value.split("\\s+");
if (parts.length < 1) {
Iris.logger.error("Invalid buffer object directive for index " + index + ": expected size");
return;
}
final int size = Integer.parseInt(parts[0]);
// Size < 1 means the shader dev intended to disable the buffer
if (size < 1) {
return;
}
ShaderStorageInfo info;
if (parts.length >= 4 && "true".equalsIgnoreCase(parts[1])) {
// Relative: size relative scaleX scaleY
float scaleX = Float.parseFloat(parts[2]);
float scaleY = Float.parseFloat(parts[3]);
info = new ShaderStorageInfo(size, true, scaleX, scaleY);
} else {
// Absolute: size only
info = new ShaderStorageInfo(size, false, 1.0f, 1.0f);
}
bufferObjects.put(index, info);
Iris.logger.debug("Parsed buffer object: " + index + " -> " + info);
} catch (NumberFormatException e) {
Iris.logger.error("Failed to parse buffer object " + indexStr + ": " + e.getMessage());
}
}
/**
* Parses a texture definition from a shaders.properties value.
* Format can be:
* - PNG: path
* - Raw 1D: path type format sizeX pixelFormat pixelType
* - Raw 2D: path type format sizeX sizeY pixelFormat pixelType
* - Raw 3D: path type format sizeX sizeY sizeZ pixelFormat pixelType
*/
private TextureDefinition parseTextureDefinition(String key, String value) {
final String[] parts = value.split(" ");
if (parts.length == 1) {
// PNG texture - just a path
return new TextureDefinition.PNGDefinition(value);
}
try {
if (parts.length == 6) {
// 1D raw texture: path type format sizeX pixelFormat pixelType
final Optional<TextureType> targetOpt = TextureType.fromString(parts[1].toUpperCase(Locale.ROOT));
if (!targetOpt.isPresent()) {
Iris.logger.error("Invalid texture type for {}: {}", key, parts[1]);
return null;
}
final Optional<InternalTextureFormat> internalFormatOpt = InternalTextureFormat.fromString(parts[2].toUpperCase(Locale.ROOT));
if (!internalFormatOpt.isPresent()) {
Iris.logger.error("Invalid internal format for {}: {}", key, parts[2]);
return null;
}
final Optional<PixelFormat> formatOpt = PixelFormat.fromString(parts[4].toUpperCase(Locale.ROOT));
if (!formatOpt.isPresent()) {
Iris.logger.error("Invalid pixel format for {}: {}", key, parts[4]);
return null;
}
final Optional<PixelType> pixelTypeOpt = PixelType.fromString(parts[5].toUpperCase(Locale.ROOT));
if (!pixelTypeOpt.isPresent()) {
Iris.logger.error("Invalid pixel type for {}: {}", key, parts[5]);
return null;
}
return new TextureDefinition.RawDefinition(parts[0], targetOpt.get(), internalFormatOpt.get(),
Integer.parseInt(parts[3]), 0, 0, formatOpt.get(), pixelTypeOpt.get());
} else if (parts.length == 7) {
// 2D raw texture: path type format sizeX sizeY pixelFormat pixelType
final Optional<TextureType> targetOpt = TextureType.fromString(parts[1].toUpperCase(Locale.ROOT));
if (!targetOpt.isPresent()) {
Iris.logger.error("Invalid texture type for {}: {}", key, parts[1]);
return null;
}
final Optional<InternalTextureFormat> internalFormatOpt = InternalTextureFormat.fromString(parts[2].toUpperCase(Locale.ROOT));
if (!internalFormatOpt.isPresent()) {
Iris.logger.error("Invalid internal format for {}: {}", key, parts[2]);
return null;
}
final Optional<PixelFormat> formatOpt = PixelFormat.fromString(parts[5].toUpperCase(Locale.ROOT));
if (!formatOpt.isPresent()) {
Iris.logger.error("Invalid pixel format for {}: {}", key, parts[5]);
return null;
}
final Optional<PixelType> pixelTypeOpt = PixelType.fromString(parts[6].toUpperCase(Locale.ROOT));
if (!pixelTypeOpt.isPresent()) {
Iris.logger.error("Invalid pixel type for {}: {}", key, parts[6]);
return null;
}
return new TextureDefinition.RawDefinition(parts[0], targetOpt.get(), internalFormatOpt.get(),
Integer.parseInt(parts[3]), Integer.parseInt(parts[4]), 0, formatOpt.get(), pixelTypeOpt.get());
} else if (parts.length == 8) {
// 3D raw texture: path type format sizeX sizeY sizeZ pixelFormat pixelType
final Optional<TextureType> targetOpt = TextureType.fromString(parts[1].toUpperCase(Locale.ROOT));
if (!targetOpt.isPresent()) {
Iris.logger.error("Invalid texture type for {}: {}", key, parts[1]);
return null;
}
final Optional<InternalTextureFormat> internalFormatOpt = InternalTextureFormat.fromString(parts[2].toUpperCase(Locale.ROOT));
if (!internalFormatOpt.isPresent()) {
Iris.logger.error("Invalid internal format for {}: {}", key, parts[2]);
return null;
}
final Optional<PixelFormat> formatOpt = PixelFormat.fromString(parts[6].toUpperCase(Locale.ROOT));
if (!formatOpt.isPresent()) {
Iris.logger.error("Invalid pixel format for {}: {}", key, parts[6]);
return null;
}
final Optional<PixelType> pixelTypeOpt = PixelType.fromString(parts[7].toUpperCase(Locale.ROOT));
if (!pixelTypeOpt.isPresent()) {
Iris.logger.error("Invalid pixel type for {}: {}", key, parts[7]);
return null;
}
return new TextureDefinition.RawDefinition(parts[0], targetOpt.get(), internalFormatOpt.get(),
Integer.parseInt(parts[3]), Integer.parseInt(parts[4]), Integer.parseInt(parts[5]),
formatOpt.get(), pixelTypeOpt.get());
} else {
Iris.logger.warn("Unknown texture directive format for {}: {} (expected 1, 6, 7, or 8 parts, got {})",
key, value, parts.length);
return null;
}
} catch (NumberFormatException e) {
Iris.logger.error("Failed to parse texture dimensions for {}: {}", key, e.getMessage());
return null;
}
}
}