MTLTexture.cs 1.5 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 unsafe struct MTLTexture
  8. {
  9. public readonly IntPtr NativePtr;
  10. public MTLTexture(IntPtr ptr) => NativePtr = ptr;
  11. public bool IsNull => NativePtr == IntPtr.Zero;
  12. public void replaceRegion(
  13. MTLRegion region,
  14. UIntPtr mipmapLevel,
  15. UIntPtr slice,
  16. void* pixelBytes,
  17. UIntPtr bytesPerRow,
  18. UIntPtr bytesPerImage)
  19. {
  20. objc_msgSend(NativePtr, sel_replaceRegion,
  21. region,
  22. mipmapLevel,
  23. slice,
  24. (IntPtr)pixelBytes,
  25. bytesPerRow,
  26. bytesPerImage);
  27. }
  28. public MTLTexture newTextureView(
  29. MTLPixelFormat pixelFormat,
  30. MTLTextureType textureType,
  31. NSRange levelRange,
  32. NSRange sliceRange)
  33. {
  34. IntPtr ret = IntPtr_objc_msgSend(NativePtr, sel_newTextureView,
  35. (uint)pixelFormat, (uint)textureType, levelRange, sliceRange);
  36. return new MTLTexture(ret);
  37. }
  38. private static readonly Selector sel_replaceRegion = "replaceRegion:mipmapLevel:slice:withBytes:bytesPerRow:bytesPerImage:";
  39. private static readonly Selector sel_newTextureView = "newTextureViewWithPixelFormat:textureType:levels:slices:";
  40. }
  41. }