| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include "Exception.h" |
|---|
| 16 | #include "Program.h" |
|---|
| 17 | #include "Object.h" |
|---|
| 18 | |
|---|
| 19 | using namespace ive; |
|---|
| 20 | |
|---|
| 21 | void Program::write(DataOutputStream* out){ |
|---|
| 22 | |
|---|
| 23 | out->writeInt(IVEPROGRAM); |
|---|
| 24 | |
|---|
| 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 | |
|---|
| 51 | out->writeUInt(getNumShaders()); |
|---|
| 52 | for(unsigned int si=0; si<getNumShaders(); ++si) |
|---|
| 53 | { |
|---|
| 54 | out->writeShader(getShader(si)); |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | void Program::read(DataInputStream* in) |
|---|
| 59 | { |
|---|
| 60 | |
|---|
| 61 | int id = in->peekInt(); |
|---|
| 62 | if(id == IVEPROGRAM) |
|---|
| 63 | { |
|---|
| 64 | |
|---|
| 65 | id = in->readInt(); |
|---|
| 66 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 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 | } |
|---|