From 56b812f22f74d848094a2b6ab79da2938457fda9 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 6 Sep 2023 09:47:06 +0200 Subject: [PATCH] Fix build. --- modules/dds/texture_loader_dds.cpp | 62 ++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index c08e3590e..fd4fdf70f 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -32,6 +32,68 @@ #include "core/os/file_access.h" +#define PF_FOURCC(s) ((uint32_t)(((s)[3] << 24U) | ((s)[2] << 16U) | ((s)[1] << 8U) | ((s)[0]))) + +// Reference: https://docs.microsoft.com/en-us/windows/win32/direct3ddds/dds-header + +enum { + DDS_MAGIC = 0x20534444, + DDSD_PITCH = 0x00000008, + DDSD_LINEARSIZE = 0x00080000, + DDSD_MIPMAPCOUNT = 0x00020000, + DDPF_FOURCC = 0x00000004, + DDPF_ALPHAPIXELS = 0x00000001, + DDPF_INDEXED = 0x00000020, + DDPF_RGB = 0x00000040, +}; + +enum DDSFormat { + DDS_DXT1, + DDS_DXT3, + DDS_DXT5, + DDS_ATI1, + DDS_ATI2, + DDS_A2XY, + DDS_BGRA8, + DDS_BGR8, + DDS_RGBA8, //flipped in dds + DDS_RGB8, //flipped in dds + DDS_BGR5A1, + DDS_BGR565, + DDS_BGR10A2, + DDS_INDEXED, + DDS_LUMINANCE, + DDS_LUMINANCE_ALPHA, + DDS_MAX +}; + +struct DDSFormatInfo { + const char *name; + bool compressed; + bool palette; + uint32_t divisor; + uint32_t block_size; + Image::Format format; +}; + +static const DDSFormatInfo dds_format_info[DDS_MAX] = { + { "DXT1/BC1", true, false, 4, 8, Image::FORMAT_DXT1 }, + { "DXT3/BC2", true, false, 4, 16, Image::FORMAT_DXT3 }, + { "DXT5/BC3", true, false, 4, 16, Image::FORMAT_DXT5 }, + { "ATI1/BC4", true, false, 4, 8, Image::FORMAT_RGTC_R }, + { "ATI2/3DC/BC5", true, false, 4, 16, Image::FORMAT_RGTC_RG }, + { "A2XY/DXN/BC5", true, false, 4, 16, Image::FORMAT_RGTC_RG }, + { "BGRA8", false, false, 1, 4, Image::FORMAT_RGBA8 }, + { "BGR8", false, false, 1, 3, Image::FORMAT_RGB8 }, + { "RGBA8", false, false, 1, 4, Image::FORMAT_RGBA8 }, + { "RGB8", false, false, 1, 3, Image::FORMAT_RGB8 }, + { "BGR5A1", false, false, 1, 2, Image::FORMAT_RGBA8 }, + { "BGR565", false, false, 1, 2, Image::FORMAT_RGB8 }, + { "BGR10A2", false, false, 1, 4, Image::FORMAT_RGBA8 }, + { "GRAYSCALE", false, false, 1, 1, Image::FORMAT_L8 }, + { "GRAYSCALE_ALPHA", false, false, 1, 2, Image::FORMAT_LA8 } +}; + RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) { if (r_error) { *r_error = ERR_CANT_OPEN;