WebGLRenderTarget.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { EventDispatcher } from '../core/EventDispatcher';
  2. import { Texture } from '../textures/Texture';
  3. import { LinearFilter } from '../constants';
  4. import { Vector4 } from '../math/Vector4';
  5. import { _Math } from '../math/Math';
  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. Object.assign( WebGLRenderTarget.prototype, EventDispatcher.prototype, {
  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 };