| 743 | /// @endcond |
| 744 | |
| 745 | void Renderer::SortPrimitives() { |
| 746 | if( m_primitives_sorted ) { |
| 747 | return; |
| 748 | } |
| 749 | |
| 750 | std::size_t current_position = 1; |
| 751 | std::size_t sort_index; |
| 752 | |
| 753 | auto primitives_size = m_primitives.size(); |
| 754 | |
| 755 | // Classic insertion sort. |
| 756 | while( current_position < primitives_size ) { |
| 757 | sort_index = current_position++; |
| 758 | |
| 759 | while( ( sort_index > 0 ) && ( m_primitives[sort_index - 1]->GetLayer() * 1048576 + m_primitives[sort_index - 1]->GetLevel() > m_primitives[sort_index]->GetLayer() * 1048576 + m_primitives[sort_index]->GetLevel() ) ) { |
| 760 | m_primitives[sort_index].swap( m_primitives[sort_index - 1] ); |
| 761 | --sort_index; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | m_primitives_sorted = true; |
| 766 | } |
| 767 | |
| 768 | void Renderer::AddPrimitive( Primitive::Ptr primitive ) { |
| 769 | m_primitives.push_back( primitive ); |