mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 07:10:05 +00:00 
			
		
		
		
	Use ImGui Manager to create contexts
This commit is contained in:
		
							parent
							
								
									ee2ec329da
								
							
						
					
					
						commit
						0f8b8d73f9
					
				
					 3 changed files with 37 additions and 80 deletions
				
			
		|  | @ -4,12 +4,6 @@ | |||
| #include <scwx/qt/util/texture_atlas.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <backends/imgui_impl_opengl3.h> | ||||
| #include <backends/imgui_impl_qt.hpp> | ||||
| #include <imgui.h> | ||||
| #include <QOffscreenSurface> | ||||
| #include <QOpenGLContext> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
|  | @ -18,58 +12,21 @@ namespace manager | |||
| { | ||||
| namespace ResourceManager | ||||
| { | ||||
| static const std::string logPrefix_ = "scwx::qt::manager::ResourceManager"; | ||||
| static const std::string logPrefix_ = "scwx::qt::manager::resource_manager"; | ||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| static void InitializeImGui(); | ||||
| static void LoadFonts(); | ||||
| static void LoadTextures(); | ||||
| static void ShutdownImGui(); | ||||
| 
 | ||||
| static std::unique_ptr<QOffscreenSurface> surface_ {}; | ||||
| static ImGuiContext*                      imGuiContext_ {}; | ||||
| 
 | ||||
| void Initialize() | ||||
| { | ||||
|    config::CountyDatabase::Initialize(); | ||||
| 
 | ||||
|    InitializeImGui(); | ||||
|    LoadFonts(); | ||||
|    LoadTextures(); | ||||
| } | ||||
| 
 | ||||
| void Shutdown() | ||||
| { | ||||
|    ShutdownImGui(); | ||||
| } | ||||
| 
 | ||||
| static void InitializeImGui() | ||||
| { | ||||
|    // Create OpenGL Offscreen Surface
 | ||||
|    surface_ = std::make_unique<QOffscreenSurface>(); | ||||
|    surface_->create(); | ||||
|    if (!QOpenGLContext::globalShareContext()->makeCurrent(surface_.get())) | ||||
|    { | ||||
|       logger_->warn("Failed to initialize offscreen surface"); | ||||
|    } | ||||
| 
 | ||||
|    // Initialize ImGui
 | ||||
|    imGuiContext_ = ImGui::CreateContext(); | ||||
|    ImGui_ImplQt_Init(); | ||||
|    ImGui_ImplOpenGL3_Init(); | ||||
|    QOpenGLContext::globalShareContext()->doneCurrent(); | ||||
| 
 | ||||
|    // ImGui Configuration
 | ||||
|    auto& io = ImGui::GetIO(); | ||||
| 
 | ||||
|    // Disable automatic configuration loading/saving
 | ||||
|    io.IniFilename = nullptr; | ||||
| 
 | ||||
|    // Style
 | ||||
|    auto& style = ImGui::GetStyle(); | ||||
| 
 | ||||
|    style.WindowMinSize = {10.0f, 10.0f}; | ||||
| } | ||||
| void Shutdown() {} | ||||
| 
 | ||||
| static void LoadFonts() | ||||
| { | ||||
|  | @ -87,16 +44,6 @@ static void LoadTextures() | |||
|    textureAtlas.BuildAtlas(8, 8); | ||||
| } | ||||
| 
 | ||||
| static void ShutdownImGui() | ||||
| { | ||||
|    QOpenGLContext::globalShareContext()->makeCurrent(surface_.get()); | ||||
|    ImGui::SetCurrentContext(imGuiContext_); | ||||
|    ImGui_ImplOpenGL3_Shutdown(); | ||||
|    ImGui_ImplQt_Shutdown(); | ||||
|    ImGui::DestroyContext(); | ||||
|    QOpenGLContext::globalShareContext()->doneCurrent(); | ||||
| } | ||||
| 
 | ||||
| } // namespace ResourceManager
 | ||||
| } // namespace manager
 | ||||
| } // namespace qt
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat