[slimdx] r2199 committed - Simplified the font rendering path.

11 views
Skip to first unread message

sli...@googlecode.com

unread,
Mar 25, 2012, 11:24:18 PM3/25/12
to slimdx...@googlegroups.com
Revision: 2199
Author: mike.popoloski
Date: Sun Mar 25 20:23:55 2012
Log: Simplified the font rendering path.
http://code.google.com/p/slimdx/source/detail?r=2199

Modified:
/branches/lite/SlimDX.Toolkit/Drawing/TextureAtlas.cs
/branches/lite/SlimDX.Toolkit/Fonts/Font.cs
/branches/lite/SlimDX.Toolkit/Fonts/Internal/GlyphAtlas.cs
/branches/lite/SlimDX.Toolkit/Fonts/Internal/GlyphImageRenderer.cs
/branches/lite/SlimDX.Toolkit/Fonts/Internal/GlyphProvider.cs
/branches/lite/SlimDX.Toolkit/Fonts/Internal/TextRenderer.cs
/branches/lite/SlimDX.Toolkit/Fonts/Internal/VertexDrawer.cs

=======================================
--- /branches/lite/SlimDX.Toolkit/Drawing/TextureAtlas.cs Sat Mar 24
18:37:53 2012
+++ /branches/lite/SlimDX.Toolkit/Drawing/TextureAtlas.cs Sun Mar 25
20:23:55 2012
@@ -154,6 +154,16 @@
{
unsafe { return *(RectangleF*)coordinates[texture]; }
}
+
+ /// <summary>
+ /// Gets the texture coordinates for the given texture stored in
the atlas.
+ /// </summary>
+ /// <param name="texture">The ID of the texture whose coordinates
are to be retrieved.</param>
+ /// <param name="rect">When the method completes, contains a
pointer to the normalized texture coordinates.</param>
+ public unsafe void GetCoordinates(int texture, out RectangleF
*rect)
+ {
+ rect = (RectangleF*)coordinates[texture];
+ }

/// <summary>
/// Freezes the texture atlas, preventing further additions and
allowing the local copy
=======================================
--- /branches/lite/SlimDX.Toolkit/Fonts/Font.cs Sat Mar 24 20:12:36 2012
+++ /branches/lite/SlimDX.Toolkit/Fonts/Font.cs Sun Mar 25 20:23:55 2012
@@ -180,10 +180,8 @@
{
flags |= TextOptions.NoWordWrap;

- var layout = CreateTextLayout(text, fontFamily, size, new
RectangleF(x, y, 0, 0), flags);
- DrawTextLayout(context, layout, x, y, color, flags);
-
- layout.Dispose();
+ using (var layout = CreateTextLayout(text, fontFamily, size,
new RectangleF(x, y, 0, 0), flags))
+ DrawTextLayout(context, layout, x, y, color, flags);
}

/// <summary>
@@ -249,16 +247,17 @@
/// <returns>A rectangle denoting the extents of the measured
text.</returns>
public RectangleF MeasureText(string text, string fontFamily,
float size, RectangleF layoutBounds, TextOptions flags)
{
- var result = new RectangleF(layoutBounds.Left,
layoutBounds.Top, 0, 0);
- var layout = CreateTextLayout(text, fontFamily, size,
layoutBounds, flags);
- var metrics = layout.OverhangMetrics;
-
- result.X = (float)Math.Floor(layoutBounds.Left - metrics.Left);
- result.Y = (float)Math.Floor(layoutBounds.Top - metrics.Top);
- result.Width = (float)Math.Ceiling(layoutBounds.Left +
metrics.Right) - result.X;
- result.Height = (float)Math.Ceiling(layoutBounds.Top +
metrics.Bottom) - result.Y;
-
- return result;
+ using (var layout = CreateTextLayout(text, fontFamily, size,
layoutBounds, flags))
+ {
+ var metrics = layout.OverhangMetrics;
+ var result = new RectangleF();
+ result.X = (float)Math.Floor(layoutBounds.Left -
metrics.Left);
+ result.Y = (float)Math.Floor(layoutBounds.Top -
metrics.Top);
+ result.Width = (float)Math.Ceiling(layoutBounds.Left +
metrics.Right) - result.X;
+ result.Height = (float)Math.Ceiling(layoutBounds.Top +
metrics.Bottom) - result.Y;
+
+ return result;
+ }
}

