MBMCustomLayerHost.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #import <Foundation/Foundation.h>
  2. @protocol MTLDevice, MTLCommandBuffer, MTLRenderCommandEncoder;
  3. @class MTLRenderPassDescriptor;
  4. @class MBMCanonicalTileID;
  5. @class MBMCustomLayerRenderConfiguration;
  6. @class MBMCustomLayerRenderParameters;
  7. /**
  8. * Interface for hosting a custom map style layer.
  9. */
  10. NS_SWIFT_NAME(CustomLayerHost)
  11. @protocol MBMCustomLayerHost <NSObject>
  12. /**
  13. * Initialize any Metal 3D graphic API state needed by the custom layer. This method is called
  14. * once when view starts or resumes to foreground but before rendering for the first time.
  15. *
  16. * `colorPixelFormat` and `depthStencilPixelFormat` are values of MTLPixelFormat and are declared here
  17. * as underlying NSUinteger to avoid import here.
  18. *
  19. * This method is called if underlying map rendering backend uses Metal graphic API.
  20. *
  21. * Resources that are acquired in this method must be released in the `deinitialize` function.
  22. */
  23. - (void)renderingWillStart:(nonnull id<MTLDevice>)metalDevice
  24. colorPixelFormat:(NSUInteger)colorPixelFormat
  25. depthStencilPixelFormat:(NSUInteger)depthStencilPixelFormat;
  26. /**
  27. * Render the layer. This method is called once per frame.
  28. *
  29. * This method is called if underlying map rendering backend uses Metal graphic API.
  30. *
  31. * @param The `parameters` that define the current camera position.
  32. * @param The MTLCommandBuffer used to render all map layers.
  33. * Use to create new command encoders. Do not submit as there could be map
  34. * layers following this custom layer in style's layer list and those won't get
  35. * to be encoded.
  36. * @param The MTLRenderPassDescriptor that defines rendering map to view drawable.
  37. *
  38. */
  39. - (void)render:(nonnull MBMCustomLayerRenderParameters *)parameters
  40. mtlCommandBuffer:(nonnull id<MTLCommandBuffer>)mtlCommandBuffer
  41. mtlRenderPassDescriptor:(nonnull MTLRenderPassDescriptor *)mtlRenderPassDescriptor;
  42. /**
  43. * Destroy any state needed by the custom layer, and deallocate context, if necessary. This
  44. * method is called once, from the main thread, at a point when Metal or OpenGL context is active.
  45. *
  46. * Note that it may be called even when the `renderingWillStart` function has not been called.
  47. */
  48. - (void)renderingWillEnd;
  49. @optional
  50. /**
  51. * Note! This selector is an experimental feature. It can be changed or removed in future versions.
  52. */
  53. - (nonnull MBMCustomLayerRenderConfiguration *)prerender:(nonnull MBMCustomLayerRenderParameters *)parameters
  54. mtlCommandBuffer:(nonnull id<MTLCommandBuffer>)mtlCommandBuffer;
  55. /**
  56. * Note! This selector is an experimental feature. It can be changed or removed in future versions.
  57. */
  58. - (void)renderToTile:(nonnull MBMCanonicalTileID *)tileID
  59. mtlRenderCommandEncoder:(nonnull id<MTLRenderCommandEncoder>)mtlRenderCommandEncoder;
  60. /**
  61. * Initialize any OpenGL 3D graphic API state needed by the custom layer. This method is called
  62. * once when view starts or resumes to foreground but before rendering for the first time.
  63. *
  64. * As Apple is deprecating legacy OpenGL API, this method is optional and is called only if
  65. * underlying map rendering backend uses OpenGL graphic API.
  66. *
  67. * Resources that are acquired in this method must be released in the `deinitialize` function.
  68. */
  69. - (void)renderingWillStartOpenGL;
  70. /**
  71. * Render the layer. This method is called once per frame. The implementation should not make
  72. * any assumptions about the GL state (other than that the correct context is active). It may
  73. * make changes to the state, and is not required to reset values such as the depth mask, stencil
  74. * mask, and corresponding test flags to their original values.
  75. * Make sure that you are drawing your fragments with a z value of 1 to take advantage of the
  76. * opaque fragment culling in case there are opaque layers above your custom layer.
  77. *
  78. * As Apple is deprecating legacy OpenGL API, this method is optional and is called only if
  79. * underlying map rendering backend uses OpenGL graphic API.
  80. *
  81. * @param The `parameters` that define the current camera position.
  82. *
  83. */
  84. - (void)renderOpenGL:(nonnull MBMCustomLayerRenderParameters *)parameters;
  85. /**
  86. * Called when the system has destroyed the underlying OpenGL context. The
  87. * `renderingWillEnd` function will not be called in this case, however
  88. * `setupRendering` will be called instead to prepare for a new render.
  89. *
  90. * As Apple is deprecating legacy OpenGL API, this method is optional and is called only if
  91. * underlying map rendering backend uses OpenGL graphic API.
  92. *
  93. */
  94. - (void)openGLContextLost;
  95. @end