mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-26 19:15:33 +00:00
Fixed dynamic text rendering when no text is precached at all.
This commit is contained in:
parent
c56152fe3b
commit
40b074179e
|
@ -27,43 +27,49 @@ namespace OpenTK.Graphics
|
||||||
{
|
{
|
||||||
//static Regex break_point = new Regex("[ .,/*-+?\\!=]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
//static Regex break_point = new Regex("[ .,/*-+?\\!=]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||||
//static char[] split_chars = new char[] { ' ', '\n', '\t', ',', '.', '/', '?', '!', ';', '\\', '-', '+', '*', '=' };
|
//static char[] split_chars = new char[] { ' ', '\n', '\t', ',', '.', '/', '?', '!', ';', '\\', '-', '+', '*', '=' };
|
||||||
static bool functionality_checked = false;
|
|
||||||
static ITextPrinterImplementation printer;
|
static ITextPrinterImplementation printer;
|
||||||
float[] viewport = new float[4];
|
float[] viewport = new float[4];
|
||||||
// 8 chars by default
|
Vector2[] vertices = new Vector2[8 * 8]; // Interleaved, vertex, texcoord, vertex, etc... Starts with 8 chars, will expand as needed.
|
||||||
Vector2[] vertices = new Vector2[8 * 8]; // Interleaved, vertex, texcoord, vertex, etc...
|
|
||||||
ushort[] indices = new ushort[6 * 8];
|
ushort[] indices = new ushort[6 * 8];
|
||||||
|
|
||||||
#region --- Constructor ---
|
#region --- Constructor ---
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new DefaultLayoutProvider object.
|
/// Constructs a new TextPrinter object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TextPrinter() { }
|
public TextPrinter() { }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region static void CheckNeededFunctionality()
|
#region --- Private Members ---
|
||||||
|
|
||||||
|
#region static ITextPrinterImplementation Printer
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks the machine's capabilities and selects the fastest method to print text.
|
/// Checks the machine's capabilities and selects the fastest method to print text.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static void CheckNeededFunctionality()
|
static ITextPrinterImplementation Printer
|
||||||
{
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (printer == null)
|
||||||
|
{
|
||||||
|
|
||||||
printer = (ITextPrinterImplementation)new DisplayListTextPrinter();
|
printer = (ITextPrinterImplementation)new DisplayListTextPrinter();
|
||||||
/*
|
//GL.SupportsExtension("VERSION_1_5") ?
|
||||||
GL.SupportsExtension("VERSION_1_5") ?
|
//(ITextPrinterImplementation)new VboTextPrinter() :
|
||||||
(ITextPrinterImplementation)new VboTextPrinter() :
|
//GL.SupportsExtension("ARB_vertex_buffer_object") ? null :
|
||||||
GL.SupportsExtension("ARB_vertex_buffer_object") ? null :
|
//GL.SupportsExtension("VERSION_1_1") ? null : null;
|
||||||
GL.SupportsExtension("VERSION_1_1") ? null : null;
|
|
||||||
*/
|
|
||||||
if (printer == null)
|
if (printer == null)
|
||||||
throw new NotSupportedException("TextPrinter requires at least OpenGL 1.1 support.");
|
throw new NotSupportedException("TextPrinter requires at least OpenGL 1.1 support.");
|
||||||
|
|
||||||
functionality_checked = true;
|
|
||||||
|
|
||||||
Debug.Print("Using {0} for font printing.", printer);
|
Debug.Print("Using {0} for font printing.", printer);
|
||||||
}
|
}
|
||||||
|
return printer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -138,14 +144,11 @@ namespace OpenTK.Graphics
|
||||||
/// <exception cref="NotSupportedException">Occurs when OpenGL 1.1 is not supported.</exception>
|
/// <exception cref="NotSupportedException">Occurs when OpenGL 1.1 is not supported.</exception>
|
||||||
public void Prepare(string text, TextureFont font, out TextHandle handle, float width, bool wordWarp, StringAlignment alignment, bool rightToLeft)
|
public void Prepare(string text, TextureFont font, out TextHandle handle, float width, bool wordWarp, StringAlignment alignment, bool rightToLeft)
|
||||||
{
|
{
|
||||||
if (!functionality_checked)
|
|
||||||
CheckNeededFunctionality();
|
|
||||||
|
|
||||||
int num_indices;
|
int num_indices;
|
||||||
|
|
||||||
PerformLayout(text, font, width, wordWarp, alignment, rightToLeft, ref vertices, ref indices, out num_indices);
|
PerformLayout(text, font, width, wordWarp, alignment, rightToLeft, ref vertices, ref indices, out num_indices);
|
||||||
|
|
||||||
handle = printer.Load(vertices, indices, num_indices);
|
handle = Printer.Load(vertices, indices, num_indices);
|
||||||
handle.font = font;
|
handle.font = font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +265,7 @@ namespace OpenTK.Graphics
|
||||||
{
|
{
|
||||||
GL.BindTexture(TextureTarget.Texture2D, handle.font.Texture);
|
GL.BindTexture(TextureTarget.Texture2D, handle.font.Texture);
|
||||||
|
|
||||||
printer.Draw(handle);
|
Printer.Draw(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -278,7 +281,10 @@ namespace OpenTK.Graphics
|
||||||
{
|
{
|
||||||
int num_indices;
|
int num_indices;
|
||||||
PerformLayout(text, font, 0, false, StringAlignment.Near, false, ref vertices, ref indices, out num_indices);
|
PerformLayout(text, font, 0, false, StringAlignment.Near, false, ref vertices, ref indices, out num_indices);
|
||||||
printer.Draw(vertices, indices, num_indices);
|
|
||||||
|
GL.BindTexture(TextureTarget.Texture2D, font.Texture);
|
||||||
|
|
||||||
|
Printer.Draw(vertices, indices, num_indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -290,6 +296,9 @@ namespace OpenTK.Graphics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Begin()
|
public void Begin()
|
||||||
{
|
{
|
||||||
|
if (GraphicsContext.CurrentContext == null)
|
||||||
|
throw new GraphicsContextException("No GraphicsContext is current in the calling thread.");
|
||||||
|
|
||||||
GL.GetFloat(GetPName.Viewport, viewport);
|
GL.GetFloat(GetPName.Viewport, viewport);
|
||||||
|
|
||||||
// Prepare to draw text. We want pixel perfect precision, so we setup a 2D mode,
|
// Prepare to draw text. We want pixel perfect precision, so we setup a 2D mode,
|
||||||
|
@ -305,9 +314,7 @@ namespace OpenTK.Graphics
|
||||||
GL.PushMatrix();
|
GL.PushMatrix();
|
||||||
GL.LoadIdentity();
|
GL.LoadIdentity();
|
||||||
|
|
||||||
GL.PushAttrib(AttribMask.TextureBit);
|
GL.PushAttrib(AttribMask.TextureBit | AttribMask.EnableBit | AttribMask.ColorBufferBit);
|
||||||
GL.PushAttrib(AttribMask.EnableBit);
|
|
||||||
GL.PushAttrib(AttribMask.ColorBufferBit);
|
|
||||||
|
|
||||||
GL.Enable(EnableCap.Texture2D);
|
GL.Enable(EnableCap.Texture2D);
|
||||||
GL.Enable(EnableCap.Blend);
|
GL.Enable(EnableCap.Blend);
|
||||||
|
|
Loading…
Reference in a new issue