diff --git a/src/lang/english.txt b/src/lang/english.txt index f5a56db931..4b138d2195 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1025,6 +1025,8 @@ STR_GAME_OPTIONS_VIDEO_ACCELERATION_RESTART :{WHITE}The sett STR_GAME_OPTIONS_VIDEO_VSYNC :{BLACK}VSync STR_GAME_OPTIONS_VIDEO_VSYNC_TOOLTIP :{BLACK}Check this box to v-sync the screen. A changed setting will only be applied upon game restart. Only works with hardware acceleration enabled +STR_GAME_OPTIONS_VIDEO_DRIVER_INFO :{BLACK}Current driver: {RAW_STRING} + STR_GAME_OPTIONS_GUI_ZOOM_FRAME :{BLACK}Interface size STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_TOOLTIP :{BLACK}Select the interface element size to use diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 3a151c1d4c..bc7eb98595 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -310,6 +310,7 @@ struct GameOptionsWindow : Window { case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name); break; case WID_GO_BASE_MUSIC_DROPDOWN: SetDParamStr(0, BaseMusic::GetUsedSet()->name); break; case WID_GO_BASE_MUSIC_STATUS: SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break; + case WID_GO_VIDEO_DRIVER_INFO: SetDParamStr(0, VideoDriver::GetInstance()->GetInfoString()); break; case WID_GO_REFRESH_RATE_DROPDOWN: SetDParam(0, _settings_client.gui.refresh_rate); break; case WID_GO_RESOLUTION_DROPDOWN: { auto current_resolution = GetCurrentResolutionIndex(); @@ -690,6 +691,9 @@ static const NWidgetPart _nested_game_options_widgets[] = { NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_VIDEO_VSYNC_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_VIDEO_VSYNC_TOOLTIP), EndContainer(), #endif + NWidget(NWID_HORIZONTAL), + NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_VIDEO_DRIVER_INFO), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_VIDEO_DRIVER_INFO, STR_NULL), + EndContainer(), EndContainer(), EndContainer(), EndContainer(), diff --git a/src/video/cocoa/cocoa_ogl.h b/src/video/cocoa/cocoa_ogl.h index fe8490932d..5d616c1472 100644 --- a/src/video/cocoa/cocoa_ogl.h +++ b/src/video/cocoa/cocoa_ogl.h @@ -18,11 +18,12 @@ class VideoDriver_CocoaOpenGL : public VideoDriver_Cocoa { CGLContextObj gl_context; uint8 *anim_buffer; ///< Animation buffer from OpenGL back-end. + std::string driver_info; ///< Information string about selected driver. const char *AllocateContext(bool allow_software); public: - VideoDriver_CocoaOpenGL() : gl_context(nullptr), anim_buffer(nullptr) {} + VideoDriver_CocoaOpenGL() : gl_context(nullptr), anim_buffer(nullptr), driver_info(this->GetName()) {} const char *Start(const StringList ¶m) override; void Stop() override; @@ -41,6 +42,8 @@ public: /** Return driver name */ const char *GetName() const override { return "cocoa-opengl"; } + const char *GetInfoString() const override { return this->driver_info.c_str(); } + void AllocateBackingStore(bool force = false) override; protected: diff --git a/src/video/cocoa/cocoa_ogl.mm b/src/video/cocoa/cocoa_ogl.mm index 96c7fcc540..a5fe9badeb 100644 --- a/src/video/cocoa/cocoa_ogl.mm +++ b/src/video/cocoa/cocoa_ogl.mm @@ -203,6 +203,11 @@ const char *VideoDriver_CocoaOpenGL::Start(const StringList ¶m) return err; } + this->driver_info = GetName(); + this->driver_info += " ("; + this->driver_info += OpenGLBackend::Get()->GetDriverName(); + this->driver_info += ")"; + bool fullscreen = _fullscreen; if (!this->MakeWindow(_cur_resolution.width, _cur_resolution.height)) { this->Stop(); diff --git a/src/video/opengl.cpp b/src/video/opengl.cpp index 8ac12b959a..01ef24c555 100644 --- a/src/video/opengl.cpp +++ b/src/video/opengl.cpp @@ -745,6 +745,16 @@ void OpenGLBackend::PrepareContext() _glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } +std::string OpenGLBackend::GetDriverName() +{ + std::string res{}; + /* Skipping GL_VENDOR as it tends to be "obvious" from the renderer and version data, and just makes the string pointlessly longer */ + res += reinterpret_cast(_glGetString(GL_RENDERER)); + res += ", "; + res += reinterpret_cast(_glGetString(GL_VERSION)); + return res; +} + /** * Check a shader for compilation errors and log them if necessary. * @param shader Shader to check. diff --git a/src/video/opengl.h b/src/video/opengl.h index e5cd749f2e..b1d9080ba7 100644 --- a/src/video/opengl.h +++ b/src/video/opengl.h @@ -92,6 +92,8 @@ public: void PrepareContext(); + std::string GetDriverName(); + void UpdatePalette(const Colour *pal, uint first, uint length); bool Resize(int w, int h, bool force = false); void Paint(); diff --git a/src/video/sdl2_opengl_v.cpp b/src/video/sdl2_opengl_v.cpp index 596a63a28f..7460f34bb5 100644 --- a/src/video/sdl2_opengl_v.cpp +++ b/src/video/sdl2_opengl_v.cpp @@ -64,6 +64,10 @@ const char *VideoDriver_SDL_OpenGL::Start(const StringList ¶m) return error; } + this->driver_info += " ("; + this->driver_info += OpenGLBackend::Get()->GetDriverName(); + this->driver_info += ")"; + /* Now we have a OpenGL context, force a client-size-changed event, * so all buffers are allocated correctly. */ int w, h; diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index 8ef00a00c3..5f6950a8e1 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -540,6 +540,11 @@ const char *VideoDriver_SDL_Base::Start(const StringList ¶m) const char *dname = SDL_GetCurrentVideoDriver(); Debug(driver, 1, "SDL2: using driver '{}'", dname); + this->driver_info = this->GetName(); + this->driver_info += " ("; + this->driver_info += dname; + this->driver_info += ")"; + MarkWholeScreenDirty(); SDL_StopTextInput(); diff --git a/src/video/sdl2_v.h b/src/video/sdl2_v.h index 48c597d4fd..a2298c44e9 100644 --- a/src/video/sdl2_v.h +++ b/src/video/sdl2_v.h @@ -17,7 +17,7 @@ /** The SDL video driver. */ class VideoDriver_SDL_Base : public VideoDriver { public: - VideoDriver_SDL_Base() : sdl_window(nullptr), buffer_locked(false) {} + VideoDriver_SDL_Base() : sdl_window(nullptr), buffer_locked(false), driver_info(this->GetName()) {} const char *Start(const StringList ¶m) override; @@ -43,11 +43,14 @@ public: const char *GetName() const override { return "sdl"; } + const char *GetInfoString() const override { return this->driver_info.c_str(); } + protected: struct SDL_Window *sdl_window; ///< Main SDL window. Palette local_palette; ///< Current palette to use for drawing. bool buffer_locked; ///< Video buffer was locked by the main thread. Rect dirty_rect; ///< Rectangle encompassing the dirty area of the video buffer. + std::string driver_info; ///< Information string about selected driver. Dimension GetScreenSize() const override; void InputLoop() override; diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp index 458c674024..6ef06c45f6 100644 --- a/src/video/video_driver.hpp +++ b/src/video/video_driver.hpp @@ -178,6 +178,11 @@ public: return ZOOM_LVL_OUT_4X; } + virtual const char *GetInfoString() const + { + return this->GetName(); + } + /** * Queue a function to be called on the main thread with game state * lock held and video buffer locked. Queued functions will be diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index 22b8f35412..44368b2249 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -1310,6 +1310,11 @@ const char *VideoDriver_Win32OpenGL::Start(const StringList ¶m) return err; } + this->driver_info = GetName(); + this->driver_info += " ("; + this->driver_info += OpenGLBackend::Get()->GetDriverName(); + this->driver_info += ")"; + this->ClientSizeChanged(this->width, this->height, true); /* We should have a valid screen buffer now. If not, something went wrong and we should abort. */ if (_screen.dst_ptr == nullptr) { diff --git a/src/video/win32_v.h b/src/video/win32_v.h index 4686df7160..c25d5d73ac 100644 --- a/src/video/win32_v.h +++ b/src/video/win32_v.h @@ -117,7 +117,7 @@ public: /** The OpenGL video driver for windows. */ class VideoDriver_Win32OpenGL : public VideoDriver_Win32Base { public: - VideoDriver_Win32OpenGL() : dc(nullptr), gl_rc(nullptr), anim_buffer(nullptr) {} + VideoDriver_Win32OpenGL() : dc(nullptr), gl_rc(nullptr), anim_buffer(nullptr), driver_info(this->GetName()) {} const char *Start(const StringList ¶m) override; @@ -142,10 +142,13 @@ public: const char *GetName() const override { return "win32-opengl"; } + const char *GetInfoString() const override { return this->driver_info.c_str(); } + protected: HDC dc; ///< Window device context. HGLRC gl_rc; ///< OpenGL context. uint8 *anim_buffer; ///< Animation buffer from OpenGL back-end. + std::string driver_info; ///< Information string about selected driver. uint8 GetFullscreenBpp() override { return 32; } // OpenGL is always 32 bpp. diff --git a/src/widgets/settings_widget.h b/src/widgets/settings_widget.h index c897927341..2a83ec657a 100644 --- a/src/widgets/settings_widget.h +++ b/src/widgets/settings_widget.h @@ -37,6 +37,7 @@ enum GameOptionsWidgets { WID_GO_VIDEO_ACCEL_BUTTON, ///< Toggle for video acceleration. WID_GO_VIDEO_VSYNC_BUTTON, ///< Toggle for video vsync. WID_GO_REFRESH_RATE_DROPDOWN, ///< Dropdown for all available refresh rates. + WID_GO_VIDEO_DRIVER_INFO, ///< Label showing details about the current video driver. }; /** Widgets of the #GameSettingsWindow class. */