Exemple #1
0
        protected IGlPlatformSurfaceRenderingSession BeginDraw(EglSurface surface,
                                                               EglGlPlatformSurfaceBase.IEglWindowGlPlatformSurfaceInfo info, Action onFinish = null, bool isYFlipped = false)
        {
            var restoreContext = _egl.PrimaryEglContext.MakeCurrent(surface);
            var success        = false;

            try
            {
                var egli = _egl.Display.EglInterface;
                egli.WaitClient();
                egli.WaitGL();
                egli.WaitNative(EglConsts.EGL_CORE_NATIVE_ENGINE);

                _egl.PrimaryContext.GlInterface.BindFramebuffer(GlConsts.GL_FRAMEBUFFER, 0);

                success = true;
                return(new Session(_egl.Display, _egl.PrimaryEglContext, surface, info, restoreContext, onFinish, isYFlipped));
            }
            finally
            {
                if (!success)
                {
                    restoreContext.Dispose();
                }
            }
        }
        public IDisposable MakeCurrent(EglSurface surface)
        {
            Monitor.Enter(_lock);
            var success = false;

            try
            {
                var old  = new RestoreContext(_egl, _disp.Handle, _lock);
                var surf = surface ?? OffscreenSurface;
                _egl.MakeCurrent(_disp.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                if (!_egl.MakeCurrent(_disp.Handle, surf?.DangerousGetHandle() ?? IntPtr.Zero,
                                      surf?.DangerousGetHandle() ?? IntPtr.Zero, Context))
                {
                    throw OpenGlException.GetFormattedException("eglMakeCurrent", _egl);
                }
                success = true;
                return(old);
            }
            finally
            {
                if (!success)
                {
                    Monitor.Enter(_lock);
                }
            }
        }
Exemple #3
0
 public RenderTarget(EglPlatformOpenGlInterface egl,
                     EglSurface glSurface, IEglWindowGlPlatformSurfaceInfo info) : base(egl)
 {
     _egl         = egl;
     _glSurface   = glSurface;
     _info        = info;
     _currentSize = info.Size;
 }
Exemple #4
0
 public override IGlPlatformSurfaceRenderingSession BeginDraw()
 {
     if (_info.Size != _currentSize || _glSurface == null)
     {
         _glSurface?.Dispose();
         _glSurface   = null;
         _glSurface   = _egl.CreateWindowSurface(_info.Handle);
         _currentSize = _info.Size;
     }
     return(base.BeginDraw(_glSurface, _info));
 }
Exemple #5
0
 public Session(EglDisplay display, EglContext context,
                EglSurface glSurface, EglGlPlatformSurfaceBase.IEglWindowGlPlatformSurfaceInfo info,
                IDisposable restoreContext, Action onFinish, bool isYFlipped)
 {
     IsYFlipped      = isYFlipped;
     _context        = context;
     _display        = display;
     _glSurface      = glSurface;
     _info           = info;
     _restoreContext = restoreContext;
     _onFinish       = onFinish;
 }
Exemple #6
0
        public EglContext CreateContext(EglContext share, EglSurface offscreenSurface)
        {
            if (share != null && !SupportsSharing)
            {
                throw new NotSupportedException("Context sharing is not supported by this display");
            }

            var ctx = _egl.CreateContext(_display, _config, share?.Context ?? IntPtr.Zero, _contextAttributes);

            if (ctx == IntPtr.Zero)
            {
                throw OpenGlException.GetFormattedException("eglCreateContext", _egl);
            }
            var rv = new EglContext(this, _egl, share, ctx, _ => offscreenSurface, _version, _sampleCount, _stencilSize);

            rv.MakeCurrent(null);
            return(rv);
        }