Skip to content

Commit

Permalink
Merge pull request #12567 from kircher1/users/briank/etc-srgb-fallback
Browse files Browse the repository at this point in the history
Add sRGB handling for ETC texture formats
  • Loading branch information
sebavan committed May 24, 2022
2 parents 15d670c + b26ad05 commit fae0db8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/dev/core/src/Engines/WebGPU/webgpuTextureHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,10 @@ export class WebGPUTextureHelper {
case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4:
return useSRGBBuffer ? WebGPUConstants.TextureFormat.ASTC4x4UnormSRGB : WebGPUConstants.TextureFormat.ASTC4x4Unorm;
case Constants.TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL:
case Constants.TEXTUREFORMAT_COMPRESSED_RGB8_ETC2:
return useSRGBBuffer ? WebGPUConstants.TextureFormat.ETC2RGB8UnormSRGB : WebGPUConstants.TextureFormat.ETC2RGB8Unorm;
case Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC:
return useSRGBBuffer ? WebGPUConstants.TextureFormat.ETC2RGBA8UnormSRGB : WebGPUConstants.TextureFormat.ETC2RGBA8Unorm;
}

switch (type) {
Expand Down
20 changes: 20 additions & 0 deletions packages/dev/core/src/Engines/thinEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,10 @@ export class ThinEngine {
this._gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
this._gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
}
if (this._caps.etc2) {
this._gl.COMPRESSED_SRGB8_ETC2 = this._caps.etc2.COMPRESSED_SRGB8_ETC2;
this._gl.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = this._caps.etc2.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
}

// Checks if some of the format renders first to allow the use of webgl inspector.
if (this._webGLVersion > 1) {
Expand Down Expand Up @@ -4481,6 +4485,22 @@ export class ThinEngine {

if (texture._useSRGBBuffer) {
switch (internalFormat) {
case Constants.TEXTUREFORMAT_COMPRESSED_RGB8_ETC2:
case Constants.TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL:
// Note, if using ETC1 and sRGB is requested, this will use ETC2 if available.
if (this._caps.etc2) {
internalFormat = gl.COMPRESSED_SRGB8_ETC2;
} else {
texture._useSRGBBuffer = false;
}
break;
case Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC:
if (this._caps.etc2) {
internalFormat = gl.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
} else {
texture._useSRGBBuffer = false;
}
break;
case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM:
internalFormat = gl.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT;
break;
Expand Down
2 changes: 2 additions & 0 deletions packages/dev/core/src/LibDeclarations/webgl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ interface WebGLRenderingContext {
COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: number;
COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: number;
COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: number;
COMPRESSED_SRGB8_ETC2: number;
COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: number;

UNSIGNED_INT_24_8: number;
DEPTH24_STENCIL8: number;
Expand Down

0 comments on commit fae0db8

Please sign in to comment.