Drawuserprimitives lag

how can i drawuserprimitive effectively without lagging. when i draw alot of dynamic linelist by using drawuserprimitive() function, it become very lag… can anyone help?

Try batching them all. Every DrawUserPrimitives call does an actual draw call to the backend and you want to minimize those. Just have one big array and update the lines in there, then draw them all at once. That way you should be able to draw a ton of lines in one call at steady fps. You can either update the whole array every frame or wrap it in some code to manage removing and adding lines. I think @LithiumToast has implemented or is working on a batcher for primitives in MG.Extended, that’s maybe able to handle lines but I’m not sure.

The idea like @Jjagg said is to reduce actual draw calls.

I’ve done this in QueueRenderer in my Tiled re-work branch of MonoGame.Extended. The name QueueRenderer might change if I can think of something more fitting (naming things are hard). Basically it defers draw calls which is done similar to SpriteBatch: you call renderer.Begin(), then enqueue draw calls, then sort and flush the enqueued draw calls by calling renderer.End(). If you want to see how I use QueueRenderer, check out DynamicBatchRenderer2D which is very similar to SpriteBatch but is different in implementation.

Here is a screenshot of a demo in MonoGame.Extended using DynamicBatchRenderer2D to draw 2048 sprites using two textures which sprite information changes every frame. The two textures here basically dictates the number of actual draw calls since the textures need to be binded.