Put in place the class to implement GLSL support in .ive
This commit is contained in:
@@ -372,6 +372,18 @@ SOURCE=..\..\..\src\osgPlugins\ive\Text.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\Program.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\Shader.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\Uniform.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\Texture.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -688,6 +700,18 @@ SOURCE=..\..\..\src\osgPlugins\ive\Text.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\Program.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\Shader.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\Uniform.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\ive\Texture.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "LightModel.h"
|
||||
#include "ProxyNode.h"
|
||||
#include "FrontFace.h"
|
||||
#include "Program.h"
|
||||
|
||||
#include "Group.h"
|
||||
#include "MatrixTransform.h"
|
||||
@@ -58,6 +59,7 @@
|
||||
#include "OccluderNode.h"
|
||||
#include "Impostor.h"
|
||||
#include "CoordinateSystemNode.h"
|
||||
#include "Uniform.h"
|
||||
|
||||
#include "LightPointNode.h"
|
||||
#include "MultiSwitch.h"
|
||||
@@ -775,6 +777,10 @@ osg::StateAttribute* DataInputStream::readStateAttribute()
|
||||
attribute = new osg::FrontFace();
|
||||
((ive::FrontFace*)(attribute))->read(this);
|
||||
}
|
||||
else if(attributeID == IVEPROGRAM){
|
||||
attribute = new osg::Program();
|
||||
((ive::Program*)(attribute))->read(this);
|
||||
}
|
||||
else{
|
||||
throw Exception("Unknown StateAttribute in StateSet::read()");
|
||||
}
|
||||
@@ -788,6 +794,30 @@ osg::StateAttribute* DataInputStream::readStateAttribute()
|
||||
return attribute;
|
||||
}
|
||||
|
||||
osg::Uniform* DataInputStream::readUniform()
|
||||
{
|
||||
// Read uniforms unique ID.
|
||||
int id = readInt();
|
||||
// See if uniform is already in the list.
|
||||
UniformMap::iterator itr= _uniformMap.find(id);
|
||||
if (itr!=_uniformMap.end()) return itr->second.get();
|
||||
|
||||
// Uniform is not in list.
|
||||
// Create a new uniform,
|
||||
osg::Uniform* uniform = new osg::Uniform();
|
||||
|
||||
// read its properties from stream
|
||||
((ive::Uniform*)(uniform))->read(this);
|
||||
|
||||
// and add it to the uniform map,
|
||||
_uniformMap[id] = uniform;
|
||||
|
||||
|
||||
if (_verboseOutput) std::cout<<"read/writeUniform() ["<<id<<"]"<<std::endl;
|
||||
|
||||
return uniform;
|
||||
}
|
||||
|
||||
osg::Drawable* DataInputStream::readDrawable()
|
||||
{
|
||||
// Read stateattributes unique ID.
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Image>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Uniform>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
#include <osgDB/ReaderWriter>
|
||||
@@ -79,6 +80,7 @@ public:
|
||||
osg::Image* readImage(std::string s);
|
||||
osg::StateSet* readStateSet();
|
||||
osg::StateAttribute* readStateAttribute();
|
||||
osg::Uniform* readUniform();
|
||||
osg::Drawable* readDrawable();
|
||||
osg::Shape* readShape();
|
||||
osg::Node* readNode();
|
||||
@@ -90,13 +92,14 @@ public:
|
||||
typedef std::map<std::string, osg::ref_ptr<osg::Image> > ImageMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::StateSet> > StateSetMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::StateAttribute> > StateAttributeMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::Uniform> > UniformMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::Drawable> > DrawableMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::Shape> > ShapeMap;
|
||||
typedef std::map<int,osg::ref_ptr<osg::Node> > NodeMap;
|
||||
|
||||
bool _verboseOutput;
|
||||
bool _verboseOutput;
|
||||
std::istream* _istream;
|
||||
int _byteswap;
|
||||
int _byteswap;
|
||||
|
||||
private:
|
||||
int _version;
|
||||
@@ -105,6 +108,7 @@ private:
|
||||
ImageMap _imageMap;
|
||||
StateSetMap _statesetMap;
|
||||
StateAttributeMap _stateAttributeMap;
|
||||
UniformMap _uniformMap;
|
||||
DrawableMap _drawableMap;
|
||||
ShapeMap _shapeMap;
|
||||
NodeMap _nodeMap;
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
#include "LightModel.h"
|
||||
#include "ProxyNode.h"
|
||||
#include "FrontFace.h"
|
||||
#include "Program.h"
|
||||
#include "Uniform.h"
|
||||
|
||||
#include "Group.h"
|
||||
#include "MatrixTransform.h"
|
||||
@@ -467,7 +469,6 @@ void DataOutputStream::writeStateSet(const osg::StateSet* stateset)
|
||||
if (_verboseOutput) std::cout<<"read/writeStateSet() ["<<id<<"]"<<std::endl;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute)
|
||||
@@ -577,6 +578,10 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute)
|
||||
else if(dynamic_cast<const osg::FrontFace*>(attribute)){
|
||||
((ive::FrontFace*)(attribute))->write(this);
|
||||
}
|
||||
// This is a FrontFace
|
||||
else if(dynamic_cast<const osg::Program*>(attribute)){
|
||||
((ive::Program*)(attribute))->write(this);
|
||||
}
|
||||
|
||||
else{
|
||||
std::string className = attribute->className();
|
||||
@@ -586,6 +591,35 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute)
|
||||
}
|
||||
}
|
||||
|
||||
void DataOutputStream::writeUniform(const osg::Uniform* uniform)
|
||||
{
|
||||
UniformMap::iterator itr = _uniformMap.find(uniform);
|
||||
if (itr!=_uniformMap.end())
|
||||
{
|
||||
// Id already exists so just write ID.
|
||||
writeInt(itr->second);
|
||||
|
||||
if (_verboseOutput) std::cout<<"read/writeStateSet() ["<<itr->second<<"]"<<std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// id doesn't exist so create a new ID and
|
||||
// register the uniform.
|
||||
|
||||
int id = _uniformMap.size();
|
||||
_uniformMap[uniform] = id;
|
||||
|
||||
// write the id.
|
||||
writeInt(id);
|
||||
|
||||
// write the stateset.
|
||||
((ive::Uniform*)(uniform))->write(this);
|
||||
|
||||
if (_verboseOutput) std::cout<<"read/writeUniform() ["<<id<<"]"<<std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DataOutputStream::writeDrawable(const osg::Drawable* drawable)
|
||||
{
|
||||
DrawableMap::iterator itr = _drawableMap.find(drawable);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <osg/Matrix>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Shape>
|
||||
#include <osg/Uniform>
|
||||
#include <osgDB/ReaderWriter>
|
||||
|
||||
#include "IveVersion.h"
|
||||
@@ -71,6 +72,7 @@ public:
|
||||
|
||||
void writeStateSet(const osg::StateSet* stateset);
|
||||
void writeStateAttribute(const osg::StateAttribute* sa);
|
||||
void writeUniform(const osg::Uniform* uniform);
|
||||
void writeDrawable(const osg::Drawable* sa);
|
||||
void writeShape(const osg::Shape* sa);
|
||||
void writeNode(const osg::Node* sa);
|
||||
@@ -99,12 +101,14 @@ private:
|
||||
// Container to map stateset uniques to their respective stateset.
|
||||
typedef std::map<const osg::StateSet*,int> StateSetMap;
|
||||
typedef std::map<const osg::StateAttribute*,int> StateAttributeMap;
|
||||
typedef std::map<const osg::Uniform*,int> UniformMap;
|
||||
typedef std::map<const osg::Drawable*,int> DrawableMap;
|
||||
typedef std::map<const osg::Shape*,int> ShapeMap;
|
||||
typedef std::map<const osg::Shape*,int> ShapeMap;
|
||||
typedef std::map<const osg::Node*,int> NodeMap;
|
||||
|
||||
StateSetMap _stateSetMap;
|
||||
StateAttributeMap _stateAttributeMap;
|
||||
UniformMap _uniformMap;
|
||||
DrawableMap _drawableMap;
|
||||
ShapeMap _shapeMap;
|
||||
NodeMap _nodeMap;
|
||||
|
||||
@@ -57,10 +57,12 @@ CXXFILES =\
|
||||
PolygonOffset.cpp\
|
||||
PositionAttitudeTransform.cpp\
|
||||
PrimitiveSet.cpp\
|
||||
Program.cpp\
|
||||
ProxyNode.cpp\
|
||||
ReaderWriterIVE.cpp\
|
||||
Sequence.cpp\
|
||||
ShadeModel.cpp\
|
||||
Shader.cpp\
|
||||
Shape.cpp\
|
||||
ShapeDrawable.cpp\
|
||||
StateSet.cpp\
|
||||
@@ -70,13 +72,14 @@ CXXFILES =\
|
||||
TexGen.cpp\
|
||||
TexGenNode.cpp\
|
||||
TexMat.cpp\
|
||||
Text.cpp\
|
||||
Texture1D.cpp\
|
||||
Texture2D.cpp\
|
||||
Texture3D.cpp\
|
||||
Texture.cpp\
|
||||
Text.cpp\
|
||||
TextureCubeMap.cpp\
|
||||
Transform.cpp\
|
||||
Uniform.cpp\
|
||||
VertexProgram.cpp\
|
||||
VisibilityGroup.cpp\
|
||||
|
||||
|
||||
@@ -18,8 +18,9 @@
|
||||
|
||||
#define VERSION_0008 8
|
||||
#define VERSION_0009 9
|
||||
#define VERSION_0010 10
|
||||
|
||||
#define VERSION VERSION_0009
|
||||
#define VERSION VERSION_0010
|
||||
|
||||
|
||||
/* The BYTE_SEX tag is used to check the endian
|
||||
|
||||
57
src/osgPlugins/ive/Program.cpp
Normal file
57
src/osgPlugins/ive/Program.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/**********************************************************************
|
||||
*
|
||||
* FILE: Program.cpp
|
||||
*
|
||||
* DESCRIPTION: Read/Write osg::Program 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 "Program.h"
|
||||
#include "Object.h"
|
||||
|
||||
using namespace ive;
|
||||
|
||||
void Program::write(DataOutputStream* out){
|
||||
// Write Program's identification.
|
||||
out->writeInt(IVEPROGRAM);
|
||||
// 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("Program::write(): Could not cast this osg::Program to an osg::Object.");
|
||||
|
||||
}
|
||||
|
||||
void Program::read(DataInputStream* in)
|
||||
{
|
||||
// Read Program's identification.
|
||||
int id = in->peekInt();
|
||||
if(id == IVEPROGRAM)
|
||||
{
|
||||
// Read Program'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
|
||||
throw Exception("Program::read(): Could not cast this osg::Program to an osg::Object.");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Exception("Program::read(): Expected Program identification.");
|
||||
}
|
||||
}
|
||||
15
src/osgPlugins/ive/Program.h
Normal file
15
src/osgPlugins/ive/Program.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef IVE_PROGRAM
|
||||
#define IVE_PROGRAM 1
|
||||
|
||||
#include <osg/Program>
|
||||
#include "ReadWrite.h"
|
||||
|
||||
namespace ive{
|
||||
class Program : public osg::Program, public ReadWrite {
|
||||
public:
|
||||
void write(DataOutputStream* out);
|
||||
void read(DataInputStream* in);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -63,7 +63,10 @@ namespace ive {
|
||||
#define IVEVERTEXPROGRAM 0x0000012F
|
||||
#define IVELIGHTMODEL 0x00001121
|
||||
#define IVECLIPPLANE 0x00001122
|
||||
#define IVEFRONTFACE 0x00001123
|
||||
#define IVEFRONTFACE 0x00001123
|
||||
#define IVEPROGRAM 0x00001124
|
||||
#define IVESHADER 0x00001125
|
||||
#define IVEUNIFORM 0x00001126
|
||||
|
||||
// Drawables
|
||||
#define IVEDRAWABLE 0x00001000
|
||||
|
||||
57
src/osgPlugins/ive/Shader.cpp
Normal file
57
src/osgPlugins/ive/Shader.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/**********************************************************************
|
||||
*
|
||||
* 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
|
||||
throw Exception("Shader::write(): Could not cast this osg::Shader to an osg::Object.");
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
throw Exception("Shader::read(): Could not cast this osg::Shader to an osg::Object.");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Exception("Shader::read(): Expected Shader identification.");
|
||||
}
|
||||
}
|
||||
15
src/osgPlugins/ive/Shader.h
Normal file
15
src/osgPlugins/ive/Shader.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef IVE_SHADER
|
||||
#define IVE_SHADER 1
|
||||
|
||||
#include <osg/Shader>
|
||||
#include "ReadWrite.h"
|
||||
|
||||
namespace ive{
|
||||
class Shader : public osg::Shader, public ReadWrite {
|
||||
public:
|
||||
void write(DataOutputStream* out);
|
||||
void read(DataInputStream* in);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -87,6 +87,17 @@ void StateSet::write(DataOutputStream* out){
|
||||
out->writeInt(aitr->second.second);
|
||||
}
|
||||
}
|
||||
|
||||
if ( out->getVersion() >= VERSION_0010 )
|
||||
{
|
||||
// Write stateset attributes, this could for instance be alphafunctions, materials, etc.
|
||||
StateSet::UniformList ul = getUniformList();
|
||||
out->writeInt(ul.size());
|
||||
for(StateSet::UniformList::iterator uitr=ul.begin(); uitr!=ul.end(); ++uitr){
|
||||
out->writeUniform(uitr->second.first.get());
|
||||
out->writeInt(uitr->second.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StateSet::read(DataInputStream* in){
|
||||
@@ -126,7 +137,7 @@ void StateSet::read(DataInputStream* in){
|
||||
|
||||
// Read stateset modes.
|
||||
int size = in->readInt();
|
||||
int i;
|
||||
int i;
|
||||
for(i=0;i<size;i++){
|
||||
int mode = in->readInt();
|
||||
int value = in->readInt();
|
||||
@@ -142,7 +153,7 @@ void StateSet::read(DataInputStream* in){
|
||||
|
||||
// Read texture stateset mode.
|
||||
int nUnits = in->readInt();
|
||||
int unit;
|
||||
int unit;
|
||||
for(unit=0;unit<nUnits;unit++){
|
||||
size = in->readInt();
|
||||
for(i=0;i<size;i++){
|
||||
@@ -161,6 +172,16 @@ void StateSet::read(DataInputStream* in){
|
||||
setTextureAttribute(unit, attribute, (osg::StateAttribute::OverrideValue)in->readInt());
|
||||
}
|
||||
}
|
||||
|
||||
if ( in->getVersion() >= VERSION_0010 )
|
||||
{
|
||||
// Read uniforms
|
||||
size = in->readInt();
|
||||
for(i=0;i<size;i++){
|
||||
osg::Uniform* uniform = in->readUniform();
|
||||
addUniform(uniform, (osg::StateAttribute::OverrideValue)in->readInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw Exception("StateSet::read(): Expected StateSet identification");
|
||||
|
||||
57
src/osgPlugins/ive/Uniform.cpp
Normal file
57
src/osgPlugins/ive/Uniform.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/**********************************************************************
|
||||
*
|
||||
* FILE: Uniform.cpp
|
||||
*
|
||||
* DESCRIPTION: Read/Write osg::Uniform 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 "Uniform.h"
|
||||
#include "Object.h"
|
||||
|
||||
using namespace ive;
|
||||
|
||||
void Uniform::write(DataOutputStream* out){
|
||||
// Write Uniform's identification.
|
||||
out->writeInt(IVEUNIFORM);
|
||||
// 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("Uniform::write(): Could not cast this osg::Uniform to an osg::Object.");
|
||||
|
||||
}
|
||||
|
||||
void Uniform::read(DataInputStream* in)
|
||||
{
|
||||
// Read Uniform's identification.
|
||||
int id = in->peekInt();
|
||||
if(id == IVEUNIFORM)
|
||||
{
|
||||
// Read Uniform'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
|
||||
throw Exception("Uniform::read(): Could not cast this osg::Uniform to an osg::Object.");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Exception("Uniform::read(): Expected Uniform identification.");
|
||||
}
|
||||
}
|
||||
15
src/osgPlugins/ive/Uniform.h
Normal file
15
src/osgPlugins/ive/Uniform.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef IVE_UNIFORM
|
||||
#define IVE_UNIFORM 1
|
||||
|
||||
#include <osg/Uniform>
|
||||
#include "ReadWrite.h"
|
||||
|
||||
namespace ive{
|
||||
class Uniform : public osg::Uniform, public ReadWrite {
|
||||
public:
|
||||
void write(DataOutputStream* out);
|
||||
void read(DataInputStream* in);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user