| 386 | } |
| 387 | |
| 388 | void SpriteRenderer::RenderText(const SpriteFont& font, |
| 389 | const wchar* text, |
| 390 | const Float4x4& transform, |
| 391 | const Float4& color) |
| 392 | { |
| 393 | D3DPERF_BeginEvent(0xFFFFFFFF, L"SpriteRenderer RenderText"); |
| 394 | |
| 395 | size_t length = wcslen(text); |
| 396 | |
| 397 | Float4x4 textTransform; |
| 398 | |
| 399 | uint64 numCharsToDraw = std::min(length, MaxBatchSize); |
| 400 | uint64 currentDraw = 0; |
| 401 | for(uint64 i = 0; i < numCharsToDraw; ++i) |
| 402 | { |
| 403 | wchar character = text[i]; |
| 404 | if(character == ' ') |
| 405 | textTransform._41 += font.SpaceWidth(); |
| 406 | else if(character == '\n') |
| 407 | { |
| 408 | textTransform._42 += font.CharHeight(); |
| 409 | textTransform._41 = 0; |
| 410 | } |
| 411 | else |
| 412 | { |
| 413 | SpriteFont::CharDesc desc = font.GetCharDescriptor(character); |
| 414 | |
| 415 | textDrawData[currentDraw].Transform = textTransform * transform; |
| 416 | textDrawData[currentDraw].Color = color; |
| 417 | textDrawData[currentDraw].DrawRect.x = desc.X; |
| 418 | textDrawData[currentDraw].DrawRect.y = desc.Y; |
| 419 | textDrawData[currentDraw].DrawRect.z = desc.Width; |
| 420 | textDrawData[currentDraw].DrawRect.w = desc.Height; |
| 421 | currentDraw++; |
| 422 | |
| 423 | textTransform._41 += desc.Width + 1; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | // Submit a batch |
| 428 | RenderBatch(font.SRView(), textDrawData, currentDraw); |
| 429 | |
| 430 | D3DPERF_EndEvent(); |
| 431 | |
| 432 | if(length > numCharsToDraw) |
| 433 | RenderText(font, text + numCharsToDraw, textTransform, color); |
| 434 | } |
| 435 | |
| 436 | void SpriteRenderer::End() |
| 437 | { |
no test coverage detected