root/OpenSceneGraph/trunk/src/osgPlugins/ive/Program.cpp @ 13041

Revision 13041, 3.0 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/**********************************************************************
2 *
3 *    FILE:            Program.cpp
4 *
5 *    DESCRIPTION:    Read/Write osg::Program in binary format to disk.
6 *
7 *    CREATED BY:        Auto generated by iveGenerated
8 *                    and later modified by Rune Schmidt Jensen.
9 *
10 *    HISTORY:        Created 20.3.2003
11 *
12 *    Copyright 2003 VR-C
13 **********************************************************************/
14
15#include "Exception.h"
16#include "Program.h"
17#include "Object.h"
18
19using namespace ive;
20
21void Program::write(DataOutputStream* out){
22    // Write Program's identification.
23    out->writeInt(IVEPROGRAM);
24    // If the osg class is inherited by any other class we should also write this to file.
25    osg::Object*  obj = dynamic_cast<osg::Object*>(this);
26    if(obj)
27    {
28        ((ive::Object*)(obj))->write(out);
29    }
30    else
31        out_THROW_EXCEPTION("Program::write(): Could not cast this osg::Program to an osg::Object.");
32
33    if ( out->getVersion() >= VERSION_0030 )
34    {
35        out->writeInt(getParameter(GL_GEOMETRY_VERTICES_OUT_EXT));
36        out->writeInt(getParameter(GL_GEOMETRY_INPUT_TYPE_EXT));
37        out->writeInt(getParameter(GL_GEOMETRY_OUTPUT_TYPE_EXT));
38    }
39
40    const AttribBindingList& abl = getAttribBindingList();
41    out->writeUInt(abl.size());
42    for(AttribBindingList::const_iterator itr = abl.begin();
43        itr != abl.end();
44        ++itr)
45    {
46        out->writeString(itr->first);
47        out->writeUInt(itr->second);
48    }
49
50    // Write
51    out->writeUInt(getNumShaders());
52    for(unsigned int si=0; si<getNumShaders(); ++si)
53    {
54        out->writeShader(getShader(si));
55    }
56}
57
58void Program::read(DataInputStream* in)
59{
60    // Read Program's identification.
61    int id = in->peekInt();
62    if(id == IVEPROGRAM)
63    {
64        // Read Program's identification.
65        id = in->readInt();
66        // If the osg class is inherited by any other class we should also read this from file.
67        osg::Object*  obj = dynamic_cast<osg::Object*>(this);
68        if(obj)
69        {
70            ((ive::Object*)(obj))->read(in);
71        }
72        else
73            in_THROW_EXCEPTION("Program::read(): Could not cast this osg::Program to an osg::Object.");
74
75    }
76    else
77    {
78        in_THROW_EXCEPTION("Program::read(): Expected Program identification.");
79    }
80
81    if ( in->getVersion() >= VERSION_0030 )
82    {
83        setParameter(GL_GEOMETRY_VERTICES_OUT_EXT, in->readInt());
84        setParameter(GL_GEOMETRY_INPUT_TYPE_EXT, in->readInt());
85        setParameter(GL_GEOMETRY_OUTPUT_TYPE_EXT, in->readInt());
86    }
87
88    // reading in shaders.
89    unsigned int size = in->readUInt();
90    for(unsigned int ai=0; ai<size; ++ai)
91    {
92        std::string name = in->readString();
93        unsigned int index = in->readUInt();
94        addBindAttribLocation(name, index);
95    }
96
97    // reading in shaders.
98    size = in->readUInt();
99    for(unsigned int si=0; si<size; ++si)
100    {
101        osg::Shader* shader = in->readShader();
102        addShader(shader);
103    }
104
105}
Note: See TracBrowser for help on using the browser.