Skip to content

Commit a22c52f

Browse files
authored
WebGPURenderer: Add support for BC4 and BC5 texture compression. (#31737)
1 parent 7ea407a commit a22c52f

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

examples/webgpu_loader_texture_ktx2.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@
117117
{ path: '2d_etc2.ktx2' },
118118
{ path: '2d_bc1.ktx2' },
119119
{ path: '2d_bc3.ktx2' },
120-
// { path: '2d_bc5.ktx2' },
120+
{ path: '2d_bc4.ktx2' },
121+
{ path: '2d_bc5.ktx2' },
121122
{ path: '2d_bc7.ktx2' },
122123
]
123124
},

src/renderers/webgl-fallback/utils/WebGLUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class WebGLUtils {
232232

233233
if ( extension !== null ) {
234234

235-
if ( p === RGBA_BPTC_Format ) return extension.COMPRESSED_RED_RGTC1_EXT;
235+
if ( p === RED_RGTC1_Format ) return extension.COMPRESSED_RED_RGTC1_EXT;
236236
if ( p === SIGNED_RED_RGTC1_Format ) return extension.COMPRESSED_SIGNED_RED_RGTC1_EXT;
237237
if ( p === RED_GREEN_RGTC2_Format ) return extension.COMPRESSED_RED_GREEN_RGTC2_EXT;
238238
if ( p === SIGNED_RED_GREEN_RGTC2_Format ) return extension.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT;

src/renderers/webgpu/utils/WebGPUTextureUtils.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
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,
1515
RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, UnsignedIntType, UnsignedShortType, UnsignedInt248Type, UnsignedInt5999Type,
1616
NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, IntType, RedIntegerFormat, RGIntegerFormat, RGBAIntegerFormat,
17-
UnsignedInt101111Type, RGBA_BPTC_Format, RGB_ETC1_Format, RGB_S3TC_DXT1_Format
17+
UnsignedInt101111Type, RGBA_BPTC_Format, RGB_ETC1_Format, RGB_S3TC_DXT1_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format
1818
} from '../../../constants.js';
1919
import { CubeTexture } from '../../../textures/CubeTexture.js';
2020
import { DepthTexture } from '../../../textures/DepthTexture.js';
@@ -1140,6 +1140,22 @@ export function getFormat( texture, device = null ) {
11401140
formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.BC3RGBAUnormSRGB : GPUTextureFormat.BC3RGBAUnorm;
11411141
break;
11421142

1143+
case RED_RGTC1_Format:
1144+
formatGPU = GPUTextureFormat.BC4RUnorm;
1145+
break;
1146+
1147+
case SIGNED_RED_RGTC1_Format:
1148+
formatGPU = GPUTextureFormat.BC4RSnorm;
1149+
break;
1150+
1151+
case RED_GREEN_RGTC2_Format:
1152+
formatGPU = GPUTextureFormat.BC5RGUnorm;
1153+
break;
1154+
1155+
case SIGNED_RED_GREEN_RGTC2_Format:
1156+
formatGPU = GPUTextureFormat.BC5RGSnorm;
1157+
break;
1158+
11431159
case RGBA_BPTC_Format:
11441160
formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.BC7RGBAUnormSRGB : GPUTextureFormat.BC7RGBAUnorm;
11451161
break;

0 commit comments

Comments
 (0)