| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | #include <osg/CopyOp> |
|---|
| 14 | #include <osg/Node> |
|---|
| 15 | #include <osg/StateSet> |
|---|
| 16 | #include <osg/Texture> |
|---|
| 17 | #include <osg/Drawable> |
|---|
| 18 | #include <osg/Array> |
|---|
| 19 | #include <osg/PrimitiveSet> |
|---|
| 20 | #include <osg/Shape> |
|---|
| 21 | #include <osg/StateAttribute> |
|---|
| 22 | |
|---|
| 23 | using namespace osg; |
|---|
| 24 | |
|---|
| 25 | #define COPY_OP( TYPE, FLAG ) \ |
|---|
| 26 | TYPE* CopyOp::operator() (const TYPE* obj) const \ |
|---|
| 27 | { \ |
|---|
| 28 | if (obj && _flags&FLAG) \ |
|---|
| 29 | return osg::clone(obj, *this); \ |
|---|
| 30 | else \ |
|---|
| 31 | return const_cast<TYPE*>(obj); \ |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | COPY_OP( Object, DEEP_COPY_OBJECTS ) |
|---|
| 35 | COPY_OP( Node, DEEP_COPY_NODES ) |
|---|
| 36 | COPY_OP( StateSet, DEEP_COPY_STATESETS ) |
|---|
| 37 | COPY_OP( Image, DEEP_COPY_IMAGES ) |
|---|
| 38 | COPY_OP( Uniform, DEEP_COPY_UNIFORMS ) |
|---|
| 39 | COPY_OP( StateAttributeCallback, DEEP_COPY_CALLBACKS ) |
|---|
| 40 | COPY_OP( Drawable, DEEP_COPY_DRAWABLES ) |
|---|
| 41 | COPY_OP( Texture, DEEP_COPY_TEXTURES ) |
|---|
| 42 | COPY_OP( Array, DEEP_COPY_ARRAYS ) |
|---|
| 43 | COPY_OP( PrimitiveSet, DEEP_COPY_PRIMITIVES ) |
|---|
| 44 | COPY_OP( Shape, DEEP_COPY_SHAPES ) |
|---|
| 45 | |
|---|
| 46 | Referenced* CopyOp::operator() (const Referenced* ref) const |
|---|
| 47 | { |
|---|
| 48 | return const_cast<Referenced*>(ref); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | StateAttribute* CopyOp::operator() (const StateAttribute* attr) const |
|---|
| 52 | { |
|---|
| 53 | if (attr && _flags&DEEP_COPY_STATEATTRIBUTES) |
|---|
| 54 | { |
|---|
| 55 | const Texture* textbase = dynamic_cast<const Texture*>(attr); |
|---|
| 56 | if (textbase) |
|---|
| 57 | { |
|---|
| 58 | return operator()(textbase); |
|---|
| 59 | } |
|---|
| 60 | else |
|---|
| 61 | { |
|---|
| 62 | return osg::clone(attr, *this); |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | else |
|---|
| 66 | return const_cast<StateAttribute*>(attr); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | NodeCallback* CopyOp::operator() (const NodeCallback* nc) const |
|---|
| 70 | { |
|---|
| 71 | if (nc && _flags&DEEP_COPY_CALLBACKS) |
|---|
| 72 | { |
|---|
| 73 | |
|---|
| 74 | osg::NodeCallback* first = osg::clone(nc, *this); |
|---|
| 75 | if (!first) return 0; |
|---|
| 76 | |
|---|
| 77 | first->setNestedCallback(0); |
|---|
| 78 | nc = nc->getNestedCallback(); |
|---|
| 79 | while (nc) |
|---|
| 80 | { |
|---|
| 81 | osg::NodeCallback* ucb = osg::clone(nc, *this); |
|---|
| 82 | if (ucb) |
|---|
| 83 | { |
|---|
| 84 | ucb->setNestedCallback(0); |
|---|
| 85 | first->addNestedCallback(ucb); |
|---|
| 86 | } |
|---|
| 87 | nc = nc->getNestedCallback(); |
|---|
| 88 | } |
|---|
| 89 | return first; |
|---|
| 90 | } |
|---|
| 91 | else |
|---|
| 92 | return const_cast<NodeCallback*>(nc); |
|---|
| 93 | } |
|---|