MCPcopy Create free account
hub / github.com/NVIDIA-RTX/Donut / FillTextureData

Method FillTextureData

src/engine/TextureCache.cpp:184–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182}
183
184bool TextureCache::FillTextureData(
185 const std::shared_ptr<vfs::IBlob>& fileData,
186 const std::shared_ptr<TextureData>& texture,
187 const std::string& extension,
188 const std::string& mimeType) const
189{
190 if (extension == ".dds" || extension == ".DDS" || mimeType == "image/vnd-ms.dds")
191 {
192 texture->data = fileData;
193 if (!LoadDDSTextureFromMemory(*texture))
194 {
195 texture->data = nullptr;
196 log::message(m_ErrorLogSeverity, "Couldn't load DDS texture '%s'", texture->path.c_str());
197 return false;
198 }
199 }
200#ifdef DONUT_WITH_TINYEXR
201 else if (extension == ".exr" || extension == ".EXR" || mimeType == "image/aces")
202 {
203 float* data = nullptr;
204 int width = 0, height = 0;
205 char const* err = nullptr;
206
207 // This reads only 1 or 4 channel images and duplicates channels
208 // Should rewrite w/ lower level EXR functions
209 if (LoadEXRFromMemory(&data, &width, &height, (uint8_t*)fileData->data(), fileData->size(), &err) == TINYEXR_SUCCESS)
210 {
211 uint32_t channels = 4;
212 uint32_t bytesPerPixel = channels * 4;
213
214 texture->data = std::make_shared<Blob>(data, bytesPerPixel * width * height);
215 texture->width = static_cast<uint32_t>(width);
216 texture->height = static_cast<uint32_t>(height);
217 texture->format = nvrhi::Format::RGBA32_FLOAT;
218
219 texture->originalBitsPerPixel = channels * 32;
220 texture->isRenderTarget = true;
221 texture->mipLevels = 1;
222 texture->dimension = nvrhi::TextureDimension::Texture2D;
223
224 texture->dataLayout.resize(1);
225 texture->dataLayout[0].resize(1);
226 texture->dataLayout[0][0].dataOffset = 0;
227 texture->dataLayout[0][0].rowPitch = static_cast<size_t>(width * bytesPerPixel);
228 texture->dataLayout[0][0].dataSize = static_cast<size_t>(width * height * bytesPerPixel);
229
230 return true;
231 }
232 else
233 {
234 log::warning("Couldn't load EXR texture '%s'", texture->path.c_str());
235 return false;
236 }
237 }
238#endif // DONUT_WITH_TINYEXR
239 else
240 {
241 int width = 0, height = 0, originalChannels = 0, channels = 0;

Callers

nothing calls this directly

Calls 6

LoadDDSTextureFromMemoryFunction · 0.85
messageFunction · 0.85
warningFunction · 0.85
resetMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected