SoPolygonOffset(3) The SoPolygonOffset class is a node type for 'layering' rendering primitives.

SYNOPSIS


#include <Inventor/nodes/SoPolygonOffset.h>

Inherits SoNode.

Public Types


enum Style { FILLED = SoPolygonOffsetElement::FILLED, LINES = SoPolygonOffsetElement::LINES, POINTS = SoPolygonOffsetElement::POINTS }

Public Member Functions


virtual SoType getTypeId (void) const

SoPolygonOffset (void)

virtual void doAction (SoAction *action)

virtual void callback (SoCallbackAction *action)

virtual void GLRender (SoGLRenderAction *action)

Static Public Member Functions


static SoType getClassTypeId (void)

static void initClass (void)

Public Attributes


SoSFFloat factor

SoSFFloat units

SoSFBitMask styles

SoSFBool on

Protected Member Functions


virtual const SoFieldData * getFieldData (void) const

virtual ~SoPolygonOffset ()

Static Protected Member Functions


static const SoFieldData ** getFieldDataPtr (void)

Additional Inherited Members

Detailed Description

The SoPolygonOffset class is a node type for 'layering' rendering primitives.

A common problem with realtime 3D rendering systems is that rendered primitives which are at approximately the same depth with regard to the camera viewpoint will appear to flicker. I.e.: from one angle one primitive will appear to be closer, while at another angle, another primitive will appear closer. When this happens, the rendered graphics at that part of the scene will of course look a lot less visually pleasing.

One common situation where this problem often occurs is when you attempt to put a wireframe grid as an outline on top of filled polygons.

The cause of the problem described above is that the Z-buffer of any render system has a limited resolution, often at 16, 24 or 32 bits. Because of this, primitives which are close will sometimes get the same depth value in the Z-buffer, even though they are not actually at the same depth-coordinate.

To rectify the flickering problem, this node can be inserted in the scene graph at the proper place(s) to explicitly define how polygons, lines and/or points should be offset with regard to other primitives.

As for the details of how the SoPolygonOffset::factor and SoPolygonOffset::units should be set, we quote the OpenGL documentation:

      The value of the offset is
          factor * DZ + r * units
      where DZ is a measurement of the change in depth relative to the
      screen area of the polygon, and r is the smallest value that is
      guaranteed to produce a resolvable offset for a given
      implementation. The offset is added before the depth test is
      performed and before the value is written into the depth buffer..fi
One word of notice with regard to the above quote from the OpenGL documentation: it doesn't really make sense to set 'factor' and 'units' to values with different signs, i.e. 'factor' to a negative value and 'units' to a positive value, or vice versa.
The pixels would then be 'pushed back' in z-order by one part of the equation, but at the same time be 'pushed forward' by the other part of the equation. This would most likely give very inconsistent results, but which may at first look ok.
We mention this potential for making a mistake, as it seems to be a quite common error.
Below is a simple, correct usage example:
  #Inventor V2.1 ascii
  
  Separator {
     Coordinate3 { point [ -1 -1 0, 1 -1 0, 1 1 0, -1 1 0 ] }
     
     Separator {
        BaseColor { rgb 1 1 0 }
        # needs to draw polygons-as-line, and not "real" lines -- see
        # documentation below on why this is so:
        DrawStyle { style LINES }
        # draw two triangles, to get a line crossing the face of the
        # polygon:
        IndexedFaceSet { coordIndex [ 0, 1, 2, -1, 0, 2, 3 -1 ] }
     }
     
     PolygonOffset {
        styles FILLED
        factor 1.0
        units 1.0
     }
     
     BaseColor { rgb 0 0.5 0 }
     FaceSet { numVertices [ 4 ] }
  }.fi
Without the polygonoffset node in the above example, the lines may look irregularly stippled with some graphics card drivers, as parts of it will show through the faceset, others not. This happen on seemingly random parts, as the z-buffer floating point calculations will be fickle with regard to whether or not the polygon or the line will be closer to the camera.
See the API documentation of the SoPolygonOffset::styles field below for a discussion of one important limitation of OpenGL's Z-buffer offset mechanism: it only works with polygons or polygons rendered in line or point mode, using the SoDrawStyle::style field.
FILE FORMAT/DEFAULTS: 
    PolygonOffset {
        factor 1
        units 1
        styles FILLED
        on TRUE
    }

Since:

TGS Inventor 2.5

Coin 1.0

Member Enumeration Documentation

enum SoPolygonOffset::Style

Enumeration of the rendering primitives which can be influenced by an SoPolygonOffset node.

Constructor & Destructor Documentation

SoPolygonOffset::SoPolygonOffset (void)

Constructor.

SoPolygonOffset::~SoPolygonOffset () [protected], [virtual]

Destructor.

Member Function Documentation

SoType SoPolygonOffset::getClassTypeId (void) [static]

This static method returns the SoType object associated with objects of this class.

