UnityMetalSupport.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. // we allow to build with sdk 9.0 (and run on ios7) so we need to take an extra care about Metal support
  3. // it is expected to substitute Metal.h so only objc
  4. #ifdef __cplusplus
  5. extern "C" typedef MTLDeviceRef (*MTLCreateSystemDefaultDeviceFunc)();
  6. #else
  7. typedef MTLDeviceRef (*MTLCreateSystemDefaultDeviceFunc)();
  8. #endif
  9. #if UNITY_CAN_USE_METAL
  10. #import <Metal/Metal.h>
  11. #import <QuartzCore/CAMetalLayer.h>
  12. #else
  13. // everything below is to allow compilation of the code that uses metal interfaces for simulator
  14. // as protocols declarations should be available even if we do not call functions themselves
  15. #if !(TARGET_IPHONE_SIMULATOR && defined(__IPHONE_11_0)) && !(TARGET_TVOS_SIMULATOR && defined(__TVOS_11_0))
  16. typedef NSUInteger MTLPixelFormat;
  17. enum
  18. {
  19. MTLPixelFormatBGRA8Unorm,
  20. MTLPixelFormatBGRA8Unorm_sRGB,
  21. MTLPixelFormatR16Float,
  22. };
  23. #endif
  24. @interface CAMetalLayer : CALayer
  25. @property (readwrite) BOOL framebufferOnly;
  26. @property (readwrite) CGSize drawableSize;
  27. @property BOOL presentsWithTransaction;
  28. @property (readwrite, retain) id<MTLDevice> device;
  29. @property (readwrite) MTLPixelFormat pixelFormat;
  30. @property (readonly) id<MTLTexture> texture;
  31. - (id<CAMetalDrawable>)newDrawable;
  32. - (id<CAMetalDrawable>)nextDrawable;
  33. @end
  34. @protocol MTLDrawable
  35. @end
  36. @protocol CAMetalDrawable<MTLDrawable>
  37. @property (readonly) id<MTLTexture> texture;
  38. @end
  39. @protocol MTLDevice
  40. - (id<MTLCommandQueue>)newCommandQueue;
  41. - (id<MTLCommandQueue>)newCommandQueueWithMaxCommandBufferCount:(NSUInteger)maxCommandBufferCount;
  42. - (BOOL)supportsTextureSampleCount:(NSUInteger)sampleCount;
  43. @end
  44. @protocol MTLCommandBuffer
  45. - (void)presentDrawable:(id<MTLDrawable>)drawable;
  46. @end
  47. #endif