jingwood / d2dlib

A .NET library for hardware-accelerated, high performance, immediate mode rendering via Direct2D.
MIT License
234 stars 40 forks source link

Text Performance #36

Open Unreal852 opened 3 years ago

Unreal852 commented 3 years ago

Hello, i noticed that Text rendering is fairly slow. I found a work-around by creating bitmap and rendering the text on it once and then rendering the bitmap. This is working but maybe there is another way to have better text rendering performance ? To be more clear, i'm creating a Node-Based graph and so each nodes may need to have 1 or more text, and this clearly degrade performance when more and more nodes are added.

jingwood commented 3 years ago

@Unreal852 Thanks for the feedback. How many nodes (texts) to be rendered in one frame in your scene? about 100 ~ 1000?

The text rendering is a more expensive operation comparing to other geometry renderings. And current API doesn't support doing something optimization like cache font and text resource, that could be the first thing to do to improve the performance. I will try something.

gilsonwang commented 3 years ago

Maybe you can passing the Brush and TextFormat to DrawString() in Text.cpp. It will get a little bit improve. I try to render 2900 texts on a 2k screen and it will be about 23FPS. After rewrite the DrawString function in Text.cpp, it will be 30FPS.

Unreal852 commented 3 years ago

@jingwood Each node have a title, so there is a minimum of 2 nodes ( entry node and exit node ) but between them there can be 0 or 10, 100, etc, it is up to the user. I already wrote a Node system with winform GDI+ but the performance is not that good that why i'm looking to rewrite it with anoter renderer. I was thinking about OpenTK (GL) but it is way too overkill for what i'm doing. Here is a example of what i want to do Unity Shader Graph

jingwood commented 3 years ago

Added a performance test for text rendering https://github.com/jingwood/d2dlib/commit/fd011886399e2c36e32f94bb6935e04c55309d82