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-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-07 17:48:12 +08:00
|
|
|
RenderAPI* 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());
|
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
|
{
|
2024-09-07 17:48:12 +08:00
|
|
|
RenderAPI* API = RenderAPI::Ptr();
|
2024-08-17 18:01:21 +08:00
|
|
|
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-08-17 18:01:21 +08:00
|
|
|
}
|
2024-07-31 10:48:28 +08:00
|
|
|
}
|