Files

98 lines
2.7 KiB
C++
Raw Permalink Normal View History

2020-03-21 01:14:50 -10:00
#include <boo2/boo2.hpp>
#include <iostream>
#include "testpipeline.hpp"
using namespace std::literals;
template <class App, class Win>
class Delegate : public boo2::DelegateBase<App, Win> {
Win m_window;
2020-04-21 20:01:00 -10:00
hsh::owner<hsh::render_texture2d> m_renderTexture;
2020-03-21 01:14:50 -10:00
Binding PipelineBind{};
2020-05-03 17:04:23 -10:00
#if __SWITCH__
static constexpr int W = 1280;
static constexpr int H = 720;
#else
static constexpr int W = 512;
static constexpr int H = 512;
#endif
2020-03-21 01:14:50 -10:00
public:
void onAppLaunched(App& a) noexcept {
std::cout << "launch" << std::endl;
2020-05-03 17:04:23 -10:00
m_window = a.createWindow(_SYS_STR("Hello World!"sv), 0, 0, W, H);
2020-04-23 17:20:56 -10:00
if (!m_window) {
a.quit(1);
return;
}
2020-03-21 01:14:50 -10:00
m_renderTexture = hsh::create_render_texture2d(m_window);
}
void onAppIdle(App& a) noexcept {
2020-04-23 17:20:56 -10:00
if (!PipelineBind.Binding) {
2020-03-21 01:14:50 -10:00
PipelineBind = BuildPipeline();
2020-04-23 17:20:56 -10:00
UniformData UniData{};
UniData.xf[0][0] = 1.f;
UniData.xf[1][1] = 1.f;
UniData.xf[2][2] = 1.f;
UniData.xf[3][3] = 1.f;
PipelineBind.Uniform.load(UniData);
}
2020-03-21 01:14:50 -10:00
2020-03-27 18:21:48 -10:00
if (m_window.acquireNextImage()) {
m_renderTexture.attach();
hsh::clear_attachments();
PipelineBind.Binding.draw(0, 3);
m_renderTexture.resolve_surface(m_window);
}
2020-03-21 01:14:50 -10:00
}
void onAppExiting(App& a) noexcept { std::cout << "exiting" << std::endl; }
void onQuitRequest(App& a) noexcept {
std::cout << "quit" << std::endl;
a.quit();
}
#if HSH_ENABLE_VULKAN
2020-03-27 18:21:48 -10:00
bool onAcceptDeviceRequest(
App& a, const vk::PhysicalDeviceProperties& props,
const vk::PhysicalDeviceDriverProperties& driverProps) noexcept {
if (driverProps.driverID == vk::DriverId::eMesaRadv)
return true;
2020-05-03 17:04:23 -10:00
// if (driverProps.driverID == vk::DriverId::eAmdOpenSource)
2020-03-27 18:21:48 -10:00
// return true;
return false;
2020-03-21 01:14:50 -10:00
}
#endif
2020-03-27 18:21:48 -10:00
void onStartBuildPipelines(App& a, std::size_t done,
std::size_t count) noexcept {
2020-03-21 01:14:50 -10:00
std::cout << "start " << done << "/" << count << std::endl;
}
2020-03-27 18:21:48 -10:00
void onUpdateBuildPipelines(App& a, std::size_t done,
std::size_t count) noexcept {
2020-03-21 01:14:50 -10:00
std::cout << "update " << done << "/" << count << std::endl;
}
2020-03-27 18:21:48 -10:00
void onEndBuildPipelines(App& a, std::size_t done,
std::size_t count) noexcept {
2020-03-21 01:14:50 -10:00
std::cout << "end " << done << "/" << count << std::endl;
}
2020-03-21 17:29:11 -10:00
void onWindowResize(App& a, typename Win::ID id,
const hsh::extent2d& extent) noexcept {
std::cout << "resize " << extent.w << "*" << extent.h << std::endl;
}
2020-03-21 01:14:50 -10:00
};
int main(int argc, char** argv) noexcept {
2020-05-03 17:04:23 -10:00
logvisor::RegisterStandardExceptions();
2020-03-21 01:14:50 -10:00
logvisor::RegisterConsoleLogger();
return boo2::Application<Delegate>::exec(argc, argv, "boo2_testapp"sv);
}