VLC 4.0.0-dev
Loading...
Searching...
No Matches
vlc_opengl_sampler.h
Go to the documentation of this file.
1/*****************************************************************************
2 * vlc_opengl_sampler.h: VLC OpenGL sampler API
3 *****************************************************************************
4 * Copyright (C) 2020-2026 VLC authors and VideoLAN
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
20
21#ifndef VLC_GL_SAMPLER_H
22#define VLC_GL_SAMPLER_H 1
23
24#include <stdint.h>
25#include <vlc_es.h>
26#include <vlc_picture.h>
27#include <vlc_opengl_picture.h>
28
29/**
30 * \file
31 * This file defines the public OpenGL sampler interface.
32 *
33 * The purpose of a sampler is to provide pixel values of a VLC input picture,
34 * stored in any format.
35 *
36 * Concretely, a GLSL function:
37 *
38 * vec4 vlc_texture(vec2 coords)
39 *
40 * returns the RGBA values for the given coordinates.
41 *
42 * Contrary to the standard GLSL function:
43 *
44 * vec4 texture2D(sampler2D sampler, vec2 coords)
45 *
46 * it does not take a sampler2D as parameter. The role of the sampler is to
47 * abstract the input picture from the filter, so the input picture is
48 * implicitly available.
49 */
50
51struct vlc_gl_sampler;
52
53struct vlc_gl_sampler_ops {
54 /**
55 * Callback to fetch locations of uniform or attribute variables
56 *
57 * This function pointer cannot be NULL. This callback is called one time
58 * after the program is linked.
59 *
60 * \param sampler the sampler
61 * \param program the linked GL program handle
62 */
63 void (*fetch_locations)(struct vlc_gl_sampler *sampler, uint32_t program);
65 /**
66 * Callback to load sampler data
67 *
68 * This function pointer cannot be NULL. This callback can be used to
69 * specify values of uniform variables.
70 *
71 * \param sampler the sampler
72 */
73 void (*load)(struct vlc_gl_sampler *sampler);
75 /**
76 * Update the input picture
77 *
78 * \param sampler the sampler
79 * \param picture the OpenGL picture
80 * \return VLC_SUCCESS or a VLC error
81 */
82 int (*update)(struct vlc_gl_sampler *sampler,
83 const struct vlc_gl_picture *picture);
84
85 /**
86 * Select the plane to expose
87 *
88 * If the sampler exposes planes separately (for plane filters), select the
89 * plane to expose via the GLSL function vlc_texture().
90 *
91 * \param sampler the sampler
92 * \param plane the plane number
93 */
94 void (*select_plane)(struct vlc_gl_sampler *sampler, unsigned plane);
96 /**
97 * Close the sampler, releasing resources
98 *
99 * \param sampler the sampler
100 */
101 void (*close)(struct vlc_gl_sampler *sampler);
103
104/**
105 * OpenGL sampler
106 *
107 * Generates GLSL code for sampling input textures and handles chroma
108 * conversion, transfer functions, and color space mapping.
109 */
110struct vlc_gl_sampler {
114 /** OpenGL context */
115 struct vlc_gl_t *gl;
117 /** Input video format */
120 /** Number of texture planes */
121 unsigned tex_count;
123 /** Per-plane texture widths */
126 /** Per-plane texture heights */
129 /** GL texture target (e.g. GL_TEXTURE_2D) */
130 uint32_t tex_target;
132 /** Per-plane GL format (GLenum values) */
133 uint32_t formats[PICTURE_PLANE_MAX];
135 /** Whether textures use half-float storage */
136 bool half_float;
138 /**
139 * Matrix to convert from picture coordinates to texture coordinates
140 *
141 * The matrix is 2x3 and is stored in column-major order:
142 *
143 * / a b c \
144 * \ d e f /
145 *
146 * It is stored as an array of 6 floats:
147 *
148 * [a, d, b, e, c, f]
149 *
150 * It is NULL before the first picture is available and may theoretically
151 * change on every picture.
152 */
153 const float *pic_to_tex_matrix;
155 struct {
156 /**
157 * Version header appropriate for this shader.
158 */
159 char *version;
161 /**
162 * Precision preamble appropriate for this shader.
163 */
164 char *precision;
166 /**
167 * Piece of fragment shader code declaring OpenGL extensions.
168 *
169 * It is initialized by the sampler, and may be NULL if no extensions
170 * are required.
171 *
172 * If non-NULL, users of this sampler must inject this code into their
173 * fragment shader, immediately after the "version" line.
174 */
175 char *extensions;
177 /**
178 * Piece of fragment shader code providing the GLSL function
179 * vlc_texture(vec2 coords).
180 *
181 * It is initialized by the sampler, and is never NULL.
182 *
183 * Users of this sampler should inject this code into their fragment
184 * shader, before any call to vlc_texture().
185 */
186 char *body;
189 const struct vlc_gl_sampler_ops *ops;
191 /** Private data for the sampler implementation */
192 void *sys;
194
195static inline void
196vlc_gl_sampler_FetchLocations(struct vlc_gl_sampler *sampler, uint32_t program)
198 sampler->ops->fetch_locations(sampler, program);
199}
200
201static inline void
202vlc_gl_sampler_Load(struct vlc_gl_sampler *sampler)
204 sampler->ops->load(sampler);
205}
206
207static inline int
209 const struct vlc_gl_picture *picture)
210{
211 return sampler->ops->update(sampler, picture);
212}
213
214static inline void
215vlc_gl_sampler_SelectPlane(struct vlc_gl_sampler *sampler, unsigned plane)
217 sampler->ops->select_plane(sampler, plane);
218}
219
220/**
221 * Activation function for OpenGL sampler module implementations.
222 *
223 * The input format is described by the public fields of the sampler object
224 * which are populated before the module is loaded.
225 *
226 * \param sampler the sampler
227 * \param expose_planes if set, vlc_texture() exposes a single plane at a time
228 *
229 * \return VLC_SUCCESS when the module can be opened
230 */
231typedef int
232vlc_gl_sampler_open_fn(struct vlc_gl_sampler *sampler, bool expose_planes);
234#define set_callback_opengl_sampler(open) \
235 { \
236 vlc_gl_sampler_open_fn *fn = open; \
237 (void) fn; \
238 set_callback(fn); \
239 }
240
241#endif /* VLC_GL_SAMPLER_H */
#define PICTURE_PLANE_MAX
Maximum number of plane for a picture.
Definition vlc_picture.h:67
Internal module descriptor.
Definition modules.h:76
video format description
Definition vlc_es.h:337
An OpenGL picture state, with textures and a coordinate transformation matrix.
Definition vlc_opengl_picture.h:40
Definition vlc_opengl_sampler.h:54
int(* update)(struct vlc_gl_sampler *sampler, const struct vlc_gl_picture *picture)
Update the input picture.
Definition vlc_opengl_sampler.h:83
void(* select_plane)(struct vlc_gl_sampler *sampler, unsigned plane)
Select the plane to expose.
Definition vlc_opengl_sampler.h:95
void(* close)(struct vlc_gl_sampler *sampler)
Close the sampler, releasing resources.
Definition vlc_opengl_sampler.h:102
void(* fetch_locations)(struct vlc_gl_sampler *sampler, uint32_t program)
Callback to fetch locations of uniform or attribute variables.
Definition vlc_opengl_sampler.h:64
void(* load)(struct vlc_gl_sampler *sampler)
Callback to load sampler data.
Definition vlc_opengl_sampler.h:74
OpenGL sampler.
Definition vlc_opengl_sampler.h:111
unsigned tex_count
Number of texture planes.
Definition vlc_opengl_sampler.h:122
struct vlc_gl_sampler::@027113026266275344074003175020250126365045174031 shader
video_format_t fmt_in
Input video format.
Definition vlc_opengl_sampler.h:119
void * sys
Private data for the sampler implementation.
Definition vlc_opengl_sampler.h:193
uint32_t tex_target
GL texture target (e.g.
Definition vlc_opengl_sampler.h:131
int32_t tex_heights[(5)]
Per-plane texture heights.
Definition vlc_opengl_sampler.h:128
int32_t tex_widths[(5)]
Per-plane texture widths.
Definition vlc_opengl_sampler.h:125
vlc_object_t obj
Definition vlc_opengl_sampler.h:112
char * version
Version header appropriate for this shader.
Definition vlc_opengl_sampler.h:160
char * extensions
Piece of fragment shader code declaring OpenGL extensions.
Definition vlc_opengl_sampler.h:176
struct vlc_gl_t * gl
OpenGL context.
Definition vlc_opengl_sampler.h:116
char * precision
Precision preamble appropriate for this shader.
Definition vlc_opengl_sampler.h:165
char * body
Piece of fragment shader code providing the GLSL function vlc_texture(vec2 coords).
Definition vlc_opengl_sampler.h:187
module_t * module
Definition vlc_opengl_sampler.h:113
uint32_t formats[(5)]
Per-plane GL format (GLenum values).
Definition vlc_opengl_sampler.h:134
bool half_float
Whether textures use half-float storage.
Definition vlc_opengl_sampler.h:137
const float * pic_to_tex_matrix
Matrix to convert from picture coordinates to texture coordinates.
Definition vlc_opengl_sampler.h:154
const struct vlc_gl_sampler_ops * ops
Definition vlc_opengl_sampler.h:190
Definition vlc_opengl.h:100
VLC object common members.
Definition vlc_objects.h:53
This file is a collection of common definitions and types.
This file defines the elementary streams format types.
This file defines the public OpenGL picture interface.
static int vlc_gl_sampler_Update(struct vlc_gl_sampler *sampler, const struct vlc_gl_picture *picture)
Definition vlc_opengl_sampler.h:209
static void vlc_gl_sampler_Load(struct vlc_gl_sampler *sampler)
Definition vlc_opengl_sampler.h:203
static void vlc_gl_sampler_FetchLocations(struct vlc_gl_sampler *sampler, uint32_t program)
Definition vlc_opengl_sampler.h:197
static void vlc_gl_sampler_SelectPlane(struct vlc_gl_sampler *sampler, unsigned plane)
Definition vlc_opengl_sampler.h:216
int vlc_gl_sampler_open_fn(struct vlc_gl_sampler *sampler, bool expose_planes)
Activation function for OpenGL sampler module implementations.
Definition vlc_opengl_sampler.h:233
This file defines picture structures and functions in vlc.