From Bob Kuehne, added support for FragmentProgram and VertexProgram into .ive
This commit is contained in:
@@ -170,6 +170,14 @@ SOURCE=..\..\..\src\osgPlugins\ive\Exception.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\FragmentProgram.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\VertexProgram.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\Geode.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -422,6 +430,14 @@ SOURCE=..\..\..\src\osgPlugins\ive\Exception.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\FragmentProgram.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\VertexProgram.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\Geode.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#include "TexEnvCombine.h"
|
||||
#include "TexGen.h"
|
||||
#include "TexMat.h"
|
||||
#include "FragmentProgram.h"
|
||||
#include "VertexProgram.h"
|
||||
|
||||
#include "Group.h"
|
||||
#include "MatrixTransform.h"
|
||||
@@ -663,6 +665,14 @@ osg::StateAttribute* DataInputStream::readStateAttribute()
|
||||
attribute = new osg::TexMat();
|
||||
((ive::TexMat*)(attribute))->read(this);
|
||||
}
|
||||
else if(attributeID == IVEFRAGMENTPROGRAM){
|
||||
attribute = new osg::FragmentProgram();
|
||||
((ive::FragmentProgram*)(attribute))->read(this);
|
||||
}
|
||||
else if(attributeID == IVEVERTEXPROGRAM){
|
||||
attribute = new osg::VertexProgram();
|
||||
((ive::VertexProgram*)(attribute))->read(this);
|
||||
}
|
||||
else{
|
||||
throw Exception("Unknown StateAttribute in StateSet::read()");
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#include "TexEnvCombine.h"
|
||||
#include "TexGen.h"
|
||||
#include "TexMat.h"
|
||||
#include "FragmentProgram.h"
|
||||
#include "VertexProgram.h"
|
||||
|
||||
#include "Group.h"
|
||||
#include "MatrixTransform.h"
|
||||
@@ -466,6 +468,14 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute)
|
||||
else if(dynamic_cast<const osg::TexMat*>(attribute)){
|
||||
((ive::TexMat*)(attribute))->write(this);
|
||||
}
|
||||
// This is a FragmentProgram
|
||||
else if(dynamic_cast<const osg::FragmentProgram*>(attribute)){
|
||||
((ive::FragmentProgram*)(attribute))->write(this);
|
||||
}
|
||||
// This is a VertexProgram
|
||||
else if(dynamic_cast<const osg::VertexProgram*>(attribute)){
|
||||
((ive::VertexProgram*)(attribute))->write(this);
|
||||
}
|
||||
else{
|
||||
std::string className = attribute->className();
|
||||
throw Exception(std::string("StateSet::write(): Unknown StateAttribute: ").append(className));
|
||||
|
||||
68
src/osgPlugins/ive/FragmentProgram.cpp
Normal file
68
src/osgPlugins/ive/FragmentProgram.cpp
Normal 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.");
|
||||
}
|
||||
}
|
||||
15
src/osgPlugins/ive/FragmentProgram.h
Normal file
15
src/osgPlugins/ive/FragmentProgram.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef IVE_FRAGMENT_PROGRAM
|
||||
#define IVE_FRAGMENT_PROGRAM 1
|
||||
|
||||
#include <osg/FragmentProgram>
|
||||
#include "ReadWrite.h"
|
||||
|
||||
namespace ive{
|
||||
class FragmentProgram : public osg::FragmentProgram, public ReadWrite {
|
||||
public:
|
||||
void write(DataOutputStream* out);
|
||||
void read(DataInputStream* in);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // IVE_FRAGMENT_PROGRAM
|
||||
@@ -52,6 +52,8 @@ CXXFILES =\
|
||||
Texture.cpp\
|
||||
Texture1D.cpp\
|
||||
Texture2D.cpp\
|
||||
FragmentProgram.cpp\
|
||||
VertexProgram.cpp\
|
||||
TextureCubeMap.cpp\
|
||||
Transform.cpp\
|
||||
ReaderWriterIVE.cpp\
|
||||
|
||||
@@ -54,6 +54,8 @@ namespace ive {
|
||||
#define IVEPOINT 0x0000012B
|
||||
#define IVETEXMAT 0x0000012C
|
||||
#define IVELINEWIDTH 0x0000012D
|
||||
#define IVEFRAGMENTPROGRAM 0x0000012E
|
||||
#define IVEVERTEXPROGRAM 0x0000012F
|
||||
|
||||
// Drawables
|
||||
#define IVEDRAWABLE 0x00001000
|
||||
|
||||
@@ -81,7 +81,7 @@ class IVEReaderWriter : public ReaderWriter
|
||||
}
|
||||
catch(ive::Exception e)
|
||||
{
|
||||
osg::notify(osg::WARN)<<"Error parsing OSG file: "<< e.getError() << std::endl;
|
||||
osg::notify(osg::WARN)<<"Error writing IVE file: "<< e.getError() << std::endl;
|
||||
}
|
||||
return WriteResult::FILE_NOT_HANDLED;
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "Object.h"
|
||||
#include "BlendFunc.h"
|
||||
#include "Material.h"
|
||||
#include "Material.h"
|
||||
#include "CullFace.h"
|
||||
#include "PolygonOffset.h"
|
||||
#include "ShadeModel.h"
|
||||
|
||||
68
src/osgPlugins/ive/VertexProgram.cpp
Normal file
68
src/osgPlugins/ive/VertexProgram.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/**********************************************************************
|
||||
*
|
||||
* FILE: VertexProgram.cpp
|
||||
*
|
||||
* DESCRIPTION: Read/Write osg::VertexProgram 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 "VertexProgram.h"
|
||||
#include "Object.h"
|
||||
|
||||
using namespace ive;
|
||||
|
||||
void VertexProgram::write( DataOutputStream* out )
|
||||
{
|
||||
// Write VertexProgram identification.
|
||||
out->writeInt( IVEVERTEXPROGRAM );
|
||||
// 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::VertexProgram to an osg::Object.");
|
||||
}
|
||||
|
||||
// Write VertexProgram properties.
|
||||
// Write program.
|
||||
out->writeString( this->getVertexProgram() );
|
||||
}
|
||||
|
||||
void VertexProgram::read(DataInputStream* in){
|
||||
// Read VertexProgram identification.
|
||||
int id = in->peekInt();
|
||||
if( id == IVEVERTEXPROGRAM )
|
||||
{
|
||||
// Code to read VertexProgram 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::VertexProgram to an osg::Object." );
|
||||
}
|
||||
|
||||
// Read data
|
||||
std::string fp = in->readString();
|
||||
this->setVertexProgram( fp );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Exception("VertexProgram::read(): Expected VertexProgram identification.");
|
||||
}
|
||||
}
|
||||
15
src/osgPlugins/ive/VertexProgram.h
Normal file
15
src/osgPlugins/ive/VertexProgram.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef IVE_VERTEX_PROGRAM
|
||||
#define IVE_VERTEX_PROGRAM 1
|
||||
|
||||
#include <osg/VertexProgram>
|
||||
#include "ReadWrite.h"
|
||||
|
||||
namespace ive{
|
||||
class VertexProgram : public osg::VertexProgram, public ReadWrite {
|
||||
public:
|
||||
void write(DataOutputStream* out);
|
||||
void read(DataInputStream* in);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // IVE_VERTEX_PROGRAM
|
||||
Reference in New Issue
Block a user