TileMap Component
This commit is contained in:
@ -18,8 +18,8 @@
|
||||
#include <ResourceManager.hpp>
|
||||
|
||||
#include <AudioManager.hpp>
|
||||
#include <Renderer/Renderer.hpp>
|
||||
#include <Renderer/GPUResourceManager.hpp>
|
||||
#include <Renderer/Renderer.hpp>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_RESIZE_IMPLEMENTATION
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
Vector<SDL_GPUTexture*> ResourceManager::s_imageHandles;
|
||||
Vector<SDL_GPUTexture *> ResourceManager::s_imageHandles;
|
||||
Map<String, Handle> ResourceManager::s_images;
|
||||
Map<String, Handle> ResourceManager::s_sounds;
|
||||
Map<Handle, UINT64> ResourceManager::s_imageExtents;
|
||||
@ -37,8 +37,8 @@ namespace ia::iae
|
||||
VOID ResourceManager::Initialize()
|
||||
{
|
||||
{ // Set Texture Handle 0 to a pure white image
|
||||
const auto data = new UINT8[100*100*4];
|
||||
ia_memset(data, 0xFF, 100* 100* 4);
|
||||
const auto data = new UINT8[100 * 100 * 4];
|
||||
ia_memset(data, 0xFF, 100 * 100 * 4);
|
||||
CreateImage(Engine::GetUniqueResourceName(), data, 100, 100);
|
||||
delete[] data;
|
||||
}
|
||||
@ -63,8 +63,8 @@ namespace ia::iae
|
||||
|
||||
Handle ResourceManager::CreateImage(IN CONST String &name, IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height)
|
||||
{
|
||||
const auto texture = GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER, width, height,
|
||||
rgbaData, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
|
||||
const auto texture = GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER, width, height, rgbaData,
|
||||
SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
|
||||
s_imageHandles.pushBack(texture);
|
||||
Handle handle = s_imageHandles.size() - 1;
|
||||
s_images[name] = handle;
|
||||
@ -138,7 +138,7 @@ namespace ia::iae
|
||||
stbir_resize_uint8_linear(pixelData.data(), currentExtent.x, currentExtent.y, currentExtent.x * 4, nullptr,
|
||||
newWidth, newHeight, newWidth * 4, stbir_pixel_layout::STBIR_RGBA);
|
||||
const auto texture = GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER, newWidth, newHeight,
|
||||
newPixelData, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
|
||||
newPixelData, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
|
||||
s_imageExtents[image] = (((UINT64) newWidth) << 32) | newHeight;
|
||||
GPUResourceManager::DestroyTexture(s_imageHandles[image]);
|
||||
s_imageHandles[image] = texture;
|
||||
@ -149,16 +149,24 @@ namespace ia::iae
|
||||
Handle ResourceManager::CombineImages(IN CONST Vector<Handle> &images, IN INT32 unitWidth, IN INT32 unitHeight,
|
||||
IN INT32 unitCountX, IN INT32 unitCountY)
|
||||
{
|
||||
Vector<SDL_GPUTexture*> textures;
|
||||
for(const auto& t: images)
|
||||
const auto w = unitWidth * unitCountX;
|
||||
const auto h = unitHeight * unitCountY;
|
||||
Vector<SDL_GPUTexture *> textures;
|
||||
for (const auto &t : images)
|
||||
textures.pushBack(s_imageHandles[t]);
|
||||
return (Handle) GPUResourceManager::CombineTextures(textures.data(), unitWidth, unitHeight,
|
||||
unitCountX, unitCountY);
|
||||
const auto texture =
|
||||
GPUResourceManager::CombineTextures(textures.data(), unitWidth, unitHeight, unitCountX, unitCountY);
|
||||
s_imageHandles.pushBack(texture);
|
||||
Handle handle = s_imageHandles.size() - 1;
|
||||
s_images[Engine::GetUniqueResourceName()] = handle;
|
||||
s_imageExtents[handle] = (((UINT64) w) << 32) | h;
|
||||
s_nonScaledImageExtents[handle] = s_imageExtents[handle];
|
||||
return handle;
|
||||
}
|
||||
|
||||
VOID ResourceManager::RescaleAllImages(IN FLOAT32 factorX, IN FLOAT32 factorY)
|
||||
{
|
||||
for(auto& t: s_images)
|
||||
for (auto &t : s_images)
|
||||
{
|
||||
const auto p = s_nonScaledImageExtents[t->Value];
|
||||
t->Value = ResizeImage(t->Value, ((INT32) (p >> 32)) * factorX, ((INT32) p) * factorY);
|
||||
|
||||
Reference in New Issue
Block a user