diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-04-01 18:32:52 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-04-01 18:32:52 +0000 |
| commit | 3800d79e3d5491340e22cbf237ec4b62b75545a2 (patch) | |
| tree | 25d6a8eb1a4efe07e7d2a6547e3655ce5f8b3f87 /TextureLoader/interface | |
| parent | Minor update (diff) | |
| download | DiligentTools-3800d79e3d5491340e22cbf237ec4b62b75545a2.tar.gz DiligentTools-3800d79e3d5491340e22cbf237ec4b62b75545a2.zip | |
Some updates to texture loading routines.
Fixed https://github.com/DiligentGraphics/DiligentTools/issues/3
Diffstat (limited to 'TextureLoader/interface')
| -rw-r--r-- | TextureLoader/interface/Image.h | 67 | ||||
| -rw-r--r-- | TextureLoader/interface/TextureLoader.h | 58 | ||||
| -rw-r--r-- | TextureLoader/interface/TextureUtilities.h | 21 |
3 files changed, 107 insertions, 39 deletions
diff --git a/TextureLoader/interface/Image.h b/TextureLoader/interface/Image.h index ba8f09f..b4abdc3 100644 --- a/TextureLoader/interface/Image.h +++ b/TextureLoader/interface/Image.h @@ -30,51 +30,78 @@ namespace Diligent { + /// Image file format enum class EImageFileFormat { + /// Unknown format unknown = 0, + + /// The image is encoded in JPEG format jpeg, + + /// The image is encoded in PNG format png, + + /// The image is encoded in TIFF format tiff }; + /// Image loading information struct ImageLoadInfo { - EImageFileFormat Format; - ImageLoadInfo() : - Format(EImageFileFormat::unknown) - {} + /// Image file format + EImageFileFormat Format = EImageFileFormat::unknown; }; + /// Image description struct ImageDesc { - Diligent::Uint32 Width; - Diligent::Uint32 Height; - Diligent::Uint32 BitsPerPixel; - Diligent::Uint32 NumComponents; - Diligent::Uint32 RowStride; // In bytes - ImageDesc() : - Width(0), - Height(0), - BitsPerPixel(0), - NumComponents(0), - RowStride(0) - {} + /// Image width in pixels + Uint32 Width = 0; + + /// Image height in pixels + Uint32 Height = 0; + + /// Bits per pixel + Uint32 BitsPerPixel = 0; + + /// Number of color components + Uint32 NumComponents = 0; + + /// Image row stride in bytes + Uint32 RowStride = 0; }; + /// Implementation of a 2D image class Image : public ObjectBase<IObject> { public: typedef ObjectBase<IObject> TBase; - Image( IReferenceCounters *pRefCounters, - Diligent::IFileStream *pSrcFile, - const ImageLoadInfo& LoadInfo ); - + /// Creates a new image from the data blob + + /// \param [in] pFileData - Pointer to the data blob containing image data + /// \param [in] LoadInfo - Image loading information + /// \param [out] ppImage - Memory location where pointer to the created image is written. + /// The image should be released via Release(). + static void CreateFromDataBlob(IDataBlob *pFileData, + const ImageLoadInfo& LoadInfo, + Image **ppImage); + + /// Returns image description const ImageDesc &GetDesc(){ return m_Desc; } + + /// Returns a pointer to the image data IDataBlob *GetData(){ return m_pData; } private: + template<typename AllocatorType, typename ObjectType> + friend class MakeNewRCObj; + + 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 ); diff --git a/TextureLoader/interface/TextureLoader.h b/TextureLoader/interface/TextureLoader.h index 3d49e07..3cb1d24 100644 --- a/TextureLoader/interface/TextureLoader.h +++ b/TextureLoader/interface/TextureLoader.h @@ -30,36 +30,64 @@ namespace Diligent { + /// Texture loading information struct TextureLoadInfo { - const Diligent::Char *Name; - Diligent::USAGE Usage; - Diligent::Uint32 BindFlags; - Diligent::Uint32 MipLevels; - Diligent::Uint32 CPUAccessFlags; - Diligent::Bool IsSRGB; - Diligent::Bool GenerateMips; - Diligent::TEXTURE_FORMAT Format; + /// Texture name passed over to the texture creation method + const Char *Name; + + /// Usage + USAGE Usage; + + /// Bind flags + Uint32 BindFlags; + + /// Number of mip levels + Uint32 MipLevels; + + /// CPU access flags + Uint32 CPUAccessFlags; + + /// Flag indicating if this texture uses sRGB gamma encoding + Bool IsSRGB; + + /// Flag indicating that the procedure should generate lower mip levels + Bool GenerateMips; + + /// Texture format + TEXTURE_FORMAT Format; TextureLoadInfo() : Name(""), - Usage( Diligent::USAGE_STATIC ), - BindFlags( Diligent::BIND_SHADER_RESOURCE ), + Usage( USAGE_STATIC ), + BindFlags( BIND_SHADER_RESOURCE ), MipLevels(0), CPUAccessFlags(0), IsSRGB(false), GenerateMips(true), - Format(Diligent::TEX_FORMAT_UNKNOWN) + Format(TEX_FORMAT_UNKNOWN) {} }; + /// Creates a texture from 2D image + + /// \param [in] pSrcImage - Pointer to the source image data + /// \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, const TextureLoadInfo& TexLoadInfo, - Diligent::IRenderDevice *pDevice, - Diligent::ITexture **ppTexture ); + IRenderDevice *pDevice, + ITexture **ppTexture ); + + /// Creates a texture from DDS data blob + /// \param [in] pDDSData - Pointer to the DDS 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 CreateTextureFromDDS( IDataBlob *pDDSData, const TextureLoadInfo& TexLoadInfo, - Diligent::IRenderDevice *pDevice, - Diligent::ITexture **ppTexture ); + IRenderDevice *pDevice, + ITexture **ppTexture ); }; diff --git a/TextureLoader/interface/TextureUtilities.h b/TextureLoader/interface/TextureUtilities.h index ffd9e56..82fbf8d 100644 --- a/TextureLoader/interface/TextureUtilities.h +++ b/TextureLoader/interface/TextureUtilities.h @@ -34,13 +34,26 @@ namespace Diligent { -void CreateImageFromFile( const Diligent::Char *FilePath, +/// 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); -void CreateTextureFromFile( const Diligent::Char *FilePath, + +/// Creates a texture from file + +/// \param [in] FilePath - Source file path +/// \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, - Diligent::IRenderDevice *pDevice, - Diligent::ITexture **ppTexture ); + IRenderDevice *pDevice, + ITexture **ppTexture ); } |
