Completed GLSL support in .ive

This commit is contained in:
Robert Osfield
2005-05-11 13:37:38 +00:00
parent 8d31e75364
commit aa6ea8c047
10 changed files with 268 additions and 36 deletions

View File

@@ -190,7 +190,8 @@ class OSG_EXPORT Uniform : public Object
Uniform( const char* name, const osg::Vec4& v4 );
//TODO Uniform( const char* name, const osg::Matrix2& m2 );
//TODO Uniform( const char* name, const osg::Matrix3& m3 );
Uniform( const char* name, const osg::Matrix& m4 );
Uniform( const char* name, const osg::Matrixf& m4 );
Uniform( const char* name, const osg::Matrixd& m4 );
Uniform( const char* name, int i0, int i1 );
Uniform( const char* name, int i0, int i1, int i2 );
Uniform( const char* name, int i0, int i1, int i2, int i3 );
@@ -243,7 +244,8 @@ class OSG_EXPORT Uniform : public Object
bool set( const osg::Vec4& v4 );
//TODO bool set( const osg::Matrix2& m2 );
//TODO bool set( const osg::Matrix3& m3 );
bool set( const osg::Matrix& m4 );
bool set( const osg::Matrixf& m4 );
bool set( const osg::Matrixd& m4 );
bool set( int i0, int i1 );
bool set( int i0, int i1, int i2 );
bool set( int i0, int i1, int i2, int i3 );
@@ -260,7 +262,8 @@ class OSG_EXPORT Uniform : public Object
bool get( osg::Vec4& v4 ) const;
//TODO bool get( osg::Matrix2& m2 ) const;
//TODO bool get( osg::Matrix3& m3 ) const;
bool get( osg::Matrix& m4 ) const;
bool get( osg::Matrixf& m4 ) const;
bool get( osg::Matrixd& m4 ) const;
bool get( int& i0, int& i1 ) const;
bool get( int& i0, int& i1, int& i2 ) const;
bool get( int& i0, int& i1, int& i2, int& i3 ) const;
@@ -324,9 +327,11 @@ class OSG_EXPORT Uniform : public Object
ParentList _parents;
friend class osg::StateSet;
std::string _name;
Type _type;
union {
std::string _name;
union
{
GLfloat f1; // float
GLfloat f2[2]; // vec2
GLfloat f3[3]; // vec3

View File

@@ -28,7 +28,7 @@ using namespace osg;
///////////////////////////////////////////////////////////////////////////
Uniform::Uniform() :
_name(""), _type(UNDEFINED),_modifiedCount(0)
_type(UNDEFINED), _name(""), _modifiedCount(0)
{
setDataVariance(STATIC);
}
@@ -55,7 +55,7 @@ Uniform::Uniform( Type type, const std::string& name ) :
case BOOL_VEC4: set( false, false, false, false ); break;
// TODO case FLOAT_MAT2:
// TODO case FLOAT_MAT3:
case FLOAT_MAT4: set( osg::Matrix() ); break;
case FLOAT_MAT4: set( osg::Matrixf() ); break;
case SAMPLER_1D: set( 0 ); break;
case SAMPLER_2D: set( 0 ); break;
case SAMPLER_3D: set( 0 ); break;
@@ -69,7 +69,7 @@ Uniform::Uniform( Type type, const std::string& name ) :
}
Uniform::Uniform( const Uniform& rhs, const CopyOp& copyop ) :
Object(rhs,copyop), _name(rhs._name), _type(rhs._type)
Object(rhs,copyop), _type(rhs._type), _name(rhs._name)
{
copyData( rhs );
}
@@ -381,25 +381,25 @@ Uniform::Type Uniform::getGlApiType( Type t )
// value constructors
Uniform::Uniform( const char* name, float f ) :
_name(name), _type(FLOAT)
_type(FLOAT), _name(name)
{
set( f );
}
Uniform::Uniform( const char* name, const osg::Vec2& v2 ) :
_name(name), _type(FLOAT_VEC2)
_type(FLOAT_VEC2), _name(name)
{
set( v2 );
}
Uniform::Uniform( const char* name, const osg::Vec3& v3 ) :
_name(name), _type(FLOAT_VEC3)
_type(FLOAT_VEC3), _name(name)
{
set( v3 );
}
Uniform::Uniform( const char* name, const osg::Vec4& v4 ) :
_name(name), _type(FLOAT_VEC4)
_type(FLOAT_VEC4), _name(name)
{
set( v4 );
}
@@ -408,56 +408,56 @@ Uniform::Uniform( const char* name, const osg::Vec4& v4 ) :
//Uniform::Uniform( const char* name, const osg::Matrix3& m3 )
Uniform::Uniform( const char* name, const osg::Matrix& m4 ) :
_name(name), _type(FLOAT_MAT4)
Uniform::Uniform( const char* name, const osg::Matrixf& m4 ) :
_type(FLOAT_MAT4), _name(name)
{
set( m4 );
}
Uniform::Uniform( const char* name, int i ) :
_name(name), _type(INT)
_type(INT), _name(name)
{
set( i );
}
Uniform::Uniform( const char* name, int i0, int i1 ) :
_name(name), _type(INT_VEC2)
_type(INT_VEC2), _name(name)
{
set( i0, i1 );
}
Uniform::Uniform( const char* name, int i0, int i1, int i2 ) :
_name(name), _type(INT_VEC3)
_type(INT_VEC3), _name(name)
{
set( i0, i1, i2 );
}
Uniform::Uniform( const char* name, int i0, int i1, int i2, int i3 ) :
_name(name), _type(INT_VEC4)
_type(INT_VEC4), _name(name)
{
set( i0, i1, i2, i3 );
}
Uniform::Uniform( const char* name, bool b ) :
_name(name), _type(BOOL)
_type(BOOL), _name(name)
{
set( b );
}
Uniform::Uniform( const char* name, bool b0, bool b1 ) :
_name(name), _type(BOOL_VEC2)
_type(BOOL_VEC2), _name(name)
{
set( b0, b1 );
}
Uniform::Uniform( const char* name, bool b0, bool b1, bool b2 ) :
_name(name), _type(BOOL_VEC3)
_type(BOOL_VEC3), _name(name)
{
set( b0, b1, b2 );
}
Uniform::Uniform( const char* name, bool b0, bool b1, bool b2, bool b3 ) :
_name(name), _type(BOOL_VEC4)
_type(BOOL_VEC4), _name(name)
{
set( b0, b1, b2, b3 );
}
@@ -507,7 +507,7 @@ bool Uniform::set( const osg::Vec4& v4 )
//TODO bool Uniform::set( const osg::Matrix3& m3 )
bool Uniform::set( const osg::Matrix& m4 )
bool Uniform::set( const osg::Matrixf& m4 )
{
if( ! isCompatibleType(FLOAT_MAT4) ) return false;
int n = 0;
@@ -522,6 +522,21 @@ bool Uniform::set( const osg::Matrix& m4 )
return true;
}
bool Uniform::set( const osg::Matrixd& m4 )
{
if( ! isCompatibleType(FLOAT_MAT4) ) return false;
int n = 0;
for(int row=0; row<4; ++row)
{
for(int col=0; col<4; ++col)
{
_data.f16[n++] = static_cast<float>(m4(row,col));
}
}
dirty();
return true;
}
bool Uniform::set( int i )
{
if( ! isCompatibleType(INT) ) return false;
@@ -639,7 +654,21 @@ bool Uniform::get( osg::Vec4& v4 ) const
//TODO bool Uniform::get( osg::Matrix3& m3 ) const
bool Uniform::get( osg::Matrix& m4 ) const
bool Uniform::get( osg::Matrixf& m4 ) const
{
if( ! isCompatibleType(FLOAT_MAT4) ) return false;
int n = 0;
for(int row=0; row<4; ++row)
{
for(int col=0; col<4; ++col)
{
m4(row,col) = _data.f16[n++];
}
}
return true;
}
bool Uniform::get( osg::Matrixd& m4 ) const
{
if( ! isCompatibleType(FLOAT_MAT4) ) return false;
int n = 0;

View File

@@ -29,7 +29,7 @@ void DOFTransform::write(DataOutputStream* out){
throw Exception("DOFTransform::write(): Could not cast this osg::DOFTransform to an osg::Transform.");
// Write DOFTransform's properties.
out->writeMatrix(getPutMatrix());
out->writeMatrixd(getPutMatrix());
out->writeVec3(getMinHPR());
out->writeVec3(getMaxHPR());
@@ -64,8 +64,8 @@ void DOFTransform::read(DataInputStream* in){
else
throw Exception("DOFTransform::read(): Could not cast this osg::DOFTransform to an osg::Transform.");
// Read DOFTransform's properties
setPutMatrix(in->readMatrix());
setInversePutMatrix( osg::Matrix::inverse( getPutMatrix() ) );
setPutMatrix(in->readMatrixd());
setInversePutMatrix( osg::Matrixd::inverse( getPutMatrix() ) );
setMinHPR(in->readVec3());
setMaxHPR(in->readVec3());

View File

@@ -612,9 +612,29 @@ osg::Vec4Array* DataInputStream::readVec4Array(){
return a;
}
osg::Matrix DataInputStream::readMatrix()
osg::Matrixf DataInputStream::readMatrixf()
{
osg::Matrix mat;
osg::Matrixf mat;
for(int r=0;r<4;r++)
{
for(int c=0;c<4;c++)
{
mat(r,c) = readFloat();
}
}
if (_istream->rdstate() & _istream->failbit)
throw Exception("DataInputStream::readMatrix(): Failed to read Matrix array.");
if (_verboseOutput) std::cout<<"read/writeMatrix() ["<<mat<<"]"<<std::endl;
return mat;
}
osg::Matrixd DataInputStream::readMatrixd()
{
osg::Matrixd mat;
for(int r=0;r<4;r++)
{
for(int c=0;c<4;c++)

View File

@@ -64,7 +64,8 @@ public:
osg::Plane readPlane();
osg::UByte4 readUByte4();
osg::Quat readQuat();
osg::Matrix readMatrix();
osg::Matrixf readMatrixf();
osg::Matrixd readMatrixd();
osg::Geometry::AttributeBinding readBinding();
osg::Array* readArray();
osg::IntArray* readIntArray();

View File

@@ -429,7 +429,20 @@ void DataOutputStream::writeVec4Array(const osg::Vec4Array* a)
if (_verboseOutput) std::cout<<"read/writeVec4Array() ["<<size<<"]"<<std::endl;
}
void DataOutputStream::writeMatrix(const osg::Matrix& mat)
void DataOutputStream::writeMatrixf(const osg::Matrixf& mat)
{
for(int r=0;r<4;r++)
{
for(int c=0;c<4;c++)
{
writeFloat(mat(r,c));
}
}
if (_verboseOutput) std::cout<<"read/writeMatrix() ["<<mat<<"]"<<std::endl;
}
void DataOutputStream::writeMatrixd(const osg::Matrixd& mat)
{
for(int r=0;r<4;r++)
{

View File

@@ -68,7 +68,8 @@ public:
void writeVec2Array(const osg::Vec2Array* a);
void writeVec3Array(const osg::Vec3Array* a);
void writeVec4Array(const osg::Vec4Array* a);
void writeMatrix(const osg::Matrix& mat);
void writeMatrixf(const osg::Matrixf& mat);
void writeMatrixd(const osg::Matrixd& mat);
void writeStateSet(const osg::StateSet* stateset);
void writeStateAttribute(const osg::StateAttribute* sa);

View File

@@ -32,7 +32,7 @@ void MatrixTransform::write(DataOutputStream* out){
// Write MatrixTransform's properties.
out->writeMatrix(getMatrix());
out->writeMatrixf(getMatrix());
}
void MatrixTransform::read(DataInputStream* in){
@@ -50,7 +50,7 @@ void MatrixTransform::read(DataInputStream* in){
throw Exception("MatrixTransform::read(): Could not cast this osg::MatrixTransform to an osg::Group.");
// Read matrix
setMatrix(in->readMatrix());
setMatrix(in->readMatrixd());
}
else{
throw Exception("MatrixTransform::read(): Expected MatrixTransform identification");

View File

@@ -31,7 +31,7 @@ void TexMat::write(DataOutputStream* out){
// Write TexMat's properties.
// Write mode
out->writeMatrix(getMatrix());
out->writeMatrixf(getMatrix());
}
void TexMat::read(DataInputStream* in){
@@ -50,7 +50,7 @@ void TexMat::read(DataInputStream* in){
// Read TexMat's properties
// Read matrix
setMatrix(in->readMatrix());
setMatrix(in->readMatrixf());
}
else{

View File

@@ -15,6 +15,7 @@
#include "Exception.h"
#include "Uniform.h"
#include "Object.h"
#include <osg/Notify>
using namespace ive;
@@ -32,6 +33,94 @@ void Uniform::write(DataOutputStream* out){
out->writeInt(getType());
out->writeString(getName());
switch( Uniform::getGlApiType(getType()) )
{
case(osg::Uniform::FLOAT):
{
float value;
get(value);
out->writeFloat(value);
break;
}
case(osg::Uniform::FLOAT_VEC2):
{
osg::Vec2 value;
get(value);
out->writeVec2(value);
break;
}
case(osg::Uniform::FLOAT_VEC3):
{
osg::Vec3 value;
get(value);
out->writeVec3(value);
break;
}
case(osg::Uniform::FLOAT_VEC4):
{
osg::Vec4 value;
get(value);
out->writeVec4(value);
break;
}
case(osg::Uniform::INT):
{
int i0;
get(i0);
out->writeInt(i0);
break;
}
case(osg::Uniform::INT_VEC2):
{
int i0, i1;
get(i0, i1);
out->writeInt(i0);
out->writeInt(i1);
break;
}
case(osg::Uniform::INT_VEC3):
{
int i0, i1, i2;
get(i0, i1, i2);
out->writeInt(i0);
out->writeInt(i1);
out->writeInt(i2);
break;
}
case(osg::Uniform::INT_VEC4):
{
int i0, i1, i2, i3;
get(i0, i1, i2, i3);
out->writeInt(i0);
out->writeInt(i1);
out->writeInt(i2);
out->writeInt(i3);
break;
}
case(osg::Uniform::FLOAT_MAT2):
{
osg::notify(osg::WARN)<<"Warning : type mat2 not supported for reading."<<std::endl;
break;
}
case(osg::Uniform::FLOAT_MAT3):
{
osg::notify(osg::WARN)<<"Warning : type mat3 not supported for reading."<<std::endl;
break;
}
case(osg::Uniform::FLOAT_MAT4):
{
osg::Matrixf matrix;
get(matrix);
out->writeMatrixf(matrix);
break;
}
default:
{
osg::notify(osg::WARN)<<"Warning : uniform "<<getType()<<"type not supported for reading."<<std::endl;
break;
}
}
}
void Uniform::read(DataInputStream* in)
@@ -59,4 +148,78 @@ void Uniform::read(DataInputStream* in)
setType(static_cast<Type>(in->readInt()));
setName(in->readString());
switch( Uniform::getGlApiType(getType()) )
{
case(osg::Uniform::FLOAT):
{
set(in->readFloat());
break;
}
case(osg::Uniform::FLOAT_VEC2):
{
set(in->readVec2());
break;
}
case(osg::Uniform::FLOAT_VEC3):
{
set(in->readVec3());
break;
}
case(osg::Uniform::FLOAT_VEC4):
{
set(in->readVec4());
break;
}
case(osg::Uniform::INT):
{
set(in->readInt());
break;
}
case(osg::Uniform::INT_VEC2):
{
int i0 = in->readInt();
int i1 = in->readInt();
set(i0,i1);
break;
}
case(osg::Uniform::INT_VEC3):
{
int i0 = in->readInt();
int i1 = in->readInt();
int i2 = in->readInt();
set(i0,i1,i2);
break;
}
case(osg::Uniform::INT_VEC4):
{
int i0 = in->readInt();
int i1 = in->readInt();
int i2 = in->readInt();
int i3 = in->readInt();
set(i0,i1,i2,i3);
break;
}
case(osg::Uniform::FLOAT_MAT2):
{
osg::notify(osg::WARN)<<"Warning : type mat2 not supported for reading."<<std::endl;
break;
}
case(osg::Uniform::FLOAT_MAT3):
{
osg::notify(osg::WARN)<<"Warning : type mat3 not supported for reading."<<std::endl;
break;
}
case(osg::Uniform::FLOAT_MAT4):
{
set( in->readMatrixf() );
break;
}
default:
{
osg::notify(osg::WARN)<<"Warning : uniform "<<getType()<<"type not supported for reading."<<std::endl;
break;
}
}
}