1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: gr_RenderState.cpp 4 5 Copyright (C)2010 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: 38755 $ 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 bit32 clearMask = 0x00fffffe; 175 zBiasFix24 &= clearMask; 176 177 // The zScale value is invalid and kept just for compatibility. 178 // (Assigned to 0 here.) 179 u8 zScale8 = 0; 180 181 // 0x8b 182 *command++ = 183 PICA_CMD_DATA_TEXTURE_SHADOW( isPerspective, 184 // f32 -> 24bit unsigned, fixed point upper 23 bits 185 zBiasFix24, 186 // zScale value is invalid 187 zScale8 ); 188 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_TEXTURE0_SHADOW ); 189 190 return command; 191 } 192 193 //------------------------------------------------------------------------------ 194 MakeAttenuationCommand(bit32 * command) const195 bit32* RenderState::ShadowMap::MakeAttenuationCommand( bit32* command ) const 196 { 197 // 0x130 198 *command++ = ( Float32ToFloat16( - penumbraScale ) ) << 16 | 199 Float32ToFloat16( penumbraScale + penumbraBias ); 200 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_SHADOW ); 201 202 return command; 203 } 204 205 //------------------------------------------------------------------------------ 206 MakeCommand(bit32 * command,bool isUpdateFBAccess) const207 bit32* RenderState::AlphaTest::MakeCommand( bit32* command, bool isUpdateFBAccess ) const 208 { 209 // 0x104 210 *command++ = PICA_CMD_DATA_FRAGOP_ALPHA_TEST( isEnable, func, refValue ); 211 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_FRAGOP_ALPHA_TEST, 0x3 ); 212 213 return isUpdateFBAccess ? m_RenderState.fbAccess.MakeCommand( command ) : command; 214 } 215 216 //------------------------------------------------------------------------------ 217 MakeDisableCommand(bit32 * command,bool isClearFrameBufferCache)218 bit32* RenderState::AlphaTest::MakeDisableCommand( bit32* command, bool isClearFrameBufferCache ) 219 { 220 // 0x104 221 *command++ = 0x0; 222 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_FRAGOP_ALPHA_TEST, 0x1 ); 223 224 if ( isClearFrameBufferCache ) 225 { 226 command = FBAccess::MakeClearCacheCommand( command ); 227 } 228 229 return command; 230 } 231 232 //------------------------------------------------------------------------------ 233 MakeCommand(bit32 * command,bool isUpdateFBAccess) const234 bit32* RenderState::StencilTest::MakeCommand( bit32* command, bool isUpdateFBAccess ) const 235 { 236 // 0x105 237 *command++ = PICA_CMD_DATA_STENCIL_TEST( isEnable, func, maskOp, ref, mask ); 238 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_STENCIL_TEST ); 239 240 // 0x106 241 *command++ = PICA_CMD_DATA_STENCIL_OP( opFail, opZFail, opZPass ); 242 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_STENCIL_OP ); 243 244 return isUpdateFBAccess ? m_RenderState.fbAccess.MakeCommand( command ) : command; 245 } 246 247 //------------------------------------------------------------------------------ 248 MakeDisableCommand(bit32 * command,bool isClearFrameBufferCache)249 bit32* RenderState::StencilTest::MakeDisableCommand( bit32* command, bool isClearFrameBufferCache ) 250 { 251 // 0x105 252 *command++ = 0x0; 253 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_STENCIL_TEST, 0x1 ); 254 255 if ( isClearFrameBufferCache ) 256 { 257 command = FBAccess::MakeClearCacheCommand( command ); 258 } 259 260 return command; 261 } 262 263 //------------------------------------------------------------------------------ 264 MakeCommand(bit32 * command,bool isUpdateFBAccess) const265 bit32* RenderState::DepthTest::MakeCommand( bit32* command, bool isUpdateFBAccess ) const 266 { 267 // [ 0:7 ] and [12:12] in 0x107 are depth test settings, and [8:11] is the color mask settings. 268 *command++ = PICA_CMD_DATA_DEPTH_COLOR_MASK( isEnable, 269 func, 270 m_RenderState.colorMask & COLOR_MASK_R, 271 m_RenderState.colorMask & COLOR_MASK_G, 272 m_RenderState.colorMask & COLOR_MASK_B, 273 m_RenderState.colorMask & COLOR_MASK_A, 274 isEnableWrite ); 275 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_DEPTH_COLOR_MASK ); 276 277 return isUpdateFBAccess ? m_RenderState.fbAccess.MakeCommand( command ) : command; 278 } 279 280 //------------------------------------------------------------------------------ 281 MakeDisableCommand(bit32 * command,bool isClearFrameBufferCache)282 bit32* RenderState::DepthTest::MakeDisableCommand( bit32* command, bool isClearFrameBufferCache ) 283 { 284 const bool isEnableDepth = false; 285 const PicaDataDepthTest depthFunc = PICA_DATA_DEPTH_TEST_LESS; 286 const bool colorMaskRed = true; 287 const bool colorMaskGreen = true; 288 const bool colorMaskBlue = true; 289 const bool colorMaskAlpha = true; 290 const bool isEnableDepthWrite = false; 291 292 // [ 0:7 ] and [12:12] in 0x107 are depth test settings, and [8:11] is the color mask settings. 293 *command++ = PICA_CMD_DATA_DEPTH_COLOR_MASK( isEnableDepth, 294 depthFunc, 295 colorMaskRed, 296 colorMaskGreen, 297 colorMaskBlue, 298 colorMaskAlpha, 299 isEnableDepthWrite ); 300 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_DEPTH_COLOR_MASK ); 301 302 if ( isClearFrameBufferCache ) 303 { 304 command = FBAccess::MakeClearCacheCommand( command ); 305 } 306 307 return command; 308 } 309 310 //------------------------------------------------------------------------------ 311 MakeCommand(bit32 * command,bool isUpdateFBAccess) const312 bit32* RenderState::WBuffer::MakeCommand( bit32* command, bool isUpdateFBAccess ) const 313 { 314 // When the w buffer is disabled 315 if ( wScale == 0.0f ) 316 { 317 // 0x6d 318 *command++ = 1; 319 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_WSCALE ); 320 321 // 0x04d 322 *command++ = Float32ToFloat24( depthRangeNear - depthRangeFar ); 323 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_WSCALE_DATA1 ); 324 325 // 0x04e 326 // Set the polygon offset 327 f32 zNear = isEnablePolygonOffset ? 328 depthRangeNear - (depthRangeNear - depthRangeFar) * polygonOffsetUnit / f32( (1 << depthRangeBit) - 1) : 329 depthRangeNear; 330 *command++ = Float32ToFloat24( zNear ); 331 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_WSCALE_DATA2 ); 332 } 333 // When the w buffer is enabled 334 else 335 { 336 // 0x6d 337 *command++ = 0; 338 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_WSCALE ); 339 340 // 0x04d 341 *command++ = Float32ToFloat24( - wScale ); 342 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_WSCALE_DATA1 ); 343 344 // 0x04e 345 *command++ = isEnablePolygonOffset ? 346 ( ( depthRangeBit == 24 ) ? 347 // To avoid loss of data due to the precision of the 24-bit float type, multiply by 128.0f using a value near 0.5f as the baseline depth value. 348 // 349 ( polygonOffsetUnit * 128.0f / f32( (1 << depthRangeBit) - 1 ) ) : 350 ( polygonOffsetUnit / f32( (1 << depthRangeBit) - 1 ) ) ) 351 : 0.0f; 352 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_FRAGOP_WSCALE_DATA2 ); 353 } 354 355 return isUpdateFBAccess ? m_RenderState.fbAccess.MakeCommand( command ) : command; 356 } 357 358 //------------------------------------------------------------------------------ 359 MakeCommand(bit32 * command,bool isClearFrameBufferCache) const360 bit32* RenderState::FBAccess::MakeCommand( bit32* command, bool isClearFrameBufferCache ) const 361 { 362 if ( isClearFrameBufferCache ) 363 { 364 // 0x111 365 *command++ = 0x1; 366 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_COLOR_DEPTH_BUFFER_CLEAR1 ); 367 368 // 0x110 369 *command++ = 0x1; 370 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_COLOR_DEPTH_BUFFER_CLEAR0 ); 371 } 372 373 if ( m_RenderState.shadowMap.isEnable ) 374 { 375 // 0x112 Enable color buffer READ 376 *command++ = 0xf; 377 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_COLOR_BUFFER_READ, 0x1 ); 378 379 // 0x113 Enable color buffer WRITE 380 *command++ = 0xf; 381 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_COLOR_BUFFER_WRITE, 0x1 ); 382 383 // 0x114 Enable depth/stencil buffer READ 384 *command++ = 0x0; 385 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_DEPTH_STENCIL_BUFFER_READ, 0x1 ); 386 387 // 0x115 Enable depth/stencil buffer WRITE 388 *command++ = 0x0; 389 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_DEPTH_STENCIL_BUFFER_WRITE, 0x1 ); 390 } 391 else 392 { 393 // 0x112 394 *command++ = ( (m_RenderState.colorMask && m_RenderState.colorMask != 0xf) || 395 (m_RenderState.colorMask && m_RenderState.blend.isEnable ) || 396 (m_RenderState.colorMask && m_RenderState.logicOp.isEnable ) ) ? 0xf : 0; 397 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_COLOR_BUFFER_READ, 0x1 ); 398 399 // 0x113 400 *command++ = m_RenderState.colorMask ? 0xf : 0; 401 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_COLOR_BUFFER_WRITE, 0x1 ); 402 403 bit32 depth_stencil_read = 0; 404 bit32 depth_stencil_write = 0; 405 406 if ( m_RenderState.depthTest.isEnable ) 407 { 408 if ( m_RenderState.depthTest.isEnableWrite ) 409 { 410 depth_stencil_read |= 2; 411 depth_stencil_write |= 2; 412 } 413 else if ( m_RenderState.colorMask ) 414 { 415 depth_stencil_read |= 2; 416 } 417 } 418 419 if ( m_RenderState.stencilTest.isEnable ) 420 { 421 if ( m_RenderState.stencilTest.maskOp != 0 ) 422 { 423 depth_stencil_read |= 1; 424 depth_stencil_write |= 1; 425 } 426 else if ( m_RenderState.colorMask ) 427 { 428 depth_stencil_read |= 1; 429 } 430 } 431 432 // 0x114 433 *command++ = depth_stencil_read; 434 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_DEPTH_STENCIL_BUFFER_READ, 0x1 ); 435 436 // 0x115 437 *command++ = depth_stencil_write; 438 *command++ = PICA_CMD_HEADER_SINGLE_BE( PICA_REG_DEPTH_STENCIL_BUFFER_WRITE, 0x1 ); 439 } 440 441 return command; 442 } 443 444 //------------------------------------------------------------------------------ 445 MakeDisableCommand(bit32 * command,bool isClearFrameBufferCache)446 bit32* RenderState::FBAccess::MakeDisableCommand( bit32* command, bool isClearFrameBufferCache ) 447 { 448 if ( isClearFrameBufferCache ) 449 { 450 command = MakeClearCacheCommand( command ); 451 } 452 453 // 0x112 : Color read 454 *command++ = 0xf; 455 *command++ = PICA_CMD_HEADER_BURSTSEQ_BE( PICA_REG_COLOR_BUFFER_READ, 0x4, 0x1 ); 456 457 // 0x113 : Color write 458 *command++ = 0xf; 459 // 0x114 : Depth/Stencil read 460 *command++ = 0x0; 461 462 // 0x115 : Depth/Stencil write 463 *command++ = 0x0; 464 // Padding 465 *command++ = 0x0; 466 467 return command; 468 } 469 470 //------------------------------------------------------------------------------ 471 MakeClearCacheCommand(bit32 * command)472 bit32* RenderState::FBAccess::MakeClearCacheCommand( bit32* command ) 473 { 474 // 0x111 475 *command++ = 0x1; 476 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_COLOR_DEPTH_BUFFER_CLEAR1 ); 477 478 // 0x110 479 *command++ = 0x1; 480 *command++ = PICA_CMD_HEADER_SINGLE( PICA_REG_COLOR_DEPTH_BUFFER_CLEAR0 ); 481 482 return command; 483 } 484 485 //------------------------------------------------------------------------------ 486 MakeCommand(bit32 * buffer,bool isClearFrameBufferCache) const487 bit32* RenderState::RenderState::MakeCommand( bit32* buffer, bool isClearFrameBufferCache ) const 488 { 489 bit32* command = buffer; 490 491 command = cullingTest.MakeCommand( command, false ); 492 command = blend.MakeCommand( command, false ); 493 command = logicOp.MakeCommand( command, false ); 494 command = shadowMap.MakeCommand( command, false ); 495 command = alphaTest.MakeCommand( command, false ); 496 command = stencilTest.MakeCommand( command, false ); 497 command = depthTest.MakeCommand( command, false ); 498 command = wBuffer.MakeCommand( command, false ); 499 command = fbAccess.MakeCommand( command, isClearFrameBufferCache ); 500 501 return command; 502 } 503 504 //------------------------------------------------------------------------------ 505 Culling(const RenderState & renderState_)506 RenderState::Culling::Culling( const RenderState& renderState_ ) 507 : isEnable( true ), 508 frontFace( FRONT_FACE_CCW ), 509 cullFace( CULL_FACE_BACK ), 510 m_RenderState( renderState_ ) 511 { 512 } 513 514 //------------------------------------------------------------------------------ 515 Blend(const RenderState & renderState_)516 RenderState::Blend::Blend( const RenderState& renderState_ ) 517 : isEnable( false ), 518 eqRgb ( PICA_DATA_BLEND_EQUATION_ADD ), 519 eqAlpha ( PICA_DATA_BLEND_EQUATION_ADD ), 520 srcRgb ( PICA_DATA_BLEND_FUNC_SRC_ALPHA ), 521 srcAlpha( PICA_DATA_BLEND_FUNC_SRC_ALPHA ), 522 dstRgb ( PICA_DATA_BLEND_FUNC_ONE_MINUS_SRC_ALPHA ), 523 dstAlpha( PICA_DATA_BLEND_FUNC_ONE_MINUS_SRC_ALPHA ), 524 colorR( 0xff ), 525 colorG( 0xff ), 526 colorB( 0xff ), 527 colorA( 0xff ), 528 m_RenderState( renderState_ ) 529 { 530 } 531 532 //------------------------------------------------------------------------------ 533 LogicOp(const RenderState & renderState_)534 RenderState::LogicOp::LogicOp( const RenderState& renderState_ ) 535 : isEnable( false ), 536 opCode( PICA_DATA_LOGIC_NOOP ), 537 m_RenderState( renderState_ ) 538 { 539 } 540 541 //------------------------------------------------------------------------------ 542 ShadowMap(const RenderState & renderState_)543 RenderState::ShadowMap::ShadowMap( const RenderState& renderState_ ) 544 : isEnable( false ), 545 isPerspective( true ), 546 zBias( 0.0f ), 547 zScale( 1.0f ), 548 penumbraScale( 0.0f ), 549 penumbraBias( 1.0f ), 550 m_RenderState( renderState_ ) 551 { 552 } 553 554 //------------------------------------------------------------------------------ 555 AlphaTest(const RenderState & renderState_)556 RenderState::AlphaTest::AlphaTest( const RenderState& renderState_ ) 557 : isEnable( false ), 558 refValue( 0 ), 559 func ( PICA_DATA_ALPHA_TEST_NEVER ), 560 m_RenderState( renderState_ ) 561 { 562 } 563 564 //------------------------------------------------------------------------------ 565 StencilTest(const RenderState & renderState_)566 RenderState::StencilTest::StencilTest( const RenderState& renderState_ ) 567 : isEnable ( false ), 568 maskOp ( 0xff ), 569 func ( PICA_DATA_STENCIL_TEST_ALWAYS ), 570 ref ( 0 ), 571 mask ( 0xff ), 572 opFail ( PICA_DATA_STENCIL_OP_KEEP ), 573 opZFail ( PICA_DATA_STENCIL_OP_KEEP ), 574 opZPass ( PICA_DATA_STENCIL_OP_KEEP ), 575 m_RenderState( renderState_ ) 576 { 577 } 578 579 //------------------------------------------------------------------------------ 580 DepthTest(const RenderState & renderState_)581 RenderState::DepthTest::DepthTest( const RenderState& renderState_ ) 582 : isEnable( true ), 583 isEnableWrite( true ), 584 func( PICA_DATA_DEPTH_TEST_LESS ), 585 m_RenderState( renderState_ ) 586 { 587 } 588 589 //------------------------------------------------------------------------------ 590 WBuffer(const RenderState & renderState_)591 RenderState::WBuffer::WBuffer( const RenderState& renderState_ ) 592 : wScale( 0.f ), 593 isEnablePolygonOffset( false ), 594 polygonOffsetUnit ( 0.f ), 595 depthRangeNear ( 0.0f ), 596 depthRangeFar ( 1.0f ), 597 depthRangeBit ( 24 ), 598 m_RenderState ( renderState_ ) 599 { 600 } 601 602 603 //------------------------------------------------------------------------------ 604 FBAccess(const RenderState & renderState_)605 RenderState::FBAccess::FBAccess( const RenderState& renderState_ ) 606 : m_RenderState( renderState_ ) 607 { 608 } 609 610 //------------------------------------------------------------------------------ 611 RenderState()612 RenderState::RenderState() : 613 blend ( *this ), 614 logicOp ( *this ), 615 shadowMap ( *this ), 616 alphaTest ( *this ), 617 stencilTest ( *this ), 618 colorMask ( COLOR_MASK_RGBA ), 619 depthTest ( *this ), 620 cullingTest ( *this ), 621 wBuffer ( *this ), 622 fbAccess ( *this ) 623 { 624 } 625 626 //------------------------------------------------------------------------------ 627 MakeDisableCommand(bit32 * command,bool isClearFrameBufferCache)628 bit32* RenderState::MakeDisableCommand( bit32* command, bool isClearFrameBufferCache ) 629 { 630 command = Culling::MakeDisableCommand( command, false ); 631 command = Blend::MakeDisableCommand( command, false ); 632 command = AlphaTest::MakeDisableCommand( command, false ); 633 command = StencilTest::MakeDisableCommand( command, false ); 634 command = DepthTest::MakeDisableCommand( command, false ); 635 command = FBAccess::MakeDisableCommand( command, isClearFrameBufferCache ); 636 637 return command; 638 } 639 640 } // namespace CTR 641 } // namespace gr 642 } // namespace nn 643