initial
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
project(server_gui)
|
||||
|
||||
|
||||
file(GLOB CXX_FILES
|
||||
src/*.cpp
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${CXX_FILES})
|
||||
|
||||
target_include_directories(
|
||||
${PROJECT_NAME}
|
||||
PUBLIC
|
||||
./src/
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
${PROJECT_NAME}
|
||||
PUBLIC
|
||||
tw::network
|
||||
loft::common
|
||||
loft::base
|
||||
loft_window
|
||||
loft::render_graph
|
||||
tw::protocol
|
||||
towards
|
||||
tw::gui
|
||||
imgui::imgui
|
||||
imgui::plot
|
||||
glm::glm
|
||||
)
|
||||
@@ -0,0 +1,69 @@
|
||||
#include "GuiRenderer.hpp"
|
||||
|
||||
#include "ImGuiRenderPass.hpp"
|
||||
|
||||
#include "SDLWindow.h"
|
||||
#include "Window.hpp"
|
||||
|
||||
void lft_dbg_callback(lft::dbg::LogMessageSeverity severity,
|
||||
lft::dbg::LogMessageType type,
|
||||
const char *__restrict format,
|
||||
va_list args) {
|
||||
const char* titles[3] = {
|
||||
"\033[0;34m[info]:",
|
||||
"\033[0;33m[warn]:",
|
||||
"\033[0;31m[fail]:"
|
||||
};
|
||||
fwrite(titles[severity], 14, 1, stdout);
|
||||
|
||||
if(args != nullptr) {
|
||||
vfprintf(stdout, format, args);
|
||||
} else {
|
||||
fwrite(format, 1, strlen(format), stdout);
|
||||
}
|
||||
|
||||
fwrite("\033[0m", 4, 1, stdout);
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
Instance create_instance(const std::string& name, const lft::win::Window* window) {
|
||||
std::vector<std::string> required_extensions = window->get_required_extensions();
|
||||
// required_extensions.push_back(VK_EXT_ROBUSTNESS_2_EXTENSION_NAME);
|
||||
|
||||
std::vector<std::string> required_layers = {
|
||||
"VK_LAYER_KHRONOS_validation"
|
||||
};
|
||||
|
||||
/**
|
||||
* Instance initializes a connection with Vulkan driver
|
||||
*/
|
||||
return Instance(
|
||||
name, name,
|
||||
required_extensions,
|
||||
required_layers,
|
||||
lft_dbg_callback);
|
||||
}
|
||||
|
||||
Surface create_surface(lft::win::SDLWindow* window, const Instance* instance) {
|
||||
return window->create_surface(instance);
|
||||
}
|
||||
|
||||
lft::rg::RenderGraph GuiRenderer::init_render_graph() {
|
||||
auto imgui_render_pass = new tw::drw::gui::ImGuiRenderPass(&m_gpu, (const lft::win::SDLWindow*)m_window);
|
||||
|
||||
m_render_graph_builder.add_task(imgui_render_pass->get_render_task().build());
|
||||
|
||||
auto render_graph = m_render_graph_builder.build();
|
||||
return std::move(render_graph);
|
||||
}
|
||||
|
||||
GuiRenderer::GuiRenderer(const lft::win::Window* window) :
|
||||
m_window(window),
|
||||
m_instance(create_instance("ServerGui", window)),
|
||||
m_surface(create_surface((lft::win::SDLWindow*)window, &m_instance)),
|
||||
m_gpu(&m_instance, &m_surface),
|
||||
m_swapchain(&m_gpu, m_window->get_size(), &m_surface),
|
||||
m_render_graph_builder(&m_gpu, ImageChain::from_swapchain(m_swapchain), "swapchain"),
|
||||
m_render_graph(init_render_graph())
|
||||
{ }
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "Gpu.hpp"
|
||||
#include "RenderGraph.hpp"
|
||||
#include "RenderGraphBuilder.hpp"
|
||||
#include "Swapchain.hpp"
|
||||
#include "Window.hpp"
|
||||
|
||||
class GuiRenderer {
|
||||
private:
|
||||
const lft::win::Window* m_window;
|
||||
|
||||
Instance m_instance;
|
||||
|
||||
Surface m_surface;
|
||||
|
||||
Gpu m_gpu;
|
||||
|
||||
Swapchain m_swapchain;
|
||||
|
||||
lft::rg::Builder m_render_graph_builder;
|
||||
lft::rg::RenderGraph m_render_graph;
|
||||
|
||||
lft::rg::RenderGraph init_render_graph();
|
||||
|
||||
public:
|
||||
GuiRenderer(const lft::win::Window* window);
|
||||
|
||||
void render() {
|
||||
// uint32_t imageIdx = 0;
|
||||
// auto result = m_swapchain.get_next_image_idx(
|
||||
// VK_NULL_HANDLE, m_wait_on_image_fence, &imageIdx);
|
||||
|
||||
// m_rendergraph.run(imageIdx, VK_NULL_HANDLE, m_wait_on_image_fence);
|
||||
|
||||
// m_swapchain.present({ m_rendergraph.buffer(0).final_signal(imageIdx) }, imageIdx);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "GuiRenderer.hpp"
|
||||
#include "SDLWindow.h"
|
||||
#include "Window.hpp"
|
||||
#include "runtime/LockStep.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class ServerGuiRuntime {
|
||||
std::unique_ptr<lft::win::Window> m_window;
|
||||
|
||||
std::unique_ptr<GuiRenderer> m_renderer;
|
||||
|
||||
bool m_is_running;
|
||||
|
||||
std::unique_ptr<lft::win::Window> create_window(const std::string& name, VkExtent2D extent) {
|
||||
return std::make_unique<lft::win::SDLWindow>(name, (VkRect2D){
|
||||
0, 0,
|
||||
extent.width, extent.height
|
||||
});
|
||||
}
|
||||
|
||||
public:
|
||||
ServerGuiRuntime() :
|
||||
m_window(create_window("ServerGui", {1024, 1024})),
|
||||
m_is_running(true) {
|
||||
|
||||
}
|
||||
|
||||
void run() {
|
||||
tw::LockStep lock_step(20);
|
||||
|
||||
while(m_is_running) {
|
||||
if(lock_step.wait_for_next_step()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// ImGui_ImplVulkan_NewFrame();
|
||||
// ImGui_ImplSDL2_NewFrame();
|
||||
// ImGui::NewFrame();
|
||||
|
||||
// ImGui::ShowDemoWindow();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
#include "ServerGuiRuntime.hpp"
|
||||
|
||||
int main() {
|
||||
ServerGuiRuntime runtime;
|
||||
runtime.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user