private void CreateContext() { // create the interface using the function pointers provided by the EFL var glInterface = GRGlInterface.CreateNativeEvasInterface(glEvas); context = GRContext.Create(GRBackend.OpenGL, glInterface); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { //base.OnPaint(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.Width = Width; renderTarget.Height = Height; // create the surface using (var surface = SKSurface.Create(grContext, renderTarget)) { if (PaintSurface != null) { PaintSurface.Invoke(surface); } // start drawing OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget)); surface.Canvas.Flush(); } // update the control SwapBuffers(); }
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(); } }
protected override void OnLoad(EventArgs ee) { base.OnLoad(ee); var glInterface = GRGlInterface.CreateNativeGlInterface(); Debug.Assert(glInterface.Validate()); this.context = GRContext.Create(GRBackend.OpenGL, glInterface); Debug.Assert(this.context.Handle != IntPtr.Zero); this.renderTarget = CreateRenderTarget(); this.KeyDown += (o, e) => { if (e.Key == Key.Escape) { this.Close(); } }; InputMouse = new InputMouse(this); InputMouse.MouseDown += state => Engine.OnMouse(state); InputMouse.MouseUp += state => Engine.OnMouse(state); InputMouse.MouseMove += state => Engine.OnMouse(state); InputMouse.MousePressedMove += state => Engine.OnMouse(state); FocusedChanged += OnFocusedChanged; // WindowState = WindowState.Fullscreen; CursorVisible = false; }
private void PrepareGLContexts() { // create GL context glContext = new EAGLContext(EAGLRenderingAPI.OpenGLES2); EAGLContext.SetCurrentContext(glContext); // create render buffer Gles.glGenRenderbuffers(1, ref renderBuffer); Gles.glBindRenderbuffer(Gles.GL_RENDERBUFFER, renderBuffer); glContext.RenderBufferStorage(Gles.GL_RENDERBUFFER, this); // create frame buffer Gles.glGenFramebuffers(1, ref framebuffer); Gles.glBindFramebuffer(Gles.GL_FRAMEBUFFER, framebuffer); Gles.glFramebufferRenderbuffer(Gles.GL_FRAMEBUFFER, Gles.GL_COLOR_ATTACHMENT0, Gles.GL_RENDERBUFFER, renderBuffer); // get the bits for SkiaSharp var glInterface = GRGlInterface.Create(); context = GRContext.CreateGl(glInterface); // finished EAGLContext.SetCurrentContext(null); recreateSurface = true; }
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.Create(); context = GRContext.CreateGl(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(); }
private void InitSkia() { if (grContext == null) { var glInterface = GRGlInterface.Create(); grContext = GRContext.CreateGl(glInterface); } // define the surface properties // create or update the dimensions renderTarget?.Dispose(); GL.GetInteger(GetPName.FramebufferBinding, out var framebuffer); var stencil = 0; GL.GetInteger(GetPName.Samples, out var samples); var maxSamples = grContext.GetMaxSurfaceSampleCount(ColorType); if (samples > maxSamples) { samples = maxSamples; } var glInfo = new GRGlFramebufferInfo((uint)framebuffer, ColorType.ToGlSizedFormat()); renderTarget = new GRBackendRenderTarget(CurrentSize.X, CurrentSize.Y, 0, 0, glInfo); // create the surface surface?.Dispose(); surface = SKSurface.Create(grContext, renderTarget, SurfaceOrigin, ColorType); Paint = new SKPaint { Color = new SKColor(0, 128, 0), IsAntialias = true }; }
public new void DrawInRect(GLKView view, CGRect rect) { if (designMode) { return; } if (context == null) { var glInterface = GRGlInterface.CreateNativeGlInterface(); context = GRContext.Create(GRBackend.OpenGL, glInterface); // get the initial details renderTarget = SKGLDrawable.CreateRenderTarget(); } // set the dimensions as they might have changed renderTarget.Width = (int)DrawableWidth; renderTarget.Height = (int)DrawableHeight; // create the surface using (var surface = SKSurface.Create(context, renderTarget)) { // draw on the surface DrawInSurface(surface, renderTarget); surface.Canvas.Flush(); } // flush the SkiaSharp contents to GL context.Flush(); }
protected override void OnLoad(EventArgs ee) { base.OnLoad(ee); var glInterface = GRGlInterface.CreateNativeGlInterface(); Debug.Assert(glInterface.Validate()); this._context = GRContext.Create(GRBackend.OpenGL, glInterface); Debug.Assert(this._context.Handle != IntPtr.Zero); this._renderTarget = CreateRenderTarget(_context); this.KeyDown += (o, e) => { if (e.Key == Key.Escape) { this.Close(); } }; FocusedChanged += OnFocusedChanged; InitMouse(); // WindowState = WindowState.Fullscreen; CursorVisible = false; this.CursorVisible = true; }
public override void DrawInCGLContext(CGLContext glContext, CGLPixelFormat pixelFormat, double timeInterval, ref CVTimeStamp timeStamp) { CGLContext.CurrentContext = glContext; if (context == null) { // get the bits for SkiaSharp var glInterface = GRGlInterface.CreateNativeGlInterface(); context = GRContext.Create(GRBackend.OpenGL, glInterface); } // create the surface renderTarget = SKGLDrawable.CreateRenderTarget(); renderTarget.Width = (int)(Bounds.Width * ContentsScale); renderTarget.Height = (int)(Bounds.Height * ContentsScale); using (var surface = SKSurface.Create(context, renderTarget)) { // draw on the surface DrawInSurface(surface, renderTarget); SKDelegate?.DrawInSurface(surface, renderTarget); surface.Canvas.Flush(); } // flush the SkiaSharp context to the GL context context.Flush(); base.DrawInCGLContext(glContext, pixelFormat, timeInterval, ref timeStamp); }
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(); }
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(); }
protected sealed override void CreateDrawingSurface() { if (glSurface == IntPtr.Zero) { // create the surface glSurface = Evas.evas_gl_surface_create(glEvas, glConfigPtr, surfaceSize.Width, surfaceSize.Height); // copy the native surface to the image Evas.evas_gl_native_surface_get(glEvas, glSurface, out var nativeSurface); Evas.evas_object_image_native_surface_set(evasImage, ref nativeSurface); // switch to the current OpenGL context Evas.evas_gl_make_current(glEvas, glSurface, glContext); // resize the viewport Gles.glViewport(0, 0, surfaceSize.Width, surfaceSize.Height); // create the interface using the function pointers provided by the EFL var glInterface = GRGlInterface.CreateNativeEvasInterface(glEvas); context?.Dispose(); context = GRContext.Create(GRBackend.OpenGL, glInterface); // create the render target 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(surfaceSize.Width, surfaceSize.Height, context.GetMaxSurfaceSampleCount(colorType), stencil, glInfo); // create the surface surface?.Dispose(); surface = SKSurface.Create(context, renderTarget, surfaceOrigin, colorType); } }
protected sealed override void CreateDrawingSurface() { if (glSurface == IntPtr.Zero) { // create the surface glSurface = Evas.evas_gl_surface_create(glEvas, glConfigPtr, surfaceSize.Width, surfaceSize.Height); // copy the native surface to the image Evas.evas_gl_native_surface_get(glEvas, glSurface, out var nativeSurface); Evas.evas_object_image_native_surface_set(evasImage, ref nativeSurface); // switch to the current OpenGL context Evas.evas_gl_make_current(glEvas, glSurface, glContext); // resize the viewport Gles.glViewport(0, 0, surfaceSize.Width, surfaceSize.Height); // create the interface using the function pointers provided by the EFL var glInterface = GRGlInterface.CreateNativeEvasInterface(glEvas); context?.Dispose(); context = GRContext.Create(GRBackend.OpenGL, glInterface); // create the render target renderTarget?.Dispose(); renderTarget = SKGLDrawable.CreateRenderTarget(surfaceSize.Width, surfaceSize.Height); // create the surface surface?.Dispose(); surface = SKSurface.Create(context, renderTarget, GRSurfaceOrigin.BottomLeft, SKImageInfo.PlatformColorType); } }
private void glControl1_Paint(object sender, PaintEventArgs e) { Control senderControl = (Control)sender; if (context == null) { var glInterface = GRGlInterface.CreateNativeGlInterface(); context = GRContext.Create(GRBackend.OpenGL, glInterface); } if (renderTarget == null || surface == null || renderTarget.Width != senderControl.Width || renderTarget.Height != senderControl.Height) { renderTarget?.Dispose(); GL.GetInteger(GetPName.FramebufferBinding, out var framebuffer); GL.GetInteger(GetPName.StencilBits, out var stencil); var glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat()); renderTarget = new GRBackendRenderTarget(senderControl.Width, senderControl.Height, context.GetMaxSurfaceSampleCount(colorType), stencil, glInfo); surface?.Dispose(); surface = SKSurface.Create(context, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888); } figure.Render(surface.Canvas, figureSize, plotEngagedWithMouse); surface.Canvas.Flush(); glControl1.SwapBuffers(); }
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)); }
private void CreateContext() { if (context == null) { var glInterface = GRGlInterface.CreateNativeGlInterface(); context = GRContext.Create(GRBackend.OpenGL, glInterface); } }
public override void PrepareOpenGL() { base.PrepareOpenGL(); // create the context var glInterface = GRGlInterface.CreateNativeGlInterface(); context = GRContext.Create(GRBackend.OpenGL, glInterface); }
public override void PrepareOpenGL() { base.PrepareOpenGL(); // create the context var glInterface = GRGlInterface.Create(); context = GRContext.CreateGl(glInterface); }
internal void RenderFrame() { if (!jsInfo.IsValid) { return; } // create the SkiaSharp context if (context == null) { glInterface = GRGlInterface.Create(); context = GRContext.CreateGl(glInterface); // bump the default resource cache limit context.SetResourceCacheLimit(ResourceCacheBytes); } // get the new surface size var newSize = new SKSizeI((int)(ActualWidth * ContentsScale), (int)(ActualHeight * ContentsScale)); // manage the drawing surface if (renderTarget == null || lastSize != newSize || !renderTarget.IsValid) { // create or update the dimensions lastSize = newSize; glInfo = new GRGlFramebufferInfo(jsInfo.FboId, 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, jsInfo.Samples, jsInfo.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 #pragma warning disable CS0612 // Type or member is obsolete OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType, glInfo)); #pragma warning restore CS0612 // Type or member is obsolete } // update the control canvas.Flush(); context.Flush(); }
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 CreateSpecificContextIsValid() { using (var ctx = CreateGlContext()) { ctx.MakeCurrent(); var glInterface = GRGlInterface.CreateNativeGlInterface(); var grContext = GRContext.Create(GRBackend.OpenGL, glInterface); } }
private GRContext GenerateSkiaContext(NativeWindow nativeWindow) { var glInterface = GRGlInterface.CreateNativeGlInterface(); if (glInterface == null) { throw new PlatformNotSupportedException(); } return(GRContext.CreateGl(glInterface)); }
protected override void OnAfterRender(bool firstRender) { if (firstRender) { Threading.Dispatcher.UIThread.Post(async() => { _inputHelper = await InputHelperInterop.ImportAsync(Js, _inputElement); _canvasHelper = await InputHelperInterop.ImportAsync(Js, _htmlCanvas); _inputHelper.Hide(); _canvasHelper.SetCursor("default"); _topLevelImpl.SetCssCursor = x => { _inputHelper.SetCursor(x); //macOS _canvasHelper.SetCursor(x); //windows }; Console.WriteLine("starting html canvas setup"); _interop = await SKHtmlCanvasInterop.ImportAsync(Js, _htmlCanvas, OnRenderFrame); Console.WriteLine("Interop created"); _jsGlInfo = _interop.InitGL(); Console.WriteLine("jsglinfo created - init gl"); _sizeWatcher = await SizeWatcherInterop.ImportAsync(Js, _htmlCanvas, OnSizeChanged); _dpiWatcher = await DpiWatcherInterop.ImportAsync(Js, OnDpiChanged); Console.WriteLine("watchers created."); // create the SkiaSharp context if (_context == null) { Console.WriteLine("create glcontext"); _glInterface = GRGlInterface.Create(); _context = GRContext.CreateGl(_glInterface); var options = AvaloniaLocator.Current.GetService <SkiaOptions>(); // bump the default resource cache limit _context.SetResourceCacheLimit(options?.MaxGpuResourceSizeBytes ?? 32 * 1024 * 1024); Console.WriteLine("glcontext created and resource limit set"); } _topLevelImpl.SetSurface(_context, _jsGlInfo, ColorType, new PixelSize((int)_canvasSize.Width, (int)_canvasSize.Height), _dpi); _initialised = true; _topLevel.Prepare(); _topLevel.Renderer.Start(); Invalidate(); }); } }
protected override void OnRenderFrame() { var rect = Allocation; // create the contexts if not done already if (grContext == null) { var glInterface = GRGlInterface.CreateNativeGlInterface(); if (glInterface == null) { Console.WriteLine("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.", "Error Creating OpenGL ES interface"); System.Diagnostics.Process.GetCurrentProcess().Kill(); } else { grContext = GRContext.Create(GRBackend.OpenGL, glInterface); } try { renderTarget = CreateRenderTarget(); } catch (Exception ex) { Console.WriteLine("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.\nError message:\n" + ex.ToString()); System.Diagnostics.Process.GetCurrentProcess().Kill(); } } if (grContext != null) { // update to the latest dimensions renderTarget.Width = rect.Width; renderTarget.Height = rect.Height; // create the surface using (var surface = SKSurface.Create(grContext, renderTarget)) { surface.Canvas.Clear(SKColors.White); // start drawing if (fsurface != null) { fsurface.UpdateSurface(surface); } // start drawing OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget)); surface.Canvas.Flush(); } } }
public void CreateDefaultInterfaceIsValid() { using (var ctx = CreateGlContext()) { ctx.MakeCurrent(); var glInterface = GRGlInterface.CreateNativeGlInterface(); Assert.NotNull(glInterface); Assert.True(glInterface.Validate()); } }
protected override GRContext TryBuildGRContext() { var glInterface = GRGlInterface.Create(); if (glInterface == null) { throw new NotSupportedException($"OpenGL is not supported in this system"); } return(GRContext.CreateGl(glInterface)); }
void RenderWithSkia() { int width = glControl1.Width; int height = glControl1.Height; if (field == null || field.width != width || field.height != height) { field = new Starfield.Field(100_000, width, height); } field.StepForward(); // Create a Skia surface using the OpenGL control SKColorType colorType = SKColorType.Rgba8888; GRContext contextOpenGL = GRContext.Create(GRBackend.OpenGL, GRGlInterface.CreateNativeGlInterface()); GL.GetInteger(GetPName.FramebufferBinding, out var framebuffer); GRGlFramebufferInfo glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat()); GL.GetInteger(GetPName.StencilBits, out var stencil); GRBackendRenderTarget renderTarget = new GRBackendRenderTarget(width, height, contextOpenGL.GetMaxSurfaceSampleCount(colorType), stencil, glInfo); SKSurface surface = SKSurface.Create(contextOpenGL, renderTarget, GRSurfaceOrigin.BottomLeft, colorType); SKCanvas canvas = surface.Canvas; // draw the starfield var paint = new SKPaint { Color = SKColors.White, IsAntialias = true }; canvas.Clear(SKColors.Black); foreach (Starfield.Star star in field.stars) { //canvas.DrawRect(star.X, star.Y, star.Size, star.Size, paint); canvas.DrawCircle(new SKPoint(star.X, star.Y), star.Size / 2, paint); } // Force a display surface.Canvas.Flush(); glControl1.SwapBuffers(); // dispose to prevent memory access violations while exiting renderTarget?.Dispose(); contextOpenGL?.Dispose(); canvas?.Dispose(); surface?.Dispose(); // update the FPS display renderCount += 1; double elapsedSeconds = (double)stopwatch.ElapsedMilliseconds / 1000; Text = string.Format("Rendered {0} frames in {1:0.00} seconds ({2:0.00} Hz)", renderCount, elapsedSeconds, renderCount / elapsedSeconds); }
protected sealed override void CreateDrawingSurface() { if (glSurface == IntPtr.Zero) { // create the surface glSurface = Evas.evas_gl_surface_create(glEvas, glConfigPtr, surfaceSize.Width, surfaceSize.Height); // copy the native surface to the image Evas.evas_gl_native_surface_get(glEvas, glSurface, out var nativeSurface); Evas.evas_object_image_native_surface_set(evasImage, ref nativeSurface); // switch to the current OpenGL context Evas.evas_gl_make_current(glEvas, glSurface, glContext); // resize the viewport Gles.glViewport(0, 0, surfaceSize.Width, surfaceSize.Height); // create the interface using the function pointers provided by the EFL var glInterface = GRGlInterface.CreateEvas(glEvas); if (glInterface == null) { Log.Error("SKGLSurfaceView", "Unable to create GRGlInterface."); } if (!glInterface.Validate()) { Log.Error("SKGLSurfaceView", "The created GRGlInterface was not valid."); } context?.Dispose(); context = GRContext.CreateGl(glInterface); if (context == null) { Log.Error("SKGLSurfaceView", "Unable to create the GRContext."); } // create the render target renderTarget?.Dispose(); 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()); renderTarget = new GRBackendRenderTarget(surfaceSize.Width, surfaceSize.Height, samples, stencil, glInfo); // create the surface surface?.Dispose(); surface = SKSurface.Create(context, renderTarget, surfaceOrigin, colorType); canvas = surface.Canvas; } }
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..."); } } }