<div>Hi guys,</div>
<div> </div>
<div>I have a question about the internal implementation of glDrawArrays or any rendering functions.</div>
<div>In the code path, it calls to _mesa_update_texture(), and if there is really a complete texture, </div>
<div>it will call _mesa_reference_texobj to set it to _Current, and increase the texture object's reference </div>
<div>counter.</div>
<div> </div>
<div>My question is when it will decrease the reference counter? This implicit increasing seems </div>
<div>causes the reference counter unbalanced, and then will cause unexpected behaviour. Here is an </div>
<div>example:</div>
<div> </div>
<div>1 glGenTextures(1, &tex);<br>2 glActiveTexture(GL_TEXTURE0);<br>3 glBindTexture(GL_TEXTURE_2D, tex);</div>
<div>4 glTexImage2D(GL_TEXTURE_2D, 0, iformat,<br> w, h, 0, format, type, bits);</div>
<div>5 glEnable(GL_TEXTURE_2D);<br>6 glUseProgram(shader_prog);</div>
<div>7 ... /*setup attribute array here.*/</div>
<div>8 glDrawArray(GL_TRIANGLE_FAN, 0, 4);</div>
<div>9 glUseProgram(0);</div>
<div>10 glDeleteTexture(1, &tex);</div>
<div> </div>
<div>At Line 1, tex object is created with reference count initialized to 1.</div>
<div>At Line 3, tex object's reference count increased to 2.</div>
<div>At Line 8, it implicit increases tex object's reference count to 3.</div>
<div>At Line 10, it implict unbinds the tex object which decreases the count to 2.</div>
<div> then it try to unreference the tex object which decreases the count to1.</div>
<div> </div>
<div>You can see that finally, the tex object's reference's count is 1 not zero </div>
<div>and thus it will not be freed. This is not what I expected.</div>
<div> </div>
<div>Is there any mistakes in my use case? Or anyone can tell me how to </div>
<div>make sure the texture object get freed after the usage of it. </div>
<div> </div>
<div>Thanks.</div>
<div> </div>
<div><br> </div>