Solution 1 :
Call SDL_GL_SetAttribute()
before SDL_CreateWindow()
, not after:
SDL_GL_SetAttribute()
:This function sets the OpenGL attribute attr to value. The requested attributes should be set before creating an OpenGL window. You should use SDL_GL_GetAttribute() to check the values after creating the OpenGL context, since the values obtained can differ from the requested ones.
Problem :
I use SDL2 to create and use contexts on this way (now is without check):
const int init_result = SDL_Init(SDL_INIT_EVERYTHING);
window = SDL_CreateWindow(
title.data(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
window_width, window_height,
::SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE);
// setting context attributes
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, 2);
// 1th context - main
gl_context = SDL_GL_CreateContext(window);
// 2th is using for loading textures while 1th works
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
gl_context_sub = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context);
In adds, 1th context creates textures, draws it while 2th one is loading other textures for the game process. Swap context function:
static int load_gl_in_background(void *foo) {
SDL_GL_MakeCurrent(window, gl_context_sub);
// here foo is calling - loading textures
SDL_GL_MakeCurrent(window, gl_context);
return 0;
}
SDL_Thread *thread =
SDL_CreateThread(load_gl_in_background, "SDL thread", (void *)foo);
Yes, that’s work on desktop well with es context, but when I start to port my game on Android, I have the sharing objects problem. The textures, loaded by 2th context, after making context current is missing. I’m sure, loop is working, all process are fine (sounds, not loaded textures rendering …).
Android debug says only E/libEGL: eglMakeCurrentImpl:1321 error 3002 (EGL_BAD_ACCESS).
I do think the trouble is that I should use special SurfaceView for the each context, but I hope it could be solved by flags, attributes in C++ code.
For porting I used SDL
I need any ideas. Thanks!
Comments
Comment posted by Mariya Shpakovskaya
SDL_Sets have been removed on the top (before the window init). Now I have the same trouble on the desktop (es). Core is fine. Ty for @genpfault
Comment posted by genpfault
Which OpenGL ES implementation are you using on desktop? ANGLE? Intel’s ICD?
Comment posted by Mariya Shpakovskaya
I set it before, and now I have problems on the desktop too (from SDL_Error()) – Cannot change context: Unable to make EGL context current (call to eglMakeCurrent failed, reporting an error of EGL_BAD_ACCESS).
Comment posted by Mariya Shpakovskaya
I really sure that when I use MakeCurrent firstly (on the init block), I dont have tha problem. Maybe it’ll help. Ty!
Comment posted by keltar
@MariyaShpakovskaya you think your desktop system supports ES profile at all? Also your last context switch is unlikely to work – context could be current only on one thread at any moment of time – probably your error message originates there. That being said, multicontext usually considered a minefield, as it is poorly tested and even when it works performance is lacking.