/***************************************************************************** * CreateOpenGL: initialize an OpenGL provider *****************************************************************************/ static int CreateOpenGL( vlc_object_t *p_this ) { vout_thread_t *p_vout = (vout_thread_t *)p_this; vlc_bool_t b_glx13; if( CheckGLX( p_this, &b_glx13 ) != VLC_SUCCESS ) { msg_Err( p_vout, "no GLX support" ); return VLC_EGENERIC; } if( E_(Activate)( p_this ) != VLC_SUCCESS ) { return VLC_EGENERIC; } /* Set the function pointer */ p_vout->pf_init = InitOpenGL; p_vout->pf_swap = SwapBuffers; p_vout->p_sys->b_glx13 = b_glx13; return VLC_SUCCESS; }
static int Open (vlc_object_t *obj) { vlc_gl_t *gl = (vlc_gl_t *)obj; if (gl->surface->type != VOUT_WINDOW_TYPE_XID || !vlc_xlib_init (obj)) return VLC_EGENERIC; /* Initialize GLX display */ Display *dpy = XOpenDisplay (gl->surface->display.x11); if (dpy == NULL) return VLC_EGENERIC; vlc_gl_sys_t *sys = malloc (sizeof (*sys)); if (unlikely(sys == NULL)) { XCloseDisplay (dpy); return VLC_ENOMEM; } gl->sys = sys; sys->display = dpy; if (!CheckGLX (obj, dpy)) goto error; /* Determine our pixel format */ XWindowAttributes wa; if (!XGetWindowAttributes (dpy, gl->surface->handle.xid, &wa)) goto error; const int snum = XScreenNumberOfScreen (wa.screen); const VisualID visual = XVisualIDFromVisual (wa.visual); static const int attr[] = { GLX_RED_SIZE, 5, GLX_GREEN_SIZE, 5, GLX_BLUE_SIZE, 5, GLX_DOUBLEBUFFER, True, GLX_X_RENDERABLE, True, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, None }; int nelem; GLXFBConfig *confs = glXChooseFBConfig (dpy, snum, attr, &nelem); if (confs == NULL) { msg_Err (obj, "cannot choose GLX frame buffer configurations"); goto error; } GLXFBConfig conf; bool found = false; for (int i = 0; i < nelem && !found; i++) { conf = confs[i]; XVisualInfo *vi = glXGetVisualFromFBConfig (dpy, conf); if (vi == NULL) continue; if (vi->visualid == visual) found = true; XFree (vi); } XFree (confs); if (!found) { msg_Err (obj, "cannot match GLX frame buffer configuration"); goto error; } /* Create a drawing surface */ sys->win = glXCreateWindow (dpy, conf, gl->surface->handle.xid, NULL); if (sys->win == None) { msg_Err (obj, "cannot create GLX window"); goto error; } /* Create an OpenGL context */ sys->ctx = glXCreateNewContext (dpy, conf, GLX_RGBA_TYPE, NULL, True); if (sys->ctx == NULL) { glXDestroyWindow (dpy, sys->win); msg_Err (obj, "cannot create GLX context"); goto error; } /* Initialize OpenGL callbacks */ gl->sys = sys; gl->makeCurrent = MakeCurrent; gl->releaseCurrent = ReleaseCurrent; gl->resize = NULL; gl->swap = SwapBuffers; gl->getProcAddress = GetSymbol; #ifdef GLX_ARB_get_proc_address bool is_swap_interval_set = false; MakeCurrent (gl); # ifdef GLX_SGI_swap_control if (!is_swap_interval_set && CheckGLXext (dpy, snum, "GLX_SGI_swap_control")) { PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) glXGetProcAddressARB ((const GLubyte *)"glXSwapIntervalSGI"); assert (SwapIntervalSGI != NULL); is_swap_interval_set = !SwapIntervalSGI (1); } # endif # ifdef GLX_EXT_swap_control if (!is_swap_interval_set && CheckGLXext (dpy, snum, "GLX_EXT_swap_control")) { PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddress ((const GLubyte *)"glXSwapIntervalEXT"); assert (SwapIntervalEXT != NULL); SwapIntervalEXT (dpy, sys->win, 1); is_swap_interval_set = true; } # endif ReleaseCurrent (gl); #endif return VLC_SUCCESS; error: XCloseDisplay (dpy); free (sys); return VLC_EGENERIC; }