Compare commits
2 Commits
70d9cb3a85
...
8a2baf6659
| Author | SHA1 | Date | |
|---|---|---|---|
| 8a2baf6659 | |||
| a0b5dc2af2 |
14
.vscode/settings.json
vendored
Normal file
14
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"functional": "cpp",
|
||||
"array": "cpp",
|
||||
"utility": "cpp",
|
||||
"xutility": "cpp",
|
||||
"compare": "cpp",
|
||||
"memory": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"xmemory": "cpp",
|
||||
"xtr1common": "cpp"
|
||||
}
|
||||
}
|
||||
2
Dependencies/IACore
vendored
2
Dependencies/IACore
vendored
Submodule Dependencies/IACore updated: 0fd33d958e...8e2e118dd5
@ -17,13 +17,7 @@ namespace ia::iae::game
|
||||
scene = m_engine->CreateScene();
|
||||
m_engine->ChangeScene(scene);
|
||||
|
||||
const auto player = MakeRefPtr<Player>(m_engine);
|
||||
player->SetLocalPosition({100.0f, 200.0f, 0.0f});
|
||||
scene->AddNode(player);
|
||||
|
||||
const auto ground = MakeRefPtr<Ground>(m_engine);
|
||||
ground->SetLocalPosition({50.0f, 500.0f, 0.0f});
|
||||
scene->AddNode(ground);
|
||||
iae::Renderer::AddDebugUIWindow("Debug Window", {100, 100}, {100, 200}, [](){});
|
||||
}
|
||||
|
||||
VOID Game::Terminate()
|
||||
|
||||
@ -3,13 +3,22 @@ set(IAEngine_Sources
|
||||
imp/cpp/IAEngine.cpp
|
||||
imp/cpp/Time.cpp
|
||||
imp/cpp/Audio.cpp
|
||||
imp/cpp/Texture.cpp
|
||||
imp/cpp/Input.cpp
|
||||
imp/cpp/Scene.cpp
|
||||
imp/cpp/Random.cpp
|
||||
|
||||
imp/cpp/ResourceManager.cpp
|
||||
|
||||
imp/cpp/Rendering/Camera.cpp
|
||||
imp/cpp/Rendering/Texture.cpp
|
||||
imp/cpp/Rendering/Renderer.cpp
|
||||
imp/cpp/Rendering/GPUBuffer.cpp
|
||||
|
||||
imp/cpp/Rendering/Mesh/Quad.cpp
|
||||
|
||||
imp/cpp/Rendering/Pipeline/Pipeline.cpp
|
||||
imp/cpp/Rendering/Pipeline/UnlitMesh.cpp
|
||||
|
||||
imp/cpp/Physics/Physics.cpp
|
||||
|
||||
imp/cpp/Events/Event.cpp
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/Audio.hpp>
|
||||
|
||||
#include <SDL3/SDL_iostream.h>
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
// 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>
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/ParticleEmitter.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/PhysicsBody.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/SoundEmitter.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/SpriteRenderer.hpp>
|
||||
|
||||
#include <IAEngine/Nodes/Node.hpp>
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/TextureRenderer.hpp>
|
||||
|
||||
#include <IAEngine/Nodes/Node.hpp>
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/Events/Event.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/Audio.hpp>
|
||||
#include <IAEngine/IAEngine.hpp>
|
||||
#include <IAEngine/Input.hpp>
|
||||
@ -7,18 +23,15 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <backends/imgui_impl_sdl3.h>
|
||||
#include <backends/imgui_impl_sdlrenderer3.h>
|
||||
#include <imgui.h>
|
||||
#include <backends/imgui_impl_sdl3.h>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
struct EngineContext
|
||||
{
|
||||
SDL_Renderer *Renderer{};
|
||||
SDL_Window *Window{};
|
||||
SDL_Event Event{};
|
||||
ImGuiIO ImGUIIO{};
|
||||
|
||||
BOOL ShouldClose{false};
|
||||
};
|
||||
@ -46,36 +59,20 @@ namespace ia::iae
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SDL_CreateWindowAndRenderer(config.GameName.c_str(), config.WindowWidth, config.WindowHeight,
|
||||
SDL_WINDOW_RESIZABLE, &m_context->Window, &m_context->Renderer))
|
||||
if (!(m_context->Window = SDL_CreateWindow(config.GameName.c_str(), config.WindowWidth, config.WindowHeight, SDL_WINDOW_RESIZABLE)))
|
||||
{
|
||||
IAE_LOG_ERROR("Couldn't create SDL3 window and renderer: ", SDL_GetError());
|
||||
IAE_LOG_ERROR("Couldn't create SDL3 window: ", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_SetWindowResizable(m_context->Window, false);
|
||||
SDL_SetRenderVSync(m_context->Renderer, 1);
|
||||
|
||||
const auto mainScale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay());
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
m_context->ImGUIIO = ImGui::GetIO();
|
||||
(void) m_context->ImGUIIO;
|
||||
m_context->ImGUIIO.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
m_context->ImGUIIO.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
||||
|
||||
ImGui::StyleColorsClassic();
|
||||
|
||||
ImGuiStyle &style = ImGui::GetStyle();
|
||||
style.ScaleAllSizes(mainScale);
|
||||
style.FontScaleDpi = mainScale;
|
||||
|
||||
ImGui_ImplSDL3_InitForSDLRenderer(m_context->Window, m_context->Renderer);
|
||||
ImGui_ImplSDLRenderer3_Init(m_context->Renderer);
|
||||
|
||||
Time::Initialize();
|
||||
|
||||
if (!Renderer::Initialize(this))
|
||||
return false;
|
||||
|
||||
Random::Initialize();
|
||||
|
||||
Input::Initialize();
|
||||
Audio::Initialize();
|
||||
Physics::Initialize();
|
||||
@ -89,12 +86,8 @@ namespace ia::iae
|
||||
|
||||
Physics::Terminate();
|
||||
Audio::Terminate();
|
||||
Renderer::Terminate();
|
||||
|
||||
ImGui_ImplSDLRenderer3_Shutdown();
|
||||
ImGui_ImplSDL3_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
SDL_DestroyRenderer(m_context->Renderer);
|
||||
SDL_DestroyWindow(m_context->Window);
|
||||
|
||||
SDL_Quit();
|
||||
@ -113,47 +106,21 @@ namespace ia::iae
|
||||
while (m_updateTimer >= GAME_UPDATE_INTERVAL)
|
||||
m_updateTimer -= GAME_UPDATE_INTERVAL;
|
||||
}
|
||||
ImGui_ImplSDLRenderer3_NewFrame();
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
RenderDebugUI();
|
||||
ImGui::Render();
|
||||
SDL_SetRenderScale(m_context->Renderer, m_context->ImGUIIO.DisplayFramebufferScale.x,
|
||||
m_context->ImGUIIO.DisplayFramebufferScale.y);
|
||||
SDL_SetRenderDrawColorFloat(m_context->Renderer, 0.33f, 0.33f, 0.33f, 1.0f);
|
||||
SDL_RenderClear(m_context->Renderer);
|
||||
Renderer::BeginFrame();
|
||||
RenderGame();
|
||||
}
|
||||
|
||||
VOID Engine::EndFrame()
|
||||
{
|
||||
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), m_context->Renderer);
|
||||
SDL_RenderPresent(m_context->Renderer);
|
||||
Renderer::EndFrame();
|
||||
Time::NextFrame();
|
||||
}
|
||||
|
||||
VOID Engine::AddDebugUIWindow(IN PCCHAR title, IN CONST iam::Vec2f &position, IN CONST iam::Vec2f &size,
|
||||
IN std::function<VOID()> contentDrawCallback)
|
||||
{
|
||||
m_debugUIWindows.pushBack(DebugUIWindow{title, position, size, contentDrawCallback});
|
||||
}
|
||||
|
||||
BOOL Engine::ShouldClose()
|
||||
{
|
||||
return m_context->ShouldClose;
|
||||
}
|
||||
|
||||
VOID Engine::RenderDebugUI()
|
||||
{
|
||||
for (const auto &w : m_debugUIWindows) {
|
||||
ImGui::Begin(w.Title);
|
||||
ImGui::SetWindowPos({w.Position.X, w.Position.Y});
|
||||
ImGui::SetWindowSize({w.Size.X, w.Size.Y});
|
||||
w.ContentDrawCallback();
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
VOID Engine::ProcessEvents()
|
||||
{
|
||||
ImGui_ImplSDL3_ProcessEvent(&m_context->Event);
|
||||
@ -184,8 +151,8 @@ namespace ia::iae
|
||||
return MakeRefPtr<Scene>(this);
|
||||
}
|
||||
|
||||
PVOID Engine::GetRendererHandle() CONST
|
||||
PVOID Engine::GetWindowHandle() CONST
|
||||
{
|
||||
return m_context->Renderer;
|
||||
return m_context->Window;
|
||||
}
|
||||
} // namespace ia::iae
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/Input.hpp>
|
||||
|
||||
#include <SDL3/SDL_events.h>
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/Nodes/Node.hpp>
|
||||
|
||||
#include <IAEngine/IAEngine.hpp>
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/Nodes/Transform.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/Physics/Physics.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/Random.hpp>
|
||||
|
||||
#include <IAEngine/Time.hpp>
|
||||
|
||||
15
Src/IAEngine/imp/cpp/Rendering/Camera.cpp
Normal file
15
Src/IAEngine/imp/cpp/Rendering/Camera.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
// 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/>.
|
||||
115
Src/IAEngine/imp/cpp/Rendering/GPUBuffer.cpp
Normal file
115
Src/IAEngine/imp/cpp/Rendering/GPUBuffer.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
// 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/Rendering/GPUBuffer.hpp>
|
||||
|
||||
#include <SDL3/SDL_gpu.h>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
EXTERN SDL_GPUDevice *g_gpuDevice;
|
||||
|
||||
UINT32 g_stagingBufferSize = 4096;
|
||||
SDL_GPUTransferBuffer* g_stagingBuffer{};
|
||||
|
||||
RefPtr<GPUBuffer> GPUBuffer::Create(IN PCVOID data, IN UINT32 dataSize)
|
||||
{
|
||||
const auto res = MakeRefPtr<GPUBuffer>();
|
||||
|
||||
SDL_GPUBufferCreateInfo createInfo{
|
||||
.usage = SDL_GPU_BUFFERUSAGE_VERTEX,
|
||||
.size = dataSize
|
||||
};
|
||||
SDL_GPUBuffer* handle{};
|
||||
if(!(handle = SDL_CreateGPUBuffer(g_gpuDevice, &createInfo)))
|
||||
{
|
||||
IAE_LOG_ERROR("Couldn't create a SDL3 GPU Buffer: ", SDL_GetError());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if(data && dataSize)
|
||||
{
|
||||
if(!EnsureStagingBufferSize((UINT32)dataSize))
|
||||
return nullptr;
|
||||
|
||||
const auto mappedPtr = SDL_MapGPUTransferBuffer(g_gpuDevice, g_stagingBuffer, false);
|
||||
memcpy(mappedPtr, data, dataSize);
|
||||
SDL_UnmapGPUTransferBuffer(g_gpuDevice, g_stagingBuffer);
|
||||
|
||||
const auto cmdBuffer = SDL_AcquireGPUCommandBuffer(g_gpuDevice);
|
||||
const auto copyPass = SDL_BeginGPUCopyPass(cmdBuffer);
|
||||
|
||||
SDL_GPUTransferBufferLocation src{
|
||||
.transfer_buffer = g_stagingBuffer,
|
||||
.offset = 0
|
||||
};
|
||||
SDL_GPUBufferRegion dst{
|
||||
.buffer = handle,
|
||||
.offset = 0,
|
||||
.size = dataSize
|
||||
};
|
||||
SDL_UploadToGPUBuffer(copyPass, &src, &dst, false);
|
||||
|
||||
SDL_EndGPUCopyPass(copyPass);
|
||||
SDL_SubmitGPUCommandBuffer(cmdBuffer);
|
||||
}
|
||||
|
||||
res->m_handle = (Handle)handle;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
BOOL GPUBuffer::InitializeStagingBuffer()
|
||||
{
|
||||
SDL_GPUTransferBufferCreateInfo createInfo{
|
||||
.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD,
|
||||
.size = g_stagingBufferSize
|
||||
};
|
||||
if(!(g_stagingBuffer = SDL_CreateGPUTransferBuffer(g_gpuDevice, &createInfo)))
|
||||
{
|
||||
IAE_LOG_ERROR("Couldn't create a SDL3 GPU Staging Buffer: ", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
VOID GPUBuffer::TerminateStagingBuffer()
|
||||
{
|
||||
if(!g_stagingBuffer)
|
||||
return;
|
||||
|
||||
SDL_ReleaseGPUTransferBuffer(g_gpuDevice, g_stagingBuffer);
|
||||
}
|
||||
|
||||
BOOL GPUBuffer::EnsureStagingBufferSize(IN UINT32 size)
|
||||
{
|
||||
if(!g_stagingBuffer)
|
||||
return false;
|
||||
if(size <= g_stagingBufferSize)
|
||||
return true;
|
||||
SDL_ReleaseGPUTransferBuffer(g_gpuDevice, g_stagingBuffer);
|
||||
SDL_GPUTransferBufferCreateInfo createInfo{
|
||||
.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD,
|
||||
.size = (g_stagingBufferSize = size)
|
||||
};
|
||||
if(!(g_stagingBuffer = SDL_CreateGPUTransferBuffer(g_gpuDevice, &createInfo)))
|
||||
{
|
||||
IAE_LOG_ERROR("Couldn't create a SDL3 GPU Staging Buffer: ", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace ia::iae
|
||||
44
Src/IAEngine/imp/cpp/Rendering/Mesh/Quad.cpp
Normal file
44
Src/IAEngine/imp/cpp/Rendering/Mesh/Quad.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
// 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/Rendering/GPUBuffer.hpp>
|
||||
#include <IAEngine/Rendering/Mesh/Quad.hpp>
|
||||
#include <IAEngine/Rendering/Renderer.hpp>
|
||||
#include <IAEngine/Rendering/Types.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
RefPtr<GPUBuffer> g_quadMeshVertexBuffer{};
|
||||
|
||||
VOID QuadMesh::Initialize()
|
||||
{
|
||||
Vertex_Mesh vertices[6] = {{iam::Vec3f{-1, 1, 0}, iam::Vec2f{0, 0}}, {iam::Vec3f{1, 1, 0}, iam::Vec2f{1, 0}},
|
||||
{iam::Vec3f{1, -1, 0}, iam::Vec2f{1, 1}}, {iam::Vec3f{-1, 1, 0}, iam::Vec2f{0, 0}},
|
||||
{iam::Vec3f{1, -1, 0}, iam::Vec2f{1, 1}}, {iam::Vec3f{-1, -1, 0}, iam::Vec2f{0, 1}}};
|
||||
g_quadMeshVertexBuffer = GPUBuffer::Create(&vertices, sizeof(vertices));
|
||||
}
|
||||
|
||||
VOID QuadMesh::Terminate()
|
||||
{
|
||||
if(g_quadMeshVertexBuffer)
|
||||
g_quadMeshVertexBuffer.reset();
|
||||
}
|
||||
|
||||
VOID QuadMesh::Draw(IN CONST iam::Vec3f &position, IN CONST iam::Vec3f &scale, IN FLOAT32 rotation)
|
||||
{
|
||||
Renderer::Draw((Handle)g_quadMeshVertexBuffer.get(), 6);
|
||||
}
|
||||
} // namespace ia::iae
|
||||
83
Src/IAEngine/imp/cpp/Rendering/Pipeline/Pipeline.cpp
Normal file
83
Src/IAEngine/imp/cpp/Rendering/Pipeline/Pipeline.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
// 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/Rendering/Pipeline/Pipeline.hpp>
|
||||
|
||||
#include <IACore/File.hpp>
|
||||
|
||||
#include <SDL3/SDL_gpu.h>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
EXTERN SDL_GPUDevice *g_gpuDevice;
|
||||
|
||||
Handle IPipeline::LoadShaderFromMemory(IN ShaderStage _stage, IN PCUINT8 sourceData, IN SIZE_T sourceLength,
|
||||
IN UINT32 samplerCount, IN UINT32 uniformBufferCount,
|
||||
IN UINT32 storageBufferCount, IN UINT32 storageTextureCount)
|
||||
{
|
||||
SDL_GPUShader* res{};
|
||||
|
||||
SDL_GPUShaderStage stage{};
|
||||
switch (_stage)
|
||||
{
|
||||
case ShaderStage::VERTEX:
|
||||
stage = SDL_GPU_SHADERSTAGE_VERTEX;
|
||||
break;
|
||||
|
||||
case ShaderStage::PIXEL:
|
||||
stage = SDL_GPU_SHADERSTAGE_FRAGMENT;
|
||||
break;
|
||||
|
||||
default:
|
||||
THROW_INVALID_DATA("Unsupported shader stage");
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_GPUShaderCreateInfo createInfo = {
|
||||
.code_size = sourceLength,
|
||||
.code = sourceData,
|
||||
.entrypoint = "main",
|
||||
.format = SDL_GPU_SHADERFORMAT_SPIRV,
|
||||
.stage = stage,
|
||||
.num_samplers = samplerCount,
|
||||
.num_storage_textures = storageTextureCount,
|
||||
.num_storage_buffers = storageBufferCount,
|
||||
.num_uniform_buffers = uniformBufferCount,
|
||||
};
|
||||
|
||||
if(!(res = SDL_CreateGPUShader(g_gpuDevice, &createInfo)))
|
||||
{
|
||||
IAE_LOG_ERROR("Failed to create a SDL shader: ", SDL_GetError());
|
||||
return INVALID_HANDLE;
|
||||
}
|
||||
|
||||
return (Handle)res;
|
||||
}
|
||||
|
||||
Handle IPipeline::LoadShaderFromFile(IN ShaderStage stage, IN PCCHAR fileName, IN UINT32 samplerCount,
|
||||
IN UINT32 uniformBufferCount, IN UINT32 storageBufferCount,
|
||||
IN UINT32 storageTextureCount)
|
||||
{
|
||||
const auto source = File::ReadToVector(fileName);
|
||||
return LoadShaderFromMemory(stage, source.data(), source.size(), samplerCount, uniformBufferCount,
|
||||
storageBufferCount, storageTextureCount);
|
||||
}
|
||||
|
||||
VOID IPipeline::UnloadShader(IN Handle handle)
|
||||
{
|
||||
SDL_ReleaseGPUShader(g_gpuDevice, (SDL_GPUShader *) handle);
|
||||
}
|
||||
} // namespace ia::iae
|
||||
89
Src/IAEngine/imp/cpp/Rendering/Pipeline/UnlitMesh.cpp
Normal file
89
Src/IAEngine/imp/cpp/Rendering/Pipeline/UnlitMesh.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
// 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/Rendering/Pipeline/UnlitMesh.hpp>
|
||||
|
||||
#include <SDL3/SDL_gpu.h>
|
||||
|
||||
#include <EmbeddedShaders.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
EXTERN SDL_GPUDevice *g_gpuDevice;
|
||||
EXTERN SDL_Window *g_windowHandle;
|
||||
|
||||
Pipeline_UnlitMesh::~Pipeline_UnlitMesh()
|
||||
{
|
||||
}
|
||||
|
||||
RefPtr<Pipeline_UnlitMesh> Pipeline_UnlitMesh::Create()
|
||||
{
|
||||
const auto res = MakeRefPtr<Pipeline_UnlitMesh>();
|
||||
|
||||
const auto vertexShader = LoadShaderFromMemory(ShaderStage::VERTEX, SHADER_SOURCE_UNLITMESH_VERT, sizeof(SHADER_SOURCE_UNLITMESH_VERT), 0, 0, 0, 0);
|
||||
const auto pixelShader = LoadShaderFromMemory(ShaderStage::PIXEL, SHADER_SOURCE_UNLITMESH_FRAG, sizeof(SHADER_SOURCE_UNLITMESH_FRAG), 0, 0, 0, 0);
|
||||
|
||||
SDL_GPUColorTargetDescription colorTargets[] = {
|
||||
{.format = SDL_GetGPUSwapchainTextureFormat(g_gpuDevice, g_windowHandle)}};
|
||||
SDL_GPUVertexBufferDescription vertexBuffers[] = {{
|
||||
.slot = 0,
|
||||
.pitch = sizeof(Vertex_Mesh),
|
||||
.input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX,
|
||||
.instance_step_rate = 0,
|
||||
}};
|
||||
SDL_GPUVertexAttribute vertexAttributes[] = {
|
||||
{.location = 0, .buffer_slot = 0, .format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3, .offset = 0},
|
||||
{.location = 1,
|
||||
.buffer_slot = 0,
|
||||
.format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2,
|
||||
.offset = sizeof(float) * 3}};
|
||||
SDL_GPUGraphicsPipelineCreateInfo createInfo = {
|
||||
.vertex_shader = (SDL_GPUShader *) vertexShader,
|
||||
.fragment_shader = (SDL_GPUShader *) pixelShader,
|
||||
.vertex_input_state =
|
||||
SDL_GPUVertexInputState{.vertex_buffer_descriptions = vertexBuffers,
|
||||
.num_vertex_buffers = sizeof(vertexBuffers) / sizeof(vertexBuffers[0]),
|
||||
.vertex_attributes = vertexAttributes,
|
||||
.num_vertex_attributes =
|
||||
sizeof(vertexAttributes) / sizeof(vertexAttributes[0])},
|
||||
.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST,
|
||||
.target_info =
|
||||
{
|
||||
.color_target_descriptions = colorTargets,
|
||||
.num_color_targets = sizeof(colorTargets) / sizeof(colorTargets[0]),
|
||||
},
|
||||
};
|
||||
|
||||
SDL_GPUGraphicsPipeline* handle{};
|
||||
if(!(handle = SDL_CreateGPUGraphicsPipeline(g_gpuDevice, &createInfo)))
|
||||
{
|
||||
IAE_LOG_ERROR("Failed to create a SDL graphics pipeline: ", SDL_GetError());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UnloadShader(pixelShader);
|
||||
UnloadShader(vertexShader);
|
||||
|
||||
res->m_handle = (Handle)handle;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
VOID Pipeline_UnlitMesh::Bind(IN Handle renderPassHandle)
|
||||
{
|
||||
SDL_BindGPUGraphicsPipeline((SDL_GPURenderPass*)renderPassHandle, (SDL_GPUGraphicsPipeline*)m_handle);
|
||||
}
|
||||
} // namespace ia::iae
|
||||
190
Src/IAEngine/imp/cpp/Rendering/Renderer.cpp
Normal file
190
Src/IAEngine/imp/cpp/Rendering/Renderer.cpp
Normal file
@ -0,0 +1,190 @@
|
||||
// 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/IAEngine.hpp>
|
||||
#include <IAEngine/Rendering/GPUBuffer.hpp>
|
||||
#include <IAEngine/Rendering/Mesh/Quad.hpp>
|
||||
#include <IAEngine/Rendering/Pipeline/UnlitMesh.hpp>
|
||||
#include <IAEngine/Rendering/Renderer.hpp>
|
||||
|
||||
#include <SDL3/SDL_gpu.h>
|
||||
|
||||
#include <backends/imgui_impl_sdl3.h>
|
||||
#include <backends/imgui_impl_sdlgpu3.h>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
INT32 Renderer::s_width{};
|
||||
INT32 Renderer::s_height{};
|
||||
Vector<Renderer::DebugUIWindow> Renderer::s_debugUIWindows;
|
||||
|
||||
SDL_Window *g_windowHandle{};
|
||||
SDL_GPUDevice *g_gpuDevice{};
|
||||
|
||||
// Render State
|
||||
SDL_GPUCommandBuffer *g_cmdBuffer{};
|
||||
SDL_GPURenderPass *g_renderPass{};
|
||||
SDL_GPUTexture *g_swpChainTexture{};
|
||||
|
||||
// ImGUI State
|
||||
ImGuiIO g_imGUIIO{};
|
||||
ImDrawData *g_imDrawData{};
|
||||
|
||||
RefPtr<Pipeline_UnlitMesh> g_pipelineUnlitMesh;
|
||||
|
||||
BOOL Renderer::Initialize(IN Engine *engine)
|
||||
{
|
||||
g_windowHandle = (SDL_Window *) engine->GetWindowHandle();
|
||||
|
||||
if (!(g_gpuDevice = SDL_CreateGPUDevice(SDL_GPU_SHADERFORMAT_SPIRV, engine->IsDebugMode, nullptr)))
|
||||
{
|
||||
IAE_LOG_ERROR("Couldn't create SDL3 GPU Device: ", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SDL_ClaimWindowForGPUDevice(g_gpuDevice, g_windowHandle))
|
||||
{
|
||||
IAE_LOG_ERROR("Couldn't initialize SDL3 GPU for the window: ", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
SDL_SetGPUSwapchainParameters(g_gpuDevice, g_windowHandle, SDL_GPU_SWAPCHAINCOMPOSITION_SDR,
|
||||
SDL_GPU_PRESENTMODE_VSYNC);
|
||||
|
||||
const auto mainScale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay());
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
g_imGUIIO = ImGui::GetIO();
|
||||
g_imGUIIO.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
g_imGUIIO.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
||||
|
||||
ImGui::StyleColorsClassic();
|
||||
|
||||
ImGuiStyle &style = ImGui::GetStyle();
|
||||
style.ScaleAllSizes(mainScale);
|
||||
style.FontScaleDpi = mainScale;
|
||||
|
||||
ImGui_ImplSDLGPU3_InitInfo initInfo{.Device = g_gpuDevice,
|
||||
.ColorTargetFormat =
|
||||
SDL_GetGPUSwapchainTextureFormat(g_gpuDevice, g_windowHandle),
|
||||
.PresentMode = SDL_GPU_PRESENTMODE_VSYNC};
|
||||
ImGui_ImplSDL3_InitForSDLGPU(g_windowHandle);
|
||||
ImGui_ImplSDLGPU3_Init(&initInfo);
|
||||
|
||||
if (!GPUBuffer::InitializeStagingBuffer())
|
||||
return false;
|
||||
|
||||
g_pipelineUnlitMesh = Pipeline_UnlitMesh::Create();
|
||||
|
||||
QuadMesh::Initialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
VOID Renderer::Terminate()
|
||||
{
|
||||
SDL_WaitForGPUIdle(g_gpuDevice);
|
||||
|
||||
QuadMesh::Terminate();
|
||||
|
||||
GPUBuffer::TerminateStagingBuffer();
|
||||
|
||||
ImGui_ImplSDL3_Shutdown();
|
||||
ImGui_ImplSDLGPU3_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
SDL_ReleaseWindowFromGPUDevice(g_gpuDevice, g_windowHandle);
|
||||
SDL_DestroyGPUDevice(g_gpuDevice);
|
||||
}
|
||||
|
||||
VOID Renderer::AddDebugUIWindow(IN PCCHAR title, IN CONST iam::Vec2f &position, IN CONST iam::Vec2f &size,
|
||||
IN std::function<VOID()> contentDrawCallback)
|
||||
{
|
||||
s_debugUIWindows.pushBack(DebugUIWindow{title, position, size, contentDrawCallback});
|
||||
}
|
||||
|
||||
VOID Renderer::BeginFrame()
|
||||
{
|
||||
ImGui_ImplSDLGPU3_NewFrame();
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
for (const auto &w : s_debugUIWindows)
|
||||
{
|
||||
ImGui::Begin(w.Title);
|
||||
ImGui::SetWindowPos({w.Position.X, w.Position.Y});
|
||||
ImGui::SetWindowSize({w.Size.X, w.Size.Y});
|
||||
w.ContentDrawCallback();
|
||||
ImGui::End();
|
||||
}
|
||||
ImGui::Render();
|
||||
|
||||
if (!(g_cmdBuffer = SDL_AcquireGPUCommandBuffer(g_gpuDevice)))
|
||||
{
|
||||
IAE_LOG_ERROR("Couldn't acquire SDL3 GPU command buffer: ", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SDL_WaitAndAcquireGPUSwapchainTexture(g_cmdBuffer, g_windowHandle, &g_swpChainTexture, (PUINT32) &s_width,
|
||||
(PUINT32) &s_height))
|
||||
{
|
||||
IAE_LOG_ERROR("Couldn't acquire SDL3 GPU Swapchain texture: ", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!g_swpChainTexture)
|
||||
return;
|
||||
|
||||
g_imDrawData = ImGui::GetDrawData();
|
||||
|
||||
ImGui_ImplSDLGPU3_PrepareDrawData(g_imDrawData, g_cmdBuffer);
|
||||
|
||||
SDL_GPUColorTargetInfo colorTargetInfo = {0};
|
||||
colorTargetInfo.texture = g_swpChainTexture;
|
||||
colorTargetInfo.clear_color = SDL_FColor{0.33f, 0.33f, 0.33f, 1.0f};
|
||||
colorTargetInfo.load_op = SDL_GPU_LOADOP_CLEAR;
|
||||
colorTargetInfo.store_op = SDL_GPU_STOREOP_STORE;
|
||||
|
||||
g_renderPass = SDL_BeginGPURenderPass(g_cmdBuffer, &colorTargetInfo, 1, NULL);
|
||||
|
||||
g_pipelineUnlitMesh->Bind((Handle) g_renderPass);
|
||||
}
|
||||
|
||||
VOID Renderer::EndFrame()
|
||||
{
|
||||
if (!g_swpChainTexture)
|
||||
return;
|
||||
|
||||
ImGui_ImplSDLGPU3_RenderDrawData(g_imDrawData, g_cmdBuffer, g_renderPass);
|
||||
SDL_EndGPURenderPass(g_renderPass);
|
||||
SDL_SubmitGPUCommandBuffer(g_cmdBuffer);
|
||||
}
|
||||
|
||||
VOID Renderer::Draw(IN Handle vertexBufferHandle, IN INT32 vertexCount)
|
||||
{
|
||||
SDL_GPUBufferBinding bindings[] = {{.buffer = (SDL_GPUBuffer *) vertexBufferHandle, .offset = 0}};
|
||||
SDL_BindGPUVertexBuffers(g_renderPass, 0, bindings, 1);
|
||||
SDL_DrawGPUPrimitives(g_renderPass, vertexCount, 1, 0, 0);
|
||||
}
|
||||
|
||||
VOID Renderer::Draw(IN Handle vertexBufferHandle, IN Handle indexBufferHandle, IN INT32 indexCount)
|
||||
{
|
||||
SDL_GPUBufferBinding bindings[] = {{.buffer = (SDL_GPUBuffer *) vertexBufferHandle, .offset = 0},
|
||||
{.buffer = (SDL_GPUBuffer *) indexBufferHandle, .offset = 0}};
|
||||
SDL_BindGPUVertexBuffers(g_renderPass, 0, bindings, 1);
|
||||
SDL_BindGPUIndexBuffer(g_renderPass, &bindings[1], SDL_GPU_INDEXELEMENTSIZE_32BIT);
|
||||
SDL_DrawGPUIndexedPrimitives(g_renderPass, indexCount, 1, 0, 0, 0);
|
||||
}
|
||||
} // namespace ia::iae
|
||||
46
Src/IAEngine/imp/cpp/Rendering/Texture.cpp
Normal file
46
Src/IAEngine/imp/cpp/Rendering/Texture.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
// 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/IAEngine.hpp>
|
||||
#include <IAEngine/Rendering/Texture.hpp>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#define TEXTURE_HANDLE (SDL_Texture *) m_handle
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
Texture::Texture()
|
||||
{
|
||||
}
|
||||
|
||||
Texture::~Texture()
|
||||
{
|
||||
SDL_DestroyTexture(TEXTURE_HANDLE);
|
||||
}
|
||||
|
||||
VOID Texture::Draw(IN CONST iam::Vec3f &position, IN CONST iam::Vec3f &scale, IN FLOAT32 rotation, IN BOOL flipH,
|
||||
IN BOOL flipV, IN CONST iam::Vec4f &colorOverlay) CONST
|
||||
{
|
||||
// SDL_FRect rect{.x = position.X, .y = position.Y, .w = m_width * scale.X, .h = m_height * scale.Y};
|
||||
//SDL_SetTextureColorModFloat(TEXTURE_HANDLE, colorOverlay.X, colorOverlay.Y, colorOverlay.Z);
|
||||
//SDL_SetTextureAlphaModFloat(TEXTURE_HANDLE, colorOverlay.W);
|
||||
//SDL_RenderTextureRotated((SDL_Renderer *) m_engine->GetRendererHandle(), TEXTURE_HANDLE, nullptr, &rect,
|
||||
// rotation, nullptr,
|
||||
// (SDL_FlipMode) (SDL_FLIP_NONE | (flipV ? SDL_FLIP_VERTICAL : SDL_FLIP_NONE) |
|
||||
// (flipH ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE)));
|
||||
}
|
||||
} // namespace ia::iae
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/IAEngine.hpp>
|
||||
#include <IAEngine/ResourceManager.hpp>
|
||||
|
||||
@ -30,20 +46,20 @@ namespace ia::iae
|
||||
|
||||
RefPtr<Texture> ResourceManager::CreateTexture(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height)
|
||||
{
|
||||
const auto result = MakeRefPtr<Texture>(m_engine);
|
||||
//const auto result = MakeRefPtr<Texture>(m_engine);
|
||||
|
||||
result->m_width = width;
|
||||
result->m_height = height;
|
||||
//result->m_width = width;
|
||||
//result->m_height = height;
|
||||
|
||||
SDL_Surface *surface =
|
||||
SDL_CreateSurfaceFrom(width, height, SDL_PIXELFORMAT_RGBA32, (void *) rgbaData, width << 2);
|
||||
if (!surface)
|
||||
THROW_UNKNOWN("Failed to create SDL surface: ", SDL_GetError());
|
||||
result->m_handle = SDL_CreateTextureFromSurface((SDL_Renderer *) m_engine->GetRendererHandle(), surface);
|
||||
if (!result->m_handle)
|
||||
THROW_UNKNOWN("Failed to create SDL Texture: ", SDL_GetError());
|
||||
SDL_DestroySurface(surface);
|
||||
//SDL_Surface *surface =
|
||||
// SDL_CreateSurfaceFrom(width, height, SDL_PIXELFORMAT_RGBA32, (void *) rgbaData, width << 2);
|
||||
//if (!surface)
|
||||
// THROW_UNKNOWN("Failed to create SDL surface: ", SDL_GetError());
|
||||
//result->m_handle = SDL_CreateTextureFromSurface((SDL_Renderer *) m_engine->GetRendererHandle(), surface);
|
||||
//if (!result->m_handle)
|
||||
// THROW_UNKNOWN("Failed to create SDL Texture: ", SDL_GetError());
|
||||
//SDL_DestroySurface(surface);
|
||||
|
||||
return result;
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace ia::iae
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/Scene.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
#include <IAEngine/IAEngine.hpp>
|
||||
#include <IAEngine/Texture.hpp>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#define TEXTURE_HANDLE (SDL_Texture *) m_handle
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
Texture::Texture(IN Engine *engine) : m_engine(engine)
|
||||
{
|
||||
}
|
||||
|
||||
Texture::~Texture()
|
||||
{
|
||||
SDL_DestroyTexture(TEXTURE_HANDLE);
|
||||
}
|
||||
|
||||
VOID Texture::Draw(IN CONST iam::Vec3f &position, IN CONST iam::Vec3f &scale, IN FLOAT32 rotation, IN BOOL flipH,
|
||||
IN BOOL flipV, IN CONST iam::Vec4f &colorOverlay) CONST
|
||||
{
|
||||
SDL_FRect rect{.x = position.X, .y = position.Y, .w = m_width * scale.X, .h = m_height * scale.Y};
|
||||
|
||||
SDL_SetTextureColorModFloat(TEXTURE_HANDLE, colorOverlay.X, colorOverlay.Y, colorOverlay.Z);
|
||||
SDL_SetTextureAlphaModFloat(TEXTURE_HANDLE, colorOverlay.W);
|
||||
SDL_RenderTextureRotated((SDL_Renderer *) m_engine->GetRendererHandle(), TEXTURE_HANDLE, nullptr, &rect,
|
||||
rotation, nullptr,
|
||||
(SDL_FlipMode) (SDL_FLIP_NONE | (flipV ? SDL_FLIP_VERTICAL : SDL_FLIP_NONE) |
|
||||
(flipH ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE)));
|
||||
}
|
||||
} // namespace ia::iae
|
||||
@ -1,3 +1,19 @@
|
||||
// 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/Random.hpp>
|
||||
#include <IAEngine/Time.hpp>
|
||||
|
||||
|
||||
11
Src/IAEngine/imp/glsl/UnlitMesh/UnlitMesh.frag
Normal file
11
Src/IAEngine/imp/glsl/UnlitMesh/UnlitMesh.frag
Normal file
@ -0,0 +1,11 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec2 inTexCoord;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
outColor = vec4(0, 1, 0, 1);
|
||||
}
|
||||
10
Src/IAEngine/imp/glsl/UnlitMesh/UnlitMesh.vert
Normal file
10
Src/IAEngine/imp/glsl/UnlitMesh/UnlitMesh.vert
Normal file
@ -0,0 +1,10 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) out vec2 outTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
outTexCoord = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
|
||||
gl_Position = vec4(outTexCoord * 2.0f - 1.0f, 0.0f, 1.0f);
|
||||
}
|
||||
33
Src/IAEngine/imp/hpp/EmbeddedShaders.hpp
Normal file
33
Src/IAEngine/imp/hpp/EmbeddedShaders.hpp
Normal file
File diff suppressed because one or more lines are too long
@ -17,7 +17,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Components/Component.hpp>
|
||||
#include <IAEngine/Texture.hpp>
|
||||
#include <IAEngine/Rendering/Texture.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Components/Component.hpp>
|
||||
#include <IAEngine/Texture.hpp>
|
||||
#include <IAEngine/Rendering/Texture.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Components/Component.hpp>
|
||||
#include <IAEngine/Texture.hpp>
|
||||
#include <IAEngine/Rendering/Texture.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
@ -17,9 +17,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Nodes/Node.hpp>
|
||||
#include <IAEngine/Scene.hpp>
|
||||
#include <IAEngine/Texture.hpp>
|
||||
#include <IAEngine/Rendering/Texture.hpp>
|
||||
#include <IAEngine/Rendering/Renderer.hpp>
|
||||
#include <IAEngine/ResourceManager.hpp>
|
||||
#include <IAEngine/Scene.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
@ -27,14 +28,6 @@ namespace ia::iae
|
||||
|
||||
class Engine
|
||||
{
|
||||
struct DebugUIWindow
|
||||
{
|
||||
PCCHAR Title{""};
|
||||
iam::Vec2f Position{};
|
||||
iam::Vec2f Size{};
|
||||
std::function<VOID()> ContentDrawCallback{};
|
||||
};
|
||||
|
||||
public:
|
||||
struct InitConfig
|
||||
{
|
||||
@ -43,6 +36,12 @@ namespace ia::iae
|
||||
INT32 WindowHeight{600};
|
||||
};
|
||||
|
||||
#if defined(__DEBUG_MODE__)
|
||||
STATIC CONSTEXPR BOOL IsDebugMode = TRUE;
|
||||
#else
|
||||
STATIC CONSTEXPR BOOL IsDebugMode = FALSE;
|
||||
#endif
|
||||
|
||||
public:
|
||||
Engine();
|
||||
~Engine();
|
||||
@ -54,10 +53,7 @@ namespace ia::iae
|
||||
VOID EndFrame();
|
||||
BOOL ShouldClose();
|
||||
|
||||
VOID AddDebugUIWindow(IN PCCHAR title, IN CONST iam::Vec2f &position, IN CONST iam::Vec2f &size, IN std::function<VOID()> contentDrawCallback);
|
||||
|
||||
template<typename _class_type>
|
||||
_class_type* RegisterResourceManager();
|
||||
template<typename _class_type> _class_type *RegisterResourceManager();
|
||||
|
||||
public:
|
||||
RefPtr<Scene> CreateScene();
|
||||
@ -65,10 +61,9 @@ namespace ia::iae
|
||||
VOID ChangeScene(IN RefPtr<Scene> scene);
|
||||
|
||||
public:
|
||||
PVOID GetRendererHandle() CONST;
|
||||
PVOID GetWindowHandle() CONST;
|
||||
|
||||
private:
|
||||
VOID RenderDebugUI();
|
||||
VOID ProcessEvents();
|
||||
VOID UpdateGame();
|
||||
VOID RenderGame();
|
||||
@ -78,13 +73,11 @@ namespace ia::iae
|
||||
RefPtr<Scene> m_activeScene{};
|
||||
CONST RefPtr<EngineContext> m_context;
|
||||
RefPtr<ResourceManager> m_resourceManager;
|
||||
Vector<DebugUIWindow> m_debugUIWindows;
|
||||
};
|
||||
|
||||
template<typename _class_type>
|
||||
_class_type* Engine::RegisterResourceManager()
|
||||
template<typename _class_type> _class_type *Engine::RegisterResourceManager()
|
||||
{
|
||||
m_resourceManager = MakeRefPtr<_class_type>(this);
|
||||
return (_class_type*)m_resourceManager.get();
|
||||
return (_class_type *) m_resourceManager.get();
|
||||
}
|
||||
} // namespace ia::iae
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
#include <IAEngine/Components/Component.hpp>
|
||||
#include <IAEngine/Nodes/Transform.hpp>
|
||||
#include <IAEngine/Texture.hpp>
|
||||
#include <IAEngine/Rendering/Texture.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
0
Src/IAEngine/inc/IAEngine/Rendering/Camera.hpp
Normal file
0
Src/IAEngine/inc/IAEngine/Rendering/Camera.hpp
Normal file
40
Src/IAEngine/inc/IAEngine/Rendering/GPUBuffer.hpp
Normal file
40
Src/IAEngine/inc/IAEngine/Rendering/GPUBuffer.hpp
Normal file
@ -0,0 +1,40 @@
|
||||
// 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/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Base.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class Renderer;
|
||||
|
||||
class GPUBuffer
|
||||
{
|
||||
public:
|
||||
STATIC RefPtr<GPUBuffer> Create(IN PCVOID data, IN UINT32 dataSize);
|
||||
|
||||
private:
|
||||
Handle m_handle{};
|
||||
|
||||
private:
|
||||
STATIC BOOL InitializeStagingBuffer();
|
||||
STATIC VOID TerminateStagingBuffer();
|
||||
STATIC BOOL EnsureStagingBufferSize(IN UINT32 size);
|
||||
|
||||
friend class Renderer;
|
||||
};
|
||||
} // namespace ia::iae
|
||||
31
Src/IAEngine/inc/IAEngine/Rendering/Mesh/Quad.hpp
Normal file
31
Src/IAEngine/inc/IAEngine/Rendering/Mesh/Quad.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
// 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/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Base.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class QuadMesh
|
||||
{
|
||||
public:
|
||||
STATIC VOID Initialize();
|
||||
STATIC VOID Terminate();
|
||||
|
||||
STATIC VOID Draw(IN CONST iam::Vec3f &position, IN CONST iam::Vec3f &scale, IN FLOAT32 rotation);
|
||||
};
|
||||
} // namespace ia::iae
|
||||
47
Src/IAEngine/inc/IAEngine/Rendering/Pipeline/Pipeline.hpp
Normal file
47
Src/IAEngine/inc/IAEngine/Rendering/Pipeline/Pipeline.hpp
Normal file
@ -0,0 +1,47 @@
|
||||
// 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/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Rendering/Types.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class IPipeline
|
||||
{
|
||||
public:
|
||||
enum class ShaderStage
|
||||
{
|
||||
VERTEX,
|
||||
PIXEL,
|
||||
COMPUTE,
|
||||
GEOMETRY
|
||||
};
|
||||
|
||||
public:
|
||||
PURE_VIRTUAL(VOID Bind(IN Handle renderPassHandle));
|
||||
|
||||
protected:
|
||||
STATIC Handle LoadShaderFromMemory(IN ShaderStage stage, IN PCUINT8 sourceData, IN SIZE_T sourceLength, IN UINT32 samplerCount,
|
||||
IN UINT32 uniformBufferCount, IN UINT32 storageBufferCount,
|
||||
IN UINT32 storageTextureCount);
|
||||
STATIC Handle LoadShaderFromFile(IN ShaderStage stage, IN PCCHAR fileName, IN UINT32 samplerCount,
|
||||
IN UINT32 uniformBufferCount, IN UINT32 storageBufferCount,
|
||||
IN UINT32 storageTextureCount);
|
||||
|
||||
STATIC VOID UnloadShader(IN Handle handle);
|
||||
};
|
||||
} // namespace ia::iae
|
||||
35
Src/IAEngine/inc/IAEngine/Rendering/Pipeline/UnlitMesh.hpp
Normal file
35
Src/IAEngine/inc/IAEngine/Rendering/Pipeline/UnlitMesh.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
// 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/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Rendering/Pipeline/Pipeline.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class Pipeline_UnlitMesh: public IPipeline
|
||||
{
|
||||
public:
|
||||
~Pipeline_UnlitMesh();
|
||||
|
||||
STATIC RefPtr<Pipeline_UnlitMesh> Create();
|
||||
|
||||
VOID Bind(IN Handle renderPassHandle);
|
||||
|
||||
private:
|
||||
Handle m_handle{INVALID_HANDLE};
|
||||
};
|
||||
}
|
||||
66
Src/IAEngine/inc/IAEngine/Rendering/Renderer.hpp
Normal file
66
Src/IAEngine/inc/IAEngine/Rendering/Renderer.hpp
Normal file
@ -0,0 +1,66 @@
|
||||
// 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/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Base.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class Engine;
|
||||
|
||||
class Renderer
|
||||
{
|
||||
struct DebugUIWindow
|
||||
{
|
||||
PCCHAR Title{""};
|
||||
iam::Vec2f Position{};
|
||||
iam::Vec2f Size{};
|
||||
std::function<VOID()> ContentDrawCallback{};
|
||||
};
|
||||
|
||||
public:
|
||||
STATIC BOOL Initialize(IN Engine *engine);
|
||||
STATIC VOID Terminate();
|
||||
|
||||
public:
|
||||
STATIC VOID AddDebugUIWindow(IN PCCHAR title, IN CONST iam::Vec2f &position, IN CONST iam::Vec2f &size,
|
||||
IN std::function<VOID()> contentDrawCallback);
|
||||
|
||||
public:
|
||||
STATIC VOID BeginFrame();
|
||||
STATIC VOID EndFrame();
|
||||
|
||||
STATIC VOID Draw(IN Handle vertexBufferHandle, IN INT32 vertexCount);
|
||||
STATIC VOID Draw(IN Handle vertexBufferHandle, IN Handle indexBufferHandle, IN INT32 indexCount);
|
||||
|
||||
public:
|
||||
STATIC INT32 Width()
|
||||
{
|
||||
return s_width;
|
||||
}
|
||||
|
||||
STATIC INT32 Height()
|
||||
{
|
||||
return s_height;
|
||||
}
|
||||
|
||||
private:
|
||||
STATIC INT32 s_width;
|
||||
STATIC INT32 s_height;
|
||||
STATIC Vector<DebugUIWindow> s_debugUIWindows;
|
||||
};
|
||||
} // namespace ia::iae
|
||||
@ -20,12 +20,10 @@
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class Engine;
|
||||
|
||||
class Texture
|
||||
{
|
||||
public:
|
||||
Texture(IN Engine* engine);
|
||||
Texture();
|
||||
~Texture();
|
||||
|
||||
public:
|
||||
@ -46,10 +44,5 @@ namespace ia::iae
|
||||
INT32 m_width;
|
||||
INT32 m_height;
|
||||
PVOID m_handle{};
|
||||
Engine* CONST m_engine;
|
||||
|
||||
private:
|
||||
friend class Engine;
|
||||
friend class ResourceManager;
|
||||
};
|
||||
} // namespace ia::iae
|
||||
30
Src/IAEngine/inc/IAEngine/Rendering/Types.hpp
Normal file
30
Src/IAEngine/inc/IAEngine/Rendering/Types.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
// 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/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Base.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
struct Vertex_Mesh
|
||||
{
|
||||
iam::Vec3f Position{};
|
||||
iam::Vec2f UV{};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@ -17,7 +17,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Audio.hpp>
|
||||
#include <IAEngine/Texture.hpp>
|
||||
#include <IAEngine/Rendering/Texture.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
61
Src/IAEngine/srcgen/embed_shaders.py
Normal file
61
Src/IAEngine/srcgen/embed_shaders.py
Normal file
@ -0,0 +1,61 @@
|
||||
import os
|
||||
|
||||
GEN_SOURCE_PREFIX = """// 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/>.
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// GENERATED FILE. DO NOT EDIT.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Base.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
"""
|
||||
|
||||
GEN_SOURCE_SUFFIX = """} // namespace ia::iae\n"""
|
||||
GEN_SOURCE_PATH = "Src/IAEngine/imp/hpp/EmbeddedShaders.hpp"
|
||||
SHADER_SOURCE_PATH = "Src/IAEngine/imp/glsl"
|
||||
|
||||
SHADER_SOURCE_FILES = [
|
||||
"UnlitMesh/UnlitMesh.vert",
|
||||
"UnlitMesh/UnlitMesh.frag"
|
||||
]
|
||||
|
||||
def file_to_source_array(arrayName, filePath):
|
||||
data = b''
|
||||
with open(filePath, 'rb') as f:
|
||||
data = f.read()
|
||||
res = f"CONSTEXPR UINT8 {arrayName}[{len(data)}] = {{\n"
|
||||
for d in data:
|
||||
res += f"{hex(d)},"
|
||||
res += "};\n"
|
||||
return res
|
||||
|
||||
def main():
|
||||
with open(GEN_SOURCE_PATH, 'w') as outFile:
|
||||
outFile.write(GEN_SOURCE_PREFIX)
|
||||
for fileName in SHADER_SOURCE_FILES:
|
||||
p = f"{SHADER_SOURCE_PATH}/{fileName}"
|
||||
os.system(f"glslc {p} -o {p}.spv")
|
||||
src = file_to_source_array(f"SHADER_SOURCE_{fileName.split('/')[-1].upper().replace('.', '_')}", f"{p}.spv")
|
||||
outFile.write(f"{src}\n")
|
||||
os.remove(f"{p}.spv")
|
||||
outFile.write(GEN_SOURCE_SUFFIX)
|
||||
|
||||
main()
|
||||
2
Vendor/CMakeLists.txt
vendored
2
Vendor/CMakeLists.txt
vendored
@ -23,7 +23,7 @@ add_library(
|
||||
"imgui/imgui_tables.cpp"
|
||||
"imgui/imgui_widgets.cpp"
|
||||
"imgui/backends/imgui_impl_sdl3.cpp"
|
||||
"imgui/backends/imgui_impl_sdlrenderer3.cpp"
|
||||
"imgui/backends/imgui_impl_sdlgpu3.cpp"
|
||||
)
|
||||
target_include_directories(
|
||||
ImGui PRIVATE
|
||||
|
||||
2
Vendor/SDL
vendored
2
Vendor/SDL
vendored
Submodule Vendor/SDL updated: 4efdfd92a2...cfa31df2d5
2
Vendor/SDL_Mixer
vendored
2
Vendor/SDL_Mixer
vendored
Submodule Vendor/SDL_Mixer updated: 172997758b...40a580fe85
2
Vendor/imgui
vendored
2
Vendor/imgui
vendored
Submodule Vendor/imgui updated: 8eb22ea620...02af06ea5f
Reference in New Issue
Block a user