summaryrefslogtreecommitdiff
path: root/drawinglayer/source/processor3d/defaultprocessor3d.cxx
blob: 4d11f2bd8fb7c89a96bd63161aeae5a922d025dc (plain)
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
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: defaultprocessor3d.cxx,v $
 *
 *  $Revision: 1.1 $
 *
 *  last change: $Author: aw $ $Date: 2006-08-09 16:57:47 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _DRAWINGLAYER_PROCESSOR3D_DEFAULTPROCESSOR3D_HXX
#include <drawinglayer/processor3d/defaultprocessor3d.hxx>
#endif

#ifndef _SV_BMPACC_HXX
#include <vcl/bmpacc.hxx>
#endif

#ifndef _BGFX_POLYGON_B3DPOLYGON_HXX
#include <basegfx/polygon/b3dpolygon.hxx>
#endif

#ifndef _DRAWINGLAYER_PRIMITIVE3D_POLYGONPRIMITIVE3D_HXX
#include <drawinglayer/primitive3d/polygonprimitive3d.hxx>
#endif

#ifndef _DRAWINGLAYER_PRIMITIVE3D_MODIFIEDCOLORPRIMITIVE3D_HXX
#include <drawinglayer/primitive3d/modifiedcolorprimitive3d.hxx>
#endif

#ifndef _DRAWINGLAYER_PRIMITIVE3D_POLYPOLYGONPRIMITIVE_HXX
#include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx>
#endif

#ifndef _BGFX_POLYPOLYGON_B3DPOLYGONCLIPPER_HXX
#include <basegfx/polygon/b3dpolygonclipper.hxx>
#endif

#ifndef _BGFX_RASTER_BZPIXELRASTER_HXX
#include <basegfx/raster/bzpixelraster.hxx>
#endif

#ifndef _DRAWINGLAYER_ATTRIBUTE_SDRATTRIBUTE3D_HXX
#include <drawinglayer/attribute/sdrattribute3d.hxx>
#endif

#ifndef _BGFX_POLYGON_B3DPOLYGONTOOLS_HXX
#include <basegfx/polygon/b3dpolygontools.hxx>
#endif

#ifndef _BGFX_POLYPOLYGON_B3DPOLYGONTOOLS_HXX
#include <basegfx/polygon/b3dpolypolygontools.hxx>
#endif

#ifndef _DRAWINGLAYER_PRIMITIVE3D_TEXTUREPRIMITIVE3D_HXX
#include <drawinglayer/primitive3d/textureprimitive3d.hxx>
#endif

#ifndef _DRAWINGLAYER_PRIMITIVE3D_HATCHTEXTUREPRIMITIVE3D_HXX
#include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
#endif

#ifndef _DRAWINGLAYER_PRIMITIVE3D_TRANSFORMPRIMITIVE3D_HXX
#include <drawinglayer/primitive3d/transformprimitive3d.hxx>
#endif

//////////////////////////////////////////////////////////////////////////////

namespace basegfx
{
    class BDInterpolator
    {
    protected:
        double                                      mfVal;
        double                                      mfInc;

    public:
        BDInterpolator() {}
        BDInterpolator(double fValA, double fValB, sal_uInt32 nCount) : mfVal(fValA), mfInc((fValB - fValA) / (double)nCount) {}

        double getVal() const { return mfVal; }
        double getInc() const { return mfInc; }
        void increment() { mfVal += mfInc; }
        void increment(double fStep) { mfVal += fStep * mfInc; }
    };

    class BColorInterpolator
    {
    protected:
        BColor                                      maVal;
        BColor                                      maInc;

    public:
        BColorInterpolator() {}
        BColorInterpolator(const BColor& rValA, const BColor& rValB, sal_uInt32 nCount) : maVal(rValA), maInc((rValB - rValA) / (double)nCount) {}

        const BColor& getVal() const { return maVal; }
        const BColor& getInc() const { return maInc; }
        void increment() { maVal += maInc; }
        void increment(double fStep) { maVal += fStep * maInc; }
    };

    class B3DVectorInterpolator
    {
    protected:
        B3DVector                                   maVal;
        B3DVector                                   maInc;

    public:
        B3DVectorInterpolator() {}
        B3DVectorInterpolator(const B3DVector& rValA, const B3DVector& rValB, sal_uInt32 nCount) : maVal(rValA), maInc((rValB - rValA) / (double)nCount) {}

        const B3DVector& getVal() const { return maVal; }
        const B3DVector& getInc() const { return maInc; }
        void increment() { maVal += maInc; }
        void increment(double fStep) { maVal += fStep * maInc; }
    };

    class B2DPointInterpolator
    {
    protected:
        B2DPoint                                    maVal;
        B2DPoint                                    maInc;
        BDInterpolator                              maZInv;

    public:
        B2DPointInterpolator() {}
        B2DPointInterpolator(const B2DPoint& rValA, const B2DPoint& rValB, double fInvZEyeA, double fInvZEyeB, sal_uInt32 nCount)
        :   maVal(rValA),
            maInc((rValB - rValA) / (double)nCount),
            maZInv(fInvZEyeA, fInvZEyeB, nCount)
        {}

        const B2DPoint& getVal() const { return maVal; }
        const B2DPoint& getInc() const { return maInc; }
        double getZVal() const { return maZInv.getVal(); }
        double getZInc() const { return maZInv.getInc(); }
        void increment() { maVal += maInc; maZInv.increment(); }
        void increment(double fStep) { maVal += fStep * maInc; maZInv.increment(fStep); }
    };
} // end of namespace basegfx

//////////////////////////////////////////////////////////////////////////////

#define SCANLINE_EMPTY_INDEX (0xffffffff)

namespace basegfx
{
    class B3DScanlineEntry
    {
    protected:
        sal_Int32                                   mnLine;
        sal_uInt32                                  mnLineCount;
        BDInterpolator                              maX;
        BDInterpolator                              maZ;

        // values for normal and texture coordinate interpolation are optional,
        // held simply by an index. Empty is marked by SCANLINE_EMPTY_INDEX to which it needs
        // to be initialized
        sal_uInt32                                  mnBColorIndex;
        sal_uInt32                                  mnNormalIndex;
        sal_uInt32                                  mnTextureCoordinateIndex;

    public:
        B3DScanlineEntry() {}

        // data write access
        void setLine(sal_Int32 nLine) { mnLine = nLine; }
        void setLineCount(sal_uInt32 nLineCount) { mnLineCount = nLineCount; }
        void setXInterpolator(const BDInterpolator& rInt) { maX = rInt; }
        void setZInterpolator(const BDInterpolator& rInt) { maZ = rInt; }
        void setBColorIndex(sal_uInt32 nIndex) { mnBColorIndex = nIndex; }
        void setNormalIndex(sal_uInt32 nIndex) { mnNormalIndex = nIndex; }
        void setTextureCoordinateIndex(sal_uInt32 nIndex) { mnTextureCoordinateIndex = nIndex; }

        // data read access
        sal_Int32 getLine() const { return mnLine; }
        sal_uInt32 getLineCount() const { return mnLineCount; }
        const BDInterpolator& getXInterpolator() const { return maX; }
        const BDInterpolator& getZInterpolator() const { return maZ; }
        sal_uInt32 getBColorIndex() const {return mnBColorIndex; }
        sal_uInt32 getNormalIndex() const {return mnNormalIndex; }
        sal_uInt32 getTextureCoordinateIndex() const {return mnTextureCoordinateIndex; }

        bool simpleLineSortComparator(const B3DScanlineEntry& rComp) const
        {
            return (maX.getVal() < rComp.maX.getVal());
        }

        bool operator<(const B3DScanlineEntry& rComp) const
        {
            if(mnLine == rComp.mnLine)
            {
                return simpleLineSortComparator(rComp);
            }

            return (mnLine < rComp.mnLine);
        }

        bool isValid() const
        {
            return (0L != mnLineCount);
        }

        bool decrement(sal_uInt32 nCount = 1L)
        {
            if(mnLineCount > nCount)
            {
                mnLineCount -= nCount;
                return true;
            }
            else
            {
                mnLineCount = 0L;
                return false;
            }
        }

        void increment()
        {
            maX.increment();
            maZ.increment();
        }

        void increment(double fStep)
        {
            maX.increment(fStep);
            maZ.increment(fStep);
        }
    };
} // end of namespace basegfx

//////////////////////////////////////////////////////////////////////////////

namespace basegfx
{
    class B3DPolyPolygonRasterConverter
    {
    protected:
        ::std::vector< B3DScanlineEntry >               maGlobalEntries;
        ::std::vector< BColorInterpolator >             maGlobalBColorInterpolators;
        ::std::vector< B3DVectorInterpolator >          maGlobalNormalInterpolators;
        ::std::vector< B2DPointInterpolator >           maGlobalTextureCoordinateInterpolators;

