[vlc-devel] [PATCH 14/41] opengl: extract vlc_texture()
Romain Vimont
rom1v at videolabs.io
Fri Feb 7 17:42:00 CET 2020
Extract a fragment shader function to provide the pixel color of a
picture from pictures coordinates.
Concretely, it replaces:
void main(void) {
vec3 pic_hcoords = vec3(PicCoords, 1.0);
...
gl_FragColor = result * FillColor;
}
by:
vec4 vlc_texture(vec2 pic_coords) {
vec3 pic_hcoords = vec3(pic_coords, 1.0);
...
return result * FillColor;
}
void main() {
gl_FragColor = vlc_texture(PicCoords);
}
---
.../video_output/opengl/fragment_shaders.c | 31 ++++++++++++-------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/modules/video_output/opengl/fragment_shaders.c b/modules/video_output/opengl/fragment_shaders.c
index 51c5ca6055..9d148028ba 100644
--- a/modules/video_output/opengl/fragment_shaders.c
+++ b/modules/video_output/opengl/fragment_shaders.c
@@ -350,16 +350,19 @@ xyz12_shader_init(struct vlc_gl_renderer *renderer)
" );"
"varying vec2 PicCoords;"
- "void main()"
+ "vec4 vlc_texture(vec2 pic_coords)\n"
"{ "
" vec4 v_in, v_out;"
- " v_in = texture2D(Texture0, PicCoords);"
+ " v_in = texture2D(Texture0, pic_coords);"
" v_in = pow(v_in, xyz_gamma);"
" v_out = matrix_xyz_rgb * v_in ;"
" v_out = pow(v_out, rgb_gamma) ;"
" v_out = clamp(v_out, 0.0, 1.0) ;"
- " gl_FragColor = v_out;"
- "}";
+ " return v_out;"
+ "}\n"
+ "void main() {\n"
+ " gl_FragColor = vlc_texture(PicCoords);\n"
+ "}\n";
char *code;
if (asprintf(&code, template, renderer->glsl_version,
@@ -589,12 +592,12 @@ opengl_fragment_shader_init(struct vlc_gl_renderer *renderer, GLenum tex_target,
ADD("uniform mat4 ConvMatrix;\n");
ADD("uniform vec4 FillColor;\n"
- "void main(void) {\n");
- /* Oriented picture coordinates */
- ADDF(" vec2 pic_txcoords = (TransformMatrix * OrientationMatrix * vec4(%s, 0.0, 1.0)).st;\n", coord_name);
- /* Homogeneous coordinates */
- ADD(" vec3 pic_hcoords = vec3(pic_txcoords, 1.0);\n");
- ADD(" vec2 tex_coords;\n");
+ "vec4 vlc_texture(vec2 pic_coords) {\n"
+ /* Oriented picture coordinates */
+ " vec2 pic_txcoords = (TransformMatrix * OrientationMatrix * vec4(pic_coords, 0.0, 1.0)).st;\n"
+ /* Homogeneous coords */
+ " vec3 pic_hcoords = vec3(pic_txcoords, 1.0);\n"
+ " vec2 tex_coords;\n");
if (tex_target == GL_TEXTURE_RECTANGLE)
{
@@ -645,8 +648,12 @@ opengl_fragment_shader_init(struct vlc_gl_renderer *renderer, GLenum tex_target,
}
#endif
- ADD(" gl_FragColor = result * FillColor;\n"
- "}");
+ ADD(" return result * FillColor;\n"
+ "}\n");
+
+ ADDF("void main() {\n"
+ " gl_FragColor = vlc_texture(%s);\n"
+ "}\n", coord_name);
#undef ADD
#undef ADDF
--
2.25.0
More information about the vlc-devel
mailing list