How to get 2D texture size?

Started by
2 comments, last by Nik02 12 years ago
Hello. I'm porting some D3D9 code to D3D10 (in this instance, the code in question is a textured quad renderer) and I can't seem to figure out how to get the size of a texture. The best thing I've found is the HLSL function Texture2D.GetDimensions(), which would allow me to do this on the GPU. It seems like that would be slow - correct me if I'm wrong. Is there perhaps a way to get a D3D10_TEXTURE2D_DESC from a loaded texture that I don't know about? Currently, I'm using D3DX10CreateShaderResourceViewFromFile and passing the view to my shader. I looked at D3DX10CreateTextureFromFile but it doesn't appear to give me a way to obtain texture information either.

In my old code, I would cache the texture size and calculate the texcoords of each vertex on the CPU before sending them off to be rendered. I would like to do the same thing here if possible.

Many thanks!
Advertisement
ID3D10Texture2D::GetDesc is what you need here (using ID3D10View::GetResource if you only have access to the SRV, and remembering to Release the resource afterwards).

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.


ID3D10Texture2D::GetDesc is what you need here (using ID3D10View::GetResource if you only have access to the SRV, and remembering to Release the resource afterwards).

That's definitely what I want, thanks! Is there a way to be absolutely sure that the ID3D10View resource is indeed a ID3D10Texture2D?

EDIT: Nevermind, I think I got it. I need to make sure that ID3D10Resource::GetType() returns D3D10_RESOURCE_DIMENSION_TEXTURE2D. Thanks again.
Querying for texture dimensions in shader isn't particularly slow. From what I know about common implementations, the cost is about the same as in ordinary constant buffer reads.

Of course, you will want to optimize to reduce total computation effort and memory access.

Niko Suni

This topic is closed to new replies.

Advertisement