/// <summary>
@@ -310,7 +309,7 @@
unsafe void DrawGeometry(DeviceContext context, RectangleF*
clipBounds, Matrix* transformMatrix, TextOptions flags)
{
using (new StateSaver(context, (flags &
TextOptions.RestoreState) != 0))
- glyphDrawer.DrawVertices(context, glyphAtlas,
renderer.SortVertices(), anisotropic, clipBounds, transformMatrix, flags);
+ glyphDrawer.DrawVertices(context, glyphAtlas,
renderer.GetGlyphs(), anisotropic, clipBounds, transformMatrix, flags);
}
}
}
=======================================
--- /branches/lite/SlimDX.Toolkit/Fonts/Internal/GlyphAtlas.cs Sat Mar 24
18:37:53 2012
+++ /branches/lite/SlimDX.Toolkit/Fonts/Internal/GlyphAtlas.cs Sun Mar 25
20:23:55 2012
@@ -3,13 +3,14 @@
using System.Linq;
using System.Text;
using SlimDX.Direct3D11;
+using System.Drawing;

namespace SlimDX.Toolkit
{
struct GlyphBounds
{
- public float OffsetX;
- public float OffsetY;
+ public float X;
+ public float Y;
public int Width;
public int Height;
}
@@ -21,49 +22,12 @@
public int RowPitch;
public int PixelStride;
}
-
- struct GlyphCoords
- {
- public float TexCoordLeft;
- public float TexCoordTop;
- public float TexCoordRight;
- public float TexCoordBottom;
- public float PositionLeft;
- public float PositionTop;
- public float PositionRight;
- public float PositionBottom;
- }
-
- // an index into a glyph atlas, including the sheet index and the
texture index within that sheet
- struct GlyphIndex
- {
- public short SheetIndex;
- public short LocalIndex;
-
- public bool IsValid
- {
- get { return SheetIndex != -1 && LocalIndex != -1; }
- }
-
- public GlyphIndex(int value)
- {
- SheetIndex = (short)value;
- LocalIndex = (short)value;
- }
-
- public GlyphIndex(int localIndex, int sheetIndex)
- {
- SheetIndex = (short)sheetIndex;
- LocalIndex = (short)localIndex;
- }
- }

/// <summary>
/// Maintains a collection of texture atlases for the font glyphs.
/// </summary>
class GlyphAtlas : IDisposable
{
- Dictionary<GlyphIndex, GlyphCoords> coordinates = new
Dictionary<GlyphIndex, GlyphCoords>();
TextureAtlas[] glyphSheets;
int currentSheetIndex;
int sheetCount;
@@ -84,26 +48,6 @@
if (maxSheetCount > 0 && maxSheetCount < 655536)
this.maxSheetCount = maxSheetCount;
glyphSheets = new TextureAtlas[this.maxSheetCount];
-
- // create a default glyph
- unsafe
- {
- byte* glyph0 = stackalloc byte[256];
- for (int i = 0; i < 256; i++)
- glyph0[i] = 0xff;
-
- InsertGlyph(new GlyphImageData
- {
- GlyphPixels = new IntPtr(glyph0),
- RowPitch = 16,
- PixelStride = 1,
- Metrics = new GlyphBounds
- {
- Width = 16,
- Height = 16
- }
- });
- }
}

public void Dispose()
@@ -128,11 +72,6 @@
for (int i = first; i < sheetCount; i++)
glyphSheets[i].Flush(context);
}
-
- public GlyphCoords GetGlyphCoords(GlyphIndex index)
- {
- return coordinates[index];
- }

public void BindSheet(DeviceContext context, int sheetIndex)
{
@@ -140,7 +79,7 @@
glyphSheets[sheetIndex].Bind(context);
}

