diff --git a/vtkext/private/module/vtkF3DImguiObserver.cxx b/vtkext/private/module/vtkF3DImguiObserver.cxx index 3792c01c20..039e411b8d 100644 --- a/vtkext/private/module/vtkF3DImguiObserver.cxx +++ b/vtkext/private/module/vtkF3DImguiObserver.cxx @@ -8,7 +8,6 @@ namespace { - ImGuiKey GetImGuiKeyFromKeySym(std::string_view keySym) { if (keySym == "Tab") return ImGuiKey_Tab; @@ -126,6 +125,7 @@ namespace } } +//---------------------------------------------------------------------------- vtkStandardNewMacro(vtkF3DImguiObserver); //---------------------------------------------------------------------------- diff --git a/vtkext/private/module/vtkF3DImguiRender.cxx b/vtkext/private/module/vtkF3DImguiRender.cxx index bca41beb58..6e0f7b9fef 100644 --- a/vtkext/private/module/vtkF3DImguiRender.cxx +++ b/vtkext/private/module/vtkF3DImguiRender.cxx @@ -74,6 +74,40 @@ struct vtkF3DImguiRender::Internals } } + void Release(vtkOpenGLRenderWindow* renWin) + { + if (ImGui::GetCurrentContext() != nullptr) + { + ImGuiIO& io = ImGui::GetIO(); + + if (this->FontTexture) + { + io.Fonts->SetTexID(0); + this->FontTexture->ReleaseGraphicsResources(renWin); + this->FontTexture = nullptr; + } + + if (this->VertexBuffer) + { + this->VertexBuffer = nullptr; + } + + if (this->IndexBuffer) + { + this->IndexBuffer = nullptr; + } + + if (this->Program) + { + this->Program->ReleaseGraphicsResources(renWin); + this->Program = nullptr; + } + + io.BackendPlatformName = io.BackendRendererName = nullptr; + ImGui::DestroyContext(); + } + } + void RenderDrawData(vtkOpenGLRenderWindow* renWin, ImDrawData* drawData) { // Avoid rendering when minimized, scale coordinates for retina displays @@ -261,38 +295,7 @@ void vtkF3DImguiRender::Initialize(vtkOpenGLRenderWindow* renWin) void vtkF3DImguiRender::ReleaseGraphicsResources(vtkWindow* w) { - if (ImGui::GetCurrentContext() != nullptr) - { - ImGuiIO& io = ImGui::GetIO(); - - vtkOpenGLRenderWindow* renWin = vtkOpenGLRenderWindow::SafeDownCast(w); - - if (this->Pimpl->FontTexture) - { - io.Fonts->SetTexID(0); - this->Pimpl->FontTexture->ReleaseGraphicsResources(renWin); - this->Pimpl->FontTexture = nullptr; - } - - if (this->Pimpl->VertexBuffer) - { - this->Pimpl->VertexBuffer = nullptr; - } - - if (this->Pimpl->IndexBuffer) - { - this->Pimpl->IndexBuffer = nullptr; - } - - if (this->Pimpl->Program) - { - this->Pimpl->Program->ReleaseGraphicsResources(renWin); - this->Pimpl->Program = nullptr; - } - - io.BackendPlatformName = io.BackendRendererName = nullptr; - ImGui::DestroyContext(); - } + this->Pimpl->Release(vtkOpenGLRenderWindow::SafeDownCast(w)); } //----------------------------------------------------------------------------