2 * Copyright © 2009 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
21 * DEALINGS IN THE SOFTWARE.
27 * This test uses the built-in glsl function fwidth.
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 10;
37 config
.window_width
= 400;
38 config
.window_height
= 300;
39 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
41 PIGLIT_GL_TEST_CONFIG_END
43 static void loadTex(void);
44 static void compileLinkProg(void);
53 static GLfloat verts
[12] = {175.0, 125.0, 0.0,
58 static GLfloat texCoords
[8] = {1.0, 0.0,
64 static const char *vertShaderText
=
65 "attribute vec2 textureCoords;\n"
66 "varying vec2 texCoords;\n"
69 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
70 " texCoords = textureCoords;\n"
73 static const char *fragShaderText
=
74 "uniform sampler2D tex2d;\n"
75 "varying vec2 texCoords;\n"
78 " gl_FragColor = texture2D(tex2d, texCoords);\n"
81 static const char *fragShaderText2
=
82 "uniform sampler2D tex2d;\n"
83 "varying vec2 texCoords;\n"
86 " gl_FragColor = vec4(fwidth(texCoords),0.0,1.0);\n"
92 piglit_init(int argc
, char **argv
)
94 piglit_require_gl_version(20);
100 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
102 glEnable(GL_TEXTURE_2D
);
103 glClearColor(0.6, 0.6, 0.6, 1.0);
107 compileLinkProg(void)
111 vs1
= glCreateShader(GL_VERTEX_SHADER
);
112 fs1
= glCreateShader(GL_FRAGMENT_SHADER
);
114 fs2
= glCreateShader(GL_FRAGMENT_SHADER
);
116 glShaderSource(vs1
, 1, (const GLchar
**) &vertShaderText
, NULL
);
117 glShaderSource(fs1
, 1, (const GLchar
**) &fragShaderText
, NULL
);
118 glShaderSource(fs2
, 1, (const GLchar
**) &fragShaderText2
, NULL
);
120 glCompileShader(vs1
);
121 glGetShaderiv(vs1
, GL_COMPILE_STATUS
, &stat
);
123 printf("error compiling vertex shader1!\n");
127 glCompileShader(fs1
);
128 glGetShaderiv(fs1
, GL_COMPILE_STATUS
, &stat
);
130 printf("error compiling fragment shader1!\n");
134 glCompileShader(fs2
);
135 glGetShaderiv(fs2
, GL_COMPILE_STATUS
, &stat
);
137 printf("error compiling fragment shader2!\n");
142 prog1
= glCreateProgram();
143 glAttachShader(prog1
, vs1
);
144 glAttachShader(prog1
, fs1
);
145 glBindAttribLocation(prog1
, 1, "textureCoords");
146 glLinkProgram(prog1
);
149 glVertexAttribPointer(0, 3, GL_FLOAT
, GL_FALSE
, 3*sizeof(GLfloat
),
151 glVertexAttribPointer(1, 2, GL_FLOAT
, GL_FALSE
, 2*sizeof(GLfloat
),
153 glEnableVertexAttribArray(0);
154 glEnableVertexAttribArray(1);
157 prog2
= glCreateProgram();
158 glAttachShader(prog2
, vs1
);
159 glAttachShader(prog2
, fs2
);
160 glBindAttribLocation(prog2
, 1, "textureCoords");
161 glLinkProgram(prog2
);
164 glVertexAttribPointer(0, 3, GL_FLOAT
, GL_FALSE
, 3*sizeof(GLfloat
),
166 glVertexAttribPointer(1, 2, GL_FLOAT
, GL_FALSE
, 2*sizeof(GLfloat
),
168 glEnableVertexAttribArray(0);
169 glEnableVertexAttribArray(1);
179 GLfloat texData
[width
][height
][4];
180 for (i
=0; i
< width
; ++i
) {
181 for (j
=0; j
< height
; ++j
) {
183 texData
[i
][j
][0] = 1;
184 texData
[i
][j
][1] = 0;
185 texData
[i
][j
][2] = 1;
186 texData
[i
][j
][3] = 0;
189 texData
[i
][j
][0] = 0;
190 texData
[i
][j
][1] = 1;
191 texData
[i
][j
][2] = 0;
192 texData
[i
][j
][3] = 1;
197 glGenTextures(1, tex
);
198 glActiveTexture(GL_TEXTURE0
);
199 glBindTexture(GL_TEXTURE_2D
, tex
[0]);
200 glTexParameteri(GL_TEXTURE_2D
, GL_GENERATE_MIPMAP
, GL_FALSE
);
201 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
202 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
203 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
204 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
205 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, width
, height
, 0,
206 GL_RGBA
, GL_FLOAT
, texData
);
216 GLboolean pass
= GL_TRUE
;
218 float mostlyBlack
[3] = {0.019608, 0.019608, 0.0};
219 float green
[3] = {0, 1, 0};
221 glClear(GL_COLOR_BUFFER_BIT
);
226 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
228 glTranslatef(75.0, 0.0, 0.0);
231 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
235 pass
= pass
&& piglit_probe_pixel_rgb(132, 125, green
);
236 pass
= pass
&& piglit_probe_pixel_rgb(205, 125, mostlyBlack
);
239 piglit_present_results();
241 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;