Skip to content

Commit a1024a9

Browse files
committed
Add new render target types for 3D and array textures.
1 parent 766b95b commit a1024a9

11 files changed

+59
-54
lines changed

examples/webgl2_materials_texture2darray.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@
107107
const zip = unzipSync( new Uint8Array( data ) );
108108
const array = new Uint8Array( zip[ 'head256x256x109' ].buffer );
109109

110-
const texture = new THREE.DataTexture2DArray( array, 256, 256, 109 );
111-
texture.format = THREE.RedFormat;
110+
const texture = new THREE.DataTexture2DArray( array, 256, 256, 109, THREE.RedFormat );
112111
texture.needsUpdate = true;
113112

114113
const material = new THREE.ShaderMaterial( {

examples/webgl2_rendertarget_texture2darray.html

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,10 @@
138138
const postProcessScene = new THREE.Scene();
139139
const postProcessCamera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
140140

141-
const renderTargetTexture = new THREE.DataTexture2DArray();
142-
renderTargetTexture.format = THREE.RedFormat;
143-
renderTargetTexture.type = THREE.UnsignedByteType;
144-
145-
const renderTarget = new THREE.WebGLRenderTarget( DIMENSIONS.width, DIMENSIONS.height );
146-
renderTarget.depth = DIMENSIONS.depth;
147-
renderTarget.setTexture( renderTargetTexture );
141+
const renderTarget = new THREE.WebGL2DArrayRenderTarget( DIMENSIONS.width, DIMENSIONS.height, DIMENSIONS.depth, {
142+
format: THREE.RedFormat,
143+
type: THREE.UnsignedByteType
144+
} );
148145

149146
const postProcessMaterial = new THREE.ShaderMaterial( {
150147
uniforms: {

src/Three.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { REVISION } from './constants.js';
22

3+
export { WebGL2DArrayRenderTarget } from './renderers/WebGL2DArrayRenderTarget.js';
4+
export { WebGL3DRenderTarget } from './renderers/WebGL3DRenderTarget.js';
35
export { WebGLMultipleRenderTargets } from './renderers/WebGLMultipleRenderTargets.js';
46
export { WebGLCubeRenderTarget } from './renderers/WebGLCubeRenderTarget.js';
57
export { WebGLRenderTarget } from './renderers/WebGLRenderTarget.js';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { WebGLRenderTarget } from './WebGLRenderTarget.js';
2+
import { DataTexture2DArray } from '../textures/DataTexture2DArray.js';
3+
4+
class WebGL2DArrayRenderTarget extends WebGLRenderTarget {
5+
6+
constructor( width, height, depth, options = {} ) {
7+
8+
super( width, height, options );
9+
10+
this.depth = depth;
11+
12+
this.texture = new DataTexture2DArray( null, width, height, depth, options.format, options.type, options.mapping, options.wrapS, options.wrapT, options.wrapR, options.magFilter, options.minFilter, options.anisotropy, options.encoding );
13+
this.texture.isRenderTargetTexture = true;
14+
15+
}
16+
17+
}
18+
19+
WebGL2DArrayRenderTarget.prototype.isWebGL2DArrayRenderTarget = true;
20+
21+
export { WebGL2DArrayRenderTarget };
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { WebGLRenderTarget } from './WebGLRenderTarget.js';
2+
import { DataTexture3D } from '../textures/DataTexture3D.js';
3+
4+
class WebGL3DRenderTarget extends WebGLRenderTarget {
5+
6+
constructor( width, height, depth, options = {} ) {
7+
8+
super( width, height, options );
9+
10+
this.depth = depth;
11+
12+
this.texture = new DataTexture3D( null, width, height, depth, options.format, options.type, options.mapping, options.wrapS, options.wrapT, options.wrapR, options.magFilter, options.minFilter, options.anisotropy, options.encoding );
13+
this.texture.isRenderTargetTexture = true;
14+
15+
}
16+
17+
}
18+
19+
WebGL3DRenderTarget.prototype.isWebGL3DRenderTarget = true;
20+
21+
export { WebGL3DRenderTarget };

src/renderers/WebGLRenderTarget.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,6 @@ class WebGLRenderTarget extends EventDispatcher {
4141

4242
}
4343

44-
setTexture( texture ) {
45-
46-
texture.image = {
47-
width: this.width,
48-
height: this.height,
49-
depth: this.depth
50-
};
51-
52-
this.texture = texture;
53-
54-
}
55-
5644
setSize( width, height, depth = 1 ) {
5745

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

src/renderers/webgl/WebGLMorphtargets.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ function WebGLMorphtargets( gl, capabilities, textures ) {
8181

8282
const buffer = new Float32Array( width * height * 4 * numberOfMorphTargets );
8383

84-
const texture = new DataTexture2DArray( buffer, width, height, numberOfMorphTargets );
85-
texture.format = RGBAFormat; // using RGBA since RGB might be emulated (and is thus slower)
86-
texture.type = FloatType;
84+
const texture = new DataTexture2DArray( buffer, width, height, numberOfMorphTargets, RGBAFormat, FloatType );
8785
texture.needsUpdate = true;
8886

8987
// fill buffer

src/renderers/webgl/WebGLTextures.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
14921492

14931493
const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
14941494
const isMultipleRenderTargets = ( renderTarget.isWebGLMultipleRenderTargets === true );
1495-
const isRenderTarget3D = texture.isDataTexture3D || texture.isDataTexture2DArray;
14961495
const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
14971496

14981497
// Setup framebuffer
@@ -1615,18 +1614,15 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
16151614

16161615
let glTextureType = _gl.TEXTURE_2D;
16171616

1618-
if ( isRenderTarget3D ) {
1619-
1620-
// Render targets containing layers, i.e: Texture 3D and 2d arrays
1617+
if ( renderTarget.isWebGL3DRenderTarget || renderTarget.isWebGL2DArrayRenderTarget ) {
16211618

16221619
if ( isWebGL2 ) {
16231620

1624-
const isTexture3D = texture.isDataTexture3D;
1625-
glTextureType = isTexture3D ? _gl.TEXTURE_3D : _gl.TEXTURE_2D_ARRAY;
1621+
glTextureType = renderTarget.isWebGL3DRenderTarget ? _gl.TEXTURE_3D : _gl.TEXTURE_2D_ARRAY;
16261622

16271623
} else {
16281624

1629-
console.warn( 'THREE.DataTexture3D and THREE.DataTexture2DArray only supported with WebGL2.' );
1625+
console.error( 'THREE.WebGLTextures: THREE.DataTexture3D and THREE.DataTexture2DArray only supported with WebGL2.' );
16301626

16311627
}
16321628

src/textures/DataTexture.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ class DataTexture extends Texture {
99

1010
this.image = { data: data, width: width, height: height };
1111

12-
this.magFilter = magFilter;
13-
this.minFilter = minFilter;
14-
1512
this.generateMipmaps = false;
1613
this.flipY = false;
1714
this.unpackAlignment = 1;

src/textures/DataTexture2DArray.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ import { ClampToEdgeWrapping, NearestFilter } from '../constants.js';
33

44
class DataTexture2DArray extends Texture {
55

6-
constructor( data = null, width = 1, height = 1, depth = 1 ) {
6+
constructor( data = null, width = 1, height = 1, depth = 1, format, type, mapping, wrapS, wrapT, wrapR = ClampToEdgeWrapping, magFilter = NearestFilter, minFilter = NearestFilter, anisotropy, encoding ) {
77

8-
super( null );
8+
super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
99

1010
this.image = { data, width, height, depth };
1111

12-
this.magFilter = NearestFilter;
13-
this.minFilter = NearestFilter;
14-
15-
this.wrapR = ClampToEdgeWrapping;
12+
this.wrapR = wrapR;
1613

1714
this.generateMipmaps = false;
1815
this.flipY = false;

0 commit comments

Comments
 (0)