Exemple #1
0
        public PlatformRenderInterface(ICustomSkiaGpu customSkiaGpu)
        {
            if (customSkiaGpu != null)
            {
                _customSkiaGpu = customSkiaGpu;

                GrContext = _customSkiaGpu.GrContext;

                return;
            }

            var gl = AvaloniaLocator.Current.GetService <IWindowingPlatformGlFeature>();

            if (gl != null)
            {
                var display = gl.ImmediateContext.Display;
                gl.ImmediateContext.MakeCurrent();
                using (var iface = display.Type == GlDisplayType.OpenGL2
                    ? GRGlInterface.AssembleGlInterface((_, proc) => display.GlInterface.GetProcAddress(proc))
                    : GRGlInterface.AssembleGlesInterface((_, proc) => display.GlInterface.GetProcAddress(proc)))
                {
                    GrContext = GRContext.Create(GRBackend.OpenGL, iface);
                }
                display.ClearContext();
            }
        }
Exemple #2
0
        private static GRContext GenerateSkiaContext(NativeWindow nativeWindow)
        {
            var nativeContext = Program.GetNativeContext(nativeWindow);
            var glInterface   = GRGlInterface.AssembleGlInterface(nativeContext, (contextHandle, name) => Glfw.GetProcAddress(name));

            return(GRContext.Create(GRBackend.OpenGL, glInterface));
        }
Exemple #3
0
        static void Main(string[] args)
        {
            a.Add(new BezierPiece(new SKPoint(80, 80), new SKPoint(-80, 150)));
            a.Add(new BezierPiece(new SKPoint(280, 80), new SKPoint(380, 180)));
            a.Add(new BezierPiece(new SKPoint(680, 80), new SKPoint(580, 10)));

            using (window = new NativeWindow(800, 600, "BezierSharp", Monitor.None, Window.None))
            {
                Glfw.MakeContextCurrent(window);
                GRGlInterface             glInterface = GRGlInterface.AssembleGlInterface(Glfw.CurrentContext, (contextHandle, name) => Glfw.GetProcAddress(name));
                GRContext                 context     = GRContext.CreateGl(glInterface);
                GRBackendRenderTargetDesc backendRenderTargetDescription = new GRBackendRenderTargetDesc
                {
                    Config             = GRPixelConfig.Rgba8888,
                    Height             = 600,
                    Width              = 800,
                    Origin             = GRSurfaceOrigin.TopLeft,
                    RenderTargetHandle = new IntPtr(0),
                    SampleCount        = 0,
                    StencilBits        = 8
                };


                using (var surface = SKSurface.Create(context, backendRenderTargetDescription))
                {
                    var canvas = surface.Canvas;
                    int height = canvas.DeviceClipBounds.Height;
                    // Main application loop
                    while (!window.IsClosing)
                    {
                        AjustCurve(ref a, height);
                        canvas.Clear(SKColors.White);
                        using (var paint = new SKPaint {
                            Color = SKColors.Blue
                        })
                        {
                            paint.StrokeWidth = 3;
                            paint.Style       = SKPaintStyle.Stroke;
                            paint.IsAntialias = true;

                            a.Draw(ref canvas, paint, SKPathFillType.Winding);
                        }

                        // OpenGL rendering
                        // Implement any timing for flow control, etc (see Glfw.GetTime())
                        canvas.Flush();
                        context.Flush();
                        // Swap the front/back buffers
                        window.SwapBuffers();

                        // Poll native operating system events (must be called or OS will think application is hanging)
                        Glfw.PollEvents();
                    }
                }
            }
        }
        public void AssembleInterfaceIsValid()
        {
            using (var ctx = CreateGlContext()) {
                ctx.MakeCurrent();

                if (IsMac)
                {
                    var lib = MacDynamicLibraries.dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib", 1);

                    var glInterface = GRGlInterface.AssembleGlInterface((context, name) => {
                        return(MacDynamicLibraries.dlsym(lib, name));
                    });

                    Assert.NotNull(glInterface);
                    Assert.True(glInterface.Validate());

                    MacDynamicLibraries.dlclose(lib);
                }
                else if (IsWindows)
                {
                    var lib = WindowsDynamicLibraries.LoadLibrary("opengl32.dll");

                    var glInterface = GRGlInterface.AssembleGlInterface((context, name) => {
                        var ptr = WindowsDynamicLibraries.GetProcAddress(lib, name);
                        if (ptr == IntPtr.Zero)
                        {
                            ptr = wglGetProcAddress(name);
                        }
                        return(ptr);
                    });

                    Assert.NotNull(glInterface);
                    Assert.True(glInterface.Validate());

                    WindowsDynamicLibraries.FreeLibrary(lib);
                }
                else if (IsLinux)
                {
                    var glInterface = GRGlInterface.AssembleGlInterface((context, name) => {
                        return(glXGetProcAddress(name));
                    });

                    Assert.NotNull(glInterface);
                    Assert.True(glInterface.Validate());
                }
                else
                {
                    // more platforms !!!
                    throw new Exception("Some strange platform that is not Windows, macOS nor Linux...");
                }
            }
        }
Exemple #5
0
        public PlatformRenderInterface()
        {
            var gl = AvaloniaLocator.Current.GetService <IWindowingPlatformGlFeature>();

            if (gl != null)
            {
                var display = gl.ImmediateContext.Display;
                var iface   = display.Type == GlDisplayType.OpenGL2
                    ? GRGlInterface.AssembleGlInterface((_, proc) => display.GlInterface.GetProcAddress(proc))
                    : GRGlInterface.AssembleGlesInterface((_, proc) => display.GlInterface.GetProcAddress(proc));
                gl.ImmediateContext.MakeCurrent();
                GrContext = GRContext.Create(GRBackend.OpenGL, iface);
            }
        }
Exemple #6
0
        protected override void OnLoad()
        {
            var iface = GRGlInterface.AssembleGlInterface((_, proc) =>
            {
                if (proc.StartsWith("egl"))
                {
                    return(IntPtr.Zero);
                }
                if (proc == "glShaderSource")
                {
                    return(new ShaderProxy(GLFW.GetProcAddress(proc.ToString())).Pointer);
                }
                return(GLFW.GetProcAddress(proc.ToString()));
            });

            GrContext = GRContext.CreateGl(iface);
            base.OnLoad();
        }
Exemple #7
0
        public GlSkiaGpu(IWindowingPlatformGlFeature gl, long?maxResourceBytes)
        {
            var context = gl.MainContext;

            using (context.MakeCurrent())
            {
                using (var iface = context.Version.Type == GlProfileType.OpenGL ?
                                   GRGlInterface.AssembleGlInterface((_, proc) => context.GlInterface.GetProcAddress(proc)) :
                                   GRGlInterface.AssembleGlesInterface((_, proc) => context.GlInterface.GetProcAddress(proc)))
                {
                    _grContext = GRContext.Create(GRBackend.OpenGL, iface);
                    if (maxResourceBytes.HasValue)
                    {
                        _grContext.GetResourceCacheLimits(out var maxResources, out _);
                        _grContext.SetResourceCacheLimits(maxResources, maxResourceBytes.Value);
                    }
                }
            }
        }