Skip to content

Commit 4c7912c

Browse files
authored
StorageTexture: Mipmaps (#27332)
* StorageTexture: Mipmaps * revision * use texture.generateMipmaps
1 parent f584af2 commit 4c7912c

File tree

9 files changed

+91
-3
lines changed

9 files changed

+91
-3
lines changed

examples/jsm/renderers/common/Bindings.js

+20
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class Bindings extends DataMap {
124124

125125
} else if ( binding.isSampledTexture ) {
126126

127+
const texture = binding.texture;
128+
127129
if ( binding.needsBindingsUpdate ) needsBindingsUpdate = true;
128130

129131
const updated = binding.update();
@@ -134,6 +136,24 @@ class Bindings extends DataMap {
134136

135137
}
136138

139+
if ( texture.isStorageTexture === true ) {
140+
141+
const textureData = this.get( texture );
142+
143+
if ( binding.store === true ) {
144+
145+
textureData.needsMipmap = true;
146+
147+
} else if ( texture.generateMipmaps === true && this.textures.needsMipmaps( texture ) && textureData.needsMipmap === true ) {
148+
149+
this.backend.generateMipmaps( texture );
150+
151+
textureData.needsMipmap = false;
152+
153+
}
154+
155+
}
156+
137157
}
138158

139159
}

examples/jsm/renderers/common/Renderer.js

+6
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@ class Renderer {
352352

353353
}
354354

355+
getMaxAnisotropy() {
356+
357+
return this.backend.getMaxAnisotropy();
358+
359+
}
360+
355361
getActiveCubeFace() {
356362

357363
return this._activeCubeFace;

examples/jsm/renderers/common/StorageTexture.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class StorageTexture extends Texture {
1414
this.isStorageTexture = true;
1515

1616
}
17+
1718
}
1819

1920
export default StorageTexture;

examples/jsm/renderers/webgl/WebGLBackend.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import WebGLState from './utils/WebGLState.js';
88
import WebGLUtils from './utils/WebGLUtils.js';
99
import WebGLTextureUtils from './utils/WebGLTextureUtils.js';
1010
import WebGLExtensions from './utils/WebGLExtensions.js';
11+
import WebGLCapabilities from './utils/WebGLCapabilities.js';
1112

1213
//
1314

@@ -34,6 +35,7 @@ class WebGLBackend extends Backend {
3435
this.gl = glContext;
3536

3637
this.extensions = new WebGLExtensions( this );
38+
this.capabilities = new WebGLCapabilities( this );
3739
this.attributeUtils = new WebGLAttributeUtils( this );
3840
this.textureUtils = new WebGLTextureUtils( this );
3941
this.state = new WebGLState( this );
@@ -877,12 +879,18 @@ class WebGLBackend extends Backend {
877879

878880
}
879881

880-
hasFeature( name ) {
882+
hasFeature( /*name*/ ) {
881883

882884
return true;
883885

884886
}
885887

888+
getMaxAnisotropy() {
889+
890+
return this.capabilities.getMaxAnisotropy();
891+
892+
}
893+
886894
copyFramebufferToTexture( texture, renderContext ) {
887895

888896
const { gl } = this;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class WebGLCapabilities {
2+
3+
constructor( backend ) {
4+
5+
this.backend = backend;
6+
7+
this.maxAnisotropy = null;
8+
9+
}
10+
11+
getMaxAnisotropy() {
12+
13+
if ( this.maxAnisotropy !== null ) return this.maxAnisotropy;
14+
15+
const gl = this.backend.gl;
16+
const extensions = this.backend.extensions;
17+
18+
if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) {
19+
20+
const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
21+
22+
this.maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
23+
24+
} else {
25+
26+
this.maxAnisotropy = 0;
27+
28+
}
29+
30+
return this.maxAnisotropy;
31+
32+
}
33+
34+
}
35+
36+
export default WebGLCapabilities;

examples/jsm/renderers/webgl/utils/WebGLExtensions.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,21 @@ class WebGLExtensions {
77
this.gl = this.backend.gl;
88
this.availableExtensions = this.gl.getSupportedExtensions();
99

10+
this.extensions = {};
11+
1012
}
1113

1214
get( name ) {
1315

14-
return this.gl.getExtension( name );
16+
let extension = this.extensions[ name ];
17+
18+
if ( extension === undefined ) {
19+
20+
extension = this.gl.getExtension( name );
21+
22+
}
23+
24+
return extension;
1525

1626
}
1727

examples/jsm/renderers/webgpu/WebGPUBackend.js

+6
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,12 @@ class WebGPUBackend extends Backend {
10561056

10571057
// utils public
10581058

1059+
getMaxAnisotropy() {
1060+
1061+
return 16;
1062+
1063+
}
1064+
10591065
hasFeature( name ) {
10601066

10611067
const adapter = this.adapter || _staticAdapter;

examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class WebGPUBindingUtils {
220220

221221
const aspectGPU = GPUTextureAspect.All;
222222

223-
resourceGPU = textureData.texture.createView( { aspect: aspectGPU, dimension: dimensionViewGPU } );
223+
resourceGPU = textureData.texture.createView( { aspect: aspectGPU, dimension: dimensionViewGPU, mipLevelCount: binding.store ? 1 : textureData.mipLevelCount } );
224224

225225
}
226226

examples/webgpu_compute_texture.html

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
const width = 512, height = 512;
5757

5858
const storageTexture = new StorageTexture( width, height );
59+
//storageTexture.minFilter = THREE.LinearMipMapLinearFilter;
5960

6061
// create function
6162

0 commit comments

Comments
 (0)