[vlc-devel] [PATCH v2 10/17] opengl: move callbacks to sampler
Romain Vimont
rom1v at videolabs.io
Thu May 14 15:38:08 CEST 2020
The sampler is responsible to fetch its location and initialize its
textures and uniforms.
---
.../video_output/opengl/fragment_shaders.c | 42 +++++++++----------
modules/video_output/opengl/renderer.c | 10 ++---
modules/video_output/opengl/renderer.h | 27 ------------
modules/video_output/opengl/sampler.h | 27 ++++++++++++
4 files changed, 52 insertions(+), 54 deletions(-)
diff --git a/modules/video_output/opengl/fragment_shaders.c b/modules/video_output/opengl/fragment_shaders.c
index 98e77dbaea7..298837c2631 100644
--- a/modules/video_output/opengl/fragment_shaders.c
+++ b/modules/video_output/opengl/fragment_shaders.c
@@ -205,11 +205,10 @@ renderer_yuv_base_init(struct vlc_gl_renderer *renderer, vlc_fourcc_t chroma,
}
static int
-renderer_base_fetch_locations(struct vlc_gl_renderer *renderer, GLuint program)
+sampler_base_fetch_locations(struct vlc_gl_sampler *sampler, GLuint program)
{
- struct vlc_gl_interop *interop = renderer->interop;
- struct vlc_gl_sampler *sampler = renderer->sampler;
- const opengl_vtable_t *vt = renderer->vt;
+ struct vlc_gl_interop *interop = sampler->interop;
+ const opengl_vtable_t *vt = sampler->vt;
if (sampler->yuv_color)
{
@@ -251,14 +250,13 @@ renderer_base_fetch_locations(struct vlc_gl_renderer *renderer, GLuint program)
}
static void
-renderer_base_prepare_shader(const struct vlc_gl_renderer *renderer,
- const GLsizei *tex_width,
- const GLsizei *tex_height, float alpha)
+sampler_base_prepare_shader(const struct vlc_gl_sampler *sampler,
+ const GLsizei *tex_width,
+ const GLsizei *tex_height, float alpha)
{
(void) tex_width; (void) tex_height;
- const struct vlc_gl_interop *interop = renderer->interop;
- struct vlc_gl_sampler *sampler = renderer->sampler;
- const opengl_vtable_t *vt = renderer->vt;
+ const struct vlc_gl_interop *interop = sampler->interop;
+ const opengl_vtable_t *vt = sampler->vt;
if (sampler->yuv_color)
vt->UniformMatrix4fv(sampler->uloc.ConvMatrix, 1, GL_FALSE,
@@ -311,23 +309,21 @@ renderer_base_prepare_shader(const struct vlc_gl_renderer *renderer,
}
static int
-renderer_xyz12_fetch_locations(struct vlc_gl_renderer *renderer, GLuint program)
+sampler_xyz12_fetch_locations(struct vlc_gl_sampler *sampler, GLuint program)
{
- const opengl_vtable_t *vt = renderer->vt;
- struct vlc_gl_sampler *sampler = renderer->sampler;
+ const opengl_vtable_t *vt = sampler->vt;
sampler->uloc.Texture[0] = vt->GetUniformLocation(program, "Texture0");
return sampler->uloc.Texture[0] != -1 ? VLC_SUCCESS : VLC_EGENERIC;
}
static void
-renderer_xyz12_prepare_shader(const struct vlc_gl_renderer *renderer,
- const GLsizei *tex_width,
- const GLsizei *tex_height, float alpha)
+sampler_xyz12_prepare_shader(const struct vlc_gl_sampler *sampler,
+ const GLsizei *tex_width,
+ const GLsizei *tex_height, float alpha)
{
(void) tex_width; (void) tex_height; (void) alpha;
- const opengl_vtable_t *vt = renderer->vt;
- struct vlc_gl_sampler *sampler = renderer->sampler;
+ const opengl_vtable_t *vt = sampler->vt;
vt->Uniform1i(sampler->uloc.Texture[0], 0);
}
@@ -335,8 +331,10 @@ renderer_xyz12_prepare_shader(const struct vlc_gl_renderer *renderer,
static char *
xyz12_shader_init(struct vlc_gl_renderer *renderer)
{
- renderer->pf_fetch_locations = renderer_xyz12_fetch_locations;
- renderer->pf_prepare_shader = renderer_xyz12_prepare_shader;
+ struct vlc_gl_sampler *sampler = renderer->sampler;
+
+ sampler->pf_fetch_locations = sampler_xyz12_fetch_locations;
+ sampler->pf_prepare_shader = sampler_xyz12_prepare_shader;
/* Shader for XYZ to RGB correction
* 3 steps :
@@ -645,8 +643,8 @@ opengl_fragment_shader_init(struct vlc_gl_renderer *renderer, GLenum tex_target,
if (vlc_memstream_close(&ms) != 0)
return NULL;
- renderer->pf_fetch_locations = renderer_base_fetch_locations;
- renderer->pf_prepare_shader = renderer_base_prepare_shader;
+ sampler->pf_fetch_locations = sampler_base_fetch_locations;
+ sampler->pf_prepare_shader = sampler_base_prepare_shader;
return ms.ptr;
}
diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index c8d1d3170da..81655b92ea4 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -327,8 +327,8 @@ opengl_link_program(struct vlc_gl_renderer *renderer)
assert(interop->tex_target != 0 &&
interop->tex_count > 0 &&
interop->ops->update_textures != NULL &&
- renderer->pf_fetch_locations != NULL &&
- renderer->pf_prepare_shader != NULL);
+ sampler->pf_fetch_locations != NULL &&
+ sampler->pf_prepare_shader != NULL);
GLuint program_id =
vlc_gl_BuildProgram(VLC_OBJECT(renderer->gl), vt,
@@ -375,7 +375,7 @@ opengl_link_program(struct vlc_gl_renderer *renderer)
#undef GET_ULOC
#undef GET_ALOC
#undef GET_SAMPLER_ULOC
- int ret = renderer->pf_fetch_locations(renderer, program_id);
+ int ret = sampler->pf_fetch_locations(sampler, program_id);
assert(ret == VLC_SUCCESS);
if (ret != VLC_SUCCESS)
{
@@ -846,8 +846,8 @@ static void DrawWithShaders(struct vlc_gl_renderer *renderer)
const struct vlc_gl_interop *interop = renderer->interop;
struct vlc_gl_sampler *sampler = renderer->sampler;
const opengl_vtable_t *vt = renderer->vt;
- renderer->pf_prepare_shader(renderer, sampler->tex_width,
- sampler->tex_height, 1.0f);
+ sampler->pf_prepare_shader(sampler, sampler->tex_width,
+ sampler->tex_height, 1.0f);
for (unsigned j = 0; j < interop->tex_count; j++) {
assert(sampler->textures[j] != 0);
diff --git a/modules/video_output/opengl/renderer.h b/modules/video_output/opengl/renderer.h
index 51508346030..a75db93d05f 100644
--- a/modules/video_output/opengl/renderer.h
+++ b/modules/video_output/opengl/renderer.h
@@ -96,33 +96,6 @@ struct vlc_gl_renderer
float f_fovy; /* to avoid recalculating them when needed. */
float f_z; /* Position of the camera on the shpere radius vector */
float f_sar;
-
- /**
- * Callback to fetch locations of uniform or attributes variables
- *
- * This function pointer cannot be NULL. This callback is called one time
- * after init.
- *
- * \param renderer OpenGL renderer
- * \param program linked program that will be used by this renderer
- * \return VLC_SUCCESS or a VLC error
- */
- int (*pf_fetch_locations)(struct vlc_gl_renderer *renderer, GLuint program);
-
- /**
- * Callback to prepare the fragment shader
- *
- * This function pointer cannot be NULL. This callback can be used to
- * specify values of uniform variables.
- *
- * \param renderer OpenGL renderer
- * \param tex_width array of tex width (one per plane)
- * \param tex_height array of tex height (one per plane)
- * \param alpha alpha value, used only for RGBA fragment shader
- */
- void (*pf_prepare_shader)(const struct vlc_gl_renderer *renderer,
- const GLsizei *tex_width, const GLsizei *tex_height,
- float alpha);
};
/**
diff --git a/modules/video_output/opengl/sampler.h b/modules/video_output/opengl/sampler.h
index 1211f29953d..c021ce8edf3 100644
--- a/modules/video_output/opengl/sampler.h
+++ b/modules/video_output/opengl/sampler.h
@@ -90,6 +90,33 @@ struct vlc_gl_sampler {
} last_source;
struct vlc_gl_interop *interop;
+
+ /**
+ * Callback to fetch locations of uniform or attributes variables
+ *
+ * This function pointer cannot be NULL. This callback is called one time
+ * after init.
+ *
+ * \param sampler the sampler
+ * \param program linked program that will be used by this sampler
+ * \return VLC_SUCCESS or a VLC error
+ */
+ int (*pf_fetch_locations)(struct vlc_gl_sampler *sampler, GLuint program);
+
+ /**
+ * Callback to prepare the fragment shader
+ *
+ * This function pointer cannot be NULL. This callback can be used to
+ * specify values of uniform variables.
+ *
+ * \param sampler the sampler
+ * \param tex_width array of tex width (one per plane)
+ * \param tex_height array of tex height (one per plane)
+ * \param alpha alpha value, used only for RGBA fragment shader
+ */
+ void (*pf_prepare_shader)(const struct vlc_gl_sampler *sampler,
+ const GLsizei *tex_width, const GLsizei *tex_height,
+ float alpha);
};
/**
--
2.26.2
More information about the vlc-devel
mailing list