如何确定在Android上的OpenGL ES最大纹理内存 [英] How to determine maximum texture memory on Android OpenGL ES

查看:1262
本文介绍了如何确定在Android上的OpenGL ES最大纹理内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一篇Android的混合2D / 3D游戏,我不能确定我是多么的纹理内存可以使用。有没有办法在OpenGL ES以确定最大纹理内存?

I'm writing a mixed 2D/3D game on Android and I'm not able to determine how much texture memory I can use. Is there any way to determine maximum texture memory in OpenGL ES?

我有我自己的纹理缓存,想知道纹理内存的最大阈值。我使用的是做一个大致的估计 activityManager.getMemoryInfo(MI),但在某些设备上,当我尝试分配的纹理(和许多已经在内存中)的应用程序崩溃( EGL_BAD_ALLOC )。当我设置这个门槛较低值,似乎一切都OK。有没有人有什么想法?或最终如何确定纹理分配是不是崩溃不成功,

I have my own texture cache and want to know the maximum threshold of texture memory. I'm making an approximate estimation using activityManager.getMemoryInfo(mi), but on some devices when I try to allocate texture (and many more are already in memory) the application crashes (EGL_BAD_ALLOC). When I set this threshold to a lower value, everything seems to be ok. Does anyone have any idea? Or eventually how to determine that the texture allocation was unsuccessful, instead of crashing.

推荐答案

看来你正试图了解VRAM(显存)可用的大写金额。 的问题已经部分地回答。

It seems that you are trying to know the amout of VRAM (video RAM) available. The question has already been partially answered.

不过,VRAM的量不会确定有多少纹理也装不下了:这些的可COM pressed,因为其他应用程序VRAM的量能变化,而我们不知道有多少内存视频驱动程序使用。

However, the amount of VRAM does not determine how much textures will fit in it: these ones can be compressed, the amount of VRAM can change because of another app, and we doesn't know how much memory the video driver uses.

方法1

从这个话题,你可以得到的纹理单元的最大数量;这意味着最大数目可以绑定同时

From this topic, you can get the maximum amount of texture units; that means the max number that can be bound at the same time:

int[] maxSize = new int[1];
gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxSize, 0);

而从这个另外一个,您可以检索最大纹理大小:

And from this other one, you can retrieve the max texture size:

int[] maxNum = new int[1];
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, maxNum, 0);

所以,从逻辑上讲,你至少可以配合(MAXSIZE [0] * MAXSIZE [0])* MAXNUM [0]没有问题的VRAM像素。即使VRAM空间用完,Android将管理它对于我们(的可以的包括一个Java异常或者是Dalvik虚拟机崩溃)。

So, logically, you can at least fit (maxSize[0]*maxSize[0])*maxNum[0] pixels in the VRAM without problems. Even if the VRAM runs out of space, Android will manage it for us (may include a Java exception or a Dalvik VM crash).

总之,你可能不会取决于VRAM量或可用像素调整纹理'大小;这是可行的,但不能盈利和(也许)难以实施。 有一种方法更好的方式来做到这一点:

Anyway, you're probably not going to adjust your textures' size depending on the VRAM amount or the available pixels; It's doable but not profitable and (maybe) hard to implement. There's a WAY better way to do this:

方法2

99%的时间,VRAM的图形芯片上的分数为正比于屏幕尺寸。因此,使用屏幕的DPI(LDPI,MDPI,华电国际,xhdpi)确定纹理的版本(大小)来加载(试验不同的(真正的)设备),所以你是安全的有关将是适合该设备?。

99% of the time, the amout of VRAM on the graphics chip is proportional to the screen size. Thus, use the screen's DPI (ldpi, mdpi, hdpi, xhdpi) to determine which version (size) of the texture to load (experiment with different (real) devices), so you're safe about the "will it fit for that device?".

这篇关于如何确定在Android上的OpenGL ES最大纹理内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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