-bool GetDamagedRect( Rect<int32_t> &viewportRect, RenderInstruction& instruction, Rect<int32_t> &damagedRect )
-{
- // merge bounding
- int dx1 = viewportRect.width, dx2 = 0, dy1 = viewportRect.height, dy2 = 0;
- int checkWidth = static_cast<int>( static_cast<float>( viewportRect.width ) * partialUpdateRatio );
- int checkHeight = static_cast<int>( static_cast<float>( viewportRect.height ) * partialUpdateRatio );
- Rect<int32_t> screenRect;
-
- bool isPartialUpdate = false;
-
- const RenderListContainer::SizeType renderListCount = instruction.RenderListCount();
- // Iterate through each render list.
-
- for( RenderListContainer::SizeType index = 0; index < renderListCount; ++index )
- {
- const RenderList* renderList = instruction.GetRenderList( index );
-
- if( renderList && !renderList->IsEmpty() && renderList->IsPartialUpdateEnabled() )
- {
- const std::size_t itemCount = renderList->Count();
- for( uint32_t itemIndex = 0u; itemIndex < itemCount; ++itemIndex )
- {
- const RenderItem& item = renderList->GetItem( itemIndex );
-
- if( item.mPartialUpdateEnabled )
- {
- isPartialUpdate = true;
-
- screenRect = item.CalculateViewportSpaceAABB( viewportRect.width, viewportRect.height, true );
-
- dx1 = std::min( screenRect.x, dx1 );
- dx2 = std::max( screenRect.x + screenRect.width, dx2);
- dy1 = std::min( screenRect.y, dy1 );
- dy2 = std::max( screenRect.y + screenRect.height, dy2 );
-
- if( ( dx2 - dx1 ) > checkWidth && ( dy2 - dy1 ) > checkHeight )
- {
- return false;
- }
- }
- }
- }
- }
-
- if( isPartialUpdate )
- {
- damagedRect.x = dx1 - partialUpdateMargin;
- damagedRect.y = dy1 - partialUpdateMargin;
- damagedRect.width = dx2 - dx1 + ( 2 * partialUpdateMargin );
- damagedRect.height = dy2 - dy1 + ( 2 * partialUpdateMargin );
- }
-
- return isPartialUpdate;
-}
-