diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2017-11-13 03:18:57 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2017-11-13 03:18:57 +0000 |
| commit | 5e3941de79b573b8798f6a6bcd4eaf544c48cde2 (patch) | |
| tree | 77f33c32420cec66a88f24555f7211c02136468a /TextureLoader/src | |
| parent | Merge from dev branch (diff) | |
| download | DiligentTools-5e3941de79b573b8798f6a6bcd4eaf544c48cde2.tar.gz DiligentTools-5e3941de79b573b8798f6a6bcd4eaf544c48cde2.zip | |
Updated to version 2.1
Diffstat (limited to 'TextureLoader/src')
| -rw-r--r-- | TextureLoader/src/DDSLoader.cpp | 17 | ||||
| -rw-r--r-- | TextureLoader/src/Image.cpp | 8 | ||||
| -rw-r--r-- | TextureLoader/src/TextureLoader.cpp | 25 | ||||
| -rw-r--r-- | TextureLoader/src/TextureUtilities.cpp | 65 |
4 files changed, 68 insertions, 47 deletions
diff --git a/TextureLoader/src/DDSLoader.cpp b/TextureLoader/src/DDSLoader.cpp index 37bccf6..34a625a 100644 --- a/TextureLoader/src/DDSLoader.cpp +++ b/TextureLoader/src/DDSLoader.cpp @@ -537,6 +537,7 @@ static void GetSurfaceInfo( case DXGI_FORMAT_G8R8_G8B8_UNORM: packed = true; break; + default: break; } if (bc) @@ -930,6 +931,7 @@ static void CreateTexture( _In_ size_t arraySize, _In_ DXGI_FORMAT format, _In_ USAGE usage, + _In_ const char *name, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, @@ -951,6 +953,7 @@ static void CreateTexture( } TextureDesc desc; + desc.Name = name; desc.Width = static_cast<Uint32>(width); desc.MipLevels = static_cast<Uint32>(mipCount); desc.ArraySize = static_cast<Uint32>(arraySize); @@ -1150,6 +1153,7 @@ static void CreateTextureFromDDS( _In_ size_t bitSize, _In_ size_t maxsize, _In_ USAGE usage, + _In_ const char *name, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, @@ -1319,7 +1323,7 @@ static void CreateTextureFromDDS( size_t tdepth = 0; FillInitData(width, height, depth, mipCount, arraySize, format, maxsize, bitSize, bitData, twidth, theight, tdepth, skipMip, initData.get()); - CreateTexture(pDevice, resDim, twidth, theight, tdepth, mipCount - skipMip, arraySize, format, usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB, isCubeMap, initData.get(), texture/*, textureView*/); + CreateTexture(pDevice, resDim, twidth, theight, tdepth, mipCount - skipMip, arraySize, format, usage, name, bindFlags, cpuAccessFlags, miscFlags, forceSRGB, isCubeMap, initData.get(), texture/*, textureView*/); #if 0 if (FAILED(hr) && !maxsize && (mipCount > 1)) @@ -1403,11 +1407,11 @@ void CreateDDSTextureFromMemory( const Uint8* ddsData, size_t ddsDataSize, ITexture** texture, - size_t maxsize/*, - D2D1_ALPHA_MODE* alphaMode*/ - ) + size_t maxsize, + /*D2D1_ALPHA_MODE* alphaMode,*/ + const char* name) { - return CreateDDSTextureFromMemoryEx(pDevice, ddsData, ddsDataSize, maxsize, USAGE_DEFAULT, BIND_SHADER_RESOURCE, 0, 0, false, texture/*, alphaMode*/); + return CreateDDSTextureFromMemoryEx(pDevice, ddsData, ddsDataSize, maxsize, USAGE_DEFAULT, name, BIND_SHADER_RESOURCE, 0, 0, false, texture/*, alphaMode*/); } @@ -1418,6 +1422,7 @@ void CreateDDSTextureFromMemoryEx( size_t ddsDataSize, size_t maxsize, USAGE usage, + const char *name, unsigned int bindFlags, unsigned int cpuAccessFlags, unsigned int miscFlags, @@ -1482,7 +1487,7 @@ void CreateDDSTextureFromMemoryEx( ptrdiff_t offset = sizeof(Uint32) + sizeof(DDS_HEADER) + (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0); - CreateTextureFromDDS(pDevice, header, ddsData + offset, ddsDataSize - offset, maxsize, usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB, texture/*, textureView*/); + CreateTextureFromDDS(pDevice, header, ddsData + offset, ddsDataSize - offset, maxsize, usage, name, bindFlags, cpuAccessFlags, miscFlags, forceSRGB, texture/*, textureView*/); //if (alphaMode) // *alphaMode = GetAlphaMode(header); diff --git a/TextureLoader/src/Image.cpp b/TextureLoader/src/Image.cpp index e47b311..2cf0dbe 100644 --- a/TextureLoader/src/Image.cpp +++ b/TextureLoader/src/Image.cpp @@ -386,11 +386,13 @@ namespace Diligent // warnings occurred (test whether jerr.pub.num_warnings is nonzero). } - Image::Image( Diligent::IFileStream *pSrcFile, + Image::Image( IReferenceCounters *pRefCounters, + IFileStream *pSrcFile, const ImageLoadInfo& LoadInfo ) : - m_pData( new Diligent::DataBlobImpl ) + TBase(pRefCounters), + m_pData( MakeNewRCObj<DataBlobImpl>()(0) ) { - RefCntAutoPtr<IDataBlob> pFileData( new Diligent::DataBlobImpl ); + RefCntAutoPtr<IDataBlob> pFileData( MakeNewRCObj<DataBlobImpl>()(0) ); pSrcFile->Read(pFileData); if( LoadInfo.Format == EImageFileFormat::tiff ) diff --git a/TextureLoader/src/TextureLoader.cpp b/TextureLoader/src/TextureLoader.cpp index 14f6f24..cf7a32d 100644 --- a/TextureLoader/src/TextureLoader.cpp +++ b/TextureLoader/src/TextureLoader.cpp @@ -119,6 +119,7 @@ namespace Diligent { const auto& ImgDesc = pSrcImage->GetDesc(); TextureDesc TexDesc; + TexDesc.Name = TexLoadInfo.Name; TexDesc.Type = RESOURCE_DIM_TEX_2D; TexDesc.Width = ImgDesc.Width; TexDesc.Height = ImgDesc.Height; @@ -204,16 +205,19 @@ namespace Diligent CoarseMipStride = (CoarseMipStride + 3) & (-4); Mips[m].resize(CoarseMipStride * CoarseMipHeight); - if( ChannelDepth == 8 ) - ComputeCoarseMip<Uint8>( NumComponents, IsSRGB, - pSubResources[m-1].pData, pSubResources[m-1].Stride, - Mips[m].data(), CoarseMipStride, - CoarseMipWidth, CoarseMipHeight); - else if( ChannelDepth == 16 ) - ComputeCoarseMip<Uint16>( NumComponents, IsSRGB, - pSubResources[m-1].pData, pSubResources[m-1].Stride, - Mips[m].data(), CoarseMipStride, - CoarseMipWidth, CoarseMipHeight); + if (TexLoadInfo.GenerateMips) + { + if (ChannelDepth == 8) + ComputeCoarseMip<Uint8>(NumComponents, IsSRGB, + pSubResources[m - 1].pData, pSubResources[m - 1].Stride, + Mips[m].data(), CoarseMipStride, + CoarseMipWidth, CoarseMipHeight); + else if (ChannelDepth == 16) + ComputeCoarseMip<Uint16>(NumComponents, IsSRGB, + pSubResources[m - 1].pData, pSubResources[m - 1].Stride, + Mips[m].data(), CoarseMipStride, + CoarseMipWidth, CoarseMipHeight); + } pSubResources[m].pData = Mips[m].data(); pSubResources[m].Stride = CoarseMipStride; @@ -239,6 +243,7 @@ namespace Diligent static_cast<size_t>(pDDSData->GetSize()), 0, // maxSize TexLoadInfo.Usage, + TexLoadInfo.Name, TexLoadInfo.BindFlags, TexLoadInfo.CPUAccessFlags, 0, // miscFlags diff --git a/TextureLoader/src/TextureUtilities.cpp b/TextureLoader/src/TextureUtilities.cpp index 48f5bd5..3bd8442 100644 --- a/TextureLoader/src/TextureUtilities.cpp +++ b/TextureLoader/src/TextureUtilities.cpp @@ -40,40 +40,49 @@ void CreateImageFromFile( const Diligent::Char *FilePath, Image **ppImage, IDataBlob **ppDDSData) { - auto *pDotPos = strrchr( FilePath, '.' ); - if( pDotPos == nullptr ) - LOG_ERROR_AND_THROW( "File path ", FilePath, " does not contain extension" ); + try + { + auto *pDotPos = strrchr(FilePath, '.'); + if (pDotPos == nullptr) + LOG_ERROR_AND_THROW("File path \"", FilePath, "\" does not contain extension"); - auto *pExtension = pDotPos + 1; - if( *pExtension == 0 ) - LOG_ERROR_AND_THROW( "File path ", FilePath, " contains empty extension" ); + auto *pExtension = pDotPos + 1; + if (*pExtension == 0) + LOG_ERROR_AND_THROW("File path \"", FilePath, "\" contains empty extension"); - String Extension(pExtension); - std::transform( Extension.begin(), Extension.end(), Extension.begin(), ::tolower ); + String Extension(pExtension); + std::transform(Extension.begin(), Extension.end(), Extension.begin(), ::tolower); - Diligent::RefCntAutoPtr<BasicFileStream> pFileStream( new BasicFileStream( FilePath, EFileAccessMode::Read ) ); + RefCntAutoPtr<BasicFileStream> pFileStream(MakeNewRCObj<BasicFileStream>()(FilePath, EFileAccessMode::Read)); + if(!pFileStream->IsValid()) + LOG_ERROR_AND_THROW("Failed to open image file \"", FilePath, '\"'); - if( Extension == "dds" ) - { - VERIFY_EXPR(ppDDSData != nullptr); - *ppDDSData = new DataBlobImpl; - pFileStream->Read(*ppDDSData); - (*ppDDSData)->AddRef(); - } - else - { - ImageLoadInfo ImgLoadInfo; - if( Extension == "png" ) - ImgLoadInfo.Format = EImageFileFormat::png; - else if( Extension == "jpeg" || Extension == "jpg" ) - ImgLoadInfo.Format = EImageFileFormat::jpeg; - else if( Extension == "tiff" || Extension == "tif" ) - ImgLoadInfo.Format = EImageFileFormat::tiff; + if (Extension == "dds") + { + VERIFY_EXPR(ppDDSData != nullptr); + *ppDDSData = MakeNewRCObj<DataBlobImpl>()(0); + pFileStream->Read(*ppDDSData); + (*ppDDSData)->AddRef(); + } else - LOG_ERROR_AND_THROW( "Unsupported file format ", Extension ); + { + ImageLoadInfo ImgLoadInfo; + if (Extension == "png") + ImgLoadInfo.Format = EImageFileFormat::png; + else if (Extension == "jpeg" || Extension == "jpg") + ImgLoadInfo.Format = EImageFileFormat::jpeg; + else if (Extension == "tiff" || Extension == "tif") + ImgLoadInfo.Format = EImageFileFormat::tiff; + else + LOG_ERROR_AND_THROW("Unsupported file format ", Extension); - *ppImage = new Image(pFileStream, ImgLoadInfo); - (*ppImage)->AddRef(); + *ppImage = MakeNewRCObj<Image>()(pFileStream, ImgLoadInfo); + (*ppImage)->AddRef(); + } + } + catch (std::runtime_error &err) + { + LOG_ERROR("Failed to create image from file: ", err.what()) } } |
