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.h"
33 int piglit_width
= 400, piglit_height
= 300;
34 int piglit_window_mode
= GLUT_RGB
| GLUT_DOUBLE
;
36 static void loadTex(void);
37 static void compileLinkProg(void);
46 static GLfloat verts
[12] = {175.0, 125.0, 0.0,
51 static GLfloat texCoords
[8] = {1.0, 0.0,
57 static const char *vertShaderText
=
58 "attribute vec2 textureCoords;\n"
59 "varying vec2 texCoords;\n"
62 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
63 " texCoords = textureCoords;\n"
66 static const char *fragShaderText
=
67 "uniform sampler2D tex2d;\n"
68 "varying vec2 texCoords;\n"
71 " gl_FragColor = texture2D(tex2d, texCoords);\n"
74 static const char *fragShaderText2
=
75 "uniform sampler2D tex2d;\n"
76 "varying vec2 texCoords;\n"
79 " gl_FragColor = vec4(fwidth(texCoords),0.0,1.0);\n"
85 piglit_init(int argc
, char **argv
)
87 if (!GLEW_VERSION_2_0
) {
88 printf("Requires OpenGL 2.0\n");
89 piglit_report_result(PIGLIT_SKIP
);
96 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
98 glEnable(GL_TEXTURE_2D
);
99 glClearColor(0.6, 0.6, 0.6, 1.0);
103 compileLinkProg(void)
107 vs1
= glCreateShader(GL_VERTEX_SHADER
);
108 fs1
= glCreateShader(GL_FRAGMENT_SHADER
);
110 fs2
= glCreateShader(GL_FRAGMENT_SHADER
);
112 glShaderSource(vs1
, 1, (const GLchar
**) &vertShaderText
, NULL
);
113 glShaderSource(fs1
, 1, (const GLchar
**) &fragShaderText
, NULL
);
114 glShaderSource(fs2
, 1, (const GLchar
**) &fragShaderText2
, NULL
);
116 glCompileShader(vs1
);
117 glGetShaderiv(vs1
, GL_COMPILE_STATUS
, &stat
);
119 printf("error compiling vertex shader1!\n");
123 glCompileShader(fs1
);
124 glGetShaderiv(fs1
, GL_COMPILE_STATUS
, &stat
);
126 printf("error compiling fragment shader1!\n");
130 glCompileShader(fs2
);
131 glGetShaderiv(fs2
, GL_COMPILE_STATUS
, &stat
);
133 printf("error compiling fragment shader2!\n");
138 prog1
= glCreateProgram();
139 glAttachShader(prog1
, vs1
);
140 glAttachShader(prog1
, fs1
);
141 glBindAttribLocation(prog1
, 1, "textureCoords");
142 glLinkProgram(prog1
);
145 glVertexAttribPointer(0, 3, GL_FLOAT
, GL_FALSE
, 3*sizeof(GLfloat
),
147 glVertexAttribPointer(1, 2, GL_FLOAT
, GL_FALSE
, 2*sizeof(GLfloat
),
149 glEnableVertexAttribArray(0);
150 glEnableVertexAttribArray(1);
153 prog2
= glCreateProgram();
154 glAttachShader(prog2
, vs1
);
155 glAttachShader(prog2
, fs2
);
156 glBindAttribLocation(prog2
, 1, "textureCoords");
157 glLinkProgram(prog2
);
160 glVertexAttribPointer(0, 3, GL_FLOAT
, GL_FALSE
, 3*sizeof(GLfloat
),
162 glVertexAttribPointer(1, 2, GL_FLOAT
, GL_FALSE
, 2*sizeof(GLfloat
),
164 glEnableVertexAttribArray(0);
165 glEnableVertexAttribArray(1);
175 GLfloat texData
[width
][height
][4];
176 for (i
=0; i
< width
; ++i
) {
177 for (j
=0; j
< height
; ++j
) {
179 texData
[i
][j
][0] = 1;
180 texData
[i
][j
][1] = 0;
181 texData
[i
][j
][2] = 1;
182 texData
[i
][j
][3] = 0;
185 texData
[i
][j
][0] = 0;
186 texData
[i
][j
][1] = 1;
187 texData
[i
][j
][2] = 0;
188 texData
[i
][j
][3] = 1;
193 glGenTextures(1, tex
);
194 glActiveTexture(GL_TEXTURE0
);
195 glBindTexture(GL_TEXTURE_2D
, tex
[0]);
196 glTexParameteri(GL_TEXTURE_2D
, GL_GENERATE_MIPMAP
, GL_FALSE
);
197 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
198 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
199 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
200 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
201 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, width
, height
, 0,
202 GL_RGBA
, GL_FLOAT
, texData
);
212 GLboolean pass
= GL_TRUE
;
214 float mostlyBlack
[3] = {0.019608, 0.019608, 0.0};
215 float green
[3] = {0, 1, 0};
217 glClear(GL_COLOR_BUFFER_BIT
);
222 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
224 glTranslatef(75.0, 0.0, 0.0);
227 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
231 pass
= pass
&& piglit_probe_pixel_rgb(132, 125, green
);
232 pass
= pass
&& piglit_probe_pixel_rgb(205, 125, mostlyBlack
);
237 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;