Answer the question
In order to leave comments, you need to log in
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(); // шейдеры
}
void GLRender::OnResume(SDL_GLContext _ctx)
{
if(m_glContext != _ctx) // SDL_GLContext - это указатель
{
DeinitAll(); // удалить к чертям все текстуры, буфферы, шейдеры, сбросить все в 0
Init(); // к этому моменту SDL_GL_GetCurrentContext() вернет то же самое, что и _ctx в этом методе
}
}
void GLRender::Flip()
{
// рисование в текстуры offscreen
...
glBindFramebuffer(GL_FRAMEBUFFER, m_defaultFramebuffer);
m_offscreenTexture->Draw(); // отрисовка оффскрина на экран
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question