M
M
Manburger2016-10-15 22:15:18
Android
Manburger, 2016-10-15 22:15:18

How to correctly set up an Android EGL context after it has been removed on collapse?

There is a native application (c++ ndk SDL2) with graphics on Open GLES2.
On some devices, I delete the EGL context WHEN FOLDING AND EXPANDING and creating a new one, after which I get a pointer to it in the native part and recreate all the textures and buffers.
Everything is fine, but nothing is displayed on the screen. Shaders compile without problems, opengl trace shows that everything is working fine, but the screen is black, as if I draw the application in the offscreen buffer, and then display it ... but not on the screen ... strange.
In general, if anyone can poke my nose into an error or share a piece of plus or at worst java code with the correct re-creation of the context and off-screen buffers, I will be very grateful. If someone has come across this while working with SDL2, it will be even cooler.
Render initialization:

void GLRender::Init()
{
...
SDL_GLContext cur_ctx = SDL_GL_GetCurrentContext();

if (cur_ctx == nullptr)
{
m_glContext = SDL_GL_CreateContext(_window);
}
else
{
m_glContext = cur_ctx;
}
SDL_GL_MakeCurrent(_window, m_glContext);
...
GLint default_buffer;	GL_CHECK(glGetIntegerv(GL_FRAMEBUFFER_BINDING, &default_buffer));
m_defaultFramebuffer = default_buffer; // индекс экранного буффера

InitBuffers(); // буфферы для эффектов
InitOffscreenBuffers(); // оффскрин буфферы
InitShaders(); // шейдеры
}

At the first initialization, I do not have a current context and I create a new one. Everything is ok, everything works.
After I collapse and expand - something like this happens
void GLRender::OnResume(SDL_GLContext _ctx)
{
if(m_glContext != _ctx) // SDL_GLContext - это указатель
{
DeinitAll(); // удалить к чертям все текстуры, буфферы, шейдеры, сбросить все в 0
Init(); // к этому моменту SDL_GL_GetCurrentContext() вернет то же самое, что и _ctx в этом методе
}
}

When initialized on the Java return, the wrapper already throws a NEW context to me if it was not possible to save the original one. I set it as current and do absolutely all the same initializations as on the first run. Everything is going well, glGetError is checked at each step and everything is fine there too, the shaders were rendered and the drawing process went ... but not to the screen ...
in m_defaultFramebuffer - as in the first run, it is 0, actually - the screen buffer index.
void GLRender::Flip()
{
// рисование в текстуры offscreen
...
glBindFramebuffer(GL_FRAMEBUFFER, m_defaultFramebuffer);
m_offscreenTexture->Draw(); // отрисовка оффскрина на экран
}

Result - black screen

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question