SP3-237 Texture load/compile successfully
This commit is contained in:
parent
5069a42319
commit
c82d01631c
Binary file not shown.
|
@ -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<SHADE::SHAudioSystem, SHADE::SHAudioSystem::AudioRoutine>();
|
||||
|
|
|
@ -7,6 +7,8 @@ namespace SHADE
|
|||
{
|
||||
struct SHTextureAsset
|
||||
{
|
||||
bool compiled;
|
||||
|
||||
uint32_t numBytes;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
|
|
|
@ -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<char const*>(&asset.format),
|
||||
sizeof(SHTexture::PixelChannel)
|
||||
sizeof(SHTexture::TextureFormat)
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(&mipOffsetCount),
|
||||
intBytes
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(&asset.numBytes),
|
||||
intBytes
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(asset.mipOffsets.data()),
|
||||
|
|
|
@ -93,6 +93,7 @@ namespace SHADE
|
|||
std::memcpy(pixel, file.GetImageData()->m_mem, totalBytes);
|
||||
//pixel = std::move(reinterpret_cast<SHTexture::PixelChannel const*>(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<tinyddsloader::DDSFile::DXGIFormat>(formatCarrier), true);
|
||||
|
||||
file >> mipCount;
|
||||
file >> byteCount;
|
||||
file.read(reinterpret_cast<char*>(&asset.numBytes), intBytes);
|
||||
file.read(reinterpret_cast<char*>(&asset.width), intBytes);
|
||||
file.read(reinterpret_cast<char*>(&asset.height), intBytes);
|
||||
file.read(reinterpret_cast<char*>(&asset.format), sizeof(SHTexture::TextureFormat));
|
||||
|
||||
file.read(reinterpret_cast<char*>(&mipCount), intBytes);
|
||||
std::vector<uint32_t> mips(mipCount);
|
||||
for (auto i {0}; i < mipCount; ++i)
|
||||
{
|
||||
file >> mips[i];
|
||||
}
|
||||
file.read(reinterpret_cast<char*>(mips.data()), intBytes * mipCount);
|
||||
|
||||
auto pixel = new SHTexture::PixelChannel[asset.numBytes];
|
||||
file.read(reinterpret_cast<char*>(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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
Loading…
Reference in New Issue