如何执行异步关屏的查询? [英] How to perform asynchronous off-screen queries?

查看:162
本文介绍了如何执行异步关屏的查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有场景的几个(可能数以千计)我想以什么绘制执行查询来呈现。我遇到的问题是,到 glGetQueryObjectiv电话()是昂贵的,所以我想找出一种方法来呈现几个场景提前而我等待查询的结果变得可用。

I have several (potentially thousands) of scenes I would like to render in order to perform queries on what is drawn. The problem I am running into is that calls to glGetQueryObjectiv() are expensive, so I'd like to figure out a way to render several scenes in advance while I wait for the results of the queries to become available.

我读了一些关于帧缓冲区对象和像素缓冲区对象,但主要是在使用保存到文件的情况下 glReadPixels(),我一直没能跟踪在异步查询使用任一这些对象中的一个例子。是否有任何理由设置执行 glGetQueryObjectiv()会从 glReadPixels()不同在的这个例子(例如,我应该使用一个FBO或PBO)?

I have read a bit about Framebuffer Objects and Pixel Buffer Objects, but mostly in the context of saving to a file using glReadPixels() and I haven't been able to track down an example of using either of these objects in asynchronous queries. Is there any reason why the setup for performing glGetQueryObjectiv() would be different from glReadPixels() as in this example (e.g., should I use an FBO or a PBO)?

注意:
这不是一个图形应用程序。所有我感兴趣的是GL_SAMPLES_PASSED查询的结果(即多少像素被吸引?)。

Note: This is NOT for a graphics application. All I'm interested in is the result of the GL_SAMPLES_PASSED query (i.e. how many pixels were drawn?).

具体应用估计有多少阳光是惊人的表面,当其他表面投射阴影。如果你有兴趣,你可以读到它这里

The specific application is estimating how much sunlight is striking a surface when other surfaces are casting shadows. If you are interested, you can read about it here.

推荐答案

既不的帧缓冲区对象的也没有的(像素)的缓冲区对象的是正确的类对象在使用中(异步)查询; GL拥有​​一个完全独立的对象类称为 查询对象 。你可以喂某些查询到缓冲区对象的结果,但这是就他们的关系去。

Neither Framebuffer Objects nor (Pixel) Buffer Objects are the proper class of objects to use in an (asynchronous) query; GL has an entirely separate class of objects called Query Objects. You can feed the results of certain queries into Buffer Objects, but that is about as far as their relationship goes.

基本上与异步查询的想法是,你把查询到的图形管线,让一些时间通过您尝试读取它回来。这使GPU的时间来真正完成所有的命令在查询的开始和结束之间的第一次。另一种方法是一个同步查询,这意味着你的调用线程停止做任何有用的和等待作为GPU完成一切必要措施,完成查询。

Basically the idea with asynchronous queries is that you put the query into the graphics pipeline and let some time pass before you try to read it back. This gives the GPU time to actually finish all of the commands in between the beginning and end of your query first. The alternative is a synchronous query, which means that your calling thread stops doing anything useful and waits for the GPU to finish everything necessary to complete your query.

执行一个查询,并没有强迫同步将开始和完成您的查询,你会通常,但不是立即读取结果,在应用程序的主循环定期检查<$ C $状态的最简单方法C> GL_QUERY_RESULT_AVAILABLE 为您的查询对象。在这给你 GL_TRUE ,这意味着你可以阅读从查询对象的结果,而不破坏管道渲染。如果你试图从一个查询对象得到的结果之前,它是在这种状态下,你要强制同步查询。

The simplest way of implementing a query that does not force synchronization would be to start and finish your query as you would typically, but rather than reading the result immediately, in your application's main loop periodically check the status of GL_QUERY_RESULT_AVAILABLE for your query object. When this gives you GL_TRUE, it means you can read the results from the query object without disrupting the render pipeline. If you do try to get the results from a query object before it is in this state, you are going to force a synchronous query.

这篇关于如何执行异步关屏的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