Browse Source

Backends: Metal, OSX: Various fixes (ARC / Autorelease fixes with metal-cpp and extensions). (#5403)

pull/5447/head
Stephen H. Gerstacker 2 years ago
committed by ocornut
parent
commit
67410d53f7
  1. 3
      backends/imgui_impl_metal.h
  2. 16
      backends/imgui_impl_metal.mm
  3. 19
      backends/imgui_impl_osx.h
  4. 12
      backends/imgui_impl_osx.mm
  5. 2
      docs/CHANGELOG.txt

3
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/ // More info about using Metal from C++: https://developer.apple.com/metal/cpp/
#ifdef IMGUI_IMPL_METAL_CPP #ifdef IMGUI_IMPL_METAL_CPP
#include <Metal/Metal.hpp> #include <Metal/Metal.hpp>
#ifndef __OBJC__ #ifndef __OBJC__
IMGUI_IMPL_API bool ImGui_ImplMetal_Init(MTL::Device* device); 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(); IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects();
#endif #endif
#endif #endif

16
backends/imgui_impl_metal.mm

@ -84,12 +84,12 @@ static inline CFTimeInterval GetMachAbsoluteTimeInSeconds() { return s
bool ImGui_ImplMetal_Init(MTL::Device* device) bool ImGui_ImplMetal_Init(MTL::Device* device)
{ {
return ImGui_ImplMetal_Init((id<MTLDevice>)(device)); return ImGui_ImplMetal_Init((__bridge id<MTLDevice>)(device));
} }
void ImGui_ImplMetal_NewFrame(MTL::RenderPassDescriptor* renderPassDescriptor) 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, void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data,
@ -97,19 +97,19 @@ void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data,
MTL::RenderCommandEncoder* commandEncoder) MTL::RenderCommandEncoder* commandEncoder)
{ {
ImGui_ImplMetal_RenderDrawData(draw_data, ImGui_ImplMetal_RenderDrawData(draw_data,
(id<MTLCommandBuffer>)(commandBuffer), (__bridge id<MTLCommandBuffer>)(commandBuffer),
(id<MTLRenderCommandEncoder>)(commandEncoder)); (__bridge id<MTLRenderCommandEncoder>)(commandEncoder));
} }
bool ImGui_ImplMetal_CreateFontsTexture(MTL::Device* device) bool ImGui_ImplMetal_CreateFontsTexture(MTL::Device* device)
{ {
return ImGui_ImplMetal_CreateFontsTexture((id<MTLDevice>)(device)); return ImGui_ImplMetal_CreateFontsTexture((__bridge id<MTLDevice>)(device));
} }
bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device) bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device)
{ {
return ImGui_ImplMetal_CreateDeviceObjects((id<MTLDevice>)(device)); return ImGui_ImplMetal_CreateDeviceObjects((__bridge id<MTLDevice>)(device));
} }
#endif // #ifdef IMGUI_IMPL_METAL_CPP #endif // #ifdef IMGUI_IMPL_METAL_CPP
@ -429,8 +429,8 @@ void ImGui_ImplMetal_DestroyDeviceObjects()
{ {
if ((self = [super init])) if ((self = [super init]))
{ {
_renderPipelineStateCache = [NSMutableDictionary dictionary]; self.renderPipelineStateCache = [NSMutableDictionary dictionary];
_bufferCache = [NSMutableArray array]; self.bufferCache = [NSMutableArray array];
_lastBufferCachePurge = GetMachAbsoluteTimeInSeconds(); _lastBufferCachePurge = GetMachAbsoluteTimeInSeconds();
} }
return self; return self;

19
backends/imgui_impl_osx.h

@ -16,9 +16,28 @@
#include "imgui.h" // IMGUI_IMPL_API #include "imgui.h" // IMGUI_IMPL_API
#ifdef __OBJC__
@class NSEvent; @class NSEvent;
@class NSView; @class NSView;
IMGUI_IMPL_API bool ImGui_ImplOSX_Init(NSView* _Nonnull view); IMGUI_IMPL_API bool ImGui_ImplOSX_Init(NSView* _Nonnull view);
IMGUI_IMPL_API void ImGui_ImplOSX_Shutdown(); IMGUI_IMPL_API void ImGui_ImplOSX_Shutdown();
IMGUI_IMPL_API void ImGui_ImplOSX_NewFrame(NSView* _Nullable view); IMGUI_IMPL_API void ImGui_ImplOSX_NewFrame(NSView* _Nullable view);
#endif
//-----------------------------------------------------------------------------
// C++ API
//-----------------------------------------------------------------------------
#ifdef IMGUI_IMPL_METAL_CPP_EXTENSIONS
// #include <AppKit/AppKit.hpp>
#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

12
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) bool ImGui_ImplOSX_Init(NSView* view)
{ {

2
docs/CHANGELOG.txt

@ -41,6 +41,8 @@ Other Changes:
- InputText: added experimental io.ConfigInputTextEnterKeepActive feature to make pressing - InputText: added experimental io.ConfigInputTextEnterKeepActive feature to make pressing
Enter keep the input active and select all text. 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]
----------------------------------------------------------------------- -----------------------------------------------------------------------

Loading…
Cancel
Save