- public GlyphIndex InsertGlyph(GlyphImageData data)
+ public int InsertGlyph(GlyphImageData data, out RectangleF
positionOffsets, out RectangleF textureCoordinates)
{
int sheetIndex = 0;
int glyphIndex = -1;
@@ -170,23 +109,16 @@
}

if (glyphIndex == -1)
- return new GlyphIndex(-1);
-
- var result = new GlyphIndex(glyphIndex, sheetIndex);
- var coords =
glyphSheets[sheetIndex].GetCoordinates(glyphIndex);
- coordinates[result] = new GlyphCoords()
- {
- PositionLeft = data.Metrics.OffsetX,
- PositionTop = data.Metrics.OffsetY,
- PositionRight = data.Metrics.OffsetX + data.Metrics.Width,
- PositionBottom = data.Metrics.OffsetY +
data.Metrics.Height,
- TexCoordLeft = coords.Left,
- TexCoordTop = coords.Top,
- TexCoordRight = coords.Right,
- TexCoordBottom = coords.Bottom
- };
-
- return result;
+ {
+ positionOffsets = RectangleF.Empty;
+ textureCoordinates = RectangleF.Empty;
+ return -1;
+ }
+
+ textureCoordinates =
glyphSheets[sheetIndex].GetCoordinates(glyphIndex);
+ positionOffsets = new RectangleF(data.Metrics.X,
data.Metrics.Y, data.Metrics.Width, data.Metrics.Height);
+
+ return sheetIndex;
}

int InsertSheet(TextureAtlas sheet)
=======================================
--- /branches/lite/SlimDX.Toolkit/Fonts/Internal/GlyphImageRenderer.cs Sat
Mar 24 18:37:53 2012
+++ /branches/lite/SlimDX.Toolkit/Fonts/Internal/GlyphImageRenderer.cs Sun
Mar 25 20:23:55 2012
@@ -101,7 +101,7 @@

// draw the glyph
Rectangle rect;
- renderTarget.DrawGlyphRun(2.0f - data.OffsetX, 2.0f -
data.OffsetY, measuringMode, run, renderingParams, new Color4(1.0f, 1.0f,
1.0f), out rect);
+ renderTarget.DrawGlyphRun(2.0f - data.X, 2.0f - data.Y,
measuringMode, run, renderingParams, new Color4(1.0f, 1.0f, 1.0f), out
rect);

// clip to valid render target to avoid buffer overruns in
case the glyph was too large
rect.X = Math.Max(rect.X, 0);
@@ -110,8 +110,8 @@
rect.Height = Math.Min(rect.Height, maxHeight);

// return the glyph data
- data.OffsetX += rect.Left - 2.0f;
- data.OffsetY += rect.Top - 2.0f;
+ data.X += rect.Left - 2.0f;
+ data.Y += rect.Top - 2.0f;
data.Width = rect.Width;
data.Height = rect.Height;

@@ -139,8 +139,8 @@
float ah = glyphMetrics.AdvanceHeight * fscale;

var result = new GlyphBounds();
- result.OffsetX = (float)Math.Floor(l);
- result.OffsetY = (float)(Math.Floor(t) - Math.Floor(v));
+ result.X = (float)Math.Floor(l);
+ result.Y = (float)(Math.Floor(t) - Math.Floor(v));
result.Width = (int)(aw - r - l + 2.0f);
result.Height = (int)(ah - b - t + 2.0f);

=======================================
--- /branches/lite/SlimDX.Toolkit/Fonts/Internal/GlyphProvider.cs Sat Mar
24 18:37:53 2012
+++ /branches/lite/SlimDX.Toolkit/Fonts/Internal/GlyphProvider.cs Sun Mar
25 20:23:55 2012
@@ -3,10 +3,11 @@
using System.Linq;
using System.Text;
using SlimDX.DirectWrite;
+using System.Drawing;
+using System.Collections;

