Optimized Renderer

This commit is contained in:
Isuru Samarathunga
2025-10-21 10:44:11 +05:30
parent b10aacaee7
commit 86ed9346aa
21 changed files with 516 additions and 241 deletions

View File

@ -39,7 +39,7 @@ namespace ia::iae
CONST Mat4 *CameraComponent::GetViewMatrix()
{
const auto pos = (m_node->GetPosition() + m_positionOffset) * Engine::GetRendererScalingFactor();
const auto pos = (m_node->GetPosition() + m_positionOffset) * Engine::GetSceneScalingFactor();
m_viewMatrix = glm::lookAtLH(glm::vec3{pos, -2.0f}, {pos, 0.0f}, {0.0f, 1.0f, 0.0f});
return &m_viewMatrix;
}

View File

@ -35,15 +35,15 @@ namespace ia::iae
m_textureExtent = {t.x, t.y};
m_drawnSize = m_node->GetScale() * m_textureExtent * m_scaleOffset;
Engine::SetRenderState_Texture(m_texture);
Engine::SetRenderState_FlippedH(m_isFlippedH);
Engine::SetRenderState_FlippedV(m_isFlippedV);
Engine::SetRenderState_ColorOverlay(m_colorOverlay);
Engine::SetRenderState_TextureOffset(m_textureOffset);
Engine::SetRenderState_CameraRelative(m_isCameraRelative);
Engine::SetRenderState_Transform(m_node->GetPosition() + m_positionOffset, m_node->GetScale() * Vec2{t2.x, t2.y} * m_scaleOffset, m_node->GetRotation() + m_rotationOffset);
Engine::DrawGeometry(Engine::GetGeometry_Quad(), m_node->Layer(), m_node->SortIndex());
Engine::DrawGeometry(Engine::GetGeometry_Quad(), m_texture, m_node->GetPosition() + m_positionOffset,
m_node->GetScale() * Vec2{t2.x, t2.y} * m_scaleOffset,
m_node->GetRotation() + m_rotationOffset, m_node->Layer(), m_node->SortIndex());
}
VOID TextureComponent::DebugDraw()

View File

@ -0,0 +1,65 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@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/UIButtonComponent.hpp>
#include <IAEngine/Engine.hpp>
#include <IAEngine/Nodes/UINode.hpp>
namespace ia::iae
{
UIButtonComponent::UIButtonComponent(IN UINode *node) : UIImageComponent(node)
{
}
VOID UIButtonComponent::Draw()
{
UIImageComponent::Draw();
if (m_label.length())
{
Engine::SetRenderState_FlippedH(false);
Engine::SetRenderState_FlippedV(false);
Engine::SetRenderState_ColorOverlay(m_labelColor);
Engine::SetRenderState_TextureOffset({});
Engine::SetRenderState_CameraRelative(false);
Engine::DrawText(m_label, m_node->GetPosition() + m_labelPosition, m_node->GetScale() * m_labelSize,
m_node->GetRotation(), 0xFF, 0);
}
}
VOID UIButtonComponent::DebugDraw()
{
}
VOID UIButtonComponent::Update()
{
if (Engine::Input_IsPointerDown(m_node->GetPosition(), m_node->GetPosition() + DrawnSize()))
{
if (m_onDownCallback)
m_onDownCallback();
}
if (Engine::Input_DidPointerClick(m_node->GetPosition(), m_node->GetPosition() + DrawnSize()))
{
if (m_onClickCallback)
m_onClickCallback();
}
}
VOID UIButtonComponent::FixedUpdate()
{
}
} // namespace ia::iae

View File

@ -0,0 +1,52 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@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/Engine.hpp>
#include <IAEngine/Nodes/UINode.hpp>
#include <IAEngine/Components/UIImageComponent.hpp>
namespace ia::iae
{
UIImageComponent::UIImageComponent(IN UINode *node) : IUIComponent(node)
{
}
VOID UIImageComponent::Draw()
{
const auto t = Engine::GetImageOriginalExtent(m_image);
m_drawnSize = {m_node->GetScale() * t.x, m_node->GetScale() * t.y};
Engine::SetRenderState_FlippedH(false);
Engine::SetRenderState_FlippedV(false);
Engine::SetRenderState_ColorOverlay({0xFF, 0xFF, 0xFF, 0xFF});
Engine::SetRenderState_TextureOffset({});
Engine::SetRenderState_CameraRelative(false);
Engine::DrawGeometry(Engine::GetGeometry_Quad(), m_image, m_node->GetPosition(), m_drawnSize, m_node->GetRotation(), 0xFF, 0);
}
VOID UIImageComponent::DebugDraw()
{
}
VOID UIImageComponent::Update()
{
}
VOID UIImageComponent::FixedUpdate()
{
}
} // namespace ia::iae

View File

@ -26,10 +26,9 @@ namespace ia::iae
VOID UILabelComponent::Draw()
{
Engine::SetRenderState_Texture(0);
Engine::SetRenderState_FlippedH(false);
Engine::SetRenderState_FlippedV(false);
Engine::SetRenderState_ColorOverlay({0xFF, 0xFF, 0xFF, 0xFF});
Engine::SetRenderState_ColorOverlay(m_color);
Engine::SetRenderState_TextureOffset({});
Engine::SetRenderState_CameraRelative(false);
Engine::DrawText(m_label, m_node->GetPosition(), m_node->GetScale(), m_node->GetRotation(), 0xFF, 0);