问题描述
我正在实现自己的EGLConfigChooser
传递给setEGLConfigChooser()
,以便根据我对应用程序的需求为当前设备选择最佳的可用配置.
I'm implementing my own EGLConfigChooser
to pass to setEGLConfigChooser()
in order to select the best available configuration for the current device according to the needs I have for the application.
更具体地说,我要查询所有可用的配置,然后选择最大深度缓冲区大小的配置(并且在那些具有相同深度缓冲区大小的配置中,我想要最大颜色深度的配置),下面是代码墙:
To be more specific I'm querying all the available configurations and selecting the one with the biggest depth buffer size (and between those with the same depth buffer size I want the one with the biggest colour depth), wall of code follows:
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
{
//Querying number of configurations
int[] num_conf = new int[1];
egl.eglGetConfigs(display, null, 0, num_conf); //if configuration array is null it still returns the number of configurations
int configurations = num_conf[0];
//Querying actual configurations
EGLConfig[] conf = new EGLConfig[configurations];
egl.eglGetConfigs(display, conf, configurations, num_conf);
EGLConfig result = null;
for(int i = 0; i < configurations; i++)
{
Log.v("EGLConfigChooser", "Configuration #" + i );
print(egl, display, conf[i]);
result = better(result, conf[i], egl, display);
}
Log.v("EGLConfigChooser", "Chosen EGLConfig:");
print(egl, display, result);
return result;
}
/**
* Returns the best of the two EGLConfig passed according to depth and colours
* @param a The first candidate
* @param b The second candidate
* @return The chosen candidate
*/
private EGLConfig better(EGLConfig a, EGLConfig b, EGL10 egl, EGLDisplay display)
{
if(a == null) return b;
EGLConfig result = null;
int[] value = new int[1];
egl.eglGetConfigAttrib(display, a, EGL10.EGL_DEPTH_SIZE, value);
int depthA = value[0];
egl.eglGetConfigAttrib(display, b, EGL10.EGL_DEPTH_SIZE, value);
int depthB = value[0];
if(depthA > depthB)
result = a;
else if(depthA < depthB)
result = b;
else //if depthA == depthB
{
egl.eglGetConfigAttrib(display, a, EGL10.EGL_RED_SIZE, value);
int redA = value[0];
egl.eglGetConfigAttrib(display, b, EGL10.EGL_RED_SIZE, value);
int redB = value[0];
if(redA > redB)
result = a;
else if(redA < redB)
result = b;
else //if redA == redB
{
//Don't care
result = a;
}
}
return result;
}
(打印方法将EGLConfig值打印到Logger)
(The print method prints EGLConfig values to the Logger)
现在,它似乎可以正常工作,它选择了以下配置:
Now, it appears to work fine, it selects the following configuration:
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): Chosen EGLConfig:
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_RED_SIZE = 8
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_BLUE_SIZE = 8
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_GREEN_SIZE = 8
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_ALPHA_SIZE = 8
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_DEPTH_SIZE = 24
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_ALPHA_FORMAT = 24
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_ALPHA_MASK_SIZE = 0
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_STENCIL_SIZE = 8
问题是,使用此配置时,电话屏幕会变成绿色并带有紫色伪影(场景应该是黑色的,上面有木桌),它会完全挂起并停止响应任何类型的输入,我所能做的是通过调试器终止进程,然后重启设备(?!!).
The problem is that when this configuration is used the phone screen turns green with purple artifacts (the scene is supposed to be black with a wooden table), it completely hangs and stops responding to any kind of input, all I can do is to terminate my process via the debugger and when I do so the device reboots(?!!).
eglGetConfigs
为何返回一个导致此类问题的配置?你们中是否有人经历过类似的事情或可以在我的代码中找到某种缺陷?我仔细检查了一下,但对我来说似乎没问题(它受到 http的启发://brandnewreality.com/blog/android-egl-querying-your-gl-driver )
How come that eglGetConfigs
is returning a configuration which causes this kind of issues? Has anyone of you experienced something similar or can find some kind of flaw in my code? I double checked it but it looks ok to me (it has been inspired by http://brandnewreality.com/blog/android-egl-querying-your-gl-driver )
感谢您的帮助.
推荐答案
尝试添加:
getHolder().setFormat(PixelFormat.RGBA_8888);
getHolder( ).setFormat( PixelFormat.RGBA_8888 );
在设置GL配置选择器后,对您的Surfaces构造函数.基本上我在选择格式8,8,8,0,0,0(R8,G8,B8,A0,Z0,Stencil0)时遇到崩溃,直到我添加了该行...
To your surfaces constructor, after setting the GL config chooser. Basically I was getting a crash when selecting format 8,8,8,0,0,0 (R8, G8, B8, A0, Z0, Stencil0) until I added that line...
史蒂夫
这篇关于HTC Desire上的EGLConfig,可用配置将设备挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!