RenderPluginDelegate.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include "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. // use it for enabling CVTextureCache support and the likes
  19. - (void)onBeforeMainDisplaySurfaceRecreate:(struct RenderingSurfaceParams*)params;
  20. // this will be called right after recreating main display surface (from [UnityView recreateRenderingSurface])
  21. // as [UnityView recreateRenderingSurface] is the only place where unity itself will trigger surface recreate
  22. // you can use this method to update your rendering depending on changes
  23. - (void)onAfterMainDisplaySurfaceRecreate;
  24. // this will be called after frame render and msaa resolve but before blitting to system FB
  25. // you can expect that frame contents are ready (though still in target resolution)
  26. // use it for anylizing/postprocessing rendered frame, taking screenshot and the like
  27. // you should use targetFB if it is not 0
  28. // otherwise use systemFB (covers case of intermediate fb not needed: no msaa, native res, no CVTextureCache involved)
  29. - (void)onFrameResolved;
  30. @end
  31. // simple helper for common plugin stuff
  32. // you can implement protocol directly, but subclassing this will provide some common implementation
  33. @interface RenderPluginDelegate : NSObject<RenderPluginDelegate>
  34. {
  35. struct UnityDisplaySurfaceBase* mainDisplaySurface;
  36. }
  37. - (void)mainDisplayInited:(struct UnityDisplaySurfaceBase*)surface;
  38. @end
  39. // simple helper to have an array of render delegates.
  40. // be warned that it works in simplest cases only, when there is no interop between delegates
  41. @interface RenderPluginArrayDelegate : RenderPluginDelegate
  42. {
  43. NSArray* delegateArray;
  44. }
  45. @property(nonatomic, retain) NSArray* delegateArray;
  46. - (void)mainDisplayInited:(struct UnityDisplaySurfaceBase*)surface;
  47. - (void)onBeforeMainDisplaySurfaceRecreate:(struct RenderingSurfaceParams*)params;
  48. - (void)onAfterMainDisplaySurfaceRecreate;
  49. - (void)onFrameResolved;
  50. - (void)didBecomeActive:(NSNotification*)notification;
  51. - (void)willResignActive:(NSNotification*)notification;
  52. - (void)didEnterBackground:(NSNotification*)notification;
  53. - (void)willEnterForeground:(NSNotification*)notification;
  54. - (void)willTerminate:(NSNotification*)notification;
  55. @end