MCPcopy Create free account
hub / github.com/TheRealMJP/SHforHLSL / RenderText

Method RenderText

SHTest/SampleFramework12/v1.04/Graphics/SpriteRenderer.cpp:163–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161}
162
163void 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
211void SpriteRenderer::End()
212{

Callers

nothing calls this directly

Calls 4

SpriteTransformClass · 0.85
SpaceWidthMethod · 0.80
CharHeightMethod · 0.80
FontTextureMethod · 0.80

Tested by

no test coverage detected