Viewport Class
A Viewport class is used to render a scene with the specified settings.
The main use cases of the Viewport class are as follows:
- Render a scene to the image interface (data will be transfered from GPU memory to CPU memory), using the following methods:
- renderImage2D(camera,image)
- renderImage2D(camera,image,width,height,hdr)
- renderImageCube(camera, image)
- renderImageCube(camera,image,size,hdr,local_space)
// initialization Viewport viewport = new Viewport(); Image image = new Image(); image.create2D(512, 512, IMAGE_FORMAT_RGBA8);// create 512 x 512 render target CameraPtr camera = new Camera(); // set modelview & projection matrices to camera instance // rendering an image from the camera to the image viewport.renderImage2D(camera, image);
- Render a node to the image (data will be transfered from GPU memory to CPU memory)
- To render the node to the Image interface, use the following methods:
To set any viewport as a main, use the setViewport() method of the Render class.
A single viewport should be used with a single camera, otherwise it may cause visual artefacts. To avoid artefacts, when using several cameras with a single viewport, all post effects must be disabled using the setSkipFlags() method with the SKIP_POSTEFFECTS flag.
Viewport Class
Members
static Viewport()
Creates a new viewport with default settings.void setAspectCorrection(int correction)
Sets the aspect correction for current viewport. 1 enables correction, 0 disables.Arguments
- int correction - 1 to enable aspect correction, 0 to disable.
int getAspectCorrection()
Return the value indicating if the aspect correction enabled for current viewport.Return value
1 if the aspect correction enabled, otherwise 0.void setFirstFrame(int frame)
Sets a value indicating if the first frame should be enabled over the current frame.Arguments
- int frame - 1 to set the first frame flag; otherwise, 0.
int getFirstFrame()
Returns a value indicating if the first frame is enabled over the current frame.Return value
1 if the first frame flag is set; otherwise, 0.int getID()
Returns the viewport ID.Return value
Viewport ID.void setMode(int mode)
Sets the rendering mode for the current viewport. It can be one of the stereo or panoramic modes or the default mode.Arguments
- int mode - A rendering mode.
int getMode()
Returns the rendering mode set for the current viewport. It can be one of the stereo or panoramic modes or the default mode.Return value
The current rendering mode.void setNodeEnvironmentTextureName(string name)
Sets a name for the environment texture.Arguments
- string name - A texture name.
void setNodeLightUsage(int usage)
Sets the type of lighting for the render node.Arguments
- int usage - The lighting type. Can be one of the following:
int getNodeLightUsage()
Returns the type of lighting of the render node.Return value
The lighting type. Can be one of the following:int isPanorama180()
Returns a value indicating if a 180-degree panoramic rendering is enabled.Return value
1 if a 180-degree panoramic rendering is enabled; otherwise, 0.int isPanorama360()
Returns a value indicating if a 360-degree panoramic rendering is enabled.Return value
1 if a 360-degree panoramic rendering is enabled; otherwise, 0.void setRenderMode(int mode)
Sets the specified render mode. The mode determines the set buffers to be rendered.Arguments
- int mode - Render mode to set. Can be one of the following:
int getRenderMode()
Returns the current render mode. The mode determines the set buffers to be rendered.Return value
Current render mode. Can be one of the following:void setSkipFlags(int flags)
Sets the skip flag for the current viewport.Arguments
- int flags - A skip flag.
int getSkipFlags()
Returns the skip flag set for the current viewport.Return value
A skip flag.int isStereo()
Returns a value indicating if the stereo rendering is enabled for the current viewport (one of the stereo modes is set).Return value
1 if the stereo rendering is enabled; otherwise, 0.void setStereoDistance(float distance)
Sets the focal distance for stereo rendering (distance in the world space to the point where two views line up, i.e. to the zero parallax plane).Arguments
- float distance - A focal distance in units.
float getStereoDistance()
Returns the focal distance for stereo rendering (distance in the world space to the point where two views line up, i.e. to the zero parallax plane).Return value
A focal distance in units.void setStereoOffset(float offset)
Updates the virtual camera offset (an offset after the perspective projection).Arguments
- float offset - A virtual camera offset in units.
float getStereoOffset()
Returns the virtual camera offset (an offset after the perspective projection).Return value
A virtual camera offset in units.void setStereoRadius(float radius)
Updates the radius for stereo (the half of the separation distance between the cameras (i.e. between eyes)).Arguments
- float radius - A stereo radius in units. If a negative value is provided, 0 will be used instead.
float getStereoRadius()
Returns the current radius for stereo (the half of the separation distance between the cameras (i.e. between eyes)).Return value
Stereo radius in units.void appendSkipFlags(int flags)
Appends specified skip flags to the list of currently used ones.Arguments
- int flags - Skip flags to append.
int checkSkipFlags(int flags)
Returns a value indicating if the specified skip flags are set for the current viewport.Arguments
- int flags - Skip flags to check.
Return value
1 if the skip flags are set; otherwise, 0.void removeSkipFlags(int flags)
Removes specified skip flags from the list of currently used ones.Arguments
- int flags - Skip flags to remove.
void render(Camera camera)
Renders an image from the specified camera.
To render an image from the camera to the TextureRender interface, do the following:
camera = new Camera();
texturerender->enable();
viewport->render(camera);
texturerender->disable();
Arguments
- Camera camera - Camera an image from which should be rendered.
void render(Camera camera, int width, int height)
Renders an image of the specified size from the specified camera to the current rendering target.Arguments
- Camera camera - Camera, an image from which should be rendered.
- int width - Image width, in pixels.
- int height - Image height, in pixels.
void renderImage2D(Camera camera, Image image)
Renders an image from the camera to the given 2D image.Arguments
- Camera camera - Camera, an image from which should be rendered.
- Image image - Target 2D image to save the result to.
void renderImage2D(Camera camera, Image image, int width, int height, int hdr = 0)
Renders an image of the specified size from the camera to the 2D image.Arguments
- Camera camera - Camera, an image from which should be rendered.
- Image image - Target 2D image to save the result to.
- int width - Image width, in pixels.
- int height - Image height, in pixels.
- int hdr - HDR flag.
void renderImageCube(Camera camera, Image image, int size, int hdr = 0, int local_space = 0)
Renders the image from the camera to the cube map of the specified size.Arguments
- Camera camera - Camera, an image from which should be rendered.
- Image image - Target cube map to save the result to.
- int size - Cube map edge size.
- int hdr - HDR flag.
- int local_space - A flag indicating if the camera angle should be used for the cube map rendering.
void renderImageCube(Camera camera, Image image)
Renders the image from the camera into the cube map.Arguments
- Camera camera - Camera, an image from which should be rendered.
- Image image - Target cube map to save the result to.
void renderNode(Camera camera, Node node)
Renders the given node with all children to the current rendering target.Arguments
- Camera camera - Camera, an image from which should be rendered.
- Node node - Node to be rendered.
void renderNode(Camera camera, Node node, int width, int height)
Renders the given node with all children to the current rendering target.Arguments
- Camera camera - Camera, an image from which should be rendered.
- Node node - Node to be rendered.
- int width - Image width, in pixels.
- int height - Image height, in pixels.
void renderNodeImage2D(Camera camera, Node node, Image image, int width, int height, int hdr)
Renders the given node with all children to the 2D image of the specified size.Arguments
- Camera camera - Camera, an image from which should be rendered.
- Node node - Node to be rendered.
- Image image - Target 2D image to save the result to.
- int width - Image width, in pixels.
- int height - Image height, in pixels.
- int hdr - HDR flag.
void renderNodeImage2D(Camera camera, Node node, Image image)
Renders the given node with all children to the specified 2D image.Arguments
- Camera camera - Camera, an image from which should be rendered.
- Node node - Node to be rendered.
- Image image - Target 2D image to save the result to.
void renderNodeTexture2D(Camera camera, Node node, Texture texture)
Renders the given node with all children to the specified 2D texture.Arguments
- Camera camera - Camera, an image from which should be rendered.
- Node node - Node to be rendered.
- Texture texture - Target 2D texture to save the result to.
void renderStereo(Camera camera_left, Camera camera_right, string stereo_material)
Renders a stereo image in the current viewport.Arguments
- Camera camera_left - Camera that renders an image for the left eye.
- Camera camera_right - Camera that renders an image for the right eye.
- string stereo_material - List of names of stereo materials to be used.
void renderTexture2D(Camera camera, Texture texture)
Renders an image from the camera to the specified 2D texture.Arguments
- Camera camera - Camera, an image from which should be rendered.
- Texture texture - Target 2D texture to save the result to.
int VIEWPORT_MODE_DEFAULT
Description
Enables the default stereo mode - no stereo and panoramic rendering in the current viewport is available. This mode is set by default for a new viewport.int VIEWPORT_MODE_PANORAMA_180_CURVED
Description
Enables rendering of the viewport as a 180-degree panorama with curved edges.int VIEWPORT_MODE_PANORAMA_180_FISHEYE
Description
Enables rendering of the viewport as a 180-degree spherical panorama (fisheye).int VIEWPORT_MODE_PANORAMA_180_LINEAR
Description
Enables rendering of the viewport as a 180-degree linear panorama without distortion at the edges.int VIEWPORT_MODE_PANORAMA_360_CURVED
Description
Enables rendering of the viewport as a 360-degree panorama with curved edges.int VIEWPORT_MODE_PANORAMA_360_FISHEYE
Description
Enables rendering of the viewport as a 360-degree spherical panorama (fisheye).int VIEWPORT_MODE_PANORAMA_360_LINEAR
Description
Enables rendering of the viewport as a 360-degree linear panorama without distortion at the edges.int VIEWPORT_MODE_STEREO_ANAGLYPH
Description
Enables the anaglyph stereo mode that is viewed with red-cyan anaglyph glasses.int VIEWPORT_MODE_STEREO_HORIZONTAL
Description
Enables the horizontal stereo mode that is supported on mobile devices.int VIEWPORT_MODE_STEREO_INTERLACED
Description
Enables the interlaced stereo mode that is used with interlaced stereo monitors and polarized 3D glasses.int VIEWPORT_MODE_STEREO_REPLICATE
Description
Enables the separate images stereo mode. This mode serves to output two separate images for each of the eye. It can be used with any VR/AR output devices that support separate images output, e.g. for 3D video glasses or helmets (HMD).int VIEWPORT_MODE_STEREO_SEPARATE
Description
Enables the replicate images stereo mode.int VIEWPORT_MODE_STEREO_VERTICAL
Description
Enables the vertical stereo mode that is supported on mobile devices.int VIEWPORT_SKIP_DYNAMIC_REFLECTIONS
Description
Skip rendering of dynamic reflections in the viewport.int VIEWPORT_SKIP_FORMAT_RG11B10
Description
Skip rendering of RG11B10 formats in the viewport.int VIEWPORT_SKIP_POSTEFFECTS
Description
Skip rendering of post effects in the viewport.int VIEWPORT_SKIP_SHADOWS
Description
Skip shadows rendering in the viewport.int VIEWPORT_SKIP_SRGB
Description
Skip rendering of the srgb color space.int VIEWPORT_SKIP_STREAMING
Description
Disables data streaming in the process of rendering.int VIEWPORT_SKIP_TRANSPARENT
Description
Skip rendering of transparent objects in the viewport.int VIEWPORT_SKIP_VELOCITY_BUFFER
Description
Skip rendering to the velocity buffer for the viewport.int VIEWPORT_SKIP_VISUALIZER
Description
Skip rendering of the visualizer in the viewport. This flag is set by default for a new viewport.int VIEWPORT_USAGE_AUX_LIGHT
Description
Use lighting from the auxiliary virtual scene containing one LightWorld (with 45, 45 and 45 degrees slope angles), scattering is not used.int VIEWPORT_USAGE_NODE_LIGHT
Description
Use the node lighting.int VIEWPORT_USAGE_WORLD_LIGHT
Description
Use lighting from the LightWorld set in the current loaded world.int VIEWPORT_NUM_CALLBACKS
Description
Callback counter.int VIEWPORT_CALLBACK_ALL
Description
Callbacks before all stages.int VIEWPORT_CALLBACK_BEGIN
Description
Beginning of the callback range.int VIEWPORT_CALLBACK_END
Description
End of the callback range.int VIEWPORT_CALLBACK_BEGIN_ADAPTIVE_EXPOSURE
Description
Callback before the adaptive exposure stage.int VIEWPORT_CALLBACK_END_ADAPTIVE_EXPOSURE
Description
Callback after the adaptive exposure stage.int VIEWPORT_CALLBACK_BEGIN_AUXILIARY_BUFFER
Description
Callback before filling the auxiliary buffer.int VIEWPORT_CALLBACK_END_AUXILIARY_BUFFER
Description
Callback after filling the auxiliary buffer.int VIEWPORT_CALLBACK_BEGIN_CAMERA_EFFECTS
Description
Callback before the camera effects stage.int VIEWPORT_CALLBACK_END_CAMERA_EFFECTS
Description
Callback after the camera effects stage.int VIEWPORT_CALLBACK_BEGIN_CLOUDS
Description
Callback before the clouds rendering stage.int VIEWPORT_CALLBACK_END_CLOUDS
Description
Callback after the clouds rendering stage.int VIEWPORT_CALLBACK_BEGIN_COMPOSITE_DEFERRED
Description
Callback before the clouds deferred composite stage.int VIEWPORT_CALLBACK_END_COMPOSITE_DEFERRED
Description
Callback after the clouds deferred composite stage.int VIEWPORT_CALLBACK_BEGIN_DEBUG_MATERIALS
Description
Callback before the debug materials stage.int VIEWPORT_CALLBACK_END_DEBUG_MATERIALS
Description
Callback after the debug materials stage.int VIEWPORT_CALLBACK_BEGIN_OPACITY_DECALS
Description
Callback before the opacity decals rendering stage.int VIEWPORT_CALLBACK_END_OPACITY_DECALS
Description
Callback after the opacity decals rendering stage.int VIEWPORT_CALLBACK_BEGIN_OPACITY_ENVIRONMENT_PROBES
Description
Callback before the opacity environment probes rendering stage.int VIEWPORT_CALLBACK_END_OPACITY_ENVIRONMENT_PROBES
Description
Callback after the opacity environment probes rendering stage.int VIEWPORT_CALLBACK_BEGIN_OPACITY_GBUFFER
Description
Callback before filling the Gbuffer.int VIEWPORT_CALLBACK_END_OPACITY_GBUFFER
Description
Callback after filling the Gbuffer.int VIEWPORT_CALLBACK_BEGIN_OPACITY_LIGHTS
Description
Callback before the opacity lightgs rendering stage.int VIEWPORT_CALLBACK_END_OPACITY_LIGHTS
Description
Callback after the opacity lightgs rendering stage.int VIEWPORT_CALLBACK_BEGIN_POST_MATERIALS
Description
Callback before the post materials rendering stage.int VIEWPORT_CALLBACK_END_POST_MATERIALS
Description
Callback after the post materials rendering stage.int VIEWPORT_CALLBACK_BEGIN_REFRACTION_BUFFER
Description
Callback before filling the refraction buffer.int VIEWPORT_CALLBACK_END_REFRACTION_BUFFER
Description
Callback after filling the refraction buffer.int VIEWPORT_CALLBACK_BEGIN_SRGB_CORRECTION
Description
Callback before the sRGB correction stage.int VIEWPORT_CALLBACK_END_SRGB_CORRECTION
Description
Callback after the sRGB correction stage.int VIEWPORT_CALLBACK_BEGIN_SSAO
Description
Callback before the SSAO rendering stage.int VIEWPORT_CALLBACK_END_SSAO
Description
Callback after the SSAO rendering stage.int VIEWPORT_CALLBACK_BEGIN_SSGI
Description
Callback before the SSGI rendering stage.int VIEWPORT_CALLBACK_END_SSGI
Description
Callback after the SSGI rendering stage.int VIEWPORT_CALLBACK_BEGIN_SSR
Description
Callback before the SSR rendering stage.int VIEWPORT_CALLBACK_END_SSR
Description
Callback after the SSR rendering stage.int VIEWPORT_CALLBACK_BEGIN_SSRTGI
Description
Callback before the SSRTGI rendering stage.int VIEWPORT_CALLBACK_END_SSRTGI
Description
Callback after the SSRTGI rendering stage.int VIEWPORT_CALLBACK_BEGIN_TRANSPARENT_BLUR_BUFFER
Description
Callback before filling the transparent blur buffer.int VIEWPORT_CALLBACK_END_TRANSPARENT_BLUR_BUFFER
Description
Callback after filling the transparent blur buffer.int VIEWPORT_CALLBACK_BEGIN_TAA
Description
Callback before the Temporal Anti-Aliasing (TAA) pass.int VIEWPORT_CALLBACK_END_TAA
Description
Callback after the Temporal Anti-Aliasing (TAA) pass.int VIEWPORT_CALLBACK_BEGIN_TRANSPARENT
Description
Callback before the transparent objects rendering stage.int VIEWPORT_CALLBACK_END_TRANSPARENT
Description
Callback after the transparent objects rendering stage.int VIEWPORT_CALLBACK_BEGIN_VISUALIZER
Description
Callback before the visualizer rendering stage.int VIEWPORT_CALLBACK_END_VISUALIZER
Description
Callback after the visualizer rendering stage.int VIEWPORT_CALLBACK_BEGIN_WATER
Description
Callback before the water rendering stage.int VIEWPORT_CALLBACK_END_WATER
Description
Callback after the water rendering stage.int VIEWPORT_CALLBACK_BEGIN_WATER_DECALS
Description
Callback before the water decals rendering stage.int VIEWPORT_CALLBACK_END_WATER_DECALS
Description
Callback after the water decals rendering stage.int VIEWPORT_CALLBACK_BEGIN_WATER_ENVIRONMENT_PROBES
Description
Callback before the water environment probes rendering stage.int VIEWPORT_CALLBACK_END_WATER_ENVIRONMENT_PROBES
Description
Callback after the water environment probes rendering stage.int VIEWPORT_CALLBACK_BEGIN_WATER_LIGHTS
Description
Callback before the water lights rendering stage.int VIEWPORT_CALLBACK_END_WATER_LIGHTS
Description
Callback after the water lights rendering stage.int VIEWPORT_RENDER_DEPTH
Description
Render only depth.int VIEWPORT_RENDER_DEPTH_GBUFFER
Description
Render only depth and Gbuffer.int VIEWPORT_RENDER_DEPTH_GBUFFER_FINAL
Description
Render depth, Gbuffer and final image.Last update: 2017-12-21
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)