Cleanup 1/2
This commit is contained in:
@ -14,12 +14,18 @@
|
||||
// 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 <SDL3/SDL.h>
|
||||
#include <RenderCore/RenderCore.hpp>
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <Vendor/imgui/backends/imgui_impl_sdl3.h>
|
||||
#include <Vendor/imgui/backends/imgui_impl_sdlgpu3.h>
|
||||
#include <Vendor/imgui/imgui.h>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
SDL_Window* g_windowHandle{};
|
||||
ImDrawData *g_imDrawData{};
|
||||
|
||||
SDL_Window *g_windowHandle{};
|
||||
|
||||
INT32 Run(IN INT32 argc, IN PCCHAR argv[])
|
||||
{
|
||||
@ -29,12 +35,35 @@ namespace ia::iae
|
||||
THROW_UNKNOWN("Failed to intialize SDL: ", SDL_GetError());
|
||||
|
||||
if (!(g_windowHandle = SDL_CreateWindow("IAEngine", windowExtent.x, windowExtent.y,
|
||||
SDL_WINDOW_RESIZABLE)))
|
||||
SDL_WINDOW_RESIZABLE | SDL_WINDOW_MAXIMIZED)))
|
||||
THROW_UNKNOWN("Failed to create the SDL window: ", SDL_GetError());
|
||||
SDL_MaximizeWindow(g_windowHandle);
|
||||
SDL_GetWindowSizeInPixels(g_windowHandle, &windowExtent.x, &windowExtent.y);
|
||||
|
||||
RDC::Initialize(windowExtent, g_windowHandle, true);
|
||||
|
||||
const auto mainScale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay());
|
||||
|
||||
auto gamePreviewTexture = new RDC_Texture(RDC_Texture::EType::SAMPLED, 800, 600);
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
auto& imGUIIO = ImGui::GetIO();
|
||||
imGUIIO.IniFilename = nullptr;
|
||||
imGUIIO.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
imGUIIO.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
||||
|
||||
ImGui::StyleColorsClassic();
|
||||
|
||||
ImGuiStyle &style = ImGui::GetStyle();
|
||||
style.ScaleAllSizes(mainScale);
|
||||
style.FontScaleDpi = mainScale;
|
||||
|
||||
ImGui_ImplSDLGPU3_InitInfo initInfo{.Device = RDC_Device::GetHandle(),
|
||||
.ColorTargetFormat = RDC_Device::GetSwapchainTextureFormat(),
|
||||
.PresentMode = SDL_GPU_PRESENTMODE_VSYNC};
|
||||
ImGui_ImplSDL3_InitForSDLGPU(g_windowHandle);
|
||||
ImGui_ImplSDLGPU3_Init(&initInfo);
|
||||
|
||||
SDL_Event event{};
|
||||
while (true)
|
||||
@ -42,20 +71,66 @@ namespace ia::iae
|
||||
SDL_PollEvent(&event);
|
||||
if (event.type == SDL_EVENT_QUIT)
|
||||
break;
|
||||
ImGui_ImplSDL3_ProcessEvent(&event);
|
||||
|
||||
//RDC::DrawSpriteTopLeft(0, 0, 0, {100.0f, 100.0f}, {1.0f, 1.0f}, 0.0f);
|
||||
RDC::RenderToWindow();
|
||||
RDC::RenderToTexture(gamePreviewTexture->GetHandle());
|
||||
|
||||
ImGui_ImplSDLGPU3_NewFrame();
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
{
|
||||
ImGui::Begin("Scene");
|
||||
ImGui::Image(gamePreviewTexture->GetHandle(), {800, 600});
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
ImGui::Render();
|
||||
|
||||
STATIC SDL_GPURenderPass *ActiveRenderPass{};
|
||||
STATIC SDL_GPUCommandBuffer *ActiveCommandBuffer{};
|
||||
STATIC SDL_GPUColorTargetInfo ActiveColorTargetInfo{.clear_color = SDL_FColor{0.0f, 0.0f, 0.0f, 1.0f},
|
||||
.load_op = SDL_GPU_LOADOP_CLEAR,
|
||||
.store_op = SDL_GPU_STOREOP_STORE};
|
||||
|
||||
if (!(ActiveCommandBuffer = SDL_AcquireGPUCommandBuffer(RDC_Device::GetHandle())))
|
||||
THROW_UNKNOWN("Failed to acquire SDL GPU command buffer: ", SDL_GetError());
|
||||
|
||||
g_imDrawData = ImGui::GetDrawData();
|
||||
ImGui_ImplSDLGPU3_PrepareDrawData(g_imDrawData, ActiveCommandBuffer);
|
||||
|
||||
SDL_GPUTexture *swapChainTexture{};
|
||||
if (!SDL_WaitAndAcquireGPUSwapchainTexture(ActiveCommandBuffer, g_windowHandle, &swapChainTexture, nullptr,
|
||||
nullptr))
|
||||
THROW_UNKNOWN("Failed to acquire SDL GPU Swapchain texture: ", SDL_GetError());
|
||||
|
||||
ActiveColorTargetInfo.texture = swapChainTexture;
|
||||
ActiveColorTargetInfo.clear_color = SDL_FColor{0.3f, 0.3f, 0.3f, 1.0f};
|
||||
ActiveRenderPass = SDL_BeginGPURenderPass(ActiveCommandBuffer, &ActiveColorTargetInfo, 1, nullptr);
|
||||
ImGui_ImplSDLGPU3_RenderDrawData(g_imDrawData, ActiveCommandBuffer, ActiveRenderPass);
|
||||
|
||||
SDL_EndGPURenderPass(ActiveRenderPass);
|
||||
|
||||
SDL_SubmitGPUCommandBuffer(ActiveCommandBuffer);
|
||||
|
||||
RDC_Device::WaitForIdle();
|
||||
}
|
||||
|
||||
ImGui_ImplSDL3_Shutdown();
|
||||
ImGui_ImplSDLGPU3_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
delete gamePreviewTexture;
|
||||
|
||||
RDC::Terminate();
|
||||
|
||||
SDL_DestroyWindow(g_windowHandle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} // namespace ia::iae
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
return ia::iae::Run(argc, (const char**)argv);
|
||||
return ia::iae::Run(argc, (const char **) argv);
|
||||
}
|
||||
Reference in New Issue
Block a user