9 changed files with 106 additions and 75 deletions
@ -0,0 +1,44 @@ |
|||
using System; |
|||
using System.Reactive.Disposables; |
|||
using System.Threading; |
|||
|
|||
namespace Avalonia.OpenGL |
|||
{ |
|||
public class EglContext : IGlContext |
|||
{ |
|||
private readonly EglDisplay _disp; |
|||
private readonly EglInterface _egl; |
|||
private readonly object _lock = new object(); |
|||
|
|||
public EglContext(EglDisplay display, EglInterface egl, IntPtr ctx, IntPtr offscreenSurface) |
|||
{ |
|||
_disp = display; |
|||
_egl = egl; |
|||
Context = ctx; |
|||
OffscreenSurface = offscreenSurface; |
|||
} |
|||
|
|||
public IntPtr Context { get; } |
|||
public IntPtr OffscreenSurface { get; } |
|||
public IGlDisplay Display => _disp; |
|||
|
|||
public IDisposable Lock() |
|||
{ |
|||
Monitor.Enter(_lock); |
|||
return Disposable.Create(() => Monitor.Exit(_lock)); |
|||
} |
|||
|
|||
public void MakeCurrent() |
|||
{ |
|||
if (!_egl.MakeCurrent(_disp.Handle, IntPtr.Zero, IntPtr.Zero, Context)) |
|||
throw new OpenGlException("eglMakeCurrent failed"); |
|||
} |
|||
|
|||
public void MakeCurrent(EglSurface surface) |
|||
{ |
|||
var surf = ((EglSurface)surface)?.DangerousGetHandle() ?? OffscreenSurface; |
|||
if (!_egl.MakeCurrent(_disp.Handle, surf, surf, Context)) |
|||
throw new OpenGlException("eglMakeCurrent failed"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
using System; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
namespace Avalonia.OpenGL |
|||
{ |
|||
public class EglSurface : SafeHandle |
|||
{ |
|||
private readonly EglDisplay _display; |
|||
private readonly EglInterface _egl; |
|||
|
|||
public EglSurface(EglDisplay display, EglInterface egl, IntPtr surface) : base(surface, true) |
|||
{ |
|||
_display = display; |
|||
_egl = egl; |
|||
} |
|||
|
|||
protected override bool ReleaseHandle() |
|||
{ |
|||
_egl.DestroySurface(_display.Handle, handle); |
|||
return true; |
|||
} |
|||
|
|||
public override bool IsInvalid => handle == IntPtr.Zero; |
|||
|
|||
public IGlDisplay Display => _display; |
|||
public void SwapBuffers() => _egl.SwapBuffers(_display.Handle, handle); |
|||
} |
|||
} |
|||
@ -1,10 +0,0 @@ |
|||
using System; |
|||
|
|||
namespace Avalonia.OpenGL |
|||
{ |
|||
public interface IGlSurface : IDisposable |
|||
{ |
|||
IGlDisplay Display { get; } |
|||
void SwapBuffers(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue