xamarin / urho

Code to integrate with the Urho3D engine
Other
463 stars 122 forks source link

Multisampling does not work with ExternalWindow #216

Open andrekoehler opened 7 years ago

andrekoehler commented 7 years ago

I slightly modified "Urho.Samples.Console" and "Urho.Samples.WinForms" so that the ApplicationOptions contain the setting "Multisampling = 8".

In "Urho.Samples.Console" it is correctly applied to the example games, but in "Urho.Samples.WinForms" it seems to be ignored because I can clearly see aliasing on edges. (Tested with 04_StaticScene)

EgorBo commented 7 years ago

@andrekoehler as far as I remember Multisampling doesn't work when ExternalWindow is used (WinForms, Wpf, etc). Probably viewport.RenderPath.Append(CoreAssets.PostProcess.FXAA2); (or FXAA3) will be enough for you.

andrekoehler commented 7 years ago

I built the debug version of Urho3D and UrhoSharp and found out, that the line "SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, multiSample);" in OGLGraphics.cpp with multiSample = 8 is definitely called, but the call has no effect for some reason.

andrekoehler commented 7 years ago

I built the Direct3D11 backend version of mono-urho.dll (instead of the OpenGL backend that is shipped on NuGet) and multisampling now works correctly within Windows Forms.

EgorBo commented 7 years ago

Ok, I'll take a look. The sources you attached use DX or Opengl?

andrekoehler commented 7 years ago

Oops, it turns out D3D9 is the default for the native Urho3D library when compiling from Windows, so the screenshot I posted was created using the D3D9 backend. I recompiled the native Urho3D library with the "-DURHO3D_OPENGL=1" build option and it has the same issues as the UrhoSharp nuget package: aliasing even tough multisampling is set to 8.

yerumaku commented 6 years ago

as far as I remember Multisampling doesn't work when ExternalWindow is used (WinForms, Wpf, etc). Probably

It is possible to make a game with Xamarin (UI) + UrhoSharp will only without smoothing?

andrekoehler commented 6 years ago

I found out that this bug is fixed in SDL 2.0.7 and 2.0.8. UrhoSharp currently uses SDL 2.0.5. I created a native Win32 Window test project to compare both versions to find that out. The bug might already been fixed in 2.0.6 but I did not check it. So in order to fix this bug, please update libSDL to >= 2.0.7. Maybe it helps that Urho3D native is currently at 2.0.7 as well: https://github.com/urho3d/Urho3D/blob/master/Source/ThirdParty/SDL/WhatsNew.txt

SDL 2.0.5 2 0 5

SDL 2.0.7 and SDL 2.0.8 2 0 8

Here is my test project: WindowsProject1.zip

Keep in mind that you can not use a vanilla libSDL version for this test project but need a patch in order for SDL to initialize OpenGL when using SDL_CreateWindowFrom instead of SDL_CreateWindow. This patch is already included in Urho's version of libSDL:

https://github.com/xamarin/Urho3D/blob/213dffe479708d35b10b6dc50387e91061cf4216/Source/ThirdParty/SDL/src/video/windows/SDL_windowswindow.c#L367-L372

https://github.com/xamarin/Urho3D/blob/213dffe479708d35b10b6dc50387e91061cf4216/Source/ThirdParty/SDL/src/video/SDL_video.c#L1510-L1518