本文整理汇总了C++中osg::State::convertVertexShaderSourceToOsgBuiltIns方法的典型用法代码示例。如果您正苦于以下问题:C++ State::convertVertexShaderSourceToOsgBuiltIns方法的具体用法?C++ State::convertVertexShaderSourceToOsgBuiltIns怎么用?C++ State::convertVertexShaderSourceToOsgBuiltIns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::State
的用法示例。
在下文中一共展示了State::convertVertexShaderSourceToOsgBuiltIns方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: defined
void Shader::PerContextShader::compileShader(osg::State& state)
{
if( ! _needsCompile ) return;
_needsCompile = false;
#if defined(OSG_GLES2_AVAILABLE)
if (_shader->getShaderBinary())
{
GLint numFormats = 0;
glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &numFormats);
if (numFormats>0)
{
std::vector<GLint> formats(numFormats);
glGetIntegerv(GL_SHADER_BINARY_FORMATS, &formats[0]);
for(GLint i=0; i<numFormats; ++i)
{
OSG_NOTICE<<" format="<<formats[i]<<std::endl;
GLenum shaderBinaryFormat = formats[i];
glShaderBinary(1, &_glShaderHandle, shaderBinaryFormat, _shader->getShaderBinary()->getData(), _shader->getShaderBinary()->getSize());
if (glGetError() == GL_NO_ERROR)
{
_isCompiled = true;
return;
}
}
if (_shader->getShaderSource().empty())
{
OSG_WARN<<"Warning: No suitable shader of supported format by GLES driver found in shader binary, unable to compile shader."<<std::endl;
_isCompiled = false;
return;
}
else
{
OSG_NOTICE<<"osg::Shader::compileShader(): No suitable shader of supported format by GLES driver found in shader binary, falling back to shader source."<<std::endl;
}
}
else
{
if (_shader->getShaderSource().empty())
{
OSG_WARN<<"Warning: No shader binary formats supported by GLES driver, unable to compile shader."<<std::endl;
_isCompiled = false;
return;
}
else
{
OSG_NOTICE<<"osg::Shader::compileShader(): No shader binary formats supported by GLES driver, falling back to shader source."<<std::endl;
}
}
}
#endif
std::string source = _shader->getShaderSource();
if (_shader->getType()==osg::Shader::VERTEX && (state.getUseVertexAttributeAliasing() || state.getUseModelViewAndProjectionUniforms()))
{
state.convertVertexShaderSourceToOsgBuiltIns(source);
}
if (osg::getNotifyLevel()>=osg::INFO)
{
std::string sourceWithLineNumbers = insertLineNumbers(source);
OSG_INFO << "\nCompiling " << _shader->getTypename()
<< " source:\n" << sourceWithLineNumbers << std::endl;
}
GLint compiled = GL_FALSE;
const GLchar* sourceText = reinterpret_cast<const GLchar*>(source.c_str());
_extensions->glShaderSource( _glShaderHandle, 1, &sourceText, NULL );
_extensions->glCompileShader( _glShaderHandle );
_extensions->glGetShaderiv( _glShaderHandle, GL_COMPILE_STATUS, &compiled );
_isCompiled = (compiled == GL_TRUE);
if( ! _isCompiled )
{
OSG_WARN << _shader->getTypename() << " glCompileShader \""
<< _shader->getName() << "\" FAILED" << std::endl;
std::string infoLog;
if( getInfoLog(infoLog) )
{
OSG_WARN << _shader->getTypename() << " Shader \""
<< _shader->getName() << "\" infolog:\n" << infoLog << std::endl;
}
}
else
{
std::string infoLog;
if( getInfoLog(infoLog) )
{
OSG_INFO << _shader->getTypename() << " Shader \""
<< _shader->getName() << "\" infolog:\n" << infoLog << std::endl;
}
}
}
示例2: defined
void Shader::PerContextShader::compileShader(osg::State& state)
{
if( ! _needsCompile ) return;
_needsCompile = false;
#if defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)
if (_shader->getShaderBinary())
{
GLint numFormats = 0;
glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &numFormats);
if (numFormats>0)
{
std::vector<GLint> formats(numFormats);
glGetIntegerv(GL_SHADER_BINARY_FORMATS, &formats[0]);
for(GLint i=0; i<numFormats; ++i)
{
OSG_NOTICE<<" format="<<formats[i]<<std::endl;
GLenum shaderBinaryFormat = formats[i];
glShaderBinary(1, &_glShaderHandle, shaderBinaryFormat, _shader->getShaderBinary()->getData(), _shader->getShaderBinary()->getSize());
if (glGetError() == GL_NO_ERROR)
{
_isCompiled = true;
return;
}
}
if (_shader->getShaderSource().empty())
{
OSG_WARN<<"Warning: No suitable shader of supported format by GLES driver found in shader binary, unable to compile shader."<<std::endl;
_isCompiled = false;
return;
}
else
{
OSG_NOTICE<<"osg::Shader::compileShader(): No suitable shader of supported format by GLES driver found in shader binary, falling back to shader source."<<std::endl;
}
}
else
{
if (_shader->getShaderSource().empty())
{
OSG_WARN<<"Warning: No shader binary formats supported by GLES driver, unable to compile shader."<<std::endl;
_isCompiled = false;
return;
}
else
{
OSG_NOTICE<<"osg::Shader::compileShader(): No shader binary formats supported by GLES driver, falling back to shader source."<<std::endl;
}
}
}
#endif
std::string source = _shader->getShaderSource();
// if (_shader->getType()==osg::Shader::VERTEX && (state.getUseVertexAttributeAliasing() || state.getUseModelViewAndProjectionUniforms()))
{
state.convertVertexShaderSourceToOsgBuiltIns(source);
}
GLint compiled = GL_FALSE;
// OSG_NOTICE<<"Compiling PerContextShader "<<this<<" ShaderDefine="<<getDefineString()<<std::endl;
bool printOutShaders = osg::getNotifyLevel()>=osg::NOTICE;//INFO;
if (_defineStr.empty())
{
const GLchar* sourceText = reinterpret_cast<const GLchar*>(source.c_str());
if (printOutShaders)
{
std::string sourceToCompile;
if (!_defineStr.empty()) sourceToCompile += _defineStr;
if (!source.empty()) sourceToCompile += source;
std::string sourceWithLineNumbers = insertLineNumbers(sourceToCompile);
OSG_INFO << "\nCompiling " << _shader->getTypename()
<< " source:\n" << sourceWithLineNumbers << std::endl;
}
_extensions->glShaderSource( _glShaderHandle, 1, &sourceText, NULL );
if (osg::getNotifyLevel()>=osg::INFO)
{
std::string sourceWithLineNumbers = insertLineNumbers(source);
OSG_INFO << "\nCompiling A :" << _shader->getTypename()
<< " source:\n" << sourceWithLineNumbers << std::endl;
}
}
else
{
// Convert all windows line endings to \n
replaceAll(source, "\r\n", " \n");
std::string versionLine;
unsigned int lineNum = 0;
std::string::size_type previous_pos = 0;
do
//.........这里部分代码省略.........