diff --git a/clutter/cogl/cogl/cogl-shader-boilerplate.h b/clutter/cogl/cogl/cogl-shader-boilerplate.h index 1ed3519e2..f9a817fc6 100644 --- a/clutter/cogl/cogl/cogl-shader-boilerplate.h +++ b/clutter/cogl/cogl/cogl-shader-boilerplate.h @@ -59,7 +59,7 @@ "#define cogl_modelview_matrix gl_ModelViewMatrix\n" \ "#define cogl_modelview_projection_matrix gl_ModelViewProjectionMatrix\n" \ "#define cogl_projection_matrix gl_ProjectionMatrix\n" \ - "#define cogl_texture_matrix gl_TextureMatrix\n" \ + "#define cogl_texture_matrix gl_TextureMatrix\n" #define _COGL_FRAGMENT_SHADER_BOILERPLATE \ _COGL_COMMON_SHADER_BOILERPLATE \ @@ -79,11 +79,28 @@ #else /* HAVE_COGL_GLES2 */ +/* This declares all of the variables that we might need. This is + working on the assumption that the compiler will optimise them out + if they are not actually used. The GLSL spec for GLES at least + implies that this will happen for varyings but it doesn't + explicitly so for attributes */ #define _COGL_VERTEX_SHADER_BOILERPLATE \ _COGL_COMMON_SHADER_BOILERPLATE \ "#define cogl_color_out _cogl_color\n" \ - "#define cogl_point_coord_out _cogl_point_coord\n" \ - "#define cogl_tex_coord_out _cogl_tex_coord\n" + "varying vec4 _cogl_color;\n" \ + "#define cogl_tex_coord_out _cogl_tex_coord\n" \ + "#define cogl_position_out gl_Position\n" \ + "#define cogl_point_size_out gl_PointSize\n" \ + "\n" \ + "attribute vec4 cogl_position_in;\n" \ + "attribute vec4 cogl_color_in;\n" \ + "#define cogl_tex_coord_in cogl_tex_coord0_in;\n" \ + "attribute vec3 cogl_normal_in;\n" \ + "\n" \ + "uniform mat4 cogl_modelview_matrix;\n" \ + "uniform mat4 cogl_modelview_projection_matrix;\n" \ + "uniform mat4 cogl_projection_matrix;\n" \ + "uniform float cogl_point_size_in;\n" #define _COGL_FRAGMENT_SHADER_BOILERPLATE \ _COGL_COMMON_SHADER_BOILERPLATE \ diff --git a/clutter/cogl/cogl/cogl-shader.c b/clutter/cogl/cogl/cogl-shader.c index 15f926d3b..8bc7c1f60 100644 --- a/clutter/cogl/cogl/cogl-shader.c +++ b/clutter/cogl/cogl/cogl-shader.c @@ -200,7 +200,7 @@ _cogl_shader_set_source_with_boilerplate (GLuint shader_gl_handle, GLint *lengths = g_alloca (sizeof (GLint) * (count_in + 2)); int count = 0; #ifdef HAVE_COGL_GLES2 - char *tex_coords_declaration = NULL; + char *tex_coord_declarations = NULL; #endif GET_CONTEXT (ctx, NO_RETVAL); @@ -219,10 +219,28 @@ _cogl_shader_set_source_with_boilerplate (GLuint shader_gl_handle, #ifdef HAVE_COGL_GLES2 if (n_tex_coord_attribs) { - tex_coords_declaration = - g_strdup_printf ("varying vec2 _cogl_tex_coord[%d];\n", - n_tex_coord_attribs); - strings[count] = tex_coords_declaration; + GString *declarations = g_string_new (NULL); + + g_string_append_printf (declarations, + "varying vec4 _cogl_tex_coord[%d];\n", + n_tex_coord_attribs); + + if (shader_gl_type == GL_VERTEX_SHADER) + { + int i; + + g_string_append_printf (declarations, + "uniform mat4 cogl_texture_matrix[%d];\n", + n_tex_coord_attribs); + + for (i = 0; i < n_tex_coord_attribs; i++) + g_string_append_printf (declarations, + "attribute vec4 cogl_tex_coord%d_in;\n", + i); + } + + tex_coord_declarations = g_string_free (declarations, FALSE); + strings[count] = tex_coord_declarations; lengths[count++] = -1; /* null terminated */ } #endif @@ -243,7 +261,7 @@ _cogl_shader_set_source_with_boilerplate (GLuint shader_gl_handle, (const char **) strings, lengths) ); #ifdef HAVE_COGL_GLES2 - g_free (tex_coords_declaration); + g_free (tex_coord_declarations); #endif }