From 04b452543ccb6cca4989f793dce727da6387fae0 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 27 Sep 2022 16:05:47 +0800 Subject: [PATCH] Modified TextureLibrary to use SHTextureAsset instead of SHDDSAsset --- SHADE_Application/src/Scenes/SBTestScene.cpp | 4 +-- .../src/Assets/Libraries/SHTextureLoader.cpp | 2 +- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 8 ++--- .../MiddleEnd/Interface/SHGraphicsSystem.h | 2 +- .../MiddleEnd/Textures/SHTextureLibrary.cpp | 30 +++++-------------- .../MiddleEnd/Textures/SHTextureLibrary.h | 4 +-- 6 files changed, 17 insertions(+), 33 deletions(-) diff --git a/SHADE_Application/src/Scenes/SBTestScene.cpp b/SHADE_Application/src/Scenes/SBTestScene.cpp index bc99dada..39c8cf97 100644 --- a/SHADE_Application/src/Scenes/SBTestScene.cpp +++ b/SHADE_Application/src/Scenes/SBTestScene.cpp @@ -55,13 +55,13 @@ namespace Sandbox graphicsSystem->BuildMeshBuffers(); // Load Textures - auto textures = SHADE::SHAssetManager::GetAllDDS(); + /*auto textures = SHADE::SHAssetManager::GetAllTextures(); std::vector> texHandles; for (const auto& tex : textures) { auto texture = graphicsSystem->Add(tex); texHandles.push_back(texture); - } + }*/ graphicsSystem->BuildTextures(); // Create Materials diff --git a/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp b/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp index 33270bb6..94b65dc1 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp @@ -79,7 +79,7 @@ namespace SHADE } SHTexture::PixelChannel* pixel = new SHTexture::PixelChannel[totalBytes]; - std::memcpy(pixel, file.GetDDSData(), totalBytes); + //std::memcpy(pixel, file.GetDDSData(), totalBytes); //pixel = std::move(reinterpret_cast(file.GetDDSData())); asset.numBytes = totalBytes; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index fb3535c1..8129298b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -31,7 +31,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Images/SHVkSampler.h" -#include "Assets/Asset Types/SHDDSAsset.h" +#include "Assets/Asset Types/SHTextureAsset.h" namespace SHADE { @@ -482,10 +482,10 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Texture Registration Functions */ /*---------------------------------------------------------------------------------*/ - Handle SHGraphicsSystem::Add(const SHDDSAsset& ddsAsset) + Handle SHGraphicsSystem::Add(const SHTextureAsset& texAsset) { - auto sampler = samplerCache.GetSampler(device, SHVkSamplerParams { .maxLod = static_cast(ddsAsset.image.GetMipCount()) }); - return texLibrary.Add(ddsAsset, sampler); + auto sampler = samplerCache.GetSampler(device, SHVkSamplerParams { .maxLod = static_cast(texAsset.mipOffsets.size()) }); + return texLibrary.Add(texAsset, sampler); } SHADE::Handle SHGraphicsSystem::Add(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData, uint32_t width, uint32_t height, SHTexture::TextureFormat format, std::vector mipOffsets) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 5e8068be..84dc39cd 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -215,7 +215,7 @@ namespace SHADE */ /*******************************************************************************/ - Handle Add(const SHDDSAsset& ddsAsset); + Handle Add(const SHTextureAsset& texAsset); Handle Add(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData, uint32_t width, uint32_t height, SHTexture::TextureFormat format, std::vector mipOffsets); /*******************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp index b7b14697..c6793796 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp @@ -22,40 +22,24 @@ of DigiPen Institute of Technology is prohibited. #include "Tools/SHLogger.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" -#include "Assets/Asset Types/SHDDSAsset.h" #include "Graphics/Images/SHVkImage.h" #include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" +#include "Assets/Asset Types/SHTextureAsset.h" namespace SHADE { /*---------------------------------------------------------------------------------*/ /* Usage Functions */ /*---------------------------------------------------------------------------------*/ - Handle SHTextureLibrary::Add(const SHDDSAsset& ddsAsset, Handle sampler) + Handle SHTextureLibrary::Add(const SHTextureAsset& texAsset, Handle sampler) { - // Define constants - const uint32_t IMG_WIDTH = ddsAsset.image.GetWidth(); - const uint32_t IMG_HEIGHT = ddsAsset.image.GetHeight(); - const uint32_t MIPMAP_LEVEL = ddsAsset.image.GetMipCount(); - - // Compute total texture size and create buffer image copy objects - std::vector mipOffsets(MIPMAP_LEVEL); - uint32_t texBytes = 0; - for (uint32_t i = 0; i < MIPMAP_LEVEL; i++) - { - mipOffsets[i] = texBytes; - - // Get ready for next mip - texBytes += ddsAsset.image.GetImageData(i)->m_memSlicePitch; - } - return Add ( - texBytes, - reinterpret_cast(ddsAsset.image.m_dds.data()), - IMG_WIDTH, IMG_HEIGHT, - ddsLoaderToVkFormat(ddsAsset.image.GetFormat(), true), - mipOffsets, + texAsset.numBytes, + texAsset.pixelData, + texAsset.width, texAsset.height, + texAsset.format, + texAsset.mipOffsets, sampler ); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h index 89168596..660d93eb 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h @@ -37,7 +37,7 @@ namespace SHADE class SHVkDescriptorSetLayout; class SHVkDescriptorSetGroup; class SHVkSampler; - struct SHDDSAsset; + class SHTextureAsset; /*---------------------------------------------------------------------------------*/ /* Type Definitions */ @@ -94,7 +94,7 @@ namespace SHADE */ /*******************************************************************************/ - Handle Add(const SHDDSAsset& ddsAsset, Handle sampler); + Handle Add(const SHTextureAsset& texAsset, Handle sampler); Handle Add(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData, uint32_t width, uint32_t height, SHTexture::TextureFormat format, std::vector mipOffsets, Handle sampler); /*******************************************************************************/ /*!