Anti-aliasing problem

san's picture

Problem context

This topic was extracted from OCCT Mantis issue 24324 to involve wider audience into the discussion.

Enabling anti-aliasing with help of V3d_View::SetAntialiasingOn() call for a scene containing shaded polygons often results in problems illustrated by the snapshot below:

Depth test errors on triangles edges after glEnable(GL_POLYGON_SMOOTH) call
(NVIDIA GeForce 640M LE, driver version 320.57, Windows 7 64-bit)

To reproduce the problem using DRAW test harness, the following command sequence can be executed:

pload ALL
psphere b 10
vdisplay b
vsetdispmode b 1
vantialiasing 1
vsetgradientbg 64 192 255 255 255 255 2

Gradient background is used to illustrate the nature of the "triangle edges" clearly (depth test errors).

This effect is typical for NVIDIA graphic cards, while it might not be reproduced e.g. with Intel graphics.

Up to OCCT 6.7.0, anti-aliasing is implemented in a very simple way (see OpenGl_View::RenderStructs() method):

if( antiAliasingMode & 2 ) glEnable(GL_POLYGON_SMOOTH);
glEnable (GL_BLEND);

Thus the problem seems be an old issue with GL_POLYGON_SMOOTH which results in depth test errors on polygon boundaries and thus is not the recommended anti-aliasing method nowadays.

After all, the old-style OpenGL smoothing is not hardware-accelerated and thus impacts the frame rate negatively.


With OCCT releases up to 6.7.0 it is not possible to enable or disable anti-aliasing selectively for different types of geometry from the application code using OCCT API.

However, there is a workaround. Adding the following line to the Windows application's environment resolves the problem:


As the result, GL_POLYGON_SMOOTH is not enabled when V3d_View::SetAntialiasingOn() is called.

Potential improvements

Both the current way to enable/disable anti-aliasing and the current implementation of anti-aliasing definitely could be improved, though this is rather a low-priority task for the OCCT development team:

  1. The most logical way to control anti-aliasing would be to move the anti-aliasing flag from V3d_View (the global switch) to Graphic3d_Aspect* classes, so as to enable/disable anti-aliasing selectively for given type of primitives and within the given Graphic3d_Group instance(s) only and thus to have full control over the visual result and rendering performance. At this step, we can keep GL_*_SMOOTH as anti-aliasing method.
  2. As the second step, something smarter and faster than just enabling GL_*_SMOOTH could be used.
    E.g. setting up multi-sampling could be tried: [^]
    This would require some extra platform-specific work at 3D view initialization stage.
    Alternatively, shader programs supported since OCCT 6.7.0 could be considered as a tool for anti-aliasing, though choosing a suitable algorithm might not be an easy task.

Thus if some of you have time for the above-mentioned experiments, your contribution would be appreciated a lot!

Copyright 2011-2019
Contact us