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
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.
25 * \file depth-tex-modes-common.c
26 * Common framework for tests of GL_DEPTH_TEXTURE_MODE.
29 * \author Ian Romanick
32 #include "piglit-util-gl.h"
33 #include "depth-tex-modes-common.h"
35 static void loadTex(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);
56 GLfloat texDepthData
[width
][height
];
58 for (i
=0; i
< width
; ++i
) {
59 for (j
=0; j
< height
; ++j
) {
61 texDepthData
[i
][j
] = 1.0;
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
,
85 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MAG_FILTER
,
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
);
105 calculate_expected_color(GLenum depth_mode
, GLenum operand
,
106 const float *env_color
, float texel
,
111 switch (depth_mode
) {
113 color
[0] = 0.0; color
[1] = 0.0; color
[2] = 0.0;
117 color
[0] = texel
; color
[1] = texel
; color
[2] = texel
;
121 color
[0] = texel
; color
[1] = texel
; color
[2] = texel
;
125 color
[0] = texel
; color
[1] = 0.0; color
[2] = 0.0;
130 color
[0] = color
[1] = color
[2] = color
[3] = 0.0;
134 if (operand
== GL_SRC_ALPHA
) {
140 result
[0] = color
[0] * env_color
[0];
141 result
[1] = color
[1] * env_color
[1];
142 result
[2] = color
[2] * env_color
[2];
147 depth_tex_display(const GLenum
*depth_texture_modes
, unsigned num_modes
,
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
;
159 static const struct {
162 const GLfloat
*color
;
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
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
,
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
];
203 glTexParameteri(test_rows
[row
].target
,
204 GL_DEPTH_TEXTURE_MODE
,
207 piglit_draw_rect_tex(x
, y
, box_size
, box_size
,
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);
219 calculate_expected_color(mode
,
220 test_rows
[row
].operand0_rgb
,
221 test_rows
[row
].color
,
222 ((j
== 0) || (j
== 3))
226 if (!piglit_probe_pixel_rgb(tx
, ty
, tc
)) {
229 if (!piglit_automatic
)
230 printf(" Mode: 0x%04x\n",
237 piglit_present_results();
239 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;