1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: gd_Combiner.h 4 5 Copyright (C)2011 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 *---------------------------------------------------------------------------*/ 14 15 16 #ifndef NN_GD_CTR_GD_COMBINER_H_ 17 #define NN_GD_CTR_GD_COMBINER_H_ 18 19 #include <nn/gd/CTR/gd_Types.h> 20 #include <nn/gd/CTR/gd_Result.h> 21 22 #include <string.h> 23 24 #if NN_GD_DOCUMENT_TYPE == ENGLISH 25 /* Please see man pages for details 26 27 28 */ 29 #else 30 /* Please see man pages for details 31 32 33 */ 34 #endif 35 36 namespace nn { 37 namespace gd { 38 namespace CTR { 39 40 class CombinerState; 41 class CombinerDescription; 42 class LightingStage; 43 44 #if NN_GD_DOCUMENT_TYPE == ENGLISH 45 /* Please see man pages for details 46 47 48 49 50 51 52 */ 53 #else 54 /* Please see man pages for details 55 56 57 58 59 60 61 */ 62 #endif 63 class CombinerStage 64 { 65 public: 66 #if NN_GD_DOCUMENT_TYPE == ENGLISH 67 /* Please see man pages for details */ 68 #else 69 /* Please see man pages for details */ 70 #endif 71 static const u32 COUNT_TEXTURE_COMBINER_UNITS = 6; 72 73 #if NN_GD_DOCUMENT_TYPE == ENGLISH 74 /* Please see man pages for details */ 75 #else 76 /* Please see man pages for details */ 77 #endif 78 enum UnitId 79 { 80 UNIT0 = 0, 81 UNIT1 = 1, 82 UNIT2 = 2, 83 UNIT3 = 3, 84 UNIT4 = 4, 85 UNIT5 = 5, 86 87 UNIT_RESERVED_MAX_U32 = 0xffffffffu 88 }; 89 90 #if NN_GD_DOCUMENT_TYPE == ENGLISH 91 /* Please see man pages for details */ 92 #else 93 /* Please see man pages for details 94 95 */ 96 #endif 97 enum Source 98 { 99 SOURCE_PRIMARY_COLOR = 0x0, 100 SOURCE_FRAGMENT_PRIMARY_COLOR = 0x1, 101 SOURCE_FRAGMENT_SECONDARY_COLOR = 0x2, 102 SOURCE_TEXTURE0 = 0x3, 103 SOURCE_TEXTURE1 = 0x4, 104 SOURCE_TEXTURE2 = 0x5, 105 SOURCE_TEXTURE3 = 0x6, 106 SOURCE_PREVIOUS_BUFFER = 0xd, 107 SOURCE_CONSTANT = 0xe, 108 SOURCE_PREVIOUS = 0xf, 109 110 SOURCE_RESERVED_MAX_U32 = 0xffffffffu 111 }; 112 113 #if NN_GD_DOCUMENT_TYPE == ENGLISH 114 /* Please see man pages for details */ 115 #else 116 /* Please see man pages for details */ 117 #endif 118 enum OperandRgb 119 { 120 OPERAND_RGB_SRC_COLOR = 0x0, 121 OPERAND_RGB_ONE_MINUS_SRC_COLOR = 0x1, 122 OPERAND_RGB_SRC_ALPHA = 0x2, 123 OPERAND_RGB_ONE_MINUS_SRC_ALPHA = 0x3, 124 OPERAND_RGB_SRC_R = 0x4, 125 OPERAND_RGB_ONE_MINUS_SRC_R = 0x5, 126 OPERAND_RGB_SRC_G = 0x8, 127 OPERAND_RGB_ONE_MINUS_SRC_G = 0x9, 128 OPERAND_RGB_SRC_B = 0xc, 129 OPERAND_RGB_ONE_MINUS_SRC_B = 0xd, 130 131 OPERAND_RGB_RESERVED_MAX_U32 = 0xffffffffu 132 }; 133 134 #if NN_GD_DOCUMENT_TYPE == ENGLISH 135 /* Please see man pages for details */ 136 #else 137 /* Please see man pages for details */ 138 #endif 139 enum OperandAlpha 140 { 141 OPERAND_ALPHA_SRC_ALPHA = 0x0, 142 OPERAND_ALPHA_ONE_MINUS_SRC_ALPHA = 0x1, 143 OPERAND_ALPHA_SRC_R = 0x2, 144 OPERAND_ALPHA_ONE_MINUS_SRC_R = 0x3, 145 OPERAND_ALPHA_SRC_G = 0x4, 146 OPERAND_ALPHA_ONE_MINUS_SRC_G = 0x5, 147 OPERAND_ALPHA_SRC_B = 0x6, 148 OPERAND_ALPHA_ONE_MINUS_SRC_B = 0x7, 149 150 OPERAND_ALPHA_RESERVED_MAX_U32 = 0xffffffffu 151 }; 152 153 #if NN_GD_DOCUMENT_TYPE == ENGLISH 154 /* Please see man pages for details */ 155 #else 156 /* Please see man pages for details */ 157 #endif 158 enum CombineRgb 159 { 160 COMBINE_RGB_REPLACE = 0x0, 161 COMBINE_RGB_MODULATE = 0x1, 162 COMBINE_RGB_ADD = 0x2, 163 COMBINE_RGB_ADD_SIGNED = 0x3, 164 COMBINE_RGB_INTERPOLATE = 0x4, 165 COMBINE_RGB_SUBTRACT = 0x5, 166 COMBINE_RGB_DOT3_RGB = 0x6, 167 COMBINE_RGB_DOT3_RGBA = 0x7, 168 COMBINE_RGB_MULT_ADD = 0x8, 169 COMBINE_RGB_ADD_MULT = 0x9, 170 171 COMBINE_RGB_RESERVED_MAX_U32 = 0xffffffffu 172 }; 173 174 #if NN_GD_DOCUMENT_TYPE == ENGLISH 175 /* Please see man pages for details */ 176 #else 177 /* Please see man pages for details */ 178 #endif 179 enum CombineAlpha 180 { 181 COMBINE_ALPHA_REPLACE = 0x0, 182 COMBINE_ALPHA_MODULATE = 0x1, 183 COMBINE_ALPHA_ADD = 0x2, 184 COMBINE_ALPHA_ADD_SIGNED = 0x3, 185 COMBINE_ALPHA_INTERPOLATE = 0x4, 186 COMBINE_ALPHA_SUBTRACT = 0x5, 187 COMBINE_ALPHA_DOT3_RGBA = 0x7, 188 COMBINE_ALPHA_MULT_ADD = 0x8, 189 COMBINE_ALPHA_ADD_MULT = 0x9, 190 191 COMBINE_ALPHA_RESERVED_MAX_U32 = 0xffffffffu 192 }; 193 194 #if NN_GD_DOCUMENT_TYPE == ENGLISH 195 /* Please see man pages for details */ 196 #else 197 /* Please see man pages for details */ 198 #endif 199 enum Scale 200 { 201 SCALE_1 = 0x0, 202 SCALE_2 = 0x1, 203 SCALE_4 = 0x2, 204 205 SCALE_RESERVED_MAX_U32 = 0xffffffffu 206 }; 207 208 #if NN_GD_DOCUMENT_TYPE == ENGLISH 209 /* Please see man pages for details */ 210 #else 211 /* Please see man pages for details */ 212 #endif 213 enum BufferInput 214 { 215 INPUT_PREVIOUS_BUFFER = 0x0, 216 INPUT_PREVIOUS_UNIT = 0x1, 217 218 INPUT_PREVIOUS_RESERVED_MAX_U32 = 0xffffffffu 219 }; 220 221 222 #if NN_GD_DOCUMENT_TYPE == ENGLISH 223 /* Please see man pages for details 224 225 226 227 228 229 230 231 232 233 */ 234 #else 235 /* Please see man pages for details 236 237 238 239 240 241 242 243 244 245 246 247 */ 248 #endif 249 static nnResult CreateTextureCombinerState(const CombinerDescription* description, CombinerState** textureCombinerState); 250 251 #if NN_GD_DOCUMENT_TYPE == ENGLISH 252 /* Please see man pages for details 253 254 255 256 257 258 259 */ 260 #else 261 /* Please see man pages for details 262 263 264 265 266 267 268 269 */ 270 #endif 271 static nnResult ReleaseTextureCombinerState(CombinerState* textureCombinerState); 272 273 #if NN_GD_DOCUMENT_TYPE == ENGLISH 274 /* Please see man pages for details 275 276 277 278 279 280 281 */ 282 #else 283 /* Please see man pages for details 284 285 286 287 288 289 290 291 292 293 294 295 */ 296 #endif 297 static nnResult SetTextureCombinerState(CombinerState* textureCombinerState); 298 299 #if NN_GD_DOCUMENT_TYPE == ENGLISH 300 /* Please see man pages for details 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 */ 317 #else 318 /* Please see man pages for details 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 */ 335 #endif 336 static nnResult SetTextureCombinerUnitConstantColor(UnitId unit, u8 colorR, u8 colorG, u8 colorB, u8 colorA); 337 338 }; // CombinerStage 339 340 341 #if NN_GD_DOCUMENT_TYPE == ENGLISH 342 /* Please see man pages for details 343 344 345 */ 346 #else 347 /* Please see man pages for details 348 349 350 */ 351 #endif 352 class CombinerUnitDescription 353 { 354 public: 355 356 #if NN_GD_DOCUMENT_TYPE == ENGLISH 357 /* Please see man pages for details 358 359 360 */ 361 #else 362 /* Please see man pages for details 363 364 365 */ 366 #endif 367 CombinerStage::Source m_SrcRGB[3]; 368 369 #if NN_GD_DOCUMENT_TYPE == ENGLISH 370 /* Please see man pages for details 371 372 373 */ 374 #else 375 /* Please see man pages for details 376 377 378 */ 379 #endif 380 CombinerStage::Source m_SrcAlpha[3]; 381 382 #if NN_GD_DOCUMENT_TYPE == ENGLISH 383 /* Please see man pages for details 384 385 */ 386 #else 387 /* Please see man pages for details 388 389 */ 390 #endif 391 CombinerStage::OperandRgb m_OperandRgb[3]; 392 393 #if NN_GD_DOCUMENT_TYPE == ENGLISH 394 /* Please see man pages for details 395 396 */ 397 #else 398 /* Please see man pages for details 399 400 */ 401 #endif 402 CombinerStage::OperandAlpha m_OperandAlpha[3]; 403 404 #if NN_GD_DOCUMENT_TYPE == ENGLISH 405 /* Please see man pages for details 406 407 */ 408 #else 409 /* Please see man pages for details 410 411 */ 412 #endif 413 CombinerStage::CombineRgb m_CombineRgb; 414 415 #if NN_GD_DOCUMENT_TYPE == ENGLISH 416 /* Please see man pages for details 417 418 */ 419 #else 420 /* Please see man pages for details 421 422 */ 423 #endif 424 CombinerStage::CombineAlpha m_CombineAlpha; 425 426 #if NN_GD_DOCUMENT_TYPE == ENGLISH 427 /* Please see man pages for details 428 429 */ 430 #else 431 /* Please see man pages for details 432 433 */ 434 #endif 435 CombinerStage::Scale m_ScaleRgb; 436 437 #if NN_GD_DOCUMENT_TYPE == ENGLISH 438 /* Please see man pages for details 439 440 */ 441 #else 442 /* Please see man pages for details 443 444 */ 445 #endif 446 CombinerStage::Scale m_ScaleAlpha; 447 }; 448 449 #if NN_GD_DOCUMENT_TYPE == ENGLISH 450 /* Please see man pages for details 451 452 453 454 */ 455 #else 456 /* Please see man pages for details 457 458 459 460 */ 461 #endif 462 class CombinerDescription 463 { 464 public: 465 #if NN_GD_DOCUMENT_TYPE == ENGLISH 466 /* Please see man pages for details 467 468 */ 469 #else 470 /* Please see man pages for details 471 472 */ 473 #endif 474 CombinerUnitDescription m_CombinerUnit[CombinerStage::COUNT_TEXTURE_COMBINER_UNITS]; 475 476 #if NN_GD_DOCUMENT_TYPE == ENGLISH 477 /* Please see man pages for details 478 479 */ 480 #else 481 /* Please see man pages for details 482 483 */ 484 #endif 485 u8 m_BufferColor[4]; 486 487 #if NN_GD_DOCUMENT_TYPE == ENGLISH 488 /* Please see man pages for details 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 */ 520 #else 521 /* Please see man pages for details 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 */ 555 #endif 556 u32 m_CombinerInUse; 557 558 #if NN_GD_DOCUMENT_TYPE == ENGLISH 559 /* Please see man pages for details 560 561 562 563 564 565 */ 566 #else 567 /* Please see man pages for details 568 569 570 571 */ 572 #endif 573 struct BufferInput 574 { 575 //! Texture combiner unit 1 color 576 CombinerStage::BufferInput m_Rgb1; 577 //! Texture combiner unit 2 color 578 CombinerStage::BufferInput m_Rgb2; 579 //! Texture combiner unit 3 color 580 CombinerStage::BufferInput m_Rgb3; 581 //! Texture combiner unit 4 color 582 CombinerStage::BufferInput m_Rgb4; 583 //! Texture combiner unit 1 alpha 584 CombinerStage::BufferInput m_Alpha1; 585 //! Texture combiner unit 2 alpha 586 CombinerStage::BufferInput m_Alpha2; 587 //! Texture combiner unit 3 alpha 588 CombinerStage::BufferInput m_Alpha3; 589 //! Texture combiner unit 4 alpha 590 CombinerStage::BufferInput m_Alpha4; 591 }; 592 593 #if NN_GD_DOCUMENT_TYPE == ENGLISH 594 /* Please see man pages for details 595 596 */ 597 #else 598 /* Please see man pages for details 599 600 601 */ 602 #endif 603 struct BufferInput m_BufferInput; 604 605 #if NN_GD_DOCUMENT_TYPE == ENGLISH 606 /* Please see man pages for details 607 608 609 610 611 612 613 614 */ 615 #else 616 /* Please see man pages for details 617 618 619 620 621 622 623 624 */ 625 #endif SetSourceRGB(CombinerStage::UnitId unit,CombinerStage::Source sourceRGB1,CombinerStage::Source sourceRGB2,CombinerStage::Source sourceRGB3)626 void SetSourceRGB(CombinerStage::UnitId unit, CombinerStage::Source sourceRGB1, CombinerStage::Source sourceRGB2, CombinerStage::Source sourceRGB3) 627 { 628 m_CombinerUnit[unit].m_SrcRGB[0] = sourceRGB1; 629 m_CombinerUnit[unit].m_SrcRGB[1] = sourceRGB2; 630 m_CombinerUnit[unit].m_SrcRGB[2] = sourceRGB3; 631 } 632 633 #if NN_GD_DOCUMENT_TYPE == ENGLISH 634 /* Please see man pages for details 635 636 637 638 639 640 641 642 */ 643 #else 644 /* Please see man pages for details 645 646 647 648 649 650 651 652 */ 653 #endif SetOperandRGB(CombinerStage::UnitId unit,CombinerStage::OperandRgb opRGB1,CombinerStage::OperandRgb opRGB2,CombinerStage::OperandRgb opRGB3)654 void SetOperandRGB(CombinerStage::UnitId unit, CombinerStage::OperandRgb opRGB1, CombinerStage::OperandRgb opRGB2, CombinerStage::OperandRgb opRGB3) 655 { 656 m_CombinerUnit[unit].m_OperandRgb[0] = opRGB1; 657 m_CombinerUnit[unit].m_OperandRgb[1] = opRGB2; 658 m_CombinerUnit[unit].m_OperandRgb[2] = opRGB3; 659 } 660 661 #if NN_GD_DOCUMENT_TYPE == ENGLISH 662 /* Please see man pages for details 663 664 665 666 667 668 669 670 */ 671 #else 672 /* Please see man pages for details 673 674 675 676 677 678 679 680 */ 681 #endif SetSourceAlpha(CombinerStage::UnitId unit,CombinerStage::Source sourceA1,CombinerStage::Source sourceA2,CombinerStage::Source sourceA3)682 void SetSourceAlpha(CombinerStage::UnitId unit, CombinerStage::Source sourceA1, CombinerStage::Source sourceA2, CombinerStage::Source sourceA3) 683 { 684 m_CombinerUnit[unit].m_SrcAlpha[0] = sourceA1; 685 m_CombinerUnit[unit].m_SrcAlpha[1] = sourceA2; 686 m_CombinerUnit[unit].m_SrcAlpha[2] = sourceA3; 687 } 688 689 #if NN_GD_DOCUMENT_TYPE == ENGLISH 690 /* Please see man pages for details 691 692 693 694 695 696 697 698 */ 699 #else 700 /* Please see man pages for details 701 702 703 704 705 706 707 708 */ 709 #endif SetOperandAlpha(CombinerStage::UnitId unit,CombinerStage::OperandAlpha opA1,CombinerStage::OperandAlpha opA2,CombinerStage::OperandAlpha opA3)710 void SetOperandAlpha(CombinerStage::UnitId unit, CombinerStage::OperandAlpha opA1, CombinerStage::OperandAlpha opA2, CombinerStage::OperandAlpha opA3) 711 { 712 m_CombinerUnit[unit].m_OperandAlpha[0] = opA1; 713 m_CombinerUnit[unit].m_OperandAlpha[1] = opA2; 714 m_CombinerUnit[unit].m_OperandAlpha[2] = opA3; 715 } 716 717 #if NN_GD_DOCUMENT_TYPE == ENGLISH 718 /* Please see man pages for details 719 720 721 722 723 724 */ 725 #else 726 /* Please see man pages for details 727 728 729 730 731 732 */ 733 #endif SetCombineRGB(CombinerStage::UnitId unit,CombinerStage::CombineRgb combineRgb)734 void SetCombineRGB(CombinerStage::UnitId unit, CombinerStage::CombineRgb combineRgb) 735 { 736 m_CombinerUnit[unit].m_CombineRgb = combineRgb; 737 } 738 739 #if NN_GD_DOCUMENT_TYPE == ENGLISH 740 /* Please see man pages for details 741 742 743 744 745 746 */ 747 #else 748 /* Please see man pages for details 749 750 751 752 753 754 */ 755 #endif SetCombineAlpha(CombinerStage::UnitId unit,CombinerStage::CombineAlpha combineAlpha)756 void SetCombineAlpha(CombinerStage::UnitId unit, CombinerStage::CombineAlpha combineAlpha) 757 { 758 m_CombinerUnit[unit].m_CombineAlpha = combineAlpha; 759 } 760 761 #if NN_GD_DOCUMENT_TYPE == ENGLISH 762 /* Please see man pages for details 763 764 765 766 767 768 */ 769 #else 770 /* Please see man pages for details 771 772 773 774 775 776 */ 777 #endif SetScaleRGB(CombinerStage::UnitId unit,CombinerStage::Scale scaleRgb)778 void SetScaleRGB(CombinerStage::UnitId unit, CombinerStage::Scale scaleRgb) 779 { 780 m_CombinerUnit[unit].m_ScaleRgb = scaleRgb; 781 } 782 783 #if NN_GD_DOCUMENT_TYPE == ENGLISH 784 /* Please see man pages for details 785 786 787 788 789 790 */ 791 #else 792 /* Please see man pages for details 793 794 795 796 797 798 */ 799 #endif SetScaleAlpha(CombinerStage::UnitId unit,CombinerStage::Scale scaleAlpha)800 void SetScaleAlpha(CombinerStage::UnitId unit, CombinerStage::Scale scaleAlpha) 801 { 802 m_CombinerUnit[unit].m_ScaleAlpha = scaleAlpha; 803 } 804 805 #if NN_GD_DOCUMENT_TYPE == ENGLISH 806 /* Please see man pages for details 807 808 809 810 811 */ 812 #else 813 /* Please see man pages for details 814 815 816 817 818 */ 819 #endif SetBufferColor(u8 colorR,u8 colorG,u8 colorB,u8 colorA)820 void SetBufferColor(u8 colorR, u8 colorG, u8 colorB, u8 colorA) 821 { 822 m_BufferColor[0] = colorR; 823 m_BufferColor[1] = colorG; 824 m_BufferColor[2] = colorB; 825 m_BufferColor[3] = colorA; 826 } 827 828 #if NN_GD_DOCUMENT_TYPE == ENGLISH 829 /* Please see man pages for details 830 831 832 */ 833 #else 834 /* Please see man pages for details 835 836 837 */ 838 #endif SetCombinerInUse(CombinerStage::UnitId unit,gdBool mode)839 void SetCombinerInUse(CombinerStage::UnitId unit, gdBool mode) 840 { 841 u32 UseId = 1<<unit; 842 843 m_CombinerInUse &= ~(UseId); 844 if (mode == GD_TRUE) m_CombinerInUse |= UseId; 845 } 846 847 #if NN_GD_DOCUMENT_TYPE == ENGLISH 848 /* Please see man pages for details 849 */ 850 #else 851 /* Please see man pages for details 852 */ 853 #endif CombinerDescription()854 CombinerDescription() 855 { 856 ToDefault(); 857 } 858 859 #if NN_GD_DOCUMENT_TYPE == ENGLISH 860 /* Please see man pages for details 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 */ 879 #else 880 /* Please see man pages for details 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 */ 912 #endif ToDefault()913 void ToDefault() 914 { 915 memset(m_CombinerUnit, 0, sizeof(m_CombinerUnit)); 916 917 m_CombinerUnit[0].m_SrcRGB[0] = m_CombinerUnit[0].m_SrcRGB[1] = m_CombinerUnit[0].m_SrcRGB[2] = CombinerStage::SOURCE_CONSTANT; 918 m_CombinerUnit[0].m_SrcAlpha[0] = m_CombinerUnit[0].m_SrcAlpha[1] = m_CombinerUnit[0].m_SrcAlpha[2] = CombinerStage::SOURCE_CONSTANT; 919 920 for (int i = 1; i < CombinerStage::COUNT_TEXTURE_COMBINER_UNITS; i++) 921 { 922 m_CombinerUnit[i].m_SrcRGB[0] = m_CombinerUnit[i].m_SrcRGB[1] = m_CombinerUnit[i].m_SrcRGB[2] = CombinerStage::SOURCE_PREVIOUS; 923 m_CombinerUnit[i].m_SrcAlpha[0] = m_CombinerUnit[i].m_SrcAlpha[1] = m_CombinerUnit[i].m_SrcAlpha[2] = CombinerStage::SOURCE_PREVIOUS; 924 } 925 m_BufferInput.m_Rgb1 = m_BufferInput.m_Rgb2 = m_BufferInput.m_Rgb3 = m_BufferInput.m_Rgb4 = 926 m_BufferInput.m_Alpha1 = m_BufferInput.m_Alpha2 = m_BufferInput.m_Alpha3 = m_BufferInput.m_Alpha4 = CombinerStage::INPUT_PREVIOUS_BUFFER; 927 m_BufferColor[0] = m_BufferColor[1] = m_BufferColor[2] = m_BufferColor[3] = 0; 928 m_CombinerInUse = 0; 929 } 930 931 }; // CombinerDescription; 932 933 } // namespace CTR 934 } // namespace gd 935 } // namespace nn 936 937 938 #endif // NN_GD_CTR_GD_COMBINER_H_ 939