Unity OpenGL Texture not accessible in build
I am trying to pass the render texture from Unity into a C++ plugin to then use CUDA on the texture. This works fine in DirectX in editor and build, and also OpenGL in editor. But when I build in OpenGL it gives me a blank texture. I've also noticed that if I try and save said texture it also saves as a blank texture. I call my plugin using GL.IssuePluginEvent(PluginFunction(), 1), and this happens in a coroutine after yield return new WaitForEndOfFrame(). Any ideas on how to fix it?
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);
}
}
Comment
Your answer
Follow this Question
Related Questions
Why are there speckles on my texture? 0 Answers
OpenGL textures always show up black 0 Answers
Problem with textures 0 Answers
Unity Project Heavily Bugged When Downloaded As Collab Project 0 Answers