加载后查找 OpenGL 纹理大小(以字节为单位)
嘿,我有一个加载了 glTextImage2D 的纹理。 我想在纹理加载到 VRAM 后获取纹理的大小,我需要做什么? 我的内部格式是 RGBA,纹理的格式有所不同。
Hey, I have a texture loaded with glTextImage2D.
I want to get the texture's size after it was loaded to the VRAM, what do I need to do?
My internal format is RGBA and the texture's format varies.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能对您有帮助,您可能可以从中推断出实际的内存使用情况。但是,我相信这仍然是一个近似值:
http://www.geeks3d.com/20100531/programming-tips-how-to-know-the-graphics-memory-size-and-usage-in-opengl/< /a>
(使用 NVIDIA 或 ATI 特定扩展查询 OpenGL 的总内存使用量)
另请注意,根据我的经验,通过粗略计算来近似内存使用量通常就足够了。纹理“应该”存储 1,2 或 4 个分量,而不需要任何显着的开销。因此,对于 WxH RGBA 纹理,计算 W*H*4。如果存储浮点纹理(即GL_RGBA32F),则计算W*H*4*4。对于 Mip-Map,添加 (1/3) 额外内存消耗。但请注意,至少据我所知,纹理内存也会碎片化,可能会导致您的可用内存少于估计的数量。
This might be helpful to you and you can probably infer the actual memory usage from it. However, I believe this still is rather an approximation:
http://www.geeks3d.com/20100531/programming-tips-how-to-know-the-graphics-memory-size-and-usage-in-opengl/
(query the total memory usage of OpenGL using NVIDIA or ATI specific extensions)
Also note that from my experience, approximating the memory usage by rough calculation was usually sufficient. Textures "should" be stored either 1,2 or 4 components without any significant overhead. Therefore for a WxH RGBA texture, calculate W*H*4. If you store float textures (i.e. GL_RGBA32F), calculate W*H*4*4. For Mip-Maps, add (1/3) additional memory consumption. Be aware however, that - at least to my knowledge - texture memory can also fragment, possibly leaving you with less available memory as estimated.
使用 GetTexLevelParameter,它可以为您提供(对于每个level):
(*) 使用这些参数计算纹理大小(针对指定级别)。
单个纹理内存使用量取决于生成的 mipmap。实际上,要正确计算单个纹理使用的内存,您必须确定与纹理相关的 mipmap,然后对每个级别的内存使用量求和。
mipmap 计数由 OpenGL 规范根据纹理目标确定:纹理数组元素有自己的 mipmap 集,每个立方体面纹理都有自己的 mipmap 集。
每个级别的 mipmap 的尺寸都会减半,直到变为 1。如果尺寸不是 2 的幂,则会四舍五入到较小的整数。
Use GetTexLevelParameter, which can give you (for each level):
(*) Uses these parameters for computing the texture size (for the specified level).
The single texture memory usage is dependent on the generated mipmaps. Indeed to compute correctly the memory used by a single texture you have to determine the mipmaps related to the textures, and then sum the memory usage for each level.
The mipmap count is determined by the OpenGL specification depending on the texture target: texture arrays elements has their own mipmaps set, each cube face texture has its own mipmap set.
The dimension of the mipmaps are halfed for each level, untill they goes to 1. In the case the dimension are not power of two, they are rounded to the lower integer.