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