add pbobench: a benchmark for pbo functions
[piglit.git] / tests / texturing / fxt1-teximage.c
blob6a09e036a362ef9461d8808132240fb8554da360
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 DEALINGS
21 * IN THE SOFTWARE.
23 * Authors:
24 * Chris Lord <chris@openedhand.com>
25 * Eric Anholt <eric@anholt.net>
29 /** @file fxt1-teximage.c
31 * Tests that a full 3DFX FXT1-compressed mipmap tree can be created
32 * and used.
35 #include "piglit-util-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config.supports_gl_compat_version = 10;
41 config.window_width = 300;
42 config.window_height = 300;
43 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
44 config.khr_no_error_support = PIGLIT_NO_ERRORS;
46 PIGLIT_GL_TEST_CONFIG_END
48 #define SIZE 128
50 const float red[4] = {1.0, 0.0, 0.0, 1.0};
51 const float green[4] = {0.0, 1.0, 0.0, 1.0};
52 const float blue[4] = {0.0, 0.0, 1.0, 1.0};
53 const float white[4] = {1.0, 1.0, 1.0, 1.0};
55 static void
56 display_mipmaps(int start_x, int start_y)
58 int i;
60 glEnable(GL_TEXTURE_2D);
62 /* Disply all the mipmap levels */
63 for (i = SIZE; i > 0; i /= 2) {
64 glBegin(GL_QUADS);
65 glTexCoord2f(0.0, 0.0); glVertex2f(start_x + 0, start_y + 0);
66 glTexCoord2f(1.0, 0.0); glVertex2f(start_x + i, start_y + 0);
67 glTexCoord2f(1.0, 1.0); glVertex2f(start_x + i, start_y + i);
68 glTexCoord2f(0.0, 1.0); glVertex2f(start_x + 0, start_y + i);
69 glEnd();
71 start_x += i + 5;
76 static GLboolean
77 check_resulting_mipmaps(int x, int y)
79 GLboolean pass = GL_TRUE;
80 int size;
82 for (size = SIZE; size > 0; size /= 2) {
83 if (size == 4)
84 pass = pass && piglit_probe_pixel_rgb(x + 2, y + 2,
85 red);
86 else if (size == 2)
87 pass = pass && piglit_probe_pixel_rgb(x + 1, y + 1,
88 green);
89 else if (size == 1)
90 pass = pass && piglit_probe_pixel_rgb(x, y,
91 blue);
92 else {
93 pass = pass && piglit_probe_pixel_rgb(x + size / 4,
94 y + size / 4,
95 red);
96 pass = pass && piglit_probe_pixel_rgb(x + size * 3 / 4,
97 y + size / 4,
98 green);
99 pass = pass && piglit_probe_pixel_rgb(x + size / 4,
100 y + size * 3 / 4,
101 blue);
102 pass = pass && piglit_probe_pixel_rgb(x + size * 3 / 4,
103 y + size * 3 / 4,
104 white);
106 x += size + 5;
109 return pass;
112 enum piglit_result
113 piglit_display(void)
115 GLuint tex;
116 GLboolean pass = GL_TRUE;
118 glClearColor(0, 0, 0, 0);
119 glClear(GL_COLOR_BUFFER_BIT);
121 tex = piglit_rgbw_texture(GL_COMPRESSED_RGB_FXT1_3DFX, SIZE, SIZE,
122 GL_TRUE, GL_FALSE, GL_UNSIGNED_NORMALIZED);
123 display_mipmaps(10, 10 + (10 + SIZE) * 0);
124 glDeleteTextures(1, &tex);
125 tex = piglit_rgbw_texture(GL_COMPRESSED_RGBA_FXT1_3DFX, SIZE, SIZE,
126 GL_TRUE, GL_FALSE, GL_UNSIGNED_NORMALIZED);
127 display_mipmaps(10, 10 + (10 + SIZE) * 1);
128 glDeleteTextures(1, &tex);
130 pass = pass && check_resulting_mipmaps(10, 10 + (10 + SIZE) * 0);
131 pass = pass && check_resulting_mipmaps(10, 10 + (10 + SIZE) * 1);
133 piglit_present_results();
135 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
138 void
139 piglit_init(int argc, char **argv)
141 piglit_require_extension("GL_3DFX_texture_compression_FXT1");
143 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);