OpenGL 不释放显示列表内存
我有一个显示静态场景的 OpenGL 应用程序。该场景由大约 150k 个多边形组成。由于多边形太多,而且是静态场景,所以我决定使用显示列表来存储所有多边形。当应用程序仍在运行时,可以“重新生成”场景。
我的问题是 OpenGL 似乎没有释放它为列表分配的任何内存。
这是我创建列表的地方:
m_displayList = glGenLists(1);
m_polygons = m_generator->polygons(scene_name);
glNewList(m_displayList, GL_COMPILE);
for(int i = 0; i < m_polygons.size(); i++)
{
glBegin(GL_POLYGON);
glNormal3fv(m_polygons[i]->get_normal());
for(int j = 0; j < 4; j++)
{
glColor3fv(m_polygons[i]->get_colors()[j]);
glVertex3fv(m_polygons[i]->get_vertices()[j]);
}
glEnd();
}
glEndList();
稍后,当我想要重新生成场景时,我称之为:
glDeleteLists(m_displayList, 1);
这应该处理 OpenGL 为列表分配的所有内存,对吗?据我所知,事实并非如此。当我生成场景时,我的内存使用量增加了大约 600 Mb,而当我重新生成时,它只下降了大约 30 Mb,然后又增加了 600 Mb。我想也许 OpenGL 只是懒得删除它,但我可以生成场景,直到我点击交换,并且没有任何东西被释放。
我知道我的应用程序的其余部分没有使用太多。 “生成器”类仅使用大约 30 Mb(这是我重新生成场景时释放的内存)。
无论如何,我不知道我做错了什么。
I have an OpenGL app that displays a static scene. This scene is comprised of about 150k polygons. Since there are so many polygons, and since it's a static scene, I decided to use a display list to store all the polygons. It's possible to 'regenerate' the scene while the app is still running.
My problem is that OpenGL doesn't seem to deallocate any of the memory it allocated for the list.
This is where I create the list:
m_displayList = glGenLists(1);
m_polygons = m_generator->polygons(scene_name);
glNewList(m_displayList, GL_COMPILE);
for(int i = 0; i < m_polygons.size(); i++)
{
glBegin(GL_POLYGON);
glNormal3fv(m_polygons[i]->get_normal());
for(int j = 0; j < 4; j++)
{
glColor3fv(m_polygons[i]->get_colors()[j]);
glVertex3fv(m_polygons[i]->get_vertices()[j]);
}
glEnd();
}
glEndList();
Later on, when I want to regenerate the scene, I call this:
glDeleteLists(m_displayList, 1);
That should take care of all the memory OpenGL allocated for the list, correct? As far as I can tell, it isn't. When I generate the scene, my memory usage grows by about 600 Mb, and when I regenerate, it only drops about 30 Mb, before going up another 600 Mb. I figured maybe OpenGL was just being lazy about deleting it, but I can generate scenes until I hit the swap, and nothing ever gets freed.
I know the rest of my application isn't using much. The "generator" class only uses about 30 Mb (that's what's getting deallocated when I regen the scene).
Anyway, I have no idea what I'm doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将释放 OpenGL 为列表分配的内存。但它不会释放您分配的任何内存。
我不知道 m_generator->polygons(scene_name); 是如何工作的,但“生成器”似乎可能会分配内存来保存生成的数据。所以检查一下你是否应该释放它。
That will free the memory OpenGL allocated for the list. But it won't free any memory YOU allocated.
I don't know how
m_generator->polygons(scene_name);
works, but it seems likely that a "generator" might allocate memory to hold the generated data. So check if you should be freeing that.600 MB 听起来像是很大的内存,只是猜测,但从我所看到的来看,150k 多边形应该只占用大约 20 MB 的内存。当您为所有这些多边形创建显示列表时,所有数据都必须复制到显示列表中,这样再加上其他内容,至少还需要 20 MB。
检查您的分配并查看是否有任何内容被过度分配可能是个好主意。只是我的想法。
600 MB sounds like a lot of memory, just guessing but from what I can see 150k polys should only take up about 20 MB in memory. When you create a display list for all these polys, all the data has to be copied to the display list so that would be another 20 MB at least plus other stuff.
Might be a good idea to look through your allocations and see if anything is being over allocated. Just my thoughts.