Archived

This topic is now archived and is closed to further replies.

ZeroBit

Texture Memory Management

Recommended Posts

ZeroBit    122
Hi.. I got couple of questions Does OpenGL do Texture Memory Management ? What happens if user calls glTexImage2D() while there is not enough video memory for the action ? Also, where does OpenGL allocate memory for glTexImage2D()? how to tell if the texture stored in System RAM or Video RAM ? How to check available Video Memory in OpenGL ? Thanks..

Share this post


Link to post
Share on other sites
blizzard999    268
quote:

What happens if user calls glTexImage2D() while there is not enough video memory for the action ?



TexImage() re-load the texture from system to video memory in the current ''bind texture'' (by deafult 0). It never fails because you have to copy the texture form system to video memory every time you call it...however OpenGL guarentees that TexImage() works always (also on unaccelerated systems).

quote:

Also, where does OpenGL allocate memory for glTexImage2D()? how to tell if the texture stored in System RAM or Video RAM ?



To store textures in video memory you must call
(see spec for detail...please

GenTexture(); // obtain a texture object id
BindTexture(); // use the texture id you got

TexImage2D();
...
//to reload the texture simply
BindTexture(); // without TexImage2D()!!!
...
//to clear
DeleteTexture();

Note that if you continue to use the same texture you do not need to call BindTexture() or TexImage2D()

To know where the texture is, the only command (if it works is
AreTextureResidents();

quote:

How to check available Video Memory in OpenGL ?



Pray for new extensions...



Share this post


Link to post
Share on other sites
ZeroBit    122
quote:
TexImage() re-load the texture from system to video memory in the current ''bind texture'' (by deafult 0). It never fails because you have to copy the texture form system to video memory every time you call it...however OpenGL guarentees that TexImage() works always (also on unaccelerated systems).



Never fail ? are you sure ?
Suppose we have an accelerated system, with only 8 MB of tex memory. Then what if those 8 MB is full already ? I think textures need to resides in Video Memory if we are using hardware acceleration. Will openGL use software rasterizer only for this texture ? Thats most unlikely isnt it

quote:

To store textures in video memory you must call
(see spec for detail...please

GenTexture(); // obtain a texture object id
BindTexture(); // use the texture id you got

TexImage2D();
...
//to reload the texture simply
BindTexture(); // without TexImage2D()!!!
...
//to clear
DeleteTexture();



Ok thats how we load texture into MEMORY, what im asking is how to tell if OpenGL loads them into SYSTEM MEMORY or VIDEO MEMORY.
Coz in Direct3D, user may request to create a texture surface in SYSTEM MEMORY, or VIDEO MEMORY. Although textures which resides in SYSTEM MEMORY, cant be used for hardware-accelerated rendering.

quote:

To know where the texture is, the only command (if it works is
AreTextureResidents();


Hmm i cant find AreTextureResidents() function in any of my openGL headers ?? Is it an OpenGL API call ? or Win32 ?

Thanks..


Share this post


Link to post
Share on other sites
rotos    122
quote:
Original post by ZeroBit
Never fail ? are you sure ?
Suppose we have an accelerated system, with only 8 MB of tex memory. Then what if those 8 MB is full already ? I think textures need to resides in Video Memory if we are using hardware acceleration. Will openGL use software rasterizer only for this texture ? Thats most unlikely isnt it



In the case that all the texture memory is used, OpenGL will free other textures from video memory to make room for the new one. It''ll put the freed textures back in video memory when they are bound again.

Share this post


Link to post
Share on other sites
blizzard999    268
quote:
ZeroBit
Hmm i cant find AreTextureResidents() function in any of my openGL headers ?? Is it an OpenGL API call ? or Win32 ?



GLboolean glAreTexturesResident
(
GLsizei n,
GLuint * textures
GLboolean * residences
);

available in OpenGL version 1.1 or later. The header is gl.h (it is an API function), if you have glBindTextures() you have glAreTexRes...(perhaps a syntax error of mine

The function does not work well on older systems...however to test for a single texture you may use your own function


    
BOOL glIsTextureResident(GLuint texobjID)
{
BOOL b;
return(1, &texobjID, &b);
}


quote:
ZeroBit

Never fail ? are you sure ?
Suppose we have an accelerated system, with only 8 MB of tex memory. Then what if those 8 MB is full already ? I think textures need to resides in Video Memory if we are using hardware acceleration.



I dont know what happens internally in this case (there is obviously no documentation) however a compliant OpenGL implementation must always works with TexImage.
This doesnt mean that you can bind on video memory every texture you want (but I think that if the textureId is valid, the glBind works always too).

quote:
ZeroBit

Will openGL use software rasterizer only for this texture ? Thats most unlikely isnt it



I think that a compliant implementation must mantain VRAM for at least one texture (of max size) for glBind(0).

quote:
ZeroBit

Ok thats how we load texture into MEMORY, what im asking is how to tell if OpenGL loads them into SYSTEM MEMORY or VIDEO MEMORY.
Coz in Direct3D, user may request to create a texture surface in SYSTEM MEMORY, or VIDEO MEMORY.



Yes I know DirectDraw...no there is not an explicit method to allocate texture on video memory: you have only glBind().
In most cases if you have enough VRAM glBind loads on video memory the texture you specify via TexImage2D()...
However OpenGL dosnt impose you the use of Surfaces or strange classes...so at least you need only a buffer in system mem with your texture.
If glBind works you can copy this buffer to the video memory to better performance...


quote:
ZeroBit

Although textures which reside in SYSTEM MEMORY, cant be used for hardware-accelerated rendering.



If your system supports HW you always use HW in OpenGL,...the difference is that if the texture doesnt reside on VRAM you have to copy it from system memory (via AGP) and you loose a bit in term of speed.














[edited by - blizzard999 on April 30, 2003 1:13:01 PM]

Share this post


Link to post
Share on other sites