GNOME Bugzilla – Bug 662184
Pipeline shaders often fail to link on GLES2 because of different n_tex_coord_attribs
Last modified: 2011-11-02 13:54:45 UTC
Cogl generates the boiler plate for shaders on GLES2 and it needs to pick a size for the texture coord arrays. However it can end up picking different numbers for the shaders and then it will fail when it tries to link them together. Attached is a patch for test-just-vertex-shader which demonstrates the problem. It also affects test-pick and test-shader-effect in the Clutter test suite.
Created attachment 199427 [details] [review] test-just-vertex-shader: Sample a texture in the fragment pipeline Previously the layer combine on the test pipeline was set up to replace the incoming color with the layer constant. This patch changes it to sample the replacement color from a 1x1 texture instead. This exposes a bug on the GLES2 backend where the vertex shader will be generated with a size for cogl_tex_coord_out of 4 but the corresponding declaration in the fragment shader will have n_layers, which is 1. This makes the program fail to link and the test fails.
Created attachment 199428 [details] [review] Use the same number for n_tex_coord_attribs in all linked shaders On GLES2, we need to specify an array size for the texture coord varying array. Previously this size would be decided in one of the following ways: - For generated vertex shaders it is always the number of layers in the pipeline. - For generated fragment shaders it is the highest sampled texture unit in the pipeline or the number of attributes supplied by the primitive, whichever is higher. - For user shaders it is usually the number of attributes supplied by the primitive. However, if the application tries to compile the shader and query the result before using it, it will always be at least 4. These shaders can quite easily end up with different values for the declaration which makes it fail to link. This patch changes it so that all of the shaders are generated with the maximum of the number of texture attributes supplied by the primitive and the number of layers in the pipeline. If this value changes then the shaders are regenerated, including user shaders. That way all of the shaders will always have the same value.
I've pushed the two patches to master as 757916f..00f0a66 and the main patch to the cogl-1.8 branch as 521b39c