Skip to content

Fix multisampling in DesktopGL#7338

Merged
harry-cpp merged 3 commits intoMonoGame:developfrom
sk-zk:desktopgl-enable-multisampling
Aug 29, 2020
Merged

Fix multisampling in DesktopGL#7338
harry-cpp merged 3 commits intoMonoGame:developfrom
sk-zk:desktopgl-enable-multisampling

Conversation

@sk-zk
Copy link
Copy Markdown
Contributor

@sk-zk sk-zk commented Aug 29, 2020

This is a quick and dirty fix to make multisampling work in DesktopGL.

The problem seems to be that OpenGL doesn't let you change the multisampling params after the window has been created, so they need to be passed to SDL before that point, in PlatformInitialize(). There was no way for the user to do that though because setting params via graphics.GraphicsDevice or through the PreparingDeviceSettings event are too late since PlatformInitialize() has already run. To deal with this, I added another event that is raised right before PlatformInitialize() so the user can pass the multisample count at that point.

The game code for enabling multisampling would look like this:

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferMultiSampling = true;
            graphics.BeforeDeviceCreated += Graphics_BeforeDeviceCreated;
            Content.RootDirectory = "Content";
        }

        private void Graphics_BeforeDeviceCreated(object sender, PresentationParameters e)
        {
            e.MultiSampleCount = 16;
        }

@harry-cpp
Copy link
Copy Markdown
Member

Couldn't you pass the MultiSampleCount in constructor?

@sk-zk
Copy link
Copy Markdown
Contributor Author

sk-zk commented Aug 29, 2020

You could, but then you'd have to store that in a member variable until CreateDevice is called. Idk if that's a good idea.

@harry-cpp
Copy link
Copy Markdown
Member

Everything else in GraphicsDeviceManager.SDL.cs works like that.

Constructor is the only thing that happens before the main window gets created and some other window related things need to be set from it. We were gonna implement the window recreation at some point, but that was/is too low on the priority list.

@sk-zk
Copy link
Copy Markdown
Contributor Author

sk-zk commented Aug 29, 2020

I see. I've updated the PR

@harry-cpp
Copy link
Copy Markdown
Member

Actually you have the PreparingDeviceSettings event to modify the params before device creation, so you just need the gdm.sdl.cs changes, right?

@harry-cpp
Copy link
Copy Markdown
Member

Unless its a partial void with half of the method missing XD

@sk-zk
Copy link
Copy Markdown
Contributor Author

sk-zk commented Aug 29, 2020

PreparingDeviceSettings happens after PlatformInitialize, that's the issue

@harry-cpp
Copy link
Copy Markdown
Member

harry-cpp commented Aug 29, 2020

Yea, I now see why it was so problematic, modify CreateDevice in GDM to do the following, that should do the trick:

var gdi = DoPreparingDeviceSettings();

if (!_initialized)
    Initialize(gdi);

CreateDevice(gdi);

@sk-zk
Copy link
Copy Markdown
Contributor Author

sk-zk commented Aug 29, 2020

That'll do it

@harry-cpp harry-cpp merged commit 8fc0155 into MonoGame:develop Aug 29, 2020
@harry-cpp
Copy link
Copy Markdown
Member

Big thanks @sk-zk ! Merging!

@harry-cpp harry-cpp added this to the 3.8.1 milestone Aug 29, 2020
nkast added a commit to nkast/MonoGame that referenced this pull request Sep 13, 2020
kimimaru4000 pushed a commit to kimimaru4000/MonoGame that referenced this pull request Sep 25, 2020
* Apply Multisampling to the SDL window
* Call DoPreparingDeviceSettings before Init in GDM
@OtherStuffThatSpam
Copy link
Copy Markdown

I've been testing Monogame 3.8.1.303 and I am not able to enable multi-sampling on Windows DesktopGL Cross platform project, the same code base works on DirectX Windows, is this really fixed in the latest version of Monogame? or I am missing something?

@lorissikora
Copy link
Copy Markdown

Sorry for necrobumping, but I'm experiencing the exact same issue, also on version 3.8.1.303. Has there been any development on this? @OtherStuffThatSpam did you find a solution?

@orosbogdan
Copy link
Copy Markdown

Experiencing the same issue on 3.8.1.303

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants