diff --git a/VisualStudio/osgPlugins/osg/dot_osg.dsp b/VisualStudio/osgPlugins/osg/dot_osg.dsp index 07c91b0f9..77a69e17c 100755 --- a/VisualStudio/osgPlugins/osg/dot_osg.dsp +++ b/VisualStudio/osgPlugins/osg/dot_osg.dsp @@ -328,6 +328,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\MatrixTransform.cpp SOURCE=..\..\..\src\osgPlugins\osg\BlendFunc.cpp # End Source File +# Begin Source File + +SOURCE=..\..\..\src\osgPlugins\osg\VertexProgram.cpp +# End Source File # End Group # Begin Group "Header Files" diff --git a/src/osgPlugins/osg/GNUmakefile b/src/osgPlugins/osg/GNUmakefile index db20bdd22..880d6f5dc 100644 --- a/src/osgPlugins/osg/GNUmakefile +++ b/src/osgPlugins/osg/GNUmakefile @@ -60,6 +60,7 @@ CXXFILES =\ TextureRectangle.cpp\ TextureCubeMap.cpp\ Transform.cpp\ + VertexProgram.cpp\ LIBS += $(OSG_LIBS) $(OTHER_LIBS) diff --git a/src/osgPlugins/osg/VertexProgram.cpp b/src/osgPlugins/osg/VertexProgram.cpp new file mode 100644 index 000000000..6c4695ca8 --- /dev/null +++ b/src/osgPlugins/osg/VertexProgram.cpp @@ -0,0 +1,75 @@ +#include "osg/VertexProgram" + +#include +#include +#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 VertexProgram_readLocalData(Object& obj, Input& fr); +bool VertexProgram_writeLocalData(const Object& obj, Output& fw); + +// register the read and write functions with the osgDB::Registry. +RegisterDotOsgWrapperProxy g_VertexProgramProxy +( + new osg::VertexProgram, + "VertexProgram", + "Object StateAttribute VertexProgram", + &VertexProgram_readLocalData, + &VertexProgram_writeLocalData +); + + +bool VertexProgram_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + VertexProgram& vertexProgram = static_cast(obj); + + if (fr.matchSequence("code {")) { + std::string code; + fr += 2; + iteratorAdvanced = true; + int entry = fr[0].getNoNestedBrackets(); + while (!fr.eof() && fr[0].getNoNestedBrackets() >= entry) { + if (fr[0].getStr()) { + code.append(std::string(fr[0].getStr())); + code.push_back('\n'); + } + ++fr; + } + vertexProgram.setVertexProgram(code); + } + return iteratorAdvanced; +} + + +bool VertexProgram_writeLocalData(const Object& obj,Output& fw) +{ + const VertexProgram& vertexProgram = static_cast(obj); + + std::vector lines; + std::istringstream iss(vertexProgram.getVertexProgram()); + std::string line; + while (std::getline(iss, line)) { + lines.push_back(line); + } + + fw.indent() << "code {\n"; + fw.moveIn(); + + std::vector::const_iterator j; + for (j=lines.begin(); j!=lines.end(); ++j) { + fw.indent() << "\"" << *j << "\"\n"; + } + + fw.moveOut(); + fw.indent() << "}\n"; + + return true; +}