<div dir="ltr">Hi James, <div><br></div><div>Its not direct answer to your questions but a code snippet overloading Program which I used to change shader variant depending on compilation/link result (from most advanced to more basic fallbacks). This approach was quite simple I tested Program compilation result (including compilation/ling log) by simply checking if my Program was really applied after Program::apply() and if not adopted fallback to less demanding shaders. Not sure if this will solve your problem but perhaps will be a step forward to proper solution.</div><div><br></div><div>class MyProgram: public osg::Program <br>{<br>public:<br> MyProgram( ): _shaderVariant( DefaultShaderVariant )<br> {<br> osg::Shader * vertShader = osgDB::readShaderFile( osg::Shader::VERTEX,
"MyVertexShader.glsl"
);<br> osg::Shader * fragShader = osgDB::readShaderFile( osg::Shader::FRAGMENT,
"MyFragmentShader.glsl"
);<br><br> addShader( vertShader );<br> addShader( fragShader ); <br><br> notified.resize( DefaultShaderVariant + 1 );<br> }<br><br> void setDigitDefine( std::string MACRO, int DIGIT ) const<br> {</div><div> // For brevity code removed but</div><div> // this function simply checks shader sources and </div><div> // finds all ocurences of </div><div> // #define MACRO DEFAULT_DIGIT </div><div> // and replaces them to </div><div>
// #define MACRO DIGIT
</div><div> // to select shader codepath dependant on macro value</div><div> }<br><br> void apply( osg::State& state ) const<br> { <br> while( _shaderVariant > 0 )<br> { <br> osg::Program::apply( state );<br><br> // Break if program was applied ie its not null<br> if( state.getLastAppliedProgramObject() != NULL ) <br> {<br> if( !notified[0] )<br> {<br> std::cout<< "INFO: MyProgram - GLSL Compilation Succeeded." << std::endl;<br> std::cout<< " Shader variant: " << _shaderVariant << std::endl;<br> std::cout<< " GL Vendor: " << glGetString(GL_VENDOR) << std::endl;<br> std::cout<< " GL Renderer: " << glGetString(GL_RENDERER) << std::endl; <br> std::cout<< " GL Version: " << glGetString(GL_VERSION) << std::endl;<br> notified[0] = true;<br> }<br> break;<br> }<br><br> if( !notified[_shaderVariant] ) <br> {<br> std::string infoLog;<br> getPCP( state )->getInfoLog( infoLog );<br> std::cout<< "ERROR: MyProgram - GLSL Compilation Failed." << std::endl;<br> std::cout<< " Shader variant: " << _shaderVariant << std::endl;<br> std::cout<< " GL Vendor: " << glGetString(GL_VENDOR) << std::endl;<br> std::cout<< " GL Renderer: " << glGetString(GL_RENDERER) << std::endl; <br> std::cout<< " GL Version: " << glGetString(GL_VERSION) << std::endl;<br> std::cout<< infoLog << std::endl;<br><br> notified[_shaderVariant] = true;<br> }<br><br> // Switch to fallback variants if program link failed<br> setDigitDefine( "SHADER_VARIANT", --_shaderVariant );<br> }<br> }<br><br>protected:<br> mutable int _shaderVariant;<br> static const int DefaultShaderVariant = 2;<br> mutable std::vector< bool > notified;<br>};<br><br></div><div>Cheers,<br></div><div>Wojtek Lewandowski</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">śr., 24 lut 2021 o 19:04 'James Turner' via OpenSceneGraph Users <<a href="mailto:osg-users@googlegroups.com">osg-users@googlegroups.com</a>> napisał(a):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I’m trying to extract shader compile and link info logs at runtime, so I can log+report them.<br><br>I note osg::Program::getGlProgramInfoLog exists, obviously it takes a context ID since the PerContextProgram is what has the actual errors.<br><br>Two things I need help with:<br><br>1) does the program log also contain shader compile errors, or is this only the link log? I don’t see a corresponding APi on osg::Shader, is why I ask<br><br>2) *when* can I call the log functions and expect to get valid results? Given the OSG drawing model, obviously the log won’t be available immediately when creating the Program.. Do I need to use a DrawCallback to check the log after the first time the Program has been used?<br><br>I looked for examples of using getGlProgramInfoLog but unfortunately couldn't find any, maybe pointing me at one would answer both of these points.<br><br>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:osg-users+unsubscribe@googlegroups.com" target="_blank">osg-users+unsubscribe@googlegroups.com</a>.<br>
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/osg-users/437023da-c7b2-4bfb-a6b9-6d6613236e04n%40googlegroups.com?utm_medium=email&utm_source=footer" target="_blank">https://groups.google.com/d/msgid/osg-users/437023da-c7b2-4bfb-a6b9-6d6613236e04n%40googlegroups.com</a>.<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</blockquote></div>