cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / hiz / hiz-util.h
blob29171eea2e4665611f37f8b0151077b3aa86cf95
1 /*
2 * Copyright © 2011 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 * Chad Versace <chad.versace@intel.com>
27 /**
28 * \file hiz-util.h
29 * \brief Utilities for HiZ tests
30 * \author Chad Versace <chad.versace@intel.com>
33 #pragma once
35 #include "piglit-util-gl.h"
37 struct hiz_fbo_options {
38 GLenum color_format;
39 GLenum depth_format;
40 GLenum stencil_format;
41 GLenum depth_stencil_format;
44 static const GLfloat hiz_green[4] = { 0.0, 1.0, 0.0, 1.0 };
45 static const GLfloat hiz_blue[4] = { 0.0, 0.0, 1.0, 1.0 };
46 static const GLfloat hiz_grey[4] = { 0.5, 0.5, 0.5, 1.0 };
48 /* These must be defines so that they can be used in constant initializers. */
49 #define hiz_green_z 0.25
50 #define hiz_blue_z 0.50
51 #define hiz_clear_z 0.875
54 * \brief Probe the color buffer.
55 * \param expected_colors An array of 9 pointers, each to a float[4].
56 * \return True if all probes pass.
58 * The color buffer is probed as follows. Let the read buffer's dimension be
59 * (w, h) and choose a tuple (i, j) where i and j are in {0, 1, 2}. Then the
60 * expected color in the subrectangle
61 * {(x, y) | x in w / 3 * [i, i + 1] and y in h / 3 * [j, j + 1]}
62 * is expected_colors[3 * j + i].
64 bool hiz_probe_color_buffer(const float *expected_colors[]);
67 * \brief Probe the depth buffer.
68 * \param expected_depths Array of 9 floats.
69 * \return True if all probes pass.
70 * \see hiz_probe_color_buffer()
72 bool hiz_probe_depth_buffer(const float expected_depths[]);
74 /**
75 * \brief Probe the stencil buffer.
76 * \param expected_stencil Array of 9 ints.
77 * \return True if all probes pass.
78 * \see hiz_probe_color_buffer()
80 bool hiz_probe_stencil_buffer(const unsigned expected_stencil[]);
82 GLuint hiz_make_fbo(const struct hiz_fbo_options *options);
84 /**
85 * \brief For Valgrind's sake, delete the FBO and all attached renderbuffers.
87 void hiz_delete_fbo(GLuint fbo);
89 /**
90 * \brief Check that depth tests work correctly when rendering to an FBO.
92 * This test does not probe the depth buffer because correct operation of 1)
93 * depth testing and depth writes (via glDraw*) and of 2) depth buffer
94 * reads (via glRead*) are independent. It is possible for 1 to work while
95 * 2 to fail. This test covers only case 1.
97 * \param options Perform the test with an FBO with the given formats.
98 * \return True if test passed.
100 bool hiz_run_test_depth_test_fbo(const struct hiz_fbo_options *options);
103 * Check that depth tests work correctly when rendering to the window
104 * framebuffer.
106 * \param options Perform the test with an FBO with the given formats.
107 * \return True if test passed.
109 bool hiz_run_test_depth_test_window();
112 * \brief Check that depth reads work correctly when rendering to an FBO.
114 * First, probe the color buffer to check that depth testing worked as
115 * expected. If it did not, then immediately report test failure and do not
116 * probe the depth buffer. If depth testing misbehaved, we cannot expect
117 * the depth buffer to hold the expected values.
119 * For this test, depth test is enabled and stencil test disabled.
121 * \param options Perform the test with an FBO with the given formats.
122 * \return True if test passed.
124 * \see hiz_run_test_depth_read_window()
126 bool hiz_run_test_depth_read_fbo(const struct hiz_fbo_options *options);
129 * \brief Check that depth reads work correctly when rendering to the window
130 * framebuffer.
132 * \param options Perform the test with an FBO with the given formats.
133 * \return True if test passed.
135 * \see hiz_run_test_depth_read_fbo()
137 bool hiz_run_test_depth_read_window();
140 * \brief Check that stencil testing works correctly when rendering to an FBO.
142 * This test probes only the color buffer; it does not probe the stencil
143 * buffer. Stencil test is enabled and depth test disabled.
145 * This test does not probe the stencil buffer because correct operation of 1)
146 * stencil testing and stencil writes (via glDraw*) and of 2) stencil buffer
147 * reads (via glRead*) are independent. It is possible for 1 to work while
148 * 2 to fail. This test covers only case 1.
150 * \param options Perform the test with an FBO with the given formats.
151 * \return True if test passed.
153 bool hiz_run_test_stencil_test_fbo(const struct hiz_fbo_options *options);
156 * Check that stencil testing works correctly when rendering to the window
157 * framebuffer.
159 * \return True if test passed.
160 * \see hiz_run_test_stencil_test_fbo()
162 bool hiz_run_test_stencil_test_window();
165 * \brief Test reading the stencil buffer of an FBO.
167 * First, probe the color buffer to check that stencil testing worked as
168 * expected. If it did not, then immediately report test failure and do not
169 * probe the stencil buffer. If stencil testing misbehaved, we cannot expect
170 * the stencil buffer to hold the expected values.
172 * For this test, stencil test is enabled and depth test disabled.
174 * \param options Perform the test with an FBO with the given formats.
175 * \return True if test passed.
177 bool hiz_run_test_stencil_read_fbo(const struct hiz_fbo_options *options);
180 * \brief Test reading the stencil buffer of the window framebuffer.
182 * \return True if test passed.
183 * \see hiz_run_test_stencil_read_fbo()
185 bool hiz_run_test_stencil_read_window();
188 * Check that rendering to an FBO works correctly when depth and stencil test
189 * are simultaneously enabled.
191 * This test probes only the color buffer; it does not probe the stencil
192 * nor the depth buffer.
194 * Superficially, this test appears to simply be hiz_run_test_depth_test_fbo()
195 * and hiz_run_test_stencil_test_fbo() amalgamated. But, this test's purpose is
196 * more sinister than the sum of its parts. It tests for undefined GPU behavior
197 * when stencil read/writes are accidentally enabled in hardware when no
198 * stencil buffer is present, and analogously for depth read/writes when no
199 * depth buffer is present.
201 * \param options Perform the test with an FBO with the given formats.
202 * \return True if test passed.
204 bool hiz_run_test_depth_stencil_test_fbo(const struct hiz_fbo_options *options);