DWORD* loaded_data; // loaded using FreeImage
uint width = FreeImage_GetWidth(image32);
uint height = FreeImage_GetHeight(image32);
uint mips = GetNumMipLevels(width, height);
Desc.Width = width;
Desc.Height = height;
Desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
Desc.MipLevels = mips; // auto-generates the whole chain
Desc.MiscFlags = 0;
Desc.ArraySize = 1;
Desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
Desc.CPUAccessFlags = 0;
Desc.SampleDesc.Count = 1;
Desc.SampleDesc.Quality = 0;
Desc.Usage = D3D11_USAGE_IMMUTABLE;
D3D11_SUBRESOURCE_DATA* initialData = new D3D11_SUBRESOURCE_DATA[mips];
for (uint i = 0; i < mips; i++)
{
uint mip = (uint)powf(2.f, (float)i);
initialData[i].pSysMem = loaded_data;
initialData[i].SysMemPitch = width * 4;
initialData[i].SysMemSlicePitch = width * height * 4;
}
pDevice->pDevice->CreateTexture2D(&Desc, initialData, &pTexture);
delete[] initialData;
D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc;
ZeroMemory(&viewDesc, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC));
viewDesc.Format = Desc.Format;
viewDesc.Texture2D.MipLevels = -1;
viewDesc.Texture2D.MostDetailedMip = 0;
viewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
pDevice->pDevice->CreateShaderResourceView(pTexture, &viewDesc, &pView);
return S_OK;
However I don't think this is generating the mip maps correctly, or they aren't being used. Look at the left of the cube in this screenshot

Uploaded with ImageShack.us
I dont think the sampler is at fault, but just in case, it is set up like this
D3D11_SAMPLER_DESC desc; desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; desc.AddressV = desc.AddressU; desc.AddressW = desc.AddressU; desc.BorderColor[0] = desc.BorderColor[1] = desc.BorderColor[2] = desc.BorderColor[3] = 1.0f; desc.ComparisonFunc = D3D11_COMPARISON_NEVER; desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; desc.MaxAnisotropy = 0; desc.MaxLOD = 0; desc.MinLOD = 0; desc.MipLODBias = 0.0f;
So can anyone see what I'm doing wrong?






