Viewport, Platform: SDL: Makes the CreateViewport function restore current GL context so in theory it is free from side-effect. That said, it seems like there is a bug in SDL because our CreateViewport (currently in Render(), not for long) have affect a jerky side-effect if SDL_GL_MakeCurrent() is called before Render(). (#1542)

This commit is contained in:
omar 2018-03-15 19:25:23 +01:00
parent 8364d1ca6c
commit 2e1ac0f683
2 changed files with 15 additions and 6 deletions

View File

@ -294,19 +294,28 @@ static void ImGui_ImplSDL2_CreateViewport(ImGuiViewport* viewport)
// FIXME-PLATFORM
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
ImGuiPlatformDataSDL2* main_viewport_data = (ImGuiPlatformDataSDL2*)main_viewport->PlatformUserData;
bool use_opengl = (main_viewport_data->GLContext != NULL);
SDL_GLContext backup_context = NULL;
if (use_opengl)
{
backup_context = SDL_GL_GetCurrentContext();
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
SDL_GL_MakeCurrent(main_viewport_data->Window, main_viewport_data->GLContext);
}
// We don't enable SDL_WINDOW_RESIZABLE because it enforce windows decorations
Uint32 sdl_flags = 0;
sdl_flags |= main_viewport_data->GLContext ? SDL_WINDOW_OPENGL : SDL_WINDOW_VULKAN;
sdl_flags |= use_opengl ? SDL_WINDOW_OPENGL : SDL_WINDOW_VULKAN;
sdl_flags |= SDL_WINDOW_HIDDEN;
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? SDL_WINDOW_BORDERLESS : 0;
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? 0 : SDL_WINDOW_RESIZABLE;
data->Window = SDL_CreateWindow("No Title Yet",
(int)viewport->PlatformOsDesktopPos.x, (int)viewport->PlatformOsDesktopPos.y, (int)viewport->Size.x, (int)viewport->Size.y, sdl_flags);
if (main_viewport_data->GLContext)
if (use_opengl)
data->GLContext = SDL_GL_CreateContext(data->Window);
if (use_opengl && backup_context)
SDL_GL_MakeCurrent(data->Window, backup_context);
viewport->PlatformHandle = (void*)data->Window;
}
@ -404,7 +413,7 @@ static void ImGui_ImplSDL2_SwapBuffers(ImGuiViewport* viewport)
ImGuiPlatformDataSDL2* data = (ImGuiPlatformDataSDL2*)viewport->PlatformUserData;
if (data->GLContext)
{
SDL_GL_MakeCurrent(data->Window, data->GLContext); // FIXME-PLATFORM2
SDL_GL_MakeCurrent(data->Window, data->GLContext);
SDL_GL_SwapWindow(data->Window);
}
}

View File

@ -125,11 +125,11 @@ int main(int, char**)
}
// Rendering
ImGui::Render();
SDL_GL_MakeCurrent(window, gl_context);
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
ImGui::RenderAdditionalViewports();