Add more structure constructor tests.
[piglit/hramrach.git] / tests / texturing / lodclamp-between.c
blob628fc712a02350ba27e15af73b512a381b6f26b8
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 * Eric Anholt <eric@anholt.net>
28 /**
29 * @file lodclamp-between.c
31 * Tests that setting LOD clamp to between two texture levels results in
32 * appropriate mipmap filtering.
35 #include "piglit-util.h"
37 #define MAX_SIZE 32
38 #define MAX_LOD 5
39 #define PAD 5
41 int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB;
42 int piglit_width = 100;
43 int piglit_height = 200;
45 static GLfloat colors[][3] = {
46 {1.0, 0.0, 0.0},
47 {0.0, 1.0, 0.0},
48 {0.0, 0.0, 1.0},
49 {1.0, 0.0, 1.0},
50 {0.0, 1.0, 1.0},
51 {1.0, 1.0, 0.0},
54 static void
55 set_level_color(int level, int size, int color)
57 GLfloat *tex;
58 int x, y;
60 tex = malloc(size * size * 3 * sizeof(GLfloat));
62 for (y = 0; y < size; y++) {
63 for (x = 0; x < size; x++) {
64 tex[(y * size + x) * 3 + 0] = colors[color][0];
65 tex[(y * size + x) * 3 + 1] = colors[color][1];
66 tex[(y * size + x) * 3 + 2] = colors[color][2];
70 glTexImage2D(GL_TEXTURE_2D, level, GL_RGB,
71 size, size, 0,
72 GL_RGB, GL_FLOAT, tex);
74 free(tex);
77 enum piglit_result
78 piglit_display(void)
80 int dim;
81 GLboolean pass = GL_TRUE;
82 int level, x, y;
83 GLuint tex;
85 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
87 /* Clear background to gray */
88 glClearColor(0.5, 0.5, 0.5, 1.0);
89 glClear(GL_COLOR_BUFFER_BIT);
91 /* Create the texture. */
92 glGenTextures(1, &tex);
93 glBindTexture(GL_TEXTURE_2D, tex);
95 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
96 GL_LINEAR_MIPMAP_LINEAR);
97 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
98 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
99 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
101 /* Fill in each level */
102 for (level = 0, dim = MAX_SIZE; dim > 0; level++, dim /= 2) {
103 set_level_color(level, dim, level);
106 glEnable(GL_TEXTURE_2D);
108 /* Draw areas of the base level size with clamping to mip lods
109 * between each texture level.
111 x = 10;
112 y = 10;
113 for (level = 0, dim = MAX_SIZE; dim > 1; level++, dim /= 2) {
114 float clamp = (float)level + 0.5;
116 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, clamp);
118 piglit_draw_rect_tex(x, y, MAX_SIZE, MAX_SIZE,
119 0.0, 0.0, 1.0, 1.0);
121 y += MAX_SIZE + PAD;
124 /* Verify that the resulting images are blended between the levels. */
125 y = 10;
126 for (level = 0, dim = MAX_SIZE; dim > 1; level++, dim /= 2) {
127 float expected[3];
128 int i;
130 for (i = 0; i < 3; i++) {
131 expected[i] = (colors[level ][i] +
132 colors[level + 1][i]) / 2.0;
135 pass = piglit_probe_pixel_rgb(x + MAX_SIZE / 2,
136 y + MAX_SIZE / 2,
137 expected) && pass;
139 y += MAX_SIZE + PAD;
142 glDeleteTextures(1, &tex);
144 glutSwapBuffers();
146 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
149 void
150 piglit_init(int argc, char **argv)