Modified TextureLibrary to use SHTextureAsset instead of SHDDSAsset

This commit is contained in:
Kah Wei 2022-09-27 16:05:47 +08:00
parent 10b22374c0
commit 04b452543c
6 changed files with 17 additions and 33 deletions

View File

@ -55,13 +55,13 @@ namespace Sandbox
graphicsSystem->BuildMeshBuffers();
// Load Textures
auto textures = SHADE::SHAssetManager::GetAllDDS();
/*auto textures = SHADE::SHAssetManager::GetAllTextures();
std::vector<Handle<SHTexture>> texHandles;
for (const auto& tex : textures)
{
auto texture = graphicsSystem->Add(tex);
texHandles.push_back(texture);
}
}*/
graphicsSystem->BuildTextures();
// Create Materials

View File

@ -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<SHTexture::PixelChannel const*>(file.GetDDSData()));
asset.numBytes = totalBytes;

View File

@ -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<SHTexture> SHGraphicsSystem::Add(const SHDDSAsset& ddsAsset)
Handle<SHTexture> SHGraphicsSystem::Add(const SHTextureAsset& texAsset)
{
auto sampler = samplerCache.GetSampler(device, SHVkSamplerParams { .maxLod = static_cast<float>(ddsAsset.image.GetMipCount()) });
return texLibrary.Add(ddsAsset, sampler);
auto sampler = samplerCache.GetSampler(device, SHVkSamplerParams { .maxLod = static_cast<float>(texAsset.mipOffsets.size()) });
return texLibrary.Add(texAsset, sampler);
}
SHADE::Handle<SHADE::SHTexture> SHGraphicsSystem::Add(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData, uint32_t width, uint32_t height, SHTexture::TextureFormat format, std::vector<uint32_t> mipOffsets)

View File

@ -215,7 +215,7 @@ namespace SHADE
*/
/*******************************************************************************/
Handle<SHTexture> Add(const SHDDSAsset& ddsAsset);
Handle<SHTexture> Add(const SHTextureAsset& texAsset);
Handle<SHTexture> Add(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData, uint32_t width, uint32_t height, SHTexture::TextureFormat format, std::vector<uint32_t> mipOffsets);
/*******************************************************************************/
/*!

View File

@ -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<SHTexture> SHTextureLibrary::Add(const SHDDSAsset& ddsAsset, Handle<SHVkSampler> sampler)
Handle<SHTexture> SHTextureLibrary::Add(const SHTextureAsset& texAsset, Handle<SHVkSampler> 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<uint32_t> 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<const SHTexture::PixelChannel*>(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
);
}

View File

@ -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<SHTexture> Add(const SHDDSAsset& ddsAsset, Handle<SHVkSampler> sampler);
Handle<SHTexture> Add(const SHTextureAsset& texAsset, Handle<SHVkSampler> sampler);
Handle<SHTexture> Add(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData, uint32_t width, uint32_t height, SHTexture::TextureFormat format, std::vector<uint32_t> mipOffsets, Handle<SHVkSampler> sampler);
/*******************************************************************************/
/*!