From 201b19e8a6ad413fa3b7429119afda8451790e6e Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Wed, 28 Sep 2022 18:35:22 +0800 Subject: [PATCH] SP3-237 Renamed MeshWriter to MeshCompiler Implemented texture compiler --- .../{SHMeshWriter.cpp => SHMeshCompiler.cpp} | 4 +- .../{SHMeshWriter.h => SHMeshCompiler.h} | 4 +- .../Assets/Libraries/SHTextureCompiler.cpp | 50 +++++++++++++++++++ .../src/Assets/Libraries/SHTextureCompiler.h | 12 +++++ 4 files changed, 66 insertions(+), 4 deletions(-) rename SHADE_Engine/src/Assets/Libraries/{SHMeshWriter.cpp => SHMeshCompiler.cpp} (88%) rename SHADE_Engine/src/Assets/Libraries/{SHMeshWriter.h => SHMeshCompiler.h} (54%) create mode 100644 SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.cpp create mode 100644 SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.h diff --git a/SHADE_Engine/src/Assets/Libraries/SHMeshWriter.cpp b/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.cpp similarity index 88% rename from SHADE_Engine/src/Assets/Libraries/SHMeshWriter.cpp rename to SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.cpp index 965e7d68..1a9dede2 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHMeshWriter.cpp +++ b/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.cpp @@ -1,9 +1,9 @@ #include "SHpch.h" -#include "SHMeshWriter.h" +#include "SHMeshCompiler.h" #include -void SHADE::SHMeshWriter::WriteMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept +void SHADE::SHMeshCompiler::CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept { std::ofstream file{path, std::ios::out | std::ios::binary}; if (!file.is_open()) diff --git a/SHADE_Engine/src/Assets/Libraries/SHMeshWriter.h b/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.h similarity index 54% rename from SHADE_Engine/src/Assets/Libraries/SHMeshWriter.h rename to SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.h index 4a1a3e6b..090e241e 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHMeshWriter.h +++ b/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.h @@ -5,10 +5,10 @@ namespace SHADE { - class SHMeshWriter + class SHMeshCompiler { private: public: - static void WriteMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept; + static void CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.cpp b/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.cpp new file mode 100644 index 00000000..342a0aee --- /dev/null +++ b/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.cpp @@ -0,0 +1,50 @@ +#include "SHpch.h" +#include "SHTextureCompiler.h" + +#include + +namespace SHADE +{ + void SHTextureCompiler::CompileTextureBinary(SHTextureAsset const& asset, AssetPath path) + { + std::ofstream file{path, std::ios::out | std::ios::binary}; + if (!file.is_open()) + { + SHLOG_ERROR("Unable to open file for writing texture file: {}", path.string()); + } + + auto const intBytes{sizeof(uint32_t)}; + + file.write( + reinterpret_cast(&asset.numBytes), + intBytes + ); + + file.write( + reinterpret_cast(&asset.width), + intBytes + ); + + file.write( + reinterpret_cast(&asset.height), + intBytes + ); + + file.write( + reinterpret_cast(&asset.format), + sizeof(SHTexture::PixelChannel) + ); + + file.write( + reinterpret_cast(asset.mipOffsets.data()), + intBytes * asset.mipOffsets.size() + ); + + file.write( + reinterpret_cast(asset.pixelData), + asset.numBytes + ); + + file.close(); + } +} diff --git a/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.h b/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.h new file mode 100644 index 00000000..494907f7 --- /dev/null +++ b/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.h @@ -0,0 +1,12 @@ +#pragma once + +#include "Assets/Asset Types/SHTextureAsset.h" +#include "Assets/SHAssetMacros.h" + +namespace SHADE +{ + struct SHTextureCompiler + { + static void CompileTextureBinary(SHTextureAsset const& asset, AssetPath path); + }; +} \ No newline at end of file