From 499fefec07c21639e9922708376310ba8cff6fa3 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sun, 27 Jan 2008 05:23:10 +0000 Subject: [PATCH] - Added preloading of fonts to reduce the chance that characters from a single font will require more than one hardware texture to display. SVN r717 (trunk) --- docs/rh-log.txt | 2 ++ src/v_font.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/v_font.h | 2 ++ src/v_video.cpp | 4 ++++ 4 files changed, 52 insertions(+) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 559c5be2b3..772f5688d6 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,6 @@ January 26, 2008 +- Added preloading of fonts to reduce the chance that characters from a single + font will require more than one hardware texture to display. - Fixed: P_RailAttack() crashed if you didn't specify a puff for a rail. - Decided that allowing arbitrary alpha values for color remaps isn't so hot. Changed it back the way it was. diff --git a/src/v_font.cpp b/src/v_font.cpp index 79433d5fe8..34a83f1c32 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -741,6 +741,50 @@ int FFont::GetCharWidth (int code) const return Chars[code - FirstChar].Pic->GetScaledWidth(); } +//========================================================================== +// +// FFont :: Preload +// +// Loads most of the 7-bit ASCII characters. In the case of D3DFB, this +// means all the characters of a font have a better chance of being packed +// into the same hardware texture. +// +//========================================================================== + +void FFont::Preload() const +{ + // First and last char are the same? Wait until it's actually needed + // since nothing is gained by preloading now. + if (FirstChar == LastChar) + { + return; + } + for (int i = MAX(FirstChar, 0x21); i < MIN(LastChar, 0x7e); ++i) + { + int foo; + FTexture *pic = GetChar(i, &foo); + if (pic != NULL) + { + pic->GetNative(false); + } + } +} + +//========================================================================== +// +// FFont :: StaticPreloadFonts +// +// Preloads all the defined fonts. +// +//========================================================================== + +void FFont::StaticPreloadFonts() +{ + for (FFont *font = FirstFont; font != NULL; font = font->Next) + { + font->Preload(); + } +} //========================================================================== // diff --git a/src/v_font.h b/src/v_font.h index c485615730..d71ef785e5 100644 --- a/src/v_font.h +++ b/src/v_font.h @@ -91,8 +91,10 @@ public: int GetSpaceWidth () const { return SpaceWidth; } int GetHeight () const { return FontHeight; } int GetDefaultKerning () const { return GlobalKerning; } + void Preload() const; static FFont *FindFont (const char *fontname); + static void StaticPreloadFonts(); // Return width of string in pixels (unscaled) int StringWidth (const BYTE *str) const; diff --git a/src/v_video.cpp b/src/v_video.cpp index f3ddc79ea5..ebb3282ebd 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -1386,6 +1386,10 @@ bool V_DoModeSetup (int width, int height, int bits) screen->SetFont (SmallFont); screen->SetGamma (Gamma); + // Load fonts now so they can be packed into textures straight away, + // if D3DFB is being used for the display. + FFont::StaticPreloadFonts(); + { int ratio; int cwidth;