effectRenderer.d.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import type { Nullable } from "../types";
  2. import type { AbstractEngine } from "../Engines/abstractEngine";
  3. import { Viewport } from "../Maths/math.viewport";
  4. import { Observable } from "../Misc/observable";
  5. import { Effect } from "./effect";
  6. import { DrawWrapper } from "./drawWrapper";
  7. import type { IRenderTargetTexture, RenderTargetWrapper } from "../Engines/renderTargetWrapper";
  8. import type { ShaderLanguage } from "./shaderLanguage";
  9. import "../Shaders/postprocess.vertex";
  10. /**
  11. * Effect Render Options
  12. */
  13. export interface IEffectRendererOptions {
  14. /**
  15. * Defines the vertices positions.
  16. */
  17. positions?: number[];
  18. /**
  19. * Defines the indices.
  20. */
  21. indices?: number[];
  22. }
  23. /**
  24. * Helper class to render one or more effects.
  25. * You can access the previous rendering in your shader by declaring a sampler named textureSampler
  26. */
  27. export declare class EffectRenderer {
  28. /**
  29. * The engine the effect renderer has been created for.
  30. */
  31. readonly engine: AbstractEngine;
  32. private _vertexBuffers;
  33. private _indexBuffer;
  34. private _fullscreenViewport;
  35. private _onContextRestoredObserver;
  36. private _savedStateDepthTest;
  37. private _savedStateStencilTest;
  38. /**
  39. * Creates an effect renderer
  40. * @param engine the engine to use for rendering
  41. * @param options defines the options of the effect renderer
  42. */
  43. constructor(engine: AbstractEngine, options?: IEffectRendererOptions);
  44. /**
  45. * Sets the current viewport in normalized coordinates 0-1
  46. * @param viewport Defines the viewport to set (defaults to 0 0 1 1)
  47. */
  48. setViewport(viewport?: Viewport): void;
  49. /**
  50. * Binds the embedded attributes buffer to the effect.
  51. * @param effect Defines the effect to bind the attributes for
  52. */
  53. bindBuffers(effect: Effect): void;
  54. /**
  55. * Sets the current effect wrapper to use during draw.
  56. * The effect needs to be ready before calling this api.
  57. * This also sets the default full screen position attribute.
  58. * @param effectWrapper Defines the effect to draw with
  59. */
  60. applyEffectWrapper(effectWrapper: EffectWrapper): void;
  61. /**
  62. * Saves engine states
  63. */
  64. saveStates(): void;
  65. /**
  66. * Restores engine states
  67. */
  68. restoreStates(): void;
  69. /**
  70. * Draws a full screen quad.
  71. */
  72. draw(): void;
  73. private _isRenderTargetTexture;
  74. /**
  75. * renders one or more effects to a specified texture
  76. * @param effectWrapper the effect to renderer
  77. * @param outputTexture texture to draw to, if null it will render to the screen.
  78. */
  79. render(effectWrapper: EffectWrapper, outputTexture?: Nullable<RenderTargetWrapper | IRenderTargetTexture>): void;
  80. /**
  81. * Disposes of the effect renderer
  82. */
  83. dispose(): void;
  84. }
  85. /**
  86. * Options to create an EffectWrapper
  87. */
  88. interface EffectWrapperCreationOptions {
  89. /**
  90. * Engine to use to create the effect
  91. */
  92. engine: AbstractEngine;
  93. /**
  94. * Fragment shader for the effect
  95. */
  96. fragmentShader: string;
  97. /**
  98. * Use the shader store instead of direct source code
  99. */
  100. useShaderStore?: boolean;
  101. /**
  102. * Vertex shader for the effect
  103. */
  104. vertexShader?: string;
  105. /**
  106. * Attributes to use in the shader
  107. */
  108. attributeNames?: Array<string>;
  109. /**
  110. * Uniforms to use in the shader
  111. */
  112. uniformNames?: Array<string>;
  113. /**
  114. * Texture sampler names to use in the shader
  115. */
  116. samplerNames?: Array<string>;
  117. /**
  118. * Defines to use in the shader
  119. */
  120. defines?: Array<string>;
  121. /**
  122. * Callback when effect is compiled
  123. */
  124. onCompiled?: Nullable<(effect: Effect) => void>;
  125. /**
  126. * The friendly name of the effect displayed in Spector.
  127. */
  128. name?: string;
  129. /**
  130. * The language the shader is written in (default: GLSL)
  131. */
  132. shaderLanguage?: ShaderLanguage;
  133. }
  134. /**
  135. * Wraps an effect to be used for rendering
  136. */
  137. export declare class EffectWrapper {
  138. /**
  139. * Event that is fired right before the effect is drawn (should be used to update uniforms)
  140. */
  141. onApplyObservable: Observable<{}>;
  142. /**
  143. * The underlying effect
  144. */
  145. get effect(): Effect;
  146. set effect(effect: Effect);
  147. /** @internal */
  148. _drawWrapper: DrawWrapper;
  149. private _onContextRestoredObserver;
  150. /**
  151. * Creates an effect to be renderer
  152. * @param creationOptions options to create the effect
  153. */
  154. constructor(creationOptions: EffectWrapperCreationOptions);
  155. /**
  156. * Disposes of the effect wrapper
  157. */
  158. dispose(): void;
  159. }
  160. export {};