Android:GLES20:调用未实现的 OpenGL ES API
在尝试由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 虚拟设备和使用 Android 2.2.1 的 HTC Wildfire 上尝试了该示例。
我很感激任何帮助
I am getting a "Called unimplemented OpenGL ES API" error, when trying the GLES20 Sample, provided by developer.android.com. I modified the sample, though.
The reason was because
I got an IllegalArgumentException in GLSurfaceView.BaseConfigChooser.chooseconfig, so i replacedmGLSurfaceView.setEGLContextClientVersion( 2 );
The new 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 );
}
The "Called unimplemented OpenGL ES API" error occurs for example atGLES20.glCreateShader;
or GLES20.glShaderSource
.
I thought, maybe to check the version, so I calledgl.glGetString( GLES20.GL_VERSION );
inpublic void onSurfaceCreated( GL10 gl, EGLConfig config )
.
glGetString returned "OpenGL ES-CM 1.0". OnSurfaceCreated is called after choosing the config and creating the context, so I really do not understand, why glGetString returns "OpenGL ES-CM 1.0".
I am using Android 2.2 API and tried the sample on a Android 2.2 Virtual device and on a HTC Wildfire, with Android 2.2.1.
I appreciate any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅这篇文章 -
android 中的 triangle opengl
正如那里提到的,模拟器不支持 GL2,但正如那篇文章提到的,它在实际设备上对我有用。
See this post -
triangle opengl in android
As mentioned there, the emulators do not support GL2, but as that post mentions, it worked for me on an actual device.
这不是一个错误,而是一个声明。它只是告诉您您的目标不支持 OpenGL ES 版本 2.0。
This is not an error, but a statement. It simply tells you that your target doesn't support OpenGL ES version 2.0.
这可能是因为您正在使用我们在渲染器实现中的 onSurfaceCreated()、onSurfaceChanged() 和 onDrawFrame() 中作为参数获取的 GL10 实例。由于您打算使用 OpenGL ES 2.0,因此我们可以而且可能不会使用该实例,而是使用替代方案。还有其他选择!这就是我们在网络上的代码中看到这些参数名称和未使用或类似的原因!
It may be because you are using the GL10 instance we are getting as a parameter in onSurfaceCreated(), onSurfaceChanged() and onDrawFrame() in your Renderer implementation. Since you intend to use OpenGL ES 2.0, we can and probably not use the instance and use an alternative instead. There are alternatives! This is the reason we see those parameters names and unused or similar in codes across the net!