root/OpenSceneGraph/trunk/src/osgPlugins/ive/Drawable.cpp @ 13041

Revision 13041, 3.8 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/**********************************************************************
2 *
3 *    FILE:            Drawable.cpp
4 *
5 *    DESCRIPTION:    Read/Write osg::Drawable in binary format to disk.
6 *
7 *    CREATED BY:        Auto generated by iveGenerated
8 *                    and later modified by Rune Schmidt Jensen.
9 *
10 *    HISTORY:        Created 18.3.2003
11 *
12 *    Copyright 2003 VR-C
13 **********************************************************************/
14
15#include "Exception.h"
16#include "Drawable.h"
17#include "ClusterCullingCallback.h"
18#include "Object.h"
19#include "StateSet.h"
20
21
22using namespace ive;
23
24void Drawable::write(DataOutputStream* out)
25{
26    // Write Drawable's identification.
27    out->writeInt(IVEDRAWABLE);
28    // If the osg class is inherited by any other class we should also write this to file.
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    // Write Drawable's properties.
37
38    // Write stateset if any
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    // Write support display list.
70    out->writeBool(getSupportsDisplayList());
71
72    // Write use display list.
73    out->writeBool(getUseDisplayList());
74
75    // Write use display list.
76    out->writeBool(getUseVertexBufferObjects());
77}
78
79void Drawable::read(DataInputStream* in)
80{
81    // Read Drawable's identification.
82    int id = in->peekInt();
83    if(id == IVEDRAWABLE)
84    {
85        // Code to read Drawable's properties.
86        id = in->readInt();
87        // If the osg class is inherited by any other class we should also read this from file.
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        // Read in drawable's properties
96
97        // Read stateset if any
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        // Read support display list
127        setSupportsDisplayList(in->readBool());
128
129        // Read use display list
130        setUseDisplayList(in->readBool());
131
132        // Read use display list
133        setUseVertexBufferObjects(in->readBool());
134
135    }
136    else{
137        in_THROW_EXCEPTION("Drawable::read(): Expected Drawable identification.");
138    }
139}
Note: See TracBrowser for help on using the browser.