From feb36860b663c5fd13577119a6d32a3939b2bac2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 4 Mar 2004 14:33:01 +0000 Subject: [PATCH] From Bob Kuehne, added support for FragmentProgram and VertexProgram into .ive --- VisualStudio/osgPlugins/ive/ive.dsp | 16 ++++++ src/osgPlugins/ive/DataInputStream.cpp | 10 ++++ src/osgPlugins/ive/DataOutputStream.cpp | 10 ++++ src/osgPlugins/ive/FragmentProgram.cpp | 68 +++++++++++++++++++++++++ src/osgPlugins/ive/FragmentProgram.h | 15 ++++++ src/osgPlugins/ive/GNUmakefile | 2 + src/osgPlugins/ive/ReadWrite.h | 2 + src/osgPlugins/ive/ReaderWriterIVE.cpp | 2 +- src/osgPlugins/ive/StateSet.cpp | 1 + src/osgPlugins/ive/VertexProgram.cpp | 68 +++++++++++++++++++++++++ src/osgPlugins/ive/VertexProgram.h | 15 ++++++ 11 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 src/osgPlugins/ive/FragmentProgram.cpp create mode 100644 src/osgPlugins/ive/FragmentProgram.h create mode 100644 src/osgPlugins/ive/VertexProgram.cpp create mode 100644 src/osgPlugins/ive/VertexProgram.h diff --git a/VisualStudio/osgPlugins/ive/ive.dsp b/VisualStudio/osgPlugins/ive/ive.dsp index f27e9ff52..1c29dc937 100755 --- a/VisualStudio/osgPlugins/ive/ive.dsp +++ b/VisualStudio/osgPlugins/ive/ive.dsp @@ -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 diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index 4e7dec06f..01dcf2e77 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -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()"); } diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index ef47cdf73..d95dc660d 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -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(attribute)){ ((ive::TexMat*)(attribute))->write(this); } + // This is a FragmentProgram + else if(dynamic_cast(attribute)){ + ((ive::FragmentProgram*)(attribute))->write(this); + } + // This is a VertexProgram + else if(dynamic_cast(attribute)){ + ((ive::VertexProgram*)(attribute))->write(this); + } else{ std::string className = attribute->className(); throw Exception(std::string("StateSet::write(): Unknown StateAttribute: ").append(className)); diff --git a/src/osgPlugins/ive/FragmentProgram.cpp b/src/osgPlugins/ive/FragmentProgram.cpp new file mode 100644 index 000000000..0cfbe0d26 --- /dev/null +++ b/src/osgPlugins/ive/FragmentProgram.cpp @@ -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(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(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."); + } +} diff --git a/src/osgPlugins/ive/FragmentProgram.h b/src/osgPlugins/ive/FragmentProgram.h new file mode 100644 index 000000000..822cd1d4d --- /dev/null +++ b/src/osgPlugins/ive/FragmentProgram.h @@ -0,0 +1,15 @@ +#ifndef IVE_FRAGMENT_PROGRAM +#define IVE_FRAGMENT_PROGRAM 1 + +#include +#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 \ No newline at end of file diff --git a/src/osgPlugins/ive/GNUmakefile b/src/osgPlugins/ive/GNUmakefile index 10388b802..b952e19a6 100644 --- a/src/osgPlugins/ive/GNUmakefile +++ b/src/osgPlugins/ive/GNUmakefile @@ -52,6 +52,8 @@ CXXFILES =\ Texture.cpp\ Texture1D.cpp\ Texture2D.cpp\ + FragmentProgram.cpp\ + VertexProgram.cpp\ TextureCubeMap.cpp\ Transform.cpp\ ReaderWriterIVE.cpp\ diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index fa5dfee51..064b75414 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -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 diff --git a/src/osgPlugins/ive/ReaderWriterIVE.cpp b/src/osgPlugins/ive/ReaderWriterIVE.cpp index fd59dae8a..f63da4d49 100644 --- a/src/osgPlugins/ive/ReaderWriterIVE.cpp +++ b/src/osgPlugins/ive/ReaderWriterIVE.cpp @@ -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; diff --git a/src/osgPlugins/ive/StateSet.cpp b/src/osgPlugins/ive/StateSet.cpp index 2711777f7..672f8144a 100644 --- a/src/osgPlugins/ive/StateSet.cpp +++ b/src/osgPlugins/ive/StateSet.cpp @@ -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" diff --git a/src/osgPlugins/ive/VertexProgram.cpp b/src/osgPlugins/ive/VertexProgram.cpp new file mode 100644 index 000000000..5a6c5adfd --- /dev/null +++ b/src/osgPlugins/ive/VertexProgram.cpp @@ -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(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(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."); + } +} diff --git a/src/osgPlugins/ive/VertexProgram.h b/src/osgPlugins/ive/VertexProgram.h new file mode 100644 index 000000000..d190a11e0 --- /dev/null +++ b/src/osgPlugins/ive/VertexProgram.h @@ -0,0 +1,15 @@ +#ifndef IVE_VERTEX_PROGRAM +#define IVE_VERTEX_PROGRAM 1 + +#include +#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 \ No newline at end of file