From 450a6606cedbf45aa888637058af4742d5491b01 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 28 Apr 2019 14:32:59 -0700 Subject: Implemented loading textures from KTX --- TextureLoader/interface/Image.h | 38 ++++++++++++++++++------------ TextureLoader/interface/TextureLoader.h | 24 ++++++++++++++----- TextureLoader/interface/TextureUtilities.h | 23 +++++++++--------- 3 files changed, 53 insertions(+), 32 deletions(-) (limited to 'TextureLoader/interface') diff --git a/TextureLoader/interface/Image.h b/TextureLoader/interface/Image.h index 5b9860e..a970d77 100644 --- a/TextureLoader/interface/Image.h +++ b/TextureLoader/interface/Image.h @@ -47,7 +47,13 @@ enum class EImageFileFormat png, /// The image is encoded in TIFF format - tiff + tiff, + + /// DDS file + dds, + + /// KTX file + ktx }; /// Image loading information @@ -106,30 +112,32 @@ public: static void Encode(const EncodeInfo& Info, IDataBlob** ppEncodedData); /// Returns image description - const ImageDesc &GetDesc(){ return m_Desc; } + const ImageDesc& GetDesc(){ return m_Desc; } /// Returns a pointer to the image data - IDataBlob *GetData(){ return m_pData; } + IDataBlob* GetData(){ return m_pData; } static std::vector ConvertImageData(Uint32 Width, - Uint32 Height, - const Uint8* pData, - Uint32 Stride, - TEXTURE_FORMAT SrcFormat, - TEXTURE_FORMAT DstFormat, - bool KeepAlpha); + Uint32 Height, + const Uint8* pData, + Uint32 Stride, + TEXTURE_FORMAT SrcFormat, + TEXTURE_FORMAT DstFormat, + bool KeepAlpha); + + static EImageFileFormat GetFileFormat(const Uint8* pData, size_t Size); private: template friend class MakeNewRCObj; - Image(IReferenceCounters *pRefCounters, - IDataBlob *pFileData, - const ImageLoadInfo& LoadInfo); + Image(IReferenceCounters* pRefCounters, + IDataBlob* pFileData, + const ImageLoadInfo& LoadInfo); - void LoadPngFile( IDataBlob *pFileData, const ImageLoadInfo& LoadInfo ); - void LoadTiffFile( IDataBlob *pFileData,const ImageLoadInfo& LoadInfo ); - void LoadJpegFile( IDataBlob *pFileData,const ImageLoadInfo& LoadInfo ); + void LoadPngFile( IDataBlob* pFileData, const ImageLoadInfo& LoadInfo ); + void LoadTiffFile( IDataBlob* pFileData, const ImageLoadInfo& LoadInfo ); + void LoadJpegFile( IDataBlob* pFileData, const ImageLoadInfo& LoadInfo ); ImageDesc m_Desc; RefCntAutoPtr m_pData; diff --git a/TextureLoader/interface/TextureLoader.h b/TextureLoader/interface/TextureLoader.h index ffc86d0..4de89fb 100644 --- a/TextureLoader/interface/TextureLoader.h +++ b/TextureLoader/interface/TextureLoader.h @@ -75,10 +75,10 @@ namespace Diligent /// \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 CreateTextureFromImage( Image *pSrcImage, + void CreateTextureFromImage( Image* pSrcImage, const TextureLoadInfo& TexLoadInfo, - IRenderDevice *pDevice, - ITexture **ppTexture ); + IRenderDevice* pDevice, + ITexture** ppTexture ); /// Creates a texture from DDS data blob @@ -86,8 +86,20 @@ namespace Diligent /// \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 CreateTextureFromDDS( IDataBlob *pDDSData, + void CreateTextureFromDDS( IDataBlob* pDDSData, const TextureLoadInfo& TexLoadInfo, - IRenderDevice *pDevice, - ITexture **ppTexture ); + IRenderDevice* pDevice, + ITexture** ppTexture ); + + + /// Creates a texture from KTX data blob + + /// \param [in] pKTXData - Pointer to the KTX data blob + /// \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 CreateTextureFromKTX( IDataBlob* pKTXData, + const TextureLoadInfo& TexLoadInfo, + IRenderDevice* pDevice, + ITexture** ppTexture ); }; diff --git a/TextureLoader/interface/TextureUtilities.h b/TextureLoader/interface/TextureUtilities.h index 82fbf8d..73ba1e0 100644 --- a/TextureLoader/interface/TextureUtilities.h +++ b/TextureLoader/interface/TextureUtilities.h @@ -36,13 +36,14 @@ namespace Diligent /// Creates an image from file -/// \param [in] FilePath - Source file path -/// \param [out] ppImage - Memory location where pointer to the created image will be stored -/// \param [out] ppDDSData - If the file is a dds file, this will contain the pointer to the blob -/// containing dds data. This parameter can be null. -void CreateImageFromFile( const Char *FilePath, - Image **ppImage, - IDataBlob **ppDDSData = nullptr); +/// \param [in] FilePath - Source file path +/// \param [out] ppImage - Memory location where pointer to the created image will be stored +/// \param [out] ppRawData - If the file format is not recognized by the function, it will load raw bytes +/// and return them in the data blob. This parameter can be null. +/// \return Image file format. +EImageFileFormat CreateImageFromFile(const Char* FilePath, + Image** ppImage, + IDataBlob** ppRawData = nullptr); /// Creates a texture from file @@ -51,9 +52,9 @@ void CreateImageFromFile( const Char *FilePath, /// \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 CreateTextureFromFile( const Char *FilePath, - const TextureLoadInfo& TexLoadInfo, - IRenderDevice *pDevice, - ITexture **ppTexture ); +void CreateTextureFromFile( const Char* FilePath, + const TextureLoadInfo& TexLoadInfo, + IRenderDevice* pDevice, + ITexture** ppTexture ); } -- cgit v1.2.3