| 229 | } |
| 230 | |
| 231 | D3D11_TEXTURE2D_DESC SpriteRenderer::SetPerBatchData(ID3D11ShaderResourceView* texture) |
| 232 | { |
| 233 | // Set per-batch constants |
| 234 | VSPerBatchCB perBatch; |
| 235 | |
| 236 | // Get the viewport dimensions |
| 237 | UINT numViewports = 1; |
| 238 | D3D11_VIEWPORT vp; |
| 239 | context->RSGetViewports(&numViewports, &vp); |
| 240 | perBatch.ViewportSize = Float2(static_cast<float>(vp.Width), static_cast<float>(vp.Height)); |
| 241 | |
| 242 | D3D11_TEXTURE2D_DESC desc; |
| 243 | |
| 244 | // Get the size of the texture |
| 245 | if(texture) |
| 246 | { |
| 247 | ID3D11Resource* resource; |
| 248 | ID3D11Texture2DPtr texResource; |
| 249 | texture->GetResource(&resource); |
| 250 | texResource.Attach(reinterpret_cast<ID3D11Texture2D*>(resource)); |
| 251 | texResource->GetDesc(&desc); |
| 252 | perBatch.TextureSize = Float2(static_cast<float>(desc.Width), static_cast<float>(desc.Height)); |
| 253 | } |
| 254 | else |
| 255 | { |
| 256 | perBatch.TextureSize = Float2(1.0f, 1.0f); |
| 257 | desc.Width = 1; |
| 258 | desc.Height = 1; |
| 259 | } |
| 260 | |
| 261 | // Copy it into the buffer |
| 262 | D3D11_MAPPED_SUBRESOURCE mapped; |
| 263 | DXCall(context->Map(vsPerBatchCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped)); |
| 264 | CopyMemory(mapped.pData, &perBatch, sizeof(VSPerBatchCB)); |
| 265 | context->Unmap(vsPerBatchCB, 0); |
| 266 | |
| 267 | return desc; |
| 268 | } |
| 269 | |
| 270 | void SpriteRenderer::Render(ID3D11ShaderResourceView* texture, |
| 271 | const Float4x4& transform, |