|
@@ -1,6 +1,6 @@
|
|
import { GPUTextureFormat, GPUAddressMode, GPUFilterMode, GPUTextureDimension } from './constants.js';
|
|
import { GPUTextureFormat, GPUAddressMode, GPUFilterMode, GPUTextureDimension } from './constants.js';
|
|
import { VideoTexture, CubeTexture, Texture, NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter, RepeatWrapping, MirroredRepeatWrapping,
|
|
import { VideoTexture, CubeTexture, Texture, NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter, RepeatWrapping, MirroredRepeatWrapping,
|
|
- RGBAFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, SRGBColorSpace
|
|
|
|
|
|
+ RGBAFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, SRGBColorSpace, DepthFormat, DepthTexture
|
|
} from 'three';
|
|
} from 'three';
|
|
import WebGPUTextureUtils from './WebGPUTextureUtils.js';
|
|
import WebGPUTextureUtils from './WebGPUTextureUtils.js';
|
|
|
|
|
|
@@ -13,6 +13,7 @@ class WebGPUTextures {
|
|
this.info = info;
|
|
this.info = info;
|
|
|
|
|
|
this.defaultTexture = null;
|
|
this.defaultTexture = null;
|
|
|
|
+ this.depthDefaultTexture = null;
|
|
this.defaultVideoTexture = null;
|
|
this.defaultVideoTexture = null;
|
|
this.defaultCubeTexture = null;
|
|
this.defaultCubeTexture = null;
|
|
this.defaultSampler = null;
|
|
this.defaultSampler = null;
|
|
@@ -34,6 +35,26 @@ class WebGPUTextures {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ getDepthDefaultTexture() {
|
|
|
|
+
|
|
|
|
+ if ( this.depthDefaultTexture === null ) {
|
|
|
|
+
|
|
|
|
+ const depthTexture = new DepthTexture();
|
|
|
|
+ depthTexture.minFilter = NearestFilter;
|
|
|
|
+ depthTexture.magFilter = NearestFilter;
|
|
|
|
+ depthTexture.image.width = 1;
|
|
|
|
+ depthTexture.image.height = 1;
|
|
|
|
+
|
|
|
|
+ this._uploadTexture( depthTexture );
|
|
|
|
+
|
|
|
|
+ this.depthDefaultTexture = this.getTextureGPU( depthTexture );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return this.depthDefaultTexture;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
getDefaultTexture() {
|
|
getDefaultTexture() {
|
|
|
|
|
|
if ( this.defaultTexture === null ) {
|
|
if ( this.defaultTexture === null ) {
|
|
@@ -245,7 +266,7 @@ class WebGPUTextures {
|
|
|
|
|
|
if ( renderTarget.depthBuffer === true ) {
|
|
if ( renderTarget.depthBuffer === true ) {
|
|
|
|
|
|
- const depthTextureFormat = GPUTextureFormat.Depth24PlusStencil8; // @TODO: Make configurable
|
|
|
|
|
|
+ const depthTextureFormat = renderTarget.depthTexture !== null ? this._getFormat( renderTarget.depthTexture ) : GPUTextureFormat.Depth24PlusStencil8;
|
|
|
|
|
|
const depthTextureGPU = device.createTexture( {
|
|
const depthTextureGPU = device.createTexture( {
|
|
size: {
|
|
size: {
|
|
@@ -254,7 +275,7 @@ class WebGPUTextures {
|
|
depthOrArrayLayers: 1
|
|
depthOrArrayLayers: 1
|
|
},
|
|
},
|
|
format: depthTextureFormat,
|
|
format: depthTextureFormat,
|
|
- usage: GPUTextureUsage.RENDER_ATTACHMENT
|
|
|
|
|
|
+ usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
|
|
} );
|
|
} );
|
|
|
|
|
|
this.info.memory.textures ++;
|
|
this.info.memory.textures ++;
|
|
@@ -412,7 +433,7 @@ class WebGPUTextures {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- } else if ( image !== null ) {
|
|
|
|
|
|
+ } else if ( texture.isDepthTexture !== true && image !== null ) {
|
|
|
|
|
|
// assume HTMLImageElement, HTMLCanvasElement or ImageBitmap
|
|
// assume HTMLImageElement, HTMLCanvasElement or ImageBitmap
|
|
|
|
|
|
@@ -625,6 +646,10 @@ class WebGPUTextures {
|
|
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC3RGBAUnormSRGB : GPUTextureFormat.BC3RGBAUnorm;
|
|
formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC3RGBAUnormSRGB : GPUTextureFormat.BC3RGBAUnorm;
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
+ case DepthFormat:
|
|
|
|
+ formatGPU = GPUTextureFormat.Depth32Float;
|
|
|
|
+ break;
|
|
|
|
+
|
|
case RGBAFormat:
|
|
case RGBAFormat:
|
|
|
|
|
|
switch ( type ) {
|
|
switch ( type ) {
|