SoOffscreenRenderer Class |
Renders to an off-screen buffer for printing or generating textures.
Namespace: OIV.Inventor
The SoOffscreenRenderer type exposes the following members.
Name | Description | |
---|---|---|
![]() | SoOffscreenRenderer(SbViewportRegion) | Constructor. |
![]() | SoOffscreenRenderer(SoGLRenderAction) | Constructor. |
Name | Description | |
---|---|---|
![]() | Dispose | |
![]() | Equals | (Inherited from Object.) |
![]() | GetBackgroundColor | Returns the background color for rendering. |
![]() | GetBackgroundColorRGBA | Returns the RGBA background color for rendering. |
![]() | GetBuffer | Calls GetBuffer(OIV.Inventor.SoOffscreenRenderer.BufferTypes( .SoOffscreenRenderer.RGB_BUFFER )). |
![]() | GetBuffer(SoOffscreenRendererBufferTypes) | Returns a buffer containing the rendered image. |
![]() | GetBufferSize | Calls GetBufferSize(OIV.Inventor.SoOffscreenRenderer.BufferTypes( .SoOffscreenRenderer.RGB_BUFFER )). |
![]() | GetBufferSize(SoOffscreenRendererBufferTypes) | Returns the buffer size in bytes. |
![]() | GetColorDepth | Gets the color depth to be used for offscreen rendering. |
![]() | GetComponents | Returns the components to be rendered. |
![]() | GetDC | <font color="#0000FF">[Windows only] This method has no effect on UNIX systems. |
![]() | GetFullSceneAntialiasing | Returns the full-scene antialiasing preference and number of samples. |
![]() | GetGLRenderAction | Gets the render action to use for rendering. |
![]() | GetGraphicConfigTemplate | Gets the current graphics configuration template. |
![]() | GetHashCode |
Overrides GetHashCode().
(Inherited from SoNetBase.) |
![]() | GetLongBufferSize | Obsolete. Returns the buffer size in bytes. |
![]() ![]() | GetMaximumResolution | Gets the maximum supported resolution of the viewport. |
![]() | GetMaxSubimage | Synonym for getMaxTileSize. |
![]() | GetMaxTileSize | Gets the maximum subimage (tile) size for rendering. |
![]() | GetNumEdgePixels | Gets the number of pixels on the edge of each subimage that are not written on the big image (overlapped pixels). |
![]() | GetPBuffer | Get the SoPBuffer used for rendering. |
![]() | GetPbufferEnable | Returns true if a Pbuffer may be used for rendering. |
![]() ![]() | GetScreenPixelsPerInch | Returns the number of pixels per inch (in the horizontal direction) of the current X device screen. |
![]() | GetShareContext | Gets the OpenGL context shared by the SoOffscreenRenderer. |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | GetViewportRegion | Returns the viewport region used for rendering. |
![]() | IsFullSceneAntialiasing | Returns true if FSAA is currently enabled. |
![]() | Render(SoNode) | Renders the given scene, specified as a node, into an off-screen buffer. |
![]() | Render(SoPath) | Renders the given scene, specified as a path, into an off-screen buffer. |
![]() | SetBackgroundColor | Sets the RGB background color for rendering. |
![]() | SetBackgroundColorRGBA | Sets the RGBA background color for rendering. |
![]() | SetColorDepth | Sets the color depth to be used for offscreen rendering. |
![]() | SetComponents | Sets the components to be rendered. |
![]() | SetFullSceneAntialiasing(Boolean) | Calls SetFullSceneAntialiasing(enable, -1.0, SoFullSceneAntialiasing.ALL). |
![]() | SetFullSceneAntialiasing(SoGraphicConfigTemplatePreferences) | Calls SetFullSceneAntialiasing(pref, System.Int32(0), INT_MAX). |
![]() | SetFullSceneAntialiasing(Boolean, Single) | Calls SetFullSceneAntialiasing(enable, quality, SoFullSceneAntialiasing.ALL). |
![]() | SetFullSceneAntialiasing(SoGraphicConfigTemplatePreferences, Int32) | Calls SetFullSceneAntialiasing(pref, minFsaaBits, INT_MAX). |
![]() | SetFullSceneAntialiasing(Boolean, Single, Int32) | Sets the full-scene antialiasing preferences. |
![]() | SetFullSceneAntialiasing(SoGraphicConfigTemplatePreferences, Int32, Int32) | Sets the full-scene antialiasing preferences. |
![]() | SetGLRenderAction | Sets the render action to use for rendering. |
![]() | SetGraphicConfigTemplate | Sets a new graphics configuration template. |
![]() | SetMaxSubimage | Synonym for setMaxTileSize. |
![]() | SetMaxTileSize | Sets the maximum subimage (tile) size for rendering. |
![]() | SetNumEdgePixels | Sets the number of pixels on the edge of each subimage that are not written on the big image (overlapped pixels). |
![]() | SetPbufferEnable | Specifies if a Pbuffer may be used for rendering. |
![]() | SetRegion | Sets a subregion of the viewport to be rendered. |
![]() | SetRegion_i32 | Sets a subregion of the viewport to be rendered. |
![]() | SetShareContext | Sets the OpenGL context to be shared by the SoOffscreenRenderer. |
![]() | SetTileObserver | Specifies a tile observer object which will be called after each tile is rendered. |
![]() | SetupPixmap | Do all the setup for rendering and make the offscreen context current (useful if you want to make your own OpenGL calls) |
![]() | SetViewportRegion | Sets the viewport region used for rendering. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() | WriteToBMP | <font color="#0000FF">[Windows only] This method has no effect on UNIX systems. |
![]() | WriteToJPEG(String) | Calls WriteToJPEG(filename, 1.0). |
![]() | WriteToJPEG(String, Single) | Writes the buffer as a JPEG file to the given filename. |
![]() | WriteToJPEGBuffer |
Writes the JPEG compression stream to a buffer.
|
![]() | WriteToPNG | Writes the buffer as a PNG file to the given filename. |
![]() | WriteToPostScript(String) | Writes the buffer as encapsulated PostScript to the given filename. |
![]() | WriteToPostScript(String, SbVec2f) | Writes the buffer as encapsulated PostScript to the given filename. |
![]() | WriteToRaster | Writes the buffer using the image writer class passed as the second parameter. |
![]() | WriteToRGB | Writes the buffer as an .rgb file to the given filename. |
![]() | WriteToTIFF(String) | Calls WriteToTIFF(filename, OIV.Inventor.SoOffscreenRenderer.TIFFCompressionModes( .SoOffscreenRenderer.PACKBITS_COMPRESSION )). |
![]() | WriteToTIFF(String, SoOffscreenRendererTIFFCompressionModes) | Writes the buffer as a TIFF file to the given filename. |
Name | Description | |
---|---|---|
![]() | AbortCallback | Sets callback to call during rendering to test for abort condition. |
This class is used to render into an off-screen buffer to create a printable image or to generate a texture image. It uses a Pbuffer (if possible) or an off-screen bitmap for rendering. Methods are provided to write the buffer to a file, as an RGB image, an encapsulated PostScript description, or in one of several other image formats.
<font color="#0000FF">NOTE:</font> This class does not exist in Open Inventor 10.0 and later. Replace with SoOffscreenRenderArea.
The renderer can generate images of any size. If the requested image size exceeds OpenGL rendering capabilities, the image will be created by automatically rendering some number of "tiles" and "stitching" them together. See setMaxTileSize for details. Using tiles allows you to create very large, very high resolution images. For example, a poster size image to be printed at 300 dpi would need to be (approximately) 10,000 pixels wide.
The renderer can generate images with a transparent background (as long as there is an OpenGL render format available that supports an alpha buffer). See setBackgroundColorRGBA(). Note that you must also call setComponents() with the parameter set to RGBA (setBackgroundColorRGBA does not do this automatically).
Some output file formats are much more efficient than others at dealing with tiled output. If you anticipate generating very large images, it may be helpful to chose an output format that can generate tiled output efficiently. The formats in the "WRITE_SCANLINES" column in the following table are more efficient at generating tiled output.
Write Capability WRITE_FULL_IMAGE | Write Capability WRITE SCANLINES |
BMP JP2 (JPEG2000) PGX PNM SUN | JPEG PNG PS (PostScript) SGIRGB TIFF |
For the WRITE_FULL_IMAGE formats, the entire image must be written at once, so a buffer large enough for the whole image is allocated, and tiles are copied into it. Therefore it must be possible to allocate enough memory for a single tile (num_components * tile_width * tile_height) plus enough memory to assemble the complete image (num_components * width * height).
For the WRITE_SCANLINES formats, the image can be written incrementally, some number of scanlines at a time. Therefore it is only necessary to allocate enough memory for a single tile, which at most will be the size of the maximum OpenGL viewport (typically 2048x2048).
See the documentation for SoRasterImageRW and the individual image classes (SoBMPImageRW, SoGIFImageRW, etc.) for further information.
PBuffers Beginning with Open Inventor 3.1, this class will automatically try to use an OpenGL Pbuffer for rendering. If a Pbuffer is available, rendering will be accelerated by the 3D graphics hardware. If no Pbuffer is available, rendering will use a software rendered off-screen buffer as before. Pbuffers are a standard feature of OpenGL 1.2 and are often available as an extension on older versions of OpenGL. However it is not guaranteed that Pbuffers will be available or that a Pbuffer of the desired size can be created.
Rendering with a Pbuffer will generally produce the same image as would be rendered on the screen, but this is not guaranteed. In general, software rendering will produce the same image as on-screen if only OpenGL 1.1 features are used. Newer OpenGL features and extensions will generally not be available using software rendering.
Note that Pbuffers are a limited resource. If the application creates multiple instances of SoOffscreenRenderer, it may be desirable to prevent some of them (that are lower priority or render small scene graphs) from using a Pbuffer. See the method setPbufferEnable().
Rendering contexts The setShareContext method allows you to share an already existing OpenGL context with the offscreen renderer. This avoids the necessity to re-generate textures and display lists if they are already available in another OpenGL context (the viewer context, for instance). This can dramatically reduce offscreen rendering time, depending on your scene graph.
A corresponding query method (#GetShareContext) is also available.
Here's how you might use these methods to share OpenGL contexts:
renderer.SetShareContext( viewer.GetShareContext() );
Rendering a "snapshot" SoOffscreenRenderer is often used to save a snapshot of the image in the viewer window. There are several common pitfalls. First, the scene graph given to the renderer must include the camera node that the viewer is using. If the application allows the viewer to create a camera automatically, the scene graph returned by the viewer's getSceneGraph() method does not include the camera. It's always safer to get the SoSceneManager object then get the scene graph. Second, some rendering options are set on the viewer object, not in the scene graph. These options, which include background color and transparency mode, must be explicitly queried from the viewer and set on the renderer object.
Sample code to make a snapshot, given a viewer object, might look like this:
SoOffscreenRenderer renderer = new SoOffscreenRenderer( viewer.GetViewportRegion() ); renderer.SetShareContext( viewer.GetShareContext() ); renderer.SetBackgroundColor( viewer.GetBackgroundColor() ); renderer.GetGLRenderAction().SetTransparencyType( viewer.GetTransparencyType() ); renderer.Render( viewer.GetSceneManager().GetSceneGraph() ); renderer.WriteToPNG( "output.png" );
NOTE: Tiled rendering does not currently work correctly when a camera node's viewportMapping field is set to one of the CROP_ options. It does work correctly with the LEAVE_ALONE and ADJUST_CAMERA (default) settings.
SoOffscreenRenderer is useful because it allows the image size to be specified (e.g. different than the on-screen window) and because it can render images of almost any size (much larger than the physical screen). However it does require an additional render traversal to create the image. For a simple snapshot of an on-screen window it may be more efficient to use the saveSnapshot() method in the So___GLWidget class (e.g. SoWinGLWidget).