Jump to content
  • Advertisement
Sign in to follow this  
Telanor

Custom text renderer performance

This topic is 2106 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to implement text outlines in direct2d using a custom text renderer. The problem is the performance hit from merely calling GetGlyphRunOutline is beyond absurd. Forget about drawing, just calling that function for a dozen or so TextLayouts costs about 30ms. It only takes about 0.02ms to render those same TextLayouts using the standard DrawTextLayout call. All the examples I've seen call it every time DrawGlyphRun is called.

I tried to cache the resulting PathGeometry but Direct2D seems to create a new GlyphRun object every time TextLayout.Draw is called and I don't see any other parameters that I could use as an identifier. Although even if that worked, it would be useless for dynamic text. How are we supposed to have any remotely-decent render times with a custom text renderer?

Share this post


Link to post
Share on other sites
Advertisement

That's scary!

Personally, I do my trisoups for text starting from uniscribe data. Quality is really rock-bottom but since I've switched to a faster triangulator, it has become pretty instant operation. Maybe you could try an hybrid approach with uniscribe as well?

Share this post


Link to post
Share on other sites
I've never heard of uniscribe before but from googling it seems to be the predecessor to direct2d/directwrite? It seems like a pretty complicated API and I'm using c# which would just complicate using it even more... I don't know if it would be worth all the hassle just to get text outlines.

I'd like to stick with direct2d since it gives me such wonderful high quality text, but its pretty limiting if I can't do any custom style rendering because of that 1 function call.

Share this post


Link to post
Share on other sites
I guess from the lack of responses, no one's really used Direct2D much? It's strange how the DrawTextLayout function has really good performance, but then as soon as you implement your own version of it, performance goes right down the drain. Surely the library needs to go through the same steps to generate the glyph run outlines to do the standard rendering, right? I don't get how it can render text fast on its own but then provide us with a vital function that is slow as molasses.

Share this post


Link to post
Share on other sites

Typically you render the text once to a texture and render just that, only updating it if its text changes.

 

 

L. Spiro

Share this post


Link to post
Share on other sites

Yeah, GetGlyphOutline and its ilk should be used to render a font to a bitmap at a specified size for all the sizes you want to use just once and then rendered from that bitmap. If you want polygonal fonts that can be scaled and rotated and transformed up the wazoo use poly models instead.

Share this post


Link to post
Share on other sites
The problem with that is that I have no way of knowing when to update the texture, since a Direct2D TextLayout is a mutable object. You can change things like the font size or font family, or even more trivially, the layout area width/height. The only thing you can't change is the actual text. Not to mention it will also force Direct2D to use gray-scale subpixel AA instead of cleartype, since it would be rendering on a transparent texture.

Share this post


Link to post
Share on other sites

The problem with that is that I have no way of knowing when to update the texture, since a Direct2D TextLayout is a mutable object. You can change things like the font size or font family, or even more trivially, the layout area width/height. The only thing you can't change is the actual text. Not to mention it will also force Direct2D to use gray-scale subpixel AA instead of cleartype, since it would be rendering on a transparent texture.

I’m not seeing the problem here.

A “text object” has the actual texture with the text in it as well as a record of what font size, family, layout areas, etc. was last used to create the texture.

When any of these properties change it is time to update the texture.  You can perform the test for any changed properties prior to rendering.

Why is this a problem?

 

 

L. Spiro

Edited by L. Spiro

Share this post


Link to post
Share on other sites
Its a problem because the Direct2D TextLayout isn't just a uniform blob of text. You can have the first 2 letters be size 18, the next 2 be size 20, have every even character in arial and every odd character in times new roman. All within a single TextLayout.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!