Skip to content

Commit

Permalink
WebGLTextures: Use gl.texStorage2D() for data textures. (#22947)
Browse files Browse the repository at this point in the history
Mugen87 authored Dec 3, 2021
1 parent 384d1e9 commit f3149ba
Showing 28 changed files with 128 additions and 17 deletions.
1 change: 1 addition & 0 deletions docs/api/en/textures/DataTexture.html
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@ <h2>Code Example</h2>
// used the buffer to create a [name]

const texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
texture.needsUpdate = true;
</code>

<h2>Properties</h2>
2 changes: 1 addition & 1 deletion docs/api/en/textures/DataTexture2DArray.html
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ <h2>Code Example</h2>

const texture = new THREE.DataTexture2DArray( data, width, height, depth );
texture.format = THREE.RGBFormat;
texture.type = THREE.UnsignedByteType;
texture.needsUpdate = true;
</code>

<h2>Examples</h2>
1 change: 1 addition & 0 deletions docs/api/zh/textures/DataTexture.html
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@ <h2>代码示例</h2>
// used the buffer to create a [name]

const texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
texture.needsUpdate = true;
</code>

<h2>属性</h2>
2 changes: 1 addition & 1 deletion docs/api/zh/textures/DataTexture2DArray.html
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ <h2>代码示例</h2>

const texture = new THREE.DataTexture2DArray( data, width, height, depth );
texture.format = THREE.RGBFormat;
texture.type = THREE.UnsignedByteType;
texture.needsUpdate = true;
</code>

<p>
7 changes: 7 additions & 0 deletions examples/jsm/lights/RectAreaLightUniformsLib.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/jsm/loaders/LUT3dlLoader.js
Original file line number Diff line number Diff line change
@@ -118,6 +118,7 @@ export class LUT3dlLoader extends Loader {
texture.wrapS = ClampToEdgeWrapping;
texture.wrapT = ClampToEdgeWrapping;
texture.generateMipmaps = false;
texture.needsUpdate = true;

const texture3D = new DataTexture3D();
texture3D.image.data = data;
@@ -132,6 +133,7 @@ export class LUT3dlLoader extends Loader {
texture3D.wrapT = ClampToEdgeWrapping;
texture3D.wrapR = ClampToEdgeWrapping;
texture3D.generateMipmaps = false;
texture3D.needsUpdate = true;

return {
size,
2 changes: 2 additions & 0 deletions examples/jsm/loaders/LUTCubeLoader.js
Original file line number Diff line number Diff line change
@@ -124,6 +124,7 @@ export class LUTCubeLoader extends Loader {
texture.wrapS = ClampToEdgeWrapping;
texture.wrapT = ClampToEdgeWrapping;
texture.generateMipmaps = false;
texture.needsUpdate = true;

const texture3D = new DataTexture3D();
texture3D.image.data = data;
@@ -138,6 +139,7 @@ export class LUTCubeLoader extends Loader {
texture3D.wrapT = ClampToEdgeWrapping;
texture3D.wrapR = ClampToEdgeWrapping;
texture3D.generateMipmaps = false;
texture3D.needsUpdate = true;

return {
title,
1 change: 1 addition & 0 deletions examples/jsm/loaders/VOXLoader.js
Original file line number Diff line number Diff line change
@@ -296,6 +296,7 @@ class VOXDataTexture3D extends DataTexture3D {
this.minFilter = NearestFilter;
this.magFilter = LinearFilter;
this.unpackAlignment = 1;
this.needsUpdate = true;

}

1 change: 1 addition & 0 deletions examples/jsm/loaders/VRMLLoader.js
Original file line number Diff line number Diff line change
@@ -1382,6 +1382,7 @@ class VRMLLoader extends Loader {
}

texture = new DataTexture( data, width, height, ( useAlpha === true ) ? RGBAFormat : RGBFormat );
texture.needsUpdate = true;
texture.__type = textureType; // needed for material modifications
break;

4 changes: 3 additions & 1 deletion examples/jsm/misc/GPUComputationRenderer.js
Original file line number Diff line number Diff line change
@@ -345,7 +345,9 @@ class GPUComputationRenderer {
this.createTexture = function () {

const data = new Float32Array( sizeX * sizeY * 4 );
return new DataTexture( data, sizeX, sizeY, RGBAFormat, FloatType );
const texture = new DataTexture( data, sizeX, sizeY, RGBAFormat, FloatType );
texture.needsUpdate = true;
return texture;

};

4 changes: 3 additions & 1 deletion examples/jsm/postprocessing/GlitchPass.js
Original file line number Diff line number Diff line change
@@ -106,7 +106,9 @@ class GlitchPass extends Pass {

}

return new DataTexture( data_arr, dt_size, dt_size, RGBFormat, FloatType );
const texture = new DataTexture( data_arr, dt_size, dt_size, RGBFormat, FloatType );
texture.needsUpdate = true;
return texture;

}

1 change: 1 addition & 0 deletions examples/jsm/postprocessing/SSAOPass.js
Original file line number Diff line number Diff line change
@@ -413,6 +413,7 @@ class SSAOPass extends Pass {
this.noiseTexture = new DataTexture( data, width, height, RGBAFormat, FloatType );
this.noiseTexture.wrapS = RepeatWrapping;
this.noiseTexture.wrapT = RepeatWrapping;
this.noiseTexture.needsUpdate = true;

}

1 change: 1 addition & 0 deletions examples/misc_exporter_gltf.html
Original file line number Diff line number Diff line change
@@ -161,6 +161,7 @@
const gradientTexture = new THREE.DataTexture( data, 100, 100, THREE.RGBFormat );
gradientTexture.minFilter = THREE.LinearFilter;
gradientTexture.magFilter = THREE.LinearFilter;
gradientTexture.needsUpdate = true;

scene1 = new THREE.Scene();
scene1.name = 'Scene1';
2 changes: 1 addition & 1 deletion examples/webgl2_materials_texture2darray.html
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@

const texture = new THREE.DataTexture2DArray( array, 256, 256, 109 );
texture.format = THREE.RedFormat;
texture.type = THREE.UnsignedByteType;
texture.needsUpdate = true;

const material = new THREE.ShaderMaterial( {
uniforms: {
1 change: 1 addition & 0 deletions examples/webgl2_materials_texture3d.html
Original file line number Diff line number Diff line change
@@ -90,6 +90,7 @@
texture.type = THREE.FloatType;
texture.minFilter = texture.magFilter = THREE.LinearFilter;
texture.unpackAlignment = 1;
texture.needsUpdate = true;

// Colormap textures
cmtextures = {
1 change: 1 addition & 0 deletions examples/webgl2_materials_texture3d_partialupdate.html
Original file line number Diff line number Diff line change
@@ -113,6 +113,7 @@
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.unpackAlignment = 1;
texture.needsUpdate = true;

cloudTexture = texture;

2 changes: 1 addition & 1 deletion examples/webgl2_rendertarget_texture2darray.html
Original file line number Diff line number Diff line change
@@ -197,7 +197,7 @@

const texture = new THREE.DataTexture2DArray( array, DIMENSIONS.width, DIMENSIONS.height, DIMENSIONS.depth );
texture.format = THREE.RedFormat;
texture.type = THREE.UnsignedByteType;
texture.needsUpdate = true;

var material = new THREE.ShaderMaterial( {
uniforms: {
1 change: 1 addition & 0 deletions examples/webgl2_volume_cloud.html
Original file line number Diff line number Diff line change
@@ -97,6 +97,7 @@
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.unpackAlignment = 1;
texture.needsUpdate = true;

// Material

1 change: 1 addition & 0 deletions examples/webgl2_volume_perlin.html
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.unpackAlignment = 1;
texture.needsUpdate = true;

// Material

1 change: 1 addition & 0 deletions examples/webgl_materials_variations_toon.html
Original file line number Diff line number Diff line change
@@ -77,6 +77,7 @@
}

const gradientMap = new THREE.DataTexture( colors, colors.length, 1, format );
gradientMap.needsUpdate = true;

for ( let beta = 0; beta <= 1.0; beta += stepSize ) {

4 changes: 3 additions & 1 deletion examples/webgpu_sandbox.html
Original file line number Diff line number Diff line change
@@ -227,7 +227,9 @@

}

return new THREE.DataTexture( data, width, height, THREE.RGBAFormat );
const texture = THREE.DataTexture( data, width, height, THREE.RGBAFormat );
texture.needsUpdate = true;
return texture;

}

1 change: 1 addition & 0 deletions src/objects/Skeleton.js
Original file line number Diff line number Diff line change
@@ -178,6 +178,7 @@ class Skeleton {
boneMatrices.set( this.boneMatrices ); // copy current values

const boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
boneTexture.needsUpdate = true;

this.boneMatrices = boneMatrices;
this.boneTexture = boneTexture;
1 change: 1 addition & 0 deletions src/renderers/webgl/WebGLMorphtargets.js
Original file line number Diff line number Diff line change
@@ -84,6 +84,7 @@ function WebGLMorphtargets( gl, capabilities, textures ) {
const texture = new DataTexture2DArray( buffer, width, height, numberOfMorphTargets );
texture.format = RGBAFormat; // using RGBA since RGB might be emulated (and is thus slower)
texture.type = FloatType;
texture.needsUpdate = true;

// fill buffer

30 changes: 30 additions & 0 deletions src/renderers/webgl/WebGLState.js
Original file line number Diff line number Diff line change
@@ -878,6 +878,20 @@ function WebGLState( gl, extensions, capabilities ) {

}

function texSubImage3D() {

try {

gl.texSubImage3D.apply( gl, arguments );

} catch ( error ) {

console.error( 'THREE.WebGLState:', error );

}

}

function compressedTexSubImage2D() {

try {
@@ -906,6 +920,20 @@ function WebGLState( gl, extensions, capabilities ) {

}

function texStorage3D() {

try {

gl.texStorage3D.apply( gl, arguments );

} catch ( error ) {

console.error( 'THREE.WebGLState:', error );

}

}

function texImage2D() {

try {
@@ -1083,7 +1111,9 @@ function WebGLState( gl, extensions, capabilities ) {
texImage3D: texImage3D,

texStorage2D: texStorage2D,
texStorage3D: texStorage3D,
texSubImage2D: texSubImage2D,
texSubImage3D: texSubImage3D,
compressedTexSubImage2D: compressedTexSubImage2D,

scissor: scissor,
65 changes: 61 additions & 4 deletions src/renderers/webgl/WebGLTextures.js
Original file line number Diff line number Diff line change
@@ -661,18 +661,47 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

if ( mipmaps.length > 0 && supportsMips ) {

if ( useTexStorage && allocateMemory ) {

state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[ 0 ].width, mipmaps[ 0 ].height );

}

for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {

mipmap = mipmaps[ i ];
state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );

if ( useTexStorage ) {

state.texSubImage2D( _gl.TEXTURE_2D, 0, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data );

} else {

state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );

}

}

texture.generateMipmaps = false;

} else {

state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
if ( useTexStorage ) {

if ( allocateMemory ) {

state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height );

}

state.texSubImage2D( _gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, glFormat, glType, image.data );

} else {

state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );

}

}

@@ -726,11 +755,39 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

} else if ( texture.isDataTexture2DArray ) {

state.texImage3D( _gl.TEXTURE_2D_ARRAY, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
if ( useTexStorage ) {

if ( allocateMemory ) {

state.texStorage3D( _gl.TEXTURE_2D_ARRAY, levels, glInternalFormat, image.width, image.height, image.depth );

}

state.texSubImage3D( _gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data );

} else {

state.texImage3D( _gl.TEXTURE_2D_ARRAY, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );

}

} else if ( texture.isDataTexture3D ) {

state.texImage3D( _gl.TEXTURE_3D, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
if ( useTexStorage ) {

if ( allocateMemory ) {

state.texStorage3D( _gl.TEXTURE_3D, levels, glInternalFormat, image.width, image.height, image.depth );

}

state.texSubImage3D( _gl.TEXTURE_3D, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data );

} else {

state.texImage3D( _gl.TEXTURE_3D, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );

}

} else if ( texture.isFramebufferTexture ) {

2 changes: 0 additions & 2 deletions src/textures/DataTexture.js
Original file line number Diff line number Diff line change
@@ -16,8 +16,6 @@ class DataTexture extends Texture {
this.flipY = false;
this.unpackAlignment = 1;

this.needsUpdate = true;

}

}
2 changes: 0 additions & 2 deletions src/textures/DataTexture2DArray.js
Original file line number Diff line number Diff line change
@@ -18,8 +18,6 @@ class DataTexture2DArray extends Texture {
this.flipY = false;
this.unpackAlignment = 1;

this.needsUpdate = true;

}

}
2 changes: 0 additions & 2 deletions src/textures/DataTexture3D.js
Original file line number Diff line number Diff line change
@@ -26,8 +26,6 @@ class DataTexture3D extends Texture {
this.flipY = false;
this.unpackAlignment = 1;

this.needsUpdate = true;

}

}

0 comments on commit f3149ba

Please sign in to comment.