| 1135 | #endif |
| 1136 | |
| 1137 | void Particles::DrawParticles(RenderContextBatch& renderContextBatch, ParticleEffect* effect) |
| 1138 | { |
| 1139 | PROFILE_CPU(); |
| 1140 | PROFILE_MEM(Particles); |
| 1141 | |
| 1142 | // Drawing assumes that all views within a batch have the same Origin |
| 1143 | const Vector3& viewOrigin = renderContextBatch.GetMainContext().View.Origin; |
| 1144 | BoundingSphere bounds = effect->GetSphere(); |
| 1145 | bounds.Center -= viewOrigin; |
| 1146 | |
| 1147 | // Cull particles against all views |
| 1148 | bool drawAnyView = false, drawMainView = false; |
| 1149 | DrawPass viewsDrawModes = DrawPass::None; |
| 1150 | for (int32 i = 0; i < renderContextBatch.Contexts.Count(); i++) |
| 1151 | { |
| 1152 | const RenderView& view = renderContextBatch.Contexts.Get()[i].View; |
| 1153 | const bool visible = (view.Pass & effect->DrawModes) != DrawPass::None && (view.IsCullingDisabled || view.CullingFrustum.Intersects(bounds)); |
| 1154 | if (visible) |
| 1155 | { |
| 1156 | drawAnyView = true; |
| 1157 | drawMainView |= i == 0; |
| 1158 | viewsDrawModes |= view.Pass; |
| 1159 | } |
| 1160 | } |
| 1161 | if (drawAnyView == false) |
| 1162 | return; |
| 1163 | viewsDrawModes &= effect->DrawModes; |
| 1164 | |
| 1165 | // Setup |
| 1166 | ScopeReadLock systemScope(SystemLocker); |
| 1167 | Matrix worlds[2]; |
| 1168 | Matrix::Translation(-viewOrigin, worlds[0]); // World |
| 1169 | renderContextBatch.GetMainContext().View.GetWorldMatrix(effect->GetTransform(), worlds[1]); // Local |
| 1170 | const StaticFlags staticFlags = effect->GetStaticFlags(); |
| 1171 | const int8 sortOrder = effect->SortOrder; |
| 1172 | |
| 1173 | // Draw lights (only to into the main view) |
| 1174 | if (drawMainView && renderContextBatch.GetMainContext().View.Pass != DrawPass::Depth) |
| 1175 | { |
| 1176 | for (int32 emitterIndex = 0; emitterIndex < effect->Instance.Emitters.Count(); emitterIndex++) |
| 1177 | { |
| 1178 | auto& emitterData = effect->Instance.Emitters[emitterIndex]; |
| 1179 | const auto buffer = emitterData.Buffer; |
| 1180 | if (!buffer || (buffer->Mode == ParticlesSimulationMode::CPU && buffer->CPU.Count == 0)) |
| 1181 | continue; |
| 1182 | auto emitter = buffer->Emitter; |
| 1183 | if (!emitter || !emitter->IsLoaded()) |
| 1184 | continue; |
| 1185 | |
| 1186 | buffer->Emitter->GraphExecutorCPU.Draw(buffer->Emitter, effect, emitterData, renderContextBatch.GetMainContext(), worlds[(int32)emitter->SimulationSpace]); |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | // Setup a draw call common data |
| 1191 | DrawCall drawCall; |
| 1192 | drawCall.PerInstanceRandom = effect->GetPerInstanceRandom(); |
| 1193 | drawCall.SetStencilValue(effect->GetLayer()); |
| 1194 | drawCall.ObjectPosition = bounds.Center; |
nothing calls this directly
no test coverage detected