Skip to content

Commit

Permalink
StorageTexture: Mipmaps (mrdoob#27332)
Browse files Browse the repository at this point in the history
* StorageTexture: Mipmaps

* revision

* use texture.generateMipmaps
  • Loading branch information
sunag authored and AdaRoseCannon committed Jan 15, 2024
1 parent 5764789 commit 54bba22
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 3 deletions.
20 changes: 20 additions & 0 deletions examples/jsm/renderers/common/Bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class Bindings extends DataMap {

} else if ( binding.isSampledTexture ) {

const texture = binding.texture;

if ( binding.needsBindingsUpdate ) needsBindingsUpdate = true;

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

}

if ( texture.isStorageTexture === true ) {

const textureData = this.get( texture );

if ( binding.store === true ) {

textureData.needsMipmap = true;

} else if ( texture.generateMipmaps === true && this.textures.needsMipmaps( texture ) && textureData.needsMipmap === true ) {

this.backend.generateMipmaps( texture );

textureData.needsMipmap = false;

}

}

}

}
Expand Down
6 changes: 6 additions & 0 deletions examples/jsm/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ class Renderer {

}

getMaxAnisotropy() {

return this.backend.getMaxAnisotropy();

}

getActiveCubeFace() {

return this._activeCubeFace;
Expand Down
1 change: 1 addition & 0 deletions examples/jsm/renderers/common/StorageTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class StorageTexture extends Texture {
this.isStorageTexture = true;

}

}

export default StorageTexture;
10 changes: 9 additions & 1 deletion examples/jsm/renderers/webgl/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import WebGLState from './utils/WebGLState.js';
import WebGLUtils from './utils/WebGLUtils.js';
import WebGLTextureUtils from './utils/WebGLTextureUtils.js';
import WebGLExtensions from './utils/WebGLExtensions.js';
import WebGLCapabilities from './utils/WebGLCapabilities.js';

//

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

this.extensions = new WebGLExtensions( this );
this.capabilities = new WebGLCapabilities( this );
this.attributeUtils = new WebGLAttributeUtils( this );
this.textureUtils = new WebGLTextureUtils( this );
this.state = new WebGLState( this );
Expand Down Expand Up @@ -877,12 +879,18 @@ class WebGLBackend extends Backend {

}

hasFeature( name ) {
hasFeature( /*name*/ ) {

return true;

}

getMaxAnisotropy() {

return this.capabilities.getMaxAnisotropy();

}

copyFramebufferToTexture( texture, renderContext ) {

const { gl } = this;
Expand Down
36 changes: 36 additions & 0 deletions examples/jsm/renderers/webgl/utils/WebGLCapabilities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class WebGLCapabilities {

constructor( backend ) {

this.backend = backend;

this.maxAnisotropy = null;

}

getMaxAnisotropy() {

if ( this.maxAnisotropy !== null ) return this.maxAnisotropy;

const gl = this.backend.gl;
const extensions = this.backend.extensions;

if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) {

const extension = extensions.get( 'EXT_texture_filter_anisotropic' );

this.maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );

} else {

this.maxAnisotropy = 0;

}

return this.maxAnisotropy;

}

}

export default WebGLCapabilities;
12 changes: 11 additions & 1 deletion examples/jsm/renderers/webgl/utils/WebGLExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ class WebGLExtensions {
this.gl = this.backend.gl;
this.availableExtensions = this.gl.getSupportedExtensions();

this.extensions = {};

}

get( name ) {

return this.gl.getExtension( name );
let extension = this.extensions[ name ];

if ( extension === undefined ) {

extension = this.gl.getExtension( name );

}

return extension;

}

Expand Down
6 changes: 6 additions & 0 deletions examples/jsm/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,12 @@ class WebGPUBackend extends Backend {

// utils public

getMaxAnisotropy() {

return 16;

}

hasFeature( name ) {

const adapter = this.adapter || _staticAdapter;
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class WebGPUBindingUtils {

const aspectGPU = GPUTextureAspect.All;

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

}

Expand Down
1 change: 1 addition & 0 deletions examples/webgpu_compute_texture.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
const width = 512, height = 512;

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

// create function

Expand Down

0 comments on commit 54bba22

Please sign in to comment.