|
@@ -10,7 +10,7 @@ import {
|
|
|
RGBAFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, SRGBColorSpace, DepthFormat, DepthStencilFormat,
|
|
|
RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format,
|
|
|
RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, UnsignedIntType, UnsignedShortType, UnsignedInt248Type,
|
|
|
- NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare
|
|
|
+ NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, IntType, RedIntegerFormat, RGIntegerFormat, RGBAIntegerFormat
|
|
|
} from 'three';
|
|
|
|
|
|
import { CubeReflectionMapping, CubeRefractionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping, DepthTexture } from 'three';
|
|
@@ -38,8 +38,8 @@ class WebGPUTextureUtils {
|
|
|
|
|
|
this._passUtils = null;
|
|
|
|
|
|
- this.defaultTexture = null;
|
|
|
- this.defaultCubeTexture = null;
|
|
|
+ this.defaultTexture = {};
|
|
|
+ this.defaultCubeTexture = {};
|
|
|
|
|
|
this.colorBuffer = null;
|
|
|
|
|
@@ -79,13 +79,15 @@ class WebGPUTextureUtils {
|
|
|
|
|
|
let textureGPU;
|
|
|
|
|
|
+ const format = getFormat( texture );
|
|
|
+
|
|
|
if ( texture.isCubeTexture ) {
|
|
|
|
|
|
- textureGPU = this._getDefaultCubeTextureGPU();
|
|
|
+ textureGPU = this._getDefaultCubeTextureGPU( format );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- textureGPU = this._getDefaultTextureGPU();
|
|
|
+ textureGPU = this._getDefaultTextureGPU( format );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -111,7 +113,7 @@ class WebGPUTextureUtils {
|
|
|
const { width, height, depth, levels } = options;
|
|
|
|
|
|
const dimension = this._getDimension( texture );
|
|
|
- const format = texture.internalFormat || getFormat( texture, backend.device );
|
|
|
+ const format = texture.internalFormat || options.format || getFormat( texture, backend.device );
|
|
|
|
|
|
let sampleCount = options.sampleCount !== undefined ? options.sampleCount : 1;
|
|
|
|
|
@@ -422,19 +424,19 @@ class WebGPUTextureUtils {
|
|
|
|
|
|
}
|
|
|
|
|
|
- _getDefaultTextureGPU() {
|
|
|
+ _getDefaultTextureGPU( format ) {
|
|
|
|
|
|
- let defaultTexture = this.defaultTexture;
|
|
|
+ let defaultTexture = this.defaultTexture[ format ];
|
|
|
|
|
|
- if ( defaultTexture === null ) {
|
|
|
+ if ( defaultTexture === undefined ) {
|
|
|
|
|
|
const texture = new Texture();
|
|
|
texture.minFilter = NearestFilter;
|
|
|
texture.magFilter = NearestFilter;
|
|
|
|
|
|
- this.createTexture( texture, { width: 1, height: 1 } );
|
|
|
+ this.createTexture( texture, { width: 1, height: 1, format } );
|
|
|
|
|
|
- this.defaultTexture = defaultTexture = texture;
|
|
|
+ this.defaultTexture[ format ] = defaultTexture = texture;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -442,11 +444,11 @@ class WebGPUTextureUtils {
|
|
|
|
|
|
}
|
|
|
|
|
|
- _getDefaultCubeTextureGPU() {
|
|
|
+ _getDefaultCubeTextureGPU( format ) {
|
|
|
|
|
|
- let defaultCubeTexture = this.defaultTexture;
|
|
|
+ let defaultCubeTexture = this.defaultTexture[ format ];
|
|
|
|
|
|
- if ( defaultCubeTexture === null ) {
|
|
|
+ if ( defaultCubeTexture === undefined ) {
|
|
|
|
|
|
const texture = new CubeTexture();
|
|
|
texture.minFilter = NearestFilter;
|
|
@@ -454,7 +456,7 @@ class WebGPUTextureUtils {
|
|
|
|
|
|
this.createTexture( texture, { width: 1, height: 1, depth: 6 } );
|
|
|
|
|
|
- this.defaultCubeTexture = defaultCubeTexture = texture;
|
|
|
+ this.defaultCubeTexture[ format ] = defaultCubeTexture = texture;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1026,6 +1028,63 @@ export function getFormat( texture, device = null ) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
+ case RedIntegerFormat:
|
|
|
+
|
|
|
+ switch ( type ) {
|
|
|
+
|
|
|
+ case IntType:
|
|
|
+ formatGPU = GPUTextureFormat.R32Sint;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case UnsignedIntType:
|
|
|
+ formatGPU = GPUTextureFormat.R32Uint;
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ console.error( 'WebGPURenderer: Unsupported texture type with RedIntegerFormat.', type );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case RGIntegerFormat:
|
|
|
+
|
|
|
+ switch ( type ) {
|
|
|
+
|
|
|
+ case IntType:
|
|
|
+ formatGPU = GPUTextureFormat.RG32Sint;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case UnsignedIntType:
|
|
|
+ formatGPU = GPUTextureFormat.RG32Uint;
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ console.error( 'WebGPURenderer: Unsupported texture type with RGIntegerFormat.', type );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case RGBAIntegerFormat:
|
|
|
+
|
|
|
+ switch ( type ) {
|
|
|
+
|
|
|
+ case IntType:
|
|
|
+ formatGPU = GPUTextureFormat.RGBA32Sint;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case UnsignedIntType:
|
|
|
+ formatGPU = GPUTextureFormat.RGBA32Uint;
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ console.error( 'WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.', type );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
default:
|
|
|
console.error( 'WebGPURenderer: Unsupported texture format.', format );
|
|
|
|