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

Method DrawImpl

Source/Engine/Terrain/Terrain.cpp:617–658  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

615}
616
617void Terrain::DrawImpl(RenderContext& renderContext, HashSet<TerrainChunk*, RendererAllocation>& drawnChunks)
618{
619 // Collect chunks to render and calculate LOD/material for them (required to be done before to gather NeighborLOD)
620 Array<TerrainChunk*, RendererAllocation> drawChunks;
621
622 // Frustum vs Box culling for patches
623 const BoundingFrustum frustum = renderContext.View.CullingFrustum;
624 const Vector3 origin = renderContext.View.Origin;
625 for (int32 patchIndex = 0; patchIndex < _patches.Count(); patchIndex++)
626 {
627 const auto patch = _patches[patchIndex];
628 BoundingBox bounds(patch->_bounds.Minimum - origin, patch->_bounds.Maximum - origin);
629 if (renderContext.View.IsCullingDisabled || frustum.Intersects(bounds))
630 {
631 // Skip if has no heightmap or it's not loaded
632 if (patch->Heightmap == nullptr || patch->Heightmap->GetTexture()->ResidentMipLevels() == 0)
633 continue;
634
635 // Frustum vs Box culling for chunks
636 for (int32 chunkIndex = 0; chunkIndex < Terrain::ChunksCount; chunkIndex++)
637 {
638 auto chunk = &patch->Chunks[chunkIndex];
639 bounds = BoundingBox(chunk->_bounds.Minimum - origin, chunk->_bounds.Maximum - origin);
640 if (renderContext.View.IsCullingDisabled || frustum.Intersects(bounds))
641 {
642 if (!drawnChunks.Contains(chunk) && !chunk->PrepareDraw(renderContext))
643 continue;
644
645 // Add chunk for drawing
646 drawChunks.Add(chunk);
647 drawnChunks.Add(chunk);
648 }
649 }
650 }
651 }
652
653 // Draw all visible chunks
654 for (int32 i = 0; i < drawChunks.Count(); i++)
655 {
656 drawChunks.Get()[i]->Draw(renderContext);
657 }
658}
659
660#if USE_EDITOR
661

Callers

nothing calls this directly

Calls 9

GetTextureMethod · 0.80
PrepareDrawMethod · 0.80
BoundingBoxClass · 0.50
CountMethod · 0.45
IntersectsMethod · 0.45
ContainsMethod · 0.45
AddMethod · 0.45
DrawMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected