If you’re saying its time to switch to extended, I’m wondering if you swapped your values when reporting? The way this reads is that your method takes significantly less time than MG.E’s
Also, I’m not sure it will have an impact on your overall test but its worth noting that with the MG.E method, you don’t need to involve SpriteBatch
at all. Since your timing is inside the Begin
/End
, I’m not sure it matters, but just wanted to mention that.
It’s probably worth considering what kind of use case you’re needing here before you blanket switch. MG.E may be faster, but it depends on what you’re ultimately doing. If you’re making a 2D game, for example, you might find it harder to layer in MG.E’s 2D drawing with your own layers (if you’re using SpriteBatch
instead of a manually drawn textured quad). You know your own application of course, I just wanted to throw that out there.
Finally, something else! It looks like MG.E is using the same circle method the old Primitives2D approach used to generate circles…
public void DrawCircle(Vector2 center, float radius, Color color)
{
if (!_primitiveBatch.IsReady())
throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything.");
const double increment = Math.PI * 2.0 / CircleSegments;
double theta = 0.0;
for (int i = 0; i < CircleSegments; i++)
{
Vector2 v1 = center + radius * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta));
Vector2 v2 = center + radius * new Vector2((float)Math.Cos(theta + increment), (float)Math.Sin(theta + increment));
_primitiveBatch.AddVertex(v1, color, PrimitiveType.LineList);
_primitiveBatch.AddVertex(v2, color, PrimitiveType.LineList);
theta += increment;
}
}
This is absolutely fine; however, I happened to stumble across a more interesting and performant way to generate circles the other day.
The short of it is, you can use a pixel shader to generate your circle on a quad and get a perfect circle instead of a segmented circle. Not only will this have a nice appearance, I think it might be faster for certain circle segment counts and you also get more options for colouring/texturing. The video is in shadertoy, but it should easily convert to HLSL for use with MonoGame.
Whew, ok, information dump complete! Thank you for posting your results, that’s really informative!