the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 995 lines 35 kB view raw
1//------------------------------------------------------------------------------------- 2// DirectXPackedVector.h -- SIMD C++ Math library 3// 4// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 5// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 6// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 7// PARTICULAR PURPOSE. 8// 9// Copyright (c) Microsoft Corporation. All rights reserved. 10//------------------------------------------------------------------------------------- 11 12#ifdef _MSC_VER 13#pragma once 14#endif 15 16#include "DirectXMath.h" 17 18namespace DirectX 19{ 20 21namespace PackedVector 22{ 23 24#ifdef _XM_BIGENDIAN_ 25#pragma bitfield_order(push) 26#pragma bitfield_order(lsb_to_msb) 27#endif 28 29#pragma warning(push) 30#pragma warning(disable:4201 4365 4324) 31 32//------------------------------------------------------------------------------ 33// ARGB Color; 8-8-8-8 bit unsigned normalized integer components packed into 34// a 32 bit integer. The normalized color is packed into 32 bits using 8 bit 35// unsigned, normalized integers for the alpha, red, green, and blue components. 36// The alpha component is stored in the most significant bits and the blue 37// component in the least significant bits (A8R8G8B8): 38// [32] aaaaaaaa rrrrrrrr gggggggg bbbbbbbb [0] 39struct XMCOLOR 40{ 41 union 42 { 43 struct 44 { 45 uint8_t b; // Blue: 0/255 to 255/255 46 uint8_t g; // Green: 0/255 to 255/255 47 uint8_t r; // Red: 0/255 to 255/255 48 uint8_t a; // Alpha: 0/255 to 255/255 49 }; 50 uint32_t c; 51 }; 52 53 XMCOLOR() {} 54 XMCOLOR(uint32_t Color) : c(Color) {} 55 XMCOLOR(float _r, float _g, float _b, float _a); 56 explicit XMCOLOR(_In_reads_(4) const float *pArray); 57 58 operator uint32_t () const { return c; } 59 60 XMCOLOR& operator= (const XMCOLOR& Color) { c = Color.c; return *this; } 61 XMCOLOR& operator= (const uint32_t Color) { c = Color; return *this; } 62}; 63 64//------------------------------------------------------------------------------ 65// 16 bit floating point number consisting of a sign bit, a 5 bit biased 66// exponent, and a 10 bit mantissa 67typedef uint16_t HALF; 68 69//------------------------------------------------------------------------------ 70// 2D Vector; 16 bit floating point components 71struct XMHALF2 72{ 73 union 74 { 75 struct 76 { 77 HALF x; 78 HALF y; 79 }; 80 uint32_t v; 81 }; 82 83 XMHALF2() {} 84 explicit XMHALF2(uint32_t Packed) : v(Packed) {} 85 XMHALF2(HALF _x, HALF _y) : x(_x), y(_y) {} 86 explicit XMHALF2(_In_reads_(2) const HALF *pArray) : x(pArray[0]), y(pArray[1]) {} 87 XMHALF2(float _x, float _y); 88 explicit XMHALF2(_In_reads_(2) const float *pArray); 89 90 XMHALF2& operator= (const XMHALF2& Half2) { x = Half2.x; y = Half2.y; return *this; } 91 XMHALF2& operator= (uint32_t Packed) { v = Packed; return *this; } 92}; 93 94//------------------------------------------------------------------------------ 95// 2D Vector; 16 bit signed normalized integer components 96struct XMSHORTN2 97{ 98 union 99 { 100 struct 101 { 102 int16_t x; 103 int16_t y; 104 }; 105 uint32_t v; 106 }; 107 108 XMSHORTN2() {} 109 explicit XMSHORTN2(uint32_t Packed) : v(Packed) {} 110 XMSHORTN2(int16_t _x, int16_t _y) : x(_x), y(_y) {} 111 explicit XMSHORTN2(_In_reads_(2) const int16_t *pArray) : x(pArray[0]), y(pArray[1]) {} 112 XMSHORTN2(float _x, float _y); 113 explicit XMSHORTN2(_In_reads_(2) const float *pArray); 114 115 XMSHORTN2& operator= (const XMSHORTN2& ShortN2) { x = ShortN2.x; y = ShortN2.y; return *this; } 116 XMSHORTN2& operator= (uint32_t Packed) { v = Packed; return *this; } 117}; 118 119// 2D Vector; 16 bit signed integer components 120struct XMSHORT2 121{ 122 union 123 { 124 struct 125 { 126 int16_t x; 127 int16_t y; 128 }; 129 uint32_t v; 130 }; 131 132 XMSHORT2() {} 133 explicit XMSHORT2(uint32_t Packed) : v(Packed) {} 134 XMSHORT2(int16_t _x, int16_t _y) : x(_x), y(_y) {} 135 explicit XMSHORT2(_In_reads_(2) const int16_t *pArray) : x(pArray[0]), y(pArray[1]) {} 136 XMSHORT2(float _x, float _y); 137 explicit XMSHORT2(_In_reads_(2) const float *pArray); 138 139 XMSHORT2& operator= (const XMSHORT2& Short2) { x = Short2.x; y = Short2.y; return *this; } 140 XMSHORT2& operator= (uint32_t Packed) { v = Packed; return *this; } 141}; 142 143// 2D Vector; 16 bit unsigned normalized integer components 144struct XMUSHORTN2 145{ 146 union 147 { 148 struct 149 { 150 uint16_t x; 151 uint16_t y; 152 }; 153 uint32_t v; 154 }; 155 156 XMUSHORTN2() {} 157 explicit XMUSHORTN2(uint32_t Packed) : v(Packed) {} 158 XMUSHORTN2(uint16_t _x, uint16_t _y) : x(_x), y(_y) {} 159 explicit XMUSHORTN2(_In_reads_(2) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]) {} 160 XMUSHORTN2(float _x, float _y); 161 explicit XMUSHORTN2(_In_reads_(2) const float *pArray); 162 163 XMUSHORTN2& operator= (const XMUSHORTN2& UShortN2) { x = UShortN2.x; y = UShortN2.y; return *this; } 164 XMUSHORTN2& operator= (uint32_t Packed) { v = Packed; return *this; } 165}; 166 167// 2D Vector; 16 bit unsigned integer components 168struct XMUSHORT2 169{ 170 union 171 { 172 struct 173 { 174 uint16_t x; 175 uint16_t y; 176 }; 177 uint32_t v; 178 }; 179 180 XMUSHORT2() {} 181 explicit XMUSHORT2(uint32_t Packed) : v(Packed) {} 182 XMUSHORT2(uint16_t _x, uint16_t _y) : x(_x), y(_y) {} 183 explicit XMUSHORT2(_In_reads_(2) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]) {} 184 XMUSHORT2(float _x, float _y); 185 explicit XMUSHORT2(_In_reads_(2) const float *pArray); 186 187 XMUSHORT2& operator= (const XMUSHORT2& UShort2) { x = UShort2.x; y = UShort2.y; return *this; } 188 XMUSHORT2& operator= (uint32_t Packed) { v = Packed; return *this; } 189}; 190 191//------------------------------------------------------------------------------ 192// 2D Vector; 8 bit signed normalized integer components 193struct XMBYTEN2 194{ 195 union 196 { 197 struct 198 { 199 int8_t x; 200 int8_t y; 201 }; 202 uint16_t v; 203 }; 204 205 XMBYTEN2() {} 206 explicit XMBYTEN2(uint16_t Packed) : v(Packed) {} 207 XMBYTEN2(int8_t _x, int8_t _y) : x(_x), y(_y) {} 208 explicit XMBYTEN2(_In_reads_(2) const int8_t *pArray) : x(pArray[0]), y(pArray[1]) {} 209 XMBYTEN2(float _x, float _y); 210 explicit XMBYTEN2(_In_reads_(2) const float *pArray); 211 212 XMBYTEN2& operator= (const XMBYTEN2& ByteN2) { x = ByteN2.x; y = ByteN2.y; return *this; } 213 XMBYTEN2& operator= (uint16_t Packed) { v = Packed; return *this; } 214}; 215 216// 2D Vector; 8 bit signed integer components 217struct XMBYTE2 218{ 219 union 220 { 221 struct 222 { 223 int8_t x; 224 int8_t y; 225 }; 226 uint16_t v; 227 }; 228 229 XMBYTE2() {} 230 explicit XMBYTE2(uint16_t Packed) : v(Packed) {} 231 XMBYTE2(int8_t _x, int8_t _y) : x(_x), y(_y) {} 232 explicit XMBYTE2(_In_reads_(2) const int8_t *pArray) : x(pArray[0]), y(pArray[1]) {} 233 XMBYTE2(float _x, float _y); 234 explicit XMBYTE2(_In_reads_(2) const float *pArray); 235 236 XMBYTE2& operator= (const XMBYTE2& Byte2) { x = Byte2.x; y = Byte2.y; return *this; } 237 XMBYTE2& operator= (uint16_t Packed) { v = Packed; return *this; } 238}; 239 240// 2D Vector; 8 bit unsigned normalized integer components 241struct XMUBYTEN2 242{ 243 union 244 { 245 struct 246 { 247 uint8_t x; 248 uint8_t y; 249 }; 250 uint16_t v; 251 }; 252 253 XMUBYTEN2() {} 254 explicit XMUBYTEN2(uint16_t Packed) : v(Packed) {} 255 XMUBYTEN2(uint8_t _x, uint8_t _y) : x(_x), y(_y) {} 256 explicit XMUBYTEN2(_In_reads_(2) const uint8_t *pArray) : x(pArray[0]), y(pArray[1]) {} 257 XMUBYTEN2(float _x, float _y); 258 explicit XMUBYTEN2(_In_reads_(2) const float *pArray); 259 260 XMUBYTEN2& operator= (const XMUBYTEN2& UByteN2) { x = UByteN2.x; y = UByteN2.y; return *this; } 261 XMUBYTEN2& operator= (uint16_t Packed) { v = Packed; return *this; } 262}; 263 264// 2D Vector; 8 bit unsigned integer components 265struct XMUBYTE2 266{ 267 union 268 { 269 struct 270 { 271 uint8_t x; 272 uint8_t y; 273 }; 274 uint16_t v; 275 }; 276 277 XMUBYTE2() {} 278 explicit XMUBYTE2(uint16_t Packed) : v(Packed) {} 279 XMUBYTE2(uint8_t _x, uint8_t _y) : x(_x), y(_y) {} 280 explicit XMUBYTE2(_In_reads_(2) const uint8_t *pArray) : x(pArray[0]), y(pArray[1]) {} 281 XMUBYTE2(float _x, float _y); 282 explicit XMUBYTE2(_In_reads_(2) const float *pArray); 283 284 XMUBYTE2& operator= (const XMUBYTE2& UByte2) { x = UByte2.x; y = UByte2.y; return *this; } 285 XMUBYTE2& operator= (uint16_t Packed) { v = Packed; return *this; } 286}; 287 288//------------------------------------------------------------------------------ 289// 3D vector: 5/6/5 unsigned integer components 290struct XMU565 291{ 292 union 293 { 294 struct 295 { 296 uint16_t x : 5; // 0 to 31 297 uint16_t y : 6; // 0 to 63 298 uint16_t z : 5; // 0 to 31 299 }; 300 uint16_t v; 301 }; 302 303 XMU565() {} 304 explicit XMU565(uint16_t Packed) : v(Packed) {} 305 XMU565(uint8_t _x, uint8_t _y, uint8_t _z) : x(_x), y(_y), z(_z) {} 306 explicit XMU565(_In_reads_(3) const int8_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]) {} 307 XMU565(float _x, float _y, float _z); 308 explicit XMU565(_In_reads_(3) const float *pArray); 309 310 operator uint16_t () const { return v; } 311 312 XMU565& operator= (const XMU565& U565) { v = U565.v; return *this; } 313 XMU565& operator= (uint16_t Packed) { v = Packed; return *this; } 314}; 315 316//------------------------------------------------------------------------------ 317// 3D vector: 11/11/10 floating-point components 318// The 3D vector is packed into 32 bits as follows: a 5-bit biased exponent 319// and 6-bit mantissa for x component, a 5-bit biased exponent and 320// 6-bit mantissa for y component, a 5-bit biased exponent and a 5-bit 321// mantissa for z. The z component is stored in the most significant bits 322// and the x component in the least significant bits. No sign bits so 323// all partial-precision numbers are positive. 324// (Z10Y11X11): [32] ZZZZZzzz zzzYYYYY yyyyyyXX XXXxxxxx [0] 325struct XMFLOAT3PK 326{ 327 union 328 { 329 struct 330 { 331 uint32_t xm : 6; // x-mantissa 332 uint32_t xe : 5; // x-exponent 333 uint32_t ym : 6; // y-mantissa 334 uint32_t ye : 5; // y-exponent 335 uint32_t zm : 5; // z-mantissa 336 uint32_t ze : 5; // z-exponent 337 }; 338 uint32_t v; 339 }; 340 341 XMFLOAT3PK() {} 342 explicit XMFLOAT3PK(uint32_t Packed) : v(Packed) {} 343 XMFLOAT3PK(float _x, float _y, float _z); 344 explicit XMFLOAT3PK(_In_reads_(3) const float *pArray); 345 346 operator uint32_t () const { return v; } 347 348 XMFLOAT3PK& operator= (const XMFLOAT3PK& float3pk) { v = float3pk.v; return *this; } 349 XMFLOAT3PK& operator= (uint32_t Packed) { v = Packed; return *this; } 350}; 351 352//------------------------------------------------------------------------------ 353// 3D vector: 9/9/9 floating-point components with shared 5-bit exponent 354// The 3D vector is packed into 32 bits as follows: a 5-bit biased exponent 355// with 9-bit mantissa for the x, y, and z component. The shared exponent 356// is stored in the most significant bits and the x component mantissa is in 357// the least significant bits. No sign bits so all partial-precision numbers 358// are positive. 359// (E5Z9Y9X9): [32] EEEEEzzz zzzzzzyy yyyyyyyx xxxxxxxx [0] 360struct XMFLOAT3SE 361{ 362 union 363 { 364 struct 365 { 366 uint32_t xm : 9; // x-mantissa 367 uint32_t ym : 9; // y-mantissa 368 uint32_t zm : 9; // z-mantissa 369 uint32_t e : 5; // shared exponent 370 }; 371 uint32_t v; 372 }; 373 374 XMFLOAT3SE() {} 375 explicit XMFLOAT3SE(uint32_t Packed) : v(Packed) {} 376 XMFLOAT3SE(float _x, float _y, float _z); 377 explicit XMFLOAT3SE(_In_reads_(3) const float *pArray); 378 379 operator uint32_t () const { return v; } 380 381 XMFLOAT3SE& operator= (const XMFLOAT3SE& float3se) { v = float3se.v; return *this; } 382 XMFLOAT3SE& operator= (uint32_t Packed) { v = Packed; return *this; } 383}; 384 385//------------------------------------------------------------------------------ 386// 4D Vector; 16 bit floating point components 387struct XMHALF4 388{ 389 union 390 { 391 struct 392 { 393 HALF x; 394 HALF y; 395 HALF z; 396 HALF w; 397 }; 398 uint64_t v; 399 }; 400 401 XMHALF4() {} 402 explicit XMHALF4(uint64_t Packed) : v(Packed) {} 403 XMHALF4(HALF _x, HALF _y, HALF _z, HALF _w) : x(_x), y(_y), z(_z), w(_w) {} 404 explicit XMHALF4(_In_reads_(4) const HALF *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {} 405 XMHALF4(float _x, float _y, float _z, float _w); 406 explicit XMHALF4(_In_reads_(4) const float *pArray); 407 408 XMHALF4& operator= (const XMHALF4& Half4) { x = Half4.x; y = Half4.y; z = Half4.z; w = Half4.w; return *this; } 409 XMHALF4& operator= (uint64_t Packed) { v = Packed; return *this; } 410}; 411 412//------------------------------------------------------------------------------ 413// 4D Vector; 16 bit signed normalized integer components 414struct XMSHORTN4 415{ 416 union 417 { 418 struct 419 { 420 int16_t x; 421 int16_t y; 422 int16_t z; 423 int16_t w; 424 }; 425 uint64_t v; 426 }; 427 428 XMSHORTN4() {} 429 explicit XMSHORTN4(uint64_t Packed) : v(Packed) {} 430 XMSHORTN4(int16_t _x, int16_t _y, int16_t _z, int16_t _w) : x(_x), y(_y), z(_z), w(_w) {} 431 explicit XMSHORTN4(_In_reads_(4) const int16_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {} 432 XMSHORTN4(float _x, float _y, float _z, float _w); 433 explicit XMSHORTN4(_In_reads_(4) const float *pArray); 434 435 XMSHORTN4& operator= (const XMSHORTN4& ShortN4) { x = ShortN4.x; y = ShortN4.y; z = ShortN4.z; w = ShortN4.w; return *this; } 436 XMSHORTN4& operator= (uint64_t Packed) { v = Packed; return *this; } 437}; 438 439// 4D Vector; 16 bit signed integer components 440struct XMSHORT4 441{ 442 union 443 { 444 struct 445 { 446 int16_t x; 447 int16_t y; 448 int16_t z; 449 int16_t w; 450 }; 451 uint64_t v; 452 }; 453 454 XMSHORT4() {} 455 explicit XMSHORT4(uint64_t Packed) : v(Packed) {} 456 XMSHORT4(int16_t _x, int16_t _y, int16_t _z, int16_t _w) : x(_x), y(_y), z(_z), w(_w) {} 457 explicit XMSHORT4(_In_reads_(4) const int16_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {} 458 XMSHORT4(float _x, float _y, float _z, float _w); 459 explicit XMSHORT4(_In_reads_(4) const float *pArray); 460 461 XMSHORT4& operator= (const XMSHORT4& Short4) { x = Short4.x; y = Short4.y; z = Short4.z; w = Short4.w; return *this; } 462 XMSHORT4& operator= (uint64_t Packed) { v = Packed; return *this; } 463}; 464 465// 4D Vector; 16 bit unsigned normalized integer components 466struct XMUSHORTN4 467{ 468 union 469 { 470 struct 471 { 472 uint16_t x; 473 uint16_t y; 474 uint16_t z; 475 uint16_t w; 476 }; 477 uint64_t v; 478 }; 479 480 XMUSHORTN4() {} 481 explicit XMUSHORTN4(uint64_t Packed) : v(Packed) {} 482 XMUSHORTN4(uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _w) : x(_x), y(_y), z(_z), w(_w) {} 483 explicit XMUSHORTN4(_In_reads_(4) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {} 484 XMUSHORTN4(float _x, float _y, float _z, float _w); 485 explicit XMUSHORTN4(_In_reads_(4) const float *pArray); 486 487 XMUSHORTN4& operator= (const XMUSHORTN4& UShortN4) { x = UShortN4.x; y = UShortN4.y; z = UShortN4.z; w = UShortN4.w; return *this; } 488 XMUSHORTN4& operator= (uint64_t Packed) { v = Packed; return *this; } 489}; 490 491// 4D Vector; 16 bit unsigned integer components 492struct XMUSHORT4 493{ 494 union 495 { 496 struct 497 { 498 uint16_t x; 499 uint16_t y; 500 uint16_t z; 501 uint16_t w; 502 }; 503 uint64_t v; 504 }; 505 506 XMUSHORT4() {} 507 explicit XMUSHORT4(uint64_t Packed) : v(Packed) {} 508 XMUSHORT4(uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _w) : x(_x), y(_y), z(_z), w(_w) {} 509 explicit XMUSHORT4(_In_reads_(4) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {} 510 XMUSHORT4(float _x, float _y, float _z, float _w); 511 explicit XMUSHORT4(_In_reads_(4) const float *pArray); 512 513 XMUSHORT4& operator= (const XMUSHORT4& UShort4) { x = UShort4.x; y = UShort4.y; z = UShort4.z; w = UShort4.w; return *this; } 514 XMUSHORT4& operator= (uint32_t Packed) { v = Packed; return *this; } 515}; 516 517//------------------------------------------------------------------------------ 518// 4D Vector; 10-10-10-2 bit normalized components packed into a 32 bit integer 519// The normalized 4D Vector is packed into 32 bits as follows: a 2 bit unsigned, 520// normalized integer for the w component and 10 bit signed, normalized 521// integers for the z, y, and x components. The w component is stored in the 522// most significant bits and the x component in the least significant bits 523// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0] 524struct XMXDECN4 525{ 526 union 527 { 528 struct 529 { 530 int32_t x : 10; // -511/511 to 511/511 531 int32_t y : 10; // -511/511 to 511/511 532 int32_t z : 10; // -511/511 to 511/511 533 uint32_t w : 2; // 0/3 to 3/3 534 }; 535 uint32_t v; 536 }; 537 538 XMXDECN4() {} 539 explicit XMXDECN4(uint32_t Packed) : v(Packed) {} 540 XMXDECN4(float _x, float _y, float _z, float _w); 541 explicit XMXDECN4(_In_reads_(4) const float *pArray); 542 543 operator uint32_t () const { return v; } 544 545 XMXDECN4& operator= (const XMXDECN4& XDecN4) { v = XDecN4.v; return *this; } 546 XMXDECN4& operator= (uint32_t Packed) { v = Packed; return *this; } 547}; 548 549// 4D Vector; 10-10-10-2 bit components packed into a 32 bit integer 550// The normalized 4D Vector is packed into 32 bits as follows: a 2 bit unsigned 551// integer for the w component and 10 bit signed integers for the 552// z, y, and x components. The w component is stored in the 553// most significant bits and the x component in the least significant bits 554// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0] 555struct XMXDEC4 556{ 557 union 558 { 559 struct 560 { 561 int32_t x : 10; // -511 to 511 562 int32_t y : 10; // -511 to 511 563 int32_t z : 10; // -511 to 511 564 uint32_t w : 2; // 0 to 3 565 }; 566 uint32_t v; 567 }; 568 569 XMXDEC4() {} 570 explicit XMXDEC4(uint32_t Packed) : v(Packed) {} 571 XMXDEC4(float _x, float _y, float _z, float _w); 572 explicit XMXDEC4(_In_reads_(4) const float *pArray); 573 574 operator uint32_t () const { return v; } 575 576 XMXDEC4& operator= (const XMXDEC4& XDec4) { v = XDec4.v; return *this; } 577 XMXDEC4& operator= (uint32_t Packed) { v = Packed; return *this; } 578}; 579 580// 4D Vector; 10-10-10-2 bit normalized components packed into a 32 bit integer 581// The normalized 4D Vector is packed into 32 bits as follows: a 2 bit signed, 582// normalized integer for the w component and 10 bit signed, normalized 583// integers for the z, y, and x components. The w component is stored in the 584// most significant bits and the x component in the least significant bits 585// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0] 586struct XMDECN4 587{ 588 union 589 { 590 struct 591 { 592 int32_t x : 10; // -511/511 to 511/511 593 int32_t y : 10; // -511/511 to 511/511 594 int32_t z : 10; // -511/511 to 511/511 595 int32_t w : 2; // -1/1 to 1/1 596 }; 597 uint32_t v; 598 }; 599 600 XMDECN4() {} 601 explicit XMDECN4(uint32_t Packed) : v(Packed) {} 602 XMDECN4(float _x, float _y, float _z, float _w); 603 explicit XMDECN4(_In_reads_(4) const float *pArray); 604 605 operator uint32_t () const { return v; } 606 607 XMDECN4& operator= (const XMDECN4& DecN4) { v = DecN4.v; return *this; } 608 XMDECN4& operator= (uint32_t Packed) { v = Packed; return *this; } 609}; 610 611// 4D Vector; 10-10-10-2 bit components packed into a 32 bit integer 612// The 4D Vector is packed into 32 bits as follows: a 2 bit signed, 613// integer for the w component and 10 bit signed integers for the 614// z, y, and x components. The w component is stored in the 615// most significant bits and the x component in the least significant bits 616// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0] 617struct XMDEC4 618{ 619 union 620 { 621 struct 622 { 623 int32_t x : 10; // -511 to 511 624 int32_t y : 10; // -511 to 511 625 int32_t z : 10; // -511 to 511 626 int32_t w : 2; // -1 to 1 627 }; 628 uint32_t v; 629 }; 630 631 XMDEC4() {} 632 explicit XMDEC4(uint32_t Packed) : v(Packed) {} 633 XMDEC4(float _x, float _y, float _z, float _w); 634 explicit XMDEC4(_In_reads_(4) const float *pArray); 635 636 operator uint32_t () const { return v; } 637 638 XMDEC4& operator= (const XMDEC4& Dec4) { v = Dec4.v; return *this; } 639 XMDEC4& operator= (uint32_t Packed) { v = Packed; return *this; } 640}; 641 642// 4D Vector; 10-10-10-2 bit normalized components packed into a 32 bit integer 643// The normalized 4D Vector is packed into 32 bits as follows: a 2 bit unsigned, 644// normalized integer for the w component and 10 bit unsigned, normalized 645// integers for the z, y, and x components. The w component is stored in the 646// most significant bits and the x component in the least significant bits 647// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0] 648struct XMUDECN4 649{ 650 union 651 { 652 struct 653 { 654 uint32_t x : 10; // 0/1023 to 1023/1023 655 uint32_t y : 10; // 0/1023 to 1023/1023 656 uint32_t z : 10; // 0/1023 to 1023/1023 657 uint32_t w : 2; // 0/3 to 3/3 658 }; 659 uint32_t v; 660 }; 661 662 XMUDECN4() {} 663 explicit XMUDECN4(uint32_t Packed) : v(Packed) {} 664 XMUDECN4(float _x, float _y, float _z, float _w); 665 explicit XMUDECN4(_In_reads_(4) const float *pArray); 666 667 operator uint32_t () const { return v; } 668 669 XMUDECN4& operator= (const XMUDECN4& UDecN4) { v = UDecN4.v; return *this; } 670 XMUDECN4& operator= (uint32_t Packed) { v = Packed; return *this; } 671}; 672 673// 4D Vector; 10-10-10-2 bit components packed into a 32 bit integer 674// The 4D Vector is packed into 32 bits as follows: a 2 bit unsigned, 675// integer for the w component and 10 bit unsigned integers 676// for the z, y, and x components. The w component is stored in the 677// most significant bits and the x component in the least significant bits 678// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0] 679struct XMUDEC4 680{ 681 union 682 { 683 struct 684 { 685 uint32_t x : 10; // 0 to 1023 686 uint32_t y : 10; // 0 to 1023 687 uint32_t z : 10; // 0 to 1023 688 uint32_t w : 2; // 0 to 3 689 }; 690 uint32_t v; 691 }; 692 693 XMUDEC4() {} 694 explicit XMUDEC4(uint32_t Packed) : v(Packed) {} 695 XMUDEC4(float _x, float _y, float _z, float _w); 696 explicit XMUDEC4(_In_reads_(4) const float *pArray); 697 698 operator uint32_t () const { return v; } 699 700 XMUDEC4& operator= (const XMUDEC4& UDec4) { v = UDec4.v; return *this; } 701 XMUDEC4& operator= (uint32_t Packed) { v = Packed; return *this; } 702}; 703 704//------------------------------------------------------------------------------ 705// 4D Vector; 8 bit signed normalized integer components 706struct XMBYTEN4 707{ 708 union 709 { 710 struct 711 { 712 int8_t x; 713 int8_t y; 714 int8_t z; 715 int8_t w; 716 }; 717 uint32_t v; 718 }; 719 720 XMBYTEN4() {} 721 XMBYTEN4(int8_t _x, int8_t _y, int8_t _z, int8_t _w) : x(_x), y(_y), z(_z), w(_w) {} 722 explicit XMBYTEN4(uint32_t Packed) : v(Packed) {} 723 explicit XMBYTEN4(_In_reads_(4) const int8_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {} 724 XMBYTEN4(float _x, float _y, float _z, float _w); 725 explicit XMBYTEN4(_In_reads_(4) const float *pArray); 726 727 XMBYTEN4& operator= (const XMBYTEN4& ByteN4) { x = ByteN4.x; y = ByteN4.y; z = ByteN4.z; w = ByteN4.w; return *this; } 728 XMBYTEN4& operator= (uint32_t Packed) { v = Packed; return *this; } 729}; 730 731// 4D Vector; 8 bit signed integer components 732struct XMBYTE4 733{ 734 union 735 { 736 struct 737 { 738 int8_t x; 739 int8_t y; 740 int8_t z; 741 int8_t w; 742 }; 743 uint32_t v; 744 }; 745 746 XMBYTE4() {} 747 XMBYTE4(int8_t _x, int8_t _y, int8_t _z, int8_t _w) : x(_x), y(_y), z(_z), w(_w) {} 748 explicit XMBYTE4(uint32_t Packed) : v(Packed) {} 749 explicit XMBYTE4(_In_reads_(4) const int8_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {} 750 XMBYTE4(float _x, float _y, float _z, float _w); 751 explicit XMBYTE4(_In_reads_(4) const float *pArray); 752 753 XMBYTE4& operator= (const XMBYTE4& Byte4) { x = Byte4.x; y = Byte4.y; z = Byte4.z; w = Byte4.w; return *this; } 754 XMBYTE4& operator= (uint32_t Packed) { v = Packed; return *this; } 755}; 756 757// 4D Vector; 8 bit unsigned normalized integer components 758struct XMUBYTEN4 759{ 760 union 761 { 762 struct 763 { 764 uint8_t x; 765 uint8_t y; 766 uint8_t z; 767 uint8_t w; 768 }; 769 uint32_t v; 770 }; 771 772 XMUBYTEN4() {} 773 XMUBYTEN4(uint8_t _x, uint8_t _y, uint8_t _z, uint8_t _w) : x(_x), y(_y), z(_z), w(_w) {} 774 explicit XMUBYTEN4(uint32_t Packed) : v(Packed) {} 775 explicit XMUBYTEN4(_In_reads_(4) const uint8_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {} 776 XMUBYTEN4(float _x, float _y, float _z, float _w); 777 explicit XMUBYTEN4(_In_reads_(4) const float *pArray); 778 779 XMUBYTEN4& operator= (const XMUBYTEN4& UByteN4) { x = UByteN4.x; y = UByteN4.y; z = UByteN4.z; w = UByteN4.w; return *this; } 780 XMUBYTEN4& operator= (uint32_t Packed) { v = Packed; return *this; } 781}; 782 783// 4D Vector; 8 bit unsigned integer components 784struct XMUBYTE4 785{ 786 union 787 { 788 struct 789 { 790 uint8_t x; 791 uint8_t y; 792 uint8_t z; 793 uint8_t w; 794 }; 795 uint32_t v; 796 }; 797 798 XMUBYTE4() {} 799 XMUBYTE4(uint8_t _x, uint8_t _y, uint8_t _z, uint8_t _w) : x(_x), y(_y), z(_z), w(_w) {} 800 explicit XMUBYTE4(uint32_t Packed) : v(Packed) {} 801 explicit XMUBYTE4(_In_reads_(4) const uint8_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {} 802 XMUBYTE4(float _x, float _y, float _z, float _w); 803 explicit XMUBYTE4(_In_reads_(4) const float *pArray); 804 805 XMUBYTE4& operator= (const XMUBYTE4& UByte4) { x = UByte4.x; y = UByte4.y; z = UByte4.z; w = UByte4.w; return *this; } 806 XMUBYTE4& operator= (uint32_t Packed) { v = Packed; return *this; } 807}; 808 809//------------------------------------------------------------------------------ 810// 4D vector; 4 bit unsigned integer components 811struct XMUNIBBLE4 812{ 813 union 814 { 815 struct 816 { 817 uint16_t x : 4; // 0 to 15 818 uint16_t y : 4; // 0 to 15 819 uint16_t z : 4; // 0 to 15 820 uint16_t w : 4; // 0 to 15 821 }; 822 uint16_t v; 823 }; 824 825 XMUNIBBLE4() {} 826 explicit XMUNIBBLE4(uint16_t Packed) : v(Packed) {} 827 XMUNIBBLE4(int8_t _x, int8_t _y, int8_t _z, int8_t _w) : x(_x), y(_y), z(_z), w(_w) {} 828 explicit XMUNIBBLE4(_In_reads_(4) const int8_t *pArray) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {} 829 XMUNIBBLE4(float _x, float _y, float _z, float _w); 830 explicit XMUNIBBLE4(_In_reads_(4) const float *pArray); 831 832 operator uint16_t () const { return v; } 833 834 XMUNIBBLE4& operator= (const XMUNIBBLE4& UNibble4) { v = UNibble4.v; return *this; } 835 XMUNIBBLE4& operator= (uint16_t Packed) { v = Packed; return *this; } 836}; 837 838//------------------------------------------------------------------------------ 839// 4D vector: 5/5/5/1 unsigned integer components 840struct XMU555 841{ 842 union 843 { 844 struct 845 { 846 uint16_t x : 5; // 0 to 31 847 uint16_t y : 5; // 0 to 31 848 uint16_t z : 5; // 0 to 31 849 uint16_t w : 1; // 0 or 1 850 }; 851 uint16_t v; 852 }; 853 854 XMU555() {} 855 explicit XMU555(uint16_t Packed) : v(Packed) {} 856 XMU555(int8_t _x, int8_t _y, int8_t _z, bool _w) : x(_x), y(_y), z(_z), w(_w ? 0x1 : 0) {} 857 XMU555(_In_reads_(3) const int8_t *pArray, _In_ bool _w) : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(_w ? 0x1 : 0) {} 858 XMU555(float _x, float _y, float _z, bool _w); 859 XMU555(_In_reads_(3) const float *pArray, _In_ bool _w); 860 861 operator uint16_t () const { return v; } 862 863 XMU555& operator= (const XMU555& U555) { v = U555.v; return *this; } 864 XMU555& operator= (uint16_t Packed) { v = Packed; return *this; } 865}; 866 867 868#pragma warning(pop) 869 870#ifdef _XM_BIGENDIAN_ 871#pragma bitfield_order(pop) 872#endif 873 874 875/**************************************************************************** 876 * 877 * Data conversion operations 878 * 879 ****************************************************************************/ 880 881float XMConvertHalfToFloat(HALF Value); 882float* XMConvertHalfToFloatStream(_Out_writes_bytes_(sizeof(float)+OutputStride*(HalfCount-1)) float* pOutputStream, 883 _In_ size_t OutputStride, 884 _In_reads_bytes_(sizeof(HALF)+InputStride*(HalfCount-1)) const HALF* pInputStream, 885 _In_ size_t InputStride, _In_ size_t HalfCount); 886HALF XMConvertFloatToHalf(float Value); 887HALF* XMConvertFloatToHalfStream(_Out_writes_bytes_(sizeof(HALF)+OutputStride*(FloatCount-1)) HALF* pOutputStream, 888 _In_ size_t OutputStride, 889 _In_reads_bytes_(sizeof(float)+InputStride*(FloatCount-1)) const float* pInputStream, 890 _In_ size_t InputStride, _In_ size_t FloatCount); 891 892/**************************************************************************** 893 * 894 * Load operations 895 * 896 ****************************************************************************/ 897 898XMVECTOR XMLoadColor(_In_ const XMCOLOR* pSource); 899 900XMVECTOR XMLoadHalf2(_In_ const XMHALF2* pSource); 901XMVECTOR XMLoadShortN2(_In_ const XMSHORTN2* pSource); 902XMVECTOR XMLoadShort2(_In_ const XMSHORT2* pSource); 903XMVECTOR XMLoadUShortN2(_In_ const XMUSHORTN2* pSource); 904XMVECTOR XMLoadUShort2(_In_ const XMUSHORT2* pSource); 905XMVECTOR XMLoadByteN2(_In_ const XMBYTEN2* pSource); 906XMVECTOR XMLoadByte2(_In_ const XMBYTE2* pSource); 907XMVECTOR XMLoadUByteN2(_In_ const XMUBYTEN2* pSource); 908XMVECTOR XMLoadUByte2(_In_ const XMUBYTE2* pSource); 909 910XMVECTOR XMLoadU565(_In_ const XMU565* pSource); 911XMVECTOR XMLoadFloat3PK(_In_ const XMFLOAT3PK* pSource); 912XMVECTOR XMLoadFloat3SE(_In_ const XMFLOAT3SE* pSource); 913 914XMVECTOR XMLoadHalf4(_In_ const XMHALF4* pSource); 915XMVECTOR XMLoadShortN4(_In_ const XMSHORTN4* pSource); 916XMVECTOR XMLoadShort4(_In_ const XMSHORT4* pSource); 917XMVECTOR XMLoadUShortN4(_In_ const XMUSHORTN4* pSource); 918XMVECTOR XMLoadUShort4(_In_ const XMUSHORT4* pSource); 919XMVECTOR XMLoadXDecN4(_In_ const XMXDECN4* pSource); 920XMVECTOR XMLoadXDec4(_In_ const XMXDEC4* pSource); 921XMVECTOR XMLoadDecN4(_In_ const XMDECN4* pSource); 922XMVECTOR XMLoadDec4(_In_ const XMDEC4* pSource); 923XMVECTOR XMLoadUDecN4(_In_ const XMUDECN4* pSource); 924XMVECTOR XMLoadUDec4(_In_ const XMUDEC4* pSource); 925XMVECTOR XMLoadByteN4(_In_ const XMBYTEN4* pSource); 926XMVECTOR XMLoadByte4(_In_ const XMBYTE4* pSource); 927XMVECTOR XMLoadUByteN4(_In_ const XMUBYTEN4* pSource); 928XMVECTOR XMLoadUByte4(_In_ const XMUBYTE4* pSource); 929XMVECTOR XMLoadUNibble4(_In_ const XMUNIBBLE4* pSource); 930XMVECTOR XMLoadU555(_In_ const XMU555* pSource); 931 932 933/**************************************************************************** 934 * 935 * Store operations 936 * 937 ****************************************************************************/ 938 939void XMStoreColor(_Out_ XMCOLOR* pDestination, _In_ FXMVECTOR V); 940 941void XMStoreHalf2(_Out_ XMHALF2* pDestination, _In_ FXMVECTOR V); 942void XMStoreShortN2(_Out_ XMSHORTN2* pDestination, _In_ FXMVECTOR V); 943void XMStoreShort2(_Out_ XMSHORT2* pDestination, _In_ FXMVECTOR V); 944void XMStoreUShortN2(_Out_ XMUSHORTN2* pDestination, _In_ FXMVECTOR V); 945void XMStoreUShort2(_Out_ XMUSHORT2* pDestination, _In_ FXMVECTOR V); 946void XMStoreByteN2(_Out_ XMBYTEN2* pDestination, _In_ FXMVECTOR V); 947void XMStoreByte2(_Out_ XMBYTE2* pDestination, _In_ FXMVECTOR V); 948void XMStoreUByteN2(_Out_ XMUBYTEN2* pDestination, _In_ FXMVECTOR V); 949void XMStoreUByte2(_Out_ XMUBYTE2* pDestination, _In_ FXMVECTOR V); 950 951void XMStoreU565(_Out_ XMU565* pDestination, _In_ FXMVECTOR V); 952void XMStoreFloat3PK(_Out_ XMFLOAT3PK* pDestination, _In_ FXMVECTOR V); 953void XMStoreFloat3SE(_Out_ XMFLOAT3SE* pDestination, _In_ FXMVECTOR V); 954 955void XMStoreHalf4(_Out_ XMHALF4* pDestination, _In_ FXMVECTOR V); 956void XMStoreShortN4(_Out_ XMSHORTN4* pDestination, _In_ FXMVECTOR V); 957void XMStoreShort4(_Out_ XMSHORT4* pDestination, _In_ FXMVECTOR V); 958void XMStoreUShortN4(_Out_ XMUSHORTN4* pDestination, _In_ FXMVECTOR V); 959void XMStoreUShort4(_Out_ XMUSHORT4* pDestination, _In_ FXMVECTOR V); 960void XMStoreXDecN4(_Out_ XMXDECN4* pDestination, _In_ FXMVECTOR V); 961void XMStoreXDec4(_Out_ XMXDEC4* pDestination, _In_ FXMVECTOR V); 962void XMStoreDecN4(_Out_ XMDECN4* pDestination, _In_ FXMVECTOR V); 963void XMStoreDec4(_Out_ XMDEC4* pDestination, _In_ FXMVECTOR V); 964void XMStoreUDecN4(_Out_ XMUDECN4* pDestination, _In_ FXMVECTOR V); 965void XMStoreUDec4(_Out_ XMUDEC4* pDestination, _In_ FXMVECTOR V); 966void XMStoreByteN4(_Out_ XMBYTEN4* pDestination, _In_ FXMVECTOR V); 967void XMStoreByte4(_Out_ XMBYTE4* pDestination, _In_ FXMVECTOR V); 968void XMStoreUByteN4(_Out_ XMUBYTEN4* pDestination, _In_ FXMVECTOR V); 969void XMStoreUByte4(_Out_ XMUBYTE4* pDestination, _In_ FXMVECTOR V); 970void XMStoreUNibble4(_Out_ XMUNIBBLE4* pDestination, _In_ FXMVECTOR V); 971void XMStoreU555(_Out_ XMU555* pDestination, _In_ FXMVECTOR V); 972 973 974/**************************************************************************** 975 * 976 * Implementation 977 * 978 ****************************************************************************/ 979 980#pragma warning(push) 981#pragma warning(disable:4068 4214 4204 4365 4616 6001) 982 983#pragma prefast(push) 984#pragma prefast(disable : 25000, "FXMVECTOR is 16 bytes") 985 986#include "DirectXPackedVector.inl" 987 988#pragma prefast(pop) 989#pragma warning(pop) 990 991}; // namespace PackedVector 992 993}; // namespace DirectX 994 995