示例#1
0
        protected override void OnRenderFrame(Rect rect)
        {
            // clear everything
            Gles.glClear(Gles.GL_COLOR_BUFFER_BIT | Gles.GL_DEPTH_BUFFER_BIT | Gles.GL_STENCIL_BUFFER_BIT);

            // create the SkiaSharp context
            if (context == null)
            {
                glInterface = GRGlInterface.CreateNativeAngleInterface();
                context     = GRContext.Create(GRBackend.OpenGL, glInterface);
            }

            // get the new surface size
            var newSize = new SKSizeI((int)rect.Width, (int)rect.Height);

            // manage the drawing surface
            if (renderTarget == null || lastSize != newSize || !renderTarget.IsValid)
            {
                // create or update the dimensions
                lastSize = newSize;

                // read the info from the buffer
                Gles.glGetIntegerv(Gles.GL_FRAMEBUFFER_BINDING, out var framebuffer);
                Gles.glGetIntegerv(Gles.GL_STENCIL_BITS, out var stencil);
                Gles.glGetIntegerv(Gles.GL_SAMPLES, out var samples);
                var maxSamples = context.GetMaxSurfaceSampleCount(colorType);
                if (samples > maxSamples)
                {
                    samples = maxSamples;
                }

                glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat());

                // destroy the old surface
                surface?.Dispose();
                surface = null;
                canvas  = null;

                // re-create the render target
                renderTarget?.Dispose();
                renderTarget = new GRBackendRenderTarget(newSize.Width, newSize.Height, samples, stencil, glInfo);
            }

            // create the surface
            if (surface == null)
            {
                surface = SKSurface.Create(context, renderTarget, surfaceOrigin, colorType);
                canvas  = surface.Canvas;
            }

            using (new SKAutoCanvasRestore(canvas, true))
            {
                // start drawing
                OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType, glInfo));
            }

            // update the control
            canvas.Flush();
            context.Flush();
        }
示例#2
0
        protected override void OnRenderFrame(Rect rect)
        {
            // clear everything
            Gles.glClear(Gles.GL_COLOR_BUFFER_BIT | Gles.GL_DEPTH_BUFFER_BIT | Gles.GL_STENCIL_BUFFER_BIT);

            // create the SkiaSharp context
            if (context == null)
            {
                glInterface = GRGlInterface.CreateNativeAngleInterface();
                context     = GRContext.Create(GRBackend.OpenGL, glInterface);
            }

            // manage the drawing surface
            if (renderTarget == null || surface == null || renderTarget.Width != (int)rect.Width || renderTarget.Height != (int)rect.Height)
            {
                // create or update the dimensions
                renderTarget?.Dispose();
                renderTarget = SKGLDrawable.CreateRenderTarget((int)rect.Width, (int)rect.Height);

                // create the surface
                surface?.Dispose();
                surface = SKSurface.Create(context, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888);
            }

            using (new SKAutoCanvasRestore(surface.Canvas, true))
            {
                // start drawing
                OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888));
            }

            // update the control
            surface.Canvas.Flush();
            context.Flush();
        }
        public void Resize(int width, int height)
        {
            if (_context == null)
            {
                //var glInterface = GRGlInterface.AssembleAngleInterface(D3DAngleInterop._window_info,);
                var glInterface = GRGlInterface.CreateNativeAngleInterface();
                _context = GRContext.Create(GRBackend.OpenGL, glInterface);
            }
            var glInfo = new GRGlFramebufferInfo(
                fboId: 0,
                format: SKColorType.Rgba8888.ToGlSizedFormat());

            _renderTarget = new GRBackendRenderTarget(
                width: width,
                height: height,
                sampleCount: 8,
                stencilBits: 8,
                glInfo: glInfo);
            _surface = SKSurface.Create(
                _context, _renderTarget, GRSurfaceOrigin.TopLeft, SKColorType.Rgba8888);
        }
示例#4
0
        protected override void OnRenderFrame(Rect rect)
        {
            base.OnRenderFrame(rect);

            if (designMode)
            {
                return;
            }

            if (!isVisible)
            {
                return;
            }

            // create the SkiaSharp context
            if (context == null)
            {
                var glInterface = GRGlInterface.CreateNativeAngleInterface();
                context = GRContext.Create(GRBackend.OpenGL, glInterface);

                renderTarget = SKGLDrawable.CreateRenderTarget();
            }

            // set the size
            renderTarget.Width  = (int)rect.Width;
            renderTarget.Height = (int)rect.Height;

            // create the surface
            using (var surface = SKSurface.Create(context, renderTarget))
            {
                // draw to the SkiaSharp surface
                OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget));

                // flush the canvas
                surface.Canvas.Flush();
            }

            // flush the SkiaSharp context to the GL context
            context.Flush();
        }
示例#5
0
        protected override void OnRenderFrame(Rect rect)
        {
            // clear everything
            Gles.glClear(Gles.GL_COLOR_BUFFER_BIT | Gles.GL_DEPTH_BUFFER_BIT | Gles.GL_STENCIL_BUFFER_BIT);

            // create the SkiaSharp context
            if (context == null)
            {
                glInterface = GRGlInterface.CreateNativeAngleInterface();
                context     = GRContext.Create(GRBackend.OpenGL, glInterface);
            }

            // manage the drawing surface
            if (renderTarget == null || surface == null || renderTarget.Width != (int)rect.Width || renderTarget.Height != (int)rect.Height)
            {
                // create or update the dimensions
                renderTarget?.Dispose();
                Gles.glGetIntegerv(Gles.GL_FRAMEBUFFER_BINDING, out var framebuffer);
                Gles.glGetIntegerv(Gles.GL_STENCIL_BITS, out var stencil);
                var glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat());
                renderTarget = new GRBackendRenderTarget((int)rect.Width, (int)rect.Height, context.GetMaxSurfaceSampleCount(colorType), stencil, glInfo);

                // create the surface
                surface?.Dispose();
                surface = SKSurface.Create(context, renderTarget, surfaceOrigin, colorType);
            }

            using (new SKAutoCanvasRestore(surface.Canvas, true))
            {
                // start drawing
                OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType));
            }

            // update the control
            surface.Canvas.Flush();
            context.Flush();
        }