I'm trying to wrap my head around the use of effects and their use in rendering models and primitives. The sample code to render a model "m" looks like the following:
foreach (ModelMesh mesh in m.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.View = view;
effect.Projection = projection;
effect.World = MyWorldRotation * mesh.ParentBone.Transform *
Matrix.CreateTranslation(Position);
}
mesh.Draw();
}
While the sample code to render a primitive looks like this:
basicEffect.Begin();
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Begin();
graphics.GraphicsDevice.Vertices[0].SetSource(vertexBuffer, 0,
VertexPositionNormalTexture.SizeInBytes);
graphics.GraphicsDevice.DrawPrimitives(
PrimitiveType.TriangleList,
0,
12
);
pass.End();
}
basicEffect.End();
A couple of questions:
- Does the call to "mesh.Draw" in the first example contain an EffectPass loop like the one shown for rendering a primitive
- When a model is loaded, is it normally associated with a BasicEffect effect (it would appear so from the sample) Are they separate instances of the BasicEffect class Would/should you share the same effect instance among more than one model so that effect properties only have to be set once
- If you're rendering both primitives and models, is there a way to render the models as part of the EffectPass loop used by the primitives Or would you render them separately
Thank you!