opengl: expose npot support in gl_api
[vlc.git] / modules / video_output / opengl / renderer.h
blob913a8c8e6e8d29584467af685bf3c47f9b1b43c2
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 dump_shaders indicate if the shaders must be dumped in logs
163 struct vlc_gl_renderer *
164 vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
165 vlc_video_context *context, const video_format_t *fmt,
166 bool dump_shaders);
169 * Delete a renderer
171 * \param renderer the renderer
173 void
174 vlc_gl_renderer_Delete(struct vlc_gl_renderer *renderer);
177 * Prepare the fragment shader
179 * Concretely, it allocates OpenGL textures if necessary and uploads the
180 * picture.
182 * \param sr the renderer
183 * \param subpicture the subpicture to render
186 vlc_gl_renderer_Prepare(struct vlc_gl_renderer *renderer, picture_t *picture);
189 * Draw the prepared picture
191 * \param sr the renderer
194 vlc_gl_renderer_Draw(struct vlc_gl_renderer *renderer,
195 const video_format_t *source);
198 vlc_gl_renderer_SetViewpoint(struct vlc_gl_renderer *renderer,
199 const vlc_viewpoint_t *p_vp);
201 void
202 vlc_gl_renderer_SetWindowAspectRatio(struct vlc_gl_renderer *renderer,
203 float f_sar);
205 #endif /* include-guard */