texture_compression_s3tc.txt 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. Name
  2. EXT_texture_compression_s3tc
  3. Name Strings
  4. GL_EXT_texture_compression_s3tc
  5. Contact
  6. Pat Brown, NVIDIA Corporation (pbrown 'at' nvidia.com)
  7. Status
  8. FINAL
  9. Version
  10. 1.1, 16 November 2001 (containing only clarifications relative to
  11. version 1.0, dated 7 July 2000)
  12. Number
  13. 198
  14. Dependencies
  15. OpenGL 1.1 is required.
  16. GL_ARB_texture_compression is required.
  17. This extension is written against the OpenGL 1.2.1 Specification.
  18. Overview
  19. This extension provides additional texture compression functionality
  20. specific to S3's S3TC format (called DXTC in Microsoft's DirectX API),
  21. subject to all the requirements and limitations described by the extension
  22. GL_ARB_texture_compression.
  23. This extension supports DXT1, DXT3, and DXT5 texture compression formats.
  24. For the DXT1 image format, this specification supports an RGB-only mode
  25. and a special RGBA mode with single-bit "transparent" alpha.
  26. IP Status
  27. Contact S3 Incorporated (http://www.s3.com) regarding any intellectual
  28. property issues associated with implementing this extension.
  29. WARNING: Vendors able to support S3TC texture compression in Direct3D
  30. drivers do not necessarily have the right to use the same functionality in
  31. OpenGL.
  32. Issues
  33. (1) Should DXT2 and DXT4 (premultiplied alpha) formats be supported?
  34. RESOLVED: No -- insufficient interest. Supporting DXT2 and DXT4
  35. would require some rework to the TexEnv definition (maybe add a new
  36. base internal format RGBA_PREMULTIPLIED_ALPHA) for these formats.
  37. Note that the EXT_texture_env_combine extension (which extends normal
  38. TexEnv modes) can be used to support textures with premultipled alpha.
  39. (2) Should generic "RGB_S3TC_EXT" and "RGBA_S3TC_EXT" enums be supported
  40. or should we use only the DXT<n> enums?
  41. RESOLVED: No. A generic RGBA_S3TC_EXT is problematic because DXT3
  42. and DXT5 are both nominally RGBA (and DXT1 with the 1-bit alpha is
  43. also) yet one format must be chosen up front.
  44. (3) Should TexSubImage support all block-aligned edits or just the minimal
  45. functionality required by the ARB_texture_compression extension?
  46. RESOLVED: Allow all valid block-aligned edits.
  47. (4) A pre-compressed image with a DXT1 format can be used as either an
  48. RGB_S3TC_DXT1 or an RGBA_S3TC_DXT1 image. If the image has
  49. transparent texels, how are they treated in each format?
  50. RESOLVED: The renderer has to make sure that an RGB_S3TC_DXT1 format
  51. is decoded as RGB (where alpha is effectively one for all texels),
  52. while RGBA_S3TC_DXT1 is decoded as RGBA (where alpha is zero for all
  53. texels with "transparent" encodings). Otherwise, the formats are
  54. identical.
  55. (5) Is the encoding of the RGB components for DXT1 formats correct in this
  56. spec? MSDN documentation does not specify an RGB color for the
  57. "transparent" encoding. Is it really black?
  58. RESOLVED: Yes. The specification for the DXT1 format initially
  59. required black, but later changed that requirement to a
  60. recommendation. All vendors involved in the definition of this
  61. specification support black. In addition, specifying black has a
  62. useful behavior.
  63. When blending multiple texels (GL_LINEAR filtering), mixing opaque and
  64. transparent samples is problematic. Defining a black color on
  65. transparent texels achieves a sensible result that works like a
  66. texture with premultiplied alpha. For example, if three opaque white
  67. and one transparent sample is being averaged, the result would be a
  68. 75% intensity gray (with an alpha of 75%). This is the same result on
  69. the color channels as would be obtained using a white color, 75%
  70. alpha, and a SRC_ALPHA blend factor.
  71. (6) Is the encoding of the RGB components for DXT3 and DXT5 formats
  72. correct in this spec? MSDN documentation suggests that the RGB blocks
  73. for DXT3 and DXT5 are decoded as described by the DXT1 format.
  74. RESOLVED: Yes -- this appears to be a bug in the MSDN documentation.
  75. The specification for the DXT2-DXT5 formats require decoding using the
  76. opaque block encoding, regardless of the relative values of "color0"
  77. and "color1".
  78. New Procedures and Functions
  79. None.
  80. New Tokens
  81. Accepted by the <internalformat> parameter of TexImage2D, CopyTexImage2D,
  82. and CompressedTexImage2DARB and the <format> parameter of
  83. CompressedTexSubImage2DARB:
  84. COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
  85. COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
  86. COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
  87. COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
  88. Additions to Chapter 2 of the OpenGL 1.2.1 Specification (OpenGL Operation)
  89. None.
  90. Additions to Chapter 3 of the OpenGL 1.2.1 Specification (Rasterization)
  91. Add to Table 3.16.1: Specific Compressed Internal Formats
  92. Compressed Internal Format Base Internal Format
  93. ========================== ====================
  94. COMPRESSED_RGB_S3TC_DXT1_EXT RGB
  95. COMPRESSED_RGBA_S3TC_DXT1_EXT RGBA
  96. COMPRESSED_RGBA_S3TC_DXT3_EXT RGBA
  97. COMPRESSED_RGBA_S3TC_DXT5_EXT RGBA
  98. Modify Section 3.8.2, Alternate Image Specification
  99. (add to end of TexSubImage discussion, p.123 -- after edit from the
  100. ARB_texture_compression spec)
  101. If the internal format of the texture image being modified is
  102. COMPRESSED_RGB_S3TC_DXT1_EXT, COMPRESSED_RGBA_S3TC_DXT1_EXT,
  103. COMPRESSED_RGBA_S3TC_DXT3_EXT, or COMPRESSED_RGBA_S3TC_DXT5_EXT, the
  104. texture is stored using one of the several S3TC compressed texture image
  105. formats. Such images are easily edited along 4x4 texel boundaries, so the
  106. limitations on TexSubImage2D or CopyTexSubImage2D parameters are relaxed.
  107. TexSubImage2D and CopyTexSubImage2D will result in an INVALID_OPERATION
  108. error only if one of the following conditions occurs:
  109. * <width> is not a multiple of four or equal to TEXTURE_WIDTH,
  110. unless <xoffset> and <yoffset> are both zero.
  111. * <height> is not a multiple of four or equal to TEXTURE_HEIGHT,
  112. unless <xoffset> and <yoffset> are both zero.
  113. * <xoffset> or <yoffset> is not a multiple of four.
  114. The contents of any 4x4 block of texels of an S3TC compressed texture
  115. image that does not intersect the area being modified are preserved during
  116. valid TexSubImage2D and CopyTexSubImage2D calls.
  117. Add to Section 3.8.2, Alternate Image Specification (adding to the end of
  118. the CompressedTexImage section introduced by the ARB_texture_compression
  119. spec)
  120. If <internalformat> is COMPRESSED_RGB_S3TC_DXT1_EXT,
  121. COMPRESSED_RGBA_S3TC_DXT1_EXT, COMPRESSED_RGBA_S3TC_DXT3_EXT, or
  122. COMPRESSED_RGBA_S3TC_DXT5_EXT, the compressed texture is stored using one
  123. of several S3TC compressed texture image formats. The S3TC texture
  124. compression algorithm supports only 2D images without borders.
  125. CompressedTexImage1DARB and CompressedTexImage3DARB produce an
  126. INVALID_ENUM error if <internalformat> is an S3TC format.
  127. CompressedTexImage2DARB will produce an INVALID_OPERATION error if
  128. <border> is non-zero.
  129. Add to Section 3.8.2, Alternate Image Specification (adding to the end of
  130. the CompressedTexSubImage section introduced by the
  131. ARB_texture_compression spec)
  132. If the internal format of the texture image being modified is
  133. COMPRESSED_RGB_S3TC_DXT1_EXT, COMPRESSED_RGBA_S3TC_DXT1_EXT,
  134. COMPRESSED_RGBA_S3TC_DXT3_EXT, or COMPRESSED_RGBA_S3TC_DXT5_EXT, the
  135. texture is stored using one of the several S3TC compressed texture image
  136. formats. Since the S3TC texture compression algorithm supports only 2D
  137. images, CompressedTexSubImage1DARB and CompressedTexSubImage3DARB produce
  138. an INVALID_ENUM error if <format> is an S3TC format. Since S3TC images
  139. are easily edited along 4x4 texel boundaries, the limitations on
  140. CompressedTexSubImage2D are relaxed. CompressedTexSubImage2D will result
  141. in an INVALID_OPERATION error only if one of the following conditions
  142. occurs:
  143. * <width> is not a multiple of four or equal to TEXTURE_WIDTH.
  144. * <height> is not a multiple of four or equal to TEXTURE_HEIGHT.
  145. * <xoffset> or <yoffset> is not a multiple of four.
  146. The contents of any 4x4 block of texels of an S3TC compressed texture
  147. image that does not intersect the area being modified are preserved during
  148. valid TexSubImage2D and CopyTexSubImage2D calls.
  149. Additions to Chapter 4 of the OpenGL 1.2.1 Specification (Per-Fragment
  150. Operations and the Frame Buffer)
  151. None.
  152. Additions to Chapter 5 of the OpenGL 1.2.1 Specification (Special Functions)
  153. None.
  154. Additions to Chapter 6 of the OpenGL 1.2.1 Specification (State and
  155. State Requests)
  156. None.
  157. Additions to Appendix A of the OpenGL 1.2.1 Specification (Invariance)
  158. None.
  159. Additions to the AGL/GLX/WGL Specifications
  160. None.
  161. GLX Protocol
  162. None.
  163. Errors
  164. INVALID_ENUM is generated by CompressedTexImage1DARB or
  165. CompressedTexImage3DARB if <internalformat> is
  166. COMPRESSED_RGB_S3TC_DXT1_EXT, COMPRESSED_RGBA_S3TC_DXT1_EXT,
  167. COMPRESSED_RGBA_S3TC_DXT3_EXT, or COMPRESSED_RGBA_S3TC_DXT5_EXT.
  168. INVALID_OPERATION is generated by CompressedTexImage2DARB if
  169. <internalformat> is COMPRESSED_RGB_S3TC_DXT1_EXT,
  170. COMPRESSED_RGBA_S3TC_DXT1_EXT, COMPRESSED_RGBA_S3TC_DXT3_EXT, or
  171. COMPRESSED_RGBA_S3TC_DXT5_EXT and <border> is not equal to zero.
  172. INVALID_ENUM is generated by CompressedTexSubImage1DARB or
  173. CompressedTexSubImage3DARB if <format> is COMPRESSED_RGB_S3TC_DXT1_EXT,
  174. COMPRESSED_RGBA_S3TC_DXT1_EXT, COMPRESSED_RGBA_S3TC_DXT3_EXT, or
  175. COMPRESSED_RGBA_S3TC_DXT5_EXT.
  176. INVALID_OPERATION is generated by TexSubImage2D CopyTexSubImage2D, or
  177. CompressedTexSubImage2D if TEXTURE_INTERNAL_FORMAT is
  178. COMPRESSED_RGB_S3TC_DXT1_EXT, COMPRESSED_RGBA_S3TC_DXT1_EXT,
  179. COMPRESSED_RGBA_S3TC_DXT3_EXT, or COMPRESSED_RGBA_S3TC_DXT5_EXT and any of
  180. the following apply: <width> is not a multiple of four or equal to
  181. TEXTURE_WIDTH; <height> is not a multiple of four or equal to
  182. TEXTURE_HEIGHT; <xoffset> or <yoffset> is not a multiple of four.
  183. The following restrictions from the ARB_texture_compression specification
  184. do not apply to S3TC texture formats, since subimage modification is
  185. straightforward as long as the subimage is properly aligned.
  186. DELETE: INVALID_OPERATION is generated by TexSubImage1D, TexSubImage2D,
  187. DELETE: TexSubImage3D, CopyTexSubImage1D, CopyTexSubImage2D, or
  188. DELETE: CopyTexSubImage3D if the internal format of the texture image is
  189. DELETE: compressed and <xoffset>, <yoffset>, or <zoffset> does not equal
  190. DELETE: -b, where b is value of TEXTURE_BORDER.
  191. DELETE: INVALID_VALUE is generated by CompressedTexSubImage1DARB,
  192. DELETE: CompressedTexSubImage2DARB, or CompressedTexSubImage3DARB if the
  193. DELETE: entire texture image is not being edited: if <xoffset>,
  194. DELETE: <yoffset>, or <zoffset> is greater than -b, <xoffset> + <width> is
  195. DELETE: less than w+b, <yoffset> + <height> is less than h+b, or <zoffset>
  196. DELETE: + <depth> is less than d+b, where b is the value of
  197. DELETE: TEXTURE_BORDER, w is the value of TEXTURE_WIDTH, h is the value of
  198. DELETE: TEXTURE_HEIGHT, and d is the value of TEXTURE_DEPTH.
  199. See also errors in the GL_ARB_texture_compression specification.
  200. New State
  201. In the "Textures" state table, increment the TEXTURE_INTERNAL_FORMAT
  202. subscript for Z by 4 in the "Type" row.
  203. New Implementation Dependent State
  204. None
  205. Appendix
  206. S3TC Compressed Texture Image Formats
  207. Compressed texture images stored using the S3TC compressed image formats
  208. are represented as a collection of 4x4 texel blocks, where each block
  209. contains 64 or 128 bits of texel data. The image is encoded as a normal
  210. 2D raster image in which each 4x4 block is treated as a single pixel. If
  211. an S3TC image has a width or height less than four, the data corresponding
  212. to texels outside the image are irrelevant and undefined.
  213. When an S3TC image with a width of <w>, height of <h>, and block size of
  214. <blocksize> (8 or 16 bytes) is decoded, the corresponding image size (in
  215. bytes) is:
  216. ceil(<w>/4) * ceil(<h>/4) * blocksize.
  217. When decoding an S3TC image, the block containing the texel at offset
  218. (<x>, <y>) begins at an offset (in bytes) relative to the base of the
  219. image of:
  220. blocksize * (ceil(<w>/4) * floor(<y>/4) + floor(<x>/4)).
  221. The data corresponding to a specific texel (<x>, <y>) are extracted from a
  222. 4x4 texel block using a relative (x,y) value of
  223. (<x> modulo 4, <y> modulo 4).
  224. There are four distinct S3TC image formats:
  225. COMPRESSED_RGB_S3TC_DXT1_EXT: Each 4x4 block of texels consists of 64
  226. bits of RGB image data.
  227. Each RGB image data block is encoded as a sequence of 8 bytes, called (in
  228. order of increasing address):
  229. c0_lo, c0_hi, c1_lo, c1_hi, bits_0, bits_1, bits_2, bits_3
  230. The 8 bytes of the block are decoded into three quantities:
  231. color0 = c0_lo + c0_hi * 256
  232. color1 = c1_lo + c1_hi * 256
  233. bits = bits_0 + 256 * (bits_1 + 256 * (bits_2 + 256 * bits_3))
  234. color0 and color1 are 16-bit unsigned integers that are unpacked to
  235. RGB colors RGB0 and RGB1 as though they were 16-bit packed pixels with
  236. a <format> of RGB and a type of UNSIGNED_SHORT_5_6_5.
  237. bits is a 32-bit unsigned integer, from which a two-bit control code
  238. is extracted for a texel at location (x,y) in the block using:
  239. code(x,y) = bits[2*(4*y+x)+1..2*(4*y+x)+0]
  240. where bit 31 is the most significant and bit 0 is the least
  241. significant bit.
  242. The RGB color for a texel at location (x,y) in the block is given by:
  243. RGB0, if color0 > color1 and code(x,y) == 0
  244. RGB1, if color0 > color1 and code(x,y) == 1
  245. (2*RGB0+RGB1)/3, if color0 > color1 and code(x,y) == 2
  246. (RGB0+2*RGB1)/3, if color0 > color1 and code(x,y) == 3
  247. RGB0, if color0 <= color1 and code(x,y) == 0
  248. RGB1, if color0 <= color1 and code(x,y) == 1
  249. (RGB0+RGB1)/2, if color0 <= color1 and code(x,y) == 2
  250. BLACK, if color0 <= color1 and code(x,y) == 3
  251. Arithmetic operations are done per component, and BLACK refers to an
  252. RGB color where red, green, and blue are all zero.
  253. Since this image has an RGB format, there is no alpha component and the
  254. image is considered fully opaque.
  255. COMPRESSED_RGBA_S3TC_DXT1_EXT: Each 4x4 block of texels consists of 64
  256. bits of RGB image data and minimal alpha information. The RGB components
  257. of a texel are extracted in the same way as COMPRESSED_RGB_S3TC_DXT1_EXT.
  258. The alpha component for a texel at location (x,y) in the block is
  259. given by:
  260. 0.0, if color0 <= color1 and code(x,y) == 3
  261. 1.0, otherwise
  262. IMPORTANT: When encoding an RGBA image into a format using 1-bit
  263. alpha, any texels with an alpha component less than 0.5 end up with an
  264. alpha of 0.0 and any texels with an alpha component greater than or
  265. equal to 0.5 end up with an alpha of 1.0. When encoding an RGBA image
  266. into the COMPRESSED_RGBA_S3TC_DXT1_EXT format, the resulting red,
  267. green, and blue components of any texels with a final alpha of 0.0
  268. will automatically be zero (black). If this behavior is not desired
  269. by an application, it should not use COMPRESSED_RGBA_S3TC_DXT1_EXT.
  270. This format will never be used when a generic compressed internal
  271. format (Table 3.16.2) is specified, although the nearly identical
  272. format COMPRESSED_RGB_S3TC_DXT1_EXT (above) may be.
  273. COMPRESSED_RGBA_S3TC_DXT3_EXT: Each 4x4 block of texels consists of 64
  274. bits of uncompressed alpha image data followed by 64 bits of RGB image
  275. data.
  276. Each RGB image data block is encoded according to the
  277. COMPRESSED_RGB_S3TC_DXT1_EXT format, with the exception that the two code
  278. bits always use the non-transparent encodings. In other words, they are
  279. treated as though color0 > color1, regardless of the actual values of
  280. color0 and color1.
  281. Each alpha image data block is encoded as a sequence of 8 bytes, called
  282. (in order of increasing address):
  283. a0, a1, a2, a3, a4, a5, a6, a7
  284. The 8 bytes of the block are decoded into one 64-bit integer:
  285. alpha = a0 + 256 * (a1 + 256 * (a2 + 256 * (a3 + 256 * (a4 +
  286. 256 * (a5 + 256 * (a6 + 256 * a7))))))
  287. alpha is a 64-bit unsigned integer, from which a four-bit alpha value
  288. is extracted for a texel at location (x,y) in the block using:
  289. alpha(x,y) = bits[4*(4*y+x)+3..4*(4*y+x)+0]
  290. where bit 63 is the most significant and bit 0 is the least
  291. significant bit.
  292. The alpha component for a texel at location (x,y) in the block is
  293. given by alpha(x,y) / 15.
  294. COMPRESSED_RGBA_S3TC_DXT5_EXT: Each 4x4 block of texels consists of 64
  295. bits of compressed alpha image data followed by 64 bits of RGB image data.
  296. Each RGB image data block is encoded according to the
  297. COMPRESSED_RGB_S3TC_DXT1_EXT format, with the exception that the two code
  298. bits always use the non-transparent encodings. In other words, they are
  299. treated as though color0 > color1, regardless of the actual values of
  300. color0 and color1.
  301. Each alpha image data block is encoded as a sequence of 8 bytes, called
  302. (in order of increasing address):
  303. alpha0, alpha1, bits_0, bits_1, bits_2, bits_3, bits_4, bits_5
  304. The alpha0 and alpha1 are 8-bit unsigned bytes converted to alpha
  305. components by multiplying by 1/255.
  306. The 6 "bits" bytes of the block are decoded into one 48-bit integer:
  307. bits = bits_0 + 256 * (bits_1 + 256 * (bits_2 + 256 * (bits_3 +
  308. 256 * (bits_4 + 256 * bits_5))))
  309. bits is a 48-bit unsigned integer, from which a three-bit control code
  310. is extracted for a texel at location (x,y) in the block using:
  311. code(x,y) = bits[3*(4*y+x)+1..3*(4*y+x)+0]
  312. where bit 47 is the most significant and bit 0 is the least
  313. significant bit.
  314. The alpha component for a texel at location (x,y) in the block is
  315. given by:
  316. alpha0, code(x,y) == 0
  317. alpha1, code(x,y) == 1
  318. (6*alpha0 + 1*alpha1)/7, alpha0 > alpha1 and code(x,y) == 2
  319. (5*alpha0 + 2*alpha1)/7, alpha0 > alpha1 and code(x,y) == 3
  320. (4*alpha0 + 3*alpha1)/7, alpha0 > alpha1 and code(x,y) == 4
  321. (3*alpha0 + 4*alpha1)/7, alpha0 > alpha1 and code(x,y) == 5
  322. (2*alpha0 + 5*alpha1)/7, alpha0 > alpha1 and code(x,y) == 6
  323. (1*alpha0 + 6*alpha1)/7, alpha0 > alpha1 and code(x,y) == 7
  324. (4*alpha0 + 1*alpha1)/5, alpha0 <= alpha1 and code(x,y) == 2
  325. (3*alpha0 + 2*alpha1)/5, alpha0 <= alpha1 and code(x,y) == 3
  326. (2*alpha0 + 3*alpha1)/5, alpha0 <= alpha1 and code(x,y) == 4
  327. (1*alpha0 + 4*alpha1)/5, alpha0 <= alpha1 and code(x,y) == 5
  328. 0.0, alpha0 <= alpha1 and code(x,y) == 6
  329. 1.0, alpha0 <= alpha1 and code(x,y) == 7
  330. Revision History
  331. 1.1, 11/16/01 pbrown: Updated contact info, clarified where texels
  332. fall within a single block.
  333. 1.0, 07/07/00 prbrown1: Published final version agreed to by working
  334. group members.
  335. 0.9, 06/24/00 prbrown1: Documented that block-aligned TexSubImage calls
  336. do not modify existing texels outside the
  337. modified blocks. Added caveat to allow for a
  338. (0,0)-anchored TexSubImage operation of
  339. arbitrary size.
  340. 0.7, 04/11/00 prbrown1: Added issues on DXT1, DXT3, and DXT5 encodings
  341. where the MSDN documentation doesn't match what
  342. is really done. Added enum values from the
  343. extension registry.
  344. 0.4, 03/28/00 prbrown1: Updated to reflect final version of the
  345. ARB_texture_compression extension. Allowed
  346. block-aligned TexSubImage calls.
  347. 0.3, 03/07/00 prbrown1: Resolved issues pertaining to the format of RGB
  348. blocks in the DXT3 and DXT5 formats (they don't
  349. ever use the "transparent" encoding). Fixed
  350. decoding of DXT1 blocks. Pointed out issue of
  351. "transparent" texels in DXT1 encodings having
  352. different behaviors for RGB and RGBA internal
  353. formats.
  354. 0.2, 02/23/00 prbrown1: Minor revisions; added several issues.
  355. 0.11, 02/17/00 prbrown1: Slight modification to error semantics
  356. (INVALID_ENUM instead of INVALID_OPERATION).
  357. 0.1, 02/15/00 prbrown1: Initial revision.