3745: Print GPU info into console r=def- a=Jupeyy


![screenshot_2021-03-26_11-38-30](https://user-images.githubusercontent.com/6654924/112619605-d1d1fa00-8e27-11eb-93e5-94f7bddb6e49.png)


## Checklist

- [x] Tested the change ingame
- [x] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
bors[bot] 2021-03-26 10:56:21 +00:00 committed by GitHub
commit aed9ee268f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 0 deletions

View file

@ -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();

View file

@ -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

View file

@ -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)

View file

@ -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();

View file

@ -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;