diff --git a/Assets/RaccoonPreTexturedVer1_Base9.shtex b/Assets/RaccoonPreTexturedVer1_Base9.shtex new file mode 100644 index 00000000..38e0cd0f Binary files /dev/null and b/Assets/RaccoonPreTexturedVer1_Base9.shtex differ diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 0584d39b..fa626d63 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -84,7 +84,8 @@ namespace Sandbox //SHADE::SHAssetManager::LoadDataTemp("../../Assets/racoon.gltf"); SHADE::SHAssetManager::LoadDataTemp("../../Assets/Cube.012.shmesh"); //SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonBag_Color_Ver4.dds"); - SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.dds"); + //SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.dds"); + SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.shtex"); //TODO: REMOVE AFTER PRESENTATION //SHADE::SHSystemManager::RegisterRoutine(); diff --git a/SHADE_Engine/src/Assets/Asset Types/SHTextureAsset.h b/SHADE_Engine/src/Assets/Asset Types/SHTextureAsset.h index 94b1b74c..634d9a9a 100644 --- a/SHADE_Engine/src/Assets/Asset Types/SHTextureAsset.h +++ b/SHADE_Engine/src/Assets/Asset Types/SHTextureAsset.h @@ -7,6 +7,8 @@ namespace SHADE { struct SHTextureAsset { + bool compiled; + uint32_t numBytes; uint32_t width; uint32_t height; diff --git a/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.cpp b/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.cpp index a2fc3b77..62af4da6 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.cpp +++ b/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.cpp @@ -19,7 +19,11 @@ namespace SHADE { void SHTextureCompiler::CompileTextureBinary(SHTextureAsset const& asset, AssetPath path) { - std::ofstream file{path, std::ios::out | std::ios::binary}; + std::string newPath{ path.string() }; + newPath = newPath.substr(0, newPath.find_last_of('.')); + newPath += TEXTURE_EXTENSION; + + std::ofstream file{ newPath, std::ios::out | std::ios::binary }; if (!file.is_open()) { SHLOG_ERROR("Unable to open file for writing texture file: {}", path.string()); @@ -46,18 +50,13 @@ namespace SHADE file.write( reinterpret_cast(&asset.format), - sizeof(SHTexture::PixelChannel) + sizeof(SHTexture::TextureFormat) ); file.write( reinterpret_cast(&mipOffsetCount), intBytes ); - - file.write( - reinterpret_cast(&asset.numBytes), - intBytes - ); file.write( reinterpret_cast(asset.mipOffsets.data()), diff --git a/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp b/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp index 68f86030..1047cdc6 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp @@ -93,6 +93,7 @@ namespace SHADE std::memcpy(pixel, file.GetImageData()->m_mem, totalBytes); //pixel = std::move(reinterpret_cast(file.GetDDSData())); + asset.compiled = false; asset.numBytes = totalBytes; asset.width = file.GetWidth(); asset.height = file.GetHeight(); @@ -109,38 +110,25 @@ namespace SHADE SHLOG_ERROR("Error opening SHTexture file: {}", path.string()); } - tinyddsloader::DDSFile::DXGIFormat format; - uint32_t formatCarrier; + auto const intBytes{ sizeof(uint32_t) }; uint32_t mipCount; - uint32_t byteCount; - file >> asset.numBytes; - file >> asset.width; - file >> asset.height; - - file >> formatCarrier; - asset.format = ddsLoaderToVkFormat(static_cast(formatCarrier), true); - - file >> mipCount; - file >> byteCount; + file.read(reinterpret_cast(&asset.numBytes), intBytes); + file.read(reinterpret_cast(&asset.width), intBytes); + file.read(reinterpret_cast(&asset.height), intBytes); + file.read(reinterpret_cast(&asset.format), sizeof(SHTexture::TextureFormat)); + file.read(reinterpret_cast(&mipCount), intBytes); std::vector mips(mipCount); - for (auto i {0}; i < mipCount; ++i) - { - file >> mips[i]; - } + file.read(reinterpret_cast(mips.data()), intBytes * mipCount); + + auto pixel = new SHTexture::PixelChannel[asset.numBytes]; + file.read(reinterpret_cast(pixel), asset.numBytes); asset.mipOffsets = std::move(mips); - - auto pixel = new SHTexture::PixelChannel[byteCount]; - auto pixelIt{ pixel }; - - while(!file.eof()) - { - file >> *(pixelIt++); - } asset.pixelData = std::move( pixel ); + asset.compiled = true; file.close(); } diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index dde3b0e2..989cd2ad 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -18,6 +18,7 @@ #include "Libraries/SHTextureLoader.h" #include "Libraries/SHMeshCompiler.h" +#include "Libraries/SHTextureCompiler.h" namespace SHADE { @@ -215,7 +216,8 @@ namespace SHADE } ); } - else if (path.extension().string() == DDS_EXTENSION) + else if (path.extension().string() == DDS_EXTENSION + || path.extension().string() == TEXTURE_EXTENSION) { LoadDDS( { @@ -319,6 +321,11 @@ namespace SHADE SHTextureLoader::LoadImageAsset(asset.path, image); textureCollection.emplace(GenerateAssetID(AssetType::DDS), image); + + if (!image.compiled) + { + SHTextureCompiler::CompileTextureBinary(image, asset.path); + } } /****************************************************************************