Loading gfx/src/renderer.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -56,12 +56,13 @@ void Renderer::release() { } void Renderer::clear_render_buffers(bool using_deferred) { if (using_deferred) { // m_g_buffer used to render viewport to a texture first // if (using_deferred) { GL_ASSUME_SUCCESS(glBindFramebuffer(GL_FRAMEBUFFER, m_g_buffer)); GL_ASSUME_SUCCESS(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); GL_ASSUME_SUCCESS(glClearDepth(1.0)); GL_ASSUME_SUCCESS(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); } // } GL_ASSUME_SUCCESS(glBindFramebuffer(GL_FRAMEBUFFER, 0)); Loading Loading @@ -98,13 +99,17 @@ void Renderer::present_collection(com::Folder *const collection, pipeline p) { return; // silence linter } GL_ASSUME_SUCCESS(glBindFramebuffer(GL_FRAMEBUFFER, framebuffer)); // render viewport to texture GL_ASSUME_SUCCESS(glBindFramebuffer(GL_FRAMEBUFFER, m_g_buffer)); GL_ASSUME_SUCCESS(glEnable(GL_DEPTH_TEST)); if (p == TRANSPARENT) present_collection_transparent(collection, common); else present_collection(collection, common); // change back to default framebuffer GL_ASSUME_SUCCESS(glBindFramebuffer(GL_FRAMEBUFFER, 0)); } void Renderer::lighting_pass(const std::vector<const com::Folder *> &lights, ShaderGraph::lighting_model lm) const { Loading osi/include/osi/gui_callbacks.hpp 0 → 100644 +40 −0 Original line number Diff line number Diff line #pragma once #include <SDL2/SDL.h> #include <com/context.hpp> #include <functional> namespace osi { namespace gui { struct GuiCallbacks { std::function<void(SDL_Window*, void*, com::Folder*)> init; std::function<void(const SDL_Event*)> process_event; std::function<void()> render; std::function<void()> shutdown; }; // Global callbacks that will be set by external modules extern GuiCallbacks gui_callbacks; // Wrapper functions that will be called from osi inline void init(SDL_Window* window, void* sdl_gl_context, com::Folder* root_folder) { if (gui_callbacks.init) gui_callbacks.init(window, sdl_gl_context, root_folder); } inline void process_event(const SDL_Event* event) { if (gui_callbacks.process_event) gui_callbacks.process_event(event); } inline void render() { if (gui_callbacks.render) gui_callbacks.render(); } inline void shutdown() { if (gui_callbacks.shutdown) gui_callbacks.shutdown(); } } // namespace gui } // namespace osi No newline at end of file osi/src/run.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ #include <stdexcept> #include <utils/timeprof.hpp> #include <cctype> #include <osi/gui_callbacks.hpp> namespace osi { Loading Loading @@ -134,6 +135,9 @@ static void start(Config const& cfg) if (!cfg.icon_relative_path.empty() && lfs::loader() != nullptr) SDL_SetWindowIcon(window_ptr, png_bytes_to_sdl_surface(lfs::loader()->load_now(cfg.icon_relative_path)->data())); // Setup GUI context gui::init(window_ptr, gl_context_ptr, detail::get_root_folder()); } static void finish() Loading @@ -147,6 +151,9 @@ static void finish() try { root_folder_ptr = nullptr; } catch (...) {} // GUI cleanup gui::shutdown(); if (gl_context_ptr != nullptr) { SDL_GL_DeleteContext(gl_context_ptr); Loading Loading @@ -231,6 +238,8 @@ void run(Config const& cfg) SDL_Event event; while (SDL_PollEvent(&event)) { gui::process_event(&event); switch (event.type) { case SDL_QUIT: Loading Loading @@ -364,6 +373,8 @@ void run(Config const& cfg) timer->m_passed_seconds += (double)timer->m_time_step; timer->m_time_step = 0.0f; gui::render(); SDL_GL_SwapWindow(window_ptr); } } Loading Loading
gfx/src/renderer.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -56,12 +56,13 @@ void Renderer::release() { } void Renderer::clear_render_buffers(bool using_deferred) { if (using_deferred) { // m_g_buffer used to render viewport to a texture first // if (using_deferred) { GL_ASSUME_SUCCESS(glBindFramebuffer(GL_FRAMEBUFFER, m_g_buffer)); GL_ASSUME_SUCCESS(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); GL_ASSUME_SUCCESS(glClearDepth(1.0)); GL_ASSUME_SUCCESS(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); } // } GL_ASSUME_SUCCESS(glBindFramebuffer(GL_FRAMEBUFFER, 0)); Loading Loading @@ -98,13 +99,17 @@ void Renderer::present_collection(com::Folder *const collection, pipeline p) { return; // silence linter } GL_ASSUME_SUCCESS(glBindFramebuffer(GL_FRAMEBUFFER, framebuffer)); // render viewport to texture GL_ASSUME_SUCCESS(glBindFramebuffer(GL_FRAMEBUFFER, m_g_buffer)); GL_ASSUME_SUCCESS(glEnable(GL_DEPTH_TEST)); if (p == TRANSPARENT) present_collection_transparent(collection, common); else present_collection(collection, common); // change back to default framebuffer GL_ASSUME_SUCCESS(glBindFramebuffer(GL_FRAMEBUFFER, 0)); } void Renderer::lighting_pass(const std::vector<const com::Folder *> &lights, ShaderGraph::lighting_model lm) const { Loading
osi/include/osi/gui_callbacks.hpp 0 → 100644 +40 −0 Original line number Diff line number Diff line #pragma once #include <SDL2/SDL.h> #include <com/context.hpp> #include <functional> namespace osi { namespace gui { struct GuiCallbacks { std::function<void(SDL_Window*, void*, com::Folder*)> init; std::function<void(const SDL_Event*)> process_event; std::function<void()> render; std::function<void()> shutdown; }; // Global callbacks that will be set by external modules extern GuiCallbacks gui_callbacks; // Wrapper functions that will be called from osi inline void init(SDL_Window* window, void* sdl_gl_context, com::Folder* root_folder) { if (gui_callbacks.init) gui_callbacks.init(window, sdl_gl_context, root_folder); } inline void process_event(const SDL_Event* event) { if (gui_callbacks.process_event) gui_callbacks.process_event(event); } inline void render() { if (gui_callbacks.render) gui_callbacks.render(); } inline void shutdown() { if (gui_callbacks.shutdown) gui_callbacks.shutdown(); } } // namespace gui } // namespace osi No newline at end of file
osi/src/run.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ #include <stdexcept> #include <utils/timeprof.hpp> #include <cctype> #include <osi/gui_callbacks.hpp> namespace osi { Loading Loading @@ -134,6 +135,9 @@ static void start(Config const& cfg) if (!cfg.icon_relative_path.empty() && lfs::loader() != nullptr) SDL_SetWindowIcon(window_ptr, png_bytes_to_sdl_surface(lfs::loader()->load_now(cfg.icon_relative_path)->data())); // Setup GUI context gui::init(window_ptr, gl_context_ptr, detail::get_root_folder()); } static void finish() Loading @@ -147,6 +151,9 @@ static void finish() try { root_folder_ptr = nullptr; } catch (...) {} // GUI cleanup gui::shutdown(); if (gl_context_ptr != nullptr) { SDL_GL_DeleteContext(gl_context_ptr); Loading Loading @@ -231,6 +238,8 @@ void run(Config const& cfg) SDL_Event event; while (SDL_PollEvent(&event)) { gui::process_event(&event); switch (event.type) { case SDL_QUIT: Loading Loading @@ -364,6 +373,8 @@ void run(Config const& cfg) timer->m_passed_seconds += (double)timer->m_time_step; timer->m_time_step = 0.0f; gui::render(); SDL_GL_SwapWindow(window_ptr); } } Loading