From 21b9e42964cfaa44b949b701fea37f2e6012e319 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Mon, 10 Feb 2020 16:13:29 +0200 Subject: [PATCH] Minor fixes to example_sdl_metal and a changelog entry. Add example_sdl_metal to CI builds. Closes #3017. --- .github/workflows/build.yml | 3 +++ docs/CHANGELOG.txt | 9 +++++++ examples/README.txt | 6 ++++- examples/example_glfw_metal/main.mm | 8 +++---- examples/example_glfw_opengl2/main.cpp | 2 +- examples/example_glfw_opengl3/main.cpp | 2 +- examples/example_sdl_directx11/main.cpp | 2 +- examples/example_sdl_metal/main.mm | 31 ++++++++----------------- examples/example_sdl_opengl2/main.cpp | 2 +- examples/example_sdl_opengl3/main.cpp | 2 +- examples/imgui_impl_sdl.cpp | 28 ---------------------- examples/imgui_impl_sdl.h | 3 +-- 12 files changed, 37 insertions(+), 61 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a874bfff8..ff83bd3d1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -241,6 +241,9 @@ jobs: - name: Build example_glfw_metal run: make -C examples/example_glfw_metal + - name: Build example_sdl_metal + run: make -C examples/example_sdl_metal + - name: Build example_sdl_opengl2 run: make -C examples/example_sdl_opengl2 if: github.event_name == 'schedule' diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 736cb4472..66c5160a2 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -30,6 +30,15 @@ HOW TO UPDATE? - Please report any issue! +----------------------------------------------------------------------- + VERSION 1.76 WIP (In Progress) +----------------------------------------------------------------------- + +Other Changes: + +- Backends: Added SDL2+Metal example application. (#3017) [@coding-jackalope] + + ----------------------------------------------------------------------- VERSION 1.75 (Released 2020-02-10) ----------------------------------------------------------------------- diff --git a/examples/README.txt b/examples/README.txt index 5bd16be42..5d07a210c 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -190,7 +190,7 @@ example_empscripten: example_glfw_metal/ GLFW (Mac) + Metal example. - = main.mm + imgui_impl_glfw.cpp + imgui_impl_metal.mm. + = main.mm + imgui_impl_glfw.cpp + imgui_impl_metal.mm example_glfw_opengl2/ GLFW + OpenGL2 example (legacy, fixed pipeline). @@ -237,6 +237,10 @@ example_sdl_directx11/ = main.cpp + imgui_impl_sdl.cpp + imgui_impl_dx11.cpp This to demonstrate usage of DirectX with SDL. +example_sdl_metal/ + SDL2 (Mac) + Metal example. + = main.mm + imgui_impl_sdl.cpp + imgui_impl_metal.mm + example_sdl_opengl2/ SDL2 (Win32, Mac, Linux etc.) + OpenGL example (legacy, fixed pipeline). = main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl2.cpp diff --git a/examples/example_glfw_metal/main.mm b/examples/example_glfw_metal/main.mm index 45dbb37bb..d6f9ae3f6 100644 --- a/examples/example_glfw_metal/main.mm +++ b/examples/example_glfw_metal/main.mm @@ -1,9 +1,11 @@ -// ImGui - standalone example application for GLFW + Metal, using programmable pipeline -// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// dear imgui: standalone example application for GLFW + Metal, using programmable pipeline +// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp. +// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.) #include "imgui.h" #include "imgui_impl_glfw.h" #include "imgui_impl_metal.h" +#include #define GLFW_INCLUDE_NONE #define GLFW_EXPOSE_NATIVE_COCOA @@ -13,8 +15,6 @@ #import #import -#include - static void glfw_error_callback(int error, const char* description) { fprintf(stderr, "Glfw Error %d: %s\n", error, description); diff --git a/examples/example_glfw_opengl2/main.cpp b/examples/example_glfw_opengl2/main.cpp index 5630b6c39..a50b46377 100644 --- a/examples/example_glfw_opengl2/main.cpp +++ b/examples/example_glfw_opengl2/main.cpp @@ -1,6 +1,6 @@ // dear imgui: standalone example application for GLFW + OpenGL2, using legacy fixed pipeline // If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp. -// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) +// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.) // **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** // **Prefer using the code in the example_glfw_opengl2/ folder** diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index ef7ddfed9..55b379deb 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -1,6 +1,6 @@ // dear imgui: standalone example application for GLFW + OpenGL 3, using programmable pipeline // If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp. -// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) +// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.) #include "imgui.h" #include "imgui_impl_glfw.h" diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp index 812b40f4a..0a97325d2 100644 --- a/examples/example_sdl_directx11/main.cpp +++ b/examples/example_sdl_directx11/main.cpp @@ -1,6 +1,6 @@ // dear imgui: standalone example application for SDL2 + DirectX 11 // If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp. -// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) +// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.) #include "imgui.h" #include "imgui_impl_sdl.h" diff --git a/examples/example_sdl_metal/main.mm b/examples/example_sdl_metal/main.mm index 7801ca145..3cb1ea4d3 100644 --- a/examples/example_sdl_metal/main.mm +++ b/examples/example_sdl_metal/main.mm @@ -1,17 +1,16 @@ -// ImGui - standalone example application for GLFW + Metal, using programmable pipeline -// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// Dear ImGui: standalone example application for SDL2 + Metal +// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp. +// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.) #include "imgui.h" #include "imgui_impl_sdl.h" #include "imgui_impl_metal.h" - -#include "SDL.h" +#include +#include #import #import -#include - int main(int, char**) { // Setup Dear ImGui binding @@ -49,27 +48,17 @@ int main(int, char**) return -1; } - SDL_Window* window = SDL_CreateWindow( - "Dear ImGui SDL+Metal example", - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, - 1280, - 720, - SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI - ); + // Inform SDL that we will be using metal for rendering. Without this hint initialization of metal renderer may fail. + SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal"); + SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL+Metal example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); if (window == NULL) { printf("Error creating window: %s\n", SDL_GetError()); return -2; } - SDL_Renderer* renderer = SDL_CreateRenderer( - window, - -1, - SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC - ); - + SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (renderer == NULL) { printf("Error creating renderer: %s\n", SDL_GetError()); @@ -125,7 +114,7 @@ int main(int, char**) // Start the Dear ImGui frame ImGui_ImplMetal_NewFrame(renderPassDescriptor); - ImGui_ImplSDL2_NewFrame_Metal(window); + ImGui_ImplSDL2_NewFrame(window); ImGui::NewFrame(); // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). diff --git a/examples/example_sdl_opengl2/main.cpp b/examples/example_sdl_opengl2/main.cpp index b55cb22f3..ff54ec411 100644 --- a/examples/example_sdl_opengl2/main.cpp +++ b/examples/example_sdl_opengl2/main.cpp @@ -1,6 +1,6 @@ // dear imgui: standalone example application for SDL2 + OpenGL // If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp. -// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) +// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.) // **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** // **Prefer using the code in the example_sdl_opengl3/ folder** diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index a0cfe2404..20801a194 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -1,6 +1,6 @@ // dear imgui: standalone example application for SDL2 + OpenGL // If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp. -// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) +// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.) // (GL3W is a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc.) #include "imgui.h" diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index aac3b82ce..69172622a 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -364,31 +364,3 @@ 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(); -} diff --git a/examples/imgui_impl_sdl.h b/examples/imgui_impl_sdl.h index 42da71ed3..a672ca838 100644 --- a/examples/imgui_impl_sdl.h +++ b/examples/imgui_impl_sdl.h @@ -22,8 +22,7 @@ typedef union SDL_Event SDL_Event; IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context); IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window); IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window); -IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window); +IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window); IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown(); IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame(SDL_Window* window); -IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame_Metal(SDL_Window* window); IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);