找到并删除从内存中隐藏的纹理的最佳方法 [英] Best way to find and remove hidden textures from memory

查看:169
本文介绍了找到并删除从内存中隐藏的纹理的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到一种方法来跟踪这些加载纹理绘制位置。当一些加载纹理被覆盖,我必须从内存中删除它们。

I need to find a way to track positions where the loaded textures are drawn. When some of the loaded textures are overwritten, i have to delete them from memory.

我有给我发了很多小图像,这是组装,然后RUI客户机的屏幕上显示的远程用户界面(RUI)服务器。在这种情况下,我不知道它的纹理是其他一些纹理的后面,所以我无法将其删除。此外,覆盖必须是完整的(纹理的背后一定完全被隐藏)。
有没有什么有效的方式来实现这一目标的跟踪和删除?

I have a Remote User Interface (RUI) server which sends me a lot of small images, which are assembled and then shown on the RUI client's screen. In this scenario, i have no clue which textures are behind some other textures, so i am unable to delete them. Also, overwriting must be complete (texture behind must be totally hidden). Is there any efficient way to achieve this tracking and deleting?

我的用例是这样的:我有存储在服务器上的按钮图像菜单。整个画面是由片段(按钮,滚动,动画等)。
例如,当我点击一个按钮,服务器将我存储在其存储图片的多个缩略图,我在显示它们,例如,在屏幕的右半部分。
在其他按钮点击,显示的歌曲,视频,电子书或别的东西名单。
我需要从内存中删除的照片缩略图的纹理,然后显示歌曲列表,例如。这样,重写就会消失,我的内存使用量将减少显著

My use-case is something like this: i have a menu with button images stored on a server. Whole screen is made of fragments (buttons, scrollbars, animations etc.). For example, when i click on a button, server sends me a multiple thumbnails of pictures stored in its storage, and i display them in ,for example, right half of the screen. On other button click, list of songs, videos, ebooks or something else are shown. I need to remove textures of picture thumbnails from memory and then show list of songs, for example. In this way, overwriting will disappear, and my memory usage will be significantly reduced.

我的OpenGL ES 2.0的实现是在Android平台,在这里整个工作在JNI层完成。没有复杂的图纸,只是解码PNG图像转换为纹理和纹理基本显示。

My openGL ES 2.0 implementation is on Android platform, where whole job is done in JNI layer. There is no complicated drawing, just decoding png images, converting to textures, and basic textures displaying.

推荐答案

您可以做沿着东西线引用计数来跟踪多少次相同的图像已被使用。当一个实例是完全闭塞或关闭屏幕,你递减引用计数,并以0引用删除所有的纹理。

You can do something along the lines of reference counting to keep track of how many times the same image has been used. When an instance is entirely occluded or off-screen, you decrement the reference count, and delete all the textures with 0 references.

引用计数可能是一样简单的std ::地图<纹理,诠释方式>

Reference counting could be as simple as a std::map<Texture, int>.

您闭塞支票可能只是为O(n ^ 2)AABB相交/测试遏制和反对屏幕的AABB一个额外的O(n)的测试。如果这不是你不够快,尝试像一个四叉树或<一个更好的数据结构href=\"http://conkerjo.word$p$pss.com/2009/06/13/spatial-hashing-implementation-for-fast-2d-collisions/\"相对=nofollow>空间散列。

Your occlusion check could just be an O(n^2) AABB intersection/containment test and an extra O(n) test against the screen's AABB. If that's not fast enough for you, try a better data structure like a quadtree or spatial hashing.

根据应用程序的设置方式,您还可以跟踪你的纹理的情况下,与一类智能指针并找出当你所有的隐藏的观点已被删除。

Depending on how your application is set up, you could also track instances of your texture with a type of smart pointer and figure out when all of your hidden views have been deleted.

话虽这么说,这可能是在浪费时间,除非你被VRAM量的设备上实际约束或正在接近它。加载/卸载从磁盘或网络位置的图像将是数量级比只是保持它VRAM如果您有它可用慢几个数量级。

That being said, this is probably a waste of time unless you're actually bound by the amount of VRAM on the device or getting close to it. Loading/unloading images from either disk or a network location is going to be orders of magnitude slower than just keeping it in VRAM if you have it available.

这篇关于找到并删除从内存中隐藏的纹理的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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