How to determine size of textures (in bytes)

Started by
2 comments, last by Brisco 18 years, 10 months ago
Hello! I have a question about textures in DirectX... I need to know the size of a texture - or better, the size of every mip level considering the used format. This is no problem for uncompressed textures, I simply determine the dimensions of a mip level and multiply them with the bytes that are required per pixel for the specified format... but what about compressed textures? I think there should be a way to determine the required memory?
Advertisement
If you know the initial size I believe the sizes work in the following manner
Eg.

256 x 256
128 x 128
64 x 64

That's how it will work, you will also want to specify the number of mipmap levels to create...

Eg.
From the SDK Docs.
"The following example shows how your application can call the IDirect3DDevice9::CreateTexture method to build a chain of five mipmap levels: 256x256, 128x128, 64x64, 32x32, and 16x16.

// This code example assumes that m_d3dDevice is a
// valid pointer to a IDirect3DDevice9 interface

IDirect3DTexture9 * pMipMap;
m_pD3DDevice->CreateTexture(256, 256, 5, 0, D3DFMT_R8G8B8,
D3DPOOL_MANAGED, &pMipMap);

"

Hope this helps a bit.
If you want to know the size of a non mip-levelled texture just open it first as a file with fstream.

ace
That's right, but it doesn't help me to get the exact size in bytes of a compressed texture. In fact, I know the size of any mip level - and as long as the texture is not compressed, I also know the size in bytes because it can be easily calculated by width*height*bytesperpixel.

My goal is, to lock a texture and write the complete data into a file in my own format, this is part of an object persistence framework I have written, but to do this, I need to know the exact size in bytes.

This topic is closed to new replies.

Advertisement