- August 5, 2009 at 5:09 pm #29881
I am loading Fonts and Images on demand as I need to display them. So while I draw the current frame I may bind a few textures and send some vertices to draw them and then have to create a texture, use glTexSubImage to update it and then use it in a draw.
Sometimes while this is happening a few textures will become distorted (the one that was last loaded). I sometimes also see what I expect to be on the texture flash on the screen and then disappear. I have found that the only way to stop this is to remove the glDrawArrays calls that a4re used to show these dynamic textures. At that point I will still create the textures but never draw them.
Is it possible its a timing issue and if so what should I do to make sure the new textures are not distorted?August 5, 2009 at 5:19 pm #33294
First of all, on what platform are you seeing these problems?
We strongly discourage using glTexSubImage to update textures mid-frame. It can be a very expensive operation if the texture has already been used in the current or previous frames. I’d recommend creating new texture objects for textures you need to load on demand, and loading them at the start of a frame, not in between draw calls.August 5, 2009 at 5:36 pm #33295
The problem is seen on Windows CE.
The slowdown is acceptable for what I am working on but are you saying I should not do this regardless?August 6, 2009 at 5:37 pm #33296
So I moved font loading to application load and found that I no longer have any texture distortion. I cant do this with all images though because they may change on the server during application run time so I guess I just need to make sure they are loaded at frame start.
Before making any changes, what do you consider to be ‘start of the frame’? Does that just mean before any calls to glDrawArrays or should I start the load before doing anything after the eglSwapBuffer call?
Just wondering, my initial design should have worked, correct? Like I should be able to call texSubImage at any time and it should only be an issue that its slow and my textures should not be distorted?August 10, 2009 at 6:58 pm #33297
I believe I may have found the solution to my problem or at least a hint at where the problem lies. I load glyphs into font textures that start at 512×512. I decreased this size to 256×256 and I have stopped seeing the distortion. I’m not sure if this is just postponing the issue but so far so good.
Would that make sense as the problem?