mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-19 06:26:35 +00:00
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:
parent
8364d1ca6c
commit
2e1ac0f683
@ -294,19 +294,28 @@ static void ImGui_ImplSDL2_CreateViewport(ImGuiViewport* viewport)
|
|||||||
// FIXME-PLATFORM
|
// FIXME-PLATFORM
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
ImGuiPlatformDataSDL2* main_viewport_data = (ImGuiPlatformDataSDL2*)main_viewport->PlatformUserData;
|
ImGuiPlatformDataSDL2* main_viewport_data = (ImGuiPlatformDataSDL2*)main_viewport->PlatformUserData;
|
||||||
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
|
|
||||||
SDL_GL_MakeCurrent(main_viewport_data->Window, main_viewport_data->GLContext);
|
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
|
// We don't enable SDL_WINDOW_RESIZABLE because it enforce windows decorations
|
||||||
Uint32 sdl_flags = 0;
|
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 |= SDL_WINDOW_HIDDEN;
|
||||||
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? SDL_WINDOW_BORDERLESS : 0;
|
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? SDL_WINDOW_BORDERLESS : 0;
|
||||||
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? 0 : SDL_WINDOW_RESIZABLE;
|
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? 0 : SDL_WINDOW_RESIZABLE;
|
||||||
data->Window = SDL_CreateWindow("No Title Yet",
|
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);
|
(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);
|
data->GLContext = SDL_GL_CreateContext(data->Window);
|
||||||
|
if (use_opengl && backup_context)
|
||||||
|
SDL_GL_MakeCurrent(data->Window, backup_context);
|
||||||
viewport->PlatformHandle = (void*)data->Window;
|
viewport->PlatformHandle = (void*)data->Window;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,7 +413,7 @@ static void ImGui_ImplSDL2_SwapBuffers(ImGuiViewport* viewport)
|
|||||||
ImGuiPlatformDataSDL2* data = (ImGuiPlatformDataSDL2*)viewport->PlatformUserData;
|
ImGuiPlatformDataSDL2* data = (ImGuiPlatformDataSDL2*)viewport->PlatformUserData;
|
||||||
if (data->GLContext)
|
if (data->GLContext)
|
||||||
{
|
{
|
||||||
SDL_GL_MakeCurrent(data->Window, data->GLContext); // FIXME-PLATFORM2
|
SDL_GL_MakeCurrent(data->Window, data->GLContext);
|
||||||
SDL_GL_SwapWindow(data->Window);
|
SDL_GL_SwapWindow(data->Window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,11 +125,11 @@ int main(int, char**)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
|
ImGui::Render();
|
||||||
SDL_GL_MakeCurrent(window, gl_context);
|
SDL_GL_MakeCurrent(window, gl_context);
|
||||||
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
||||||
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
|
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
ImGui::Render();
|
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
ImGui::RenderAdditionalViewports();
|
ImGui::RenderAdditionalViewports();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user