~ubuntu-branches/debian/experimental/openscenegraph/experimental

« back to all changes in this revision

Viewing changes to OpenSceneGraph/src/osgWrappers/serializers/osg/ShaderBinary.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alberto Luaces
  • Date: 2011-01-29 11:36:29 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110129113629-qisrm2kdqlurc7t3
Tags: 2.9.11-1
* Removed bug-555869-ftbfs_with_binutils_gold.dpatch since upstream has
  already taken care of the issue.
* Removed bug-528229.dpatch since the pkgconfig files are now also split
  in upstream.
* Removed explicit dependency on GLU.
* Upstream no longer includes osgIntrospection (Closes: #592420).
* Disabled zip plugin as its implementation stores an embedded copy of
  zlib.
* Enabled Qt support. Thanks James Goppert.
* Enabled SVG and PDF plugins. Thanks James Goppert.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <osg/Shader>
 
2
#include <osgDB/ObjectWrapper>
 
3
#include <osgDB/Serializer>
 
4
 
 
5
static bool checkData( const osg::ShaderBinary& sb )
 
6
{
 
7
    return sb.getSize()>0;
 
8
}
 
9
 
 
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 >> osgDB::BEGIN_BRACKET;
 
21
        for ( unsigned int i=0; i<size; ++i )
 
22
        {
 
23
            is >> std::hex >> data[i] >> std::dec;
 
24
        }
 
25
        is >> osgDB::END_BRACKET;
 
26
    }
 
27
    sb.assign( size, (unsigned char*)data );
 
28
    delete data;
 
29
    return true;
 
30
}
 
31
 
 
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 << osgDB::BEGIN_BRACKET << std::endl;
 
43
        for ( unsigned int i=0; i<sb.getSize(); ++i )
 
44
        {
 
45
            os << std::hex << data[i] << std::dec << std::endl;
 
46
        }
 
47
        os << osgDB::END_BRACKET << std::endl;
 
48
    }
 
49
    return true;
 
50
}
 
51
 
 
52
REGISTER_OBJECT_WRAPPER( ShaderBinary,
 
53
                         new osg::ShaderBinary,
 
54
                         osg::ShaderBinary,
 
55
                         "osg::Object osg::ShaderBinary" )
 
56
{
 
57
    ADD_USER_SERIALIZER( Data );  // _data
 
58
}