1 #include <osg/Shader>
2 #include <osgDB/ObjectWrapper>
3 #include <osgDB/Serializer>
4
checkData(const osg::ShaderBinary & sb)5 static bool checkData( const osg::ShaderBinary& sb )
6 {
7 return sb.getSize()>0;
8 }
9
readData(osgDB::InputStream & is,osg::ShaderBinary & sb)10 static bool readData( osgDB::InputStream& is, osg::ShaderBinary& sb )
11 {
12 unsigned int size; is >> size;
13 char* data = new char[size];
14 if ( is.isBinary() )
15 {
16 is.readCharArray( data, size );
17 }
18 else
19 {
20 is >> is.BEGIN_BRACKET;
21 for ( unsigned int i=0; i<size; ++i )
22 {
23 is >> std::hex >> data[i] >> std::dec;
24 }
25 is >> is.END_BRACKET;
26 }
27 sb.assign( size, (unsigned char*)data );
28 delete [] data;
29 return true;
30 }
31
writeData(osgDB::OutputStream & os,const osg::ShaderBinary & sb)32 static bool writeData( osgDB::OutputStream& os, const osg::ShaderBinary& sb )
33 {
34 if ( os.isBinary() )
35 {
36 os << (unsigned int)sb.getSize();
37 os.writeCharArray( (char*)sb.getData(), sb.getSize() );
38 }
39 else
40 {
41 const unsigned char* data = sb.getData();
42 os << (unsigned int)sb.getSize();
43 os << os.BEGIN_BRACKET << std::endl;
44 for ( unsigned int i=0; i<sb.getSize(); ++i )
45 {
46 os << std::hex << data[i] << std::dec << std::endl;
47 }
48 os << os.END_BRACKET << std::endl;
49 }
50 return true;
51 }
52
53 REGISTER_OBJECT_WRAPPER( ShaderBinary,
54 new osg::ShaderBinary,
55 osg::ShaderBinary,
56 "osg::Object osg::ShaderBinary" )
57 {
58 ADD_USER_SERIALIZER( Data ); // _data
59 }
60