Jump to content

  • Log In with Google      Sign In   
  • Create Account

How to get 2D texture size?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Kuraitou   Members   -  Reputation: 250

Like
0Likes
Like

Posted 15 April 2012 - 02:56 PM

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!

Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 7939

Like
1Likes
Like

Posted 15 April 2012 - 04:44 PM

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).

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 Kuraitou   Members   -  Reputation: 250

Like
0Likes
Like

Posted 15 April 2012 - 05:21 PM

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.

#4 Nik02   Crossbones+   -  Reputation: 2818

Like
0Likes
Like

Posted 16 April 2012 - 04:14 AM

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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS