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