Java – sharing resources between OpenGL contexts on Android

I tried to use multiple EGL contexts to load textures outside my main thread After my eglcreatecontext call, I received an EGL_ BAD_ Context error

On my android opengl. Inside the renderer

public void onSurfaceCreated (javax.microedition.khronos.opengles.GL10 gl,EGLConfig config) {
    // ...
    EGLContext sharedContext = egl.getCurrentContext();
    EGLDisplay display = eglGetCurrentDisplay();
    eglCreateContext(display,config,sharedContext,new int[] { EGL_CONTEXT_CLIENT_VERSION,2 } );
}

EGL_ BAD_ Context guides me through the document here

This is me at EGL_ CONTEXT_ CLIENT_ The reason added in the version parameter, but it doesn't seem to work

What I see is that even if I receive this error, the context seems to be semi - valid I can use it on another thread

egl.eglMakeCurrent(display,EGL10.EGL_NO_SURFACE,context);

After that, creating a texture on this thread does not cause an error But I do see that texture names are not shared, and each thread seems to count from 0 itself

My next assumption is that I need to share surfaces between contexts However, if I enter my eglmakecurrent through the same surface from the original context, I fail completely

E/AndroidRuntime(3210): java.lang.IllegalArgumentException
E/AndroidRuntime(3210):     at com.google.android.gles_jni.EGLImpl._eglCreateContext(Native Method)
E/AndroidRuntime(3210):     at com.google.android.gles_jni.EGLImpl.eglCreateContext(EGLImpl.java:54)

I feel like I'm almost there. Does anyone know what's missing?

Solution

It turns out that thanks for some help from this question:

My secondary background needs a surface It differs from the surface of the original context

I need to use eglcreatepuffersurface to create a new surface The reason why my previous attempt failed is that it defaults to width and height of 0 By setting it to 1 × On the surface, it works perfectly

egl.eglCreatePbufferSurface(display,new int[] { EGL10.EGL_WIDTH,1,EGL10.EGL_HEIGHT,EGL10.EGL_NONE });
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>