spriteRenderer.d.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import type { Nullable } from "../types";
  2. import type { IMatrixLike } from "../Maths/math.like";
  3. import type { AbstractEngine } from "../Engines/abstractEngine";
  4. import type { ThinSprite } from "./thinSprite";
  5. import type { ISize } from "../Maths/math.size";
  6. import type { ThinTexture } from "../Materials/Textures/thinTexture";
  7. import type { Scene } from "../scene";
  8. import "../Engines/Extensions/engine.alpha";
  9. import "../Engines/Extensions/engine.dynamicBuffer";
  10. import "../Shaders/sprites.fragment";
  11. import "../Shaders/sprites.vertex";
  12. /**
  13. * Class used to render sprites.
  14. *
  15. * It can be used either to render Sprites or ThinSprites with ThinEngine only.
  16. */
  17. export declare class SpriteRenderer {
  18. /**
  19. * Defines the texture of the spritesheet
  20. */
  21. texture: Nullable<ThinTexture>;
  22. /**
  23. * Defines the default width of a cell in the spritesheet
  24. */
  25. cellWidth: number;
  26. /**
  27. * Defines the default height of a cell in the spritesheet
  28. */
  29. cellHeight: number;
  30. /**
  31. * Blend mode use to render the particle, it can be any of
  32. * the static Constants.ALPHA_x properties provided in this class.
  33. * Default value is Constants.ALPHA_COMBINE
  34. */
  35. blendMode: number;
  36. /**
  37. * Gets or sets a boolean indicating if alpha mode is automatically
  38. * reset.
  39. */
  40. autoResetAlpha: boolean;
  41. /**
  42. * Disables writing to the depth buffer when rendering the sprites.
  43. * It can be handy to disable depth writing when using textures without alpha channel
  44. * and setting some specific blend modes.
  45. */
  46. disableDepthWrite: boolean;
  47. /**
  48. * Gets or sets a boolean indicating if the manager must consider scene fog when rendering
  49. */
  50. fogEnabled: boolean;
  51. /**
  52. * Gets the capacity of the manager
  53. */
  54. get capacity(): number;
  55. private _pixelPerfect;
  56. /**
  57. * Gets or sets a boolean indicating if the renderer must render sprites with pixel perfect rendering
  58. * Note that pixel perfect mode is not supported in WebGL 1
  59. */
  60. get pixelPerfect(): boolean;
  61. set pixelPerfect(value: boolean);
  62. private readonly _engine;
  63. private readonly _useVAO;
  64. private readonly _useInstancing;
  65. private readonly _scene;
  66. private readonly _capacity;
  67. private readonly _epsilon;
  68. private _vertexBufferSize;
  69. private _vertexData;
  70. private _buffer;
  71. private _vertexBuffers;
  72. private _spriteBuffer;
  73. private _indexBuffer;
  74. private _drawWrapperBase;
  75. private _drawWrapperFog;
  76. private _drawWrapperDepth;
  77. private _drawWrapperFogDepth;
  78. private _vertexArrayObject;
  79. /**
  80. * Creates a new sprite Renderer
  81. * @param engine defines the engine the renderer works with
  82. * @param capacity defines the maximum allowed number of sprites
  83. * @param epsilon defines the epsilon value to align texture (0.01 by default)
  84. * @param scene defines the hosting scene
  85. */
  86. constructor(engine: AbstractEngine, capacity: number, epsilon?: number, scene?: Nullable<Scene>);
  87. private _createEffects;
  88. /**
  89. * Render all child sprites
  90. * @param sprites defines the list of sprites to render
  91. * @param deltaTime defines the time since last frame
  92. * @param viewMatrix defines the viewMatrix to use to render the sprites
  93. * @param projectionMatrix defines the projectionMatrix to use to render the sprites
  94. * @param customSpriteUpdate defines a custom function to update the sprites data before they render
  95. */
  96. render(sprites: ThinSprite[], deltaTime: number, viewMatrix: IMatrixLike, projectionMatrix: IMatrixLike, customSpriteUpdate?: Nullable<(sprite: ThinSprite, baseSize: ISize) => void>): void;
  97. private _appendSpriteVertex;
  98. private _buildIndexBuffer;
  99. /**
  100. * Rebuilds the renderer (after a context lost, for eg)
  101. */
  102. rebuild(): void;
  103. /**
  104. * Release associated resources
  105. */
  106. dispose(): void;
  107. }