Okay i am trying to replace the use of Panels and Pictureboxes in my application, as they aren´t suitable for drawing many pictures fast.
Now i am looking at SlimDX, and have gotten it to work sligthly, but, it´s much slower than drawing in a Panel, and i am a bit confused to what i can change.
I also have a problem where the texture size isn´t correct, it appears much bigger and distorted than it´s supposed to, and this kills performance.
Here is the code:
First to initialize everything:
var form = new SlimDX.Windows.RenderForm("Test");
form.Width = 1280;
form.Height = 1024;
SlimDX.Direct3D9.PresentParameters presentParams = new SlimDX.Direct3D9.PresentParameters
{
BackBufferWidth = form.Width,
BackBufferHeight = form.Height,
DeviceWindowHandle = form.Handle,
PresentFlags = SlimDX.Direct3D9.PresentFlags.None,
Multisample = SlimDX.Direct3D9.MultisampleType.None,
BackBufferCount = 0,
PresentationInterval = SlimDX.Direct3D9.PresentInterval.Immediate,
SwapEffect = SlimDX.Direct3D9.SwapEffect.Flip,
BackBufferFormat = SlimDX.Direct3D9.Format.X8R8G8B8,
Windowed = true,
};
var device = new SlimDX.Direct3D9.Device(new SlimDX.Direct3D9.Direct3D(), 0, SlimDX.Direct3D9.DeviceType.Hardware, form.Handle, SlimDX.Direct3D9.CreateFlags.HardwareVertexProcessing, presentParams);
device.Viewport = new SlimDX.Direct3D9.Viewport(0, 0, form.Width, form.Height);
SlimDX.Direct3D9.Sprite sprite;
sprite = new SlimDX.Direct3D9.Sprite(device);
Any thoughts on that, please tell.
Then the actual drawing.
SlimDX.Windows.MessagePump.Run(form, () =>
{
sprite.Begin(SlimDX.Direct3D9.SpriteFlags.None);
device.BeginScene();
var tx = SlimDX.Direct3D9.Texture.FromStream(device, ms, 0, 0, 0, SlimDX.Direct3D9.Usage.None, SlimDX.Direct3D9.Format.X8R8G8B8, SlimDX.Direct3D9.Pool.Managed, SlimDX.Direct3D9.Filter.None, SlimDX.Direct3D9.Filter.None, 0);
sprite.Draw(tx, Color.Transparent);
sprite.End();
tx.Dispose();
device.EndScene();
device.Present();
});
Now there is a bit more going on, but that´s just getting the network stream etc and hasn´t anything to do with the actual drawing performance.
Now, is there anything wrong with this?
Can it be improve (hope it can)?
The only thing i am trying to do, is to draw a new picture every loop (i send a new image, and i want to display it).
So the thing that must be improved is how fast it can draw it. Perhaps the conversions is slow, i don´t know, but form my tests it´s the Texture.FromStream that is slow, the actual displaying is fast.
Thanks