How to use fileformats/nv_dds and fileformats/nv_ktx
Hello! How to load .dds and .ktx files to vulkan image with fileformats/nv_dds and fileformats/nv_ktx? Can you show small example?
Hi @tigrazone !
We have an image_ktx sample for the KTX loader. Its core code looks like this:
#include "fileformats/nv_ktx.h"
...
nv_ktx::KTXImage ktx_image;
const nv_ktx::ReadSettings ktx_read_settings;
nv_ktx::ErrorWithText maybe_error = ktx_image.readFromFile(filename.c_str(), ktx_read_settings);
if(maybe_error.has_value())
{
LOGE("KTX Error: %s\n", maybe_error->c_str());
}
Nv_dds is used in the gl_vk_chopper sample here. The code for that looks like this:
#include "fileformats/nv_dds.h"
...
nv_dds::CDDSImage ddsImage;
ddsImage.load(filePath, true);
if(!ddsImage.is_valid())
{
LOGE("Could not load texture image %s\n", inFile);
exit(1);
}
else
{
LOGI("loaded texture image %s\n", filePath.c_str());
}
Note that, as of this writing, nv_ktx is much safer to use than nv_dds. Nv_ktx has thorough error-checking, is fuzz-tested with libFuzzer, AddressSanitizer, and UndefinedBehaviorSanitizer, has passed static analysis, and I consider it safe to use on any input. Nv_dds should currently only be used on images you trust/know are good, and not malicious.
Hope this helps!
thank you. I will try. My needs is only read task
Quickly updating this to mention that we just released nv_dds 2.0! It's now fuzz-tested, supports many more kinds of DDS files (including obscure color transforms like YCoCgScaled), but breaks the API to more closely match nv_ktx. Here's how to read a DDS file now:
#include "fileformats/nv_dds.h"
...
nv_dds::Image image;
nv_dds::ErrorWithText maybe_error = image.readFromFile("data/image.dds", {});
if(maybe_error.has_value())
{
// Do something with the error message, maybe_error.value()
}
else
{
// Access subresources using image.subresource(...), and upload them
// to the GPU using your graphics API of choice.
}
Hope this helps; let me know if you have any questions about it! Closing this issue for now.