Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: query GL_MAX_SAMPLES before setting multisampling hint #8087

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion MonoGame.Framework/Platform/Graphics/OpenGL.cs
Expand Up @@ -1258,6 +1258,15 @@ static void DebugMessageCallbackHandler(int source, int type, int id, int severi

internal static int SwapInterval { get; set; }

internal unsafe static int GetMaxSamples()
{
GetIntegerv = LoadFunction<GetIntegerDelegate> ("glGetIntegerv");

int maxSamples = 0;
GetIntegerv((int)GetPName.MaxSamples, &maxSamples);
return maxSamples;
}

internal static void LoadEntryPoints ()
{
LoadPlatformEntryPoints ();
Expand Down Expand Up @@ -1455,7 +1464,7 @@ internal static void LoadExtensions()
GL.LoadFrameBufferObjectEXTEntryPoints();
}
if (GL.RenderbufferStorageMultisample == null)
{
{
if (Extensions.Contains("GL_APPLE_framebuffer_multisample"))
{
GL.RenderbufferStorageMultisample = LoadFunction<GL.RenderbufferStorageMultisampleDelegate>("glRenderbufferStorageMultisampleAPPLE");
Expand Down
20 changes: 19 additions & 1 deletion MonoGame.Framework/Platform/GraphicsDeviceManager.SDL.cs
Expand Up @@ -2,7 +2,9 @@
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.

using System;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.OpenGL;

namespace Microsoft.Xna.Framework
{
Expand Down Expand Up @@ -45,8 +47,24 @@ public partial class GraphicsDeviceManager

if (presentationParameters.MultiSampleCount > 0)
{
var temporaryWindow = Sdl.Window.Create(
"glContextInfoWindow",
0,
0,
0,
0,
Sdl.Window.State.OpenGL |
Sdl.Window.State.Hidden |
Sdl.Window.State.InputFocus |
Sdl.Window.State.MouseFocus
);
var temporaryGLContext = Sdl.GL.CreateContext(temporaryWindow);
var maxSamples = GL.GetMaxSamples();
Sdl.GL.DeleteContext(temporaryGLContext);
Sdl.Window.Destroy(temporaryWindow);

Sdl.GL.SetAttribute(Sdl.GL.Attribute.MultiSampleBuffers, 1);
Sdl.GL.SetAttribute(Sdl.GL.Attribute.MultiSampleSamples, presentationParameters.MultiSampleCount);
Sdl.GL.SetAttribute(Sdl.GL.Attribute.MultiSampleSamples, Math.Min(maxSamples, presentationParameters.MultiSampleCount));
}

((SdlGameWindow)SdlGameWindow.Instance).CreateWindow();
Expand Down
14 changes: 14 additions & 0 deletions MonoGame.Framework/Platform/SDL/SDLGameWindow.cs
Expand Up @@ -3,11 +3,13 @@
// file 'LICENSE.txt', which is part of this source code package.

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGame.Framework.Utilities;
using MonoGame.OpenGL;

namespace Microsoft.Xna.Framework
{
Expand Down Expand Up @@ -133,6 +135,12 @@ public SdlGameWindow(Game game)
_handle = Sdl.Window.Create("", 0, 0,
GraphicsDeviceManager.DefaultBackBufferWidth, GraphicsDeviceManager.DefaultBackBufferHeight,
Sdl.Window.State.Hidden | Sdl.Window.State.FullscreenDesktop);

if (_handle == default)
{
var sdlError = Sdl.GetError();
throw new NoSuitableGraphicsDeviceException(sdlError);
}
}

internal void CreateWindow()
Expand Down Expand Up @@ -164,6 +172,12 @@ internal void CreateWindow()
winx, winy, _width, _height, initflags
);

if (_handle == default)
{
var sdlError = Sdl.GetError();
throw new NoSuitableGraphicsDeviceException(sdlError);
}

Id = Sdl.Window.GetWindowId(_handle);

if (_icon != IntPtr.Zero)
Expand Down