Jump to content
  • Advertisement
Sign in to follow this  
Ripiz

DX11 [C++, DX11] How to get texture size?

This topic is 2599 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 load my texture using this code: D3DX11CreateTextureFromFileA(device, sFilename, 0, 0, &textureResource, 0);

D3D11_SHADER_RESOURCE_VIEW_DESC resourceDesc;
resourceDesc.Format = DXGI_FORMAT_UNKNOWN;
resourceDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
resourceDesc.Texture2D.MostDetailedMip = 0;
resourceDesc.Texture2D.MipLevels = -1;
device->CreateShaderResourceView(textureResource, &resourceDesc, &shaderTextureResource);


But I can't seem figure how to get texture size/resolution which I need for interface rendering. Can anyone help please? Thank you in advance.

Share this post


Link to post
Share on other sites
Advertisement

Hello. I load my texture using this code: D3DX11CreateTextureFromFileA(device, sFilename, 0, 0, &textureResource, 0);

D3D11_SHADER_RESOURCE_VIEW_DESC resourceDesc;
resourceDesc.Format = DXGI_FORMAT_UNKNOWN;
resourceDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
resourceDesc.Texture2D.MostDetailedMip = 0;
resourceDesc.Texture2D.MipLevels = -1;
device->CreateShaderResourceView(textureResource, &resourceDesc, &shaderTextureResource);


But I can't seem figure how to get texture size/resolution which I need for interface rendering. Can anyone help please? Thank you in advance.


  • you have to query ID3D11Texture2D interface from shaderTextureResource,then you have to get description from it with GetDesc
  • if you don't want or don't know how to query, then u may just call GetDesc from textureResource, it will give you D3D11_TEXTURE2D_DESC structure with all the fields(w,h format e.t.c.) that you need
  • you can also call D3DX11GetImageInfoFromFile to retrieve information about the file

Share this post


Link to post
Share on other sites

you have to query ID3D11Texture2D interface from shaderTextureResource,then you have to get description from it with GetDesc

Doesn't work, pointer remains NULL.


if you don't want or don't know how to query, then u may just call GetDesc from textureResource, it will give you D3D11_TEXTURE2D_DESC structure with all the fields(w,h format e.t.c.) that you need

textureResource doesn't have GetDesc method, however shaderTextureResource does have it, but it doesn't return information I need


you can also call D3DX11GetImageInfoFromFile to retrieve information about the file

I though that'll be somewhat slow to open file extra time, so I didn't do it.

However, based on your suggestions I managed to Query interface from textureResource and it worked correctly, thank you.



ID3D11Texture2D *pTextureInterface = 0;
textureResource->QueryInterface<ID3D11Texture2D>(&pTextureInterface);
D3D11_TEXTURE2D_DESC desc;
pTextureInterface->GetDesc(&desc);

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!