| 161 | } |
| 162 | |
| 163 | void SpriteRenderer::RenderText(ID3D12GraphicsCommandList* cmdList, const SpriteFont& font, |
| 164 | const wchar* text, Float2 position, const Float4& color) |
| 165 | { |
| 166 | Assert_(text != nullptr); |
| 167 | |
| 168 | const uint64 numChars = wcslen(text); |
| 169 | |
| 170 | SpriteTransform textTransform = SpriteTransform(position); |
| 171 | |
| 172 | uint64 numCharsLeft = numChars; |
| 173 | for(uint64 offset = 0; offset < numChars; offset += MaxBatchSize) |
| 174 | { |
| 175 | uint64 numCharsToDraw = Min<uint64>(numChars, MaxBatchSize); |
| 176 | uint64 currentDraw = 0; |
| 177 | |
| 178 | for(uint64 i = 0; i < numCharsToDraw; ++i) |
| 179 | { |
| 180 | wchar character = text[i + offset]; |
| 181 | if(character == ' ') |
| 182 | textTransform.Position.x += font.SpaceWidth(); |
| 183 | else if(character == '\n') |
| 184 | { |
| 185 | textTransform.Position.y += font.CharHeight(); |
| 186 | textTransform.Position.x = 0; |
| 187 | } |
| 188 | else |
| 189 | { |
| 190 | SpriteFont::CharDesc desc = font.GetCharDescriptor(character); |
| 191 | |
| 192 | textDrawData[currentDraw].Transform = textTransform; |
| 193 | textDrawData[currentDraw].Color = color; |
| 194 | textDrawData[currentDraw].DrawRect.x = desc.X; |
| 195 | textDrawData[currentDraw].DrawRect.y = desc.Y; |
| 196 | textDrawData[currentDraw].DrawRect.z = desc.Width; |
| 197 | textDrawData[currentDraw].DrawRect.w = desc.Height; |
| 198 | |
| 199 | textTransform.Position.x += desc.Width + 1; |
| 200 | |
| 201 | ++currentDraw; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | RenderBatch(cmdList, font.FontTexture(), textDrawData, currentDraw); |
| 206 | |
| 207 | numCharsLeft -= numCharsToDraw; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | void SpriteRenderer::End() |
| 212 | { |
nothing calls this directly
no test coverage detected