        // bitfield
        unsigned                                        mbAreaMode : 1;

        struct scanlineEntryComparator
        {
            bool operator()( const B3DScanlineEntry* pA, const B3DScanlineEntry* pB)
            {
                // here, Y is the same anyways (sorting a scanline), so simple compare is enough
                OSL_ENSURE(pA && pB, "scanlineEntryComparator: empty pointer (!)");
                return pA->simpleLineSortComparator(*pB);
            }
        };

        // add BColor interpolator, return index
        sal_uInt32 addBColor(const BColor& rA, const BColor& rB, sal_uInt32 nDelta)
        {
            maGlobalBColorInterpolators.push_back(BColorInterpolator(rA, rB, nDelta));
            return (maGlobalBColorInterpolators.size() - 1L);
        }

        // add normal interpolator, return index
        sal_uInt32 addNormal(const B3DVector& rA, const B3DVector& rB, sal_uInt32 nDelta)
        {
            maGlobalNormalInterpolators.push_back(B3DVectorInterpolator(rA, rB, nDelta));
            return (maGlobalNormalInterpolators.size() - 1L);
        }

        // add texture interpolator, return index
        sal_uInt32 addTextureCoordinate(const B2DPoint& rA, const B2DPoint& rB, double fZEyeA, double fZEyeB, sal_uInt32 nDelta)
        {
            const double fInvZEyeA(fTools::equalZero(fZEyeA) ? fZEyeA : 1.0 / fZEyeA);
            const double fInvZEyeB(fTools::equalZero(fZEyeB) ? fZEyeB : 1.0 / fZEyeB);
            maGlobalTextureCoordinateInterpolators.push_back(B2DPointInterpolator(rA * fInvZEyeA, rB * fInvZEyeB, fInvZEyeA, fInvZEyeB, nDelta));
            return (maGlobalTextureCoordinateInterpolators.size() - 1L);
        }

        void increment(B3DScanlineEntry& rScanEntry)
        {
            rScanEntry.increment();

            const sal_uInt32 nBColor(rScanEntry.getBColorIndex());

            if(SCANLINE_EMPTY_INDEX != nBColor)
            {
                maGlobalBColorInterpolators[nBColor].increment();
            }

            const sal_uInt32 nNormal(rScanEntry.getNormalIndex());

            if(SCANLINE_EMPTY_INDEX != nNormal)
            {
                maGlobalNormalInterpolators[nNormal].increment();
            }

            const sal_uInt32 nTextureCoordinate(rScanEntry.getTextureCoordinateIndex());

            if(SCANLINE_EMPTY_INDEX != nTextureCoordinate)
            {
                maGlobalTextureCoordinateInterpolators[nTextureCoordinate].increment();
            }
        }

        void increment(B3DScanlineEntry& rScanEntry, double fStep)
        {
            rScanEntry.increment(fStep);

            const sal_uInt32 nBColor(rScanEntry.getBColorIndex());

            if(SCANLINE_EMPTY_INDEX != nBColor)
            {
                maGlobalBColorInterpolators[nBColor].increment(fStep);
            }

            const sal_uInt32 nNormal(rScanEntry.getNormalIndex());

            if(SCANLINE_EMPTY_INDEX != nNormal)
            {
                maGlobalNormalInterpolators[nNormal].increment(fStep);
            }

            const sal_uInt32 nTextureCoordinate(rScanEntry.getTextureCoordinateIndex());

            if(SCANLINE_EMPTY_INDEX != nTextureCoordinate)
            {
                maGlobalTextureCoordinateInterpolators[nTextureCoordinate].increment(fStep);
            }
        }

        void addEdge(const B3DPolygon& rPolygon, const B3DHomMatrix& rInvEyeToView, sal_uInt32 nIndA, sal_uInt32 nIndB)
        {
            B3DPoint aPntA(rPolygon.getB3DPoint(nIndA));
            B3DPoint aPntB(rPolygon.getB3DPoint(nIndB));
            sal_Int32 nLineA((sal_Int32)(aPntA.getY()));
            sal_Int32 nLineB((sal_Int32)(aPntB.getY()));

            if(nLineA == nLineB)
            {
                if(!mbAreaMode)
                {
                    B3DScanlineEntry aNewEntry;

                    aNewEntry.setLine(nLineA);
                    aNewEntry.setLineCount(0L);
                    aNewEntry.setXInterpolator(BDInterpolator(aPntA.getX(), aPntB.getX(), 1L));
                    aNewEntry.setZInterpolator(BDInterpolator(aPntA.getZ(), aPntB.getZ(), 1L));
                    aNewEntry.setBColorIndex(SCANLINE_EMPTY_INDEX);
                    aNewEntry.setNormalIndex(SCANLINE_EMPTY_INDEX);
                    aNewEntry.setTextureCoordinateIndex(SCANLINE_EMPTY_INDEX);

                    maGlobalEntries.push_back(aNewEntry);
                }
            }
            else
            {
                if(nLineB < nLineA)
                {
                    ::std::swap(aPntA, aPntB);
                    ::std::swap(nLineA, nLineB);
                    ::std::swap(nIndA, nIndB);
                }

                const sal_uInt32 nLineDelta(nLineB - nLineA);
                B3DScanlineEntry aNewEntry;

                aNewEntry.setLine(nLineA);
                aNewEntry.setLineCount(nLineDelta);
                aNewEntry.setXInterpolator(BDInterpolator(aPntA.getX(), aPntB.getX(), nLineDelta));
                aNewEntry.setZInterpolator(BDInterpolator(aPntA.getZ(), aPntB.getZ(), nLineDelta));

                const bool bColUsed(mbAreaMode && rPolygon.areBColorsUsed());
                aNewEntry.setBColorIndex(bColUsed ? addBColor(rPolygon.getBColor(nIndA), rPolygon.getBColor(nIndB), nLineDelta) : SCANLINE_EMPTY_INDEX);

                const bool bNrmUsed(mbAreaMode && rPolygon.areNormalsUsed());
                aNewEntry.setNormalIndex(bNrmUsed ? addNormal(rPolygon.getNormal(nIndA), rPolygon.getNormal(nIndB), nLineDelta) : SCANLINE_EMPTY_INDEX);

                const bool bTexUsed(mbAreaMode && rPolygon.areTextureCoordinatesUsed());
                if(bTexUsed)
                {
                    const double fEyeA((rInvEyeToView * aPntA).getZ());
                    const double fEyeB((rInvEyeToView * aPntB).getZ());
                    aNewEntry.setTextureCoordinateIndex(addTextureCoordinate(
                        rPolygon.getTextureCoordinate(nIndA),
                        rPolygon.getTextureCoordinate(nIndB),
                        fEyeA, fEyeB, nLineDelta));
                }
                else
                {
                    aNewEntry.setTextureCoordinateIndex(SCANLINE_EMPTY_INDEX);
                }

                maGlobalEntries.push_back(aNewEntry);
            }
        }

        // virtual rasterconverter
        virtual void processSpan(const B3DScanlineEntry& rA, const B3DScanlineEntry& rB, sal_Int32 nLine, sal_uInt32 nSpanCount) = 0;
        virtual void processLine(const B3DScanlineEntry& rEntry, sal_Int32 nLine) = 0;

    public:
        B3DPolyPolygonRasterConverter(bool bArea)
        :   mbAreaMode(bArea)
        {
        }

        void addPolygon(const B3DPolygon& rPolygon, const B3DHomMatrix& rInvEyeToView)
        {
            const sal_uInt32 nPointCount(rPolygon.count());

            if(nPointCount)
            {
                const sal_uInt32 nLoopCount((mbAreaMode || rPolygon.isClosed()) ? nPointCount : nPointCount - 1L);
                const bool bEnoughEdges(mbAreaMode ? (nLoopCount > 2L) : (nLoopCount > 0L));

                if(bEnoughEdges)
                {
                    for(sal_uInt32 a(0L); a < nLoopCount; a++)
                    {
                        addEdge(rPolygon, rInvEyeToView, a, (a + 1L) % nPointCount);
                    }
                }
            }
        }

