1 #include <osg/FragmentProgram> 2 #include <osgDB/ObjectWrapper> 3 #include <osgDB/InputStream> 4 #include <osgDB/OutputStream> 5 6 // _programLocalParameters 7 static bool checkLocalParameters( const osg::FragmentProgram& fp ) 8 { 9 return fp.getLocalParameters().size()>0; 10 } 11 12 static bool readLocalParameters( osgDB::InputStream& is, osg::FragmentProgram& fp ) 13 { 14 unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; 15 for ( unsigned int i=0; i<size; ++i ) 16 { 17 GLuint key; osg::Vec4d value; 18 is >> key >> value; 19 fp.setProgramLocalParameter( key, value ); 20 } 21 is >> is.END_BRACKET; 22 return true; 23 } 24 25 static bool writeLocalParameters( osgDB::OutputStream& os, const osg::FragmentProgram& fp ) 26 { 27 const osg::FragmentProgram::LocalParamList& params = fp.getLocalParameters(); 28 os.writeSize(params.size()); os << os.BEGIN_BRACKET << std::endl; 29 for ( osg::FragmentProgram::LocalParamList::const_iterator itr=params.begin(); 30 itr!=params.end(); ++itr ) 31 { 32 os << itr->first << osg::Vec4d(itr->second) << std::endl; 33 } 34 os << os.END_BRACKET << std::endl; 35 return true; 36 } 37 38 // _matrixList 39 static bool checkMatrices( const osg::FragmentProgram& fp ) 40 { 41 return fp.getMatrices().size()>0; 42 } 43 44 static bool readMatrices( osgDB::InputStream& is, osg::FragmentProgram& fp ) 45 { 46 unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; 47 for ( unsigned int i=0; i<size; ++i ) 48 { 49 unsigned int key; osg::Matrixd value; 50 is >> key >> value; 51 fp.setMatrix( key, value ); 52 } 53 is >> is.END_BRACKET; 54 return true; 55 } 56 57 static bool writeMatrices( osgDB::OutputStream& os, const osg::FragmentProgram& fp ) 58 { 59 const osg::FragmentProgram::MatrixList& matrices = fp.getMatrices(); 60 os.writeSize(matrices.size()); os << os.BEGIN_BRACKET << std::endl; 61 for ( osg::FragmentProgram::MatrixList::const_iterator itr=matrices.begin(); 62 itr!=matrices.end(); ++itr ) 63 { 64 os << (unsigned int)itr->first << osg::Matrixd(itr->second) << std::endl; 65 } 66 os << os.END_BRACKET << std::endl; 67 return true; 68 } 69 70 REGISTER_OBJECT_WRAPPER( FragmentProgram, 71 new osg::FragmentProgram, 72 osg::FragmentProgram, 73 "osg::Object osg::StateAttribute osg::FragmentProgram" ) 74 { 75 ADD_STRING_SERIALIZER( FragmentProgram, "" ); // _fragmentProgram 76 ADD_USER_SERIALIZER( LocalParameters ); // _programLocalParameters 77 ADD_USER_SERIALIZER( Matrices ); // _matrixList 78 } 79