[Scummvm-git-logs] scummvm master -> 17a1b37dda658e0cff86434592b09f765a2ebf47
lephilousophe
noreply at scummvm.org
Sun Jun 30 13:57:39 UTC 2024
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
81196ec6c6 OPENGL: Don't use glBlendColor when it's not available
2587fa53c3 DIRECTOR: Don't free the font which will be freed by ImGui on destroy
17a1b37dda BACKENDS: SDL: Refactor ImGui processing
Commit: 81196ec6c6b29a16fd303750b68af4b1e84de1f1
https://github.com/scummvm/scummvm/commit/81196ec6c6b29a16fd303750b68af4b1e84de1f1
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-06-30T15:57:03+02:00
Commit Message:
OPENGL: Don't use glBlendColor when it's not available
Bare Windows XP only has OpenGL 1.1 implementation where the function
is not here.
Fallback on no blending at all: this is like it was before.
Changed paths:
backends/graphics/opengl/framebuffer.cpp
diff --git a/backends/graphics/opengl/framebuffer.cpp b/backends/graphics/opengl/framebuffer.cpp
index d6b69079f76..3b2b3efe04d 100644
--- a/backends/graphics/opengl/framebuffer.cpp
+++ b/backends/graphics/opengl/framebuffer.cpp
@@ -112,6 +112,11 @@ void Framebuffer::applyBlendState() {
GL_CALL(glDisable(GL_BLEND));
break;
case kBlendModeOpaque:
+ if (!glBlendColor) {
+ // If glBlendColor is not available (old OpenGL) fallback on disabling blending
+ GL_CALL(glDisable(GL_BLEND));
+ break;
+ }
GL_CALL(glEnable(GL_BLEND));
GL_CALL(glBlendColor(1.f, 1.f, 1.f, 0.f));
GL_CALL(glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR));
Commit: 2587fa53c34ad06888181ca9f87fb1f0f1e72719
https://github.com/scummvm/scummvm/commit/2587fa53c34ad06888181ca9f87fb1f0f1e72719
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-06-30T15:57:03+02:00
Commit Message:
DIRECTOR: Don't free the font which will be freed by ImGui on destroy
Changed paths:
engines/director/debugger/debugtools.cpp
diff --git a/engines/director/debugger/debugtools.cpp b/engines/director/debugger/debugtools.cpp
index 744c1816693..dc0e2bda939 100644
--- a/engines/director/debugger/debugtools.cpp
+++ b/engines/director/debugger/debugtools.cpp
@@ -441,7 +441,6 @@ void onImGuiRender() {
void onImGuiCleanup() {
Common::setLogWatcher(nullptr);
if (_state) {
- delete _state->_tinyFont;
free(_state->_archive.data);
delete _state->_logger;
Commit: 17a1b37dda658e0cff86434592b09f765a2ebf47
https://github.com/scummvm/scummvm/commit/17a1b37dda658e0cff86434592b09f765a2ebf47
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-06-30T15:57:03+02:00
Commit Message:
BACKENDS: SDL: Refactor ImGui processing
This unifies the ImGui processing for both 2D and 3D engine.
This also make sure we don't destroy ImGui if init failed (like on older
OpenGL).
The destroy callback is also called whenever we destroy the context.
Changed paths:
backends/graphics/openglsdl/openglsdl-graphics.cpp
backends/graphics/sdl/sdl-graphics.cpp
backends/graphics/sdl/sdl-graphics.h
backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
backends/graphics3d/openglsdl/openglsdl-graphics3d.h
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index 4036d4e9816..bdf4a22f593 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -34,11 +34,6 @@
#include "common/translation.h"
#endif
-#ifdef USE_IMGUI
-#include "backends/imgui/backends/imgui_impl_sdl2.h"
-#include "backends/imgui/backends/imgui_impl_opengl3.h"
-#endif
-
OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(SdlEventSource *eventSource, SdlWindow *window)
: SdlGraphicsManager(eventSource, window), _lastRequestedHeight(0),
#if SDL_VERSION_ATLEAST(2, 0, 0)
@@ -198,11 +193,7 @@ OpenGLSdlGraphicsManager::~OpenGLSdlGraphicsManager() {
#if SDL_VERSION_ATLEAST(2, 0, 0)
#ifdef USE_IMGUI
- if (_glContext) {
- ImGui_ImplOpenGL3_Shutdown();
- ImGui_ImplSDL2_Shutdown();
- ImGui::DestroyContext();
- }
+ destroyImGui();
#endif
notifyContextDestroy();
@@ -306,7 +297,7 @@ void OpenGLSdlGraphicsManager::updateScreen() {
}
#if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
- if (_callbacks.render) {
+ if (_imGuiCallbacks.render) {
_forceRedraw = true;
}
#endif
@@ -465,21 +456,7 @@ void OpenGLSdlGraphicsManager::refreshScreen() {
#endif
#if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
- if (_callbacks.render) {
- ImGui_ImplOpenGL3_NewFrame();
- ImGui_ImplSDL2_NewFrame();
-
- ImGui::NewFrame();
- _callbacks.render();
- ImGui::Render();
- ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
-
- SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow();
- SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext();
- ImGui::UpdatePlatformWindows();
- ImGui::RenderPlatformWindowsDefault();
- SDL_GL_MakeCurrent(backup_current_window, backup_current_context);
- }
+ renderImGui();
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
@@ -561,12 +538,7 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
notifyContextDestroy();
#ifdef USE_IMGUI
- if (_callbacks.cleanup) {
- _callbacks.cleanup();
- }
- ImGui_ImplOpenGL3_Shutdown();
- ImGui_ImplSDL2_Shutdown();
- ImGui::DestroyContext();
+ destroyImGui();
#endif
SDL_GL_DeleteContext(_glContext);
@@ -619,23 +591,7 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
#ifdef USE_IMGUI
// Setup Dear ImGui
- IMGUI_CHECKVERSION();
- ImGui::CreateContext();
- ImGuiIO &io = ImGui::GetIO();
- io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
- io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
- ImGui::StyleColorsDark();
- // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
- ImGuiStyle& style = ImGui::GetStyle();
- style.WindowRounding = 0.0f;
- style.Colors[ImGuiCol_WindowBg].w = 1.0f;
- io.IniFilename = nullptr;
- ImGui_ImplSDL2_InitForOpenGL(_window->getSDLWindow(), _glContext);
- ImGui_ImplOpenGL3_Init("#version 110");
-
- if (_callbacks.init) {
- _callbacks.init();
- }
+ initImGui(_glContext);
#endif
if (SDL_GL_SetSwapInterval(_vsync ? 1 : 0)) {
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index e6026e941b6..2d23b7f9138 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -37,6 +37,12 @@
#ifdef EMSCRIPTEN
#include "backends/platform/sdl/emscripten/emscripten.h"
#endif
+
+#if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
+#include "backends/imgui/backends/imgui_impl_sdl2.h"
+#include "backends/imgui/backends/imgui_impl_opengl3.h"
+#endif
+
SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source, SdlWindow *window)
: _eventSource(source), _window(window), _hwScreen(nullptr)
#if SDL_VERSION_ATLEAST(2, 0, 0)
@@ -501,3 +507,89 @@ Common::Keymap *SdlGraphicsManager::getKeymap() {
return keymap;
}
+
+#if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
+void SdlGraphicsManager::initImGui(void *glContext) {
+ assert(!_imGuiReady);
+ _imGuiInited = false;
+
+ if (!glContext) {
+ return;
+ }
+
+ IMGUI_CHECKVERSION();
+ if (!ImGui::CreateContext()) {
+ return;
+ }
+ ImGuiIO &io = ImGui::GetIO();
+ io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
+ io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
+ ImGui::StyleColorsDark();
+ // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
+ ImGuiStyle& style = ImGui::GetStyle();
+ style.WindowRounding = 0.0f;
+ style.Colors[ImGuiCol_WindowBg].w = 1.0f;
+ io.IniFilename = nullptr;
+ if (!ImGui_ImplSDL2_InitForOpenGL(_window->getSDLWindow(), glContext)) {
+ ImGui::DestroyContext();
+ return;
+ }
+
+ if (!ImGui_ImplOpenGL3_Init("#version 110")) {
+ ImGui_ImplSDL2_Shutdown();
+ ImGui::DestroyContext();
+ return;
+ }
+
+ _imGuiReady = true;
+
+ if (_imGuiCallbacks.init) {
+ _imGuiCallbacks.init();
+ _imGuiInited = true;
+ }
+}
+
+void SdlGraphicsManager::renderImGui() {
+ if (!_imGuiReady || !_imGuiCallbacks.render) {
+ return;
+ }
+
+ if (!_imGuiInited) {
+ if (_imGuiCallbacks.init) {
+ _imGuiCallbacks.init();
+ }
+ _imGuiInited = true;
+ }
+
+ ImGui_ImplOpenGL3_NewFrame();
+ ImGui_ImplSDL2_NewFrame();
+
+ ImGui::NewFrame();
+ _imGuiCallbacks.render();
+ ImGui::Render();
+ ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
+
+ SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow();
+ SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext();
+ ImGui::UpdatePlatformWindows();
+ ImGui::RenderPlatformWindowsDefault();
+ SDL_GL_MakeCurrent(backup_current_window, backup_current_context);
+}
+
+void SdlGraphicsManager::destroyImGui() {
+ if (!_imGuiReady) {
+ return;
+ }
+
+ if (_imGuiCallbacks.cleanup) {
+ _imGuiCallbacks.cleanup();
+ }
+
+ _imGuiInited = false;
+ _imGuiReady = false;
+
+ ImGui_ImplOpenGL3_Shutdown();
+ ImGui_ImplSDL2_Shutdown();
+ ImGui::DestroyContext();
+}
+#endif
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index e38daca739e..6774a96830d 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -208,10 +208,16 @@ private:
#if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
public:
- void setImGuiCallbacks(const ImGuiCallbacks &callbacks) override { _callbacks = callbacks; }
+ void setImGuiCallbacks(const ImGuiCallbacks &callbacks) override { _imGuiCallbacks = callbacks; }
protected:
- ImGuiCallbacks _callbacks;
+ ImGuiCallbacks _imGuiCallbacks;
+ bool _imGuiReady = false;
+ bool _imGuiInited = false;
+
+ void initImGui(void *glContext);
+ void renderImGui();
+ void destroyImGui();
#endif
};
diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
index 4a9a41cf10c..284ab28d06b 100644
--- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
+++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
@@ -46,11 +46,6 @@
#include "image/bmp.h"
#endif
-#ifdef USE_IMGUI
-#include "backends/imgui/backends/imgui_impl_sdl2.h"
-#include "backends/imgui/backends/imgui_impl_opengl3.h"
-#endif
-
OpenGLSdlGraphics3dManager::OpenGLSdlGraphics3dManager(SdlEventSource *eventSource, SdlWindow *window, bool supportsFrameBuffer)
: SdlGraphicsManager(eventSource, window),
#if SDL_VERSION_ATLEAST(2, 0, 0)
@@ -559,17 +554,7 @@ bool OpenGLSdlGraphics3dManager::createOrUpdateGLContext(uint gameWidth, uint ga
#ifdef USE_IMGUI
// Setup Dear ImGui
- IMGUI_CHECKVERSION();
- ImGui::CreateContext();
- ImGui_ImplSDL2_InitForOpenGL(_window->getSDLWindow(), _glContext);
- ImGui_ImplOpenGL3_Init("#version 110");
- ImGui::StyleColorsDark();
- ImGuiIO &io = ImGui::GetIO();
- io.IniFilename = nullptr;
- if (_callbacks.init) {
- _imguiInitCalled = true;
- _callbacks.init();
- }
+ initImGui(_glContext);
#endif
}
}
@@ -681,23 +666,7 @@ void OpenGLSdlGraphics3dManager::updateScreen() {
#endif
#if defined(USE_IMGUI) && SDL_VERSION_ATLEAST(2, 0, 0)
- if (_callbacks.render) {
- if (!_imguiRenderCalled && _callbacks.init) {
- _imguiRenderCalled = true;
- if (!_imguiInitCalled) {
- _imguiInitCalled = true;
- _callbacks.init();
- }
- }
- ImGui_ImplOpenGL3_NewFrame();
- ImGui_ImplSDL2_NewFrame();
-
- ImGui::NewFrame();
- _callbacks.render();
- ImGui::Render();
-
- ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
- }
+ renderImGui();
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
@@ -831,14 +800,7 @@ void OpenGLSdlGraphics3dManager::showSystemMouseCursor(bool visible) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
void OpenGLSdlGraphics3dManager::deinitializeRenderer() {
#ifdef USE_IMGUI
- if (_glContext) {
- if (_callbacks.cleanup) {
- _callbacks.cleanup();
- }
- ImGui_ImplOpenGL3_Shutdown();
- ImGui_ImplSDL2_Shutdown();
- ImGui::DestroyContext();
- }
+ destroyImGui();
#endif
SDL_GL_DeleteContext(_glContext);
diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.h b/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
index 3a0add14248..7c633fbef75 100644
--- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
+++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
@@ -120,11 +120,6 @@ 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;
More information about the Scummvm-git-logs
mailing list