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); } }
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.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; } }
protected override void Dispose(bool disposing) { base.Dispose(disposing); context.Dispose(); glContext.Dispose(); }
public override void Dispose() { surface?.Dispose(); renderTarget?.Dispose(); grContext?.Dispose(); base.Dispose(); }
protected override void OnClosing(CancelEventArgs e) { renderTarget?.Dispose(); contextOpenGL?.Dispose(); surface?.Dispose(); base.OnClosing(e); }
private void FreeContext() { if (context != null) { context.Dispose(); context = null; } }
private void FreeContext() { surface?.Dispose(); surface = null; renderTarget?.Dispose(); renderTarget = null; context?.Dispose(); context = null; }
private void DestroyContext() { if (context != null) { // dispose the unmanaged memory context.Dispose(); context = null; } }
protected override void Dispose(bool disposing) { base.Dispose(disposing); // clean up if (grContext != null) { grContext.Dispose(); grContext = null; } }
public override void Dispose() { base.Dispose(); // clean up if (grContext != null) { grContext.Dispose(); grContext = null; } }
private void OnUnload(object sender, EventArgs e) { textureSurface.Dispose(); textureSurface = null; renderSurface.Dispose(); renderSurface = null; context.Dispose(); context = null; }
protected override void Dispose(bool disposing) { base.Dispose(disposing); // clean up surface?.Dispose(); surface = null; renderTarget?.Dispose(); renderTarget = null; grContext?.Dispose(); grContext = null; }
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 void Dispose() { // clean up canvas = null; surface?.Dispose(); surface = null; renderTarget?.Dispose(); renderTarget = null; grContext?.Dispose(); grContext = null; disposed = true; }
private void OnPaintSurface(SKCanvas canvas, int width, int height) { var canvasSize = new SKSize(width, height); // check if we need to recreate the off-screen surface if (_screenCanvasSize != canvasSize) { _surface?.Dispose(); _grContext?.Dispose(); _grContext = GRContext.Create(GRBackend.OpenGL); _surface = SKSurface.Create(_grContext, true, new SKImageInfo(width, height)); _screenCanvasSize = canvasSize; } // draw onto off-screen gl context DrawOffscreen(_surface.Canvas, width, height); // draw offscreen surface onto screen canvas.DrawSurface(_surface, new SKPoint(0f, 0f)); }
private void RenderWithOpenGL(object sender, PaintEventArgs e) { Control sctl = (Control)sender; int width = sctl.Width; int height = sctl.Height; // setup the Skia surface using OpenGL 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); // Draw some stuff on the canvas surface.Canvas.Clear(SKColor.Parse("#FFFFFF")); // adds about 3ms fullscreen byte alpha = 128; var paint = new SKPaint(); for (int i = 0; i < 1_000; i++) { float x1 = (float)(rand.NextDouble() * width); float x2 = (float)(rand.NextDouble() * width); float y1 = (float)(rand.NextDouble() * height); float y2 = (float)(rand.NextDouble() * height); paint.Color = new SKColor( red: (byte)(rand.NextDouble() * 255), green: (byte)(rand.NextDouble() * 255), blue: (byte)(rand.NextDouble() * 255), alpha: alpha ); surface.Canvas.DrawLine(x1, y1, x2, y2, paint); } surface.Canvas.Flush(); glControl1.SwapBuffers(); // prevent memory access violations by disposing before exiting renderTarget?.Dispose(); contextOpenGL?.Dispose(); surface?.Dispose(); }
void Render() { // Create a Skia surface using the OpenGL control int width = glControl1.Width; int height = glControl1.Height; 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 some lines canvas.Clear(SKColor.Parse("#003366")); var paint = new SKPaint { Color = new SKColor(255, 255, 255, 50), IsAntialias = true }; for (int i = 0; i < 1_000; i++) { SKPoint ptA = new SKPoint(rand.Next(width), rand.Next(height)); SKPoint ptB = new SKPoint(rand.Next(width), rand.Next(height)); canvas.DrawLine(ptA, ptB, 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 virtual void Dispose(bool disposing) { if (disposing) { if (_config != null) { Toml.WriteFile(_config, "config.toml", _tomlSettings); _config = null; } _waveIn?.StopRecording(); _waveIn?.Dispose(); _waveIn = null; _speechRecognizer?.Dispose(); _speechRecognizer = null; _skFont?.Dispose(); _skFont = null; _skStrokePaint?.Dispose(); _skStrokePaint = null; _skFillPaint?.Dispose(); _skFillPaint = null; _skScreenSurface?.Dispose(); _skScreenSurface = null; _skScreenRenderTarget?.Dispose(); _skScreenRenderTarget = null; _skContext?.Dispose(); _skContext = null; _skInterface?.Dispose(); _skInterface = null; _tkContext?.Dispose(); _tkContext = null; _tkWindow?.Dispose(); _tkWindow = null; } }
protected override void OnDestroyingContext() { base.OnDestroyingContext(); lastSize = default; canvas?.Dispose(); canvas = null; surface?.Dispose(); surface = null; renderTarget?.Dispose(); renderTarget = null; glInfo = default; context?.AbandonContext(false); context?.Dispose(); context = null; glInterface?.Dispose(); glInterface = null; }
private void Render(int lineCount) { Stopwatch stopwatch = Stopwatch.StartNew(); // set up the Skia surface using OpenGL 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 stencilBits); GRBackendRenderTarget renderTarget = new GRBackendRenderTarget( width: skglControl1.Width, height: skglControl1.Height, sampleCount: contextOpenGL.GetMaxSurfaceSampleCount(colorType), stencilBits: stencilBits, glInfo: glInfo); SKSurface surface = SKSurface.Create( context: contextOpenGL, renderTarget: renderTarget, origin: GRSurfaceOrigin.BottomLeft, colorType: colorType); // perform the drawing surface.Canvas.Clear(SKColor.Parse("#003366")); for (int i = 0; i < lineCount; i++) { var paint = new SKPaint { Color = new SKColor( red: (byte)rand.Next(255), green: (byte)rand.Next(255), blue: (byte)rand.Next(255), alpha: (byte)rand.Next(255)), StrokeWidth = rand.Next(1, 10), IsAntialias = true }; surface.Canvas.DrawLine( x0: rand.Next(skglControl1.Width), y0: rand.Next(skglControl1.Height), x1: rand.Next(skglControl1.Width), y1: rand.Next(skglControl1.Height), paint: paint); } // Force a display surface.Canvas.Flush(); skglControl1.SwapBuffers(); // prevent memory access violations by disposing before exiting renderTarget?.Dispose(); contextOpenGL?.Dispose(); surface?.Dispose(); stopwatch.Stop(); renderTimesMsec.Add(1000.0 * stopwatch.ElapsedTicks / Stopwatch.Frequency); double mean = renderTimesMsec.Sum() / renderTimesMsec.Count(); Debug.WriteLine($"Render {renderTimesMsec.Count:00} " + $"took {renderTimesMsec.Last():0.000} ms " + $"(running mean: {mean:0.000} ms)"); Application.DoEvents(); }
private void Render(int cornerCount = 100, int maxVisibleDistance = 200) { // create the field if needed or if the size changed if (field == null || field.width != glControl1.Width || field.height != glControl1.Height) { field = new IntroAnimation.Field(glControl1.Width, glControl1.Height, cornerCount); } // step the field forward in time field.StepForward(3); // 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(glControl1.Width, glControl1.Height, contextOpenGL.GetMaxSurfaceSampleCount(colorType), stencil, glInfo); SKSurface surface = SKSurface.Create(contextOpenGL, renderTarget, GRSurfaceOrigin.BottomLeft, colorType); SKCanvas canvas = surface.Canvas; // draw the stuff var bgColor = field.GetBackgroundColor(); canvas.Clear(new SKColor(bgColor.R, bgColor.G, bgColor.B)); // draw circles at every corner var paint = new SKPaint { Color = new SKColor(255, 255, 255), IsAntialias = true }; float radius = 2; for (int cornerIndex = 0; cornerIndex < field.corners.Length; cornerIndex++) { canvas.DrawCircle((float)field.corners[cornerIndex].X, (float)field.corners[cornerIndex].Y, radius, paint); } // draw lines between every corner and every other corner for (int i = 0; i < field.corners.Length; i++) { for (int j = 0; j < field.corners.Length; j++) { double distance = field.GetDistance(i, j); if (distance < maxVisibleDistance && distance != 0) { SKPoint pt1 = new SKPoint((float)field.corners[i].X, (float)field.corners[i].Y); SKPoint pt2 = new SKPoint((float)field.corners[j].X, (float)field.corners[j].Y); double distanceFraction = distance / maxVisibleDistance; byte alpha = (byte)(255 - distanceFraction * 256); var linePaint = new SKPaint { Color = new SKColor(255, 255, 255, alpha), IsAntialias = true }; canvas.DrawLine(pt1, pt2, linePaint); } } } // 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 Text = field.GetBenchmarkMessage(); }
private void OnDispose(Object sender, EventArgs e) { renderTarget?.Dispose(); surface?.Dispose(); context?.Dispose(); }
public void Dispose() { _grVkBackend.Dispose(); GrContext.Dispose(); _surface.Dispose(); }
public override void Release(CGLContext glContext) { context.Dispose(); base.Release(glContext); }
protected override void Dispose(bool disposing) { grContext.Dispose(); base.Dispose(disposing); }