Iray Programmer's Manual

Asynchronous rendering

When using neuray, an application uses a render context for doing the actual rendering. A render context allows you to call the render() function. That call will initiate rendering and will not return before the rendering is done and an image was generated and stored for all requested render targets. You can give an optional callback function which reports about the progress of the rendering and may be called before the call to render() returns.

Especially for interactive applications, the blocking behavior of the render call can be inconvenient, because the application can not react to user events during the time of the rendering. For that reason the render context class offers an additional function named render_async(). When your application calls that function, the rendering will be initiated as in the render() function. But in contrast to that function, the call will return immediately without waiting for any result. Rendering will proceed in the background and your application can do other things during that time. To enable your application to find out, when the rendering is finished, you should give an additional callback function to the render_async() function callback, the ready_callback. That callback will be called when the rendering is finished.

Note, that it is important that you do not commit or abort the transaction as long as the asynchronous rendering is running. Otherwise, the rendering will be cancelled immediately. In that case the result of the rendering so far would be discarded.

Note also, that neuray and all its renderers are fully multi-threading safe. That means as an alternative to using render_async(), you can create additional render threads in your application which then call the blocking render() function. Other application threads can still react to user input and other events. The effect with this approach would be very similar to using the render_async() function.