namespace SlimDX.Toolkit
{
- using FontKey = Tuple<FontFace, TextOptions, float>;
using ResourceKey = Tuple<Factory, int, int>;

/// <summary>
@@ -14,12 +15,109 @@
/// </summary>
class GlyphProvider : IDisposable
{
+ #region FontKey
+
+ // mutable tuple type that we can use as a key without allocating
for every glyph
+ class FontKey : IStructuralEquatable, IStructuralComparable,
IComparable
+ {
+ public FontFace FontFace;
+ public TextOptions Flags;
+ public float FontSize;
+
+ public FontKey()
+ {
+ }
+
+ public void Set(FontFace fontFace, TextOptions flags, float
fontSize)
+ {
+ FontFace = fontFace;
+ Flags = flags;
+ FontSize = fontSize;
+ }
+
+ public override bool Equals(object obj)
+ {
+ return ((IStructuralEquatable)this).Equals(obj,
EqualityComparer<object>.Default);
+ }
+
+ public override int GetHashCode()
+ {
+ return
((IStructuralEquatable)this).GetHashCode(EqualityComparer<object>.Default);
+ }
+
+ int IStructuralComparable.CompareTo(object other, IComparer
comparer)
+ {
+ if (other == null)
+ return 1;
+
+ var key = other as FontKey;
+ if (key == null)
+ throw new ArgumentException("gdiaf");
+
+ int num = 0;
+ num = comparer.Compare(FontFace, key.FontFace);
+ if (num != 0)
+ return num;
+
+ num = comparer.Compare(Flags, key.Flags);
+ if (num != 0)
+ return num;
+
+ return comparer.Compare(FontSize, key.FontSize);
+ }
+
+ bool IStructuralEquatable.Equals(object other,
IEqualityComparer comparer)
+ {
+ if (other == null)
+ return false;
+
+ var key = other as FontKey;
+ if (key == null)
+ return false;
+
+ return ((comparer.Equals(FontFace, key.FontFace) &&
comparer.Equals(Flags, key.Flags)) && comparer.Equals(FontSize,
key.FontSize));
+ }
+
+ int IStructuralEquatable.GetHashCode(IEqualityComparer
comparer)
+ {
+ return
CombineHashCodes(CombineHashCodes(comparer.GetHashCode(FontFace),
comparer.GetHashCode(Flags)), comparer.GetHashCode(FontSize));
+ }
+
+ int IComparable.CompareTo(object obj)
+ {
+ return ((IStructuralComparable)this).CompareTo(obj,
Comparer<object>.Default);
+ }
+
+ public override string ToString()
+ {
+ var sb = new StringBuilder();
+ sb.Append("(");
+ sb.Append(FontFace);
+ sb.Append(", ");
+ sb.Append(Flags);
+ sb.Append(", ");
+ sb.Append(FontSize);
+ sb.Append(")");
+ return sb.ToString();
+ }
+
+ static int CombineHashCodes(int h1, int h2)
+ {
+ return ((h1 << 5) + h1) ^ h2;
+ }
+ }
+
+ #endregion
+
+ #region GlyphMap
+
+ // keeps track of rendered glyphs for each font face
class GlyphMap : IDisposable
{
public FontFace FontFace;
public float FontSize;
public TextOptions Flags;
- public GlyphIndex[] Glyphs;
+ public Glyph[] Glyphs;

public GlyphMap(FontFace fontFace, float fontSize, TextOptions
flags)
{
@@ -28,9 +126,9 @@
Flags = flags;

int count = fontFace.GlyphCount;
- Glyphs = new GlyphIndex[count];
+ Glyphs = new Glyph[count];
for (int i = 0; i < count; i++)
- Glyphs[i] = new GlyphIndex(-1);
+ Glyphs[i] = new Glyph(-1);
}

public void Dispose()
@@ -39,13 +137,15 @@
}
}

- static SharedResourcePool<ResourceKey, GlyphImageRenderer>
sharedRenderTargets = new SharedResourcePool<ResourceKey,
GlyphImageRenderer>();
+ #endregion
+
+ static SharedResourcePool<ResourceKey, GlyphImageRenderer>
sharedRenderers = new SharedResourcePool<ResourceKey, GlyphImageRenderer>();
static SharedResourcePool<FontKey, GlyphMap> sharedFontMaps = new
SharedResourcePool<FontKey, GlyphMap>();

Dictionary<FontKey, ISharedResource<GlyphMap>> localFontMaps = new
Dictionary<FontKey, ISharedResource<GlyphMap>>();
- ISharedResource<GlyphImageRenderer> renderTargetResource;
- GlyphImageRenderer renderTarget;
+ ISharedResource<GlyphImageRenderer> renderer;
GlyphAtlas glyphAtlas;
+ FontKey key= new FontKey();

public GlyphProvider(Factory factory, GlyphAtlas glyphAtlas, int
maxGlyphWidth, int maxGlyphHeight)
{
@@ -58,16 +158,15 @@
if (maxGlyphHeight > 0 && maxGlyphHeight <= 8192)
renderTargetHeight = maxGlyphHeight;

- renderTargetResource = sharedRenderTargets.DemandCreate(new
ResourceKey(factory, renderTargetWidth, renderTargetHeight), () => new
GlyphImageRenderer(factory, renderTargetWidth, renderTargetHeight));
- renderTarget = renderTargetResource.Resource;
+ renderer = sharedRenderers.DemandCreate(new
ResourceKey(factory, renderTargetWidth, renderTargetHeight), () => new
GlyphImageRenderer(factory, renderTargetWidth, renderTargetHeight));
}

public void Dispose()
{
- if (renderTargetResource != null)
- {
- renderTargetResource.Release();
- renderTargetResource = null;
+ if (renderer != null)
+ {
+ renderer.Release();
+ renderer = null;
}

foreach (var key in localFontMaps.Values)
@@ -78,7 +177,7 @@
GlyphMap GetGlyphMapFromFont(FontFace fontFace, float fontSize,
TextOptions flags)
{
ISharedResource<GlyphMap> resource;
- var key = new FontKey(fontFace, flags & TextOptions.Aliased,
fontSize);
+ key.Set(fontFace, flags & TextOptions.Aliased, fontSize);
if (localFontMaps.TryGetValue(key, out resource))
return resource.Resource;

@@ -86,29 +185,34 @@
return null;

// when creating a new map, insert the default glyph (glyph
zero) to seed the map
- resource = sharedFontMaps.DemandCreate(key, () => { var map =
new GlyphMap(fontFace, fontSize, flags); InsertNewGlyph(map, 0, fontFace);
return map; });
- localFontMaps.Add(key, resource);
-
+ resource = sharedFontMaps.DemandCreate(key, () =>
+ {
+ var map = new GlyphMap(fontFace, fontSize, flags);
+ InsertNewGlyph(map, 0, fontFace);
+ return map;
+ });
+
+ localFontMaps.Add(key, resource);
return resource.Resource;
}

- public GlyphIndex RenderToAtlas(int index, FontFace fontFace,
float fontSize, TextOptions flags)
+ public void GetGlyph(int index, FontFace fontFace, float fontSize,
TextOptions flags, out Glyph glyph)
{
var map = GetGlyphMapFromFont(fontFace, fontSize, flags);
if (map == null || index >= map.Glyphs.Length)
- return new GlyphIndex(0);
-
- // try to look up the desired glyph in the map; if it's not
there, create it
- var atlasId = map.Glyphs[index];
- if (!atlasId.IsValid && (flags & TextOptions.NoNewGlyphs) == 0)
- InsertNewGlyph(map, index, fontFace);
-
- // fallback to the default glyph on failure
- atlasId = map.Glyphs[index];
- if (!atlasId.IsValid)
- atlasId = map.Glyphs[0];
-
- return atlasId;
+ glyph = map.Glyphs[0];
+ else
+ {
+ // try to look up the desired glyph in the map; if it's
not there, create it
+ glyph = map.Glyphs[index];
+ if (glyph.SheetIndex == -1 && (flags &
TextOptions.NoNewGlyphs) == 0)
+ InsertNewGlyph(map, index, fontFace);
+
+ // fallback to the default glyph on failure
+ glyph = map.Glyphs[index];
+ if (glyph.SheetIndex == -1)
+ glyph = map.Glyphs[0];
+ }
}

void InsertNewGlyph(GlyphMap glyphMap, int index, FontFace
fontFace)
@@ -121,8 +225,11 @@
measuringMode = MeasuringMode.GdiClassic;
}

- var data = renderTarget.DrawGlyph(fontFace, index,
glyphMap.FontSize, renderingMode, measuringMode);
- glyphMap.Glyphs[index] = glyphAtlas.InsertGlyph(data);
+ var data = renderer.Resource.DrawGlyph(fontFace, index,
glyphMap.FontSize, renderingMode, measuringMode);
+ var glyph = new Glyph();
+ glyph.SheetIndex = glyphAtlas.InsertGlyph(data, out
glyph.PositionOffsets, out glyph.TextureCoordinates);
+
+ glyphMap.Glyphs[index] = glyph;
}
}
}
=======================================
--- /branches/lite/SlimDX.Toolkit/Fonts/Internal/TextRenderer.cs Sat Mar 24
18:37:53 2012
+++ /branches/lite/SlimDX.Toolkit/Fonts/Internal/TextRenderer.cs Sun Mar 25
20:23:55 2012
@@ -5,21 +5,23 @@
using SlimDX.DirectWrite;
using System.Runtime.InteropServices;
using SlimMath;
+using System.Drawing;

