cogl-shader-boilerplate: Add more builtins for GLES2

Some builtin attributes such as the matrix uniforms and some varyings
were missing from the boilerplate for GLES2. This also moves the
texture matrix and texture coord attribute declarations to
cogl-shader.c so that they can be dynamically defined depending on the
number of texture coord arrays enabled.
This commit is contained in:
Neil Roberts 2010-12-02 22:08:51 +00:00
parent 17d689f794
commit cf0ded1361
2 changed files with 44 additions and 9 deletions

View File

@ -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 \

View File

@ -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
}