Commit 003d491f86a2e9cd14185eebf645d573c7a198be

Sam Lantinga 2017-08-27T19:05:57

Fixed bug 3724 - Allow Angle Static Link Carlos We would like to add a switch (define) that allows us to compile Angle statically with SDL. That is, getting rid of the OpenGL DLL. Usually you need OpenGL to be loaded dynamically as DLL because implementation is provided by the system but no need with Angle. Only 2 files need modification and it shouldn't affect current behaivor: include/SDL_egl.h and src/video/SDL_egl.c, as in here https://github.com/native-toolkit/sdl/pull/10/files The flag name could be SDL_VIDEO_STATIC_ANGLE (instead of NATIVE_TOOLKIT_STATIC_ANGLE) as discussed here https://github.com/native-toolkit/sdl/pull/10 We have tested this with both Windows and UWP, using NME engine (https://github.com/haxenme/nme). Releated issue: https://bugzilla.libsdl.org/show_bug.cgi?id=1820

diff --git a/include/SDL_egl.h b/include/SDL_egl.h
index 65c110c..e47fbe8 100644
--- a/include/SDL_egl.h
+++ b/include/SDL_egl.h
@@ -132,7 +132,7 @@
 *-------------------------------------------------------------------------
 * This precedes the return type of the function in the function prototype.
 */
-#if defined(_WIN32) && !defined(__SCITECH_SNAP__)
+#if defined(_WIN32) && !defined(__SCITECH_SNAP__) && !defined(SDL_VIDEO_STATIC_ANGLE)
 #   define KHRONOS_APICALL __declspec(dllimport)
 #elif defined (__SYMBIAN32__)
 #   define KHRONOS_APICALL IMPORT_C
diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index 1e0aacf..24ad00a 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -72,12 +72,17 @@
 #define DEFAULT_OGL_ES "libGLESv1_CM.so.1"
 #endif /* SDL_VIDEO_DRIVER_RPI */
 
+#ifdef SDL_VIDEO_STATIC_ANGLE
+#define LOAD_FUNC(NAME) \
+_this->egl_data->NAME = (void *)NAME;
+#else
 #define LOAD_FUNC(NAME) \
 _this->egl_data->NAME = SDL_LoadFunction(_this->egl_data->dll_handle, #NAME); \
 if (!_this->egl_data->NAME) \
 { \
     return SDL_SetError("Could not retrieve EGL function " #NAME); \
 }
+#endif
 
 static const char * SDL_EGL_GetErrorName(EGLint eglErrorCode)
 {
@@ -275,6 +280,7 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
     }
 #endif
 
+#ifndef SDL_VIDEO_STATIC_ANGLE
     /* A funny thing, loading EGL.so first does not work on the Raspberry, so we load libGL* first */
     path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
     if (path != NULL) {
@@ -330,6 +336,7 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
         }
         SDL_ClearError();
     }
+#endif
 
     _this->egl_data->dll_handle = dll_handle;