imgui_impl_metal.mm (imgui-1.86) | : | imgui_impl_metal.mm (imgui-1.87) | ||
---|---|---|---|---|
skipping to change at line 15 | skipping to change at line 15 | |||
// [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read th e FAQ about ImTextureID! | // [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read th e FAQ about ImTextureID! | |||
// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. | // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. | |||
// You can use unmodified imgui_impl_* files in your project. See examples/ fold er for examples of using this. | // You can use unmodified imgui_impl_* files in your project. See examples/ fold er for examples of using this. | |||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. | |||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. | |||
// Read online: https://github.com/ocornut/imgui/tree/master/docs | // Read online: https://github.com/ocornut/imgui/tree/master/docs | |||
// CHANGELOG | // CHANGELOG | |||
// (minor and older changes stripped away, please see git history for details) | // (minor and older changes stripped away, please see git history for details) | |||
// 2022-01-03: Metal: Ignore ImDrawCmd where ElemCount == 0 (very rare but can | ||||
technically be manufactured by user code). | ||||
// 2021-12-30: Metal: Added Metal C++ support. Enable with '#define IMGUI_IMPL_ | ||||
METAL_CPP' in your imconfig.h file. | ||||
// 2021-08-24: Metal: Fixed a crash when clipping rect larger than framebuffer is submitted. (#4464) | // 2021-08-24: Metal: Fixed a crash when clipping rect larger than framebuffer is submitted. (#4464) | |||
// 2021-05-19: Metal: Replaced direct access to ImDrawCmd::TextureId with a cal l to ImDrawCmd::GetTexID(). (will become a requirement) | // 2021-05-19: Metal: Replaced direct access to ImDrawCmd::TextureId with a cal l to ImDrawCmd::GetTexID(). (will become a requirement) | |||
// 2021-02-18: Metal: Change blending equation to preserve alpha in output buff er. | // 2021-02-18: Metal: Change blending equation to preserve alpha in output buff er. | |||
// 2021-01-25: Metal: Fixed texture storage mode when building on Mac Catalyst. | // 2021-01-25: Metal: Fixed texture storage mode when building on Mac Catalyst. | |||
// 2019-05-29: Metal: Added support for large mesh (64K+ vertices), enable ImGu iBackendFlags_RendererHasVtxOffset flag. | // 2019-05-29: Metal: Added support for large mesh (64K+ vertices), enable ImGu iBackendFlags_RendererHasVtxOffset flag. | |||
// 2019-04-30: Metal: Added support for special ImDrawCallback_ResetRenderState callback to reset render state. | // 2019-04-30: Metal: Added support for special ImDrawCallback_ResetRenderState callback to reset render state. | |||
// 2019-02-11: Metal: Projecting clipping rectangles correctly using draw_data- >FramebufferScale to allow multi-viewports for retina display. | // 2019-02-11: Metal: Projecting clipping rectangles correctly using draw_data- >FramebufferScale to allow multi-viewports for retina display. | |||
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed i n the About Window. | // 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed i n the About Window. | |||
// 2018-07-05: Metal: Added new Metal backend implementation. | // 2018-07-05: Metal: Added new Metal backend implementation. | |||
skipping to change at line 80 | skipping to change at line 82 | |||
renderPipelineState:(id<MTLRenderPipelineState>)renderPipelineState | renderPipelineState:(id<MTLRenderPipelineState>)renderPipelineState | |||
vertexBuffer:(MetalBuffer *)vertexBuffer | vertexBuffer:(MetalBuffer *)vertexBuffer | |||
vertexBufferOffset:(size_t)vertexBufferOffset; | vertexBufferOffset:(size_t)vertexBufferOffset; | |||
- (void)renderDrawData:(ImDrawData *)drawData | - (void)renderDrawData:(ImDrawData *)drawData | |||
commandBuffer:(id<MTLCommandBuffer>)commandBuffer | commandBuffer:(id<MTLCommandBuffer>)commandBuffer | |||
commandEncoder:(id<MTLRenderCommandEncoder>)commandEncoder; | commandEncoder:(id<MTLRenderCommandEncoder>)commandEncoder; | |||
@end | @end | |||
static MetalContext *g_sharedMetalContext = nil; | static MetalContext *g_sharedMetalContext = nil; | |||
#pragma mark - ImGui API implementation | #ifdef IMGUI_IMPL_METAL_CPP | |||
#pragma mark - Dear ImGui Metal C++ Backend API | ||||
bool ImGui_ImplMetal_Init(MTL::Device* device) | ||||
{ | ||||
return ImGui_ImplMetal_Init((id<MTLDevice>)(device)); | ||||
} | ||||
void ImGui_ImplMetal_NewFrame(MTL::RenderPassDescriptor* renderPassDescriptor) | ||||
{ | ||||
ImGui_ImplMetal_NewFrame((MTLRenderPassDescriptor*)(renderPassDescriptor)); | ||||
} | ||||
void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, | ||||
MTL::CommandBuffer* commandBuffer, | ||||
MTL::RenderCommandEncoder* commandEncoder) | ||||
{ | ||||
ImGui_ImplMetal_RenderDrawData(draw_data, | ||||
(id<MTLCommandBuffer>)(commandBuffer), | ||||
(id<MTLRenderCommandEncoder>)(commandEncoder) | ||||
); | ||||
} | ||||
bool ImGui_ImplMetal_CreateFontsTexture(MTL::Device* device) | ||||
{ | ||||
return ImGui_ImplMetal_CreateFontsTexture((id<MTLDevice>)(device)); | ||||
} | ||||
bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device) | ||||
{ | ||||
return ImGui_ImplMetal_CreateDeviceObjects((id<MTLDevice>)(device)); | ||||
} | ||||
#endif // #ifdef IMGUI_IMPL_METAL_CPP | ||||
#pragma mark - Dear ImGui Metal Backend API | ||||
bool ImGui_ImplMetal_Init(id<MTLDevice> device) | bool ImGui_ImplMetal_Init(id<MTLDevice> device) | |||
{ | { | |||
ImGuiIO& io = ImGui::GetIO(); | ImGuiIO& io = ImGui::GetIO(); | |||
io.BackendRendererName = "imgui_impl_metal"; | io.BackendRendererName = "imgui_impl_metal"; | |||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. | io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. | |||
static dispatch_once_t onceToken; | static dispatch_once_t onceToken; | |||
dispatch_once(&onceToken, ^{ | dispatch_once(&onceToken, ^{ | |||
g_sharedMetalContext = [[MetalContext alloc] init]; | g_sharedMetalContext = [[MetalContext alloc] init]; | |||
skipping to change at line 518 | skipping to change at line 556 | |||
ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y); | ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y); | |||
ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y); | ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y); | |||
// Clamp to viewport as setScissorRect() won't accept values tha t are off bounds | // Clamp to viewport as setScissorRect() won't accept values tha t are off bounds | |||
if (clip_min.x < 0.0f) { clip_min.x = 0.0f; } | if (clip_min.x < 0.0f) { clip_min.x = 0.0f; } | |||
if (clip_min.y < 0.0f) { clip_min.y = 0.0f; } | if (clip_min.y < 0.0f) { clip_min.y = 0.0f; } | |||
if (clip_max.x > fb_width) { clip_max.x = (float)fb_width; } | if (clip_max.x > fb_width) { clip_max.x = (float)fb_width; } | |||
if (clip_max.y > fb_height) { clip_max.y = (float)fb_height; } | if (clip_max.y > fb_height) { clip_max.y = (float)fb_height; } | |||
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) | if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) | |||
continue; | continue; | |||
if (pcmd->ElemCount == 0) // drawIndexedPrimitives() validation | ||||
doesn't accept this | ||||
continue; | ||||
// Apply scissor/clipping rectangle | // Apply scissor/clipping rectangle | |||
MTLScissorRect scissorRect = | MTLScissorRect scissorRect = | |||
{ | { | |||
.x = NSUInteger(clip_min.x), | .x = NSUInteger(clip_min.x), | |||
.y = NSUInteger(clip_min.y), | .y = NSUInteger(clip_min.y), | |||
.width = NSUInteger(clip_max.x - clip_min.x), | .width = NSUInteger(clip_max.x - clip_min.x), | |||
.height = NSUInteger(clip_max.y - clip_min.y) | .height = NSUInteger(clip_max.y - clip_min.y) | |||
}; | }; | |||
[commandEncoder setScissorRect:scissorRect]; | [commandEncoder setScissorRect:scissorRect]; | |||
End of changes. 3 change blocks. | ||||
1 lines changed or deleted | 45 lines changed or added |