Exemplo n.º 1
0
        public EglContext CreateContext(IGlContext share)
        {
            if (share != null && !SupportsSharing)
            {
                throw new NotSupportedException("Context sharing is not supported by this display");
            }

            if ((_surfaceType | EGL_PBUFFER_BIT) == 0)
            {
                throw new InvalidOperationException("Platform doesn't support PBUFFER surfaces");
            }
            var shareCtx = (EglContext)share;
            var ctx      = _egl.CreateContext(_display, _config, shareCtx?.Context ?? IntPtr.Zero, _contextAttributes);

            if (ctx == IntPtr.Zero)
            {
                throw OpenGlException.GetFormattedException("eglCreateContext", _egl);
            }
            var surf = _egl.CreatePBufferSurface(_display, _config, new[]
            {
                EGL_WIDTH, 1,
                EGL_HEIGHT, 1,
                EGL_NONE
            });

            if (surf == IntPtr.Zero)
            {
                throw OpenGlException.GetFormattedException("eglCreatePBufferSurface", _egl);
            }
            var rv = new EglContext(this, _egl, shareCtx, ctx, context => new EglSurface(this, context, surf),
                                    _version, _sampleCount, _stencilSize);

            return(rv);
        }
Exemplo n.º 2
0
        public EglContext CreateContext(IGlContext share)
        {
            if ((_surfaceType | EGL_PBUFFER_BIT) == 0)
            {
                throw new InvalidOperationException("Platform doesn't support PBUFFER surfaces");
            }
            var shareCtx = (EglContext)share;
            var ctx      = _egl.CreateContext(_display, _config, shareCtx?.Context ?? IntPtr.Zero, _contextAttributes);

            if (ctx == IntPtr.Zero)
            {
                throw OpenGlException.GetFormattedException("eglCreateContext", _egl);
            }
            var surf = _egl.CreatePBufferSurface(_display, _config, new[]
            {
                EGL_WIDTH, 1,
                EGL_HEIGHT, 1,
                EGL_NONE
            });

            if (surf == IntPtr.Zero)
            {
                throw OpenGlException.GetFormattedException("eglCreatePBufferSurface", _egl);
            }
            var rv = new EglContext(this, _egl, ctx, new EglSurface(this, _egl, surf));

            rv.MakeCurrent(null);
            return(rv);
        }
