1

i'm building a song visualization where i need to compute each ~50ms a new Bitmap and show this on the Form by painting it on a picturebox.

Unfortunately the rendering / painting performance of this image isn't fast when using DrawImage / DrawLine.

Is there a way to improve by using XNA / DirectX?

Which one is better for this task?

Any examples?

nr1
  • 777
  • 3
  • 12
  • 31

2 Answers2

2

XNA uses DirectX in the Background. Also you can't directly use plain DirectX in C# anymore, because ManagedDX was discontinued because of XNA. There are alternatives though slimdx for example. XNA is closer to an engine that uses directx. What you need is a more low level approach, where it seems that the drawing performance is not the real issue, but the managed memory io operations. I would suggest to use Direct2D(also part of slimdx), which uses hardware acceleration and is more suitable for 2D rendering. You could also try this and manipulate the bitmap completely by hand.

Community
  • 1
  • 1
dowhilefor
  • 10,971
  • 3
  • 28
  • 45
  • hmm so in fact there is no direct solution without using 3rd party frameworks? – nr1 Jul 06 '11 at 15:56
  • @nr1 XNA is a first-party framework. Look up the XNA WinForms samples on App Hub for an example of how to use XNA with WinForms. – Andrew Russell Jul 06 '11 at 16:23
  • @Nr1 see the last link, you still have the option to write directly in a bitmap, maybe its fast enough for you. I'm still certain, that your problem is not the drawing performance, but just the way managed memory is accessed and modified. You will get a lot of overhead using XNA, SlimDX etc. just to fill an image ... i'm sure that with the proper optimization you can accomplish that using just a normal bitmap. Of course, depending how big the bitmap is. – dowhilefor Jul 06 '11 at 16:54
  • hmm so i'm still not sure how to do this best. When using XNA a shader supporting graphic card is prerequisite, for SlimDX i found no example that "just" shows how to draw a bitmap on a windows forms control (or something like this).. – nr1 Sep 05 '11 at 19:13
  • SlimDX is really low level and you would need a bit of a work to accomplish that. But like i said before, i just mentioned SlimDX because you brought up XNA. I still think, both XNA and SlimDX would be to much overhead and not necessary because i believe it can be accomplished with the last link in my previous comment. Have you tried it yet? – dowhilefor Sep 06 '11 at 09:40
0

I'd agree with using xna in a manner similar to the winforms sample.

I think you might get the best appearance and performance for the lines not by rendering a bitmap or using the SpriteBatch but by creating a dynamic vertex buffer to contain all the endpoints of all the lines. Then use the DrawUserPrimitives() and specify the primitiveType param to be PrimitiveType.LineList.

This sends all those points to the GPU where you can create all kinds of effects (shaders) on the lines while the GPU does all the heavy lifting.

Some of the samples in the educational section of the app hub use this kind of rendering to make grids. One that comes to mind is the perPixelLighting sample. You may (or may not) need to to work somewhat in 3d space.

Steve H
  • 5,479
  • 4
  • 20
  • 26