Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef SDL_VIDEO_OPENGL_ES
- /*
- * A macro for loading a function pointer with dlsym
- */
- #define LOAD_FUNC(NAME) \
- *((void**)&this->gles_data->NAME) = dlsym(handle, #NAME); \
- if (!this->gles_data->NAME) \
- { \
- SDL_SetError("Could not retrieve EGL function " #NAME); \
- return -1; \
- }
- /* Passing a NULL path means load pointers from the application */
- int X11_GLES_LoadLibrary(_THIS, const char* path)
- {
- void* handle;
- int dlopen_flags;
- if ( this->gles_data->egl_active ) {
- SDL_SetError("OpenGL ES context already created");
- return -1;
- }
- #ifdef RTLD_GLOBAL
- dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
- #else
- dlopen_flags = RTLD_LAZY;
- #endif
- handle = dlopen(path, dlopen_flags);
- /* Catch the case where the application isn't linked with EGL */
- if ( (dlsym(handle, "eglChooseConfig") == NULL) && (path == NULL) ) {
- dlclose(handle);
- path = getenv("SDL_VIDEO_GL_DRIVER");
- if ( path == NULL ) {
- path = DEFAULT_OPENGL;
- }
- handle = dlopen(path, dlopen_flags);
- }
- if ( handle == NULL ) {
- SDL_SetError("Could not load OpenGL ES/EGL library");
- return -1;
- }
- /* Unload the old driver and reset the pointers */
- X11_GLES_UnloadLibrary(this);
- /* Load new function pointers */
- LOAD_FUNC(eglGetDisplay);
- LOAD_FUNC(eglInitialize);
- LOAD_FUNC(eglTerminate);
- LOAD_FUNC(eglGetProcAddress);
- LOAD_FUNC(eglChooseConfig);
- LOAD_FUNC(eglGetConfigAttrib);
- LOAD_FUNC(eglCreateContext);
- LOAD_FUNC(eglDestroyContext);
- LOAD_FUNC(eglCreateWindowSurface);
- LOAD_FUNC(eglDestroySurface);
- LOAD_FUNC(eglMakeCurrent);
- LOAD_FUNC(eglSwapBuffers);
- /*
- * Initialize EGL
- */
- this->gles_data->egl_display = this->gles_data->eglGetDisplay(SDL_Display);
- if ( !this->gles_data->egl_display ) {
- SDL_SetError("Could not get EGL display");
- return -1;
- }
- if ( this->gles_data->eglInitialize(this->gles_data->egl_display, NULL, NULL) != EGL_TRUE ) {
- SDL_SetError("Could not initialize EGL");
- return -1;
- }
- this->gl_config.dll_handle = handle;
- this->gl_config.driver_loaded = 1;
- if ( path ) {
- strncpy(this->gl_config.driver_path, path,
- sizeof(this->gl_config.driver_path)-1);
- } else {
- strcpy(this->gl_config.driver_path, "");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement