osg学习(五十五)osg_ModelViewMatrix osg_ModelViewProjectionMatrix osg_ProjectionMatrix osg_NormalMatrix(代码
Posted hankern
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了osg学习(五十五)osg_ModelViewMatrix osg_ModelViewProjectionMatrix osg_ProjectionMatrix osg_NormalMatrix(代码相关的知识,希望对你有一定的参考价值。
分别替换glsl中的gl_ModelViewMatrix gl_ModelViewProjectionMatrix gl_ProjectionMatrix gl_NormalMatrix,如果没有这些则插入。
为什么要如此替换?
这些gl_*变量在早期的版本中有(330中已经没有了),如果glsl有这些变量可能会出现高版本无法使用的问题,osg同一采用新的变量好处在于,避免不同版本的不兼容性问题。在低版本可以用,在高版本也可以用。不足的地方时,需要在程序中随时更新osg_*变量。
osg/State.cpp
bool State::convertVertexShaderSourceToOsgBuiltIns(std::string& source) const
{
if (_useModelViewAndProjectionUniforms)
{
// replace ftransform as it only works with built-ins
State_Utils::replace(source, "ftransform()", "gl_ModelViewProjectionMatrix * gl_Vertex");
// replace built in uniform
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_ModelViewMatrix", "osg_ModelViewMatrix", "uniform ", "mat4 ");
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_ModelViewProjectionMatrix", "osg_ModelViewProjectionMatrix", "uniform ", "mat4 ");
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_ProjectionMatrix", "osg_ProjectionMatrix", "uniform ", "mat4 ");
State_Utils::replaceAndInsertDeclaration(source, declPos, "gl_NormalMatrix", "osg_NormalMatrix", "uniform ", "mat3 ");
}
if (_useVertexAttributeAliasing)
{
State_Utils::replaceAndInsertDeclaration(source, declPos, _vertexAlias._glName, _vertexAlias._osgName, attributeQualifier, _vertexAlias._declaration);
State_Utils::replaceAndInsertDeclaration(source, declPos, _normalAlias._glName, _normalAlias._osgName, attributeQualifier, _normalAlias._declaration);
State_Utils::replaceAndInsertDeclaration(source, declPos, _colorAlias._glName, _colorAlias._osgName, attributeQualifier, _colorAlias._declaration);
State_Utils::replaceAndInsertDeclaration(source, declPos, _secondaryColorAlias._glName, _secondaryColorAlias._osgName, attributeQualifier, _secondaryColorAlias._declaration);
State_Utils::replaceAndInsertDeclaration(source, declPos, _fogCoordAlias._glName, _fogCoordAlias._osgName, attributeQualifier, _fogCoordAlias._declaration);
for (size_t i=0; i<_texCoordAliasList.size(); i++)
{
const VertexAttribAlias& texCoordAlias = _texCoordAliasList[i];
State_Utils::replaceAndInsertDeclaration(source, declPos, texCoordAlias._glName, texCoordAlias._osgName, attributeQualifier, texCoordAlias._declaration);
}
}
}
更新osg_*变量
以上是关于osg学习(五十五)osg_ModelViewMatrix osg_ModelViewProjectionMatrix osg_ProjectionMatrix osg_NormalMatrix(代码的主要内容,如果未能解决你的问题,请参考以下文章
osg学习(五十七)double declaration in gles osg_ModelViewProjectionMatrix
osg学习(五十六)osg::State的AttributeMap作用