MCPcopy Create free account
hub / github.com/ddnet/ddnet / Init

Method Init

src/engine/client/backend_sdl.cpp:1116–1534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1114}
1115
1116int CGraphicsBackend_SDL_GL::Init(const char *pName, int *pScreen, int *pWidth, int *pHeight, int *pRefreshRate, int *pFsaaSamples, int Flags, int *pDesktopWidth, int *pDesktopHeight, int *pCurrentWidth, int *pCurrentHeight, IStorage *pStorage)
1117{
1118#if defined(CONF_HEADLESS_CLIENT)
1119 m_BackendType = BACKEND_TYPE_OPENGL;
1120 g_Config.m_GfxGLMajor = 0;
1121 g_Config.m_GfxGLMinor = 0;
1122 g_Config.m_GfxGLPatch = 0;
1123 int InitError = 0;
1124 int GlewMajor = 0;
1125 int GlewMinor = 0;
1126 int GlewPatch = 0;
1127 *pScreen = 0;
1128 *pWidth = *pDesktopWidth = *pCurrentWidth = 800;
1129 *pHeight = *pDesktopHeight = *pCurrentHeight = 600;
1130 *pRefreshRate = 60;
1131 *pFsaaSamples = 0;
1132 log_info("gfx", "Created headless context");
1133#else
1134 // print sdl version
1135 {
1136 SDL_version Compiled;
1137 SDL_version Linked;
1138
1139 SDL_VERSION(&Compiled);
1140 SDL_GetVersion(&Linked);
1141 log_info("sdl", "SDL version %d.%d.%d (compiled = %d.%d.%d)",
1142 Linked.major, Linked.minor, Linked.patch,
1143 Compiled.major, Compiled.minor, Compiled.patch);
1144
1145#if CONF_PLATFORM_LINUX && SDL_VERSION_ATLEAST(2, 0, 22)
1146 // needed to workaround SDL from forcing exclusively X11 if linking against the GLX flavour of GLEW instead of the EGL one
1147 // w/o this on Wayland systems (no XWayland support) SDL's Video subsystem will fail to load (starting from SDL2.30+)
1148 if(Linked.major == 2 && Linked.minor >= 30)
1149 SDL_SetHint(SDL_HINT_VIDEODRIVER, "x11,wayland");
1150#endif
1151 }
1152
1153 if(!SDL_WasInit(SDL_INIT_VIDEO))
1154 {
1155 if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
1156 {
1157 log_error("gfx", "Unable to initialize SDL video: %s", SDL_GetError());
1158 return EGraphicsBackendErrorCodes::GRAPHICS_BACKEND_ERROR_CODE_SDL_INIT_FAILED;
1159 }
1160 }
1161
1162 EBackendType OldBackendType = m_BackendType;
1163 m_BackendType = DetectBackend();
1164 // little fallback for Vulkan
1165 if(OldBackendType != BACKEND_TYPE_AUTO &&
1166 m_BackendType == BACKEND_TYPE_VULKAN)
1167 {
1168 // try default opengl settings
1169 str_copy(g_Config.m_GfxBackend, "OpenGL");
1170 g_Config.m_GfxGLMajor = 3;
1171 g_Config.m_GfxGLMinor = 0;
1172 g_Config.m_GfxGLPatch = 0;
1173 // do another analysis round too, just in case

Callers

nothing calls this directly

Calls 5

BackendInitGlewFunction · 0.85
IsVersionSupportedGlewFunction · 0.85
AddCommandUnsafeMethod · 0.80
str_copyFunction · 0.50
ResetMethod · 0.45

Tested by

no test coverage detected