WebGLRenderTarget.js 1.9 KB
Newer Older
1 2
/**
 * @author szimek / https://github.com/szimek/
3
 * @author alteredq / http://alteredqualia.com/
4
 * @author Marius Kintel / https://github.com/kintel
5 6
 */

7 8 9 10 11
/*
 In options, we can specify:
 * Texture parameters for an auto-generated target texture
 * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
*/
12
THREE.WebGLRenderTarget = function ( width, height, options ) {
13

14 15
	this.uuid = THREE.Math.generateUUID();

16 17 18
	this.width = width;
	this.height = height;

M
Mr.doob 已提交
19
	this.scissor = new THREE.Vector4( 0, 0, width, height );
20 21
	this.scissorTest = false;

M
Mr.doob 已提交
22
	this.viewport = new THREE.Vector4( 0, 0, width, height );
23

24 25
	options = options || {};

M
Mr.doob 已提交
26 27
	if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;

B
Ben Houston (Clara.io) 已提交
28
	this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
29

M
Mikael Emtinger 已提交
30 31
	this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
	this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
32
	this.depthTexture = null;
33 34

};
35

36
Object.assign( THREE.WebGLRenderTarget.prototype, THREE.EventDispatcher.prototype, {
37

M
Mr.doob 已提交
38 39 40 41 42 43 44 45 46 47 48
	setSize: function ( width, height ) {

		if ( this.width !== width || this.height !== height ) {

			this.width = width;
			this.height = height;

			this.dispose();

		}

M
Mr.doob 已提交
49
		this.viewport.set( 0, 0, width, height );
50
		this.scissor.set( 0, 0, width, height );
51 52 53

	},

M
Mr.doob 已提交
54 55 56 57 58 59 60 61 62 63 64
	clone: function () {

		return new this.constructor().copy( this );

	},

	copy: function ( source ) {

		this.width = source.width;
		this.height = source.height;

M
Mr.doob 已提交
65 66
		this.viewport.copy( source.viewport );

M
Mr.doob 已提交
67 68 69 70
		this.texture = source.texture.clone();

		this.depthBuffer = source.depthBuffer;
		this.stencilBuffer = source.stencilBuffer;
71
		this.depthTexture = source.depthTexture;
M
Mr.doob 已提交
72 73 74 75 76 77 78 79

		return this;

	},

	dispose: function () {

		this.dispatchEvent( { type: 'dispose' } );
M
Marius Kintel 已提交
80 81

	}
M
Mr.doob 已提交
82

83
} );