| 116 | } |
| 117 | |
| 118 | void GBuffer::Bind(IDeviceContext* pContext, |
| 119 | Uint32 BuffersMask, |
| 120 | ITextureView* pDSV, |
| 121 | Uint32 ClearMask, |
| 122 | const Uint32* RTIndices) |
| 123 | { |
| 124 | std::array<ITextureView*, MAX_RENDER_TARGETS> RTVs = {}; |
| 125 | std::array<const float*, MAX_RENDER_TARGETS> ClearColors = {}; |
| 126 | const float* ClearDepthVal = nullptr; |
| 127 | const Uint8* ClearStencilVal = nullptr; |
| 128 | |
| 129 | Uint32 NumRTs = 0; |
| 130 | const Uint32* RTIndex = RTIndices; |
| 131 | for (Uint32 i = 0; i < GetBufferCount(); ++i) |
| 132 | { |
| 133 | Uint32 BufferBit = 1u << i; |
| 134 | if ((BuffersMask & BufferBit) == 0) |
| 135 | continue; |
| 136 | |
| 137 | const auto& ElemDesc = GetElementDesc(i); |
| 138 | const auto& BindFlags = ElemDesc.BindFlags; |
| 139 | if (BindFlags & BIND_RENDER_TARGET) |
| 140 | { |
| 141 | const Uint32 RTIdx = RTIndex != nullptr ? *(RTIndex++) : i; |
| 142 | |
| 143 | VERIFY(RTVs[RTIdx] == nullptr, "Render target slot ", RTIdx, " is already used"); |
| 144 | RTVs[RTIdx] = GetBuffer(i)->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET); |
| 145 | NumRTs = std::max(NumRTs, RTIdx + 1); |
| 146 | |
| 147 | if ((ClearMask & BufferBit) != 0) |
| 148 | ClearColors[RTIdx] = ElemDesc.ClearValue.Color; |
| 149 | } |
| 150 | else if (BindFlags & BIND_DEPTH_STENCIL) |
| 151 | { |
| 152 | VERIFY(pDSV == nullptr, "Only one depth-stencil buffer is expected"); |
| 153 | pDSV = GetBuffer(i)->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL); |
| 154 | |
| 155 | if ((ClearMask & BufferBit) != 0) |
| 156 | { |
| 157 | const TextureFormatAttribs& FmtAttribs = GetTextureFormatAttribs(ElemDesc.Format); |
| 158 | |
| 159 | ClearDepthVal = &ElemDesc.ClearValue.DepthStencil.Depth; |
| 160 | if (FmtAttribs.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL) |
| 161 | ClearStencilVal = &ElemDesc.ClearValue.DepthStencil.Stencil; |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | pContext->SetRenderTargets(NumRTs, RTVs.data(), pDSV, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); |
| 167 | |
| 168 | if ((ClearMask & BuffersMask) != 0) |
| 169 | { |
| 170 | for (Uint32 rt = 0; rt < NumRTs; ++rt) |
| 171 | { |
| 172 | if (ClearColors[rt] != nullptr) |
| 173 | pContext->ClearRenderTarget(RTVs[rt], ClearColors[rt], RESOURCE_STATE_TRANSITION_MODE_TRANSITION); |
| 174 | } |
| 175 |
nothing calls this directly
no test coverage detected