diff --git a/Switch_Toolbox_Library/FileFormats/DDS.cs b/Switch_Toolbox_Library/FileFormats/DDS.cs index b1db2852..89a95db6 100644 --- a/Switch_Toolbox_Library/FileFormats/DDS.cs +++ b/Switch_Toolbox_Library/FileFormats/DDS.cs @@ -1098,13 +1098,20 @@ namespace Toolbox.Library return TEX_FORMAT.R8G8B8A8_UNORM; } } - public void SetFlags(DXGI_FORMAT Format, bool UseDX10 = false) + public void SetFlags(DXGI_FORMAT Format, bool UseDX10 = false, bool isCubeMap = false) { header.flags = (uint)(DDSD.CAPS | DDSD.HEIGHT | DDSD.WIDTH | DDSD.PIXELFORMAT | DDSD.MIPMAPCOUNT | DDSD.LINEARSIZE); header.caps = (uint)DDSCAPS.TEXTURE; if (header.mipmapCount > 1) header.caps |= (uint)(DDSCAPS.COMPLEX | DDSCAPS.MIPMAP); + if (isCubeMap) + { + header.caps2 |= (uint)(DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_POSITIVEX | DDSCAPS2.CUBEMAP_NEGATIVEX | + DDSCAPS2.CUBEMAP_POSITIVEY | DDSCAPS2.CUBEMAP_NEGATIVEY | + DDSCAPS2.CUBEMAP_POSITIVEZ | DDSCAPS2.CUBEMAP_NEGATIVEZ); + } + if (UseDX10) { header.ddspf.flags = (uint)DDPF.FOURCC; @@ -1114,6 +1121,11 @@ namespace Toolbox.Library IsDX10 = true; DX10header.DXGI_Format = Format; + if (isCubeMap) + { + DX10header.arrayFlag = (ArrayCount / 6); + DX10header.miscFlag = 0x4; + } return; } diff --git a/Switch_Toolbox_Library/Generics/Texture/GenericTexture.cs b/Switch_Toolbox_Library/Generics/Texture/GenericTexture.cs index 89b0849a..6a42065a 100644 --- a/Switch_Toolbox_Library/Generics/Texture/GenericTexture.cs +++ b/Switch_Toolbox_Library/Generics/Texture/GenericTexture.cs @@ -992,10 +992,12 @@ namespace Toolbox.Library dds.header.ddspf.ABitMask = components[(int)AlphaChannel];*/ } + bool isCubeMap = ArrayCount == 6; + if (surfaces.Count > 1) //Use DX10 format for array surfaces as it can do custom amounts - dds.SetFlags((DDS.DXGI_FORMAT)Format, true); + dds.SetFlags((DDS.DXGI_FORMAT)Format, true, isCubeMap); else - dds.SetFlags((DDS.DXGI_FORMAT)Format); + dds.SetFlags((DDS.DXGI_FORMAT)Format, false, isCubeMap); if (dds.IsDX10) { @@ -1003,7 +1005,11 @@ namespace Toolbox.Library dds.DX10header = new DDS.DX10Header(); dds.DX10header.ResourceDim = 3; - dds.DX10header.arrayFlag = (uint)surfaces.Count; + + if (isCubeMap) + dds.DX10header.arrayFlag = (uint)(surfaces.Count / 6); + else + dds.DX10header.arrayFlag = (uint)surfaces.Count; }