Пример #1
0
        protected override void OnRenderFrame()
        {
            var rect = Allocation;

            // create the contexts if not done already
            if (grContext == null)
            {
                var glInterface = GRGlInterface.CreateNativeGlInterface();

                if (glInterface == null)
                {
                    throw new InvalidOperationException("Error creating OpenGL ES interface. Check if you have OpenGL ES correctly installed and configured or change the PFD Renderer to 'Software (CPU)' on the Global Settings panel.");
                }
                else
                {
                    grContext = GRContext.Create(GRBackend.OpenGL, glInterface);
                }

                try
                {
                    renderTarget = CreateRenderTarget();
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("Error creating OpenGL ES render target. Check if you have OpenGL ES correctly installed and configured or change the PFD Renderer to 'Software (CPU)' on the Global Settings panel.", ex);
                }
            }

            if (grContext != null)
            {
                // update to the latest dimensions
                renderTarget = new GRBackendRenderTarget(rect.Width, rect.Height, renderTarget.SampleCount, renderTarget.StencilBits, renderTarget.GetGlFramebufferInfo());

                // create the surface
                using (var surface = SKSurface.Create(grContext, renderTarget, SKColorType.Rgba8888))
                {
                    if (PaintSurface != null)
                    {
                        PaintSurface.Invoke(surface);
                    }

                    surface.Canvas.Flush();
                }
            }
        }
Пример #2
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            // create the contexts if not done already
            if (grContext == null)
            {
                var glInterface = GRGlInterface.CreateNativeGlInterface();
                grContext = GRContext.Create(GRBackend.OpenGL, glInterface);

                // get initial details
                renderTarget = CreateRenderTarget();
            }

            // update to the latest dimensions
            renderTarget = new GRBackendRenderTarget(Width, Height, renderTarget.SampleCount, renderTarget.StencilBits, renderTarget.GetGlFramebufferInfo());

            // create the surface
            using (var surface = SKSurface.Create(grContext, renderTarget, SKColorType.Rgba8888))
            {
                if (PaintSurface != null)
                {
                    PaintSurface.Invoke(surface);
                }

                // start drawing
                OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget));

                surface.Canvas.Flush();
            }

            // update the control
            SwapBuffers();
        }