What is the proper way to get draw area size and screen resolution?

Prompted by another post, I did some testing on most of the platforms I have access to and found that the various screen and window resolution metrics are not consistent between them. I looked at GraphicsDevice.DisplayMode., GraphicsDevice.PresentationParameters.BackBuffer, GraphicsDevice.Viewport., GraphicsAdapter.DefaultAdapter.CurrentDisplayMode., graphics.PreferredBackBuffer*, and Window.ClientBounds.*. I tested with mostly the current dev version using source except for MacOS where I can’t get it to run so I used 3.5.1 sable.

  1. Which variable should represent the window size such that I can use it to set the PreferredBackBuffer size when setting full screen? CurrentDisplayMode looks to be the most correct/logical, but is wrong on several platforms.

  2. Should the full screen and PreferredBackBuffer size be set in the Game1 constructor or Game1.Initialize (before or after base.Initialize)? Some of the platforms did not have the correct size in any of the variables until the first Update call.

  3. When not running as full screen, which variable should represent the draw area size and at what point should it be correct? CLientBounds was sometimes not correct until the first Update call.

  4. Are there cases where a platform will change the PreferredBackBuffer size after you set it? There are several platforms where it changed after Initialize and before the first Update.

When testing full screen, I set the full screen flag in the Game1 constructor after the GraphicsDeviceManager create and set the PreferredBackBuffer size to be the CurrentDisplayMode size. I did the size setting, even when the CurrentDisplayMode size was wrong (0x0).

This sounds like important stuff. Thanks for taking the time to post it. Maybe it would help the developers if you could provide the specifics of which platform did what. Maybe in a Google spreadsheet?

I do have a spreadsheet. What I originally wrote was too long and dry and included all the details. Yes, longer and drier than this one. The complication of the spreadsheet is that you can’t upload it directly to the forum.

If you could even just share a link to the google spreadsheet that should work. I’d love to see the breakdown of the info.

Here is a google sheet for it. It lost the formatting when uploading, so I had to manually redo it. Hopefully I didn’t get it wrong. Bolded items are where the numbers changed. The “After Setting In Constructor” is where I changed to using the CurrentDisplayMode values for the PreferredBackBuffer size and set full screen mode. That is the only place where I changed any of the values.
GDM = GraphicsDeviceManager
DM = GraphicsDevice.DisplayMode
PPBB = GraphicsDevice.PresentationParameters.BackBuffer
VP = GraphicsDevice.Viewport
CDM = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode
PBB = PreferredBackBuffer
CB = Window.ClientBounds

Code snippets:

public GraphicsDeviceManager graphics;

public Game1 ()
{
    graphics = new GraphicsDeviceManager (this);
    LogSizes ("After GraphicsDeviceManager create in Game1 constructor");
    if (setForFullScreenMode) {
        graphics.IsFullScreen = true;
        graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
        graphics.PreferredBackBufferHeight = raphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
        LogSizes ("After setting fullscreen mode & size using GraphicsAdapter in Game1 constructor");
    }
}

protected override void Initialize ()
{
    LogSizes ("before Game1.base.Initialize");
    base.Initialize ();
    LogSizes ("after Game1.base.Initialize");

    //...Setup Camera
}

protected override void LoadContent ()
{
    LogSizes ("start of Game1.LoadContent");
    // ...Load Content Code
}

private int updateCounter = 0;

protected override void Update (GameTime gameTime)
{
    if (updateCounter < 2) {
        ++updateCounter;
        LogSizes ($"Update #{updateCounter}");
    }

    // ...update code

    base.Update (gameTime);
}

private int drawCounter = 0;

protected override void Draw (GameTime gameTime)
{
    if (drawCounter < 2) {
        ++drawCounter;
        LogSizes ($"Draw #{drawCounter}");
    }
    GraphicsDevice.Clear (Color.CornflowerBlue);

    // ..draw code

    base.Draw (gameTime);
}
1 Like

Certainly related to

but for now no solution