Exact available Video Ram? Texture size?
Greetings!
I was wondering how could i achieve something like this:
temp = save_video_mem_state
loadtexture with mipmaps
ram_required = temp - video_mem_state
I saw something like GEtAvailableTexture mem but it is too unprecize.
Any ideas how I could determine texture size with mipmaps?
Quote:I saw something like GetAvailableTexture mem but it is too unprecize.
I know what you mean by "unprecise" but in truth, it is a correct value. Texture memory can also include AGP memory, whilst you might not *want* to use it, it is there to be used if necessary.
Quote:Any ideas how I could determine texture size with mipmaps?
It's not actually that complicated. Work out how many bits-per-pixel you're using (e.g. D3DFMT_A8R8G8B8 = 32bit/pixel) multiplied by the height/width of the texture, and recursively do this for each mip-map level you generate.
Technically you'd want to examine the pitch of the texture - but iirc for 2^n texture sizes this doesn't factor in. Also, the header required to describe the texture is negligeable.
As an example... a 128x64 texture in a 32bit mode:
128x64x4 = 32768
64x32x4 = 8192
32x16x4 = 2048
16x8x4 = 512
8x4x4 = 128
4x2x4 = 32
2x1x4 = 8
TOTAL = 43688 (~43kb)
Obviously, the above example is a full chain (setting '0' as the parameter in calls to D3DXCreateTextureFromFileEx..), you'd want to limit the above calculation...
//this code is untested/off the top of my head//it should calculate memory usage for a complete mip-map chain,//it shouldn't be too hard to modify it to calculate 'n' mip-map levels..DWORD CalcTexMemUsage(int iWidth, int iHeight, int iBitsPerPixel) { DWORD dwThisLevel = (iWidth * iHeight * (iBitsPerPixel / 8)); if( ( iWidth == 1 ) || ( iHeight == 1 ) ) return dwThisLevel; else return dwThisLevel + CalcTexMemUsage(iWidth / 2, iHeight / 2, iBitsPerPixel);}
hth
Jack
Thank you for the reply.
I'm aware how to compute pixels and bitdepth, I didn't post my request correct.
I was wondering if DirectX supports any method/functions with LPD3DXTEXTURE9 whith computes souch things automaticaly? How can i figure out how many lods are supported in my texture? How can I read out the bitdepth? If I try to access widtht & height it throws me an error!
Thank you for any suggestion.
I'm aware how to compute pixels and bitdepth, I didn't post my request correct.
I was wondering if DirectX supports any method/functions with LPD3DXTEXTURE9 whith computes souch things automaticaly? How can i figure out how many lods are supported in my texture? How can I read out the bitdepth? If I try to access widtht & height it throws me an error!
Thank you for any suggestion.
You can get the surface description for a given mip-map level quite easily:
I don't know of this LPD3DXTEXTURE9 you mention, so I'll assume you just meant IDirect3DTexture9 / LPDIRECT3DTEXTURE9
IDirect3DTexture9::GetLevelCount() will tell you how many levels have been generated.
You can then use this as the basis for a loop to cycle through each level:
IDirect3DTexture9::GetLevelDesc() takes in the loop index and a pointer to a D3DSURFACE_DESC. You can then use the Width, Height and Format fields of this struct to get the information you want.
I'm not aware of a built in function that'll decode a D3DFORMAT from it's constant down to the number of bits/bytes of space it occupies; but it's fairly easy to write one as a switch-case function to cover the formats you're expecting to encounter...
Put all the stuff in my two posts together and you could easily write a little function that takes in a loaded texture and computes how much memory it takes up and any other related mip-map information you want.
Jack
I don't know of this LPD3DXTEXTURE9 you mention, so I'll assume you just meant IDirect3DTexture9 / LPDIRECT3DTEXTURE9
IDirect3DTexture9::GetLevelCount() will tell you how many levels have been generated.
You can then use this as the basis for a loop to cycle through each level:
IDirect3DTexture9::GetLevelDesc() takes in the loop index and a pointer to a D3DSURFACE_DESC. You can then use the Width, Height and Format fields of this struct to get the information you want.
I'm not aware of a built in function that'll decode a D3DFORMAT from it's constant down to the number of bits/bytes of space it occupies; but it's fairly easy to write one as a switch-case function to cover the formats you're expecting to encounter...
Put all the stuff in my two posts together and you could easily write a little function that takes in a loaded texture and computes how much memory it takes up and any other related mip-map information you want.
Jack
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement