From 4756a0a769de4b3ddbba5fda42a8ebb7b78ee69f Mon Sep 17 00:00:00 2001 From: Max Katz Date: Wed, 23 Feb 2022 22:56:39 -0500 Subject: [PATCH] Fix iOS OpenGL rendering with newer Skia --- .../Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs | 13 +++++++++---- src/iOS/Avalonia.iOS/EaglDisplay.cs | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs b/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs index b4c5619c85..809f50ab8b 100644 --- a/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs +++ b/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs @@ -69,6 +69,7 @@ namespace Avalonia.Skia gl.GetIntegerv(GL_FRAMEBUFFER_BINDING, out var fb); var size = glSession.Size; + var colorType = SKColorType.Rgba8888; var scaling = glSession.Scaling; if (size.Width <= 0 || size.Height <= 0 || scaling < 0) { @@ -81,12 +82,16 @@ namespace Avalonia.Skia { _grContext.ResetContext(); - var renderTarget = - new GRBackendRenderTarget(size.Width, size.Height, disp.SampleCount, disp.StencilSize, - new GRGlFramebufferInfo((uint)fb, SKColorType.Rgba8888.ToGlSizedFormat())); + var samples = disp.SampleCount; + var maxSamples = _grContext.GetMaxSurfaceSampleCount(colorType); + if (samples > maxSamples) + samples = maxSamples; + + var glInfo = new GRGlFramebufferInfo((uint)fb, colorType.ToGlSizedFormat()); + var renderTarget = new GRBackendRenderTarget(size.Width, size.Height, samples, disp.StencilSize, glInfo); var surface = SKSurface.Create(_grContext, renderTarget, glSession.IsYFlipped ? GRSurfaceOrigin.TopLeft : GRSurfaceOrigin.BottomLeft, - SKColorType.Rgba8888); + colorType); success = true; diff --git a/src/iOS/Avalonia.iOS/EaglDisplay.cs b/src/iOS/Avalonia.iOS/EaglDisplay.cs index f1d46fcb92..bd1969081d 100644 --- a/src/iOS/Avalonia.iOS/EaglDisplay.cs +++ b/src/iOS/Avalonia.iOS/EaglDisplay.cs @@ -74,7 +74,21 @@ namespace Avalonia.iOS public GlVersion Version { get; } = new GlVersion(GlProfileType.OpenGLES, 3, 0); public GlInterface GlInterface { get; } - public int SampleCount { get; } = 0; - public int StencilSize { get; } = 9; + public int SampleCount + { + get + { + GlInterface.GetIntegerv(GlConsts.GL_SAMPLES, out var samples); + return samples; + } + } + public int StencilSize + { + get + { + GlInterface.GetIntegerv(GlConsts.GL_STENCIL_BITS, out var stencil); + return stencil; + } + } } }