mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-06 04:10:37 +00:00
Added display list cache to GL1TextOutputProvider. This change improves peak TextPrinter speed by more than 10x (1.6M glyphs per second as measured on a 1.8GHz Core 2 with a 8400M card). We still need a cache eviction strategy.
Modified ITextOutputProvider interface to pass TextBlocks by reference.
This commit is contained in:
parent
8d83b41a63
commit
b6c81ee278
|
@ -54,6 +54,11 @@ namespace OpenTK.Graphics.Text
|
||||||
Viewport viewport = new Viewport();
|
Viewport viewport = new Viewport();
|
||||||
Matrix4 matrix = new Matrix4();
|
Matrix4 matrix = new Matrix4();
|
||||||
|
|
||||||
|
// TextBlock - display list cache.
|
||||||
|
// Todo: we need a cache eviction strategy.
|
||||||
|
const int block_cache_capacity = 32;
|
||||||
|
readonly Dictionary<int, int> block_cache = new Dictionary<int, int>(block_cache_capacity);
|
||||||
|
|
||||||
bool disposed;
|
bool disposed;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -71,7 +76,7 @@ namespace OpenTK.Graphics.Text
|
||||||
|
|
||||||
#region Print
|
#region Print
|
||||||
|
|
||||||
public void Print(TextBlock block, Color color, IGlyphRasterizer rasterizer)
|
public void Print(ref TextBlock block, Color color, IGlyphRasterizer rasterizer)
|
||||||
{
|
{
|
||||||
GL.PushAttrib(AttribMask.CurrentBit | AttribMask.TextureBit | AttribMask.EnableBit | AttribMask.ColorBufferBit | AttribMask.DepthBufferBit);
|
GL.PushAttrib(AttribMask.CurrentBit | AttribMask.TextureBit | AttribMask.EnableBit | AttribMask.ColorBufferBit | AttribMask.DepthBufferBit);
|
||||||
|
|
||||||
|
@ -83,6 +88,13 @@ namespace OpenTK.Graphics.Text
|
||||||
|
|
||||||
RectangleF position;
|
RectangleF position;
|
||||||
|
|
||||||
|
int block_hash = block.GetHashCode();
|
||||||
|
if (block_cache.ContainsKey(block_hash))
|
||||||
|
{
|
||||||
|
GL.CallList(block_cache[block_hash]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
using (TextExtents extents = rasterizer.MeasureText(ref block))
|
using (TextExtents extents = rasterizer.MeasureText(ref block))
|
||||||
{
|
{
|
||||||
// Build layout
|
// Build layout
|
||||||
|
@ -139,6 +151,12 @@ namespace OpenTK.Graphics.Text
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
|
int display_list = 0;
|
||||||
|
if ((block.Options & TextPrinterOptions.NoCache) == 0)
|
||||||
|
{
|
||||||
|
display_list = GL.GenLists(1);
|
||||||
|
GL.NewList(display_list, ListMode.CompileAndExecute);
|
||||||
|
}
|
||||||
foreach (Texture2D key in active_lists.Keys)
|
foreach (Texture2D key in active_lists.Keys)
|
||||||
{
|
{
|
||||||
List<Vector2> list = active_lists[key];
|
List<Vector2> list = active_lists[key];
|
||||||
|
@ -157,6 +175,11 @@ namespace OpenTK.Graphics.Text
|
||||||
|
|
||||||
GL.End();
|
GL.End();
|
||||||
}
|
}
|
||||||
|
if ((block.Options & TextPrinterOptions.NoCache) == 0)
|
||||||
|
{
|
||||||
|
GL.EndList();
|
||||||
|
block_cache.Add(block_hash, display_list);
|
||||||
|
}
|
||||||
|
|
||||||
// Clean layout
|
// Clean layout
|
||||||
foreach (List<Vector2> list in active_lists.Values)
|
foreach (List<Vector2> list in active_lists.Values)
|
||||||
|
@ -166,6 +189,7 @@ namespace OpenTK.Graphics.Text
|
||||||
}
|
}
|
||||||
|
|
||||||
active_lists.Clear();
|
active_lists.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
GL.PopAttrib();
|
GL.PopAttrib();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace OpenTK.Graphics.Text
|
||||||
{
|
{
|
||||||
interface ITextOutputProvider : IDisposable
|
interface ITextOutputProvider : IDisposable
|
||||||
{
|
{
|
||||||
void Print(TextBlock block, Color color, IGlyphRasterizer rasterizer);
|
void Print(ref TextBlock block, Color color, IGlyphRasterizer rasterizer);
|
||||||
void Clear();
|
void Clear();
|
||||||
void Begin();
|
void Begin();
|
||||||
void End();
|
void End();
|
||||||
|
|
|
@ -134,7 +134,8 @@ namespace OpenTK.Graphics
|
||||||
if (!ValidateParameters(text, font, rect))
|
if (!ValidateParameters(text, font, rect))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TextOutput.Print(new TextBlock(text, font, rect, options, alignment, direction), color, Rasterizer);
|
TextBlock block = new TextBlock(text, font, rect, options, alignment, direction);
|
||||||
|
TextOutput.Print(ref block, color, Rasterizer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in a new issue