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/racoon.gltf");
|
||||||
SHADE::SHAssetManager::LoadDataTemp("../../Assets/Cube.012.shmesh");
|
SHADE::SHAssetManager::LoadDataTemp("../../Assets/Cube.012.shmesh");
|
||||||
//SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonBag_Color_Ver4.dds");
|
//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
|
//TODO: REMOVE AFTER PRESENTATION
|
||||||
|
|
||||||
//SHADE::SHSystemManager::RegisterRoutine<SHADE::SHAudioSystem, SHADE::SHAudioSystem::AudioRoutine>();
|
//SHADE::SHSystemManager::RegisterRoutine<SHADE::SHAudioSystem, SHADE::SHAudioSystem::AudioRoutine>();
|
||||||
|
|
|
@ -7,6 +7,8 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
struct SHTextureAsset
|
struct SHTextureAsset
|
||||||
{
|
{
|
||||||
|
bool compiled;
|
||||||
|
|
||||||
uint32_t numBytes;
|
uint32_t numBytes;
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
|
|
|
@ -19,7 +19,11 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
void SHTextureCompiler::CompileTextureBinary(SHTextureAsset const& asset, AssetPath path)
|
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())
|
if (!file.is_open())
|
||||||
{
|
{
|
||||||
SHLOG_ERROR("Unable to open file for writing texture file: {}", path.string());
|
SHLOG_ERROR("Unable to open file for writing texture file: {}", path.string());
|
||||||
|
@ -46,18 +50,13 @@ namespace SHADE
|
||||||
|
|
||||||
file.write(
|
file.write(
|
||||||
reinterpret_cast<char const*>(&asset.format),
|
reinterpret_cast<char const*>(&asset.format),
|
||||||
sizeof(SHTexture::PixelChannel)
|
sizeof(SHTexture::TextureFormat)
|
||||||
);
|
);
|
||||||
|
|
||||||
file.write(
|
file.write(
|
||||||
reinterpret_cast<char const*>(&mipOffsetCount),
|
reinterpret_cast<char const*>(&mipOffsetCount),
|
||||||
intBytes
|
intBytes
|
||||||
);
|
);
|
||||||
|
|
||||||
file.write(
|
|
||||||
reinterpret_cast<char const*>(&asset.numBytes),
|
|
||||||
intBytes
|
|
||||||
);
|
|
||||||
|
|
||||||
file.write(
|
file.write(
|
||||||
reinterpret_cast<char const*>(asset.mipOffsets.data()),
|
reinterpret_cast<char const*>(asset.mipOffsets.data()),
|
||||||
|
|
|
@ -93,6 +93,7 @@ namespace SHADE
|
||||||
std::memcpy(pixel, file.GetImageData()->m_mem, totalBytes);
|
std::memcpy(pixel, file.GetImageData()->m_mem, totalBytes);
|
||||||
//pixel = std::move(reinterpret_cast<SHTexture::PixelChannel const*>(file.GetDDSData()));
|
//pixel = std::move(reinterpret_cast<SHTexture::PixelChannel const*>(file.GetDDSData()));
|
||||||
|
|
||||||
|
asset.compiled = false;
|
||||||
asset.numBytes = totalBytes;
|
asset.numBytes = totalBytes;
|
||||||
asset.width = file.GetWidth();
|
asset.width = file.GetWidth();
|
||||||
asset.height = file.GetHeight();
|
asset.height = file.GetHeight();
|
||||||
|
@ -109,38 +110,25 @@ namespace SHADE
|
||||||
SHLOG_ERROR("Error opening SHTexture file: {}", path.string());
|
SHLOG_ERROR("Error opening SHTexture file: {}", path.string());
|
||||||
}
|
}
|
||||||
|
|
||||||
tinyddsloader::DDSFile::DXGIFormat format;
|
auto const intBytes{ sizeof(uint32_t) };
|
||||||
uint32_t formatCarrier;
|
|
||||||
uint32_t mipCount;
|
uint32_t mipCount;
|
||||||
uint32_t byteCount;
|
|
||||||
|
|
||||||
file >> asset.numBytes;
|
file.read(reinterpret_cast<char*>(&asset.numBytes), intBytes);
|
||||||
file >> asset.width;
|
file.read(reinterpret_cast<char*>(&asset.width), intBytes);
|
||||||
file >> asset.height;
|
file.read(reinterpret_cast<char*>(&asset.height), intBytes);
|
||||||
|
file.read(reinterpret_cast<char*>(&asset.format), sizeof(SHTexture::TextureFormat));
|
||||||
file >> formatCarrier;
|
|
||||||
asset.format = ddsLoaderToVkFormat(static_cast<tinyddsloader::DDSFile::DXGIFormat>(formatCarrier), true);
|
|
||||||
|
|
||||||
file >> mipCount;
|
|
||||||
file >> byteCount;
|
|
||||||
|
|
||||||
|
file.read(reinterpret_cast<char*>(&mipCount), intBytes);
|
||||||
std::vector<uint32_t> mips(mipCount);
|
std::vector<uint32_t> mips(mipCount);
|
||||||
for (auto i {0}; i < mipCount; ++i)
|
file.read(reinterpret_cast<char*>(mips.data()), intBytes * mipCount);
|
||||||
{
|
|
||||||
file >> mips[i];
|
auto pixel = new SHTexture::PixelChannel[asset.numBytes];
|
||||||
}
|
file.read(reinterpret_cast<char*>(pixel), asset.numBytes);
|
||||||
|
|
||||||
asset.mipOffsets = std::move(mips);
|
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.pixelData = std::move( pixel );
|
||||||
|
|
||||||
|
asset.compiled = true;
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "Libraries/SHTextureLoader.h"
|
#include "Libraries/SHTextureLoader.h"
|
||||||
|
|
||||||
#include "Libraries/SHMeshCompiler.h"
|
#include "Libraries/SHMeshCompiler.h"
|
||||||
|
#include "Libraries/SHTextureCompiler.h"
|
||||||
|
|
||||||
namespace SHADE
|
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(
|
LoadDDS(
|
||||||
{
|
{
|
||||||
|
@ -319,6 +321,11 @@ namespace SHADE
|
||||||
SHTextureLoader::LoadImageAsset(asset.path, image);
|
SHTextureLoader::LoadImageAsset(asset.path, image);
|
||||||
|
|
||||||
textureCollection.emplace(GenerateAssetID(AssetType::DDS), image);
|
textureCollection.emplace(GenerateAssetID(AssetType::DDS), image);
|
||||||
|
|
||||||
|
if (!image.compiled)
|
||||||
|
{
|
||||||
|
SHTextureCompiler::CompileTextureBinary(image, asset.path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
Loading…
Reference in New Issue