/****************************************************************************
* Copyright 2019 Nreal Techonology Limited. All rights reserved.
*
* This file is part of NRSDK.
*
* https://www.nreal.ai/
*
*****************************************************************************/
namespace NRKernal
{
using System;
using UnityEngine;
using System.Runtime.InteropServices;
/// Callback, called when the nr display resolution.
/// The width.
/// The height.
public delegate void NRDisplayResolutionCallback(int width, int height);
/// HMD Eye offset Native API .
internal partial class NativeMultiDisplay
{
/// Handle of the multi display.
private UInt64 m_MultiDisplayHandle;
/// Creates a new bool.
/// True if it succeeds, false if it fails.
public bool Create()
{
NativeResult result = NativeApi.NRDisplayCreate(ref m_MultiDisplayHandle);
NativeErrorListener.Check(result, this, "Create", true);
return result == NativeResult.Success;
}
/// Initializes the color space.
public void InitColorSpace()
{
NativeColorSpace colorspace = QualitySettings.activeColorSpace == ColorSpace.Gamma ?
NativeColorSpace.COLOR_SPACE_GAMMA : NativeColorSpace.COLOR_SPACE_LINEAR;
NativeResult result = NativeApi.NRDisplayInitSetTextureColorSpace(m_MultiDisplayHandle, colorspace);
NativeErrorListener.Check(result, this, "InitColorSpace");
}
/// Starts this object.
public void Start()
{
NativeResult result = NativeApi.NRDisplayStart(m_MultiDisplayHandle);
NativeErrorListener.Check(result, this, "Start", true);
}
/// Listen main screen resolution changed.
/// The callback.
public void ListenMainScrResolutionChanged(NRDisplayResolutionCallback callback)
{
NativeResult result = NativeApi.NRDisplaySetMainDisplayResolutionCallback(m_MultiDisplayHandle, callback);
NativeErrorListener.Check(result, this, "ListenMainScrResolutionChanged");
}
/// Stops this object.
public void Stop()
{
NativeResult result = NativeApi.NRDisplayStop(m_MultiDisplayHandle);
NativeErrorListener.Check(result, this, "Stop");
}
/// Updates the home screen texture described by rendertexture.
/// The rendertexture.
/// True if it succeeds, false if it fails.
public bool UpdateHomeScreenTexture(IntPtr rendertexture)
{
NativeResult result = NativeApi.NRDisplaySetMainDisplayTexture(m_MultiDisplayHandle, rendertexture);
NativeErrorListener.Check(result, this, "UpdateHomeScreenTexture");
return result == NativeResult.Success;
}
/// Pauses this object.
/// True if it succeeds, false if it fails.
public bool Pause()
{
NativeResult result = NativeApi.NRDisplayPause(m_MultiDisplayHandle);
NativeErrorListener.Check(result, this, "Pause");
return result == NativeResult.Success;
}
/// Resumes this object.
/// True if it succeeds, false if it fails.
public bool Resume()
{
NativeResult result = NativeApi.NRDisplayResume(m_MultiDisplayHandle);
NativeErrorListener.Check(result, this, "Resume");
return result == NativeResult.Success;
}
/// Destroys this object.
/// True if it succeeds, false if it fails.
public bool Destroy()
{
NativeResult result = NativeApi.NRDisplayDestroy(m_MultiDisplayHandle);
NativeErrorListener.Check(result, this, "Destroy");
return result == NativeResult.Success;
}
/// A native api.
private struct NativeApi
{
/// Nr display create.
/// [in,out] Handle of the out display.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRDisplayCreate(ref UInt64 out_display_handle);
/// Callback, called when the nr display set main display resolution.
/// The display handle.
/// The resolution callback.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRDisplaySetMainDisplayResolutionCallback(UInt64 display_handle,
NRDisplayResolutionCallback resolution_callback);
/// Nr display initialize set texture color space.
/// The display handle.
/// The color space.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRDisplayInitSetTextureColorSpace(UInt64 display_handle,
NativeColorSpace color_space);
/// Nr display start.
/// The display handle.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRDisplayStart(UInt64 display_handle);
/// Nr display stop.
/// The display handle.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRDisplayStop(UInt64 display_handle);
/// Nr display pause.
/// The display handle.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRDisplayPause(UInt64 display_handle);
/// Nr display resume.
/// The display handle.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRDisplayResume(UInt64 display_handle);
/// Nr display set main display texture.
/// The display handle.
/// The controller texture.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRDisplaySetMainDisplayTexture(UInt64 display_handle,
IntPtr controller_texture);
/// Nr display destroy.
/// The display handle.
/// A NativeResult.
[DllImport(NativeConstants.NRNativeLibrary)]
public static extern NativeResult NRDisplayDestroy(UInt64 display_handle);
};
}
}