简体   繁体   中英

Can't find the cause of an Open GL ES error

I'm using Open GL ES 3.1 in my app and I'm facing a problem I haven't be able to fix so far.

When I try to create a 3D object, depending on where the constructor is called, either the object is correctly created (and can be displayed successfully) or the app crashes because shaders can't be created (call to glCreateShader() returns 0). This lets me say my shader codes are correct.

When I try to get information about the error with glGetError() , I receive GL_NO_ERROR , even when the returned shader is 0!

I have also added setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS) but it doesn't give me any clue.

I supposed the problem could be caused by concurrent access to the Open GL environment and I had my drawing and animating methods synchronized but it didn't help either.

According to this question Compile GLSL shader asynchronously or in a different thread on Android , I'm pretty sure the problem comes from the impossibility to use the main Open GL environment in a separate thread. But I can't be sure of that because the code given uses class I can't find in the Open GL ES 3.1 library ( EGLContext2 , eglCreateContext , eglCreatePbufferSurface ).

Does anyone know how I can access the Open GL ES environment from my second thread?

You need to create a second EGL context for the second thread, and place it inside the same share group as the the first context so they can share resources. You do this by providing the first context as the share_context parameter when calling eglCreateContext() for the second context.

But I can't be sure of that because the code given uses class I can't find in the Open GL ES 3.1 library ( EGLContext2 , eglCreateContext , eglCreatePbufferSurface ).

As the function prefix might give away, for context creation you need the EGL library not the GL library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM