WebGLRenderTarget.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. this.texture = new Texture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  23. this.texture.image = {};
  24. this.texture.image.width = width;
  25. this.texture.image.height = height;
  26. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  27. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  28. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  29. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  30. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  31. }
  32. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  33. constructor: WebGLRenderTarget,
  34. isWebGLRenderTarget: true,
  35. setSize: function ( width, height ) {
  36. if ( this.width !== width || this.height !== height ) {
  37. this.width = width;
  38. this.height = height;
  39. this.texture.image.width = width;
  40. this.texture.image.height = height;
  41. this.dispose();
  42. }
  43. this.viewport.set( 0, 0, width, height );
  44. this.scissor.set( 0, 0, width, height );
  45. },
  46. clone: function () {
  47. return new this.constructor().copy( this );
  48. },
  49. copy: function ( source ) {
  50. this.width = source.width;
  51. this.height = source.height;
  52. this.viewport.copy( source.viewport );
  53. this.texture = source.texture.clone();
  54. this.depthBuffer = source.depthBuffer;
  55. this.stencilBuffer = source.stencilBuffer;
  56. this.depthTexture = source.depthTexture;
  57. return this;
  58. },
  59. dispose: function () {
  60. this.dispatchEvent( { type: 'dispose' } );
  61. }
  62. } );
  63. export { WebGLRenderTarget };