mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
glshader add support for gl3
This commit is contained in:
parent
86c084f1af
commit
dcd5fce8fb
2 changed files with 60 additions and 25 deletions
|
@ -28,25 +28,46 @@
|
|||
|
||||
/* *INDENT-OFF* */
|
||||
static const gchar *simple_vertex_shader_str_gles2 =
|
||||
"attribute vec4 a_position; \n"
|
||||
"attribute vec2 a_texCoord; \n"
|
||||
"varying vec2 v_texCoord; \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" gl_Position = a_position; \n"
|
||||
" v_texCoord = a_texCoord; \n"
|
||||
"} \n";
|
||||
"attribute vec4 a_position;\n"
|
||||
"attribute vec2 a_texcoord;\n"
|
||||
"varying vec2 v_texcoord;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = a_position;\n"
|
||||
" v_texcoord = a_texcoord;\n"
|
||||
"}\n";
|
||||
|
||||
static const gchar *simple_fragment_shader_str_gles2 =
|
||||
"#ifdef GL_ES \n"
|
||||
"precision mediump float; \n"
|
||||
"#endif \n"
|
||||
"varying vec2 v_texCoord; \n"
|
||||
"uniform sampler2D tex; \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" gl_FragColor = texture2D( tex, v_texCoord ); \n"
|
||||
"} \n";
|
||||
"#ifdef GL_ES\n"
|
||||
"precision mediump float;\n"
|
||||
"#endif\n"
|
||||
"varying vec2 v_texcoord;\n"
|
||||
"uniform sampler2D tex;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = texture2D(tex, v_texcoord);\n"
|
||||
"}";
|
||||
|
||||
static const gchar *simple_vertex_shader_str_gl3 =
|
||||
"#version 130\n"
|
||||
"in vec4 a_position;\n"
|
||||
"in vec2 a_texcoord;\n"
|
||||
"out vec2 v_texcoord;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = a_position;\n"
|
||||
" v_texcoord = a_texcoord;\n"
|
||||
"}\n";
|
||||
|
||||
static const gchar *simple_fragment_shader_str_gl3 =
|
||||
"#version 130\n"
|
||||
"in vec2 v_texcoord;\n"
|
||||
"out vec4 frag_color;\n"
|
||||
"uniform sampler2D tex;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" frag_color = texture(tex, v_texcoord);\n"
|
||||
"}\n";
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#ifndef GL_COMPILE_STATUS
|
||||
|
@ -639,21 +660,30 @@ gst_gl_shader_compile_with_default_f_and_check (GstGLShader * shader,
|
|||
const gchar * v_src, const gint n_attribs, const gchar * attrib_names[],
|
||||
GLint attrib_locs[])
|
||||
{
|
||||
return gst_gl_shader_compile_all_with_attribs_and_check (shader, v_src,
|
||||
simple_fragment_shader_str_gles2, n_attribs, attrib_names, attrib_locs);
|
||||
if (gst_gl_context_get_gl_api (shader->context) & GST_GL_API_OPENGL3)
|
||||
return gst_gl_shader_compile_all_with_attribs_and_check (shader, v_src,
|
||||
simple_fragment_shader_str_gl3, n_attribs, attrib_names, attrib_locs);
|
||||
else
|
||||
return gst_gl_shader_compile_all_with_attribs_and_check (shader, v_src,
|
||||
simple_fragment_shader_str_gles2, n_attribs, attrib_names, attrib_locs);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_gl_shader_compile_with_default_v_and_check (GstGLShader * shader,
|
||||
const gchar * f_src, GLint * pos_loc, GLint * tex_loc)
|
||||
{
|
||||
const gchar *attrib_names[2] = { "a_position", "a_texCoord" };
|
||||
const gchar *attrib_names[2] = { "a_position", "a_texcoord" };
|
||||
GLint attrib_locs[2] = { 0 };
|
||||
gboolean ret = TRUE;
|
||||
|
||||
ret =
|
||||
gst_gl_shader_compile_all_with_attribs_and_check (shader,
|
||||
simple_vertex_shader_str_gles2, f_src, 2, attrib_names, attrib_locs);
|
||||
if (gst_gl_context_get_gl_api (shader->context) & GST_GL_API_OPENGL3)
|
||||
ret =
|
||||
gst_gl_shader_compile_all_with_attribs_and_check (shader,
|
||||
simple_vertex_shader_str_gl3, f_src, 2, attrib_names, attrib_locs);
|
||||
else
|
||||
ret =
|
||||
gst_gl_shader_compile_all_with_attribs_and_check (shader,
|
||||
simple_vertex_shader_str_gles2, f_src, 2, attrib_names, attrib_locs);
|
||||
|
||||
if (ret) {
|
||||
*pos_loc = attrib_locs[0];
|
||||
|
@ -667,8 +697,12 @@ gboolean
|
|||
gst_gl_shader_compile_with_default_vf_and_check (GstGLShader * shader,
|
||||
GLint * pos_loc, GLint * tex_loc)
|
||||
{
|
||||
return gst_gl_shader_compile_with_default_v_and_check (shader,
|
||||
simple_fragment_shader_str_gles2, pos_loc, tex_loc);
|
||||
if (gst_gl_context_get_gl_api (shader->context) & GST_GL_API_OPENGL3)
|
||||
return gst_gl_shader_compile_with_default_v_and_check (shader,
|
||||
simple_fragment_shader_str_gl3, pos_loc, tex_loc);
|
||||
else
|
||||
return gst_gl_shader_compile_with_default_v_and_check (shader,
|
||||
simple_fragment_shader_str_gles2, pos_loc, tex_loc);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -79,6 +79,7 @@ gboolean gst_gl_shader_is_compiled (GstGLShader *shader);
|
|||
gboolean gst_gl_shader_compile (GstGLShader *shader, GError **error);
|
||||
gboolean gst_gl_shader_compile_and_check (GstGLShader *shader, const gchar *source, GstGLShaderSourceType type);
|
||||
gboolean gst_gl_shader_compile_all_with_attribs_and_check (GstGLShader *shader, const gchar *v_src, const gchar *f_src, const gint n_attribs, const gchar *attrib_names[], GLint attrib_locs[]);
|
||||
|
||||
gboolean gst_gl_shader_compile_with_default_f_and_check (GstGLShader *shader, const gchar *v_src, const gint n_attribs, const gchar *attrib_names[], GLint attrib_locs[]);
|
||||
gboolean gst_gl_shader_compile_with_default_v_and_check (GstGLShader *shader, const gchar *f_src, GLint *pos_loc, GLint *tex_loc);
|
||||
gboolean gst_gl_shader_compile_with_default_vf_and_check (GstGLShader *shader, GLint *pos_loc, GLint *tex_loc);
|
||||
|
|
Loading…
Reference in a new issue