Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
From Guillaume Chouvenc, "I have added the file StateAttribute.cpp in…
… src/osgPlugins/osg to support the reading and writing of StateAttribute Callback in osg files. "
- Loading branch information
1 parent
72a22ac
commit ad5fc11
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "osg/StateAttribute" | ||
|
||
#include "osgDB/Registry" | ||
#include "osgDB/Input" | ||
#include "osgDB/Output" | ||
|
||
using namespace osg; | ||
using namespace osgDB; | ||
using namespace std; | ||
|
||
// forward declare functions to use later. | ||
bool StateAttribute_readLocalData(Object& obj, Input& fr); | ||
bool StateAttribute_writeLocalData(const Object& obj, Output& fw); | ||
|
||
// register the read and write functions with the osgDB::Registry. | ||
osg::StateAttribute* g_stateAttribute = 0; | ||
RegisterDotOsgWrapperProxy g_StateAttributeProxy | ||
( | ||
g_stateAttribute, // no instance, osg::StateAttribute is an abstract class. | ||
"StateAttribute", | ||
"Object StateAttribute", | ||
&StateAttribute_readLocalData, | ||
&StateAttribute_writeLocalData | ||
); | ||
|
||
|
||
bool StateAttribute_readLocalData(Object& obj, Input& fr) | ||
{ | ||
bool iteratorAdvanced = false; | ||
StateAttribute& stateAttribute = static_cast<StateAttribute&>(obj); | ||
|
||
static ref_ptr<StateAttribute::Callback> s_callback = new osg::StateAttribute::Callback; | ||
while (fr.matchSequence("UpdateCallback {")) | ||
{ | ||
int entry = fr[0].getNoNestedBrackets(); | ||
fr += 2; | ||
StateAttribute::Callback* callback = dynamic_cast<StateAttribute::Callback*>(fr.readObjectOfType(*s_callback)); | ||
if (callback) { | ||
stateAttribute.setUpdateCallback(callback); | ||
} | ||
iteratorAdvanced = true; | ||
} | ||
|
||
while (fr.matchSequence("EventCallback {")) | ||
{ | ||
int entry = fr[0].getNoNestedBrackets(); | ||
fr += 2; | ||
StateAttribute::Callback* callback = dynamic_cast<StateAttribute::Callback*>(fr.readObjectOfType(*s_callback)); | ||
if (callback) { | ||
stateAttribute.setEventCallback(callback); | ||
} | ||
iteratorAdvanced = true; | ||
} | ||
|
||
return iteratorAdvanced; | ||
} | ||
|
||
bool StateAttribute_writeLocalData(const Object& obj,Output& fw) | ||
{ | ||
const StateAttribute& stateAttribute = static_cast<const StateAttribute&>(obj); | ||
|
||
if (stateAttribute.getUpdateCallback()) | ||
{ | ||
fw.indent() << "UpdateCallback {" << std::endl; | ||
fw.moveIn(); | ||
fw.writeObject(*stateAttribute.getUpdateCallback()); | ||
fw.moveOut(); | ||
fw.indent() << "}" << std::endl; | ||
} | ||
|
||
if (stateAttribute.getEventCallback()) | ||
{ | ||
fw.indent() << "EventCallback {" << std::endl; | ||
fw.moveIn(); | ||
fw.writeObject(*stateAttribute.getEventCallback()); | ||
fw.moveOut(); | ||
fw.indent() << "}" << std::endl; | ||
} | ||
|
||
return true; | ||
} |