1 /* Copyright © 2013 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * \file piglit-util-test-pattern.h
25 * This file declares classes and functions which can be utilized to draw
26 * test patterns in to color, depth or stencil buffers.
29 #include "piglit-util-gl.h"
32 namespace piglit_util_test_pattern
35 * There are two programs used to "manifest" an auxiliary buffer,
36 * turning it into visible colors: one for manifesting the stencil
37 * buffer, and one for manifesting the depth buffer. This is the base
38 * class that they both derive from.
43 virtual ~ManifestProgram() {};
45 virtual void compile() = 0;
46 virtual void run() = 0;
50 * Program we use to manifest the stencil buffer.
52 * This program operates by repeatedly drawing over the entire buffer
53 * using the stencil function "EQUAL", and a different color each
54 * time. This causes stencil values from 0 to 7 to manifest as colors
55 * (black, blue, green, cyan, red, magenta, yellow, white).
57 class ManifestStencil
: public ManifestProgram
60 virtual void compile();
71 * Program we use to manifest the depth buffer.
73 * This program operates by repeatedly drawing over the entire buffer
74 * at decreasing depth values with depth test enabled; the stencil
75 * function is configured to "EQUAL" with a stencil op of "INCR", so
76 * that after a sample passes the depth test, its stencil value will
77 * be incremented and it will fail the stencil test on later draws.
78 * As a result, depth values from back to front will manifest as
79 * colors (black, blue, green, cyan, red, magenta, yellow, white).
81 class ManifestDepth
: public ManifestProgram
84 virtual void compile();
96 * There are three programs used to draw a test pattern, depending on
97 * whether we are testing the color buffer, the depth buffer, or the
98 * stencil buffer. This is the base class that they all derive from.
103 virtual ~TestPattern() {};
105 virtual void compile() = 0;
108 * Draw the test pattern, applying the given projection matrix
109 * to vertex coordinates. The projection matrix is in
112 * If no projection transformation is needed, pass
113 * TestPattern::no_projection for \c proj.
115 virtual void draw(const float (*proj
)[4]) = 0;
117 static const float no_projection
[4][4];
121 * Program we use to draw a test pattern into the color buffer.
123 * This program draws a grid of small disjoint triangles, each rotated
124 * at a different angle. This ensures that the image will have a
125 * large number of edges at different angles, so that we'll thoroughly
126 * exercise antialiasing.
128 class Triangles
: public TestPattern
131 virtual void compile();
132 virtual void draw(const float (*proj
)[4]);
145 * Program we use to test that interpolation works properly.
147 * This program draws the same sequence of small triangles as the
148 * Triangles program, but it's capable of coloring the triangles in
149 * various ways based on the fragment program provided to the
152 * The fragment program has access to the following variables:
154 * - in vec3 barycentric_coords: barycentric coordinates of the
155 * triangle being drawn, normally interpolated.
157 * - centroid in vec3 barycentric_coords_centroid: same as
158 * barycentric_coords, but centroid interpolated.
160 * - in vec2 pixel_pos: pixel coordinate ((0,0) to (viewport_width,
161 * viewport_height)), normally interpolated.
163 * - centroid in vec2 pixel_pos_centroid: same as pixel_pos, but
164 * centroid interpolated.
166 class InterpolationTestPattern
: public Triangles
169 explicit InterpolationTestPattern(const char *frag
);
170 virtual void compile();
171 virtual void draw(const float (*proj
)[4]);
175 GLint viewport_size_loc
;
180 * Program we use to draw a test pattern into the color buffer.
182 * This program draws a sequence of points with varied sizes. This ensures
183 * antialiasing works well with all point sizes.
185 class Points
: public TestPattern
188 virtual void compile();
189 virtual void draw(const float (*proj
)[4]);
202 * Program we use to draw a test pattern into the color buffer.
204 * This program draws a sequence of lines with varied width. This ensures
205 * antialiasing works well with all line widths.
207 class Lines
: public TestPattern
210 virtual void compile();
211 virtual void draw(const float (*proj
)[4]);
223 * Program we use to draw a test pattern into the depth and stencil
226 * This program draws a "sunburst" pattern consisting of 7 overlapping
227 * triangles, each at a different angle. This ensures that the
228 * triangles overlap in a complex way, with the edges between them
229 * covering a a large number of different angles, so that we'll
230 * thoroughly exercise antialiasing.
232 * This program is further specialized into depth and stencil variants.
234 class Sunburst
: public TestPattern
239 virtual void compile();
242 * Type of color buffer being rendered into. Should be one of
243 * the following enum values: GL_FLOAT,
244 * GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_INT, or GL_INT.
246 * Defaults to GL_UNSIGNED_NORMALIZED.
251 * Whether or not the fragment shader should output a depth
261 GLint vert_depth_loc
;
262 GLint frag_depth_loc
;
264 GLint draw_colors_loc
;
269 const char *get_out_type_glsl() const;
275 * Program that draws a test pattern into the color buffer.
277 * This program draws triangles using a variety of colors and
280 * This program is capable of drawing to floating point, integer, and
281 * unsigned integer framebuffers, controlled by the out_type
282 * constructor parameter, which should be GL_FLOAT,
283 * GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_INT, or GL_INT.
285 class ColorGradientSunburst
: public Sunburst
288 explicit ColorGradientSunburst(GLenum out_type
);
290 virtual void draw(const float (*proj
)[4]);
292 void draw_with_scale_and_offset(const float (*proj
)[4],
293 float scale
, float offset
);
297 * Program we use to draw a test pattern into the stencil buffer.
299 * The triangles in this sunburst are drawn back-to-front, using no
300 * depth testing. Each triangle is drawn using a different stencil
303 class StencilSunburst
: public Sunburst
306 virtual void draw(const float (*proj
)[4]);
310 * Program we use to draw a test pattern into the depth buffer.
312 * The triangles in this sunburst are drawn at a series of different
313 * depth values, with depth testing enabled. They are drawn in an
314 * arbitrary non-consecutive order, to verify that depth testing
315 * properly sorts the surfaces into front-to-back order.
317 * If the constructor parameter compute_depth is true, the depth value
318 * is determined using a fragment shader output. If it is false, it
319 * is determined by the z value of the vertex shader gl_Position
322 class DepthSunburst
: public Sunburst
325 explicit DepthSunburst(bool compute_depth
= false);
327 virtual void draw(const float (*proj
)[4]);