mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-25 11:11:08 +00:00
qml/glsink: also support GLES2 needing shader 'precision' directives
Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3616 Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7125>
This commit is contained in:
parent
df62e71289
commit
d705966861
1 changed files with 12 additions and 7 deletions
|
@ -255,6 +255,9 @@ vertexShaderForFormat(GstVideoFormat v_format)
|
|||
"attribute vec4 " ATTRIBUTE_POSITION ";\n" \
|
||||
"attribute vec2 " ATTRIBUTE_TEXCOORD ";\n" \
|
||||
|
||||
#define gles2_precision \
|
||||
"precision mediump float;\n"
|
||||
|
||||
#define texcoord_input \
|
||||
"varying vec2 v_texcoord;\n"
|
||||
#define single_texture_input \
|
||||
|
@ -277,32 +280,34 @@ vertexShaderForFormat(GstVideoFormat v_format)
|
|||
static char *
|
||||
fragmentShaderForFormat(GstVideoFormat v_format, GstGLContext * context)
|
||||
{
|
||||
gboolean is_gles2 = (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES2) != 0;
|
||||
|
||||
switch (v_format) {
|
||||
case GST_VIDEO_FORMAT_RGB:
|
||||
case GST_VIDEO_FORMAT_RGBA: {
|
||||
char *swizzle = gst_gl_color_convert_swizzle_shader_string (context);
|
||||
char *ret = g_strdup_printf (texcoord_input single_texture_input uniform_opacity
|
||||
char *ret = g_strdup_printf ("%s" texcoord_input single_texture_input uniform_opacity
|
||||
"%s\n"
|
||||
"void main(void) {\n"
|
||||
" gl_FragColor = texture2D(tex, v_texcoord) * " UNIFORM_OPACITY_NAME ";\n"
|
||||
"}\n", swizzle);
|
||||
"}\n", is_gles2 ? gles2_precision : "", swizzle);
|
||||
g_clear_pointer (&swizzle, g_free);
|
||||
return ret;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_BGRA: {
|
||||
char *swizzle = gst_gl_color_convert_swizzle_shader_string (context);
|
||||
char *ret = g_strdup_printf (texcoord_input single_texture_input uniform_swizzle uniform_opacity
|
||||
char *ret = g_strdup_printf ("%s" texcoord_input single_texture_input uniform_swizzle uniform_opacity
|
||||
"%s\n"
|
||||
"void main(void) {\n"
|
||||
" gl_FragColor = swizzle(texture2D(tex, v_texcoord), " UNIFORM_SWIZZLE_COMPONENTS_NAME ") * " UNIFORM_OPACITY_NAME ";\n"
|
||||
"}\n", swizzle);
|
||||
"}\n", is_gles2 ? gles2_precision : "", swizzle);
|
||||
g_clear_pointer (&swizzle, g_free);
|
||||
return ret;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_YV12: {
|
||||
char *yuv_to_rgb = gst_gl_color_convert_yuv_to_rgb_shader_string (context);
|
||||
char *swizzle = gst_gl_color_convert_swizzle_shader_string (context);
|
||||
char *ret = g_strdup_printf (texcoord_input triplanar_texture_input uniform_swizzle uniform_yuv_to_rgb_color_matrix uniform_opacity
|
||||
char *ret = g_strdup_printf ("%s" texcoord_input triplanar_texture_input uniform_swizzle uniform_yuv_to_rgb_color_matrix uniform_opacity
|
||||
"%s\n"
|
||||
"%s\n"
|
||||
"void main(void) {\n"
|
||||
|
@ -316,7 +321,7 @@ fragmentShaderForFormat(GstVideoFormat v_format, GstGLContext * context)
|
|||
" rgba.a = yuva.a;\n"
|
||||
" gl_FragColor = rgba * " UNIFORM_OPACITY_NAME ";\n"
|
||||
//" gl_FragColor = vec4(yuva.x, 0.0, 0.0, 1.0);\n"
|
||||
"}\n", yuv_to_rgb, swizzle);
|
||||
"}\n", is_gles2 ? gles2_precision : "", yuv_to_rgb, swizzle);
|
||||
g_clear_pointer (&yuv_to_rgb, g_free);
|
||||
g_clear_pointer (&swizzle, g_free);
|
||||
return ret;
|
||||
|
@ -331,7 +336,7 @@ GstQSGMaterial::createShader() const
|
|||
{
|
||||
GstVideoFormat v_format = GST_VIDEO_INFO_FORMAT (&this->v_info);
|
||||
char *vertex = vertexShaderForFormat(v_format);
|
||||
char *fragment = fragmentShaderForFormat(v_format, NULL);
|
||||
char *fragment = fragmentShaderForFormat(v_format, gst_gl_context_get_current ());
|
||||
|
||||
if (!vertex || !fragment)
|
||||
return nullptr;
|
||||
|
|
Loading…
Reference in a new issue