Kaynağa Gözat

Minor fixes to example_sdl_metal and a changelog entry.
Add example_sdl_metal to CI builds.

Closes #3017.

Rokas Kupstys 5 yıl önce
ebeveyn
işleme
21b9e42964

+ 3 - 0
.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'

+ 9 - 0
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)
 -----------------------------------------------------------------------

+ 5 - 1
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

+ 4 - 4
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 <stdio.h>
 
 #define GLFW_INCLUDE_NONE
 #define GLFW_EXPOSE_NATIVE_COCOA
@@ -13,8 +15,6 @@
 #import <Metal/Metal.h>
 #import <QuartzCore/QuartzCore.h>
 
-#include <stdio.h>
-
 static void glfw_error_callback(int error, const char* description)
 {
     fprintf(stderr, "Glfw Error %d: %s\n", error, description);

+ 1 - 1
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**

+ 1 - 1
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"

+ 1 - 1
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"

+ 10 - 21
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 <stdio.h>
+#include <SDL.h>
 
 #import <Metal/Metal.h>
 #import <QuartzCore/QuartzCore.h>
 
-#include <stdio.h>
-
 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!).

+ 1 - 1
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**

+ 1 - 1
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"

+ 0 - 28
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();
-}

+ 1 - 2
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);