VLC 4.0.0-dev
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# ifdef __cplusplus
28extern "C" {
29# endif
30
31/**
32 * \file
33 * This file defines GL structures and functions.
34 */
35
36struct vlc_window;
37struct vlc_window_cfg;
38struct vout_display_cfg;
39
40/**
41 * A VLC GL context (and its underlying surface)
42 */
43typedef struct vlc_gl_t vlc_gl_t;
46
47enum vlc_gl_api_type {
50};
51
52struct vlc_gl_cfg
54 bool need_alpha; /* False by default */
55};
56
57typedef int (*vlc_gl_activate)(vlc_gl_t *, unsigned width, unsigned height,
58 const struct vlc_gl_cfg *cfg);
59
60#define set_callback_opengl_common(activate) \
61 { \
62 vlc_gl_activate activate__ = activate; \
63 (void) activate__; \
64 set_callback(activate) \
65 } \
66
67#define set_callback_opengl(activate, priority) \
68 set_callback_opengl_common(activate) \
69 set_capability("opengl", priority)
70
71#define set_callback_opengl_offscreen(activate, priority) \
72 set_callback_opengl_common(activate) \
73 set_capability("opengl offscreen", priority)
74
75#define set_callback_opengl_es2(activate, priority) \
76 set_callback_opengl_common(activate) \
77 set_capability("opengl es2", priority)
78
79#define set_callback_opengl_es2_offscreen(activate, priority) \
80 set_callback_opengl_common(activate) \
81 set_capability("opengl es2 offscreen", priority)
82
85 union {
86 void (*swap)(vlc_gl_t *);
87 picture_t *(*swap_offscreen)(vlc_gl_t *);
88 };
89 int (*make_current)(vlc_gl_t *gl);
91 void (*resize)(vlc_gl_t *gl, unsigned width, unsigned height);
92 void*(*get_proc_address)(vlc_gl_t *gl, const char *symbol);
93 void (*close)(vlc_gl_t *gl);
94};
95
96struct vlc_gl_t
98 struct vlc_object_t obj;
101 void *sys;
104 union {
105 struct { /* on-screen */
106 struct vlc_window *surface;
107 };
108 struct { /* off-screen */
111 /* Flag to indicate if the OpenGL implementation produces upside-down
112 * pictures */
113 bool offscreen_vflip;
114 };
115 };
116
117 /* Defined by the core for libvlc_opengl API loading. */
120 const struct vlc_gl_operations *ops;
122
123/**
124 * Creates an OpenGL context (and its underlying surface).
125 *
126 * @note In most cases, you should vlc_gl_MakeCurrent() afterward.
127 *
128 * @param cfg initial configuration (including window to use as OpenGL surface)
129 * @param flags OpenGL context type
130 * @param name module name (or NULL for auto)
131 * @param gl_cfg OpenGL configuration (or NULL for default)
132 * @return a new context, or NULL on failure
133 */
135 unsigned flags, const char *name,
136 const struct vlc_gl_cfg *gl_cfg) VLC_USED;
138 struct vlc_decoder_device *device,
139 unsigned width, unsigned height,
140 unsigned flags, const char *name,
141 const struct vlc_gl_cfg *gl_cfg);
142
144
145static inline int vlc_gl_MakeCurrent(vlc_gl_t *gl)
147 return gl->ops->make_current(gl);
148}
149
150static inline void vlc_gl_ReleaseCurrent(vlc_gl_t *gl)
152 gl->ops->release_current(gl);
153}
154
155static inline void vlc_gl_Resize(vlc_gl_t *gl, unsigned w, unsigned h)
157 if (gl->ops->resize != NULL)
158 gl->ops->resize(gl, w, h);
159}
160
161static inline void vlc_gl_Swap(vlc_gl_t *gl)
163 gl->ops->swap(gl);
164}
165
166static inline picture_t *vlc_gl_SwapOffscreen(vlc_gl_t *gl)
168 return gl->ops->swap_offscreen(gl);
169}
170
171/**
172 * Fetch a symbol or pointer function from the OpenGL implementation.
173 *
174 * Return a pointer from the OpenGL implementation, which can be part of
175 * either the underlying OpenGL provider or an OpenGL function matching
176 * the version requested.
177 *
178 * If the symbol name is not matching the underlying implementation of
179 * OpenGL, an invalid pointer or NULL can be returned.
180 *
181 * @note This function must be called between MakeCurrent and ReleaseCurrent.
182 *
183 * @param gl the OpenGL provider to fetch the function from
184 * @param name the symbol name to fetch from the implementation
185 *
186 * @return A pointer corresponding to the symbol, or a potentially invalid
187 * value or NULL in case of error.
188 */
189static inline void *vlc_gl_GetProcAddress(vlc_gl_t *gl, const char *name)
191 return gl->ops->get_proc_address(gl, name);
192}
193
195 const struct vlc_window_cfg *,
196 struct vlc_window **,
197 const struct vlc_gl_cfg *) VLC_USED;
198
199VLC_API bool vlc_gl_surface_CheckSize(vlc_gl_t *, unsigned *w, unsigned *h);
201
202static inline bool vlc_gl_StrHasToken(const char *apis, const char *api)
204 size_t apilen = strlen(api);
205 while (apis) {
206 while (*apis == ' ')
207 apis++;
208 if (!strncmp(apis, api, apilen) && memchr(" ", apis[apilen], 2))
209 return true;
210 apis = strchr(apis, ' ');
211 }
212 return false;
213}
214
215#ifdef __cplusplus
216}
217#endif /* C++ */
218
219#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:1281
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:54
bool need_alpha
Definition: vlc_opengl.h:55
Definition: vlc_opengl.h:85
void *(* get_proc_address)(vlc_gl_t *gl, const char *symbol)
Definition: vlc_opengl.h:93
void(* swap)(vlc_gl_t *)
Definition: vlc_opengl.h:87
picture_t *(* swap_offscreen)(vlc_gl_t *)
Definition: vlc_opengl.h:88
void(* resize)(vlc_gl_t *gl, unsigned width, unsigned height)
Definition: vlc_opengl.h:92
int(* make_current)(vlc_gl_t *gl)
Definition: vlc_opengl.h:90
void(* release_current)(vlc_gl_t *gl)
Definition: vlc_opengl.h:91
void(* close)(vlc_gl_t *gl)
Definition: vlc_opengl.h:94
Definition: vlc_opengl.h:98
vlc_fourcc_t offscreen_chroma_out
Definition: vlc_opengl.h:110
enum vlc_gl_api_type api_type
Definition: vlc_opengl.h:119
struct vlc_video_context * offscreen_vctx_out
Definition: vlc_opengl.h:111
void * sys
Definition: vlc_opengl.h:102
struct vlc_window * surface
Definition: vlc_opengl.h:107
struct vlc_decoder_device * device
Definition: vlc_opengl.h:104
bool offscreen_vflip
Definition: vlc_opengl.h:114
module_t * module
Definition: vlc_opengl.h:101
const struct vlc_gl_operations * ops
Definition: vlc_opengl.h:121
struct vlc_object_t obj
Definition: vlc_opengl.h:99
VLC object common members.
Definition: vlc_objects.h:45
Definition: decoder_device.c:97
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:116
This file is a collection of common definitions and types.
static int vlc_gl_MakeCurrent(vlc_gl_t *gl)
Definition: vlc_opengl.h:146
static void vlc_gl_Swap(vlc_gl_t *gl)
Definition: vlc_opengl.h:162
static void vlc_gl_Resize(vlc_gl_t *gl, unsigned w, unsigned h)
Definition: vlc_opengl.h:156
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:151
static bool vlc_gl_StrHasToken(const char *apis, const char *api)
Definition: vlc_opengl.h:203
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:190
int(* vlc_gl_activate)(vlc_gl_t *, unsigned width, unsigned height, const struct vlc_gl_cfg *cfg)
Definition: vlc_opengl.h:58
void vlc_gl_surface_Destroy(vlc_gl_t *)
Definition: opengl.c:304
void vlc_gl_Delete(vlc_gl_t *)
Definition: opengl.c:174
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:167
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:113
vlc_gl_api_type
Definition: vlc_opengl.h:48
@ VLC_OPENGL
Definition: vlc_opengl.h:49
@ VLC_OPENGL_ES2
Definition: vlc_opengl.h:50