使用glTexImage2D更新OpenGL中的纹理 [英] Updating a texture in OpenGL with glTexImage2D
问题描述
glTexImage2D 和 glTexSubImage2D 是将像素缓冲区传递到纹理的唯一方法吗?
Are glTexImage2D and glTexSubImage2D the only ways to pass a buffer of pixels to a texture?
此刻,我在设置函数 glTexImage2D 中使用传递空值作为缓冲区,然后在渲染循环中,每次迭代时,我都会用新的缓冲区数据调用 glTexSubImage2D
At the moment I use in a setup function glTexImage2D passing null as the buffer, and then on the render loop I call glTexSubImage2D with the new buffer data on each iteration.
但是知道纹理不会改变任何属性(例如尺寸),是否有更有效的方法将实际像素数据传递给渲染纹理?
But knowing that the texture will not change any property such as the dimensions, is there any more efficient way to pass the actual pixel data to the rendering texture?
推荐答案
在现代的OpenGL
中,有4种不同的方法来更新2D纹理:
In modern OpenGL
there are 4 different methods to update 2D textures:
-
glTexImage2D
-最慢的一个,它重新创建内部数据结构.
glTexImage2D
- the slowest one, recreates internal data structures.
glTexSubImage2D
-快一点,但是不能更改图像的参数(大小,像素格式).
glTexSubImage2D
- a bit faster, but can't change the parameters (size, pixel format) of the image.
使用FBO
渲染到纹理-非常快地完全在GPU上更新纹理.请参阅此答案以获取更多详细信息: https://stackoverflow.com/a/10702468/1065190
Render-to-texture with FBO
- update texture entirely on GPU, very fast. Refer to this answer for more details: https://stackoverflow.com/a/10702468/1065190
像素缓冲对象PBO
-用于从CPU到GPU的快速上载,但OpenGL ES尚不支持.
Pixel Buffer Object PBO
- for fast uploads from CPU to GPU, not supported (yet) on OpenGL ES.
这篇关于使用glTexImage2D更新OpenGL中的纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!