简体   繁体   English

E / libEGL:调用OpenGL ES API,没有当前上下文(每个线程记录一次) - Android / SDL

[英]E/libEGL: call to OpenGL ES API with no current context (logged once per thread) - Android/SDL

I am aware that different versions of this question have been answered before and I have read alot of them. 我知道此问题的不同版本之前已经得到解答,我已经阅读了很多这些版本。 Yet none seems to help me with my problem. 然而似乎没有人帮助我解决我的问题。

I am using SDL to create a context to hold OpenGL ES. 我正在使用SDL创建一个上下文来保存OpenGL ES。 If I make OpenGL ES calls from the thread that contains the current context I am able to render as normal. 如果我从包含当前上下文的线程进行OpenGL ES调用,我可以正常渲染。 However if I make an OpenGL ES call from another thread I'm unable to do any rendering and I get the error message in the title. 但是,如果我从另一个线程进行OpenGL ES调用,我无法进行任何渲染,并且我在标题中收到错误消息。

E/libEGL: call to OpenGL ES API with no current context (logged once per thread)

I am using the android project template provided in SDL source package. 我正在使用SDL源包中提供的android项目模板。 This uses a class called SDLActivity to communicate with android and native c/c++ code. 这使用一个名为SDLActivity的类与android和本机c / c ++代码进行通信。

The question is how can I create multiple SDL contexts so that I can still make OpenGL ES calls from another thread? 问题是如何创建多个SDL上下文,以便我仍然可以从另一个线程进行OpenGL ES调用?

EDIT: Here is where I create the SDL context in my code: 编辑:这是我在我的代码中创建SDL上下文的地方:

    int SDL_main(int argc, char **argv)
    {
       window = nullptr;

       if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
          return false;


       SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

       SDL_DisplayMode currentDisplayMode;
       int success = SDL_GetCurrentDisplayMode(0, &currentDisplayMode);
       assert(success == 0);
       WIDTH = currentDisplayMode.w;
       HEIGHT = currentDisplayMode.h;

        window = SDL_CreateWindow(Name.c_str(),
        SDL_WINDOWPOS_CENTERED,
        SDL_WINDOWPOS_CENTERED,
        WIDTH, HEIGHT, SDL_WINDOW_OPENGL);
        assert(window != nullptr);

        SDL_SetHint("SDL_HINT_ORIENTATIONS", "LandscapeRight LandscapeLeft");

        context = SDL_GL_CreateContext(window);
        assert(context != nullptr);

    glGetError();   

    //OpenGL configuration
    glViewport(0, 0, WIDTH, HEIGHT);
    glEnable(GL_CULL_FACE);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    //initialise 

    obj.functionA();

    obj.functionB();    

    SDL_SetEventFilter(FilteringEvents, NULL);



    SDL_Event event;
    shouldQuit = false; 
    while (!shouldQuit)
    {
        SDL_PollEvent(event);

        //Render
        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);


        obj.Render();

        SDL_GL_SwapWindow(window);

    }

    SDL_Quit();

    return 0;
}

For the sake of simplicity I have included only the context creation of Opengl ES via SDL, and a few simply obj function calls such as the call to render. 为了简单起见,我仅包括通过SDL创建Opengl ES的上下文,以及一些简单的obj函数调用,例如对render的调用。

As you can see a render call is made within the thread of the OpenGL context created by SDL. 如您所见,在SDL创建的OpenGL上下文的线程内进行了渲染调用。 So how do I create a shared context using SDL, since when I make OpenGL ES calls outside this thread I get the error. 那么如何使用SDL创建共享上下文,因为当我在此线程之外进行OpenGL ES调用时,我得到了错误。 Please note, that I dont have this problem when I run the same code on my PC, so I'm sure its a issue peculiar to Android. 请注意,当我在PC上运行相同的代码时,我没有这个问题,所以我确定它是Android特有的问题。

Traditionally, OpenGL ES applications only render to one surface from one thread. 传统上,OpenGL ES应用程序仅从一个线程渲染到一个表面。

A rendering thread is one CPU thread associated with one graphics context. 呈现线程是与一个图形上下文相关联的一个CPU线程。 By default, each graphics context will not be able to access the resources (textures, shaders and vertex buffers) of another context. 默认情况下,每个图形上下文都无法访问另一个上下文的资源(纹理,着色器和顶点缓冲区)。 For this reason, shared contexts are used so one or more background loading threads can access the resources of a primary thread. 出于这个原因,使用共享上下文,因此一个或多个后台加载线程可以访问主线程的资源。

I think your problem is EGL rendering context doesn't bind to the current rendering thread. 我认为你的问题是EGL渲染上下文没有绑定到当前的渲染线程。

Take a look at eglCreateContext to know how to make shared context and eglMakeCurrent to bind EGL rendering context to the current rendering thread. 查看eglCreateContext以了解如何创建共享上下文和eglMakeCurrent以将EGL呈现上下文绑定到当前呈现线程。


Using SDL with OpenGL ES 将SDL与OpenGL ES结合使用

This can be accomplished with SDL_GetWMInfo() call to get the required handles, like: 这可以通过SDL_GetWMInfo()调用来完成,以获取所需的句柄,如:

SDL_SysWMinfo sysWmInfo;
SDL_VERSION(&sysWmInfo.version);
SDL_GetWMInfo(&sysWmInfo);
eglDisplay = eglGetDisplay((EGLNativeDisplayType)sysWmInfo.info.x11.display);
...
eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (NativeWindowType)sysWmInfo.info.x11.window, NULL);

Or, 要么,

Did you try to use SDL_GL_MakeCurrent ? 您是否尝试使用SDL_GL_MakeCurrent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用没有当前上下文的OpenGL ES API(每个线程记录一次) - call to OpenGL ES API with no current context (logged once per thread) 在没有当前上下文的情况下调用OpenGL ES API(每个线程记录一次)-OpenGL ES - call to OpenGL ES API with no current context (logged once per thread) - OpenGL ES Android 2.2 Webview导致OpenGL ES API没有当前上下文(每个线程记录一次) - Android 2.2 Webview causes OpenGL ES API with no current context (logged once per thread) 错误/libEGL(206):在没有当前上下文的情况下调用 OpenGL ES API - ERROR/libEGL(206): call to OpenGL ES API with no current context E / libEGL:称为未实现的OpenGL ES API - E/libEGL﹕ called unimplemented OpenGL ES API libEGL称为未实现的OpenGL ES Api Android - libEGL called unimplemented OpenGL ES Api Android 在Android中使用imageloader时“在没有当前上下文的情况下调用OpenGL ES API” - “call to OpenGL ES API with no current context” while using imageloader in android ARToolkit-在没有当前上下文的情况下调用OpenGL ES API - ARToolkit - call to OpenGL ES API with no current context 在没有当前上下文的情况下调用OpenGL ES API - Call to OpenGL ES API with no current context Android NDK OpenGL glDeleteTextures导致错误:在没有当前上下文的情况下调用OpenGL ES API - Android NDK OpenGL glDeleteTextures causes error: call to OpenGL ES API with no current context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM