Selector.cs 960 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Text;
  3. namespace Veldrid.MetalBindings
  4. {
  5. public unsafe struct Selector
  6. {
  7. public readonly IntPtr NativePtr;
  8. public Selector(IntPtr ptr)
  9. {
  10. NativePtr = ptr;
  11. }
  12. public Selector(string name)
  13. {
  14. int byteCount = Encoding.UTF8.GetMaxByteCount(name.Length);
  15. byte* utf8BytesPtr = stackalloc byte[byteCount];
  16. fixed (char* namePtr = name)
  17. {
  18. Encoding.UTF8.GetBytes(namePtr, name.Length, utf8BytesPtr, byteCount);
  19. }
  20. NativePtr = ObjectiveCRuntime.sel_registerName(utf8BytesPtr);
  21. }
  22. public string Name
  23. {
  24. get
  25. {
  26. byte* name = ObjectiveCRuntime.sel_getName(NativePtr);
  27. return MTLUtil.GetUtf8String(name);
  28. }
  29. }
  30. public static implicit operator Selector(string s) => new Selector(s);
  31. }
  32. }