75 lines
2.7 KiB
C++
75 lines
2.7 KiB
C++
// IAEngine: 2D Game Engine by IA
|
|
// Copyright (C) 2025 IAS (ias@iasoft.dev)
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#include <IAEngine/Components/AtlasRenderer.hpp>
|
|
|
|
#include <IAEngine/Nodes/Node.hpp>
|
|
|
|
namespace ia::iae
|
|
{
|
|
AtlasRendererComponent::AtlasRendererComponent(IN Node *node) : TextureRendererComponent(node)
|
|
{
|
|
}
|
|
|
|
AtlasRendererComponent::~AtlasRendererComponent()
|
|
{
|
|
m_bakedGPUTexture.reset();
|
|
}
|
|
|
|
VOID AtlasRendererComponent::SetGrid(IN INT32 tileWidth, IN INT32 tileHeight, IN INT32 tileCountX,
|
|
IN INT32 tileCountY)
|
|
{
|
|
m_tileGrid = {};
|
|
m_tileGrid.TileWidth = tileWidth;
|
|
m_tileGrid.TileHeight = tileHeight;
|
|
m_tileGrid.TileCountX = tileCountX;
|
|
m_tileGrid.TileCountY = tileCountY;
|
|
m_tileGrid.m_tileTextures.resize(m_tileGrid.TileCountX * m_tileGrid.TileCountY);
|
|
}
|
|
|
|
VOID AtlasRendererComponent::SetGridTileTexture(IN INT32 index, IN class Texture texture)
|
|
{
|
|
m_tileGrid.m_tileTextures[index] = texture;
|
|
}
|
|
|
|
VOID AtlasRendererComponent::SetGridTileTexture(IN INT32 x, IN INT32 y, IN class Texture texture)
|
|
{
|
|
m_tileGrid.m_tileTextures[x + (y * m_tileGrid.TileCountX)] = texture;
|
|
}
|
|
|
|
VOID AtlasRendererComponent::BakeGrid()
|
|
{
|
|
CONST INT32 w = m_tileGrid.TileWidth * m_tileGrid.TileCountX, h = m_tileGrid.TileHeight * m_tileGrid.TileCountY;
|
|
Vector<Handle> handles;
|
|
handles.resize(m_tileGrid.TileCountX * m_tileGrid.TileCountY);
|
|
for (SIZE_T i = 0; i < handles.size(); i++)
|
|
handles[i] = m_tileGrid.m_tileTextures[i].GetHandle();
|
|
m_bakedGPUTexture = GPUTexture::GridCombine(handles.data(), m_tileGrid.TileCountX, m_tileGrid.TileCountY,
|
|
m_tileGrid.TileWidth, m_tileGrid.TileHeight);
|
|
CurrentTexture() = Texture(m_bakedGPUTexture->GetHandle(), w, h);
|
|
PositionOffset() = m_tileGrid.Position;
|
|
}
|
|
|
|
VOID AtlasRendererComponent::Update()
|
|
{
|
|
}
|
|
|
|
VOID AtlasRendererComponent::Draw()
|
|
{
|
|
TextureRendererComponent::Draw();
|
|
}
|
|
} // namespace ia::iae
|