int X11_GLES_LoadLibrary(_THIS, const char *path) { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; /* If SDL_GL_CONTEXT_EGL has been changed to 0, switch over to X11_GL functions */ if (_this->gl_config.use_egl == 0) { #if SDL_VIDEO_OPENGL_GLX _this->GL_LoadLibrary = X11_GL_LoadLibrary; _this->GL_GetProcAddress = X11_GL_GetProcAddress; _this->GL_UnloadLibrary = X11_GL_UnloadLibrary; _this->GL_CreateContext = X11_GL_CreateContext; _this->GL_MakeCurrent = X11_GL_MakeCurrent; _this->GL_SetSwapInterval = X11_GL_SetSwapInterval; _this->GL_GetSwapInterval = X11_GL_GetSwapInterval; _this->GL_SwapWindow = X11_GL_SwapWindow; _this->GL_DeleteContext = X11_GL_DeleteContext; return X11_GL_LoadLibrary(_this, path); #else return SDL_SetError("SDL not configured with OpenGL/GLX support"); #endif } return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display); }
int X11_GLES_LoadLibrary(_THIS, const char *path) { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; /* If the profile requested is not GL ES, switch over to X11_GL functions */ if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) { #if SDL_VIDEO_OPENGL_GLX X11_GLES_UnloadLibrary(_this); _this->GL_LoadLibrary = X11_GL_LoadLibrary; _this->GL_GetProcAddress = X11_GL_GetProcAddress; _this->GL_UnloadLibrary = X11_GL_UnloadLibrary; _this->GL_CreateContext = X11_GL_CreateContext; _this->GL_MakeCurrent = X11_GL_MakeCurrent; _this->GL_SetSwapInterval = X11_GL_SetSwapInterval; _this->GL_GetSwapInterval = X11_GL_GetSwapInterval; _this->GL_SwapWindow = X11_GL_SwapWindow; _this->GL_DeleteContext = X11_GL_DeleteContext; return X11_GL_LoadLibrary(_this, path); #else return SDL_SetError("SDL not configured with OpenGL/GLX support"); #endif } return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display); }
XVisualInfo *X11_GL_GetVisual(_THIS) { #if SDL_VIDEO_OPENGL_GLX int attribs[64]; int i; if ( ! this->gl_config.driver_loaded ) { if ( X11_GL_LoadLibrary(this, NULL) < 0 ) { return NULL; } } if ( SDL_windowid ) { XWindowAttributes a; XVisualInfo vi_in; int out_count; XGetWindowAttributes(SDL_Display, SDL_Window, &a); vi_in.screen = SDL_Screen; vi_in.visualid = XVisualIDFromVisual(a.visual); glx_visualinfo = XGetVisualInfo(SDL_Display, VisualScreenMask|VisualIDMask, &vi_in, &out_count); return glx_visualinfo; } i = 0; attribs[i++] = GLX_RGBA; attribs[i++] = GLX_RED_SIZE; attribs[i++] = this->gl_config.red_size; attribs[i++] = GLX_GREEN_SIZE; attribs[i++] = this->gl_config.green_size; attribs[i++] = GLX_BLUE_SIZE; attribs[i++] = this->gl_config.blue_size; if( this->gl_config.alpha_size ) { attribs[i++] = GLX_ALPHA_SIZE; attribs[i++] = this->gl_config.alpha_size; } if( this->gl_config.double_buffer ) { attribs[i++] = GLX_DOUBLEBUFFER; } attribs[i++] = GLX_DEPTH_SIZE; attribs[i++] = this->gl_config.depth_size; if( this->gl_config.stencil_size ) { attribs[i++] = GLX_STENCIL_SIZE; attribs[i++] = this->gl_config.stencil_size; } if( this->gl_config.accum_red_size ) { attribs[i++] = GLX_ACCUM_RED_SIZE; attribs[i++] = this->gl_config.accum_red_size; } if( this->gl_config.accum_green_size ) { attribs[i++] = GLX_ACCUM_GREEN_SIZE; attribs[i++] = this->gl_config.accum_green_size; } if( this->gl_config.accum_blue_size ) { attribs[i++] = GLX_ACCUM_BLUE_SIZE; attribs[i++] = this->gl_config.accum_blue_size; } if( this->gl_config.accum_alpha_size ) { attribs[i++] = GLX_ACCUM_ALPHA_SIZE; attribs[i++] = this->gl_config.accum_alpha_size; } if( this->gl_config.stereo ) { attribs[i++] = GLX_STEREO; } if( this->gl_config.multisamplebuffers ) { attribs[i++] = GLX_SAMPLE_BUFFERS_ARB; attribs[i++] = this->gl_config.multisamplebuffers; } if( this->gl_config.multisamplesamples ) { attribs[i++] = GLX_SAMPLES_ARB; attribs[i++] = this->gl_config.multisamplesamples; } if( this->gl_config.accelerated >= 0 && glXExtensionSupported(this, "GLX_EXT_visual_rating") ) { attribs[i++] = GLX_VISUAL_CAVEAT_EXT; attribs[i++] = GLX_NONE_EXT; } #ifdef GLX_DIRECT_COLOR if ( !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { attribs[i++] = GLX_X_VISUAL_TYPE; attribs[i++] = GLX_DIRECT_COLOR; } #endif attribs[i++] = None; glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, SDL_Screen, attribs); #ifdef GLX_DIRECT_COLOR if( !glx_visualinfo && !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { attribs[i-3] = None; glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, SDL_Screen, attribs); } #endif if( !glx_visualinfo ) { SDL_SetError( "Couldn't find matching GLX visual"); return NULL; } return glx_visualinfo; #else SDL_SetError("X11 driver not configured with OpenGL"); return NULL; #endif }
XVisualInfo *X11_GL_GetVisual(_THIS) { #if SDL_VIDEO_OPENGL_GLX /* 64 seems nice. */ int attribs[64]; int i; /* load the gl driver from a default path */ if ( ! this->gl_config.driver_loaded ) { /* no driver has been loaded, use default (ourselves) */ if ( X11_GL_LoadLibrary(this, NULL) < 0 ) { return NULL; } } /* See if we already have a window which we must use */ if ( SDL_windowid ) { XWindowAttributes a; XVisualInfo vi_in; int out_count; XGetWindowAttributes(SDL_Display, SDL_Window, &a); vi_in.screen = SDL_Screen; vi_in.visualid = XVisualIDFromVisual(a.visual); glx_visualinfo = XGetVisualInfo(SDL_Display, VisualScreenMask|VisualIDMask, &vi_in, &out_count); return glx_visualinfo; } /* Setup our GLX attributes according to the gl_config. */ i = 0; attribs[i++] = GLX_RGBA; attribs[i++] = GLX_RED_SIZE; attribs[i++] = this->gl_config.red_size; attribs[i++] = GLX_GREEN_SIZE; attribs[i++] = this->gl_config.green_size; attribs[i++] = GLX_BLUE_SIZE; attribs[i++] = this->gl_config.blue_size; if( this->gl_config.alpha_size ) { attribs[i++] = GLX_ALPHA_SIZE; attribs[i++] = this->gl_config.alpha_size; } if( this->gl_config.buffer_size ) { attribs[i++] = GLX_BUFFER_SIZE; attribs[i++] = this->gl_config.buffer_size; } if( this->gl_config.double_buffer ) { attribs[i++] = GLX_DOUBLEBUFFER; } attribs[i++] = GLX_DEPTH_SIZE; attribs[i++] = this->gl_config.depth_size; if( this->gl_config.stencil_size ) { attribs[i++] = GLX_STENCIL_SIZE; attribs[i++] = this->gl_config.stencil_size; } if( this->gl_config.accum_red_size ) { attribs[i++] = GLX_ACCUM_RED_SIZE; attribs[i++] = this->gl_config.accum_red_size; } if( this->gl_config.accum_green_size ) { attribs[i++] = GLX_ACCUM_GREEN_SIZE; attribs[i++] = this->gl_config.accum_green_size; } if( this->gl_config.accum_blue_size ) { attribs[i++] = GLX_ACCUM_BLUE_SIZE; attribs[i++] = this->gl_config.accum_blue_size; } if( this->gl_config.accum_alpha_size ) { attribs[i++] = GLX_ACCUM_ALPHA_SIZE; attribs[i++] = this->gl_config.accum_alpha_size; } if( this->gl_config.stereo ) { attribs[i++] = GLX_STEREO; } if( this->gl_config.multisamplebuffers ) { attribs[i++] = GLX_SAMPLE_BUFFERS_ARB; attribs[i++] = this->gl_config.multisamplebuffers; } if( this->gl_config.multisamplesamples ) { attribs[i++] = GLX_SAMPLES_ARB; attribs[i++] = this->gl_config.multisamplesamples; } if( this->gl_config.accelerated >= 0 && glXExtensionSupported(this, "GLX_EXT_visual_rating") ) { attribs[i++] = GLX_VISUAL_CAVEAT_EXT; attribs[i++] = GLX_NONE_EXT; } #ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */ if ( !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { attribs[i++] = GLX_X_VISUAL_TYPE; attribs[i++] = GLX_DIRECT_COLOR; } #endif attribs[i++] = None; glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, SDL_Screen, attribs); #ifdef GLX_DIRECT_COLOR if( !glx_visualinfo && !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { /* No DirectColor visual? Try again.. */ attribs[i-3] = None; glx_visualinfo = this->gl_data->glXChooseVisual(GFX_Display, SDL_Screen, attribs); } #endif if( !glx_visualinfo ) { SDL_SetError( "Couldn't find matching GLX visual"); return NULL; } /* printf("Found GLX visual 0x%x\n", glx_visualinfo->visualid); */ return glx_visualinfo; #else SDL_SetError("X11 driver not configured with OpenGL"); return NULL; #endif }
int X11_GLES_LoadLibrary(_THIS, const char *path) { void *handle; int dlopen_flags; SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; if (_this->gles_data) { return SDL_SetError("OpenGL ES context already created"); } /* If SDL_GL_CONTEXT_EGL has been changed to 0, switch over to X11_GL functions */ if (_this->gl_config.use_egl == 0) { #if SDL_VIDEO_OPENGL_GLX _this->GL_LoadLibrary = X11_GL_LoadLibrary; _this->GL_GetProcAddress = X11_GL_GetProcAddress; _this->GL_UnloadLibrary = X11_GL_UnloadLibrary; _this->GL_CreateContext = X11_GL_CreateContext; _this->GL_MakeCurrent = X11_GL_MakeCurrent; _this->GL_SetSwapInterval = X11_GL_SetSwapInterval; _this->GL_GetSwapInterval = X11_GL_GetSwapInterval; _this->GL_SwapWindow = X11_GL_SwapWindow; _this->GL_DeleteContext = X11_GL_DeleteContext; return X11_GL_LoadLibrary(_this, path); #else return SDL_SetError("SDL not configured with OpenGL/GLX support"); #endif } #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_EGL_DRIVER"); if (path == NULL) { path = DEFAULT_EGL; } handle = dlopen(path, dlopen_flags); } if (handle == NULL) { return SDL_SetError("Could not load OpenGL ES/EGL library"); } /* Unload the old driver and reset the pointers */ X11_GLES_UnloadLibrary(_this); _this->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData)); if (!_this->gles_data) { return SDL_OutOfMemory(); } /* 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); LOAD_FUNC(eglSwapInterval); _this->gles_data->egl_display = _this->gles_data->eglGetDisplay((NativeDisplayType) data->display); if (!_this->gles_data->egl_display) { return SDL_SetError("Could not get EGL display"); } if (_this->gles_data-> eglInitialize(_this->gles_data->egl_display, NULL, NULL) != EGL_TRUE) { return SDL_SetError("Could not initialize EGL"); } _this->gles_data->egl_dll_handle = handle; path = getenv("SDL_VIDEO_GL_DRIVER"); handle = dlopen(path, dlopen_flags); if ((path == NULL) | (handle == NULL)) { if (_this->gl_config.major_version > 1) { path = DEFAULT_OGL_ES2; handle = dlopen(path, dlopen_flags); } else { path = DEFAULT_OGL_ES; handle = dlopen(path, dlopen_flags); if (handle == NULL) { path = DEFAULT_OGL_ES_PVR; handle = dlopen(path, dlopen_flags); } } } if (handle == NULL) { return SDL_SetError("Could not initialize OpenGL ES library"); } _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; }