1- import { 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 , RGB_ETC1_Format , RGB_ETC2_Format , RGBA_ETC2_EAC_Format , RGBA_PVRTC_2BPPV1_Format , RGBA_PVRTC_4BPPV1_Format , RGB_PVRTC_2BPPV1_Format , RGB_PVRTC_4BPPV1_Format , RGBA_S3TC_DXT5_Format , RGBA_S3TC_DXT3_Format , RGBA_S3TC_DXT1_Format , RGB_S3TC_DXT1_Format , DepthFormat , DepthStencilFormat , RedFormat , RGBFormat , RGBAFormat , AlphaFormat , RedIntegerFormat , RGFormat , RGIntegerFormat , RGBAIntegerFormat , HalfFloatType , FloatType , UnsignedIntType , IntType , UnsignedShortType , ShortType , ByteType , UnsignedInt248Type , UnsignedInt5999Type , UnsignedShort5551Type , UnsignedShort4444Type , UnsignedByteType , RGBA_BPTC_Format , RED_RGTC1_Format , SIGNED_RED_RGTC1_Format , RED_GREEN_RGTC2_Format , SIGNED_RED_GREEN_RGTC2_Format , SRGBColorSpace , NoColorSpace } from '../../../constants.js' ;
1+ import { 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 , RGB_ETC1_Format , RGB_ETC2_Format , RGBA_ETC2_EAC_Format , RGBA_PVRTC_2BPPV1_Format , RGBA_PVRTC_4BPPV1_Format , RGB_PVRTC_2BPPV1_Format , RGB_PVRTC_4BPPV1_Format , RGBA_S3TC_DXT5_Format , RGBA_S3TC_DXT3_Format , RGBA_S3TC_DXT1_Format , RGB_S3TC_DXT1_Format , DepthFormat , DepthStencilFormat , RedFormat , RGBFormat , RGBAFormat , AlphaFormat , RedIntegerFormat , RGFormat , RGIntegerFormat , RGBAIntegerFormat , HalfFloatType , FloatType , UnsignedIntType , IntType , UnsignedShortType , ShortType , ByteType , UnsignedInt248Type , UnsignedInt5999Type , UnsignedShort5551Type , UnsignedShort4444Type , UnsignedByteType , RGBA_BPTC_Format , RED_RGTC1_Format , SIGNED_RED_RGTC1_Format , RED_GREEN_RGTC2_Format , SIGNED_RED_GREEN_RGTC2_Format , SRGBTransfer , NoColorSpace } from '../../../constants.js' ;
2+ import { ColorManagement } from '../../../math/ColorManagement.js' ;
23
34/**
45 * A WebGL 2 backend utility module with common helpers.
@@ -53,6 +54,8 @@ class WebGLUtils {
5354
5455 let extension ;
5556
57+ const transfer = ColorManagement . getTransfer ( colorSpace ) ;
58+
5659 if ( p === UnsignedByteType ) return gl . UNSIGNED_BYTE ;
5760 if ( p === UnsignedShort4444Type ) return gl . UNSIGNED_SHORT_4_4_4_4 ;
5861 if ( p === UnsignedShort5551Type ) return gl . UNSIGNED_SHORT_5_5_5_1 ;
@@ -89,7 +92,7 @@ class WebGLUtils {
8992
9093 if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
9194
92- if ( colorSpace === SRGBColorSpace ) {
95+ if ( transfer === SRGBTransfer ) {
9396
9497 extension = extensions . get ( 'WEBGL_compressed_texture_s3tc_srgb' ) ;
9598
@@ -156,8 +159,8 @@ class WebGLUtils {
156159
157160 if ( extension !== null ) {
158161
159- if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ETC2 : extension . COMPRESSED_RGB8_ETC2 ;
160- if ( p === RGBA_ETC2_EAC_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : extension . COMPRESSED_RGBA8_ETC2_EAC ;
162+ if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ETC2 : extension . COMPRESSED_RGB8_ETC2 ;
163+ if ( p === RGBA_ETC2_EAC_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : extension . COMPRESSED_RGBA8_ETC2_EAC ;
161164
162165 } else {
163166
@@ -179,20 +182,20 @@ class WebGLUtils {
179182
180183 if ( extension !== null ) {
181184
182- if ( p === RGBA_ASTC_4x4_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR : extension . COMPRESSED_RGBA_ASTC_4x4_KHR ;
183- if ( p === RGBA_ASTC_5x4_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR : extension . COMPRESSED_RGBA_ASTC_5x4_KHR ;
184- if ( p === RGBA_ASTC_5x5_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR : extension . COMPRESSED_RGBA_ASTC_5x5_KHR ;
185- if ( p === RGBA_ASTC_6x5_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR : extension . COMPRESSED_RGBA_ASTC_6x5_KHR ;
186- if ( p === RGBA_ASTC_6x6_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR : extension . COMPRESSED_RGBA_ASTC_6x6_KHR ;
187- if ( p === RGBA_ASTC_8x5_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR : extension . COMPRESSED_RGBA_ASTC_8x5_KHR ;
188- if ( p === RGBA_ASTC_8x6_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR : extension . COMPRESSED_RGBA_ASTC_8x6_KHR ;
189- if ( p === RGBA_ASTC_8x8_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR : extension . COMPRESSED_RGBA_ASTC_8x8_KHR ;
190- if ( p === RGBA_ASTC_10x5_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR : extension . COMPRESSED_RGBA_ASTC_10x5_KHR ;
191- if ( p === RGBA_ASTC_10x6_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR : extension . COMPRESSED_RGBA_ASTC_10x6_KHR ;
192- if ( p === RGBA_ASTC_10x8_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR : extension . COMPRESSED_RGBA_ASTC_10x8_KHR ;
193- if ( p === RGBA_ASTC_10x10_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR : extension . COMPRESSED_RGBA_ASTC_10x10_KHR ;
194- if ( p === RGBA_ASTC_12x10_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR : extension . COMPRESSED_RGBA_ASTC_12x10_KHR ;
195- if ( p === RGBA_ASTC_12x12_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR : extension . COMPRESSED_RGBA_ASTC_12x12_KHR ;
185+ if ( p === RGBA_ASTC_4x4_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR : extension . COMPRESSED_RGBA_ASTC_4x4_KHR ;
186+ if ( p === RGBA_ASTC_5x4_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR : extension . COMPRESSED_RGBA_ASTC_5x4_KHR ;
187+ if ( p === RGBA_ASTC_5x5_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR : extension . COMPRESSED_RGBA_ASTC_5x5_KHR ;
188+ if ( p === RGBA_ASTC_6x5_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR : extension . COMPRESSED_RGBA_ASTC_6x5_KHR ;
189+ if ( p === RGBA_ASTC_6x6_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR : extension . COMPRESSED_RGBA_ASTC_6x6_KHR ;
190+ if ( p === RGBA_ASTC_8x5_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR : extension . COMPRESSED_RGBA_ASTC_8x5_KHR ;
191+ if ( p === RGBA_ASTC_8x6_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR : extension . COMPRESSED_RGBA_ASTC_8x6_KHR ;
192+ if ( p === RGBA_ASTC_8x8_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR : extension . COMPRESSED_RGBA_ASTC_8x8_KHR ;
193+ if ( p === RGBA_ASTC_10x5_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR : extension . COMPRESSED_RGBA_ASTC_10x5_KHR ;
194+ if ( p === RGBA_ASTC_10x6_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR : extension . COMPRESSED_RGBA_ASTC_10x6_KHR ;
195+ if ( p === RGBA_ASTC_10x8_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR : extension . COMPRESSED_RGBA_ASTC_10x8_KHR ;
196+ if ( p === RGBA_ASTC_10x10_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR : extension . COMPRESSED_RGBA_ASTC_10x10_KHR ;
197+ if ( p === RGBA_ASTC_12x10_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR : extension . COMPRESSED_RGBA_ASTC_12x10_KHR ;
198+ if ( p === RGBA_ASTC_12x12_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR : extension . COMPRESSED_RGBA_ASTC_12x12_KHR ;
196199
197200 } else {
198201
@@ -210,7 +213,7 @@ class WebGLUtils {
210213
211214 if ( extension !== null ) {
212215
213- if ( p === RGBA_BPTC_Format ) return ( colorSpace === SRGBColorSpace ) ? extension . COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT : extension . COMPRESSED_RGBA_BPTC_UNORM_EXT ;
216+ if ( p === RGBA_BPTC_Format ) return ( transfer === SRGBTransfer ) ? extension . COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT : extension . COMPRESSED_RGBA_BPTC_UNORM_EXT ;
214217
215218 } else {
216219
0 commit comments