Reimplemented from SoNode.

SoType SoPolygonOffset::getTypeId (void) const [virtual]

Returns the type identification of an object derived from a class inheriting SoBase. This is used for run-time type checking and 'downward' casting.

Usage example:

  void foo(SoNode * node)
  {
    if (node->getTypeId() == SoFile::getClassTypeId()) {
      SoFile * filenode = (SoFile *)node;  // safe downward cast, knows the type
    }
  }

For application programmers wanting to extend the library with new nodes, engines, nodekits, draggers or others: this method needs to be overridden in all subclasses. This is typically done as part of setting up the full type system for extension classes, which is usually accomplished by using the pre-defined macros available through for instance Inventor/nodes/SoSubNode.h (SO_NODE_INIT_CLASS and SO_NODE_CONSTRUCTOR for node classes), Inventor/engines/SoSubEngine.h (for engine classes) and so on.

For more information on writing Coin extensions, see the class documentation of the toplevel superclasses for the various class groups.

Implements SoBase.

const SoFieldData ** SoPolygonOffset::getFieldDataPtr (void) [static], [protected]

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Reimplemented from SoNode.

const SoFieldData * SoPolygonOffset::getFieldData (void) const [protected], [virtual]

Returns a pointer to the class-wide field data storage object for this instance. If no fields are present, returns NULL.

Reimplemented from SoFieldContainer.

void SoPolygonOffset::initClass (void) [static]

Sets up initialization for data common to all instances of this class, like submitting necessary information to the Coin type system.

Reimplemented from SoNode.

void SoPolygonOffset::doAction (SoAction *action) [virtual]

This function performs the typical operation of a node for any action.

Reimplemented from SoNode.

void SoPolygonOffset::callback (SoCallbackAction *action) [virtual]

Action method for SoCallbackAction.

Simply updates the state according to how the node behaves for the render action, so the application programmer can use the SoCallbackAction for extracting information about the scene graph.

Reimplemented from SoNode.

void SoPolygonOffset::GLRender (SoGLRenderAction *action) [virtual]

Action method for the SoGLRenderAction.

This is called during rendering traversals. Nodes influencing the rendering state in any way or who wants to throw geometry primitives at OpenGL overrides this method.

Reimplemented from SoNode.

Member Data Documentation

SoSFFloat SoPolygonOffset::factor

Offset multiplication factor. Scales the variable depth in the z-buffer of the rendered primitives.

See SoPolygonOffset's main class documentation above for detailed information on how the factor value is used.

Default value is 1.0.

SoSFFloat SoPolygonOffset::units

Offset translation multiplication factor. Will be multiplied with the value which represents the smallest discrete step that can be distinguished with the underlying Z-buffer resolution.

See SoPolygonOffset's main class documentation above for detailed information on how the units value is used.

Note that positive values will push geometry 'away' into the Z-buffer, while negative values will 'move' geometry closer.

Default value is 1.0.

SoSFBitMask SoPolygonOffset::styles

The rendering primitive type to be influenced by this node. This is a bitmask variable, so you can select several primitive types (out of filled polygons, lines and points) be influenced by the offset at the same time.

There is one very important OpenGL limitation to know about in this regard: Z-buffer offsetting can only be done for either polygons, or for polygons rendered as lines or as points.

So attempts at using this node to offset e.g. SoLineSet / SoIndexedLineSet or SoPointSet primitives will not work.

See the comments in the scene graph below for a detailed example on what SoPolygonOffset can and can not do:

  #Inventor V2.1 ascii
  
  Separator {
     # render polygon:
  
     Coordinate3 { point [ -1.1 -1.1 0, 1.1 -1.1 0, 1.1 1.1 0, -1.1 1.1 0 ] }
     BaseColor { rgb 0 0.5 0 }
     FaceSet { numVertices [ 4 ] }
  
     # offset polygon-as-lines to be in front of above polygon:
  
     PolygonOffset {
        styles LINES
        factor -2.0
        units 1.0
     }
     
     # render lines:
  
     Coordinate3 { point [ -1 -1 0, 1 -1 0, 1 1 0, -1 1 0 ] }
     BaseColor { rgb 1 1 0 }
  
     Switch {
        # change this to '0' to see how glPolygonOffset() does *not* work
        # with 'true' lines
        whichChild 1
  
        DEF child0 Group {
           # can *not* be offset
           IndexedLineSet { coordIndex [ 0, 1, 2, 3, 0, 2, -1, 1, 3 -1 ]
           }
        }
  
        DEF child1 Group {
           # will be offset
           DrawStyle { style LINES }
           FaceSet { numVertices [ 4 ] }
        }
     }
  }

Field default value is SoPolygonOffset::FILLED.

SoSFBool SoPolygonOffset::on

Whether the offset is on or off. Default is for SoPolygonOffset::on to be TRUE.

Author

Generated automatically by Doxygen for Coin from the source code.