Bläddra i källkod

Examples: Metal: Removed unnecessary loop. Fixed OSX Clang warning in imstb_truetype. (#1929, #1873)

Omar Cornut 6 år sedan
förälder
incheckning
ef7940699e
2 ändrade filer med 10 tillägg och 14 borttagningar
  1. 9 13
      examples/imgui_impl_metal.mm
  2. 1 1
      imstb_truetype.h

+ 9 - 13
examples/imgui_impl_metal.mm

@@ -440,17 +440,10 @@ void ImGui_ImplMetal_DestroyDeviceObjects()
 
 
     [commandEncoder setVertexBytes:&ortho_projection length:sizeof(ortho_projection) atIndex:1];
     [commandEncoder setVertexBytes:&ortho_projection length:sizeof(ortho_projection) atIndex:1];
 
 
-    size_t vertexBufferLength = 0;
-    size_t indexBufferLength = 0;
-    for (int n = 0; n < drawData->CmdListsCount; n++)
-    {
-        const ImDrawList* cmd_list = drawData->CmdLists[n];
-        vertexBufferLength += cmd_list->VtxBuffer.Size * sizeof(ImDrawVert);
-        indexBufferLength += cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx);
-    }
-
-    MetalBuffer *vertexBuffer = [self dequeueReusableBufferOfLength:vertexBufferLength device:commandBuffer.device];
-    MetalBuffer *indexBuffer = [self dequeueReusableBufferOfLength:indexBufferLength device:commandBuffer.device];
+    size_t vertexBufferLength = drawData->TotalVtxCount * sizeof(ImDrawVert);
+    size_t indexBufferLength = drawData->TotalIdxCount * sizeof(ImDrawIdx);
+    MetalBuffer* vertexBuffer = [self dequeueReusableBufferOfLength:vertexBufferLength device:commandBuffer.device];
+    MetalBuffer* indexBuffer = [self dequeueReusableBufferOfLength:indexBufferLength device:commandBuffer.device];
 
 
     id<MTLRenderPipelineState> renderPipelineState = [self renderPipelineStateForFrameAndDevice:commandBuffer.device];
     id<MTLRenderPipelineState> renderPipelineState = [self renderPipelineStateForFrameAndDevice:commandBuffer.device];
     [commandEncoder setRenderPipelineState:renderPipelineState];
     [commandEncoder setRenderPipelineState:renderPipelineState];
@@ -484,10 +477,13 @@ void ImGui_ImplMetal_DestroyDeviceObjects()
                 if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f)
                 if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f)
                 {
                 {
                     // Apply scissor/clipping rectangle
                     // Apply scissor/clipping rectangle
-                    MTLScissorRect scissorRect = { .x = NSUInteger(clip_rect.x),
+                    MTLScissorRect scissorRect =
+                    {
+                        .x = NSUInteger(clip_rect.x),
                         .y = NSUInteger(clip_rect.y),
                         .y = NSUInteger(clip_rect.y),
                         .width = NSUInteger(clip_rect.z - clip_rect.x),
                         .width = NSUInteger(clip_rect.z - clip_rect.x),
-                        .height = NSUInteger(clip_rect.w - clip_rect.y) };
+                        .height = NSUInteger(clip_rect.w - clip_rect.y)
+                    };
                     [commandEncoder setScissorRect:scissorRect];
                     [commandEncoder setScissorRect:scissorRect];
 
 
 
 

+ 1 - 1
imstb_truetype.h

@@ -253,7 +253,7 @@
 //   Documentation & header file        520 LOC  \___ 660 LOC documentation
 //   Documentation & header file        520 LOC  \___ 660 LOC documentation
 //   Sample code                        140 LOC  /
 //   Sample code                        140 LOC  /
 //   Truetype parsing                   620 LOC  ---- 620 LOC TrueType
 //   Truetype parsing                   620 LOC  ---- 620 LOC TrueType
-//   Software rasterization             240 LOC  \                           
+//   Software rasterization             240 LOC  \
 //   Curve tessellation                 120 LOC   \__ 550 LOC Bitmap creation
 //   Curve tessellation                 120 LOC   \__ 550 LOC Bitmap creation
 //   Bitmap management                  100 LOC   /
 //   Bitmap management                  100 LOC   /
 //   Baked bitmap interface              70 LOC  /
 //   Baked bitmap interface              70 LOC  /