From 6593f462e48d77f06c01c6767473ad6aba1485d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=BA=A2=E5=B8=BD?= <761716178@qq.com> Date: Tue, 28 Nov 2023 12:48:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4gl=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CPF.Skia/GlView.cs | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/CPF.Skia/GlView.cs b/CPF.Skia/GlView.cs index 467d8d5..af93c99 100644 --- a/CPF.Skia/GlView.cs +++ b/CPF.Skia/GlView.cs @@ -112,28 +112,34 @@ namespace CPF.Skia gl.BindTexture(GlConsts.GL_TEXTURE_2D, oldTexture); gl.BindFramebuffer(GlConsts.GL_FRAMEBUFFER, oldfb); // using (var backendTexture = new GRBackendRenderTarget(size.Width, size.Height, samples, stencil, framebufferInfo)) - using (var backendTexture = new GRBackendTexture((int)size.Width, (int)size.Height, false, new GRGlTextureInfo { Format = GlConsts.GL_RGBA8, Id = (uint)texture, Target = GlConsts.GL_TEXTURE_2D })) - { - // using (var surface = SKSurface.Create((GRContext)skia.GlContext.GRContext, backendTexture, GRSurfaceOrigin.TopLeft, SKColorType.Rgba8888)) - using (var surface = SKSurface.Create((GRContext)skia.GlContext.GRContext, backendTexture, GRSurfaceOrigin.TopLeft, SKColorType.Rgba8888)) - { - //if (surface == null) - // return; - //byte[] data = new byte[size.Width * size.Height * 4]; - //gl.GetTexImage(GlConsts.GL_TEXTURE_2D, 0, GlConsts.GL_RGBA, GlConsts.GL_UNSIGNED_BYTE, data); + //using (var backendTexture = new GRBackendTexture((int)size.Width, (int)size.Height, false, new GRGlTextureInfo { Format = GlConsts.GL_RGBA8, Id = (uint)texture, Target = GlConsts.GL_TEXTURE_2D })) + //{ + // // using (var surface = SKSurface.Create((GRContext)skia.GlContext.GRContext, backendTexture, GRSurfaceOrigin.TopLeft, SKColorType.Rgba8888)) + // using (var surface = SKSurface.Create((GRContext)skia.GlContext.GRContext, backendTexture, GRSurfaceOrigin.TopLeft, SKColorType.Rgba8888)) + // { + // //if (surface == null) + // // return; + // //byte[] data = new byte[size.Width * size.Height * 4]; + // //gl.GetTexImage(GlConsts.GL_TEXTURE_2D, 0, GlConsts.GL_RGBA, GlConsts.GL_UNSIGNED_BYTE, data); - //System.Diagnostics.Debug.WriteLine($"{oldfb},{oldRenderbuffer},{oldTexture}"); + // //System.Diagnostics.Debug.WriteLine($"{oldfb},{oldRenderbuffer},{oldTexture}"); - //恢复状态 - gl.MatrixMode(GlConsts.GL_MODELVIEW); - gl.PopMatrix(); - gl.MatrixMode(GlConsts.GL_PROJECTION); - gl.PopMatrix(); - gl.PopAttrib(); + //恢复状态 + gl.MatrixMode(GlConsts.GL_MODELVIEW); + gl.PopMatrix(); + gl.MatrixMode(GlConsts.GL_PROJECTION); + gl.PopMatrix(); + gl.PopAttrib(); - skia.SKCanvas.DrawSurface(surface, 0, 0); - } - } + // skia.SKCanvas.DrawSurface(surface, 0, 0); + // } + //} + + + GRBackendTexture backendTexture = new GRBackendTexture((int)size.Width, (int)size.Height, false, new GRGlTextureInfo(0x0DE1, (uint)texture, SKColorType.Rgba8888.ToGlSizedFormat())); + + var sKImage = SKImage.FromTexture((GRContext)skia.GlContext.GRContext, backendTexture, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888); + skia.SKCanvas.DrawImage(sKImage, 0, 0); //unsafe //{ // fixed (byte* p = data)