1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
/* Copyright © 2013 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/**
* \file piglit-util-test-pattern.h
* This file declares classes and functions which can be utilized to draw
* test patterns in to color, depth or stencil buffers.
*/
#include "piglit-util-gl-common.h"
#include "math.h"
namespace piglit_util_test_pattern
{
/**
* There are two programs used to "manifest" an auxiliary buffer,
* turning it into visible colors: one for manifesting the stencil
* buffer, and one for manifesting the depth buffer. This is the base
* class that they both derive from.
*/
class ManifestProgram
{
public:
virtual void compile() = 0;
virtual void run() = 0;
};
/**
* Program we use to manifest the stencil buffer.
*
* This program operates by repeatedly drawing over the entire buffer
* using the stencil function "EQUAL", and a different color each
* time. This causes stencil values from 0 to 7 to manifest as colors
* (black, blue, green, cyan, red, magenta, yellow, white).
*/
class ManifestStencil : public ManifestProgram
{
public:
virtual void compile();
virtual void run();
private:
GLint prog;
GLint color_loc;
GLuint vertex_buf;
GLuint vao;
};
/**
* Program we use to manifest the depth buffer.
*
* This program operates by repeatedly drawing over the entire buffer
* at decreasing depth values with depth test enabled; the stencil
* function is configured to "EQUAL" with a stencil op of "INCR", so
* that after a sample passes the depth test, its stencil value will
* be incremented and it will fail the stencil test on later draws.
* As a result, depth values from back to front will manifest as
* colors (black, blue, green, cyan, red, magenta, yellow, white).
*/
class ManifestDepth : public ManifestProgram
{
public:
virtual void compile();
virtual void run();
private:
GLint prog;
GLint color_loc;
GLint depth_loc;
GLuint vertex_buf;
GLuint vao;
};
/**
* There are three programs used to draw a test pattern, depending on
* whether we are testing the color buffer, the depth buffer, or the
* stencil buffer. This is the base class that they all derive from.
*/
class TestPattern
{
public:
virtual void compile() = 0;
/**
* Draw the test pattern, applying the given projection matrix
* to vertex coordinates. The projection matrix is in
* row-major order.
*
* If no projection transformation is needed, pass
* TestPattern::no_projection for \c proj.
*/
virtual void draw(const float (*proj)[4]) = 0;
static const float no_projection[4][4];
};
/**
* Program we use to draw a test pattern into the color buffer.
*
* This program draws a grid of small disjoint triangles, each rotated
* at a different angle. This ensures that the image will have a
* large number of edges at different angles, so that we'll thoroughly
* exercise antialiasing.
*/
class Triangles : public TestPattern
{
public:
virtual void compile();
virtual void draw(const float (*proj)[4]);
protected:
GLint prog;
GLuint vertex_buf;
GLuint vao;
GLint proj_loc;
GLint tri_num_loc;
int num_tris;
};
/**
* Program we use to test that interpolation works properly.
*
* This program draws the same sequence of small triangles as the
* Triangles program, but it's capable of coloring the triangles in
* various ways based on the fragment program provided to the
* constructor.
*
* The fragment program has access to the following variables:
*
* - in vec3 barycentric_coords: barycentric coordinates of the
* triangle being drawn, normally interpolated.
*
* - centroid in vec3 barycentric_coords_centroid: same as
* barycentric_coords, but centroid interpolated.
*
* - in vec2 pixel_pos: pixel coordinate ((0,0) to (viewport_width,
* viewport_height)), normally interpolated.
*
* - centroid in vec2 pixel_pos_centroid: same as pixel_pos, but
* centroid interpolated.
*/
class InterpolationTestPattern : public Triangles
{
public:
explicit InterpolationTestPattern(const char *frag);
virtual void compile();
virtual void draw(const float (*proj)[4]);
private:
const char *frag;
GLint viewport_size_loc;
};
/**
* Program we use to draw a test pattern into the color buffer.
*
* This program draws a sequence of points with varied sizes. This ensures
* antialiasing works well with all point sizes.
*/
class Points : public TestPattern
{
public:
virtual void compile();
virtual void draw(const float (*proj)[4]);
private:
GLint prog;
GLuint vao;
GLint proj_loc;
GLint depth_loc;
GLint point_num_loc;
GLuint vertex_buf;
int num_points;
};
/**
* Program we use to draw a test pattern into the color buffer.
*
* This program draws a sequence of lines with varied width. This ensures
* antialiasing works well with all line widths.
*/
class Lines : public TestPattern
{
public:
virtual void compile();
virtual void draw(const float (*proj)[4]);
private:
GLint prog;
GLuint vao;
GLint proj_loc;
GLint line_num_loc;
GLuint vertex_buf;
int num_lines;
};
/**
* Program we use to draw a test pattern into the depth and stencil
* buffers.
*
* This program draws a "sunburst" pattern consisting of 7 overlapping
* triangles, each at a different angle. This ensures that the
* triangles overlap in a complex way, with the edges between them
* covering a a large number of different angles, so that we'll
* thoroughly exercise antialiasing.
*
* This program is further specialized into depth and stencil variants.
*/
class Sunburst : public TestPattern
{
public:
Sunburst();
virtual void compile();
/**
* Type of color buffer being rendered into. Should be one of
* the following enum values: GL_FLOAT,
* GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_INT, or GL_INT.
*
* Defaults to GL_UNSIGNED_NORMALIZED.
*/
GLenum out_type;
/**
* Whether or not the fragment shader should output a depth
* value.
*
* Defaults to false.
*/
bool compute_depth;
protected:
GLint prog;
GLint rotation_loc;
GLint vert_depth_loc;
GLint frag_depth_loc;
GLint proj_loc;
GLint draw_colors_loc;
GLuint vao;
int num_tris;
private:
const char *get_out_type_glsl() const;
GLuint vertex_buf;
};
/**
* Program that draws a test pattern into the color buffer.
*
* This program draws triangles using a variety of colors and
* gradients.
*
* This program is capable of drawing to floating point, integer, and
* unsigned integer framebuffers, controlled by the out_type
* constructor parameter, which should be GL_FLOAT,
* GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_INT, or GL_INT.
*/
class ColorGradientSunburst : public Sunburst
{
public:
explicit ColorGradientSunburst(GLenum out_type);
virtual void draw(const float (*proj)[4]);
void draw_with_scale_and_offset(const float (*proj)[4],
float scale, float offset);
};
/**
* Program we use to draw a test pattern into the stencil buffer.
*
* The triangles in this sunburst are drawn back-to-front, using no
* depth testing. Each triangle is drawn using a different stencil
* value.
*/
class StencilSunburst : public Sunburst
{
public:
virtual void draw(const float (*proj)[4]);
};
/**
* Program we use to draw a test pattern into the depth buffer.
*
* The triangles in this sunburst are drawn at a series of different
* depth values, with depth testing enabled. They are drawn in an
* arbitrary non-consecutive order, to verify that depth testing
* properly sorts the surfaces into front-to-back order.
*
* If the constructor parameter compute_depth is true, the depth value
* is determined using a fragment shader output. If it is false, it
* is determined by the z value of the vertex shader gl_Position
* output.
*/
class DepthSunburst : public Sunburst
{
public:
explicit DepthSunburst(bool compute_depth = false);
virtual void draw(const float (*proj)[4]);
};
}
|