From 67410d53f739b6a0df138e2252f0e5136b42062f Mon Sep 17 00:00:00 2001 From: "Stephen H. Gerstacker" Date: Thu, 30 Jun 2022 20:09:18 +0200 Subject: [PATCH] Backends: Metal, OSX: Various fixes (ARC / Autorelease fixes with metal-cpp and extensions). (#5403) --- backends/imgui_impl_metal.h | 3 --- backends/imgui_impl_metal.mm | 16 ++++++++-------- backends/imgui_impl_osx.h | 19 +++++++++++++++++++ backends/imgui_impl_osx.mm | 12 ++++++++++++ docs/CHANGELOG.txt | 2 ++ 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/backends/imgui_impl_metal.h b/backends/imgui_impl_metal.h index 12a67b61..49584443 100644 --- a/backends/imgui_impl_metal.h +++ b/backends/imgui_impl_metal.h @@ -44,9 +44,7 @@ IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects(); // More info about using Metal from C++: https://developer.apple.com/metal/cpp/ #ifdef IMGUI_IMPL_METAL_CPP - #include - #ifndef __OBJC__ IMGUI_IMPL_API bool ImGui_ImplMetal_Init(MTL::Device* device); @@ -63,5 +61,4 @@ IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device); IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects(); #endif - #endif diff --git a/backends/imgui_impl_metal.mm b/backends/imgui_impl_metal.mm index 199a4c3a..4a9feafd 100644 --- a/backends/imgui_impl_metal.mm +++ b/backends/imgui_impl_metal.mm @@ -84,12 +84,12 @@ static inline CFTimeInterval GetMachAbsoluteTimeInSeconds() { return s bool ImGui_ImplMetal_Init(MTL::Device* device) { - return ImGui_ImplMetal_Init((id)(device)); + return ImGui_ImplMetal_Init((__bridge id)(device)); } void ImGui_ImplMetal_NewFrame(MTL::RenderPassDescriptor* renderPassDescriptor) { - ImGui_ImplMetal_NewFrame((MTLRenderPassDescriptor*)(renderPassDescriptor)); + ImGui_ImplMetal_NewFrame((__bridge MTLRenderPassDescriptor*)(renderPassDescriptor)); } void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, @@ -97,19 +97,19 @@ void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, MTL::RenderCommandEncoder* commandEncoder) { ImGui_ImplMetal_RenderDrawData(draw_data, - (id)(commandBuffer), - (id)(commandEncoder)); + (__bridge id)(commandBuffer), + (__bridge id)(commandEncoder)); } bool ImGui_ImplMetal_CreateFontsTexture(MTL::Device* device) { - return ImGui_ImplMetal_CreateFontsTexture((id)(device)); + return ImGui_ImplMetal_CreateFontsTexture((__bridge id)(device)); } bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device) { - return ImGui_ImplMetal_CreateDeviceObjects((id)(device)); + return ImGui_ImplMetal_CreateDeviceObjects((__bridge id)(device)); } #endif // #ifdef IMGUI_IMPL_METAL_CPP @@ -429,8 +429,8 @@ void ImGui_ImplMetal_DestroyDeviceObjects() { if ((self = [super init])) { - _renderPipelineStateCache = [NSMutableDictionary dictionary]; - _bufferCache = [NSMutableArray array]; + self.renderPipelineStateCache = [NSMutableDictionary dictionary]; + self.bufferCache = [NSMutableArray array]; _lastBufferCachePurge = GetMachAbsoluteTimeInSeconds(); } return self; diff --git a/backends/imgui_impl_osx.h b/backends/imgui_impl_osx.h index d483dcf2..70619e39 100644 --- a/backends/imgui_impl_osx.h +++ b/backends/imgui_impl_osx.h @@ -16,9 +16,28 @@ #include "imgui.h" // IMGUI_IMPL_API +#ifdef __OBJC__ + @class NSEvent; @class NSView; IMGUI_IMPL_API bool ImGui_ImplOSX_Init(NSView* _Nonnull view); IMGUI_IMPL_API void ImGui_ImplOSX_Shutdown(); IMGUI_IMPL_API void ImGui_ImplOSX_NewFrame(NSView* _Nullable view); + +#endif + +//----------------------------------------------------------------------------- +// C++ API +//----------------------------------------------------------------------------- + +#ifdef IMGUI_IMPL_METAL_CPP_EXTENSIONS +// #include +#ifndef __OBJC__ + +IMGUI_IMPL_API bool ImGui_ImplOSX_Init(void* _Nonnull view); +IMGUI_IMPL_API void ImGui_ImplOSX_Shutdown(); +IMGUI_IMPL_API void ImGui_ImplOSX_NewFrame(void* _Nullable view); + +#endif +#endif diff --git a/backends/imgui_impl_osx.mm b/backends/imgui_impl_osx.mm index 597eb855..2966ec7c 100644 --- a/backends/imgui_impl_osx.mm +++ b/backends/imgui_impl_osx.mm @@ -364,6 +364,18 @@ static ImGuiKey ImGui_ImplOSX_KeyCodeToImGuiKey(int key_code) } } +#ifdef IMGUI_IMPL_METAL_CPP_EXTENSIONS + +IMGUI_IMPL_API bool ImGui_ImplOSX_Init(void* _Nonnull view) { + return ImGui_ImplOSX_Init((__bridge NSView*)(view)); +} + +IMGUI_IMPL_API void ImGui_ImplOSX_NewFrame(void* _Nullable view) { + return ImGui_ImplOSX_NewFrame((__bridge NSView*)(view)); +} + +#endif + bool ImGui_ImplOSX_Init(NSView* view) { diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c5494ccb..ce466620 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -41,6 +41,8 @@ Other Changes: - InputText: added experimental io.ConfigInputTextEnterKeepActive feature to make pressing Enter keep the input active and select all text. +- Backends: Metal: Use __bridge for ARC based systems. (#5403) [@stack] +- Backends: OSX: Fixes to support full app creation in C++. (#5403) [@stack] -----------------------------------------------------------------------