MCPcopy Create free account
hub / github.com/cjcliffe/CubicSDR / cacheString

Method cacheString

src/util/GLFont.cpp:694–753  ·  view source on GitHub ↗

Compile optimized GLFontCacheString

Source from the content-addressed store, hash-verified

692
693// Compile optimized GLFontCacheString
694GLFontStringCache *GLFont::cacheString(const std::wstring& str, int pxHeight, int vpx, int vpy) {
695
696 auto *fc = new GLFontStringCache;
697
698 fc->pxHeight = pxHeight;
699 fc->vpx = vpx;
700 fc->vpy = vpy;
701
702 float size = (float) pxHeight / (float) vpy;
703 float viewAspect = (float) vpx / (float) vpy;
704
705 fc->msgWidth = getStringWidth(str, size, viewAspect);
706
707 int nChar = 0;
708 for (int charId : str) {
709 if (characters.find(charId) == characters.end()) {
710 continue;
711 }
712 nChar++;
713 }
714
715 fc->drawlen = nChar;
716 fc->gl_vertices.resize(nChar*8);
717 fc->gl_uv.resize(nChar*8);
718
719
720 CubicVR::mat4 trans = CubicVR::mat4::scale(size / viewAspect, size, 1.0f);
721
722 int c = 0;
723 for (int charId : str) {
724 if (characters.find(charId) == characters.end()) {
725 continue;
726 }
727
728 GLFontChar *fchar = characters[charId];
729
730 float ofsx = (float) fchar->getXOffset() / (float) imageWidth;
731 float advx = (float) fchar->getXAdvance() / (float) imageWidth;
732
733 if (charId == 32) {
734 advx = characters[L'_']->getAspect();
735 }
736
737 // freeze transform to buffer
738 trans *= CubicVR::mat4::translate(ofsx, 0.0, 0.0);
739 int charIdx = fchar->getIndex();
740 for (int j = 0; j < 8; j+=2) {
741 CubicVR::vec3 pt(gl_vertices[charIdx + j],gl_vertices[charIdx + j + 1], 0.0);
742 pt = CubicVR::mat4::multiply(trans, pt, true);
743 fc->gl_vertices[c * 8 + j] = pt[0];
744 fc->gl_vertices[c * 8 + j + 1] = pt[1];
745 fc->gl_uv[c * 8 + j] = gl_uv[charIdx + j];
746 fc->gl_uv[c * 8 + j + 1] = gl_uv[charIdx + j + 1];
747 }
748 trans *= CubicVR::mat4::translate(fchar->getAspect() + advx, 0.0, 0.0);
749 c++;
750 }
751

Callers

nothing calls this directly

Calls 5

findMethod · 0.80
getXOffsetMethod · 0.80
getXAdvanceMethod · 0.80
getAspectMethod · 0.80
getIndexMethod · 0.45

Tested by

no test coverage detected