WebGLMultipleRenderTargets.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { WebGLRenderTarget } from './WebGLRenderTarget.js';
  2. class WebGLMultipleRenderTargets extends WebGLRenderTarget {
  3. constructor( width = 1, height = 1, count = 1, options = {} ) {
  4. super( width, height, options );
  5. this.isWebGLMultipleRenderTargets = true;
  6. const texture = this.texture;
  7. this.texture = [];
  8. for ( let i = 0; i < count; i ++ ) {
  9. this.texture[ i ] = texture.clone();
  10. this.texture[ i ].isRenderTargetTexture = true;
  11. }
  12. }
  13. setSize( width, height, depth = 1 ) {
  14. if ( this.width !== width || this.height !== height || this.depth !== depth ) {
  15. this.width = width;
  16. this.height = height;
  17. this.depth = depth;
  18. for ( let i = 0, il = this.texture.length; i < il; i ++ ) {
  19. this.texture[ i ].image.width = width;
  20. this.texture[ i ].image.height = height;
  21. this.texture[ i ].image.depth = depth;
  22. }
  23. this.dispose();
  24. }
  25. this.viewport.set( 0, 0, width, height );
  26. this.scissor.set( 0, 0, width, height );
  27. }
  28. copy( source ) {
  29. this.dispose();
  30. this.width = source.width;
  31. this.height = source.height;
  32. this.depth = source.depth;
  33. this.scissor.copy( source.scissor );
  34. this.scissorTest = source.scissorTest;
  35. this.viewport.copy( source.viewport );
  36. this.depthBuffer = source.depthBuffer;
  37. this.stencilBuffer = source.stencilBuffer;
  38. if ( source.depthTexture !== null ) this.depthTexture = source.depthTexture.clone();
  39. this.texture.length = 0;
  40. for ( let i = 0, il = source.texture.length; i < il; i ++ ) {
  41. this.texture[ i ] = source.texture[ i ].clone();
  42. this.texture[ i ].isRenderTargetTexture = true;
  43. }
  44. return this;
  45. }
  46. }
  47. export { WebGLMultipleRenderTargets };