WebGLRenderTarget.js 2.4 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. In options, we can specify:
  7. * Texture parameters for an auto-generated target texture
  8. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  9. */
  10. function WebGLRenderTarget( width, height, options ) {
  11. this.width = width;
  12. this.height = height;
  13. this.scissor = new Vector4( 0, 0, width, height );
  14. this.scissorTest = false;
  15. this.viewport = new Vector4( 0, 0, width, height );
  16. options = options || {};
  17. this.texture = new Texture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  18. this.texture.image = {};
  19. this.texture.image.width = width;
  20. this.texture.image.height = height;
  21. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  22. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  23. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  24. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  25. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  26. }
  27. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  28. constructor: WebGLRenderTarget,
  29. isWebGLRenderTarget: true,
  30. setSize: function ( width, height ) {
  31. if ( this.width !== width || this.height !== height ) {
  32. this.width = width;
  33. this.height = height;
  34. this.texture.image.width = width;
  35. this.texture.image.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 };