[Scummvm-git-logs] scummvm master -> 8e07681356b9bdb406132423cf85f7a499eee1eb

sev- noreply at scummvm.org
Fri May 3 18:04:33 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
8e07681356 BACKENDS: Update setImGuiRenderCallback in OSystem


Commit: 8e07681356b9bdb406132423cf85f7a499eee1eb
    https://github.com/scummvm/scummvm/commit/8e07681356b9bdb406132423cf85f7a499eee1eb
Author: scemino (scemino74 at gmail.com)
Date: 2024-05-03T20:04:30+02:00

Commit Message:
BACKENDS: Update setImGuiRenderCallback in OSystem

Changed paths:
    backends/graphics/graphics.h
    backends/graphics/openglsdl/openglsdl-graphics.cpp
    backends/graphics/sdl/sdl-graphics.h
    backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
    backends/graphics3d/openglsdl/openglsdl-graphics3d.h
    backends/modular-backend.cpp
    backends/modular-backend.h
    common/system.h


diff --git a/backends/graphics/graphics.h b/backends/graphics/graphics.h
index 91e57d83b3c..d40642aa77c 100644
--- a/backends/graphics/graphics.h
+++ b/backends/graphics/graphics.h
@@ -49,7 +49,7 @@ public:
 	virtual bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags) { return (mode == 0); }
 	virtual int getGraphicsMode() const { return 0; }
 #if defined(USE_IMGUI)
