Hello guys.
I’m porting my game from Windows Phone to Android. It looks really good, after some adjustments in code it run almost perfect.
However I found out strange behaviour of Texture2D.GetData() function. What I get after this operation is array filled with zeros (RGBA = 0, 0, 0, 0). Texture which were used for getting data are displayed properly.
Ok guys. I put monogame code in my project to debug this issue a little. And everything looks ok, but in function PlatformGetData (Texture2D.OpenGL.cs) on line 254 GL.ReadPixels returns zeros. So this is some opengl issue. There are no any errors, only zeros. Maybe some ideas?
Ok guys. I found out what was wrong. I was getting texture array on seperate thread. That was why it returns zeros.
It was done on purpose, because I was doing this on splash screen to load data asynchronously. Maybe you have idea how to do this to read this texture arrays and doesn’t block my display thread.
OpenGL is not very thread friendly, especially OpenGL ES as used on mobile devices. OpenGL ES 2 does not even officially support reading data back from the GPU, so we’re using some hack work-arounds to get that feature. OpenGL uses shared contexts to support multiple threads, and we don’t have shared contexts on Android due to lower level issues. All GPU-related functions are executed on the main render thread while the calling thread is blocked.