From b2285058a4b054e2e49ea1dbb9e7299be94b5792 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Wed, 12 Jan 2011 13:47:55 +0000 Subject: [PATCH] cogl-shader-boilerplate: Move the uniforms to the common code The builtin uniforms are accessible from either the vertex shader or the fragment shader so we should define them in the common section. This doesn't really matter for the current list of uniforms because it's pretty unlikely that you'd want to access the matrices from the fragment shader, but for other builtins such as the lighting material properties it makes sense. --- cogl/cogl-shader-boilerplate.h | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/cogl/cogl-shader-boilerplate.h b/cogl/cogl-shader-boilerplate.h index 115e84bdf..db7a6b3c1 100644 --- a/cogl/cogl-shader-boilerplate.h +++ b/cogl/cogl-shader-boilerplate.h @@ -30,12 +30,17 @@ #include "cogl.h" +#ifndef HAVE_COGL_GLES2 + #define _COGL_COMMON_SHADER_BOILERPLATE \ "#define COGL_VERSION 100\n" \ + "\n" \ + "#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" \ "\n" -#ifndef HAVE_COGL_GLES2 - #define _COGL_VERTEX_SHADER_BOILERPLATE \ _COGL_COMMON_SHADER_BOILERPLATE \ "#define cogl_position_in gl_Vertex\n" \ @@ -54,12 +59,7 @@ "#define cogl_position_out gl_Position\n" \ "#define cogl_point_size_out gl_PointSize\n" \ "#define cogl_color_out gl_FrontColor\n" \ - "#define cogl_tex_coord_out gl_TexCoord\n" \ - "\n" \ - "#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_tex_coord_out gl_TexCoord\n" #define _COGL_FRAGMENT_SHADER_BOILERPLATE \ _COGL_COMMON_SHADER_BOILERPLATE \ @@ -79,6 +79,14 @@ #else /* HAVE_COGL_GLES2 */ +#define _COGL_COMMON_SHADER_BOILERPLATE \ + "#define COGL_VERSION 100\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" + /* 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 @@ -95,12 +103,7 @@ "attribute vec4 cogl_color_in;\n" \ "attribute vec4 cogl_position_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" + "attribute vec3 cogl_normal_in;\n" #define _COGL_FRAGMENT_SHADER_BOILERPLATE \ _COGL_COMMON_SHADER_BOILERPLATE \