add pbobench: a benchmark for pbo functions
[piglit.git] / tests / texturing / gen-nonzero-unit.c
blobcfb017a9a227173f222799763641c6fe87093d96
1 /*
2 * Copyright © 2008, 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 DEALINGS
21 * IN THE SOFTWARE.
23 * Authors:
24 * Chris Lord <chris@openedhand.com>
25 * Eric Anholt <eric@anholt.net>
26 * Ian Romanick <ian.d.romanick@intel.com>
30 /** @file gen-nonzero-unit.c
32 * Tests that:
33 * - Only uses textures bound to texture unit 1. This seems to be the source
34 * of bugzilla #24219.
35 * - The full mipmap tree is generated when level 0 is set in a new
36 * texture object.
37 * - Changing GL_GENERATE_MIPMAP state flushes previous vertices.
38 * - The full mipmap tree is regenerated when level 0 is updated in an
39 * existing texture.
42 #include "piglit-util-gl.h"
44 PIGLIT_GL_TEST_CONFIG_BEGIN
46 config.supports_gl_compat_version = 10;
48 config.window_width = 512;
49 config.window_height = 512;
50 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
51 config.khr_no_error_support = PIGLIT_NO_ERRORS;
53 PIGLIT_GL_TEST_CONFIG_END
55 static PFNGLACTIVETEXTUREPROC ActiveTexture = NULL;
57 #define SIZE 128
59 static void display_mipmaps(int start_x, int start_y)
61 int i;
63 /* Disply all the mipmap levels */
64 for (i = SIZE; i > 0; i /= 2) {
65 glBegin(GL_QUADS);
66 glTexCoord2f(0.0, 0.0); glVertex2f(start_x + 0, start_y + 0);
67 glTexCoord2f(1.0, 0.0); glVertex2f(start_x + i, start_y + 0);
68 glTexCoord2f(1.0, 1.0); glVertex2f(start_x + i, start_y + i);
69 glTexCoord2f(0.0, 1.0); glVertex2f(start_x + 0, start_y + i);
70 glEnd();
72 start_x += i;
76 static void fill_level(int level, const GLfloat *color)
78 GLfloat *data;
79 int size = SIZE / (1 << level);
80 int i;
82 /* Update a square inside the texture to red */
83 data = malloc(size * size * 4 * sizeof(GLfloat));
84 for (i = 0; i < 4 * size * size; i += 4) {
85 data[i + 0] = color[0];
86 data[i + 1] = color[1];
87 data[i + 2] = color[2];
88 data[i + 3] = color[3];
90 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0,
91 GL_RGBA, GL_FLOAT, data);
92 free(data);
95 static GLboolean check_resulting_mipmaps(int x, int y, const GLfloat *color)
97 GLboolean pass = GL_TRUE;
98 int i;
100 for (i = SIZE; i > 4; i /= 2) {
101 pass = pass && piglit_probe_pixel_rgb(x + i / 2, y + i / 2,
102 color);
103 x += i;
106 return pass;
109 enum piglit_result
110 piglit_display(void)
112 GLboolean pass = GL_TRUE;
113 const GLfloat red[4] = {1.0, 0.0, 0.0, 0.0};
114 const GLfloat blue[4] = {0.0, 0.0, 1.0, 0.0};
115 GLuint textures[3];
116 int i;
118 glClearColor(0, 0, 0, 0);
119 glClear(GL_COLOR_BUFFER_BIT);
121 glGenTextures(3, textures);
123 ActiveTexture(GL_TEXTURE0);
124 glDisable(GL_TEXTURE_2D);
125 glBindTexture(GL_TEXTURE_2D, textures[0]);
126 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SIZE, SIZE, 0,
127 GL_RGBA, GL_FLOAT, NULL);
129 ActiveTexture(GL_TEXTURE1);
130 glEnable(GL_TEXTURE_2D);
132 /* Set up a texture object with mipmap generation */
133 glBindTexture(GL_TEXTURE_2D, textures[1]);
135 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
136 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
137 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
139 GL_LINEAR_MIPMAP_NEAREST);
140 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
142 /* Set the first level of the new texture to red and display. */
143 fill_level(0, red);
144 display_mipmaps(0, 0);
146 /* Set up texture object without mipmap generation */
147 glBindTexture(GL_TEXTURE_2D, textures[2]);
149 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
150 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
151 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
152 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
153 GL_LINEAR_MIPMAP_NEAREST);
155 /* Paint normal blue mipmap set */
156 for (i = 0; SIZE / (1 << i) > 0; i++)
157 fill_level(i, blue);
159 display_mipmaps(0, SIZE);
161 /* Enable GENERATE_MIPMAP and set the first (and thus all) levels to
162 * red.
164 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
165 fill_level(0, red);
166 display_mipmaps(0, SIZE * 2);
168 pass = pass && check_resulting_mipmaps(0, 0, red);
169 pass = pass && check_resulting_mipmaps(0, SIZE, blue);
170 pass = pass && check_resulting_mipmaps(0, SIZE * 2, red);
172 piglit_present_results();
174 glDeleteTextures(3, textures);
176 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
179 void
180 piglit_init(int argc, char **argv)
182 piglit_require_extension("GL_SGIS_generate_mipmap");
184 if (piglit_get_gl_version() >= 13) {
185 ActiveTexture = glActiveTexture;
186 } else {
187 piglit_require_extension("GL_ARB_multitexture");
188 ActiveTexture = glActiveTextureARB;
191 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);