glTexImage2D完成上传后如何获得通知? [英] How to get notified when glTexImage2D finished upload?

查看:125
本文介绍了glTexImage2D完成上传后如何获得通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在将纹理上传到OpenGL后进行渲染,但是无法获得有关完成的通知.

I want to render after a texture is uploaded to OpenGL, but I cannot get notified about the completition.

我确实想避免使用动画或任何形式的重复渲染.

I do want to avoid using animation, or any kind of repetitive rendering.

glTexImage2D是否完全异步?据我所知,几乎每个OpenGL调用都是异步的.

Is glTexImage2D asynchronous at all? As far as I know, almost every OpenGL call is async.

如果我也可以得知glDrawArrays的完成情况,那就太好了.

It would be great anyway, if I could be informed about a glDrawArrays completition as well.

推荐答案

答案是,在对glTexImage2D的调用返回后才继续.从您的角度来看,这是一个同步调用,从某种意义上说,它在返回后已正确设置.您可以通过使用PBO作为中间存储来使纹理上载异步进行,但是即使如此,一切都由驱动程序为您管理,您需要知道的是,当glTexImage2D返回时,您可以假定纹理数据已正确上载并开始渲染.如果尚未在内部上传纹理数据,则您的内容将始终无法渲染,并且将等待设置纹理.

The answer is, just continue after the call to glTexImage2D returns. From your point of view it is a synchronous call in the sense that everything is properly set up after it returns. You can make texture uploads asynchronous by using PBOs as intermediate storage, but even then everything is managed by the driver for you and all you need to know is that when glTexImage2D returns you can assume the texture data to be properly uploaded and start rendering. If the texture data is not yet uploaded internally your things won't get rendered anyway and will wait for the texture to be set up.

您是正确的,大多数OpenGL调用可以看作是异步的,因为它们仅调度要发送到图形卡的命令,而驱动程序可以决定何时将其最终发送到硬件,而硬件可以自由决定何时处理它们,更不用说没人知道它们何时真正完成.但是你知道吗,通常你不在乎.如果需要阻塞以等待之前的某些操作完成(例如异步纹理上传),则将自动为您进行管理,并且一旦返回OpenGL函数,就可以确定它已经完成了工作视图.

You are correct that most OpenGL calls can be seen as asynchronous in the sense that they only schedule commands to be sent to the graphics card and the driver decides when to finally send them to the hardware and the hardware is free to decide when to process them, not to speak of the fact that nobody knows when they're actually finished. But you know what, you usually just don't care. If anything needs to block in order to wait for some previous operation to complete (like an asynchronous texture upload), then it will be managed for you automagically and once an OpenGL function returned you can be sure it has done its work from your point of view.

免责声明:在某些情况下,确实确实需要知道实际操作何时最终在设备上完成工作.虽然您的情况不是其中之一.您可能真的想同步操作的少数情况之一是,由于调试或性能分析的原因而对某些东西进行计时.而且由于OpenGL ES可能缺少 ARB_timer_query ,因此发布glFinish(例如在这种情况下, BlueVoodoo 的答案中建议的方法)可能是一个选项.

disclaimer: There are indeed situations when you really need to know when an actual operation has finally finished its work on the device. Though your scenario isn't one of those. One of the few situations when you might really want to synchronize operations is, when you are timing something for debugging or profiling reasons. And since OpenGL ES probably lacks ARB_timer_query, issuing a glFinish (like suggested in BlueVoodoo's answer) might be an option in this case.

编辑:以同样的方式,当最终用glDrawArrays绘制的内容最终呈现到屏幕上时,您也不会得到通知,但是您根本不在乎.

In the same way you don't get notified when your things drawn with glDrawArrays are finally rendered to screen, but you just don't care about it.

这篇关于glTexImage2D完成上传后如何获得通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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