Class SoRenderToTarget

  • All Implemented Interfaces:

    public class SoRenderToTarget
    extends SoSeparator
    Group node that renders its children to one or more "targets". This group node renders its children to one or more render targets.

    Multiple targets can be "attached" to the different outputs of the node.

    This node also provides antialiasing. When FrameBufferObjects (FBO) are used (this is the default mode if they are available) multisampling can be configured in order to perform antialiasing on the FBO. This MSAA feature is not related to the viewer's FSAA. The quality factor is set between 0.f(default value) and 1.f. The underlying system will setup the FBO with the correct number of samples according to the quality value and according to the attachments configuration.

    By default the node clears the targets when the rendering is started. The values used to clear the buffers can be specified by the fields clearColorValue, clearDepthValue and clearStencilValue. It is also possible to disable this feature by setting the field clearTargets to false.

    During rendering, the viewport from the Open Inventor state is used, which means that the current size of the render area is used. It is possible to change this default behavior by setting the size field. Setting it to (-1, -1) will switch back to the default mode, other values will be used as the custom rendering size in pixels. The targets are automatically resized to the correct size.

    The SoRenderToTextureProperty node can also be used to create a texture image and is useful for simpler cases.


    • Performance:
      • Using the TARGET_COPY mode at each frame really reduces performance because a transfer from GPU memory to CPU memory is performed to transfer the data to the SoSFImage field of the texture.
      • Antialiasing (MSAA) can really reduce performance and increase memory consumption. It can even be impossible to use antialiasing with large FLOAT color attachments.
    • Target limitations:
    • By default the textures are resized using the following rules:
      • RBGA uint8 for the color attachements. (Internal mode is RGBA8)
      • Luminance float32 for the depth attachment. (Internal mode is DEPTH_COMPONENT24).
      • Luminance uint8 for the stencil attachment. It is possible to override the default internal mode for the textures by using the internalFormat field of SoTexture.
    • Rendering
      • SoRenderToTarget is an SoSeparator and can be added directly to the scene graph. In this case its children are rendered as part of the main scene graph and inherit properties (camera, light, material, etc) from the main scene graph.

      • SoRenderToTarget can also be used separate from the main scene graph and re-rendered as-needed by applying an SoGLRenderAction. In this case the children of the SoRenderToTarget will normally include a camera, light, etc node. But also note that, in this case, the OpenGL calls normally made by the viewer and/or SoSceneManager will not be done automatically. For example, the OpenGL depth test is not enabled. Use an SoDepthBuffer node to do this.
    • Bounding box
      • WARNING: The 'boundingBoxIgnoring' default value is true.
        Usually the SoRenderToTarget scenegraph is not really part of the main scene and should not have any effect on the bounding box computed for the main scene. But in some cases, it can be useful to include the SoRenderToTarget scenegraph's bounding box, like when doing post-processing effects. In that case, manually set 'boundingBoxIgnoring' to false.
    • Hardware compatibility:
      • All the exposed features are supported by the FBO rendering subsystem. PBuffer and pixmap might not support some of them. For example it is not possible to have multiple color attachments in PBuffer mode. Those alternative modes are supported only for compatibility with legacy hardware.

    Open Inventor 8.6 File format/default:

    RenderToTarget {
      modes AUTO
      targets NULL
      layers 0
      clearTargets true
      clearColorValue (0.F, 0.F, 0.F, 0.F)
      clearDepthValue 1.F
      clearStencilValue 0
      antialiasingQuality 0.F
      size (-1, -1)
      enableFragmentsQuery false

    Action behavior:

    Performs an offscreen rendering using either FBO, PBuffer or pixmap. Sets: SoCacheElement

    See Also:
    SoTexture, SoTexture2
    • Field Detail

      • modes

        public final SoMFEnum<SoRenderToTarget.ModeType> modes
        This defines the mode modifier for the targets. For each target it is possible to specify a mode. Use enum Mode. Default is AUTO.

        NOTE: This field is indexed using the Attachment enum. For example (in pseudo-code):

        • modes[COLOR0] = TARGET_AND_COPY;
        • modes[STENCIL] = INTERNAL;
      • targets

        public final SoMFNode targets
        This field allows to attach a texture to a specific attachment. Supported target types are SoTexture2, SoTexture3 and SoTextureCubeMap. Default is empty (no targets).

        NOTE: This field is indexed using the Attachment enum. For example (in pseudo-code):

        • targets[COLOR0] = rgbaTexture;
        • targets[STENCIL] = stencilTexture;
      • layers

        public final SoMFInt32 layers
        This field is used when targets are SoTexture3 or SoTextureCubeMap. It describes the layer where the color attachment must be written, along the Z dimension for SoTexture3, or the cube map face for SoTextureCubeMap (the cube map faces order is presented in the table below). This field is indexed by color attachments (i.e. from COLOR0 to COLOR15) and has no effect when targets are of type SoTexture2 or when target attachments are DEPTH or STENCIL, which require a SoTexture2 Target.

          Layer number Cube Map Face
          0 Positive X
          1 Negative X
          2 Positive Y
          3 Negative Y
          4 Positive Z
          5 Negative Z
      • clearTargets

        public final SoSFBool clearTargets
        If this field is set the targets are cleared before the rendering. Default is true.
      • clearColorValue

        public final SoSFVec4f clearColorValue
        Value used to clear the color buffer before the rendering. Default is (0.0, 0.0, 0.0, 0.0).
      • clearDepthValue

        public final SoSFFloat clearDepthValue
        Value used to clear the depth buffer before the rendering. Default is 1.0.
      • clearStencilValue

        public final SoSFInt32 clearStencilValue
        Value used to clear the stencil buffer before the rendering. Default is 0.
      • antialiasingQuality

        public final SoSFFloat antialiasingQuality
        This field defines the antialiasing quality between 0.0 and 1.0 for the rendering. The value 1.0 represents the maximun quality possible on this hardware. Default is 0.

        NOTE: Hardware limitations: The result depends on the support for multisampling in FBO or the FSAA support for PBuffers.

      • size

        public final SoSFVec2i32 size
        This field allows a custom rendering size for the render to texture. When this field is set to the default value (-1, -1) the global viewport size from the viewer is used. The size is in pixels.
      • enableFragmentsQuery

        public final SoSFBool enableFragmentsQuery
        This field enables or disables the query counter used to count the number of fragments rasterized during the render to texture operation. Default is false.

        The method getRasterizedSamplesCount() can be used to get the result of the query.

    • Constructor Detail

      • SoRenderToTarget

        public SoRenderToTarget()
        Default constructor.
    • Method Detail

      • isSupported

        public static boolean isSupported()
        Calls isSupported((com.openinventor.inventor.misc.SoState)null).
      • getRasterizedSamplesCount

        public int getRasterizedSamplesCount()
        Returns the number of samples generated by the rasterizer during the last GLRender action. To enable this feature the enableFragmentsQuery field must be set to true. Otherwise the result is undefined.
      • isSupported

        public static boolean isSupported​(SoState state)
        Indicates if this node can be used on the actual hardware. When using a debug build of Open Inventor, some "no context available" warning messages may be generated. You can ignore them or see SoGLExtension for an example of using SoGLContext to avoid them.