From Mike Weiblen, "adds sourcefiles for beginnings of .osg fileformat i/o support

> - enhancemens to core GLSL classes to support file i/o"
This commit is contained in:
Robert Osfield
2005-04-07 20:23:58 +00:00
parent c8a3198129
commit 84e8338be1
11 changed files with 373 additions and 34 deletions

View File

@@ -13,7 +13,7 @@
*/
/* file: src/osg/Program.cpp
* author: Mike Weiblen 2005-03-30
* author: Mike Weiblen 2005-04-06
*/
#include <fstream>
@@ -2000,6 +2000,8 @@ void Program::releaseGLObjects(osg::State* state) const
bool Program::addShader( Shader* shader )
{
if( !shader ) return false;
// Shader can only be added once to a Program
for( unsigned int i=0; i < _shaderList.size(); ++i )
{
@@ -2015,6 +2017,8 @@ bool Program::addShader( Shader* shader )
bool Program::removeShader( Shader* shader )
{
if( !shader ) return false;
// Shader must exist to be removed.
for( unsigned int i=0; i < _shaderList.size(); ++i )
{

View File

@@ -13,7 +13,7 @@
*/
/* file: src/osg/Shader.cpp
* author: Mike Weiblen 2005-03-30
* author: Mike Weiblen 2005-04-06
*/
#include <fstream>
@@ -99,11 +99,8 @@ Shader::Shader(Type type, const char* sourceText) :
}
Shader::Shader() :
_type(VERTEX)
_type(UNDEFINED)
{
// TODO this default constructor is inappropriate for the Shader class.
// It exists for now because it is required by META_OBject
osg::notify(osg::FATAL) << "how got here?" << std::endl;
}
Shader::Shader(const Shader& rhs, const osg::CopyOp& copyop):
@@ -118,6 +115,17 @@ Shader::~Shader()
{
}
bool Shader::setType( Type t )
{
if( _type != UNDEFINED )
{
osg::notify(osg::WARN) << "cannot change type of Shader" << std::endl;
return false;
}
_type = t;
return true;
}
int Shader::compare(const Shader& rhs) const
{
@@ -172,13 +180,21 @@ const char* Shader::getTypename() const
{
switch( getType() )
{
case VERTEX: return "Vertex";
case FRAGMENT: return "Fragment";
case VERTEX: return "VERTEX";
case FRAGMENT: return "FRAGMENT";
default: return "UNDEFINED";
}
}
/*static*/ Shader::Type Shader::getTypeId( const std::string& tname )
{
if( tname == "VERTEX" ) return VERTEX;
if( tname == "FRAGMENT" ) return FRAGMENT;
return UNDEFINED;
}
void Shader::compileShader( unsigned int contextID ) const
{
getPCS( contextID )->compileShader();

View File

@@ -11,7 +11,7 @@
*/
/* file: src/osg/Uniform.cpp
* author: Mike Weiblen 2005-03-30
* author: Mike Weiblen 2005-04-06
*/
// NOTICE: This code is CLOSED during construction and/or renovation!
@@ -34,10 +34,6 @@ using namespace osg;
Uniform::Uniform() :
_name(""), _type(UNDEFINED)
{
// do not use this constructor in application code.
// it exists only because META_Object requires a trivial
// default constructor, but that is concept is meaningless for Uniform.
osg::notify(osg::FATAL) << "how got here?" << std::endl;
}
@@ -79,6 +75,29 @@ Uniform::Uniform( const Uniform& rhs, const CopyOp& copyop ) :
copyData( rhs );
}
bool Uniform::setType( Type t )
{
if( _type != UNDEFINED )
{
osg::notify(osg::WARN) << "cannot change type of Uniform" << std::endl;
return false;
}
_type = t;
return true;
}
bool Uniform::setName( const std::string& name )
{
if( _name != "" )
{
osg::notify(osg::WARN) << "cannot change name of Uniform" << std::endl;
return false;
}
_name = name;
return true;
}
///////////////////////////////////////////////////////////////////////////
int Uniform::compare(const Uniform& rhs) const
@@ -286,6 +305,32 @@ const char* Uniform::getTypename( Type t )
}
}
Uniform::Type Uniform::getTypeId( const std::string& tname )
{
if( tname == "float" ) return FLOAT;
if( tname == "vec2" ) return FLOAT_VEC2;
if( tname == "vec3" ) return FLOAT_VEC3;
if( tname == "vec4" ) return FLOAT_VEC4;
if( tname == "int" ) return INT;
if( tname == "ivec2" ) return INT_VEC2;
if( tname == "ivec3" ) return INT_VEC3;
if( tname == "ivec4" ) return INT_VEC4;
if( tname == "bool" ) return BOOL;
if( tname == "bvec2" ) return BOOL_VEC2;
if( tname == "bvec3" ) return BOOL_VEC3;
if( tname == "bvec4" ) return BOOL_VEC4;
if( tname == "mat2" ) return FLOAT_MAT2;
if( tname == "mat3" ) return FLOAT_MAT3;
if( tname == "mat4" ) return FLOAT_MAT4;
if( tname == "sampler1D" ) return SAMPLER_1D;
if( tname == "sampler2D" ) return SAMPLER_2D;
if( tname == "sampler3D" ) return SAMPLER_3D;
if( tname == "samplerCube" ) return SAMPLER_CUBE;
if( tname == "sampler1DShadow" ) return SAMPLER_1D_SHADOW;
if( tname == "sampler2DShadow" ) return SAMPLER_2D_SHADOW;
return UNDEFINED;
}
Uniform::Type Uniform::repType( Type t )
{
switch( t )