zengine/game/zworld/src/zworld.cpp

59 lines
1.5 KiB
C++

#include "zlog.h"
#include "zworld.h"
#include "data/global.h"
#include "event/event_system.h"
#include "vkn/vulkan_window.h"
#include "vkn/vulkan_api.h"
#ifdef WITH_EDITOR
#include "imgui/imgui_impl_sdl2.h"
#endif
#include "render/pass/demo_pass.h"
#include <iostream>
using namespace api;
RenderAPI* API;
void ZWorldModule::OnLoad(int argc, char** argv)
{
// 创建窗口
gEngineConfig.API = GraphicsAPI::Vulkan;
auto window = new vkn::VulkanWindow(&SDL_CreateWindow, { "zengine" , SDL_WINDOW_VULKAN }, 1080, 720);
API = new vkn::VulkanAPI();
auto args = vkn::VulkanWindowArgs::Default();
args.frames = 3;
if (!window->CreateRender(&SDL_Vulkan_CreateSurface, args)) {
zlog::errorf("SDL_Vulkan_CreateSurface failed {}", SDL_GetError());
}
API->Init();
API->context.views.push_back({});
#ifdef WITH_EDITOR //绑定窗口交互
ImGui_ImplSDL2_InitForVulkan(window->GetPtr());
#endif
EventSystem::Ptr()->BeginRenderFrame.Subscribe(mInfo.name, [](FrameGraph& graph, uint32_t frame) {
graph.AddRenderPass<DemoPass>();
});
}
void ZWorldModule::Initialize()
{
}
void ZWorldModule::OnUnload()
{
}
void ZWorldModule::MainLoop()
{
bool running = true;
SDL_Event event_;
while (running) {
// 处理事件
while (SDL_PollEvent(&event_)) {
if (event_.type == SDL_QUIT) {
running = false;
}
}
API->BeginFrame();
API->Render();
API->EndFrame();
FramePool()->reset();
}
}