Exemplo n.º 3
0
        void DoCleanup(bool callUserDeinit)
        {
            if (_context != null)
            {
                using (_context.MakeCurrent())
                {
                    var gl = _context.GlInterface;
                    gl.BindTexture(GL_TEXTURE_2D, 0);
                    gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
                    gl.DeleteFramebuffers(1, new[] { _fb });
                    using (_bitmap.Lock())
                        _bitmap.SetTexture(0, 0, new PixelSize(1, 1), 1);
                    gl.DeleteTextures(1, new[] { _texture });
                    gl.DeleteRenderbuffers(1, new[] { _renderBuffer });
                    _bitmap.Dispose();

                    try
                    {
                        if (callUserDeinit)
                        {
                            OnOpenGlDeinit(_context.GlInterface, _fb);
                        }
                    }
                    finally
                    {
                        _context.Dispose();
                        _context = null;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public IGlContext CreateContext(IGlContext share)
        {
            var shareCtx = (EglContext)share;
            var ctx      = _egl.CreateContext(_display, _config, shareCtx?.Context ?? IntPtr.Zero, _contextAttributes);

            if (ctx == IntPtr.Zero)
            {
                throw OpenGlException.GetFormattedException("eglCreateContext", _egl);
            }
            var surf = _egl.CreatePBufferSurface(_display, _config, new[]
            {
                EGL_WIDTH, 1,
                EGL_HEIGHT, 1,
                EGL_NONE
            });

            if (surf == IntPtr.Zero)
            {
                throw OpenGlException.GetFormattedException("eglCreatePBufferSurface", _egl);
            }
            var rv = new EglContext(this, _egl, ctx, surf);

            rv.MakeCurrent(null);
            return(rv);
        }
        void DoCleanup()
        {
            if (_context != null)
            {
                using (_context.MakeCurrent())
                {
                    var gl = _context.GlInterface;
                    gl.BindTexture(GL_TEXTURE_2D, 0);
                    gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
                    gl.DeleteFramebuffers(1, new[] { _fb });
                    _fb = 0;
                    gl.DeleteRenderbuffers(1, new[] { _depthBuffer });
                    _depthBuffer = 0;
                    _attachment?.Dispose();
                    _attachment = null;
                    _bitmap?.Dispose();
                    _bitmap = null;

                    try
                    {
                        if (_initialized)
                        {
                            _initialized = false;
                            OnOpenGlDeinit(_context.GlInterface, _fb);
                        }
                    }
                    finally
                    {
                        _context.Dispose();
                        _context = null;
                    }
                }
            }
        }
Exemplo n.º 6
0
        private static IntPtr CreateEglSurface(IGlContext eglContext, IntPtr displayHandle, IntPtr sharedHandle, IntPtr configHandle)
        {
            // getting handle to eglCreatePbufferFromClientBuffer function
            var pBufferFunctionHandle =
                eglContext.Display.GlInterface.GetProcAddress("eglCreatePbufferFromClientBuffer");


            // create attributes
            var pBufferAttributes = new[]
            {
                EglConsts.EGL_WIDTH, 800,
                EglConsts.EGL_HEIGHT, 600,
                EglConsts.EGL_TEXTURE_TARGET, EglConsts.EGL_TEXTURE_2D,
                EglConsts.EGL_TEXTURE_FORMAT, EglConsts.EGL_TEXTURE_RGBA,
                EglConsts.EGL_NONE
            };


            // create function by handle
            var createEGLSurface =
                (CreateEGLSurfaceDelegate)Marshal.GetDelegateForFunctionPointer(pBufferFunctionHandle,
                                                                                typeof(CreateEGLSurfaceDelegate));

            // create and return egl surface
            var eglSurfaceHandle =
                createEGLSurface(displayHandle, 0x33A3, sharedHandle, configHandle, pBufferAttributes);

            return(eglSurfaceHandle);
        }
Exemplo n.º 7
0
 public IOpenGlBitmapAttachment CreateFramebufferAttachment(IGlContext context, Action presentCallback)
 {
     if (!SupportsContext(context))
     {
         throw new OpenGlException("Context is not supported for texture sharing");
     }
     return(new SharedOpenGlBitmapAttachment(this, context, presentCallback));
 }
Exemplo n.º 8
0
 public Session(IGlContext context, EglSurface glSurface, IEglWindowGlPlatformSurfaceInfo info,
                IDisposable @lock)
 {
     _context   = context;
     _glSurface = glSurface;
     _info      = info;
     _lock      = @lock;
 }
        public bool IsSharedWith(IGlContext context)
        {
            var c = (GlContext)context;

            return(c == this ||
                   c._sharedWith == this ||
                   _sharedWith == context ||
                   _sharedWith != null && _sharedWith == c._sharedWith);
        }
Exemplo n.º 10
0
 protected override void OnHandleCreated(EventArgs e)
 {
     base.OnHandleCreated(e);
     if (!DesignMode)
     {
         this.Context = GlContextFactory.CreateFromWindowHandle(this.Handle);
         this.Context.MakeCurrent();
     }
 }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <see cref="http://www.opentk.com/doc/graphics/graphicscontext"/>
        //[HandleProcessCorruptedStateExceptions]
        public override void InitSynchronizedOnce()
        {
            //Memory.WriteBytesHook += OnMemoryWrite;
            ScaleViewport = PspStoredConfig.RenderScale;

            if (!AlreadyInitialized)
            {
                AlreadyInitialized = true;
                var completedEvent = new AutoResetEvent(false);
                new Thread(() =>
                {
                    Thread.CurrentThread.CurrentCulture = new CultureInfo(GlobalConfig.ThreadCultureName);

                    OpenglContext = GlContextFactory.CreateWindowless();
                    OpenglContext.MakeCurrent();

                    Console.Out.WriteLineColored(ConsoleColor.White, "## OpenGL Context Version: {0}",
                                                 GlGetString(GL.GL_VERSION));
                    Console.Out.WriteLineColored(ConsoleColor.White, "## Depth Bits: {0}",
                                                 GL.glGetInteger(GL.GL_DEPTH_BITS));
                    Console.Out.WriteLineColored(ConsoleColor.White, "## Stencil Bits: {0}",
                                                 GL.glGetInteger(GL.GL_STENCIL_BITS));
                    Console.Out.WriteLineColored(ConsoleColor.White, "## Color Bits: {0},{1},{2},{3}",
                                                 GL.glGetInteger(GL.GL_RED_BITS), GL.glGetInteger(GL.GL_GREEN_BITS),
                                                 GL.glGetInteger(GL.GL_BLUE_BITS), GL.glGetInteger(GL.GL_ALPHA_BITS));

                    if (GL.glGetInteger(GL.GL_STENCIL_BITS) <= 0)
                    {
                        Console.Error.WriteLineColored(ConsoleColor.Red, "No stencil bits available!");
                    }

                    OpenglContext.ReleaseCurrent();

                    completedEvent.Set();
                    Console.WriteLine("OpenglGpuImpl.Init.Start()");
                    try
                    {
                        while (Running)
                        {
                            Thread.Sleep(10);
                        }
                        StopEvent.Set();
                    }
                    finally
                    {
                        Console.WriteLine("OpenglGpuImpl.Init.End()");
                    }
                })
                {
                    Name         = "GpuImplEventHandling",
                    IsBackground = true
                }.Start();

                completedEvent.WaitOne();
            }
        }
Exemplo n.º 12
0
        public GlxContext CreateContext(IGlContext share)
        {
            var sharelist = ((GlxContext)share)?.Handle ?? IntPtr.Zero;
            var h         = GlxCreateContext(_x11.Display, _visual, sharelist, true);

            if (h == IntPtr.Zero)
            {
                throw new OpenGlException("Unable to create direct GLX context");
            }
            return(new GlxContext(h, this, _x11));
        }
Exemplo n.º 13
0
        public static OpenGLContextBase AsOpenGLContextBase(this IGlContext context)
        {
            var handle = (IntPtr)context.GetType().GetProperty("Handle").GetValue(context);

            if (OperatingSystem.IsWindows())
            {
                return(new AvaloniaWglContext(handle));
            }
            else if (OperatingSystem.IsLinux())
            {
                return(new AvaloniaGlxContext(handle));
            }

            return(null);
        }
Exemplo n.º 14
0
        public static WglContext CreateContext(GlVersion[] versions, IGlContext share)
        {
            if (!Initialize())
            {
                return(null);
            }

            var shareContext = (WglContext)share;

            using (new WglRestoreContext(_bootstrapDc, _bootstrapContext, null))
            {
                var window = CreateOffscreenWindow();
                var dc     = GetDC(window);
                SetPixelFormat(dc, _defaultPixelFormat, ref _defaultPfd);
                foreach (var version in versions)
                {
                    if (version.Type != GlProfileType.OpenGL)
                    {
                        continue;
                    }
                    var context = WglCreateContextAttribsArb(dc, shareContext?.Handle ?? IntPtr.Zero,
                                                             new[]
                    {
                        // major
                        WGL_CONTEXT_MAJOR_VERSION_ARB, version.Major,
                        // minor
                        WGL_CONTEXT_MINOR_VERSION_ARB, version.Minor,
                        // core profile
                        WGL_CONTEXT_PROFILE_MASK_ARB, 1,
                        // debug
                        // WGL_CONTEXT_FLAGS_ARB, 1,
                        // end
                        0, 0
                    });
                    using (new WglRestoreContext(dc, context, null))
                        GlDebugMessageCallback(Marshal.GetFunctionPointerForDelegate(_debugCallback), IntPtr.Zero);
                    if (context != IntPtr.Zero)
                    {
                        return(new WglContext(shareContext, version, context, window, dc,
                                              _defaultPixelFormat, _defaultPfd));
                    }
                }

                ReleaseDC(window, dc);
                DestroyWindow(window);
                return(null);
            }
        }
Exemplo n.º 15
0
        public unsafe SharedOpenGlBitmapAttachment(GlOpenGlBitmapImpl bitmap, IGlContext context, Action presentCallback)
        {
            _bitmap          = bitmap;
            _context         = context;
            _presentCallback = presentCallback;
            using (_context.EnsureCurrent())
            {
                var glVersion = _context.Version;
                InternalFormat = glVersion.Type == GlProfileType.OpenGLES ? GL_RGBA : GL_RGBA8;

                _context.GlInterface.GetIntegerv(GL_FRAMEBUFFER_BINDING, out _fbo);
                if (_fbo == 0)
                {
                    throw new OpenGlException("Current FBO is 0");
                }

                {
                    var gl = _context.GlInterface;

                    Span <int> textures = stackalloc int[2];

                    fixed(int *ptex = textures)
                    gl.GenTextures(2, ptex);

                    _texture     = textures[0];
                    _frontBuffer = textures[1];

                    gl.GetIntegerv(GL_TEXTURE_BINDING_2D, out var oldTexture);
                    foreach (var t in textures)
                    {
                        gl.BindTexture(GL_TEXTURE_2D, t);
                        gl.TexImage2D(GL_TEXTURE_2D, 0,
                                      InternalFormat,
                                      _bitmap.PixelSize.Width, _bitmap.PixelSize.Height,
                                      0, GL_RGBA, GL_UNSIGNED_BYTE, IntPtr.Zero);

                        gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
                        gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
                    }

                    gl.FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture, 0);
                    gl.BindTexture(GL_TEXTURE_2D, oldTexture);
                }
            }
        }
Exemplo n.º 16
0
        protected void Init(IAvnWindowBase window, IAvnScreens screens, IGlContext glContext)
        {
            _native    = window;
            _glContext = glContext;

            Handle = new MacOSTopLevelWindowHandle(window);
            if (_gpu)
            {
                _glSurface = new GlPlatformSurface(window, _glContext);
            }
            Screen            = new ScreenImpl(screens);
            _savedLogicalSize = ClientSize;
            _savedScaling     = Scaling;

            var monitor = Screen.AllScreens.OrderBy(x => x.PixelDensity)
                          .FirstOrDefault(m => m.Bounds.Contains(Position));

            Resize(new Size(monitor.WorkingArea.Width * 0.75d, monitor.WorkingArea.Height * 0.7d));
        }
Exemplo n.º 17
0
        public GlSkiaGpu(IPlatformOpenGlInterface openGl, long?maxResourceBytes)
        {
            var context = openGl.PrimaryContext;

            _glContext = context;
            using (context.MakeCurrent())
            {
                using (var iface = context.Version.Type == GlProfileType.OpenGL ?
                                   GRGlInterface.CreateOpenGl(proc => context.GlInterface.GetProcAddress(proc)) :
                                   GRGlInterface.CreateGles(proc => context.GlInterface.GetProcAddress(proc)))
                {
                    _grContext = GRContext.CreateGl(iface);
                    if (maxResourceBytes.HasValue)
                    {
                        _grContext.SetResourceCacheLimit(maxResourceBytes.Value);
                    }
                }
            }
        }
Exemplo n.º 18
0
        private IntPtr GetEglD3Device(IGlContext eglContext)
        {
            var eglQueryDeviceAttribEXTPointer = eglContext.Display.GlInterface.GetProcAddress("eglQueryDisplayAttribEXT");
            var getDevice =
                (GetDeviceDelegate)Marshal.GetDelegateForFunctionPointer(eglQueryDeviceAttribEXTPointer,
                                                                         typeof(GetDeviceDelegate));

            var eglDeviceHandle = IntPtr.Zero;
            var eglDevice       = getDevice((eglContext.Display as EglDisplay).Handle, 0x322C, out eglDeviceHandle);


            var d3dQueryDeviceAttribEXTPointer = eglContext.Display.GlInterface.GetProcAddress("eglQueryDeviceAttribEXT");
            var getD3dDevice =
                (GetDeviceDelegate)Marshal.GetDelegateForFunctionPointer(d3dQueryDeviceAttribEXTPointer,
                                                                         typeof(GetDeviceDelegate));

            var d3dDeviceHandle = IntPtr.Zero;
            var d3dDevice       = getD3dDevice(eglDeviceHandle, 0x33A1, out d3dDeviceHandle);

            return(d3dDeviceHandle);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Creates the context.
        /// </summary>
        /// <param name="defaultXid">The default xid.</param>
        /// <param name="share">The share.</param>
        /// <returns>GlxContext.</returns>
        /// <exception cref="OpenGlException">Unable to create direct GLX context</exception>
        public GlxContext CreateContext(IntPtr defaultXid, IGlContext share)
        {
            var    sharelist = ((GlxContext)share)?.Handle ?? IntPtr.Zero;
            IntPtr handle    = default;

            foreach (var ver in new[]
            {
                new Version(4, 0), new Version(3, 2),
                new Version(3, 0), new Version(2, 0)
            })
            {
                var attrs = new[]
                {
                    GLX_CONTEXT_MAJOR_VERSION_ARB, ver.Major,
                    GLX_CONTEXT_MINOR_VERSION_ARB, ver.Minor,
                    GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
                    0
                };
                try
                {
                    handle = Glx.CreateContextAttribsARB(_x11.Display, _fbconfig, sharelist, true, attrs);
                    if (handle != IntPtr.Zero)
                    {
                        break;
                    }
                }
                catch
                {
                    break;
                }
            }

            if (handle == IntPtr.Zero)
            {
                throw new OpenGlException("Unable to create direct GLX context");
            }
            return(new GlxContext(new GlxInterface(), handle, this, _x11, defaultXid));
        }
        private bool EnsureInitializedCore()
        {
            if (_context != null)
            {
                return(true);
            }

            if (_glFailed)
            {
                return(false);
            }

            var feature = AvaloniaLocator.Current.GetService <IPlatformOpenGlInterface>();

            if (feature == null)
            {
                return(false);
            }
            if (!feature.CanShareContexts)
            {
                Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log("OpenGlControlBase",
                                                                  "Unable to initialize OpenGL: current platform does not support multithreaded context sharing");
                return(false);
            }
            try
            {
                _context = feature.CreateSharedContext();
            }
            catch (Exception e)
            {
                Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log("OpenGlControlBase",
                                                                  "Unable to initialize OpenGL: unable to create additional OpenGL context: {exception}", e);
                return(false);
            }

            GlVersion = _context.Version;
            try
            {
                _bitmap = new OpenGlBitmap(GetPixelSize(), new Vector(96, 96));
                if (!_bitmap.SupportsContext(_context))
                {
                    Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log("OpenGlControlBase",
                                                                      "Unable to initialize OpenGL: unable to create OpenGlBitmap: OpenGL context is not compatible");
                    return(false);
                }
            }
            catch (Exception e)
            {
                _context.Dispose();
                _context = null;
                Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log("OpenGlControlBase",
                                                                  "Unable to initialize OpenGL: unable to create OpenGlBitmap: {exception}", e);
                return(false);
            }

            using (_context.MakeCurrent())
            {
                try
                {
                    _depthBufferSize = GetPixelSize();
                    var gl     = _context.GlInterface;
                    var oneArr = new int[1];
                    gl.GenFramebuffers(1, oneArr);
                    _fb = oneArr[0];
                    gl.BindFramebuffer(GL_FRAMEBUFFER, _fb);

                    EnsureDepthBufferAttachment(gl);
                    EnsureTextureAttachment();

                    return(CheckFramebufferStatus(gl));
                }
                catch (Exception e)
                {
                    Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log("OpenGlControlBase",
                                                                      "Unable to initialize OpenGL FBO: {exception}", e);
                    return(false);
                }
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// Creates the context.
 /// </summary>
 /// <param name="share">The share.</param>
 /// <returns>GlxContext.</returns>
 public GlxContext CreateContext(IGlContext share) => CreateContext(IntPtr.Zero, share);
 public GlPlatformSurface(IAvnWindowBase window, IGlContext context)
 {
     _window  = window;
     _context = context;
 }
 public GlPlatformSurfaceRenderingSession(IGlContext context, IAvnGlSurfaceRenderingSession session)
 {
     Context  = context;
     _session = session;
 }
 public GlPlatformSurfaceRenderTarget(IAvnGlSurfaceRenderTarget target, IGlContext context)
 {
     _target  = target;
     _context = context;
 }
Exemplo n.º 25
0
 public Session(IGlContext context, IGlSurface glSurface, IEglWindowGlPlatformSurfaceInfo info)
 {
     _context   = context;
     _glSurface = glSurface;
     _info      = info;
 }
Exemplo n.º 26
0
        public FboSkiaSurface(GRContext grContext, IGlContext glContext, PixelSize pixelSize, GRSurfaceOrigin surfaceOrigin)
        {
            _grContext = grContext;
            _glContext = glContext;
            _pixelSize = pixelSize;
            var InternalFormat = glContext.Version.Type == GlProfileType.OpenGLES ? GL_RGBA : GL_RGBA8;
            var gl             = glContext.GlInterface;

            // Save old bindings
            gl.GetIntegerv(GL_FRAMEBUFFER_BINDING, out var oldFbo);
            gl.GetIntegerv(GL_RENDERBUFFER_BINDING, out var oldRenderbuffer);
            gl.GetIntegerv(GL_TEXTURE_BINDING_2D, out var oldTexture);

            var arr = new int[2];

            // Generate FBO
            gl.GenFramebuffers(1, arr);
            _fbo = arr[0];
            gl.BindFramebuffer(GL_FRAMEBUFFER, _fbo);

            // Create a texture to render into
            gl.GenTextures(1, arr);
            _texture = arr[0];
            gl.BindTexture(GL_TEXTURE_2D, _texture);
            gl.TexImage2D(GL_TEXTURE_2D, 0,
                          InternalFormat, pixelSize.Width, pixelSize.Height,
                          0, GL_RGBA, GL_UNSIGNED_BYTE, IntPtr.Zero);
            gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            gl.FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture, 0);

            var success = false;

            foreach (var useStencil8 in TrueFalse)
            {
                gl.GenRenderbuffers(1, arr);
                _depthStencil = arr[0];
                gl.BindRenderbuffer(GL_RENDERBUFFER, _depthStencil);

                if (useStencil8)
                {
                    gl.RenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, pixelSize.Width, pixelSize.Height);
                    gl.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _depthStencil);
                }
                else
                {
                    gl.RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, pixelSize.Width, pixelSize.Height);
                    gl.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthStencil);
                    gl.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _depthStencil);
                }

                var status = gl.CheckFramebufferStatus(GL_FRAMEBUFFER);
                if (status == GL_FRAMEBUFFER_COMPLETE)
                {
                    success = true;
                    break;
                }
                else
                {
                    gl.BindRenderbuffer(GL_RENDERBUFFER, oldRenderbuffer);
                    gl.DeleteRenderbuffers(1, arr);
                }
            }

            gl.BindRenderbuffer(GL_RENDERBUFFER, oldRenderbuffer);
            gl.BindTexture(GL_TEXTURE_2D, oldTexture);
            gl.BindFramebuffer(GL_FRAMEBUFFER, oldFbo);

            if (!success)
            {
                arr[0] = _fbo;
                gl.DeleteFramebuffers(1, arr);
                arr[0] = _texture;
                gl.DeleteTextures(1, arr);
                throw new OpenGlException("Unable to create FBO with stencil");
            }

            var target = new GRBackendRenderTarget(pixelSize.Width, pixelSize.Height, 0, 8,
                                                   new GRGlFramebufferInfo((uint)_fbo, SKColorType.Rgba8888.ToGlSizedFormat()));

            Surface = SKSurface.Create(_grContext, target,
                                       surfaceOrigin, SKColorType.Rgba8888);
            CanBlit = gl.BlitFramebuffer != null;
        }
