| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | #include <osg/GL> |
|---|
| 14 | #include <osg/PolygonStipple> |
|---|
| 15 | #include <osg/Notify> |
|---|
| 16 | |
|---|
| 17 | #include <algorithm> |
|---|
| 18 | |
|---|
| 19 | using namespace osg; |
|---|
| 20 | |
|---|
| 21 | static GLubyte defaultPolygonStippleMask[] = |
|---|
| 22 | { |
|---|
| 23 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 24 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 25 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 26 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 27 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 28 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 29 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 30 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 31 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 32 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 33 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 34 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 35 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 36 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 37 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, |
|---|
| 38 | 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99 |
|---|
| 39 | }; |
|---|
| 40 | |
|---|
| 41 | PolygonStipple::PolygonStipple() |
|---|
| 42 | { |
|---|
| 43 | setMask(defaultPolygonStippleMask); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | PolygonStipple::PolygonStipple(const GLubyte* mask) |
|---|
| 47 | { |
|---|
| 48 | setMask(mask); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | PolygonStipple::PolygonStipple(const PolygonStipple& ps,const CopyOp& copyop): |
|---|
| 52 | StateAttribute(ps,copyop) |
|---|
| 53 | { |
|---|
| 54 | setMask(ps.getMask()); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | PolygonStipple::~PolygonStipple() |
|---|
| 58 | { |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | int PolygonStipple::compare(const StateAttribute& sa) const |
|---|
| 62 | { |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | COMPARE_StateAttribute_Types(PolygonStipple,sa) |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | for(unsigned int i=0;i<128;++i) |
|---|
| 69 | { |
|---|
| 70 | if (_mask[i]<rhs._mask[i]) return -1; |
|---|
| 71 | else if (_mask[i]>rhs._mask[i]) return 1; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | return 0; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | void PolygonStipple::setMask(const GLubyte* givenMask) |
|---|
| 78 | { |
|---|
| 79 | std::copy(givenMask,givenMask+128,_mask); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | void PolygonStipple::apply(State&) const |
|---|
| 83 | { |
|---|
| 84 | #ifdef OSG_GL1_AVAILABLE |
|---|
| 85 | glPolygonStipple(_mask); |
|---|
| 86 | #else |
|---|
| 87 | OSG_NOTICE<<"Warning: PolygonStipple::apply(State&) - not supported."<<std::endl; |
|---|
| 88 | #endif |
|---|
| 89 | } |
|---|