|
| 1 | +// dear imgui: Renderer Backend for Metal |
| 2 | +// This needs to be used along with a Platform Backend (e.g. OSX) |
| 3 | + |
| 4 | +// Implemented features: |
| 5 | +// [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID! |
| 6 | +// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. |
| 7 | + |
| 8 | +// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. |
| 9 | +// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. |
| 10 | +// Learn about Dear ImGui: |
| 11 | +// - FAQ https://dearimgui.com/faq |
| 12 | +// - Getting Started https://dearimgui.com/getting-started |
| 13 | +// - Documentation https://dearimgui.com/docs (same as your local docs/ folder). |
| 14 | +// - Introduction, links and more at the top of imgui.cpp |
| 15 | + |
| 16 | +#include "imgui.h" // IMGUI_IMPL_API |
| 17 | +#ifndef IMGUI_DISABLE |
| 18 | + |
| 19 | +//----------------------------------------------------------------------------- |
| 20 | +// ObjC API |
| 21 | +//----------------------------------------------------------------------------- |
| 22 | + |
| 23 | +#ifdef __OBJC__ |
| 24 | + |
| 25 | +extern "C" { |
| 26 | +@class MTLRenderPassDescriptor; |
| 27 | +@protocol MTLDevice, MTLCommandBuffer, MTLRenderCommandEncoder; |
| 28 | + |
| 29 | +// Follow "Getting Started" link and check examples/ folder to learn about using backends! |
| 30 | +IMGUI_IMPL_API bool ImGui_ImplMetal_Init(id<MTLDevice> device); |
| 31 | +IMGUI_IMPL_API void ImGui_ImplMetal_Shutdown(); |
| 32 | +IMGUI_IMPL_API void ImGui_ImplMetal_NewFrame(MTLRenderPassDescriptor* renderPassDescriptor); |
| 33 | +IMGUI_IMPL_API void ImGui_ImplMetal_RenderDrawData(ImDrawData* drawData, |
| 34 | + id<MTLCommandBuffer> commandBuffer, |
| 35 | + id<MTLRenderCommandEncoder> commandEncoder); |
| 36 | +} |
| 37 | + |
| 38 | +// Called by Init/NewFrame/Shutdown |
| 39 | +IMGUI_IMPL_API bool ImGui_ImplMetal_CreateFontsTexture(id<MTLDevice> device); |
| 40 | +IMGUI_IMPL_API void ImGui_ImplMetal_DestroyFontsTexture(); |
| 41 | +IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(id<MTLDevice> device); |
| 42 | +IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects(); |
| 43 | + |
| 44 | +#endif |
| 45 | + |
| 46 | +//----------------------------------------------------------------------------- |
| 47 | +// C++ API |
| 48 | +//----------------------------------------------------------------------------- |
| 49 | + |
| 50 | +// Enable Metal C++ binding support with '#define IMGUI_IMPL_METAL_CPP' in your imconfig.h file |
| 51 | +// More info about using Metal from C++: https://developer.apple.com/metal/cpp/ |
| 52 | + |
| 53 | +#ifdef IMGUI_IMPL_METAL_CPP |
| 54 | +#include <Metal/Metal.hpp> |
| 55 | +#ifndef __OBJC__ |
| 56 | + |
| 57 | +extern "C" { |
| 58 | +// Follow "Getting Started" link and check examples/ folder to learn about using backends! |
| 59 | +IMGUI_IMPL_API bool ImGui_ImplMetal_Init(MTL::Device* device); |
| 60 | +IMGUI_IMPL_API void ImGui_ImplMetal_Shutdown(); |
| 61 | +IMGUI_IMPL_API void ImGui_ImplMetal_NewFrame(MTL::RenderPassDescriptor* renderPassDescriptor); |
| 62 | +IMGUI_IMPL_API void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, |
| 63 | + MTL::CommandBuffer* commandBuffer, |
| 64 | + MTL::RenderCommandEncoder* commandEncoder); |
| 65 | +} |
| 66 | + |
| 67 | +// Called by Init/NewFrame/Shutdown |
| 68 | +IMGUI_IMPL_API bool ImGui_ImplMetal_CreateFontsTexture(MTL::Device* device); |
| 69 | +IMGUI_IMPL_API void ImGui_ImplMetal_DestroyFontsTexture(); |
| 70 | +IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device); |
| 71 | +IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects(); |
| 72 | + |
| 73 | +#endif |
| 74 | +#endif |
| 75 | + |
| 76 | +//----------------------------------------------------------------------------- |
| 77 | + |
| 78 | +#endif // #ifndef IMGUI_DISABLE |
0 commit comments