framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / shaders / glsl-lod-bias.c
blobb8e3f9ac8c04198283feb219695188d73e164b40
1 /*
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
13 * Software.
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.
24 // author: Ben Holmes
26 /* This test utilizes a texture sampling function in GLSL that specifies a
27 * LOD bias. Create a texture with a 4x4 checkerboard pattern. Draw that
28 * texture with all of the positive LOD biases that will result in a mipmap
29 * level greater than or equal to 4x4 (single texel tiles) being used. Verify
30 * that all the image are the same.
33 #include "piglit-util-gl.h"
35 /* Pick the number of LODs to examine and the size of the texture so that the
36 * smallest LOD is the one where each of the 4x4 tiles in the checkerboard
37 * texture is 1x1.
39 #define TEST_COLS 5
40 #define BOX_SIZE (1 << (TEST_COLS + 1))
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config.supports_gl_compat_version = 10;
46 config.window_width = (BOX_SIZE+2)*TEST_COLS+1;
47 config.window_height = (BOX_SIZE+1)+1;
48 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
50 PIGLIT_GL_TEST_CONFIG_END
52 static GLuint tex[1];
53 static GLint prog;
54 static GLint vs;
55 static GLint fs;
56 static GLint tex_loc;
57 static GLint bias_loc;
60 static void loadTex(void);
61 static void compileLinkProg(void);
63 static const char *vertShaderText =
64 "varying vec2 texCoords;\n"
65 "void main()\n"
66 "{ \n"
67 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
68 " texCoords = gl_MultiTexCoord0.st;\n"
69 "} \n";
71 static const char *fragShaderText =
72 "uniform sampler2D tex2d;\n"
73 "uniform float lodBias;\n"
74 "varying vec2 texCoords;\n"
75 "void main()\n"
76 "{ \n"
77 " gl_FragColor = texture2D(tex2d, texCoords, lodBias);\n"
78 "} \n";
81 static const float clear_color[4] = {0.6, 0.6, 0.6, 1.0};
82 static const float green[4] = {0.0, 1.0, 0.0, 1.0};
83 static const float pink[4] = {1.0, 0.0, 1.0, 0.0}; /* Note: 0.0 alpha */
85 void
86 piglit_init(int argc, char **argv)
88 piglit_require_gl_version(20);
90 loadTex();
91 compileLinkProg();
93 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
94 glEnable(GL_TEXTURE_2D);
95 glClearColor(clear_color[0], clear_color[1],
96 clear_color[2], clear_color[3]);
99 static void
100 compileLinkProg(void)
102 GLint stat;
104 vs = glCreateShader(GL_VERTEX_SHADER);
105 fs = glCreateShader(GL_FRAGMENT_SHADER);
107 glShaderSource(vs, 1, (const GLchar **) &vertShaderText, NULL);
108 glShaderSource(fs, 1, (const GLchar **) &fragShaderText, NULL);
110 glCompileShader(vs);
111 glGetShaderiv(vs, GL_COMPILE_STATUS, &stat);
112 if (!stat) {
113 printf("error compiling vertex shader!\n");
114 exit(1);
117 glCompileShader(fs);
118 glGetShaderiv(fs, GL_COMPILE_STATUS, &stat);
119 if (!stat) {
120 printf("error compiling fragment shader!\n");
121 exit(1);
125 prog = glCreateProgram();
126 glAttachShader(prog, vs);
127 glAttachShader(prog, fs);
128 glLinkProgram(prog);
129 glUseProgram(prog);
131 tex_loc = glGetUniformLocation(prog, "tex2d");
132 bias_loc = glGetUniformLocation(prog, "lodBias");
134 glUniform1i(tex_loc, 0);
137 static void
138 loadTex(void)
140 #define height BOX_SIZE
141 #define width BOX_SIZE
142 int i, j;
144 GLfloat texData[width][height][4];
145 for (i=0; i < width; ++i) {
146 for (j=0; j < height; ++j) {
147 if ((i ^ j) & (BOX_SIZE / 4)) {
148 memcpy(texData[i][j], pink, sizeof(pink));
150 else {
151 memcpy(texData[i][j], green, sizeof(green));
156 glGenTextures(1, tex);
157 glActiveTexture(GL_TEXTURE0);
158 glBindTexture(GL_TEXTURE_2D, tex[0]);
159 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
160 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
161 GL_NEAREST_MIPMAP_NEAREST);
162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
163 GL_NEAREST);
164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
165 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
166 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
167 GL_RGBA, GL_FLOAT, texData);
169 glEnable(GL_BLEND);
170 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
171 #undef height
172 #undef width
176 enum piglit_result
177 piglit_display(void)
179 const int tile_size = BOX_SIZE / 4;
180 GLboolean pass = GL_TRUE;
181 unsigned i;
183 glClear(GL_COLOR_BUFFER_BIT);
185 for (i = 0; i < TEST_COLS; i++) {
186 const int x = 1 + ((BOX_SIZE + 2) * i);
188 glUniform1f(bias_loc, (float) i);
190 /* Draw the rectangle the same size as the texture. This
191 * guarantees that the unbiased LOD will be 0.0.
193 piglit_draw_rect_tex((float) x, 1.0,
194 BOX_SIZE, BOX_SIZE,
195 0.0, 0.0, 1.0, 1.0);
197 /* The middle of the lower left tile should be green, and the
198 * middle of the tile next to it should be the clear color.
200 if (!piglit_probe_pixel_rgb(x + (3 * tile_size / 2), 2, clear_color)
201 || !piglit_probe_pixel_rgb(x + (tile_size / 2), 2, green)) {
202 pass = GL_FALSE;
206 piglit_present_results();
208 return pass ? PIGLIT_PASS : PIGLIT_FAIL;