Minor fixes to example_sdl_metal and a changelog entry.

Add example_sdl_metal to CI builds.

Closes #3017.
This commit is contained in:
Rokas Kupstys 2020-02-10 16:13:29 +02:00 committed by omar
parent f346b4b302
commit 21b9e42964
12 changed files with 37 additions and 61 deletions

View File

@ -241,6 +241,9 @@ jobs:
- name: Build example_glfw_metal - name: Build example_glfw_metal
run: make -C examples/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 - name: Build example_sdl_opengl2
run: make -C examples/example_sdl_opengl2 run: make -C examples/example_sdl_opengl2
if: github.event_name == 'schedule' if: github.event_name == 'schedule'

View File

@ -30,6 +30,15 @@ HOW TO UPDATE?
- Please report any issue! - 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) VERSION 1.75 (Released 2020-02-10)
----------------------------------------------------------------------- -----------------------------------------------------------------------

View File

@ -190,7 +190,7 @@ example_empscripten:
example_glfw_metal/ example_glfw_metal/
GLFW (Mac) + Metal example. 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/ example_glfw_opengl2/
GLFW + OpenGL2 example (legacy, fixed pipeline). GLFW + OpenGL2 example (legacy, fixed pipeline).
@ -237,6 +237,10 @@ example_sdl_directx11/
= main.cpp + imgui_impl_sdl.cpp + imgui_impl_dx11.cpp = main.cpp + imgui_impl_sdl.cpp + imgui_impl_dx11.cpp
This to demonstrate usage of DirectX with SDL. 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/ example_sdl_opengl2/
SDL2 (Win32, Mac, Linux etc.) + OpenGL example (legacy, fixed pipeline). SDL2 (Win32, Mac, Linux etc.) + OpenGL example (legacy, fixed pipeline).
= main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl2.cpp = main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl2.cpp

View File

@ -1,9 +1,11 @@
// ImGui - standalone example application for GLFW + Metal, using programmable pipeline // dear 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. // 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.h"
#include "imgui_impl_glfw.h" #include "imgui_impl_glfw.h"
#include "imgui_impl_metal.h" #include "imgui_impl_metal.h"
#include <stdio.h>
#define GLFW_INCLUDE_NONE #define GLFW_INCLUDE_NONE
#define GLFW_EXPOSE_NATIVE_COCOA #define GLFW_EXPOSE_NATIVE_COCOA
@ -13,8 +15,6 @@
#import <Metal/Metal.h> #import <Metal/Metal.h>
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
#include <stdio.h>
static void glfw_error_callback(int error, const char* description) static void glfw_error_callback(int error, const char* description)
{ {
fprintf(stderr, "Glfw Error %d: %s\n", error, description); fprintf(stderr, "Glfw Error %d: %s\n", error, description);

View File

@ -1,6 +1,6 @@
// dear imgui: standalone example application for GLFW + OpenGL2, using legacy fixed pipeline // 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. // 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.)** // **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** // **Prefer using the code in the example_glfw_opengl2/ folder**

View File

@ -1,6 +1,6 @@
// dear imgui: standalone example application for GLFW + OpenGL 3, using programmable pipeline // 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. // 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.h"
#include "imgui_impl_glfw.h" #include "imgui_impl_glfw.h"

View File

@ -1,6 +1,6 @@
// dear imgui: standalone example application for SDL2 + DirectX 11 // 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. // 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.h"
#include "imgui_impl_sdl.h" #include "imgui_impl_sdl.h"

View File

@ -1,17 +1,16 @@
// ImGui - standalone example application for GLFW + Metal, using programmable pipeline // Dear ImGui: standalone example application for SDL2 + Metal
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. // 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.h"
#include "imgui_impl_sdl.h" #include "imgui_impl_sdl.h"
#include "imgui_impl_metal.h" #include "imgui_impl_metal.h"
#include <stdio.h>
#include "SDL.h" #include <SDL.h>
#import <Metal/Metal.h> #import <Metal/Metal.h>
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
#include <stdio.h>
int main(int, char**) int main(int, char**)
{ {
// Setup Dear ImGui binding // Setup Dear ImGui binding
@ -49,27 +48,17 @@ int main(int, char**)
return -1; return -1;
} }
SDL_Window* window = SDL_CreateWindow( // Inform SDL that we will be using metal for rendering. Without this hint initialization of metal renderer may fail.
"Dear ImGui SDL+Metal example", SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal");
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
1280,
720,
SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI
);
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) if (window == NULL)
{ {
printf("Error creating window: %s\n", SDL_GetError()); printf("Error creating window: %s\n", SDL_GetError());
return -2; return -2;
} }
SDL_Renderer* renderer = SDL_CreateRenderer( SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
window,
-1,
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
);
if (renderer == NULL) if (renderer == NULL)
{ {
printf("Error creating renderer: %s\n", SDL_GetError()); printf("Error creating renderer: %s\n", SDL_GetError());
@ -125,7 +114,7 @@ int main(int, char**)
// Start the Dear ImGui frame // Start the Dear ImGui frame
ImGui_ImplMetal_NewFrame(renderPassDescriptor); ImGui_ImplMetal_NewFrame(renderPassDescriptor);
ImGui_ImplSDL2_NewFrame_Metal(window); ImGui_ImplSDL2_NewFrame(window);
ImGui::NewFrame(); 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. 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!).

View File

@ -1,6 +1,6 @@
// dear imgui: standalone example application for SDL2 + OpenGL // 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. // 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.)** // **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** // **Prefer using the code in the example_sdl_opengl3/ folder**

View File

@ -1,6 +1,6 @@
// dear imgui: standalone example application for SDL2 + OpenGL // 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. // 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.) // (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" #include "imgui.h"

View File

@ -364,31 +364,3 @@ void ImGui_ImplSDL2_NewFrame(SDL_Window* window)
// Update game controllers (if enabled and available) // Update game controllers (if enabled and available)
ImGui_ImplSDL2_UpdateGamepads(); 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();
}

View File

@ -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_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window); 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_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_Shutdown();
IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame(SDL_Window* window); 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); IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);