MultiviewRenderTarget.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { RenderTargetTexture } from '../Textures/renderTargetTexture';
  2. import { Scene } from '../../scene';
  3. import { InternalTextureSource } from '../Textures/internalTexture';
  4. /**
  5. * Renders to multiple views with a single draw call
  6. * @see https://www.khronos.org/registry/webgl/extensions/WEBGL_multiview/
  7. */
  8. export class MultiviewRenderTarget extends RenderTargetTexture {
  9. /**
  10. * Creates a multiview render target
  11. * @param scene scene used with the render target
  12. * @param size the size of the render target (used for each view)
  13. */
  14. constructor(scene: Scene, size: number | { width: number, height: number } | { ratio: number } = 512) {
  15. super("multiview rtt", size, scene, false, true, InternalTextureSource.Unknown, false, undefined, false, false, true, undefined, true);
  16. var internalTexture = scene.getEngine().createMultiviewRenderTargetTexture(this.getRenderWidth(), this.getRenderHeight());
  17. internalTexture.isMultiview = true;
  18. this._texture = internalTexture;
  19. this.samples = this._engine.getCaps().maxSamples || this.samples;
  20. }
  21. /**
  22. * @hidden
  23. * @param faceIndex the face index, if its a cube texture
  24. */
  25. public _bindFrameBuffer(faceIndex: number = 0) {
  26. if (!this._texture) {
  27. return;
  28. }
  29. this.getScene()!.getEngine().bindMultiviewFramebuffer(this._texture);
  30. }
  31. /**
  32. * Gets the number of views the corresponding to the texture (eg. a MultiviewRenderTarget will have > 1)
  33. * @returns the view count
  34. */
  35. public getViewCount() {
  36. return 2;
  37. }
  38. }