glshader add support for gl3

This commit is contained in:
Matthew Waters 2014-10-21 19:30:38 +11:00 committed by Tim-Philipp Müller
parent 86c084f1af
commit dcd5fce8fb
2 changed files with 60 additions and 25 deletions

View file

@ -28,25 +28,46 @@
/* *INDENT-OFF* */ /* *INDENT-OFF* */
static const gchar *simple_vertex_shader_str_gles2 = static const gchar *simple_vertex_shader_str_gles2 =
"attribute vec4 a_position; \n" "attribute vec4 a_position;\n"
"attribute vec2 a_texCoord; \n" "attribute vec2 a_texcoord;\n"
"varying vec2 v_texCoord; \n" "varying vec2 v_texcoord;\n"
"void main() \n" "void main()\n"
"{ \n" "{\n"
" gl_Position = a_position; \n" " gl_Position = a_position;\n"
" v_texCoord = a_texCoord; \n" " v_texcoord = a_texcoord;\n"
"} \n"; "}\n";
static const gchar *simple_fragment_shader_str_gles2 = static const gchar *simple_fragment_shader_str_gles2 =
"#ifdef GL_ES \n" "#ifdef GL_ES\n"
"precision mediump float; \n" "precision mediump float;\n"
"#endif \n" "#endif\n"
"varying vec2 v_texCoord; \n" "varying vec2 v_texcoord;\n"
"uniform sampler2D tex; \n" "uniform sampler2D tex;\n"
"void main() \n" "void main()\n"
"{ \n" "{\n"
" gl_FragColor = texture2D( tex, v_texCoord ); \n" " gl_FragColor = texture2D(tex, v_texcoord);\n"
"} \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* */ /* *INDENT-ON* */
#ifndef GL_COMPILE_STATUS #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[], const gchar * v_src, const gint n_attribs, const gchar * attrib_names[],
GLint attrib_locs[]) GLint attrib_locs[])
{ {
return gst_gl_shader_compile_all_with_attribs_and_check (shader, v_src, if (gst_gl_context_get_gl_api (shader->context) & GST_GL_API_OPENGL3)
simple_fragment_shader_str_gles2, n_attribs, attrib_names, attrib_locs); 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 gboolean
gst_gl_shader_compile_with_default_v_and_check (GstGLShader * shader, gst_gl_shader_compile_with_default_v_and_check (GstGLShader * shader,
const gchar * f_src, GLint * pos_loc, GLint * tex_loc) 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 }; GLint attrib_locs[2] = { 0 };
gboolean ret = TRUE; gboolean ret = TRUE;
ret = if (gst_gl_context_get_gl_api (shader->context) & GST_GL_API_OPENGL3)
gst_gl_shader_compile_all_with_attribs_and_check (shader, ret =
simple_vertex_shader_str_gles2, f_src, 2, attrib_names, attrib_locs); 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) { if (ret) {
*pos_loc = attrib_locs[0]; *pos_loc = attrib_locs[0];
@ -667,8 +697,12 @@ gboolean
gst_gl_shader_compile_with_default_vf_and_check (GstGLShader * shader, gst_gl_shader_compile_with_default_vf_and_check (GstGLShader * shader,
GLint * pos_loc, GLint * tex_loc) GLint * pos_loc, GLint * tex_loc)
{ {
return gst_gl_shader_compile_with_default_v_and_check (shader, if (gst_gl_context_get_gl_api (shader->context) & GST_GL_API_OPENGL3)
simple_fragment_shader_str_gles2, pos_loc, tex_loc); 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 void

View file

@ -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 (GstGLShader *shader, GError **error);
gboolean gst_gl_shader_compile_and_check (GstGLShader *shader, const gchar *source, GstGLShaderSourceType type); 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_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_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_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); gboolean gst_gl_shader_compile_with_default_vf_and_check (GstGLShader *shader, GLint *pos_loc, GLint *tex_loc);