1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: gr_RenderState.h 4 5 Copyright (C)2009-2012 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 $Rev: 47904 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NN_GR_CTR_GR_RENDER_STATE_H_ 17 #define NN_GR_CTR_GR_RENDER_STATE_H_ 18 19 #include <nn/gr/CTR/gr_Utility.h> 20 21 namespace nn 22 { 23 namespace gr 24 { 25 namespace CTR 26 { 27 28 /* Please see man pages for details 29 30 */ 31 class RenderState 32 { 33 public : 34 /* Please see man pages for details 35 36 */ 37 enum ColorMask 38 { 39 // 40 COLOR_MASK_R = 1 << 0, 41 // 42 COLOR_MASK_G = 1 << 1, 43 // 44 COLOR_MASK_B = 1 << 2, 45 // 46 COLOR_MASK_A = 1 << 3, 47 // 48 COLOR_MASK_RGBA = COLOR_MASK_R | COLOR_MASK_G | COLOR_MASK_B | COLOR_MASK_A 49 }; 50 51 /* Please see man pages for details 52 53 */ 54 /* 55 By setting each value and calling the MakeCommand function, the render command can be generated. 56 */ 57 class AlphaTest 58 { 59 public : 60 /* Please see man pages for details 61 62 63 64 65 */ 66 bool isEnable; 67 68 /* Please see man pages for details 69 70 71 72 73 */ 74 u8 refValue; 75 76 /* Please see man pages for details 77 78 79 80 */ 81 PicaDataAlphaTest func; 82 83 NN_PADDING1; 84 85 public : 86 /* Please see man pages for details 87 88 89 90 */ 91 explicit AlphaTest( const RenderState& renderState_ ); 92 93 /* Please see man pages for details 94 95 96 97 98 99 100 */ 101 bit32* MakeCommand( bit32* command, bool isUpdateFBAccess = true ) const; 102 103 104 /* Please see man pages for details 105 106 107 108 109 110 111 */ 112 static bit32* MakeDisableCommand( bit32* command, bool isClearFrameBufferCache = true ); 113 114 protected: 115 const RenderState& m_RenderState; 116 }; 117 118 /* Please see man pages for details 119 120 121 122 */ 123 class Blend 124 { 125 public : 126 /* Please see man pages for details 127 128 129 130 */ 131 bool isEnable; 132 /* Please see man pages for details 133 134 135 */ 136 PicaDataBlendEquation eqRgb; 137 138 139 /* Please see man pages for details 140 141 142 */ 143 PicaDataBlendEquation eqAlpha; 144 145 /* Please see man pages for details 146 147 148 149 */ 150 PicaDataBlendFunc srcRgb; 151 152 /* Please see man pages for details 153 154 155 156 */ 157 PicaDataBlendFunc srcAlpha; 158 159 160 /* Please see man pages for details 161 162 163 164 */ 165 PicaDataBlendFunc dstRgb; 166 167 /* Please see man pages for details 168 169 170 171 */ 172 PicaDataBlendFunc dstAlpha; 173 174 175 /* Please see man pages for details 176 177 178 179 */ 180 u8 colorR; 181 182 183 /* Please see man pages for details 184 185 186 187 */ 188 u8 colorG; 189 190 191 /* Please see man pages for details 192 193 194 195 */ 196 u8 colorB; 197 198 199 /* Please see man pages for details 200 201 202 */ 203 u8 colorA; 204 205 NN_PADDING1; 206 207 public : 208 /* Please see man pages for details 209 210 211 212 */ 213 explicit Blend( const RenderState& renderState_ ); 214 215 216 /* Please see man pages for details 217 218 219 220 221 222 223 */ 224 bit32* MakeCommand( bit32* command, bool isUpdateFBAccess = true ) const; 225 226 /* Please see man pages for details 227 228 229 230 231 232 233 */ 234 static bit32* MakeDisableCommand( bit32* command, bool isClearFrameBufferCache = true ); 235 236 protected: 237 const RenderState& m_RenderState; 238 239 }; 240 241 /* Please see man pages for details 242 243 244 245 */ 246 class LogicOp 247 { 248 public : 249 /* Please see man pages for details 250 251 252 */ 253 bool isEnable; 254 255 /* Please see man pages for details 256 257 258 259 */ 260 PicaDataLogicOp opCode; 261 262 NN_PADDING2; 263 264 public : 265 /* Please see man pages for details 266 267 268 269 */ 270 explicit LogicOp( const RenderState& renderState_ ); 271 272 /* Please see man pages for details 273 274 275 276 277 278 279 */ 280 bit32* MakeCommand( bit32* command, bool isUpdateFBAccess = true ) const; 281 282 protected: 283 const RenderState& m_RenderState; 284 }; 285 286 /* Please see man pages for details 287 288 289 290 */ 291 class ShadowMap 292 { 293 public : 294 /* Please see man pages for details 295 296 297 298 */ 299 explicit ShadowMap( const RenderState& renderState_ ); 300 301 /* Please see man pages for details 302 303 304 305 306 307 308 309 */ 310 bit32* MakeCommand( bit32* command, 311 bool isUpdateFBAccess = true, 312 bool isAddDummyCommand = true ) const; 313 314 /* Please see man pages for details 315 316 317 318 319 320 321 */ 322 bit32* MakeTextureCommand( bit32* command, 323 bool isAddDummyCommand = true ) const; 324 325 /* Please see man pages for details 326 327 328 329 330 331 */ 332 bit32* MakeAttenuationCommand( bit32* command ) const; 333 334 /* Please see man pages for details 335 336 337 338 339 340 341 */ 342 bool isEnable; 343 344 /* Please see man pages for details 345 346 347 348 */ 349 bool isPerspective; 350 NN_PADDING2; 351 352 /* Please see man pages for details 353 354 355 356 357 */ 358 f32 zBias; 359 360 361 /* Please see man pages for details 362 363 364 365 366 */ 367 f32 zScale; 368 369 /* Please see man pages for details 370 371 372 373 */ 374 f32 penumbraScale; 375 376 /* Please see man pages for details 377 378 379 380 */ 381 f32 penumbraBias; 382 383 protected: 384 const RenderState& m_RenderState; 385 }; 386 387 /* Please see man pages for details 388 389 */ 390 class StencilTest 391 { 392 public : 393 /* Please see man pages for details 394 395 */ 396 bool isEnable; 397 398 /* Please see man pages for details 399 400 401 402 */ 403 bit8 maskOp; 404 NN_PADDING2; 405 406 /* Please see man pages for details 407 408 409 410 411 */ 412 PicaDataStencilTest func; 413 NN_PADDING3; 414 415 /* Please see man pages for details 416 417 418 */ 419 bit32 ref; 420 421 422 /* Please see man pages for details 423 424 425 426 */ 427 /* 428 When the stencil buffer value is set to stencil, 429 a comparison is done between ( stencil & mask ) and ( ref & mask ). 430 */ 431 bit32 mask; 432 433 /* Please see man pages for details 434 435 436 437 438 439 */ 440 PicaDataStencilOp opFail; 441 442 443 /* Please see man pages for details 444 445 446 447 448 449 */ 450 PicaDataStencilOp opZFail; 451 452 /* Please see man pages for details 453 454 455 456 457 */ 458 PicaDataStencilOp opZPass; 459 460 NN_PADDING1; 461 462 public : 463 /* Please see man pages for details 464 465 466 467 */ 468 explicit StencilTest( const RenderState& renderState_ ); 469 470 /* Please see man pages for details 471 472 473 474 475 476 477 */ 478 bit32* MakeCommand( bit32* command, bool isUpdateFBAccess = true ) const; 479 480 /* Please see man pages for details 481 482 483 484 485 486 487 */ 488 static bit32* MakeDisableCommand( bit32* command, bool isClearFrameBufferCache = true ); 489 490 protected: 491 const RenderState& m_RenderState; 492 }; 493 494 /* Please see man pages for details 495 496 */ 497 class DepthTest 498 { 499 public : 500 /* Please see man pages for details 501 502 503 504 505 */ 506 bool isEnable; 507 508 509 /* Please see man pages for details 510 511 512 513 */ 514 bool isEnableWrite; 515 516 /* Please see man pages for details 517 518 519 520 */ 521 PicaDataDepthTest func; 522 523 NN_PADDING1; 524 525 public : 526 /* Please see man pages for details 527 528 529 530 */ 531 explicit DepthTest( const RenderState& renderState_ ); 532 533 534 /* Please see man pages for details 535 536 537 538 539 540 541 542 543 */ 544 bit32* MakeCommand( bit32* command, bool isUpdateFBAccess = true ) const; 545 546 /* Please see man pages for details 547 548 549 550 551 552 553 554 */ 555 static bit32* MakeDisableCommand( bit32* command, bool isClearFrameBufferCache = true ); 556 557 protected: 558 const RenderState& m_RenderState; 559 }; 560 561 /* Please see man pages for details 562 563 */ 564 class WBuffer 565 { 566 public : 567 568 /* Please see man pages for details 569 570 571 */ 572 f32 wScale; 573 574 /* Please see man pages for details 575 576 577 */ 578 bool isEnablePolygonOffset; 579 580 NN_PADDING3; 581 582 /* Please see man pages for details 583 584 585 586 587 588 589 590 591 592 */ 593 594 f32 polygonOffsetUnit; 595 596 /* Please see man pages for details 597 598 599 600 601 602 */ 603 f32 depthRangeNear; 604 605 /* Please see man pages for details 606 607 608 609 610 611 */ 612 f32 depthRangeFar; 613 614 /* Please see man pages for details 615 616 617 618 */ 619 u8 depthRangeBit; 620 621 NN_PADDING3; 622 623 public : 624 /* Please see man pages for details 625 626 */ 627 explicit WBuffer( ); 628 629 /* Please see man pages for details 630 631 632 633 634 635 */ 636 bit32* MakeCommand( bit32* command ) const; 637 }; 638 639 /* Please see man pages for details 640 641 */ 642 class Culling 643 { 644 public : 645 /* Please see man pages for details 646 647 648 649 650 */ 651 bool isEnable; 652 653 /* Please see man pages for details 654 655 */ 656 enum FrontFace 657 { 658 /* Please see man pages for details 659 660 */ 661 FRONT_FACE_CW , 662 663 /* Please see man pages for details 664 665 */ 666 FRONT_FACE_CCW 667 }; 668 669 /* Please see man pages for details 670 671 672 673 */ 674 FrontFace frontFace; 675 676 /* Please see man pages for details 677 678 */ 679 enum CullFace 680 { 681 /* Please see man pages for details 682 683 */ 684 CULL_FACE_FRONT, 685 /* Please see man pages for details 686 687 */ 688 CULL_FACE_BACK 689 }; 690 691 /* Please see man pages for details 692 693 694 695 */ 696 CullFace cullFace; 697 698 NN_PADDING1; 699 700 public : 701 /* Please see man pages for details 702 703 704 705 */ 706 explicit Culling( const RenderState& renderState_ ); 707 708 709 /* Please see man pages for details 710 711 712 713 714 715 */ 716 bit32* MakeCommand( bit32* command, bool isUpdateFBAccess = true ) const; 717 718 /* Please see man pages for details 719 720 721 722 723 724 725 */ 726 static bit32* MakeDisableCommand( bit32* command, bool isClearFrameBufferCache = true ); 727 728 protected: 729 const RenderState& m_RenderState; 730 }; 731 732 /* Please see man pages for details 733 734 */ 735 /* 736 Specifies referencing with constructor because the frame buffer settings depend on the settings of the color mask, blend, logical operations, depth test, and stencil test. 737 738 If there is a change in frame buffer access after generating a command that changes the above settings, a command must be generated using FBAccess::MakeCommand. 739 740 741 */ 742 class FBAccess 743 { 744 public : 745 /* Please see man pages for details 746 747 748 749 750 */ 751 explicit FBAccess( const RenderState& renderState_ ); 752 753 /* Please see man pages for details 754 755 756 757 758 759 760 */ 761 bit32* MakeCommand( bit32* command, bool isClearFrameBufferCache = true ) const; 762 763 /* Please see man pages for details 764 765 766 767 768 769 770 */ 771 static bit32* MakeDisableCommand( bit32* command, bool isClearFrameBufferCache = true ); 772 773 /* Please see man pages for details 774 775 776 777 778 779 */ 780 static bit32* MakeClearCacheCommand( bit32* command ); 781 782 protected: 783 const RenderState& m_RenderState; 784 }; 785 786 public : 787 /* Please see man pages for details 788 789 790 791 792 */ 793 Blend blend; 794 795 /* Please see man pages for details 796 797 798 799 800 */ 801 LogicOp logicOp; 802 803 /* Please see man pages for details 804 805 806 807 */ 808 ShadowMap shadowMap; 809 810 /* Please see man pages for details 811 812 813 */ 814 AlphaTest alphaTest; 815 816 /* Please see man pages for details 817 818 819 */ 820 StencilTest stencilTest; 821 822 /* Please see man pages for details 823 824 825 */ 826 ColorMask colorMask; 827 NN_PADDING3; 828 829 /* Please see man pages for details 830 831 832 833 834 */ 835 DepthTest depthTest; 836 837 /* Please see man pages for details 838 839 840 841 842 */ 843 Culling cullingTest; 844 845 /* Please see man pages for details 846 847 848 849 850 */ 851 WBuffer wBuffer; 852 853 /* Please see man pages for details 854 855 856 857 */ 858 FBAccess fbAccess; 859 860 public : 861 /* Please see man pages for details 862 863 864 865 866 867 868 869 870 871 872 873 */ 874 explicit RenderState(); 875 876 /* Please see man pages for details 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 */ 894 bit32* MakeCommand( bit32* command, bool isClearFrameBufferCache = true ) const; 895 896 /* Please see man pages for details 897 898 899 900 901 902 903 */ 904 static bit32* MakeDisableCommand( bit32* command, bool isClearFrameBufferCache = true ); 905 }; 906 907 } // namespace CTR 908 } // namespace gr 909 } // namespace nn 910 911 #endif // NN_GR_CTR_GR_RENDER_STATE_H_ 912