WebGLRenderTarget.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { EventDispatcher } from '../core/EventDispatcher.js';
  2. import { Texture } from '../textures/Texture.js';
  3. import { LinearFilter } from '../constants.js';
  4. import { Vector4 } from '../math/Vector4.js';
  5. /**
  6. * @author szimek / https://github.com/szimek/
  7. * @author alteredq / http://alteredqualia.com/
  8. * @author Marius Kintel / https://github.com/kintel
  9. */
  10. /*
  11. In options, we can specify:
  12. * Texture parameters for an auto-generated target texture
  13. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  14. */
  15. function WebGLRenderTarget( width, height, options ) {
  16. this.width = width;
  17. this.height = height;
  18. this.scissor = new Vector4( 0, 0, width, height );
  19. this.scissorTest = false;
  20. this.viewport = new Vector4( 0, 0, width, height );
  21. options = options || {};
  22. if ( options.minFilter === undefined ) options.minFilter = LinearFilter;
  23. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  24. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  25. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  26. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  27. }
  28. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  29. constructor: WebGLRenderTarget,
  30. isWebGLRenderTarget: true,
  31. setSize: function ( width, height ) {
  32. if ( this.width !== width || this.height !== height ) {
  33. this.width = width;
  34. this.height = height;
  35. this.dispose();
  36. }
  37. this.viewport.set( 0, 0, width, height );
  38. this.scissor.set( 0, 0, width, height );
  39. },
  40. clone: function () {
  41. return new this.constructor().copy( this );
  42. },
  43. copy: function ( source ) {
  44. this.width = source.width;
  45. this.height = source.height;
  46. this.viewport.copy( source.viewport );
  47. this.texture = source.texture.clone();
  48. this.depthBuffer = source.depthBuffer;
  49. this.stencilBuffer = source.stencilBuffer;
  50. this.depthTexture = source.depthTexture;
  51. return this;
  52. },
  53. dispose: function () {
  54. this.dispatchEvent( { type: 'dispose' } );
  55. }
  56. } );
  57. export { WebGLRenderTarget };