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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
|
// BEGIN_COPYRIGHT -*- glean -*-
//
// Copyright (C) 2000 Allen Akin All Rights Reserved.
//
// 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 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 ALLEN AKIN 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.
//
// END_COPYRIGHT
// torthopos.cpp: Test positioning of primitives in orthographic projection.
// Some applications use OpenGL extensively for 2D rendering: portable
// GUI toolkits, heads-up display generators, etc. These apps require
// primitives to be drawn with reliable position and size in orthographic
// projections. There are some potential pitfalls; for a good discussion,
// see the OpenGL Programming Guide (the Red Book). In the second edition,
// see the OpenGL Correctness Tips on page 601.
#include "torthpos.h"
#include "image.h"
#include "rand.h"
#include "geomutil.h"
#if 0
#ifdef __UNIX__
#include <unistd.h>
#endif
#include <iostream>
#include <fstream>
#include <algorithm>
#include "dsconfig.h"
#include "dsfilt.h"
#include "dsurf.h"
#include "winsys.h"
#include "environ.h"
#include "rc.h"
#include "glutils.h"
#include "torthpos.h"
#include "misc.h"
#endif
namespace {
void
logStats1(const char* title, GLEAN::OPResult& r,
GLEAN::Environment* env) {
env->log << '\t' << title << ": ";
if (r.hasGaps || r.hasOverlaps || r.hasBadEdges) {
env->log << (r.hasGaps? " Gaps.": "")
<< (r.hasOverlaps? " Overlaps.": "")
<< (r.hasBadEdges? " Incorrect edges.": "")
<< '\n';
} else {
env->log << " No gaps, overlaps, or incorrect edges.\n";
}
} // logStats1
void
diffHeader(bool& same, const string& name,
GLEAN::DrawingSurfaceConfig* config, GLEAN::Environment* env) {
if (same) {
same = false;
env->log << name << ": DIFF "
<< config->conciseDescription() << '\n';
}
} // diffHeader
void
failHeader(bool& pass, const string& name,
GLEAN::DrawingSurfaceConfig* config, GLEAN::Environment* env) {
if (pass) {
pass = false;
env->log << name << ": FAIL "
<< config->conciseDescription() << '\n';
}
} // failHeader
GLubyte
logicalSum(GLubyte* start, int stride, int count) {
GLubyte* p = start;
GLubyte sum = 0;
for (int i = 0; i < count; ++i) {
sum |= p[0];
sum |= p[1];
sum |= p[2];
p += stride;
}
return sum;
}
void
verifyOrthPos(GLEAN::Window& w, bool& passed, string& name,
GLEAN::DrawingSurfaceConfig* config, GLEAN::OPResult& res,
GLEAN::Environment* env, const char* title) {
GLEAN::Image img(windowSize, windowSize, GL_RGB, GL_UNSIGNED_BYTE);
img.read(0, 0);
w.swap(); // give the user something to watch
// All of the tests in this group are constructed so that the
// "correct" image covers a square of exactly drawingSize by
// drawingSize pixels, embedded in a window that's two pixels
// larger in both dimensions. The border consists of pixels
// with all components set to zero. Within the image, all
// pixels should be either red (only the red component is
// nonzero) or green (only the green component is nonzero). If
// any pixels with all zero components are found, that indicates
// the presence of gaps. If any pixels with both red and green
// nonzero components are found, that indicates the presence of
// overlaps.
res.hasGaps = false;
res.hasOverlaps = false;
res.hasBadEdges = false;
GLubyte* row0 = reinterpret_cast<GLubyte*>(img.pixels());
GLubyte* row1 = row0 + img.rowSizeInBytes();
GLubyte* rowLast = row0 + (windowSize - 1) * img.rowSizeInBytes();
GLubyte* rowNextLast = rowLast - img.rowSizeInBytes();
// Check the bottom horizontal edge; it must be all zero.
if (logicalSum(row0, 3, windowSize)) {
failHeader(passed, name, config, env);
env->log << '\t' << title
<< ": bottom border (at Y==0) was touched\n";
res.hasBadEdges = true;
}
// Repeat the process for the top horizontal edge.
if (logicalSum(rowLast, 3, windowSize)) {
failHeader(passed, name, config, env);
env->log << '\t' << title
<< ": top border (at Y==" << windowSize - 1
<< ") was touched\n";
res.hasBadEdges = true;
}
// Check the second row; there must be at least one nonzero
// pixel in the "drawn" region (excluding the first and last
// column).
if (!logicalSum(row1 + 3/*skip first pixel's RGB*/, 3, drawingSize)) {
failHeader(passed, name, config, env);
env->log << '\t' << title
<< ": first row (at Y==1) was not drawn\n";
res.hasBadEdges = true;
}
// Repeat the process for the last row.
if (!logicalSum(rowNextLast + 3, 3, drawingSize)) {
failHeader(passed, name, config, env);
env->log << '\t' << title
<< ": last row (at Y==" << windowSize - 2
<< ") was not drawn\n";
res.hasBadEdges = true;
}
// Check the left-hand vertical edge; it must be all zero.
if (logicalSum(row0, img.rowSizeInBytes(), windowSize)) {
failHeader(passed, name, config, env);
env->log << '\t' << title
<< ": left border (at X==0) was touched\n";
res.hasBadEdges = true;
}
// Repeat for the right-hand vertical edge.
if (logicalSum(row0 + 3 * (windowSize - 1), img.rowSizeInBytes(),
windowSize)) {
failHeader(passed, name, config, env);
env->log << '\t' << title
<< ": right border (at X==" << windowSize - 1
<< ") was touched\n";
res.hasBadEdges = true;
}
// Check the left-hand column; something must be nonzero.
if (!logicalSum(row1 + 3, img.rowSizeInBytes(), drawingSize)) {
failHeader(passed, name, config, env);
env->log << '\t' << title
<< ": first column (at X==1) was not drawn\n";
res.hasBadEdges = true;
}
// And repeat for the right-hand column:
if (!logicalSum(row1 + 3 * (drawingSize - 1), img.rowSizeInBytes(),
drawingSize)) {
failHeader(passed, name, config, env);
env->log << '\t' << title
<< ": last column (at X==" << windowSize - 2
<< ") was not drawn\n";
res.hasBadEdges = true;
}
// Scan the drawing area. Anytime we find a pixel with all zero
// components, that's a gap. Anytime we find a pixel with both
// red and green components nonzero, that's an overlap.
GLubyte* row = row1 + 3; // lower-left pixel in drawing area
for (int i = 0; i < drawingSize; ++i) {
GLubyte* p = row;
for (int j = 0; j < drawingSize; ++j) {
if (!p[0] && !p[1] && !p[2]) {
if (!res.hasGaps) {
failHeader(passed, name, config, env);
env->log << '\t' << title
<< ": found first gap at X=="
<< j + 1 << ", Y==" << i + 1
<< '\n';
res.hasGaps = true;
}
}
if (p[0] && p[1]) {
if (!res.hasOverlaps) {
failHeader(passed, name, config, env);
env->log << '\t' << title
<< ": found first overlap at "
<< "X==" << j + 1 << ", Y=="
<< i + 1 << '\n';
res.hasOverlaps = true;
}
}
p += 3;
}
row += img.rowSizeInBytes();
}
} // verifyOrthPos
void
subdivideRects(int minX, int maxX, int minY, int maxY,
GLEAN::RandomDouble& rand, bool splitHoriz, bool drawInRed) {
// Basically we're just splitting the input rectangle
// recursively. At each step we alternate between splitting
// horizontally (dividing along Y) or vertically (along X). We
// also toggle colors (between red and green) at various times,
// in order to give us some adjacent edges of different colors
// that we can check for overlaps. Recursion bottoms out when
// the axis of interest drops below 30 pixels in length.
//
int min = splitHoriz? minY: minX;
int max = splitHoriz? maxY: maxX;
if (min + 30 > max) {
glColor4f(drawInRed? 1.0: 0.0, drawInRed? 0.0: 1.0,
0.0, 0.5);
glBegin(GL_QUADS);
glVertex2i(minX, minY);
glVertex2i(maxX, minY);
glVertex2i(maxX, maxY);
glVertex2i(minX, maxY);
glEnd();
return;
}
int split = min + static_cast<int>((max - min) * rand.next());
if (splitHoriz) {
subdivideRects(minX, maxX, minY, split,
rand, !splitHoriz, drawInRed);
subdivideRects(minX, maxX, split, maxY,
rand, !splitHoriz, !drawInRed);
} else {
subdivideRects(minX, split, minY, maxY,
rand, !splitHoriz, drawInRed);
subdivideRects(split, maxX, minY, maxY,
rand, !splitHoriz, !drawInRed);
}
}
} // anonymous namespace
namespace GLEAN {
///////////////////////////////////////////////////////////////////////////////
// runOne: Run a single test case
///////////////////////////////////////////////////////////////////////////////
void
OrthoPosPoints::runOne(OPResult& r, Window& w) {
bool passed = true;
GLUtils::useScreenCoords(windowSize, windowSize);
glFrontFace(GL_CCW);
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDisable(GL_DITHER);
glDisable(GL_COLOR_LOGIC_OP);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glDisable(GL_POLYGON_STIPPLE);
glDisable(GL_POLYGON_OFFSET_FILL);
glShadeModel(GL_FLAT);
glClearColor(0, 0, 0, 0);
////////////////////////////////////////////////////////////
// Immediate-mode points
////////////////////////////////////////////////////////////
// Clear both front and back buffers and swap, to avoid confusing
// this test with results of the previous test:
glClear(GL_COLOR_BUFFER_BIT);
w.swap();
glClear(GL_COLOR_BUFFER_BIT);
{
glBegin(GL_POINTS);
for (int x = 1; x <= drawingSize; ++x)
for (int y = 1; y <= drawingSize; ++y) {
if ((x ^ y) & 1)
glColor4f(0.0, 1.0, 0.0, 0.5);
else
glColor4f(1.0, 0.0, 0.0, 0.5);
glVertex2i(x, y);
}
glEnd();
}
verifyOrthPos(w, passed, name, r.config, r, env, "Immediate-mode points");
r.pass = passed;
} // OrthoPosPoints::runOne
///////////////////////////////////////////////////////////////////////////////
// logOne: Log a single test case
///////////////////////////////////////////////////////////////////////////////
void
OrthoPosPoints::logOne(OPResult& r) {
if (r.pass) {
logPassFail(r);
logConcise(r);
} else {
env->log << '\n';
}
logStats(r);
} // OrthoPosPoints::logOne
void
OrthoPosPoints::logStats(OPResult& r) {
logStats1("Immediate-mode points", r, env);
} // OrthoPosPoints::logStats
///////////////////////////////////////////////////////////////////////////////
// The test object itself:
///////////////////////////////////////////////////////////////////////////////
OrthoPosPoints orthoPosPointsTest("orthoPosPoints",
"window, rgb > 1, z, fast",
"This test checks the positioning of unit-sized points under\n"
"orthographic projection. (This is important for apps that\n"
"want to use OpenGL for precise 2D drawing.) It fills in an\n"
"entire rectangle one pixel at a time, drawing adjacent pixels\n"
"with different colors and with blending enabled. If there are\n"
"gaps (pixels that are the background color, and thus haven't\n"
"been filled), overlaps (pixels that show a blend of more than\n"
"one color), or improper edges (pixels around the edge of the\n"
"rectangle that haven't been filled, or pixels just outside the\n"
"edge that have), then the test fails.\n"
"\n"
"This test generally fails for one of several reasons. First,\n"
"the coordinate transformation process may have an incorrect bias;\n"
"this usually will cause a bad edge. Second, the coordinate\n"
"transformation process may round pixel coordinates incorrectly;\n"
"this will usually cause gaps and/or overlaps. Third, the point\n"
"rasterization process may not be filling the correct pixels;\n"
"this can cause gaps, overlaps, or bad edges.\n"
);
///////////////////////////////////////////////////////////////////////////////
// runOne: Run a single test case
///////////////////////////////////////////////////////////////////////////////
void
OrthoPosVLines::runOne(OPResult& r, Window& w) {
bool passed = true;
GLUtils::useScreenCoords(windowSize, windowSize);
glFrontFace(GL_CCW);
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDisable(GL_DITHER);
glDisable(GL_COLOR_LOGIC_OP);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glDisable(GL_POLYGON_STIPPLE);
glDisable(GL_POLYGON_OFFSET_FILL);
glShadeModel(GL_FLAT);
glClearColor(0, 0, 0, 0);
////////////////////////////////////////////////////////////
// Immediate-mode vertical lines
// Note that these are a little tricky, because of
// OpenGL's "diamond-exit rule" line semantics. In
// this case, we can safely treat them as half-open
// lines, where the terminal point isn't drawn. Thus
// we need to specify a terminal coordinate one pixel
// beyond the last pixel we wish to be drawn.
////////////////////////////////////////////////////////////
// Clear both front and back buffers and swap, to avoid confusing
// this test with results of the previous test:
glClear(GL_COLOR_BUFFER_BIT);
w.swap();
glClear(GL_COLOR_BUFFER_BIT);
{
glBegin(GL_LINES);
for (int x = 1; x <= drawingSize; ++x) {
if (x & 1)
glColor4f(0.0, 1.0, 0.0, 0.5);
else
glColor4f(1.0, 0.0, 0.0, 0.5);
glVertex2i(x, 1);
glVertex2i(x, drawingSize + 1);
}
glEnd();
}
verifyOrthPos(w, passed, name, r.config, r, env,
"Immediate-mode vertical lines");
r.pass = passed;
} // OrthoPosVLines::runOne
///////////////////////////////////////////////////////////////////////////////
// logOne: Log a single test case
///////////////////////////////////////////////////////////////////////////////
void
OrthoPosVLines::logOne(OPResult& r) {
if (r.pass) {
logPassFail(r);
logConcise(r);
} else {
env->log << '\n';
}
logStats(r);
} // OrthoPosVLines::logOne
void
OrthoPosVLines::logStats(OPResult& r) {
logStats1("Immediate-mode vertical lines", r, env);
} // OrthoPosVLines::logStats
///////////////////////////////////////////////////////////////////////////////
// The test object itself:
///////////////////////////////////////////////////////////////////////////////
OrthoPosVLines orthoPosVLinesTest("orthoPosVLines",
"window, rgb > 1, z, fast",
"This test checks the positioning of unit-width vertical lines\n"
"under orthographic projection. (This is important for apps\n"
"that want to use OpenGL for precise 2D drawing.) It fills in\n"
"an entire rectangle with a collection of vertical lines, drawing\n"
"adjacent lines with different colors and with blending enabled.\n"
"If there are gaps (pixels that are the background color, and\n"
"thus haven't been filled), overlaps (pixels that show a blend\n"
"of more than one color), or improper edges (pixels around the\n"
"edge of the rectangle that haven't been filled, or pixels just\n"
"outside the edge that have), then the test fails.\n"
"\n"
"This test generally fails for one of several reasons. First,\n"
"the coordinate transformation process may have an incorrect bias;\n"
"this usually will cause a bad edge. Second, the coordinate\n"
"transformation process may round pixel coordinates incorrectly;\n"
"this will usually cause gaps and/or overlaps. Third, the\n"
"line rasterization process may not be filling the correct\n"
"pixels; this can cause gaps, overlaps, or bad edges. Fourth,\n"
"the OpenGL implementation may not handle the diamond-exit rule\n"
"(section 3.4.1 in version 1.2.1 of the OpenGL spec) correctly;\n"
"this should cause a bad border or bad top edge.\n"
"\n"
"It can be argued that this test is more strict that the OpenGL\n"
"specification requires. However, it is necessary to be this\n"
"strict in order for the results to be useful to app developers\n"
"using OpenGL for 2D drawing.\n"
);
///////////////////////////////////////////////////////////////////////////////
// runOne: Run a single test case
///////////////////////////////////////////////////////////////////////////////
void
OrthoPosHLines::runOne(OPResult& r, Window& w) {
bool passed = true;
GLUtils::useScreenCoords(windowSize, windowSize);
glFrontFace(GL_CCW);
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDisable(GL_DITHER);
glDisable(GL_COLOR_LOGIC_OP);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glDisable(GL_POLYGON_STIPPLE);
glDisable(GL_POLYGON_OFFSET_FILL);
glShadeModel(GL_FLAT);
glClearColor(0, 0, 0, 0);
////////////////////////////////////////////////////////////
// Immediate-mode horizontal lines
// See the comments in the vertical line case above.
////////////////////////////////////////////////////////////
// Clear both front and back buffers and swap, to avoid confusing
// this test with results of the previous test:
glClear(GL_COLOR_BUFFER_BIT);
w.swap();
glClear(GL_COLOR_BUFFER_BIT);
{
glBegin(GL_LINES);
for (int y = 1; y <= drawingSize; ++y) {
if (y & 1)
glColor4f(0.0, 1.0, 0.0, 0.5);
else
glColor4f(1.0, 0.0, 0.0, 0.5);
glVertex2i(1, y);
glVertex2i(drawingSize + 1, y);
}
glEnd();
}
verifyOrthPos(w, passed, name, r.config, r, env,
"Immediate-mode horizontal lines");
r.pass = passed;
} // OrthoPosHLines::runOne
///////////////////////////////////////////////////////////////////////////////
// logOne: Log a single test case
///////////////////////////////////////////////////////////////////////////////
void
OrthoPosHLines::logOne(OPResult& r) {
if (r.pass) {
logPassFail(r);
logConcise(r);
} else {
env->log << '\n';
}
logStats(r);
} // OrthoPosHLines::logOne
void
OrthoPosHLines::logStats(OPResult& r) {
logStats1("Immediate-mode horizontal lines", r, env);
} // OrthoPosHLines::logStats
///////////////////////////////////////////////////////////////////////////////
// The test object itself:
///////////////////////////////////////////////////////////////////////////////
OrthoPosHLines orthoPosHLinesTest("orthoPosHLines",
"window, rgb > 1, z, fast",
"This test checks the positioning of unit-width horizontal lines\n"
"under orthographic projection. (This is important for apps\n"
"that want to use OpenGL for precise 2D drawing.) It fills in\n"
"an entire rectangle with a stack of horizontal lines, drawing\n"
"adjacent lines with different colors and with blending enabled.\n"
"If there are gaps (pixels that are the background color, and\n"
"thus haven't been filled), overlaps (pixels that show a blend\n"
"of more than one color), or improper edges (pixels around the\n"
"edge of the rectangle that haven't been filled, or pixels just\n"
"outside the edge that have), then the test fails.\n"
"\n"
"This test generally fails for one of several reasons. First,\n"
"the coordinate transformation process may have an incorrect bias;\n"
"this usually will cause a bad edge. Second, the coordinate\n"
"transformation process may round pixel coordinates incorrectly;\n"
"this will usually cause gaps and/or overlaps. Third, the\n"
"line rasterization process may not be filling the correct\n"
"pixels; this can cause gaps, overlaps, or bad edges. Fourth,\n"
"the OpenGL implementation may not handle the diamond-exit rule\n"
"(section 3.4.1 in version 1.2.1 of the OpenGL spec) correctly;\n"
"this should cause a bad border or bad right edge.\n"
"\n"
"It can be argued that this test is more strict that the OpenGL\n"
"specification requires. However, it is necessary to be this\n"
"strict in order for the results to be useful to app developers\n"
"using OpenGL for 2D drawing.\n"
);
///////////////////////////////////////////////////////////////////////////////
// runOne: Run a single test case
///////////////////////////////////////////////////////////////////////////////
void
OrthoPosTinyQuads::runOne(OPResult& r, Window& w) {
bool passed = true;
GLUtils::useScreenCoords(windowSize, windowSize);
glFrontFace(GL_CCW);
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDisable(GL_DITHER);
glDisable(GL_COLOR_LOGIC_OP);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glDisable(GL_POLYGON_STIPPLE);
glDisable(GL_POLYGON_OFFSET_FILL);
glShadeModel(GL_FLAT);
glClearColor(0, 0, 0, 0);
////////////////////////////////////////////////////////////
// Immediate-mode 1x1-pixel quads
////////////////////////////////////////////////////////////
// Clear both front and back buffers and swap, to avoid confusing
// this test with results of the previous test:
glClear(GL_COLOR_BUFFER_BIT);
w.swap();
glClear(GL_COLOR_BUFFER_BIT);
{
glBegin(GL_QUADS);
for (int x = 1; x <= drawingSize; ++x)
for (int y = 1; y <= drawingSize; ++y) {
if ((x ^ y) & 1)
glColor4f(0.0, 1.0, 0.0, 0.5);
else
glColor4f(1.0, 0.0, 0.0, 0.5);
glVertex2i(x, y);
glVertex2i(x + 1, y);
glVertex2i(x + 1, y + 1);
glVertex2i(x, y + 1);
}
glEnd();
}
verifyOrthPos(w, passed, name, r.config, r, env,
"Immediate-mode 1x1 quads");
r.pass = passed;
} // OrthoPosTinyQuads::runOne
///////////////////////////////////////////////////////////////////////////////
// logOne: Log a single test case
///////////////////////////////////////////////////////////////////////////////
void
OrthoPosTinyQuads::logOne(OPResult& r) {
if (r.pass) {
logPassFail(r);
logConcise(r);
} else {
env->log << '\n';
}
logStats(r);
} // OrthoPosTinyQuads::logOne
void
OrthoPosTinyQuads::logStats(OPResult& r) {
logStats1("Immediate-mode 1x1 quads", r, env);
} // OrthoPosTinyQuads::logStats
///////////////////////////////////////////////////////////////////////////////
// The test object itself:
///////////////////////////////////////////////////////////////////////////////
OrthoPosTinyQuads orthoPosTinyQuadsTest("orthoPosTinyQuads",
"window, rgb > 1, z, fast",
"This test checks the positioning of 1x1-pixel quadrilaterals\n"
"under orthographic projection. (This is important for apps\n"
"that want to use OpenGL for precise 2D drawing.) It fills in\n"
"an entire rectangle with an array of quadrilaterals, drawing\n"
"adjacent quads with different colors and with blending enabled.\n"
"If there are gaps (pixels that are the background color, and\n"
"thus haven't been filled), overlaps (pixels that show a blend\n"
"of more than one color), or improper edges (pixels around the\n"
"edge of the rectangle that haven't been filled, or pixels just\n"
"outside the edge that have), then the test fails.\n"
"\n"
"This test generally fails for one of several reasons. First,\n"
"the coordinate transformation process may have an incorrect bias;\n"
"this usually will cause a bad edge. Second, the coordinate\n"
"transformation process may round pixel coordinates incorrectly;\n"
"this will usually cause gaps and/or overlaps. Third, the\n"
"quad rasterization process may not be filling the correct\n"
"pixels; this can cause gaps, overlaps, or bad edges.\n"
);
///////////////////////////////////////////////////////////////////////////////
// runOne: Run a single test case
///////////////////////////////////////////////////////////////////////////////
void
OrthoPosRandRects::runOne(OPResult& r, Window& w) {
bool passed = true;
GLUtils::useScreenCoords(windowSize, windowSize);
glFrontFace(GL_CCW);
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDisable(GL_DITHER);
glDisable(GL_COLOR_LOGIC_OP);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glDisable(GL_POLYGON_STIPPLE);
glDisable(GL_POLYGON_OFFSET_FILL);
glShadeModel(GL_FLAT);
glClearColor(0, 0, 0, 0);
////////////////////////////////////////////////////////////
// Immediate-mode random axis-aligned rectangles
////////////////////////////////////////////////////////////
// Clear both front and back buffers and swap, to avoid confusing
// this test with results of the previous test:
glClear(GL_COLOR_BUFFER_BIT);
w.swap();
glClear(GL_COLOR_BUFFER_BIT);
RandomDouble rand(1618);
subdivideRects(1, drawingSize + 1, 1, drawingSize + 1,
rand, true, true);
verifyOrthPos(w, passed, name, r.config, r, env,
"Immediate-mode axis-aligned rectangles");
r.pass = passed;
} // OrthoPosRandRects::runOne
///////////////////////////////////////////////////////////////////////////////
// logOne: Log a single test case
///////////////////////////////////////////////////////////////////////////////
void
OrthoPosRandRects::logOne(OPResult& r) {
if (r.pass) {
logPassFail(r);
logConcise(r);
} else {
env->log << '\n';
}
logStats(r);
} // OrthoPosRandRects::logOne
void
OrthoPosRandRects::logStats(OPResult& r) {
logStats1("Immediate-mode axis-aligned rectangles", r, env);
} // OrthoPosRandRects::logStats
///////////////////////////////////////////////////////////////////////////////
// The test object itself:
///////////////////////////////////////////////////////////////////////////////
OrthoPosRandRects orthoPosRandRectsTest("orthoPosRandRects",
"window, rgb > 1, z, fast",
"This test checks the positioning of axis-aligned rectangles\n"
"under orthographic projection. (This is important for apps\n"
"that want to use OpenGL for precise 2D drawing.) It fills in\n"
"an entire rectangle with an array of smaller rects, drawing\n"
"adjacent rects with different colors and with blending enabled.\n"
"If there are gaps (pixels that are the background color, and\n"
"thus haven't been filled), overlaps (pixels that show a blend\n"
"of more than one color), or improper edges (pixels around the\n"
"edge of the rectangle that haven't been filled, or pixels just\n"
"outside the edge that have), then the test fails.\n"
"\n"
"This test generally fails for one of several reasons. First,\n"
"the coordinate transformation process may have an incorrect bias;\n"
"this usually will cause a bad edge. Second, the coordinate\n"
"transformation process may round pixel coordinates incorrectly;\n"
"this will usually cause gaps and/or overlaps. Third, the\n"
"rectangle rasterization process may not be filling the correct\n"
"pixels; this can cause gaps, overlaps, or bad edges.\n"
);
///////////////////////////////////////////////////////////////////////////////
// runOne: Run a single test case
///////////////////////////////////////////////////////////////////////////////
void
OrthoPosRandTris::runOne(OPResult& r, Window& w) {
bool passed = true;
GLUtils::useScreenCoords(windowSize, windowSize);
glFrontFace(GL_CCW);
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDisable(GL_DITHER);
glDisable(GL_COLOR_LOGIC_OP);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glDisable(GL_POLYGON_STIPPLE);
glDisable(GL_POLYGON_OFFSET_FILL);
glShadeModel(GL_FLAT);
glClearColor(0, 0, 0, 0);
////////////////////////////////////////////////////////////
// Immediate-mode random axis-aligned rectangles
////////////////////////////////////////////////////////////
// Clear both front and back buffers and swap, to avoid confusing
// this test with results of the previous test:
glClear(GL_COLOR_BUFFER_BIT);
w.swap();
glClear(GL_COLOR_BUFFER_BIT);
const int nPoints = 10;
RandomDouble vRand(141421356);
RandomMesh2D v(1, drawingSize + 1, nPoints,
1, drawingSize + 1, nPoints,
vRand);
for (int i = nPoints - 1; i > 0; --i) {
glBegin(GL_TRIANGLE_STRIP);
for (int j = 0; j < nPoints; ++j) {
glColor4f(1.0, 0.0, 0.0, 0.5);
glVertex2fv(v(i, j));
glColor4f(0.0, 1.0, 0.0, 0.5);
glVertex2fv(v(i - 1, j));
}
glEnd();
}
verifyOrthPos(w, passed, name, r.config, r, env,
"Immediate-mode triangles");
r.pass = passed;
} // OrthoPosRandTris::runOne
///////////////////////////////////////////////////////////////////////////////
// logOne: Log a single test case
///////////////////////////////////////////////////////////////////////////////
void
OrthoPosRandTris::logOne(OPResult& r) {
if (r.pass) {
logPassFail(r);
logConcise(r);
} else {
env->log << '\n';
}
logStats(r);
} // OrthoPosRandTris::logOne
void
OrthoPosRandTris::logStats(OPResult& r) {
logStats1("Immediate-mode triangles", r, env);
} // OrthoPosRandTris::logStats
///////////////////////////////////////////////////////////////////////////////
// The test object itself:
///////////////////////////////////////////////////////////////////////////////
OrthoPosRandTris orthoPosRandTrisTest("orthoPosRandTris",
"window, rgb > 1, z, fast",
"This test checks the positioning of random triangles under\n"
"orthographic projection. (This is important for apps that\n"
"want to use OpenGL for precise 2D drawing.) It fills in an\n"
"entire rectangle with an array of randomly-generated triangles,\n"
"drawing adjacent triangles with different colors and with blending\n"
"enabled. If there are gaps (pixels that are the background color,\n"
"and thus haven't been filled), overlaps (pixels that show a blend\n"
"of more than one color), or improper edges (pixels around the\n"
"edge of the rectangle that haven't been filled, or pixels just\n"
"outside the edge that have), then the test fails.\n"
"\n"
"This test generally fails for one of several reasons. First,\n"
"the coordinate transformation process may have an incorrect bias;\n"
"this usually will cause a bad edge. Second, the coordinate\n"
"transformation process may round pixel coordinates incorrectly;\n"
"this will usually cause gaps and/or overlaps. Third, the\n"
"triangle rasterization process may not be filling the correct\n"
"pixels; this can cause gaps, overlaps, or bad edges.\n"
);
} // namespace GLEAN
|