MTLCommandBuffer.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using static Veldrid.MetalBindings.ObjectiveCRuntime;
  2. using System;
  3. using System.Runtime.InteropServices;
  4. namespace Veldrid.MetalBindings
  5. {
  6. [StructLayout(LayoutKind.Sequential)]
  7. public struct MTLCommandBuffer
  8. {
  9. public readonly IntPtr NativePtr;
  10. public MTLRenderCommandEncoder renderCommandEncoderWithDescriptor(MTLRenderPassDescriptor desc)
  11. {
  12. return new MTLRenderCommandEncoder(
  13. IntPtr_objc_msgSend(NativePtr, sel_renderCommandEncoderWithDescriptor, desc.NativePtr));
  14. }
  15. public void presentDrawable(IntPtr drawable) => objc_msgSend(NativePtr, sel_presentDrawable, drawable);
  16. public void commit() => objc_msgSend(NativePtr, sel_commit);
  17. public MTLBlitCommandEncoder blitCommandEncoder()
  18. => objc_msgSend<MTLBlitCommandEncoder>(NativePtr, sel_blitCommandEncoder);
  19. public MTLComputeCommandEncoder computeCommandEncoder()
  20. => objc_msgSend<MTLComputeCommandEncoder>(NativePtr, sel_computeCommandEncoder);
  21. public void waitUntilCompleted() => objc_msgSend(NativePtr, sel_waitUntilCompleted);
  22. public void addCompletedHandler(MTLCommandBufferHandler block)
  23. => objc_msgSend(NativePtr, sel_addCompletedHandler, block);
  24. public void addCompletedHandler(IntPtr block)
  25. => objc_msgSend(NativePtr, sel_addCompletedHandler, block);
  26. public MTLCommandBufferStatus status => (MTLCommandBufferStatus)uint_objc_msgSend(NativePtr, sel_status);
  27. private static readonly Selector sel_renderCommandEncoderWithDescriptor = "renderCommandEncoderWithDescriptor:";
  28. private static readonly Selector sel_presentDrawable = "presentDrawable:";
  29. private static readonly Selector sel_commit = "commit";
  30. private static readonly Selector sel_blitCommandEncoder = "blitCommandEncoder";
  31. private static readonly Selector sel_computeCommandEncoder = "computeCommandEncoder";
  32. private static readonly Selector sel_waitUntilCompleted = "waitUntilCompleted";
  33. private static readonly Selector sel_addCompletedHandler = "addCompletedHandler:";
  34. private static readonly Selector sel_status = "status";
  35. }
  36. }