-
Notifications
You must be signed in to change notification settings - Fork 2
/
GR32_VPR.pas
792 lines (702 loc) · 19.3 KB
/
GR32_VPR.pas
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
unit GR32_VPR;
(* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Vectorial Polygon Rasterizer for Graphics32
*
* The Initial Developer of the Original Code is
* Mattias Andersson <[email protected]>
*
* Portions created by the Initial Developer are Copyright (C) 2008-2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** *)
interface
{$I GR32.INC}
uses
GR32, Math;
type
PInteger = ^Integer;
PSingleArray = GR32.PSingleArray;
TSingleArray = GR32.TSingleArray;
PValueSpan = ^TValueSpan;
TValueSpan = record
X1, X2: Integer;
Values: PSingleArray;
end;
TRenderSpanEvent = procedure(const Span: TValueSpan; DstY: Integer) of object;
TRenderSpanProc = procedure(Data: Pointer; const Span: TValueSpan; DstY: Integer);
procedure RenderPolyPolygon(const Points: TArrayOfArrayOfFloatPoint;
const ClipRect: TFloatRect; const RenderProc: TRenderSpanProc; Data: Pointer = nil); overload;
procedure RenderPolygon(const Points: TArrayOfFloatPoint;
const ClipRect: TFloatRect; const RenderProc: TRenderSpanProc; Data: Pointer = nil); overload;
procedure RenderPolyPolygon(const Points: TArrayOfArrayOfFloatPoint;
const ClipRect: TFloatRect; const RenderProc: TRenderSpanEvent); overload;
procedure RenderPolygon(const Points: TArrayOfFloatPoint;
const ClipRect: TFloatRect; const RenderProc: TRenderSpanEvent); overload;
implementation
uses
Windows, SysUtils, GR32_Math, GR32_LowLevel, GR32_Blend, GR32_VectorUtils,
GR32_System;
type
TArrayOfValueSpan = array of TValueSpan;
PValueSpanArray = ^TValueSpanArray;
TValueSpanArray = array [0..0] of TValueSpan;
PLineSegment = ^TLineSegment;
TLineSegment = array [0..1] of TFloatPoint;
TArrayOfLineSegment = array of TLineSegment;
PLineSegmentArray = ^TLineSegmentArray;
TLineSegmentArray = array [0..0] of TLineSegment;
PScanLine = ^TScanLine;
TScanLine = record
Segments: PLineSegmentArray;
Count: Integer;
Y: Integer;
end;
TScanLines = array of TScanLine;
PScanLineArray = ^TScanLineArray;
TScanLineArray = array [0..0] of TScanLine;
TCumSumProc = procedure(Values: PSingleArray; Count: Integer);
var
CumSum: TCumSumProc;
procedure IntegrateSegment(var P1, P2: TFloatPoint; Values: PSingleArray);
var
X1, X2, I: Integer;
Dx, Dy, DyDx, Sx, Y, fracX1, fracX2: TFloat;
begin
X1 := _Round(P1.X);
X2 := _Round(P2.X);
if X1 = X2 then
begin
Values[X1] := Values[X1] + 0.5 * (P2.X - P1.X) * (P1.Y + P2.Y);
end
else
begin
fracX1 := P1.X - X1;
fracX2 := P2.X - X2;
Dx := P2.X - P1.X;
Dy := P2.Y - P1.Y;
DyDx := Dy/Dx;
if X1 < X2 then
begin
Sx := 1 - fracX1;
Y := P1.Y + Sx * DyDx;
Values[X1] := Values[X1] + 0.5 * (P1.Y + Y) * Sx;
for I := X1 + 1 to X2 - 1 do
begin
Values[I] := Values[I] + (Y + DyDx * 0.5); // N: Sx = 1
Y := Y + DyDx;
end;
Sx := fracX2;
Values[X2] := Values[X2] + 0.5 * (Y + P2.Y) * Sx;
end
else // X1 > X2
begin
Sx := fracX1;
Y := P1.Y - Sx * DyDx;
Values[X1] := Values[X1] - 0.5 * (P1.Y + Y) * Sx;
for I := X1 - 1 downto X2 + 1 do
begin
Values[I] := Values[I] - (Y - DyDx * 0.5); // N: Sx = -1
Y := Y - DyDx;
end;
Sx := 1 - fracX2;
Values[X2] := Values[X2] - 0.5 * (Y + P2.Y) * Sx;
end;
end;
end;
procedure CumSum_Native(Values: PSingleArray; Count: Integer);
var
I: Integer;
V: TFloat;
begin
V := Values[0];
for I := 1 to Count - 1 do
begin
if PInteger(@Values[I])^ <> 0 then
V := V + Values[I];
Values[I] := V;
end;
end;
{$IFNDEF PUREPASCAL}
// Aligned SSE2 version -- Credits: Sanyin <[email protected]>
procedure CumSum_SSE2(Values: PSingleArray; Count: Integer);
asm
{$IFDEF TARGET_x86}
MOV ECX,EDX
CMP ECX,2 // if count < 2, exit
JL @END
CMP ECX,32 // if count < 32, avoid SSE2 overhead
JL @SMALL
{--- align memory ---}
PUSH EBX
PXOR XMM4,XMM4
MOV EBX,EAX
AND EBX,15 // get aligned count
JZ @ENDALIGNING // already aligned
ADD EBX,-16
NEG EBX // get bytes to advance
JZ @ENDALIGNING // already aligned
MOV ECX,EBX
SAR ECX,2 // div with 4 to get cnt
SUB EDX,ECX
ADD EAX,4
DEC ECX
JZ @SETUPLAST // one element
@ALIGNINGLOOP:
FLD DWORD PTR [EAX-4]
FADD DWORD PTR [EAX]
FSTP DWORD PTR [EAX]
ADD EAX,4
DEC ECX
JNZ @ALIGNINGLOOP
@SETUPLAST:
MOVUPS XMM4,[EAX-4]
PSLLDQ XMM4,12
PSRLDQ XMM4,12
@ENDALIGNING:
POP EBX
PUSH EBX
MOV ECX,EDX
SAR ECX,2
@LOOP:
MOVAPS XMM0,[EAX]
PXOR XMM5,XMM5
PCMPEQD XMM5,XMM0
PMOVMSKB EBX,XMM5
CMP EBX,$0000FFFF
JNE @NORMAL
PSHUFD XMM0,XMM4,0
JMP @SKIP
@NORMAL:
ADDPS XMM0,XMM4
PSHUFD XMM1,XMM0,$e4
PSLLDQ XMM1,4
PSHUFD XMM2,XMM1,$90
PSHUFD XMM3,XMM1,$40
ADDPS XMM2,XMM3
ADDPS XMM1,XMM2
ADDPS XMM0,XMM1
PSHUFLW XMM4,XMM0,$E4
PSRLDQ XMM4,12
@SKIP:
PREFETCHNTA [eax+16*16*2]
MOVAPS [EAX],XMM0
ADD EAX,16
SUB ECX,1
JNZ @LOOP
POP EBX
MOV ECX,EDX
SAR ECX,2
SHL ECX,2
SUB EDX,ECX
MOV ECX,EDX
JZ @END
@LOOP2:
FLD DWORD PTR [EAX-4]
FADD DWORD PTR [EAX]
FSTP DWORD PTR [EAX]
ADD EAX,4
DEC ECX
JNZ @LOOP2
JMP @END
@SMALL:
MOV ECX,EDX
ADD EAX,4
DEC ECX
@LOOP3:
FLD DWORD PTR [EAX-4]
FADD DWORD PTR [EAX]
FSTP DWORD PTR [EAX]
ADD EAX,4
DEC ECX
JNZ @LOOP3
{$ENDIF}
{$IFDEF TARGET_x64}
CMP EDX,2 // if count < 2, exit
JL @END
MOV EAX,ECX
MOV ECX,EDX
CMP ECX,32 // if count < 32, avoid SSE2 overhead
JL @SMALL
{--- align memory ---}
PXOR XMM4,XMM4
MOV R8D,EAX
AND R8D,15 // get aligned count
JZ @ENDALIGNING // already aligned
ADD R8D,-16
NEG R8D // get bytes to advance
JZ @ENDALIGNING // already aligned
MOV ECX,R8D
SAR ECX,2 // div with 4 to get cnt
SUB EDX,ECX
ADD EAX,4
DEC ECX
JZ @SETUPLAST // one element
@ALIGNINGLOOP:
FLD DWORD PTR [EAX-4]
FADD DWORD PTR [EAX]
FSTP DWORD PTR [EAX]
ADD EAX,4
DEC ECX
JNZ @ALIGNINGLOOP
@SETUPLAST:
MOVUPS XMM4,[EAX-4]
PSLLDQ XMM4,12
PSRLDQ XMM4,12
@ENDALIGNING:
MOV ECX,EDX
SAR ECX,2
@LOOP:
MOVAPS XMM0,[EAX]
PXOR XMM5,XMM5
PCMPEQD XMM5,XMM0
PMOVMSKB R8D,XMM5
CMP R8D,$0000FFFF
JNE @NORMAL
PSHUFD XMM0,XMM4,0
JMP @SKIP
@NORMAL:
ADDPS XMM0,XMM4
PSHUFD XMM1,XMM0,$e4
PSLLDQ XMM1,4
PSHUFD XMM2,XMM1,$90
PSHUFD XMM3,XMM1,$40
ADDPS XMM2,XMM3
ADDPS XMM1,XMM2
ADDPS XMM0,XMM1
PSHUFLW XMM4,XMM0,$E4
PSRLDQ XMM4,12
@SKIP:
PREFETCHNTA [EAX + 32 * 2]
MOVAPS [EAX],XMM0
ADD EAX,16
SUB ECX,1
JNZ @LOOP
MOV ECX,EDX
SAR ECX,2
SHL ECX,2
SUB EDX,ECX
MOV ECX,EDX
JZ @END
@LOOP2:
FLD DWORD PTR [EAX-4]
FADD DWORD PTR [EAX]
FSTP DWORD PTR [EAX]
ADD EAX,4
DEC ECX
JNZ @LOOP2
JMP @END
@SMALL:
MOV ECX,EDX
ADD EAX,4
DEC ECX
@LOOP3:
FLD DWORD PTR [EAX-4]
FADD DWORD PTR [EAX]
FSTP DWORD PTR [EAX]
ADD EAX,4
DEC ECX
JNZ @LOOP3
{$ENDIF}
@END:
end;
{$ENDIF}
procedure ExtractSingleSpan(const ScanLine: TScanLine; out Span: TValueSpan;
SpanData: PSingleArray);
var
I, X: Integer;
P: PFloatPoint;
S: PLineSegment;
fracX: TFloat;
Points: PFloatPointArray;
N: Integer;
begin
N := ScanLine.Count * 2;
Points := @ScanLine.Segments[0];
Span.X1 := High(Integer);
Span.X2 := Low(Integer);
for I := 0 to N - 1 do
begin
P := @Points[I];
X := _Round(P.X);
if X < Span.X1 then Span.X1 := X;
if P.Y = 1 then
begin
fracX := P.X - X;
if Odd(I) then
begin
SpanData[X] := SpanData[X] + (1 - fracX); Inc(X);
SpanData[X] := SpanData[X] + fracX;
end
else
begin
SpanData[X] := SpanData[X] - (1 - fracX); Inc(X);
SpanData[X] := SpanData[X] - fracX;
end;
end;
if X > Span.X2 then Span.X2 := X;
end;
CumSum(@SpanData[Span.X1], Span.X2 - Span.X1 + 1);
for I := 0 to ScanLine.Count - 1 do
begin
S := @ScanLine.Segments[I];
IntegrateSegment(S[0], S[1], SpanData);
end;
Span.Values := @SpanData[Span.X1];
end;
(*
procedure ExtractPackedSpans(const ScanLine: TScanLine; out Spans: PValueSpanArray;
out Count: Integer);
const
SpanDelta = 16; {** N: this constant adjusts the span subdivision size }
var
I, J, X, J1, J2: Integer;
Values: PSingleArray;
SpanData: PSingleArray;
P: TFloatPoint;
S: PLineSegment;
V, fracX: TFloat;
Points: PFloatPointArray;
N, SpanWidth: Integer;
X1, X2: Integer;
Span: PValueSpan;
begin
N := ScanLine.Count * 2;
Points := @ScanLine.Segments[0];
X1 := ScanLine.X1;
X2 := ScanLine.X2;
SpanWidth := X2 - X1 + 1;
FillLongWord(ScanLine.SpanData[0], SpanWidth + 1, 0);
Count := (SpanWidth - 1) div SpanDelta + 1;
GetMem(Spans, Count * SizeOf(TValueSpan));
for I := 0 to Count - 1 do
begin
Spans[I].SpanMode := smPacked;
end;
for I := 0 to ScanLine.Count - 1 do
begin
S := @ScanLine.Segments[I];
J1 := (Round(S[0].X) - X1) div SpanDelta;
J2 := (Round(S[1].X) - X1) div SpanDelta;
if J1 > J2 then Swap(J1, J2);
for J := J1 to J2 do Spans[J].SpanMode := smUnpacked;
end;
SpanData := ScanLine.SpanData;
Values := @SpanData[-X1];
for I := 0 to N - 1 do
begin
P := Points[I];
if P.Y = 1 then
begin
X := Round(P.X);
fracX := P.X - X;
if Odd(I) then
begin
Values[X] := Values[X] + (1 - fracX);
Inc(X);
Values[X] := Values[X] + fracX;
end
else
begin
Values[X] := Values[X] - (1 - fracX);
Inc(X);
Values[X] := Values[X] - fracX;
end;
end;
end;
Span := @Spans[0];
Span.X1 := X1;
Span.Values := @SpanData[0];
for I := 1 to Count - 1 do
begin
if Spans[I].SpanMode <> Span.SpanMode then
begin
X := I * SpanDelta;
Span.X2 := X1 + X - 1;
Inc(Span);
Span^ := Spans[I];
Span.Values := @SpanData[X];
Span.X1 := X1 + X;
end
else
Dec(Count);
end;
Span.X2 := X2;
V := 0;
Span := @Spans[0];
if Span.SpanMode = smPacked then Span.Values[0] := V;
for I := 0 to Count - 1 do
begin
if Span.SpanMode = smPacked then
begin
V := Span.Values[0];
Span.Value := V;
end
else
begin
Span.Values[0] := Span.Values[0] + V;
CumSum(Span.Values, Span.X2 - Span.X1 + 2);
end;
Inc(Span);
end;
for I := 0 to ScanLine.Count - 1 do
begin
S := @ScanLine.Segments[I];
IntegrateSegment(S[0], S[1], Values);
end;
end;
*)
procedure AddSegment(const X1, Y1, X2, Y2: TFloat; var ScanLine: TScanLine); {$IFDEF USEINLINING} inline; {$ENDIF}
var
S: PLineSegment;
begin
if (Y1 = 0) and (Y2 = 0) then Exit; {** needed for proper clipping }
with ScanLine do
begin
S := @Segments[Count];
Inc(Count);
end;
S[0].X := X1;
S[0].Y := Y1;
S[1].X := X2;
S[1].Y := Y2;
end;
procedure DivideSegment(var P1, P2: TFloatPoint; const ScanLines: PScanLineArray);
var
Y, Y1, Y2: Integer;
k, X: TFloat;
begin
Y1 := _Round(P1.Y);
Y2 := _Round(P2.Y);
if Y1 = Y2 then
begin
AddSegment(P1.X, P1.Y - Y1, P2.X, P2.Y - Y1, ScanLines[Y1]);
end
else
begin
k := (P2.X - P1.X) / (P2.Y - P1.Y);
if Y1 < Y2 then
begin
X := P1.X + (Y1 + 1 - P1.Y) * k;
AddSegment(P1.X, P1.Y - Y1, X, 1, ScanLines[Y1]);
for Y := Y1 + 1 to Y2 - 1 do
begin
AddSegment(X, 0, X + k, 1, ScanLines[Y]);
X := X + k;
end;
AddSegment(X, 0, P2.X, P2.Y - Y2, ScanLines[Y2]);
end
else
begin
X := P1.X + (Y1 - P1.Y) * k;
AddSegment(P1.X, P1.Y - Y1, X, 0, ScanLines[Y1]);
for Y := Y1 - 1 downto Y2 + 1 do
begin
AddSegment(X, 1, X - k, 0, ScanLines[Y]);
X := X - k
end;
AddSegment(X, 1, P2.X, P2.Y - Y2, ScanLines[Y2]);
end;
end;
end;
procedure BuildScanLines(const Points: TArrayOfFloatPoint;
out ScanLines: TScanLines);
var
I, J, N, J0, J1, Y, YMin, YMax: Integer;
PScanLines: PScanLineArray;
begin
N := Length(Points);
if N <= 2 then Exit;
YMin := High(Integer);
YMax := Low(Integer);
for I := 0 to N - 1 do
begin
Y := _Round(Points[I].Y);
if YMin > Y then YMin := Y;
if YMax < Y then YMax := Y;
end;
SetLength(ScanLines, YMax - YMin + 2);
PScanLines := @ScanLines[-YMin];
{** compute array sizes for each scanline }
J0 := _Round(Points[0].Y);
for I := 1 to N - 1 do
begin
J1 := J0;
J0 := _Round(Points[I].Y);
if J0 <= J1 then
begin
Inc(PScanLines[J0].Count);
Dec(PScanLines[J1 + 1].Count);
end
else
begin
Inc(PScanLines[J1].Count);
Dec(PScanLines[J0 + 1].Count);
end;
end;
{** allocate memory }
J := 0;
for I := 0 to High(ScanLines) do
begin
Inc(J, ScanLines[I].Count);
GetMem(ScanLines[I].Segments, J * SizeOf(TLineSegment));
ScanLines[I].Count := 0;
ScanLines[I].Y := YMin + I;
end;
for I := 0 to N - 2 do
begin
DivideSegment(Points[I], Points[I + 1], PScanLines);
end;
end;
procedure MergeScanLines(const Src: TScanLines; var Dst: TScanLines);
var
Temp: TScanLines;
I, J, K, SrcCount, DstCount: Integer;
begin
if Length(Src) = 0 then Exit;
SetLength(Temp, Length(Src) + Length(Dst));
I := 0;
J := 0;
K := 0;
while (I <= High(Src)) and (J <= High(Dst)) do
begin
if Src[I].Y = Dst[J].Y then
begin
SrcCount := Src[I].Count;
DstCount := Dst[J].Count;
Temp[K].Count := SrcCount + DstCount;
Temp[K].Y := Src[I].Y;
GetMem(Temp[K].Segments, Temp[K].Count * SizeOf(TLineSegment));
Move(Src[I].Segments[0], Temp[K].Segments[0], SrcCount * SizeOf(TLineSegment));
Move(Dst[J].Segments[0], Temp[K].Segments[SrcCount], DstCount * SizeOf(TLineSegment));
FreeMem(Src[I].Segments);
FreeMem(Dst[J].Segments);
Inc(I);
Inc(J);
end
else if Src[I].Y < Dst[J].Y then
begin
Temp[K] := Src[I];
Inc(I);
end
else
begin
Temp[K] := Dst[J];
Inc(J);
end;
Inc(K);
end;
while I <= High(Src) do
begin
Temp[K] := Src[I];
Inc(I); Inc(K);
end;
while J <= High(Dst) do
begin
Temp[K] := Dst[J];
Inc(J); Inc(K);
end;
Dst := Copy(Temp, 0, K);
end;
type
TExtractSpanProc = procedure(const ScanLine: TScanLine; out Span: TValueSpan; //PValueSpanArray;
SpanData: PSingleArray);
procedure RenderScanline(var ScanLine: TScanLine;
ExtractProc: TExtractSpanProc;
RenderProc: TRenderSpanProc; Data: Pointer; SpanData: PSingleArray; X1, X2: Integer);
var
Span: TValueSpan;
begin
if ScanLine.Count > 0 then
begin
ExtractProc(ScanLine, Span, SpanData);
if Span.X1 < X1 then Span.X1 := X1;
if Span.X2 > X2 then Span.X2 := X2;
if Span.X2 < Span.X1 then Exit;
RenderProc(Data, Span, ScanLine.Y);
FillLongWord(SpanData[Span.X1], Span.X2 - Span.X1 + 1, 0);
end;
end;
procedure RenderPolyPolygon(const Points: TArrayOfArrayOfFloatPoint;
const ClipRect: TFloatRect; const RenderProc: TRenderSpanProc; Data: Pointer);
var
ScanLines, Temp: TScanLines;
I: Integer;
Poly: TArrayOfFloatPoint;
SavedRoundMode: TFPURoundingMode;
CX1, CX2: Integer;
SpanData: PSingleArray;
begin
if Length(Points) = 0 then Exit;
SavedRoundMode := SetRoundMode(rmDown);
try
Poly := ClosePolygon(ClipPolygon(Points[0], ClipRect));
BuildScanLines(Poly, ScanLines);
for I := 1 to High(Points) do
begin
Poly := ClosePolygon(ClipPolygon(Points[I], ClipRect));
BuildScanLines(Poly, Temp);
MergeScanLines(Temp, ScanLines);
Temp := nil;
end;
CX1 := Round(ClipRect.Left);
CX2 := -Round(-ClipRect.Right) - 1;
I := CX2 - CX1 + 4;
GetMem(SpanData, I * SizeOf(Single));
FillLongWord(SpanData^, I, 0);
for I := 0 to High(ScanLines) do
begin
RenderScanline(ScanLines[I], ExtractSingleSpan, RenderProc, Data,
@SpanData[-CX1 + 1], CX1, CX2);
FreeMem(ScanLines[I].Segments);
end;
FreeMem(SpanData);
finally
SetRoundMode(SavedRoundMode);
end;
end;
procedure RenderPolygon(const Points: TArrayOfFloatPoint;
const ClipRect: TFloatRect; const RenderProc: TRenderSpanProc; Data: Pointer);
var
H: TArrayOfArrayOfFloatPoint;
begin
SetLength(H, 1);
H[0] := Points;
RenderPolyPolygon(H, ClipRect, RenderProc, Data);
end;
procedure RenderPolyPolygon(const Points: TArrayOfArrayOfFloatPoint;
const ClipRect: TFloatRect; const RenderProc: TRenderSpanEvent);
begin
with TMethod(RenderProc) do
RenderPolyPolygon(Points, ClipRect, Code, Data);
end;
procedure RenderPolygon(const Points: TArrayOfFloatPoint;
const ClipRect: TFloatRect; const RenderProc: TRenderSpanEvent);
begin
with TMethod(RenderProc) do
RenderPolygon(Points, ClipRect, Code, Data);
end;
{$IFNDEF PUREPASCAL}
const
CumSumProcs: array [Boolean] of TCumSumProc = (CumSum_Native, CumSum_SSE2);
{$ENDIF}
initialization
{$IFDEF PUREPASCAL}
CumSum := CumSum_Native;
{$ELSE}
CumSum := CumSumProcs[HasInstructionSet(ciSSE2)];
{$ENDIF}
end.