gpt4 book ai didi

opengl - 什么时候应该使用 glInvalidateBufferData?

转载 作者:行者123 更新时间:2023-12-04 16:10:29 25 4
gpt4 key购买 nike

OpenGL 提供函数 glInvalidateBufferDataglInvalidateBufferSubData 来使缓冲区无效。

根据 OpenGL wiki,这些函数的作用是:

When a buffer or region thereof is invalidated, it means that the contents of that buffer are now undefined.

The idea is that, by invalidating a buffer or range thereof, the implementation will simply grab a new piece of memory to use for any later operations. Thus, while previously issued GL commands can still read the buffer's original data, you can fill the invalidated buffer with new values (via mapping or glBufferSubData) without causing implicit synchronization.

我很难理解什么时候应该调用这个函数,什么时候不应该调用。理论上,如果缓冲区的内容将被覆盖,那么之前的内容是否被丢弃完全没有区别。这是否意味着每次写入之前都应调用缓冲区?还是只在某些情况下?

最佳答案

In theory, if the contents of the buffer are going to be overwritten it makes absolutely no difference if the previous contents were trashed or not.

你完全正确。

本质上你是否调用glBufferDataglInvalidateBufferData您正在实现相同的最终目标。不同之处在于 glBufferData你更多的是说“我现在需要这么多内存”,这反过来意味着旧内存被丢弃了。然而 glInvalidateBufferData你是说“我不再需要这段内存了”。 glInvalidateBufferSubData()也是如此对比glBufferSubData()以及所有其他 glInvalidate*() 函数。

这里的关键是,如果您有一个缓冲区,并且您目前不再需要它,但是您要保留该句柄供以后使用。然后你可以调用glInvalidateBufferData告诉内存可以释放。

glInvalidateBufferSubData() 也是如此.如果您突然不需要分配给缓冲区的最后一半内存块,那么现在您的驱动程序知道可以重新分配这 block 内存。

When should glInvalidateBufferData be used?

所以回答你的问题。当您有一个缓冲区并且您不再需要内存时。

关于opengl - 什么时候应该使用 glInvalidateBufferData?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43036568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com