texture memory

Hello all, first time here,

I was trying save GPU memory when loading texture mipmaps to higher levels (low resolution) first. To my amazement the GPU memory (using GPU-Z) had increased to the full texture size as if loading all mipmaps including the high resolution ones.
i am using s3tc/dxtc compressed textures.

is this behaviour expected, or is there a trick to allocate only the memory for the actual loaded levels ?

i was counting on that to also delete high res levels (when no longer used), specifying null as the level pointer, is there another way to acheive this without deleting the whole texture ?

thanks

Specifying a NULL pointer doesn’t reduce memory usage: http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml

In GL version 1.1 or greater, data may be a null pointer. In this case, texture memory is allocated to accommodate a texture of width width and height height.

The thing about textures is that mipmap levels don’t exist in isolation. With the exception a texture that only contains level 0, you must specify all mipmap levels or the resulting texture object is incomplete.

Roundabout now I’m wondering if you’ve profiled your application and determined that excessive texture memory usage is a problem.

Hi,

thanks, i thought that much.
as i recall for the texture to be complete all mipmaps from base lod (can be > 0) until max lod should exist(loaded). that is why i thought that not loading the 0 lod will not allocate it.

anyways i am using over 1GB of textures, all of them very big (2kX2k rgba). i need some mechanism to load only the levels i need without allocating the whole texture , and a way to release unused high-res levels without the need to generate and reload a new texture. anybody can help here, please. reference to code would be much appreciated.

thanks in advance,
frantic

Don’t call glTexImage* for a mipmap until you have texture data to upload. It’s really that simple.

There’s no rule in OpenGL that says you must call glTexImage* for the highest mipmap layer. Just set your GL_TEXTURE_BASE_LOD and GL_TEXTURE_MAX_LOD values to exclude mipmap levels that you haven’t loaded yet.

that is exactly what i am doing, but the problem is the memory for lod 0 is allocated anyways. i am trying to avoid that as i have many many large textures.

Oh. Well, I guess there’s nothing you can do about it. There’s no way to tell it not to allocate more memory than you specifically asked for.

So, create “smaller” versions of the textures (with their own GLuint names/handles), where lod0 is i.e lod3 of the file-original. On demand, create the bigger version, and copy via cpu or PBO/FBO texels from the smaller version; load from file lods 0…2

yep,
I guess no other solution.

is there a way to copy directly between textures ?

thanks, frantic

If you are targeting NV hardware, then: NV_copy_image (GL/WGL/GLX).
I’m note sure whether AMD supports it.

thanks, looks promising