408 lines
16 KiB
C#
408 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Xml;
|
|
using System.ComponentModel;
|
|
using JD.Core;
|
|
|
|
namespace ResourceViewer
|
|
{
|
|
// do not change these enum names cause it corresponds to const string in engine
|
|
public enum CompressionMode
|
|
{
|
|
DXT1 = 1,
|
|
DXT3 = 2,
|
|
DXT5 = 0,
|
|
ARGB8 = 3,
|
|
L8,
|
|
LA8
|
|
};
|
|
|
|
// do not change these enum names cause it corresponds to const string in engine
|
|
public enum MipmapFilter
|
|
{
|
|
MipmapFilter_Box = 0, ///< Box filter is quite good and very fast.
|
|
MipmapFilter_Triangle, ///< Triangle filter blurs the results too much, but that might be what you want.
|
|
MipmapFilter_Kaiser, ///< Kaiser-windowed Sinc filter is the best downsampling filter.
|
|
};
|
|
|
|
// do not change these enum names cause it corresponds to const string in engine
|
|
public enum WrapMode
|
|
{
|
|
WrapMode_Repeat = 0,
|
|
WrapMode_Clamp,
|
|
WrapMode_Mirror,
|
|
};
|
|
|
|
// do not change these enum names cause it corresponds to const string in engine
|
|
public enum OneColorMode
|
|
{
|
|
Auto = 0,
|
|
No,
|
|
Yes,
|
|
};
|
|
|
|
// do not change these enum names cause it corresponds to const string in engine
|
|
public enum Anisotropy
|
|
{
|
|
Max = 0,
|
|
Low,
|
|
};
|
|
|
|
public enum From
|
|
{
|
|
File = 0,
|
|
Memory,
|
|
};
|
|
|
|
public enum SaveState
|
|
{
|
|
Unchanged = 0,
|
|
Modified,
|
|
};
|
|
|
|
public enum CookState
|
|
{
|
|
Unchanged = 0,
|
|
Modified,
|
|
};
|
|
|
|
/// <summary>
|
|
/// Class dedicated to texture configuration, loading, modifying, and saving
|
|
/// Properties are used in the property grid control
|
|
/// </summary>
|
|
public class TextureConfiguration : IEquatable<TextureConfiguration>
|
|
{
|
|
#region const
|
|
private const string groupFileName = "File";
|
|
private const string groupMipmapName = "Mipmap";
|
|
private const string groupWrapName = "Wrap";
|
|
private const string groupMiscName = "Misc";
|
|
private const string groupDebugName = "Debug";
|
|
private const bool DEBUG = true;
|
|
#endregion
|
|
|
|
private static readonly Dictionary<PlatformId, TextureConfiguration> _defaultList = new Dictionary<PlatformId, TextureConfiguration>()
|
|
{
|
|
{PlatformId.ORBIS, new TextureConfiguration(PlatformId.ORBIS, CompressionMode.DXT5, "0", false, MipmapFilter.MipmapFilter_Box,
|
|
WrapMode.WrapMode_Clamp, WrapMode.WrapMode_Clamp, false, 0.0F, false, OneColorMode.Auto, Anisotropy.Max )},
|
|
{PlatformId.DURANGO, new TextureConfiguration(PlatformId.DURANGO, CompressionMode.DXT5, "0", false, MipmapFilter.MipmapFilter_Box,
|
|
WrapMode.WrapMode_Clamp, WrapMode.WrapMode_Clamp, false, 0.0F, false, OneColorMode.Auto, Anisotropy.Max )},
|
|
{PlatformId.X360, new TextureConfiguration(PlatformId.X360, CompressionMode.DXT5, "1", false, MipmapFilter.MipmapFilter_Box,
|
|
WrapMode.WrapMode_Clamp, WrapMode.WrapMode_Clamp, false, 0.0F, false, OneColorMode.Auto, Anisotropy.Max )},
|
|
{PlatformId.PS3, new TextureConfiguration(PlatformId.PS3, CompressionMode.DXT5, "1", false, MipmapFilter.MipmapFilter_Box,
|
|
WrapMode.WrapMode_Clamp, WrapMode.WrapMode_Clamp, false, 0.0F, false, OneColorMode.Auto, Anisotropy.Max )},
|
|
{PlatformId.WIIU, new TextureConfiguration(PlatformId.WIIU, CompressionMode.DXT5, "1", false, MipmapFilter.MipmapFilter_Box,
|
|
WrapMode.WrapMode_Clamp, WrapMode.WrapMode_Clamp, false, 0.0F, false, OneColorMode.Auto, Anisotropy.Max )},
|
|
{PlatformId.WII, new TextureConfiguration(PlatformId.WII, CompressionMode.DXT5, "2", false, MipmapFilter.MipmapFilter_Box,
|
|
WrapMode.WrapMode_Clamp, WrapMode.WrapMode_Clamp, false, 0.0F, false, OneColorMode.No, Anisotropy.Low )},
|
|
{PlatformId.PC, new TextureConfiguration(PlatformId.PC, CompressionMode.DXT5, "1", false, MipmapFilter.MipmapFilter_Box,
|
|
WrapMode.WrapMode_Clamp, WrapMode.WrapMode_Clamp, false, 0.0F, false, OneColorMode.Auto, Anisotropy.Max )},
|
|
{PlatformId.VITA, new TextureConfiguration(PlatformId.VITA, CompressionMode.DXT5, "2", false, MipmapFilter.MipmapFilter_Box,
|
|
WrapMode.WrapMode_Clamp, WrapMode.WrapMode_Clamp, false, 0.0F, false, OneColorMode.Auto, Anisotropy.Max )},
|
|
{PlatformId.IPAD, new TextureConfiguration(PlatformId.IPAD, CompressionMode.DXT5, "1", false, MipmapFilter.MipmapFilter_Box,
|
|
WrapMode.WrapMode_Clamp, WrapMode.WrapMode_Clamp, false, 0.0F, false, OneColorMode.Auto, Anisotropy.Max )},
|
|
};
|
|
|
|
#region properties
|
|
|
|
[Browsable(false)]
|
|
public float Epsilon
|
|
{
|
|
get { return 0.0000001f; }
|
|
}
|
|
|
|
[CategoryAttribute(groupFileName)]
|
|
[Description("Different compression modes allowed on every console")]
|
|
public CompressionMode CompressionMode
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
[CategoryAttribute(groupMipmapName)]
|
|
[Description("Filter applied at mipmap creation.Box is fastest. Triangle is blur. Kaiser-windowed Sinc filter is the best downsampling filter.")]
|
|
public MipmapFilter Filter
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[CategoryAttribute(groupWrapName), DisplayNameAttribute("x")]
|
|
[Description("Addressing method for UV. Horizontal parameter")]
|
|
public WrapMode WrapModeX
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[CategoryAttribute(groupWrapName), DisplayNameAttribute("y")]
|
|
[Description("Addressing method for UV. Vertical parameter")]
|
|
public WrapMode WrapModeY
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[CategoryAttribute(groupMipmapName), DisplayNameAttribute("Start level")]
|
|
[Description("Mipmap index for first MipMap level")]
|
|
public string MipmapLevelStart
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
[CategoryAttribute(groupMipmapName), DisplayNameAttribute("Enabled")]
|
|
[Description("Set to true to enable MipMap use on this texture")]
|
|
public bool UseMipmap
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[CategoryAttribute(groupMiscName), DisplayNameAttribute("Auto Degrade")]
|
|
[Description("Authorize engine to degrade texture dynamically. GPU Optimization.")]
|
|
public bool AllowAutoDegrade
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[CategoryAttribute(groupMiscName), DisplayNameAttribute("Lod Bias")]
|
|
[Description("Texture level of detail. GPU Optimization.")]
|
|
public float LodBias
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[CategoryAttribute(groupMiscName), DisplayNameAttribute("Auto Degrade Alpha")]
|
|
[Description("Authorize engine to degrade alpha dynamically. GPU Optimization.")]
|
|
public bool AllowAutoDegradeAlpha
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[CategoryAttribute(groupMiscName), DisplayNameAttribute("One Color Mode")]
|
|
[Description("Allow engine to create a one channel texture from RGB texture if only channel is used (this includes Alpha channel).")]
|
|
public OneColorMode OneColorMode
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[CategoryAttribute(groupMiscName)]
|
|
[Description("Anisotropic filtering is a method of enhancing the image quality of textures on surfaces of computer graphics that are at oblique viewing angles with respect to the camera where the projection of the texture")]
|
|
public Anisotropy Anisotropy
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[Browsable(DEBUG), ReadOnly(true), CategoryAttribute(groupDebugName)]
|
|
[Description("The console which you want the configuration to apply on")]
|
|
public PlatformId Target
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
private string TargetName
|
|
{
|
|
get { return Target.ToString(); }
|
|
}
|
|
|
|
[Browsable(DEBUG), ReadOnly(true), CategoryAttribute(groupDebugName)]
|
|
public From From { get; set; }
|
|
[Browsable(DEBUG), ReadOnly(true), CategoryAttribute(groupDebugName)]
|
|
public SaveState SaveState { get; private set; }
|
|
[Browsable(DEBUG), ReadOnly(true), CategoryAttribute(groupDebugName)]
|
|
public CookState CookState { get; private set; }
|
|
|
|
[Browsable(false)]
|
|
public bool ModifyStateChanged
|
|
{
|
|
get { return SaveState == SaveState.Modified; }
|
|
}
|
|
|
|
[Browsable(false)]
|
|
public bool CookStateChanged
|
|
{
|
|
get { return CookState == CookState.Modified; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region functions
|
|
private TextureConfiguration(PlatformId target, From from)
|
|
{
|
|
Target = target;
|
|
From = from;
|
|
SaveState = SaveState.Unchanged;
|
|
|
|
CompressionMode = default(CompressionMode);
|
|
MipmapLevelStart = "0";//there is no loss
|
|
UseMipmap = true;
|
|
Filter = default(MipmapFilter);
|
|
WrapModeX = default(WrapMode);
|
|
WrapModeY = default(WrapMode);
|
|
AllowAutoDegrade = false;
|
|
LodBias = 0.0F;
|
|
AllowAutoDegradeAlpha = false;
|
|
OneColorMode = default(OneColorMode);
|
|
Anisotropy = default(Anisotropy);
|
|
}
|
|
|
|
private TextureConfiguration(PlatformId target, CompressionMode compressionMode, string MipMapLevelStart,
|
|
bool useMipMap, MipmapFilter filter, WrapMode X, WrapMode Y, bool autoDegrade, float lodBias, bool autoDegradeAlpha,
|
|
OneColorMode onecColorMode, Anisotropy anisotropy)
|
|
{
|
|
From = From.Memory;
|
|
SaveState = SaveState.Unchanged;
|
|
|
|
Target = target;
|
|
CompressionMode = compressionMode;
|
|
MipmapLevelStart = MipMapLevelStart;
|
|
UseMipmap = useMipMap;
|
|
Filter = filter;
|
|
WrapModeX = X;
|
|
WrapModeY = Y;
|
|
AllowAutoDegrade = autoDegrade;
|
|
LodBias = lodBias;
|
|
AllowAutoDegradeAlpha = autoDegradeAlpha;
|
|
OneColorMode = onecColorMode;
|
|
Anisotropy = anisotropy;
|
|
}
|
|
|
|
public static TextureConfiguration Create(PlatformId target, From from)
|
|
{
|
|
// if the target is not a known default or if it is created from file load, do not use default value
|
|
// cause every member will be updated on load file
|
|
var newTextureConfig = DefaultList.ContainsKey(target) && from == From.Memory
|
|
? (TextureConfiguration) DefaultList[target].MemberwiseClone()
|
|
: new TextureConfiguration(target, from);
|
|
newTextureConfig.From = from;
|
|
return newTextureConfig;
|
|
}
|
|
|
|
public void Modify()
|
|
{
|
|
SaveState = SaveState.Modified;
|
|
CookState = CookState.Modified;
|
|
}
|
|
|
|
public void MarkAsCooked()
|
|
{
|
|
CookState = CookState.Unchanged;
|
|
}
|
|
|
|
public static Dictionary<PlatformId, TextureConfiguration> DefaultList
|
|
{
|
|
get { return _defaultList; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generic function to retrieve an enum value according to a string parameter
|
|
/// Return the default value if string param do not corresponds to an enum name,
|
|
/// the enum value else
|
|
/// </summary>
|
|
/// <typeparam name="TEnumType">The type of enum to parse</typeparam>
|
|
/// <param name="toCompareValue">the string to compare to value names</param>
|
|
/// <returns></returns>
|
|
private TEnumType GetEnumValueString<TEnumType>(string toCompareValue)
|
|
{
|
|
if (string.IsNullOrEmpty(toCompareValue) == false)
|
|
{
|
|
const bool compareNoCase = true;
|
|
foreach (TEnumType val in Enum.GetValues(typeof(TEnumType)))
|
|
{
|
|
if (string.Compare(val.ToString(), toCompareValue, compareNoCase) == 0 ||
|
|
val.ToString().EndsWith(toCompareValue))
|
|
{
|
|
return val;
|
|
}
|
|
}
|
|
}
|
|
return default(TEnumType);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Save the texture configuration file element, in the filexml
|
|
/// </summary>
|
|
/// <param name="filexml">the xml file object, the file should be open to write</param>
|
|
public void Save(XmlTextWriter filexml, TextureConfigFileWriter.ModifyUpdate update)
|
|
{
|
|
filexml.WriteStartElement("TextureConfiguration");
|
|
filexml.WriteAttributeString("TargetName", TargetName);
|
|
filexml.WriteAttributeString("CompressionMode", CompressionMode.ToString());
|
|
filexml.WriteAttributeString("MipmapLevelStart", MipmapLevelStart);
|
|
filexml.WriteAttributeString("UseMipmap", UseMipmap.ToString());
|
|
filexml.WriteAttributeString("WrapModeX", WrapModeX.ToString());
|
|
filexml.WriteAttributeString("WrapModeY", WrapModeY.ToString());
|
|
filexml.WriteAttributeString("Filter", Filter.ToString());
|
|
filexml.WriteAttributeString("AllowDegradation", AllowAutoDegrade.ToString());
|
|
filexml.WriteAttributeString("LodBias", LodBias.ToString(CultureInfo.InvariantCulture));
|
|
filexml.WriteAttributeString("AllowDegradationAlpha", AllowAutoDegradeAlpha.ToString());
|
|
filexml.WriteAttributeString("OneColMode", OneColorMode.ToString());
|
|
filexml.WriteAttributeString("Anisotropy", Anisotropy.ToString());
|
|
filexml.WriteEndElement();
|
|
|
|
if (update == TextureConfigFileWriter.ModifyUpdate.SetUnchanged)
|
|
SaveState = SaveState.Unchanged;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load a xml file element
|
|
/// </summary>
|
|
/// <param name="filexml">the xml file object, the file should be open to read</param>
|
|
public void Load(XmlTextReader filexml)
|
|
{
|
|
string compressionModeString = filexml.GetAttribute("CompressionMode");
|
|
string wrapModeXString = filexml.GetAttribute("WrapModeX");
|
|
string wrapModeYString = filexml.GetAttribute("WrapModeY");
|
|
string deprecatedWrapModeString = filexml.GetAttribute("WrapMode");
|
|
string filterString = filexml.GetAttribute("Filter");
|
|
string allowDegradationString = filexml.GetAttribute("AllowDegradation");
|
|
string lodBiasString = filexml.GetAttribute("LodBias");
|
|
string allowDegradationAlphaString = filexml.GetAttribute("AllowDegradationAlpha");
|
|
string oneColModeString = filexml.GetAttribute("OneColMode");
|
|
string anisotropyString = filexml.GetAttribute("Anisotropy");
|
|
|
|
MipmapLevelStart = filexml.GetAttribute("MipmapLevelStart");
|
|
UseMipmap = bool.Parse(filexml.GetAttribute("UseMipmap"));
|
|
if(allowDegradationString != null)
|
|
AllowAutoDegrade = bool.Parse(allowDegradationString);
|
|
if (lodBiasString != null)
|
|
LodBias = float.Parse(lodBiasString);
|
|
if (allowDegradationAlphaString != null)
|
|
AllowAutoDegradeAlpha = bool.Parse(allowDegradationAlphaString);
|
|
|
|
CompressionMode = GetEnumValueString<CompressionMode>(compressionModeString);
|
|
Filter = GetEnumValueString<MipmapFilter>(filterString);
|
|
WrapModeX = WrapModeY = GetEnumValueString<WrapMode>(deprecatedWrapModeString);
|
|
WrapModeX = GetEnumValueString<WrapMode>(wrapModeXString);
|
|
WrapModeY = GetEnumValueString<WrapMode>(wrapModeYString);
|
|
OneColorMode = GetEnumValueString<OneColorMode>(oneColModeString);
|
|
Anisotropy = GetEnumValueString<Anisotropy>(anisotropyString);
|
|
}
|
|
#endregion
|
|
|
|
public bool Equals(TextureConfiguration other)
|
|
{
|
|
if (other.AllowAutoDegrade != AllowAutoDegrade ||
|
|
other.AllowAutoDegradeAlpha != AllowAutoDegradeAlpha ||
|
|
other.Anisotropy != Anisotropy ||
|
|
other.CompressionMode != CompressionMode ||
|
|
other.Filter != Filter ||
|
|
other.WrapModeX != WrapModeX ||
|
|
other.WrapModeY != WrapModeY ||
|
|
other.MipmapLevelStart != MipmapLevelStart ||
|
|
other.OneColorMode != OneColorMode ||
|
|
other.UseMipmap != UseMipmap)
|
|
return false;
|
|
if (Math.Abs(other.LodBias - LodBias) > Epsilon)
|
|
return false;
|
|
return true;
|
|
}
|
|
}
|
|
}
|