|Version 1 (modified by martin, 8 years ago)|
osgDB Loading Progress
- Developer Blog
- Mailing Lists
- Getting Started
- Platform Specifics
- User Guides
- Programming Guides
- Reference Guides
- Tips And Tricks
- Knowledge Base
- Trac Usage Examples
- TracGuide Documentation
- Software Patents
- Software Patents Europe
How to show progress information while loading files with osgDB
An important rule in interactive software is to always give the user some signs of activity while he/she is waiting for an operation to be completed, so that the application doesn't seem unresponsive. In OSG it is common to have large model or image files that may take a long time to load, so it would be nice to have a progress bar or some other indicators that can show the status of the loading process. This tutorial explains how you can do that using standard techniques.
Only osgDB plugins that support direct streaming through iostreams can take advantage of this tecnhique. Currently the .osg and .ive plugins do support streaming, as well as many image plugins.
All osgDB plugins can read and/or write files through the well-known osgDB::readNodeFile(), osgDB::writeNodeFile(), osgDB::readImageFile() and similar functions. Some plugins also allow more low-level access via standard streams, providing support for reading and/or writing from/to user-defined streams instead of files. Thanks to the flexibility of the C++ Standard Template Library you can write your own stream buffer class to keep track of the number of bytes read by hooking into the uflow() method. The file attached to this page contains a simple implementation of such class along with a working example.
Once you have a properly customized stream buffer class (as that of the attached example), follow these steps in order to read the file:
- given a file name, search for a suitable plugin that can read the file. It all boils down to calling osgDB::Registry::instance()->getReaderWriterForExtension() passing it the file extension and storing the osgDB::ReaderWriter? object it returns.
- create an instance of the custom stream buffer class passing it the name of the file that must be opened. This operation will open the file much like the standard std::basic_filebuf<> template does.
- create a std::istream object based on the custom stream buffer.
- take the ReaderWriter? object you found at step 1 and call its readNode() method passing it the stream object created at the previous step. This will read the file, and the uflow() method in your custom streambuffer will display progress information as bytes are read.
Others can enter related things or hints to the goal or solution...
Tutorial written by Marco Jez.
add your name here