1Name 2 3 EXT_texture_sRGB_decode 4 5Name Strings 6 7 GL_EXT_texture_sRGB_decode 8 9Contributors 10 11 Matt Collins, Apple Inc 12 Alex Eddy, Apple Inc 13 Mark Kilgard, NVIDIA 14 Chris Niederauer, Apple Inc 15 Richard Schreyer, Apple Inc 16 Henri Verbeet, CodeWeavers 17 Brent Wilson, NVIDIA 18 Jeff Bolz, NVIDIA 19 Dan Omachi, Apple Inc 20 Jason Green, TransGaming 21 Daniel Koch, NVIDIA 22 Mathias Heyer, NVIDIA 23 24Contact 25 26 Matt Collins, Apple Inc (matthew.collins 'at' apple.com) 27 28Status 29 30 Shipping on OS X 10.7 31 32Version 33 34 Date: November 8, 2017 35 Revision: 0.91 36 37Number 38 39 OpenGL Extension #402 40 OpenGL ES Extension #152 41 42Dependencies 43 44 OpenGL 2.1 or EXT_texture_sRGB requried for OpenGL 45 46 OpenGL ES 3.0 or EXT_sRGB are required for OpenGL ES 47 48 OpenGL 3.0 or later interacts with this extension. 49 50 OpenGL ES 2.0 interacts with this extension. 51 52 OpenGL ES 3.0 interacts with this extension. 53 54 ARB_bindless_texture interacts with this extension. 55 56 ARB_sampler_objects interacts with this extension. 57 58 ARB_framebuffer_object interacts with this extension. 59 60 EXT_direct_state_access interacts with this extension. 61 62 EXT_texture_compression_s3tc interacts with this extension. 63 64 EXT_texture_integer interacts with this extension. 65 66 EXT_sRGB interacts with this extension. 67 68 NV_sRGB_formats interacts with this extension. 69 70 NV_generate_mipmap_sRGB interacts with this extension. 71 72 KHR_texture_compression_astc_ldr interacts with this extension. 73 74 ETC2 texure compression formats interact with this extension. 75 76 This extension is written against the OpenGL 2.1 (December 1, 2006) 77 specification. 78 79Overview 80 81 The EXT_texture_sRGB extension (promoted to core in OpenGL 2.1) 82 provides a texture format stored in the sRGB color space. Sampling one 83 of these textures will always return the color value decoded into a 84 linear color space. However, an application may wish to sample and 85 retrieve the undecoded sRGB data from the texture and manipulate 86 that directly. 87 88 This extension adds a Texture Parameter and Sampler Object parameter to 89 allow sRGB textures to be read directly, without decoding. 90 91 The new parameter, TEXTURE_SRGB_DECODE_EXT controls whether the 92 decoding happens at sample time. It only applies to textures with an 93 internal format that is sRGB and is ignored for all other textures. 94 This value defaults to DECODE_EXT, which indicates the texture 95 should be decoded to linear color space. 96 97New Procedures and Functions 98 99 None 100 101New Tokens 102 103 Accepted by the <pname> parameter of TexParameterf, TexParameteri, 104 TexParameterfv, TexParameteriv, TexParameterIiv, TexParameterIuiv, 105 TexParameterIivEXT, TexParameterIuivEXT, TextureParameterfEXT, 106 TextureParameterfvEXT, TextureParameteriEXT, TextureParameterivEXT, 107 TextureParameterIivEXT, TextureParameterIuivEXT, 108 MultiTexParameterfEXT, MultiTexParameterfvEXT, MultiTexParameteriEXT, 109 MultiTexParameterivEXT, MultiTexParameterIivEXT, 110 MultiTexParameterIuivEXT, GetTexParameterfv, GetTexParameteriv, 111 GetTexParameterIiv, GetTexParameterIuiv, GetTexParameterIivEXT, 112 GetTexParameterIuivEXT, GetTextureParameterfEXT, 113 GetTextureParameterfvEXT, GetTextureParameteriEXT, 114 GetTextureParameterivEXT, GetTextureParameterIivEXT, 115 GetTextureParameterIuivEXT, GetMultiTexParameterfEXT, 116 GetMultiTexParameterfvEXT, GetMultiTexParameteriEXT, 117 GetMultiTexParameterivEXT, GetMultiTexParameterIivEXT, 118 GetMultiTexParameterIuivEXT, SamplerParameteri, SamplerParameterf, 119 SamplerParameteriv, SamplerParameterfv, SamplerParameterIiv, 120 SamplerParameterIuiv, GetSamplerParameteriv, GetSamplerParameterfv, 121 GetSamplerParameterIiv, and GetSamplerParameterIuiv: 122 123 TEXTURE_SRGB_DECODE_EXT 0x8A48 124 125 Accepted by the <param> parameter of TexParameterf, TexParameteri, 126 TexParameterfv, TexParameteriv, TexParameterIiv, TexParameterIuiv, 127 TexParameterIivEXT, TexParameterIuivEXT, TextureParameterfEXT, 128 TextureParameterfvEXT, TextureParameteriEXT, TextureParameterivEXT, 129 TextureParameterIivEXT, TextureParameterIuivEXT, 130 MultiTexParameterfEXT, MultiTexParameterfvEXT, MultiTexParameteriEXT, 131 MultiTexParameterivEXT, MultiTexParameterIivEXT, 132 MultiTexParameterIuivEXT, SamplerParameteri, SamplerParameterf, 133 SamplerParameteriv, SamplerParameterfv, SamplerParameterIiv, and 134 SamplerParameterIuiv: 135 136 DECODE_EXT 0x8A49 137 SKIP_DECODE_EXT 0x8A4A 138 139Additions to Chapter 3 of the 2.1 Specification (Rasterization) 140 141 Add 1 new row to Table 3.18 (page 169). 142 143 Name Type Initial value Legal values 144 ---- ---- ------------- ------------ 145 TEXTURE_SRGB_DECODE_EXT enum DECODE_EXT DECODE_EXT, SKIP_DECODE_EXT 146 147-- OpenGL: Section 3.8.8, Texture Minification 148 149 Add to the end of the "Automatic Mipmap Generation" subsection: 150 151 If the automatic mipmap generation is applied to a texture 152 whose internal format is one of SRGB_EXT, SRGB8_EXT, 153 SRGB_ALPHA_EXT, SRGB8_ALPHA8_EXT, SLUMINANCE_ALPHA_EXT, 154 SLUMINANCE8_ALPHA8_EXT, SLUMINANCE_EXT, SLUMINANCE8_EXT, 155 COMPRESSED_SRGB_EXT, COMPRESSED_SRGB_ALPHA_EXT, 156 COMPRESSED_SLUMINANCE_EXT, COMPRESSED_SLUMINANCE_ALPHA_EXT, 157 COMPRESSED_SRGB_S3TC_DXT1_EXT, COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 158 COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, or 159 COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, and the TEXTURE_SRGB_DECODE_EXT 160 parameter for the current texture unit is DECODE_EXT, the RGB 161 texel components are decoded to a linear components as described 162 in section 3.8.15 prior to downsampling; then after downsampling, 163 the linear components are re-encoded as sRGB in the following manner: 164 165 If cl is the linear color component, then the corresponding sRGB 166 encoded component is encoded as follows 167 168 { cl * 12.92, cl < 0.0031308 169 cs = { 170 { 1.055 * cl^0.41666 - 0.055, cl >= 0.0031308 171 172 If the automatic mipmap generation is applied to a texture whose 173 internal format is one of the sRGB formats listed previously and 174 the TEXTURE_SRGB_DECODE_EXT parameter for the texture object is 175 SKIP_DECODE_EXT, the sRGB decode and encode steps are skipped during 176 mipmap generation. 177 178-- OpenGL: Section 3.8.15, sRGB Color Decoding 179 180 (section was previously titled sRGB Color Conversion) 181 182 Replace current text with the following: 183 184 If the currently bound texture's internal format is one 185 of SRGB_EXT, SRGB8_EXT, SRGB_ALPHA_EXT, SRGB8_ALPHA8_EXT, 186 SLUMINANCE_ALPHA_EXT, SLUMINANCE8_ALPHA8_EXT, SLUMINANCE_EXT, 187 SLUMINANCE8_EXT, COMPRESSED_SRGB_EXT, COMPRESSED_SRGB_ALPHA_EXT, 188 COMPRESSED_SLUMINANCE_EXT, COMPRESSED_SLUMINANCE_ALPHA_EXT, 189 COMPRESSED_SRGB_S3TC_DXT1_EXT, COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 190 COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, or 191 COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, and the TEXTURE_SRGB_DECODE_EXT 192 parameter for the current texture unit is DECODE_EXT, the red, green, and blue 193 components are decoded from an sRGB color space to a linear color 194 space as part of filtering described in sections 3.8.8 and 3.8.9. 195 Any alpha component is left unchanged. Ideally, implementations 196 should perform this color decoding on each sample prior to filtering 197 but implementations are allowed to perform this decoding after 198 filtering (though this post-filtering approach is inferior to 199 decoding from sRGB prior to filtering). 200 201 The decoding from an sRGB encoded component, cs, to a linear 202 component, cl, is as follows 203 204 { 0, cs <= 0 205 { 206 { cs / 12.92, 0 < cs <= 0.04045 207 cl = { 208 { ((cs + 0.055)/1.055)^2.4, 0.04045 < cs < 1 209 { 210 { 1, cs >= 1 211 212 Assume cs is the sRGB component in the range [0,1]. 213 214 If the TEXTURE_SRGB_DECODE_EXT parameter is SKIP_DECODE_EXT, the value 215 is returned without decoding. The TEXTURE_SRGB_DECODE_EXT 216 parameter state is ignored for any texture with an internal format 217 not explicitly listed above, as no decoding needs to be done. 218 219--- OpenGL ES 3.2: Section 8.21, sRGB Texture Color Conversion 220--- OpenGL ES 3.0: Section 3.8.16, sRGB Texture Color Conversion 221--- OpenGL ES 2.0: Section 3.7.14, sRGB Texture Color Conversion 222 223 Add after the first paragraph of the section: 224 225 "The conversion of sRGB color space components to linear color space is 226 always applied if the TEXTURE_SRGB_DECODE_EXT parameter is DECODE_EXT. 227 Table X.1 describes whether the conversion is skipped if the 228 TEXTURE_SRGB_DECODE_EXT parameter is SKIP_DECODE_EXT, depending on 229 the function used for the access, whether the access occurs through a 230 bindless sampler, and whether the texture is statically accessed 231 elsewhere with a texelFetch function." 232 233 Add a new table X.1, Whether the conversion of sRGB color space 234 components to linear color space is skipped when the 235 TEXTURE_SRGB_DECODE_EXT parameter is SKIP_DECODE_EXT. 236 237 texelFetch other builtin 238 -------------------------------------------------------------------- 239 non-bindless sampler, n/a yes 240 no accesses with 241 texelFetch 242 243 non-bindless sampler, no undefined 244 statically accessed with 245 texelFetch 246 247 bindless sampler undefined yes 248 249Dependencies on ARB_bindless_texture 250 251 If ARB_bindless_texture is NOT supported, delete all references to 252 bindless samplers. 253 254Dependencies on ARB_sampler_objects or OpenGL 3.3 or later 255 256 If ARB_sampler_objects or OpenGL 3.3 or later is NOT supported, 257 delete all references to SamplerParameter* and GetSamplerParameter*. 258 259Dependencies on ARB_framebuffer_object or OpenGL 3.0 or later 260 261 If ARB_framebuffer_object or OpenGL 3.0 or later is supported, the 262 explanation in the "Automatic Mipmap Generation" section applies to 263 the GenerateMipmap command as well. 264 265Dependencies on EXT_texture_compression_s3tc 266 267 If EXT_texture_compression_s3tc is NOT supported, delete 268 COMPRESSED_SRGB_S3TC_DXT1_EXT, COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 269 COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, and 270 COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT from Section 3.8.15. 271 272Dependencies on EXT_texture_integer 273 274 If EXT_texture_integer is NOT supported, delete references to 275 TexParameterIivEXT, TexParameterIuivEXT, GetTexParameterIivEXT, 276 and GetTexParameterIuivEXT. 277 278Dependencies on EXT_direct_state_access 279 280 If EXT_direct_state_access is NOT supported, delete 281 references to TextureParameterfEXT, TextureParameterfvEXT, 282 TextureParameteriEXT, TextureParameterivEXT, TextureParameterIivEXT, 283 TextureParameterIuivEXT, MultiTexParameterfEXT, 284 MultiTexParameterfvEXT, MultiTexParameteriEXT, MultiTexParameterivEXT, 285 MultiTexParameterIivEXT, MultiTexParameterIuivEXT, 286 GetTextureParameterfEXT, GetTextureParameterfvEXT, 287 GetTextureParameteriEXT, GetTextureParameterivEXT, 288 GetTextureParameterIivEXT, GetTextureParameterIuivEXT, 289 GetMultiTexParameterfEXT, GetMultiTexParameterfvEXT, 290 GetMultiTexParameteriEXT, GetMultiTexParameterivEXT, 291 GetMultiTexParameterIivEXT, and GetMultiTexParameterIuivEXT. 292 293Dependencies on OpenGL 3.0 294 295 If OpenGL 3.0 or later is NOT supported, delete references 296 to TexParameterIiv, TexParameterIuiv, GetTexParameterIiv, 297 and GetTexParameterIuiv. 298 299Interactions with OpenGL ES 300 301 If OpenGL ES 3.0 is NOT supported, delete references 302 to TexParameterIiv, TexParameterIuiv, GetTexParameterIiv, 303 and GetTexParameterIuiv, GetTexParameterfv, GetTexParameteriv. 304 305 If OpenGL ES 3.0 or NV_generate_mipmap_sRGB is supported, 306 TEXTURE_SRGB_DECODE_EXT will control the linearization of sRGB 307 texture levels while generating the mipmap levels. The section 308 "Automatic Mipmap Generation" applies to glGenerateMipmap instead. 309 310 If neither OpenGL ES 3.0 nor NV_sampler_objects is supported, 311 delete all references to SamplerParameter* and GetSamplerParameter*. 312 313 If NV_sampler_objects is supported, substitue the ARB_sampler_objects 314 references with corresponding commands of NV_sampler_objects. 315 316Interactions with KHR_texture_compression_astc_ldr 317 318 If KHR_texture_compression_astc_ldr is supported, the 319 TEXTURE_SRGB_DECODE_EXT texture and/or sampler parameter affects the 320 COMPRESSED_SRGB8_ALPHA8_ASTC_*_KHR formats as described in the Section 321 3.8.16 edits. 322 323Interactions with ETC2 compressed texture formats 324 325 If the ETC2 texture compression formats (part of OpenGL ES 3.0 and OpenGL 326 4.3) are supported, the TEXTURE_SRGB_DECODE_EXT texture and/or sampler 327 parameter affects the COMPRESSED_SRGB8_*ETC2* formats as described in the 328 Section 3.8.16 edits. 329 330Interactions with NV_sRGB_formats 331 332 If NV_sRGB_formats is supported, the TEXTURE_SRGB_DECODE_EXT texture and/or 333 sampler parameter affects the new SRGB and SLUMINANCE formats as described 334 in the Section 3.7.14 edits. 335 336Errors 337 338 INVALID_ENUM is generated if the <pname> parameter of 339 TexParameter[i,f,Ii,Iui][v][EXT], MultiTexParameter[i,f,Ii,Iui][v]EXT, 340 TextureParameter[i,f,Ii,Iui][v]EXT, SamplerParameter[i,f,Ii,Iui][v] 341 is TEXTURE_SRGB_DECODE_EXT when the <param> parameter is not one of 342 DECODE_EXT or SKIP_DECODE_EXT. 343 344New State 345 346 In table 6.20, Texture Objects, p. 384, add the following: 347 348 Get Value Type Get Command Initial Value Description Sec. Attribute 349 ---------------------------- ---- -------------------- ------------- ---------------- ----- --------- 350 TEXTURE_SRGB_DECODE_EXT Z_2 GetTexParameter[if]v DECODE_EXT indicates when 3.8.15 texture 351 sRGB textures 352 are decoded from 353 sRGB or the 354 decoding step is 355 skipped 356 357 Add to Table 6.23 of ARB_sampler_objects, "Textures (state per sampler object)": 358 359 Get Value Type Get Command Initial Value Description Sec. Attribute 360 ---------------------------- ---- ------------------------ ------------- ---------------- ----- --------- 361 TEXTURE_SRGB_DECODE_EXT Z_2 GetSamplerParameter[if]v DECODE_EXT indicates when 3.8.15 texture 362 sRGB textures 363 are decoded from 364 sRGB or the 365 decoding step is 366 skipped 367 368Issues 369 370 1) What should this extension be called? 371 372 RESOLVED: EXT_texture_sRGB_decode 373 374 The purpose of this extension is to allow developers to skip 375 the sRGB-to-linear decoding detailed in Section 3.8.15. 376 Since this is a decoding of the sRGB value into linear space, we 377 use that word to describe the pname. The enum indicating this 378 decoding is to happen is DECODE, as that is what the GL will do. 379 The enum that indicates this decoding is to be skipped is then 380 appropriately, SKIP_DECODE. 381 382 2) Should this allow for filters other than NEAREST on undecoded 383 sRGB values? 384 385 RESOLVED: YES 386 387 Hardware supports this, and it is left up to the programmer. 388 389 3) Do we generate an error if TEXTURE_SRGB_DECODE_EXT is changed for normal 390 textures? 391 392 RESOLVED: NO 393 394 This is similar to the ARB_shadow and ARB_framebuffer_sRGB extensions - the flag 395 is ignored for non-sRGB texture internal formats. 396 397 4) Should we add forward-looking support for ARB_sampler_objects? 398 399 RESOLVED: YES 400 401 If ARB_sampler_objects exists in the implementation, the sampler 402 objects should also include this parameter per sampler. 403 404 5) What is the expense of changing the sRGB-ness of a texture without 405 this extension? 406 407 RESOLVED: If an application wants to use a texture with sRGB 408 texels and then switch to using it with linear filtering (or vice 409 versa), OpenGL without this extension requires the application 410 to read back all the texels in all the mipmap levels of all the 411 images, and respecify a different texture object with a different 412 texture format. This is very expensive. 413 414 With this extension, the driver can simply change the underlying 415 hardware texture format associated with the texture to perform 416 sRGB conversion on filtering or not. This is very inexpensive. 417 418 However, note that the functionality of this extension can also 419 be obtained using the more modern approach provided by 420 ARB_texture_view (added to OpenGL 4.3) and OES_texture_view. 421 422 6) Do any major games or game engines depend on the ability to 423 change the sRGB-ness of textures? 424 425 RESOLVED: Yes, Valve's Source engine used by Half-Life 2, 426 Counter-Strike: Source, and Left 4 Dead; and Unreal Engine 3 427 games including Unreal Tournament 3 and BioShock. 428 429 These games and their underlying engines repeatedly render linear 430 color values into textures and then texture from the rendered 431 textures with sRGB texture filtering. 432 433 7) Why not simply allow changing whether a standard GL_RGBA8 434 can perform an sRGB color space conversion for filtering? 435 436 RESOLVED: Allowing this would create a consistency problem. 437 Why would the GL_TEXTURE_SRGB_DECODE_EXT parameter not 438 apply to GL_RGB4 or GL_RGB12 textures too? In practice, 439 sRGB color conversion for texture filtering is only typically 440 supported in hardware for a small subset of texture formats 441 (corresponding to the sized internal formats introduced by the 442 EXT_texture_sRGB specification). It's essentially only 8-bit 443 fixed-point unsigned textures where sRGB color conversion makes 444 sense. And the initial value of the parameter (GL_DECODE_EXT) would be 445 appropriate for sRGB texture formats but not conventional linear 446 texture formats (as no decoding needs to be done). Having the 447 448 texture parameter apply just to sRGB texture eliminates the ambiguity 449 of which conventional texture formats can and cannot have sRGB decoding 450 applied to them. This also eliminates the burden of having every future 451 452 texture format extension specify whether or not the sRGB decoding parameter 453 applies to them. 454 455 Direct3D 9 handles this situation by advertising for each surface 456 format (which double as texture formats) a D3DUSAGE_QUERY_SRGBREAD 457 parameter. In practice, Direct3D 9 implementation only advertise 458 the D3DUSAGE_QUERY_SRGBREAD parameter for 8-bit fixed-point 459 unsigned RGB or luminance formats, corresponding to the formats 460 available from EXT_texture_sRGB. 461 462 8) Does there need to be a control for whether to update (and 463 possibly blend) framebuffer pixels in sRGB or linear color space? 464 465 RESOLVED: The EXT_framebuffer_sRGB extension (made core in OpenGL 466 3.0) already has this capability with the GL_FRAMEBUFFER_SRGB_EXT 467 enable. 468 469 The GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING query parameter 470 roughly corresponds to Direct3D 9's D3DUSAGE_QUERY_SRGBWRITE 471 parameter. 472 473 9) How is the border color handled when toggling sRGB color 474 conversion for blending of sRGB textures? 475 476 RESOLVED: Consistent with the EXT_texture_sRGB specification, the 477 border color is always specified as a linear value (never sRGB). 478 So changing the TEXTURE_SRGB_DECODE_EXT parameter will 479 not affect the resulting sampled border color. 480 481 If an implementation were to store the texture border color in a 482 format consistent with the texel format (including the sRGB color 483 space), this would require such implementations to convert the 484 (linear) texture border RGB components to sRGB space. 485 In this case, this would mean an implementation to re-specify 486 the texture border color state in the hardware when the 487 TEXTURE_SRGB_DECODE_EXT parameter for an sRGB texture 488 changed. 489 490 Alternatively, if the implementation stored the texture 491 border color in texture formant-independent format (say 4 492 floating-point values) and always treated this as a linear RGB 493 color for purposes of texture filtering, no sRGB conversion 494 of the texture border color would ever occur. In this case, 495 this would mean an implementation would NOT need to re-specify 496 the texture border color state in the hardware when the 497 TEXTURE_SRGB_DECODE_EXT parameter for an sRGB texture 498 changed. 499 500 10) How is mipmap generation of sRGB textures affected by the 501 TEXTURE_SRGB_DECODE_EXT parameter? 502 503 RESOLVED: When the TEXTURE_SRGB_DECODE parameter is DECODE_EXT 504 for an sRGB texture, mipmap generation should decode sRGB texels 505 to a linear RGB color space, perform downsampling, then encode 506 back to an sRGB color space. (Issue 24 in the EXT_texture_sRGB 507 specification provides a rationale for why.) When the parameter 508 is SKIP_DECODE_EXT instead, mipmap generation skips the encode 509 and decode steps during mipmap generation. By skipping the 510 encode and decode steps, sRGB mipmap generation should match 511 the mipmap generation for a non-sRGB texture. 512 513 The TEXTURE_SRGB_DECODE_EXT texture parameter has no effect on 514 mipmap generation of non-sRGB textures. 515 516 Direct3D 10 and Direct3D 11 expect mipmap generation for sRGB 517 textures to be "correctly done" (meaning sRGB decode samples, 518 perform weighted average in linear space, then sRGB encode 519 the result). 520 521 Direct3D 9 expects to NOT perform sRGB-correct mipmap generation. 522 Hence the ability to generate mipmaps from an sRGB texture 523 where you skip the decode (and encode) during mipmap generation 524 is important. 525 526 11) Does automatic mipmap generation change the smaller mipmap levels 527 when the TEXTURE_SRGB_DECODE texture parameter changes? 528 529 RESOLVED: No, automatic mipmap generation only happens when the 530 base level is changed. 531 532 This means if the TEXTURE_SRGB_DECODE parameter is changed from 533 DECODE_EXT to SKIP_DECODE_EXT (or vice versa), the texels in the 534 smaller mipmap levels are not modified. 535 536 Use the glGenerateMipmap command to regenerate mipmaps explicitly 537 to reflect a change in the TEXTURE_SRGB_DECODE parameter. 538 539 12) How is this extension expected to be used for Direct3D 9 emulation? 540 541 RESOLVED: Direct3D texture resources that are created with a 542 format supporting either the SRGBREAD or SRGBWRITE capabilities 543 should be created as an OpenGL texture object with an sRGB 544 internal format. 545 546 This means that normal "linear" RGBA8 textures for Direct3D 9 547 should be created as GL_SRGB8_ALPHA8 textures so they can be used 548 with samplers where the GL_TEXTURE_SRGB_DECODE_EXT parameter of 549 the sampler (assuming ARB_sampler_objects) determines whether 550 they operate as linear textures (the GL_SKIP_DECODE_EXT) state 551 or sRGB textures (the GL_DECODE_EXT state). 552 553 Example for a Direct3D9 CreateTexture with a D3DFMT_A8R8G8B8 format: 554 555 glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, 556 width, height, border, GL_UNSIGNED_BYTE, GL_RGBA, texels); 557 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); 558 559 Notice the texture is created with a GL_SRGB_ALPHA8 format but 560 immediately switched to GL_SKIP_DECODE_EXT. This is because: 561 562 1a) The format needs to be GL_SRGBA_ALPHA so that when used with 563 a sampler configured with the (initial) value of zero (false) 564 for D3DSAMP_SRGBTEXTURE, the texture will be filtered without 565 sRGB decode. 566 567 1b) Likewise, when D3DSAMP_SRGBTEXTURE is true for a sampler, the 568 texture needs to be decoded to sRGB for filtering. In this case, 569 the OpenGL translation would use: 570 571 glSamplerParameteri(sampler, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT); 572 573 2) Direct3D9's D3DUSAGE_AUTOGENMIPMAP does not generate mipmaps 574 in sRGB space (but rather in linear space). 575 576 When rendering into a surface in Direct3D 9 with the 577 D3DRS_SRGBWRITEENABLE render state (set by SetRenderState) set to false, 578 the pixel updates (including blending) need to operate with 579 GL_FRAMEBUFFER_SRGB disabled. So: 580 581 glDisable(GL_FRAMEBUFFER_SRGB); 582 583 Likewise when the D3DRS_SRGBWRITEENABLE render state is true, 584 OpenGL should operate 585 586 glEnable(GL_FRAMEBUFFER_SRGB); 587 588 Any texture with an sRGB internal format (for example, 589 GL_SRGB8_ALPHA8 for the internal format) will perform sRGB decode 590 before blending and encode after blending. This matches the Direct3D9 591 semantics when D3DUSAGE_QUERY_SRGBWRITE is true of the resource format. 592 593 13) How is this extension expected to be used for Direct3D 10 and 594 11 emulation? 595 596 RESOLVED: Direct3D 10 and 11 support non-mutable formats for sRGB 597 textures (matching the original behavior of EXT_texture_sRGB, 598 unextended by this extension). So the DXGI_FORMAT_*_SRGB 599 formats are always decoded from sRGB to linear (and vice versa) 600 as necessary. Formats not suffixed with _SRGB are never decoded 601 or encoded to sRGB. 602 603 Direct3D 10 and 11 support "typeless" resources with resource views 604 that can have different formats. So you can create a texture 605 with a format of DXGI_FORMAT_R8G8B8A8_TYPELESS and then create 606 shader resource views with the DXGI_FORMAT_R8G8B8A8_UNORM and 607 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB formats on that. This is a much 608 more generic approach to decoupling storage and interpretation in 609 Direct3D 10 and 11. However support for "typeless" resources 610 and resource views is beyond the scope of this extension. 611 612 These two questions from Microsoft's Direct3D 10 Frequently Asked 613 Questions list provide helpful context: 614 615 "Q: Where did the D3DSAMP_SRGBTEXTURE state go? 616 617 A: SRGB was removed as part of the sampler state and now 618 is tied to the texture format. Binding an SRGB texture will 619 result in the same sampling you would get if you specified 620 D3DSAMP_SRGBTEXTURE in Direct3D 9. 621 622 Q: What are these new SRGB formats? 623 624 A: SRGB was removed as part of the sampler state and is 625 now tied to the texture format. Binding an SRGB texture will 626 result in the same sampling you would get if you specified 627 D3DSAMP_SRGBTEXTURE in Direct3D 9." 628 629 This means that normal "linear" textures, such as 630 DXGI_FORMAT_R8G8B8A8_UNORM, would be created as GL_RGBA8 textures 631 (not sRGB), so that they will always behave as linear textures 632 (never sRGB-decoded). 633 634 On the other hand, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB would be 635 created as GL_SRGB8_ALPHA8. Its texture sRGB decode parameter 636 would be left with the initial value of GL_DECODE_EXT. Mipmap 637 generation for a texture using DXGI_FORMAT_R8G8B8A8_UNORM_SRGB 638 (GL_RGB8_ALPHA8 in OpenGL) would perform the proper sRGB decode 639 and encode needed for automatic mipmap generation. 640 641 In Direct3D 10 and 11 emulation, the GL_TEXTURE_SRGB_DECODE_EXT 642 parameter of sampler objects would simply be left at its initial 643 value of GL_DECODE_EXT. Unlike Direct3D 9 where the sampler 644 controlled sRGB decode (via the D3DSAMP_SRGBTEXTURE), that parameter 645 is not present in Direct3D 10 and 11 (see the FAQ questions above). 646 647 The conclusion of this issue's discussion is that Direct3D 648 10 and 11 emulation software should simply ignore the 649 EXT_texture_sRGB_decode extension. This is to be expected 650 because the EXT_texture_sRGB_decode extension is meant to match 651 the legacy functionality of Direct3D 9. 652 653 14) Why does Table X.1 show "Undefined", and why does it appear in 654 different columns depending on whether bindless samplers are used 655 or not? 656 657 RESOLVED: Conceptually, TEXTURE_SRGB_DECODE_EXT is part of the 658 sampler state and should therefore not apply to texelFetch. However, 659 not all hardware has the required bit in the sampler state. 660 661 With bindless samplers, texture handles are *always* statically 662 accessed by texelFetch (because an application could choose to do so 663 at any time), so applying the same rules as for non-bindless 664 samplers would make the functionality provided in this extension 665 useless. 666 667Revision History 668 669 Rev. Date Author Changes 670 ---- -------- -------- ------------------------------------- 671 0.91 11/08/17 nhaehnle Add interaction with bindless textures 672 (API issue #51) 673 0.90 04/27/16 Jon Leech Add interaction with texelFetch builtins 674 (Bug 14934) 675 0.89 08/14/13 dkoch Add interactions with ASTC/ETC2/NV_sRGB_formats 676 0.88 07/24/13 mheyer Add OpenGL ES interactions 677 0.87 08/22/11 mjk correction to issue #8 from Jason 678 0.86 08/22/11 mjk corrections from Daniel + more interactions 679 0.85 08/13/11 mjk corrections to issues from Jason and Henri 680 0.84 08/05/11 mjk New issues to explain Direct3D interactions; 681 fix table Get Command. 682 0.83 07/15/11 mjk "current texture unit" -> "texture 683 object" for mipmap generation 684 0.82 04/12/11 mjk Mipmap generation interactions. 685 0.81 11/18/10 mattc Fixed language in error section. 686 Cleaned up which functions take which tokens. 687 0.8 11/18/10 mattc Added issues from EXT_texture_sRGB_decode 688 689 for background info. Cleaned up layout. 690 0.71 11/18/10 mattc Adapted apple_texture_linearize_srgb into 691 this specification. 692