Problem on OpenGL

andrijapetrovic1

27-06-2010 13:56:20

I wonder how come that nobody else encountered this problem, but here it is:

the _updateShaders method of GrassLoader has the following construct:


String shaderLanguage;
...
if (vertexShader.isNull())
{
...
}
...
if(shaderLanguage.compare("glsl"))
//glsl can use the built in gl_ModelViewProjectionMatrix
params->setNamedAutoConstant("worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);


The problem is that the value of shaderLanguage is set only if vertexShader.isNull().
Therefore, on the OpenGL rendering subsystem shaderLanguage will evaluate to "glsl" only if vertexShader.isNull().

I encountered this problem using Ogitor - when adding new Grass layers. Shader already exists, so vertexShader.isNull() is false. In that case, shaderLanguage is an empty string, params->setNamedAutoConstant("worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); is called, so Ogre raises an exception


14:43:45: OGRE EXCEPTION(2:InvalidParametersException): Parameter called worldViewProj does not exist. in GpuProgramParameters::_findNamedConstantDefinition at /Users/andra/Install/ogre_src_v1-7-1/OgreMain/src/OgreGpuProgramParams.cpp (line 1433)


The problem is easily solved if the value for shaderLanguage is read from the vertex shader if one exists:


String shaderLanguage;
...
if (vertexShader.isNull())
{
...
}else{
shaderLanguage = vertexShader->getLanguage();
}



Cheers,
Andrija