root/OpenSceneGraph/trunk/src/osgPlugins/osg/StateAttribute.cpp @ 10671

Revision 10671, 2.4 kB (checked in by robert, 4 years ago)

From Cedric Pinson, "Here a patch to be able to clone stateattribute, in order to do that i
moved the StateAttribute::Callback structure to a file
StateAttributeCallback? with the same behavior as NodeCallback?.
"

RevLine 
[8790]1#include "osg/StateAttribute"
2
3#include "osgDB/Registry"
4#include "osgDB/Input"
5#include "osgDB/Output"
6
7using namespace osg;
8using namespace osgDB;
9using namespace std;
10
11// forward declare functions to use later.
12bool StateAttribute_readLocalData(Object& obj, Input& fr);
13bool StateAttribute_writeLocalData(const Object& obj, Output& fw);
14
15// register the read and write functions with the osgDB::Registry.
16osg::StateAttribute* g_stateAttribute = 0;
[9334]17REGISTER_DOTOSGWRAPPER(StateAttribute)
[8790]18(
19    g_stateAttribute, // no instance, osg::StateAttribute is an abstract class.
20    "StateAttribute",
21    "Object StateAttribute",
22    &StateAttribute_readLocalData,
23    &StateAttribute_writeLocalData
24);
25
26
27bool StateAttribute_readLocalData(Object& obj, Input& fr)
28{
29    bool iteratorAdvanced = false;
30    StateAttribute& stateAttribute = static_cast<StateAttribute&>(obj);
31
[10671]32    static ref_ptr<StateAttributeCallback> s_callback = new osg::StateAttributeCallback;
[8790]33    while (fr.matchSequence("UpdateCallback {"))
34    {
[9389]35        //int entry = fr[0].getNoNestedBrackets();
[8790]36        fr += 2;
[10671]37        StateAttributeCallback* callback = dynamic_cast<StateAttributeCallback*>(fr.readObjectOfType(*s_callback));
[8790]38        if (callback) {
39            stateAttribute.setUpdateCallback(callback);
40        }
41        iteratorAdvanced = true;
42    }
43
44    while (fr.matchSequence("EventCallback {"))
45    {
[9389]46        //int entry = fr[0].getNoNestedBrackets();
[8790]47        fr += 2;
[10671]48        StateAttributeCallback* callback = dynamic_cast<StateAttributeCallback*>(fr.readObjectOfType(*s_callback));
[8790]49        if (callback) {
50            stateAttribute.setEventCallback(callback);
51        }
52        iteratorAdvanced = true;
53    }
54
55    return iteratorAdvanced;
56}
57
58bool StateAttribute_writeLocalData(const Object& obj,Output& fw)
59{
60    const StateAttribute& stateAttribute = static_cast<const StateAttribute&>(obj);
61
62    if (stateAttribute.getUpdateCallback())
63    {
64        fw.indent() << "UpdateCallback {" << std::endl;
65        fw.moveIn();
66        fw.writeObject(*stateAttribute.getUpdateCallback());
67        fw.moveOut();
68        fw.indent() << "}" << std::endl;
69    }
70
71    if (stateAttribute.getEventCallback())
72    {
73        fw.indent() << "EventCallback {" << std::endl;
74        fw.moveIn();
75        fw.writeObject(*stateAttribute.getEventCallback());
76        fw.moveOut();
77        fw.indent() << "}" << std::endl;
78    }
79
80    return true;
81}
Note: See TracBrowser for help on using the browser.