Examples: SDL+Metal example.

This commit is contained in:
coding_jackalope
2020-02-07 12:48:59 -08:00
committed by omar
parent d16c87a5b1
commit f346b4b302
4 changed files with 271 additions and 0 deletions

View File

@ -212,6 +212,11 @@ bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window)
return ImGui_ImplSDL2_Init(window);
}
bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window)
{
return ImGui_ImplSDL2_Init(window);
}
void ImGui_ImplSDL2_Shutdown()
{
g_Window = NULL;
@ -359,3 +364,31 @@ void ImGui_ImplSDL2_NewFrame(SDL_Window* window)
// Update game controllers (if enabled and available)
ImGui_ImplSDL2_UpdateGamepads();
}
void ImGui_ImplSDL2_NewFrame_Metal(SDL_Window* window)
{
ImGuiIO& io = ImGui::GetIO();
IM_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built! It is generally built by the renderer back-end. Missing call to renderer _NewFrame() function? e.g. ImGui_ImplMetal_NewFrame().");
// Setup display size (every frame to accommodate for window resizing)
SDL_Renderer* renderer = SDL_GetRenderer(window);
int w, h;
int display_w, display_h;
SDL_GetWindowSize(window, &w, &h);
SDL_GetRendererOutputSize(renderer, &display_w, &display_h);
io.DisplaySize = ImVec2((float)w, (float)h);
if (w > 0 && h > 0)
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
// Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
static Uint64 frequency = SDL_GetPerformanceFrequency();
Uint64 current_time = SDL_GetPerformanceCounter();
io.DeltaTime = g_Time > 0 ? (float)((double)(current_time - g_Time) / frequency) : (float)(1.0f / 60.0f);
g_Time = current_time;
ImGui_ImplSDL2_UpdateMousePosAndButtons();
ImGui_ImplSDL2_UpdateMouseCursor();
// Update game controllers (if enabled and available)
ImGui_ImplSDL2_UpdateGamepads();
}