protected override Glyph GetGlyph(CommandList commandList, char character, ref Vector2 fontSize, bool uploadGpuResources, out Vector2 fixScaling)
        {
            // Add a safe guard to prevent the system to generate characters too big for the dynamic font cache texture
            fontSize.X = Math.Min(fontSize.X, 1024);
            fontSize.Y = Math.Min(fontSize.Y, 1024);

            // get the character data associated to the provided character and size
            var characterData = GetOrCreateCharacterData(fontSize, character);

            // generate the bitmap if it does not exist
            if (characterData.Bitmap == null)
            {
                FontManager.GenerateBitmap(characterData, false);
            }

            // upload the character to the GPU font texture and create the glyph if does not exists
            if (uploadGpuResources && characterData.Bitmap != null && !characterData.IsBitmapUploaded)
            {
                FontCacheManager.UploadCharacterBitmap(commandList, characterData);
            }

            // update the character usage info
            FontCacheManager.NotifyCharacterUtilization(characterData);

            fixScaling = fontSize / characterData.Size;

            return(characterData.Glyph);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Load this system.
 /// </summary>
 /// <param name="graphicsDevice">The graphics device.</param>
 /// <exception cref="System.ArgumentNullException">graphicsDevice</exception>
 public void Load(GraphicsDevice graphicsDevice, IDatabaseFileProviderService fileProviderService)
 {
     // TODO possibly load cached character bitmaps from the disk
     if (graphicsDevice == null)
     {
         throw new ArgumentNullException("graphicsDevice");
     }
     GraphicsDevice   = graphicsDevice;
     FontManager      = new FontManager(fileProviderService);
     FontCacheManager = new FontCacheManager(this);
 }