Skip to content

Commit ea863f0

Browse files
Texture loader: added CreateTextureLoaderFromDataBlob function
1 parent 7df60d6 commit ea863f0

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

TextureLoader/interface/TextureLoader.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ DILIGENT_END_INTERFACE
223223

224224
/// \param [in] pSrcImage - Pointer to the source image object.
225225
/// \param [in] TexLoadInfo - Texture loading information, see Diligent::TextureLoadInfo.
226-
/// \param [out] ppLoader - Memory location where pointer to the created texture loader will be written.
226+
/// \param [out] ppLoader - Memory location where a pointer to the created texture loader will be written.
227227
void DILIGENT_GLOBAL_FUNCTION(CreateTextureLoaderFromImage)(struct Image* pSrcImage,
228228
const TextureLoadInfo REF TexLoadInfo,
229229
ITextureLoader** ppLoader);
@@ -234,19 +234,19 @@ void DILIGENT_GLOBAL_FUNCTION(CreateTextureLoaderFromImage)(struct Image*
234234
/// \param [in] FileFormat - File format. If this parameter is IMAGE_FILE_FORMAT_UNKNOWN,
235235
/// the format will be derived from the file contents.
236236
/// \param [in] TexLoadInfo - Texture loading information, see Diligent::TextureLoadInfo.
237-
/// \param [out] ppLoader - Memory location where pointer to the created texture loader will be written.
237+
/// \param [out] ppLoader - Memory location where a pointer to the created texture loader will be written.
238238
void DILIGENT_GLOBAL_FUNCTION(CreateTextureLoaderFromFile)(const char* FilePath,
239239
IMAGE_FILE_FORMAT FileFormat,
240240
const TextureLoadInfo REF TexLoadInfo,
241241
ITextureLoader** ppLoader);
242242

243243
/// Creates a texture loader from memory.
244244

245-
/// \param [in] pData - Pointer to the data.
245+
/// \param [in] pData - Pointer to the texture data.
246246
/// \param [in] Size - The data size.
247247
/// \param [in] MakeCopy - Whether to make the copy of the data (see remarks).
248248
/// \param [in] TexLoadInfo - Texture loading information, see Diligent::TextureLoadInfo.
249-
/// \param [out] ppLoader - Memory location where pointer to the created texture loader will be written.
249+
/// \param [out] ppLoader - Memory location where a pointer to the created texture loader will be written.
250250
///
251251
/// \remarks If MakeCopy is false, the pointer to the memory must remain valid until the
252252
/// texture loader object is destroyed.
@@ -256,6 +256,16 @@ void DILIGENT_GLOBAL_FUNCTION(CreateTextureLoaderFromMemory)(const void*
256256
const TextureLoadInfo REF TexLoadInfo,
257257
ITextureLoader** ppLoader);
258258

259+
/// Creates a texture loader from data blob.
260+
///
261+
/// \param [in] pDataBlob - Pointer to the data blob that contains the texture data.
262+
/// \param [in] TexLoadInfo - Texture loading information, see Diligent::TextureLoadInfo.
263+
/// \param [out] ppLoader - Memory location where a pointer to the created texture loader will be written.
264+
///
265+
/// \remarks If needed, the loader will keep a strong reference to the data blob.
266+
void DILIGENT_GLOBAL_FUNCTION(CreateTextureLoaderFromDataBlob)(IDataBlob* pDataBlob,
267+
const TextureLoadInfo REF TexLoadInfo,
268+
ITextureLoader** ppLoader);
259269

260270
/// Writes texture data as DDS file.
261271

TextureLoader/src/TextureLoaderImpl.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,22 @@ void CreateTextureLoaderFromMemory(const void* pData,
517517
}
518518
}
519519

520+
void CreateTextureLoaderFromDataBlob(IDataBlob* pDataBlob,
521+
const TextureLoadInfo& TexLoadInfo,
522+
ITextureLoader** ppLoader)
523+
{
524+
try
525+
{
526+
RefCntAutoPtr<ITextureLoader> pTexLoader{MakeNewRCObj<TextureLoaderImpl>()(TexLoadInfo, pDataBlob->GetConstDataPtr<Uint8>(), pDataBlob->GetSize(), RefCntAutoPtr<IDataBlob>{pDataBlob})};
527+
if (pTexLoader)
528+
pTexLoader->QueryInterface(IID_TextureLoader, reinterpret_cast<IObject**>(ppLoader));
529+
}
530+
catch (std::runtime_error& err)
531+
{
532+
LOG_ERROR("Failed to create texture loader from data blob: ", err.what());
533+
}
534+
}
535+
520536
void CreateTextureLoaderFromImage(Image* pSrcImage,
521537
const TextureLoadInfo& TexLoadInfo,
522538
ITextureLoader** ppLoader)

0 commit comments

Comments
 (0)