From d31cd3dce660b400a9957b4eb064128b41e12fa5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 8 Apr 2005 13:10:44 +0000 Subject: [PATCH] From Mike Weiblen, updates to GL Shadler Language support --- src/osg/Shader.cpp | 17 +++++++++++++---- src/osg/Uniform.cpp | 13 +++++++------ src/osgPlugins/osg/Shader.cpp | 2 +- src/osgPlugins/osg/Uniform.cpp | 6 +++--- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/osg/Shader.cpp b/src/osg/Shader.cpp index 03deddce2..5375c7963 100644 --- a/src/osg/Shader.cpp +++ b/src/osg/Shader.cpp @@ -13,7 +13,7 @@ */ /* file: src/osg/Shader.cpp - * author: Mike Weiblen 2005-04-06 + * author: Mike Weiblen 2005-04-07 */ #include @@ -197,12 +197,19 @@ const char* Shader::getTypename() const void Shader::compileShader( unsigned int contextID ) const { - getPCS( contextID )->compileShader(); + PerContextShader* pcs = getPCS( contextID ); + if( pcs ) pcs->compileShader(); } Shader::PerContextShader* Shader::getPCS(unsigned int contextID) const { + if( getType() == UNDEFINED ) + { + osg::notify(osg::WARN) << "Shader type is UNDEFINED" << std::endl; + return 0; + } + if( ! _pcsList[contextID].valid() ) { _pcsList[contextID] = new PerContextShader( this, contextID ); @@ -213,13 +220,15 @@ Shader::PerContextShader* Shader::getPCS(unsigned int contextID) const void Shader::attachShader(unsigned int contextID, GLuint program) const { - getPCS( contextID )->attachShader( program ); + PerContextShader* pcs = getPCS( contextID ); + if( pcs ) pcs->attachShader( program ); } void Shader::getGlShaderInfoLog(unsigned int contextID, std::string& log) const { - getPCS( contextID )->getInfoLog( log ); + PerContextShader* pcs = getPCS( contextID ); + if( pcs ) pcs->getInfoLog( log ); } diff --git a/src/osg/Uniform.cpp b/src/osg/Uniform.cpp index 5a0a81922..54c5878c2 100644 --- a/src/osg/Uniform.cpp +++ b/src/osg/Uniform.cpp @@ -11,7 +11,7 @@ */ /* file: src/osg/Uniform.cpp - * author: Mike Weiblen 2005-04-06 + * author: Mike Weiblen 2005-04-07 */ // NOTICE: This code is CLOSED during construction and/or renovation! @@ -64,7 +64,7 @@ Uniform::Uniform( const char* name, Type type ) : case SAMPLER_1D_SHADOW: set( 0 ); break; case SAMPLER_2D_SHADOW: set( 0 ); break; default: - osg::notify(osg::WARN) << "unhandled Uniform type" << std::endl; + osg::notify(osg::WARN) << "UNDEFINED Uniform type" << std::endl; break; } } @@ -79,7 +79,7 @@ bool Uniform::setType( Type t ) { if( _type != UNDEFINED ) { - osg::notify(osg::WARN) << "cannot change type of Uniform" << std::endl; + osg::notify(osg::WARN) << "cannot change Uniform type" << std::endl; return false; } _type = t; @@ -90,7 +90,7 @@ bool Uniform::setName( const std::string& name ) { if( _name != "" ) { - osg::notify(osg::WARN) << "cannot change name of Uniform" << std::endl; + osg::notify(osg::WARN) << "cannot change Uniform name" << std::endl; return false; } _name = name; @@ -191,7 +191,7 @@ int Uniform::compareData(const Uniform& rhs) const return 0; default: - osg::notify(osg::FATAL) << "how got here?" << std::endl; + osg::notify(osg::WARN) << "cannot compare UNDEFINED Uniform type" << std::endl; return 0; } } @@ -257,13 +257,14 @@ void Uniform::copyData(const Uniform& rhs) break; default: - osg::notify(osg::FATAL) << "how got here?" << std::endl; + osg::notify(osg::WARN) << "cannot copy UNDEFINED Uniform type" << std::endl; break; } } bool Uniform::isCompatibleType( Type t ) const { + if( (t==UNDEFINED) || (getType()==UNDEFINED) ) return false; if( t == getType() ) return true; if( repType(t) == repType(getType()) ) return true; diff --git a/src/osgPlugins/osg/Shader.cpp b/src/osgPlugins/osg/Shader.cpp index 1baf1c50f..23a657c61 100644 --- a/src/osgPlugins/osg/Shader.cpp +++ b/src/osgPlugins/osg/Shader.cpp @@ -31,7 +31,7 @@ bool Shader_readLocalData(Object& obj, Input& fr) Shader& shader = static_cast(obj); - if (fr.matchSequence("type %s")) + if (fr.matchSequence("type %w")) { shader.setType( Shader::getTypeId(fr[1].getStr()) ); fr+=2; diff --git a/src/osgPlugins/osg/Uniform.cpp b/src/osgPlugins/osg/Uniform.cpp index 09dc2e3db..19e89e12d 100644 --- a/src/osgPlugins/osg/Uniform.cpp +++ b/src/osgPlugins/osg/Uniform.cpp @@ -29,7 +29,7 @@ bool Uniform_readLocalData(Object& obj, Input& fr) Uniform& uniform = static_cast(obj); - if (fr.matchSequence("type %s")) + if (fr.matchSequence("type %w")) { uniform.setType( Uniform::getTypeId(fr[1].getStr()) ); fr+=2; @@ -53,9 +53,9 @@ bool Uniform_writeLocalData(const Object& obj,Output& fw) { const Uniform& uniform = static_cast(obj); - fw.indent() << "type " << uniform.getTypename( uniform.getType() ) << std::endl; + fw.indent() << "type " << Uniform::getTypename( uniform.getType() ) << std::endl; - fw.indent() << "name "<< uniform.getName() << std::endl; + fw.indent() << "name "<< fw.wrapString(uniform.getName()) << std::endl; // TODO write uniform value based on type