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. If I make OpenGL ES calls from the thread that contains the current context I am able to render as normal. 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.
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. This uses a class called SDLActivity to communicate with android and native c/c++ code.
The question is how can I create multiple SDL contexts so that I can still make OpenGL ES calls from another thread?
EDIT: Here is where I create the SDL context in my code:
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, ¤tDisplayMode);
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.
As you can see a render call is made within the thread of the OpenGL context created by SDL. So how do I create a shared context using SDL, since when I make OpenGL ES calls outside this thread I get the error. 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.