-	virtual void setImGuiRenderCallback(void(*render)()) { }
+	virtual void setImGuiRenderCallback(ImGuiCallbacks callbacks) { }
 #endif
 	virtual bool setShader(const Common::Path &fileName) { return false; }
 	virtual const OSystem::GraphicsMode *getSupportedStretchModes() const {
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index a27ebde9f5a..3ea5d1048b4 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -306,7 +306,7 @@ void OpenGLSdlGraphicsManager::updateScreen() {
 	}
 
 #if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
-	if (_imGuiRender) {
+	if (_callbacks.render) {
 		_forceRedraw = true;
 	}
 #endif
@@ -465,12 +465,12 @@ void OpenGLSdlGraphicsManager::refreshScreen() {
 #endif
 
 #if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
-	if (_imGuiRender) {
+	if (_callbacks.render) {
 		ImGui_ImplOpenGL3_NewFrame();
 		ImGui_ImplSDL2_NewFrame(_window->getSDLWindow());
 
 		ImGui::NewFrame();
-		_imGuiRender();
+		_callbacks.render();
 		ImGui::Render();
 
 		ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
@@ -556,6 +556,9 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
 		notifyContextDestroy();
 
 #ifdef USE_IMGUI
+		if (_callbacks.cleanup) {
+			_callbacks.cleanup();
+		}
 		ImGui_ImplOpenGL3_Shutdown();
 		ImGui_ImplSDL2_Shutdown();
 		ImGui::DestroyContext();
@@ -618,6 +621,9 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
 	ImGui::StyleColorsDark();
 	ImGuiIO &io = ImGui::GetIO();
 	io.IniFilename = nullptr;
+	if (_callbacks.init) {
+		_callbacks.init();
+	}
 #endif
 
 	if (SDL_GL_SetSwapInterval(_vsync ? 1 : 0)) {
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index 7ecb516c18a..ad693010f9b 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -208,10 +208,10 @@ private:
 
 #if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
 public:
-	void setImGuiRenderCallback(void(*render)()) override { _imGuiRender = render; }
+	void setImGuiRenderCallback(ImGuiCallbacks callbacks) override { _callbacks = callbacks; }
 
 protected:
-	void(*_imGuiRender)() = nullptr;
+	ImGuiCallbacks _callbacks;
 #endif
 
 };
diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
index e0e549266b2..1e30f6f2a76 100644
--- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
+++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
@@ -566,6 +566,10 @@ bool OpenGLSdlGraphics3dManager::createOrUpdateGLContext(uint gameWidth, uint ga
 					ImGui::StyleColorsDark();
 					ImGuiIO &io = ImGui::GetIO();
 					io.IniFilename = nullptr;
+					if (_callbacks.init) {
+						_imguiInitCalled = true;
+						_callbacks.init();
+					}
 #endif
 				}
 			}
@@ -677,12 +681,19 @@ void OpenGLSdlGraphics3dManager::updateScreen() {
 #endif
 
 #if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
-	if (_imGuiRender) {
+	if (_callbacks.render) {
+		if (!_imguiRenderCalled && _callbacks.init) {
+			_imguiRenderCalled = true;
+			if (!_imguiInitCalled) {
+				_imguiInitCalled = true;
+				_callbacks.init();
+			}
+		}
 		ImGui_ImplOpenGL3_NewFrame();
 		ImGui_ImplSDL2_NewFrame(_window->getSDLWindow());
 
 		ImGui::NewFrame();
-		_imGuiRender();
+		_callbacks.render();
 		ImGui::Render();
 
 		ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
@@ -821,6 +832,9 @@ void OpenGLSdlGraphics3dManager::showSystemMouseCursor(bool visible) {
 void OpenGLSdlGraphics3dManager::deinitializeRenderer() {
 #ifdef USE_IMGUI
 	if (_glContext) {
+		if (_callbacks.cleanup) {
+			_callbacks.cleanup();
+		}
 		ImGui_ImplOpenGL3_Shutdown();
 		ImGui_ImplSDL2_Shutdown();
 		ImGui::DestroyContext();
diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.h b/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
index 7c633fbef75..3a0add14248 100644
--- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
+++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
@@ -120,6 +120,11 @@ protected:
 	int _glContextProfileMask, _glContextMajor, _glContextMinor;
 	SDL_GLContext _glContext;
 	void deinitializeRenderer();
+
+#if defined(USE_IMGUI)
+	bool _imguiInitCalled = false;
+	bool _imguiRenderCalled = false;
+#endif
 #endif
 
 	OpenGL::ContextType _glContextType;
diff --git a/backends/modular-backend.cpp b/backends/modular-backend.cpp
index dfbe88b44e4..d4397f655e4 100644
--- a/backends/modular-backend.cpp
+++ b/backends/modular-backend.cpp
@@ -74,8 +74,8 @@ int ModularGraphicsBackend::getGraphicsMode() const {
 }
 
 #if defined(USE_IMGUI)
-void ModularGraphicsBackend::setImGuiRenderCallback(void(*render)()) {
-	_graphicsManager->setImGuiRenderCallback(render);
+void ModularGraphicsBackend::setImGuiRenderCallback(ImGuiCallbacks callbacks) {
+	_graphicsManager->setImGuiRenderCallback(callbacks);
 }
 #endif
 
diff --git a/backends/modular-backend.h b/backends/modular-backend.h
index 033759d6347..fedf4b35d5f 100644
--- a/backends/modular-backend.h
+++ b/backends/modular-backend.h
@@ -68,7 +68,7 @@ public:
 	bool setGraphicsMode(int mode, uint flags = kGfxModeNoFlags) override;
 	int getGraphicsMode() const override;
 #if defined(USE_IMGUI)
-	void setImGuiRenderCallback(void(*render)()) override final;
+	void setImGuiRenderCallback(ImGuiCallbacks callbacks) override final;
 #endif
 	bool setShader(const Common::Path &name) override final;
 	const GraphicsMode *getSupportedStretchModes() const override final;
diff --git a/common/system.h b/common/system.h
index f67e056d649..3c6f7221cf0 100644
--- a/common/system.h
+++ b/common/system.h
@@ -148,6 +148,14 @@ enum CursorMaskValue {
 	kCursorMaskPaletteXorColorXnor = 3,
 };
 
+#if defined(USE_IMGUI)
+typedef struct ImGuiCallbacks {
+	void (*init)() = nullptr;
+	void (*render)() = nullptr;
+	void (*cleanup)() = nullptr;
+} ImGuiCallbacks;
+#endif
+
 /**
  * Interface for ScummVM backends.
  *
@@ -915,7 +923,7 @@ public:
 	 *
 	 * @param render The function pointer called while rendering on screen
 	 */
-	virtual void setImGuiRenderCallback(void(*render)()) { }
+	virtual void setImGuiRenderCallback(ImGuiCallbacks callbacks) { }
 #endif
 
 	/**




More information about the Scummvm-git-logs mailing list