MCPcopy Create free account
hub / github.com/TheRealMJP/BakingLab / Render

Method Render

SampleFramework11/v1.02/Graphics/SpriteRenderer.cpp:270–327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268}
269
270void SpriteRenderer::Render(ID3D11ShaderResourceView* texture,
271 const Float4x4& transform,
272 const Float4& color,
273 const Float4* drawRect)
274{
275 _ASSERT(context);
276 _ASSERT(initialized);
277
278 D3DPERF_BeginEvent(0xFFFFFFFF, L"SpriteRenderer Render");
279
280 // Set the vertex shader
281 context->VSSetShader(vertexShader, nullptr, 0);
282
283 // Set the input layout
284 context->IASetInputLayout(inputLayout);
285
286 // Set the vertex buffer
287 UINT stride = sizeof(SpriteVertex);
288 UINT offset = 0;
289 ID3D11Buffer* vb = vertexBuffer.GetInterfacePtr();
290 context->IASetVertexBuffers(0, 1, &vb, &stride, &offset);
291
292 // Set per-batch constants
293 D3D11_TEXTURE2D_DESC desc = SetPerBatchData(texture);
294
295 // Set per-instance data
296 SpriteDrawData perInstance;
297 perInstance.Transform = Float4x4::Transpose(transform);
298 perInstance.Color = color;
299
300 // Draw rect
301 if(drawRect == nullptr)
302 perInstance.DrawRect = Float4(0, 0, static_cast<float>(desc.Width), static_cast<float>(desc.Height));
303 else
304 {
305 _ASSERT(drawRect->x >= 0 && drawRect->x < desc.Width);
306 _ASSERT(drawRect->y >= 0 && drawRect->y < desc.Height);
307 _ASSERT(drawRect->z > 0 && drawRect->x + drawRect->z < desc.Width);
308 _ASSERT(drawRect->w > 0 && drawRect->y + drawRect->w < desc.Height);
309 perInstance.DrawRect = *drawRect;
310 }
311
312 // Copy in the buffer data
313 D3D11_MAPPED_SUBRESOURCE mapped;
314 DXCall(context->Map(vsPerInstanceCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped));
315 CopyMemory(mapped.pData, &perInstance, sizeof(SpriteDrawData));
316 context->Unmap(vsPerInstanceCB, 0);
317
318 ID3D11Buffer* buffers [2] = { vsPerBatchCB, vsPerInstanceCB };
319 context->VSSetConstantBuffers(0, 2, buffers);
320
321 // Set the texture
322 context->PSSetShaderResources(0, 1, &texture);
323
324 context->DrawIndexed(6, 0, 0);
325
326 D3DPERF_EndEvent();
327}

Callers

nothing calls this directly

Calls 5

DXCallFunction · 0.85
UnmapMethod · 0.80
Float4Class · 0.70
TransposeClass · 0.50
MapMethod · 0.45

Tested by

no test coverage detected