namespace SlimDX.Toolkit
{
// represents a glyph (index into an atlas) rendered at a specified
position with a given color
- struct GlyphVertex
+ struct Glyph
{
public Vector2 Position;
- public GlyphIndex GlyphIndex;
+ public RectangleF PositionOffsets;
+ public RectangleF TextureCoordinates;
public int Color;
-
- public GlyphVertex(GlyphIndex index, float x, float y, int color)
- {
- Position = new Vector2(x, y);
- GlyphIndex = index;
- Color = color;
+ public int SheetIndex;
+
+ public Glyph(int sheetIndex)
+ : this()
+ {
+ SheetIndex = sheetIndex;
}
}

@@ -29,7 +31,7 @@
class TextRenderer : ITextRenderer
{
GlyphProvider glyphProvider;
- List<GlyphVertex> vertices = new List<GlyphVertex>();
+ List<Glyph> glyphs = new List<Glyph>(32);
TextOptions currentFlags;

public TextRenderer(GlyphProvider glyphProvider)
@@ -39,7 +41,7 @@

public void DrawTextLayout(TextLayout layout, float originX, float
originY, int color, TextOptions flags)
{
- vertices.Clear();
+ glyphs.Clear();

currentFlags = flags;
layout.Draw(new IntPtr(color), this, originX, originY);
@@ -58,7 +60,8 @@
// go through each glyph in the run and render it into the
atlas
for (int i = 0; i < glyphRun.GlyphCount; i++)
{
- var index =
glyphProvider.RenderToAtlas(glyphRun.GlyphIndices[i], glyphRun.FontFace,
glyphRun.FontSize, currentFlags);
+ Glyph glyph;
+ glyphProvider.GetGlyph(glyphRun.GlyphIndices[i],
glyphRun.FontFace, glyphRun.FontSize, currentFlags, out glyph);

// check if we should draw the vertex or if we just want
to cache the glyphs
if ((currentFlags & TextOptions.CacheOnly) == 0)
@@ -66,7 +69,9 @@
if ((glyphRun.BidiLevel & 0x1) != 0)
x -= glyphRun.GlyphAdvances[i];

- vertices.Add(new GlyphVertex(index, x, y, color));
+ glyph.Position = new Vector2(x, y);
+ glyph.Color = color;
+ glyphs.Add(glyph);

if ((glyphRun.BidiLevel & 0x1) == 0)
x += glyphRun.GlyphAdvances[i];
@@ -76,11 +81,11 @@
return ResultCode.Success;
}

- public IList<GlyphVertex> SortVertices()
+ public IList<Glyph> GetGlyphs()
{
// group vertices by the sheet they're in
- vertices.Sort((x, y) =>
x.GlyphIndex.SheetIndex.CompareTo(y.GlyphIndex.SheetIndex));
- return vertices;
+ glyphs.Sort((x, y) => x.SheetIndex.CompareTo(y.SheetIndex));
+ return glyphs;
}

#region Default Interface Implementation
=======================================
--- /branches/lite/SlimDX.Toolkit/Fonts/Internal/VertexDrawer.cs Sat Mar 24
20:12:36 2012
+++ /branches/lite/SlimDX.Toolkit/Fonts/Internal/VertexDrawer.cs Sun Mar 25
20:23:55 2012
@@ -93,7 +93,7 @@
renderData = null;
}

- public unsafe void DrawVertices(DeviceContext context, GlyphAtlas
glyphAtlas, IList<GlyphVertex> vertexData, bool anisotropic, RectangleF*
clipBounds, Matrix* transformMatrix, TextOptions flags)
+ public unsafe void DrawVertices(DeviceContext context, GlyphAtlas
glyphAtlas, IList<Glyph> glyphs, bool anisotropic, RectangleF* clipBounds,
Matrix* transformMatrix, TextOptions flags)
{
// set states and shaders
if ((flags & TextOptions.StatePrepared) == 0)
@@ -114,9 +114,9 @@
maxVertexCount -= (maxVertexCount % 4);

int current = 0;
- int total = vertexData.Count;
-
- // draw every vertex as a 2-tri quad
+ int total = glyphs.Count;
+
+ // draw every glyph as a 2-tri quad
while (current < total)
{
var data = context.MapSubresource(vertexBuffer,
MapMode.WriteDiscard, MapFlags.None).Data;
@@ -125,25 +125,23 @@
int count = Math.Min(total - current, maxVertexCount / 4);
for (int i = 0; i < count; i++)
{
- var vertex = vertexData[current + i];
- var coords =
glyphAtlas.GetGlyphCoords(vertex.GlyphIndex);
-
+ var glyph = glyphs[current + i];
var output = new QuadVertex();
- output.Color = vertex.Color;
- output.Position = vertex.Position + new
Vector2(coords.PositionLeft, coords.PositionTop);
- output.TexCoords = new Vector2(coords.TexCoordLeft,
coords.TexCoordTop);
+ output.Color = glyph.Color;
+ output.Position = glyph.Position + new
Vector2(glyph.PositionOffsets.Left, glyph.PositionOffsets.Top);
+ output.TexCoords = new
Vector2(glyph.TextureCoordinates.Left, glyph.TextureCoordinates.Top);
data.Write(output);

- output.Position.X = vertex.Position.X +
coords.PositionRight;
- output.TexCoords.X = coords.TexCoordRight;
+ output.Position.X = glyph.Position.X +
glyph.PositionOffsets.Right;
+ output.TexCoords.X = glyph.TextureCoordinates.Right;
data.Write(output);

- output.Position.Y = vertex.Position.Y +
coords.PositionBottom;
- output.TexCoords.Y = coords.TexCoordBottom;
+ output.Position.Y = glyph.Position.Y +
glyph.PositionOffsets.Bottom;
+ output.TexCoords.Y = glyph.TextureCoordinates.Bottom;
data.Write(output);

- output.Position.X = vertex.Position.X +
coords.PositionLeft;
- output.TexCoords.X = coords.TexCoordLeft;
+ output.Position.X = glyph.Position.X +
glyph.PositionOffsets.Left;
+ output.TexCoords.X = glyph.TextureCoordinates.Left;
data.Write(output);
}

@@ -156,7 +154,7 @@

for (int i = 0; i < count; i++)
{
- int sheet = vertexData[current +
i].GlyphIndex.SheetIndex;
+ int sheet = glyphs[current + i].SheetIndex;
if (sheet != currentSheet)
{
if (sheetCount != 0)

Reply all
Reply to author
Forward
0 new messages