RenderTextureOutput

class NatML.Devices.Outputs.RenderTextureOutput : CameraOutput

The RenderTextureOutput streams CameraImage instances into a RenderTexture.

Unlike the TextureOutput, this output performs all conversions on the GPU. As such, it typically has better performance when pixel data access is not needed.

The RenderTextureOutput is not supported on WebGL, due to a lack of support for compute shaders on the platform.

Creating the Output

/// <summary>
/// Create a RenderTexture output.
/// </summary>
RenderTextureOutput ();

The render texture output is trivially constructed.

Specifying the Orientation

/// <summary>
/// Get or set the texture orientation.
/// </summary>
ScreenOrientation orientation { get; set; }

The render texture output supports specifying the desired output orientation of the converted texture.

This property is especially useful on mobile devices where camera images are always returned in the "natural orientation" of the camera device.

This property is only supported on Android and iOS.

Updating with New Images

/// <summary>
/// Update the output with a new camera image.
/// </summary>
/// <param name="image">Camera image.</param>
void Update (CameraImage image);

The output will upload the CameraImage into a RenderTexture. The output supports specifying options that are used when converting the image:

/// <summary>
/// Update the output with a new camera image.
/// </summary>
/// <param name="image">Camera image.</param>
/// <param name="options">Conversion options.</param>
void Update (CameraImage image, ConversionOptions options);

The provided options can be null, in which case reasonable defaults are used.

Conversion Options

/// <summary>
/// Texture conversion options.
/// </summary>
class ConversionOptions {
    /// <summary>
    /// Desired pixel buffer orientation.
    /// </summary>
    ScreenOrientation orientation;
    /// <summary>
    /// Whether to vertically mirror the pixel buffer.
    /// </summary>
    bool mirror;
}

The ConversionOptions expose some options that can be used when performing the conversion.

Accessing the Texture

/// <summary>
/// Texture containing the latest camera image.
/// </summary>
RenderTexture texture { get; }

When the output has been updated with a CameraImage, the texture will contain the converted pixel data in the correct pixel format and orientation on the GPU.

Disposing the Output

/// <summary>
/// Dispose the camera output and release resources.
/// </summary>
void Dispose ();

Refer to the Disposing the Output section of the CameraOutput class for more information.

Last updated