| 25 | |
| 26 | template<typename ModelType, typename DrawInfoType, typename ContextType> |
| 27 | FORCE_INLINE void ModelDraw(ModelType* model, const RenderContext& renderContext, const ContextType& context, const DrawInfoType& info) |
| 28 | { |
| 29 | ASSERT(info.Buffer); |
| 30 | if (!model->CanBeRendered()) |
| 31 | return; |
| 32 | if (!info.Buffer->IsValidFor(model)) |
| 33 | info.Buffer->Setup(model); |
| 34 | const auto frame = Engine::FrameCount; |
| 35 | const auto modelFrame = info.DrawState->PrevFrame + 1; |
| 36 | |
| 37 | // Select a proper LOD index (model may be culled) |
| 38 | int32 lodIndex; |
| 39 | if (info.ForcedLOD != -1) |
| 40 | { |
| 41 | lodIndex = info.ForcedLOD; |
| 42 | } |
| 43 | else |
| 44 | { |
| 45 | lodIndex = RenderTools::ComputeModelLOD(model, info.Bounds.Center, (float)info.Bounds.Radius, renderContext); |
| 46 | if (lodIndex == -1) |
| 47 | { |
| 48 | // Handling model fade-out transition |
| 49 | if (modelFrame == frame && info.DrawState->PrevLOD != -1 && !renderContext.View.IsSingleFrame && ModelDrawTransition(model, info)) |
| 50 | { |
| 51 | // Check if start transition |
| 52 | if (info.DrawState->LODTransition == 255) |
| 53 | { |
| 54 | info.DrawState->LODTransition = 0; |
| 55 | } |
| 56 | |
| 57 | RenderTools::UpdateModelLODTransition(info.DrawState->LODTransition); |
| 58 | |
| 59 | // Check if end transition |
| 60 | if (info.DrawState->LODTransition == 255) |
| 61 | { |
| 62 | info.DrawState->PrevLOD = lodIndex; |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | const auto prevLOD = model->ClampLODIndex(info.DrawState->PrevLOD); |
| 67 | const float normalizedProgress = static_cast<float>(info.DrawState->LODTransition) * (1.0f / 255.0f); |
| 68 | model->LODs.Get()[prevLOD].Draw(renderContext, info, normalizedProgress); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | return; |
| 73 | } |
| 74 | } |
| 75 | lodIndex += info.LODBias + renderContext.View.ModelLODBias; |
| 76 | lodIndex = model->ClampLODIndex(lodIndex); |
| 77 | |
| 78 | if (renderContext.View.IsSingleFrame) |
| 79 | { |
| 80 | } |
| 81 | // Check if it's the new frame and could update the drawing state (note: model instance could be rendered many times per frame to different viewports) |
| 82 | else if (modelFrame == frame) |
| 83 | { |
| 84 | // Check if materials use transition |
no test coverage detected