+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 )
+ {
+ if( dx1 < 0.0f )
+ {
+ dx1 = 0.0f;
+ }
+ if( dy1 < 0.0f )
+ {
+ dy1 = 0.0f;
+ }
+ if( dx2 > viewportRect.width )
+ {
+ dx2 = viewportRect.width;
+ }
+ if( dy2 > viewportRect.height )
+ {
+ dy2 = viewportRect.height;
+ }
+
+ damagedRect.x = dx1;
+ damagedRect.y = dy1;
+ damagedRect.width = dx2 - dx1;
+ damagedRect.height = dy2 - dy1;
+ }
+
+ return isPartialUpdate;
+}
+