本文介绍了如何获得总内存在OpenGL在C ++中使用的字节数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取OpenGL在C ++中使用的总内存(以字节为单位)?

How to get total memory in bytes used by OpenGL in C++?

我正在构建一个OpenGL应用程序,使用的内存总量似乎在上升,我可以得到有关变量&对象创建自己,但不能保证OpenGL使用多少内存的变量&对象&纹理等。因此,可以获得 OpenGL在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++?

推荐答案

一般来说,你不会。 OpenGL最终是一个硬件抽象。而且OpenGL根本不提供一种获得这种信息的方法。

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.

有供应商特定的扩展,它会给你提问的方法,尽管你得到的取决于架构。 AMD硬件提供。它会将内存分割为多种类型的对象:缓冲区对象,纹理和渲染缓冲区。

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提供了实验性扩展NVX_gpu_memory_info。在注册表中没有关于如何使用它的信息,所以我不能链接到任何东西。

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.

在任何情况下,最有效的方式知道什么GPU正在使用是只是自己跟踪它。始终使用的内部图片格式;这意味着你可以计算一个纹理占用多少内存的很好的估计。对于缓冲对象等也是如此。

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.

这篇关于如何获得总内存在OpenGL在C ++中使用的字节数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 11:30