1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: gr_RenderState.cpp 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: 46347 $ 14 *---------------------------------------------------------------------------*/ 15 16 #include <nn/gr/CTR/gr_RenderState.h> 17 18 namespace nn 19 { 20 namespace gr 21 { 22 namespace CTR 23 { 24 MakeCommand(bit32 * command,bool isUpdateFBAccess) const25 bit32* RenderState::Culling::MakeCommand( bit32* command, bool isUpdateFBAccess ) const 26 { 27 bit32 culling = 0; 28 29 if ( isEnable ) 30 { 31 if ( ( frontFace == FRONT_FACE_CW && cullFace == CULL_FACE_FRONT ) || 32 ( frontFace == FRONT_FACE_CCW && cullFace == CULL_FACE_BACK ) ) 33 { 34 culling = 2; 35 } 36 else 37 { 38 culling = 1; 39 } 40 } 41 42 // 0x040 43 *command++ = culling; 44 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_CULL_FACE ); 45 46 return isUpdateFBAccess ? m_RenderState.fbAccess.MakeCommand( command ) : command; 47 } 48 49 //------------------------------------------------------------------------------ 50 MakeDisableCommand(bit32 * command,bool isClearFrameBufferCache)51 bit32* RenderState::Culling::MakeDisableCommand( bit32* command, bool isClearFrameBufferCache ) 52 { 53 // 0x040 54 *command++ = 0x0; 55 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_CULL_FACE, 0x1 ); 56 57 if ( isClearFrameBufferCache ) 58 { 59 command = FBAccess::MakeClearCacheCommand( command ); 60 } 61 62 return command; 63 } 64 65 //------------------------------------------------------------------------------ 66 MakeCommand(bit32 * command,bool isUpdateFBAccess) const67 bit32* RenderState::Blend::MakeCommand( bit32* command, bool isUpdateFBAccess ) const 68 { 69 if ( isEnable ) 70 { 71 // 0x100 72 *command++ = PICA_CMD_DATA_COLOR_OPERATION( PICA_DATA_FRAGOP_MODE_DMP, PICA_DATA_ENABLE_BLEND ); 73 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_COLOR_OPERATION, 0x3 ); 74 75 // 0x101 76 *command++ = PICA_CMD_DATA_BLEND_FUNC_SEPARATE( eqRgb, eqAlpha, srcRgb, dstRgb, srcAlpha, dstAlpha ); 77 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_BLEND_FUNC ); 78 79 // 0x102 80 *command++ = PICA_CMD_DATA_LOGIC_OP( PICA_DATA_LOGIC_NOOP ); 81 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_LOGIC_OP ); 82 83 // 0x103 84 *command++ = colorR | colorG << 8 | colorB << 16 | colorA << 24; 85 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_BLEND_COLOR ); 86 } 87 else 88 { 89 command = Blend::MakeDisableCommand( command, false ); 90 } 91 92 return isUpdateFBAccess ? m_RenderState.fbAccess.MakeCommand( command ) : command; 93 } 94 95 //------------------------------------------------------------------------------ 96 MakeDisableCommand(bit32 * command,bool isClearFrameBufferCache)97 bit32* RenderState::Blend::MakeDisableCommand( bit32* command, bool isClearFrameBufferCache ) 98 { 99 // 0x100 100 *command++ = PICA_CMD_DATA_COLOR_OPERATION( PICA_DATA_FRAGOP_MODE_DMP, PICA_DATA_ENABLE_BLEND ); 101 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_COLOR_OPERATION, 0x3 ); 102 103 // 0x101 104 *command++ = PICA_CMD_DATA_BLEND_FUNC( PICA_DATA_BLEND_EQUATION_ADD, PICA_DATA_BLEND_FUNC_ONE, PICA_DATA_BLEND_FUNC_ZERO ); 105 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_BLEND_FUNC ); 106 107 if ( isClearFrameBufferCache ) 108 { 109 command = FBAccess::MakeClearCacheCommand( command ); 110 } 111 112 return command; 113 } 114 115 //------------------------------------------------------------------------------ 116 MakeCommand(bit32 * command,bool isUpdateFBAccess) const117 bit32* RenderState::LogicOp::MakeCommand( bit32* command, bool isUpdateFBAccess ) const 118 { 119 if ( isEnable ) 120 { 121 // 0x100 122 *command++ = PICA_CMD_DATA_COLOR_OPERATION( PICA_DATA_FRAGOP_MODE_DMP, PICA_DATA_ENABLE_COLOR_LOGIC_OP ); 123 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_COLOR_OPERATION, 0x3 ); 124 125 // 0x101 126 *command++ = PICA_CMD_DATA_LOGIC_OP_ENABLE(); 127 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_BLEND_FUNC ); 128 129 // 0x102 130 *command++ = PICA_CMD_DATA_LOGIC_OP( opCode ); 131 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_LOGIC_OP ); 132 } 133 134 return isUpdateFBAccess ? m_RenderState.fbAccess.MakeCommand( command ) : command; 135 } 136 137 //------------------------------------------------------------------------------ 138 MakeCommand(bit32 * command,bool isUpdateFBAccess,bool isAddDummyCommand) const139 bit32* RenderState::ShadowMap::MakeCommand( bit32* command, 140 bool isUpdateFBAccess, bool isAddDummyCommand ) const 141 { 142 if ( isEnable ) 143 { 144 // 0x100 145 *command++ = PICA_CMD_DATA_COLOR_OPERATION( PICA_DATA_FRAGOP_MODE_SHADOW_DMP, PICA_DATA_ENABLE_BLEND ); 146 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_COLOR_OPERATION, 0x1 ); 147 148 // 0x8b 149 command = MakeTextureCommand( command, isAddDummyCommand ); 150 151 // 0x130 152 command = MakeAttenuationCommand( command ); 153 } 154 155 return isUpdateFBAccess ? m_RenderState.fbAccess.MakeCommand( command ) : command; 156 } 157 158 //------------------------------------------------------------------------------ 159 MakeTextureCommand(bit32 * command,bool isAddDummyCommand) const160 bit32* RenderState::ShadowMap::MakeTextureCommand( bit32* command, bool isAddDummyCommand ) const 161 { 162 // Send a dummy command to 0x080 three times 163 if ( isAddDummyCommand ) 164 { 165 *command++ = 0x0; 166 *command++ = PICA_CMD_HEADER_BURST_BE( PICA_REG_TEXTURE_FUNC, 0x3, 0x0 ); 167 168 *command++ = 0x0; 169 *command++ = 0x0; 170 } 171 172 // Clear the lowest 1 bit and use the upper 23 bits of the 24 bits 173 u32 zBiasFix24 = Float32ToUnsignedFix24( zBias ); 174 zBiasFix24 = zBiasFix24 >> 1; 175 176 // The zScale value is invalid and kept just for compatibility. 177 // (Assigned 0 at this point. ) 178 u8 zScale8 = 0; 179 180 // 0x8b 181 *command++ = 182 PICA_CMD_DATA_TEXTURE_SHADOW( isPerspective, 183 // f32 -> 24bit unsigned, fixed point upper 23 bits 184 zBiasFix24, 185 // zScale value is invalid 186 zScale8 ); 187 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_TEXTURE0_SHADOW ); 188 189 return command; 190 } 191 192 //------------------------------------------------------------------------------ 193 MakeAttenuationCommand(bit32 * command) const194 bit32* RenderState::ShadowMap::MakeAttenuationCommand( bit32* command ) const 195 { 196 // 0x130 197 *command++ = ( Float32ToFloat16( - penumbraScale ) ) << 16 | 198 Float32ToFloat16( penumbraScale + penumbraBias ); 199 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_SHADOW ); 200 201 return command; 202 } 203 204 //------------------------------------------------------------------------------ 205 MakeCommand(bit32 * command,bool isUpdateFBAccess) const206 bit32* RenderState::AlphaTest::MakeCommand( bit32* command, bool isUpdateFBAccess ) const 207 { 208 // 0x104 209 *command++ = PICA_CMD_DATA_FRAGOP_ALPHA_TEST( isEnable, func, refValue ); 210 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_FRAGOP_ALPHA_TEST, 0x3 ); 211 212 return isUpdateFBAccess ? m_RenderState.fbAccess.MakeCommand( command ) : command; 213 } 214 215 //------------------------------------------------------------------------------ 216 MakeDisableCommand(bit32 * command,bool isClearFrameBufferCache)217 bit32* RenderState::AlphaTest::MakeDisableCommand( bit32* command, bool isClearFrameBufferCache ) 218 { 219 // 0x104 220 *command++ = 0x0; 221 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_FRAGOP_ALPHA_TEST, 0x1 ); 222 223 if ( isClearFrameBufferCache ) 224 { 225 command = FBAccess::MakeClearCacheCommand( command ); 226 } 227 228 return command; 229 } 230 231 //------------------------------------------------------------------------------ 232 MakeCommand(bit32 * command,bool isUpdateFBAccess) const233 bit32* RenderState::StencilTest::MakeCommand( bit32* command, bool isUpdateFBAccess ) const 234 { 235 // 0x105 236 *command++ = PICA_CMD_DATA_STENCIL_TEST( isEnable, func, maskOp, ref, mask ); 237 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_STENCIL_TEST ); 238 239 // 0x106 240 *command++ = PICA_CMD_DATA_STENCIL_OP( opFail, opZFail, opZPass ); 241 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_STENCIL_OP ); 242 243 return isUpdateFBAccess ? m_RenderState.fbAccess.MakeCommand( command ) : command; 244 } 245 246 //------------------------------------------------------------------------------ 247 MakeDisableCommand(bit32 * command,bool isClearFrameBufferCache)248 bit32* RenderState::StencilTest::MakeDisableCommand( bit32* command, bool isClearFrameBufferCache ) 249 { 250 // 0x105 251 *command++ = 0x0; 252 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_STENCIL_TEST, 0x1 ); 253 254 if ( isClearFrameBufferCache ) 255 { 256 command = FBAccess::MakeClearCacheCommand( command ); 257 } 258 259 return command; 260 } 261 262 //------------------------------------------------------------------------------ 263 MakeCommand(bit32 * command,bool isUpdateFBAccess) const264 bit32* RenderState::DepthTest::MakeCommand( bit32* command, bool isUpdateFBAccess ) const 265 { 266 // [ 0:7 ] and [12:12] in 0x107 are depth test settings, and [8:11] is the color mask settings. 267 *command++ = PICA_CMD_DATA_DEPTH_COLOR_MASK( isEnable, 268 func, 269 m_RenderState.colorMask & COLOR_MASK_R, 270 m_RenderState.colorMask & COLOR_MASK_G, 271 m_RenderState.colorMask & COLOR_MASK_B, 272 m_RenderState.colorMask & COLOR_MASK_A, 273 isEnableWrite ); 274 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_DEPTH_COLOR_MASK ); 275 276 return isUpdateFBAccess ? m_RenderState.fbAccess.MakeCommand( command ) : command; 277 } 278 279 //------------------------------------------------------------------------------ 280 MakeDisableCommand(bit32 * command,bool isClearFrameBufferCache)281 bit32* RenderState::DepthTest::MakeDisableCommand( bit32* command, bool isClearFrameBufferCache ) 282 { 283 const bool isEnableDepth = false; 284 const PicaDataDepthTest depthFunc = PICA_DATA_DEPTH_TEST_LESS; 285 const bool colorMaskRed = true; 286 const bool colorMaskGreen = true; 287 const bool colorMaskBlue = true; 288 const bool colorMaskAlpha = true; 289 const bool isEnableDepthWrite = false; 290 291 // [ 0:7 ] and [12:12] in 0x107 are depth test settings, and [8:11] is the color mask settings. 292 *command++ = PICA_CMD_DATA_DEPTH_COLOR_MASK( isEnableDepth, 293 depthFunc, 294 colorMaskRed, 295 colorMaskGreen, 296 colorMaskBlue, 297 colorMaskAlpha, 298 isEnableDepthWrite ); 299 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_DEPTH_COLOR_MASK ); 300 301 if ( isClearFrameBufferCache ) 302 { 303 command = FBAccess::MakeClearCacheCommand( command ); 304 } 305 306 return command; 307 } 308 309 //------------------------------------------------------------------------------ 310 MakeCommand(bit32 * command) const311 bit32* RenderState::WBuffer::MakeCommand( bit32* command ) const 312 { 313 // When the w buffer is disabled 314 if ( wScale == 0.0f ) 315 { 316 // 0x6d 317 *command++ = 1; 318 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_WSCALE ); 319 320 // 0x04d 321 *command++ = Float32ToFloat24( depthRangeNear - depthRangeFar ); 322 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_WSCALE_DATA1 ); 323 324 // 0x04e 325 // Set the polygon offset 326 f32 zNear = isEnablePolygonOffset ? 327 // To prevent the value from disappearing completely due to errors at the limits of 24-bit float precision, the value is multiplied by 128.0f as a reference depth value in the neighborhood of 0.5f. 328 // 329 depthRangeNear - (depthRangeNear - depthRangeFar) * polygonOffsetUnit * 128.0f / f32( (1 << depthRangeBit) - 1) : 330 depthRangeNear; 331 *command++ = Float32ToFloat24( zNear ); 332 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_WSCALE_DATA2 ); 333 } 334 // When the w buffer is enabled 335 else 336 { 337 // 0x6d 338 *command++ = 0; 339 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_WSCALE ); 340 341 // 0x04d 342 *command++ = Float32ToFloat24( - wScale ); 343 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_WSCALE_DATA1 ); 344 345 // 0x04e 346 *command++ = isEnablePolygonOffset ? 347 ( ( depthRangeBit == 24 ) ? 348 // To prevent the value from disappearing completely due to errors at the limits of 24-bit float precision, the value is multiplied by 128.0f as a reference depth value in the neighborhood of 0.5f. 349 // 350 Float32ToFloat24( ( polygonOffsetUnit * 128.0f / f32( (1 << depthRangeBit) - 1 ) ) ): 351 Float32ToFloat24( ( polygonOffsetUnit / f32( (1 << depthRangeBit) - 1 ) ) ) ) 352 : 0.0f; 353 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_WSCALE_DATA2 ); 354 } 355 356 return command; 357 } 358 359 //------------------------------------------------------------------------------ 360 MakeCommand(bit32 * command,bool isClearFrameBufferCache) const361 bit32* RenderState::FBAccess::MakeCommand( bit32* command, bool isClearFrameBufferCache ) const 362 { 363 if ( isClearFrameBufferCache ) 364 { 365 // 0x111 366 *command++ = 0x1; 367 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_COLOR_DEPTH_BUFFER_CLEAR1 ); 368 369 // 0x110 370 *command++ = 0x1; 371 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_COLOR_DEPTH_BUFFER_CLEAR0 ); 372 } 373 374 if ( m_RenderState.shadowMap.isEnable ) 375 { 376 // 0x112 Enable color buffer READ 377 *command++ = 0xf; 378 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_COLOR_BUFFER_READ, 0x1 ); 379 380 // 0x113 Enable color buffer WRITE 381 *command++ = 0xf; 382 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_COLOR_BUFFER_WRITE, 0x1 ); 383 384 // 0x114 Disable depth/stencil buffer READ 385 *command++ = 0x0; 386 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_DEPTH_STENCIL_BUFFER_READ, 0x1 ); 387 388 // 0x115 Disable depth/stencil buffer WRITE 389 *command++ = 0x0; 390 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_DEPTH_STENCIL_BUFFER_WRITE, 0x1 ); 391 } 392 else 393 { 394 // 0x112 395 *command++ = ( (m_RenderState.colorMask && m_RenderState.colorMask != 0xf) || 396 (m_RenderState.colorMask && m_RenderState.blend.isEnable ) || 397 (m_RenderState.colorMask && m_RenderState.logicOp.isEnable ) ) ? 0xf : 0; 398 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_COLOR_BUFFER_READ, 0x1 ); 399 400 // 0x113 401 *command++ = m_RenderState.colorMask ? 0xf : 0; 402 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_COLOR_BUFFER_WRITE, 0x1 ); 403 404 bit32 depth_stencil_read = 0; 405 bit32 depth_stencil_write = 0; 406 407 if ( m_RenderState.depthTest.isEnable ) 408 { 409 if ( m_RenderState.depthTest.isEnableWrite ) 410 { 411 depth_stencil_read |= 2; 412 depth_stencil_write |= 2; 413 } 414 else if ( m_RenderState.colorMask ) 415 { 416 depth_stencil_read |= 2; 417 } 418 } 419 420 if ( m_RenderState.stencilTest.isEnable ) 421 { 422 if ( m_RenderState.stencilTest.maskOp != 0 ) 423 { 424 depth_stencil_read |= 1; 425 depth_stencil_write |= 1; 426 } 427 else if ( m_RenderState.colorMask ) 428 { 429 depth_stencil_read |= 1; 430 } 431 } 432 433 // 0x114 434 *command++ = depth_stencil_read; 435 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_DEPTH_STENCIL_BUFFER_READ, 0x1 ); 436 437 // 0x115 438 *command++ = depth_stencil_write; 439 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_DEPTH_STENCIL_BUFFER_WRITE, 0x1 ); 440 } 441 442 return command; 443 } 444 445 //------------------------------------------------------------------------------ 446 MakeDisableCommand(bit32 * command,bool isClearFrameBufferCache)447 bit32* RenderState::FBAccess::MakeDisableCommand( bit32* command, bool isClearFrameBufferCache ) 448 { 449 if ( isClearFrameBufferCache ) 450 { 451 command = MakeClearCacheCommand( command ); 452 } 453 454 // 0x112 : Color read 455 *command++ = 0xf; 456 *command++ = PICA_CMD_HEADER_BURSTSEQ_BE( PICA_REG_COLOR_BUFFER_READ, 0x4, 0x1 ); 457 458 // 0x113 : Color write 459 *command++ = 0xf; 460 // 0x114 : Depth/Stencil read 461 *command++ = 0x0; 462 463 // 0x115 : Depth/Stencil write 464 *command++ = 0x0; 465 // Padding 466 *command++ = 0x0; 467 468 return command; 469 } 470 471 //------------------------------------------------------------------------------ 472 MakeClearCacheCommand(bit32 * command)473 bit32* RenderState::FBAccess::MakeClearCacheCommand( bit32* command ) 474 { 475 // 0x111 476 *command++ = 0x1; 477 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_COLOR_DEPTH_BUFFER_CLEAR1 ); 478 479 // 0x110 480 *command++ = 0x1; 481 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_COLOR_DEPTH_BUFFER_CLEAR0 ); 482 483 return command; 484 } 485 486 //------------------------------------------------------------------------------ 487 MakeCommand(bit32 * buffer,bool isClearFrameBufferCache) const488 bit32* RenderState::RenderState::MakeCommand( bit32* buffer, bool isClearFrameBufferCache ) const 489 { 490 bit32* command = buffer; 491 492 command = cullingTest.MakeCommand( command, false ); 493 command = blend.MakeCommand( command, false ); 494 command = logicOp.MakeCommand( command, false ); 495 command = shadowMap.MakeCommand( command, false ); 496 command = alphaTest.MakeCommand( command, false ); 497 command = stencilTest.MakeCommand( command, false ); 498 command = depthTest.MakeCommand( command, false ); 499 command = wBuffer.MakeCommand( command ); 500 command = fbAccess.MakeCommand( command, isClearFrameBufferCache ); 501 502 return command; 503 } 504 505 //------------------------------------------------------------------------------ 506 Culling(const RenderState & renderState_)507 RenderState::Culling::Culling( const RenderState& renderState_ ) 508 : isEnable( true ), 509 frontFace( FRONT_FACE_CCW ), 510 cullFace( CULL_FACE_BACK ), 511 m_RenderState( renderState_ ) 512 { 513 } 514 515 //------------------------------------------------------------------------------ 516 Blend(const RenderState & renderState_)517 RenderState::Blend::Blend( const RenderState& renderState_ ) 518 : isEnable( false ), 519 eqRgb ( PICA_DATA_BLEND_EQUATION_ADD ), 520 eqAlpha ( PICA_DATA_BLEND_EQUATION_ADD ), 521 srcRgb ( PICA_DATA_BLEND_FUNC_SRC_ALPHA ), 522 srcAlpha( PICA_DATA_BLEND_FUNC_SRC_ALPHA ), 523 dstRgb ( PICA_DATA_BLEND_FUNC_ONE_MINUS_SRC_ALPHA ), 524 dstAlpha( PICA_DATA_BLEND_FUNC_ONE_MINUS_SRC_ALPHA ), 525 colorR( 0xff ), 526 colorG( 0xff ), 527 colorB( 0xff ), 528 colorA( 0xff ), 529 m_RenderState( renderState_ ) 530 { 531 } 532 533 //------------------------------------------------------------------------------ 534 LogicOp(const RenderState & renderState_)535 RenderState::LogicOp::LogicOp( const RenderState& renderState_ ) 536 : isEnable( false ), 537 opCode( PICA_DATA_LOGIC_NOOP ), 538 m_RenderState( renderState_ ) 539 { 540 } 541 542 //------------------------------------------------------------------------------ 543 ShadowMap(const RenderState & renderState_)544 RenderState::ShadowMap::ShadowMap( const RenderState& renderState_ ) 545 : isEnable( false ), 546 isPerspective( true ), 547 zBias( 0.0f ), 548 zScale( 1.0f ), 549 penumbraScale( 0.0f ), 550 penumbraBias( 1.0f ), 551 m_RenderState( renderState_ ) 552 { 553 } 554 555 //------------------------------------------------------------------------------ 556 AlphaTest(const RenderState & renderState_)557 RenderState::AlphaTest::AlphaTest( const RenderState& renderState_ ) 558 : isEnable( false ), 559 refValue( 0 ), 560 func ( PICA_DATA_ALPHA_TEST_NEVER ), 561 m_RenderState( renderState_ ) 562 { 563 } 564 565 //------------------------------------------------------------------------------ 566 StencilTest(const RenderState & renderState_)567 RenderState::StencilTest::StencilTest( const RenderState& renderState_ ) 568 : isEnable ( false ), 569 maskOp ( 0xff ), 570 func ( PICA_DATA_STENCIL_TEST_ALWAYS ), 571 ref ( 0 ), 572 mask ( 0xff ), 573 opFail ( PICA_DATA_STENCIL_OP_KEEP ), 574 opZFail ( PICA_DATA_STENCIL_OP_KEEP ), 575 opZPass ( PICA_DATA_STENCIL_OP_KEEP ), 576 m_RenderState( renderState_ ) 577 { 578 } 579 580 //------------------------------------------------------------------------------ 581 DepthTest(const RenderState & renderState_)582 RenderState::DepthTest::DepthTest( const RenderState& renderState_ ) 583 : isEnable( true ), 584 isEnableWrite( true ), 585 func( PICA_DATA_DEPTH_TEST_LESS ), 586 m_RenderState( renderState_ ) 587 { 588 } 589 590 //------------------------------------------------------------------------------ 591 WBuffer()592 RenderState::WBuffer::WBuffer( ) 593 : wScale( 0.f ), 594 isEnablePolygonOffset( false ), 595 polygonOffsetUnit ( 0.f ), 596 depthRangeNear ( 0.0f ), 597 depthRangeFar ( 1.0f ), 598 depthRangeBit ( 24 ) 599 { 600 } 601 602 //------------------------------------------------------------------------------ 603 FBAccess(const RenderState & renderState_)604 RenderState::FBAccess::FBAccess( const RenderState& renderState_ ) 605 : m_RenderState( renderState_ ) 606 { 607 } 608 609 //------------------------------------------------------------------------------ 610 RenderState()611 RenderState::RenderState() : 612 blend ( *this ), 613 logicOp ( *this ), 614 shadowMap ( *this ), 615 alphaTest ( *this ), 616 stencilTest ( *this ), 617 colorMask ( COLOR_MASK_RGBA ), 618 depthTest ( *this ), 619 cullingTest ( *this ), 620 wBuffer ( ), 621 fbAccess ( *this ) 622 { 623 } 624 625 //------------------------------------------------------------------------------ 626 MakeDisableCommand(bit32 * command,bool isClearFrameBufferCache)627 bit32* RenderState::MakeDisableCommand( bit32* command, bool isClearFrameBufferCache ) 628 { 629 command = Culling::MakeDisableCommand( command, false ); 630 command = Blend::MakeDisableCommand( command, false ); 631 command = AlphaTest::MakeDisableCommand( command, false ); 632 command = StencilTest::MakeDisableCommand( command, false ); 633 command = DepthTest::MakeDisableCommand( command, false ); 634 command = FBAccess::MakeDisableCommand( command, isClearFrameBufferCache ); 635 636 return command; 637 } 638 639 } // namespace CTR 640 } // namespace gr 641 } // namespace nn 642