WebGLRenderTarget.js 2.3 KB

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