Hello, I would like to generate mipmaps for a RGBA8 texture, however it only works for one face. Here my source:
D3D11_TEXTURE2D_DESC desc = { 0 };
desc.Width = this->x;
desc.Height = this->y;
if(cil_props & CIL_CUBE_MAP)
desc.ArraySize = 6;
else
desc.ArraySize = 1;
if (this->props&TEXT_BASIC_FORMAT::CH_ALPHA)
desc.Format = DXGI_FORMAT_R8_UNORM;
else
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
desc.MiscFlags = 0;
if (cil_props & CIL_CUBE_MAP) {
desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
}
desc.MipLevels = 0;
desc.MiscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS;
HRESULT hr;
hr = D3D11Device->CreateTexture2D(&desc, nullptr, Tex.GetAddressOf());
if (hr != S_OK) {
this->id = -1;
return;
}
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc{};
srvDesc.Format = desc.Format;
if (cil_props & CIL_CUBE_MAP) {
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
srvDesc.Texture2D.MipLevels = -1;
srvDesc.TextureCube.MipLevels = -1;
}
else {
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = -1;
}
D3D11Device->CreateShaderResourceView(Tex.Get(), &srvDesc, pSRVTex.GetAddressOf());
D3D11_SUBRESOURCE_DATA initData[6];
int bufferSize = this->size/6;
if (cil_props & CIL_CUBE_MAP) {
unsigned char *pHead = buffer;
for (int i = 0; i < 6; i++) {
initData[i].pSysMem = pHead;
initData[i].SysMemPitch = sizeof(unsigned char) * this->x * 4;
pHead += bufferSize;
}
}else {
initData[0].pSysMem = buffer;
initData[0].SysMemPitch = sizeof(unsigned char) * this->x * 4;
}
if (cil_props & CIL_CUBE_MAP) {
for (int i = 0; i < 6; i++) {
D3D11DeviceContext->UpdateSubresource(Tex.Get(), i, 0, initData[i].pSysMem, initData[i].SysMemPitch, size); //size is the size of the entire buffer
}
}else {
D3D11DeviceContext->UpdateSubresource(Tex.Get(), 0, 0, buffer, initData[0].SysMemPitch, 0);
}
D3D11DeviceContext->GenerateMips(pSRVTex.Get());
This code assume RGBA (32 bpp) and no mipmaps in the buffer. This is how it looks without mipmaps:
This is how it looks with the code above, only one face is updated but curiously, that face alone does have mipmaps:
Can anyone help me, I can add mipmaps offline but this should work, I would like to handle were the buffer is a cubemap and doesn't have any mipmaps. I tried on Intel and Nvidia, so I guess is not a driver issue, but something I am doing wrong.
Thanks!
↧