Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] opengl – SDL2 contexts don’t share objects (Android porting)

Posted on November 14, 2022

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

READ  [ANSWERED] arduino - Bluetooth Low Energy (between ESP32 and Android smartphone): Data transmission quite slow
Powered by Inline Related Posts

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.

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress