const gchar *extensions;
const gchar *uniforms;
const gchar *functions[MAX_FUNCTIONS];
- const gchar *body;
GstGLTextureTarget target;
};
"}\n"
/* Channel reordering for XYZ <-> ZYX conversion */
+static const gchar templ_REORDER_BODY[] =
+ "vec4 t = texture2D(tex, texcoord * tex_scale0);\n"
+ "%s\n" /* clobber alpha channel? */
+ "gl_FragColor = vec4(t.%c, t.%c, t.%c, t.%c);\n";
+
static const struct shader_templ templ_REORDER =
{ NULL,
DEFAULT_UNIFORMS "uniform sampler2D tex;\n",
{ NULL, },
- "vec4 t = texture2D(tex, texcoord * tex_scale0);\n"
- "%s\n" /* clobber alpha channel? */
- "gl_FragColor = vec4(t.%c, t.%c, t.%c, t.%c);\n",
GST_GL_TEXTURE_TARGET_2D
};
* ([0~1] denormalize to [0~255],shift to high byte,normalize to [0~1])
* low byte weight as : 255/65535 (similar)
* */
-static const struct shader_templ templ_COMPOSE =
- { NULL,
- DEFAULT_UNIFORMS COMPOSE_WEIGHT "uniform sampler2D tex;\n",
- { NULL, },
+static const gchar templ_COMPOSE_BODY[] =
"vec4 rgba;\n"
"vec4 t = texture2D(tex, texcoord * tex_scale0);\n"
"rgba.rgb = vec3 (dot(t.%c%c, compose_weight));"
"rgba.a = 1.0;\n"
- "gl_FragColor = vec4(rgba.%c, rgba.%c, rgba.%c, rgba.%c);\n",
+ "gl_FragColor = vec4(rgba.%c, rgba.%c, rgba.%c, rgba.%c);\n";
+
+static const struct shader_templ templ_COMPOSE =
+ { NULL,
+ DEFAULT_UNIFORMS COMPOSE_WEIGHT "uniform sampler2D tex;\n",
+ { NULL, },
GST_GL_TEXTURE_TARGET_2D
};
-static const struct shader_templ templ_AYUV_to_RGB =
- { NULL,
- DEFAULT_UNIFORMS YUV_TO_RGB_COEFFICIENTS "uniform sampler2D tex;\n",
- { glsl_func_yuv_to_rgb, NULL, },
+static const gchar templ_AYUV_to_RGB_BODY[] =
"vec4 texel, rgba;\n"
"texel = texture2D(tex, texcoord * tex_scale0);\n"
"rgba.rgb = yuv_to_rgb (texel.yzw, offset, coeff1, coeff2, coeff3);\n"
"rgba.a = texel.r;\n"
- "gl_FragColor=vec4(rgba.%c,rgba.%c,rgba.%c,rgba.%c);\n",
+ "gl_FragColor=vec4(rgba.%c,rgba.%c,rgba.%c,rgba.%c);\n";
+
+static const struct shader_templ templ_AYUV_to_RGB =
+ { NULL,
+ DEFAULT_UNIFORMS YUV_TO_RGB_COEFFICIENTS "uniform sampler2D tex;\n",
+ { glsl_func_yuv_to_rgb, NULL, },
GST_GL_TEXTURE_TARGET_2D
};
-static const struct shader_templ templ_RGB_to_AYUV =
- { NULL,
- DEFAULT_UNIFORMS RGB_TO_YUV_COEFFICIENTS "uniform sampler2D tex;\n",
- { glsl_func_rgb_to_yuv, NULL, },
+static const gchar templ_RGB_to_AYUV_BODY[] =
"vec4 texel, ayuv;\n"
"texel = texture2D(tex, texcoord).%c%c%c%c;\n"
"ayuv.yzw = rgb_to_yuv (texel.rgb, offset, coeff1, coeff2, coeff3);\n"
"ayuv.x = %s;\n"
- "gl_FragColor = ayuv;\n",
+ "gl_FragColor = ayuv;\n";
+
+static const struct shader_templ templ_RGB_to_AYUV =
+ { NULL,
+ DEFAULT_UNIFORMS RGB_TO_YUV_COEFFICIENTS "uniform sampler2D tex;\n",
+ { glsl_func_rgb_to_yuv, NULL, },
GST_GL_TEXTURE_TARGET_2D
};
/* YUV to RGB conversion */
-static const struct shader_templ templ_PLANAR_YUV_to_RGB =
- { NULL,
- DEFAULT_UNIFORMS YUV_TO_RGB_COEFFICIENTS "uniform sampler2D Ytex, Utex, Vtex;\n",
- { glsl_func_yuv_to_rgb, NULL, },
+static const gchar templ_PLANAR_YUV_to_RGB_BODY[] =
"vec4 texel, rgba;\n"
/* FIXME: should get the sampling right... */
"texel.x = texture2D(Ytex, texcoord * tex_scale0).r;\n"
"texel.z = texture2D(Vtex, texcoord * tex_scale2).r;\n"
"rgba.rgb = yuv_to_rgb (texel.xyz, offset, coeff1, coeff2, coeff3);\n"
"rgba.a = 1.0;\n"
- "gl_FragColor=vec4(rgba.%c,rgba.%c,rgba.%c,rgba.%c);\n",
+ "gl_FragColor=vec4(rgba.%c,rgba.%c,rgba.%c,rgba.%c);\n";
+
+static const struct shader_templ templ_PLANAR_YUV_to_RGB =
+ { NULL,
+ DEFAULT_UNIFORMS YUV_TO_RGB_COEFFICIENTS "uniform sampler2D Ytex, Utex, Vtex;\n",
+ { glsl_func_yuv_to_rgb, NULL, },
GST_GL_TEXTURE_TARGET_2D
};
-static const struct shader_templ templ_RGB_to_PLANAR_YUV =
- { NULL,
- DEFAULT_UNIFORMS RGB_TO_YUV_COEFFICIENTS "uniform sampler2D tex;\n"
- "uniform vec2 chroma_sampling;\n",
- { glsl_func_rgb_to_yuv, NULL, },
+static const gchar templ_RGB_to_PLANAR_YUV_BODY[] =
"vec4 texel;\n"
"vec3 yuv;\n"
"texel = texture2D(tex, texcoord).%c%c%c%c;\n"
/* FIXME: this is not quite correct yet */
"vec4 uv_texel = vec4(0.0);\n"
- /* One u and v sample can be generated by a nxm sized block given by
- * @chroma_sampling. The result is the average of all the values in the
- * block computed with a rolling average.
- */
+ /* One u and v sample can be generated by a nxm sized block given by */
+ /* @chroma_sampling. The result is the average of all the values in the */
+ /* block computed with a rolling average. */
"vec2 unnormalization;\n"
"if (texcoord.x == v_texcoord.x) {\n"
" unnormalization = vec2(width, height);\n"
"yuv.yz = rgb_to_yuv (uv_texel.rgb, offset, coeff1, coeff2, coeff3).yz;\n"
"gl_FragData[0] = vec4(yuv.x, 0.0, 0.0, 1.0);\n"
"gl_FragData[1] = vec4(yuv.y, 0.0, 0.0, 1.0);\n"
- "gl_FragData[2] = vec4(yuv.z, 0.0, 0.0, 1.0);\n",
+ "gl_FragData[2] = vec4(yuv.z, 0.0, 0.0, 1.0);\n";
+
+static const struct shader_templ templ_RGB_to_PLANAR_YUV =
+ { NULL,
+ DEFAULT_UNIFORMS RGB_TO_YUV_COEFFICIENTS "uniform sampler2D tex;\n"
+ "uniform vec2 chroma_sampling;\n",
+ { glsl_func_rgb_to_yuv, NULL, },
GST_GL_TEXTURE_TARGET_2D
};
/* NV12/NV21 to RGB conversion */
-static const struct shader_templ templ_NV12_NV21_to_RGB =
- { NULL,
- DEFAULT_UNIFORMS YUV_TO_RGB_COEFFICIENTS "uniform sampler2D Ytex, UVtex;\n",
- { glsl_func_yuv_to_rgb, NULL, },
+static const gchar templ_NV12_NV21_to_RGB_BODY[] =
"vec4 rgba;\n"
"vec3 yuv;\n"
/* FIXME: should get the sampling right... */
"yuv.yz=texture2D(UVtex, texcoord * tex_scale1).%c%c;\n"
"rgba.rgb = yuv_to_rgb (yuv, offset, coeff1, coeff2, coeff3);\n"
"rgba.a = 1.0;\n"
- "gl_FragColor=vec4(rgba.%c,rgba.%c,rgba.%c,rgba.%c);\n",
+ "gl_FragColor=vec4(rgba.%c,rgba.%c,rgba.%c,rgba.%c);\n";
+
+static const struct shader_templ templ_NV12_NV21_to_RGB =
+ { NULL,
+ DEFAULT_UNIFORMS YUV_TO_RGB_COEFFICIENTS "uniform sampler2D Ytex, UVtex;\n",
+ { glsl_func_yuv_to_rgb, NULL, },
GST_GL_TEXTURE_TARGET_2D
};
/* RGB to NV12/NV21 conversion */
/* NV12: u, v
NV21: v, u */
-static const struct shader_templ templ_RGB_to_NV12_NV21 =
- { NULL,
- DEFAULT_UNIFORMS RGB_TO_YUV_COEFFICIENTS "uniform sampler2D tex;\n",
- { glsl_func_rgb_to_yuv, NULL, },
+static const gchar templ_RGB_to_NV12_NV21_BODY[] =
"vec4 texel, uv_texel;\n"
"vec3 yuv;\n"
"texel = texture2D(tex, texcoord).%c%c%c%c;\n"
"yuv.x = rgb_to_yuv (texel.rgb, offset, coeff1, coeff2, coeff3).x;\n"
"yuv.yz = rgb_to_yuv (uv_texel.rgb, offset, coeff1, coeff2, coeff3).yz;\n"
"gl_FragData[0] = vec4(yuv.x, 0.0, 0.0, 1.0);\n"
- "gl_FragData[1] = vec4(yuv.%c, yuv.%c, 0.0, 1.0);\n",
+ "gl_FragData[1] = vec4(yuv.%c, yuv.%c, 0.0, 1.0);\n";
+
+static const struct shader_templ templ_RGB_to_NV12_NV21 =
+ { NULL,
+ DEFAULT_UNIFORMS RGB_TO_YUV_COEFFICIENTS "uniform sampler2D tex;\n",
+ { glsl_func_rgb_to_yuv, NULL, },
GST_GL_TEXTURE_TARGET_2D
};
/* YUY2:r,g,a
UYVY:a,b,r */
-static const struct shader_templ templ_YUY2_UYVY_to_RGB =
- { NULL,
- DEFAULT_UNIFORMS YUV_TO_RGB_COEFFICIENTS "uniform sampler2D Ytex;\n",
- { glsl_func_yuv_to_rgb, NULL, },
+static const gchar templ_YUY2_UYVY_to_RGB_BODY[] =
"vec4 rgba, uv_texel;\n"
"vec3 yuv;\n"
/* FIXME: should get the sampling right... */
"yuv.yz = uv_texel.%c%c;\n"
"rgba.rgb = yuv_to_rgb (yuv, offset, coeff1, coeff2, coeff3);\n"
"rgba.a = 1.0;\n"
- "gl_FragColor = vec4(rgba.%c,rgba.%c,rgba.%c,rgba.%c);\n",
+ "gl_FragColor = vec4(rgba.%c,rgba.%c,rgba.%c,rgba.%c);\n";
+
+static const struct shader_templ templ_YUY2_UYVY_to_RGB =
+ { NULL,
+ DEFAULT_UNIFORMS YUV_TO_RGB_COEFFICIENTS "uniform sampler2D Ytex;\n",
+ { glsl_func_yuv_to_rgb, NULL, },
GST_GL_TEXTURE_TARGET_2D
};
-static const struct shader_templ templ_RGB_to_YUY2_UYVY =
- { NULL,
- DEFAULT_UNIFORMS RGB_TO_YUV_COEFFICIENTS "uniform sampler2D tex;\n",
- { glsl_func_rgb_to_yuv, NULL, },
+static const gchar templ_RGB_to_YUY2_UYVY_BODY[] =
"vec4 texel1, texel2;\n"
"vec3 yuv, yuv1, yuv2;\n"
"float fx, dx, fy;\n"
" gl_FragColor = vec4(yuv.%c, yuv.%c, 0.0, 0.0);\n"
"} else {\n"
" gl_FragColor = vec4(yuv.%c, yuv.%c, 0.0, 0.0);\n"
- "}\n",
+ "}\n";
+
+static const struct shader_templ templ_RGB_to_YUY2_UYVY =
+ { NULL,
+ DEFAULT_UNIFORMS RGB_TO_YUV_COEFFICIENTS "uniform sampler2D tex;\n",
+ { glsl_func_rgb_to_yuv, NULL, },
GST_GL_TEXTURE_TARGET_2D
};
alpha = g_strdup_printf ("t.%c = 1.0;", input_alpha_channel);
}
info->templ = &templ_REORDER;
- info->frag_body = g_strdup_printf (info->templ->body, alpha ? alpha : "",
+ info->frag_body = g_strdup_printf (templ_REORDER_BODY, alpha ? alpha : "",
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3]);
info->shader_tex_names[0] = "tex";
* for us */
info->templ = &templ_REORDER;
info->frag_body =
- g_strdup_printf (info->templ->body, "", pixel_order[0], pixel_order[1],
+ g_strdup_printf (templ_REORDER_BODY, "", pixel_order[0], pixel_order[1],
pixel_order[2], pixel_order[3]);
info->shader_tex_names[0] = "tex";
} else {
switch (GST_VIDEO_INFO_FORMAT (&convert->in_info)) {
case GST_VIDEO_FORMAT_AYUV:
info->templ = &templ_AYUV_to_RGB;
- info->frag_body = g_strdup_printf (info->templ->body, pixel_order[0],
- pixel_order[1], pixel_order[2], pixel_order[3]);
+ info->frag_body = g_strdup_printf (templ_AYUV_to_RGB_BODY,
+ pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3]);
info->shader_tex_names[0] = "tex";
break;
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_Y41B:
info->templ = &templ_PLANAR_YUV_to_RGB;
info->frag_body =
- g_strdup_printf (info->templ->body, pixel_order[0],
+ g_strdup_printf (templ_PLANAR_YUV_to_RGB_BODY, pixel_order[0],
pixel_order[1], pixel_order[2], pixel_order[3]);
info->shader_tex_names[0] = "Ytex";
info->shader_tex_names[1] = "Utex";
case GST_VIDEO_FORMAT_YV12:
info->templ = &templ_PLANAR_YUV_to_RGB;
info->frag_body =
- g_strdup_printf (info->templ->body, pixel_order[0],
+ g_strdup_printf (templ_PLANAR_YUV_to_RGB_BODY, pixel_order[0],
pixel_order[1], pixel_order[2], pixel_order[3]);
info->shader_tex_names[0] = "Ytex";
info->shader_tex_names[1] = "Vtex";
{
char uv_val = convert->priv->in_tex_formats[0] == GST_GL_RG ? 'g' : 'a';
info->templ = &templ_YUY2_UYVY_to_RGB;
- info->frag_body = g_strdup_printf (info->templ->body, 'r', uv_val,
- uv_val, 'g', 'a', pixel_order[0], pixel_order[1], pixel_order[2],
+ info->frag_body =
+ g_strdup_printf (templ_YUY2_UYVY_to_RGB_BODY, 'r', uv_val, uv_val,
+ 'g', 'a', pixel_order[0], pixel_order[1], pixel_order[2],
pixel_order[3]);
info->shader_tex_names[0] = "Ytex";
break;
{
char y_val = convert->priv->in_tex_formats[0] == GST_GL_RG ? 'g' : 'a';
info->templ = &templ_YUY2_UYVY_to_RGB;
- info->frag_body = g_strdup_printf (info->templ->body, y_val, 'g',
- 'g', 'r', 'b', pixel_order[0], pixel_order[1], pixel_order[2],
+ info->frag_body =
+ g_strdup_printf (templ_YUY2_UYVY_to_RGB_BODY, y_val, 'g', 'g', 'r',
+ 'b', pixel_order[0], pixel_order[1], pixel_order[2],
pixel_order[3]);
info->shader_tex_names[0] = "Ytex";
break;
{
char val2 = convert->priv->in_tex_formats[1] == GST_GL_RG ? 'g' : 'a';
info->templ = &templ_NV12_NV21_to_RGB;
- info->frag_body = g_strdup_printf (info->templ->body, 'r', val2,
+ info->frag_body =
+ g_strdup_printf (templ_NV12_NV21_to_RGB_BODY, 'r', val2,
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3]);
info->shader_tex_names[0] = "Ytex";
info->shader_tex_names[1] = "UVtex";
{
char val2 = convert->priv->in_tex_formats[1] == GST_GL_RG ? 'g' : 'a';
info->templ = &templ_NV12_NV21_to_RGB;
- info->frag_body = g_strdup_printf (info->templ->body, val2, 'r',
+ info->frag_body =
+ g_strdup_printf (templ_NV12_NV21_to_RGB_BODY, val2, 'r',
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3]);
info->shader_tex_names[0] = "Ytex";
info->shader_tex_names[1] = "UVtex";
case GST_VIDEO_FORMAT_AYUV:
alpha = _is_RGBx (in_format) ? "1.0" : "texel.a";
info->templ = &templ_RGB_to_AYUV;
- info->frag_body = g_strdup_printf (info->templ->body, pixel_order[0],
+ info->frag_body = g_strdup_printf (templ_RGB_to_AYUV_BODY, pixel_order[0],
pixel_order[1], pixel_order[2], pixel_order[3], alpha);
info->out_n_textures = 1;
break;
case GST_VIDEO_FORMAT_Y42B:
case GST_VIDEO_FORMAT_Y41B:
info->templ = &templ_RGB_to_PLANAR_YUV;
- info->frag_body = g_strdup_printf (info->templ->body,
+ info->frag_body = g_strdup_printf (templ_RGB_to_PLANAR_YUV_BODY,
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3],
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3]);
info->out_n_textures = 3;
break;
case GST_VIDEO_FORMAT_YUY2:
info->templ = &templ_RGB_to_YUY2_UYVY;
- info->frag_body = g_strdup_printf (info->templ->body,
+ info->frag_body = g_strdup_printf (templ_RGB_to_YUY2_UYVY_BODY,
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3],
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3],
'x', 'y', 'x', 'z');
break;
case GST_VIDEO_FORMAT_UYVY:
info->templ = &templ_RGB_to_YUY2_UYVY,
- info->frag_body = g_strdup_printf (info->templ->body,
+ info->frag_body = g_strdup_printf (templ_RGB_to_YUY2_UYVY_BODY,
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3],
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3],
'y', 'x', 'z', 'x');
break;
case GST_VIDEO_FORMAT_NV12:
info->templ = &templ_RGB_to_NV12_NV21,
- info->frag_body = g_strdup_printf (info->templ->body,
+ info->frag_body = g_strdup_printf (templ_RGB_to_NV12_NV21_BODY,
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3],
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3],
'y', 'z');
break;
case GST_VIDEO_FORMAT_NV21:
info->templ = &templ_RGB_to_NV12_NV21,
- info->frag_body = g_strdup_printf (info->templ->body,
+ info->frag_body = g_strdup_printf (templ_RGB_to_NV12_NV21_BODY,
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3],
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3],
'z', 'y');
switch (GST_VIDEO_INFO_FORMAT (&convert->out_info)) {
case GST_VIDEO_FORMAT_GRAY8:
info->templ = &templ_REORDER;
- info->frag_body = g_strdup_printf (info->templ->body, alpha ? alpha : "",
+ info->frag_body = g_strdup_printf (templ_REORDER_BODY, alpha ? alpha : "",
pixel_order[0], pixel_order[0], pixel_order[0], pixel_order[3]);
break;
default:
switch (GST_VIDEO_INFO_FORMAT (&convert->in_info)) {
case GST_VIDEO_FORMAT_GRAY8:
info->templ = &templ_REORDER;
- info->frag_body = g_strdup_printf (info->templ->body, "", pixel_order[0],
+ info->frag_body = g_strdup_printf (templ_REORDER_BODY, "", pixel_order[0],
pixel_order[0], pixel_order[0], pixel_order[3]);
break;
case GST_VIDEO_FORMAT_GRAY16_LE:
{
char val2 = convert->priv->in_tex_formats[0] == GST_GL_RG ? 'g' : 'a';
info->templ = &templ_COMPOSE;
- info->frag_body = g_strdup_printf (info->templ->body, val2, 'r',
+ info->frag_body = g_strdup_printf (templ_COMPOSE_BODY, val2, 'r',
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3]);
break;
}
{
char val2 = convert->priv->in_tex_formats[0] == GST_GL_RG ? 'g' : 'a';
info->templ = &templ_COMPOSE;
- info->frag_body = g_strdup_printf (info->templ->body, 'r', val2,
+ info->frag_body = g_strdup_printf (templ_COMPOSE_BODY, 'r', val2,
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3]);
break;
}