AndreN
Topic Author
Posts: 6
Joined: 01 Sep 2015, 08:28

MonoGame 3.8 and Noesis GUI 3.1.1 integration example

03 Oct 2021, 17:49

Hello

The awsome MonoGame integration project from AtomicTorchStudios (https://github.com/AtomicTorchStudio/No ... ameWrapper) is not directly working with the current Noesis GUI version (it was implemented for version 2). Even after adapting everything for the latest version, I got issues with using fonts and some other things.

That's why I decided to first create a minimal example of a Noesis GUI 3 integration for the latest MonoGame version for DirectX. The minimal example is more or less the same as it was provided for pure C# inside the official Noesis Tutorial Samples (https://github.com/Noesis/Tutorials/tre ... ionSharpDX) just that it integrates with MonoGame.

For the mouse event handling and the render state recovery, I used heavenly the code from the older integration provided from AtomicTorchStudios.

In the end the example is not especially fancy or advanced, it should be as simple as possible to give a good and easy to understand starting point for a more advanced integration.

You can find it here: https://github.com/Netzeband/noesis_monogame

Since I'm not an expert for DirectX, I still have some questions:

1.) The old integration from AtomicTorchStudio (Noesis GUI 2) has saved and restored the render state several times: When the device for Noesis GUI was created, during the offscreen render-step and also for the real render step. When I was looking at your documentation (https://www.noesisengine.com/docs/Gui.C ... Guide.html) it seams that this is only needed for the offscreen-render-step. Is this correct, or did I understand it wrong?

2.) Is there a list of render-state variables for DirectX, which are changed by Noesis GUI? The old example for Noesis GUI 2, from AtomicTorchStudios stored and resets a very huge list of variables. But the official DirectX integration from noesis just restores little variables. What is the right approach here?

3.) Unrelated to DirectX. In all C# examples of Noesis GUI, I see that the entry-point is decorated with the [STAThread] attribute. Since this attribute might lead to issues in other usecases, i was wondering if this is really necessary for Noesis GUI?

I hope my code example helps anyone who also want to integrate Noesis GUI with MonoGame. Maybe some time later I will provide a more advance implementation with real XAML providers, hot reloading, keyboard event handling and so on.

Tags:
 
User avatar
jsantos
Site Admin
Posts: 3253
Joined: 20 Jan 2012, 17:18
Contact:

Re: MonoGame 3.8 and Noesis GUI 3.1.1 integration example

04 Oct 2021, 13:19

Awesome work Andre! I am not the author of the MonoGame integration you used but I think I can answer the questions:

1. You need to restore for all the three cases: creation, offscreen and onscreen. But as an optimization, if after onscreen you are not using the device then you can defer the restoration to the next frame, after offscreen.

2. The D3D11 renderer implementation is open sourced and in C++. You can get it downloading the C++ SDK, the filename is D3D11RenderDevice.cpp

3. That attribute is created automatically by Visual Studio and probably it is not necessary. I will verify that. The only important thing regarding Noesis is always using the API from the same thread (with the exception of the render thread, where the view renderer can be used).

Thanks again for this!
 
AndreN
Topic Author
Posts: 6
Joined: 01 Sep 2015, 08:28

Re: MonoGame 3.8 and Noesis GUI 3.1.1 integration example

04 Oct 2021, 14:04

Thanks for your explanation. I will add the save/restore for the render device also to the creation and onscreen step in the example.

I will also look up in the C++ code to understand, what actually needed to be stored/restored.

Thanks for this awesome GUI library.
 
User avatar
ai_enabled
Posts: 226
Joined: 18 Jul 2013, 05:28
Contact:

Re: MonoGame 3.8 and Noesis GUI 3.1.1 integration example

05 Oct 2021, 00:25

Hello!
Good job!

Please check this branch https://github.com/AtomicTorchStudio/No ... ree/3.0.12
It has the complete support of NoesisGUI 3.0.12 except that I have no luck making the sample app work—I hope NoesisGUI guys (hi guys!) will have a look as there is nothing special, I've copied their code from Gallery C# sample basically as-is and wrapped it in a MonoGame 3.8 game project. It almost worked (had another issue) when I've used the sample for Unity instead, but I guess C# sample is the better fit here.

Regards!
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
 
User avatar
sfernandez
Site Admin
Posts: 2384
Joined: 22 Dec 2011, 19:20

Re: MonoGame 3.8 and Noesis GUI 3.1.1 integration example

05 Oct 2021, 18:26

Hi Vladimir,

I've looked at the sample in the repository and found why it was not correctly loading. It turns out that Noesis.App assembly is not explicitly referenced in the sample code, so it doesn't get loaded into the domain and the XAML parser can't create the types belonging to that assembly (Window and all interactivity classes). We have issue #1016 related to this still unresolved, perhaps we need to push this for the next release. In the meantime I manually loaded the assembly when application started:
private void CreateNoesisGUI()
{
  System.Reflection.Assembly.Load("Noesis.App");
  ...
}
And then it loaded fine after a couple of fixes:
- Resources.xaml, removed <ResourceDictionary> around MergedDictionaries property because it is already inside a ResourceDictionary.
- MainWindow.xaml.cs, as it is not using our application framework it doesn't have access to the Display, so GetScale method should be:
float GetScale()
{
  return Display != null ? Display.Scale : 1.0F;
}
 
User avatar
ai_enabled
Posts: 226
Joined: 18 Jul 2013, 05:28
Contact:

Re: MonoGame 3.8 and Noesis GUI 3.1.1 integration example

05 Oct 2021, 18:46

Hi Sergio,
thank you for the great work! It's perfect now. (pushed to Github)

I've also worked on an issue with the texture loading. The problem is that MonoGame 3.8 doesn't expose the native pointer for the SharpDX texture object. A workaround with Reflection is provided.

Regards!
AtomicTorch Studio Pte. Ltd. http://atomictorch.com

Who is online

Users browsing this forum: No registered users and 1 guest