mellinoe / veldrid-samples

Sample projects for Veldrid
https://mellinoe.github.io/veldrid-docs/
121 stars 49 forks source link

Android .NET 6.0 CreateOpenGLES() failed to get the default Android EGLDisplay #45

Closed eightonegulf closed 2 years ago

eightonegulf commented 2 years ago

Hi, I'm trying to setup Veldrid within an Android .NET 6.0 app. My OnCreate method looks as follow:

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            GraphicsDeviceOptions options = new GraphicsDeviceOptions(
                false,
                PixelFormat.R16_UNorm,
                false,
                ResourceBindingModel.Improved,
                true,
                true);
            var surface = new VeldridSurfaceView(this, Veldrid.GraphicsBackend.OpenGLES, options);
            SetContentView(surface);
        }

The VeldridSurfaceView is directly copied from https://github.com/mellinoe/veldrid-samples/blob/master/src/SampleBase.Android/VeldridSurfaceView.cs

When I run this on my Android device, line #84 in VeldridSurfaceView GraphicsDevice = GraphicsDevice.CreateOpenGLES(DeviceOptions, sd); will throw an exception stating;

CreateOpenGLES() failed to get the default Android EGLDisplay: BadParameter

This exception originates from https://github.com/mellinoe/veldrid/blob/master/src/Veldrid/OpenGL/OpenGLGraphicsDevice.cs InitializeANativeWindow(), line #621. For some reason the display can't be found.

When I run exactly the same code from an Xamarin Android app, everything works as expected, and I can use Veldrid just fine. Only when I run from a .NET 6.0 app this goes wrong.

I am using VS 2022 Preview in order to use .NET 6.0 on Android.

I can't figure out what I'm missing. Is this a compatability issue, or am I missing something else?

Thanks.

eightonegulf commented 2 years ago

Just realized I opened this issue on the Samples repository, instead of the main Veldrid repo.