在Android OpenGL ES 2.0中最大程度地创建/删除纹理 [英] Maximum texture creation/deletion in Android OpenGL ES 2.0

查看:445
本文介绍了在Android OpenGL ES 2.0中最大程度地创建/删除纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用本机代码编写游戏,所有图形均使用OpenGL ES 2.0完成.我尝试通过重复创建纹理并在不需要它们时删除它们(使用glDeleteTextures)来节省纹理的使用.我注意到OpenGL无论如何将永远不会重复使用相同的纹理ID,并且在精确创建192个纹理后,Android屏幕会变成白色(首先是部分,下一次加载使其完全变成白色),除非释放应用程序焦点并将其放回原处,否则它不会恢复.这是错误还是功能? glFlush()也无济于事.

I'm writing a game in native code and all graphics is done with OpenGL ES 2.0. I've tried sparing with the texture usage by repeatedly creating them and deleting when they're not needed (with glDeleteTextures). I noticed that the OpenGL will never reuse same texture id anyway and after exactly 192 texture creations the android screen turns white, (first partially, next load makes it fully) and it does not recover except by releasing app focus and getting it back. Is this a bug or feature? glFlush() does not help either.

我已经编写了自己的字体渲染引擎,该引擎使用字体精灵地图集将所有文本渲染为单独的新纹理.这样,实际文本将完成一次,而随后的绘制调用仅适用于一个纹理.但是,例如播放器名称查询会导致每次输入或删除新字母时都会重新创建文本纹理,在这里我很快遇到了192个限制.加载和删除什么纹理都没有关系,经过固定数量的创建后,屏幕变为白色.

I have written my own font rendering engine that uses font sprite atlas to render all text into a separate new texture. This way the actual text is done once and subsequent draw calls is for one texture only. However, e.g. a player name query causes the text texture to be recreated every time a new letter is entered or deleted and here I quickly encountered the 192 limit. It does not matter what textures are loaded and deleted, screen goes white after fixed amount of creations.

至少在运行Android 6.0的android设备Samsung J5 2016上运行时会发生这种情况.任何建议表示赞赏.

This happens at least when running on my android device Samsung J5 2016 with Android 6.0. Any advice is appreciated.

推荐答案

找出原因.每次创建新的纹理渲染操作时,我实际上都在删除帧缓冲区并重新创建它.通过只创建一次

Found out the reason. I was actually deleting the framebuffer and recreating it every time I created a new render to texture operation. By doing creation only once

glGenFramebuffers(1, &m_renderFrameBuffer);

并在后续操作中重新使用它,然后将其删除

and reusing it in subsequent operations and putting delete

if (m_renderFrameBuffer != 0)
{
    glDeleteFramebuffers(1, &m_renderFrameBuffer);
    m_renderFrameBuffer = 0;
}

对于类析构函数,我不再遇到问题了.

to class destructor I didn't run into the problem anymore.

但是在很多例子中这并不明显,或者至少没有被警告.看来完成许多帧缓冲区的创建和删除操作最终将耗尽一些资源.

But this is not obvious in the numerous examples out there or at least this is not warned. It seems that doing many framebuffer creations and deletions will eventually exhaust some resources.

这篇关于在Android OpenGL ES 2.0中最大程度地创建/删除纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