libmpv  20200718-git-96cdf53
development library for the MPV media player
Looking for a C++ dev?
I'm looking for work. Hire me!
render_gl.h
Go to the documentation of this file.
1 /* Copyright (C) 2018 the mpv developers
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14  */
15 
16 #ifndef MPV_CLIENT_API_RENDER_GL_H_
17 #define MPV_CLIENT_API_RENDER_GL_H_
18 
19 #include "render.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /**
26  * OpenGL backend
27  * --------------
28  *
29  * This header contains definitions for using OpenGL with the render.h API.
30  *
31  * OpenGL interop
32  * --------------
33  *
34  * The OpenGL backend has some special rules, because OpenGL itself uses
35  * implicit per-thread contexts, which causes additional API problems.
36  *
37  * This assumes the OpenGL context lives on a certain thread controlled by the
38  * API user. All mpv_render_* APIs have to be assumed to implicitly use the
39  * OpenGL context if you pass a mpv_render_context using the OpenGL backend,
40  * unless specified otherwise.
41  *
42  * The OpenGL context is indirectly accessed through the OpenGL function
43  * pointers returned by the get_proc_address callback in mpv_opengl_init_params.
44  * Generally, mpv will not load the system OpenGL library when using this API.
45  *
46  * OpenGL state
47  * ------------
48  *
49  * OpenGL has a large amount of implicit state. All the mpv functions mentioned
50  * above expect that the OpenGL state is reasonably set to OpenGL standard
51  * defaults. Likewise, mpv will attempt to leave the OpenGL context with
52  * standard defaults. The following state is excluded from this:
53  *
54  * - the glViewport state
55  * - the glScissor state (but GL_SCISSOR_TEST is in its default value)
56  * - glBlendFuncSeparate() state (but GL_BLEND is in its default value)
57  * - glClearColor() state
58  * - mpv may overwrite the callback set with glDebugMessageCallback()
59  * - mpv always disables GL_DITHER at init
60  *
61  * Messing with the state could be avoided by creating shared OpenGL contexts,
62  * but this is avoided for the sake of compatibility and interoperability.
63  *
64  * On OpenGL 2.1, mpv will strictly call functions like glGenTextures() to
65  * create OpenGL objects. You will have to do the same. This ensures that
66  * objects created by mpv and the API users don't clash. Also, legacy state
67  * must be either in its defaults, or not interfere with core state.
68  *
69  * API use
70  * -------
71  *
72  * The mpv_render_* API is used. That API supports multiple backends, and this
73  * section documents specifics for the OpenGL backend.
74  *
75  * Use mpv_render_context_create() with MPV_RENDER_PARAM_API_TYPE set to
76  * MPV_RENDER_API_TYPE_OPENGL, and MPV_RENDER_PARAM_OPENGL_INIT_PARAMS provided.
77  *
78  * Call mpv_render_context_render() with MPV_RENDER_PARAM_OPENGL_FBO to render
79  * the video frame to an FBO.
80  *
81  * Hardware decoding
82  * -----------------
83  *
84  * Hardware decoding via this API is fully supported, but requires some
85  * additional setup. (At least if direct hardware decoding modes are wanted,
86  * instead of copying back surface data from GPU to CPU RAM.)
87  *
88  * There may be certain requirements on the OpenGL implementation:
89  *
90  * - Windows: ANGLE is required (although in theory GL/DX interop could be used)
91  * - Intel/Linux: EGL is required, and also the native display resource needs
92  * to be provided (e.g. MPV_RENDER_PARAM_X11_DISPLAY for X11 and
93  * MPV_RENDER_PARAM_WL_DISPLAY for Wayland)
94  * - nVidia/Linux: Both GLX and EGL should work (GLX is required if vdpau is
95  * used, e.g. due to old drivers.)
96  * - OSX: CGL is required (CGLGetCurrentContext() returning non-NULL)
97  * - iOS: EAGL is required (EAGLContext.currentContext returning non-nil)
98  *
99  * Once these things are setup, hardware decoding can be enabled/disabled at
100  * any time by setting the "hwdec" property.
101  */
102 
103 /**
104  * For initializing the mpv OpenGL state via MPV_RENDER_PARAM_OPENGL_INIT_PARAMS.
105  */
106 typedef struct mpv_opengl_init_params {
107  /**
108  * This retrieves OpenGL function pointers, and will use them in subsequent
109  * operation.
110  * Usually, you can simply call the GL context APIs from this callback (e.g.
111  * glXGetProcAddressARB or wglGetProcAddress), but some APIs do not always
112  * return pointers for all standard functions (even if present); in this
113  * case you have to compensate by looking up these functions yourself when
114  * libmpv wants to resolve them through this callback.
115  * libmpv will not normally attempt to resolve GL functions on its own, nor
116  * does it link to GL libraries directly.
117  */
118  void *(*get_proc_address)(void *ctx, const char *name);
119  /**
120  * Value passed as ctx parameter to get_proc_address().
121  */
123  /**
124  * This should not be used. It is deprecated and will be removed or ignored
125  * when the opengl_cb API is removed.
126  */
127  const char *extra_exts;
129 
130 /**
131  * For MPV_RENDER_PARAM_OPENGL_FBO.
132  */
133 typedef struct mpv_opengl_fbo {
134  /**
135  * Framebuffer object name. This must be either a valid FBO generated by
136  * glGenFramebuffers() that is complete and color-renderable, or 0. If the
137  * value is 0, this refers to the OpenGL default framebuffer.
138  */
139  int fbo;
140  /**
141  * Valid dimensions. This must refer to the size of the framebuffer. This
142  * must always be set.
143  */
144  int w, h;
145  /**
146  * Underlying texture internal format (e.g. GL_RGBA8), or 0 if unknown. If
147  * this is the default framebuffer, this can be an equivalent.
148  */
151 
152 /**
153  * Deprecated. For MPV_RENDER_PARAM_DRM_DISPLAY.
154  */
155 typedef struct mpv_opengl_drm_params {
156  int fd;
157  int crtc_id;
159  struct _drmModeAtomicReq **atomic_request_ptr;
162 
163 /**
164  * For MPV_RENDER_PARAM_DRM_DRAW_SURFACE_SIZE.
165  */
167  /**
168  * size of the draw plane surface in pixels.
169  */
170  int width, height;
172 
173 /**
174  * For MPV_RENDER_PARAM_DRM_DISPLAY_V2.
175  */
176 typedef struct mpv_opengl_drm_params_v2 {
177  /**
178  * DRM fd (int). Set to -1 if invalid.
179  */
180  int fd;
181 
182  /**
183  * Currently used crtc id
184  */
185  int crtc_id;
186 
187  /**
188  * Currently used connector id
189  */
191 
192  /**
193  * Pointer to a drmModeAtomicReq pointer that is being used for the renderloop.
194  * This pointer should hold a pointer to the atomic request pointer
195  * The atomic request pointer is usually changed at every renderloop.
196  */
197  struct _drmModeAtomicReq **atomic_request_ptr;
198 
199  /**
200  * DRM render node. Used for VAAPI interop.
201  * Set to -1 if invalid.
202  */
205 
206 
207 /**
208  * For backwards compatibility with the old naming of mpv_opengl_drm_draw_surface_size
209  */
210 #define mpv_opengl_drm_osd_size mpv_opengl_drm_draw_surface_size
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 
216 #endif
mpv_opengl_drm_draw_surface_size
For MPV_RENDER_PARAM_DRM_DRAW_SURFACE_SIZE.
Definition: render_gl.h:166
mpv_opengl_fbo
For MPV_RENDER_PARAM_OPENGL_FBO.
Definition: render_gl.h:133
render.h
mpv_opengl_drm_params::render_fd
int render_fd
Definition: render_gl.h:160
mpv_opengl_init_params
struct mpv_opengl_init_params mpv_opengl_init_params
For initializing the mpv OpenGL state via MPV_RENDER_PARAM_OPENGL_INIT_PARAMS.
mpv_opengl_fbo
struct mpv_opengl_fbo mpv_opengl_fbo
For MPV_RENDER_PARAM_OPENGL_FBO.
mpv_opengl_fbo::fbo
int fbo
Framebuffer object name.
Definition: render_gl.h:139
mpv_opengl_fbo::h
int h
Definition: render_gl.h:144
mpv_opengl_drm_params_v2
struct mpv_opengl_drm_params_v2 mpv_opengl_drm_params_v2
For MPV_RENDER_PARAM_DRM_DISPLAY_V2.
mpv_opengl_drm_params
struct mpv_opengl_drm_params mpv_opengl_drm_params
Deprecated.
mpv_opengl_drm_params::atomic_request_ptr
struct _drmModeAtomicReq ** atomic_request_ptr
Definition: render_gl.h:159
mpv_opengl_drm_params::connector_id
int connector_id
Definition: render_gl.h:158
mpv_opengl_init_params::extra_exts
const char * extra_exts
This should not be used.
Definition: render_gl.h:127
mpv_opengl_drm_params_v2::connector_id
int connector_id
Currently used connector id.
Definition: render_gl.h:190
mpv_opengl_drm_params_v2::crtc_id
int crtc_id
Currently used crtc id.
Definition: render_gl.h:185
mpv_opengl_drm_params_v2::atomic_request_ptr
struct _drmModeAtomicReq ** atomic_request_ptr
Pointer to a drmModeAtomicReq pointer that is being used for the renderloop.
Definition: render_gl.h:197
mpv_opengl_fbo::w
int w
Valid dimensions.
Definition: render_gl.h:144
mpv_opengl_drm_params_v2::fd
int fd
DRM fd (int).
Definition: render_gl.h:180
mpv_opengl_drm_params_v2
For MPV_RENDER_PARAM_DRM_DISPLAY_V2.
Definition: render_gl.h:176
mpv_opengl_drm_params::crtc_id
int crtc_id
Definition: render_gl.h:157
mpv_opengl_drm_params::fd
int fd
Definition: render_gl.h:156
mpv_opengl_init_params::get_proc_address_ctx
void * get_proc_address_ctx
Value passed as ctx parameter to get_proc_address().
Definition: render_gl.h:122
mpv_opengl_fbo::internal_format
int internal_format
Underlying texture internal format (e.g.
Definition: render_gl.h:149
mpv_opengl_drm_draw_surface_size::height
int height
Definition: render_gl.h:170
mpv_opengl_drm_draw_surface_size::width
int width
size of the draw plane surface in pixels.
Definition: render_gl.h:170
mpv_opengl_drm_params_v2::render_fd
int render_fd
DRM render node.
Definition: render_gl.h:203
mpv_opengl_drm_draw_surface_size
struct mpv_opengl_drm_draw_surface_size mpv_opengl_drm_draw_surface_size
For MPV_RENDER_PARAM_DRM_DRAW_SURFACE_SIZE.
mpv_opengl_drm_params
Deprecated.
Definition: render_gl.h:155
mpv_opengl_init_params
For initializing the mpv OpenGL state via MPV_RENDER_PARAM_OPENGL_INIT_PARAMS.
Definition: render_gl.h:106