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 #else 228 /* Please see man pages for details 229 230 231 232 233 234 235 236 237 238 239 240 */ 241 #endif 242 static nnResult CreateTextureCombinerState(const CombinerDescription* description, CombinerState** textureCombinerState); 243 244 #if NN_GD_DOCUMENT_TYPE == ENGLISH 245 /* Please see man pages for details 246 247 */ 248 #else 249 /* Please see man pages for details 250 251 252 253 254 255 256 257 */ 258 #endif 259 static nnResult ReleaseTextureCombinerState(CombinerState* textureCombinerState); 260 261 #if NN_GD_DOCUMENT_TYPE == ENGLISH 262 /* Please see man pages for details 263 264 */ 265 #else 266 /* Please see man pages for details 267 268 269 270 271 272 273 274 275 276 277 278 */ 279 #endif 280 static nnResult SetTextureCombinerState(CombinerState* textureCombinerState); 281 282 #if NN_GD_DOCUMENT_TYPE == ENGLISH 283 /* Please see man pages for details 284 285 286 287 288 289 290 291 292 293 */ 294 #else 295 /* Please see man pages for details 296 297 298 299 300 301 302 303 304 305 306 307 308 309 */ 310 #endif 311 static nnResult SetTextureCombinerUnitConstantColor(UnitId unit, u8 colorR, u8 colorG, u8 colorB, u8 colorA); 312 313 }; // CombinerStage 314 315 316 #if NN_GD_DOCUMENT_TYPE == ENGLISH 317 /* Please see man pages for details 318 319 320 */ 321 #else 322 /* Please see man pages for details 323 324 325 */ 326 #endif 327 class CombinerUnitDescription 328 { 329 public: 330 331 #if NN_GD_DOCUMENT_TYPE == ENGLISH 332 /* Please see man pages for details 333 334 */ 335 #else 336 /* Please see man pages for details 337 338 */ 339 #endif 340 CombinerStage::Source m_SrcRGB[3]; 341 342 #if NN_GD_DOCUMENT_TYPE == ENGLISH 343 /* Please see man pages for details 344 345 */ 346 #else 347 /* Please see man pages for details 348 349 */ 350 #endif 351 CombinerStage::Source m_SrcAlpha[3]; 352 353 #if NN_GD_DOCUMENT_TYPE == ENGLISH 354 /* Please see man pages for details 355 356 */ 357 #else 358 /* Please see man pages for details 359 360 */ 361 #endif 362 CombinerStage::OperandRgb m_OperandRgb[3]; 363 364 #if NN_GD_DOCUMENT_TYPE == ENGLISH 365 /* Please see man pages for details 366 367 */ 368 #else 369 /* Please see man pages for details 370 371 */ 372 #endif 373 CombinerStage::OperandAlpha m_OperandAlpha[3]; 374 375 #if NN_GD_DOCUMENT_TYPE == ENGLISH 376 /* Please see man pages for details 377 378 */ 379 #else 380 /* Please see man pages for details 381 382 */ 383 #endif 384 CombinerStage::CombineRgb m_CombineRgb; 385 386 #if NN_GD_DOCUMENT_TYPE == ENGLISH 387 /* Please see man pages for details 388 389 */ 390 #else 391 /* Please see man pages for details 392 393 */ 394 #endif 395 CombinerStage::CombineAlpha m_CombineAlpha; 396 397 #if NN_GD_DOCUMENT_TYPE == ENGLISH 398 /* Please see man pages for details 399 400 */ 401 #else 402 /* Please see man pages for details 403 404 */ 405 #endif 406 CombinerStage::Scale m_ScaleRgb; 407 408 #if NN_GD_DOCUMENT_TYPE == ENGLISH 409 /* Please see man pages for details 410 411 */ 412 #else 413 /* Please see man pages for details 414 415 */ 416 #endif 417 CombinerStage::Scale m_ScaleAlpha; 418 }; 419 420 #if NN_GD_DOCUMENT_TYPE == ENGLISH 421 /* Please see man pages for details 422 423 424 425 */ 426 #else 427 /* Please see man pages for details 428 429 430 431 */ 432 #endif 433 class CombinerDescription 434 { 435 public: 436 #if NN_GD_DOCUMENT_TYPE == ENGLISH 437 /* Please see man pages for details 438 439 */ 440 #else 441 /* Please see man pages for details 442 443 */ 444 #endif 445 CombinerUnitDescription m_CombinerUnit[CombinerStage::COUNT_TEXTURE_COMBINER_UNITS]; 446 447 #if NN_GD_DOCUMENT_TYPE == ENGLISH 448 /* Please see man pages for details 449 450 */ 451 #else 452 /* Please see man pages for details 453 454 */ 455 #endif 456 u8 m_BufferColor[4]; 457 458 #if NN_GD_DOCUMENT_TYPE == ENGLISH 459 /* Please see man pages for details 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 */ 491 #else 492 /* Please see man pages for details 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 521 522 523 524 525 */ 526 #endif 527 u32 m_CombinerInUse; 528 529 #if NN_GD_DOCUMENT_TYPE == ENGLISH 530 /* Please see man pages for details 531 532 533 534 535 536 */ 537 #else 538 /* Please see man pages for details 539 540 541 542 */ 543 #endif 544 struct BufferInput 545 { 546 //! Texture combiner unit 1 color 547 CombinerStage::BufferInput m_Rgb1; 548 //! Texture combiner unit 2 color 549 CombinerStage::BufferInput m_Rgb2; 550 //! Texture combiner unit 3 color 551 CombinerStage::BufferInput m_Rgb3; 552 //! Texture combiner unit 4 color 553 CombinerStage::BufferInput m_Rgb4; 554 //! Texture combiner unit 1 alpha 555 CombinerStage::BufferInput m_Alpha1; 556 //! Texture combiner unit 2 alpha 557 CombinerStage::BufferInput m_Alpha2; 558 //! Texture combiner unit 3 alpha 559 CombinerStage::BufferInput m_Alpha3; 560 //! Texture combiner unit 4 alpha 561 CombinerStage::BufferInput m_Alpha4; 562 }; 563 564 #if NN_GD_DOCUMENT_TYPE == ENGLISH 565 /* Please see man pages for details 566 567 */ 568 #else 569 /* Please see man pages for details 570 571 572 */ 573 #endif 574 struct BufferInput m_BufferInput; 575 576 #if NN_GD_DOCUMENT_TYPE == ENGLISH 577 /* Please see man pages for details 578 579 580 581 582 583 584 */ 585 #else 586 /* Please see man pages for details 587 588 589 590 591 592 593 */ 594 #endif SetSourceRGB(CombinerStage::UnitId unit,CombinerStage::Source sourceRGB1,CombinerStage::Source sourceRGB2,CombinerStage::Source sourceRGB3)595 void SetSourceRGB(CombinerStage::UnitId unit, CombinerStage::Source sourceRGB1, CombinerStage::Source sourceRGB2, CombinerStage::Source sourceRGB3) 596 { 597 m_CombinerUnit[unit].m_SrcRGB[0] = sourceRGB1; 598 m_CombinerUnit[unit].m_SrcRGB[1] = sourceRGB2; 599 m_CombinerUnit[unit].m_SrcRGB[2] = sourceRGB3; 600 } 601 602 #if NN_GD_DOCUMENT_TYPE == ENGLISH 603 /* Please see man pages for details 604 605 606 607 608 609 610 */ 611 #else 612 /* Please see man pages for details 613 614 615 616 617 618 619 */ 620 #endif SetOperandRGB(CombinerStage::UnitId unit,CombinerStage::OperandRgb opRGB1,CombinerStage::OperandRgb opRGB2,CombinerStage::OperandRgb opRGB3)621 void SetOperandRGB(CombinerStage::UnitId unit, CombinerStage::OperandRgb opRGB1, CombinerStage::OperandRgb opRGB2, CombinerStage::OperandRgb opRGB3) 622 { 623 m_CombinerUnit[unit].m_OperandRgb[0] = opRGB1; 624 m_CombinerUnit[unit].m_OperandRgb[1] = opRGB2; 625 m_CombinerUnit[unit].m_OperandRgb[2] = opRGB3; 626 } 627 628 #if NN_GD_DOCUMENT_TYPE == ENGLISH 629 /* Please see man pages for details 630 631 632 633 634 635 636 */ 637 #else 638 /* Please see man pages for details 639 640 641 642 643 644 645 */ 646 #endif SetSourceAlpha(CombinerStage::UnitId unit,CombinerStage::Source sourceA1,CombinerStage::Source sourceA2,CombinerStage::Source sourceA3)647 void SetSourceAlpha(CombinerStage::UnitId unit, CombinerStage::Source sourceA1, CombinerStage::Source sourceA2, CombinerStage::Source sourceA3) 648 { 649 m_CombinerUnit[unit].m_SrcAlpha[0] = sourceA1; 650 m_CombinerUnit[unit].m_SrcAlpha[1] = sourceA2; 651 m_CombinerUnit[unit].m_SrcAlpha[2] = sourceA3; 652 } 653 654 #if NN_GD_DOCUMENT_TYPE == ENGLISH 655 /* Please see man pages for details 656 657 658 659 660 661 662 */ 663 #else 664 /* Please see man pages for details 665 666 667 668 669 670 671 */ 672 #endif SetOperandAlpha(CombinerStage::UnitId unit,CombinerStage::OperandAlpha opA1,CombinerStage::OperandAlpha opA2,CombinerStage::OperandAlpha opA3)673 void SetOperandAlpha(CombinerStage::UnitId unit, CombinerStage::OperandAlpha opA1, CombinerStage::OperandAlpha opA2, CombinerStage::OperandAlpha opA3) 674 { 675 m_CombinerUnit[unit].m_OperandAlpha[0] = opA1; 676 m_CombinerUnit[unit].m_OperandAlpha[1] = opA2; 677 m_CombinerUnit[unit].m_OperandAlpha[2] = opA3; 678 } 679 680 #if NN_GD_DOCUMENT_TYPE == ENGLISH 681 /* Please see man pages for details 682 683 684 685 686 */ 687 #else 688 /* Please see man pages for details 689 690 691 692 693 */ 694 #endif SetCombineRGB(CombinerStage::UnitId unit,CombinerStage::CombineRgb combineRgb)695 void SetCombineRGB(CombinerStage::UnitId unit, CombinerStage::CombineRgb combineRgb) 696 { 697 m_CombinerUnit[unit].m_CombineRgb = combineRgb; 698 } 699 700 #if NN_GD_DOCUMENT_TYPE == ENGLISH 701 /* Please see man pages for details 702 703 704 705 706 */ 707 #else 708 /* Please see man pages for details 709 710 711 712 713 */ 714 #endif SetCombineAlpha(CombinerStage::UnitId unit,CombinerStage::CombineAlpha combineAlpha)715 void SetCombineAlpha(CombinerStage::UnitId unit, CombinerStage::CombineAlpha combineAlpha) 716 { 717 m_CombinerUnit[unit].m_CombineAlpha = combineAlpha; 718 } 719 720 #if NN_GD_DOCUMENT_TYPE == ENGLISH 721 /* Please see man pages for details 722 723 724 725 726 */ 727 #else 728 /* Please see man pages for details 729 730 731 732 733 */ 734 #endif SetScaleRGB(CombinerStage::UnitId unit,CombinerStage::Scale scaleRgb)735 void SetScaleRGB(CombinerStage::UnitId unit, CombinerStage::Scale scaleRgb) 736 { 737 m_CombinerUnit[unit].m_ScaleRgb = scaleRgb; 738 } 739 740 #if NN_GD_DOCUMENT_TYPE == ENGLISH 741 /* Please see man pages for details 742 743 744 745 746 */ 747 #else 748 /* Please see man pages for details 749 750 751 752 753 */ 754 #endif SetScaleAlpha(CombinerStage::UnitId unit,CombinerStage::Scale scaleAlpha)755 void SetScaleAlpha(CombinerStage::UnitId unit, CombinerStage::Scale scaleAlpha) 756 { 757 m_CombinerUnit[unit].m_ScaleAlpha = scaleAlpha; 758 } 759 760 #if NN_GD_DOCUMENT_TYPE == ENGLISH 761 /* Please see man pages for details 762 763 764 765 766 */ 767 #else 768 /* Please see man pages for details 769 770 771 772 773 */ 774 #endif SetBufferColor(u8 colorR,u8 colorG,u8 colorB,u8 colorA)775 void SetBufferColor(u8 colorR, u8 colorG, u8 colorB, u8 colorA) 776 { 777 m_BufferColor[0] = colorR; 778 m_BufferColor[1] = colorG; 779 m_BufferColor[2] = colorB; 780 m_BufferColor[3] = colorA; 781 } 782 783 #if NN_GD_DOCUMENT_TYPE == ENGLISH 784 /* Please see man pages for details 785 786 787 */ 788 #else 789 /* Please see man pages for details 790 791 792 */ 793 #endif SetCombinerInUse(CombinerStage::UnitId unit,gdBool mode)794 void SetCombinerInUse(CombinerStage::UnitId unit, gdBool mode) 795 { 796 u32 UseId = 1<<unit; 797 798 m_CombinerInUse &= ~(UseId); 799 if (mode == GD_TRUE) m_CombinerInUse |= UseId; 800 } 801 802 #if NN_GD_DOCUMENT_TYPE == ENGLISH 803 /* Please see man pages for details 804 */ 805 #else 806 /* Please see man pages for details 807 */ 808 #endif CombinerDescription()809 CombinerDescription() 810 { 811 ToDefault(); 812 } 813 814 #if NN_GD_DOCUMENT_TYPE == ENGLISH 815 /* Please see man pages for details 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 */ 834 #else 835 /* Please see man pages for details 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 */ 867 #endif ToDefault()868 void ToDefault() 869 { 870 memset(m_CombinerUnit, 0, sizeof(m_CombinerUnit)); 871 872 m_CombinerUnit[0].m_SrcRGB[0] = m_CombinerUnit[0].m_SrcRGB[1] = m_CombinerUnit[0].m_SrcRGB[2] = CombinerStage::SOURCE_CONSTANT; 873 m_CombinerUnit[0].m_SrcAlpha[0] = m_CombinerUnit[0].m_SrcAlpha[1] = m_CombinerUnit[0].m_SrcAlpha[2] = CombinerStage::SOURCE_CONSTANT; 874 875 for (int i = 1; i < CombinerStage::COUNT_TEXTURE_COMBINER_UNITS; i++) 876 { 877 m_CombinerUnit[i].m_SrcRGB[0] = m_CombinerUnit[i].m_SrcRGB[1] = m_CombinerUnit[i].m_SrcRGB[2] = CombinerStage::SOURCE_PREVIOUS; 878 m_CombinerUnit[i].m_SrcAlpha[0] = m_CombinerUnit[i].m_SrcAlpha[1] = m_CombinerUnit[i].m_SrcAlpha[2] = CombinerStage::SOURCE_PREVIOUS; 879 } 880 m_BufferInput.m_Rgb1 = m_BufferInput.m_Rgb2 = m_BufferInput.m_Rgb3 = m_BufferInput.m_Rgb4 = 881 m_BufferInput.m_Alpha1 = m_BufferInput.m_Alpha2 = m_BufferInput.m_Alpha3 = m_BufferInput.m_Alpha4 = CombinerStage::INPUT_PREVIOUS_BUFFER; 882 m_BufferColor[0] = m_BufferColor[1] = m_BufferColor[2] = m_BufferColor[3] = 0; 883 m_CombinerInUse = 0; 884 } 885 886 }; // CombinerDescription; 887 888 } // namespace CTR 889 } // namespace gd 890 } // namespace nn 891 892 893 #endif // NN_GD_CTR_GD_COMBINER_H_ 894