        void rasterconvert(sal_Int32 nStartLine, sal_Int32 nStopLine)
        {
            OSL_ENSURE(nStartLine <= nStopLine, "rasterconvert: wrong start/stop line (!)");

            if(maGlobalEntries.size())
            {
                // sort global entries by YStart, xPos once
                ::std::sort(maGlobalEntries.begin(), maGlobalEntries.end());

                // local parameters
                ::std::vector< B3DScanlineEntry >::iterator aCurrentGlobalEntry(maGlobalEntries.begin());
                ::std::vector< B3DScanlineEntry* > aCurrentScanLine;
                ::std::vector< B3DScanlineEntry* > aNextScanLine;
                ::std::vector< B3DScanlineEntry* >::iterator aScanLineEntry;
                sal_Int32 nLineNumber(nStartLine);
                sal_uInt32 nPairCount;

                while((nLineNumber < nStopLine) && (aCurrentScanLine.size() || aCurrentGlobalEntry != maGlobalEntries.end()))
                {
                    // add all global entries which start at current Y to current scanline
                    while(aCurrentGlobalEntry != maGlobalEntries.end() && aCurrentGlobalEntry->getLine() <= nLineNumber)
                    {
                        if(aCurrentGlobalEntry->getLine() < nLineNumber)
                        {
                            // adapt to current line in nLineNumber by decrementing count incrementing accordigly
                            const sal_uInt32 nLineDiff(nLineNumber - aCurrentGlobalEntry->getLine());

                            if(aCurrentGlobalEntry->decrement(nLineDiff))
                            {
                                increment(*aCurrentGlobalEntry, (double)nLineDiff);
                                aCurrentScanLine.push_back(&(*(aCurrentGlobalEntry)));
                            }
                        }
                        else
                        {
                            aCurrentScanLine.push_back(&(*(aCurrentGlobalEntry)));
                        }

                        aCurrentGlobalEntry++;
                    }

                    if(mbAreaMode)
                    {
                        // sort current scanline using simple comparator (only X is compared)
                        ::std::sort(aCurrentScanLine.begin(), aCurrentScanLine.end(), scanlineEntryComparator());
                    }

                    // process current scanline
                    aScanLineEntry = aCurrentScanLine.begin();
                    aNextScanLine.clear();
                    nPairCount = 0L;

                    while(aScanLineEntry != aCurrentScanLine.end())
                    {
                        B3DScanlineEntry& rPrevScanLineEntry(**aScanLineEntry++);

                        if(mbAreaMode)
                        {
                            // area mode, look for 2nd span
                            if(aScanLineEntry != aCurrentScanLine.end())
                            {
                                // work on span from rPrevScanLineEntry to aScanLineEntry, nLineNumber is valid
                                processSpan(rPrevScanLineEntry, **aScanLineEntry, nLineNumber, nPairCount++);
                            }
                        }
                        else
                        {
                            // work on line position rPrevScanLineEntry
                            processLine(rPrevScanLineEntry, nLineNumber);
                        }

                        // do decrement counter and (evtl) increment to next line
                        if(rPrevScanLineEntry.decrement())
                        {
                            increment(rPrevScanLineEntry);
                            aNextScanLine.push_back(&rPrevScanLineEntry);
                        }
                    }

                    // copy back next scanline if count has changed
                    if(aNextScanLine.size() != aCurrentScanLine.size())
                    {
                        aCurrentScanLine = aNextScanLine;
                    }

                    // increment nLineNumber
                    nLineNumber++;
                }
            }
        }
    };
} // end of namespace basegfx

//////////////////////////////////////////////////////////////////////////////

namespace basegfx
{
    BitmapEx getBitmapEx(const BPixelRaster& rRaster)
    {
        BitmapEx aRetval;
        const sal_uInt32 nWidth(rRaster.getWidth());
        const sal_uInt32 nHeight(rRaster.getHeight());

        if(nWidth && nHeight)
        {
            sal_uInt8 nInitAlpha(255);
            Bitmap aContent(Size(nWidth, nHeight), 24);
            AlphaMask aAlpha(Size(nWidth, nHeight), &nInitAlpha);
            BitmapWriteAccess* pContent = aContent.AcquireWriteAccess();
            BitmapWriteAccess* pAlpha = aAlpha.AcquireWriteAccess();

            if(pContent && pAlpha)
            {
                sal_uInt32 nIndex(0L);

                for(sal_uInt32 y(0L); y < nHeight; y++)
                {
                    for(sal_uInt32 x(0L); x < nWidth; x++)
                    {
                        const BPixel& rPixel(rRaster.getBPixel(nIndex++));

                        if(rPixel.getOpacity())
                        {
                            pContent->SetPixel(y, x, BitmapColor(rPixel.getRed(), rPixel.getGreen(), rPixel.getBlue()));
                            pAlpha->SetPixel(y, x, BitmapColor(255 - rPixel.getOpacity()));
                        }
                    }
                }

                delete pContent;
                delete pAlpha;
            }

            aRetval = BitmapEx(aContent, aAlpha);
        }

        return aRetval;
    }
} // end of namespace basegfx

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

namespace drawinglayer
{
    namespace
    {
        class BZPolyRaCon : public basegfx::B3DPolyPolygonRasterConverter
        {
        protected:
            basegfx::BZPixelRaster&                     mrBuffer;
            const attribute::materialAttribute3D&           mrMaterial;
            const processor3d::defaultProcessor3D&  mrProcessor;

            // virtual rasterconverter
            virtual void processSpan(const basegfx::B3DScanlineEntry& rA, const basegfx::B3DScanlineEntry& rB, sal_Int32 nLine, sal_uInt32 nSpanCount);
            virtual void processLine(const basegfx::B3DScanlineEntry& rEntry, sal_Int32 nLine);

        public:
            BZPolyRaCon(
                bool bArea,
                basegfx::BZPixelRaster& rBuffer,
                const attribute::materialAttribute3D& rMaterial,
                const processor3d::defaultProcessor3D& rProcessor)
            :   B3DPolyPolygonRasterConverter(bArea),
                mrBuffer(rBuffer),
                mrMaterial(rMaterial),
                mrProcessor(rProcessor)
            {}
        };

