csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.3 KiB
42 lines
1.3 KiB
using System;
|
|
using Avalonia.Logging;
|
|
|
|
namespace Avalonia.OpenGL
|
|
{
|
|
public class EglGlPlatformFeature : IWindowingPlatformGlFeature
|
|
{
|
|
private EglDisplay _display;
|
|
public EglDisplay Display => _display;
|
|
public IGlContext CreateContext()
|
|
{
|
|
return _display.CreateContext(DeferredContext);
|
|
}
|
|
public EglContext DeferredContext { get; private set; }
|
|
public IGlContext MainContext => DeferredContext;
|
|
|
|
public static void TryInitialize()
|
|
{
|
|
var feature = TryCreate();
|
|
if (feature != null)
|
|
AvaloniaLocator.CurrentMutable.Bind<IWindowingPlatformGlFeature>().ToConstant(feature);
|
|
}
|
|
|
|
public static EglGlPlatformFeature TryCreate()
|
|
{
|
|
try
|
|
{
|
|
var disp = new EglDisplay();
|
|
return new EglGlPlatformFeature
|
|
{
|
|
_display = disp,
|
|
DeferredContext = disp.CreateContext(null)
|
|
};
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log(null, "Unable to initialize EGL-based rendering: {0}", e);
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|