| 367 | } |
| 368 | |
| 369 | void SpriteRenderer::RenderText(const SpriteFont& font, |
| 370 | const wchar* text, |
| 371 | const Float4x4& transform, |
| 372 | const Float4& color) |
| 373 | { |
| 374 | D3DPERF_BeginEvent(0xFFFFFFFF, L"SpriteRenderer RenderText"); |
| 375 | |
| 376 | size_t length = wcslen(text); |
| 377 | |
| 378 | Float4x4 textTransform; |
| 379 | |
| 380 | uint64 numCharsToDraw = std::min(length, MaxBatchSize); |
| 381 | uint64 currentDraw = 0; |
| 382 | for(uint64 i = 0; i < numCharsToDraw; ++i) |
| 383 | { |
| 384 | wchar character = text[i]; |
| 385 | if(character == ' ') |
| 386 | textTransform._41 += font.SpaceWidth(); |
| 387 | else if(character == '\n') |
| 388 | { |
| 389 | textTransform._42 += font.CharHeight(); |
| 390 | textTransform._41 = 0; |
| 391 | } |
| 392 | else |
| 393 | { |
| 394 | SpriteFont::CharDesc desc = font.GetCharDescriptor(character); |
| 395 | |
| 396 | textDrawData[currentDraw].Transform = textTransform * transform; |
| 397 | textDrawData[currentDraw].Color = color; |
| 398 | textDrawData[currentDraw].DrawRect.x = desc.X; |
| 399 | textDrawData[currentDraw].DrawRect.y = desc.Y; |
| 400 | textDrawData[currentDraw].DrawRect.z = desc.Width; |
| 401 | textDrawData[currentDraw].DrawRect.w = desc.Height; |
| 402 | currentDraw++; |
| 403 | |
| 404 | textTransform._41 += desc.Width + 1; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | // Submit a batch |
| 409 | RenderBatch(font.SRView(), textDrawData, currentDraw); |
| 410 | |
| 411 | D3DPERF_EndEvent(); |
| 412 | |
| 413 | if(length > numCharsToDraw) |
| 414 | RenderText(font, text + numCharsToDraw, textTransform, color); |
| 415 | } |
| 416 | |
| 417 | void SpriteRenderer::End() |
| 418 | { |
nothing calls this directly
no test coverage detected