zengine/game/zworld/src/zworld.cpp

45 lines
1.1 KiB
C++
Raw Normal View History

2024-09-01 22:32:29 +08:00
#include "zlog.h"
2024-07-20 18:04:19 +08:00
#include "zworld.h"
2024-08-17 18:01:21 +08:00
#include "vkn/vulkan_window.h"
#include "vkn/vulkan_api.h"
2024-09-01 22:32:29 +08:00
#include "render/pass/demo_pass.h"
2024-08-17 18:01:21 +08:00
#include <iostream>
using namespace api;
2024-09-21 17:19:22 +08:00
RenderAPI* API;
2024-07-31 10:48:28 +08:00
void ZWorldModule::OnLoad(int argc, char** argv)
{
2024-08-17 18:01:21 +08:00
// 创建窗口
2024-09-01 22:32:29 +08:00
auto window = new vkn::VulkanWindow(&SDL_CreateWindow, { "zengine" , SDL_WINDOW_VULKAN }, 1080, 720);
2024-09-21 17:19:22 +08:00
API = new vkn::VulkanAPI();
2024-09-01 22:32:29 +08:00
auto args = vkn::VulkanWindowArgs::Default();
args.frames = 3;
if (!window->CreateRender(&SDL_Vulkan_CreateSurface, args)) {
zlog::errorf("SDL_Vulkan_CreateSurface failed {}", SDL_GetError());
}
2024-10-21 16:31:02 +08:00
API->Init();
2024-09-01 22:32:29 +08:00
API->context.views.push_back({});
2024-07-31 10:48:28 +08:00
}
2024-07-20 18:04:19 +08:00
2024-07-31 10:48:28 +08:00
void ZWorldModule::OnUnload()
{
2024-08-17 18:01:21 +08:00
}
void ZWorldModule::MainLoop()
{
bool running = true;
SDL_Event event_;
while (running) {
// 处理事件
while (SDL_PollEvent(&event_)) {
if (event_.type == SDL_QUIT) {
running = false;
}
}
2024-09-01 22:32:29 +08:00
API->graph.AddRenderPass<DemoPass>();
API->BeginFrame();
API->Render();
API->EndFrame();
2024-10-30 15:15:25 +08:00
FramePool()->reset();
2024-08-17 18:01:21 +08:00
}
2024-07-31 10:48:28 +08:00
}