Skip to content

Commit a0bd786

Browse files
committed
Adopt flat layer command buffers, float geometry
By preallocating a big flat command buffer for each layer that stores each draw command in sequence we can get rid of some of the pointer chasing of the pool of separate draw commands, instead reading data sequentially from the stream of draw commands. The stream can be walked from front to back by skipping ahead by the computed size of each command. While making these changes the underlying floating point type for vertex positions and texcoords was changed from doubles to floats to save significant storage space each frame.
1 parent e06849f commit a0bd786

3 files changed

Lines changed: 492 additions & 254 deletions

File tree

engine/render/r_font.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
// Glyph parameters
1919
struct f_glyph_s {
20-
double tcLeft = 0.0;
21-
double tcRight = 0.0;
22-
double tcTop = 0.0;
23-
double tcBottom = 0.0;
20+
float tcLeft = 0.0;
21+
float tcRight = 0.0;
22+
float tcTop = 0.0;
23+
float tcBottom = 0.0;
2424
int width = 0;
2525
int spLeft = 0;
2626
int spRight = 0;
@@ -32,7 +32,7 @@ struct f_fontHeight_s {
3232
int height;
3333
int numGlyph;
3434
f_glyph_s glyphs[128];
35-
f_glyph_s defGlyph{0.0, 0.0, 0.0, 0.0, 0, 0, 0};
35+
f_glyph_s defGlyph{0.0f, 0.0f, 0.0f, 0.0f, 0, 0, 0};
3636

3737
f_glyph_s const& Glyph(char ch) const {
3838
if ((unsigned char)ch >= numGlyph) {
@@ -84,10 +84,10 @@ r_font_c::r_font_c(r_renderer_c* renderer, const char* fontName)
8484
// Add glyph
8585
if (fh->numGlyph >= 128) continue;
8686
f_glyph_s* glyph = &fh->glyphs[fh->numGlyph++];
87-
glyph->tcLeft = (double)x / fh->tex->fileWidth;
88-
glyph->tcRight = (double)(x + w) / fh->tex->fileWidth;
89-
glyph->tcTop = (double)y / fh->tex->fileHeight;
90-
glyph->tcBottom = (double)(y + fh->height) / fh->tex->fileHeight;
87+
glyph->tcLeft = (float)x / fh->tex->fileWidth;
88+
glyph->tcRight = (float)(x + w) / fh->tex->fileWidth;
89+
glyph->tcTop = (float)y / fh->tex->fileHeight;
90+
glyph->tcBottom = (float)(y + fh->height) / fh->tex->fileHeight;
9191
glyph->width = w;
9292
glyph->spLeft = sl;
9393
glyph->spRight = sr;
@@ -240,14 +240,14 @@ void r_font_c::DrawTextLine(scp_t pos, int align, int height, col4_t col, const
240240

241241
// Find best height to use
242242
f_fontHeight_s *fh = fontHeights[height > maxHeight? (numFontHeight - 1) : fontHeightMap[height]];
243-
double scale = (double)height / fh->height;
243+
float scale = (float)height / fh->height;
244244

245245
// Calculate the string position
246-
double x = pos[X];
247-
double y = pos[Y];
246+
float x = pos[X];
247+
float y = pos[Y];
248248
if (align != F_LEFT) {
249249
// Calculate the real width of the string
250-
double width = StringWidthInternal(fh, str) * scale;
250+
float width = StringWidthInternal(fh, str) * scale;
251251
switch (align) {
252252
case F_CENTRE:
253253
x = floor((renderer->VirtualScreenWidth() - width) / 2.0f + pos[X]);
@@ -297,7 +297,7 @@ void r_font_c::DrawTextLine(scp_t pos, int align, int height, col4_t col, const
297297
auto& glyph = fh->Glyph(*str++);
298298
x+= glyph.spLeft * scale;
299299
if (glyph.width) {
300-
double w = glyph.width * scale;
300+
float w = glyph.width * scale;
301301
if (x + w >= 0 && x < renderer->VirtualScreenWidth()) {
302302
renderer->curLayer->Quad(
303303
glyph.tcLeft, glyph.tcTop, x, y,

0 commit comments

Comments
 (0)