Skip to content

Commit

Permalink
Debug output for mipmap level calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
s09bQ5 committed Sep 9, 2024
1 parent 579a89c commit 2edfbf5
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/base/UFont.pas
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ interface
Math,
Classes,
SysUtils,
ULog,
UUnicodeUtils,
{$IFDEF BITMAP_FONT}
UTexture,
Expand Down Expand Up @@ -1222,6 +1223,7 @@ function TScalableFont.GetMipmapLevel(): integer;
ViewPortArray: TGLVectori4;
Dist, Dist2, DistSum, PM15x2: double;
WidthScale, HeightScale: double;
Level: float;
const
// an offset to the mipmap-level to adjust the change-over of two consecutive
// mipmap levels. If for example the bias is 0.1 and unbiased level is 1.9
Expand Down Expand Up @@ -1280,7 +1282,34 @@ function TScalableFont.GetMipmapLevel(): integer;
// The result is our mipmap-level = the index of the mipmap to use.

// Level > 0: Minification; < 0: Magnification
Result := Trunc(Log2(Max(WidthScale, HeightScale)) + cBias);
Level := Log2(Max(WidthScale, HeightScale)) + cBias;

if (Level > 32767) or (Level < -32768) or IsNan(Level) then
begin
Log.LogError('Mipmap level out of range: ' + FloatToStr(Level), 'TScalableFont.GetMipmapLevel');
Log.LogError('{{' + FloatToStr(ModelMatrix[0,0]) + ', ' + FloatToStr(ModelMatrix[0,1]) + ', '
+ FloatToStr(ModelMatrix[0,2]) + ', ' + FloatToStr(ModelMatrix[0,3]) + '}, {'
+ FloatToStr(ModelMatrix[1,0]) + ', ' + FloatToStr(ModelMatrix[1,1]) + ', '
+ FloatToStr(ModelMatrix[1,2]) + ', ' + FloatToStr(ModelMatrix[1,3]) + '}, {'
+ FloatToStr(ModelMatrix[2,0]) + ', ' + FloatToStr(ModelMatrix[2,1]) + ', '
+ FloatToStr(ModelMatrix[2,2]) + ', ' + FloatToStr(ModelMatrix[2,3]) + '}, {'
+ FloatToStr(ModelMatrix[3,0]) + ', ' + FloatToStr(ModelMatrix[3,1]) + ', '
+ FloatToStr(ModelMatrix[3,2]) + ', ' + FloatToStr(ModelMatrix[3,3]) + '}}',
'ModelView Matrix');
Log.LogError('{{' + FloatToStr(ProjMatrix[0,0]) + ', ' + FloatToStr(ProjMatrix[0,1]) + ', '
+ FloatToStr(ProjMatrix[0,2]) + ', ' + FloatToStr(ProjMatrix[0,3]) + '}, {'
+ FloatToStr(ProjMatrix[1,0]) + ', ' + FloatToStr(ProjMatrix[1,1]) + ', '
+ FloatToStr(ProjMatrix[1,2]) + ', ' + FloatToStr(ProjMatrix[1,3]) + '}, {'
+ FloatToStr(ProjMatrix[2,0]) + ', ' + FloatToStr(ProjMatrix[2,1]) + ', '
+ FloatToStr(ProjMatrix[2,2]) + ', ' + FloatToStr(ProjMatrix[2,3]) + '}, {'
+ FloatToStr(ProjMatrix[3,0]) + ', ' + FloatToStr(ProjMatrix[3,1]) + ', '
+ FloatToStr(ProjMatrix[3,2]) + ', ' + FloatToStr(ProjMatrix[3,3]) + '}}',
'Projection Matrix');
Log.LogError('{' + IntToStr(ViewPortArray[0]) + ', ' + IntToStr(ViewPortArray[1]) + ', '
+ IntToStr(ViewPortArray[2]) + ', ' + IntToStr(ViewPortArray[3]) + '}',
'Viewport');
end;
Result := Trunc(Level);

// clamp to valid range
if (Result < 0) then
Expand Down

0 comments on commit 2edfbf5

Please sign in to comment.