CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Common/Data/Format/DDSLoad.h
Views: 1401
#pragma once12#include <cstdint>34// DDSPixelFormat.dwFlags bits5enum {6DDPF_ALPHAPIXELS = 1, // Texture contains alpha data; dwRGBAlphaBitMask contains valid data.7DDPF_ALPHA = 2, // Used in some older DDS files for alpha channel only uncompressed data(dwRGBBitCount contains the alpha channel bitcount; dwABitMask contains valid data)8DDPF_FOURCC = 4, // Texture contains compressed RGB data; dwFourCC contains valid data. 0x49DDPF_RGB = 8, // Texture contains uncompressed RGB data; dwRGBBitCount and the RGB masks(dwRBitMask, dwGBitMask, dwBBitMask) contain valid data. 0x4010DDPF_YUV = 16, //Used in some older DDS files for YUV uncompressed data(dwRGBBitCount contains the YUV bit count; dwRBitMask contains the Y mask, dwGBitMask contains the U mask, dwBBitMask contains the V mask)11DDPF_LUMINANCE = 32, // Used in some older DDS files for single channel color uncompressed data (dwRGBBitCount contains the luminance channel bit count; dwRBitMask contains the channel mask). Can be combined with DDPF_ALPHAPIXELS for a two channel DDS file.12};1314// dwCaps members15enum {16DDSCAPS_COMPLEX = 8,17DDSCAPS_MIPMAP = 0x400000,18DDSCAPS_TEXTURE = 0x1000, // Required19};2021// Not using any D3D headers here, this is cross platform and minimal.22// Boiled down from the public documentation.23struct DDSPixelFormat {24uint32_t dwSize; // must be 3225uint32_t dwFlags;26uint32_t dwFourCC;27uint32_t dwRGBBitCount;28uint32_t dwRBitMask;29uint32_t dwGBitMask;30uint32_t dwBBitMask;31uint32_t dwABitMask;32};3334struct DDSHeader {35uint32_t dwMagic; // Magic is not technically part of the header struct but convenient to have here when reading the files.36uint32_t dwSize; // must be 12437uint32_t dwFlags;38uint32_t dwHeight;39uint32_t dwWidth;40uint32_t dwPitchOrLinearSize; // The pitch or number of bytes per scan line in an uncompressed texture; the total number of bytes in the top level texture for a compressed texture41uint32_t dwDepth; // we'll always use 1 here42uint32_t dwMipMapCount;43uint32_t dwReserved1[11];44DDSPixelFormat ddspf;45uint32_t dwCaps;46uint32_t dwCaps2; // nothing we care about47uint32_t dwCaps3; // unused48uint32_t dwCaps4; // unused49uint32_t dwReserved2;50};5152// DDS header extension to handle resource arrays, DXGI pixel formats that don't map to the legacy Microsoft DirectDraw pixel format structures, and additional metadata.53struct DDSHeaderDXT10 {54uint32_t dxgiFormat;55uint32_t resourceDimension; // 1d = 2, 2d = 3, 3d = 4. very intuitive56uint32_t miscFlag;57uint32_t arraySize; // we only support 1 here58uint32_t miscFlags2; // sets alpha interpretation, let's not bother59};6061// Simple DDS parser, suitable for texture replacement packs.62// Doesn't actually load, only does some logic to fill out DDSLoadInfo so the caller can then63// do the actual load with a simple series of memcpys or whatever is appropriate.64struct DDSLoadInfo {65uint32_t bytesToCopy;66};6768bool DetectDDSParams(const DDSHeader *header, DDSLoadInfo *info);6970// We use the Basis library for the actual reading, but before we do, we pre-scan using this, similarly to the png trick.71struct KTXHeader {72uint8_t identifier[12];73uint32_t vkFormat;74uint32_t typeSize;75uint32_t pixelWidth;76uint32_t pixelHeight;77uint32_t pixelDepth;78uint32_t layerCount;79uint32_t faceCount;80uint32_t levelCount;81uint32_t supercompressionScheme;82};838485