Improvements to the #pragma(tic) shader composition support
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14694 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
parent
77b8962bcc
commit
6bddbdf074
@ -283,6 +283,8 @@ class OSG_EXPORT Program : public osg::StateAttribute
|
|||||||
|
|
||||||
GLuint getHandle() const {return _glProgramHandle;}
|
GLuint getHandle() const {return _glProgramHandle;}
|
||||||
|
|
||||||
|
const osg::Program* getProgram() const { return _program; }
|
||||||
|
|
||||||
void setDefineString(const std::string& defStr) { _defineStr = defStr; }
|
void setDefineString(const std::string& defStr) { _defineStr = defStr; }
|
||||||
const std::string& getDefineString() const { return _defineStr; }
|
const std::string& getDefineString() const { return _defineStr; }
|
||||||
|
|
||||||
|
@ -1914,7 +1914,6 @@ class OSG_EXPORT State : public Referenced
|
|||||||
inline void applyModeMap(ModeMap& modeMap);
|
inline void applyModeMap(ModeMap& modeMap);
|
||||||
inline void applyAttributeMap(AttributeMap& attributeMap);
|
inline void applyAttributeMap(AttributeMap& attributeMap);
|
||||||
inline void applyUniformMap(UniformMap& uniformMap);
|
inline void applyUniformMap(UniformMap& uniformMap);
|
||||||
inline void applyUniformMap(DefineMap& defineMap);
|
|
||||||
|
|
||||||
inline void applyModeListOnTexUnit(unsigned int unit,ModeMap& modeMap,const StateSet::ModeList& modeList);
|
inline void applyModeListOnTexUnit(unsigned int unit,ModeMap& modeMap,const StateSet::ModeList& modeList);
|
||||||
inline void applyAttributeListOnTexUnit(unsigned int unit,AttributeMap& attributeMap,const StateSet::AttributeList& attributeList);
|
inline void applyAttributeListOnTexUnit(unsigned int unit,AttributeMap& attributeMap,const StateSet::AttributeList& attributeList);
|
||||||
|
@ -667,6 +667,7 @@ void Shader::PerContextShader::compileShader(osg::State& state)
|
|||||||
{
|
{
|
||||||
// OSG_NOTICE<<"Shader::PerContextShader::compileShader() : Found #version, lineNum = "<<lineNum<<" ["<<versionLine<<"] new source = ["<<source<<"]"<<std::endl;
|
// OSG_NOTICE<<"Shader::PerContextShader::compileShader() : Found #version, lineNum = "<<lineNum<<" ["<<versionLine<<"] new source = ["<<source<<"]"<<std::endl;
|
||||||
const GLchar* sourceText[3];
|
const GLchar* sourceText[3];
|
||||||
|
//OSG_NOTICE<<"glShaderSource() ["<<versionLine<<"] "<<std::endl<<"["<<_defineStr<<"], ["<<sourceText<<"]"<<std::endl;
|
||||||
sourceText[0] = reinterpret_cast<const GLchar*>(versionLine.c_str());
|
sourceText[0] = reinterpret_cast<const GLchar*>(versionLine.c_str());
|
||||||
sourceText[1] = reinterpret_cast<const GLchar*>(_defineStr.c_str());
|
sourceText[1] = reinterpret_cast<const GLchar*>(_defineStr.c_str());
|
||||||
sourceText[2] = reinterpret_cast<const GLchar*>(source.c_str());
|
sourceText[2] = reinterpret_cast<const GLchar*>(source.c_str());
|
||||||
@ -675,6 +676,7 @@ void Shader::PerContextShader::compileShader(osg::State& state)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const GLchar* sourceText[2];
|
const GLchar* sourceText[2];
|
||||||
|
//OSG_NOTICE<<"glShaderSource() ["<<_defineStr<<"], ["<<sourceText<<"]"<<std::endl;
|
||||||
sourceText[0] = reinterpret_cast<const GLchar*>(_defineStr.c_str());
|
sourceText[0] = reinterpret_cast<const GLchar*>(_defineStr.c_str());
|
||||||
sourceText[1] = reinterpret_cast<const GLchar*>(source.c_str());
|
sourceText[1] = reinterpret_cast<const GLchar*>(source.c_str());
|
||||||
_extensions->glShaderSource( _glShaderHandle, 2, sourceText, NULL );
|
_extensions->glShaderSource( _glShaderHandle, 2, sourceText, NULL );
|
||||||
@ -725,6 +727,7 @@ void Shader::PerContextShader::detachShader(GLuint program) const
|
|||||||
|
|
||||||
void Shader::_parseShaderDefines(const std::string& str, ShaderDefines& defines)
|
void Shader::_parseShaderDefines(const std::string& str, ShaderDefines& defines)
|
||||||
{
|
{
|
||||||
|
OSG_NOTICE<<"Shader::_parseShaderDefines("<<str<<")"<<std::endl;
|
||||||
std::string::size_type start_of_parameter = 0;
|
std::string::size_type start_of_parameter = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -735,13 +738,24 @@ void Shader::_parseShaderDefines(const std::string& str, ShaderDefines& defines)
|
|||||||
// find end of the parameter
|
// find end of the parameter
|
||||||
std::string::size_type end_of_parameter = str.find_first_of(" \t,)", start_of_parameter);
|
std::string::size_type end_of_parameter = str.find_first_of(" \t,)", start_of_parameter);
|
||||||
|
|
||||||
if (end_of_parameter==std::string::npos) end_of_parameter = str.size();
|
if (end_of_parameter!=std::string::npos)
|
||||||
|
{
|
||||||
|
std::string::size_type start_of_open_brackets = str.find_first_of("(", start_of_parameter);
|
||||||
|
if (start_of_open_brackets<end_of_parameter) ++end_of_parameter;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
end_of_parameter = str.size();
|
||||||
|
}
|
||||||
|
|
||||||
std::string parameter = str.substr(start_of_parameter, end_of_parameter-start_of_parameter);
|
if (start_of_parameter<end_of_parameter)
|
||||||
|
{
|
||||||
|
std::string parameter = str.substr(start_of_parameter, end_of_parameter-start_of_parameter);
|
||||||
|
defines.insert(parameter);
|
||||||
|
OSG_NOTICE<<" defines.insert("<<parameter<<")"<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
defines.insert(parameter);
|
start_of_parameter = end_of_parameter+1;
|
||||||
|
|
||||||
start_of_parameter = end_of_parameter;
|
|
||||||
|
|
||||||
} while (start_of_parameter<str.size());
|
} while (start_of_parameter<str.size());
|
||||||
}
|
}
|
||||||
@ -763,7 +777,7 @@ void Shader::_computeShaderDefines()
|
|||||||
std::string::size_type eol = _shaderSource.find_first_of("\n\r", pos);
|
std::string::size_type eol = _shaderSource.find_first_of("\n\r", pos);
|
||||||
if (eol==std::string::npos) eol = _shaderSource.size();
|
if (eol==std::string::npos) eol = _shaderSource.size();
|
||||||
|
|
||||||
// OSG_NOTICE<<"\nFound pragma line ["<<_shaderSource.substr(first_chararcter, eol-first_chararcter)<<"]"<<std::endl;
|
OSG_NOTICE<<"\nFound pragma line ["<<_shaderSource.substr(first_chararcter, eol-first_chararcter)<<"]"<<std::endl;
|
||||||
|
|
||||||
if (first_chararcter<eol)
|
if (first_chararcter<eol)
|
||||||
{
|
{
|
||||||
@ -772,11 +786,10 @@ void Shader::_computeShaderDefines()
|
|||||||
std::string keyword = _shaderSource.substr(first_chararcter, end_of_keyword-first_chararcter);
|
std::string keyword = _shaderSource.substr(first_chararcter, end_of_keyword-first_chararcter);
|
||||||
|
|
||||||
std::string::size_type open_brackets = _shaderSource.find_first_of("(", end_of_keyword);
|
std::string::size_type open_brackets = _shaderSource.find_first_of("(", end_of_keyword);
|
||||||
std::string::size_type close_brackets = _shaderSource.find_first_of(")", open_brackets);
|
|
||||||
|
|
||||||
if ((open_brackets!=std::string::npos) && (close_brackets!=std::string::npos) && (close_brackets<eol))
|
if ((open_brackets!=std::string::npos))
|
||||||
{
|
{
|
||||||
std::string str(_shaderSource, open_brackets+1, close_brackets-open_brackets-1);
|
std::string str(_shaderSource, open_brackets+1, eol-open_brackets-1);
|
||||||
|
|
||||||
// OSG_NOTICE<<" parameter str = ["<<str<<"]"<<std::endl;
|
// OSG_NOTICE<<" parameter str = ["<<str<<"]"<<std::endl;
|
||||||
if (keyword == "import_defines") _parseShaderDefines(str, _shaderDefines);
|
if (keyword == "import_defines") _parseShaderDefines(str, _shaderDefines);
|
||||||
@ -785,7 +798,7 @@ void Shader::_computeShaderDefines()
|
|||||||
//OSG_NOTICE<<" keyword not matched ["<<keyword<<"]"<<std::endl;
|
//OSG_NOTICE<<" keyword not matched ["<<keyword<<"]"<<std::endl;
|
||||||
_parseShaderDefines(str, _shaderDefines);
|
_parseShaderDefines(str, _shaderDefines);
|
||||||
}
|
}
|
||||||
#if 0
|
#if 1
|
||||||
for(ShaderDefines::iterator itr = _shaderDefines.begin();
|
for(ShaderDefines::iterator itr = _shaderDefines.begin();
|
||||||
itr != _shaderDefines.end();
|
itr != _shaderDefines.end();
|
||||||
++itr)
|
++itr)
|
||||||
@ -802,7 +815,7 @@ void Shader::_computeShaderDefines()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
#if 0
|
#if 1
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OSG_NOTICE<<" Found keyword ["<<keyword<<"] but not matched ()\n"<<std::endl;
|
OSG_NOTICE<<" Found keyword ["<<keyword<<"] but not matched ()\n"<<std::endl;
|
||||||
|
@ -517,9 +517,20 @@ void State::apply(const StateSet* dstate)
|
|||||||
const Program::PerContextProgram* previousLastAppliedProgramObject = _lastAppliedProgramObject;
|
const Program::PerContextProgram* previousLastAppliedProgramObject = _lastAppliedProgramObject;
|
||||||
|
|
||||||
applyModeList(_modeMap,dstate->getModeList());
|
applyModeList(_modeMap,dstate->getModeList());
|
||||||
|
#if 1
|
||||||
|
pushDefineList(_defineMap, dstate->getDefineList());
|
||||||
|
#else
|
||||||
applyDefineList(_defineMap, dstate->getDefineList());
|
applyDefineList(_defineMap, dstate->getDefineList());
|
||||||
|
#endif
|
||||||
|
|
||||||
applyAttributeList(_attributeMap,dstate->getAttributeList());
|
applyAttributeList(_attributeMap,dstate->getAttributeList());
|
||||||
|
|
||||||
|
if ((_lastAppliedProgramObject!=0) && (previousLastAppliedProgramObject==_lastAppliedProgramObject) && _defineMap.changed)
|
||||||
|
{
|
||||||
|
// OSG_NOTICE<<"State::apply(StateSet*) Program already applied ("<<(previousLastAppliedProgramObject==_lastAppliedProgramObject)<<") and _defineMap.changed= "<<_defineMap.changed<<std::endl;
|
||||||
|
_lastAppliedProgramObject->getProgram()->apply(*this);
|
||||||
|
}
|
||||||
|
|
||||||
if (_shaderCompositionEnabled)
|
if (_shaderCompositionEnabled)
|
||||||
{
|
{
|
||||||
if (previousLastAppliedProgramObject == _lastAppliedProgramObject || _lastAppliedProgramObject==0)
|
if (previousLastAppliedProgramObject == _lastAppliedProgramObject || _lastAppliedProgramObject==0)
|
||||||
@ -545,6 +556,10 @@ void State::apply(const StateSet* dstate)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
popDefineList(_defineMap, dstate->getDefineList());
|
||||||
|
#endif
|
||||||
|
|
||||||
// pop the stateset from the stack
|
// pop the stateset from the stack
|
||||||
_stateStateStack.pop_back();
|
_stateStateStack.pop_back();
|
||||||
}
|
}
|
||||||
@ -576,10 +591,19 @@ void State::apply()
|
|||||||
// appropriate.
|
// appropriate.
|
||||||
applyModeMap(_modeMap);
|
applyModeMap(_modeMap);
|
||||||
|
|
||||||
|
const Program::PerContextProgram* previousLastAppliedProgramObject = _lastAppliedProgramObject;
|
||||||
|
|
||||||
// go through all active StateAttribute's, applying where appropriate.
|
// go through all active StateAttribute's, applying where appropriate.
|
||||||
applyAttributeMap(_attributeMap);
|
applyAttributeMap(_attributeMap);
|
||||||
|
|
||||||
|
|
||||||
|
if ((_lastAppliedProgramObject!=0) && (previousLastAppliedProgramObject==_lastAppliedProgramObject) && _defineMap.changed)
|
||||||
|
{
|
||||||
|
//OSG_NOTICE<<"State::apply() Program already applied ("<<(previousLastAppliedProgramObject==_lastAppliedProgramObject)<<") and _defineMap.changed= "<<_defineMap.changed<<std::endl;
|
||||||
|
if (_lastAppliedProgramObject) _lastAppliedProgramObject->getProgram()->apply(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (_shaderCompositionEnabled)
|
if (_shaderCompositionEnabled)
|
||||||
{
|
{
|
||||||
applyShaderComposition();
|
applyShaderComposition();
|
||||||
|
Loading…
Reference in New Issue
Block a user