// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using UnityEngine;
using UnityEngine.XR;
namespace Microsoft.MixedReality.WebRTC.Unity
{
///
/// Attribute for a property used by
/// to capture the content of a framebuffer, and for which some constraints on stereoscopic rendering
/// options need to be enforced (and errors can be reported in the Editor if they are not followed).
///
///
public class CaptureCameraAttribute : PropertyAttribute
{
///
/// Validate that a given instance can be used for framebuffer
/// capture by based on the XR settings currently in effect.
///
/// The camera instance to test the settings of.
///
/// The camera has settings not compatible with its use with .
///
///
public static void Validate(Camera camera)
{
if (camera != null)
{
if (XRSettings.stereoRenderingMode == XRSettings.StereoRenderingMode.MultiPass)
{
// Ensure camera is not rendering to both eyes in multi-pass stereo, otherwise the command buffer
// is executed twice (once per eye) and will produce twice as many frames, which leads to stuttering
// when playing back the video stream resulting from combining those frames.
if (camera.stereoTargetEye == StereoTargetEyeMask.Both)
{
throw new NotSupportedException("Capture camera renders both eyes in multi-pass stereoscopic rendering. This is not" +
" supported by the capture mechanism which cannot discriminate them. Set Camera.stereoTargetEye to either Left or" +
" Right, or use a different XRSettings.stereoRenderingMode.");
}
}
#if !UNITY_2019_1_OR_NEWER
else if ((XRSettings.stereoRenderingMode == XRSettings.StereoRenderingMode.SinglePassInstanced)
|| (XRSettings.stereoRenderingMode == XRSettings.StereoRenderingMode.SinglePassMultiview)) // same as instanced (OpenGL)
{
throw new NotSupportedException("Capture camera does not support single-pass instanced stereoscopic rendering before Unity 2019.1.");
}
#endif
}
}
}
}