Optimized Renderer
This commit is contained in:
@ -61,8 +61,9 @@ 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 | SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, width, height, rgbaData,
|
||||
SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM, true);
|
||||
const auto texture =
|
||||
GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER | SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, width,
|
||||
height, rgbaData, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM, true);
|
||||
s_imageHandles.pushBack(ImageResource{.OriginalWidth = width,
|
||||
.OriginalHeight = height,
|
||||
.OriginalPixelData = new UINT8[width * height * 4],
|
||||
@ -137,7 +138,7 @@ namespace ia::iae
|
||||
return {t.OriginalWidth, t.OriginalHeight};
|
||||
}
|
||||
|
||||
Handle ResourceManager::RescaleImage(IN Handle image, IN Vec2 factor)
|
||||
Handle ResourceManager::RescaleImage(IN Handle image, IN Vec2 factor, IN BOOL makeOriginal)
|
||||
{
|
||||
if (!s_imageHandles[image].OriginalPixelData)
|
||||
return image;
|
||||
@ -145,21 +146,29 @@ namespace ia::iae
|
||||
const auto newWidth = (INT32) (s_imageHandles[image].OriginalWidth * factor.x);
|
||||
const auto newHeight = (INT32) (s_imageHandles[image].OriginalHeight * factor.y);
|
||||
|
||||
if (!newWidth || !newHeight ||
|
||||
((newWidth <= s_imageHandles[image].OriginalWidth) && (newHeight <= s_imageHandles[image].OriginalHeight)))
|
||||
if (!newWidth || !newHeight)
|
||||
return image;
|
||||
|
||||
const auto newPixelData =
|
||||
stbir_resize_uint8_linear(s_imageHandles[image].OriginalPixelData, s_imageHandles[image].OriginalWidth,
|
||||
s_imageHandles[image].OriginalHeight, s_imageHandles[image].OriginalWidth * 4,
|
||||
nullptr, newWidth, newHeight, newWidth * 4, stbir_pixel_layout::STBIR_RGBA);
|
||||
const auto texture = GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER | SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, newWidth, newHeight,
|
||||
newPixelData, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM, true);
|
||||
const auto texture = GPUResourceManager::CreateTexture(
|
||||
SDL_GPU_TEXTUREUSAGE_SAMPLER | SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, newWidth, newHeight, newPixelData,
|
||||
SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM, true);
|
||||
GPUResourceManager::DestroyTexture(s_imageHandles[image].Handle);
|
||||
s_imageHandles[image].Handle = texture;
|
||||
s_imageHandles[image].Width = newWidth;
|
||||
s_imageHandles[image].Height = newHeight;
|
||||
free(newPixelData);
|
||||
if (!makeOriginal)
|
||||
{
|
||||
free(newPixelData);
|
||||
return image;
|
||||
}
|
||||
free(s_imageHandles[image].OriginalPixelData);
|
||||
s_imageHandles[image].OriginalPixelData = newPixelData;
|
||||
s_imageHandles[image].OriginalWidth = newWidth;
|
||||
s_imageHandles[image].OriginalHeight = newHeight;
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user