renderingManager.d.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import type { Nullable } from "../types";
  2. import type { SmartArray } from "../Misc/smartArray";
  3. import type { ISpriteManager } from "../Sprites/spriteManager";
  4. import type { IParticleSystem } from "../Particles/IParticleSystem";
  5. import { RenderingGroup } from "./renderingGroup";
  6. import type { Scene } from "../scene";
  7. import type { Camera } from "../Cameras/camera";
  8. import type { Material } from "../Materials/material";
  9. import type { SubMesh } from "../Meshes/subMesh";
  10. import type { AbstractMesh } from "../Meshes/abstractMesh";
  11. /**
  12. * Interface describing the different options available in the rendering manager
  13. * regarding Auto Clear between groups.
  14. */
  15. export interface IRenderingManagerAutoClearSetup {
  16. /**
  17. * Defines whether or not autoclear is enable.
  18. */
  19. autoClear: boolean;
  20. /**
  21. * Defines whether or not to autoclear the depth buffer.
  22. */
  23. depth: boolean;
  24. /**
  25. * Defines whether or not to autoclear the stencil buffer.
  26. */
  27. stencil: boolean;
  28. }
  29. /**
  30. * This class is used by the onRenderingGroupObservable
  31. */
  32. export declare class RenderingGroupInfo {
  33. /**
  34. * The Scene that being rendered
  35. */
  36. scene: Scene;
  37. /**
  38. * The camera currently used for the rendering pass
  39. */
  40. camera: Nullable<Camera>;
  41. /**
  42. * The ID of the renderingGroup being processed
  43. */
  44. renderingGroupId: number;
  45. }
  46. /**
  47. * This is the manager responsible of all the rendering for meshes sprites and particles.
  48. * It is enable to manage the different groups as well as the different necessary sort functions.
  49. * This should not be used directly aside of the few static configurations
  50. */
  51. export declare class RenderingManager {
  52. /**
  53. * The max id used for rendering groups (not included)
  54. */
  55. static MAX_RENDERINGGROUPS: number;
  56. /**
  57. * The min id used for rendering groups (included)
  58. */
  59. static MIN_RENDERINGGROUPS: number;
  60. /**
  61. * Used to globally prevent autoclearing scenes.
  62. */
  63. static AUTOCLEAR: boolean;
  64. /**
  65. * @internal
  66. */
  67. _useSceneAutoClearSetup: boolean;
  68. private _scene;
  69. private _renderingGroups;
  70. private _depthStencilBufferAlreadyCleaned;
  71. private _autoClearDepthStencil;
  72. private _customOpaqueSortCompareFn;
  73. private _customAlphaTestSortCompareFn;
  74. private _customTransparentSortCompareFn;
  75. private _renderingGroupInfo;
  76. private _maintainStateBetweenFrames;
  77. /**
  78. * Gets or sets a boolean indicating that the manager will not reset between frames.
  79. * This means that if a mesh becomes invisible or transparent it will not be visible until this boolean is set to false again.
  80. * By default, the rendering manager will dispatch all active meshes per frame (moving them to the transparent, opaque or alpha testing lists).
  81. * By turning this property on, you will accelerate the rendering by keeping all these lists unchanged between frames.
  82. */
  83. get maintainStateBetweenFrames(): boolean;
  84. set maintainStateBetweenFrames(value: boolean);
  85. /**
  86. * Restore wasDispatched flags on the lists of elements to render.
  87. */
  88. restoreDispachedFlags(): void;
  89. /**
  90. * Instantiates a new rendering group for a particular scene
  91. * @param scene Defines the scene the groups belongs to
  92. */
  93. constructor(scene: Scene);
  94. /**
  95. * @returns the rendering group with the specified id.
  96. * @param id the id of the rendering group (0 by default)
  97. */
  98. getRenderingGroup(id: number): RenderingGroup;
  99. private _clearDepthStencilBuffer;
  100. /**
  101. * Renders the entire managed groups. This is used by the scene or the different render targets.
  102. * @internal
  103. */
  104. render(customRenderFunction: Nullable<(opaqueSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>, depthOnlySubMeshes: SmartArray<SubMesh>) => void>, activeMeshes: Nullable<AbstractMesh[]>, renderParticles: boolean, renderSprites: boolean): void;
  105. /**
  106. * Resets the different information of the group to prepare a new frame
  107. * @internal
  108. */
  109. reset(): void;
  110. /**
  111. * Resets the sprites information of the group to prepare a new frame
  112. * @internal
  113. */
  114. resetSprites(): void;
  115. /**
  116. * Dispose and release the group and its associated resources.
  117. * @internal
  118. */
  119. dispose(): void;
  120. /**
  121. * Clear the info related to rendering groups preventing retention points during dispose.
  122. */
  123. freeRenderingGroups(): void;
  124. private _prepareRenderingGroup;
  125. /**
  126. * Add a sprite manager to the rendering manager in order to render it this frame.
  127. * @param spriteManager Define the sprite manager to render
  128. */
  129. dispatchSprites(spriteManager: ISpriteManager): void;
  130. /**
  131. * Add a particle system to the rendering manager in order to render it this frame.
  132. * @param particleSystem Define the particle system to render
  133. */
  134. dispatchParticles(particleSystem: IParticleSystem): void;
  135. /**
  136. * Add a submesh to the manager in order to render it this frame
  137. * @param subMesh The submesh to dispatch
  138. * @param mesh Optional reference to the submeshes's mesh. Provide if you have an exiting reference to improve performance.
  139. * @param material Optional reference to the submeshes's material. Provide if you have an exiting reference to improve performance.
  140. */
  141. dispatch(subMesh: SubMesh, mesh?: AbstractMesh, material?: Nullable<Material>): void;
  142. /**
  143. * Overrides the default sort function applied in the rendering group to prepare the meshes.
  144. * This allowed control for front to back rendering or reversely depending of the special needs.
  145. *
  146. * @param renderingGroupId The rendering group id corresponding to its index
  147. * @param opaqueSortCompareFn The opaque queue comparison function use to sort.
  148. * @param alphaTestSortCompareFn The alpha test queue comparison function use to sort.
  149. * @param transparentSortCompareFn The transparent queue comparison function use to sort.
  150. */
  151. setRenderingOrder(renderingGroupId: number, opaqueSortCompareFn?: Nullable<(a: SubMesh, b: SubMesh) => number>, alphaTestSortCompareFn?: Nullable<(a: SubMesh, b: SubMesh) => number>, transparentSortCompareFn?: Nullable<(a: SubMesh, b: SubMesh) => number>): void;
  152. /**
  153. * Specifies whether or not the stencil and depth buffer are cleared between two rendering groups.
  154. *
  155. * @param renderingGroupId The rendering group id corresponding to its index
  156. * @param autoClearDepthStencil Automatically clears depth and stencil between groups if true.
  157. * @param depth Automatically clears depth between groups if true and autoClear is true.
  158. * @param stencil Automatically clears stencil between groups if true and autoClear is true.
  159. */
  160. setRenderingAutoClearDepthStencil(renderingGroupId: number, autoClearDepthStencil: boolean, depth?: boolean, stencil?: boolean): void;
  161. /**
  162. * Gets the current auto clear configuration for one rendering group of the rendering
  163. * manager.
  164. * @param index the rendering group index to get the information for
  165. * @returns The auto clear setup for the requested rendering group
  166. */
  167. getAutoClearDepthStencilSetup(index: number): IRenderingManagerAutoClearSetup;
  168. }