shader_runner: don't use deleted query objects
[piglit.git] / tests / texturing / depth-tex-modes-common.c
blobfbabfe2430632358ccaa5728f99b3eae1722a06d
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 /**
25 * \file depth-tex-modes-common.c
26 * Common framework for tests of GL_DEPTH_TEXTURE_MODE.
28 * \author Ben Holmes
29 * \author Ian Romanick
32 #include "piglit-util-gl.h"
33 #include "depth-tex-modes-common.h"
35 static void loadTex(void);
37 void
38 depth_tex_init(void)
40 piglit_require_extension("GL_ARB_depth_texture");
41 piglit_require_extension("GL_ARB_texture_rectangle");
42 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
44 glClearColor(0.2, 0.2, 0.2, 1.0);
46 loadTex();
49 void
50 loadTex(void)
52 #define height 2
53 #define width 2
54 int i, j;
56 GLfloat texDepthData[width][height];
58 for (i=0; i < width; ++i) {
59 for (j=0; j < height; ++j) {
60 if ((i+j) & 1) {
61 texDepthData[i][j] = 1.0;
63 else {
64 texDepthData[i][j] = 0.0;
69 glGenTextures(2, tex);
71 // Depth texture 0: 2D
72 glBindTexture(GL_TEXTURE_2D, tex[0]);
73 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
74 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
75 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
76 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
77 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0,
78 GL_DEPTH_COMPONENT, GL_FLOAT, texDepthData);
81 // Depth texture 1: rectangle
82 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, tex[1]);
83 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
84 GL_NEAREST);
85 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
86 GL_NEAREST);
87 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_DEPTH_COMPONENT, width,
88 height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, texDepthData);
91 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
92 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
93 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
94 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
95 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
96 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);
97 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_CONSTANT);
99 #undef height
100 #undef width
104 static void
105 calculate_expected_color(GLenum depth_mode, GLenum operand,
106 const float *env_color, float texel,
107 float *result)
109 float color[4];
111 switch (depth_mode) {
112 case GL_ALPHA:
113 color[0] = 0.0; color[1] = 0.0; color[2] = 0.0;
114 color[3] = texel;
115 break;
116 case GL_LUMINANCE:
117 color[0] = texel; color[1] = texel; color[2] = texel;
118 color[3] = 1.0;
119 break;
120 case GL_INTENSITY:
121 color[0] = texel; color[1] = texel; color[2] = texel;
122 color[3] = texel;
123 break;
124 case GL_RED:
125 color[0] = texel; color[1] = 0.0; color[2] = 0.0;
126 color[3] = 1.0;
127 break;
128 default:
129 assert(0);
130 color[0] = color[1] = color[2] = color[3] = 0.0;
131 break;
134 if (operand == GL_SRC_ALPHA) {
135 color[0] = color[3];
136 color[1] = color[3];
137 color[2] = color[3];
140 result[0] = color[0] * env_color[0];
141 result[1] = color[1] * env_color[1];
142 result[2] = color[2] * env_color[2];
146 enum piglit_result
147 depth_tex_display(const GLenum *depth_texture_modes, unsigned num_modes,
148 unsigned box_size)
150 static const GLfloat color2[4] = {0.0, 1.0, 0.0, 1.0};
151 static const GLfloat color1[4] = {1.0, 0.0, 1.0, 1.0};
152 const unsigned half = box_size / 2;
153 const unsigned quarter = box_size / 4;
155 GLboolean pass = GL_TRUE;
156 unsigned i;
157 unsigned row;
159 static const struct {
160 GLenum target;
161 GLenum operand0_rgb;
162 const GLfloat *color;
163 float tex_size;
164 } test_rows[4] = {
165 { GL_TEXTURE_RECTANGLE_ARB, GL_SRC_COLOR, color2, 2.0 },
166 { GL_TEXTURE_RECTANGLE_ARB, GL_SRC_ALPHA, color2, 2.0 },
167 { GL_TEXTURE_2D, GL_SRC_COLOR, color1, 1.0 },
168 { GL_TEXTURE_2D, GL_SRC_ALPHA, color1, 1.0 }
171 glClear(GL_COLOR_BUFFER_BIT);
173 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
174 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
175 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
178 glBindTexture(GL_TEXTURE_2D, tex[0]);
179 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, tex[1]);
181 for (row = 0; row < ARRAY_SIZE(test_rows); row++) {
182 const float y = 1.0 + ((box_size + 1) * row);
184 /* Disable both texture targets, then enable just the target
185 * used in this row.
187 glDisable(GL_TEXTURE_2D);
188 glDisable(GL_TEXTURE_RECTANGLE_ARB);
189 glEnable(test_rows[row].target);
191 glTexEnvfv(GL_TEXTURE_ENV,
192 GL_TEXTURE_ENV_COLOR,
193 test_rows[row].color);
194 glTexEnvi(GL_TEXTURE_ENV,
195 GL_OPERAND0_RGB,
196 test_rows[row].operand0_rgb);
198 for (i = 0; i < num_modes; i++) {
199 const float x = 1.0 + ((box_size + 1) * i);
200 const GLenum mode = depth_texture_modes[i];
201 unsigned j;
203 glTexParameteri(test_rows[row].target,
204 GL_DEPTH_TEXTURE_MODE,
205 mode);
207 piglit_draw_rect_tex(x, y, box_size, box_size,
208 0.0, 0.0,
209 test_rows[row].tex_size,
210 test_rows[row].tex_size);
212 for (j = 0; j < 4; j++) {
213 const float tx = x + quarter
214 + ((j & 1) ? half : 0);
215 const float ty = y + quarter
216 + ((j & 2) ? half : 0);
217 float tc[3];
219 calculate_expected_color(mode,
220 test_rows[row].operand0_rgb,
221 test_rows[row].color,
222 ((j == 0) || (j == 3))
223 ? 0.0 : 1.0,
224 tc);
226 if (!piglit_probe_pixel_rgb(tx, ty, tc)) {
227 pass = GL_FALSE;
229 if (!piglit_automatic)
230 printf(" Mode: 0x%04x\n",
231 mode);
237 piglit_present_results();
239 return pass ? PIGLIT_PASS : PIGLIT_FAIL;