DirectX11 mip mapping

Started by
30 comments, last by Visje 11 years, 7 months ago
I see. That means B8G8R8A8 is not supported. When you change to R8G8B8A8 everything blue becomes red, and vice versa, which causes your colors to mismatch. This can however be fixed by changing how you load your source data or how you define your colors.
(In particular .BMP files are usually BGR instead of RGB.. I believe TGA too.. not sure).

A very fast "fix" to test it out is to change your shader that you use to draw the mipmapped resource to return some color.bgra to swizzle the color.

To investigate the format problem more closely, read the introduction here http://msdn.microsof...5(v=vs.85).aspx and try the CheckFormatSupport function.
Also, try using the D3D11_CREATE_DEVICE_BGRA_SUPPORT flag (http://msdn.microsof...7(v=vs.85).aspx) when creating your device.
Advertisement
Do you think that the mip mapping will work when the format will be changed ?? Will I be able to change the MipLevels value ?

Thanks a lot for your help :)
I assumed you had already done that and seen it working with R8G8B8A8. If that's not the case, you're kindof back where you started. smile.png But try it out.

The first most important part is to check the HRESULT return code from CreateTexture2D, using if(FAILED(hResult)) error() or similar. If you get an error from that then proceed checking the device format support and options.

If you do not get an error from CreateTexture2D (when MipLevels is 0), then your problem lies elsewhere and you can probably ignore my previous posts.
I actually already have the "D3D11_CREATE_DEVICE_BGRA_SUPPORT" flag.
I changed the format to R8G8B8A8 and did the quick fix in the Pixel Shader, the game works fine but I still get an error when I set MipLevels to 0, I'll try with the HRESULT.

Just for info, I'm working on a Metro app.
I did this :

HRESULT hr = m_d3dDevice->CreateTexture2D(
&textureDesc,
&initialData,
&texture2D
);

but I get an error inside "CreateTexture2D", thus I cannot check the error code of HRESULT :/
How do you initialize initialData?
D3D is probably expecting you to provide all mip levels, thereby reading past the end of your data.
Skip using initialData and instead upload the first mip-level using UpdateSubResource.
That's how I initialize initialData :

D3D11_SUBRESOURCE_DATA initialData;
ZeroMemory(&initialData, sizeof(initialData));
initialData.pSysMem = bitmapPixels.get();
initialData.SysMemPitch = width * 4;
initialData.SysMemSlicePitch = 0;



"Skip using initialData and instead upload the first mip-level using UpdateSubResource." humm... how can I do that ? :s
Pass NULL to CreateTexture2D and then call ID3D11DeviceContext::UpdateSubresource: http://msdn.microsoft.com/en-us/library/windows/desktop/ff476486(v=vs.85).aspx
Follow the links there and each input is described. Just set the box to (0, width, 0, height, 0, 1) and rowPitch to your sysMemPitch and pass it your data. The subresource should be 0 for the top mip level.
If your texture is static, you want to create it with D3D11_USAGE_IMMUTABLE and not D3D11_USAGE_DEFAULT.

Also when you create a texture with mipmaps and you want to pass it initialization data, you need to pass an array of D3D11_SUBRESOURCE_DATA. The array needs 1 element per subresource, where a subresource is either a mip level or an array slice. So if you have 10 mip levels, you'd need to pass an array of 10 with each one having a pointer to the data for that mip level.
Hi Erik, I passed NULL to CreateTexture2D and all became black as expected, then at each frame I call this codeto render my textures :

m_d3dDeviceContext->UpdateSubresource(
m_constantBuffer.Get(),
0,
nullptr,
&(m_constantBufferData),
0,
0
);

I don't know if I should put this function just after the createTexture, or if I must change the parameters of it... nvertheless it still is'nt working :/


MJP : I did what you told me but I still got the problem ><, I'm kind of a noob on this one :(
Here's the code if interested :

D3D11_SUBRESOURCE_DATA* initData(new D3D11_SUBRESOURCE_DATA[3 * 3]);
initData[0].pSysMem = bitmapPixels.get();
initData[0].SysMemPitch = width * 4;
initData[0].SysMemSlicePitch = 0;
initData[1].pSysMem = bitmapPixels.get();
initData[1].SysMemPitch = width * 4;
initData[1].SysMemSlicePitch = 0;
initData[2].pSysMem = bitmapPixels.get();
initData[2].SysMemPitch = width * 4;
initData[2].SysMemSlicePitch = 0;


D3D11_TEXTURE2D_DESC textureDesc;
ZeroMemory( &textureDesc, sizeof(textureDesc) );
textureDesc.Width = width;
textureDesc.Height = height;
textureDesc.MipLevels = 0; // PROBLEM WITH THIS
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
textureDesc.SampleDesc.Count = 1;
textureDesc.Usage = D3D11_USAGE_IMMUTABLE; // PROBLEM HERE ALSO
textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;

HRESULT hr = m_d3dDevice->CreateTexture2D(
&textureDesc,
initData,
&texture2D
);


Thanks again for your help guys

This topic is closed to new replies.

Advertisement