如何解决将 ID3D11Texture2D 渲染为 SkImage (Skia)
我目前正在尝试创建一个互操作层,以将我的渲染目标纹理渲染为 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 举报,一经查实,本站将立刻删除。