• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /// @ref core
2 /// @file glm/detail/func_packing.hpp
3 ///
4 /// @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>
5 /// @see gtc_packing
6 ///
7 /// @defgroup core_func_packing Floating-Point Pack and Unpack Functions
8 /// @ingroup core
9 ///
10 /// These functions do not operate component-wise, rather as described in each case.
11 
12 #pragma once
13 
14 #include "type_vec2.hpp"
15 #include "type_vec4.hpp"
16 
17 namespace glm
18 {
19 	/// @addtogroup core_func_packing
20 	/// @{
21 
22 	/// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
23 	/// Then, the results are packed into the returned 32-bit unsigned integer.
24 	///
25 	/// The conversion for component c of v to fixed point is done as follows:
26 	/// packUnorm2x16: round(clamp(c, 0, +1) * 65535.0)
27 	///
28 	/// The first component of the vector will be written to the least significant bits of the output;
29 	/// the last component will be written to the most significant bits.
30 	///
31 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm2x16.xml">GLSL packUnorm2x16 man page</a>
32 	/// @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>
33 	GLM_FUNC_DECL uint packUnorm2x16(vec2 const & v);
34 
35 	/// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
36 	/// Then, the results are packed into the returned 32-bit unsigned integer.
37 	///
38 	/// The conversion for component c of v to fixed point is done as follows:
39 	/// packSnorm2x16: round(clamp(v, -1, +1) * 32767.0)
40 	///
41 	/// The first component of the vector will be written to the least significant bits of the output;
42 	/// the last component will be written to the most significant bits.
43 	///
44 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm2x16.xml">GLSL packSnorm2x16 man page</a>
45 	/// @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>
46 	GLM_FUNC_DECL uint packSnorm2x16(vec2 const & v);
47 
48 	/// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
49 	/// Then, the results are packed into the returned 32-bit unsigned integer.
50 	///
51 	/// The conversion for component c of v to fixed point is done as follows:
52 	/// packUnorm4x8:	round(clamp(c, 0, +1) * 255.0)
53 	///
54 	/// The first component of the vector will be written to the least significant bits of the output;
55 	/// the last component will be written to the most significant bits.
56 	///
57 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm4x8.xml">GLSL packUnorm4x8 man page</a>
58 	/// @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>
59 	GLM_FUNC_DECL uint packUnorm4x8(vec4 const & v);
60 
61 	/// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
62 	/// Then, the results are packed into the returned 32-bit unsigned integer.
63 	///
64 	/// The conversion for component c of v to fixed point is done as follows:
65 	/// packSnorm4x8:	round(clamp(c, -1, +1) * 127.0)
66 	///
67 	/// The first component of the vector will be written to the least significant bits of the output;
68 	/// the last component will be written to the most significant bits.
69 	///
70 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm4x8.xml">GLSL packSnorm4x8 man page</a>
71 	/// @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>
72 	GLM_FUNC_DECL uint packSnorm4x8(vec4 const & v);
73 
74 	/// 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.
75 	/// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
76 	///
77 	/// The conversion for unpacked fixed-point value f to floating point is done as follows:
78 	/// unpackUnorm2x16: f / 65535.0
79 	///
80 	/// The first component of the returned vector will be extracted from the least significant bits of the input;
81 	/// the last component will be extracted from the most significant bits.
82 	///
83 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm2x16.xml">GLSL unpackUnorm2x16 man page</a>
84 	/// @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>
85 	GLM_FUNC_DECL vec2 unpackUnorm2x16(uint p);
86 
87 	/// 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.
88 	/// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
89 	///
90 	/// The conversion for unpacked fixed-point value f to floating point is done as follows:
91 	/// unpackSnorm2x16: clamp(f / 32767.0, -1, +1)
92 	///
93 	/// The first component of the returned vector will be extracted from the least significant bits of the input;
94 	/// the last component will be extracted from the most significant bits.
95 	///
96 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm2x16.xml">GLSL unpackSnorm2x16 man page</a>
97 	/// @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>
98 	GLM_FUNC_DECL vec2 unpackSnorm2x16(uint p);
99 
100 	/// 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.
101 	/// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
102 	///
103 	/// The conversion for unpacked fixed-point value f to floating point is done as follows:
104 	/// unpackUnorm4x8: f / 255.0
105 	///
106 	/// The first component of the returned vector will be extracted from the least significant bits of the input;
107 	/// the last component will be extracted from the most significant bits.
108 	///
109 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm4x8.xml">GLSL unpackUnorm4x8 man page</a>
110 	/// @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>
111 	GLM_FUNC_DECL vec4 unpackUnorm4x8(uint p);
112 
113 	/// 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.
114 	/// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
115 	///
116 	/// The conversion for unpacked fixed-point value f to floating point is done as follows:
117 	/// unpackSnorm4x8: clamp(f / 127.0, -1, +1)
118 	///
119 	/// The first component of the returned vector will be extracted from the least significant bits of the input;
120 	/// the last component will be extracted from the most significant bits.
121 	///
122 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm4x8.xml">GLSL unpackSnorm4x8 man page</a>
123 	/// @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>
124 	GLM_FUNC_DECL vec4 unpackSnorm4x8(uint p);
125 
126 	/// Returns a double-precision value obtained by packing the components of v into a 64-bit value.
127 	/// If an IEEE 754 Inf or NaN is created, it will not signal, and the resulting floating point value is unspecified.
128 	/// Otherwise, the bit- level representation of v is preserved.
129 	/// The first vector component specifies the 32 least significant bits;
130 	/// the second component specifies the 32 most significant bits.
131 	///
132 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packDouble2x32.xml">GLSL packDouble2x32 man page</a>
133 	/// @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>
134 	GLM_FUNC_DECL double packDouble2x32(uvec2 const & v);
135 
136 	/// Returns a two-component unsigned integer vector representation of v.
137 	/// The bit-level representation of v is preserved.
138 	/// The first component of the vector contains the 32 least significant bits of the double;
139 	/// the second component consists the 32 most significant bits.
140 	///
141 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackDouble2x32.xml">GLSL unpackDouble2x32 man page</a>
142 	/// @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>
143 	GLM_FUNC_DECL uvec2 unpackDouble2x32(double v);
144 
145 	/// Returns an unsigned integer obtained by converting the components of a two-component floating-point vector
146 	/// to the 16-bit floating-point representation found in the OpenGL Specification,
147 	/// and then packing these two 16- bit integers into a 32-bit unsigned integer.
148 	/// The first vector component specifies the 16 least-significant bits of the result;
149 	/// the second component specifies the 16 most-significant bits.
150 	///
151 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packHalf2x16.xml">GLSL packHalf2x16 man page</a>
152 	/// @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>
153 	GLM_FUNC_DECL uint packHalf2x16(vec2 const & v);
154 
155 	/// Returns a two-component floating-point vector with components obtained by unpacking a 32-bit unsigned integer into a pair of 16-bit values,
156 	/// interpreting those values as 16-bit floating-point numbers according to the OpenGL Specification,
157 	/// and converting them to 32-bit floating-point values.
158 	/// The first component of the vector is obtained from the 16 least-significant bits of v;
159 	/// the second component is obtained from the 16 most-significant bits of v.
160 	///
161 	/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackHalf2x16.xml">GLSL unpackHalf2x16 man page</a>
162 	/// @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>
163 	GLM_FUNC_DECL vec2 unpackHalf2x16(uint v);
164 
165 	/// @}
166 }//namespace glm
167 
168 #include "func_packing.inl"
169