RenderPluginDelegate.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #import <UnityFramework/LifeCycleListener.h>
  3. struct UnityDisplaySurfaceBase; // Unity/UnityRendering.h
  4. struct RenderingSurfaceParams; // Unity/DisplayManager.h
  5. // due to delicate nature of render loop we have just one delegate in app
  6. // if you need to use several rendering delegates you need to do one of:
  7. // 1. create custom delegate that will have code to combine effects by itself
  8. // 2. use helper that simply holds array of delegates (which will work only in easiest cases)
  9. @protocol RenderPluginDelegate<LifeCycleListener, NSObject>
  10. @required
  11. // this will be called right after gles intialization.
  12. // surface pointer will never be changed, so you should keep it.
  13. // the only valid fields in there as of now are layer and context
  14. - (void)mainDisplayInited:(struct UnityDisplaySurfaceBase*)surface;
  15. @optional
  16. // this will be called before recreating main display surface (from [UnityView recreateRenderingSurface])
  17. // you can tweak params here.
  18. - (void)onBeforeMainDisplaySurfaceRecreate:(struct RenderingSurfaceParams*)params;
  19. // this will be called right after recreating main display surface (from [UnityView recreateRenderingSurface])
  20. // as [UnityView recreateRenderingSurface] is the only place where unity itself will trigger surface recreate
  21. // you can use this method to update your rendering depending on changes
  22. - (void)onAfterMainDisplaySurfaceRecreate;
  23. // this will be called after frame render and msaa resolve but before blitting to system FB
  24. // you can expect that frame contents are ready (though still in target resolution)
  25. // use it for anylizing/postprocessing rendered frame, taking screenshot and the like
  26. // you should use targetFB if it is not 0
  27. // otherwise use systemFB
  28. - (void)onFrameResolved;
  29. @end
  30. // simple helper for common plugin stuff
  31. // you can implement protocol directly, but subclassing this will provide some common implementation
  32. @interface RenderPluginDelegate : NSObject<RenderPluginDelegate>
  33. {
  34. struct UnityDisplaySurfaceBase* mainDisplaySurface;
  35. }
  36. - (void)mainDisplayInited:(struct UnityDisplaySurfaceBase*)surface;
  37. @end
  38. // simple helper to have an array of render delegates.
  39. // be warned that it works in simplest cases only, when there is no interop between delegates
  40. @interface RenderPluginArrayDelegate : RenderPluginDelegate
  41. {
  42. NSArray* delegateArray;
  43. }
  44. @property(nonatomic, retain) NSArray* delegateArray;
  45. - (void)mainDisplayInited:(struct UnityDisplaySurfaceBase*)surface;
  46. - (void)onBeforeMainDisplaySurfaceRecreate:(struct RenderingSurfaceParams*)params;
  47. - (void)onAfterMainDisplaySurfaceRecreate;
  48. - (void)onFrameResolved;
  49. - (void)didBecomeActive:(NSNotification*)notification;
  50. - (void)willResignActive:(NSNotification*)notification;
  51. - (void)didEnterBackground:(NSNotification*)notification;
  52. - (void)willEnterForeground:(NSNotification*)notification;
  53. - (void)willTerminate:(NSNotification*)notification;
  54. @end