简体   繁体   English

renderer.render()是阻塞还是非阻塞?

[英]Is renderer.render() blocking or non-blocking?

I need to take a screen shot after every rendered frame completes, but I'm finding that some screen shots are duplicates, so I'm wondering if I might be saving the screen shot before the render is finished. 我需要在每个渲染帧完成之后进行屏幕截图,但是我发现某些屏幕截图是重复的,所以我想知道是否可以在渲染完成之前保存屏幕截图。 Thus... 从而...

  1. Does renderer.render() block until it finishes rendering? renderer.render()会阻塞直到完成渲染吗?
  2. If not, is there a way to know via callback or event when it is complete? 如果没有,完成时是否有办法通过回调或事件知道?

I created a render test with 50k cubes which on my laptop takes about 6-10 seconds. 我用50k多维数据集创建了一个渲染测试,在笔记本电脑上大约需要6-10秒。

The fiddle is here: http://jsfiddle.net/1ma18gLf/ 小提琴在这里: http : //jsfiddle.net/1ma18gLf/

The function does block based on the test. 该功能会根据测试进行阻止。 Use the browser console to watch the result and see the base64 image. 使用浏览器控制台观看结果并查看base64图像。

The question then becomes does webGL paint to the canvas separately regardless of what JavaScript is doing. 然后问题就变成了,无论JavaScript在做什么,webGL都会分别绘制到画布上。

You could try a manual clear before the render: 您可以在渲染之前尝试手动清除:

var renderer = new THREE.WebGLRenderer( { preserveDrawingBuffer: true } );
renderer.autoClear = false;

//In your render loop:

renderer.clear();
renderer.render( scene, camera );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM