ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / util / piglit-test-pattern.h
blobc2cf857764a3171b629d8e30241c749c68977a1a
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
12 * Software.
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
20 * IN THE SOFTWARE.
23 /**
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"
30 #include "math.h"
32 namespace piglit_util_test_pattern
34 /**
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.
40 class ManifestProgram
42 public:
43 virtual ~ManifestProgram() {};
45 virtual void compile() = 0;
46 virtual void run() = 0;
49 /**
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
59 public:
60 virtual void compile();
61 virtual void run();
63 private:
64 GLint prog;
65 GLint color_loc;
66 GLuint vertex_buf;
67 GLuint vao;
70 /**
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
83 public:
84 virtual void compile();
85 virtual void run();
87 private:
88 GLint prog;
89 GLint color_loc;
90 GLint depth_loc;
91 GLuint vertex_buf;
92 GLuint vao;
95 /**
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.
100 class TestPattern
102 public:
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
110 * row-major order.
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
130 public:
131 virtual void compile();
132 virtual void draw(const float (*proj)[4]);
134 protected:
135 GLint prog;
136 GLuint vertex_buf;
137 GLuint vao;
138 GLint proj_loc;
139 GLint tri_num_loc;
140 int num_tris;
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
150 * constructor.
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
168 public:
169 explicit InterpolationTestPattern(const char *frag);
170 virtual void compile();
171 virtual void draw(const float (*proj)[4]);
173 private:
174 const char *frag;
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
187 public:
188 virtual void compile();
189 virtual void draw(const float (*proj)[4]);
191 private:
192 GLint prog;
193 GLuint vao;
194 GLint proj_loc;
195 GLint depth_loc;
196 GLint point_num_loc;
197 GLuint vertex_buf;
198 int num_points;
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
209 public:
210 virtual void compile();
211 virtual void draw(const float (*proj)[4]);
213 private:
214 GLint prog;
215 GLuint vao;
216 GLint proj_loc;
217 GLint line_num_loc;
218 GLuint vertex_buf;
219 int num_lines;
223 * Program we use to draw a test pattern into the depth and stencil
224 * buffers.
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
236 public:
237 Sunburst();
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.
248 GLenum out_type;
251 * Whether or not the fragment shader should output a depth
252 * value.
254 * Defaults to false.
256 bool compute_depth;
258 protected:
259 GLint prog;
260 GLint rotation_loc;
261 GLint vert_depth_loc;
262 GLint frag_depth_loc;
263 GLint proj_loc;
264 GLint draw_colors_loc;
265 GLuint vao;
266 int num_tris;
268 private:
269 const char *get_out_type_glsl() const;
271 GLuint vertex_buf;
275 * Program that draws a test pattern into the color buffer.
277 * This program draws triangles using a variety of colors and
278 * gradients.
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
287 public:
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
301 * value.
303 class StencilSunburst : public Sunburst
305 public:
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
320 * output.
322 class DepthSunburst : public Sunburst
324 public:
325 explicit DepthSunburst(bool compute_depth = false);
327 virtual void draw(const float (*proj)[4]);