GL question- redefining texture?

Sage
Posts: 1,232
Joined: 2002.10
Post: #1
Basic question-

If I create a texture with glTexImage2D(), and then later want to update that texture content, is it safe to call glTexImage2D with the same texture ID (target) again? I know that using glTexSubImage2D to redefine the texture will be slightly faster, but in this case I'm concerned about memory usage not speed. Do I need to call glDeleteTexture() before resuing an ID? I'm not clear on how GL's copy of the the texture memory is freed.

thanks,
-alex
Quote this message in a reply
Member
Posts: 177
Joined: 2002.08
Post: #2
I'm pretty sure you can safely call glTexImage2D again. glGenTextures just reserves a "slot" in the texture list, all the resource management is handled internally by the GL driver.

AFAIK you should only use TexImage2D over TexSubImage2D if you want to change part of the texture that only the former gives you control over (like the dimensions).
Quote this message in a reply
henryj
Unregistered
 
Post: #3
Use texsubimage2d.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #4
Very belated followup:

I've now found that using glTexImage2D with the same ID and new image data (with possibly different dimensions than the old image) is NOT SAFE. You will leak memory in RSHRD/VSIZE. This happens even with the texture range extension and client storage, to eliminate any extra copies the GL is keeping around.

So: if you're not using images of the same dimension and can't use glTexSubImage2D, then you must call glDeleteTextures to ensure the GL really releases/unmaps your image data.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
arekkusu Wrote:I've now found that using glTexImage2D with the same ID and new image data (with possibly different dimensions than the old image) is NOT SAFE. You will leak memory in RSHRD/VSIZE. This happens even with the texture range extension and client storage, to eliminate any extra copies the GL is keeping around.

If this is true then it's a bug.

Mind you, who'd really be surprised...
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Texture Basic Question(s)... WhatMeWorry 2 3,269 Feb 27, 2007 10:06 AM
Last Post: arekkusu
  General Texture Question.... WhatMeWorry 5 4,080 Aug 5, 2005 09:38 PM
Last Post: WhatMeWorry