---------------------------------------------------------------------
| 2462 | } |
| 2463 | //--------------------------------------------------------------------- |
| 2464 | void GLRenderSystem::clearFrameBuffer(unsigned int buffers, |
| 2465 | const ColourValue& colour, float depth, unsigned short stencil) |
| 2466 | { |
| 2467 | bool colourMask = |
| 2468 | !(mCurrentBlend.writeR && mCurrentBlend.writeG && mCurrentBlend.writeB && mCurrentBlend.writeA); |
| 2469 | |
| 2470 | if(mCurrentContext) |
| 2471 | mCurrentContext->setCurrent(); |
| 2472 | |
| 2473 | GLbitfield flags = 0; |
| 2474 | if (buffers & FBT_COLOUR) |
| 2475 | { |
| 2476 | flags |= GL_COLOR_BUFFER_BIT; |
| 2477 | // Enable buffer for writing if it isn't |
| 2478 | if (colourMask) |
| 2479 | { |
| 2480 | mStateCacheManager->setColourMask(true, true, true, true); |
| 2481 | } |
| 2482 | mStateCacheManager->setClearColour(colour.r, colour.g, colour.b, colour.a); |
| 2483 | } |
| 2484 | if (buffers & FBT_DEPTH) |
| 2485 | { |
| 2486 | flags |= GL_DEPTH_BUFFER_BIT; |
| 2487 | // Enable buffer for writing if it isn't |
| 2488 | if (!mDepthWrite) |
| 2489 | { |
| 2490 | mStateCacheManager->setDepthMask( GL_TRUE ); |
| 2491 | } |
| 2492 | mStateCacheManager->setClearDepth(depth); |
| 2493 | } |
| 2494 | if (buffers & FBT_STENCIL) |
| 2495 | { |
| 2496 | flags |= GL_STENCIL_BUFFER_BIT; |
| 2497 | // Enable buffer for writing if it isn't |
| 2498 | mStateCacheManager->setStencilMask(0xFFFFFFFF); |
| 2499 | |
| 2500 | glClearStencil(stencil); |
| 2501 | } |
| 2502 | |
| 2503 | Rect vpRect = mActiveViewport->getActualDimensions(); |
| 2504 | bool needScissorBox = |
| 2505 | vpRect != Rect(0, 0, mActiveRenderTarget->getWidth(), mActiveRenderTarget->getHeight()); |
| 2506 | if (needScissorBox) |
| 2507 | { |
| 2508 | // Should be enable scissor test due the clear region is |
| 2509 | // relied on scissor box bounds. |
| 2510 | setScissorTest(true, vpRect); |
| 2511 | } |
| 2512 | |
| 2513 | // Clear buffers |
| 2514 | glClear(flags); |
| 2515 | |
| 2516 | // Restore scissor test |
| 2517 | if (needScissorBox) |
| 2518 | { |
| 2519 | setScissorTest(false); |
| 2520 | } |
| 2521 |