2 * Copyright © 2011 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * \file glsl-fs-color-matrix.c
26 * Transform the color value read from a texture by a matrix, keeping its alpha
28 * The shader in this test is fairly terrible (calling texture2D twice with
29 * the same texture coordinate), but it reproduces a bug in the Mesa i915
30 * driver. See Meego bug #13005 (https://bugs.meego.com/show_bug.cgi?id=13005).
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config
.supports_gl_compat_version
= 10;
38 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
40 PIGLIT_GL_TEST_CONFIG_END
43 "attribute vec4 vertex;\n"
44 "attribute vec2 textureCoord;\n"
45 "varying vec2 coord;\n"
48 " gl_Position = vertex;\n"
49 " coord = textureCoord;\n"
53 "uniform sampler2D texture;\n"
54 "uniform mat4 colorMatrix;\n"
55 "varying vec2 coord;\n"
58 " vec4 color = vec4(texture2D(texture, coord.st).rgb, 1.0);\n"
59 " color = colorMatrix * color;\n"
60 " gl_FragColor = vec4(color.rgb, texture2D(texture, coord.st).a);\n"
63 static const GLfloat identity_matrix
[] = {
70 static const GLfloat vertex
[] = {
77 static const GLfloat tex_coord
[] = {
84 static const GLfloat white
[4] = { 1.0, 1.0, 1.0, 1.0 };
85 static const GLfloat red
[4] = { 1.0, 0.0, 0.0, 1.0 };
86 static const GLfloat green
[4] = { 0.0, 1.0, 0.0, 1.0 };
87 static const GLfloat blue
[4] = { 0.0, 0.0, 1.0, 1.0 };
94 GLboolean pass
= GL_TRUE
;
97 tex
= piglit_rgbw_texture(GL_RGBA8
, 64, 64, GL_FALSE
, GL_TRUE
,
98 GL_UNSIGNED_NORMALIZED
);
100 glClear(GL_COLOR_BUFFER_BIT
);
101 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
103 pass
= piglit_probe_pixel_rgb(1 * piglit_width
/ 3,
104 1 * piglit_width
/ 3,
106 pass
= piglit_probe_pixel_rgb(2 * piglit_width
/ 3,
107 1 * piglit_width
/ 3,
110 pass
= piglit_probe_pixel_rgb(1 * piglit_width
/ 3,
111 2 * piglit_width
/ 3,
114 pass
= piglit_probe_pixel_rgb(2 * piglit_width
/ 3,
115 2 * piglit_width
/ 3,
119 piglit_present_results();
121 glDeleteTextures(1, &tex
);
123 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
127 piglit_init(int argc
, char **argv
)
134 piglit_require_GLSL();
136 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vs_text
);
137 fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, fs_text
);
138 prog
= piglit_link_simple_program(vs
, fs
);
140 glBindAttribLocation(prog
, 0, "vertex");
141 glBindAttribLocation(prog
, 1, "textureCoord");
144 ok
= piglit_link_check_status(prog
);
146 piglit_report_result(PIGLIT_FAIL
);
150 loc
= glGetUniformLocation(prog
, "colorMatrix");
151 glUniformMatrix4fv(loc
, 1, GL_FALSE
, identity_matrix
);
153 loc
= glGetUniformLocation(prog
, "texture");
156 glClearColor(0.2, 0.2, 0.2, 1.0);
158 glVertexAttribPointer(0, 2, GL_FLOAT
, GL_FALSE
,
159 2 * sizeof(GLfloat
), vertex
);
160 glVertexAttribPointer(1, 2, GL_FLOAT
, GL_FALSE
,
161 2 * sizeof(GLfloat
), tex_coord
);
163 glEnableVertexAttribArray(0);
164 glEnableVertexAttribArray(1);