From Bob Kuehne, added support for FragmentProgram and VertexProgram into .ive

This commit is contained in:
Robert Osfield
2004-03-04 14:33:01 +00:00
parent 8540414ae0
commit feb36860b6
11 changed files with 208 additions and 1 deletions

View File

@@ -0,0 +1,68 @@
/**********************************************************************
*
* FILE: FragmentProgram.cpp
*
* DESCRIPTION: Read/Write osg::FragmentProgram in binary format to disk.
*
* CREATED BY: rpk@blue-newt.com
*
* HISTORY: Created 04/20/2004
*
* Copyright 2004 Blue Newt Software
**********************************************************************/
#include "Exception.h"
#include "FragmentProgram.h"
#include "Object.h"
using namespace ive;
void FragmentProgram::write( DataOutputStream* out )
{
// Write FragmentProgram identification.
out->writeInt( IVEFRAGMENTPROGRAM );
// 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
{
throw Exception("Material::write(): Could not cast this osg::FragmentProgram to an osg::Object.");
}
// Write FragmentProgram properties.
// Write program.
out->writeString( this->getFragmentProgram() );
}
void FragmentProgram::read(DataInputStream* in){
// Read FragmentProgram identification.
int id = in->peekInt();
if( id == IVEFRAGMENTPROGRAM )
{
// Code to read FragmentProgram properties.
id = in->readInt();
// handle Object data
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if( obj )
{
( ( ive::Object* )( obj ) )->read( in );
}
else
{
throw Exception( "Material::read(): Could not cast this osg::FragmentProgram to an osg::Object." );
}
// Read data
std::string fp = in->readString();
this->setFragmentProgram( fp );
}
else
{
throw Exception("FragmentProgram::read(): Expected FragmentProgram identification.");
}
}