问题描述
我目前正在尝试创建一个互操作层,以将我的渲染目标纹理渲染为 Skia SkImage。这样做是为了方便从我的图形 API 渲染到 Avalonia。
我已经设法拼凑出足够多的代码,让一切都运行起来,没有任何错误(至少,我看不到任何错误),但是当我绘制 SkImage 时,我只看到一个黑色图像。
当然,这些东西用代码更容易描述:
private EglPlatformOpenGlInterface _platform;
private AngleWin32Egldisplay _angledisplay;
private readonly int[] _glTexHandle = new int[1];
IDrawingContextImpl context // <-- From Avalonia
_platform = (EglPlatformOpenGlInterface)platform;
_angledisplay = (AngleWin32Egldisplay)_platform.display;
IntPtr d3dDevicePtr = _angledisplay.GetDirect3DDevice();
// Device5 is from SharpDX.
_d3dDevice = new Device5(d3dDevicePtr);
// Texture.GetSharedHandle() is the shared handle of my render target.
_eglTarget = _d3dDevice.OpenSharedResource<Texture2D>(_target.Texture.GetSharedHandle());
// WrapDirect3D11Texture calls eglCreatePbufferFromClientBuffer.
_glSurface = _angledisplay.WrapDirect3D11Texture(_platform,_eglTarget.NativePointer);
using (_platform.PrimaryEglContext.MakeCurrent())
{
_platform.PrimaryEglContext.GlInterface.GenTextures(1,_glTexHandle);
}
var fbInfo = new GRGlTextureInfo(GlConsts.GL_TEXTURE_2D,(uint)_glTexHandle[0],GlConsts.GL_RGBA8);
_backendTarget = new GRBackendTexture(_target.Width,_target.Height,false,fbInfo);
using (_platform.PrimaryEglContext.MakeCurrent())
{
// Here's where we find the gl surface to our texture object apparently.
_platform.PrimaryEglContext.GlInterface.BindTexture(GlConsts.GL_TEXTURE_2D,_glTexHandle[0]);
EglBindTexImage(_angledisplay.Handle,_glSurface.DangerousGetHandle(),EglConsts.EGL_BACK_BUFFER);
_platform.PrimaryEglContext.GlInterface.BindTexture(GlConsts.GL_TEXTURE_2D,0);
}
// context is a GRContext
_skiaSurface = SKImage.FromTexture(context,_backendTarget,GRSurfaceOrigin.BottomLeft,SKColorType.Rgba8888,SKAlphaType.Premul);
// This clears my render target (obvIoUsly). I should be seeing this when I draw the image right?
_target.Clear(GorgonColor.CornFlowerBlue);
canvas.DrawImage(_skiaSurface,new SKPoint(320,240));
所以,据我所知,这应该有效。但正如我之前所说,它只向我展示了一个黑色图像。应该是矢车菊蓝。我已经尝试在 Flush
上调用 ID3D11DeviceContext
,但我仍然得到黑色图像。
有人知道我可能做错了什么吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)