Warning: thisAPIisdeprecated. AverysimilarAPIisprovidedbyrender.handrender_gl.h. ThedeprecatedAPIisemulatedwiththenewAPI.
ThisAPIcanbeusedtomakempvrenderintoaforeignOpenGLcontext. Itcanbeusedtohandlevideodisplay.
Therendererneedstobeexplicitlyinitializedwithmpv_opengl_cb_init_gl(),
andthenvideocanbedrawnwithmpv_opengl_cb_draw(). Theuserthreadcanbenotifiedbynewframeswithmpv_opengl_cb_set_update_callback().
YoucanoutputandembedvideowithoutthisAPIbysettingthempv"wid"optiontoanativewindowhandle (see"Embedding the video window"sectionintheclient.hheader). Ingeneral, usingtheopengl-cbAPIisrecommended,
becausewindowembeddingcancausevariousissues, especiallywithGUItoolkitsandcertainplatforms.
OpenGLinterop
This assumes the OpenGL context lives on a certain thread controlled by the
API user. The following functions require access to the OpenGL context:
mpv_opengl_cb_init_gl
mpv_opengl_cb_draw
mpv_opengl_cb_uninit_gl
The OpenGL context is indirectly accessed through the OpenGL function
pointers returned by the get_proc_address callback in mpv_opengl_cb_init_gl.
Generally, mpv will not load the system OpenGL library when using this API.
Only "desktop" OpenGL version 2.1 and later and OpenGL ES version 2.0 and
later are supported. With OpenGL 2.1, the GL_ARB_texture_rg is required. The
renderer was written for the OpenGL 3.x core profile, with additional support
for OpenGL 2.1 and OpenGL ES 2.0.
Note that some hardware decoding interop API (as set with the "hwdec" option)
may actually access some sort of host API, such as EGL.
The mpv_opengl_cb_* functions can be called from any thread, under the
following conditions:
- only one of the mpv_opengl_cb_* functions can be called at the same time
(unless they belong to different mpv cores created by mpv_create())
- for functions which need an OpenGL context (see above) the OpenGL context
must be "current" in the current thread, and it must be the same context
as used with mpv_opengl_cb_init_gl()
- never can be called from within the callbacks set with
mpv_set_wakeup_callback() or mpv_opengl_cb_set_update_callback()
Hardware decoding via opengl_cb is fully supported, but requires some
additional setup. (At least if direct hardware decoding modes are wanted,
instead of copying back surface data from GPU to CPU RAM.)
While "normal" mpv loads the OpenGL hardware decoding interop on demand,
this can't be done with opengl_cb for internal technical reasons. Instead,
it loads them by default, even if hardware decoding is not going to be used.
In older mpv releases, this had to be done by setting the
"opengl-hwdec-interop" or "hwdec-preload" options before calling
mpv_opengl_cb_init_gl(). You can still use the newer "gpu-hwdec-interop"
option to prevent loading of interop, or to load only a specific interop.
There may be certain requirements on the OpenGL implementation:
- Windows: ANGLE is required (although in theory GL/DX interop could be used)
- Intel/Linux: EGL is required, and also a glMPGetNativeDisplay() callback
must be provided (see sections below)
- nVidia/Linux: Both GLX and EGL should work (GLX is required if vdpau is
used, e.g. due to old drivers.)
- OSX: CGL is required (CGLGetCurrentContext() returning non-NULL)
- iOS: EAGL is required (EAGLContext.currentContext returning non-nil)
Once these things are setup, hardware decoding can be enabled/disabled at
any time by setting the "hwdec" property.
Special windowing system interop considerations
In some cases, libmpv needs to have access to the windowing system's handles.
This can be a pointer to a X11 "Display" for example. Usually this is needed
only for hardware decoding.
You can communicate these handles to libmpv by adding a pseudo-OpenGL
extension "GL_MP_MPGetNativeDisplay" to the additional extension string when
calling mpv_opengl_cb_init_gl(). The get_proc_address callback should resolve
a function named "glMPGetNativeDisplay", which has the signature:
See below what names are defined. Usually, libmpv will use the native handle
up until mpv_opengl_cb_uninit_gl() is called. If the name is not anything
you know/expected, return NULL from the function.
Overview
This assumes the OpenGL context lives on a certain thread controlled by the API user. The following functions require access to the OpenGL context: mpv_opengl_cb_init_gl mpv_opengl_cb_draw mpv_opengl_cb_uninit_gl
The OpenGL context is indirectly accessed through the OpenGL function pointers returned by the get_proc_address callback in mpv_opengl_cb_init_gl. Generally, mpv will not load the system OpenGL library when using this API.
Only "desktop" OpenGL version 2.1 and later and OpenGL ES version 2.0 and later are supported. With OpenGL 2.1, the GL_ARB_texture_rg is required. The renderer was written for the OpenGL 3.x core profile, with additional support for OpenGL 2.1 and OpenGL ES 2.0.
Note that some hardware decoding interop API (as set with the "hwdec" option) may actually access some sort of host API, such as EGL.
OpenGL state
The mpv_opengl_cb_* functions can be called from any thread, under the following conditions: - only one of the mpv_opengl_cb_* functions can be called at the same time (unless they belong to different mpv cores created by mpv_create()) - for functions which need an OpenGL context (see above) the OpenGL context must be "current" in the current thread, and it must be the same context as used with mpv_opengl_cb_init_gl() - never can be called from within the callbacks set with mpv_set_wakeup_callback() or mpv_opengl_cb_set_update_callback()
Context and handle lifecycle
Hardware decoding via opengl_cb is fully supported, but requires some additional setup. (At least if direct hardware decoding modes are wanted, instead of copying back surface data from GPU to CPU RAM.)
While "normal" mpv loads the OpenGL hardware decoding interop on demand, this can't be done with opengl_cb for internal technical reasons. Instead, it loads them by default, even if hardware decoding is not going to be used. In older mpv releases, this had to be done by setting the "opengl-hwdec-interop" or "hwdec-preload" options before calling mpv_opengl_cb_init_gl(). You can still use the newer "gpu-hwdec-interop" option to prevent loading of interop, or to load only a specific interop.
There may be certain requirements on the OpenGL implementation: - Windows: ANGLE is required (although in theory GL/DX interop could be used) - Intel/Linux: EGL is required, and also a glMPGetNativeDisplay() callback must be provided (see sections below) - nVidia/Linux: Both GLX and EGL should work (GLX is required if vdpau is used, e.g. due to old drivers.) - OSX: CGL is required (CGLGetCurrentContext() returning non-NULL) - iOS: EAGL is required (EAGLContext.currentContext returning non-nil)
Once these things are setup, hardware decoding can be enabled/disabled at any time by setting the "hwdec" property.
Special windowing system interop considerations
In some cases, libmpv needs to have access to the windowing system's handles. This can be a pointer to a X11 "Display" for example. Usually this is needed only for hardware decoding.
You can communicate these handles to libmpv by adding a pseudo-OpenGL extension "GL_MP_MPGetNativeDisplay" to the additional extension string when calling mpv_opengl_cb_init_gl(). The get_proc_address callback should resolve a function named "glMPGetNativeDisplay", which has the signature:
void* GLAPIENTRY glMPGetNativeDisplay(const char* name)
See below what names are defined. Usually, libmpv will use the native handle up until mpv_opengl_cb_uninit_gl() is called. If the name is not anything you know/expected, return NULL from the function.