Android: GLES20: Called unimplemented OpenGL ES API

匿名 (未验证) 提交于 2019-12-03 02:03:01

问题:

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 replaced mGLSurfaceView.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 at GLES20.glCreateShader; or GLES20.glShaderSource.

I thought, maybe to check the version, so I called gl.glGetString( GLES20.GL_VERSION ); in public 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

回答1:

You need to enable OpenGL ES 2.0 in your Android app.

First, in your AndroidManifest.xml, ensure you have the following:

Second, create a subclass of GLSurfaceView like this:

public class CustomView extends GLSurfaceView {     final CustomRenderer renderer;     CustomView(Context context) {         super(context);         setEGLContextClientVersion(2); // This is the important line         renderer = new CustomRenderer();         setRenderer(renderer);     } } 

FOR NDK

Ensure you the choose attribute and context attribute lists:

const EGLint attribs[] = {     EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,     EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,     EGL_BLUE_SIZE,       8,     EGL_GREEN_SIZE,      8,     EGL_RED_SIZE,        8,     EGL_NONE }; eglChooseConfig(dpy, attribs, &config, 1, &numConfigs);   const EGLint ContextAttribList[] = {     EGL_CONTEXT_CLIENT_VERSION, 2,     EGL_NONE }; context = eglCreateContext(GLapp.dpy, config, EGL_NO_CONTEXT, ContextAttribList); 


回答2:

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.



回答3:

This is not an error, but a statement. It simply tells you that your target doesn't support OpenGL ES version 2.0.



回答4:

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 OpwnGL ES 2.0, we can and probably not use the instance and use an alternative instead. There are alternatives!This is the reasons we see those parameters names and unUsed or similar in codes across the net!



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!