This commit is contained in:
Isuru Samarathunga
2025-11-14 09:43:09 +05:30
parent 9ff39d7245
commit a2b80ef600
32 changed files with 928 additions and 295 deletions

View File

@ -18,19 +18,18 @@
namespace ia::iae
{
RDC_TextureAtlas::RDC_TextureAtlas(IN CONST Vector<Handle> &images)
RDC_TextureAtlas::RDC_TextureAtlas(IN CONST Vector<Image*> &images)
{
if (images.empty())
return;
m_atlasSize.x = 0;
m_atlasSize.y = 0;
for (const auto &_image : images)
for (const auto &image : images)
{
const auto d = (ImageData *) _image;
m_atlasSize.x += d->Width;
if (d->Height > m_atlasSize.y)
m_atlasSize.y = d->Height;
m_atlasSize.x += image->Width;
if (image->Height > m_atlasSize.y)
m_atlasSize.y = image->Height;
}
m_inverseAtlasSize = {1.0f / ((FLOAT32) m_atlasSize.x), 1.0f / ((FLOAT32) m_atlasSize.y)};
@ -38,13 +37,12 @@ namespace ia::iae
const auto pixels = new UINT8[m_atlasSize.x * m_atlasSize.y * 4];
INT32 atlasCursor{0};
for (const auto &_image : images)
for (const auto &image : images)
{
const auto d = (ImageData *) _image;
for (INT32 y = 0; y < d->Height; y++)
ia_memcpy(&pixels[(atlasCursor + (y * m_atlasSize.x)) * 4], &d->Pixels[y * d->Width * 4], d->Width * 4);
m_texCoordMap[_image] = Vec2(((FLOAT32) atlasCursor) / ((FLOAT32) m_atlasSize.x), 0.0f);
atlasCursor += d->Width;
for (INT32 y = 0; y < image->Height; y++)
ia_memcpy(&pixels[(atlasCursor + (y * m_atlasSize.x)) * 4], &image->Pixels[y * image->Width * 4], image->Width * 4);
m_texCoordMap[(Handle)(image)] = Vec2(((FLOAT32) atlasCursor) / ((FLOAT32) m_atlasSize.x), 0.0f);
atlasCursor += image->Width;
}
m_texture = new RDC_Texture(RDC_Texture::EType::SAMPLED, m_atlasSize.x, m_atlasSize.y);
@ -58,15 +56,14 @@ namespace ia::iae
delete m_texture;
}
Vec4 RDC_TextureAtlas::GetTextureCoordinates(IN Handle _image, IN INT32 tileIndexX, IN INT32 tileIndexY, IN BOOL flipH,
Vec4 RDC_TextureAtlas::GetTextureCoordinates(IN ImageView* imageView, IN INT32 tileIndexX, IN INT32 tileIndexY, IN BOOL flipH,
IN BOOL flipV, IN Vec2 uvOffset)
{
const auto d = (ImageData *) _image;
const auto &t = m_texCoordMap[_image];
const auto pX = ((tileIndexX + uvOffset.x) * ((FLOAT32) d->TileWidth)) * m_inverseAtlasSize.x;
const auto pY = ((tileIndexY + uvOffset.y) * ((FLOAT32) d->TileHeight)) * m_inverseAtlasSize.y;
auto texCoords = Vec4(t.x + pX, t.y + pY, d->TileWidth * m_inverseAtlasSize.x,
d->TileHeight * m_inverseAtlasSize.y);
const auto &t = m_texCoordMap[(Handle)(imageView->ImagePtr)];
const auto pX = ((tileIndexX + uvOffset.x) * ((FLOAT32) imageView->TileWidth)) * m_inverseAtlasSize.x;
const auto pY = ((tileIndexY + uvOffset.y) * ((FLOAT32) imageView->TileHeight)) * m_inverseAtlasSize.y;
auto texCoords = Vec4(t.x + pX, t.y + pY, imageView->TileWidth * m_inverseAtlasSize.x,
imageView->TileHeight * m_inverseAtlasSize.y);
if (flipH)
{
texCoords.x += texCoords.z;