Topic locked

Memory leak when draw Texture in renderFrame()

December 25, 2014 - 4:52am #4

I use tracking to target, so I draw dynamic image by openGl in renderFrame(), but that cuased huge memory leak.

I tried to create an if condition which occurs once and draw once, but clear buffers, colors ... etc (as I think) clear the draw.

So, Is there any way to draw once and keep this drawing till camera leave target then initiate all buffers, colors ... ?

Memory leak when draw Texture in renderFrame()

December 26, 2014 - 12:31am #3

In OpenGL, you need to render your content at every frame; this does not mean however that you need to clear or rebuild your rendering data every frame; for example, if you have a 3d mesh (a vertex array) whose shape is not changing over time, you can create the vertex array just once e.g. at initialization time) and then pass it to OpenGL pipeline at every frame;   this also applies to textures and other OpenGL related assets;

this is also illustrated in the Vuforia samples; for instance, the Image Targets sample (in VuforiaSamples project), render a static "teapot" mesh with a static texture applied on it; the "teapot" vertex arrays is statically defined (it's not updated every frame);   at every frame, the vertex array pointer is passed to the OpenGL rendering pipeline via glVertexAttribArrayPointer();   this does not cause any memory leak, since the data structures are not cleared / recreated (they are always the same).

 

Now, if you have some texture which is updated dynamically (as you mention), you probably need to take care that the image buffers are deleted or released after copying the content of the image to an OpenGL texture;   

also, the OpenGL texture should not be "re-created" at each frame, but rather you should probably use some methods like glTexSubImage to copy the content of your image to the OpenGL texture memory, without creatng a new Texture each time.

Please, also note that this question is more a general OpenGL and iOS programming question, rather than an actual Vuforia topic.

 

 

Memory leak when draw Texture in renderFrame()

December 28, 2014 - 5:14am #2

Thank you AlessandroB, this explaination helped me to understand the openGl process.

I was actually re-create my dynamic image texture in renderFrame() (every frame), and when I changed that, memory became more good.

Thank you,

Memory leak when draw Texture in renderFrame()

December 31, 2014 - 6:02am #1

Great ;-)

Topic locked