commit 789ac69
uint
·
2026-06-13 13:30:45 +0000 UTC
parent b111d29
Cull off screen glyphs
1 files changed,
+26,
-11
+26,
-11
1@@ -31,21 +31,36 @@ void maus_draw_text(Maus* mw, MausFont* font, int32_t x, int32_t y,
2 continue;
3 }
4
5- /* origins to start drawing glpyh from */
6+ /* origins to start drawing glyph from */
7 int32_t gox = cx + g->xoff;
8 int32_t goy = cy + font->asc - g->h - g->yoff;
9
10+ /* starting coordinates */
11+ int sgx = (-gox > 0) ? -gox : 0;
12+ int sgy = (-goy > 0) ? -goy : 0;
13+
14+ /* ending coordinates. if glyph runs over right/bottom, clamp it */
15+ int end_gx = (mw->width - gox < g->w) ? (mw->width - gox) : g->w;
16+ int end_gy = (mw->height - goy < g->h) ?(mw->height - goy) : g->h;
17+
18+ /* cull glyphs which start off screen */
19+ if (sgx >= end_gx || sgy >= end_gy) {
20+ cx += g->adv;
21+ continue;
22+ }
23+
24 /* "blit" font to framebuffer */
25- for (uint16_t gy = 0; gy < g->h; gy++) {
26- for (uint16_t gx = 0; gx < g->w; gx++) {
27- bool solid = g->bmp[gy * g->w + gx] > 0;
28- if (solid) {
29- int32_t dstx = gox + gx;
30- int32_t dsty = goy + gy;
31- if (dstx >= 0 && dstx < (int)mw->width &&
32- dsty >= 0 && dsty < (int)mw->height) {
33- MAUS_PIXEL_AT(mw, dstx, dsty) = col_up;
34- }
35+ for (int gy = sgy; gy < end_gy; gy++) {
36+ int dsty = goy + gy;
37+
38+ /* calculate row pointer once per scanline */
39+ uint32_t* row = mw->bfb + (dsty * mw->stride);
40+ int offset = gy * g->w;
41+
42+ for (int gx = sgx; gx < end_gx; gx++) {
43+ if (g->bmp[offset + gx] > 0) {
44+ int dstx = gox + gx;
45+ row[dstx] = col_up;
46 }
47 }
48 }