| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include "Exception.h" |
|---|
| 16 | #include "Drawable.h" |
|---|
| 17 | #include "ClusterCullingCallback.h" |
|---|
| 18 | #include "Object.h" |
|---|
| 19 | #include "StateSet.h" |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | using namespace ive; |
|---|
| 23 | |
|---|
| 24 | void Drawable::write(DataOutputStream* out) |
|---|
| 25 | { |
|---|
| 26 | |
|---|
| 27 | out->writeInt(IVEDRAWABLE); |
|---|
| 28 | |
|---|
| 29 | osg::Object* obj = dynamic_cast<osg::Object*>(this); |
|---|
| 30 | if(obj){ |
|---|
| 31 | ((ive::Object*)(obj))->write(out); |
|---|
| 32 | } |
|---|
| 33 | else |
|---|
| 34 | out_THROW_EXCEPTION("Drawable::write(): Could not cast this osg::Drawable to an osg::Object."); |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | out->writeBool(getStateSet()!=0); |
|---|
| 40 | if (getStateSet()) |
|---|
| 41 | { |
|---|
| 42 | out->writeStateSet(getStateSet()); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | osg::ClusterCullingCallback* ccc = dynamic_cast<osg::ClusterCullingCallback*>(getCullCallback()); |
|---|
| 47 | out->writeBool(ccc!=0); |
|---|
| 48 | if(ccc) |
|---|
| 49 | { |
|---|
| 50 | ((ive::ClusterCullingCallback*)(ccc))->write(out); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | if (out->getVersion() >= VERSION_0010) |
|---|
| 55 | { |
|---|
| 56 | const osg::BoundingBox& bb = getInitialBound(); |
|---|
| 57 | out->writeBool(bb.valid()); |
|---|
| 58 | if (bb.valid()) |
|---|
| 59 | { |
|---|
| 60 | out->writeFloat(bb.xMin()); |
|---|
| 61 | out->writeFloat(bb.yMin()); |
|---|
| 62 | out->writeFloat(bb.zMin()); |
|---|
| 63 | out->writeFloat(bb.xMax()); |
|---|
| 64 | out->writeFloat(bb.yMax()); |
|---|
| 65 | out->writeFloat(bb.zMax()); |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | out->writeBool(getSupportsDisplayList()); |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | out->writeBool(getUseDisplayList()); |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | out->writeBool(getUseVertexBufferObjects()); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | void Drawable::read(DataInputStream* in) |
|---|
| 80 | { |
|---|
| 81 | |
|---|
| 82 | int id = in->peekInt(); |
|---|
| 83 | if(id == IVEDRAWABLE) |
|---|
| 84 | { |
|---|
| 85 | |
|---|
| 86 | id = in->readInt(); |
|---|
| 87 | |
|---|
| 88 | osg::Object* obj = dynamic_cast<osg::Object*>(this); |
|---|
| 89 | if(obj){ |
|---|
| 90 | ((ive::Object*)(obj))->read(in); |
|---|
| 91 | } |
|---|
| 92 | else |
|---|
| 93 | in_THROW_EXCEPTION("Drawable::read(): Could not cast this osg::Drawable to an osg::Object."); |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | if(in->readBool()) |
|---|
| 99 | { |
|---|
| 100 | setStateSet(in->readStateSet()); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | if(in->readBool()) |
|---|
| 104 | { |
|---|
| 105 | osg::ClusterCullingCallback* ccc = new osg::ClusterCullingCallback(); |
|---|
| 106 | ((ive::ClusterCullingCallback*)(ccc))->read(in); |
|---|
| 107 | setCullCallback(ccc); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | if (in->getVersion() >= VERSION_0010) |
|---|
| 112 | { |
|---|
| 113 | if (in->readBool()) |
|---|
| 114 | { |
|---|
| 115 | osg::BoundingBox bb; |
|---|
| 116 | bb.xMin() = in->readFloat(); |
|---|
| 117 | bb.yMin() = in->readFloat(); |
|---|
| 118 | bb.zMin() = in->readFloat(); |
|---|
| 119 | bb.xMax() = in->readFloat(); |
|---|
| 120 | bb.yMax() = in->readFloat(); |
|---|
| 121 | bb.zMax() = in->readFloat(); |
|---|
| 122 | setInitialBound(bb); |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | setSupportsDisplayList(in->readBool()); |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | setUseDisplayList(in->readBool()); |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | setUseVertexBufferObjects(in->readBool()); |
|---|
| 134 | |
|---|
| 135 | } |
|---|
| 136 | else{ |
|---|
| 137 | in_THROW_EXCEPTION("Drawable::read(): Expected Drawable identification."); |
|---|
| 138 | } |
|---|
| 139 | } |
|---|