1 /////////////////////////////////////////////////////////////////////////////////// 2 /// OpenGL Mathematics (glm.g-truc.net) 3 /// 4 /// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net) 5 /// Permission is hereby granted, free of charge, to any person obtaining a copy 6 /// of this software and associated documentation files (the "Software"), to deal 7 /// in the Software without restriction, including without limitation the rights 8 /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 /// copies of the Software, and to permit persons to whom the Software is 10 /// furnished to do so, subject to the following conditions: 11 /// 12 /// The above copyright notice and this permission notice shall be included in 13 /// all copies or substantial portions of the Software. 14 /// 15 /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 /// THE SOFTWARE. 22 /// 23 /// @ref core 24 /// @file glm/core/func_packing.hpp 25 /// @date 2010-03-17 / 2011-06-15 26 /// @author Christophe Riccio 27 /// 28 /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a> 29 /// 30 /// @defgroup core_func_packing Floating-Point Pack and Unpack Functions 31 /// @ingroup core 32 /// 33 /// These functions do not operate component-wise, rather as described in each case. 34 /////////////////////////////////////////////////////////////////////////////////// 35 36 #ifndef GLM_CORE_func_packing 37 #define GLM_CORE_func_packing 38 39 #include "type_vec2.hpp" 40 #include "type_vec4.hpp" 41 42 namespace glm 43 { 44 /// @addtogroup core_func_packing 45 /// @{ 46 47 /// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values. 48 /// Then, the results are packed into the returned 32-bit unsigned integer. 49 /// 50 /// The conversion for component c of v to fixed point is done as follows: 51 /// packUnorm2x16: round(clamp(c, 0, +1) * 65535.0) 52 /// 53 /// The first component of the vector will be written to the least significant bits of the output; 54 /// the last component will be written to the most significant bits. 55 /// 56 /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm2x16.xml">GLSL packUnorm2x16 man page</a> 57 /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a> 58 GLM_FUNC_DECL uint packUnorm2x16(vec2 const & v); 59 60 /// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values. 61 /// Then, the results are packed into the returned 32-bit unsigned integer. 62 /// 63 /// The conversion for component c of v to fixed point is done as follows: 64 /// packSnorm2x16: round(clamp(v, -1, +1) * 32767.0) 65 /// 66 /// The first component of the vector will be written to the least significant bits of the output; 67 /// the last component will be written to the most significant bits. 68 /// 69 /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm2x16.xml">GLSL packSnorm2x16 man page</a> 70 /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a> 71 GLM_FUNC_DECL uint packSnorm2x16(vec2 const & v); 72 73 /// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values. 74 /// Then, the results are packed into the returned 32-bit unsigned integer. 75 /// 76 /// The conversion for component c of v to fixed point is done as follows: 77 /// packUnorm4x8: round(clamp(c, 0, +1) * 255.0) 78 /// 79 /// The first component of the vector will be written to the least significant bits of the output; 80 /// the last component will be written to the most significant bits. 81 /// 82 /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm4x8.xml">GLSL packUnorm4x8 man page</a> 83 /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a> 84 GLM_FUNC_DECL uint packUnorm4x8(vec4 const & v); 85 86 /// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values. 87 /// Then, the results are packed into the returned 32-bit unsigned integer. 88 /// 89 /// The conversion for component c of v to fixed point is done as follows: 90 /// packSnorm4x8: round(clamp(c, -1, +1) * 127.0) 91 /// 92 /// The first component of the vector will be written to the least significant bits of the output; 93 /// the last component will be written to the most significant bits. 94 /// 95 /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm4x8.xml">GLSL packSnorm4x8 man page</a> 96 /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a> 97 GLM_FUNC_DECL uint packSnorm4x8(vec4 const & v); 98 99 /// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers. 100 /// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector. 101 /// 102 /// The conversion for unpacked fixed-point value f to floating point is done as follows: 103 /// unpackUnorm2x16: f / 65535.0 104 /// 105 /// The first component of the returned vector will be extracted from the least significant bits of the input; 106 /// the last component will be extracted from the most significant bits. 107 /// 108 /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm2x16.xml">GLSL unpackUnorm2x16 man page</a> 109 /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a> 110 GLM_FUNC_DECL vec2 unpackUnorm2x16(uint const & p); 111 112 /// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers. 113 /// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector. 114 /// 115 /// The conversion for unpacked fixed-point value f to floating point is done as follows: 116 /// unpackSnorm2x16: clamp(f / 32767.0, -1, +1) 117 /// 118 /// The first component of the returned vector will be extracted from the least significant bits of the input; 119 /// the last component will be extracted from the most significant bits. 120 /// 121 /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm2x16.xml">GLSL unpackSnorm2x16 man page</a> 122 /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a> 123 GLM_FUNC_DECL vec2 unpackSnorm2x16(uint const & p); 124 125 /// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers. 126 /// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector. 127 /// 128 /// The conversion for unpacked fixed-point value f to floating point is done as follows: 129 /// unpackUnorm4x8: f / 255.0 130 /// 131 /// The first component of the returned vector will be extracted from the least significant bits of the input; 132 /// the last component will be extracted from the most significant bits. 133 /// 134 /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm4x8.xml">GLSL unpackUnorm4x8 man page</a> 135 /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a> 136 GLM_FUNC_DECL vec4 unpackUnorm4x8(uint const & p); 137 138 /// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers. 139 /// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector. 140 /// 141 /// The conversion for unpacked fixed-point value f to floating point is done as follows: 142 /// unpackSnorm4x8: clamp(f / 127.0, -1, +1) 143 /// 144 /// The first component of the returned vector will be extracted from the least significant bits of the input; 145 /// the last component will be extracted from the most significant bits. 146 /// 147 /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm4x8.xml">GLSL unpackSnorm4x8 man page</a> 148 /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a> 149 GLM_FUNC_DECL vec4 unpackSnorm4x8(uint const & p); 150 151 /// Returns a double-precision value obtained by packing the components of v into a 64-bit value. 152 /// If an IEEE 754 Inf or NaN is created, it will not signal, and the resulting floating point value is unspecified. 153 /// Otherwise, the bit- level representation of v is preserved. 154 /// The first vector component specifies the 32 least significant bits; 155 /// the second component specifies the 32 most significant bits. 156 /// 157 /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packDouble2x32.xml">GLSL packDouble2x32 man page</a> 158 /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a> 159 GLM_FUNC_DECL double packDouble2x32(uvec2 const & v); 160 161 /// Returns a two-component unsigned integer vector representation of v. 162 /// The bit-level representation of v is preserved. 163 /// The first component of the vector contains the 32 least significant bits of the double; 164 /// the second component consists the 32 most significant bits. 165 /// 166 /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackDouble2x32.xml">GLSL unpackDouble2x32 man page</a> 167 /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a> 168 GLM_FUNC_DECL uvec2 unpackDouble2x32(double const & v); 169 170 /// Returns an unsigned integer obtained by converting the components of a two-component floating-point vector 171 /// to the 16-bit floating-point representation found in the OpenGL Specification, 172 /// and then packing these two 16- bit integers into a 32-bit unsigned integer. 173 /// The first vector component specifies the 16 least-significant bits of the result; 174 /// the second component specifies the 16 most-significant bits. 175 /// 176 /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packHalf2x16.xml">GLSL packHalf2x16 man page</a> 177 /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a> 178 GLM_FUNC_DECL uint packHalf2x16(vec2 const & v); 179 180 /// Returns a two-component floating-point vector with components obtained by unpacking a 32-bit unsigned integer into a pair of 16-bit values, 181 /// interpreting those values as 16-bit floating-point numbers according to the OpenGL Specification, 182 /// and converting them to 32-bit floating-point values. 183 /// The first component of the vector is obtained from the 16 least-significant bits of v; 184 /// the second component is obtained from the 16 most-significant bits of v. 185 /// 186 /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackHalf2x16.xml">GLSL unpackHalf2x16 man page</a> 187 /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a> 188 GLM_FUNC_DECL vec2 unpackHalf2x16(uint const & v); 189 190 /// @} 191 }//namespace glm 192 193 #include "func_packing.inl" 194 195 #endif//GLM_CORE_func_packing 196