1Name 2 3 EXT_pvrtc_sRGB 4 5Name Strings 6 7 GL_EXT_pvrtc_sRGB 8 9Contributors 10 11 Gokhan Avkarogullari, Apple 12 Ben Bowman, Imagination Technologies 13 Benj Lipchak, Apple 14 John Rosasco, Apple 15 Richard Schreyer, Apple 16 Anthony Tai, Apple 17 18Contact 19 20 Benj Lipchak, Apple Inc., (lipchak 'at' apple.com) 21 22Status 23 24 Complete 25 26Version 27 28 Last Modified Date: June 26, 2013 29 Revision: 3 30 31Number 32 33 OpenGL ES Extension #155 34 35Dependencies 36 37 OpenGL ES 2.0 is required. 38 39 IMG_texture_compression_pvrtc is required. 40 41 This extension extends the OpenGL ES 2.0.25 (Full Specification) and 42 the OpenGL ES Shading Language Specification v1.00 revision 16. 43 44 This extension follows precedent and issue resolution of the following 45 specifications except where otherwise noted: 46 http://www.opengl.org/registry/specs/EXT/texture_sRGB.txt 47 http://www.khronos.org/registry/gles/extensions/OES/OES_framebuffer_object.txt 48 49 For single-reference completeness, some of the issues from the issues lists 50 of these specifications have been copied into this extension. 51 52 This extension follows the conventions of and extends the EXT_sRGB 53 extension at: 54 http://www.khronos.org/registry/gles/extensions/EXT/EXT_sRGB.txt 55 56 EXT_texture_storage affects the definition of this extension. 57 58 IMG_texture_compression_pvrtc2 affects the definition of this extension. 59 60Overview 61 62 The response from electronic display systems given RGB tristimulus values 63 for each pixel is non-linear. Gamma correction is the process of encoding 64 or decoding images in a manner that will correct for non-linear response 65 profiles of output devices. The displayed results of gamma-corrected pixel 66 data are more consistent and predictable for the author of such pixel data 67 than it would otherwise be with linearly encoded pixel data. 68 69 This EXT_pvrtc_sRGB extension specifies additional tokens for gamma 70 corrected PVRTC compressed sRGB data. 71 72 Texture assets are developed and evaluated for use in OpenGL applications 73 using electronic displays with non-linear responses. This extension 74 provides a better measure of consistency between textures developed within 75 an asset toolchain and their final rendered result with an OpenGL 76 application that uses those textures. 77 78 Conventional OpenGL texture tristimulus values as well as their alpha 79 component are encoded linearly. The textures introduced by this extension 80 are encoded with gamma correction in the tristimulus components but 81 linearly in the alpha component. 82 83 When gamma corrected texture samples are fetched and operated on by ALU 84 operations in an OpenGL shading program those samples will be converted 85 from gamma corrected space to linear space for logical simplicity and 86 performance of the shader. 87 88 Texture filtering operations as well as mipmap generation are carried out 89 in linear space. 90 91IP Status 92 93 No known IP issues outstanding. 94 95Issues 96 97 (1) What must be specified as far as how do you convert to and from 98 sRGB and linear RGB color spaces? 99 100 RESOLVED: The specification language needs to only supply the 101 sRGB to linear RGB conversion. 102 103 For completeness, the accepted linear RGB to sRGB conversion 104 is as follows: 105 106 Given a linear RGB component, cl, convert it to an sRGB component, 107 cs, in the range [0,1], with this pseudo-code: 108 109 if (isnan(cl)) { 110 /* Map IEEE-754 Not-a-number to zero. */ 111 cs = 0.0; 112 } else if (cl > 1.0) { 113 cs = 1.0; 114 } else if (cl < 0.0) { 115 cs = 0.0; 116 } else if (cl < 0.0031308) { 117 cs = 12.92 * cl; 118 } else { 119 cs = 1.055 * pow(cl, 0.41666) - 0.055; 120 } 121 122 sRGB components are typically stored as unsigned 8-bit 123 fixed-point values. If cs is computed with the above 124 pseudo-code, cs can be converted to a [0,255] integer with this 125 formula: 126 127 csi = floor(255.0 * cs + 0.5) 128 129 (2) Does this extension guarantee images rendered with sRGB textures will 130 "look good" when output to a device supporting an sRGB color space? 131 132 RESOLVED: No. 133 134 With this extension, artists can author content in an sRGB color 135 space and provide that sRGB content for use as texture imagery 136 that can be properly converted to linear RGB and filtered as part 137 of texturing in a way that preserves the sRGB distribution of 138 precision, but that does NOT mean sRGB pixels are output 139 to the framebuffer. Indeed, this extension provides texture 140 formats that convert sRGB to linear RGB as part of filtering. 141 142 With programmable shading, an application could perform a 143 linear RGB to sRGB conversion just prior to emitting color 144 values from the shader. Even so, OpenGL blending (other than 145 simple modulation) will perform linear math operations on values 146 stored in a non-linear space which is technically incorrect for 147 sRGB-encoded colors. 148 149 One way to think about these sRGB texture formats is that they 150 simply provide color components with a distribution of values 151 distributed to favor precision towards 0 rather than evenly 152 distributing the precision with conventional non-sRGB formats 153 such as GL_RGB8. 154 155 (3) Should the square compressed texture restriction be applied to this 156 extension given the current state of hardware on which compressed 157 sRGB textures are expected to be implemented ? 158 159 RESOLVED: Yes 160 161 This extension does not relax any constraint established by the 162 IMG_texture_compression_pvrtc specification upon which it is 163 dependent. The compressed gamma-corrected formats provided in this 164 extension have the same characteristics and constraints as their 165 non-gamma-corrected counterparts in the IMG_texture_compression_pvrtc 166 specification. 167 168 (4) If hardware doesn't support rendering to sRGB textures to levels 169 other than the base level 0 how is this expressed through the API? 170 171 RESOLVED: Yes 172 173 N/A. This specification only includes compressed formats which are 174 not color-renderable per the ES 2.0 specification. 175 176 (5) Can PVRTC gamma corrected textures, as described in this 177 specification, cannot be used as a framebuffer-attachable image and 178 thus cannot be rendered to: 179 180 RESOLVED: No 181 182 Rendering to PVRTC textures is not usually supported by embedded 183 hardware and this specification makes no exceptions to that effect. 184 185 (6) The desktop extension EXT_texture_sRGB_decode to allow toggling 186 texel fetch gamma decoding on and off. Is this capability 187 warranted for this OpenGL ES specification ? 188 189 RESOLVED: Yes 190 191 Decode will not be included in this specification. This feature 192 can be added as an amendment / separate extension if sufficient 193 demand warrants it. 194 195 (7) Generating mipmaps without hardware support for linearizing, 196 processing then re-applying gamma is a costly operation and 197 brings into question having sRGB support for GenerateMipmaps(). 198 Evaluate hardware aspects to this issue and update this 199 specification accordingly. 200 201 RESOLVED: No 202 203 (8) Should there be an interaction with IMG_texture_compression_pvrtc2? 204 205 RESOLVED: Yes 206 207 If PVRTC2 is supported, then further enums are added to enable 208 sRGB decode of those formats. Note that these formats are not 209 available on all implementations (namely iOS), so be sure to 210 check for the extension string. 211 212New Procedures and Functions 213 214 None 215 216New Tokens 217 218 Accepted by the <internalformat> parameter of CompressedTexImage2D and 219 TexStorage2DEXT and the <format> parameter of CompressedTexSubImage2D: 220 221 COMPRESSED_SRGB_PVRTC_2BPPV1_EXT 0x8A54 222 COMPRESSED_SRGB_PVRTC_4BPPV1_EXT 0x8A55 223 COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT 0x8A56 224 COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT 0x8A57 225 226Additions to Chapter 3 of the 2.0.25 Specification (Rasterization) 227 228 -- Section 3.7.3, Compressed Texture Images 229 230 Add Table 3.9.1 "Gamma Corrected Compressed Texture Formats" 231 232 COMPRESSED_SRGB_PVRTC_2BPPV1_EXT 233 COMPRESSED_SRGB_PVRTC_4BPPV1_EXT 234 COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT 235 COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT 236 237 -- Section 3.8, Texture Access, Add paragraph after first paragraph 238 (page 85): 239 240 When a texture, of formats included in table 3.9.1, sample is performed 241 from a bound texture that is gamma corrected the sample will be implicitly 242 converted to its corresponding linear value. 243 244Additions to Chapter 8 "Built-in Functions" of the OpenGL ES Shading Language 245document version 1.00, document revision 16: 246 247 -- Section 8.7 "Texture Lookup Functions", add paragraph after 2nd 248 paragraph (page 71): 249 250 Then the 2D texture currently bound to "sampler" in the texture lookup 251 functions is a gamma corrected 2D texture (as listed in Table 3.9.1 252 of the OpenGL ES 2.0 specification) the vec4 return value of the 253 sampler functions will be converted into its linear space equivalent value 254 in accordance with the parameters established by the EXT_pvrtc_sRGB 255 extension. 256 257Dependencies on IMG_texture_compression_pvrtc2 258 259 If IMG_texture_compression_pvrtc2 is supported, then 260 261 COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV2_IMG 0x93F0 262 COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV2_IMG 0x93F1 263 264 are accepted by the <internalformat> parameter of CompressedTexImage2D and 265 TexStorage2DEXT and the <format> parameter of CompressedTexSubImage2D, and 266 are added to table 3.9.1 "Gamma Corrected Compressed Texture Formats". 267 268 Errors 269 270 Modify the errors introduced by IMG_texture_compression_pvrtc2 as below: 271 272 INVALID_OPERATION is generated by CompressedTexSubImage2D if 273 INTERNAL_FORMAT is COMPRESSED_RGBA_PVRTC_2BPPV2_IMG or 274 COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV2_IMG and any of the following apply: 275 276 * <xoffset> is not a multiple of eight. 277 * <yoffset> is not a multiple of four. 278 * <width> is not a multiple of eight, except when the sum of <width> 279 and <xoffset> is equal to TEXTURE_WIDTH. 280 * <height> is not a multiple of four, except when the sum of <height> 281 and <yoffset> is equal to TEXTURE_HEIGHT. 282 * <format> does not match the internal format of the texture image 283 being modified. 284 285 INVALID_OPERATION is generated by CompressedTexSubImage2D if 286 INTERNAL_FORMAT is COMPRESSED_RGBA_PVRTC_4BPPV2_IMG or 287 COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV2_IMG and any of the following apply: 288 289 * <xoffset> is not a multiple of four. 290 * <yoffset> is not a multiple of four. 291 * <width> is not a multiple of four, except when the sum of <width> 292 and <xoffset> is equal to TEXTURE_WIDTH. 293 * <height> is not a multiple of four, except when the sum of <height> 294 and <yoffset> is equal to TEXTURE_HEIGHT. 295 * <format> does not match the internal format of the texture image 296 being modified. 297 298 299Dependencies on EXT_texture_storage 300 301 If EXT_texture_storage is not supported, then all references to 302 TexStorage2DEXT should be ignored. 303 304Errors 305 306 Relax INVALID_ENUM errors for the new <internalformat> and <format> 307 parameters for CompressedTexImage2D and CompressedTexSubImage2D introduced 308 by this specification. 309 310 INVALID_OPERATION is generated by CompressedTexSubImage2D if <format> 311 is COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, 312 COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, or 313 COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT and any of the following apply: 314 <width> is not equal to TEXTURE_WIDTH; <height> is not equal to 315 TEXTURE_HEIGHT; <xoffset> and <yoffset> are not zero. 316 317Revision History 318 319 #1 February 6 2013, Benj Lipchak 320 - initial version 321 #2 June 26 2013, Benj Lipchak 322 - promotion from APPLE to EXT 323 #3 June 28 2013, Ben Bowman 324 - Added issue 8 and interaction with IMG_texture_compression_pvrtc2 325