【发布时间】:2011-05-08 07:59:46
【问题描述】:
在尝试由 developer.android.com 提供的 GLES20 示例时,我收到“调用未实现的 OpenGL ES API”错误。不过,我修改了示例。
原因是因为
我在 GLSurfaceView.BaseConfigChooser.chooseconfig 中遇到了 IllegalArgumentException,所以我替换了
mGLSurfaceView.setEGLContextClientVersion( 2 );
新的 OnCreateMethod:
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
mGLSurfaceView = new GLSurfaceView( this );
mGLSurfaceView.setEGLConfigChooser( new EGLConfigChooser()
{
@Override
public EGLConfig chooseConfig( EGL10 egl, EGLDisplay display )
{
EGLConfig[] configs = new EGLConfig[1];
int[] num_config = new int[1];
boolean check = false;
int[] configSpec = { EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE };
check = egl.eglInitialize( display, new int[] { 2, 0 } );
if ( !check )
return null;
check = false;
check = egl.eglChooseConfig( display, configSpec, configs, 1, num_config );
if ( !check )
return null;
return configs[0];
}
} );
mGLSurfaceView.setEGLContextFactory( new EGLContextFactory()
{
@Override
public void destroyContext( EGL10 egl, EGLDisplay display, EGLContext context )
{
egl.eglDestroyContext( display, context );
}
@Override
public EGLContext createContext( EGL10 egl, EGLDisplay display, EGLConfig eglConfig )
{
int[] attrib_list = new int[]{EGL10.EGL_VERSION, 2, EGL10.EGL_NONE};
EGLContext context = egl.eglCreateContext( display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list );
return context;
}
});
mGLSurfaceView.setRenderer( new GLES20TriangleRenderer( this ) );
setContentView( mGLSurfaceView );
}
“调用未实现的 OpenGL ES API”错误发生在例如
GLES20.glCreateShader; 或 GLES20.glShaderSource。
我想,也许是为了检查版本,所以我打电话给
gl.glGetString( GLES20.GL_VERSION ); 在
public void onSurfaceCreated( GL10 gl, EGLConfig config )。
glGetString 返回“OpenGL ES-CM 1.0”。 OnSurfaceCreated 是在选择配置并创建上下文后调用的,所以我真的不明白,为什么 glGetString 返回“OpenGL ES-CM 1.0”。
我正在使用 Android 2.2 API,并在 Android 2.2 虚拟设备和 HTC Wildfire 上使用 Android 2.2.1 尝试了该示例。
感谢您的帮助
【问题讨论】:
-
我对 GL ES 1.1/2.0 不太熟悉,但最好非常清楚模拟器并不能很好地实现它们 AFAIK。你最终可以得到可以在设备上运行但不能在模拟器上运行的代码。