MantisBT - Community
View Issue Details
0023457Community[OCCT] OCCT:Visualizationpublic2012-10-02 14:482019-04-20 15:45
Pawel 
kgv 
normalminor 
closedfixed 
WindowsVC++ 200832 bit
[OCCT] 6.5.3 
[OCCT] 6.6.0[OCCT] 6.6.0 
Not needed
0023457: Slow text rendering
This issue was discussed in: http://dev.opencascade.org/index.php?q=node/63 [^]

Here the summary:

- One more question: I have noticed that displaying lots of texts (Graphic3d_AspectText3d) slows the the view navigation a lot. I started investigating the issue and observed that is not the case for the OCCT 5.2 (haven't tried all the releases in between, only some). Would you know what the reason might be?

- We have not analyzed this point in depth yet, though we suspect FTGL of doing some non-optimal things during rendering. By the way, OCCT 5.x did not use FTGL.

Another problem that arises when the number of text labels drawn using Graphic3d_Group::Text() method becomes large is described in http://tracker.dev.opencascade.org/view.php?id=23069, [^] note that the part related to text rendering will not be corrected in OCCT 6.5.3 release.

There is an intention to put some efforts to improve text rendering in the future OCCT releases. There is already a Mantis issue where the discussion has been started: http://tracker.dev.opencascade.org/view.php?id=23049 [^]

=========================================================================
NOTE: As an important consequence of this issue implementation, OCCT will no longer use FTGL library.
=========================================================================
No tags attached.
related to 0023049closed bugmaster Open CASCADE Optimize packaging and dependencies of visualization libraries 
related to 0023069closed kgv Open CASCADE OpenGL state extraction for GL_RENDER_MODE significantly impact performance 
parent of 0028915closed kgv Open CASCADE Configuration, Font_BRepFont - do not include FreeType headers within OCCT headers 
related to 0023519closed bugmaster Community Mixing wireframe and shaded visualization impacts performance 
related to 0023747closed san Open CASCADE Enabling environment mapping breaks text rendering 
related to 0023756closed san Community VBO rendering problem (1) 
related to 0023758closed ibs Open CASCADE Removing support of FTGL product amd FontMFT from WOK 
Issue History
2012-10-02 14:48PawelNew Issue
2012-10-02 14:48PawelAssigned To => bugmaster
2012-10-02 14:49PawelRelationship addedrelated to 0023049
2012-10-02 14:58PawelRelationship addedrelated to 0023069
2012-10-02 15:12kgvAssigned Tobugmaster => kgv
2012-10-02 15:12kgvTarget Version => 6.6.0
2012-11-07 15:38PawelRelationship addedrelated to 0023519
2013-02-04 11:00kgvNote Added: 0023246
2013-02-04 11:00kgvAssigned Tokgv => san
2013-02-04 11:00kgvStatusnew => resolved
2013-02-05 15:08aplNote Added: 0023262
2013-02-06 12:47sanNote Added: 0023270
2013-02-06 12:47sanAssigned Tosan => bugmaster
2013-02-06 12:47sanStatusresolved => reviewed
2013-02-07 11:56kgvNote Added: 0023274
2013-02-07 14:40aplNote Added: 0023276
2013-02-08 13:02mkvNote Added: 0023289
2013-02-08 13:03mkvTest case number => Not needed
2013-02-08 13:03mkvStatusreviewed => tested
2013-02-08 13:53kgvNote Added: 0023290
2013-02-08 15:01sanRelationship addedrelated to 0023747
2013-02-08 15:06sanDescription Updatedbug_revision_view_page.php?rev_id=4954#r4954
2013-02-11 17:42kgvChangeset attached => occt master a174a3c5
2013-02-11 17:42kgvAssigned Tobugmaster => kgv
2013-02-11 17:42kgvStatustested => verified
2013-02-11 17:42kgvResolutionopen => fixed
2013-02-11 20:53PawelNote Added: 0023303
2013-02-12 20:28PawelRelationship addedrelated to 0023756
2013-02-15 00:16kgvRelationship addedrelated to 0023758
2013-03-20 12:38abvRelationship addedparent of 0023842
2013-03-21 08:29kgvRelationship deletedparent of 0023842
2013-04-23 13:35aivStatusverified => closed
2013-04-29 15:24aivFixed in Version => 6.6.0
2013-06-09 20:54sanRelationship addedrelated to 0022484
2013-06-09 20:59sanRelationship deletedrelated to 0022484
2017-07-17 11:30kgvRelationship addedparent of 0028915
2019-04-20 15:45kgvRelationship addedparent of 0030663

Notes
(0023246)
kgv   
2013-02-04 11:00   
Dear san,
patch is ready for review in CR23457_1 branch.
(0023262)
apl   
2013-02-05 15:08   
Dear kgv!

I have several remarks on the solution:

------------------------------------------------------------------------------
First of all, there is a bug:

Trihedron text color gets lost after drawing any colored text string (drawexe).
The scenario is the following:
>> vinit
>> vdrawtext to print red text
>> vtrihedron --> trihedron's labels are red

-------------------------------------------------------------------------------
Minor remarks:

1) OpenGl_TextFormatter::Append
  
  {
    myAscender = Max (myAscender, theFont.Ascender());
    myLineSpacing = Max (myLineSpacing, theFont.LineSpacing());

    if (theString.IsEmpty())
    {
      return;
    }

The ascender and linespacing values shouldn't change if null string passed, so the first two lines should be located below the return statement.
* Already committed to branch.

2) OpenGl_Display.hxx

