public override void Draw(GameTime gameTime)
{
GraphicsDevice device = REngine.Instance._graphics.GraphicsDevice;
// Restore the vertex buffer contents if the graphics device was lost.
if (vertexBuffer.IsContentLost)
{
vertexBuffer.SetData(particles);
}
// If there are any particles waiting in the newly added queue,
// we'd better upload them to the GPU ready for drawing.
if (firstNewParticle != firstFreeParticle)
{
AddNewParticlesToVertexBuffer();
}
// If there are any active particles, draw them now!
if (firstActiveParticle != firstFreeParticle)
{
// Set an effect parameter describing the viewport size. This is needed
// to convert particle sizes into screen space point sprite sizes.
effectViewportHeightParameter.SetValue(REngine.Instance.GetViewport().Height);
effectViewParameter.SetValue(REngine.Instance._camera.viewMatrix);
effectProjectionParameter.SetValue(REngine.Instance._camera.projMatrix);
// Set an effect parameter describing the current time. All the vertex
// shader particle animation is keyed off this value.
effectTimeParameter.SetValue(currentTime);
// Set the particle vertex buffer and vertex declaration.
device.SetVertexBuffer(vertexBuffer);
// Activate the particle effect.
foreach (EffectPass pass in particleEffect.CurrentTechnique.Passes)
{
pass.Apply();
if (firstActiveParticle < firstFreeParticle)
{
// If the active particles are all in one consecutive range,
// we can draw them all in a single call.
//device.DrawPrimitives(PrimitiveType.,
// firstActiveParticle,
// firstFreeParticle - firstActiveParticle);
}
else
{
// If the active particle range wraps past the end of the queue
// back to the start, we must split them over two draw calls.
//device.DrawPrimitives(PrimitiveType.PointList,
// firstActiveParticle,
// particles.Length - firstActiveParticle);
if (firstFreeParticle > 0)
{
// device.DrawPrimitives(PrimitiveType.PointList,
// 0,
// firstFreeParticle);
}
}
}
}
drawCounter++;
}