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

Started by
1 comment, last by Ripiz 12 years, 10 months ago
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.
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
Crazy dude smoking D3D11, AngelScript, PhysX, 3D Sound, Network, DB, FBX, and some other weird things, doing that on Visual Studio 2010 + Visual Assist X on Overclocked CPU

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

This topic is closed to new replies.

Advertisement