Jump to content
  • Advertisement
Sign in to follow this  
codehunter13

size of textures in memory

This topic is 4819 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
That depends on the format and size of the texture. For example, if you have a texture that is 256x256 and the format is a 32bit(4bytes) ARGB texture, then the size is: 4bytes/pixel * 256 * 256 = 262144 bytes = 256KB.

In general, to find the size of a texture, multiply the number of bytes per pixel by the dimensions of the texture and you'll get the total number of bytes in the texture.

neneboricua

Share this post


Link to post
Share on other sites
Don't forget all your mipmap levels as well, if you have any.


DWORD PixelSize(D3DFORMAT Format)
{
switch (Format)
{
//... Additional Formats
case D3DFMT_R8G8B8:
return 3;
case D3DFMT_X8R8G8B8:
return 4;
case D3DFMT_A8R8G8B8:
return 4;
//... Additional Formats
default:
return 0;
}
}

DWORD TextureSize(IDirect3DTexture9* pTexture)
{
DWORD Size = 0;
if (pTexture != NULL)
{
D3DSURFACE_DESC SurfaceDesc;
DWORD i;
DWORD c = pTexture->GetLevelCount();
for (i = 0; i < c; ++i)
{
if (pTexture->GetLevelDesc(i, &SurfaceDesc) == D3D_OK)
{
Size += SurfaceDesc.Width * SurfaceDesc.Height * PixelSize(SurfaceDesc.Format);
}
}
}
return Size;
}




Share this post


Link to post
Share on other sites
And if you're using it to estimate how many textures can fit in memory or anything along those lines, remember that these numbers are estimates. In video memory things like alignment issues, padding, etc can make the texture use up additional space. The card can store it anyway it likes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!