OpenGL中glTexSubImage和glTexImage函数的区别
这两个函数有什么区别? 有性能差异吗?
谢谢..
What is the difference between the two functions?
Any performance difference?
Thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用
glTexImage
创建纹理,然后使用glTexSubImage
更新其内容。更新纹理时,您可以更新整个纹理,或仅更新它的子矩形。创建一个纹理并更新它比创建它并重复删除它要高效得多,因此从这个意义上说,如果您有要更新的纹理,请始终使用
glTexSubImage
(在初始纹理之后)创建)。其他技术可能适用于纹理更新。例如,请参阅这篇关于纹理流的文章以获取更多信息。
(最初,这篇文章建议使用
glMapBuffer
进行纹理更新 - 请参阅下面的讨论。)You create a texture using
glTexImage
, and then update its contents withglTexSubImage
. When you update the texture, you can update the entire texture, or just a sub-rectangle of it.It is far more efficient to create the one texture and update it than to create it and delete it repeatedly, so in that sense if you have a texture you want to update, always use
glTexSubImage
(after the initial creation).Other techniques may be applicable for texture updates. For example, see this article on texture streaming for further information.
(Originally, this post suggested using
glMapBuffer
for texture updates - see discussion below.)名称中带有“sub”的 gl 函数不限于 2 的幂维度。正如 gavinb 指出的那样,您需要使用一次非子变体来设置总体尺寸,但我不同意重复调用非子变体比使用“sub”进行更新慢——GPU只要您使用相同的纹理 ID,仍然可以自由地覆盖现有纹理。
The gl functions with "sub" in the name aren't limited to power-of-2 dimensions. As gavinb points out, you need to use the non-sub variant once to set the overall dimensions, but I don't agree that calling the non-sub variant repeatedly is any slower than using "sub" for updates -- the GPU is still free to overwrite the existing texture in place as long as you are using the same texture id.