MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / CalculateSortKey

Function CalculateSortKey

Source/Engine/Renderer/RenderList.cpp:634–657  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

632static_assert(sizeof(PackedSortKeyDistance) == sizeof(uint64), "Invalid sort key size");
633
634FORCE_INLINE void CalculateSortKey(const RenderContext& renderContext, DrawCall& drawCall, int8 sortOrder)
635{
636 const Float3 planeNormal = renderContext.View.Direction;
637 const float planePoint = -Float3::Dot(planeNormal, renderContext.View.Position);
638 const float distance = Float3::Dot(planeNormal, drawCall.ObjectPosition) - planePoint;
639 uint32 distanceKey = RenderTools::ComputeDistanceSortKey(distance);
640 uint32 batchKey = GetHash(drawCall.Material);
641 IMaterial::InstancingHandler handler;
642 if (drawCall.Material->CanUseInstancing(handler))
643 handler.GetHash(drawCall, batchKey);
644 batchKey = (batchKey * 397) ^ drawCall.StencilValue;
645 uint32 drawKey = (uint32)(471 * drawCall.WorldDeterminant);
646 drawKey = (drawKey * 397) ^ GetHash(drawCall.Geometry.VertexBuffers[0]);
647 drawKey = (drawKey * 397) ^ GetHash(drawCall.Geometry.VertexBuffers[1]);
648 drawKey = (drawKey * 397) ^ GetHash(drawCall.Geometry.VertexBuffers[2]);
649 drawKey = (drawKey * 397) ^ GetHash(drawCall.Geometry.IndexBuffer);
650
651 PackedSortKey key;
652 key.BatchKey = (uint16)batchKey;
653 key.DistanceKey = distanceKey;
654 key.DrawKey = (uint8)drawKey;
655 key.SortKey = (uint8)(sortOrder - MIN_int8);
656 drawCall.SortKey = *(uint64*)&key;
657}
658
659void RenderList::AddDrawCall(const RenderContext& renderContext, DrawPass drawModes, StaticFlags staticFlags, DrawCall& drawCall, bool receivesDecals, int8 sortOrder)
660{

Callers 1

AddDrawCallMethod · 0.85

Calls 5

DotFunction · 0.85
ComputeDistanceSortKeyFunction · 0.85
GetHashFunction · 0.70
CanUseInstancingMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected