2005-05-11 04:20:20 +08:00
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* FILE: Shader.cpp
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Read/Write osg::Shader in binary format to disk.
|
|
|
|
*
|
|
|
|
* CREATED BY: Auto generated by iveGenerated
|
|
|
|
* and later modified by Rune Schmidt Jensen.
|
|
|
|
*
|
|
|
|
* HISTORY: Created 20.3.2003
|
|
|
|
*
|
|
|
|
* Copyright 2003 VR-C
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#include "Exception.h"
|
|
|
|
#include "Shader.h"
|
|
|
|
#include "Object.h"
|
|
|
|
|
|
|
|
using namespace ive;
|
|
|
|
|
|
|
|
void Shader::write(DataOutputStream* out){
|
|
|
|
// Write Shader's identification.
|
|
|
|
out->writeInt(IVESHADER);
|
|
|
|
// If the osg class is inherited by any other class we should also write this to file.
|
|
|
|
osg::Object* obj = dynamic_cast<osg::Object*>(this);
|
|
|
|
if(obj)
|
|
|
|
{
|
|
|
|
((ive::Object*)(obj))->write(out);
|
|
|
|
}
|
|
|
|
else
|
2009-11-17 20:54:55 +08:00
|
|
|
out_THROW_EXCEPTION("Shader::write(): Could not cast this osg::Shader to an osg::Object.");
|
2005-05-11 04:20:20 +08:00
|
|
|
|
2005-06-08 21:16:19 +08:00
|
|
|
if ( out->getVersion() < VERSION_0012 )
|
|
|
|
{
|
|
|
|
out->writeString(getName());
|
|
|
|
}
|
2005-05-11 19:42:09 +08:00
|
|
|
out->writeInt(getType());
|
|
|
|
out->writeString(getShaderSource());
|
|
|
|
|
2005-05-11 04:20:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Shader::read(DataInputStream* in)
|
|
|
|
{
|
|
|
|
// Read Shader's identification.
|
|
|
|
int id = in->peekInt();
|
|
|
|
if(id == IVESHADER)
|
|
|
|
{
|
|
|
|
// Read Shader's identification.
|
|
|
|
id = in->readInt();
|
|
|
|
// If the osg class is inherited by any other class we should also read this from file.
|
|
|
|
osg::Object* obj = dynamic_cast<osg::Object*>(this);
|
|
|
|
if(obj)
|
|
|
|
{
|
|
|
|
((ive::Object*)(obj))->read(in);
|
|
|
|
}
|
|
|
|
else
|
2009-11-17 20:54:55 +08:00
|
|
|
in_THROW_EXCEPTION("Shader::read(): Could not cast this osg::Shader to an osg::Object.");
|
2005-05-11 04:20:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-17 20:54:55 +08:00
|
|
|
in_THROW_EXCEPTION("Shader::read(): Expected Shader identification.");
|
2005-05-11 04:20:20 +08:00
|
|
|
}
|
2005-05-11 19:42:09 +08:00
|
|
|
|
2005-06-08 21:16:19 +08:00
|
|
|
if ( in->getVersion() < VERSION_0012 )
|
|
|
|
{
|
|
|
|
setName(in->readString());
|
|
|
|
}
|
|
|
|
|
|
|
|
setType(static_cast<Type>(in->readInt()));
|
|
|
|
setShaderSource(in->readString());
|
2005-05-11 19:42:09 +08:00
|
|
|
|
2005-05-11 04:20:20 +08:00
|
|
|
}
|