Update: here is the code I use to draw the model: public void Draw(...) { int index = 0;
int i = 0;
foreach (ModelMesh mesh in Actor.Model.Meshes)
{
bool isDrawable = false;
#region Check if this ModelMesh needs to be drawn according to PartsToDraw (string) list.
foreach (string s in PartsToDraw)
if (s == mesh.Name)
isDrawable = true;
#endregion
if (isDrawable)
{
int effectStartIndex = index;
foreach (Effect effect in mesh.Effects)
{
if (Actor.MatrixPaletteParams[index] != null)
{
Actor.WorldParams[index].SetValue(World);
Actor.MatrixPaletteParams[index].SetValue(Actor.Palette[i]);
}
else
Actor.WorldParams[index].SetValue(Actor.Pose[mesh.ParentBone.Index] * World);
if (drawType != null && drawType.DrawShadow)
SetShadowEffectParameters(effect, renderer, drawType.DrawShadowMort);
else
{
SetCommonEffectParameters(effect, renderer);
SetLitEffectParameters(effect, renderer, drawType);
}
index++;
}
}
else
index++;
if (isDrawable)
mesh.Draw();
i++;
}
}
"Set...EfectParameters" methods mostly consist of effect.Parameters["SomeParameter"].SetValue() calls. I pass around 30 parameters to the GPU there, mostly floats, matrices and bools. Moreover each ModelMesh has three textures that it passes into the GPU. I have no idea how fast this works and if it can be optimized. It should be fast.
You should also note that I draw a skeletaly animated model using Dastle's XNA Animation Component library. Once again, I understand that this might be the reason behind lags, and we did find the weak spot of the animation code, but why on Earth does the metrics show that mesh.Draw is the slowest spot? What is happening there?