[osg-users] How to pre-compile shaders before actual usage?

Robert Osfield robert.osfield at gmail.com
Fri Sep 29 00:38:55 PDT 2017


HI Michael,

You can't compile GL objects unless you do if from a thread with the
appropriate graphics context current, this means you can't just force a
compile from any thread.  The way the OSG manages this is to mark GL
related objects (textures, shader programs, VBO's etc) as needing to be
compile before you and then compiling them once the scene graph needs to
dispatch those GL related objects to the OpenGL FIFO.  This will all happen
automatically so usually you don't need to worry about it, what needs to
happen will be done for you.

In cases where compilation of GL objects might take a while and endanger a
break of frame then it can be useful to pre-compile these GL objects prior
to them being merged with the main scene graph.  The osgViewer has support
for forcing a compile GL objects traversal on the first frame that the
viewer is run, this will happen automatically, but if you assign scene
graph elements after the first frame then the new GL objects will be just
compiled just prior to being used.

The exception to this is when using the DatabasePager - it has support for
collecting all the GL objects that will be needed to be compiled for any
new scene graphs and passes these on to the
osgUtil::IncrementalCompileOperation that is run on every frame to compile
GL objects, it does so incrementally, only compiling what GL objects it has
time available to compile.  Once all the required objects are compiled the
subgraphs they are associated with then can be merged with the main scene
graph without risking breaking a frame.

In your case I can't say whether you need to do anything at all, or whether
use of the IncrementalCompileOperation would be appropriate, it all depends
upon the performance requirements of your application.

Robert.

On 28 September 2017 at 21:42, michael kapelko <kornerr at gmail.com> wrote:

> Hi.
>
> I want to pre-compile shader programs before they are actually used by
> real nodes.
> I tried to create empty node (new osg::Node) and assign an
> osg::StateSet with an osg::Program, but such action did not trigger
> shader compilation.
> In the logs I see shader compilation happening only when I assign
> osg::StateSet to actual nodes at my screen.
>
> What am I missing?
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170929/50081407/attachment.html>


More information about the osg-users mailing list