| 144 | } |
| 145 | |
| 146 | void TextRenderer::renderText(RenderContext* pRenderContext, const std::string& text, const ref<Fbo>& pDstFbo, float2 pos) |
| 147 | { |
| 148 | // Make sure we enough space for the next char |
| 149 | FALCOR_ASSERT(text.size() < kMaxCharCount); |
| 150 | setCbData(pDstFbo); |
| 151 | const auto& pVao = mpVaos[mVaoIndex]; |
| 152 | const auto& pVb = pVao->getVertexBuffer(0); |
| 153 | Vertex* verts = reinterpret_cast<Vertex*>(pVb->map()); |
| 154 | |
| 155 | float startX = pos.x; |
| 156 | uint32_t vertexCount = 0; // Not the same as text.size(), since some special characters are ignored |
| 157 | |
| 158 | // Create the vertex-buffer |
| 159 | for (const auto& c : text) |
| 160 | { |
| 161 | if (c == '\n') |
| 162 | { |
| 163 | pos.y += mpFont->getFontHeight(); |
| 164 | pos.x = startX; |
| 165 | } |
| 166 | else if (c == '\t') |
| 167 | pos.x += mpFont->getTabWidth(); |
| 168 | else if (c == ' ') |
| 169 | pos.x += mpFont->getLettersSpacing(); |
| 170 | else |
| 171 | { |
| 172 | // Regular character |
| 173 | const Font::CharTexCrdDesc& desc = mpFont->getCharDesc(c); |
| 174 | for (uint32_t i = 0; i < std::size(kVertexPos); i++, vertexCount++) |
| 175 | { |
| 176 | float2 posScale = kVertexPos[i]; |
| 177 | float2 charPos = desc.size * posScale; |
| 178 | charPos += pos; |
| 179 | verts[vertexCount].screenPos = charPos; |
| 180 | verts[vertexCount].texCoord = desc.topLeft + desc.size * kVertexPos[i]; |
| 181 | } |
| 182 | pos.x += mpFont->getLettersSpacing(); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | // Submit |
| 187 | pVb->unmap(); |
| 188 | mpPass->getState()->setVao(pVao); |
| 189 | mpPass->getState()->setFbo(pDstFbo); |
| 190 | mpPass->draw(pRenderContext, vertexCount, 0); |
| 191 | |
| 192 | mVaoIndex = (mVaoIndex + 1) % kVaoCount; |
| 193 | } |
| 194 | |
| 195 | } // namespace Falcor |
nothing calls this directly
no test coverage detected