vendetta / libvendetta / mpv / win64 / include / mpv / render_gl.h
211 lines · 194 sloc · 7.16 KB
Raw
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
22extern "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 * - macOS: 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 */
106typedef 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 */
122 void *get_proc_address_ctx;
123} mpv_opengl_init_params;
124
125/**
126 * For MPV_RENDER_PARAM_OPENGL_FBO.
127 */
128typedef struct mpv_opengl_fbo {
129 /**
130 * Framebuffer object name. This must be either a valid FBO generated by
131 * glGenFramebuffers() that is complete and color-renderable, or 0. If the
132 * value is 0, this refers to the OpenGL default framebuffer.
133 */
134 int fbo;
135 /**
136 * Valid dimensions. This must refer to the size of the framebuffer. This
137 * must always be set.
138 */
139 int w, h;
140 /**
141 * Underlying texture internal format (e.g. GL_RGBA8), or 0 if unknown. If
142 * this is the default framebuffer, this can be an equivalent.
143 */
144 int internal_format;
145} mpv_opengl_fbo;
146
147/**
148 * Deprecated. For MPV_RENDER_PARAM_DRM_DISPLAY.
149 */
150typedef struct mpv_opengl_drm_params {
151 int fd;
152 int crtc_id;
153 int connector_id;
154 struct _drmModeAtomicReq **atomic_request_ptr;
155 int render_fd;
156} mpv_opengl_drm_params;
157
158/**
159 * For MPV_RENDER_PARAM_DRM_DRAW_SURFACE_SIZE.
160 */
161typedef struct mpv_opengl_drm_draw_surface_size {
162 /**
163 * size of the draw plane surface in pixels.
164 */
165 int width, height;
166} mpv_opengl_drm_draw_surface_size;
167
168/**
169 * For MPV_RENDER_PARAM_DRM_DISPLAY_V2.
170 */
171typedef struct mpv_opengl_drm_params_v2 {
172 /**
173 * DRM fd (int). Set to -1 if invalid.
174 */
175 int fd;
176
177 /**
178 * Currently used crtc id
179 */
180 int crtc_id;
181
182 /**
183 * Currently used connector id
184 */
185 int connector_id;
186
187 /**
188 * Pointer to a drmModeAtomicReq pointer that is being used for the renderloop.
189 * This pointer should hold a pointer to the atomic request pointer
190 * The atomic request pointer is usually changed at every renderloop.
191 */
192 struct _drmModeAtomicReq **atomic_request_ptr;
193
194 /**
195 * DRM render node. Used for VAAPI interop.
196 * Set to -1 if invalid.
197 */
198 int render_fd;
199} mpv_opengl_drm_params_v2;
200
201
202/**
203 * For backwards compatibility with the old naming of mpv_opengl_drm_draw_surface_size
204 */
205#define mpv_opengl_drm_osd_size mpv_opengl_drm_draw_surface_size
206
207#ifdef __cplusplus
208}
209#endif
210
211#endif
212