class Handle(OpenGl_PrinterContext); - unnecessary forward declaration removed
* Already committed to branch.

3) Font_FTFont.hxx/.cxx

Magic number of multiplication (division) on 64 of point size values is implemented as protected inline methods toFTPoints (fromFTPoints) to underline semantic of these operations - conversion to 26.6 fixed-point format used by parts of FT API.
* Already committed to branch.

4) Font_FTFont::Init

In case of return, the method doesn't clean-up myFontPath, myPointSize values. In contrast with the further implementation of the method it seems strange (Release() there does the stuff).

  {
    Release();
    myFontPath = theFontPath;
    myPointSize = thePointSize;
    if (!myFTLib->isValid())
    {
      std::cerr << "FreeType library is unavailable!\n";
      return false;
    }

    if (FT_New_Face (myFTLib->getInstance(), myFontPath.ToCString(), 0, &myFTFace) != 0)
    {
      //std::cerr << "Font '" << myFontPath << "' fail to load!\n";
      Release();
      return false;
    }

5) OpenGl_Text::StringSize

The logic of this method is not purely used anywhere in OCC, but:
This method introduces its own size calculation logic that differs from the one implemented in Render method (Render method delegates this function to OpenGl_TextFormatter instance). Moreover, it is uses hard-coded 8 pixel offset to represent tabulation (assuming that it is the default value of OpenGl_TextFormatter class).

    else if (aCharThis == '\t')
    {
      aWidth += aFont->AdvanceX (' ', aCharNext) * 8.0f;
      continue;
    }

6) OpenGl_Context::ReleaseDelayed

The code of resource delay cleanup implementation is confusing. ++anIter.ChangeValue() <= 2 increases cleanup request iteration counter and checks for hard-coded value of 2 (two iterations). There are no comments that give straight definitions of what is done there. I think the delayed clean-up code could be refactored for better readability.

  NCollection_Vector<TCollection_AsciiString> aDeadList;
  for (NCollection_DataMap<TCollection_AsciiString, Standard_Integer>::Iterator anIter (*myDelayed);
       anIter.More(); anIter.Next())
  {
    if (++anIter.ChangeValue() <= 2)
    {
      continue; // postpone release one more frame to ensure noone use it periodically
    }

7) Font_FTLibrary.hxx

Lowercase naming of public methods: isValid(), getInstance().

8) All found remarks on comments and misprints are already commited into branch.
(0023270)
san   
2013-02-06 12:47   
Branch CR23457_2 reviewed without remarks, ready for testing.
(0023274)
kgv   
2013-02-07 11:56   
Dear Bugmaster,

a hot fix for regression was pushed into CR23457_2 branch.
Wrong depth-value computed for printed text.

Dear apl, thanks for your remarks.
> Trihedron text color gets lost after drawing any colored text string.
> The scenario is the following:
>> vdrawtext "My Red Text" 0 0 0 255 0 0 0 0 0 0 12 0
>> vtrihedron t
this is not a regression. Please consider registering of new bug if needed.
(0023276)
apl   
2013-02-07 14:40   
Dear kgv,

Separate bug record 0023745 added for the thrihedron label colors.
(0023289)
mkv   
2013-02-08 13:02   
Dear BugMaster,

Branch CR234457_2 (and products from GIT master) was compiled on Linux and Windows platforms and tested.
SHA-1: b2bfb5e0224111b4a0672724ceb3f3f0bcf41423

Number of compiler warnings:

occt component :
Linux: 3 (3 on master)
Windows: 39 (39 on master)

products component :
Linux: 9 (9 on master)
Windows: 50 (50 on master)

Regressions:
No regressions

Improvements:
No improvements

Testing cases:
Not needed

Tests chl/941/A3,B2,B3,B5 was correted afther pushing this fix to master (length of exported files).

Testing on Linux:
Total MEMORY difference: 237292236 / 238777776
Total CPU difference: 8703.330000000147 / 10074.61999999991

Testing on Windows:
Total MEMORY difference: 338989052 / 339706676
Total CPU difference: 12605.15625 / 12682.375

There are not serious differences in images found by testdiff.
(0023290)
kgv   
2013-02-08 13:53   
Just for information. New test cases were added to 3rdparty/fonts grid: A3 and A4 intended to estimate font rendering performance.

Tests were performed on following configuration:
Windows 7 SP1 x86_64 / 8 GiB RAM / Radeon HD 6450

Test case 3rdparty/fonts/A3 performs rendering of one huge static text label.
FPS: 18.93 / 206.13 (before the patch / after the patch)
CPU: 53.04 / 4.21 msec

Test case 3rdparty/fonts/A4 displays a lot of small static text labels.
FPS: 11.16 / 40.99 (before the patch / after the patch)
CPU: 90.01 / 24.33 msec

So text presentation caching may benefit up to 10x boost in some cases based on lower CPU load.
(0023303)
Pawel   
2013-02-11 20:53   
Thank you for solving this issue!

At the moment I can say navigation (rotation/panning etc.) in a view with a lot of texts got faster.

Unfortunately, I can observe crashes in the graphics driver. As it looks reproducible, I will provide more details as soon as possible.

Pawel