[vlc-devel] [PATCH 06/10] opengl: group sampler callbacks into struct ops
Romain Vimont
rom1v at videolabs.io
Thu Jun 4 11:52:14 CEST 2020
This makes explicit that these functions are set by the sampler
implementation and must be called by the user of sampler.
---
modules/video_output/opengl/renderer.c | 5 +++--
modules/video_output/opengl/sampler.c | 14 ++++++++++----
modules/video_output/opengl/sampler.h | 14 ++++++++++----
3 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index 0f6a7ba73f15..aa10d1f8bba6 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -247,8 +247,9 @@ opengl_link_program(struct vlc_gl_renderer *renderer)
return VLC_EGENERIC;
}
- assert(sampler->pf_fetch_locations != NULL &&
- sampler->pf_prepare_shader != NULL);
+ assert(sampler->ops &&
+ sampler->ops->fetch_locations &&
+ sampler->ops->prepare_shader);
GLuint program_id =
vlc_gl_BuildProgram(VLC_OBJECT(renderer->gl), vt,
diff --git a/modules/video_output/opengl/sampler.c b/modules/video_output/opengl/sampler.c
index e7e4d0b49ef9..6a7f75fcb689 100644
--- a/modules/video_output/opengl/sampler.c
+++ b/modules/video_output/opengl/sampler.c
@@ -434,8 +434,11 @@ sampler_xyz12_prepare_shader(const struct vlc_gl_sampler *sampler)
static int
xyz12_shader_init(struct vlc_gl_sampler *sampler)
{
- sampler->pf_fetch_locations = sampler_xyz12_fetch_locations;
- sampler->pf_prepare_shader = sampler_xyz12_prepare_shader;
+ static const struct vlc_gl_sampler_ops ops = {
+ .fetch_locations = sampler_xyz12_fetch_locations,
+ .prepare_shader = sampler_xyz12_prepare_shader,
+ };
+ sampler->ops = &ops;
/* Shader for XYZ to RGB correction
* 3 steps :
@@ -833,8 +836,11 @@ opengl_fragment_shader_init(struct vlc_gl_sampler *sampler, GLenum tex_target,
}
sampler->shader.body = ms.ptr;
- sampler->pf_fetch_locations = sampler_base_fetch_locations;
- sampler->pf_prepare_shader = sampler_base_prepare_shader;
+ static const struct vlc_gl_sampler_ops ops = {
+ .fetch_locations = sampler_base_fetch_locations,
+ .prepare_shader = sampler_base_prepare_shader,
+ };
+ sampler->ops = &ops;
return VLC_SUCCESS;
}
diff --git a/modules/video_output/opengl/sampler.h b/modules/video_output/opengl/sampler.h
index f26820bfaba3..9eec40149087 100644
--- a/modules/video_output/opengl/sampler.h
+++ b/modules/video_output/opengl/sampler.h
@@ -77,6 +77,10 @@ struct vlc_gl_sampler {
char *body;
} shader;
+ const struct vlc_gl_sampler_ops *ops;
+};
+
+struct vlc_gl_sampler_ops {
/**
* Callback to fetch locations of uniform or attributes variables
*
@@ -86,7 +90,8 @@ struct vlc_gl_sampler {
* \param sampler the sampler
* \param program linked program that will be used by this sampler
*/
- void (*pf_fetch_locations)(struct vlc_gl_sampler *sampler, GLuint program);
+ void
+ (*fetch_locations)(struct vlc_gl_sampler *sampler, GLuint program);
/**
* Callback to prepare the fragment shader
@@ -96,19 +101,20 @@ struct vlc_gl_sampler {
*
* \param sampler the sampler
*/
- void (*pf_prepare_shader)(const struct vlc_gl_sampler *sampler);
+ void
+ (*prepare_shader)(const struct vlc_gl_sampler *sampler);
};
static inline void
vlc_gl_sampler_FetchLocations(struct vlc_gl_sampler *sampler, GLuint program)
{
- sampler->pf_fetch_locations(sampler, program);
+ sampler->ops->fetch_locations(sampler, program);
}
static inline void
vlc_gl_sampler_PrepareShader(const struct vlc_gl_sampler *sampler)
{
- sampler->pf_prepare_shader(sampler);
+ sampler->ops->prepare_shader(sampler);
}
#endif
--
2.27.0
More information about the vlc-devel
mailing list