views:

455

answers:

2

I'm drawing an xna project on a winforms Control using the following code:

this.GraphicsDevice.Present(MainForm.GamePanelHandle);

This winforms control is placed on a Form that is maximized, hiding the taskbar using the following code:

this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;

Unfortunately this makes the xna code run choppily as opposed to letting xna create its own window and setting it fullscreen. As I understand this is because the graphics card needs to pay attention to the whole windowing system and other active forms.

Are there any tricks I could use to make xna run faster when embedded on a fullscreen winforms Form?

+1  A: 

Have you tried setting:

DoubleBuffered = true;

in your form's load handler ?

This will at least help out with the Form's painting. i'm not sure if it will have an effect on the XNA stuff but it's worth a try.

Paul Sasik
just tried it, unfortunately no dice..
Wouter
What are the specs on your video card? If it's not a discrete card it could explain the choppiness. And, if it isn't discrete do you have a system with a decent, discrete video card to test on? (e.g. separate video processor like Radeon, GeForce...)
Paul Sasik
Unfortunately the machines it will run on all have an internal graphics card (Intel GMA 3100)
Wouter
XNA + shit graphics card = lots of tears
Will
A: 

If you're displaying a maximized form and even hiding the taskbar, why not go to true fullscreen mode? What are you gaining by using windowed mode that just looks like fullscreen? You are certainly reducing yur framerate by doing this.

In my experience windowed mode works best when your window (XNA control) is just a smaller part of the overall form. This is really the point of windowed mode since it allows you to interact with other standard form controls at the same time.

Going to fullscreen mode gives your application exclusive access to the video framebuffer and avoids overhead of dealing with windows GDI / GDI+ in windowed mode.

Also, if you're using an integrated graphics card (ie. less powerful) you'll need every GPU and CPU processing cycle you can get.

If you absolutely have to stick to windowed mode, I've found that the smaller the window, the better the performance. In windowed mode, reducing the window size has as big an impact on framerate as reducing the complexity of the scene being displayed does.

You could also consider setting the process priority of your application to AboveNormal or possibly even High. Be aware that doing this will cause other applications to respond more slowly while your application is running. To avoid system instability it is also recommended avoid using RealTime.

In .NET this can be done using the Process.PriorityClass property on a process:

// Set the current application (process) priority to high.
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
Ash
I need this to avoid switching between XNA managed fullscreen and winforms fake fullscreen for menus. Unfortunately we are bound to using both. I reverted back to switching between XNA fullscreen and winforms, as it is the lesser of two evils. The more evil being shite performance ;)
Wouter
@Wouter, Hope this is some help. Did you know many Media player applications such as VLC, MediaplayerClassic etc. let you change process priority in settings to help avoid exactly this choppy Windows performance you're seeing? So it should a small effect at least!
Ash