@@ -21,7 +21,9 @@ namespace Platform {
2121
2222GLResolver::~GLResolver ()
2323{
24- Shutdown ();
24+ // make sure handles are released
25+ m_eglLib.Close ();
26+ m_glLib.Close ();
2527}
2628
2729auto GLResolver::Instance () -> std::shared_ptr<GLResolver>
@@ -62,18 +64,23 @@ auto GLResolver::Initialize(UserResolver resolver, void* userData) -> bool
6264
6365 if (m_userResolver == nullptr )
6466 {
67+ // need to find source for gl functions
68+ // open libs and detect backend
6569 OpenNativeLibraries ();
6670 ResolveProviderFunctions ();
6771 DetectBackend ();
6872 }
6973 else
7074 {
75+ // user resolver was provided
76+ // we *should* be able to get all gl functions from the resolver
77+ // using user resolver + global symbol fallback
7178 m_backend = Backend::UserResolver;
7279 }
7380
7481 if (LoadGlad ())
7582 {
76- // set default if detection failed, but loading succeeded
83+ // set default in case detection failed, but loading succeeded
7784 SetBackendDefault ();
7885
7986 // init SOIL2 gl functions
@@ -181,7 +188,7 @@ void GLResolver::ResolveProviderFunctions()
181188
182189 {
183190 char buf[256 ];
184- std::snprintf (buf, sizeof (buf), " [PlatformGLResolver ] Library handles: egl=%p gl=%p" ,
191+ std::snprintf (buf, sizeof (buf), " [GLResolver ] Library handles: egl=%p gl=%p" ,
185192 reinterpret_cast <void *>(m_eglLib.Handle ()),
186193 reinterpret_cast <void *>(m_glLib.Handle ()));
187194 LOG_DEBUG (buf);
@@ -204,28 +211,28 @@ void GLResolver::DetectBackend()
204211
205212 if (usingEgl)
206213 {
207- LOG_DEBUG (" [PlatformGLResolver ] current context: EGL" );
214+ LOG_DEBUG (" [GLResolver ] current context: EGL" );
208215 m_backend = Backend::EglGles;
209216 return ;
210217 }
211218
212219#ifndef _WIN32
213220 if (usingGlx)
214221 {
215- LOG_DEBUG (" [PlatformGLResolver ] current context: GLX" );
222+ LOG_DEBUG (" [GLResolver ] current context: GLX" );
216223 m_backend = Backend::GlxGl;
217224 return ;
218225 }
219226#else
220227 if (usingWgl)
221228 {
222- LOG_DEBUG (" [PlatformGLResolver ] current context: WGL" );
229+ LOG_DEBUG (" [GLResolver ] current context: WGL" );
223230 m_backend = Backend::WglGl;
224231 return ;
225232 }
226233#endif
227234
228- LOG_DEBUG (" [PlatformGLResolver ] current context: (unknown, will try generic loader)" );
235+ LOG_DEBUG (" [GLResolver ] current context: (unknown, will try generic loader)" );
229236 m_backend = Backend::None;
230237}
231238
@@ -235,11 +242,20 @@ auto GLResolver::GladResolverThunk(const char* name) -> GLapiproc
235242}
236243
237244namespace {
238- // adapt external void* handle to GLAD type
245+
246+ /* *
247+ * Resolves a GL function by name using GladResolverThunk.
248+ * Adapt external void* handle to GLAD type
249+ *
250+ * @param name GL function name.
251+ *
252+ * @return Function pointer as GLADapiproc.
253+ */
239254auto gladBridgeResolverThunk (const char * name) -> GLADapiproc
240255{
241256 return reinterpret_cast <GLADapiproc>(GLResolver::GladResolverThunk (name));
242257}
258+
243259}
244260
245261auto GLResolver::LoadGlad () -> bool
@@ -250,19 +266,19 @@ auto GLResolver::LoadGlad() -> bool
250266 result = gladLoadGL (&gladBridgeResolverThunk);
251267 if (result != 0 )
252268 {
253- LOG_DEBUG (" [PlatformGLResolver ] gladLoadGL() succeeded" );
269+ LOG_DEBUG (" [GLResolver ] gladLoadGL() succeeded" );
254270 return true ;
255271 }
256- LOG_FATAL (" [PlatformGLResolver ] gladLoadGL() failed" );
272+ LOG_FATAL (" [GLResolver ] gladLoadGL() failed" );
257273 return false ;
258274#else
259275 result = gladLoadGLES2 (&gladBridgeResolverThunk);
260276 if (result != 0 )
261277 {
262- LOG_DEBUG (" [PlatformGLResolver ] gladLoadGLES2() succeeded" );
278+ LOG_DEBUG (" [GLResolver ] gladLoadGLES2() succeeded" );
263279 return true ;
264280 }
265- LOG_FATAL (" [PlatformGLResolver ] gladLoadGLES2() failed" );
281+ LOG_FATAL (" [GLResolver ] gladLoadGLES2() failed" );
266282 return false ;
267283#endif
268284}
0 commit comments