mirror of
https://github.com/Vita3K/Vita3K.git
synced 2026-11-06 22:34:49 +01:00
* external: Update CLI11 to version 2.6.2 * external: Update MoltenVK to version 1.4.1 * external: Update VulkanMemoryAllocator-Hpp * external: Update capstone to version 5.0.9 * external: Update concurrentqueue to version 1.0.5 * external: Update cubeb * external: Update curl to version 8.21.0 * external: Update ddspp to version 1.13 * external: Update dirent to version 1.26 * external: Update googletest to version 1.17.0 * external: Update miniz to version 3.1.2 * external: Update nativefiledialog-extended to version 1.3.0 * external: Update openssl to version 4.0.1 * external: Update pugixml to version 1.16 * external: Update sdl to version 3.2.30 * external: Update spdlog to version 1.17.0 * external: Update stb * external: Update vita-toolchain * external: Update yaml-cpp to version 0.9.0 * cmake: Add expected hash for file downloads
DDS++
DDS image readers are typically not multiplatform and pull in many extra headers (e.g. the fantastic gli or Microsoft DirectXTex) This single no-dependency header can decode and encode the DDS headers and compute the mipmap and slice offset of a given DDS texture. It is meant as an aid to provide this information directly to graphics APIs to upload data to the GPU.
Usage
The code below is not meant to be an exhaustive example on how to create textures from a DDS file, merely a guideline of how you would go about using this in your own engine/API.
#include "ddspp.h"
// Load image as a stream of bytes
const char* ddsData = ...
// Decode header and get pointer to initial data
ddspp::Descriptor desc;
ddspp::Result decodeResult = ddspp::decode_header(ddsData, desc);
// Feed to the graphics API
if(decodeResult == ddspp::Success)
{
const char* initialData = ddsData + desc.headerSize;
// D3D example
{
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
srvDesc.Format = desc.format; // Maps directly to D3D
if(desc.type == ddspp::Texture2D)
{
if(desc.arraySize > 1)
{
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
srvDesc.Texture2DArray.MipLevels = desc.numMips;
srvDesc.Texture2DArray.ArraySize = desc.arraySize;
}
else
{
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = desc.mipMapCount;
}
}
// ... Fill in the rest
}
// Vulkan Example
{
VkImageCreateInfo imageCreateInfo = {};
imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageCreateInfo.pNext = nullptr;
imageCreateInfo.format = GetVulkanFormat(desc.format); // Translate DXGI format to Vulkan
imageCreateInfo.extent = { desc.width, desc.height, desc.depth };
imageCreateInfo.mipLevels = desc.numMips;
imageCreateInfo.arrayLayers = desc.arraySize;
if(desc.type == ddspp::Texture2D)
{
imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
}
// ... Fill in the rest
}
}