From c23f1e51bef07971bdf71653907646f712a989b5 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Fri, 26 Mar 2021 11:30:24 +0100 Subject: [PATCH] Print GPU info into console --- src/engine/client/backend_sdl.cpp | 10 +++++++++ src/engine/client/backend_sdl.h | 25 ++++++++++++++++++++++ src/engine/client/graphics_threaded.cpp | 28 +++++++++++++++++++++++++ src/engine/client/graphics_threaded.h | 8 +++++++ src/engine/graphics.h | 4 ++++ 5 files changed, 75 insertions(+) diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 855366a41..402e7705d 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -3785,6 +3785,13 @@ void CCommandProcessorFragment_SDL::Cmd_Init(const SCommand_Init *pCommand) // check what this context can do const char *pVersionString = (const char *)glGetString(GL_VERSION); dbg_msg("opengl", "Version string: %s", pVersionString); + + const char *pRendererString = (const char *)glGetString(GL_RENDERER); + + str_copy(pCommand->m_pVendorString, pVendorString, gs_GPUInfoStringSize); + str_copy(pCommand->m_pVersionString, pVersionString, gs_GPUInfoStringSize); + str_copy(pCommand->m_pRendererString, pRendererString, gs_GPUInfoStringSize); + // parse version string ParseVersionString(pVersionString, pCommand->m_pCapabilities->m_ContextMajor, pCommand->m_pCapabilities->m_ContextMinor, pCommand->m_pCapabilities->m_ContextPatch); @@ -4614,6 +4621,9 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt CmdSDL.m_GlewPatch = GlewPatch; CmdSDL.m_pInitError = &InitError; CmdSDL.m_pErrStringPtr = &pErrorStr; + CmdSDL.m_pVendorString = m_aVendorString; + CmdSDL.m_pVersionString = m_aVersionString; + CmdSDL.m_pRendererString = m_aRendererString; CmdBuffer.AddCommand(CmdSDL); RunBuffer(&CmdBuffer); WaitForIdle(); diff --git a/src/engine/client/backend_sdl.h b/src/engine/client/backend_sdl.h index a4231018a..50a03af43 100644 --- a/src/engine/client/backend_sdl.h +++ b/src/engine/client/backend_sdl.h @@ -433,6 +433,10 @@ public: int *m_pInitError; + char *m_pVendorString; + char *m_pVersionString; + char *m_pRendererString; + int m_RequestedMajor; int m_RequestedMinor; int m_RequestedPatch; @@ -486,6 +490,8 @@ public: virtual void RunBuffer(CCommandBuffer *pBuffer); }; +static constexpr size_t gs_GPUInfoStringSize = 256; + // graphics backend implemented with SDL and OpenGL class CGraphicsBackend_SDL_OpenGL : public CGraphicsBackend_Threaded { @@ -497,6 +503,10 @@ class CGraphicsBackend_SDL_OpenGL : public CGraphicsBackend_Threaded SBackendCapabilites m_Capabilites; + char m_aVendorString[gs_GPUInfoStringSize] = {}; + char m_aVersionString[gs_GPUInfoStringSize] = {}; + char m_aRendererString[gs_GPUInfoStringSize] = {}; + bool m_UseNewOpenGL; char m_aErrorString[256]; @@ -536,6 +546,21 @@ public: return NULL; } + + virtual const char *GetVendorString() + { + return m_aVendorString; + } + + virtual const char *GetVersionString() + { + return m_aVersionString; + } + + virtual const char *GetRendererString() + { + return m_aRendererString; + } }; #endif // ENGINE_CLIENT_BACKEND_SDL_H diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 94686eaf0..b3b030bed 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -2388,6 +2388,19 @@ int CGraphics_Threaded::Init() 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff}; m_InvalidTexture = LoadTextureRaw(4, 4, CImageInfo::FORMAT_RGBA, s_aNullTextureData, CImageInfo::FORMAT_RGBA, TEXLOAD_NORESAMPLE); + + ColorRGBA GPUInfoPrintColor{0.6f, 0.5f, 1.0f, 1.0f}; + + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "GPU vendor: %s", GetVendorString()); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "gfx", aBuf, GPUInfoPrintColor); + + str_format(aBuf, sizeof(aBuf), "GPU renderer: %s", GetRendererString()); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "gfx", aBuf, GPUInfoPrintColor); + + str_format(aBuf, sizeof(aBuf), "GPU version: %s", GetVersionString()); + m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "gfx", aBuf, GPUInfoPrintColor); + return 0; } @@ -2591,6 +2604,21 @@ SWarning *CGraphics_Threaded::GetCurWarning() } } +const char *CGraphics_Threaded::GetVendorString() +{ + return m_pBackend->GetVendorString(); +} + +const char *CGraphics_Threaded::GetVersionString() +{ + return m_pBackend->GetVersionString(); +} + +const char *CGraphics_Threaded::GetRendererString() +{ + return m_pBackend->GetRendererString(); +} + int CGraphics_Threaded::GetVideoModes(CVideoMode *pModes, int MaxModes, int Screen) { if(g_Config.m_GfxDisplayAllModes) diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 83d4abfe0..33396e6b1 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -675,6 +675,10 @@ public: virtual bool HasQuadContainerBuffering() { return false; } virtual bool Has2DTextureArrays() { return false; } virtual const char *GetErrorString() { return NULL; } + + virtual const char *GetVendorString() = 0; + virtual const char *GetVersionString() = 0; + virtual const char *GetRendererString() = 0; }; class CGraphics_Threaded : public IEngineGraphics @@ -1150,6 +1154,10 @@ public: bool IsTextBufferingEnabled() override { return m_OpenGLTextBufferingEnabled; } bool IsQuadContainerBufferingEnabled() override { return m_OpenGLQuadContainerBufferingEnabled; } bool HasTextureArrays() override { return m_OpenGLHasTextureArrays; } + + const char *GetVendorString() override; + const char *GetVersionString() override; + const char *GetRendererString() override; }; extern IGraphicsBackend *CreateGraphicsBackend(); diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 0838ad6a3..db319417a 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -276,6 +276,10 @@ public: virtual bool IsQuadContainerBufferingEnabled() = 0; virtual bool HasTextureArrays() = 0; + virtual const char *GetVendorString() = 0; + virtual const char *GetVersionString() = 0; + virtual const char *GetRendererString() = 0; + struct CLineItem { float m_X0, m_Y0, m_X1, m_Y1;