Archived
1
Fork 0

Re-enable multiviewport

Also fixes a bunch of stuff to make multiviewport way more stable
This commit is contained in:
redstrate 2021-02-17 01:09:12 -05:00
parent f3f6a219f6
commit 77c9561868
5 changed files with 28 additions and 18 deletions

View file

@ -76,6 +76,8 @@ public:
@param index The index of the window to begin rendering for. @param index The index of the window to begin rendering for.
*/ */
void render(const int index); void render(const int index);
void end_frame();
/// Pause updating. /// Pause updating.
void pause(); void pause();
@ -344,12 +346,12 @@ private:
RenderTarget* render_target; RenderTarget* render_target;
}; };
std::vector<Window> _windows; std::vector<std::unique_ptr<Window>> _windows;
Window* get_window(const int identifier) { Window* get_window(const int identifier) {
for(auto& window : _windows) { for(auto& window : _windows) {
if(window.identifier == identifier) if(window->identifier == identifier)
return &window; return window.get();
} }
return nullptr; return nullptr;

View file

@ -84,11 +84,11 @@ bool Engine::is_paused() const {
} }
void Engine::quit() { void Engine::quit() {
_windows[0].quitRequested = true; _windows[0]->quitRequested = true;
} }
bool Engine::is_quitting() const { bool Engine::is_quitting() const {
return _windows[0].quitRequested; return _windows[0]->quitRequested;
} }
void Engine::prepare_quit() { void Engine::prepare_quit() {
@ -193,7 +193,7 @@ ui::Screen* Engine::load_screen(const file::Path path) {
void Engine::set_screen(ui::Screen* screen) { void Engine::set_screen(ui::Screen* screen) {
_current_screen = screen; _current_screen = screen;
screen->extent = _windows[0].extent; screen->extent = _windows[0]->extent;
screen->calculate_sizes(); screen->calculate_sizes();
get_renderer()->set_screen(screen); get_renderer()->set_screen(screen);
@ -414,10 +414,12 @@ void Engine::add_window(void* native_handle, const int identifier, const prism::
_gfx->initialize_view(native_handle, identifier, drawable_extent.width, drawable_extent.height); _gfx->initialize_view(native_handle, identifier, drawable_extent.width, drawable_extent.height);
Window& window = _windows.emplace_back(); _windows.push_back(std::move(std::make_unique<Window>()));
window.identifier = identifier;
window.extent = extent; Window* window = _windows.back().get();
window.render_target = _renderer->allocate_render_target(drawable_extent); window->identifier = identifier;
window->extent = extent;
window->render_target = _renderer->allocate_render_target(drawable_extent);
render_ready = true; render_ready = true;
} }
@ -425,8 +427,8 @@ void Engine::add_window(void* native_handle, const int identifier, const prism::
void Engine::remove_window(const int identifier) { void Engine::remove_window(const int identifier) {
Expects(identifier >= 0); Expects(identifier >= 0);
utility::erase_if(_windows, [identifier](Window& w) { utility::erase_if(_windows, [identifier](std::unique_ptr<Window>& w) {
return w.identifier == identifier; return w->identifier == identifier;
}); });
} }
@ -658,6 +660,10 @@ void Engine::begin_frame(const float delta_time) {
_app->begin_frame(); _app->begin_frame();
} }
void Engine::end_frame() {
ImGui::UpdatePlatformWindows();
}
int frame_delay = 0; int frame_delay = 0;
const int frame_delay_between_resolution_change = 60; const int frame_delay_between_resolution_change = 60;

View file

@ -41,8 +41,8 @@ ImGuiLayer::ImGuiLayer() {
io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports;
io.BackendPlatformName = "Prism"; io.BackendPlatformName = "Prism";
//if(platform::supports_feature(PlatformFeature::Windowing)) if(platform::supports_feature(PlatformFeature::Windowing))
// io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
for (auto& [im, pl] : imToPl) for (auto& [im, pl] : imToPl)
io.KeyMap[im] = platform::get_keycode(pl); io.KeyMap[im] = platform::get_keycode(pl);
@ -196,8 +196,6 @@ void ImGuiLayer::render(int index) {
if(index == 0) { if(index == 0) {
ImGui::EndFrame(); ImGui::EndFrame();
ImGui::Render(); ImGui::Render();
ImGui::UpdatePlatformWindows();
} }
} }

View file

@ -75,9 +75,11 @@ void ImGuiPass::render_post(GFXCommandBuffer* command_buffer, const int index) {
} else { } else {
auto& io = ImGui::GetPlatformIO(); auto& io = ImGui::GetPlatformIO();
for(int i = 1; i < io.Viewports.size(); i++) { for(int i = 1; i < io.Viewports.size(); i++) {
if((io.Viewports[i]->Flags & ImGuiViewportFlags_Minimized) == 0) if((io.Viewports[i]->Flags & ImGuiViewportFlags_Minimized) == 0) {
if(*(int*)io.Viewports[i]->PlatformHandle == index) auto platform_handle = (int*)io.Viewports[i]->PlatformHandle;
if(platform_handle != nullptr && *platform_handle == index)
draw_data = io.Viewports[i]->DrawData; draw_data = io.Viewports[i]->DrawData;
}
} }
} }

View file

@ -615,6 +615,8 @@ int main(int argc, char* argv[]) {
if(window != nullptr) if(window != nullptr)
[window->delegate render]; [window->delegate render];
} }
engine->end_frame();
scrollX = 0.0f; scrollX = 0.0f;
scrollY = 0.0f; scrollY = 0.0f;