WebGLRenderTarget.js 2.3 KB

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