Exemplo n.º 27
0
 public IOpenGlBitmapAttachment CreateFramebufferAttachment(IGlContext context) =>
 _impl.CreateFramebufferAttachment(context, SetIsDirty);
Exemplo n.º 28
0
 public bool SupportsContext(IGlContext context) => _impl.SupportsContext(context);
Exemplo n.º 29
0
        GlxContext CreateContext(IntPtr defaultXid, IGlContext share,
                                 int sampleCount, int stencilSize, bool ownsPBuffer)
        {
            var    sharelist = ((GlxContext)share)?.Handle ?? IntPtr.Zero;
            IntPtr handle    = default;

            GlxContext Create(GlVersion profile)
            {
                var profileMask = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;

                if (profile.Type == GlProfileType.OpenGLES)
                {
                    profileMask = GLX_CONTEXT_ES2_PROFILE_BIT_EXT;
                }

                var attrs = new int[]
                {
                    GLX_CONTEXT_MAJOR_VERSION_ARB, profile.Major,
                    GLX_CONTEXT_MINOR_VERSION_ARB, profile.Minor,
                    GLX_CONTEXT_PROFILE_MASK_ARB, profileMask,
                    0
                };

                try
                {
                    handle = Glx.CreateContextAttribsARB(_x11.Display, _fbconfig, sharelist, true, attrs);
                    if (handle != IntPtr.Zero)
                    {
                        _version = profile;
                        return(new GlxContext(new GlxInterface(), handle, this, (GlxContext)share, profile,
                                              sampleCount, stencilSize, _x11, defaultXid, ownsPBuffer));
                    }
                }
                catch
                {
                    return(null);
                }

                return(null);
            }

            GlxContext rv = null;

            if (_version.HasValue)
            {
                rv = Create(_version.Value);
            }

            foreach (var v in _probeProfiles)
            {
                if (v.Type == GlProfileType.OpenGLES &&
                    !_displayExtensions.Contains("GLX_EXT_create_context_es2_profile"))
                {
                    continue;
                }
                rv = Create(v);
                if (rv != null)
                {
                    _version = v;
                    break;
                }
            }

            if (rv != null)
            {
                return(rv);
            }

            throw new OpenGlException("Unable to create direct GLX context");
        }
Exemplo n.º 30
0
 public GlxContext CreateContext(IGlContext share) => CreateContext(CreatePBuffer(), share,
                                                                    share.SampleCount, share.StencilSize, true);