opengl: pass vlc_gl_api instead of virtual table
[vlc.git] / modules / video_output / opengl / renderer.h
blobe161e7eb52ae48ed3421fe22aaa38252da78bbf3
1 /*****************************************************************************
2 * renderer.h: OpenGL internal header
3 *****************************************************************************
4 * Copyright (C) 2016 VLC authors and VideoLAN
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.
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.
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 *****************************************************************************/
21 #ifndef VLC_GL_RENDERER_H
22 #define VLC_GL_RENDERER_H
24 #include <vlc_common.h>
25 #include <vlc_codec.h>
26 #include <vlc_opengl.h>
27 #include <vlc_plugin.h>
29 #include "gl_api.h"
30 #include "gl_common.h"
31 #include "interop.h"
33 struct pl_context;
34 struct pl_shader;
35 struct pl_shader_res;
37 /**
38 * OpenGL picture renderer
40 struct vlc_gl_renderer
42 /* Pointer to object gl, set by the caller */
43 vlc_gl_t *gl;
45 /* libplacebo context, created by the caller (optional) */
46 struct pl_context *pl_ctx;
48 /* Set by the caller */
49 const struct vlc_gl_api *api;
50 const opengl_vtable_t *vt; /* for convenience, same as &api->vt */
52 /* True to dump shaders, set by the caller */
53 bool b_dump_shaders;
55 /* GLSL version, set by the caller. 100 for GLSL ES, 120 for desktop GLSL */
56 unsigned glsl_version;
57 /* Precision header, set by the caller. In OpenGLES, the fragment language
58 * has no default precision qualifier for floating point types. */
59 const char *glsl_precision_header;
61 GLuint program_id;
63 struct {
64 GLfloat OrientationMatrix[16];
65 GLfloat ProjectionMatrix[16];
66 GLfloat ZoomMatrix[16];
67 GLfloat ViewMatrix[16];
68 } var;
70 struct {
71 GLint Texture[PICTURE_PLANE_MAX];
72 GLint TexSize[PICTURE_PLANE_MAX]; /* for GL_TEXTURE_RECTANGLE */
73 GLint ConvMatrix;
74 GLint FillColor;
75 GLint *pl_vars; /* for pl_sh_res */
77 GLint TransformMatrix;
78 GLint OrientationMatrix;
79 GLint ProjectionMatrix;
80 GLint ViewMatrix;
81 GLint ZoomMatrix;
82 } uloc;
84 struct {
85 GLint MultiTexCoord[3];
86 GLint VertexPosition;
87 } aloc;
89 bool yuv_color;
90 GLfloat conv_matrix[16];
92 struct pl_shader *pl_sh;
93 const struct pl_shader_res *pl_sh_res;
95 struct vlc_gl_interop *interop;
97 video_format_t fmt;
99 GLsizei tex_width[PICTURE_PLANE_MAX];
100 GLsizei tex_height[PICTURE_PLANE_MAX];
102 GLuint textures[PICTURE_PLANE_MAX];
104 unsigned nb_indices;
105 GLuint vertex_buffer_object;
106 GLuint index_buffer_object;
107 GLuint texture_buffer_object[PICTURE_PLANE_MAX];
109 struct {
110 unsigned int i_x_offset;
111 unsigned int i_y_offset;
112 unsigned int i_visible_width;
113 unsigned int i_visible_height;
114 } last_source;
116 /* View point */
117 vlc_viewpoint_t vp;
118 float f_teta;
119 float f_phi;
120 float f_roll;
121 float f_fovx; /* f_fovx and f_fovy are linked but we keep both */
122 float f_fovy; /* to avoid recalculating them when needed. */
123 float f_z; /* Position of the camera on the shpere radius vector */
124 float f_sar;
127 * Callback to fetch locations of uniform or attributes variables
129 * This function pointer cannot be NULL. This callback is called one time
130 * after init.
132 * \param renderer OpenGL renderer
133 * \param program linked program that will be used by this renderer
134 * \return VLC_SUCCESS or a VLC error
136 int (*pf_fetch_locations)(struct vlc_gl_renderer *renderer, GLuint program);
139 * Callback to prepare the fragment shader
141 * This function pointer cannot be NULL. This callback can be used to
142 * specify values of uniform variables.
144 * \param renderer OpenGL renderer
145 * \param tex_width array of tex width (one per plane)
146 * \param tex_height array of tex height (one per plane)
147 * \param alpha alpha value, used only for RGBA fragment shader
149 void (*pf_prepare_shader)(const struct vlc_gl_renderer *renderer,
150 const GLsizei *tex_width, const GLsizei *tex_height,
151 float alpha);
155 * Create a new renderer
157 * \param gl the GL context
158 * \param api the OpenGL API
159 * \param context the video context
160 * \param fmt the video format
161 * \param supports_npot indicate if the implementation supports non-power-of-2
162 * texture size
163 * \param dump_shaders indicate if the shaders must be dumped in logs
165 struct vlc_gl_renderer *
166 vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
167 vlc_video_context *context, const video_format_t *fmt,
168 bool supports_npot, bool dump_shaders);
171 * Delete a renderer
173 * \param renderer the renderer
175 void
176 vlc_gl_renderer_Delete(struct vlc_gl_renderer *renderer);
179 * Prepare the fragment shader
181 * Concretely, it allocates OpenGL textures if necessary and uploads the
182 * picture.
184 * \param sr the renderer
185 * \param subpicture the subpicture to render
188 vlc_gl_renderer_Prepare(struct vlc_gl_renderer *renderer, picture_t *picture);
191 * Draw the prepared picture
193 * \param sr the renderer
196 vlc_gl_renderer_Draw(struct vlc_gl_renderer *renderer,
197 const video_format_t *source);
200 vlc_gl_renderer_SetViewpoint(struct vlc_gl_renderer *renderer,
201 const vlc_viewpoint_t *p_vp);
203 void
204 vlc_gl_renderer_SetWindowAspectRatio(struct vlc_gl_renderer *renderer,
205 float f_sar);
207 #endif /* include-guard */