Usable Engine

This commit is contained in:
Isuru Samarathunga
2025-10-07 17:11:20 +05:30
parent 0ef29f4e5f
commit 57c4309cf2
68 changed files with 1007 additions and 127 deletions

View File

@ -27,6 +27,8 @@
namespace ia::iae
{
Vector<Handle> ResourceManager::s_images;
Vector<Handle> ResourceManager::s_sounds;
Map<Handle, UINT64> ResourceManager::s_imageExtents;
VOID ResourceManager::Initialize()
@ -35,6 +37,10 @@ namespace ia::iae
VOID ResourceManager::Terminate()
{
for (const auto &t : s_images)
GPUResourceManager::DestroyTexture((SDL_GPUTexture *) t);
for (const auto &t : s_sounds)
AudioManager::DestoryAudio(t);
}
Handle ResourceManager::CreateImage(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize)
@ -51,12 +57,15 @@ namespace ia::iae
const auto handle = (Handle) GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER, width, height,
rgbaData, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
s_imageExtents[handle] = (((UINT64) width) << 32) | height;
s_images.pushBack(handle);
return handle;
}
Handle ResourceManager::CreateSound(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize)
{
return AudioManager::CreateAudio(encodedData, encodedDataSize);
const auto handle = AudioManager::CreateAudio(encodedData, encodedDataSize);
s_sounds.pushBack(handle);
return handle;
}
VOID ResourceManager::DestroyImage(IN Handle image)
@ -80,7 +89,6 @@ namespace ia::iae
const auto currentExtent = GetImageExtent(image);
const auto pixelData =
GPUResourceManager::GetTexturePixelData((SDL_GPUTexture *) image, currentExtent.x, currentExtent.y);
GPUResourceManager::DestroyTexture((SDL_GPUTexture *) image);
const auto newPixelData =
stbir_resize_uint8_linear(pixelData.data(), currentExtent.x, currentExtent.y, currentExtent.x * 4, nullptr,
newWidth, newHeight, newWidth * 4, stbir_pixel_layout::STBIR_RGBA);
@ -92,7 +100,8 @@ namespace ia::iae
Handle ResourceManager::CombineImages(IN CONST Vector<Handle> &images, IN INT32 unitWidth, IN INT32 unitHeight,
IN INT32 unitCountX, IN INT32 unitCountY)
{
return (Handle)GPUResourceManager::CombineTextures((SDL_GPUTexture**)images.data(), unitWidth, unitHeight, unitCountX, unitCountY);
return (Handle) GPUResourceManager::CombineTextures((SDL_GPUTexture **) images.data(), unitWidth, unitHeight,
unitCountX, unitCountY);
}
} // namespace ia::iae