| 187 | } |
| 188 | |
| 189 | void FastRenderer::EndFrame(ID3D11DeviceContext& context) |
| 190 | { |
| 191 | if (activeBatch) |
| 192 | { |
| 193 | pmlog_warn("Batch still open"); |
| 194 | activeBatch = std::nullopt; |
| 195 | } |
| 196 | if (!vertexMapping || !indexMapping) |
| 197 | { |
| 198 | pmlog_error("Vertex or index mapping not open"); |
| 199 | throw Except<GraphicsException>(); |
| 200 | } |
| 201 | if (chainSize) |
| 202 | { |
| 203 | pmlog_warn("chain not closed"); |
| 204 | chainSize = {}; |
| 205 | } |
| 206 | if (activeBatch) |
| 207 | { |
| 208 | pmlog_warn("batch was still active"); |
| 209 | activeBatch = std::nullopt; |
| 210 | } |
| 211 | |
| 212 | context.Unmap(pVertexBuffer.Get(), 0); |
| 213 | context.Unmap(pIndexBuffer.Get(), 0); |
| 214 | vertexMapping = std::nullopt; |
| 215 | indexMapping = std::nullopt; |
| 216 | |
| 217 | if (batches.empty()) |
| 218 | { |
| 219 | return; |
| 220 | } |
| 221 | |
| 222 | context.PSSetShader(pPixelShader.Get(), nullptr, 0); |
| 223 | context.VSSetShader(pVertexShader.Get(), nullptr, 0); |
| 224 | context.IASetInputLayout(pInputLayout.Get()); |
| 225 | // vertex buffer |
| 226 | { |
| 227 | const UINT stride = sizeof(Point); |
| 228 | const UINT offset = 0; |
| 229 | context.IASetVertexBuffers(0, 1, pVertexBuffer.GetAddressOf(), &stride, &offset); |
| 230 | } |
| 231 | context.IASetIndexBuffer(pIndexBuffer.Get(), DXGI_FORMAT_R16_UINT, 0); |
| 232 | context.OMSetDepthStencilState(pDepthStencil.Get(), 0); |
| 233 | context.OMSetBlendState(pBlender.Get(), nullptr, 0xFFFFFFFF); |
| 234 | // viewport |
| 235 | { |
| 236 | auto& actual = dims.GetActual(); |
| 237 | const D3D11_VIEWPORT vp = { |
| 238 | .TopLeftX = 0.f, |
| 239 | .TopLeftY = 0.f, |
| 240 | .Width = float(actual.width), |
| 241 | .Height = float(actual.height), |
| 242 | .MinDepth = 0.0f, |
| 243 | .MaxDepth = 1.0f, |
| 244 | }; |
| 245 | context.RSSetViewports(1, &vp); |
| 246 | } |