thinRenderTargetTexture.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { ThinTexture } from "./thinTexture.js";
  2. /**
  3. * This is a tiny helper class to wrap a RenderTargetWrapper in a texture
  4. * usable as the input of an effect.
  5. */
  6. export class ThinRenderTargetTexture extends ThinTexture {
  7. /**
  8. * Gets the render target wrapper associated with this render target
  9. */
  10. get renderTarget() {
  11. return this._renderTarget;
  12. }
  13. /**
  14. * Instantiates a new ThinRenderTargetTexture.
  15. * Tiny helper class to wrap a RenderTargetWrapper in a texture.
  16. * This can be used as an internal texture wrapper in ThinEngine to benefit from the cache and to hold on the associated RTT
  17. * @param engine Define the internalTexture to wrap
  18. * @param size Define the size of the RTT to create
  19. * @param options Define rendertarget options
  20. */
  21. constructor(engine, size, options) {
  22. super(null);
  23. this._renderTarget = null;
  24. this._engine = engine;
  25. this._renderTargetOptions = options;
  26. this.resize(size);
  27. }
  28. /**
  29. * Resize the texture to a new desired size.
  30. * Be careful as it will recreate all the data in the new texture.
  31. * @param size Define the new size. It can be:
  32. * - a number for squared texture,
  33. * - an object containing { width: number, height: number }
  34. */
  35. resize(size) {
  36. this._renderTarget?.dispose();
  37. this._renderTarget = null;
  38. this._texture = null;
  39. this._size = size;
  40. if (this._engine) {
  41. this._renderTarget = this._engine.createRenderTargetTexture(this._size, this._renderTargetOptions);
  42. }
  43. this._texture = this.renderTarget.texture;
  44. }
  45. /**
  46. * Get the underlying lower level texture from Babylon.
  47. * @returns the internal texture
  48. */
  49. getInternalTexture() {
  50. return this._texture;
  51. }
  52. /**
  53. * Get the class name of the texture.
  54. * @returns "ThinRenderTargetTexture"
  55. */
  56. getClassName() {
  57. return "ThinRenderTargetTexture";
  58. }
  59. /**
  60. * Dispose the texture and release its associated resources.
  61. * @param disposeOnlyFramebuffers if set to true it will dispose only the frame buffers (default: false)
  62. */
  63. dispose(disposeOnlyFramebuffers = false) {
  64. this._renderTarget?.dispose(true);
  65. this._renderTarget = null;
  66. if (!disposeOnlyFramebuffers) {
  67. super.dispose();
  68. }
  69. }
  70. }
  71. //# sourceMappingURL=thinRenderTargetTexture.js.map