Jump to content
  • Advertisement
Sign in to follow this  
Kuraitou

How to get 2D texture size?

This topic is 2289 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

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!

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!