        void BZPolyRaCon::processSpan(const basegfx::B3DScanlineEntry& rA, const basegfx::B3DScanlineEntry& rB, sal_Int32 nLine, sal_uInt32 nSpanCount)
        {
            if(!(nSpanCount & 0x0001))
            {
                if(nLine >= 0L && nLine < (sal_Int32)mrBuffer.getHeight())
                {
                    sal_Int32 nXA((sal_Int32)(rA.getXInterpolator().getVal()));
                    sal_Int32 nXB((sal_Int32)(rB.getXInterpolator().getVal()));
                    OSL_ENSURE(nXB >= nXA,"processSpan: positive run expected (!)");

                    if(nXB > nXA)
                    {
                        // initialize Z interpolator
                        const sal_uInt32 nSpanLength(nXB - nXA);
                        basegfx::BDInterpolator aZ(rA.getZInterpolator().getVal(), rB.getZInterpolator().getVal(), nSpanLength);

                        // prepare some references to used variables
                        const basegfx::BColor& rColor(mrMaterial.getColor());
                        const basegfx::BColor& rSpecular(mrMaterial.getSpecular());
                        const basegfx::BColor& rEmission(mrMaterial.getEmission());
                        const sal_uInt16 nSpecularIntensity(mrMaterial.getSpecularIntensity());

                        // get bools and init other interpolators on demand accordingly
                        const bool bUseTex((mrProcessor.getGeoTexSvx() || mrProcessor.getTransparenceGeoTexSvx()) && rA.getTextureCoordinateIndex() != SCANLINE_EMPTY_INDEX && rB.getTextureCoordinateIndex() != SCANLINE_EMPTY_INDEX);
                        const bool bUseColorTex(bUseTex && mrProcessor.getGeoTexSvx());
                        const bool bNeedOthers(!bUseColorTex || (bUseColorTex && mrProcessor.getModulate()));
                        const bool bUseNrm(bNeedOthers && rA.getNormalIndex() != SCANLINE_EMPTY_INDEX && rB.getNormalIndex() != SCANLINE_EMPTY_INDEX);
                        const bool bUseCol(!bUseNrm && bNeedOthers && rA.getBColorIndex() != SCANLINE_EMPTY_INDEX && rB.getBColorIndex() != SCANLINE_EMPTY_INDEX);
                        const bool bModifyColor(mrProcessor.getBColorModifierStack().count());
                        basegfx::B2DPointInterpolator aTex;
                        basegfx::B3DVectorInterpolator aNrm;
                        basegfx::BColorInterpolator aCol;

                        if(bUseTex)
                        {
                            const basegfx::B2DPointInterpolator& rA(maGlobalTextureCoordinateInterpolators[rA.getTextureCoordinateIndex()]);
                            const basegfx::B2DPointInterpolator& rB(maGlobalTextureCoordinateInterpolators[rB.getTextureCoordinateIndex()]);
                            aTex = basegfx::B2DPointInterpolator(rA.getVal(), rB.getVal(), rA.getZVal(), rB.getZVal(), nSpanLength);
                        }

                        if(bUseNrm)
                        {
                            aNrm = basegfx::B3DVectorInterpolator(
                                maGlobalNormalInterpolators[rA.getNormalIndex()].getVal(),
                                maGlobalNormalInterpolators[rB.getNormalIndex()].getVal(),
                                nSpanLength);
                        }

                        if(bUseCol)
                        {
                            aCol = basegfx::BColorInterpolator(
                                maGlobalBColorInterpolators[rA.getBColorIndex()].getVal(),
                                maGlobalBColorInterpolators[rB.getBColorIndex()].getVal(),
                                nSpanLength);
                        }

                        if(nXA < 0L)
                        {
                            const double fIncrement(-nXA);
                            nXA = 0L;
                            aZ.increment(fIncrement);

                            if(bUseTex)
                            {
                                aTex.increment(fIncrement);
                            }

                            if(bUseNrm)
                            {
                                aNrm.increment(fIncrement);
                            }

                            if(bUseCol)
                            {
                                aCol.increment(fIncrement);
                            }
                        }

                        if(nXB > (sal_Int32)mrBuffer.getWidth())
                        {
                            nXB = mrBuffer.getWidth();
                        }

                        if(nXA < nXB)
                        {
                            sal_uInt32 nScanlineIndex(mrBuffer.getIndexFromXY((sal_uInt32)nXA, (sal_uInt32)nLine));

                            while(nXA < nXB)
                            {
                                // get old and new Z to see if we need to do somethng at all
                                sal_uInt16& rOldZ(mrBuffer.getZ(nScanlineIndex));
                                const sal_uInt16 nNewZ((sal_uInt16)(aZ.getVal()));

                                if(nNewZ > rOldZ)
                                {
                                    // prepare color
                                    basegfx::BColor aNewColor(rColor);
                                    double fOpacity(1.0);
                                    bool bOpacity(true);

                                    if(bUseTex)
                                    {
                                        // get texture coor
                                        const basegfx::B2DPoint aTexCoor(aTex.getVal() / aTex.getZVal());

                                        if(mrProcessor.getGeoTexSvx())
                                        {
                                            // calc color in spot
                                            mrProcessor.getGeoTexSvx()->modifyBColor(aTexCoor, aNewColor, fOpacity);
                                            bOpacity = basegfx::fTools::more(fOpacity, 0.0);
                                        }

                                        if(bOpacity && mrProcessor.getTransparenceGeoTexSvx())
                                        {
                                            // calc opacity
                                            mrProcessor.getTransparenceGeoTexSvx()->modifyOpacity(aTexCoor, fOpacity);
                                            bOpacity = basegfx::fTools::more(fOpacity, 0.0);
                                        }
                                    }

                                    if(bOpacity)
                                    {
                                        if(mrProcessor.getGeoTexSvx())
                                        {
                                            if(bUseNrm)
                                            {
                                                // blend texture with phong
                                                aNewColor = mrProcessor.getSdrLightingAttribute().solveColorModel(aNrm.getVal(), aNewColor, rSpecular, rEmission, nSpecularIntensity);
                                            }
                                            else if(bUseCol)
                                            {
                                                // blend texture with gouraud
                                                aNewColor *= aCol.getVal();
                                            }
                                            else if(mrProcessor.getModulate())
                                            {
                                                // blend texture with single material color
                                                aNewColor *= rColor;
                                            }
                                        }
                                        else
                                        {
                                            if(bUseNrm)
                                            {
                                                // modify color with phong
                                                aNewColor = mrProcessor.getSdrLightingAttribute().solveColorModel(aNrm.getVal(), rColor, rSpecular, rEmission, nSpecularIntensity);
                                            }
                                            else if(bUseCol)
                                            {
                                                // modify color with gouraud
                                                aNewColor = aCol.getVal();
                                            }
                                        }

                                        if(bModifyColor)
                                        {
                                            aNewColor = mrProcessor.getBColorModifierStack().getModifiedColor(aNewColor);
                                        }

                                        if(basegfx::fTools::moreOrEqual(fOpacity, 1.0))
                                        {
                                            // full opacity, set z and color
                                            rOldZ = nNewZ;
                                            mrBuffer.getBPixel(nScanlineIndex) = basegfx::BPixel(aNewColor, 0xff);
                                        }
                                        else
                                        {
                                            basegfx::BPixel& rDest = mrBuffer.getBPixel(nScanlineIndex);

                                            if(rDest.getOpacity())
                                            {
                                                // mix color and existing color
                                                const double fOld(1.0 - fOpacity);
                                                fOpacity *= 255.0;
                                                rDest.setRed((sal_uInt8)(((double)rDest.getRed() * fOld) + (aNewColor.getRed() * fOpacity)));
                                                rDest.setGreen((sal_uInt8)(((double)rDest.getGreen() * fOld) + (aNewColor.getGreen() * fOpacity)));
                                                rDest.setBlue((sal_uInt8)(((double)rDest.getBlue() * fOld) + (aNewColor.getBlue() * fOpacity)));

                                                if((sal_uInt8)255 != rDest.getOpacity())
                                                {
                                                    // mix opacities by adding
                                                    double fNewOpacity(rDest.getOpacity() + fOpacity);

                                                    if(fNewOpacity > 255.0)
                                                    {
                                                        // set full opacity
                                                        rDest.setOpacity(0xff);
                                                    }
                                                    else
                                                    {
                                                        // set new opacity which is still transparent, so set no z
                                                        rDest.setOpacity((sal_uInt8)(fNewOpacity));
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                // set color and opacity
                                                rDest = basegfx::BPixel(aNewColor, (sal_uInt8)(fOpacity * 255.0));
                                            }
                                        }
                                    }
                                }

                                // increments
                                {
                                    nScanlineIndex++;
                                    nXA++;
                                    aZ.increment();

                                    if(bUseTex)
                                    {
                                        aTex.increment();
                                    }

                                    if(bUseNrm)
                                    {
                                        aNrm.increment();
                                    }

                                    if(bUseCol)
                                    {
                                        aCol.increment();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        void BZPolyRaCon::processLine(const basegfx::B3DScanlineEntry& rEntry, sal_Int32 nLine)
        {
            if(nLine >= 0L && nLine < (sal_Int32)mrBuffer.getHeight())
            {
                sal_Int32 nXA((sal_uInt32)(rEntry.getXInterpolator().getVal()));
                sal_Int32 nXB((sal_uInt32)(rEntry.getXInterpolator().getVal() + rEntry.getXInterpolator().getInc()));

                if(nXA == nXB)
                {
                    // only one position, get values and set direct
                    if(nXA >= 0L && nXA < (sal_Int32)mrBuffer.getWidth())
                    {
                        const sal_uInt32 nScanlineIndex(mrBuffer.getIndexFromXY((sal_uInt32)nXA, (sal_uInt32)nLine));
                        sal_uInt16& rOldZ(mrBuffer.getZ(nScanlineIndex));
                        const sal_uInt16 nNewZ((sal_uInt16)(rEntry.getZInterpolator().getVal()) + 0x00ff);

                        if(nNewZ > rOldZ)
                        {
                            rOldZ = nNewZ;
                            mrBuffer.getBPixel(nScanlineIndex) = basegfx::BPixel(mrMaterial.getColor(), 0xff);
                        }
                    }
                }
                else
                {
                    const sal_uInt32 nScanlineIndexLine(mrBuffer.getIndexFromXY(0L, (sal_uInt32)nLine));
                    double fZStart(rEntry.getZInterpolator().getVal());
                    double fZStop(fZStart + rEntry.getZInterpolator().getInc());

                    if(nXB < nXA)
                    {
                        ::std::swap(nXB, nXA);
                        ::std::swap(fZStart, fZStop);
                    }

                    const basegfx::BPixel aPixel(mrMaterial.getColor(), 0xff);
                    const sal_uInt32 nSpanLength(nXB - nXA);
                    basegfx::BDInterpolator aZ(fZStart, fZStop, nSpanLength);

                    if(nXA < 0L)
                    {
                        const double fIncrement(-nXA);
                        nXA = 0L;
                        aZ.increment(fIncrement);
                    }

                    if(nXB > (sal_Int32)mrBuffer.getWidth())
                    {
                        nXB = mrBuffer.getWidth();
                    }

                    if(nXA < nXB)
                    {
                        sal_uInt32 nScanlineIndex(mrBuffer.getIndexFromXY((sal_uInt32)nXA, (sal_uInt32)nLine));

                        while(nXA < nXB)
                        {
                            sal_uInt16& rOldZ(mrBuffer.getZ(nScanlineIndex));
                            const sal_uInt16 nNewZ((sal_uInt16)(aZ.getVal()) + 0x00ff);

                            if(nNewZ > rOldZ)
                            {
                                rOldZ = nNewZ;
                                mrBuffer.getBPixel(nScanlineIndex) = aPixel;
                            }

                            nScanlineIndex++;
                            nXA++;
                            aZ.increment();
                        }
                    }
                }
            }
        }
    } // end of anonymous namespace
} // end of namespace drawinglayer

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

namespace drawinglayer
{
    namespace texture
    {
        class geoTexSvxMono : public geoTexSvx
        {
        protected:
            basegfx::BColor                         maSingleColor;
            double                                      mfOpacity;

        public:
            geoTexSvxMono(const basegfx::BColor& rSingleColor, double fOpacity);
            virtual ~geoTexSvxMono();

            // compare operator
            virtual bool operator==(const geoTexSvx& rGeoTexSvx) const;
            virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const;
            virtual void modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const;
        };

        geoTexSvxMono::geoTexSvxMono(const basegfx::BColor& rSingleColor, double fOpacity)
        :   maSingleColor(rSingleColor),
            mfOpacity(fOpacity)
        {
        }

        geoTexSvxMono::~geoTexSvxMono()
        {
        }

        bool geoTexSvxMono::operator==(const geoTexSvx& rGeoTexSvx) const
        {
            const geoTexSvxMono* pCompare = dynamic_cast< const geoTexSvxMono* >(&rGeoTexSvx);
            return (pCompare
                && maSingleColor == pCompare->maSingleColor
                && mfOpacity == pCompare->mfOpacity);
        }

        void geoTexSvxMono::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
        {
            rBColor = maSingleColor;
        }

        void geoTexSvxMono::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
        {
            rfOpacity = mfOpacity;
        }
    } // end of namespace texture
} // end of namespace drawinglayer

//////////////////////////////////////////////////////////////////////////////

namespace drawinglayer
{
    namespace texture
    {
        class geoTexSvxBitmap : public geoTexSvx
        {
        protected:
            Bitmap                                      maBitmap;
            BitmapReadAccess*                           mpRead;
            basegfx::B2DPoint                           maTopLeft;
            basegfx::B2DVector                      maSize;
            double                                      mfMulX;
            double                                      mfMulY;

            // helpers
            bool impIsValid(const basegfx::B2DPoint& rUV, sal_Int32& rX, sal_Int32& rY) const;

        public:
            geoTexSvxBitmap(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize);
            virtual ~geoTexSvxBitmap();
            virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const;
            virtual void modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const;
        };

        geoTexSvxBitmap::geoTexSvxBitmap(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
        :   maBitmap(rBitmap),
            mpRead(0L),
            maTopLeft(rTopLeft),
            maSize(rSize),
            mfMulX(0.0),
            mfMulY(0.0)
        {
            mpRead = maBitmap.AcquireReadAccess();
            OSL_ENSURE(mpRead, "geoTexSvxBitmap: Got no read access to Bitmap (!)");
            mfMulX = (double)mpRead->Width() / maSize.getX();
            mfMulY = (double)mpRead->Height() / maSize.getY();
        }

        geoTexSvxBitmap::~geoTexSvxBitmap()
        {
            delete mpRead;
        }

        bool geoTexSvxBitmap::impIsValid(const basegfx::B2DPoint& rUV, sal_Int32& rX, sal_Int32& rY) const
        {
            if(mpRead)
            {
                rX = (sal_Int32)((rUV.getX() - maTopLeft.getX()) * mfMulX);

                if(rX >= 0L && rX < mpRead->Width())
                {
                    rY = (sal_Int32)((rUV.getY() - maTopLeft.getY()) * mfMulY);

                    return (rY >= 0L && rY < mpRead->Height());
                }
            }

            return false;
        }

        void geoTexSvxBitmap::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
        {
            sal_Int32 nX, nY;

            if(impIsValid(rUV, nX, nY))
            {
                rBColor = Color(mpRead->GetColor(nY, nX)).getBColor();
            }
            else
            {
                rfOpacity = 0.0;
            }
        }

        void geoTexSvxBitmap::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
        {
            sal_Int32 nX, nY;

            if(impIsValid(rUV, nX, nY))
            {
                rfOpacity = ((double)(0xff - Color(mpRead->GetColor(nY, nX)).GetLuminance()) * (1.0 / 255.0));
            }
            else
            {
                rfOpacity = 0.0;
            }
        }
    } // end of namespace texture
} // end of namespace drawinglayer

//////////////////////////////////////////////////////////////////////////////

namespace drawinglayer
{
    namespace texture
    {
        class geoTexSvxBitmapTiled : public geoTexSvxBitmap
        {
        protected:
            // helpers
            basegfx::B2DPoint impGetCorrected(const basegfx::B2DPoint& rUV) const
            {
                double fX(fmod(rUV.getX() - maTopLeft.getX(), maSize.getX()));
                double fY(fmod(rUV.getY() - maTopLeft.getY(), maSize.getY()));

                if(fX < 0.0)
                {
                    fX += maSize.getX();
                }

                if(fY < 0.0)
                {
                    fY += maSize.getY();
                }

                return basegfx::B2DPoint(fX + maTopLeft.getX(), fY + maTopLeft.getY());
            }

        public:
            geoTexSvxBitmapTiled(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize);
            virtual ~geoTexSvxBitmapTiled();
            virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const;
            virtual void modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const;
        };

        geoTexSvxBitmapTiled::geoTexSvxBitmapTiled(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
        :   geoTexSvxBitmap(rBitmap, rTopLeft, rSize)
        {
        }

        geoTexSvxBitmapTiled::~geoTexSvxBitmapTiled()
        {
        }

        void geoTexSvxBitmapTiled::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
        {
            if(mpRead)
            {
                geoTexSvxBitmap::modifyBColor(impGetCorrected(rUV), rBColor, rfOpacity);
            }
        }

        void geoTexSvxBitmapTiled::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
        {
            if(mpRead)
            {
                geoTexSvxBitmap::modifyOpacity(impGetCorrected(rUV), rfOpacity);
            }
        }
    } // end of namespace texture
} // end of namespace drawinglayer

//////////////////////////////////////////////////////////////////////////////

namespace drawinglayer
{
    namespace texture
    {
        class geoTexSvxMultiHatch : public geoTexSvx
        {
        protected:
            basegfx::BColor             maColor;
            double                          mfLogicPixelSize;
            geoTexSvxHatch*                 mp0;
            geoTexSvxHatch*                 mp1;
            geoTexSvxHatch*                 mp2;

            // bitfield
            unsigned                        mbFillBackground : 1;

            // helpers
            bool impIsOnHatch(const basegfx::B2DPoint& rUV) const;

        public:
            geoTexSvxMultiHatch(const primitive3d::hatchTexturePrimitive3D& rPrimitive, double fLogicPixelSize);
            virtual ~geoTexSvxMultiHatch();
            virtual void modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const;
            virtual void modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const;

            // dada access
            bool getFillBackground() const { return mbFillBackground; }
        };

        geoTexSvxMultiHatch::geoTexSvxMultiHatch(const primitive3d::hatchTexturePrimitive3D& rPrimitive, double fLogicPixelSize)
        :   mfLogicPixelSize(fLogicPixelSize),
            mp0(0L),
            mp1(0L),
            mp2(0L)
        {
            const attribute::fillHatchAttribute& rHatch(rPrimitive.getHatch());
            const basegfx::B2DRange aOutlineRange(0.0, 0.0, rPrimitive.getTextureSize().getX(), rPrimitive.getTextureSize().getY());
            const double fAngleA(-rHatch.getAngle());
            maColor = rHatch.getColor();
            mbFillBackground = rHatch.isFillBackground();
            mp0 = new geoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA);

            if(attribute::HATCHSTYLE_DOUBLE == rHatch.getStyle() || attribute::HATCHSTYLE_TRIPLE == rHatch.getStyle())
            {
                mp1 = new geoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA + F_PI2);
            }

            if(attribute::HATCHSTYLE_TRIPLE == rHatch.getStyle())
            {
                mp2 = new geoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA + F_PI4);
            }
        }

        geoTexSvxMultiHatch::~geoTexSvxMultiHatch()
        {
            delete mp0;
            delete mp1;
            delete mp2;
        }

        bool geoTexSvxMultiHatch::impIsOnHatch(const basegfx::B2DPoint& rUV) const
        {
            double fSmallestDistance();

            if(mp0->getDistanceToHatch(rUV) < mfLogicPixelSize)
            {
                return true;
            }

            if(mp1 && mp1->getDistanceToHatch(rUV) < mfLogicPixelSize)
            {
                return true;
            }

            if(mp2 && mp2->getDistanceToHatch(rUV) < mfLogicPixelSize)
            {
                return true;
            }

            return false;
        }

        void geoTexSvxMultiHatch::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
        {
            if(impIsOnHatch(rUV))
            {
                rBColor = maColor;
            }
            else if(!mbFillBackground)
            {
                rfOpacity = 0.0;
            }
        }

        void geoTexSvxMultiHatch::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
        {
            if(mbFillBackground || impIsOnHatch(rUV))
            {
                rfOpacity = 1.0;
            }
            else
            {
                rfOpacity = 0.0;
            }
        }
    } // end of namespace texture
} // end of namespace drawinglayer

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

namespace drawinglayer
{
    namespace processor3d
    {
        void defaultProcessor3D::impRender_GRX3(const primitive3d::gradientTexturePrimitive3D& rPrimitive, bool bTransparence)
        {
            const primitive3d::primitiveVector3D& rSubList = rPrimitive.getPrimitives();

            if(rSubList.size())
            {
                // rescue values
                const bool bOldModulate(mbModulate); mbModulate = rPrimitive.getModulate();
                const bool bOldFilter(mbFilter); mbFilter = rPrimitive.getFilter();
                texture::geoTexSvx* pOldTex = (bTransparence) ? mpTransparenceGeoTexSvx : mpGeoTexSvx;

                // create texture
                const attribute::fillGradientAttribute& rFillGradient = rPrimitive.getGradient();
                const basegfx::B2DRange aOutlineRange(0.0, 0.0, rPrimitive.getTextureSize().getX(), rPrimitive.getTextureSize().getY());
                const attribute::GradientStyle aGradientStyle(rFillGradient.getStyle());
                sal_uInt32 nSteps(rFillGradient.getSteps());
                const basegfx::BColor aStart(rFillGradient.getStartColor());
                const basegfx::BColor aEnd(rFillGradient.getEndColor());
                const sal_uInt32 nMaxSteps(sal_uInt32((aStart.getMaximumDistance(aEnd) * 127.5) + 0.5));
                texture::geoTexSvx* pNewTex = 0L;

                if(nMaxSteps)
                {
                    // there IS a color distance
                    if(nSteps == 0L)
                    {
                        nSteps = nMaxSteps;
                    }

                    if(nSteps < 2L)
                    {
                        nSteps = 2L;
                    }

                    if(nSteps > nMaxSteps)
                    {
                        nSteps = nMaxSteps;
                    }

                    switch(aGradientStyle)
                    {
                        case attribute::GRADIENTSTYLE_LINEAR:
                        {
                            pNewTex = new texture::geoTexSvxGradientLinear(aOutlineRange, aStart, aEnd, nSteps, rFillGradient.getBorder(), -rFillGradient.getAngle());
                            break;
                        }
                        case attribute::GRADIENTSTYLE_AXIAL:
                        {
                            pNewTex = new texture::geoTexSvxGradientAxial(aOutlineRange, aStart, aEnd, nSteps, rFillGradient.getBorder(), -rFillGradient.getAngle());
                            break;
                        }
                        case attribute::GRADIENTSTYLE_RADIAL:
                        {
                            pNewTex = new texture::geoTexSvxGradientRadial(aOutlineRange, aStart, aEnd, nSteps, rFillGradient.getBorder(), rFillGradient.getOffsetX(), rFillGradient.getOffsetY());
                            break;
                        }
                        case attribute::GRADIENTSTYLE_ELLIPTICAL:
                        {
                            pNewTex = new texture::geoTexSvxGradientElliptical(aOutlineRange, aStart, aEnd, nSteps, rFillGradient.getBorder(), rFillGradient.getOffsetX(), rFillGradient.getOffsetY(), -rFillGradient.getAngle());
                            break;
                        }
                        case attribute::GRADIENTSTYLE_SQUARE:
                        {
                            pNewTex = new texture::geoTexSvxGradientSquare(aOutlineRange, aStart, aEnd, nSteps, rFillGradient.getBorder(), rFillGradient.getOffsetX(), rFillGradient.getOffsetY(), -rFillGradient.getAngle());
                            break;
                        }
                        case attribute::GRADIENTSTYLE_RECT:
                        {
                            pNewTex = new texture::geoTexSvxGradientRect(aOutlineRange, aStart, aEnd, nSteps, rFillGradient.getBorder(), rFillGradient.getOffsetX(), rFillGradient.getOffsetY(), -rFillGradient.getAngle());
                            break;
                        }
                    }
                }
                else
                {
                    // no color distance -> same color, use simple texture
                    pNewTex = new texture::geoTexSvxMono(aStart, 1.0 - aStart.luminance());
                }

                // set created texture
                if(bTransparence)
                {
                    mpTransparenceGeoTexSvx = pNewTex;
                }
                else
                {
                    mpGeoTexSvx = pNewTex;
                }

                // process sub-list
                process(rSubList);

                // delete texture
                delete pNewTex;

                // restore values
                mbModulate = bOldModulate;
                mbFilter = bOldFilter;

                if(bTransparence)
                {
                    mpTransparenceGeoTexSvx = pOldTex;
                }
                else
                {
                    mpGeoTexSvx = pOldTex;
                }
            }
        }

        void defaultProcessor3D::impRender_HAX3(const primitive3d::hatchTexturePrimitive3D& rPrimitive)
        {
            const primitive3d::primitiveVector3D& rSubList = rPrimitive.getPrimitives();

            if(rSubList.size())
            {
                // rescue values
                const bool bOldModulate(mbModulate); mbModulate = rPrimitive.getModulate();
                const bool bOldFilter(mbFilter); mbFilter = rPrimitive.getFilter();
                texture::geoTexSvx* pOldTex = mpGeoTexSvx;

                // calculate logic pixel size in world coordinates
                const basegfx::B3DPoint aZero(maInvWorldToView * basegfx::B3DPoint(0.0, 0.0, 0.0));
                const basegfx::B3DPoint aOne(maInvWorldToView * basegfx::B3DPoint(1.0, 1.0, 1.0));
                const basegfx::B3DVector aLogicPixelSizeWorld(aOne - aZero);
                double fLogicPixelSizeWorld(fabs(aLogicPixelSizeWorld.getX()));

                if(fabs(aLogicPixelSizeWorld.getY()) > fLogicPixelSizeWorld)
                {
                    fLogicPixelSizeWorld = fabs(aLogicPixelSizeWorld.getY());
                }

                if(fabs(aLogicPixelSizeWorld.getZ()) > fLogicPixelSizeWorld)
                {
                    fLogicPixelSizeWorld = fabs(aLogicPixelSizeWorld.getZ());
                }

                // calculate logic pixel size in texture coordinates
                const double fLogicTexSizeX(fLogicPixelSizeWorld / rPrimitive.getTextureSize().getX());
                const double fLogicTexSizeY(fLogicPixelSizeWorld / rPrimitive.getTextureSize().getY());
                const double fLogicTexSize(fLogicTexSizeX > fLogicTexSizeY ? fLogicTexSizeX : fLogicTexSizeY);

                // create texture and set
                texture::geoTexSvxMultiHatch* pNewTex = new texture::geoTexSvxMultiHatch(rPrimitive, fLogicTexSize);
                mpGeoTexSvx = pNewTex;

                // process sub-list
                process(rSubList);

                // delete texture
                delete mpGeoTexSvx;

                // restore values
                mbModulate = bOldModulate;
                mbFilter = bOldFilter;
                mpGeoTexSvx = pOldTex;
            }
        }

        void defaultProcessor3D::impRender_BMX3(const primitive3d::bitmapTexturePrimitive3D& rPrimitive)
        {
            const primitive3d::primitiveVector3D& rSubList = rPrimitive.getPrimitives();

            if(rSubList.size())
            {
                // rescue values
                const bool bOldModulate(mbModulate); mbModulate = rPrimitive.getModulate();
                const bool bOldFilter(mbFilter); mbFilter = rPrimitive.getFilter();
                texture::geoTexSvx* pOldTex = mpGeoTexSvx;

                // create texture
                const attribute::fillBitmapAttribute& rFillBitmapAttribute = rPrimitive.getBitmap();

                if(rFillBitmapAttribute.getTiling())
                {
                    mpGeoTexSvx = new texture::geoTexSvxBitmapTiled(
                        rFillBitmapAttribute.getBitmap(),
                        rFillBitmapAttribute.getTopLeft() * rPrimitive.getTextureSize(),
                        rFillBitmapAttribute.getSize() * rPrimitive.getTextureSize());
                }
                else
                {
                    mpGeoTexSvx = new texture::geoTexSvxBitmap(
                        rFillBitmapAttribute.getBitmap(),
                        rFillBitmapAttribute.getTopLeft() * rPrimitive.getTextureSize(),
                        rFillBitmapAttribute.getSize() * rPrimitive.getTextureSize());
                }

                // process sub-list
                process(rSubList);

                // delete texture
                delete mpGeoTexSvx;

                // restore values
                mbModulate = bOldModulate;
                mbFilter = bOldFilter;
                mpGeoTexSvx = pOldTex;
            }
        }

        void defaultProcessor3D::impRender_MCOL(const primitive3d::modifiedColorPrimitive3D& rModifiedCandidate)
        {
            const primitive3d::primitiveVector3D& rSubList = rModifiedCandidate.getPrimitives();

            if(rSubList.size())
            {
                maBColorModifierStack.push(rModifiedCandidate.getColorModifier());
                process(rModifiedCandidate.getPrimitives());
                maBColorModifierStack.pop();
            }
        }

        void defaultProcessor3D::impRender_POH3(const primitive3d::polygonHairlinePrimitive3D& rPrimitive)
        {
            basegfx::B3DPolygon aHairline(rPrimitive.getB3DPolygon());

            if(aHairline.count() && mpBZPixelRaster)
            {
                // hairlines need no extra data, clear it
                aHairline.clearTextureCoordinates();
                aHairline.clearNormals();
                aHairline.clearBColors();

                // transform to device coordinates (-1.0 .. 1.0) and check for visibility
                aHairline.transform(maWorldToView);
                const basegfx::B3DRange a3DRange(basegfx::tools::getRange(aHairline));
                const basegfx::B2DRange a2DRange(a3DRange.getMinX(), a3DRange.getMinY(), a3DRange.getMaxX(), a3DRange.getMaxY());

                if(a2DRange.overlaps(maRasterRange))
                {
                    const attribute::materialAttribute3D aMaterial(rPrimitive.getBColor());
                    BZPolyRaCon aNewRaCon(false, *mpBZPixelRaster, aMaterial, *this);
                    aNewRaCon.addPolygon(aHairline, maInvEyeToView);
                    aNewRaCon.rasterconvert(0L, mpBZPixelRaster->getHeight());
                }
            }
        }

        void defaultProcessor3D::impRender_POM3(const primitive3d::polyPolygonMaterialPrimitive3D& rPrimitive)
        {
            basegfx::B3DPolyPolygon aFill(rPrimitive.getB3DPolyPolygon());
            basegfx::BColor aObjectColor(rPrimitive.getMaterial().getColor());
            bool bPaintIt(aFill.count() && mpBZPixelRaster);

            if(bPaintIt)
            {
                // get rid of texture coordinates if there is no texture
                if(aFill.areTextureCoordinatesUsed() && !mpGeoTexSvx && !mpTransparenceGeoTexSvx)
                {
                    aFill.clearTextureCoordinates();
                }

                // transform to device coordinates (-1.0 .. 1.0) and check for visibility
                aFill.transform(maWorldToView);
                const basegfx::B3DRange a3DRange(basegfx::tools::getRange(aFill));
                const basegfx::B2DRange a2DRange(a3DRange.getMinX(), a3DRange.getMinY(), a3DRange.getMaxX(), a3DRange.getMaxY());

                bPaintIt = a2DRange.overlaps(maRasterRange);
            }

            // check if it shall be painted regarding hiding of normals (backface culling)
            if(bPaintIt && !rPrimitive.getDoubleSided())
            {
                // get plane normal of polygon in view coordinates (with ZBuffer values),
                // left-handed coordinate system
                const basegfx::B3DVector aPlaneNormal(aFill.getB3DPolygon(0L).getNormal());

                if(aPlaneNormal.getZ() > 0.0)
                {
                    bPaintIt = false;
                }
            }

            if(bPaintIt)
            {
                ::com::sun::star::drawing::ShadeMode aShadeMode(mrSdrSceneAttribute.getShadeMode());
                basegfx::B3DHomMatrix aNormalTransform(maWorldToEye);

                if(mrSdrSceneAttribute.getTwoSidedLighting())
                {
                    // get plane normal of polygon in view coordinates (with ZBuffer values),
                    // left-handed coordinate system
                    const basegfx::B3DVector aPlaneNormal(aFill.getB3DPolygon(0L).getNormal());

                    if(aPlaneNormal.getZ() > 0.0)
                    {
                        // mirror normals
                        aNormalTransform.scale(-1.0, -1.0, -1.0);
                    }
                }

                if(::com::sun::star::drawing::ShadeMode_PHONG == aShadeMode)
                {
                    // phong shading
                    if(aFill.areNormalsUsed())
                    {
                        // transform normals to eye coor
                        aFill.transformNormals(aNormalTransform);
                    }
                    else
                    {
                        // fallback to gouraud when no normals available
                        aShadeMode = ::com::sun::star::drawing::ShadeMode_SMOOTH;
                    }
                }

                if(::com::sun::star::drawing::ShadeMode_SMOOTH == aShadeMode)
                {
                    // gouraud shading
                    if(aFill.areNormalsUsed())
                    {
                        // transform normals to eye coor
                        aFill.transformNormals(aNormalTransform);

                        // prepare color model parameters, evtl. use blend color
                        const basegfx::BColor aColor(mbModulate ? basegfx::BColor(1.0, 1.0, 1.0) : rPrimitive.getMaterial().getColor());
                        const basegfx::BColor& rSpecular(rPrimitive.getMaterial().getSpecular());
                        const basegfx::BColor& rEmission(rPrimitive.getMaterial().getEmission());
                        const sal_uInt16 nSpecularIntensity(rPrimitive.getMaterial().getSpecularIntensity());

                        // solve color model for each normal vector, set colors at points. Clear normals.
                        for(sal_uInt32 a(0L); a < aFill.count(); a++)
                        {
                            basegfx::B3DPolygon aPartFill(aFill.getB3DPolygon(a));

                            for(sal_uInt32 b(0L); b < aPartFill.count(); b++)
                            {
                                // solve color model. Transform normal to eye coor
                                const basegfx::B3DVector aNormal(aPartFill.getNormal(b));
                                const basegfx::BColor aSolvedColor(mrSdrLightingAttribute.solveColorModel(aNormal, aColor, rSpecular, rEmission, nSpecularIntensity));
                                aPartFill.setBColor(b, aSolvedColor);
                            }

                            // clear normals on this part polygon and write it back
                            aPartFill.clearNormals();
                            aFill.setB3DPolygon(a, aPartFill);
                        }
                    }
                    else
                    {
                        // fallback to flat when no normals available
                        aShadeMode = ::com::sun::star::drawing::ShadeMode_FLAT;
                    }
                }

                if(::com::sun::star::drawing::ShadeMode_FLAT == aShadeMode)
                {
                    // flat shading. Clear normals and colors
                    aFill.clearNormals();
                    aFill.clearBColors();

                    // get plane vector in eye coordinates
                    const basegfx::B3DVector aPlaneEyeNormal(aNormalTransform * rPrimitive.getB3DPolyPolygon().getB3DPolygon(0L).getNormal());

                    // prepare color model parameters, evtl. use blend color
                    const basegfx::BColor aColor(mbModulate ? basegfx::BColor(1.0, 1.0, 1.0) : rPrimitive.getMaterial().getColor());
                    const basegfx::BColor& rSpecular(rPrimitive.getMaterial().getSpecular());
                    const basegfx::BColor& rEmission(rPrimitive.getMaterial().getEmission());
                    const sal_uInt16 nSpecularIntensity(rPrimitive.getMaterial().getSpecularIntensity());

                    // solve color model for plane vector and use that color for whole plane
                    aObjectColor = mrSdrLightingAttribute.solveColorModel(aPlaneEyeNormal, aColor, rSpecular, rEmission, nSpecularIntensity);
                }

                if(::com::sun::star::drawing::ShadeMode_DRAFT == aShadeMode)
                {
                    // draft, just use object color which is already set. Delete all other infos
                    aFill.clearNormals();
                    aFill.clearBColors();
                }
            }

            if(bPaintIt)
            {
                // draw it to ZBuffer
                const attribute::materialAttribute3D aMaterial(
                    aObjectColor, rPrimitive.getMaterial().getSpecular(),
                    rPrimitive.getMaterial().getEmission(),
                    rPrimitive.getMaterial().getSpecularIntensity());
                BZPolyRaCon aNewRaCon(true, *mpBZPixelRaster, aMaterial, *this);

                for(sal_uInt32 a(0L); a < aFill.count(); a++)
                {
                    aNewRaCon.addPolygon(aFill.getB3DPolygon(a), maInvEyeToView);
                }

                aNewRaCon.rasterconvert(0L, mpBZPixelRaster->getHeight());
            }
        }

        void defaultProcessor3D::impRender_TRN3(const primitive3d::transformPrimitive3D& rTransformCandidate)
        {
            // remember current transformations
            basegfx::B3DHomMatrix aLastWorldToView(maWorldToView);
            basegfx::B3DHomMatrix aLastWorldToEye(maWorldToEye);
            basegfx::B3DHomMatrix aLastInvWorldToView(maInvWorldToView);

            // create new transformations
            maWorldToView = maWorldToView * rTransformCandidate.getTransformation();
            maWorldToEye = maWorldToEye * rTransformCandidate.getTransformation();
            maInvWorldToView = maWorldToView;
            maInvWorldToView.invert();

            // let break down
            process(rTransformCandidate.getPrimitives());

            // restore transformations
            maWorldToView = aLastWorldToView;
            maWorldToEye = aLastWorldToEye;
            maInvWorldToView = aLastInvWorldToView;
        }

        void defaultProcessor3D::process(const primitive3d::primitiveVector3D& rSource)
        {
            for(sal_uInt32 a(0L); a < rSource.size(); a++)
            {
                const primitive3d::referencedPrimitive3D& rCandidate = rSource[a];

                switch(rCandidate.getID())
                {
                    case CreatePrimitiveID('G', 'R', 'X', '3'):
                    {
                        // gradientTexturePrimitive3D
                        const primitive3d::gradientTexturePrimitive3D& rPrimitive = static_cast< const primitive3d::gradientTexturePrimitive3D& >(rCandidate.getBasePrimitive());
                        impRender_GRX3(rPrimitive, false);
                        break;
                    }

                    case CreatePrimitiveID('H', 'A', 'X', '3'):
                    {
                        static bool bDoHatchDecomposition(true);

                        if(bDoHatchDecomposition)
                        {
                            // let break down
                            process(rCandidate.getBasePrimitive().getDecomposition());
                        }
                        else
                        {
                            // hatchTexturePrimitive3D
                            const primitive3d::hatchTexturePrimitive3D& rPrimitive = static_cast< const primitive3d::hatchTexturePrimitive3D& >(rCandidate.getBasePrimitive());
                            impRender_HAX3(rPrimitive);
                        }

                        break;
                    }

                    case CreatePrimitiveID('B', 'M', 'X', '3'):
                    {
                        // bitmapTexturePrimitive3D
                        const primitive3d::bitmapTexturePrimitive3D& rPrimitive = static_cast< const primitive3d::bitmapTexturePrimitive3D& >(rCandidate.getBasePrimitive());
                        impRender_BMX3(rPrimitive);
                        break;
                    }

                    case CreatePrimitiveID('T', 'R', 'X', '3'):
                    {
                        // transparenceTexturePrimitive3D
                        const primitive3d::transparenceTexturePrimitive3D& rPrimitive = static_cast< const primitive3d::transparenceTexturePrimitive3D& >(rCandidate.getBasePrimitive());

                        if(mbProcessTransparent)
                        {
                            impRender_GRX3(rPrimitive, true);
                        }
                        else
                        {
                            mbContainsTransparent = true;
                        }

                        break;
                    }

                    case CreatePrimitiveID('M', 'C', 'L', '3'):
                    {
                        // modified color group. Force output to unified color.
                        const primitive3d::modifiedColorPrimitive3D& rPrimitive = static_cast< const primitive3d::modifiedColorPrimitive3D& >(rCandidate.getBasePrimitive());
                        impRender_MCOL(rPrimitive);
                        break;
                    }

                    case CreatePrimitiveID('P', 'O', 'H', '3'):
                    {
                        // directdraw of polygonHairlinePrimitive3D
                        const primitive3d::polygonHairlinePrimitive3D& rPrimitive = static_cast< const primitive3d::polygonHairlinePrimitive3D& >(rCandidate.getBasePrimitive());

                        if(mbProcessTransparent == (0L != mpTransparenceGeoTexSvx))
                        {
                            impRender_POH3(rPrimitive);
                        }

                        break;
                    }

                    case CreatePrimitiveID('P', 'O', 'M', '3'):
                    {
                        // directdraw of polyPolygonMaterialPrimitive3D
                        const primitive3d::polyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const primitive3d::polyPolygonMaterialPrimitive3D& >(rCandidate.getBasePrimitive());

                        if(mbProcessTransparent == (0L != mpTransparenceGeoTexSvx))
                        {
                            impRender_POM3(rPrimitive);
                        }

                        break;
                    }

                    case CreatePrimitiveID('T', 'R', 'N', '3'):
                    {
                        // transform group.
                        impRender_TRN3(static_cast< const primitive3d::transformPrimitive3D& >(rCandidate.getBasePrimitive()));
                        break;
                    }

                    case CreatePrimitiveID('L', 'A', 'B', '3'):
                    {
                        // sdrLabelPrimitive3D. Accept, but ignore. Is handled by the scenePrimitive decompose
                        // method which creates 2d text objects at the 3d-projection-dependent positions.
                        break;
                    }

                    default:
                    {
                        // let break down
                        process(rCandidate.getBasePrimitive().getDecomposition());
                        break;
                    }
                }
            }
        }

        void defaultProcessor3D::processNonTransparent(const primitive3d::primitiveVector3D& rSource)
        {
            mbProcessTransparent = false;
            mbContainsTransparent = false;
            process(rSource);
        }

        void defaultProcessor3D::processTransparent(const primitive3d::primitiveVector3D& rSource)
        {
            if(mbContainsTransparent)
            {
                mbProcessTransparent = true;
                process(rSource);
            }
        }

        defaultProcessor3D::defaultProcessor3D(
            const geometry::viewInformation& rViewInformation,
            const geometry::transformation3D& rTransformation3D,
            const attribute::sdrSceneAttribute& rSdrSceneAttribute,
            const attribute::sdrLightingAttribute& rsdrLightingAttribute,
            double fSizeX,
            double fSizeY,
            const basegfx::B2DRange& rVisiblePart)
        :   baseProcessor3D(rViewInformation, rTransformation3D),
            mrSdrSceneAttribute(rSdrSceneAttribute),
            mrSdrLightingAttribute(rsdrLightingAttribute),
            mpGeoTexSvx(0L),
            mpTransparenceGeoTexSvx(0L),
            mbModulate(false),
            mbFilter(false),
            mbProcessTransparent(false),
            mbContainsTransparent(false)
        {
            // generate ViewSizes
            const double fFullViewSizeX((getViewInformation().getViewTransformation() * basegfx::B2DVector(fSizeX, 0.0)).getLength());
            const double fFullViewSizeY((getViewInformation().getViewTransformation() * basegfx::B2DVector(0.0, fSizeY)).getLength());
            const double fViewSizeX(fFullViewSizeX * rVisiblePart.getWidth());
            const double fViewSizeY(fFullViewSizeY * rVisiblePart.getHeight());
            const sal_uInt32 nViewSizeX((sal_uInt32)floor(fViewSizeX));
            const sal_uInt32 nViewSizeY((sal_uInt32)floor(fViewSizeY));

            if(nViewSizeX && nViewSizeY)
            {
                // create view unit buffer
                mpBZPixelRaster = new basegfx::BZPixelRaster(nViewSizeX + 1L, nViewSizeY + 1L);
                OSL_ENSURE(mpBZPixelRaster, "defaultProcessor3D: Could not allocate basegfx::BZPixelRaster (!)");

                // create DeviceToView
                // outcome is [-1.0 .. 1.0] in X,Y and Z.

                {
                    // step one:
                    //
                    // bring from [-1.0 .. 1.0] in X,Y and Z to [0.0 .. 1.0]. Also
                    // necessary to
                    // - flip Y due to screen orientation
                    // - flip Z due to Z-Buffer orientation from back to front

                    maDeviceToView.scale(0.5, -0.5, -0.5);
                    maDeviceToView.translate(0.5, 0.5, 0.5);
                }

                {
                    // step two:
                    //
                    // bring from [0.0 .. 1.0] in X,Y and Z to view cordinates. also:
                    // - scale Z to [0.0 .. fMaxZDepth]
                    const double fMaxZDepth(double(0x0000ff00));
                    maDeviceToView.translate(-rVisiblePart.getMinX(), -rVisiblePart.getMinY(), 0.0);
                    maDeviceToView.scale(fFullViewSizeX, fFullViewSizeY, fMaxZDepth);
                }

                // create world to eye transformation
                maWorldToEye = getTransformation3D().getOrientation() * getTransformation3D().getTransformation();

                // create EyeToView transformation
                maWorldToView = maDeviceToView * getTransformation3D().getProjection() * maWorldToEye;

                // create inverse EyeToView transformation
                maInvEyeToView = maDeviceToView * getTransformation3D().getProjection();
                maInvEyeToView.invert();

                // create inverse WorldToView transformation
                maInvWorldToView = maWorldToView;
                maInvWorldToView.invert();

                // prepare maRasterRange
                maRasterRange.expand(basegfx::B2DPoint(0.0, 0.0));
                maRasterRange.expand(basegfx::B2DPoint(mpBZPixelRaster->getWidth(), mpBZPixelRaster->getHeight()));
            }
        }

        defaultProcessor3D::~defaultProcessor3D()
        {
            if(mpBZPixelRaster)
            {
                delete mpBZPixelRaster;
            }
        }

        BitmapEx defaultProcessor3D::getBitmapEx() const
        {
            if(mpBZPixelRaster)
            {
                return basegfx::getBitmapEx(*mpBZPixelRaster);
            }

            return BitmapEx();
        }
    } // end of namespace processor3d
} // end of namespace drawinglayer

//////////////////////////////////////////////////////////////////////////////
// eof