如何在 C++ 中获取 OpenGL 使用的总内存(以字节为单位)?
如何在 C++ 中获取 OpenGL 使用的总内存(以字节为单位)?
我正在构建一个 OpenGL 应用程序,使用的总内存似乎在上升,我可以获得有关变量和变量使用的总内存的信息。我自己创建的对象,但无法保证 OpenGL 为其变量和对象使用了多少内存。对象和纹理等。那么是否有可能在 C++ 中获取 OpenGL 使用的总内存(以字节为单位)?
How to get total memory in bytes used by OpenGL in C++?
I'm building an OpenGL application and the total memory used seems to be rising, I can get the info about the total memory used by variables & objects created by myself but can't guarantee how much memory OpenGL is using for its variables & objects & textures, etc. So is it possible to get the total memory in bytes used by OpenGL in C++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,你不需要。 OpenGL 最终是一个硬件抽象。而且 OpenGL 根本不提供获取此类信息的方法。
有一些特定于供应商的扩展可以为您提供询问的方式,尽管您得到的结果取决于体系结构。 AMD 硬件提供 ATI_meminfo 扩展。它将内存分解为不同类型的对象:缓冲区对象、纹理和渲染缓冲区。
NVIDIA 提供了实验性扩展 NVX_gpu_memory_info。注册表中没有有关如何使用它的信息,因此我无法将您链接到任何内容。
无论如何,了解 GPU 使用情况的最有效方法就是亲自跟踪它。始终使用带有尺寸的内部图像格式;这意味着您可以很好地估计纹理占用的内存量。缓冲区对象等也是如此。
您不会得到确切的数字,因为填充、对齐等可能会让您感到困惑。但你会得到一些相当不错的东西。
In general, you don't. OpenGL is ultimately a hardware abstraction. And OpenGL simply doesn't provide a way to get that sort of information.
There are vendor-specific extensions that will give you ways to ask, though what you get back depends on the architecture. AMD hardware provides the ATI_meminfo extension. It breaks memory down into types of objects: buffer objects, textures, and renderbuffers.
NVIDIA provides the experimental extension NVX_gpu_memory_info. There's no information in the registry about how to use it, so I can't link you to anything.
In any case, the most effective way to know what the GPU is using is to just keep track of it yourself. Always use internal image formats with sizes; this means you can compute a pretty good estimate of how much memory a texture takes up. The same goes for buffer objects and so forth.
You won't get exact numbers, as padding, alignment, and the like can confound you. But you'll get something pretty decent.