Coin
4.0.3
Coin3D core library
|
The SoGLRenderAction class renders the scene graph with OpenGL calls. More...
#include <Inventor/actions/SoGLRenderAction.h>
Public Types | |
enum | AbortCode { CONTINUE , ABORT , PRUNE , DELAY } |
typedef AbortCode | SoGLRenderAbortCB(void *userdata) |
enum | SortedObjectOrderStrategy { BBOX_CENTER , BBOX_CLOSEST_CORNER , BBOX_FARTHEST_CORNER , CUSTOM_CALLBACK } |
enum | TransparencyType { SCREEN_DOOR , ADD , DELAYED_ADD , SORTED_OBJECT_ADD , BLEND , DELAYED_BLEND , SORTED_OBJECT_BLEND , SORTED_OBJECT_SORTED_TRIANGLE_ADD , SORTED_OBJECT_SORTED_TRIANGLE_BLEND , NONE , SORTED_LAYERS_BLEND } |
enum | TransparentDelayedObjectRenderType { ONE_PASS , NONSOLID_SEPARATE_BACKFACE_PASS } |
Public Types inherited from SoAction | |
enum | AppliedCode { NODE = 0 , PATH = 1 , PATH_LIST = 2 } |
enum | PathCode { NO_PATH = 0 , IN_PATH = 1 , BELOW_PATH = 2 , OFF_PATH = 3 } |
Static Public Member Functions | |
static void | addMethod (const SoType type, SoActionMethod method) |
static void | enableElement (const SoType type, const int stackindex) |
static SoType | getClassTypeId (void) |
static void | initClass (void) |
Static Public Member Functions inherited from SoAction | |
static SoType | getClassTypeId (void) |
static void | initClass (void) |
static void | initClasses (void) |
static void | nullAction (SoAction *action, SoNode *node) |
Protected Member Functions | |
virtual void | beginTraversal (SoNode *node) |
virtual void | endTraversal (SoNode *node) |
virtual const SoEnabledElementsList & | getEnabledElements (void) const |
Protected Member Functions inherited from SoAction | |
SoAction (void) | |
void | setTerminated (const SbBool flag) |
virtual SbBool | shouldCompactPathList (void) const |
Static Protected Member Functions | |
static SoActionMethodList * | getClassActionMethods (void) |
static SoEnabledElementsList * | getClassEnabledElements (void) |
Static Protected Member Functions inherited from SoAction | |
static SoActionMethodList * | getClassActionMethods (void) |
static SoEnabledElementsList * | getClassEnabledElements (void) |
Additional Inherited Members | |
Protected Attributes inherited from SoAction | |
SoState * | state |
SoActionMethodList * | traversalMethods |
The SoGLRenderAction class renders the scene graph with OpenGL calls.
Applying this method at a root node for a scene graph, path or path list will render all geometry contained within that instance to the current OpenGL context.
typedef SoGLRenderAction::SoGLRenderAbortCB |
Abort callbacks should be of this type.
The return codes which an SoGLRenderAbortCB callback function should use.
Used for enumerating the different transparency sorting strategies.
Enumerator | |
---|---|
BBOX_CENTER | Do the sorting based on the center of the object bounding box.
|
BBOX_CLOSEST_CORNER | Do the sorting based on the bounding box corner closest to the camera.
|
BBOX_FARTHEST_CORNER | Do the sorting based on the bounding box corner farthest from the camera.
|
CUSTOM_CALLBACK | Use a custom callback to determine the sorting order.
|
Various settings for how to do rendering of transparent objects in the scene. Some of the settings will provide faster rendering, while others give you better quality rendering.
Note that doing correct rendering of multiple transparent objects often fails, because to be 100% correct, all polygons needs to be rendered in sorted order, and polygons can't intersect each other. In a dynamic scene graph it is often impossible to guarantee that no polygons intersect, and finding an algorithm that does correct sorting of polygons for all possible cases is very hard and time-consuming.
The highest quality transparency mode in the original SGI / TGS Open Inventor is SoGLRenderAction::SORTED_OBJECT_BLEND, where all transparent objects are rendered in sorted order in a rendering pass after all opaque objects. However, this mode does not sort the polygons, and if you have an object where some polygon A is behind some other polygon B, the transparency will only be correct if A happens to be rendered before B. For other camera angles, where B is behind A, the transparency will not be correct.
In Coin we have a new transparency mode that solves some of these problems: SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND. In addition to sorting the objects, all polygons inside each object is also sorted back-to-front when rendering. But, if you have intersecting objects and/or intersecting polygons, even this transparency mode will fail. Also, because of the polygon sorting, this transparency mode is quite slow. It is possible to speed things up using the SoTransparencyType node, though, which enables you to set different transparency modes for different parts of the scene graph. If you have only have a few objects where you need to sort the polygons, you can use SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND for those, and for instance SoGLRenderAction::SORTED_OBJECT_BLEND for all other transparent objects.
The highest quality transparency mode in Coin is SoGLRenderAction::SORTED_LAYERS_BLEND. It is also the only mode that overrides all other modes in the scene graph.
(One important note about this mode: we've had reports from users that some OpenGL drivers – possibly particular for some Mac OS X systems – significantly degrades rendering performance. So be careful and test your application on a wide variety of runtime systems when using SoGLRenderAction::SORTED_LAYERS_BLEND.)
Enumerator | |
---|---|
SCREEN_DOOR | Transparent triangles are rendered with a dither pattern. This is a fast (on most GFX cards) but not-so-high-quality transparency mode. One particular feature of this mode is that you are guaranteed that it always renders the transparent parts of the scene correct with regard to internal depth ordering of objects / polygons, something which is not the case for any other transparency mode. Polygons rendered with only transparent textures are not shown as being transparent when using this mode. The reason being that the SoGLRenderAction::SCREEN_DOOR mode is working on polygons, not pixels. To render polygons with dither pattern, a material node has to be inserted into the scene graph with its transparency field set. |
ADD | Transparent objects are rendered using additive alpha blending. Additive blending is probably mostly used to create special transparency effects. The new pixel color is calculated as the current pixel color plus the source pixel color multiplied with the source pixel alpha value. |
DELAYED_ADD | Transparent objects are rendered using additive alpha blending, in a second rendering pass with depth buffer updates disabled. |
SORTED_OBJECT_ADD | Transparent objects are rendered using additive alpha blending. Opaque objects are rendered first, and transparent objects are rendered back to front with z-buffer updates disabled. |
BLEND | Transparent objects are rendered using multiplicative alpha blending. Multiplicative alpha blending is the blending type that is most often used to render transparent objects. The new pixel value is calculated as the old pixel color multiplied with one minus the source alpha value, plus the source pixel color multiplied with the source alpha value. We recommend that you use this transparency mode if you have only one transparent object in your scene, and you know that it will be rendered after the opaque objects. |
DELAYED_BLEND | Transparent objects are rendered using multiplicative alpha blending, in a second rendering pass with depth buffer updates disabled. Use this transparency type when you have one transparent object, or several transparent object that you know will never overlap (when projected to screen). Since the transparent objects are rendered after opaque ones, you'll not have to worry about putting the transparent objects at the end of your scene graph. It will not be as fast as the SoGLRenderAction::BLEND transparency type, of course, since the scene graph is traversed twice. |
SORTED_OBJECT_BLEND | Transparent objects are rendered using multiplicative alpha blending, Opaque objects are rendered first, and transparent objects are rendered back to front with z-buffer updates disabled. Use this transparency mode when you have several transparent object that you know might overlap (when projected to screen). This method will require 1 + num_transparent_objects rendering passes. Path traversal is used when rendering transparent objects, of course, but it might still be slow if you have lots of state changes before your transparent object. When using this mode, we recommend placing the transparent objects as early as possible in the scene graph to minimize traversal overhead. |
SORTED_OBJECT_SORTED_TRIANGLE_ADD | This transparency type is a Coin extension versus the original SGI Open Inventor API. Transparent objects are rendered back to front, and triangles in each object are sorted back to front before rendering. See description for SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND for more information about this transparency type. |
SORTED_OBJECT_SORTED_TRIANGLE_BLEND | This transparency type is a Coin extension versus the original SGI Open Inventor API. Transparent objects are rendered back to front, and triangles in each object are sorted back to front before rendering. Use this transparency type when you have one (or more) transparent object(s) where you know triangles might overlap inside the object. This transparency type might be very slow if you have an object with lots of triangles, since all triangles have to be sorted before rendering, and an unoptimized rendering loop is used when rendering. Lines and points are not sorted before rendering. They are rendered as in the normal SoGLRenderAction::SORTED_OBJECT_BLEND transparency type. Please note that this transparency mode does not guarantee "correct" transparency rendering. It is almost impossible to find an algorithm that will sort triangles correctly in all cases, and intersecting triangles are not handled. Also, since each object is handled separately, two intersecting object will lead to incorrect transparency. |
NONE | This transparency type is a Coin extension versus the Open Inventor API. Turns off transparency for objects, even if transparency is set using an SoMaterial node.
|
SORTED_LAYERS_BLEND | This transparency type is a Coin extension versus the original SGI Open Inventor API. By using this transparency type, the SoGLRenderAction will render normal and intersecting transparent objects correctly independent of rendering order. It is the only transparency type rendering mode which is guaranteed to do so. This mode is different from all other modes in that it overrides the SoTransparencyType nodes in the scene graph; all objects are drawn using SoGLRenderAction::SORTED_LAYERS_BLEND. There are currently two separate code paths for this mode. Both paths are heavily based on OpenGL extensions. The first method is based on extensions which are only available on NVIDIA chipsets (GeForce3 and above, except GeForce4 MX). These extensions are The second method utilizes the Setting the environment variable COIN_SORTED_LAYERS_USE_NVIDIA_RC to '1' will force the use of former code path instead of the latter, even if it is available. A rendering context with >= 24 bits depth buffer and 8 bits alpha channel must be the current rendering context for this blending mode to actually become activated. If the current rendering canvas does not have these properties, Coin will fall back on a simpler transparency handling mode. If you are using one of the window-system binding libraries provided by Kongsberg Oil & Gas Technologies, e.g. SoXt, SoQt or SoWin, you will need to explicitly enable this in your viewer. See the API documentation of the The detection of whether or not the SoGLRenderAction::SORTED_LAYERS_BLEND mode can be used will be done automatically by the Coin internals. If one or more of the necessary conditions listed above are unavailable, SoGLRenderAction::SORTED_OBJECT_BLEND will be used as the transparency type instead. To be able to render correct transparency independent of object order, one have to render in multiple passes. This technique is based on depth-peeling which strips away depth layers with each successive pass. The number of passes is therefore an indication of how deep into the scene transparent surfaces will be rendered with transparency. A higher number will lead to a lower frame rate but higher quality for scenes with a lot of transparent surfaces. The default number of passes is '4'. This number can be specified using the SoGLRenderAction::setSortedLayersNumPasses() or by letting the environment variable A more detailed presentation of the algorithm is written by Cass Everitt at NVIDIA; "Interactive Order-Independent Transparency" https://www.nvidia.com/en-us/drivers/Interactive-Order-Transparency/ |
Enumerates the render types of transparent objects.
SoGLRenderAction::SoGLRenderAction | ( | const SbViewportRegion & | viewportregion | ) |
Constructor. Sets up the render action for rendering within the given viewportregion.
|
virtual |
Destructor.
SbBool SoGLRenderAction::abortNow | ( | void | ) |
Returns TRUE
if the render action should abort now based on user callback.
Adds a path to the list of paths to render after the current pass.
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
Adds a callback which is invoked right before the scene graph traversal starts. All necessary GL initialization is then done (e.g. the viewport is correctly set), and this callback can be useful to, for instance, clear the viewport before rendering, or draw a bitmap in the background before rendering etc.
The callback is only invoked once (before the first rendering pass) when multi pass rendering is enabled.
Please note that SoSceneManager usually adds a callback to clear the GL buffers in SoSceneManager::render(). So, if you plan to for instance draw an image in the color buffer using this callback, you should make sure that the scene manager doesn't clear the buffer. This can be done either by calling SoSceneManager::render() with both arguments FALSE, or, if you're using one of our GUI toolkits (SoXt/SoQt/SoGtk/SoWin), call setClearBeforeRender() on the viewer.
This method is an extension versus the Open Inventor API.
This virtual method is called from SoAction::apply(), and is the entry point for the actual scene graph traversal.
It can be overridden to initialize the action at traversal start, for specific initializations in the action subclasses inheriting SoAction.
Default method just calls traverse(), which any overridden implementation of the method must do too (or call SoAction::beginTraversal()) to trigger the scene graph traversal.
Reimplemented from SoAction.
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
This virtual method can be overridden to execute code after the scene graph traversal. Default method does nothing.
Reimplemented from SoAction.
void SoGLRenderAction::getAbortCallback | ( | SoGLRenderAbortCB *& | func_out, |
void *& | userdata_out ) const |
uint32_t SoGLRenderAction::getCacheContext | ( | void | ) | const |
Returns the cache context key for this rendering action instance.
|
staticprotected |
Returns list of action methods for this class. The enabledElements and methods variables are protected in the original OIV API. This is not such a good idea, since exposed static class member variables is a major grievance with regard to Win32 DLLs. This function is an extension for Coin, and it is not available in the original SGI Open Inventor v2.1 API.
|
staticprotected |
Returns list of enabled elements for this class. The enabledElements and methods variables are protected in the original OIV API. This is not such a good idea, since exposed static class member variables is a major grievance with regard to Win32 DLLs. This function is an extension for Coin, and it is not available in the original SGI Open Inventor v2.1 API.
This static method returns the SoType object associated with objects of this class.
int SoGLRenderAction::getCurPass | ( | void | ) | const |
Returns the number of the current rendering pass.
SbBool SoGLRenderAction::getDelayedObjDepthWrite | ( | void | ) | const |
Return whether depth buffer updates should be done when rendering delayed or sorted transparent objects. Default is FALSE.
|
protectedvirtual |
Returns list of enabled elements.
Reimplemented from SoAction.
Reimplemented in SoBoxHighlightRenderAction, and SoLineHighlightRenderAction.
int SoGLRenderAction::getNumPasses | ( | void | ) | const |
Returns the number of rendering passes done on updates.
SbBool SoGLRenderAction::getRenderingIsRemote | ( | void | ) | const |
Returns whether or not the application is running remotely.
int SoGLRenderAction::getSortedLayersNumPasses | ( | void | ) | const |
Returns the number of passes to render when in SoGLRenderAction::SORTED_LAYERS_BLEND mode.
SoGLRenderAction::TransparencyType SoGLRenderAction::getTransparencyType | ( | void | ) | const |
Returns the transparency rendering type.
SoGLRenderAction::TransparentDelayedObjectRenderType SoGLRenderAction::getTransparentDelayedObjectRenderType | ( | void | ) | const |
Returns the render type of delayed or sorted transparent objects.
Returns the type identification of an object derived from a class inheriting SoAction. This is used for runtime type checking and "downward" casting.
Implements SoAction.
Reimplemented in SoBoxHighlightRenderAction, and SoLineHighlightRenderAction.
Returns information about the area of the rendering context window to be updated.
const SbViewportRegion & SoGLRenderAction::getViewportRegion | ( | void | ) | const |
Returns the viewport region for the rendering action.
SbBool SoGLRenderAction::handleTransparency | ( | SbBool | istransparent = FALSE | ) |
Used by shape nodes or others which need to know whether or not they should immediately render themselves or if they should wait until the next pass. It also enables/disabled blending based on the istransparent parameter.
If you're using an SoCallback or a non-shape node to render your geometry, you can use this function to make sure your node is only rendered once. This function consider the istransparent parameter, and when TRUE it will return TRUE on the first pass, and FALSE on the second pass. For non-transparent objects it returns FALSE on the first pass, TRUE on the second.
Please note that this function considers the current transparency type when deciding what to do. It will delay rendering only when the transparency type is DELAYED_* or SORTED_OBJECT_*. For other transparency types, transparent objects are rendered in the same pass as opaque objects.
Initializes the runtime type system for this class, and sets up the enabled elements and action method list.
SbBool SoGLRenderAction::isPassUpdate | ( | void | ) | const |
Returns the value of the "show intermediate updates" flag.
SbBool SoGLRenderAction::isRenderingDelayedPaths | ( | void | ) | const |
Returns a flag indicating whether or not we are currently rendering from the list of delayed paths of the scene graph.
SbBool SoGLRenderAction::isRenderingTranspBackfaces | ( | void | ) | const |
Returns TRUE if the action is currently rendering back facing polygons in NONSOLID_SEPARATE_BACKFACE_PASS mode.
SbBool SoGLRenderAction::isRenderingTranspPaths | ( | void | ) | const |
Returns TRUE if the action is currently rendering delayed or sorted transparent objects.
SbBool SoGLRenderAction::isSmoothing | ( | void | ) | const |
Returns whether smoothing is set or not.
Removed a callback added with the addPreRenderCallback() method.
This method is an extension versus the Open Inventor API.
void SoGLRenderAction::setAbortCallback | ( | SoGLRenderAbortCB *const | func, |
void *const | userdata ) |
Sets the abort callback. The abort callback is called by the action for each node during traversal to check for abort conditions.
The callback method should return one of the SoGLRenderAction::AbortCode enum values to indicate how the action should proceed further.
Since the client SoGLRenderAbortCB callback function only has a single void* argument for the userdata, one has to do some additional work to find out which node the callback was made for. One can do this by for instance passing along the action pointer as userdata, and then call the SoGLRenderAction::getCurPath() method. The tail of the path will then be the last traversed node. Like this:
Sets the OpenGL cache context key, which is used for deciding when to share OpenGL display lists.
Each SoGLRenderAction has a cache context id. This can be set using SoGLRenderAction::setCacheContext(). The cache context id must be unique, so that different texture objects and display lists are created for incompatible GL contexts. For instance, when SoGLRenderAction traverses an SoTexture2 node, the node checks if it has a texture object created for the cache context. If not, a new texture object will be created and used when rendering.
Sets the current rendering pass to passnum. This can be used when antialiasing is controlled from outside the SoGLRenderAction instance. numpasses is the total number of rendering passes to be used.
Please note that this will disable any antialiasing set using the setNumPasses() method. You can re-enable the internal antialiasing again by calling setNumPasses()
void SoGLRenderAction::setDelayedObjDepthWrite | ( | SbBool | write | ) |
Set whether depth buffer updates should be done when rendering delayed or sorted transparent objects.
Sets the number of rendering passes. Default is 1, anything greater will enable antialiasing through the use of an OpenGL accumulation buffer.
Sets the pass callback. The callback is called between each rendering pass.
Sets whether each pass should render to screen or not.
void SoGLRenderAction::setRenderingIsRemote | ( | SbBool | isremote | ) |
Let SoGLRenderAction instance know if application is running on the local machine or if the rendering instructions are sent over the network.
The flag is used to optimize rendering. For instance should the display list caching strategy be influenced by this flag to be more aggressive with the caching when rendering instructions are passed over the network.
Default value is FALSE
. The value of the flag will not be changed internally from the Coin library code, as it is meant to be controlled from client code – typically from the SoQt / SoXt / SoWin / SoGtk libraries.
Sets (or unsets) smoothing. If the smoothing flag is on
, Coin will try to use built-in features from the OpenGL implementation to smooth the appearance of otherwise jagged line and point primitives, calling
glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH);
...before rendering the scene.
This is a simple (and computationally non-intensive) way of doing anti-aliasing.
Default value for this flag is to be off
.
void SoGLRenderAction::setSortedLayersNumPasses | ( | int | num | ) |
Sets the number of passes to render in SoGLRenderAction::SORTED_LAYERS_BLEND mode. Default number of passes is 4. This number can also be adjusted by setting the COIN_NUM_SORTED_LAYERS_PASSES
or OIV_NUM_SORTED_LAYERS_PASSES
environment variable.
void SoGLRenderAction::setSortedObjectOrderStrategy | ( | const SortedObjectOrderStrategy | strategy, |
SoGLSortedObjectOrderCB * | cb = NULL, | ||
void * | closure = NULL ) |
Sets the strategy used for sorting transparent objects.
The CUSTOM_CALLBACK strategy enables the user to supply a callback which is called for each transparent shape. This strategy can be used if the built in sorting strategies aren't sufficient.
The callback should return a floating point value to be used when sorting the objects in Coin. This floating point value is interpreted as a distance to the camera, and objects with higher values will be sorted behind objects with lower values.
The callback will supply the SoGLRenderAction instance, and the path to the current object can be found using SoAction::getCurPath().
void SoGLRenderAction::setTransparencyType | ( | const TransparencyType | type | ) |
Sets the transparency rendering method for transparent objects in the scene graph.
void SoGLRenderAction::setTransparentDelayedObjectRenderType | ( | TransparentDelayedObjectRenderType | type | ) |
Sets the render type of delayed or sorted transparent objects. Default is ONE_PASS.
void SoGLRenderAction::setViewportRegion | ( | const SbViewportRegion & | newregion | ) |
Sets the viewport region for rendering. This will then override the region passed in with the constructor.