| 1181 | } |
| 1182 | |
| 1183 | void Render2D::DrawText(Font* font, const StringView& text, const Color& color, const Float2& location, MaterialBase* customMaterial) |
| 1184 | { |
| 1185 | RENDER2D_CHECK_RENDERING_STATE; |
| 1186 | |
| 1187 | // Check if there is no need to do anything |
| 1188 | if (font == nullptr || |
| 1189 | text.Length() < 0 || |
| 1190 | (customMaterial && (!customMaterial->IsReady() || !customMaterial->IsGUI()))) |
| 1191 | return; |
| 1192 | |
| 1193 | // Temporary data |
| 1194 | uint32 fontAtlasIndex = 0; |
| 1195 | FontTextureAtlas* fontAtlas = nullptr; |
| 1196 | Float2 invAtlasSize = Float2::One; |
| 1197 | FontCharacterEntry previous; |
| 1198 | int32 kerning; |
| 1199 | float scale = 1.0f / FontManager::FontScale; |
| 1200 | const bool enableFallbackFonts = EnumHasAllFlags(Features, RenderingFeatures::FallbackFonts); |
| 1201 | |
| 1202 | // Render all characters |
| 1203 | FontCharacterEntry entry; |
| 1204 | Render2DDrawCall drawCall; |
| 1205 | if (customMaterial) |
| 1206 | { |
| 1207 | drawCall.Type = DrawCallType::DrawCharMaterial; |
| 1208 | drawCall.AsChar.Mat = customMaterial; |
| 1209 | } |
| 1210 | else |
| 1211 | { |
| 1212 | drawCall.Type = font->GetAsset()->GetOptions().RasterMode == FontRasterMode::MSDF ? DrawCallType::DrawCharMSDF : DrawCallType::DrawChar; |
| 1213 | drawCall.AsChar.Mat = nullptr; |
| 1214 | } |
| 1215 | Float2 pointer = location; |
| 1216 | for (int32 currentIndex = 0; currentIndex < text.Length(); currentIndex++) |
| 1217 | { |
| 1218 | // Cache current character |
| 1219 | const Char currentChar = text[currentIndex]; |
| 1220 | |
| 1221 | // Check if it isn't a newline character |
| 1222 | if (currentChar != '\n') |
| 1223 | { |
| 1224 | // Get character entry |
| 1225 | font->GetCharacter(currentChar, entry, enableFallbackFonts); |
| 1226 | |
| 1227 | // Check if need to select/change font atlas (since characters even in the same font may be located in different atlases) |
| 1228 | if (fontAtlas == nullptr || entry.TextureIndex != fontAtlasIndex) |
| 1229 | { |
| 1230 | // Get texture atlas that contains current character |
| 1231 | fontAtlasIndex = entry.TextureIndex; |
| 1232 | fontAtlas = FontManager::GetAtlas(fontAtlasIndex); |
| 1233 | if (fontAtlas) |
| 1234 | { |
| 1235 | fontAtlas->EnsureTextureCreated(); |
| 1236 | drawCall.AsChar.Tex = fontAtlas->GetTexture(); |
| 1237 | invAtlasSize = 1.0f / fontAtlas->GetSize(); |
| 1238 | } |
| 1239 | else |
| 1240 | { |
nothing calls this directly
no test coverage detected