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