Validation of rendering completion

Hey there,
I want to do a screenshot of the map by coding (canvas.toDataUrl) after rendering. The problem is that I get the screenshot before the rendering completion, so the image I get is not what I want.
How can I check if the rendering had completed, so I can do the screenshot after completion?

Thank you

There are two ways to do this.

  1. Call viewer.render() immediately before toDataUrl.

  2. Subscribe to the scene.postRender event, which gets called immediately after every frame is finished rendering. Call toDataUrl inside the callback and then unsubscribe.

I usually do 1 and both should work, but I think someone ran into an edge case that forced them to use 2. It might depend on exactly what your app is doing.

I׳m now not in front my computer to check it, but I did the second option before, and it hadn't worked well. It seems to me by debugging that several render() are invoked before the rendering is completed, especially when there is a big amount if tiles to be rendered. So, I assume that also calling render() by my code won't do the job, I will check it later.
I tried to check if the rendering completed by the object viewer.scene.globe._surface. There is an array of tiles to be rendered with a state property. I did for each and checked that all the states are done, but it wasn't enough. After some render() all the states were done, but it wasn't truely completed. In the screenshot I've got a lot black spaces.
I tried also to capture the screenshot in the complete callback of camera.flyTo(). But it hadn't worked too.
I want to know if there is a truely indicator to check the completion of rendering.

Hello elad,

I׳m now not in front my computer to check it, but I did the second option before, and it hadn't worked well. It seems to me by debugging that several render() are invoked before the rendering is completed, especially when there is a big amount if tiles to be rendered. So, I assume that also calling render() by my code won't do the job, I will check it later.
I tried to check if the rendering completed by the object viewer.scene.globe._surface. There is an array of tiles to be rendered with a state property. I did for each and checked that all the states are done, but it wasn't enough. After some render() all the states were done, but it wasn't truely completed. In the screenshot I've got a lot black spaces.
I tried also to capture the screenshot in the complete callback of camera.flyTo(). But it hadn't worked too.
I want to know if there is a truely indicator to check the completion of rendering.

make sure you are constructing your CesiumWidget / Viewer with the following options:

  options.contextOptions.webgl.preserveDrawingBuffer = true;

This ensures that the OpenGL framebuffer is not discarded after
rendering and is therefore accesible to the canvas (this option
may have performance implications).

cheers,

Manuel

Do you mean to do:
Var viewer = new viewer({contextOptions: {webgl:{preserveDrawingBuffer = true}}})?

And I have found the solution to my problem.
It goes like that

Function checkRenderingCompletion(viewer){
     return (viewer.scene.globe._surface._tileLoadQueue.length === 0)
}