Compute new sort values for everything that matches tag_mask
| 568 | |
| 569 | // Compute new sort values for everything that matches tag_mask |
| 570 | static void MakeSortBuffer(HRenderContext context, uint32_t tag_count, dmhash_t* tags, SortOrder sort_order) |
| 571 | { |
| 572 | DM_PROFILE("MakeSortBuffer"); |
| 573 | |
| 574 | const uint32_t required_capacity = context->m_RenderListSortIndices.Capacity(); |
| 575 | // SetCapacity does early out if they are the same, so just call anyway. |
| 576 | context->m_RenderListSortBuffer.SetCapacity(required_capacity); |
| 577 | context->m_RenderListSortBuffer.SetSize(0); |
| 578 | context->m_RenderListSortValues.SetCapacity(required_capacity); |
| 579 | context->m_RenderListSortValues.SetSize(context->m_RenderListSortIndices.Size()); |
| 580 | |
| 581 | RenderListSortValue* sort_values = context->m_RenderListSortValues.Begin(); |
| 582 | RenderListEntry* entries = context->m_RenderList.Begin(); |
| 583 | |
| 584 | const Matrix4& transform = context->m_ViewProj; |
| 585 | |
| 586 | float minZW = FLT_MAX; |
| 587 | float maxZW = -FLT_MAX; |
| 588 | |
| 589 | RenderListRange* ranges = context->m_RenderListRanges.Begin(); |
| 590 | uint32_t num_ranges = context->m_RenderListRanges.Size(); |
| 591 | for( uint32_t r = 0; r < num_ranges; ++r) |
| 592 | { |
| 593 | RenderListRange& range = ranges[r]; |
| 594 | |
| 595 | MaterialTagList taglist; |
| 596 | dmRender::GetMaterialTagList(context, range.m_TagListKey, &taglist); |
| 597 | |
| 598 | range.m_Skip = 0; |
| 599 | if (tag_count > 0 && !dmRender::MatchMaterialTags(taglist.m_Count, taglist.m_Tags, tag_count, tags)) |
| 600 | { |
| 601 | range.m_Skip = 1; |
| 602 | continue; |
| 603 | } |
| 604 | |
| 605 | // Write z values... |
| 606 | int num_visibility_skipped = 0; |
| 607 | for (uint32_t i = range.m_Start; i < range.m_Start+range.m_Count; ++i) |
| 608 | { |
| 609 | uint32_t idx = context->m_RenderListSortIndices[i]; |
| 610 | RenderListEntry* entry = &entries[idx]; |
| 611 | if (entry->m_Visibility == dmRender::VISIBILITY_NONE) |
| 612 | { |
| 613 | num_visibility_skipped++; |
| 614 | continue; |
| 615 | } |
| 616 | |
| 617 | if (entry->m_MajorOrder != RENDER_ORDER_WORLD) |
| 618 | { |
| 619 | continue; // Could perhaps break here, if we also sorted on the major order (cost more when I tested it /MAWE) |
| 620 | } |
| 621 | |
| 622 | const Vector4 res = transform * entry->m_WorldPosition; |
| 623 | const float zw = res.getZ() / res.getW(); |
| 624 | sort_values[idx].m_ZW = zw; |
| 625 | if (zw < minZW) minZW = zw; |
| 626 | if (zw > maxZW) maxZW = zw; |
| 627 | } |
no test coverage detected