mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-22 12:33:12 +00:00
Start to impliment backend for depth/3D textures
This commit is contained in:
parent
9735fb0ce6
commit
f7d674fe18
37 changed files with 225 additions and 138 deletions
|
@ -563,7 +563,7 @@ namespace Bfres.Structs
|
|||
}
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
format = (int)texture.Format;
|
||||
int swizzle = (int)texture.Swizzle;
|
||||
|
|
|
@ -66,7 +66,7 @@ namespace FirstPlugin
|
|||
return TextureImage.PaletteData;
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return TextureImage.ImageData;
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ namespace FirstPlugin
|
|||
IGZStructure.TextureInfo.ImageData = GenerateMipsAndCompress(bitmap, MipCount, Format);
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
if (PlatformSwizzle == PlatformSwizzle.Platform_Switch)
|
||||
return TegraX1Swizzle.GetImageData(this, IGZStructure.TextureInfo.ImageData, ArrayLevel, MipLevel, 1);
|
||||
|
|
|
@ -926,7 +926,7 @@ namespace FirstPlugin
|
|||
throw new NotImplementedException("Cannot set image data! Operation not implemented!");
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
uint GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC5_UNORM;
|
||||
|
||||
|
|
|
@ -679,7 +679,7 @@ namespace FirstPlugin
|
|||
}
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -635,7 +635,7 @@ namespace FirstPlugin
|
|||
}
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
int swizzle = (int)Swizzle;
|
||||
int pitch = (int)0;
|
||||
|
|
|
@ -678,7 +678,7 @@ namespace FirstPlugin
|
|||
}
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
uint bpp = GetBytesPerPixel(Format);
|
||||
|
||||
|
|
|
@ -113,4 +113,45 @@ namespace Grezzo.CmbEnums
|
|||
ONE_MINUS_SRC_B = 0x8585,
|
||||
};
|
||||
|
||||
public enum FresnelSelector
|
||||
{
|
||||
No = 25280,
|
||||
Pri = 25281,
|
||||
Sec = 25282,
|
||||
PriSec = 25283
|
||||
};
|
||||
|
||||
public enum LayerConfig
|
||||
{
|
||||
LayerConfig0 = 25264,
|
||||
LayerConfig1 = 25265,
|
||||
LayerConfig2 = 25266,
|
||||
LayerConfig3 = 25267,
|
||||
LayerConfig4 = 25268,
|
||||
LayerConfig5 = 25269,
|
||||
LayerConfig6 = 25270,
|
||||
LayerConfig7 = 25271,
|
||||
};
|
||||
|
||||
public enum LUTInput : ushort
|
||||
{
|
||||
CosNormalHalf = 25248,
|
||||
CosViewHalf = 25249,
|
||||
CosNormalView = 25250,
|
||||
CosLightNormal = 25251,
|
||||
CosLightSpot = 25252,
|
||||
CosPhi = 25253
|
||||
}
|
||||
|
||||
public enum StencilOp
|
||||
{
|
||||
Keep = 7680,
|
||||
Zero = 0,
|
||||
Replace = 7681,
|
||||
Increment = 7682,
|
||||
Decrement = 7683,
|
||||
Invert = 5386,
|
||||
IncrementWrap = 34055,
|
||||
DecrementWrap = 34055
|
||||
}
|
||||
}
|
||||
|
|
|
@ -265,7 +265,7 @@ namespace FirstPlugin
|
|||
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return ImageData;
|
||||
}
|
||||
|
|
|
@ -201,7 +201,7 @@ namespace FirstPlugin
|
|||
{
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
if (ContainerParent.Platform == GT1Platform.WiiU)
|
||||
{
|
||||
|
|
|
@ -179,11 +179,8 @@ namespace LayoutBXLYT
|
|||
bntx = BinaryContainers.Values.FirstOrDefault();
|
||||
}
|
||||
|
||||
int startIndex = bntx.Textures.Count - 1;
|
||||
var importedTextures = bntx.ImportTexture();
|
||||
|
||||
Console.WriteLine("startIndex " + startIndex);
|
||||
|
||||
//Load all the additional textues
|
||||
for (int i = 0; i < importedTextures.Count; i++)
|
||||
textures.Add(importedTextures[i]);
|
||||
|
|
|
@ -107,7 +107,7 @@ namespace FirstPlugin.LuigisMansion.DarkMoon
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return ImageData;
|
||||
}
|
||||
|
|
|
@ -229,7 +229,7 @@ namespace FirstPlugin.LuigisMansion3
|
|||
UpdateProperties();
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
uint blkHeight = STGenericTexture.GetBlockHeight(Format);
|
||||
uint blkDepth = STGenericTexture.GetBlockDepth(Format);
|
||||
|
@ -245,7 +245,7 @@ namespace FirstPlugin.LuigisMansion3
|
|||
Console.WriteLine("blockHeight " + blockHeight);
|
||||
Console.WriteLine("BlockHeightLog2 " + BlockHeightLog2);
|
||||
|
||||
return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, BlockHeightLog2, 1);
|
||||
return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, DepthLevel, BlockHeightLog2, 1);
|
||||
}
|
||||
|
||||
public override TEX_FORMAT[] SupportedFormats
|
||||
|
|
|
@ -192,7 +192,7 @@ namespace FirstPlugin.NLG
|
|||
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace FirstPlugin.PunchOutWii
|
|||
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ namespace FirstPlugin
|
|||
|
||||
//Gets the raw image data in bytes
|
||||
//Gets decoded automatically
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
||||
}
|
||||
|
|
|
@ -420,7 +420,7 @@ namespace FirstPlugin
|
|||
}
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return ImageData;
|
||||
}
|
||||
|
|
|
@ -586,7 +586,7 @@ namespace FirstPlugin
|
|||
}
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
if (image.Is3DS)
|
||||
{
|
||||
|
|
|
@ -1236,7 +1236,8 @@ namespace FirstPlugin
|
|||
Text = tex.Name;
|
||||
Width = tex.Width;
|
||||
Height = tex.Height;
|
||||
ArrayCount = (uint)tex.TextureData.Count;
|
||||
ArrayCount = tex.Depth;
|
||||
// ArrayCount = (uint)tex.TextureData.Count;
|
||||
MipCount = (uint)tex.TextureData[0].Count;
|
||||
Format = ConvertFormat(tex.Format);
|
||||
|
||||
|
@ -1672,7 +1673,7 @@ namespace FirstPlugin
|
|||
}
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
int target = 1;
|
||||
if (ParentBNTX != null && ParentBNTX is BNTX && ParentBNTX.BinaryTexFile != null)
|
||||
|
@ -1696,7 +1697,14 @@ namespace FirstPlugin
|
|||
int linesPerBlockHeight = (1 << (int)Texture.BlockHeightLog2) * 8;
|
||||
uint bpp = GetBytesPerPixel(Format);
|
||||
|
||||
uint numDepth = 1;
|
||||
if (Depth > 1)
|
||||
numDepth = Depth;
|
||||
|
||||
return TegraX1Swizzle.GetImageData(this, Texture.TextureData[0][0], ArrayLevel, MipLevel, DepthLevel, target, Texture.TileMode == TileMode.LinearAligned);
|
||||
|
||||
for (int depthLevel = 0; depthLevel < numDepth; depthLevel++)
|
||||
{
|
||||
for (int arrayLevel = 0; arrayLevel < Texture.TextureData.Count; arrayLevel++)
|
||||
{
|
||||
int blockHeightShift = 0;
|
||||
|
@ -1720,10 +1728,12 @@ namespace FirstPlugin
|
|||
|
||||
result = null;
|
||||
|
||||
if (ArrayLevel == arrayLevel && MipLevel == mipLevel)
|
||||
if (ArrayLevel == arrayLevel && MipLevel == mipLevel && DepthLevel == depthLevel)
|
||||
return result_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new byte[0];
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -182,7 +182,7 @@ namespace FirstPlugin
|
|||
|
||||
//Gets the raw image data in bytes
|
||||
//Gets decoded automatically
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ namespace FirstPlugin
|
|||
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return CtpkTexture.ImageData;
|
||||
}
|
||||
|
|
|
@ -668,7 +668,7 @@ namespace FirstPlugin
|
|||
LibraryGUI.UpdateViewport();
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
RedChannel = SetChannel(surface.compSel[0]);
|
||||
GreenChannel = SetChannel(surface.compSel[1]);
|
||||
|
|
|
@ -385,7 +385,7 @@ namespace FirstPlugin
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
if (Gx2HeaderData != null)
|
||||
{
|
||||
|
|
|
@ -427,6 +427,7 @@ namespace FirstPlugin
|
|||
//Seek to next one
|
||||
reader.Seek(mipPos + 0x40, System.IO.SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
reader.Seek(0, System.IO.SeekOrigin.Begin);
|
||||
ImageData = reader.ReadBytes(imagesize);
|
||||
}
|
||||
|
@ -572,12 +573,12 @@ namespace FirstPlugin
|
|||
ImageData = Utils.CombineByteArray(mipmaps.ToArray());
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
if (!IsSwizzled)
|
||||
return DDS.GetArrayFaces(this, ImageData,1)[ArrayLevel].mipmaps[0];
|
||||
|
||||
return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, 1);
|
||||
return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, DepthLevel, 1);
|
||||
}
|
||||
|
||||
STToolStripItem useSizeRestrictions = new STToolStripItem("UseSizeRestrictions");
|
||||
|
|
|
@ -206,7 +206,7 @@ namespace FirstPlugin
|
|||
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return ImageData;
|
||||
}
|
||||
|
|
|
@ -203,7 +203,7 @@ namespace FirstPlugin
|
|||
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return ImageData;
|
||||
}
|
||||
|
|
|
@ -147,6 +147,8 @@ namespace FirstPlugin
|
|||
texWrapper.ImageData = reader.getSection(image.ImageOffset,
|
||||
(uint)Decode_Gamecube.GetDataSize(GXFormat, (int)image.Width, (int)image.Height));
|
||||
|
||||
Console.WriteLine($"PaletteHeaderOffset {PaletteHeaderOffset}");
|
||||
|
||||
//Palette is sometimes unused to check
|
||||
if (PaletteHeaderOffset != 0)
|
||||
{
|
||||
|
@ -200,7 +202,7 @@ namespace FirstPlugin
|
|||
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ namespace FirstPlugin
|
|||
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
if (PlatformSwizzle == PlatformSwizzle.Platform_Switch)
|
||||
return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, (int)Target);
|
||||
|
|
|
@ -308,7 +308,7 @@ namespace FirstPlugin
|
|||
}
|
||||
|
||||
private bool hasShownDialog = false;
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
if (Texture.ImageData == null)
|
||||
{
|
||||
|
@ -324,7 +324,7 @@ namespace FirstPlugin
|
|||
|
||||
var BlockHeightLog2 = Texture.Info.textureLayout & 7;
|
||||
|
||||
return TegraX1Swizzle.GetImageData(this, Texture.ImageData, ArrayLevel, MipLevel, BlockHeightLog2, 1);
|
||||
return TegraX1Swizzle.GetImageData(this, Texture.ImageData, ArrayLevel, MipLevel, DepthLevel, BlockHeightLog2, 1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -728,7 +728,7 @@ namespace FirstPlugin
|
|||
ImageData = Utils.CombineByteArray(mipmaps.ToArray());
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, (int)Target);
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace FirstPlugin
|
|||
|
||||
for (int m = 0; m < Meshes.Count; m++)
|
||||
{
|
||||
if (((CMB.CMBMaterialWrapper)Meshes[m].GetMaterial()).Material.IsTransparent)
|
||||
if (((CMB.CMBMaterialWrapper)Meshes[m].GetMaterial()).CMBMaterial.IsTransparent)
|
||||
transparent.Add(Meshes[m]);
|
||||
else
|
||||
opaque.Add(Meshes[m]);
|
||||
|
@ -88,7 +88,7 @@ namespace FirstPlugin
|
|||
|
||||
public override void SetRenderData(STGenericMaterial mat, ShaderProgram shader, STGenericObject m)
|
||||
{
|
||||
var cmbMaterial = ((CMB.CMBMaterialWrapper)mat).Material;
|
||||
var cmbMaterial = ((CMB.CMBMaterialWrapper)mat).CMBMaterial;
|
||||
var cmbMesh = ((CMB.CmbMeshWrapper)m);
|
||||
|
||||
bool HasNoNormals = cmbMesh.Shape.Normal.VertexData == null || cmbMesh.Shape.Normal.VertexData.Length == 0;
|
||||
|
|
|
@ -208,7 +208,7 @@ namespace Toolbox.Library
|
|||
throw new NotImplementedException("Cannot set image data! Operation not implemented!");
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return DataBlock;
|
||||
}
|
||||
|
|
|
@ -816,15 +816,15 @@ namespace Toolbox.Library
|
|||
}
|
||||
|
||||
public bool SwitchSwizzle = false;
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
if (IsAtscFormat(Format))
|
||||
SwitchSwizzle = true;
|
||||
|
||||
if (SwitchSwizzle)
|
||||
return TegraX1Swizzle.GetImageData(this, bdata, ArrayLevel, MipLevel);
|
||||
return TegraX1Swizzle.GetImageData(this, bdata, ArrayLevel, MipLevel, DepthLevel);
|
||||
|
||||
return GetArrayFaces(this, ArrayCount)[ArrayLevel].mipmaps[MipLevel];
|
||||
return GetArrayFaces(this, ArrayCount, DepthLevel)[ArrayLevel].mipmaps[MipLevel];
|
||||
}
|
||||
|
||||
public override void SetImageData(Bitmap bitmap, int ArrayLevel)
|
||||
|
@ -985,8 +985,12 @@ namespace Toolbox.Library
|
|||
|
||||
uint formatSize = GetBytesPerPixel(tex.Format);
|
||||
|
||||
uint numDepth = 1;
|
||||
if (tex.Depth > 1)
|
||||
numDepth = tex.Depth;
|
||||
|
||||
uint Offset = 0;
|
||||
for (byte d = 0; d < tex.Depth; ++d)
|
||||
for (byte d = 0; d < numDepth; ++d)
|
||||
{
|
||||
for (byte i = 0; i < Length; ++i)
|
||||
{
|
||||
|
@ -1021,7 +1025,7 @@ namespace Toolbox.Library
|
|||
}
|
||||
}
|
||||
|
||||
public static List<Surface> GetArrayFaces(DDS dds, uint Length)
|
||||
public static List<Surface> GetArrayFaces(DDS dds, uint Length, int DepthLevel = 0)
|
||||
{
|
||||
using (FileReader reader = new FileReader(dds.bdata))
|
||||
{
|
||||
|
@ -1034,6 +1038,8 @@ namespace Toolbox.Library
|
|||
dds.header.mipmapCount = 1;
|
||||
|
||||
uint Offset = 0;
|
||||
for (byte d = 0; d < dds.Depth; ++d)
|
||||
{
|
||||
for (byte i = 0; i < Length; ++i)
|
||||
{
|
||||
var Surface = new STGenericTexture.Surface();
|
||||
|
@ -1059,8 +1065,11 @@ namespace Toolbox.Library
|
|||
Surface.mipmaps.Add(reader.getSection((int)Offset, (int)size));
|
||||
Offset += size;
|
||||
}
|
||||
|
||||
if (d == DepthLevel)
|
||||
Surfaces.Add(Surface);
|
||||
}
|
||||
}
|
||||
|
||||
return Surfaces;
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ namespace Toolbox.Library
|
|||
throw new NotImplementedException("Cannot set image data! Operation not implemented!");
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
if (TargaImage == null || TargaImage.Image == null) return new byte[0];
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ namespace Toolbox.Library
|
|||
ImageData = DDSCompressor.EncodePixelBlock(Data, bitmap.Width, bitmap.Width, DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
return ImageData;
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ namespace Toolbox.Library
|
|||
|
||||
public string DataSize { get { return STMath.GetFileSize(DataSizeInBytes, 5); } }
|
||||
|
||||
public abstract byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0);
|
||||
public abstract byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0);
|
||||
|
||||
private byte[] paletteData = new byte[0];
|
||||
|
||||
|
@ -493,18 +493,40 @@ namespace Toolbox.Library
|
|||
}
|
||||
}
|
||||
|
||||
public Bitmap GetBitmap3D(int ArrayLevel = 0, int MipLevel = 0)
|
||||
{
|
||||
List<Bitmap> images = new List<Bitmap>();
|
||||
for (int i = 0; i < Depth; i++)
|
||||
images.Add(GetBitmap(ArrayLevel, MipLevel, i));
|
||||
|
||||
//Combine images in a horizontal pattern
|
||||
uint width = Width * Depth;
|
||||
var newBitmap = new Bitmap((int)width, (int)Height);
|
||||
using (Graphics grfx = Graphics.FromImage(newBitmap))
|
||||
{
|
||||
int x = 0;
|
||||
foreach (var image in images) {
|
||||
grfx.DrawImage(image, x, 0);
|
||||
x += image.Width;
|
||||
}
|
||||
|
||||
return newBitmap;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Bitmap"/> given an array and mip index.
|
||||
/// </summary>
|
||||
/// <param name="ArrayIndex">The index of the surface/array. Cubemaps will have 6</param>
|
||||
/// <param name="MipLevel">The index of the mip level.</param>
|
||||
/// <returns></returns>
|
||||
public Bitmap GetBitmap(int ArrayLevel = 0, int MipLevel = 0)
|
||||
public Bitmap GetBitmap(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
uint width = Math.Max(1, Width >> MipLevel);
|
||||
uint height = Math.Max(1, Height >> MipLevel);
|
||||
byte[] data = GetImageData(ArrayLevel, MipLevel);
|
||||
byte[] data = GetImageData(ArrayLevel, MipLevel, DepthLevel);
|
||||
byte[] paletteData = GetPaletteData();
|
||||
if (Format == TEX_FORMAT.R8G8B8A8_UNORM) return BitmapExtension.GetBitmap(ConvertBgraToRgba(data), (int)width, (int)height);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -68,16 +68,16 @@ namespace Toolbox.Library
|
|||
return MipMapSizes;
|
||||
}
|
||||
|
||||
public static byte[] GetImageData(STGenericTexture texture, byte[] ImageData, int ArrayLevel, int MipLevel, int target = 1, bool LinearTileMode = false)
|
||||
public static byte[] GetImageData(STGenericTexture texture, byte[] ImageData, int ArrayLevel, int MipLevel, int DepthLevel, int target = 1, bool LinearTileMode = false)
|
||||
{
|
||||
uint blkHeight = STGenericTexture.GetBlockHeight(texture.Format);
|
||||
uint blkDepth = STGenericTexture.GetBlockDepth(texture.Format);
|
||||
uint blockHeight = TegraX1Swizzle.GetBlockHeight(TegraX1Swizzle.DIV_ROUND_UP(texture.Height, blkHeight));
|
||||
uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1;
|
||||
return GetImageData(texture, ImageData, ArrayLevel, MipLevel, BlockHeightLog2, target, LinearTileMode);
|
||||
return GetImageData(texture, ImageData, ArrayLevel, MipLevel, DepthLevel, BlockHeightLog2, target, LinearTileMode);
|
||||
}
|
||||
|
||||
public static byte[] GetImageData(STGenericTexture texture, byte[] ImageData, int ArrayLevel, int MipLevel, uint BlockHeightLog2, int target = 1, bool LinearTileMode = false)
|
||||
public static byte[] GetImageData(STGenericTexture texture, byte[] ImageData, int ArrayLevel, int MipLevel, int DepthLevel, uint BlockHeightLog2, int target = 1, bool LinearTileMode = false)
|
||||
{
|
||||
uint bpp = STGenericTexture.GetBytesPerPixel(texture.Format);
|
||||
uint blkWidth = STGenericTexture.GetBlockWidth(texture.Format);
|
||||
|
@ -90,10 +90,15 @@ namespace Toolbox.Library
|
|||
uint TileMode = 0;
|
||||
if (LinearTileMode)
|
||||
TileMode = 1;
|
||||
uint numDepth = 1;
|
||||
if (texture.Depth > 1)
|
||||
numDepth = texture.Depth;
|
||||
|
||||
int linesPerBlockHeight = (1 << (int)BlockHeightLog2) * 8;
|
||||
|
||||
uint ArrayOffset = 0;
|
||||
for (int depthLevel = 0; depthLevel < numDepth; depthLevel++)
|
||||
{
|
||||
for (int arrayLevel = 0; arrayLevel < texture.ArrayCount; arrayLevel++)
|
||||
{
|
||||
uint SurfaceSize = 0;
|
||||
|
@ -139,7 +144,7 @@ namespace Toolbox.Library
|
|||
Array.Copy(result, 0, result_, 0, size);
|
||||
result = null;
|
||||
|
||||
if (ArrayLevel == arrayLevel && MipLevel == mipLevel)
|
||||
if (ArrayLevel == arrayLevel && MipLevel == mipLevel && DepthLevel == depthLevel)
|
||||
return result_;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -150,9 +155,9 @@ namespace Toolbox.Library
|
|||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
ArrayOffset += (uint)(ImageData.Length / texture.ArrayCount);
|
||||
}
|
||||
}
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue