Skip to content

Commit 8c3d080

Browse files
authored
Merge pull request #21053 from alexfriesen/es6-render-target
WebGLRenderTarget: convert to es6
2 parents 7cc1b69 + d77892b commit 8c3d080

File tree

3 files changed

+113
-113
lines changed

3 files changed

+113
-113
lines changed

src/renderers/WebGLCubeRenderTarget.js

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -7,136 +7,138 @@ import { WebGLRenderTarget } from './WebGLRenderTarget.js';
77
import { CubeCamera } from '../cameras/CubeCamera.js';
88
import { CubeTexture } from '../textures/CubeTexture.js';
99

10-
function WebGLCubeRenderTarget( size, options, dummy ) {
10+
class WebGLCubeRenderTarget extends WebGLRenderTarget {
1111

12-
if ( Number.isInteger( options ) ) {
12+
constructor( size, options, dummy ) {
1313

14-
console.warn( 'THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )' );
14+
if ( Number.isInteger( options ) ) {
1515

16-
options = dummy;
16+
console.warn( 'THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )' );
1717

18-
}
18+
options = dummy;
1919

20-
WebGLRenderTarget.call( this, size, size, options );
20+
}
2121

22-
options = options || {};
22+
super( size, size, options );
2323

24-
this.texture = new CubeTexture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
24+
Object.defineProperty( this, 'isWebGLCubeRenderTarget', { value: true } );
2525

26-
this.texture._needsFlipEnvMap = false;
26+
options = options || {};
2727

28-
}
28+
this.texture = new CubeTexture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
2929

30-
WebGLCubeRenderTarget.prototype = Object.create( WebGLRenderTarget.prototype );
31-
WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
30+
this.texture._needsFlipEnvMap = false;
3231

33-
WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
32+
}
3433

35-
WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer, texture ) {
34+
fromEquirectangularTexture( renderer, texture ) {
3635

37-
this.texture.type = texture.type;
38-
this.texture.format = RGBAFormat; // see #18859
39-
this.texture.encoding = texture.encoding;
36+
this.texture.type = texture.type;
37+
this.texture.format = RGBAFormat; // see #18859
38+
this.texture.encoding = texture.encoding;
4039

41-
this.texture.generateMipmaps = texture.generateMipmaps;
42-
this.texture.minFilter = texture.minFilter;
43-
this.texture.magFilter = texture.magFilter;
40+
this.texture.generateMipmaps = texture.generateMipmaps;
41+
this.texture.minFilter = texture.minFilter;
42+
this.texture.magFilter = texture.magFilter;
4443

45-
const shader = {
44+
const shader = {
4645

47-
uniforms: {
48-
tEquirect: { value: null },
49-
},
46+
uniforms: {
47+
tEquirect: { value: null },
48+
},
5049

51-
vertexShader: /* glsl */`
50+
vertexShader: /* glsl */`
5251
53-
varying vec3 vWorldDirection;
52+
varying vec3 vWorldDirection;
5453
55-
vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
54+
vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
5655
57-
return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
56+
return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
5857
59-
}
58+
}
6059
61-
void main() {
60+
void main() {
6261
63-
vWorldDirection = transformDirection( position, modelMatrix );
62+
vWorldDirection = transformDirection( position, modelMatrix );
6463
65-
#include <begin_vertex>
66-
#include <project_vertex>
64+
#include <begin_vertex>
65+
#include <project_vertex>
6766
68-
}
69-
`,
67+
}
68+
`,
7069

71-
fragmentShader: /* glsl */`
70+
fragmentShader: /* glsl */`
7271
73-
uniform sampler2D tEquirect;
72+
uniform sampler2D tEquirect;
7473
75-
varying vec3 vWorldDirection;
74+
varying vec3 vWorldDirection;
7675
77-
#include <common>
76+
#include <common>
7877
79-
void main() {
78+
void main() {
8079
81-
vec3 direction = normalize( vWorldDirection );
80+
vec3 direction = normalize( vWorldDirection );
8281
83-
vec2 sampleUV = equirectUv( direction );
82+
vec2 sampleUV = equirectUv( direction );
8483
85-
gl_FragColor = texture2D( tEquirect, sampleUV );
84+
gl_FragColor = texture2D( tEquirect, sampleUV );
8685
87-
}
88-
`
89-
};
86+
}
87+
`
88+
};
9089

91-
const geometry = new BoxGeometry( 5, 5, 5 );
90+
const geometry = new BoxGeometry( 5, 5, 5 );
9291

93-
const material = new ShaderMaterial( {
92+
const material = new ShaderMaterial( {
9493

95-
name: 'CubemapFromEquirect',
94+
name: 'CubemapFromEquirect',
9695

97-
uniforms: cloneUniforms( shader.uniforms ),
98-
vertexShader: shader.vertexShader,
99-
fragmentShader: shader.fragmentShader,
100-
side: BackSide,
101-
blending: NoBlending
96+
uniforms: cloneUniforms( shader.uniforms ),
97+
vertexShader: shader.vertexShader,
98+
fragmentShader: shader.fragmentShader,
99+
side: BackSide,
100+
blending: NoBlending
102101

103-
} );
102+
} );
104103

105-
material.uniforms.tEquirect.value = texture;
104+
material.uniforms.tEquirect.value = texture;
106105

107-
const mesh = new Mesh( geometry, material );
106+
const mesh = new Mesh( geometry, material );
108107

109-
const currentMinFilter = texture.minFilter;
108+
const currentMinFilter = texture.minFilter;
110109

111-
// Avoid blurred poles
112-
if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;
110+
// Avoid blurred poles
111+
if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;
113112

114-
const camera = new CubeCamera( 1, 10, this );
115-
camera.update( renderer, mesh );
113+
const camera = new CubeCamera( 1, 10, this );
114+
camera.update( renderer, mesh );
116115

117-
texture.minFilter = currentMinFilter;
116+
texture.minFilter = currentMinFilter;
118117

119-
mesh.geometry.dispose();
120-
mesh.material.dispose();
118+
mesh.geometry.dispose();
119+
mesh.material.dispose();
121120

122-
return this;
121+
return this;
123122

124-
};
123+
}
125124

126-
WebGLCubeRenderTarget.prototype.clear = function ( renderer, color, depth, stencil ) {
125+
clear( renderer, color, depth, stencil ) {
127126

128-
const currentRenderTarget = renderer.getRenderTarget();
127+
const currentRenderTarget = renderer.getRenderTarget();
129128

130-
for ( let i = 0; i < 6; i ++ ) {
129+
for ( let i = 0; i < 6; i ++ ) {
131130

132-
renderer.setRenderTarget( this, i );
131+
renderer.setRenderTarget( this, i );
133132

134-
renderer.clear( color, depth, stencil );
133+
renderer.clear( color, depth, stencil );
134+
135+
}
136+
137+
renderer.setRenderTarget( currentRenderTarget );
135138

136139
}
137140

138-
renderer.setRenderTarget( currentRenderTarget );
141+
}
139142

140-
};
141143

142144
export { WebGLCubeRenderTarget };
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
import { WebGLRenderTarget } from './WebGLRenderTarget.js';
22

3-
function WebGLMultisampleRenderTarget( width, height, options ) {
3+
class WebGLMultisampleRenderTarget extends WebGLRenderTarget {
44

5-
WebGLRenderTarget.call( this, width, height, options );
5+
constructor( width, height, options ) {
66

7-
this.samples = 4;
7+
super( width, height, options );
88

9-
}
10-
11-
WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
9+
Object.defineProperty( this, 'isWebGLMultisampleRenderTarget', { value: true } );
1210

13-
constructor: WebGLMultisampleRenderTarget,
11+
this.samples = 4;
1412

15-
isWebGLMultisampleRenderTarget: true,
13+
}
1614

17-
copy: function ( source ) {
15+
copy( source ) {
1816

19-
WebGLRenderTarget.prototype.copy.call( this, source );
17+
super.copy.call( this, source );
2018

2119
this.samples = source.samples;
2220

2321
return this;
2422

2523
}
2624

27-
} );
25+
}
2826

2927

3028
export { WebGLMultisampleRenderTarget };

src/renderers/WebGLRenderTarget.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,40 @@ import { Vector4 } from '../math/Vector4.js';
88
* Texture parameters for an auto-generated target texture
99
* depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
1010
*/
11-
function WebGLRenderTarget( width, height, options ) {
11+
class WebGLRenderTarget extends EventDispatcher {
1212

13-
this.width = width;
14-
this.height = height;
13+
constructor( width, height, options ) {
1514

16-
this.scissor = new Vector4( 0, 0, width, height );
17-
this.scissorTest = false;
15+
super();
1816

19-
this.viewport = new Vector4( 0, 0, width, height );
17+
Object.defineProperty( this, 'isWebGLRenderTarget', { value: true } );
2018

21-
options = options || {};
19+
this.width = width;
20+
this.height = height;
2221

23-
this.texture = new Texture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
22+
this.scissor = new Vector4( 0, 0, width, height );
23+
this.scissorTest = false;
2424

25-
this.texture.image = {};
26-
this.texture.image.width = width;
27-
this.texture.image.height = height;
25+
this.viewport = new Vector4( 0, 0, width, height );
2826

29-
this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
30-
this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
27+
options = options || {};
3128

32-
this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
33-
this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
34-
this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
29+
this.texture = new Texture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
3530

36-
}
31+
this.texture.image = {};
32+
this.texture.image.width = width;
33+
this.texture.image.height = height;
3734

38-
WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
35+
this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
36+
this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
3937

40-
constructor: WebGLRenderTarget,
38+
this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
39+
this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
40+
this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
4141

42-
isWebGLRenderTarget: true,
42+
}
4343

44-
setSize: function ( width, height ) {
44+
setSize( width, height ) {
4545

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

@@ -58,15 +58,15 @@ WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prot
5858
this.viewport.set( 0, 0, width, height );
5959
this.scissor.set( 0, 0, width, height );
6060

61-
},
61+
}
6262

63-
clone: function () {
63+
clone() {
6464

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

67-
},
67+
}
6868

69-
copy: function ( source ) {
69+
copy( source ) {
7070

7171
this.width = source.width;
7272
this.height = source.height;
@@ -81,15 +81,15 @@ WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prot
8181

8282
return this;
8383

84-
},
84+
}
8585

86-
dispose: function () {
86+
dispose() {
8787

8888
this.dispatchEvent( { type: 'dispose' } );
8989

9090
}
9191

92-
} );
92+
}
9393

9494

9595
export { WebGLRenderTarget };

0 commit comments

Comments
 (0)