VLC 4.0.0-dev
Loading...
Searching...
No Matches
vlc_opengl.h
Go to the documentation of this file.
1/*****************************************************************************
2 * vlc_opengl.h: VLC GL API
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
5 * Copyright (C) 2011 RĂ©mi Denis-Courmont
6 *
7 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
23
24#ifndef VLC_GL_H
25#define VLC_GL_H 1
26
27#include <vlc_es.h>
28
29# ifdef __cplusplus
30extern "C" {
31# endif
32
33/**
34 * \file
35 * This file defines GL structures and functions.
36 */
37
38struct vlc_window;
39struct vlc_window_cfg;
40struct vout_display_cfg;
41
42/**
43 * A VLC GL context (and its underlying surface)
44 */
45typedef struct vlc_gl_t vlc_gl_t;
48
49enum vlc_gl_api_type {
54struct vlc_gl_cfg
56 bool need_alpha; /* False by default */
57};
58
59typedef int (*vlc_gl_activate)(vlc_gl_t *, unsigned width, unsigned height,
60 const struct vlc_gl_cfg *cfg);
61
62#define set_callback_opengl_common(activate) \
63 { \
64 vlc_gl_activate activate__ = activate; \
65 (void) activate__; \
66 set_callback(activate) \
67 } \
68
69#define set_callback_opengl(activate, priority) \
70 set_callback_opengl_common(activate) \
71 set_capability("opengl", priority)
72
73#define set_callback_opengl_offscreen(activate, priority) \
74 set_callback_opengl_common(activate) \
75 set_capability("opengl offscreen", priority)
76
77#define set_callback_opengl_es2(activate, priority) \
78 set_callback_opengl_common(activate) \
79 set_capability("opengl es2", priority)
80
81#define set_callback_opengl_es2_offscreen(activate, priority) \
82 set_callback_opengl_common(activate) \
83 set_capability("opengl es2 offscreen", priority)
84
87 union {
88 void (*swap)(vlc_gl_t *);
89 picture_t *(*swap_offscreen)(vlc_gl_t *);
90 };
91 int (*make_current)(vlc_gl_t *gl);
93 void (*resize)(vlc_gl_t *gl, unsigned width, unsigned height);
94 void*(*get_proc_address)(vlc_gl_t *gl, const char *symbol);
95 void (*close)(vlc_gl_t *gl);
96};
97
98struct vlc_gl_t
100 struct vlc_object_t obj;
102 module_t *module;
103 void *sys;
106 union {
107 struct { /* on-screen */
108 struct vlc_window *surface;
109 };
110 struct { /* off-screen */
111 vlc_fourcc_t offscreen_chroma_out;
112 struct vlc_video_context *offscreen_vctx_out;
113 };
114 };
115
116 /* Orientation that signals how the content should be generated by
117 * the client of the OpenGL provider. */
120 /* Defined by the core for libvlc_opengl API loading. */
123 const struct vlc_gl_operations *ops;
125
126/**
127 * Creates an OpenGL context (and its underlying surface).
128 *
129 * @note In most cases, you should vlc_gl_MakeCurrent() afterward.
130 *
131 * @param cfg initial configuration (including window to use as OpenGL surface)
132 * @param flags OpenGL context type
133 * @param name module name (or NULL for auto)
134 * @param gl_cfg OpenGL configuration (or NULL for default)
135 * @return a new context, or NULL on failure
136 */
138 unsigned flags, const char *name,
139 const struct vlc_gl_cfg *gl_cfg) VLC_USED;
141 struct vlc_decoder_device *device,
142 unsigned width, unsigned height,
143 unsigned flags, const char *name,
144 const struct vlc_gl_cfg *gl_cfg);
145
147
148static inline int vlc_gl_MakeCurrent(vlc_gl_t *gl)
150 return gl->ops->make_current(gl);
151}
152
153static inline void vlc_gl_ReleaseCurrent(vlc_gl_t *gl)
155 gl->ops->release_current(gl);
156}
157
158static inline void vlc_gl_Resize(vlc_gl_t *gl, unsigned w, unsigned h)
160 if (gl->ops->resize != NULL)
161 gl->ops->resize(gl, w, h);
162}
163
164static inline void vlc_gl_Swap(vlc_gl_t *gl)
166 gl->ops->swap(gl);
167}
168
169static inline picture_t *vlc_gl_SwapOffscreen(vlc_gl_t *gl)
171 return gl->ops->swap_offscreen(gl);
172}
173
174/**
175 * Fetch a symbol or pointer function from the OpenGL implementation.
176 *
177 * Return a pointer from the OpenGL implementation, which can be part of
178 * either the underlying OpenGL provider or an OpenGL function matching
179 * the version requested.
180 *
181 * If the symbol name is not matching the underlying implementation of
182 * OpenGL, an invalid pointer or NULL can be returned.
183 *
184 * @note This function must be called between MakeCurrent and ReleaseCurrent.
185 *
186 * @param gl the OpenGL provider to fetch the function from
187 * @param name the symbol name to fetch from the implementation
188 *
189 * @return A pointer corresponding to the symbol, or a potentially invalid
190 * value or NULL in case of error.
191 */
192static inline void *vlc_gl_GetProcAddress(vlc_gl_t *gl, const char *name)
194 return gl->ops->get_proc_address(gl, name);
195}
196
198 const struct vlc_window_cfg *,
199 struct vlc_window **,
200 const struct vlc_gl_cfg *) VLC_USED;
201
202VLC_API bool vlc_gl_surface_CheckSize(vlc_gl_t *, unsigned *w, unsigned *h);
204
205static inline bool vlc_gl_StrHasToken(const char *apis, const char *api)
207 size_t apilen = strlen(api);
208 while (apis) {
209 while (*apis == ' ')
210 apis++;
211 if (!strncmp(apis, api, apilen) && memchr(" ", apis[apilen], 2))
212 return true;
213 apis = strchr(apis, ' ');
214 }
215 return false;
216}
217
218#ifdef __cplusplus
219}
220#endif /* C++ */
221
222#endif /* VLC_GL_H */
#define VLC_USED
Definition fourcc_gen.c:32
#define VLC_API
Definition fourcc_gen.c:31
uint32_t vlc_fourcc_t
Definition fourcc_gen.c:33
const char name[16]
Definition httpd.c:1298
Internal module descriptor.
Definition modules.h:76
Video picture.
Definition vlc_picture.h:130
Decoder context struct.
Definition vlc_codec.h:604
Definition vlc_opengl.h:56
bool need_alpha
Definition vlc_opengl.h:57
Definition vlc_opengl.h:87
void *(* get_proc_address)(vlc_gl_t *gl, const char *symbol)
Definition vlc_opengl.h:95
void(* swap)(vlc_gl_t *)
Definition vlc_opengl.h:89
picture_t *(* swap_offscreen)(vlc_gl_t *)
Definition vlc_opengl.h:90
void(* resize)(vlc_gl_t *gl, unsigned width, unsigned height)
Definition vlc_opengl.h:94
int(* make_current)(vlc_gl_t *gl)
Definition vlc_opengl.h:92
void(* release_current)(vlc_gl_t *gl)
Definition vlc_opengl.h:93
void(* close)(vlc_gl_t *gl)
Definition vlc_opengl.h:96
Definition vlc_opengl.h:100
vlc_fourcc_t offscreen_chroma_out
Definition vlc_opengl.h:112
enum vlc_gl_api_type api_type
Definition vlc_opengl.h:122
struct vlc_video_context * offscreen_vctx_out
Definition vlc_opengl.h:113
struct vlc_window * surface
Definition vlc_opengl.h:109
struct vlc_decoder_device * device
Definition vlc_opengl.h:106
module_t *void * sys
Definition vlc_opengl.h:104
const struct vlc_gl_operations * ops
Definition vlc_opengl.h:124
video_orientation_t orientation
Definition vlc_opengl.h:119
struct vlc_object_t obj
Definition vlc_opengl.h:101
VLC object common members.
Definition vlc_objects.h:53
Definition decoder_device.c:98
Window (desired) configuration.
Definition vlc_window.h:150
Window object.
Definition vlc_window.h:372
User configuration for a video output display (vout_display_t)
Definition vlc_vout_display.h:118
This file is a collection of common definitions and types.
This file defines the elementary streams format types.
video_orientation_t
Picture orientation.
Definition vlc_es.h:181
static int vlc_gl_MakeCurrent(vlc_gl_t *gl)
Definition vlc_opengl.h:149
static void vlc_gl_Swap(vlc_gl_t *gl)
Definition vlc_opengl.h:165
static void vlc_gl_Resize(vlc_gl_t *gl, unsigned w, unsigned h)
Definition vlc_opengl.h:159
vlc_gl_t * vlc_gl_surface_Create(vlc_object_t *, const struct vlc_window_cfg *, struct vlc_window **, const struct vlc_gl_cfg *)
static void vlc_gl_ReleaseCurrent(vlc_gl_t *gl)
Definition vlc_opengl.h:154
static bool vlc_gl_StrHasToken(const char *apis, const char *api)
Definition vlc_opengl.h:206
bool vlc_gl_surface_CheckSize(vlc_gl_t *, unsigned *w, unsigned *h)
static void * vlc_gl_GetProcAddress(vlc_gl_t *gl, const char *name)
Fetch a symbol or pointer function from the OpenGL implementation.
Definition vlc_opengl.h:193
int(* vlc_gl_activate)(vlc_gl_t *, unsigned width, unsigned height, const struct vlc_gl_cfg *cfg)
Definition vlc_opengl.h:60
void vlc_gl_surface_Destroy(vlc_gl_t *)
Definition opengl.c:305
void vlc_gl_Delete(vlc_gl_t *)
Definition opengl.c:175
vlc_gl_t * vlc_gl_Create(const struct vout_display_cfg *cfg, unsigned flags, const char *name, const struct vlc_gl_cfg *gl_cfg)
Creates an OpenGL context (and its underlying surface).
static picture_t * vlc_gl_SwapOffscreen(vlc_gl_t *gl)
Definition vlc_opengl.h:170
vlc_gl_t * vlc_gl_CreateOffscreen(vlc_object_t *parent, struct vlc_decoder_device *device, unsigned width, unsigned height, unsigned flags, const char *name, const struct vlc_gl_cfg *gl_cfg)
Definition opengl.c:114
vlc_gl_api_type
Definition vlc_opengl.h:50
@ VLC_OPENGL
Definition vlc_opengl.h:51
@ VLC_OPENGL_ES2
Definition vlc_opengl.h:52