- Home /
Question by
BJO · Sep 18, 2014 at 09:46 PM ·
renderinggraphicsrendertexture
Does Graphics.DrawMeshNow() block the thread until rendering is complete
I've been trying to use the DrawMeshNow method, but can't seem to get it to work. I'm currently treating the call as if it was synchronous. Is this an incorrect assumption? Sample code is below:
private void Update()
{
RenderTexture renderTexture = RenderTexture.GetTemporary(Screen.width, Screen.height);
Graphics.SetRenderTarget(renderTexture);
renderer.material.SetPass(0);
Mesh mesh = GetComponent<MeshFilter>().mesh;
Graphics.DrawMeshNow(mesh, Vector3.zero, Quaternion.identity);
Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.ARGB32, false);
texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
Graphics.SetRenderTarget(null);
RenderTexture.ReleaseTemporary(renderTexture);
}
Note that while in the sample code I'm instantiating everything inside of Update, in practice this only happens once.
A related question, I also have no idea which camera is used for DrawMeshNow(). Therefore, I have no idea how I should be positioning and rotating my mesh.
Thanks for your help!
P.S. This question is a more targeted spin-off of: http://answers.unity3d.com/questions/792958/checking-for-transparency-in-texture-when-clicking.html
Comment