Is it possible to get a working GraphicsDevice without running the Engine thread? XNA allowed me to create graphics without a game engine, which is very useful for people not making games, but still want to use the 3d geometry library etc.
[EDIT]
I am using the Windows GL version. I got the source and made some minor changes, which gets me going. In particular, I check whether Game.Instance is null before using its properties to set wnd, and second, I later set wnd based on the PresentationParameters window handle. Basically it looks like the existing implementation ignores the PresentationParameters window handle that may have been passed into the GraphicsDevice constructor.
I make no claim that this is a general or good fix, just that it works in my case and identifies the problem.
MonoGame.Framework\Graphics\GraphicsDevice.OpenGL.cs
private void PlatformSetup()
{
#if WINDOWS || LINUX || ANGLE
GraphicsMode mode = GraphicsMode.Default;
var wnd = (Game.Instance == null)? null : (Game.Instance.Window as OpenTKGameWindow).Window.WindowInfo;
#if GLES
// Create an OpenGL ES 2.0 context
var flags = GraphicsContextFlags.Embedded;
int major = 2;
int minor = 0;
#else
// Create an OpenGL compatibility context
var flags = GraphicsContextFlags.Default;
int major = 1;
int minor = 0;
#endif
if (Context == null || Context.IsDisposed)
{
var color = PresentationParameters.BackBufferFormat.GetColorFormat();
var depth =
PresentationParameters.DepthStencilFormat == DepthFormat.None ? 0 :
PresentationParameters.DepthStencilFormat == DepthFormat.Depth16 ? 16 :
24;
var stencil =
PresentationParameters.DepthStencilFormat == DepthFormat.Depth24Stencil8 ? 8 :
0;
var samples = 0;
if (Game.Instance != null && Game.Instance.graphicsDeviceManager.PreferMultiSampling)
{
// Use a default of 4x samples if PreferMultiSampling is enabled
// without explicitly setting the desired MultiSampleCount.
if (PresentationParameters.MultiSampleCount == 0)
{
PresentationParameters.MultiSampleCount = 4;
}
samples = PresentationParameters.MultiSampleCount;
}
mode = new GraphicsMode(color, depth, stencil, samples);
try
{
wnd = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(PresentationParameters.DeviceWindowHandle);
Context = new GraphicsContext(mode, wnd, major, minor, flags);
}
catch (Exception e)
{
Game.Instance.Log("Failed to create OpenGL context, retrying. Error: " +
e.ToString());
major = 1;
minor = 0;
flags = GraphicsContextFlags.Default;
Context = new GraphicsContext(mode, wnd, major, minor, flags);
}
}