Advertisement
Guest User

Untitled

a guest
Nov 18th, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.21 KB | None | 0 0
  1. #ifdef SDL_VIDEO_OPENGL_ES
  2.  
  3. /*
  4.  *  A macro for loading a function pointer with dlsym
  5.  */
  6. #define LOAD_FUNC(NAME) \
  7.     *((void**)&this->gles_data->NAME) = dlsym(handle, #NAME); \
  8.     if (!this->gles_data->NAME) \
  9.     { \
  10.         SDL_SetError("Could not retrieve EGL function " #NAME); \
  11.         return -1; \
  12.     }
  13.  
  14.  
  15. /* Passing a NULL path means load pointers from the application */
  16. int X11_GLES_LoadLibrary(_THIS, const char* path)
  17. {
  18.     void* handle;
  19.     int dlopen_flags;
  20.  
  21.     if ( this->gles_data->egl_active ) {
  22.         SDL_SetError("OpenGL ES context already created");
  23.         return -1;
  24.     }
  25.  
  26. #ifdef RTLD_GLOBAL
  27.     dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
  28. #else
  29.     dlopen_flags = RTLD_LAZY;
  30. #endif
  31.     handle = dlopen(path, dlopen_flags);
  32.     /* Catch the case where the application isn't linked with EGL */
  33.     if ( (dlsym(handle, "eglChooseConfig") == NULL) && (path == NULL) ) {
  34.         dlclose(handle);
  35.         path = getenv("SDL_VIDEO_GL_DRIVER");
  36.         if ( path == NULL ) {
  37.             path = DEFAULT_OPENGL;
  38.         }
  39.         handle = dlopen(path, dlopen_flags);
  40.     }
  41.     if ( handle == NULL ) {
  42.         SDL_SetError("Could not load OpenGL ES/EGL library");
  43.         return -1;
  44.     }
  45.  
  46.     /* Unload the old driver and reset the pointers */
  47.     X11_GLES_UnloadLibrary(this);
  48.  
  49.     /* Load new function pointers */
  50.     LOAD_FUNC(eglGetDisplay);
  51.     LOAD_FUNC(eglInitialize);
  52.     LOAD_FUNC(eglTerminate);
  53.     LOAD_FUNC(eglGetProcAddress);
  54.     LOAD_FUNC(eglChooseConfig);
  55.     LOAD_FUNC(eglGetConfigAttrib);
  56.     LOAD_FUNC(eglCreateContext);
  57.     LOAD_FUNC(eglDestroyContext);
  58.     LOAD_FUNC(eglCreateWindowSurface);
  59.     LOAD_FUNC(eglDestroySurface);
  60.     LOAD_FUNC(eglMakeCurrent);
  61.     LOAD_FUNC(eglSwapBuffers);
  62.  
  63.     /*
  64.      *  Initialize EGL
  65.      */
  66.     this->gles_data->egl_display = this->gles_data->eglGetDisplay(SDL_Display);
  67.  
  68.     if ( !this->gles_data->egl_display ) {
  69.         SDL_SetError("Could not get EGL display");
  70.         return -1;
  71.     }
  72.  
  73.     if ( this->gles_data->eglInitialize(this->gles_data->egl_display, NULL, NULL) != EGL_TRUE ) {
  74.         SDL_SetError("Could not initialize EGL");
  75.         return -1;
  76.     }
  77.    
  78.     this->gl_config.dll_handle = handle;
  79.     this->gl_config.driver_loaded = 1;
  80.     if ( path ) {
  81.         strncpy(this->gl_config.driver_path, path,
  82.             sizeof(this->gl_config.driver_path)-1);
  83.     } else {
  84.         strcpy(this->gl_config.driver_path, "");
  85.     }
  86.     return 0;
  87. }
  88.  
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement