| 34 | } |
| 35 | |
| 36 | void RenderTarget2D::Initialize(ID3D11Device* device, |
| 37 | uint32 width, |
| 38 | uint32 height, |
| 39 | DXGI_FORMAT format, |
| 40 | uint32 numMipLevels, |
| 41 | uint32 multiSamples, |
| 42 | uint32 msQuality, |
| 43 | bool32 autoGenMipMaps, |
| 44 | bool32 createUAV, |
| 45 | uint32 arraySize, |
| 46 | bool32 cubeMap) |
| 47 | { |
| 48 | D3D11_TEXTURE2D_DESC desc; |
| 49 | desc.Width = width; |
| 50 | desc.Height = height; |
| 51 | desc.ArraySize = arraySize; |
| 52 | desc.BindFlags = D3D11_BIND_SHADER_RESOURCE|D3D11_BIND_RENDER_TARGET; |
| 53 | if(createUAV) |
| 54 | desc.BindFlags |= D3D11_BIND_UNORDERED_ACCESS; |
| 55 | |
| 56 | desc.CPUAccessFlags = 0; |
| 57 | desc.Format = format; |
| 58 | desc.MipLevels = numMipLevels; |
| 59 | desc.MiscFlags = (autoGenMipMaps && numMipLevels != 1) ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0; |
| 60 | desc.SampleDesc.Count = multiSamples; |
| 61 | desc.SampleDesc.Quality = msQuality; |
| 62 | desc.Usage = D3D11_USAGE_DEFAULT; |
| 63 | |
| 64 | if(cubeMap) |
| 65 | { |
| 66 | _ASSERT(arraySize == 6); |
| 67 | desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE; |
| 68 | } |
| 69 | |
| 70 | DXCall(device->CreateTexture2D(&desc, nullptr, &Texture)); |
| 71 | |
| 72 | RTVArraySlices.clear(); |
| 73 | for(uint32 i = 0; i < arraySize; ++i) |
| 74 | { |
| 75 | ID3D11RenderTargetViewPtr rtView; |
| 76 | D3D11_RENDER_TARGET_VIEW_DESC rtDesc; |
| 77 | rtDesc.Format = format; |
| 78 | |
| 79 | if(arraySize == 1) |
| 80 | { |
| 81 | if(multiSamples > 1) |
| 82 | { |
| 83 | rtDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS; |
| 84 | } |
| 85 | else |
| 86 | { |
| 87 | rtDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; |
| 88 | rtDesc.Texture2D.MipSlice = 0; |
| 89 | } |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | if(multiSamples > 1) |