summaryrefslogtreecommitdiffstats
path: root/TextureLoader
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-01-10 22:46:13 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-01-10 22:46:13 +0000
commit18c0c9dea9ff73f1526473aacb85f9a6bb272b13 (patch)
tree32e20e80f2ad8fb0f6798bfb6092e3239263674b /TextureLoader
parentMinor fix in GLTF resource manager (diff)
downloadDiligentTools-18c0c9dea9ff73f1526473aacb85f9a6bb272b13.tar.gz
DiligentTools-18c0c9dea9ff73f1526473aacb85f9a6bb272b13.zip
GLTF loader: reworked initial texture data to be stored as user data in the texture/allocation to make sure that GPU data is always initialized before the first use
Diffstat (limited to 'TextureLoader')
-rw-r--r--TextureLoader/interface/TextureLoader.h16
-rw-r--r--TextureLoader/src/KTXLoader.cpp14
-rw-r--r--TextureLoader/src/TextureLoader.cpp14
-rw-r--r--TextureLoader/src/TextureUtilities.cpp4
4 files changed, 28 insertions, 20 deletions
diff --git a/TextureLoader/interface/TextureLoader.h b/TextureLoader/interface/TextureLoader.h
index 72b0ebe..ebe81b4 100644
--- a/TextureLoader/interface/TextureLoader.h
+++ b/TextureLoader/interface/TextureLoader.h
@@ -104,11 +104,13 @@ void DILIGENT_GLOBAL_FUNCTION(CreateTextureFromImage)(struct Image*
/// Creates a texture from DDS data blob
-/// \param [in] pDDSData - Pointer to the DDS data blob
+/// \param [in] pDDSData - Pointer to DDS data
+/// \param [in] DataSize - DDS data size
/// \param [in] TexLoadInfo - Texture loading information
-/// \param [in] pDevice - Render device that will be used to create the texture
-/// \param [out] ppTexture - Memory location where pointer to the created texture will be stored
-void DILIGENT_GLOBAL_FUNCTION(CreateTextureFromDDS)(IDataBlob* pDDSData,
+/// \param [in] pDevice - Render device that will be used to create the texture
+/// \param [out] ppTexture - Memory location where pointer to the created texture will be stored
+void DILIGENT_GLOBAL_FUNCTION(CreateTextureFromDDS)(const void* pDDSData,
+ size_t DataSize,
const TextureLoadInfo REF TexLoadInfo,
IRenderDevice* pDevice,
ITexture** ppTexture);
@@ -116,11 +118,13 @@ void DILIGENT_GLOBAL_FUNCTION(CreateTextureFromDDS)(IDataBlob* pD
/// Creates a texture from KTX data blob
-/// \param [in] pKTXData - Pointer to the KTX data blob
+/// \param [in] pKTXData - Pointer to KTX data
+/// \param [in] DataSize - KTX data size
/// \param [in] TexLoadInfo - Texture loading information
/// \param [in] pDevice - Render device that will be used to create the texture
/// \param [out] ppTexture - Memory location where pointer to the created texture will be stored
-void DILIGENT_GLOBAL_FUNCTION(CreateTextureFromKTX)(IDataBlob* pKTXData,
+void DILIGENT_GLOBAL_FUNCTION(CreateTextureFromKTX)(const void* pKTXData,
+ size_t DataSize,
const TextureLoadInfo REF TexLoadInfo,
IRenderDevice* pDevice,
ITexture** ppTexture);
diff --git a/TextureLoader/src/KTXLoader.cpp b/TextureLoader/src/KTXLoader.cpp
index 28fa86e..7abbd1d 100644
--- a/TextureLoader/src/KTXLoader.cpp
+++ b/TextureLoader/src/KTXLoader.cpp
@@ -212,14 +212,15 @@ struct KTX10Header
std::uint32_t BytesOfKeyValueData;
};
-void CreateTextureFromKTX(IDataBlob* pKTXData,
+void CreateTextureFromKTX(const void* pKTXData,
+ size_t DataSize,
const TextureLoadInfo& TexLoadInfo,
IRenderDevice* pDevice,
ITexture** ppTexture)
{
+ const Uint8* pData = reinterpret_cast<const Uint8*>(pKTXData);
+
static constexpr Uint8 KTX10FileIdentifier[12] = {0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A};
- const Uint8* pData = reinterpret_cast<const Uint8*>(pKTXData->GetDataPtr());
- const auto DataSize = pKTXData->GetSize();
if (DataSize >= 12 && memcmp(pData, KTX10FileIdentifier, sizeof(KTX10FileIdentifier)) == 0)
{
pData += sizeof(KTX10FileIdentifier);
@@ -273,7 +274,7 @@ void CreateTextureFromKTX(IDataBlob* pKTXData,
pData += Align(MipInfo.MipSize, 4u);
}
}
- VERIFY(pData - reinterpret_cast<const Uint8*>(pKTXData->GetDataPtr()) == static_cast<ptrdiff_t>(DataSize), "Unexpected data size");
+ VERIFY(pData - reinterpret_cast<const Uint8*>(pKTXData) == static_cast<ptrdiff_t>(DataSize), "Unexpected data size");
TextureData InitData(SubresData.data(), static_cast<Uint32>(SubresData.size()));
pDevice->CreateTexture(TexDesc, &InitData, ppTexture);
@@ -288,11 +289,12 @@ void CreateTextureFromKTX(IDataBlob* pKTXData,
extern "C"
{
- void Diligent_CreateTextureFromKTX(Diligent::IDataBlob* pKTXData,
+ void Diligent_CreateTextureFromKTX(const void* pKTXData,
+ size_t DataSize,
const Diligent::TextureLoadInfo& TexLoadInfo,
Diligent::IRenderDevice* pDevice,
Diligent::ITexture** ppTexture)
{
- Diligent::CreateTextureFromKTX(pKTXData, TexLoadInfo, pDevice, ppTexture);
+ Diligent::CreateTextureFromKTX(pKTXData, DataSize, TexLoadInfo, pDevice, ppTexture);
}
} \ No newline at end of file
diff --git a/TextureLoader/src/TextureLoader.cpp b/TextureLoader/src/TextureLoader.cpp
index d402fed..d0021f6 100644
--- a/TextureLoader/src/TextureLoader.cpp
+++ b/TextureLoader/src/TextureLoader.cpp
@@ -205,14 +205,15 @@ void CreateTextureFromImage(Image* pSrcImage,
pDevice->CreateTexture(TexDesc, &TexData, ppTexture);
}
-void CreateTextureFromDDS(IDataBlob* pDDSData,
+void CreateTextureFromDDS(const void* pDDSData,
+ size_t DataSize,
const TextureLoadInfo& TexLoadInfo,
IRenderDevice* pDevice,
ITexture** ppTexture)
{
CreateDDSTextureFromMemoryEx(pDevice,
- reinterpret_cast<const Uint8*>(pDDSData->GetDataPtr()),
- static_cast<size_t>(pDDSData->GetSize()),
+ reinterpret_cast<const Uint8*>(pDDSData),
+ DataSize,
0, // maxSize
TexLoadInfo.Usage,
TexLoadInfo.Name,
@@ -269,12 +270,13 @@ extern "C"
Diligent::CreateTextureFromImage(pSrcImage, TexLoadInfo, pDevice, ppTexture);
}
- void Diligent_CreateTextureFromDDS(Diligent::IDataBlob* pDDSData,
+ void Diligent_CreateTextureFromDDS(const void* pDDSData,
+ size_t DataSize,
const Diligent::TextureLoadInfo& TexLoadInfo,
Diligent::IRenderDevice* pDevice,
Diligent::ITexture** ppTexture)
{
- Diligent::CreateTextureFromDDS(pDDSData, TexLoadInfo, pDevice, ppTexture);
+ Diligent::CreateTextureFromDDS(pDDSData, DataSize, TexLoadInfo, pDevice, ppTexture);
}
-} \ No newline at end of file
+}
diff --git a/TextureLoader/src/TextureUtilities.cpp b/TextureLoader/src/TextureUtilities.cpp
index 5f5b49e..6b0c91e 100644
--- a/TextureLoader/src/TextureUtilities.cpp
+++ b/TextureLoader/src/TextureUtilities.cpp
@@ -51,9 +51,9 @@ void CreateTextureFromFile(const Char* FilePath,
else if (pRawData)
{
if (ImgFmt == IMAGE_FILE_FORMAT_DDS)
- CreateTextureFromDDS(pRawData, TexLoadInfo, pDevice, ppTexture);
+ CreateTextureFromDDS(pRawData->GetConstDataPtr(), pRawData->GetSize(), TexLoadInfo, pDevice, ppTexture);
else if (ImgFmt == IMAGE_FILE_FORMAT_KTX)
- CreateTextureFromKTX(pRawData, TexLoadInfo, pDevice, ppTexture);
+ CreateTextureFromKTX(pRawData->GetConstDataPtr(), pRawData->GetSize(), TexLoadInfo, pDevice, ppTexture);
else
UNEXPECTED("Unexpected format");
}