我试图将渲染纹理从Unity传递到C ++插件中,然后在纹理上使用CUDA。这在DirectX的编辑器和内部版本以及OpenGL的编辑器中都可以正常工作。但是当我在OpenGL中构建时,它给了我空白的纹理。我还注意到,如果尝试保存所说的纹理,它也会另存为空白纹理。我使用GL.IssuePluginEvent(PluginFunction(),1)调用我的插件,这在协程中发生,在yield返回新的WaitForEndOfFrame()之后。关于如何解决它的任何想法?
private IEnumerator CallPlugin()
{
while (enabled) {
yield return new WaitForEndOfFrame();
//Attempt to save image to file, only works in editor
// Texture2D tex = new Texture2D(width, height, TextureFormat.RGBA32, false);
// RenderTexture.active = _renderTexture;
// tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
// tex.Apply();
// byte[] bytes = tex.EncodeToPNG();
// System.IO.File.WriteAllBytes("takeScreenshot.png", bytes);
GL.IssuePluginEvent(GetRenderEventFunc(), 1);
}
}
void OnRenderImage(RenderTexture src, RenderTexture dest)
{
if (shader != null)
{
Graphics.Blit(src, dest, material);
}
}