mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-26 04:05:36 +00:00
Changed internal IPrinterImplementation.cs interface to facilitate non-cached rendering.
This commit is contained in:
parent
fd888e0fdf
commit
bcd982302a
|
@ -19,17 +19,18 @@ namespace OpenTK.Fonts
|
|||
{
|
||||
#region IPrinter Members
|
||||
|
||||
public TextHandle Load(OpenTK.Math.Vector2[] vertices, ushort[] indices)
|
||||
public TextHandle Load(OpenTK.Math.Vector2[] vertices, ushort[] indices, int index_count)
|
||||
{
|
||||
DisplayListTextHandle handle = new DisplayListTextHandle(GL.GenLists(1));
|
||||
|
||||
GL.NewList(handle.Handle, OpenTK.OpenGL.Enums.ListMode.Compile);
|
||||
GL.Begin(OpenTK.OpenGL.Enums.BeginMode.Triangles);
|
||||
|
||||
foreach (ushort index in indices)
|
||||
for (int i = 0; i < index_count; i++)
|
||||
//foreach (ushort index in indices)
|
||||
{
|
||||
GL.TexCoord2(vertices[index + 1]);
|
||||
GL.Vertex2(vertices[index]);
|
||||
GL.TexCoord2(vertices[indices[i] + 1]);
|
||||
GL.Vertex2(vertices[indices[i]]);
|
||||
}
|
||||
|
||||
GL.End();
|
||||
|
|
|
@ -17,7 +17,8 @@ namespace OpenTK.Fonts
|
|||
/// </summary>
|
||||
interface ITextPrinterImplementation
|
||||
{
|
||||
TextHandle Load(Vector2[] vertices, ushort[] indices);
|
||||
TextHandle Load(Vector2[] vertices, ushort[] indices, int index_count);
|
||||
void Draw(TextHandle handle);
|
||||
//void Draw(Vector2[] vertices, ushort[] indices, int index_count);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,9 @@ namespace OpenTK.Fonts
|
|||
static bool functionality_checked = false;
|
||||
static ITextPrinterImplementation printer;
|
||||
float[] viewport = new float[6];
|
||||
// 8 chars by default
|
||||
Vector2[] vertices = new Vector2[8 * 8]; // Interleaved, vertex, texcoord, vertex, etc...
|
||||
ushort[] indices = new ushort[6 * 8];
|
||||
|
||||
#region --- Constructor ---
|
||||
|
||||
|
@ -53,7 +56,7 @@ namespace OpenTK.Fonts
|
|||
GL.SupportsExtension("VERSION_1_1") ? null : null;
|
||||
*/
|
||||
if (printer == null)
|
||||
throw new NotSupportedException("DefaultLayoutProvider requires at least OpenGL 1.1 support.");
|
||||
throw new NotSupportedException("TextPrinter requires at least OpenGL 1.1 support.");
|
||||
|
||||
functionality_checked = true;
|
||||
|
||||
|
@ -130,11 +133,29 @@ namespace OpenTK.Fonts
|
|||
/// <param name="alignment">Not implemented.</param>
|
||||
/// <param name="rightToLeft">Not implemented.</param>
|
||||
/// <see cref="TextPrinter.Draw()"/>
|
||||
/// <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)
|
||||
{
|
||||
if (!functionality_checked)
|
||||
CheckNeededFunctionality();
|
||||
|
||||
int num_indices;
|
||||
|
||||
PerformLayout(text, font, width, wordWarp, alignment, rightToLeft, ref vertices, ref indices, out num_indices);
|
||||
|
||||
handle = printer.Load(vertices, indices, num_indices);
|
||||
handle.font = font;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region void PerformLayout(string text, TextureFont font, float width, bool wordWarp, StringAlignment alignment, bool rightToLeft, ref Vector2[] vertices, ref ushort[] indices, out int num_indices)
|
||||
|
||||
// Performs layout on the given string.
|
||||
void PerformLayout(string text, TextureFont font, float width, bool wordWarp, StringAlignment alignment,
|
||||
bool rightToLeft, ref Vector2[] vertices, ref ushort[] indices, out int num_indices)
|
||||
{
|
||||
if (text == null)
|
||||
throw new ArgumentNullException("Parameter cannot be null.", "text");
|
||||
|
||||
|
@ -144,8 +165,16 @@ namespace OpenTK.Fonts
|
|||
if (wordWarp || rightToLeft || alignment != StringAlignment.Near)
|
||||
throw new NotImplementedException();
|
||||
|
||||
Vector2[] vertices = new Vector2[8 * text.Length]; // Interleaved, vertex, texcoord, vertex, etc...
|
||||
ushort[] indices = new ushort[6 * text.Length];
|
||||
while (8 * text.Length > vertices.Length)
|
||||
vertices = new Vector2[vertices.Length << 1];
|
||||
|
||||
while (6 * text.Length > indices.Length)
|
||||
indices = new ushort[indices.Length << 1];
|
||||
|
||||
num_indices = 6 * text.Length;
|
||||
|
||||
//Vector2[] vertices = new Vector2[8 * text.Length]; // Interleaved, vertex, texcoord, vertex, etc...
|
||||
//ushort[] indices = new ushort[6 * text.Length];
|
||||
float x_pos = 0, y_pos = 0;
|
||||
ushort i = 0, index_count = 0, vertex_count = 0, last_break_point = 0;
|
||||
Box2 rect = new Box2();
|
||||
|
@ -218,9 +247,6 @@ namespace OpenTK.Fonts
|
|||
{
|
||||
throw new NotImplementedException("This feature is not yet implemented. Sorry for the inconvenience.");
|
||||
}
|
||||
|
||||
handle = printer.Load(vertices, indices);
|
||||
handle.font = font;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -249,7 +275,7 @@ namespace OpenTK.Fonts
|
|||
/// <param name="font">The OpenTK.Fonts.TextureFont to draw the text in.</param>
|
||||
public void Draw(string text, TextureFont font)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//printer.Draw(text);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace OpenTK.Fonts
|
|||
|
||||
#region --- IPrinter Members ---
|
||||
|
||||
public TextHandle Load(Vector2[] vertices, ushort[] indices)
|
||||
public TextHandle Load(Vector2[] vertices, ushort[] indices, int index_count)
|
||||
{
|
||||
VboTextHandle handle = new VboTextHandle(++allocated_handles);
|
||||
|
||||
|
|
Loading…
Reference in a new issue