diff --git a/deps/Fove/FoveClient.dll b/deps/Fove/FoveClient.dll deleted file mode 100644 index 2a74259267..0000000000 --- a/deps/Fove/FoveClient.dll +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:23e1e7592268131e31dfa51506544eb00bae297d3249ba8e8911a4ed88f6edc1 -size 1720376 diff --git a/deps/Fove/FoveTypes.h b/deps/Fove/FoveTypes.h deleted file mode 100644 index 7349397299..0000000000 --- a/deps/Fove/FoveTypes.h +++ /dev/null @@ -1,386 +0,0 @@ -#pragma once - -#ifndef _FOVETYPES_H -#define _FOVETYPES_H - -#ifdef __GNUC__ -#define FVR_DEPRECATED(func) func __attribute__ ((deprecated)) -#define FVR_EXPORT __attribute__((visibility("default"))) -#elif defined(_MSC_VER) -#define FVR_DEPRECATED(func) __declspec(deprecated) func -#define FVR_EXPORT __declspec(dllexport) -#else -#pragma message("WARNING: You need to implement DEPRECATED for this compiler") -#define FVR_DEPRECATED(func) func -#define FVR_EXPORT -#endif - -#include "../NativePath/standard/math.h" -#include "../NativePath/standard/stdint.h" - -namespace Fove -{ - //! EFVR_ClientCapabilities - /*! To be passed to the initialisation function of the client library to */ - enum class EFVR_ClientCapabilities - { - Gaze = 0x01, - Orientation = 0x02, - Position = 0x04 - }; - - inline EFVR_ClientCapabilities operator|(EFVR_ClientCapabilities a, EFVR_ClientCapabilities b) - { - return static_cast(static_cast(a) | static_cast(b)); - } - inline EFVR_ClientCapabilities operator&(EFVR_ClientCapabilities a, EFVR_ClientCapabilities b) - { - return static_cast(static_cast(a) & static_cast(b)); - } - - //! EFVR_ErrorCode enum - /*! An enum of error codes that the system may return from GetLastError(). These will eventually be mapped to localised strings. */ - enum class EFVR_ErrorCode - { - None = 0, - - //! Connection Errors - Connection_General = 1, - Connect_NotConnected = 7, - Connect_ServerUnreachable = 2, - Connect_RegisterFailed = 3, - Connect_DeregisterFailed = 6, - Connect_WrongRuntimeVersion = 4, - Connect_HeartbeatNoReply = 5, - - //! Data Errors - Data_General = 10, - Data_RegisteredWrongVersion = 11, - Data_UnreadableNotFound = 12, - Data_NoUpdate = 13, - Data_Uncalibrated = 14, - - //! Hardware Errors - Hardware_General = 20, - Hardware_CoreFault = 21, - Hardware_CameraFault = 22, - Hardware_IMUFault = 23, - Hardware_ScreenFault = 24, - Hardware_SecurityFault = 25, - Hardware_Disconnected = 26, - Hardware_WrongFirmwareVersion = 27, - - //! Server Response Errors - Server_General = 30, - Server_HardwareInterfaceInvalid = 31, - Server_HeartbeatNotRegistered = 32, - Server_DataCreationError = 33, - Server_ModuleError_ET = 34, - - //! Code and placeholders - Code_NotImplementedYet = 40, - Code_FunctionDeprecated = 41, - - //! Position Tracking - Position_NoObjectsInView = 50, - Position_NoDlibRegressor = 51, - Position_NoCascadeClassifier = 52, - Position_NoModel = 53, - Position_NoImages = 54, - Position_InvalidFile = 55, - Position_NoCamParaSet = 56, - Position_CantUpdateOptical = 57, - Position_ObjectNotTracked = 58, - - //! Eye Tracking - Eye_Left_NoDlibRegressor = 60, - Eye_Right_NoDlibRegressor = 61, - }; - - //! EFVR_DataType enum - /*! The different data types that are passed internally within the FoveVR system. - Clients can subscribe to these (the default is to subscribe all at the moment). - */ - enum class EFVR_DataType - { - HeadsetState = 0, // headsetState -> SFVR_HeadsetState_2 - Orientation = 1, // headOrientation -> SFVR_HeadOrientation // deprecated. replaced with Position entirely now (contains orientation AND estimated position) - Position = 2, // pose -> SFVR_Positions // updated from SFVR_Pose as that had no ability to hold predicted results - Gaze = 3, // gaze -> SFVR_Gaze_2 - ImageData = 4, // eyeImage -> SFVR_EyeImage - Message = 5, // message -> char* \0 terminated - PositionImage = 6 // posImage -> SFVR_EyeImage - }; - - //! EFVR_ClientType - /*! Corresponds to the order in which clients are composited (Base, then Overlay, then Diagnostic) */ - enum class EFVR_ClientType - { - Base = 0, - OverlayWorld = 0x10000, - OverlayScreen = 0x20000, - Diagnostic = 0x30000 - }; - - //! SFVR_Quaternion struct - /*! A quaternion represents an orientation in 3d space.*/ - struct SFVR_Quaternion - { - float x = 0; - float y = 0; - float z = 0; - float w = 1; - - SFVR_Quaternion() = default; - SFVR_Quaternion(float ix, float iy, float iz, float iw) : x(ix), y(iy), z(iz), w(iw) {} - - //! Generate and return a conjugate of this quaternion - SFVR_Quaternion Conjugate() const - { - return SFVR_Quaternion(-x, -y, -z, w); - } - - SFVR_Quaternion Normalize() const - { - float d = sqrt(w*w + x*x + y*y + z*z); - SFVR_Quaternion result(x / d, y / d, z / d, w / d); - return result; - } - - //! Return the result of multiplying this quaternion Q1 by another Q2 such that OUT = Q1 * Q2 - SFVR_Quaternion MultiplyBefore(const SFVR_Quaternion &second) const - { - auto nx = x * second.w + y * second.z - z * second.y + w * second.x; - auto ny = -x * second.z + y * second.w + z * second.x + w * second.y; - auto nz = x * second.y - y * second.x + z * second.w + w * second.z; - auto nw = -x * second.x - y * second.y - z * second.z + w * second.w; - return SFVR_Quaternion(nx, ny, nz, nw); - } - - //! Return the result of multiplying this quaternion Q2 by another Q1 such that OUT = Q1 * Q2 - SFVR_Quaternion MultiplyAfter(const SFVR_Quaternion &first) const - { - auto nx = first.x * w + first.y * z - first.z * y + first.w * x; - auto ny = -first.x * z + first.y * w + first.z * x + first.w * y; - auto nz = first.x * y - first.y * x + first.z * w + first.w * z; - auto nw = -first.x * x - first.y * y - first.z * z + first.w * w; - return SFVR_Quaternion(nx, ny, nz, nw); - } - }; - - //! SFVR_HeadOrientation struct - /*! Represents the orientation of the Fove headset in 3d space along with some meta-information about how old this data is. */ - struct SFVR_HeadOrientation - { - //! Error Code - /*! error: if true => the rest of the data is in an unknown state. */ - EFVR_ErrorCode error = EFVR_ErrorCode::None; - //! ID - /*! Incremental counter which tells if the coord captured is a fresh value at a given frame */ - uint64_t id = 0; - //! Timestamp - /*! The time at which the coord was captured, based on system time */ - uint64_t timestamp = 0; - //! Quaternion - /*! The Quaternion which represents the orientation of the head. */ - SFVR_Quaternion quat; - }; - - //! SFVR_Vec3 struct - /*! A vector that represents an position in 3d space. */ - struct SFVR_Vec3 - { - float x = 0; - float y = 0; - float z = 0; - - SFVR_Vec3() = default; - SFVR_Vec3(float ix, float iy, float iz) : x(ix), y(iy), z(iz) {} - }; - - //! SFVR_Vec2 struct - /*! A vector that represents an position in 2d space. Usually used when refering to screen or image coordinates. */ - struct SFVR_Vec2 - { - float x = 0; - float y = 0; - - SFVR_Vec2() = default; - SFVR_Vec2(float ix, float iy) : x(ix), y(iy) {} - }; - - //! SFVR_Pose struct - /*! This structure is a combination of the Fove headset position and orientation in 3d space, collectively known as the "pose". - In the future this may also contain accelleration information for the headset, and may also be used for controllers. - */ - struct SFVR_Pose - { - //! Error Code - /*! error: if true => the rest of the data is in an unknown state. */ - EFVR_ErrorCode error = EFVR_ErrorCode::None; - //! ID - /*! Incremental counter which tells if the coord captured is a fresh value at a given frame */ - uint64_t id = 0; - //! Timestamp - /*! The time at which the coord was captured, based on system time */ - uint64_t timestamp = 0; - //! Quaternion - /*! The Quaternion which represents the orientation of the head. */ - SFVR_Quaternion orientation; - //! Vector3 - /*! The position of headset in 3D space */ - SFVR_Vec3 position; - }; - - //! SFVR_WorldGaze struct - /*! FUTURE USE ONLY: The vector (from the center of the player's head in game space) that represents the point that the user is looking at. - The accuracy is the radius of the sphere in meters of this information. - */ - struct SFVR_WorldGaze - { - EFVR_ErrorCode error = EFVR_ErrorCode::None; - uint64_t id = 0; - uint64_t timestamp = 0; - float accuracy = 0; - SFVR_Vec3 left_vec = { 0, 0, 1 }; - SFVR_Vec3 right_vec = { 0, 0, 1 }; - SFVR_Vec3 convergence = { 0, 0, 1 }; - }; - - //! SFVR_GazeScreenCoord struct - /*! The coordinate on the screen that the user is looking at. (0,0 is the top left) */ - struct SFVR_GazeScreenCoord - { - //! Error Code - /*! error: if true => the rest of the data is in an unknown state. */ - EFVR_ErrorCode error = EFVR_ErrorCode::None; - //! ID - /*! Incremental counter which tells if the coord captured is a fresh value at a given frame */ - uint64_t id = 0; - //! Timestamp - /*! The time at which the coord was captured, based on system time */ - uint64_t timestamp = 0; - //! Vector2 - /*! The Coordinate position is based on the Normalized 0,1 plane */ - SFVR_Vec2 coord; - }; - - //! SFVR_EyeImage struct - /*! DEPRICATED: For researcher use only, To be Moved to Fove Internal Types */ - struct SFVR_EyeImage - { - EFVR_ErrorCode error = EFVR_ErrorCode::None; - uint8_t eye = 0; - uint64_t frameNumber = 0; - uint32_t length = 0; - uint64_t timestamp = 0; - unsigned char* imageData = nullptr; - }; - - //! SFVR_CalibrationTarget struct - /*! To be Moved to Fove Internal Types */ - struct SFVR_CalibrationTarget - { - bool isCalibrationComplete = false; - float x = 0; - float y = 0; - float z = 0; - float scale = 0; - }; - - //! EFVR_Eye enum - /*! This is usually returned with any eye tracking information and tells the client which eye(s) the information is based on. */ - enum class EFVR_Eye - { - Neither = 0, - Left = 1, - Right = 2, - Both = 3 - }; - - //! SFVR_Matrix44 struct - /*! A rectangular array of numbers, symbols, or expressions, arranged in rows and columns. */ - struct SFVR_Matrix44 - { - float mat[4][4] = {}; - }; - - //! SFVR_Matrix34 struct - /*! A rectangular array of numbers, symbols, or expressions, arranged in rows and columns. */ - struct SFVR_Matrix34 - { - float mat[3][4] = {}; - }; - - //! EFVR_CompositorError enum - /*! Errors pertaining to Compositor */ - enum class EFVR_CompositorError - { - None = 0, - - UnableToCreateDeviceAndContext = 100, - UnableToUseTexture = 101, - DeviceMismatch = 102, - IncompatibleCompositorVersion = 103, - - UnableToFindRuntime = 200, - RuntimeAlreadyClaimed = 201, - DisconnectedFromRuntime = 202, - - ErrorCreatingShaders = 300, - ErrorCreatingTexturesOnDevice = 301, - - NoEyeSpecifiedForSubmit = 400, - - UnknownError = 99999, - }; - - //! EFVR_GraphicsAPI enum - /*! Type of Graphics API */ - enum class EFVR_GraphicsAPI - { - DirectX, - OpenGL - }; - - //! SFVR_CompositorTexture struct - /*! Texture structure used by the Compositor */ - struct SFVR_CompositorTexture - { - //! Texture Pointer - /*! D3D: Native texture pointer - OpenGL: Pointer to a texture ID */ - void* pTexture = nullptr; - EFVR_GraphicsAPI api = EFVR_GraphicsAPI::DirectX; - }; - - //! SFVR_TextureBounds struct - /*! Coordinates in normalized space where 0 is left/top and 1 is bottom/right */ - struct SFVR_TextureBounds - { - float left = 0, top = 0, right = 0, bottom = 0; - }; - - // Logging extensions to write common types to the fove log - class Log; - Log& operator << (Log&, EFVR_ClientCapabilities); - Log& operator << (Log&, EFVR_ErrorCode); - Log& operator << (Log&, EFVR_DataType); - Log& operator << (Log&, EFVR_ClientType); - Log& operator << (Log&, EFVR_Eye); - Log& operator << (Log&, EFVR_CompositorError); - Log& operator << (Log&, EFVR_GraphicsAPI); - Log& operator << (Log&, const SFVR_Quaternion&); - Log& operator << (Log&, const SFVR_HeadOrientation&); - Log& operator << (Log&, const SFVR_Vec3&); - Log& operator << (Log&, const SFVR_Vec2&); - Log& operator << (Log&, const SFVR_Pose&); - Log& operator << (Log&, const SFVR_WorldGaze&); - Log& operator << (Log&, const SFVR_GazeScreenCoord&); - Log& operator << (Log&, const SFVR_EyeImage&); - Log& operator << (Log&, const SFVR_CalibrationTarget&); - Log& operator << (Log&, const SFVR_Matrix44&); - Log& operator << (Log&, const SFVR_Matrix34&); - Log& operator << (Log&, const SFVR_TextureBounds&); -} -#endif // _FOVETYPES_H \ No newline at end of file diff --git a/deps/Fove/IFVRCompositor.h b/deps/Fove/IFVRCompositor.h deleted file mode 100644 index 1071a3eac2..0000000000 --- a/deps/Fove/IFVRCompositor.h +++ /dev/null @@ -1,86 +0,0 @@ -#pragma once - -#ifndef _IFVRCOMPOSITOR_H -#define _IFVRCOMPOSITOR_H - -#include "FoveTypes.h" - -namespace Fove -{ - class IFVRCompositor - { - public: - - //!-- Submit a frame to the compositor - /*! This functions takes your feed from your game engine to render the texture to each eye - \param pTexture The Texture pointer pointing to the location of the actualt texture to be rendered to the FoveHMD - \param api Type of Graphics API: DirectX or OpenGL - \param whichEye Defines which eye to render the given texture to, Note: You will need to render for each eye seperately since the view vector for each eye is different - \param bounds The bounds for the texture to be displayed - \param orientation The orientation used to render this frame - */ - // Deprecated in v0.6.2 released 2nd Sep 2016 - virtual FVR_DEPRECATED(EFVR_CompositorError Submit( - void* pTexture, - EFVR_GraphicsAPI api, - EFVR_Eye whichEye, - SFVR_TextureBounds bounds, - SFVR_HeadOrientation orientation)) = 0; - - //!-- Submit a frame to the compositor - /*! This functions takes your feed from your game engine to render the texture to each eye - \param pTexture The Texture pointer pointing to the location of the actualt texture to be rendered to the FoveHMD - \param api Type of Graphics API: DirectX or OpenGL - \param whichEye Defines which eye to render the given texture to, Note: You will need to render for each eye seperately since the view vector for each eye is different - \param bounds The bounds for the texture to be displayed - \param pose The pose struct used for rendering this frame - */ - virtual EFVR_CompositorError Submit( - void* pTexture, - EFVR_GraphicsAPI api, - EFVR_Eye whichEye, - SFVR_TextureBounds bounds, - SFVR_Pose pose) = 0; - - /* Submit a frame to the compositor - * - * This functions takes your feed from your game engine to render the texture to each eye. The pose of the - * submitted frames is determined by the last call to "WaitForRenderPose()". If you aren't using that system, - * then you should use the - * - * \param pTexture The Texture pointer pointing to the location of the actualt texture to be rendered to the FoveHMD - * \param api Type of Graphics API: DirectX or OpenGL - * \param whichEye Defines which eye to render the given texture to, Note: You will need to render for each eye seperately since the view vector for each eye is different - * \param bounds The bounds for the texture to be displayed - */ - virtual EFVR_CompositorError Submit( - void* pTexture, - EFVR_GraphicsAPI api, - EFVR_Eye whichEye, - SFVR_TextureBounds bounds) = 0; - - //!-- Set whether or not to show a mirror window of what's being sent to the compositor - /*! Opens a window if the option is set to true or not - Currently, this function is broken and causes things to crash. Do not use yet! - \param shouldShow bool variable to show or not show the Fove HMD mirror on Desktop system - */ - virtual void ShowMirrorWindow(bool shouldShow) = 0; - - //!-- Wait until it's time to start rendering, getting the most current poses in the process - virtual SFVR_Pose WaitForRenderPose() = 0; - - //!-- Tell the compositor that the client is done submitting textures this frame - virtual void SignalFrameComplete() = 0; - - //!-- Shut down the compositor - /*! This function releases the threads, closes the mirrow window, and the closes the backend renderer*/ - virtual void Shutdown() = 0; - - //!-- Destructor - virtual ~IFVRCompositor() {} - }; - - FVR_EXPORT IFVRCompositor* GetFVRCompositor(EFVR_ClientType clientType = EFVR_ClientType::Base); -} - -#endif // _IFVRCOMPOSITOR_H \ No newline at end of file diff --git a/deps/Fove/IFVRHeadset.h b/deps/Fove/IFVRHeadset.h deleted file mode 100644 index 61c0f41acd..0000000000 --- a/deps/Fove/IFVRHeadset.h +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once - -#ifndef _IFVRHEADSET_H -#define _IFVRHEADSET_H - -#include "FoveTypes.h" - -namespace Fove -{ - class IFVRHeadset - { - public: - // members - // General - virtual bool Initialise() = 0; - virtual bool Initialise(EFVR_ClientCapabilities capabilities) = 0; - //! hardware connected - virtual bool IsHardwareConnected() = 0; - //! the hardware for their requested capabilities started - virtual bool IsHardwareReady() = 0; - // Deprecated in v0.7.3 released after 30th Sep 2016 - virtual FVR_DEPRECATED(bool IsHeadsetMounted()) = 0; - // Deprecated in v0.6.2 released 2nd Sep 2016 - virtual FVR_DEPRECATED(float GetVersion()) = 0; - virtual EFVR_ErrorCode CheckRuntimeVersion() = 0; - virtual EFVR_ErrorCode GetLastError() = 0; - - //! eye tracking - virtual SFVR_GazeScreenCoord GetGazePoint() = 0; - virtual SFVR_WorldGaze GetWorldGaze() = 0; - //! start and stop the subsystem - // Deprecated in v0.6.2 released 2nd Sep 2016 - virtual bool FVR_DEPRECATED(DisableEyeTracking()) = 0; - // Deprecated in v0.6.2 released 2nd Sep 2016 - virtual bool FVR_DEPRECATED(EnableEyeTracking()) = 0; - //! temp - virtual SFVR_EyeImage GetFrameData() = 0; - virtual SFVR_EyeImage GetPositionImageData() = 0; - //! status - virtual bool IsEyeTracking() = 0; - virtual bool IsEyeTrackingReady() = 0; - virtual bool IsCalibrated() = 0; - virtual bool IsCalibrating() = 0; - virtual EFVR_Eye CheckEyesClosed() = 0; - - //! motion sensor - virtual bool IsMotionReady() = 0; - // Deprecated in v0.6.1 released 29th Aug 2016 - virtual FVR_DEPRECATED(SFVR_HeadOrientation GetOrientation()) = 0; - virtual bool TareOrientationSensor() = 0; - - //! position tracking - virtual bool IsPositionReady() = 0; - // Deprecated in v0.6.1 released 29th Aug 2016 - virtual FVR_DEPRECATED(SFVR_Pose GetPosition()) = 0; - virtual bool TarePositionSensors() = 0; - - virtual SFVR_Pose GetHMDPose() = 0; - virtual SFVR_Pose GetPoseByIndex(int id) = 0; - - //! metrics - virtual SFVR_Matrix44 GetProjectionMatrixLH(EFVR_Eye whichEye, float zNear, float zFar) = 0; - virtual SFVR_Matrix44 GetProjectionMatrixRH(EFVR_Eye whichEye, float zNear, float zFar) = 0; - //! Returns values at 1 unit away. Please convert yourself by multiplying by zNear. - virtual void AssignRawProjectionValues(EFVR_Eye whichEye, float *l, float *r, float *t, float *b) = 0; - virtual SFVR_Matrix44 GetEyeToHeadMatrix(EFVR_Eye whichEye) = 0; - - //! calibration - virtual void StartCalibration() = 0; - virtual SFVR_CalibrationTarget TickCalibration(float deltaTime) = 0; - virtual EFVR_ErrorCode ManualDriftCorrection(float screenX, float screenY, EFVR_Eye eye) = 0; - virtual EFVR_ErrorCode ManualDriftCorrection3D(SFVR_Vec3 position) = 0; - - //! constructor & destructor - virtual ~IFVRHeadset(); - virtual void Destroy() = 0; - }; - - inline IFVRHeadset::~IFVRHeadset() { } - - FVR_EXPORT IFVRHeadset* GetFVRHeadset(); -} -#endif // _IFVRHEADSET_H \ No newline at end of file diff --git a/deps/GoogleVR/lib/Android/GoogleVRJava.dll b/deps/GoogleVR/lib/Android/GoogleVRJava.dll deleted file mode 100644 index 8573aa7466..0000000000 --- a/deps/GoogleVR/lib/Android/GoogleVRJava.dll +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:83afbf37ef70c1d226da1b99794b4e101402a61e1ae22e12ba2c57d06dc33774 -size 818688 diff --git a/deps/GoogleVR/lib/Android/android_arm/libgvr.so b/deps/GoogleVR/lib/Android/android_arm/libgvr.so deleted file mode 100644 index c32639b4b4..0000000000 --- a/deps/GoogleVR/lib/Android/android_arm/libgvr.so +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:5ffbde8311472544ea06c6e81d03ecf280d0c935a9fa96d0e102f41f2f4887e7 -size 903164 diff --git a/deps/GoogleVR/lib/Android/android_arm/libgvr_audio.so b/deps/GoogleVR/lib/Android/android_arm/libgvr_audio.so deleted file mode 100644 index 8d119753ee..0000000000 --- a/deps/GoogleVR/lib/Android/android_arm/libgvr_audio.so +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:6e4ad93f73473b81998153cca9b0d6bcf609e1fb2b228094ac9705f52a2d4799 -size 669176 diff --git a/deps/GoogleVR/lib/Android/android_arm64/libgvr.so b/deps/GoogleVR/lib/Android/android_arm64/libgvr.so deleted file mode 100644 index c4a5f4de34..0000000000 --- a/deps/GoogleVR/lib/Android/android_arm64/libgvr.so +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:3db5ffae71b0beeb32942da4cebfc5879c654af329ffc88343de47abf0e00c97 -size 1568064 diff --git a/deps/GoogleVR/lib/Android/android_arm64/libgvr_audio.so b/deps/GoogleVR/lib/Android/android_arm64/libgvr_audio.so deleted file mode 100644 index 063bc97841..0000000000 --- a/deps/GoogleVR/lib/Android/android_arm64/libgvr_audio.so +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:b4ebf870ea509e2e28e33bcdfe60958ece874e611579c689a7276ecf61413a04 -size 1165544 diff --git a/deps/GoogleVR/lib/Android/android_x86/libgvr.so b/deps/GoogleVR/lib/Android/android_x86/libgvr.so deleted file mode 100644 index 12fc4c27bd..0000000000 --- a/deps/GoogleVR/lib/Android/android_x86/libgvr.so +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:bdc9eba394a518a244e0dd712b70ccfdd70b380c74f69a0096818047a2b63ef0 -size 1542096 diff --git a/deps/GoogleVR/lib/Android/android_x86/libgvr_audio.so b/deps/GoogleVR/lib/Android/android_x86/libgvr_audio.so deleted file mode 100644 index 769f2ceaeb..0000000000 --- a/deps/GoogleVR/lib/Android/android_x86/libgvr_audio.so +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d0a7f0b8a7170f81d3f180150fd37eac1117e56cb80e82bd1a8bd36bf55ff1a9 -size 1148360 diff --git a/deps/GoogleVR/lib/Android/android_x86_64/libgvr.so b/deps/GoogleVR/lib/Android/android_x86_64/libgvr.so deleted file mode 100644 index ce5d2285d1..0000000000 --- a/deps/GoogleVR/lib/Android/android_x86_64/libgvr.so +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:bb6f8bb513b53026785f3aa2468d37b8f1dd625d79345a1b8238abc0cab71c7d -size 1514888 diff --git a/deps/GoogleVR/lib/Android/android_x86_64/libgvr_audio.so b/deps/GoogleVR/lib/Android/android_x86_64/libgvr_audio.so deleted file mode 100644 index 8f171e9918..0000000000 --- a/deps/GoogleVR/lib/Android/android_x86_64/libgvr_audio.so +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:a7421ba39afcc76ced19a5c441f424c6ded44c37f6ab763288eb64d59eca4550 -size 1120448 diff --git a/deps/GoogleVR/lib/Android/protobuf-javanano-3.1.0.jar b/deps/GoogleVR/lib/Android/protobuf-javanano-3.1.0.jar deleted file mode 100644 index 8aac9068d2..0000000000 Binary files a/deps/GoogleVR/lib/Android/protobuf-javanano-3.1.0.jar and /dev/null differ diff --git a/deps/GoogleVR/lib/iOS/libgvr.a b/deps/GoogleVR/lib/iOS/libgvr.a deleted file mode 100644 index de8046c95a..0000000000 --- a/deps/GoogleVR/lib/iOS/libgvr.a +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:0e0c886bffd0038e8eee76d93cf2faac72ff469c4dda87faf74c57ffb2e8f37b -size 75560584 diff --git a/deps/GoogleVR/vr/gvr/capi/include/gvr.h b/deps/GoogleVR/vr/gvr/capi/include/gvr.h deleted file mode 100644 index 2e594ca06b..0000000000 --- a/deps/GoogleVR/vr/gvr/capi/include/gvr.h +++ /dev/null @@ -1,1693 +0,0 @@ -/* Copyright 2016 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VR_GVR_CAPI_INCLUDE_GVR_H_ -#define VR_GVR_CAPI_INCLUDE_GVR_H_ - -#ifdef __ANDROID__ -#include -#endif - -#include -#include - -#if defined(__cplusplus) && !defined(GVR_NO_CPP_WRAPPER) -#include -#include -#include -#endif - -#include "../GoogleVR/vr/gvr/capi/include/gvr_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/// @defgroup base Google VR Base C API -/// @brief This is the Google VR C API. It supports clients writing VR -/// experiences for head mounted displays that consist of a mobile phone and a -/// VR viewer. -/// -/// Example API usage: -/// -/// #ifdef __ANDROID__ -/// // On Android, the gvr_context should almost always be obtained from -/// // the Java GvrLayout object via -/// // GvrLayout.getGvrApi().getNativeGvrContext(). -/// gvr_context* gvr = ...; -/// #else -/// gvr_context* gvr = gvr_create(); -/// #endif -/// -/// gvr_initialize_gl(gvr); -/// -/// gvr_buffer_viewport_list* viewport_list = -/// gvr_buffer_viewport_list_create(gvr); -/// gvr_get_recommended_buffer_viewports(gvr, viewport_list); -/// gvr_buffer_viewport* left_eye_vp = gvr_buffer_viewport_create(gvr); -/// gvr_buffer_viewport* right_eye_vp = gvr_buffer_viewport_create(gvr); -/// gvr_buffer_viewport_list_get_item(viewport_list, 0, left_eye_vp); -/// gvr_buffer_viewport_list_get_item(viewport_list, 1, right_eye_vp); -/// -/// while (client_app_should_render) { -/// // A client app should be ready for the render target size to change -/// // whenever a new QR code is scanned, or a new viewer is paired. -/// gvr_sizei render_target_size = -/// gvr_get_maximum_effective_render_target_size(gvr); -/// // The maximum effective render target size can be very large, most -/// // applications need to scale down to compensate. -/// render_target_size.width /= 2; -/// render_target_size.height /= 2; -/// gvr_swap_chain_resize_buffer(swap_chain, 0, render_target_size); -/// -/// // This function will depend on your render loop's implementation. -/// gvr_clock_time_point next_vsync = AppGetNextVsyncTime(); -/// -/// const gvr_mat4f head_view = -/// gvr_get_head_space_from_start_space_rotation(gvr, next_vsync); -/// const gvr_mat4f left_eye_view = MatrixMultiply( -/// gvr_get_eye_from_head_matrix(gvr, GVR_LEFT_EYE), head_view); -/// const gvr::Mat4f right_eye_view = MatrixMultiply( -/// gvr_get_eye_from_head_matrix(gvr, GVR_RIGHT_EYE), head_view); -/// -/// // Insert client rendering code here. -/// -/// AppSetRenderTarget(offscreen_texture_id); -/// -/// AppDoSomeRenderingForEye( -/// gvr_buffer_viewport_get_source_uv(left_eye_view), -/// left_eye_matrix); -/// AppDoSomeRenderingForEye( -/// gvr_buffer_viewport_get_source_uv(right_eye_view), -/// right_eye_matrix); -/// AppSetRenderTarget(primary_display); -/// -/// gvr_frame_submit(&frame, viewport_list, head_matrix); -/// } -/// -/// // Cleanup memory. -/// gvr_buffer_viewport_list_destroy(&viewport_list); -/// gvr_buffer_viewport_destroy(&left_eye_vp); -/// gvr_buffer_viewport_destroy(&right_eye_vp); -/// -/// #ifdef __ANDROID__ -/// // On Android, The Java GvrLayout owns the gvr_context. -/// #else -/// gvr_destroy(gvr); -/// #endif -/// -/// Head tracking is enabled by default, and will begin as soon as the -/// gvr_context is created. The client should call gvr_pause_tracking() and -/// gvr_resume_tracking() when the app is paused and resumed, respectively. -/// -/// Note: Unless otherwise noted, the functions in this API may not be -/// thread-safe with respect to the gvr_context, and it is up the caller to use -/// the API in a thread-safe manner. -/// -/// @{ - -/// Creates a new gvr instance. -/// -/// The instance must remain valid as long as any GVR object is in use. When -/// the application no longer needs to use the GVR SDK, call gvr_destroy(). -/// -/// -/// On Android, the gvr_context should *almost always* be obtained from the Java -/// GvrLayout object, rather than explicitly created here. The GvrLayout should -/// live in the app's View hierarchy, and its use is required to ensure -/// consistent behavior across all varieties of GVR-compatible viewers. See -/// the Java GvrLayout and GvrApi documentation for more details. -/// -#ifdef __ANDROID__ -/// @param env The JNIEnv associated with the current thread. -/// @param app_context The Android application context. This must be the -/// application context, NOT an Activity context (Note: from any Android -/// Activity in your app, you can call getApplicationContext() to -/// retrieve the application context). -/// @param class_loader The class loader to use when loading Java classes. -/// This must be your app's main class loader (usually accessible through -/// activity.getClassLoader() on any of your Activities). -/// -/// @return Pointer to the created gvr instance, NULL on failure. -gvr_context* gvr_create(JNIEnv* env, jobject app_context, jobject class_loader); -#else -/// @return Pointer to the created gvr instance, NULL on failure. -gvr_context* gvr_create(); -#endif // #ifdef __ANDROID__ - -/// Gets the current GVR runtime version. -/// -/// Note: This runtime version may differ from the version against which the -/// client app is compiled, as defined by the semantic version components in -/// gvr_version.h. -/// -/// @return The version as a gvr_version. -gvr_version gvr_get_version(); - -/// Gets a string representation of the current GVR runtime version. This is of -/// the form "MAJOR.MINOR.PATCH". -/// -/// Note: This runtime version may differ from the version against which the -/// client app is compiled, as defined in gvr_version.h by -/// GVR_SDK_VERSION_STRING. -/// -/// @return The version as a static char pointer. -const char* gvr_get_version_string(); - -/// Gets the current GVR error code, or GVR_ERROR_NONE if there is no error. -/// This function doesn't clear the error code; see gvr_clear_error(). -/// -/// @param gvr Pointer to the gvr instance. -/// @return The current gvr_error code, or GVR_ERROR_NONE if no error has -/// occurred. -int32_t gvr_get_error(gvr_context* gvr); - -/// Clears the current GVR error code, and returns the error code that was -/// cleared. -/// -/// @param gvr Pointer to the gvr instance. -/// @return The gvr_error code that was cleared by this function, or -/// GVR_ERROR_NONE if no error has occurred. -int32_t gvr_clear_error(gvr_context* gvr); - -/// Gets a human-readable string representing the given error code. -/// -/// @param error_code The gvr_error code. -/// @return A human-readable string representing the error code. -const char* gvr_get_error_string(int32_t error_code); - -/// Returns an opaque struct containing information about user preferences. -/// -/// The returned struct will remain valid as long as the context is valid. -/// The returned struct may be updated when the user changes their preferences, -/// so this function only needs to be called once, and calling it multiple -/// times will return the same object each time. -/// -/// @param gvr Pointer to the gvr instance. -/// @return An opaque struct containing information about user preferences. -const gvr_user_prefs* gvr_get_user_prefs(gvr_context* gvr); - -/// Returns the controller handedness of the given gvr_user_prefs struct. -/// -/// @param user_prefs Pointer to the gvr_user_prefs object returned by -/// gvr_get_user_prefs. -/// @return Either GVR_CONTROLLER_RIGHT_HANDED or GVR_CONTROLLER_LEFT_HANDED -/// depending on which hand the user holds the controller in. -int32_t gvr_user_prefs_get_controller_handedness( - const gvr_user_prefs* user_prefs); - -/// Destroys a gvr_context instance. The parameter will be nulled by this -/// operation. Once this function is called, the behavior of any subsequent -/// call to a GVR SDK function that references objects created from this -/// context is undefined. -/// -/// @param gvr Pointer to a pointer to the gvr instance to be destroyed and -/// nulled. -void gvr_destroy(gvr_context** gvr); - -/// Initializes necessary GL-related objects and uses the current thread and -/// GL context for rendering. Please make sure that a valid GL context is -/// available when this function is called. -/// -/// @param gvr Pointer to the gvr instance to be initialized. -void gvr_initialize_gl(gvr_context* gvr); - -/// Gets whether asynchronous reprojection is currently enabled. -/// -/// If enabled, frames will be collected by the rendering system and -/// asynchronously re-projected in sync with the scanout of the display. This -/// feature may not be available on every platform, and requires a -/// high-priority render thread with special extensions to function properly. -/// -/// Note: On Android, this feature can be enabled solely via the GvrLayout Java -/// instance which (indirectly) owns this gvr_context. The corresponding -/// method call is GvrLayout.setAsyncReprojectionEnabled(). -/// -/// @param gvr Pointer to the gvr instance. -/// @return Whether async reprojection is enabled. Defaults to false. -bool gvr_get_async_reprojection_enabled(const gvr_context* gvr); - -/// Gets the recommended buffer viewport configuration, populating a previously -/// allocated gvr_buffer_viewport_list object. The updated values include the -/// per-eye recommended viewport and field of view for the target. -/// -/// When the recommended viewports are used for distortion rendering, this -/// method should always be called after calling refresh_viewer_profile(). That -/// will ensure that the populated viewports reflect the currently paired -/// viewer. -/// -/// @param gvr Pointer to the gvr instance from which to get the viewports. -/// @param viewport_list Pointer to a previously allocated viewport list. This -/// will be populated with the recommended buffer viewports and resized if -/// necessary. -void gvr_get_recommended_buffer_viewports( - const gvr_context* gvr, gvr_buffer_viewport_list* viewport_list); - -/// Gets the screen (non-distorted) buffer viewport configuration, populating a -/// previously allocated gvr_buffer_viewport_list object. The updated values -/// include the per-eye recommended viewport and field of view for the target. -/// -/// @param gvr Pointer to the gvr instance from which to get the viewports. -/// @param viewport_list Pointer to a previously allocated viewport list. This -/// will be populated with the screen buffer viewports and resized if -/// necessary. -void gvr_get_screen_buffer_viewports(const gvr_context* gvr, - gvr_buffer_viewport_list* viewport_list); - -/// Returns the maximum effective size for the client's render target, given the -/// parameters of the head mounted device selected. At this resolution, we have -/// a 1:1 ratio between source pixels and screen pixels in the most magnified -/// region of the screen. Applications should rarely, if ever, need to render -/// to a larger target, as it will simply result in sampling artifacts. -/// -/// Note that this is probably too large for most applications to use as a -/// render target size. Applications should scale this value to be appropriate -/// to their graphical load. -/// -/// @param gvr Pointer to the gvr instance from which to get the size. -/// -/// @return Maximum effective size for the target render target. -gvr_sizei gvr_get_maximum_effective_render_target_size(const gvr_context* gvr); - -/// Returns a non-distorted size for the screen, given the parameters -/// of the phone and/or the head mounted device selected. -/// -/// @param gvr Pointer to the gvr instance from which to get the size. -/// -/// @return Screen (non-distorted) size for the render target. -gvr_sizei gvr_get_screen_target_size(const gvr_context* gvr); - -// Sets the size of the underlying render surface. -// -// By default, it is assumed that the display size matches the surface -// size. If that is the case for the client app, this method need never be -// called. However, in certain cases (e.g., hardware scaling), this will not -// always hold, in which case the distortion pass must be informed of the -// custom surface size. -// -// Note that the caller is responsible for resizing any BufferSpec objects -// created before this function is called. Otherwise there will be rendering -// artifacts, such as edges appearing pixelated. This function will change the -// result of get_maximum_effective_render_target_size(), so that function can be -// used to compute the appropriate size for buffers. -// -// @param gvr Pointer to the gvr_context instance. -// @param surface_size_pixels The size in pixels of the display surface. If -// non-empty, this will be used in conjunction with the current display to -// perform properly scaled distortion. If empty, it is assumed that the -// rendering surface dimensions match that of the active display. -void gvr_set_surface_size(gvr_context* gvr, gvr_sizei surface_size_pixels); - -/// Performs postprocessing, including lens distortion, on the contents of the -/// passed texture and shows the result on the screen. Lens distortion is -/// determined by the parameters of the viewer encoded in its QR code. The -/// passed texture is not modified. -/// -/// If the application does not call gvr_initialize_gl() before calling this -/// function, the results are undefined. -/// -/// @deprecated This function exists only to support legacy rendering pathways -/// for Cardboard devices. It is incompatible with the low-latency -/// experiences supported by async reprojection. Use the swap chain API -/// instead. -/// -/// @param gvr Pointer to the gvr instance which will do the distortion. -/// @param texture_id The OpenGL ID of the texture that contains the next frame -/// to be displayed. -/// @param viewport_list Rendering parameters. -/// @param head_space_from_start_space This parameter is ignored. -/// @param target_presentation_time This parameter is ignored. -void gvr_distort_to_screen(gvr_context* gvr, int32_t texture_id, - const gvr_buffer_viewport_list* viewport_list, - gvr_mat4f head_space_from_start_space, - gvr_clock_time_point target_presentation_time); -/// @} - -///////////////////////////////////////////////////////////////////////////// -// Viewports and viewport lists -///////////////////////////////////////////////////////////////////////////// -/// @defgroup viewport Viewports and viewport lists -/// @brief Objects to define the mapping between the application's rendering -/// output and the user's field of view. -/// @{ - -/// Creates a gvr_buffer_viewport instance. -gvr_buffer_viewport* gvr_buffer_viewport_create(gvr_context* gvr); - -/// Frees a gvr_buffer_viewport instance and clears the pointer. -void gvr_buffer_viewport_destroy(gvr_buffer_viewport** viewport); - -/// Gets the UV coordinates specifying where the output buffer is sampled. -/// -/// @param viewport The buffer viewport. -/// @return UV coordinates as a rectangle. -gvr_rectf gvr_buffer_viewport_get_source_uv( - const gvr_buffer_viewport* viewport); - -/// Sets the UV coordinates specifying where the output buffer should be -/// sampled when compositing the final distorted image. -/// -/// @param viewport The buffer viewport. -/// @param uv The new UV coordinates for sampling. The coordinates must be -/// valid, that is, left <= right and bottom <= top. Otherwise an empty -/// source region is set, which will result in no output for this viewport. -void gvr_buffer_viewport_set_source_uv(gvr_buffer_viewport* viewport, - gvr_rectf uv); - -/// Retrieves the field of view for the referenced buffer region. -/// -/// @param viewport The buffer viewport. -/// @return The field of view of the rendered image, in degrees. -gvr_rectf gvr_buffer_viewport_get_source_fov( - const gvr_buffer_viewport* viewport); - -/// Sets the field of view for the referenced buffer region. -/// -/// @param viewport The buffer viewport. -/// @param fov The field of view to use when compositing the rendered image. -void gvr_buffer_viewport_set_source_fov(gvr_buffer_viewport* viewport, - gvr_rectf fov); - -/// Gets the target logical eye for the specified viewport. -/// -/// @param viewport The buffer viewport. -/// @return Index of the target logical eye for this viewport. -int32_t gvr_buffer_viewport_get_target_eye(const gvr_buffer_viewport* viewport); - -/// Sets the target logical eye for the specified viewport. -/// -/// @param viewport The buffer viewport. -/// @param index Index of the target logical eye. -void gvr_buffer_viewport_set_target_eye(gvr_buffer_viewport* viewport, - int32_t index); - -/// Gets the index of the source buffer from which the viewport reads its -/// undistorted pixels. -/// -/// @param viewport The buffer viewport. -/// @return Index of the source buffer. This corresponds to the index in the -/// list of buffer specs that was passed to gvr_swap_chain_create(). -int32_t gvr_buffer_viewport_get_source_buffer_index( - const gvr_buffer_viewport* viewport); - -/// Sets the buffer from which the viewport reads its undistorted pixels. -/// -/// @param viewport The buffer viewport. -/// @param buffer_index The index of the source buffer. This corresponds to the -/// index in the list of buffer specs that was passed to -/// gvr_swap_chain_create(). -void gvr_buffer_viewport_set_source_buffer_index( - gvr_buffer_viewport* viewport, int32_t buffer_index); - -/// Gets the ID of the externally-managed Surface texture from which this -/// viewport reads undistored pixels. -/// -/// @param viewport The buffer viewport. -/// @return ID of the externally-managed Surface of undistorted pixels. -int32_t gvr_buffer_viewport_get_external_surface_id( - const gvr_buffer_viewport* viewport); - -/// Sets the ID of the externally-managed Surface texture from which this -/// viewport reads. The ID is issued by the SurfaceTextureManager. If the ID -/// is not -1, the distortion renderer will sample color pixels from the -/// external surface at ID, using the source buffer for texture coords. -/// -/// @param viewport The buffer viewport. -/// @param external_surface_id The ID of the surface to read from. -void gvr_buffer_viewport_set_external_surface_id( - gvr_buffer_viewport* viewport, int32_t external_surface_id); - -/// Gets the type of reprojection to perform on the specified viewport. -/// -/// @param viewport The buffer viewport. -/// @return Type of reprojection that is applied to the viewport. -int32_t gvr_buffer_viewport_get_reprojection( - const gvr_buffer_viewport* viewport); - -/// Sets the type of reprojection to perform on the specified viewport. -/// Viewports that display world content should use full reprojection. -/// Viewports that display head-locked UI should disable reprojection to avoid -/// excessive judder. The default is to perform full reprojection. -/// -/// @param viewport The buffer viewport. -/// @param reprojection Type of reprojection that will be applied to the passed -/// viewport. -void gvr_buffer_viewport_set_reprojection(gvr_buffer_viewport* viewport, - int32_t reprojection); - -/// Compares two gvr_buffer_viewport instances and returns true if they specify -/// the same view mapping. -/// -/// @param a Instance of a buffer viewport. -/// @param b Another instance of a buffer viewport. -/// @return True if the passed viewports are the same. -bool gvr_buffer_viewport_equal(const gvr_buffer_viewport* a, - const gvr_buffer_viewport* b); - -/// Creates a new, empty list of viewports. The viewport list defines how the -/// application's rendering output should be transformed into the stabilized, -/// lens-distorted image that is sent to the screen. -/// -/// The caller should populate the returned viewport using one of: -/// - gvr_get_recommended_buffer_viewports() -/// - gvr_get_screen_buffer_viewports() -/// - gvr_buffer_viewport_list_set_item() -/// -/// @param gvr Pointer the gvr instance from which to allocate the viewport -/// list. -/// @return Pointer to an allocated gvr_buffer_viewport_list object. The caller -// is responsible for calling gvr_buffer_viewport_list_destroy() on the -/// returned object when it is no longer needed. -gvr_buffer_viewport_list* gvr_buffer_viewport_list_create( - const gvr_context* gvr); - -/// Destroys a gvr_buffer_viewport_list instance. The parameter will be nulled -/// by this operation. -/// -/// @param viewport_list Pointer to a pointer to the viewport list instance to -/// be destroyed and nulled. -void gvr_buffer_viewport_list_destroy(gvr_buffer_viewport_list** viewport_list); - -/// Returns the size of the given viewport list. -/// -/// @param viewport_list Pointer to a viewport list. -/// @return The number of entries in the viewport list. -size_t gvr_buffer_viewport_list_get_size( - const gvr_buffer_viewport_list* viewport_list); - -/// Retrieve a buffer viewport entry from a list. -/// -/// @param viewport_list Pointer to the previously allocated viewport list. -/// @param index Zero-based index of the viewport entry to query. Must be -/// smaller than the list size. -/// @param viewport The buffer viewport structure that will be populated with -/// retrieved data. -void gvr_buffer_viewport_list_get_item( - const gvr_buffer_viewport_list* viewport_list, size_t index, - gvr_buffer_viewport* viewport); - -/// Update an element of the viewport list or append a new one at the end. -/// -/// @param viewport_list Pointer to a previously allocated viewport list. -/// @param index Index of the buffer viewport entry to update. If the -/// `viewport_list` size is equal to the index, a new viewport entry will be -/// added. The `viewport_list` size must *not* be less than the index value. -/// @param viewport A pointer to the buffer viewport object. -void gvr_buffer_viewport_list_set_item(gvr_buffer_viewport_list* viewport_list, - size_t index, - const gvr_buffer_viewport* viewport); - -/// @} - -///////////////////////////////////////////////////////////////////////////// -// Swapchains and frames -///////////////////////////////////////////////////////////////////////////// -/// @defgroup swap_chain Swap chains and frames -/// @brief Functions to create a swap chain, manipulate it and submit frames -/// for lens distortion and presentation on the screen. -/// @{ - -/// Creates a default buffer specification. -gvr_buffer_spec* gvr_buffer_spec_create(gvr_context* gvr); - -/// Destroy the buffer specification and null the pointer. -void gvr_buffer_spec_destroy(gvr_buffer_spec** spec); - -/// Gets the size of the buffer to be created. -/// -/// @param spec Buffer specification. -/// @return Size of the pixel buffer. The default is equal to the recommended -/// render target size at the time when the specification was created. -gvr_sizei gvr_buffer_spec_get_size(const gvr_buffer_spec* spec); - -/// Sets the size of the buffer to be created. -/// -/// @param spec Buffer specification. -/// @param size The size. Width and height must both be greater than zero. -/// Otherwise, the application is aborted. -void gvr_buffer_spec_set_size(gvr_buffer_spec* spec, gvr_sizei size); - -/// Gets the number of samples per pixel in the buffer to be created. -/// -/// @param spec Buffer specification. -/// @return Value >= 1 giving the number of samples. 1 means multisampling is -/// disabled. Negative values and 0 are never returned. -int32_t gvr_buffer_spec_get_samples(const gvr_buffer_spec* spec); - -/// Sets the number of samples per pixel in the buffer to be created. -/// -/// @param spec Buffer specification. -/// @param num_samples The number of samples. Negative values are an error. -/// The values 0 and 1 are treated identically and indicate that -// multisampling should be disabled. -void gvr_buffer_spec_set_samples(gvr_buffer_spec* spec, int32_t num_samples); - -/// Sets the color format for the buffer to be created. Default format is -/// GVR_COLOR_FORMAT_RGBA_8888. -/// -/// @param spec Buffer specification. -/// @param color_format The color format for the buffer. Valid formats are in -/// the gvr_color_format_type enum. -void gvr_buffer_spec_set_color_format(gvr_buffer_spec* spec, - int32_t color_format); - -/// Sets the depth and stencil format for the buffer to be created. Currently, -/// only packed stencil formats are supported. Default format is -/// GVR_DEPTH_STENCIL_FORMAT_DEPTH_16. -/// -/// @param spec Buffer specification. -/// @param depth_stencil_format The depth and stencil format for the buffer. -/// Valid formats are in the gvr_depth_stencil_format_type enum. -void gvr_buffer_spec_set_depth_stencil_format(gvr_buffer_spec* spec, - int32_t depth_stencil_format); - -/// Creates a swap chain from the given buffer specifications. -/// This is a potentially time-consuming operation. All frames within the -/// swapchain will be allocated. Once rendering is stopped, call -/// gvr_swap_chain_destroy() to free GPU resources. The passed gvr_context must -/// not be destroyed until then. -/// -/// Note: Currently, swap chains only support more than one buffer when -/// asynchronous reprojection is enabled. This restriction will be lifted in a -/// future release. -/// -/// @param gvr GVR instance for which a swap chain will be created. -/// @param buffers Array of pixel buffer specifications. Each frame in the -/// swap chain will be composed of these buffers. -/// @param count Number of buffer specifications in the array. -/// @return Opaque handle to the newly created swap chain. -gvr_swap_chain* gvr_swap_chain_create(gvr_context* gvr, - const gvr_buffer_spec** buffers, - int32_t count); - -/// Destroys the swap chain and nulls the pointer. -void gvr_swap_chain_destroy(gvr_swap_chain** swap_chain); - -/// Gets the number of buffers in each frame of the swap chain. -int32_t gvr_swap_chain_get_buffer_count(const gvr_swap_chain* swap_chain); - -/// Retrieves the size of the specified pixel buffer. Note that if the buffer -/// was resized while the current frame was acquired, the return value will be -/// different than the value obtained from the equivalent function for the -/// current frame. -/// -/// @param swap_chain The swap chain. -/// @param index Index of the pixel buffer. -/// @return Size of the specified pixel buffer in frames that will be returned -/// from gvr_swap_chain_acquire_frame(). -gvr_sizei gvr_swap_chain_get_buffer_size(gvr_swap_chain* swap_chain, - int32_t index); - -/// Resizes the specified pixel buffer to the given size. The frames are resized -/// when they are unused, so the currently acquired frame will not be resized -/// immediately. -/// -/// @param swap_chain The swap chain. -/// @param index Index of the pixel buffer to resize. -/// @param size New size for the specified pixel buffer. -void gvr_swap_chain_resize_buffer(gvr_swap_chain* swap_chain, int32_t index, - gvr_sizei size); - -/// Acquires a frame from the swap chain for rendering. Buffers that are part of -/// the frame can then be bound with gvr_frame_bind_buffer(). Once the frame -/// is finished and all its constituent buffers are ready, call -/// gvr_frame_submit() to display it while applying lens distortion. -/// -/// @param swap_chain The swap chain. -/// @return Handle to the acquired frame. NULL if the swap chain is invalid, -/// or if acquire has already been called on this swap chain. -gvr_frame* gvr_swap_chain_acquire_frame(gvr_swap_chain* swap_chain); - -/// Binds a pixel buffer that is part of the frame to the OpenGL framebuffer. -/// -/// @param frame Frame handle acquired from the swap chain. -/// @param index Index of the pixel buffer to bind. This corresponds to the -/// index in the buffer spec list that was passed to -/// gvr_swap_chain_create(). -void gvr_frame_bind_buffer(gvr_frame* frame, int32_t index); - -/// Unbinds any buffers bound from this frame and binds the default OpenGL -/// framebuffer. -void gvr_frame_unbind(gvr_frame* frame); - -/// Returns the dimensions of the pixel buffer with the specified index. Note -/// that a frame that was acquired before resizing a swap chain buffer will not -/// be resized until it is submitted to the swap chain. -/// -/// @param frame Frame handle. -/// @param index Index of the pixel buffer to inspect. -/// @return Dimensions of the specified pixel buffer. -gvr_sizei gvr_frame_get_buffer_size(const gvr_frame* frame, int32_t index); - -/// Gets the name (ID) of the framebuffer object associated with the specified -/// buffer. The OpenGL state is not modified. -/// -/// @param frame Frame handle. -/// @param index Index of a pixel buffer. -/// @return OpenGL object name (ID) of a framebuffer object which can be used -/// to render into the buffer. The ID is valid only until the frame is -/// submitted. -int32_t gvr_frame_get_framebuffer_object(const gvr_frame* frame, int32_t index); - -/// Submits the frame for distortion and display on the screen. The passed -/// pointer is nulled to prevent reuse. -/// -/// @param frame The frame to submit. -/// @param list Buffer view configuration to be used for this frame. -/// @param head_space_from_start_space Transform from start space (space with -/// head at the origin at last tracking reset) to head space (space with -/// head at the origin and axes aligned to the view vector). -void gvr_frame_submit(gvr_frame** frame, const gvr_buffer_viewport_list* list, - gvr_mat4f head_space_from_start_space); - -/// Resets the OpenGL framebuffer binding to what it was at the time the -/// passed gvr_context was created. -void gvr_bind_default_framebuffer(gvr_context* gvr); - -/// @} - -///////////////////////////////////////////////////////////////////////////// -// Head tracking -///////////////////////////////////////////////////////////////////////////// -/// @defgroup Headtracking Head tracking -/// @brief Functions for managing head tracking. -/// @{ - -/// Gets the current monotonic system time. -/// -/// @return The current monotonic system time. -gvr_clock_time_point gvr_get_time_point_now(); - -/// Gets the rotation from start space to head space. The head space is a -/// space where the head is at the origin and faces the -Z direction. -/// -/// @param gvr Pointer to the gvr instance from which to get the pose. -/// @param time The time at which to get the head pose. The time should be in -/// the future. If the time is not in the future, it will be clamped to now. -/// @return A matrix representation of the rotation from start space (the space -/// where the head was last reset) to head space (the space with the head -/// at the origin, and the axes aligned to the view vector). -gvr_mat4f gvr_get_head_space_from_start_space_rotation( - const gvr_context* gvr, const gvr_clock_time_point time); - -/// Applies a simple neck model translation based on the rotation of the -/// provided head pose. -/// -/// Note: Neck model application may not be appropriate for all tracking -/// scenarios, e.g., when tracking is non-biological. -/// -/// @param gvr Pointer to the context instance from which the pose was obtained. -/// @param head_rotation_in_start_space The head rotation as returned by -/// gvr_get_head_space_from_start_space_rotation(). -/// @param factor A scaling factor for the neck model offset, clamped from 0 to -/// 1. This should be 1 for most scenarios, while 0 will effectively disable -/// neck model application. This value can be animated to smoothly -/// interpolate between alternative (client-defined) neck models. -/// @return The new head pose with the neck model applied. -gvr_mat4f gvr_apply_neck_model(const gvr_context* gvr, - gvr_mat4f head_space_from_start_space_rotation, - float factor); - -/// Pauses head tracking, disables all sensors (to save power). -/// -/// @param gvr Pointer to the gvr instance for which tracking will be paused and -/// sensors disabled. -void gvr_pause_tracking(gvr_context* gvr); - -/// Resumes head tracking, re-enables all sensors. -/// -/// @param gvr Pointer to the gvr instance for which tracking will be resumed. -void gvr_resume_tracking(gvr_context* gvr); - -/// Resets head tracking. -/// -/// This API call is deprecated. Use gvr_recenter_tracking instead, which -/// accomplishes the same effects but avoids the undesirable side-effects of -/// a full reset (temporary loss of tracking quality). -/// -/// Only to be used by Cardboard apps. Daydream apps must not call this. On the -/// Daydream platform, recentering is handled automatically and should never -/// be triggered programatically by applications. Hybrid apps that support both -/// Cardboard and Daydream must only call this function when in Cardboard mode -/// (that is, when the phone is paired with a Cardboard viewer), never in -/// Daydream mode. -/// -/// @param gvr Pointer to the gvr instance for which tracking will be reseted. -/// @deprecated Calls to this method can be safely replaced by calls to -// gvr_recenter_tracking. -void gvr_reset_tracking(gvr_context* gvr); - -/// Recenters the head orientation (resets the yaw to zero, leaving pitch and -/// roll unmodified). -/// -/// Only to be used by Cardboard apps. Daydream apps must not call this. On the -/// Daydream platform, recentering is handled automatically and should never -/// be triggered programatically by applications. Hybrid apps that support both -/// Cardboard and Daydream must only call this function when in Cardboard mode -/// (that is, when the phone is paired with a Cardboard viewer), never in -/// Daydream mode. -/// -/// @param gvr Pointer to the gvr instance for which tracking will be -/// recentered. -void gvr_recenter_tracking(gvr_context* gvr); - -/// @} - - -///////////////////////////////////////////////////////////////////////////// -// Head mounted display. -///////////////////////////////////////////////////////////////////////////// -/// @defgroup HMD Head Mounted Display -/// @brief Functions for managing viewer information. -/// @{ - -/// Sets the default viewer profile specified by viewer_profile_uri. -/// The viewer_profile_uri that is passed in will be ignored if a valid -/// viewer profile has already been stored on the device that the app -/// is running on. -/// -/// Note: This function has the potential of blocking for up to 30 seconds for -/// each redirect if a shortened URI is passed in as argument. It will try to -/// unroll the shortened URI for a maximum number of 5 times if the redirect -/// continues. In that case, it is recommended to create a separate thread to -/// call this function so that other tasks like rendering will not be blocked -/// on this. The blocking can be avoided if a standard URI is passed in. -/// -/// @param gvr Pointer to the gvr instance which to set the profile on. -/// @param viewer_profile_uri A string that contains either the shortened URI or -/// the standard URI representing the viewer profile that the app should be -/// using. If the valid viewer profile can be found on the device, the URI -/// that is passed in will be ignored and nothing will happen. Otherwise, -/// gvr will look for the viewer profile specified by viewer_profile_uri, -/// and it will be stored if found. Also, the values will be applied to gvr. -/// A valid standard URI can be generated from this page: -/// https://www.google.com/get/cardboard/viewerprofilegenerator/ -/// @return True if the viewer profile specified by viewer_profile_uri was -/// successfully stored and applied, false otherwise. -bool gvr_set_default_viewer_profile(gvr_context* gvr, - const char* viewer_profile_uri); - -/// Refreshes gvr_context with the viewer profile that is stored on the device. -/// If it can not find the viewer profile, nothing will happen. -/// -/// @param gvr Pointer to the gvr instance to refresh the profile on. -void gvr_refresh_viewer_profile(gvr_context* gvr); - -/// Gets the name of the viewer vendor. -/// -/// @param gvr Pointer to the gvr instance from which to get the vendor. -/// @return A pointer to the vendor name. May be NULL if no viewer is paired. -/// WARNING: This method guarantees the validity of the returned pointer -/// only until the next use of the `gvr` context. The string should be -/// copied immediately if persistence is required. -const char* gvr_get_viewer_vendor(const gvr_context* gvr); - -/// Gets the name of the viewer model. -/// -/// @param gvr Pointer to the gvr instance from which to get the name. -/// @return A pointer to the model name. May be NULL if no viewer is paired. -/// WARNING: This method guarantees the validity of the returned pointer -/// only until the next use of the `gvr` context. The string should be -/// copied immediately if persistence is required. -const char* gvr_get_viewer_model(const gvr_context* gvr); - -/// Gets the type of the viewer, as defined by gvr_viewer_type. -/// -/// @param gvr Pointer to the gvr instance from which to get the viewer type. -/// @return The gvr_viewer_type of the currently paired viewer. -int32_t gvr_get_viewer_type(const gvr_context* gvr); - -/// Gets the transformation matrix to convert from Head Space to Eye Space for -/// the given eye. -/// -/// @param gvr Pointer to the gvr instance from which to get the matrix. -/// @param eye Selected gvr_eye type. -/// @return Transformation matrix from Head Space to selected Eye Space. -gvr_mat4f gvr_get_eye_from_head_matrix(const gvr_context* gvr, - const int32_t eye); - -/// Gets the window bounds. -/// -/// @param gvr Pointer to the gvr instance from which to get the bounds. -/// -/// @return Window bounds in physical pixels. -gvr_recti gvr_get_window_bounds(const gvr_context* gvr); - -/// Computes the distorted point for a given point in a given eye. The -/// distortion inverts the optical distortion caused by the lens for the eye. -/// Due to chromatic aberration, the distortion is different for each -/// color channel. -/// -/// @param gvr Pointer to the gvr instance which will do the computing. -/// @param eye The gvr_eye type (left or right). -/// @param uv_in A point in screen eye Viewport Space in [0,1]^2 with (0, 0) -/// in the lower left corner of the eye's viewport and (1, 1) in the -/// upper right corner of the eye's viewport. -/// @param uv_out A pointer to an array of (at least) 3 elements, with each -/// element being a Point2f representing a point in render texture eye -/// Viewport Space in [0,1]^2 with (0, 0) in the lower left corner of the -/// eye's viewport and (1, 1) in the upper right corner of the eye's -/// viewport. -/// `uv_out[0]` is the corrected position of `uv_in` for the red channel -/// `uv_out[1]` is the corrected position of `uv_in` for the green channel -/// `uv_out[2]` is the corrected position of `uv_in` for the blue channel -void gvr_compute_distorted_point(const gvr_context* gvr, const int32_t eye, - const gvr_vec2f uv_in, gvr_vec2f uv_out[3]); - -/// @} - -#ifdef __cplusplus -} // extern "C" -#endif - -#if defined(__cplusplus) && !defined(GVR_NO_CPP_WRAPPER) -namespace gvr { - -/// Convenience C++ wrapper for gvr_user_prefs. -class UserPrefs { - public: - /// Creates a C++ wrapper for a gvr_user_prefs object. Note that unlike most - /// of the C++ wrappers in the API, this does not take ownership, as the - /// gvr_user_prefs will remain valid for the lifetime of the GVR context. - explicit UserPrefs(const gvr_user_prefs* user_prefs) - : user_prefs_(user_prefs) {} - - UserPrefs(UserPrefs&& other) : user_prefs_(nullptr) { - std::swap(user_prefs_, other.user_prefs_); - } - - UserPrefs& operator=(UserPrefs&& other) { - std::swap(user_prefs_, other.user_prefs_); - return *this; - } - - /// For more information, see gvr_user_prefs_get_controller_handedness(). - ControllerHandedness GetControllerHandedness() const { - return static_cast( - gvr_user_prefs_get_controller_handedness(user_prefs_)); - } - - /// Returns the wrapped C object. Does not affect ownership. - const gvr_user_prefs* cobj() const { return user_prefs_; } - - private: - const gvr_user_prefs* user_prefs_; - - // Disallow copy and assign. - UserPrefs(const UserPrefs&); - void operator=(const UserPrefs&); -}; - -/// Convenience C++ wrapper for the opaque gvr_buffer_viewport type. -/// The constructor allocates memory, so when used in tight loops, instances -/// should be reused. -class BufferViewport { - public: - BufferViewport(BufferViewport&& other) - : viewport_(nullptr) { - std::swap(viewport_, other.viewport_); - } - - BufferViewport& operator=(BufferViewport&& other) { - std::swap(viewport_, other.viewport_); - return *this; - } - - ~BufferViewport() { - if (viewport_) gvr_buffer_viewport_destroy(&viewport_); - } - - /// For more information, see gvr_buffer_viewport_get_source_fov(). - Rectf GetSourceFov() const { - return gvr_buffer_viewport_get_source_fov(viewport_); - } - - /// For more information, see gvr_buffer_viewport_set_source_fov(). - void SetSourceFov(const Rectf& fov) { - gvr_buffer_viewport_set_source_fov(viewport_, fov); - } - - /// For more information, see gvr_buffer_viewport_get_source_uv(). - Rectf GetSourceUv() const { - return gvr_buffer_viewport_get_source_uv(viewport_); - } - - /// For more information, see gvr_buffer_viewport_set_source_uv(). - void SetSourceUv(const Rectf& uv) { - gvr_buffer_viewport_set_source_uv(viewport_, uv); - } - - /// For more information, see gvr_buffer_viewport_get_target_eye(). - Eye GetTargetEye() const { - return static_cast(gvr_buffer_viewport_get_target_eye(viewport_)); - } - - /// For more information, see gvr_buffer_viewport_set_target_eye(). - void SetTargetEye(Eye eye) { - gvr_buffer_viewport_set_target_eye(viewport_, eye); - } - - /// For more information, see gvr_buffer_viewport_get_source_buffer_index(). - int32_t GetSourceBufferIndex() const { - return gvr_buffer_viewport_get_source_buffer_index(viewport_); - } - - /// For more information, see gvr_buffer_viewport_set_source_buffer_index(). - void SetSourceBufferIndex(int32_t buffer_index) { - gvr_buffer_viewport_set_source_buffer_index(viewport_, buffer_index); - } - - /// For more information, see gvr_buffer_viewport_get_external_surface_id(). - int32_t GetExternalSurfaceId() const { - return gvr_buffer_viewport_get_external_surface_id(viewport_); - } - - /// For more information, see gvr_buffer_viewport_set_external_surface_id(). - void SetExternalSurfaceId(const int32_t external_surface_id) { - gvr_buffer_viewport_set_external_surface_id(viewport_, external_surface_id); - } - - /// For more information, see gvr_buffer_viewport_get_reprojection(). - gvr_reprojection GetReprojection() const { - return static_cast( - gvr_buffer_viewport_get_reprojection(viewport_)); - } - /// For more information, see gvr_buffer_viewport_set_reprojection(). - void SetReprojection(gvr_reprojection reprojection) { - gvr_buffer_viewport_set_reprojection(viewport_, reprojection); - } - - /// For more information, see gvr_buffer_viewport_equal(). - bool operator==(const BufferViewport& other) const { - return gvr_buffer_viewport_equal(viewport_, other.viewport_) ? true : false; - } - bool operator!=(const BufferViewport& other) const { - return !(*this == other); - } - - /// @name Wrapper manipulation - /// @{ - /// Creates a C++ wrapper for a C object and takes ownership. - explicit BufferViewport(gvr_buffer_viewport* viewport) - : viewport_(viewport) {} - - /// Returns the wrapped C object. Does not affect ownership. - gvr_buffer_viewport* cobj() { return viewport_; } - const gvr_buffer_viewport* cobj() const { return viewport_; } - - /// Returns the wrapped C object and transfers its ownership to the caller. - /// The wrapper becomes invalid and should not be used. - gvr_buffer_viewport* release() { - auto result = viewport_; - viewport_ = nullptr; - return result; - } - /// @} - - private: - friend class GvrApi; - friend class BufferViewportList; - - explicit BufferViewport(gvr_context* gvr) - : viewport_(gvr_buffer_viewport_create(gvr)) {} - - gvr_buffer_viewport* viewport_; -}; - -/// Convenience C++ wrapper for the opaque gvr_buffer_viewport_list type. This -/// class will automatically release the wrapped gvr_buffer_viewport_list upon -/// destruction. It can only be created via a `GvrApi` instance, and its -/// validity is tied to the lifetime of that instance. -class BufferViewportList { - public: - BufferViewportList(BufferViewportList&& other) - : context_(nullptr), viewport_list_(nullptr) { - std::swap(context_, other.context_); - std::swap(viewport_list_, other.viewport_list_); - } - - BufferViewportList& operator=(BufferViewportList&& other) { - std::swap(context_, other.context_); - std::swap(viewport_list_, other.viewport_list_); - return *this; - } - - ~BufferViewportList() { - if (viewport_list_) { - gvr_buffer_viewport_list_destroy(&viewport_list_); - } - } - - /// For more information, see gvr_get_recommended_buffer_viewports(). - void SetToRecommendedBufferViewports() { - gvr_get_recommended_buffer_viewports(context_, viewport_list_); - } - - /// For more information, see gvr_get_screen_buffer_viewports(). - void SetToScreenBufferViewports() { - gvr_get_screen_buffer_viewports(context_, viewport_list_); - } - - /// For more information, see gvr_buffer_viewport_list_set_item(). - void SetBufferViewport(size_t index, const BufferViewport& viewport) { - gvr_buffer_viewport_list_set_item(viewport_list_, index, - viewport.viewport_); - } - - /// For more information, see gvr_buffer_viewport_list_get_item(). - void GetBufferViewport(size_t index, BufferViewport* viewport) const { - gvr_buffer_viewport_list_get_item(viewport_list_, index, - viewport->viewport_); - } - - /// For more information, see gvr_buffer_viewport_list_get_size(). - size_t GetSize() const { - return gvr_buffer_viewport_list_get_size(viewport_list_); - } - - /// @name Wrapper manipulation - /// @{ - /// Creates a C++ wrapper for a C object and takes ownership. - BufferViewportList(gvr_buffer_viewport_list* viewport_list, - gvr_context* context) - : context_(context), - viewport_list_(viewport_list) {} - - /// Returns the wrapped C object. Does not affect ownership. - gvr_buffer_viewport_list* cobj() { return viewport_list_; } - const gvr_buffer_viewport_list* cobj() const { return viewport_list_; } - - /// Returns the wrapped C object and transfers its ownership to the caller. - /// The wrapper becomes invalid and should not be used. - gvr_buffer_viewport_list* release() { - auto result = viewport_list_; - viewport_list_ = nullptr; - return result; - } - /// @} - - private: - friend class Frame; - friend class GvrApi; - friend class SwapChain; - - explicit BufferViewportList(gvr_context* context) - : context_(context), - viewport_list_(gvr_buffer_viewport_list_create(context)) {} - - const gvr_context* context_; - gvr_buffer_viewport_list* viewport_list_; - - // Disallow copy and assign. - BufferViewportList(const BufferViewportList&) = delete; - void operator=(const BufferViewportList&) = delete; -}; - -/// Convenience C++ wrapper for gvr_buffer_spec, an opaque pixel buffer -/// specification. Frees the underlying gvr_buffer_spec on destruction. -class BufferSpec { - public: - BufferSpec(BufferSpec&& other) - : spec_(nullptr) { - std::swap(spec_, other.spec_); - } - - BufferSpec& operator=(BufferSpec&& other) { - std::swap(spec_, other.spec_); - return *this; - } - - ~BufferSpec() { - if (spec_) gvr_buffer_spec_destroy(&spec_); - } - - /// Gets the buffer's size. The default value is the recommended render - /// target size. For more information, see gvr_buffer_spec_get_size(). - Sizei GetSize() const { - return gvr_buffer_spec_get_size(spec_); - } - - /// Sets the buffer's size. For more information, see - /// gvr_buffer_spec_set_size(). - void SetSize(const Sizei& size) { - gvr_buffer_spec_set_size(spec_, size); - } - - /// Sets the buffer's size to the passed width and height. For more - /// information, see gvr_buffer_spec_set_size(). - /// - /// @param width The width in pixels. Must be greater than 0. - /// @param height The height in pixels. Must be greater than 0. - void SetSize(int32_t width, int32_t height) { - gvr_sizei size{width, height}; - gvr_buffer_spec_set_size(spec_, size); - } - - /// Gets the number of samples per pixel in the buffer. For more - /// information, see gvr_buffer_spec_get_samples(). - int32_t GetSamples() const { return gvr_buffer_spec_get_samples(spec_); } - - /// Sets the number of samples per pixel. For more information, see - /// gvr_buffer_spec_set_samples(). - void SetSamples(int32_t num_samples) { - gvr_buffer_spec_set_samples(spec_, num_samples); - } - - /// Sets the color format for this buffer. For more information, see - /// gvr_buffer_spec_set_color_format(). - void SetColorFormat(ColorFormat color_format) { - gvr_buffer_spec_set_color_format(spec_, color_format); - } - - /// Sets the depth and stencil format for this buffer. For more - /// information, see gvr_buffer_spec_set_depth_stencil_format(). - void SetDepthStencilFormat(DepthStencilFormat depth_stencil_format) { - gvr_buffer_spec_set_depth_stencil_format(spec_, depth_stencil_format); - } - - /// @name Wrapper manipulation - /// @{ - /// Creates a C++ wrapper for a C object and takes ownership. - explicit BufferSpec(gvr_buffer_spec* spec) : spec_(spec) {} - - /// Returns the wrapped C object. Does not affect ownership. - gvr_buffer_spec* cobj() { return spec_; } - const gvr_buffer_spec* cobj() const { return spec_; } - - /// Returns the wrapped C object and transfers its ownership to the caller. - /// The wrapper becomes invalid and should not be used. - gvr_buffer_spec* release() { - auto result = spec_; - spec_ = nullptr; - return result; - } - /// @} - - private: - friend class GvrApi; - friend class SwapChain; - - explicit BufferSpec(gvr_context* gvr) { - spec_ = gvr_buffer_spec_create(gvr); - } - - gvr_buffer_spec* spec_; -}; - -/// Convenience C++ wrapper for gvr_frame, which represents a single frame -/// acquired for rendering from the swap chain. -class Frame { - public: - Frame(Frame&& other) : frame_(nullptr) { - std::swap(frame_, other.frame_); - } - - Frame& operator=(Frame&& other) { - std::swap(frame_, other.frame_); - return *this; - } - - ~Frame() { - // The swap chain owns the frame, so no clean-up is required. - } - - /// For more information, see gvr_frame_get_buffer_size(). - Sizei GetBufferSize(int32_t index) const { - return gvr_frame_get_buffer_size(frame_, index); - } - - /// For more information, see gvr_frame_bind_buffer(). - void BindBuffer(int32_t index) { - gvr_frame_bind_buffer(frame_, index); - } - - /// For more information, see gvr_frame_unbind(). - void Unbind() { - gvr_frame_unbind(frame_); - } - - /// For more information, see gvr_frame_get_framebuffer_object(). - int32_t GetFramebufferObject(int32_t index) { - return gvr_frame_get_framebuffer_object(frame_, index); - } - - /// For more information, see gvr_frame_submit(). - void Submit(const BufferViewportList& viewport_list, - const Mat4f& head_space_from_start_space) { - gvr_frame_submit(&frame_, viewport_list.viewport_list_, - head_space_from_start_space); - } - - /// @name Wrapper manipulation - /// @{ - /// Creates a C++ wrapper for a C object and takes ownership. - explicit Frame(gvr_frame* frame) : frame_(frame) {} - - /// Returns the wrapped C object. Does not affect ownership. - gvr_frame* cobj() { return frame_; } - const gvr_frame* cobj() const { return frame_; } - - /// Returns whether the wrapped gvr_frame reference is valid. - bool is_valid() const { return frame_ != nullptr; } - explicit operator bool const() { return is_valid(); } - - /// Returns the wrapped C object and transfers its ownership to the caller. - /// The wrapper becomes invalid and should not be used. - gvr_frame* release() { - auto result = frame_; - frame_ = nullptr; - return result; - } - /// @} - - private: - friend class SwapChain; - - gvr_frame* frame_; -}; - -/// Convenience C++ wrapper for gvr_swap_chain, which represents a queue of -/// frames. The GvrApi object must outlive any SwapChain objects created from -/// it. -class SwapChain { - public: - SwapChain(SwapChain&& other) - : swap_chain_(nullptr) { - std::swap(swap_chain_, other.swap_chain_); - } - - SwapChain& operator=(SwapChain&& other) { - std::swap(swap_chain_, other.swap_chain_); - return *this; - } - - ~SwapChain() { - if (swap_chain_) gvr_swap_chain_destroy(&swap_chain_); - } - - /// For more information, see gvr_swap_chain_get_buffer_count(). - int32_t GetBufferCount() const { - return gvr_swap_chain_get_buffer_count(swap_chain_); - } - - /// For more information, see gvr_swap_chain_get_buffer_size(). - Sizei GetBufferSize(int32_t index) const { - return gvr_swap_chain_get_buffer_size(swap_chain_, index); - } - - /// For more information, see gvr_swap_chain_resize_buffer(). - void ResizeBuffer(int32_t index, Sizei size) { - gvr_swap_chain_resize_buffer(swap_chain_, index, size); - } - - /// For more information, see gvr_swap_chain_acquire_frame(). - /// Note that if Frame acquisition fails, the returned Frame may not be valid. - /// The caller should inspect the returned Frame's validity before using, - /// and reschedule frame acquisition upon failure. - Frame AcquireFrame() { - Frame result(gvr_swap_chain_acquire_frame(swap_chain_)); - return result; - } - - /// @name Wrapper manipulation - /// @{ - /// Creates a C++ wrapper for a C object and takes ownership. - explicit SwapChain(gvr_swap_chain* swap_chain) : swap_chain_(swap_chain) {} - - /// Returns the wrapped C object. Does not affect ownership. - gvr_swap_chain* cobj() { return swap_chain_; } - const gvr_swap_chain* cobj() const { return swap_chain_; } - - /// Returns the wrapped C object and transfers its ownership to the caller. - /// The wrapper becomes invalid and should not be used. - gvr_swap_chain* release() { - auto result = swap_chain_; - swap_chain_ = nullptr; - return result; - } - /// @} - - private: - friend class GvrApi; - - SwapChain(gvr_context* gvr, const std::vector& specs) { - std::vector c_specs; - for (const auto& spec : specs) - c_specs.push_back(spec.spec_); - swap_chain_ = gvr_swap_chain_create(gvr, c_specs.data(), - static_cast(c_specs.size())); - } - - gvr_swap_chain* swap_chain_; - - // Disallow copy and assign. - SwapChain(const SwapChain&); - void operator=(const SwapChain&); -}; - -/// This is a convenience C++ wrapper for the Google VR C API. -/// -/// This wrapper strategy prevents ABI compatibility issues between compilers -/// by ensuring that the interface between client code and the implementation -/// code in libgvr.so is a pure C interface. The translation from C++ calls -/// to C calls provided by this wrapper runs entirely in the client's binary -/// and is compiled by the client's compiler. -/// -/// Methods in this class are only documented insofar as the C++ wrapping logic -/// is concerned; for information about the method itself, please refer to the -/// corresponding function in the C API. -/// -/// Example API usage: -/// -/// // Functionality supplied by the application in the example below has -/// // the "app-" prefix. -/// #ifdef __ANDROID__ -/// // On Android, the gvr_context should almost always be obtained from the -/// // Java GvrLayout object via -/// // GvrLayout.getGvrApi().getNativeGvrContext(). -/// std::unique_ptr gvr = GvrApi::WrapNonOwned(gvr_context); -/// #else -/// std::unique_ptr gvr = GvrApi::Create(); -/// #endif -/// -/// gvr->InitializeGl(); -/// -/// gvr::BufferViewportList viewport_list = -/// gvr->CreateEmptyBufferViewportList(); -/// gvr->GetRecommendedBufferViewports(&viewport_list); -/// gvr::BufferViewport left_eye_viewport = gvr->CreateBufferViewport(); -/// gvr::BufferViewport right_eye_viewport = gvr->CreateBufferViewport(); -/// viewport_list.Get(0, &left_eye_view); -/// viewport_list.Get(1, &right_eye_view); -/// -/// std::vector specs; -/// specs.push_back(gvr->CreateBufferSpec()); -/// specs[0].SetSamples(app_samples); -/// gvr::SwapChain swap_chain = gvr->CreateSwapChain(specs); -/// -/// while (client_app_should_render) { -/// // A client app should be ready for the render target size to change -/// // whenever a new QR code is scanned, or a new viewer is paired. -/// gvr::Sizei render_target_size = -/// gvr->GetRecommendedRenderTargetSize(); -/// swap_chain.ResizeBuffer(0, render_target_size); -/// gvr::Frame frame = swap_chain.AcquireFrame(); -/// while (!frame) { -/// std::this_thread::sleep_for(2ms); -/// frame = swap_chain.AcquireFrame(); -/// } -/// -/// // This function will depend on your render loop's implementation. -/// gvr::ClockTimePoint next_vsync = AppGetNextVsyncTime(); -/// -/// const gvr::Mat4f head_view = -/// gvr->GetHeadSpaceFromStartSpaceRotation(next_vsync); -/// const gvr::Mat4f left_eye_view = MatrixMultiply( -/// gvr->GetEyeFromHeadMatrix(kLeftEye), head_view); -/// const gvr::Mat4f right_eye_view = MatrixMultiply( -/// gvr->GetEyeFromHeadMatrix(kRightEye), head_view); -/// -/// frame.BindBuffer(0); -/// // App does its rendering to the current framebuffer here. -/// AppDoSomeRenderingForEye( -/// left_eye_viewport.GetSourceUv(), left_eye_view); -/// AppDoSomeRenderingForEye( -/// right_eye_viewport.GetSourceUv(), right_eye_view); -/// frame.Unbind(); -/// frame.Submit(viewport_list, head_matrix); -/// } -/// -class GvrApi { - public: -#ifdef __ANDROID__ - /// Instantiates and returns a GvrApi instance that owns a gvr_context. - /// - /// @param env The JNIEnv associated with the current thread. - /// @param app_context The Android application context. This must be the - /// application context, NOT an Activity context (Note: from any Android - /// Activity in your app, you can call getApplicationContext() to - /// retrieve the application context). - /// @param class_loader The class loader to use when loading Java classes. - /// This must be your app's main class loader (usually accessible through - /// activity.getClassLoader() on any of your Activities). - /// @return unique_ptr to the created GvrApi instance, nullptr on failure. - static std::unique_ptr Create(JNIEnv* env, jobject app_context, - jobject class_loader) { - gvr_context* context = gvr_create(env, app_context, class_loader); - if (!context) { - return nullptr; - } - return std::unique_ptr(new GvrApi(context, true /* owned */)); - } -#else - /// Instantiates and returns a GvrApi instance that owns a gvr_context. - /// - /// @return unique_ptr to the created GvrApi instance, nullptr on failure. - static std::unique_ptr Create() { - gvr_context* context = gvr_create(); - if (!context) { - return nullptr; - } - return std::unique_ptr(new GvrApi(context, true /* owned */)); - } -#endif // #ifdef __ANDROID__ - - ~GvrApi() { - if (context_ && owned_) { - gvr_destroy(&context_); - } - } - - /// @name Error handling - /// @{ - - /// For more information, see gvr_get_error(). - Error GetError() { return static_cast(gvr_get_error(context_)); } - - /// For more information, see gvr_clear_error(). - Error ClearError() { return static_cast(gvr_clear_error(context_)); } - - /// For more information, see gvr_get_error_string(). - static const char* GetErrorString(Error error_code) { - return gvr_get_error_string(error_code); - } - - /// For more information, see gvr_get_user_prefs(). - UserPrefs GetUserPrefs() { return UserPrefs(gvr_get_user_prefs(context_)); } - - /// @} - - /// @name Rendering - /// @{ - - /// For more information, see gvr_initialize_gl(). - void InitializeGl() { gvr_initialize_gl(context_); } - - /// For more information, see gvr_get_async_reprojection_enabled(). - bool GetAsyncReprojectionEnabled() const { - return gvr_get_async_reprojection_enabled(context_); - } - - /// Constructs a C++ wrapper for a gvr_buffer_viewport object. For more - /// information, see gvr_buffer_viewport_create(). - /// - /// @return A new BufferViewport instance with memory allocated for an - /// underlying gvr_buffer_viewport. - BufferViewport CreateBufferViewport() const { - return BufferViewport(context_); - } - - /// Constructs a C++ wrapper for a gvr_buffer_viewport_list object. - /// For more information, see gvr_buffer_viewport_list_create(). - /// - /// @return A new, empty BufferViewportList instance. - /// Note: The validity of the returned object is closely tied to the - /// lifetime of the member gvr_context. The caller is responsible for - /// ensuring correct usage accordingly. - BufferViewportList CreateEmptyBufferViewportList() const { - return BufferViewportList(context_); - } - - /// For more information, see gvr_get_maximum_effective_render_target_size(). - Sizei GetMaximumEffectiveRenderTargetSize() const { - return gvr_get_maximum_effective_render_target_size(context_); - } - - /// For more information, see gvr_get_screen_target_size(). - Sizei GetScreenTargetSize() const { - return gvr_get_screen_target_size(context_); - } - - /// For more information, see gvr_set_surface_size(). - void SetSurfaceSize(Sizei surface_size_pixels) { - gvr_set_surface_size(context_, surface_size_pixels); - } - - /// For more information, see gvr_distort_to_screen(). - void DistortToScreen(int32_t texture_id, - const BufferViewportList& viewport_list, - const Mat4f& rendered_head_pose_in_start_space_matrix, - const ClockTimePoint& texture_presentation_time) { - gvr_distort_to_screen(context_, texture_id, viewport_list.viewport_list_, - rendered_head_pose_in_start_space_matrix, - texture_presentation_time); - } - - /// For more information, see gvr_buffer_spec_create(). - BufferSpec CreateBufferSpec() { - return BufferSpec(context_); - } - - /// For more information, see gvr_swap_chain_create(). - SwapChain CreateSwapChain(const std::vector& specs) { - return SwapChain(context_, specs); - } - - /// For more information, see gvr_bind_default_framebuffer(). - void BindDefaultFramebuffer() { - gvr_bind_default_framebuffer(context_); - } - /// @} - - /// @name Head tracking - /// @{ - - /// For more information see gvr_get_head_space_from_start_space_rotation. - /// - /// @param time_point The time at which to calculate the head pose in start - /// space. - /// @return The matrix representation of the rotation from start space - /// (the space with the head pose at the last tracking reset at origin) to - /// head space (the space with the head at origin and axes aligned to the - /// view vector). - Mat4f GetHeadSpaceFromStartSpaceRotation(const ClockTimePoint& time_point) { - return gvr_get_head_space_from_start_space_rotation(context_, time_point); - } - - /// For more information, see gvr_apply_neck_model(). - Mat4f ApplyNeckModel(const Mat4f& head_pose_in_start_space, float factor) { - return gvr_apply_neck_model(context_, head_pose_in_start_space, factor); - } - - /// For more information, see gvr_pause_tracking(). - void PauseTracking() { gvr_pause_tracking(context_); } - - /// For more information, see gvr_resume_tracking(). - void ResumeTracking() { gvr_resume_tracking(context_); } - - /// For more information, see gvr_reset_tracking(). - void ResetTracking() { gvr_reset_tracking(context_); } - - // For more information, see gvr_recenter_tracking(). - void RecenterTracking() { gvr_recenter_tracking(context_); } - - /// For more information, see gvr_get_time_point_now(). - static ClockTimePoint GetTimePointNow() { return gvr_get_time_point_now(); } - /// @} - - /// @name Viewer parameters - /// @{ - - /// For more information, see gvr_set_default_viewer_profile(). - bool SetDefaultViewerProfile(const char* viewer_profile_uri) { - return gvr_set_default_viewer_profile(context_, viewer_profile_uri); - } - - /// For more information, see gvr_refresh_viewer_profile(). - void RefreshViewerProfile() { gvr_refresh_viewer_profile(context_); } - - /// For more information, see gvr_get_viewer_vendor(). - const char* GetViewerVendor() const { - return gvr_get_viewer_vendor(context_); - } - - /// For more information, see gvr_get_viewer_model(). - const char* GetViewerModel() const { return gvr_get_viewer_model(context_); } - - /// For more information, see gvr_get_viewer_type(). - ViewerType GetViewerType() const { - return static_cast(gvr_get_viewer_type(context_)); - } - - /// For more information, see gvr_get_eye_from_head_matrix(). - Mat4f GetEyeFromHeadMatrix(Eye eye) const { - return gvr_get_eye_from_head_matrix(context_, eye); - } - - /// For more information, see gvr_get_window_bounds(). - Recti GetWindowBounds() const { return gvr_get_window_bounds(context_); } - - /// For more information, see gvr_compute_distorted_point(). - std::array ComputeDistortedPoint(Eye eye, const Vec2f& uv_in) { - std::array uv_out = {{{}}}; - gvr_compute_distorted_point(context_, eye, uv_in, uv_out.data()); - return uv_out; - } - /// @} - - /// @name Wrapper manipulation - /// @{ - /// Creates a C++ wrapper for a C object and optionally takes ownership. - /// - /// @param context C object to wrap. - /// @param owned Whether the wrapper will own the underlying C object. - explicit GvrApi(gvr_context* context, bool owned = true) - : context_(context), owned_(owned) {} - - /// Returns the wrapped C object. Does not affect ownership. - gvr_context* cobj() { return context_; } - const gvr_context* cobj() const { return context_; } - - /// @deprecated Use cobj() instead. - gvr_context* GetContext() { return context_; } - /// @deprecated Use cobj() instead. - const gvr_context* GetContext() const { return context_; } - - /// Returns the wrapped C object and transfers its ownership to the caller. - /// The wrapper becomes invalid and should not be used. - gvr_context* release() { - auto result = context_; - context_ = nullptr; - return result; - } - - /// Instantiates a GvrApi instance that wraps a *non-owned* gvr_context. - /// - /// Ownership of the provided `context` remains with the caller, and they - /// are responsible for ensuring proper disposal of the context. - /// - /// @param context Pointer to a non-null, non-owned gvr_context instance. - /// @return unique_ptr to the created GvrApi instance. Never null. - static std::unique_ptr WrapNonOwned(gvr_context* context) { - return std::unique_ptr(new GvrApi(context, false /* owned */)); - } - /// @} - - private: - gvr_context* context_; - - // Whether context_ is owned by the GvrApi instance. If owned, the context - // will be released upon destruction. - const bool owned_; - - // Disallow copy and assign. - GvrApi(const GvrApi&); - void operator=(const GvrApi&); -}; - -} // namespace gvr -#endif // #if defined(__cplusplus) && !defined(GVR_NO_CPP_WRAPPER) - -#endif // VR_GVR_CAPI_INCLUDE_GVR_H_ diff --git a/deps/GoogleVR/vr/gvr/capi/include/gvr_audio.h b/deps/GoogleVR/vr/gvr/capi/include/gvr_audio.h deleted file mode 100644 index bf58179d0d..0000000000 --- a/deps/GoogleVR/vr/gvr/capi/include/gvr_audio.h +++ /dev/null @@ -1,797 +0,0 @@ -/* Copyright 2016 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VR_GVR_CAPI_INCLUDE_GVR_AUDIO_H_ -#define VR_GVR_CAPI_INCLUDE_GVR_AUDIO_H_ - -#if __ANDROID__ -#include -#endif // __ANDROID__ - -#include - -#include "vr/gvr/capi/include/gvr.h" -#include "vr/gvr/capi/include/gvr_types.h" - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -/// @defgroup Audio Spatial Audio API -/// @brief This is the GVR Audio C API, a spatial audio rendering engine, -/// optimized for mobile VR. -/// -/// It allows the user to spatialize sound sources in 3D space, including -/// distance and elevation cues. Specifically, the API is capable of playing -/// back spatial sound in three ways: -/// -/// - **Sound object rendering**: This allows the user to create a virtual sound -/// source in 3D space. These sources, while spatialized, are fed with mono -/// audio data. -/// -/// - **Ambisonic soundfields**: Ambisonic recordings are multi-channel audio -/// files which are spatialized all around the listener in 360 degrees. These -/// can be thought of as recorded or pre-baked soundfields. They can be of -/// great use for background effects which sound perfectly spatial. Examples -/// include rain noise, crowd noise or even the sound of the ocean off to one -/// side. -/// -/// - **Stereo Sounds**: This allows the user to directly play back -/// non-spatialized mono or stereo audio files. This is useful for music and -/// other such audio. -/// -/// **Initialization** -/// -/// gvr_audio_context* gvr_audio_create(int32_t rendering_mode); -/// -/// The rendering_mode argument corresponds to a `gvr_audio_rendering_mode` enum -/// value, which specifies a rendering configuration setting: -/// -/// - `GVR_AUDIO_RENDERING_STEREO_PANNING`: -/// Stereo panning of all sound objects. This disables HRTF-based rendering. -/// - `GVR_AUDIO_RENDERING_BINAURAL_LOW_QUALITY`: -/// This renders sound objects over a virtual array of 8 loudspeakers arranged -/// in a cube configuration around the listener’s head. HRTF-based rendering -/// is enabled. -/// - `GVR_AUDIO_RENDERING_BINAURAL_HIGH_QUALITY`: -/// This renders sound objects over a virtual array of 16 loudspeakers -/// arranged in an approximate equidistribution about the listener’s -/// head. HRTF-based rendering is enabled. -/// -/// For most modern phones, the high quality mode offers a good balance between -/// performance and audio quality. To optimize the rendering performance for -/// headphones *and* speaker playback, the stereo speaker mode can be enabled -/// which automatically switches to stereo panning when no headphone is plugin. -/// Note that this can lead to varying CPU usage based on headphone and speaker -/// playback. -/// -/// **Sound engine control** -/// -/// Audio playback on the default audio device can be started and stopped by -/// calling the following two methods: -/// -/// void gvr_audio_pause(gvr_audio_context* api); -/// void gvr_audio_resume(gvr_audio_context* api); -/// -/// Note that: -/// -/// void gvr_audio_update(gvr_audio_context* api); -/// -/// must be called from the main thread at a regular rate. It is used to execute -/// background operations outside of the audio thread. -/// -/// **Listener position and rotation** -/// -/// To ensure that the audio in your application reacts to listener head -/// movement, it is important to update the listener's head orientation in the -/// graphics callback using the head orientation matrix. -/// -/// The following methods can be used to control the listener’s head position -/// and orientation with the audio engine: -/// -/// void gvr_audio_set_head_position(gvr_audio_context* api, float x, -/// float y, float z); -/// or -/// -/// void gvr_audio_set_head_position_gvr(gvr_audio_context* api, -/// const gvr_vec3f& position); -/// -/// and -/// -/// void gvr_audio_set_head_rotation(gvr_audio_context* api, -/// float x, float y, float z, float w); -/// or -/// -/// void gvr_audio_set_head_rotation_gvr(gvr_audio_context* api, -/// const gvr_quatf& rotation); -/// -/// **Preloading Sounds** -/// -/// Both mono sound files for use with Sound Objects and multi-channel Ambisonic -/// soundfield files can be preloaded into memory before playback or -/// alternatively streamed during playback. Preloading can be useful to reduce -/// CPU usage especially if the same audio clip is likely to be played back many -/// times. In this case playback latency is also reduced. -/// -/// Sound files can be preloaded into memory by calling: -/// -/// bool gvr_audio_preload_soundfile(gvr_audio_context* api, -/// const char* filename); -/// -/// Unused sound files can be unloaded with a call to: -/// -/// void gvr_audio_unload_soundfile(gvr_audio_context* api, -/// const char* filename); -/// -/// NOTE: If a sound object, soundfield or stereo sound is created with a file -/// that has not been preloaded, that audio will be streamed. -/// -/// **Spatializtion of sound objects** -/// -/// The GVR Audio System allows the user to create virtual sound objects which -/// can be placed anywhere in space around the listener. -/// -/// To create a new sound object, call: -/// -/// gvr_audio_source_id -/// gvr_audio_create_sound_object(gvr_audio_context* api, -/// const char* filename); -/// -/// This returns a handle that can be used to set properties such as the -/// position and the volume of the sound object via calls to the following two -/// functions: -/// -/// void -/// gvr_audio_set_sound_object_position(gvr_audio_context* api, -/// gvr_audio_source_id sound_object_id, -/// float x, float y, float z); -/// -/// void -/// gvr_audio_set_sound_volume(gvr_audio_context* api, -/// gvr_audio_source_id source_id, float volume); -/// -/// The behavior of Sound Objects with respect to their distance from the -/// listener can be controlled via calls to the following method: -/// -/// void gvr_audio_set_sound_object_distance_rolloff_model( -/// gvr_audio_context* api, gvr_audio_source_id sound_object_id, -/// int32_t rolloff_model, float min_distance, float max_distance); -/// -/// This enables a user to choose between logarithmic and linear distance -/// rolloff methods, or to completely disable distance rolloff effects. -/// -/// -/// The spatialized playback of a sound object can be triggered with a call to: -/// -/// void gvr_audio_play_sound(gvr_audio_context* api, -/// gvr_audio_source_id source_id, -/// bool looping_enabled); -/// -/// and stopped with a call to: -/// -/// void gvr_audio_stop_sound(gvr_audio_context* api, -/// gvr_audio_source_id source_id); -/// -/// Note that the sound object handle destroys itself at the moment the sound -/// playback has stopped. This way, no clean up of sound object handles is -/// needed. On subsequent calls to this function the corresponding -/// gvr_audio_source_id no longer refers to a valid sound object. -/// -/// The following function can be used to check if a sound object is currently -/// active: -/// -/// bool gvr_audio_is_sound_playing(const gvr_audio_context* api, -/// gvr_audio_source_id source_id); -/// -/// **Rendering of ambisonic soundfields** -/// -/// The GVR Audio System also provides the user with the ability to play back -/// ambisonic soundfields. Ambisonic soundfields are captured or pre-rendered -/// 360 degree recordings. It is best to think of them as equivalent to 360 -/// degree video. While they envelop and surround the listener, they only react -/// to the listener's rotational movement. That is, one cannot walk towards -/// features in the soundfield. Soundfields are ideal for accompanying 360 -/// degree video playback, for introducing background and environmental effects -/// such as rain or crowd noise, or even for pre baking 3D audio to reduce -/// rendering costs. The GVR Audio System supports full 3D First Order -/// Ambisonic recordings using ACN channel ordering and SN3D normalization. For -/// more information please see our Spatial Audio specification at: -/// https://github.com/google/spatial-media/blob/master/docs/spatial-audio-rfc.md#semantics -/// -/// Note that Soundfield playback is directly streamed from the sound file and -/// no sound file preloading is needed. -/// -/// To obtain a soundfield handler, call: -/// -/// gvr_audio_source_id gvr_audio_create_soundfield(gvr_audio_context* api, -/// const char* filename); -/// -/// This returns a gvr_audio_source_id handle that allows the user to begin -/// playback of the soundfield, to alter the soundfield’s volume or to stop -/// soundfield playback and as such destroy the object. These actions can be -/// achieved with calls to the following functions: -/// -/// void gvr_audio_play_sound(gvr_audio_context* api, -/// gvr_audio_source_id source_id, -/// bool looping_enabled); -/// -/// void gvr_audio_set_sound_volume(gvr_audio_context* api, -/// gvr_audio_source_id source_id, -/// float volume); -/// -/// void gvr_audio_stop_sound(gvr_audio_context* api, -/// gvr_audio_source_id source_id); -/// -/// Ambisonic soundfields can also be rotated about the listener's head in order -/// to align the components of the soundfield with the visuals of the game/app. -/// -/// void gvr_audio_set_soundfield_rotation(gvr_audio_context* api, -/// gvr_audio_source_id soundfield_id, -/// const gvr_quatf& -/// soundfield_rotation); -/// -/// **Direct Playback of Stereo or Mono Sounds** -/// -/// The GVR Audio System allows the direct non-spatialized playback of both -/// stereo and mono audio. Such audio is often used for music or sound effects -/// that should not be spatialized. -/// -/// A stereo sound can be created with a call to: -/// -/// gvr_audio_source_id gvr_audio_create_stereo_sound(gvr_audio_context* api, -/// const char* filename); -/// -/// **Room effects** -/// -/// The GVR Audio System provides a powerful reverb engine which can be used to -/// create customized room effects by specifying the size of a room and a -/// material for each surface of the room from the gvr_audio_material_name enum. -/// Each of these surface materials has unique absorption properties which -/// differ with frequency. The room created will be centered around the -/// listener. Note that the Google VR Audio System uses meters as the unit of -/// distance throughout. -/// -/// The following methods are used to control room effects: -/// -/// void gvr_audio_enable_room(gvr_audio_context* api, bool enable); -/// -/// enables or disables room effects with smooth transitions. -/// -/// and -/// -/// void -/// gvr_audio_set_room_properties(gvr_audio_context* api, float size_x, -/// float size_y, float size_z, -/// gvr_audio_material_name wall_material, -/// gvr_audio_material_name ceiling_material, -/// gvr_audio_material_name floor_material); -/// -/// allows the user to describe the room based on its dimensions and its surface -/// properties. For example, one can expect very large rooms to be more -/// reverberant than smaller rooms, and a room with with hard surface materials -/// such as brick to be more reverberant than one with soft absorbent materials -/// such as heavy curtains on every surface. -/// -/// Note that when a sound source is located outside of the listener's room, -/// it will sound different from sources located within the room due to -/// attenuation of both the direct sound and the reverb on that source. Sources -/// located far outside of the listener's room will not be audible to the -/// listener. -/// -/// The following method can be used to subtly adjust the reverb in a room by -/// changing the gain/attenuation on the reverb, setting a multiplier on the -/// reverberation time to control the reverb's length, or adjusting the balance -/// between the low and high frequency components of the reverb. -/// -/// void gvr_audio_set_room_reverb_adjustments(gvr_audio_context* api, -/// float gain, -/// float time_adjust, -/// float brightness_adjust); -/// -/// If you are writing C++ code, you might prefer to use the C++ wrapper -/// rather than implement this C API directly. -/// -/// **Example usage (C++ API)** -/// -/// Construction: -/// -/// std::unique_ptr gvr_audio_api(new gvr::AudioApi); -/// gvr_audio_api->Init(GVR_AUDIO_RENDERING_BINAURAL_HIGH_QUALITY); -/// -/// Update head rotation in DrawFrame(): -/// -/// head_pose_ = gvr_api_->GetHeadSpaceFromStartSpaceRotation(target_time); -/// gvr_audio_api_->SetHeadPose(head_pose_); -/// gvr_audio_api_->Update(); -/// -/// Preload sound file, create sound handle and start playback: -/// -/// gvr_audio_api->PreloadSoundfile(kSoundFile); -/// AudioSourceId source_id = -/// gvr_audio_api_->CreateSoundObject("sound.wav"); -/// gvr_audio_api->SetSoundObjectPosition(source_id, -/// position_x, -/// position_y, -/// position_z); -/// gvr_audio_api->PlaySound(source_id, true /* looped playback */); -/// - -/// @{ - -typedef struct gvr_audio_context_ gvr_audio_context; - -/// Creates and initializes a gvr_audio_context. This call also initializes -/// the audio interface and starts the audio engine. Note that the returned -/// instance must be deleted with gvr_audio_destroy. -/// -#ifdef __ANDROID__ -/// @param env The JNI Env associated with the current thread. -/// @param android_context The Android application context. This must be the -/// application context, NOT an Activity context (Note: from any Android -/// Activity in your app, you can call getApplicationContext() to -/// retrieve the application context). -/// @param class_loader The class loader to use when loading Java -/// classes. This must be your app's main class loader (usually -/// accessible through activity.getClassLoader() on any of your Activities). -/// @param rendering_mode The gvr_audio_rendering_mode value which determines -/// the rendering configuration preset. This is passed as an int32_t to -/// ensure API compatibility. -/// @return gvr_audio_context instance. -gvr_audio_context* gvr_audio_create(JNIEnv* env, jobject android_context, - jobject class_loader, - int32_t rendering_mode); -#else -/// @param rendering_mode The gvr_audio_rendering_mode value which determines -/// the rendering configuration preset. This is passed as an int32_t to -/// ensure API compatibility. -/// @return gvr_audio_context instance. -gvr_audio_context* gvr_audio_create(int32_t rendering_mode); -#endif // #ifdef __ANDROID__ - -/// Destroys a gvr_audio_context that was previously created with -/// gvr_audio_create or gvr_audio_create_android. -/// -/// @param api Pointer to a pointer to a gvr_audio_context. The pointer -/// will be set to NULL after destruction. -void gvr_audio_destroy(gvr_audio_context** api); - -/// Resumes the VR Audio system. -/// Call this when your app/game loses focus. -/// Calling this when not paused is a no-op. -/// Thread-safe (call from any thread). -/// -/// @param api Pointer to a gvr_audio_context. -void gvr_audio_resume(gvr_audio_context* api); - -/// Pauses the VR Audio system. -/// Calling this when already paused is a no-op. -/// Thread-safe (call from any thread). -/// -/// @param api Pointer to a gvr_audio_context. -void gvr_audio_pause(gvr_audio_context* api); - -/// This method must be called from the main thread at a regular rate. It is -/// used to execute background operations outside of the audio thread. -/// -/// @param api Pointer to a gvr_audio_context. -void gvr_audio_update(gvr_audio_context* api); - -/// Preloads a local sound file. Note that the local file access method -/// depends on the target platform. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param filename Name of the file, used as identifier. -/// @return True on success or if file has already been preloaded. -bool gvr_audio_preload_soundfile(gvr_audio_context* api, const char* filename); - -/// Unloads a previously preloaded sample from memory. Note that if the sample -/// is currently used, the memory is freed at the moment playback stops. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param filename Name of the file, used as identifier. -void gvr_audio_unload_soundfile(gvr_audio_context* api, const char* filename); - -/// Returns a new sound object. Note that the sample referred to needs to be -/// preloaded and may only contain a single audio channel (mono). The handle -/// automatically destroys itself at the moment the sound playback has stopped. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param filename The path/name of the file to be played. -/// @return Id of new sound object. Returns kInvalidId if the sound file has not -/// been preloaded or if the number of input channels is > 1. -gvr_audio_source_id gvr_audio_create_sound_object(gvr_audio_context* api, - const char* filename); - -/// Returns a new ambisonic sound field. Note that the sample needs to be -/// preloaded and must have 4 separate audio channels. The handle automatically -/// destroys itself at the moment the sound playback has stopped. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param filename The path/name of the file to be played. -/// @return Id of new soundfield. Returns kInvalidId if the sound file has not -/// been preloaded or if the number of input channels does not match that -/// required. -gvr_audio_source_id gvr_audio_create_soundfield(gvr_audio_context* api, - const char* filename); - -/// Returns a new stereo non-spatialized source, which directly plays back mono -/// or stereo audio. Note the sample needs to be preloaded and may contain only -/// one (mono) or two (stereo) audio channels. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param filename The path/name of the file to be played.. -/// @return Id of new stereo non-spatialized source. Returns kInvalidId if the -/// sound file has not been preloaded or if the number of input channels is -/// > 2; -gvr_audio_source_id gvr_audio_create_stereo_sound(gvr_audio_context* api, - const char* filename); - -/// Starts the playback of a sound. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param source_id Id of the audio source to be stopped. -/// @param looping_enabled Enables looped audio playback. -void gvr_audio_play_sound(gvr_audio_context* api, gvr_audio_source_id source_id, - bool looping_enabled); - -/// Pauses the playback of a sound. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param source_id Id of the audio source to be paused. -void gvr_audio_pause_sound(gvr_audio_context* api, - gvr_audio_source_id source_id); - -/// Resumes the playback of a sound. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param source_id Id of the audio source to be resumed. -void gvr_audio_resume_sound(gvr_audio_context* api, - gvr_audio_source_id source_id); - -/// Stops the playback of a sound and destroys the corresponding sound object -/// or Soundfield. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param source_id Id of the audio source to be stopped. -void gvr_audio_stop_sound(gvr_audio_context* api, - gvr_audio_source_id source_id); - -/// Repositions an existing sound object. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param sound_object_id Id of the sound object to be moved. -/// @param x X coordinate the sound will be placed at. -/// @param y Y coordinate the sound will be placed at. -/// @param z Z coordinate the sound will be placed at. -void gvr_audio_set_sound_object_position(gvr_audio_context* api, - gvr_audio_source_id sound_object_id, - float x, float y, float z); - -/// Sets the given ambisonic soundfields's rotation. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param soundfield_id Id of the soundfield source to be rotated. -/// @param soundfield_rotation Quaternion representing the soundfield rotation. -void gvr_audio_set_soundfield_rotation(gvr_audio_context* api, - gvr_audio_source_id soundfield_id, - const gvr_quatf& soundfield_rotation); - -/// Sets the given sound object source's distance attenuation method with -/// minimum and maximum distances. Maximum distance must be greater than the -/// minimum distance for the method to be set. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param sound_object_id Id of sound object source. -/// @param rolloff_model Linear or logarithmic distance rolloff models. Note -/// setting the rolloff model to |GVR_AUDIO_ROLLOFF_NONE| will allow -/// distance attenuation values to be set manually. -/// @param min_distance Minimum distance to apply distance attenuation method. -/// @param max_distance Maximum distance to apply distance attenuation method. -void gvr_audio_set_sound_object_distance_rolloff_model( - gvr_audio_context* api, gvr_audio_source_id sound_object_id, - int32_t rolloff_model, float min_distance, float max_distance); - -/// Changes the volume of an existing sound. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param source_id Id of the audio source to be modified. -/// @param volume Volume value. Should range from 0 (mute) to 1 (max). -void gvr_audio_set_sound_volume(gvr_audio_context* api, - gvr_audio_source_id source_id, float volume); - -/// Checks if a sound is playing. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param source_id Id of the audio source to be checked. -/// @return True if the sound is being played. -bool gvr_audio_is_sound_playing(const gvr_audio_context* api, - gvr_audio_source_id source_id); - -/// Sets the head pose from a matrix representation of the same. -/// -/// @param api Pointer to a gvr_audio_context on which to set the pose. -/// @param head_pose_matrix Matrix representing the head transform to be set. -void gvr_audio_set_head_pose(gvr_audio_context* api, - const gvr_mat4f& head_pose_matrix); - -/// Turns on/off the room reverberation effect. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param enable True to enable room effect. -void gvr_audio_enable_room(gvr_audio_context* api, bool enable); - -/// Sets the room properties describing the dimensions and surface materials of -/// a given room. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param size_x Dimension along X axis. -/// @param size_y Dimension along Y axis. -/// @param size_z Dimension along Z axis. -/// @param wall_material Surface gvr_audio_material_type for the four walls. -/// @param ceiling_material Surface gvr_audio_material_type for the ceiling. -/// @param floor_material Surface gvr_audio_material_type for the floor. -void gvr_audio_set_room_properties(gvr_audio_context* api, float size_x, - float size_y, float size_z, - int32_t wall_material, - int32_t ceiling_material, - int32_t floor_material); - -/// Adjusts the properties of the current reverb, allowing changes to the -/// reverb's gain, duration and low/high frequency balance. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param gain Reverb volume (linear) adjustment in range [0, 1] for -/// attenuation, range [1, inf) for gain boost. -/// @param time_adjust Reverb time adjustment multiplier to scale the -/// reverberation tail length. This value should be >= 0. -/// @param brightness_adjust Reverb brightness adjustment that controls the -/// reverberation ratio across low and high frequency bands. -void gvr_audio_set_room_reverb_adjustments(gvr_audio_context* api, float gain, - float time_adjust, - float brightness_adjust); - -/// Enables the stereo speaker mode. It enforces stereo-panning when headphones -/// are *not* plugged into the phone. This helps to avoid HRTF-based coloring -/// effects and reduces computational complexity when speaker playback is -/// active. By default the stereo speaker mode optimization is disabled. -/// -/// @param api Pointer to a gvr_audio_context. -/// @param enable True to enable the stereo speaker mode. -void gvr_audio_enable_stereo_speaker_mode(gvr_audio_context* api, bool enable); - -/// @} - -#ifdef __cplusplus -} // extern "C" -#endif - -// Convenience C++ wrapper. -#if defined(__cplusplus) && !defined(GVR_NO_CPP_WRAPPER) - -#include -#include - -namespace gvr { -/// This is a convenience C++ wrapper for the Audio C API. -/// -/// This wrapper strategy prevents ABI compatibility issues between compilers -/// by ensuring that the interface between client code and the implementation -/// code in libgvr.so is a pure C interface. The translation from C++ calls -/// to C calls provided by this wrapper runs entirely in the client's binary -/// and is compiled by the client's compiler. -/// -/// Methods in this class are only documented insofar as the C++ wrapping logic -/// is concerned; for information about the method itself, please refer to the -/// corresponding function in the C API. -/// -/// -/// THREADING: this class is thread-safe and reentrant after initialized -/// with Init(). -class AudioApi { - public: - /// Creates an (uninitialized) ControllerApi object. You must initialize - /// it by calling Init() before interacting with it. - AudioApi() : context_(nullptr) {} - - ~AudioApi() { - if (context_) { - gvr_audio_destroy(&context_); - } - } - -/// Creates and initializes a gvr_audio_context. -/// For more information, see gvr_audio_create(). -#ifdef __ANDROID__ - bool Init(JNIEnv* env, jobject android_context, jobject class_loader, - AudioRenderingMode rendering_mode) { - context_ = - gvr_audio_create(env, android_context, class_loader, rendering_mode); - return context_ != nullptr; - } -#else - bool Init(AudioRenderingMode rendering_mode) { - context_ = gvr_audio_create(rendering_mode); - return context_ != nullptr; - } -#endif // #ifdef __ANDROID__ - - /// Pauses the audio engine. - /// For more information, see gvr_audio_pause(). - void Pause() { gvr_audio_pause(context_); } - - /// Resumes the audio engine. - /// For more information, see gvr_audio_resume(). - void Resume() { gvr_audio_resume(context_); } - - /// For more information, see gvr_audio_update(). - void Update() { gvr_audio_update(context_); } - - /// Preloads a local sound file. - /// For more information, see gvr_audio_preload_soundfile(). - bool PreloadSoundfile(const std::string& filename) { - return gvr_audio_preload_soundfile(context_, filename.c_str()); - } - - /// Unloads a previously preloaded sample from memory. - /// For more information, see gvr_audio_preload_soundfile(). - void UnloadSoundfile(const std::string& filename) { - gvr_audio_unload_soundfile(context_, filename.c_str()); - } - - /// Returns a new sound object. - /// For more information, see gvr_audio_create_sound_object(). - AudioSourceId CreateSoundObject(const std::string& filename) { - return gvr_audio_create_sound_object(context_, filename.c_str()); - } - - /// Returns a new sound field. - /// For more information, see gvr_audio_create_soundfield(). - AudioSourceId CreateSoundfield(const std::string& filename) { - return gvr_audio_create_soundfield(context_, filename.c_str()); - } - - /// Returns a new stereo soound. - /// For more information, see gvr_audio_create_stereo_sound(). - AudioSourceId CreateStereoSound(const std::string& filename) { - return gvr_audio_create_stereo_sound(context_, filename.c_str()); - } - - /// Starts the playback of a sound. - /// For more information, see gvr_audio_play_sound(). - void PlaySound(AudioSourceId source_id, bool looping_enabled) { - gvr_audio_play_sound(context_, source_id, looping_enabled); - } - - /// Pauses the playback of a sound. - /// For more information, see gvr_audio_pause_sound(). - void PauseSound(AudioSourceId source_id) { - gvr_audio_pause_sound(context_, source_id); - } - - /// Resumes the playback of a sound. - /// For more information, see gvr_audio_resume_sound(). - void ResumeSound(AudioSourceId source_id) { - gvr_audio_resume_sound(context_, source_id); - } - - /// Stops the playback of a sound. - /// For more information, see gvr_audio_stop_sound(). - void StopSound(AudioSourceId source_id) { - gvr_audio_stop_sound(context_, source_id); - } - - /// Repositions an existing sound object. - /// For more information, see gvr_audio_set_sound_object_position(). - void SetSoundObjectPosition(AudioSourceId sound_object_id, float x, float y, - float z) { - gvr_audio_set_sound_object_position(context_, sound_object_id, x, y, z); - } - - void SetSoundObjectDistanceRolloffModel( - AudioSourceId sound_object_id, - gvr_audio_distance_rolloff_type rolloff_model, float min_distance, - float max_distance) { - gvr_audio_set_sound_object_distance_rolloff_model( - context_, sound_object_id, rolloff_model, min_distance, max_distance); - } - - /// Rotates an existing soundfield. - /// For more information, see gvr_audio_set_soundfield_rotation(). - void SetSoundfieldRotation(AudioSourceId soundfield_id, - const Quatf& soundfield_rotation) { - gvr_audio_set_soundfield_rotation(context_, soundfield_id, - soundfield_rotation); - } - - /// Changes the volume of an existing sound. - /// For more information, see gvr_audio_set_sound_volume(). - void SetSoundVolume(AudioSourceId source_id, float volume) { - gvr_audio_set_sound_volume(context_, source_id, volume); - } - - /// Checks if a sound is playing. - /// For more information, see gvr_audio_is_sound_playing(). - bool IsSoundPlaying(AudioSourceId source_id) const { - return gvr_audio_is_sound_playing(context_, source_id); - } - - /// Sets the head position from a matrix representation. - /// For more information, see gvr_audio_set_head_pose(). - void SetHeadPose(const Mat4f& head_pose_matrix) { - gvr_audio_set_head_pose(context_, head_pose_matrix); - } - - /// Turns on/off the room reverberation effect. - /// For more information, see gvr_audio_enable_room(). - void EnableRoom(bool enable) { gvr_audio_enable_room(context_, enable); } - - /// Sets the room properties describing the dimensions and surface materials - /// of a given room. For more information, see - /// gvr_audio_set_room_properties(). - void SetRoomProperties(float size_x, float size_y, float size_z, - gvr_audio_material_type wall_material, - gvr_audio_material_type ceiling_material, - gvr_audio_material_type floor_material) { - gvr_audio_set_room_properties(context_, size_x, size_y, size_z, - wall_material, ceiling_material, - floor_material); - } - - /// Adjusts the properties of the current reverb, allowing changes to the - /// reverb's gain, duration and low/high frequency balance. For more - /// information see gvr_audio_set_room_reverb_adjustments(). - void SetRoomReverbAdjustments(float gain, float time_adjust, - float brightness_adjust) { - gvr_audio_set_room_reverb_adjustments(context_, gain, time_adjust, - brightness_adjust); - } - - /// Enables the stereo speaker mode. For more information see - /// gvr_audio_enable_stereo_speaker_mode(). - void EnableStereoSpeakerMode(bool enable) { - gvr_audio_enable_stereo_speaker_mode(context_, enable); - } - - /// @name Wrapper manipulation - /// @{ - /// Creates a C++ wrapper for a C object and takes ownership. - explicit AudioApi(gvr_audio_context* context) - : context_(context) {} - - /// Returns the wrapped C object. Does not affect ownership. - gvr_audio_context* cobj() { return context_; } - const gvr_audio_context* cobj() const { return context_; } - - /// Returns the wrapped C object and transfers its ownership to the caller. - /// The wrapper becomes invalid and should not be used. - gvr_audio_context* Release() { - auto result = context_; - context_ = nullptr; - return result; - } - /// @} - - private: - gvr_audio_context* context_; - - // Disallow copy and assign: - AudioApi(const AudioApi&); - void operator=(const AudioApi&); -}; - -} // namespace gvr -#endif // #if defined(__cplusplus) && !defined(GVR_NO_CPP_WRAPPER) - -#endif // VR_GVR_CAPI_INCLUDE_GVR_AUDIO_H_ diff --git a/deps/GoogleVR/vr/gvr/capi/include/gvr_controller.h b/deps/GoogleVR/vr/gvr/capi/include/gvr_controller.h deleted file mode 100644 index 1c01f9d37e..0000000000 --- a/deps/GoogleVR/vr/gvr/capi/include/gvr_controller.h +++ /dev/null @@ -1,734 +0,0 @@ -/* Copyright 2016 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VR_GVR_CAPI_INCLUDE_GVR_CONTROLLER_H_ -#define VR_GVR_CAPI_INCLUDE_GVR_CONTROLLER_H_ - -#ifdef __ANDROID__ -#include -#endif - -#include - -#include "vr/gvr/capi/include/gvr.h" -#include "vr/gvr/capi/include/gvr_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/// @defgroup Controller Controller API -/// @brief This is the Controller C API, which allows access to a VR controller. -/// -/// If you are writing C++ code, you might prefer to use the C++ wrapper rather -/// than implement this C API directly. -/// -/// Typical initialization example: -/// -/// // Get your gvr_context* pointer from GvrLayout: -/// gvr_context* gvr = ......; // (get from GvrLayout in Java) -/// -/// // Set up the API features: -/// int32_t options = gvr_controller_get_default_options(); -/// -/// // Enable non-default options, if needed: -/// options |= GVR_CONTROLLER_ENABLE_GYRO | GVR_CONTROLLER_ENABLE_ACCEL; -/// -/// // Create and init: -/// gvr_controller_context* context = -/// gvr_controller_create_and_init(options, gvr); -/// -/// // Check if init was successful. -/// if (!context) { -/// // Handle error. -/// return; -/// } -/// -/// gvr_controller_state* state = gvr_controller_state_create(); -/// -/// // Resume: -/// gvr_controller_resume(api); -/// -/// Usage: -/// -/// void DrawFrame() { -/// gvr_controller_state_update(context, 0, state); -/// // ... process controller state ... -/// } -/// -/// // When your application gets paused: -/// void OnPause() { -/// gvr_controller_pause(context); -/// } -/// -/// // When your application gets resumed: -/// void OnResume() { -/// gvr_controller_resume(context); -/// } -/// -/// To conserve battery, be sure to call gvr_controller_pause and -/// gvr_controller_resume when your app gets paused and resumed, respectively. -/// -/// THREADING: unless otherwise noted, all functions are thread-safe, so -/// you can operate on the same gvr_controller_context object from multiple -/// threads. -/// @{ - -/// Represents a Daydream Controller API object, used to invoke the -/// Daydream Controller API. -typedef struct gvr_controller_context_ gvr_controller_context; - -/// Returns the default features for the controller API. -/// -/// @return The set of default features, as bit flags (an OR'ed combination of -/// the GVR_CONTROLLER_ENABLE_* feature flags). -int32_t gvr_controller_get_default_options(); - -/// Creates and initializes a gvr_controller_context instance which can be used -/// to invoke the Daydream Controller API functions. Important: after creation -/// the API will be in the paused state (the controller will be inactive). -/// You must call gvr_controller_resume() explicitly (typically, in your Android -/// app's onResume() callback). -/// -/// @param options The API options. To get the defaults, use -/// gvr_controller_get_default_options(). -/// @param context The GVR Context object to sync with (optional). -/// This can be nullptr. If provided, the context's state will -/// be synchronized with the controller's state where possible. For -/// example, when the user recenters the controller, this will -/// automatically recenter head tracking as well. -/// WARNING: the caller is responsible for making sure the pointer -/// remains valid for the lifetime of this object. -/// @return A pointer to the initialized API, or NULL if an error occurs. -gvr_controller_context* gvr_controller_create_and_init( - int32_t options, gvr_context* context); - -#ifdef __ANDROID__ -/// Creates and initializes a gvr_controller_context instance with an explicit -/// Android context and class loader. -/// -/// @param env The JNI Env associated with the current thread. -/// @param android_context The Android application context. This must be the -/// application context, NOT an Activity context (Note: from any Android -/// Activity in your app, you can call getApplicationContext() to -/// retrieve the application context). -/// @param class_loader The class loader to use when loading Java -/// classes. This must be your app's main class loader (usually -/// accessible through activity.getClassLoader() on any of your Activities). -/// @param options The API options. To get the defaults, use -/// gvr_controller_get_default_options(). -/// @param context The GVR Context object to sync with (optional). -/// This can be nullptr. If provided, the context's state will -/// be synchronized with the controller's state where possible. For -/// example, when the user recenters the controller, this will -/// automatically recenter head tracking as well. -/// WARNING: the caller is responsible for making sure the pointer -/// remains valid for the lifetime of this object. -/// @return A pointer to the initialized API, or NULL if an error occurs. -gvr_controller_context* gvr_controller_create_and_init_android( - JNIEnv *env, jobject android_context, jobject class_loader, - int32_t options, gvr_context* context); -#endif // #ifdef __ANDROID__ - -/// Destroys a gvr_controller_context that was previously created with -/// gvr_controller_init. -/// -/// @param api Pointer to a pointer to a gvr_controller_context. The pointer -/// will be set to NULL after destruction. -void gvr_controller_destroy(gvr_controller_context** api); - -/// Pauses the controller, possibly releasing resources. -/// Call this when your app/game loses focus. -/// Calling this when already paused is a no-op. -/// Thread-safe (call from any thread). -/// -/// @param api Pointer to a pointer to a gvr_controller_context. -void gvr_controller_pause(gvr_controller_context* api); - -/// Resumes the controller. Call this when your app/game regains focus. -/// Calling this when already resumed is a no-op. -/// Thread-safe (call from any thread). -/// -/// @param api Pointer to a pointer to a gvr_controller_context. -void gvr_controller_resume(gvr_controller_context* api); - -/// Convenience to convert an API status code to string. The returned pointer -/// is static and valid throughout the lifetime of the application. -/// -/// @param status The gvr_controller_api_status to convert to string. -/// @return A pointer to a string that describes the value. -const char* gvr_controller_api_status_to_string(int32_t status); - -/// Convenience to convert an connection state to string. The returned pointer -/// is static and valid throughout the lifetime of the application. -/// -/// @param state The state to convert to string. -/// @return A pointer to a string that describes the value. -const char* gvr_controller_connection_state_to_string(int32_t state); - -/// Convenience to convert an connection state to string. The returned pointer -/// is static and valid throughout the lifetime of the application. -/// -/// @param button The gvr_controller_button to convert to string. -/// @return A pointer to a string that describes the value. -const char* gvr_controller_button_to_string(int32_t button); - -/// Creates a gvr_controller_state. -gvr_controller_state* gvr_controller_state_create(); - -/// Destroys a a gvr_controller_state that was previously created with -/// gvr_controller_state_create. -void gvr_controller_state_destroy(gvr_controller_state** state); - -/// Updates the controller state. Reading the controller state is not a -/// const getter: it has side-effects. In particular, some of the -/// gvr_controller_state fields (the ones documented as "transient") represent -/// one-time events and will be true for only one read operation, and false -/// in subsequente reads. -/// -/// @param api Pointer to a pointer to a gvr_controller_context. -/// @param flags Optional flags reserved for future use. A value of 0 should be -/// used until corresponding flag attributes are defined and documented. -/// @param out_state A pointer where the controller's state -/// is to be written. This must have been allocated with -/// gvr_controller_state_create(). -void gvr_controller_state_update(gvr_controller_context* api, int32_t flags, - gvr_controller_state* out_state); - -/// Gets the API status of the controller state. Returns one of the -/// gvr_controller_api_status variants, but returned as an int32_t for ABI -/// compatibility. -int32_t gvr_controller_state_get_api_status(const gvr_controller_state* state); - -/// Gets the connection state of the controller. Returns one of the -/// gvr_controller_connection_state variants, but returned as an int32_t for ABI -/// compatibility. -int32_t gvr_controller_state_get_connection_state( - const gvr_controller_state* state); - -/// Returns the current controller orientation, in Start Space. The Start Space -/// is the same space as the headset space and has these three axes -/// (right-handed): -/// -/// * The positive X axis points to the right. -/// * The positive Y axis points upwards. -/// * The positive Z axis points backwards. -/// -/// The definition of "backwards" and "to the right" are based on the position -/// of the controller when tracking started. For Daydream, this is when the -/// controller was first connected in the "Connect your Controller" screen -/// which is shown when the user enters VR. -/// -/// The definition of "upwards" is given by gravity (away from the pull of -/// gravity). This API may not work in environments without gravity, such -/// as space stations or near the center of the Earth. -/// -/// Since the coordinate system is right-handed, rotations are given by the -/// right-hand rule. For example, rotating the controller counter-clockwise -/// on a table top as seen from above means a positive rotation about the -/// Y axis, while clockwise would mean negative. -/// -/// Note that this is the Start Space for the *controller*, which initially -/// coincides with the Start Space for the headset, but they may diverge over -/// time due to controller/headset drift. A recentering operation will bring -/// the two spaces back into sync. -/// -/// Remember that a quaternion expresses a rotation. Given a rotation of theta -/// radians about the (x, y, z) axis, the corresponding quaternion (in -/// xyzw order) is: -/// -/// (x * sin(theta/2), y * sin(theta/2), z * sin(theta/2), cos(theta/2)) -/// -/// Here are some examples of orientations of the controller and their -/// corresponding quaternions, all given in xyzw order: -/// -/// * Initial pose, pointing forward and lying flat on a surface: identity -/// quaternion (0, 0, 0, 1). Corresponds to "no rotation". -/// -/// * Flat on table, rotated 90 degrees counter-clockwise: (0, 0.7071, 0, -/// 0.7071). Corresponds to a +90 degree rotation about the Y axis. -/// -/// * Flat on table, rotated 90 degrees clockwise: (0, -0.7071, 0, 0.7071). -/// Corresponds to a -90 degree rotation about the Y axis. -/// -/// * Flat on table, rotated 180 degrees (pointing backwards): (0, 1, 0, 0). -/// Corresponds to a 180 degree rotation about the Y axis. -/// -/// * Pointing straight up towards the sky: (0.7071, 0, 0, 0.7071). -/// Corresponds to a +90 degree rotation about the X axis. -/// -/// * Pointing straight down towards the ground: (-0.7071, 0, 0, 0.7071). -/// Corresponds to a -90 degree rotation about the X axis. -/// -/// * Banked 90 degrees to the left: (0, 0, 0.7071, 0.7071). Corresponds -/// to a +90 degree rotation about the Z axis. -/// -/// * Banked 90 degrees to the right: (0, 0, -0.7071, 0.7071). Corresponds -/// to a -90 degree rotation about the Z axis. -gvr_quatf gvr_controller_state_get_orientation( - const gvr_controller_state* state); - -/// Returns the current controller gyro reading, in Start Space. -/// -/// The gyro measures the controller's angular speed in radians per second. -/// Note that this is an angular *speed*, so it reflects how fast the -/// controller's orientation is changing with time. -/// In particular, if the controller is not being rotated, the angular speed -/// will be zero on all axes, regardless of the current pose. -/// -/// The axes are in the controller's device space. Specifically: -/// -/// * The X axis points to the right of the controller. -/// * The Y axis points upwards perpendicular to the top surface of the -/// controller. -/// * The Z axis points backwards along the body of the controller, -/// towards its rear, where the charging port is. -/// -/// As usual in a right-handed coordinate system, the sign of the angular -/// velocity is given by the right-hand rule. So, for example: -/// -/// * If the controller is flat on a table top spinning counter-clockwise -/// as seen from above, you will read a positive angular velocity -/// about the Y axis. Clockwise would be negative. -/// * If the controller is initially pointing forward and lying flat and -/// is then gradually angled up so that its tip points towards the sky, -/// it will report a positive angular velocity about the X axis during -/// that motion. Likewise, angling it down will report a negative angular -/// velocity about the X axis. -/// * If the controller is banked (rolled) to the right, this will -/// report a negative angular velocity about the Z axis during the -/// motion (remember the Z axis points backwards along the controller). -/// Banking to the left will report a positive angular velocity about -/// the Z axis. -gvr_vec3f gvr_controller_state_get_gyro(const gvr_controller_state* state); - -/// Current (latest) controller accelerometer reading, in Start Space. -/// -/// The accelerometer indicates the direction in which the controller feels -/// an acceleration, including gravity. The reading is given in meters -/// per second squared (m/s^2). The axes are the same as for the gyro. -/// To have an intuition for the signs used in the accelerometer, it is useful -/// to imagine that, when at rest, the controller is being "pushed" by a -/// force opposite to gravity. It is as if, by the equivalency princle, it were -/// on a frame of reference that is accelerating in the opposite direction to -/// gravity. For example: -/// -/// * If the controller is lying flat on a table top, it will read a positive -/// acceleration of about 9.8 m/s^2 along the Y axis, corresponding to -/// the acceleration of gravity (as if the table were pushing the controller -/// upwards at 9.8 m/s^2 to counteract gravity). -/// * If, in that situation, the controller is now accelerated upwards at -/// 3.0 m/s^2, then the reading will be 12.8 m/s^2 along the Y axis, -/// since the controller will now feel a stronger acceleration corresponding -/// to the 9.8 m/s^2 plus the upwards push of 3.0 m/s^2. -/// * If, the controller is accelerated downwards at 5.0 m/s^2, then the -/// reading will now be 4.8 m/s^2 along the Y axis, since the controller -/// will now feel a weaker acceleration (as the acceleration is giving in -/// to gravity). -/// * If you were to give in to gravity completely, letting the controller -/// free fall towards the ground, it will read 0 on all axes, as there -/// will be no force acting on the controller. (Please do not put your -/// controller in a free-fall situation. This is just a theoretical -/// example.) -gvr_vec3f gvr_controller_state_get_accel(const gvr_controller_state* state); - -/// Returns whether the user is touching the touchpad. -bool gvr_controller_state_is_touching(const gvr_controller_state* state); - -/// If the user is touching the touchpad, this returns the touch position in -/// normalized coordinates, where (0,0) is the top-left of the touchpad -/// and (1,1) is the bottom right. If the user is not touching the touchpad, -/// then this is the position of the last touch. -gvr_vec2f gvr_controller_state_get_touch_pos(const gvr_controller_state* state); - -/// Returns true if user just started touching touchpad (this is a transient -/// event: -/// it is true for only one frame after the event). -bool gvr_controller_state_get_touch_down(const gvr_controller_state* state); - -/// Returns true if user just stopped touching touchpad (this is a transient -/// event: -/// it is true for only one frame after the event). -bool gvr_controller_state_get_touch_up(const gvr_controller_state* state); - -/// Returns true if a recenter operation just ended (this is a transient event: -/// it is true only for one frame after the recenter ended). If this is -/// true then the `orientation` field is already relative to the new center. -bool gvr_controller_state_get_recentered(const gvr_controller_state* state); - -/// Returns whether the recenter flow is currently in progress. -/// -/// @deprecated Use gvr_controller_state_get_recentered instead. -bool gvr_controller_state_get_recentering(const gvr_controller_state* state); - -/// Returns whether the given button is currently pressed. -bool gvr_controller_state_get_button_state(const gvr_controller_state* state, - - int32_t button); - -/// Returns whether the given button was just pressed (transient). -bool gvr_controller_state_get_button_down(const gvr_controller_state* state, - int32_t button); - -/// Returns whether the given button was just released (transient). -bool gvr_controller_state_get_button_up(const gvr_controller_state* state, - int32_t button); - -/// Returns the timestamp (nanos) when the last orientation event was received. -int64_t gvr_controller_state_get_last_orientation_timestamp( - const gvr_controller_state* state); - -/// Returns the timestamp (nanos) when the last gyro event was received. -int64_t gvr_controller_state_get_last_gyro_timestamp( - const gvr_controller_state* state); - -/// Returns the timestamp (nanos) when the last accelerometer event was -/// received. -int64_t gvr_controller_state_get_last_accel_timestamp( - const gvr_controller_state* state); - -/// Returns the timestamp (nanos) when the last touch event was received. -int64_t gvr_controller_state_get_last_touch_timestamp( - const gvr_controller_state* state); - -/// Returns the timestamp (nanos) when the last button event was received. -int64_t gvr_controller_state_get_last_button_timestamp( - const gvr_controller_state* state); - -/// @} - -#ifdef __cplusplus -} // extern "C" -#endif - - -// Convenience C++ wrapper. -#if defined(__cplusplus) && !defined(GVR_NO_CPP_WRAPPER) - -#include - -namespace gvr { -/// This is a convenience C++ wrapper for the Controller C API. -/// -/// This wrapper strategy prevents ABI compatibility issues between compilers -/// by ensuring that the interface between client code and the implementation -/// code in libgvr.so is a pure C interface. The translation from C++ calls -/// to C calls provided by this wrapper runs entirely in the client's binary -/// and is compiled by the client's compiler. -/// -/// Methods in this class are only documented insofar as the C++ wrapping logic -/// is concerned; for information about the method itself, please refer to the -/// corresponding function in the C API. -/// -/// Typical C++ initialization example: -/// -/// std::unique_ptr controller_api(new ControllerApi); -/// -/// // Your GVR context pointer (which can be obtained from GvrLayout) -/// gvr_context* context = .....; // (get it from GvrLayout) -/// -/// // Set up the options: -/// int32_t options = ControllerApi::DefaultOptions(); -/// -/// // Enable non-default options, if you need them: -/// options |= GVR_CONTROLLER_ENABLE_GYRO; -/// -/// // Init the ControllerApi object: -/// bool success = controller_api->Init(options, context); -/// if (!success) { -/// // Handle failure. -/// // Do NOT call other methods (like Resume, etc) if init failed. -/// return; -/// } -/// -/// // Resume the ControllerApi (if your app is on the foreground). -/// controller_api->Resume(); -/// -/// ControllerState state; -/// -/// Usage example: -/// -/// void DrawFrame() { -/// state.Update(*controller_api); -/// // ... process controller state ... -/// } -/// -/// // When your application gets paused: -/// void OnPause() { -/// controller_api->Pause(); -/// } -/// -/// // When your application gets resumed: -/// void OnResume() { -/// controller_api->Resume(); -/// } -/// -/// To conserve battery, be sure to call Pause() and Resume() when your app -/// gets paused and resumed, respectively. This will allow the underlying -/// logic to unbind from the VR service and let the controller sleep when -/// no apps are using it. -/// -/// THREADING: this class is thread-safe and reentrant after initialized -/// with Init(). -class ControllerApi { - public: - /// Creates an (uninitialized) ControllerApi object. You must initialize - /// it by calling Init() before interacting with it. - ControllerApi() : context_(nullptr) {} - - /// Returns the default controller options. - static int32_t DefaultOptions() { - return gvr_controller_get_default_options(); - } - - // Deprecated factory-style create method. - // TODO(btco): remove this once no one is using it. - static std::unique_ptr Create() { - return std::unique_ptr(new ControllerApi); - } - - /// Initializes the controller API. - /// - /// This method must be called exactly once in the lifetime of this object. - /// Other methods in this class may only be called after Init() returns true. - /// Note: this does not cause the ControllerApi to be resumed. You must call - /// Resume() explicitly in order to start using the controller. - /// - /// For more information see gvr_controller_create_and_init(). - /// - /// @return True if initialization was successful, false if it failed. - /// Initialization may fail, for example, because invalid options were - /// supplied. - bool Init(int32_t options, gvr_context* context) { - context_ = gvr_controller_create_and_init(options, context); - return context_ != nullptr; - } - -#ifdef __ANDROID__ - /// Overload of Init() with explicit Android context and class loader - /// (for Android only). For more information, see: - /// gvr_controller_create_and_init_android(). - bool Init(JNIEnv *env, jobject android_context, jobject class_loader, - int32_t options, gvr_context* context) { - context_ = gvr_controller_create_and_init_android( - env, android_context, class_loader, options, context); - return context_ != nullptr; - } -#endif // #ifdef __ANDROID__ - - /// Convenience overload that calls Init without a gvr_context. - // TODO(btco): remove once it is no longer being used. - bool Init(int32_t options) { - return Init(options, nullptr); - } - - /// Pauses the controller. - /// For more information, see gvr_controller_pause(). - void Pause() { - gvr_controller_pause(context_); - } - - /// Resumes the controller. - /// For more information, see gvr_controller_resume(). - void Resume() { - gvr_controller_resume(context_); - } - - /// Destroys this ControllerApi instance. - ~ControllerApi() { - if (context_) gvr_controller_destroy(&context_); - } - - /// Convenience functions to convert enums to strings. - /// For more information, see the corresponding functions in the C API. - static const char* ToString(ControllerApiStatus status) { - return gvr_controller_api_status_to_string(status); - } - - static const char* ToString(ControllerConnectionState state) { - return gvr_controller_connection_state_to_string(state); - } - - static const char* ToString(ControllerButton button) { - return gvr_controller_button_to_string(button); - } - - /// @name Wrapper manipulation - /// @{ - /// Creates a C++ wrapper for a C object and takes ownership. - explicit ControllerApi(gvr_controller_context* context) - : context_(context) {} - - /// Returns the wrapped C object. Does not affect ownership. - gvr_controller_context* cobj() { return context_; } - const gvr_controller_context* cobj() const { return context_; } - - /// Returns the wrapped C object and transfers its ownership to the caller. - /// The wrapper becomes invalid and should not be used. - gvr_controller_context* release() { - auto result = context_; - context_ = nullptr; - return result; - } - /// @} - - protected: - gvr_controller_context* context_; - - private: - friend class ControllerState; - - // Disallow copy and assign: - ControllerApi(const ControllerApi&); - void operator=(const ControllerApi&); -}; - -/// Convenience C++ wrapper for the opaque gvr_controller_state type. See the -/// gvr_controller_state functions for more information. -class ControllerState { - public: - ControllerState() : state_(gvr_controller_state_create()) {} - - ~ControllerState() { - if (state_) gvr_controller_state_destroy(&state_); - } - - /// For more information, see gvr_controller_state_update(). - void Update(const ControllerApi& api) { - gvr_controller_state_update(api.context_, 0, state_); - } - - /// For more information, see gvr_controller_state_update(). - void Update(const ControllerApi& api, int32_t flags) { - gvr_controller_state_update(api.context_, flags, state_); - } - - /// For more information, see gvr_controller_state_get_api_status(). - ControllerApiStatus GetApiStatus() const { - return static_cast( - gvr_controller_state_get_api_status(state_)); - } - - /// For more information, see gvr_controller_state_get_connection_state(). - ControllerConnectionState GetConnectionState() const { - return static_cast( - gvr_controller_state_get_connection_state(state_)); - } - - /// For more information, see gvr_controller_state_get_orientation(). - gvr_quatf GetOrientation() const { - return gvr_controller_state_get_orientation(state_); - } - - /// For more information, see gvr_controller_state_get_gyro(). - gvr_vec3f GetGyro() const { return gvr_controller_state_get_gyro(state_); } - - /// For more information, see gvr_controller_state_get_accel(). - gvr_vec3f GetAccel() const { return gvr_controller_state_get_accel(state_); } - - /// For more information, see gvr_controller_state_is_touching(). - bool IsTouching() const { return gvr_controller_state_is_touching(state_); } - - /// For more information, see gvr_controller_state_get_touch_pos(). - gvr_vec2f GetTouchPos() const { - return gvr_controller_state_get_touch_pos(state_); - } - - /// For more information, see gvr_controller_state_get_touch_down(). - bool GetTouchDown() const { - return gvr_controller_state_get_touch_down(state_); - } - - /// For more information, see gvr_controller_state_get_touch_up(). - bool GetTouchUp() const { return gvr_controller_state_get_touch_up(state_); } - - /// For more information, see gvr_controller_state_get_recentered(). - bool GetRecentered() const { - return gvr_controller_state_get_recentered(state_); - } - - /// For more information, see gvr_controller_state_get_recentering(). - bool GetRecentering() const { - return gvr_controller_state_get_recentering(state_); - } - - /// For more information, see gvr_controller_state_get_button_state(). - bool GetButtonState(ControllerButton button) const { - return gvr_controller_state_get_button_state(state_, button); - } - - /// For more information, see gvr_controller_state_get_button_down(). - bool GetButtonDown(ControllerButton button) const { - return gvr_controller_state_get_button_down(state_, button); - } - - /// For more information, see gvr_controller_state_get_button_up(). - bool GetButtonUp(ControllerButton button) const { - return gvr_controller_state_get_button_up(state_, button); - } - - /// For more information, see - /// gvr_controller_state_get_last_orientation_timestamp(). - int64_t GetLastOrientationTimestamp() const { - return gvr_controller_state_get_last_orientation_timestamp(state_); - } - - /// For more information, see gvr_controller_state_get_last_gyro_timestamp(). - int64_t GetLastGyroTimestamp() const { - return gvr_controller_state_get_last_gyro_timestamp(state_); - } - - /// For more information, see gvr_controller_state_get_last_accel_timestamp(). - int64_t GetLastAccelTimestamp() const { - return gvr_controller_state_get_last_accel_timestamp(state_); - } - - /// For more information, see gvr_controller_state_get_last_touch_timestamp(). - int64_t GetLastTouchTimestamp() const { - return gvr_controller_state_get_last_touch_timestamp(state_); - } - - /// For more information, see - /// gvr_controller_state_get_last_button_timestamp(). - int64_t GetLastButtonTimestamp() const { - return gvr_controller_state_get_last_button_timestamp(state_); - } - - /// @name Wrapper manipulation - /// @{ - /// Creates a C++ wrapper for a C object and takes ownership. - explicit ControllerState(gvr_controller_state* state) : state_(state) {} - - /// Returns the wrapped C object. Does not affect ownership. - gvr_controller_state* cobj() { return state_; } - const gvr_controller_state* cobj() const { return state_; } - - /// Returns the wrapped C object and transfers its ownership to the caller. - /// The wrapper becomes invalid and should not be used. - gvr_controller_state* release() { - auto result = state_; - state_ = nullptr; - return result; - } - /// @} - - private: - gvr_controller_state* state_; -}; - -} // namespace gvr -#endif // #if defined(__cplusplus) && !defined(GVR_NO_CPP_WRAPPER) - -#endif // VR_GVR_CAPI_INCLUDE_GVR_CONTROLLER_H_ diff --git a/deps/GoogleVR/vr/gvr/capi/include/gvr_types.h b/deps/GoogleVR/vr/gvr/capi/include/gvr_types.h deleted file mode 100644 index b8ee73d9d8..0000000000 --- a/deps/GoogleVR/vr/gvr/capi/include/gvr_types.h +++ /dev/null @@ -1,558 +0,0 @@ -/* Copyright 2016 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VR_GVR_CAPI_INCLUDE_GVR_TYPES_H_ -#define VR_GVR_CAPI_INCLUDE_GVR_TYPES_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/// @defgroup types Google VR Types -/// @brief Various types used in the Google VR NDK. -/// @{ - -/// Primary context for invoking Google VR APIs. -typedef struct gvr_context_ gvr_context; - -/// An enum for the left and right eye. -typedef enum { - GVR_LEFT_EYE = 0, - GVR_RIGHT_EYE, - GVR_NUM_EYES -} gvr_eye; - -/// The type of VR viewer. -typedef enum { - /// A Cardboard-compatible viewer. A typical Cardboard viewer supports a - /// simple touchscreen-based trigger input mechanism. On most platforms, this - // is the default viewer type if no viewer has been explicitly paired. - GVR_VIEWER_TYPE_CARDBOARD = 0, - /// A Daydream-compatible viewer. A typical Daydream viewer supports 3DOF - /// controller input (as defined in gvr_controller.h), and is intended only - /// for Daydream-ready platforms. It does *not* support touchscreen-based - /// input unless Cardboard emulation is explicitly enabled. - GVR_VIEWER_TYPE_DAYDREAM = 1, -} gvr_viewer_type; - -/// @} - -/// Version information for the Google VR API. -typedef struct gvr_version_ { - int32_t major; - int32_t minor; - int32_t patch; -} gvr_version; - -/// An integral 2D size. Used for render target sizes. -typedef struct gvr_sizei { - int32_t width; - int32_t height; -} gvr_sizei; - -/// An integral 2D rect. Used for window bounds in pixels. -typedef struct gvr_recti { - int32_t left; - int32_t right; - int32_t bottom; - int32_t top; -} gvr_recti; - -/// A floating point 2D rect. Used for field of view, and also for ranges -/// in texture space. When used for a field of view, all angles are in positive -/// degrees from the optical axis. -typedef struct gvr_rectf { - float left; - float right; - float bottom; - float top; -} gvr_rectf; - -/// A floating point 2D vector. -typedef struct gvr_vec2f { - float x; - float y; -} gvr_vec2f; - -/// A floating point 3D vector. -typedef struct gvr_vec3f { - float x; - float y; - float z; -} gvr_vec3f; - -/// A floating point 4x4 matrix. -typedef struct gvr_mat4f { float m[4][4]; } gvr_mat4f; - -/// A floating point quaternion, in JPL format. -/// We use this simple struct in order not to impose a dependency on a -/// particular math library. The user of this API is free to encapsulate this -/// into any math library they want. -typedef struct gvr_quatf { - /// qx, qy, qz are the vector component. - float qx; - float qy; - float qz; - /// qw is the linelar component. - float qw; -} gvr_quatf; - -/// A *monotonic system time* representation. On Android, this is equivalent to -/// System.nanoTime(), or clock_gettime(CLOCK_MONOTONIC). If there is any doubt -/// about how to get the current time for the current platform, simply use -/// gvr_get_time_point_now(). -typedef struct gvr_clock_time_point { - int64_t monotonic_system_time_nanos; -} gvr_clock_time_point; - -/// A structure that ties together a region of a buffer, the field of view -/// rendered into that region and a target eye index to define part of the -/// user's field of view. The SDK implementation uses this information to -/// transform the images generated by the app output into the final display that -/// is sent to the screen. -/// -/// A set of these structures will most often be generated by the API, via -/// gvr_get_recommended_buffer_viewports() or -/// gvr_get_screen_buffer_viewports(). However, the client may also customize -/// these values via gvr_buffer_viewport_list_set(), constructing a custom -/// gvr_buffer_viewport_list for use in the distortion pass. -typedef struct gvr_buffer_viewport_ gvr_buffer_viewport; - -/// List of buffer viewports that completely specifies how to transform the -/// frame's buffers into the image displayed on the screen. -typedef struct gvr_buffer_viewport_list_ gvr_buffer_viewport_list; - -/// Specification of a pixel buffer. A pixel buffer can have color, depth and -/// stencil attachments and mostly corresponds to the OpenGL concept of a -/// framebuffer object. However, since there can be multiple such objects for -/// each frame, we avoid calling them "framebuffers". Pixel buffers which are -/// part of the currently acquired frame are immutable, i.e., they cannot be -/// resized or otherwise reconfigured. -typedef struct gvr_buffer_spec_ gvr_buffer_spec; - -/// Swap chain that contains some number of frames. Frames in the swap chain -/// can be unused, in the process of being distorted and presented on the -/// screen, or acquired and being rendered to by the application. The swap chain -/// ensures that the most recent available frame is always shown and that the -/// application never has to wait to render the next frame. -typedef struct gvr_swap_chain_ gvr_swap_chain; - -/// A single frame acquired from the swap chain. Each frame is composed of one -/// or more buffers, which are then lens distorted and composited into the final -/// output. Buffers are identified by indices that correspond to the position -/// of their gvr_buffer_spec in the list passed when constructing the swap -/// chain. -typedef struct gvr_frame_ gvr_frame; - -/// @addtogroup types -/// @{ - -/// Constants that represent GVR error codes. -typedef enum { - GVR_ERROR_NONE = 0, - GVR_ERROR_CONTROLLER_CREATE_FAILED = 2, - GVR_ERROR_NO_FRAME_AVAILABLE = 3, -} gvr_error; - -/// Controller API options (bit flags). -enum { - /// Indicates that controller orientation data should be reported. - GVR_CONTROLLER_ENABLE_ORIENTATION = 1 << 0, - /// Indicates that controller touchpad data should be reported. - GVR_CONTROLLER_ENABLE_TOUCH = 1 << 1, - /// Indicates that controller gyroscope data should be reported. - GVR_CONTROLLER_ENABLE_GYRO = 1 << 2, - /// Indicates that controller accelerometer data should be reported. - GVR_CONTROLLER_ENABLE_ACCEL = 1 << 3, - /// Indicates that controller gestures should be reported. - GVR_CONTROLLER_ENABLE_GESTURES = 1 << 4, - /// Indicates that controller pose prediction should be enabled. - GVR_CONTROLLER_ENABLE_POSE_PREDICTION = 1 << 5, -}; - -/// Constants that represent the status of the controller API. -typedef enum { - /// API is happy and healthy. This doesn't mean the controller itself - /// is connected, it just means that the underlying service is working - /// properly. - GVR_CONTROLLER_API_OK = 0, - - /// Any other status represents a permanent failure that requires - /// external action to fix: - - /// API failed because this device does not support controllers (API is too - /// low, or other required feature not present). - GVR_CONTROLLER_API_UNSUPPORTED = 1, - /// This app was not authorized to use the service (e.g., missing permissions, - /// the app is blacklisted by the underlying service, etc). - GVR_CONTROLLER_API_NOT_AUTHORIZED = 2, - /// The underlying VR service is not present. - GVR_CONTROLLER_API_UNAVAILABLE = 3, - /// The underlying VR service is too old, needs upgrade. - GVR_CONTROLLER_API_SERVICE_OBSOLETE = 4, - /// The underlying VR service is too new, is incompatible with current client. - GVR_CONTROLLER_API_CLIENT_OBSOLETE = 5, - /// The underlying VR service is malfunctioning. Try again later. - GVR_CONTROLLER_API_MALFUNCTION = 6, -} gvr_controller_api_status; - -/// Constants that represent the state of the controller. -typedef enum { - /// Controller is disconnected. - GVR_CONTROLLER_DISCONNECTED = 0, - /// Controller is scanning. - GVR_CONTROLLER_SCANNING = 1, - /// Controller is connecting. - GVR_CONTROLLER_CONNECTING = 2, - /// Controller is connected. - GVR_CONTROLLER_CONNECTED = 3, -} gvr_controller_connection_state; - -/// Controller buttons. -typedef enum { - GVR_CONTROLLER_BUTTON_NONE = 0, - GVR_CONTROLLER_BUTTON_CLICK = 1, ///< Touchpad Click. - GVR_CONTROLLER_BUTTON_HOME = 2, - GVR_CONTROLLER_BUTTON_APP = 3, - GVR_CONTROLLER_BUTTON_VOLUME_UP = 4, - GVR_CONTROLLER_BUTTON_VOLUME_DOWN = 5, - - /// Note: there are 5 buttons on the controller, but the state arrays have - /// this many elements due to the inclusion of a dummy "none" button. - GVR_CONTROLLER_BUTTON_COUNT = 6, -} gvr_controller_button; - -/// @} - -/// Opaque handle to controller state. -typedef struct gvr_controller_state_ gvr_controller_state; - -/// @addtogroup types -/// @{ - -/// Rendering modes define CPU load / rendering quality balances. -typedef enum { - /// Stereo panning of all Sound Objects. This disables HRTF-based rendering. - GVR_AUDIO_RENDERING_STEREO_PANNING = 0, - /// HRTF-based rendering over a virtual array of 8 loudspeakers arranged in - /// a cube configuration around the listener’s head. - GVR_AUDIO_RENDERING_BINAURAL_LOW_QUALITY = 1, - /// HRTF-based rendering over a virtual array of 16 loudspeakers arranged in - /// an approximate equidistribution about the around the listener’s head. - GVR_AUDIO_RENDERING_BINAURAL_HIGH_QUALITY = 2, -} gvr_audio_rendering_mode; - -/// Room surface material names, used to set room properties. -typedef enum { - /// Acoustically transparent material, reflects no sound. - GVR_AUDIO_MATERIAL_TRANSPARENT = 0, - /// Acoustic ceiling tiles, absorbs most frequencies. - GVR_AUDIO_MATERIAL_ACOUSTIC_CEILING_TILES = 1, - /// Bare brick, relatively reflective. - GVR_AUDIO_MATERIAL_BRICK_BARE = 2, - /// Painted brick - GVR_AUDIO_MATERIAL_BRICK_PAINTED = 3, - /// Coarse surface concrete block. - GVR_AUDIO_MATERIAL_CONCRETE_BLOCK_COARSE = 4, - /// Painted concrete block. - GVR_AUDIO_MATERIAL_CONCRETE_BLOCK_PAINTED = 5, - /// Heavy curtains. - GVR_AUDIO_MATERIAL_CURTAIN_HEAVY = 6, - /// Fiber glass insulation. - GVR_AUDIO_MATERIAL_FIBER_GLASS_INSULATION = 7, - /// Thin glass. - GVR_AUDIO_MATERIAL_GLASS_THIN = 8, - /// Thick glass. - GVR_AUDIO_MATERIAL_GLASS_THICK = 9, - /// Grass. - GVR_AUDIO_MATERIAL_GRASS = 10, - /// Linoleum on concrete. - GVR_AUDIO_MATERIAL_LINOLEUM_ON_CONCRETE = 11, - /// Marble. - GVR_AUDIO_MATERIAL_MARBLE = 12, - /// Galvanized sheet metal. - GVR_AUDIO_MATERIAL_METAL = 13, - /// Wooden parquet on concrete. - GVR_AUDIO_MATERIAL_PARQUET_ON_CONCRETE = 14, - /// Rough plaster surface. - GVR_AUDIO_MATERIAL_PLASTER_ROUGH = 15, - /// Smooth plaster surface. - GVR_AUDIO_MATERIAL_PLASTER_SMOOTH = 16, - /// Plywood panel. - GVR_AUDIO_MATERIAL_PLYWOOD_PANEL = 17, - /// Polished concrete OR tile surface. - GVR_AUDIO_MATERIAL_POLISHED_CONCRETE_OR_TILE = 18, - /// Sheet rock. - GVR_AUDIO_MATERIAL_SHEET_ROCK = 19, - /// Surface of water or ice. - GVR_AUDIO_MATERIAL_WATER_OR_ICE_SURFACE = 20, - /// Wooden ceiling. - GVR_AUDIO_MATERIAL_WOOD_CEILING = 21, - /// Wood paneling. - GVR_AUDIO_MATERIAL_WOOD_PANEL = 22, -} gvr_audio_material_type; - -/// Distance rolloff models used for distance attenuation. -typedef enum { - /// Logarithmic distance rolloff model. - GVR_AUDIO_ROLLOFF_LOGARITHMIC = 0, - /// Linear distance rolloff model. - GVR_AUDIO_ROLLOFF_LINEAR = 1, - /// No distance attenuation will be applied. - GVR_AUDIO_ROLLOFF_NONE = 2, -} gvr_audio_distance_rolloff_type; - -/// Sound object and sound field identifier. -typedef int32_t gvr_audio_source_id; - -/// Valid color formats for swap chain buffers. -typedef enum { - /// Equivalent to GL_RGBA8 - GVR_COLOR_FORMAT_RGBA_8888 = 0, - /// Equivalent to GL_RGB565 - GVR_COLOR_FORMAT_RGB_565 = 1, -} gvr_color_format_type; - -typedef enum { - /// No depth or stencil buffer. - GVR_DEPTH_STENCIL_FORMAT_NONE = 255, - /// Equivalent to GL_DEPTH_COMPONENT16. - GVR_DEPTH_STENCIL_FORMAT_DEPTH_16 = 0, - /// Equivalent to GL_DEPTH_COMPONENT24. - GVR_DEPTH_STENCIL_FORMAT_DEPTH_24 = 1, - /// Equivlaent to GL_DEPTH24_STENCIL8. - GVR_DEPTH_STENCIL_FORMAT_DEPTH_24_STENCIL_8 = 2, - /// Equivalent to GL_DEPTH_COMPONENT32F. - GVR_DEPTH_STENCIL_FORMAT_DEPTH_32_F = 3, - /// Equivalent to GL_DEPTH_32F_STENCIL8. - GVR_DEPTH_STENCIL_FORMAT_DEPTH_32_F_STENCIL_8 = 4, - /// Equivalent to GL_STENCIL8. - GVR_DEPTH_STENCIL_FORMAT_STENCIL_8 = 5, -} gvr_depth_stencil_format_type; - -/// Types of asynchronous reprojection. -typedef enum { - /// Do not reproject. - GVR_REPROJECTION_NONE = 0, - /// Reproject in all dimensions. - GVR_REPROJECTION_FULL = 1, -} gvr_reprojection; - -typedef enum { - GVR_CONTROLLER_RIGHT_HANDED = 0, - GVR_CONTROLLER_LEFT_HANDED = 1, -} gvr_controller_handedness; - -typedef struct gvr_user_prefs_ gvr_user_prefs; - -/// @} - -#ifdef __cplusplus -} // extern "C" -#endif - -#if defined(__cplusplus) && !defined(GVR_NO_CPP_WRAPPER) -// These typedefs convert the C-style names to C++-style names. - -namespace gvr { - -const int32_t kControllerEnableOrientation = - static_cast(GVR_CONTROLLER_ENABLE_ORIENTATION); -const int32_t kControllerEnableTouch = - static_cast(GVR_CONTROLLER_ENABLE_TOUCH); -const int32_t kControllerEnableGyro = - static_cast(GVR_CONTROLLER_ENABLE_GYRO); -const int32_t kControllerEnableAccel = - static_cast(GVR_CONTROLLER_ENABLE_ACCEL); -const int32_t kControllerEnableGestures = - static_cast(GVR_CONTROLLER_ENABLE_GESTURES); -const int32_t kControllerEnablePosePrediction = - static_cast(GVR_CONTROLLER_ENABLE_POSE_PREDICTION); - -typedef gvr_controller_api_status ControllerApiStatus; -const ControllerApiStatus kControllerApiOk = - static_cast(GVR_CONTROLLER_API_OK); -const ControllerApiStatus kControllerApiUnsupported = - static_cast(GVR_CONTROLLER_API_UNSUPPORTED); -const ControllerApiStatus kControllerApiNotAuthorized = - static_cast(GVR_CONTROLLER_API_NOT_AUTHORIZED); -const ControllerApiStatus kControllerApiUnavailable = - static_cast(GVR_CONTROLLER_API_UNAVAILABLE); -const ControllerApiStatus kControllerApiServiceObsolete = - static_cast(GVR_CONTROLLER_API_SERVICE_OBSOLETE); -const ControllerApiStatus kControllerApiClientObsolete = - static_cast(GVR_CONTROLLER_API_CLIENT_OBSOLETE); -const ControllerApiStatus kControllerApiMalfunction = - static_cast(GVR_CONTROLLER_API_MALFUNCTION); - -typedef gvr_controller_connection_state ControllerConnectionState; -const ControllerConnectionState kControllerDisconnected = - static_cast(GVR_CONTROLLER_DISCONNECTED); -const ControllerConnectionState kControllerScanning = - static_cast(GVR_CONTROLLER_SCANNING); -const ControllerConnectionState kControllerConnecting = - static_cast(GVR_CONTROLLER_CONNECTING); -const ControllerConnectionState kControllerConnected = - static_cast(GVR_CONTROLLER_CONNECTED); - -typedef gvr_controller_button ControllerButton; -const ControllerButton kControllerButtonNone = - static_cast(GVR_CONTROLLER_BUTTON_NONE); -const ControllerButton kControllerButtonClick = - static_cast(GVR_CONTROLLER_BUTTON_CLICK); -const ControllerButton kControllerButtonHome = - static_cast(GVR_CONTROLLER_BUTTON_HOME); -const ControllerButton kControllerButtonApp = - static_cast(GVR_CONTROLLER_BUTTON_APP); -const ControllerButton kControllerButtonVolumeUp = - static_cast(GVR_CONTROLLER_BUTTON_VOLUME_UP); -const ControllerButton kControllerButtonVolumeDown = - static_cast(GVR_CONTROLLER_BUTTON_VOLUME_DOWN); -const ControllerButton kControllerButtonCount = - static_cast(GVR_CONTROLLER_BUTTON_COUNT); - -/// An uninitialized external surface ID. -const int32_t kUninitializedExternalSurface = -1; -/// The default source buffer index for viewports. -const int32_t kDefaultBufferIndex = 0; - -typedef gvr_eye Eye; - -typedef gvr_viewer_type ViewerType; -const ViewerType kViewerTypeCardboard = - static_cast(GVR_VIEWER_TYPE_CARDBOARD); -const ViewerType kViewerTypeDaydream = - static_cast(GVR_VIEWER_TYPE_DAYDREAM); - -typedef gvr_version Version; -typedef gvr_sizei Sizei; -typedef gvr_recti Recti; -typedef gvr_rectf Rectf; -typedef gvr_vec2f Vec2f; -typedef gvr_vec3f Vec3f; -typedef gvr_mat4f Mat4f; -typedef gvr_quatf Quatf; -typedef gvr_clock_time_point ClockTimePoint; - -typedef gvr_vec2f ControllerVec2; -typedef gvr_vec3f ControllerVec3; -typedef gvr_quatf ControllerQuat; - -typedef gvr_audio_rendering_mode AudioRenderingMode; -typedef gvr_audio_material_type AudioMaterialName; -typedef gvr_audio_distance_rolloff_type AudioRolloffMethod; -typedef gvr_audio_source_id AudioSourceId; - -typedef gvr_color_format_type ColorFormat; -const ColorFormat kColorFormatRgba8888 = - static_cast(GVR_COLOR_FORMAT_RGBA_8888); -const ColorFormat kColorFormatRgb565 = - static_cast(GVR_COLOR_FORMAT_RGB_565); - -typedef gvr_depth_stencil_format_type DepthStencilFormat; -const DepthStencilFormat kDepthStencilFormatNone = - static_cast(GVR_DEPTH_STENCIL_FORMAT_NONE); -const DepthStencilFormat kDepthStencilFormatDepth16 = - static_cast(GVR_DEPTH_STENCIL_FORMAT_DEPTH_16); -const DepthStencilFormat kDepthStencilFormatDepth24 = - static_cast(GVR_DEPTH_STENCIL_FORMAT_DEPTH_24); -const DepthStencilFormat kDepthStencilFormatDepth24Stencil8 = - static_cast( - GVR_DEPTH_STENCIL_FORMAT_DEPTH_24_STENCIL_8); -const DepthStencilFormat kDepthStencilFormatDepth32f = - static_cast(GVR_DEPTH_STENCIL_FORMAT_DEPTH_32_F); -const DepthStencilFormat kDepthStencilFormatDepth32fStencil8 = - static_cast( - GVR_DEPTH_STENCIL_FORMAT_DEPTH_32_F_STENCIL_8); -const DepthStencilFormat kDepthStencilFormatStencil8 = - static_cast(GVR_DEPTH_STENCIL_FORMAT_STENCIL_8); - -typedef gvr_controller_handedness ControllerHandedness; -const ControllerHandedness kControllerRightHanded = - static_cast(GVR_CONTROLLER_RIGHT_HANDED); -const ControllerHandedness kControllerLeftHanded = - static_cast(GVR_CONTROLLER_LEFT_HANDED); - -typedef gvr_error Error; -const Error kErrorNone = static_cast(GVR_ERROR_NONE); -const Error kErrorControllerCreateFailed = - static_cast(GVR_ERROR_CONTROLLER_CREATE_FAILED); -const Error kErrorNoFrameAvailable = - static_cast(GVR_ERROR_NO_FRAME_AVAILABLE); - -class AudioApi; -class BufferSpec; -class ControllerApi; -class ControllerState; -class Frame; -class GvrApi; -class BufferViewport; -class BufferViewportList; -class SwapChain; -class UserPrefs; - -} // namespace gvr - -// Non-member equality operators for convenience. Since typedefs do not trigger -// argument-dependent lookup, these operators have to be defined for the -// underlying types. -inline bool operator==(const gvr_vec2f& lhs, const gvr_vec2f& rhs) { - return lhs.x == rhs.x && lhs.y == rhs.y; -} - -inline bool operator!=(const gvr_vec2f& lhs, const gvr_vec2f& rhs) { - return !(lhs == rhs); -} - -inline bool operator==(const gvr_vec3f& lhs, const gvr_vec3f& rhs) { - return lhs.x == rhs.x && lhs.y == rhs.y; -} - -inline bool operator!=(const gvr_vec3f& lhs, const gvr_vec3f& rhs) { - return !(lhs == rhs); -} - -inline bool operator==(const gvr_recti& lhs, const gvr_recti& rhs) { - return lhs.left == rhs.left && lhs.right == rhs.right && - lhs.bottom == rhs.bottom && lhs.top == rhs.top; -} - -inline bool operator!=(const gvr_recti& lhs, const gvr_recti& rhs) { - return !(lhs == rhs); -} - -inline bool operator==(const gvr_rectf& lhs, const gvr_rectf& rhs) { - return lhs.left == rhs.left && lhs.right == rhs.right && - lhs.bottom == rhs.bottom && lhs.top == rhs.top; -} - -inline bool operator!=(const gvr_rectf& lhs, const gvr_rectf& rhs) { - return !(lhs == rhs); -} - -inline bool operator==(const gvr_sizei& lhs, const gvr_sizei& rhs) { - return lhs.width == rhs.width && lhs.height == rhs.height; -} - -inline bool operator!=(const gvr_sizei& lhs, const gvr_sizei& rhs) { - return !(lhs == rhs); -} - -#endif // #if defined(__cplusplus) && !defined(GVR_NO_CPP_WRAPPER) - -#endif // VR_GVR_CAPI_INCLUDE_GVR_TYPES_H_ diff --git a/deps/GoogleVR/vr/gvr/capi/include/gvr_version.h b/deps/GoogleVR/vr/gvr/capi/include/gvr_version.h deleted file mode 100644 index b9fe41bb26..0000000000 --- a/deps/GoogleVR/vr/gvr/capi/include/gvr_version.h +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright 2016 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VR_GVR_CAPI_INCLUDE_GVR_VERSION_H_ -#define VR_GVR_CAPI_INCLUDE_GVR_VERSION_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/// A string representation of the current GVR build version. This is of -/// the form "MAJOR.MINOR.PATCH". Note that this may differ from the runtime -/// GVR version as reported by gvr_get_version_string(). -#define GVR_SDK_VERSION_STRING "1.0.2" - -/// Semantic components for the current GVR build version. Note that these -/// values may differ from the runtime GVR version as reported by -/// gvr_get_version(). -enum { - GVR_SDK_MAJOR_VERSION = 1, - GVR_SDK_MINOR_VERSION = 0, - GVR_SDK_PATCH_VERSION = 2, -}; - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // VR_GVR_CAPI_INCLUDE_GVR_VERSION_H_ diff --git a/sources/engine/Stride.Engine/Rendering/Compositing/ForwardRenderer.cs b/sources/engine/Stride.Engine/Rendering/Compositing/ForwardRenderer.cs index ea4bdca1ca..cd0e9b18f7 100644 --- a/sources/engine/Stride.Engine/Rendering/Compositing/ForwardRenderer.cs +++ b/sources/engine/Stride.Engine/Rendering/Compositing/ForwardRenderer.cs @@ -730,10 +730,6 @@ protected override void DrawCore(RenderContext context, RenderDrawContext drawCo //draw mirror to backbuffer (if size is matching and full viewport) if (VRSettings.CopyMirror) - { - CopyOrScaleTexture(drawContext, VRSettings.VRDevice.MirrorTexture, drawContext.CommandList.RenderTarget); - } - else if (hasPostEffects) { CopyOrScaleTexture(drawContext, vrFullSurface, drawContext.CommandList.RenderTarget); } diff --git a/sources/engine/Stride.Graphics/Stride.Graphics.csproj b/sources/engine/Stride.Graphics/Stride.Graphics.csproj index 2dd8b70773..aa1928c9d1 100644 --- a/sources/engine/Stride.Graphics/Stride.Graphics.csproj +++ b/sources/engine/Stride.Graphics/Stride.Graphics.csproj @@ -43,16 +43,16 @@ - + - - - - - + + + + + diff --git a/sources/engine/Stride.VirtualReality/Fove/Fove.cpp b/sources/engine/Stride.VirtualReality/Fove/Fove.cpp deleted file mode 100644 index 9a3d85b3f9..0000000000 --- a/sources/engine/Stride.VirtualReality/Fove/Fove.cpp +++ /dev/null @@ -1,194 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. - -#include "../../../deps/NativePath/NativePath.h" -#include "../../Stride.Native/StrideNative.h" - -#if defined(WINDOWS_DESKTOP) || !defined(__clang__) - -#include "../../../deps/NativePath/NativeDynamicLinking.h" -#include "../../../../deps/Fove/IFVRCompositor.h" -#include "../../../../deps/Fove/IFVRHeadset.h" - -extern "C" -{ - void* __libFove = NULL; - - static bool sFoveInitialized = false; - - static Fove::IFVRHeadset* sHeadSet = NULL; - static Fove::IFVRCompositor* sCompositor = NULL; - - typedef Fove::IFVRHeadset* (*GetFVRHeadsetPtr)(); - typedef Fove::IFVRCompositor* (*CGetFVRCompositorPtr)(); - - DLL_EXPORT_API npBool xnFoveStartup() - { - if (!__libFove) - { - __libFove = LoadDynamicLibrary("FoveClient"); - if (!__libFove) __libFove = LoadDynamicLibrary("x86\\FoveClient"); - if (!__libFove) __libFove = LoadDynamicLibrary("x64\\FoveClient"); - if (!__libFove) __libFove = LoadDynamicLibrary("x64/FoveClient"); - if (!__libFove) __libFove = LoadDynamicLibrary("x64/FoveClient"); - if (!__libFove) - { - return false; - } - - GetFVRHeadsetPtr get_fvr_headset_ptr = (GetFVRHeadsetPtr)GetSymbolAddress(__libFove, "CGetFVRHeadset"); - if (!get_fvr_headset_ptr) return false; - sHeadSet = get_fvr_headset_ptr(); - - CGetFVRCompositorPtr get_fvr_compositor_ptr = (CGetFVRCompositorPtr)GetSymbolAddress(__libFove, "CGetFVRCompositor"); - if (!get_fvr_compositor_ptr) return false; - sCompositor = get_fvr_compositor_ptr(); - } - - if(sHeadSet && !sFoveInitialized) - { - sFoveInitialized = sHeadSet->Initialise(); - } - - return sFoveInitialized; - } - - DLL_EXPORT_API void xnFoveShutdown() - { - if (sCompositor) sCompositor->Shutdown(); - if (sHeadSet) sHeadSet->Destroy(); - if(__libFove) - { - FreeDynamicLibrary(__libFove); - __libFove = NULL; - } - } - - DLL_EXPORT_API npBool xnFoveSubmit(void* texture, float* bounds, int eyeIndex) - { - if (!sCompositor) return false; - - Fove::SFVR_TextureBounds fbounds; - fbounds.left = bounds[0]; - fbounds.bottom = bounds[1]; - fbounds.right = bounds[2]; - fbounds.top = bounds[3]; - - return sCompositor->Submit(texture, - Fove::EFVR_GraphicsAPI::DirectX, - eyeIndex == 0 ? Fove::EFVR_Eye::Left : Fove::EFVR_Eye::Right, - fbounds) - == Fove::EFVR_CompositorError::None; - } - - DLL_EXPORT_API void xnFoveCommit() - { - if (sCompositor) - { - sCompositor->WaitForRenderPose(); - //sCompositor->SignalFrameComplete(); - } - } - - DLL_EXPORT_API npBool xnFoveGetLeftEyePoint(float* point) - { - if(sHeadSet) - { - auto eyePoint = sHeadSet->GetGazePoint(); - point[0] = eyePoint.coord.x; - point[1] = eyePoint.coord.y; - - return eyePoint.error == Fove::EFVR_ErrorCode::None; - } - - return false; - } - -#pragma pack(push, 4) - struct xnOvrFrameProperties - { - //Camera properties - float Near; - float Far; - float ProjLeft[16]; - float ProjRight[16]; - float Pos[3]; - float Rot[4]; - }; -#pragma pack(pop) - - DLL_EXPORT_API void xnFovePrepareRender(xnOvrFrameProperties* properties) - { - auto matrixL = sHeadSet->GetProjectionMatrixRH(Fove::EFVR_Eye::Left, properties->Near, properties->Far); - auto matrixR = sHeadSet->GetProjectionMatrixRH(Fove::EFVR_Eye::Right, properties->Near, properties->Far); - memcpy(properties->ProjLeft, &matrixL, sizeof(float) * 16); - memcpy(properties->ProjRight, &matrixR, sizeof(float) * 16); - - auto pose = sHeadSet->GetHMDPose(); - memcpy(properties->Pos, &pose.position, sizeof(float) * 3); - memcpy(properties->Rot, &pose.orientation, sizeof(float) * 4); - properties->Pos[2] = -properties->Pos[2]; //flip Z - } - - DLL_EXPORT_API void xnFoveRecenter() - { - if(sHeadSet) - { - sHeadSet->TareOrientationSensor(); - sHeadSet->TarePositionSensors(); - } - } - - DLL_EXPORT_API npBool xnFoveIsHardwareReady() - { - if(sHeadSet) - { - return sHeadSet->IsHardwareConnected() && sHeadSet->IsHardwareReady(); - } - - return false; - } -} - -#else - -extern "C" -{ - DLL_EXPORT_API npBool xnFoveStartup() - { - return false; - } - - DLL_EXPORT_API void xnFoveShutdown() - { - } - - DLL_EXPORT_API npBool xnFoveSubmit(void* texture, float* bounds, int eyeIndex) - { - return false; - } - - DLL_EXPORT_API void xnFoveCommit() - { - } - - DLL_EXPORT_API void xnFovePrepareRender(void* properties) - { - } - - DLL_EXPORT_API npBool xnFoveGetLeftEyePoint(float* point) - { - return false; - } - - DLL_EXPORT_API void xnFoveRecenter() - { - } - - DLL_EXPORT_API bool xnFoveIsHardwareReady() - { - return false; - } -} - -#endif diff --git a/sources/engine/Stride.VirtualReality/Fove/Fove.cs b/sources/engine/Stride.VirtualReality/Fove/Fove.cs deleted file mode 100644 index ee490bbfb3..0000000000 --- a/sources/engine/Stride.VirtualReality/Fove/Fove.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. - -using System; -using System.Runtime.InteropServices; -using System.Security; -using Stride.Core; -using Stride.Core.Mathematics; - -namespace Stride.VirtualReality -{ - public static class Fove - { - static Fove() - { - NativeLibraryHelper.PreloadLibrary(NativeInvoke.Library, typeof(Fove)); - } - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnFoveStartup", CallingConvention = CallingConvention.Cdecl)] - public static extern bool Startup(); - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnFoveShutdown", CallingConvention = CallingConvention.Cdecl)] - public static extern void Shutdown(); - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnFoveSubmit", CallingConvention = CallingConvention.Cdecl)] - public static extern bool Submit(IntPtr texture, ref Vector4 bounds, int eyeIndex); - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnFoveCommit", CallingConvention = CallingConvention.Cdecl)] - public static extern void Commit(); - - [StructLayout(LayoutKind.Sequential, Pack = 4)] - public struct FrameProperties - { - public float Near; - public float Far; - public Matrix ProjLeft; - public Matrix ProjRight; - public Vector3 Pos; - public Quaternion Rot; - } - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnFovePrepareRender", CallingConvention = CallingConvention.Cdecl)] - public static extern void PrepareRender(ref FrameProperties properties); - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnFoveGetLeftEyePoint", CallingConvention = CallingConvention.Cdecl)] - public static extern bool GetLeftEyePoint(ref Vector2 point); - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnFoveRecenter", CallingConvention = CallingConvention.Cdecl)] - public static extern void Recenter(); - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnFoveIsHardwareReady", CallingConvention = CallingConvention.Cdecl)] - public static extern bool IsHardwareReady(); - } -} diff --git a/sources/engine/Stride.VirtualReality/Fove/FoveHmd.cs b/sources/engine/Stride.VirtualReality/Fove/FoveHmd.cs deleted file mode 100644 index 6728870e5b..0000000000 --- a/sources/engine/Stride.VirtualReality/Fove/FoveHmd.cs +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -#if STRIDE_GRAPHICS_API_DIRECT3D11 - -using Stride.Core; -using Stride.Core.Mathematics; -using Stride.Games; -using Stride.Graphics; - -//TODO - -namespace Stride.VirtualReality -{ - internal class FoveHmd : VRDevice - { - //private Texture nonSrgbFrame; - private readonly Matrix referenceMatrix = Matrix.RotationZ(MathUtil.Pi); - private Matrix referenceMatrixInv; - - private const float HalfIpd = 0.06f; - private const float EyeHeight = 0.08f; - private const float EyeForward = -0.04f; - - internal FoveHmd() - { - referenceMatrixInv = Matrix.RotationZ(MathUtil.Pi); - referenceMatrixInv.Invert(); - } - - public override void Enable(GraphicsDevice device, GraphicsDeviceManager graphicsDeviceManager, bool requireMirror, int mirrorWidth, int mirrorHeight) - { -// RenderFrame = Texture.New2D(device, RenderFrameSize.Width, RenderFrameSize.Height, PixelFormat.R8G8B8A8_UNorm_SRgb, TextureFlags.RenderTarget | TextureFlags.ShaderResource); -// nonSrgbFrame = Texture.New2D(device, RenderFrameSize.Width, RenderFrameSize.Height, PixelFormat.R8G8B8A8_UNorm, TextureFlags.RenderTarget | TextureFlags.ShaderResource); -// if (requireMirror) -// { -// MirrorTexture = RenderFrame; //assign the surface we submit as mirror if needed -// } - -// var compositor = (SceneGraphicsCompositorLayers)Game.SceneSystem.SceneInstance.RootScene.Settings.GraphicsCompositor; -// compositor.Master.Add(new SceneDelegateRenderer((x, y) => -// { -// x.CommandList.Copy(RenderFrameProvider.RenderFrame.RenderTargets[0], nonSrgbFrame); -// //send to hmd -// var bounds0 = new Vector4(0.0f, 1.0f, 0.5f, 0.0f); -// var bounds1 = new Vector4(0.5f, 1.0f, 1.0f, 0.0f); -// if (!Fove.Submit(nonSrgbFrame.NativeResource.NativePointer, ref bounds0, 0) || -// !Fove.Submit(nonSrgbFrame.NativeResource.NativePointer, ref bounds1, 1)) -// { -// //failed... -// } -// -// Fove.Commit(); -// })); - } - - public override void ReadEyeParameters(Eyes eye, float near, float far, ref Vector3 cameraPosition, ref Matrix cameraRotation, bool ignoreHeadRotation, bool ignoreHeadPosition, out Matrix view, out Matrix projection) - { - throw new System.NotImplementedException(); - } - - public override void Commit(CommandList commandList, Texture renderFrame) - { - throw new System.NotImplementedException(); - } - - public override void Update(GameTime gameTime) - { - throw new System.NotImplementedException(); - } - - public override void Draw(GameTime gameTime) - { - throw new System.NotImplementedException(); - } - -// public override void Draw(GameTime gameTime) -// { -// var properties = new Fove.FrameProperties -// { -// Near = LeftCameraComponent.NearClipPlane, -// Far = LeftCameraComponent.FarClipPlane -// }; -// Fove.PrepareRender(ref properties); -// -// properties.ProjLeft.Transpose(); -// properties.ProjRight.Transpose(); -// -// Vector3 scale, camPos; -// Quaternion camRot; -// -// //have to make sure it's updated now -// CameraRootEntity.Transform.UpdateWorldMatrix(); -// CameraRootEntity.Transform.WorldMatrix.Decompose(out scale, out camRot, out camPos); -// -// LeftCameraComponent.ProjectionMatrix = properties.ProjLeft; -// -// var pos = camPos + (new Vector3(-HalfIpd * 0.5f, EyeHeight, EyeForward) * ViewScaling); -// var posV = pos + Vector3.Transform(properties.Pos * ViewScaling, camRot); -// var rotV = referenceMatrix * Matrix.RotationQuaternion(properties.Rot) * referenceMatrixInv * Matrix.Scaling(ViewScaling) * Matrix.RotationQuaternion(camRot); -// var finalUp = Vector3.TransformCoordinate(new Vector3(0, 1, 0), rotV); -// var finalForward = Vector3.TransformCoordinate(new Vector3(0, 0, -1), rotV); -// var view = Matrix.LookAtRH(posV, posV + finalForward, finalUp); -// LeftCameraComponent.ViewMatrix = view; -// -// RightCameraComponent.ProjectionMatrix = properties.ProjRight; -// -// pos = camPos + (new Vector3(HalfIpd * 0.5f, EyeHeight, EyeForward) * ViewScaling); -// posV = pos + Vector3.Transform(properties.Pos * ViewScaling, camRot); -// rotV = referenceMatrix * Matrix.RotationQuaternion(properties.Rot) * referenceMatrixInv * Matrix.Scaling(ViewScaling) * Matrix.RotationQuaternion(camRot); -// finalUp = Vector3.TransformCoordinate(new Vector3(0, 1, 0), rotV); -// finalForward = Vector3.TransformCoordinate(new Vector3(0, 0, -1), rotV); -// view = Matrix.LookAtRH(posV, posV + finalForward, finalUp); -// RightCameraComponent.ViewMatrix = view; -// -// base.Draw(gameTime); -// } - - public override Size2 OptimalRenderFrameSize => new Size2(2560, 1440); - public override Size2 ActualRenderFrameSize { get; protected set; } - - public override Texture MirrorTexture { get; protected set; } - - public override float RenderFrameScaling { get; set; } = 1.2f; - - public override DeviceState State => DeviceState.Valid; - - public override Vector3 HeadPosition { get; } - - public override Quaternion HeadRotation { get; } - - public override Vector3 HeadLinearVelocity { get; } - - public override Vector3 HeadAngularVelocity { get; } - - public override TouchController LeftHand => null; - - public override TouchController RightHand => null; - - public override TrackedItem[] TrackedItems => new TrackedItem[0]; - - public override bool CanInitialize => Fove.Startup() && Fove.IsHardwareReady(); - } -} - -#endif diff --git a/sources/engine/Stride.VirtualReality/GoogleVR/GoogleVR.cpp b/sources/engine/Stride.VirtualReality/GoogleVR/GoogleVR.cpp deleted file mode 100644 index 19a65d9209..0000000000 --- a/sources/engine/Stride.VirtualReality/GoogleVR/GoogleVR.cpp +++ /dev/null @@ -1,485 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. - -#if defined(DONT_BUILD_FOR_NOW) && (defined(ANDROID) || defined(IOS)) || !defined(__clang__) - -#if !defined(__clang__) -#define size_t unsigned long //shutup a error on resharper -#endif - -#if defined(IOS) -#define NP_STATIC_LINKING -#endif - -#include "../../../common/core/Stride.Core.Native/CoreNative.h" -#include "../../../deps/NativePath/NativeDynamicLinking.h" -#include "../../../deps/NativePath/NativePath.h" - -#define GVR_NO_CPP_WRAPPER -#include "../../../../deps/GoogleVR/vr/gvr/capi/include/gvr_types.h" -#include "../../../../deps/GoogleVR/vr/gvr/capi/include/gvr.h" - -extern "C" { - void* gGvrLibrary = NULL; - void* gGvrGLESv2 = NULL; - gvr_context* gGvrContext = NULL; - -#define GL_COLOR_WRITEMASK 0x0C23 -#define GL_SCISSOR_TEST 0x0C11 -#define GL_BLEND 0x0BE2 -#define GL_CULL_FACE 0x0B44 -#define GL_DEPTH_TEST 0x0B71 -#define GL_BLEND_EQUATION_RGB 0x8009 -#define GL_BLEND_EQUATION_ALPHA 0x883D -#define GL_BLEND_DST_RGB 0x80C8 -#define GL_BLEND_SRC_RGB 0x80C9 -#define GL_BLEND_DST_ALPHA 0x80CA -#define GL_BLEND_SRC_ALPHA 0x80CB -#define GL_VIEWPORT 0x0BA2 -#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 -#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 -#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 -#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 -#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A -#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 -#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F -#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 -#define GL_ELEMENT_ARRAY_BUFFER 0x8893 - -#define M_PI 3.14159265358979323846 - - typedef unsigned char GLboolean; - typedef unsigned int GLenum; - typedef unsigned int GLuint; - typedef int GLint; - typedef int GLsizei; - typedef void GLvoid; - - NP_IMPORT(void, glColorMask, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); - NP_IMPORT(void, glDisable, GLenum cap); - NP_IMPORT(void, glEnable, GLenum cap); - NP_IMPORT(void, glGetBooleanv, GLenum pname, GLboolean* data); - NP_IMPORT(void, glGetIntegerv, GLenum pname, GLint* data); - NP_IMPORT(void, glBlendEquationSeparate, GLenum modeRGB, GLenum modeAlpha); - NP_IMPORT(void, glBlendFuncSeparate, GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); - NP_IMPORT(void, glViewport, GLint x, GLint y, GLsizei width, GLsizei height); - NP_IMPORT(void, glDisableVertexAttribArray, GLuint index); - NP_IMPORT(void, glGetVertexAttribiv, GLuint index, GLenum pname, GLint *params); - NP_IMPORT(void, glVertexAttribPointer, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer); - NP_IMPORT(void, glGetVertexAttribPointerv, GLuint index, GLenum pname, GLvoid** pointer); - NP_IMPORT(void, glBindBuffer, GLenum target, GLuint buffer); - - NP_IMPORT(void, gvr_initialize_gl, gvr_context* gvr); - NP_IMPORT(int32_t, gvr_clear_error, gvr_context* gvr); - NP_IMPORT(int32_t, gvr_get_error, gvr_context* gvr); - NP_IMPORT(gvr_buffer_viewport_list*, gvr_buffer_viewport_list_create, const gvr_context* gvr); - NP_IMPORT(void, gvr_get_recommended_buffer_viewports, const gvr_context* gvr, gvr_buffer_viewport_list* viewport_list); - NP_IMPORT(void, gvr_buffer_viewport_list_get_item, const gvr_buffer_viewport_list* viewport_list, size_t index, gvr_buffer_viewport* viewport); - NP_IMPORT(gvr_buffer_viewport*, gvr_buffer_viewport_create, gvr_context* gvr); - NP_IMPORT(gvr_sizei, gvr_get_maximum_effective_render_target_size, const gvr_context* gvr); - NP_IMPORT(gvr_buffer_spec*, gvr_buffer_spec_create, gvr_context* gvr); - NP_IMPORT(void, gvr_buffer_spec_destroy, gvr_buffer_spec** spec); - NP_IMPORT(void, gvr_buffer_spec_set_size, gvr_buffer_spec* spec, gvr_sizei size); - NP_IMPORT(void, gvr_buffer_spec_set_samples, gvr_buffer_spec* spec, int32_t num_samples); - NP_IMPORT(gvr_frame*, gvr_swap_chain_acquire_frame, gvr_swap_chain* swap_chain); - NP_IMPORT(int32_t, gvr_frame_get_framebuffer_object, const gvr_frame* frame, int32_t index); - NP_IMPORT(void, gvr_swap_chain_resize_buffer, gvr_swap_chain* swap_chain, int32_t index, gvr_sizei size); - NP_IMPORT(void, gvr_frame_submit, gvr_frame** frame, const gvr_buffer_viewport_list* list, gvr_mat4f head_space_from_start_space); - NP_IMPORT(gvr_mat4f, gvr_get_head_space_from_start_space_rotation ,const gvr_context* gvr, const gvr_clock_time_point time); - NP_IMPORT(gvr_clock_time_point, gvr_get_time_point_now); - NP_IMPORT(gvr_rectf, gvr_buffer_viewport_get_source_uv, const gvr_buffer_viewport* viewport); - NP_IMPORT(void, gvr_refresh_viewer_profile, gvr_context* gvr); - NP_IMPORT(void, gvr_frame_bind_buffer, gvr_frame* frame, int32_t index); - NP_IMPORT(void, gvr_frame_unbind, gvr_frame* frame); - NP_IMPORT(gvr_context*, gvr_create); - NP_IMPORT(void, gvr_set_surface_size, gvr_context* gvr, gvr_sizei surface_size_pixels); - NP_IMPORT(void, gvr_buffer_spec_set_color_format, gvr_buffer_spec* spec, int32_t color_format); - NP_IMPORT(void, gvr_buffer_spec_set_depth_stencil_format, gvr_buffer_spec* spec, int32_t depth_stencil_format); - NP_IMPORT(gvr_swap_chain*, gvr_swap_chain_create, gvr_context* gvr, const gvr_buffer_spec** buffers, int32_t count); - NP_IMPORT(gvr_mat4f, gvr_get_eye_from_head_matrix, const gvr_context* gvr, const int32_t eye); - NP_IMPORT(gvr_rectf, gvr_buffer_viewport_get_source_fov, const gvr_buffer_viewport* viewport); - - gvr_buffer_viewport_list* xnGvr_ViewportsList = NULL; - gvr_buffer_viewport* xnGvr_LeftVieport = NULL; - gvr_buffer_viewport* xnGvr_RightVieport = NULL; - - gvr_swap_chain* xnGvr_swap_chain = NULL; - - gvr_sizei xnGvr_size; - - uint64_t kPredictionTimeWithoutVsyncNanos = 50000000; - - int xnGvrStartup(gvr_context* context) - { - //cnDebugPrintLine("xnGvrStartup"); - - if (!gGvrLibrary) - { -#if defined(ANDROID) - gGvrLibrary = LoadDynamicLibrary("libgvr"); - gGvrGLESv2 = LoadDynamicLibrary("libGLESv2"); -#else - gGvrLibrary = LoadDynamicLibrary(NULL); - gGvrGLESv2 = LoadDynamicLibrary(NULL); -#endif - - if (!gGvrLibrary) return 1; - - NP_LOAD(gGvrGLESv2, glColorMask); - NP_CHECK(glColorMask, return false); - NP_LOAD(gGvrGLESv2, glDisable); - NP_CHECK(glDisable, return false); - NP_LOAD(gGvrGLESv2, glEnable); - NP_CHECK(glEnable, return false); - NP_LOAD(gGvrGLESv2, glGetBooleanv); - NP_CHECK(glGetBooleanv, return false); - NP_LOAD(gGvrGLESv2, glGetIntegerv); - NP_CHECK(glGetIntegerv, return false); - NP_LOAD(gGvrGLESv2, glBlendEquationSeparate); - NP_CHECK(glBlendEquationSeparate, return false); - NP_LOAD(gGvrGLESv2, glBlendFuncSeparate); - NP_CHECK(glBlendFuncSeparate, return false); - NP_LOAD(gGvrGLESv2, glViewport); - NP_CHECK(glViewport, return false); - NP_LOAD(gGvrGLESv2, glDisableVertexAttribArray); - NP_CHECK(glDisableVertexAttribArray, return false); - NP_LOAD(gGvrGLESv2, glGetVertexAttribiv); - NP_CHECK(glGetVertexAttribiv, return false); - NP_LOAD(gGvrGLESv2, glVertexAttribPointer); - NP_CHECK(glVertexAttribPointer, return false); - NP_LOAD(gGvrGLESv2, glGetVertexAttribPointerv); - NP_CHECK(glGetVertexAttribPointerv, return false); - NP_LOAD(gGvrGLESv2, glBindBuffer); - NP_CHECK(glBindBuffer, return false); - - NP_LOAD(gGvrLibrary, gvr_refresh_viewer_profile); - NP_CHECK(gvr_refresh_viewer_profile, return 2); - } - - if(context) - { - gGvrContext = context; - } - else - { - NP_LOAD(gGvrLibrary, gvr_create); - NP_CHECK(gvr_create, return 3); - gGvrContext = NP_CALL(gvr_create); - - if (gGvrContext == NULL) return 4; - } - - NP_LOAD(gGvrLibrary, gvr_get_maximum_effective_render_target_size); - NP_CHECK(gvr_get_maximum_effective_render_target_size, return 5); - - NP_CALL(gvr_refresh_viewer_profile, gGvrContext); - - NP_LOAD(gGvrLibrary, gvr_set_surface_size); - NP_CHECK(gvr_set_surface_size, return 6); - - return 0; - } - - void xnGvrGetMaxRenderSize(int* outWidth, int* outHeight) - { - auto maxSize = NP_CALL(gvr_get_maximum_effective_render_target_size, gGvrContext); - *outHeight = maxSize.height; - *outWidth = maxSize.width; - } - - npBool xnGvrInit(int width, int height) - { - xnGvr_size.width = width; - xnGvr_size.height = height; - - NP_CALL(gvr_set_surface_size, gGvrContext, xnGvr_size); - - NP_LOAD(gGvrLibrary, gvr_initialize_gl); - NP_CHECK(gvr_initialize_gl, return false); - NP_LOAD(gGvrLibrary, gvr_clear_error); - NP_CHECK(gvr_clear_error, return false); - NP_LOAD(gGvrLibrary, gvr_get_error); - NP_CHECK(gvr_get_error, return false); - NP_LOAD(gGvrLibrary, gvr_buffer_viewport_list_create); - NP_CHECK(gvr_buffer_viewport_list_create, return false); - NP_LOAD(gGvrLibrary, gvr_get_recommended_buffer_viewports); - NP_CHECK(gvr_get_recommended_buffer_viewports, return false); - NP_LOAD(gGvrLibrary, gvr_buffer_viewport_list_get_item); - NP_CHECK(gvr_buffer_viewport_list_get_item, return false); - NP_LOAD(gGvrLibrary, gvr_buffer_viewport_create); - NP_CHECK(gvr_buffer_viewport_create, return false); - NP_LOAD(gGvrLibrary, gvr_buffer_spec_create); - NP_CHECK(gvr_buffer_spec_create, return false); - NP_LOAD(gGvrLibrary, gvr_buffer_spec_destroy); - NP_CHECK(gvr_buffer_spec_destroy, return false); - NP_LOAD(gGvrLibrary, gvr_swap_chain_acquire_frame); - NP_CHECK(gvr_swap_chain_acquire_frame, return false); - NP_LOAD(gGvrLibrary, gvr_frame_get_framebuffer_object); - NP_CHECK(gvr_frame_get_framebuffer_object, return false); - NP_LOAD(gGvrLibrary, gvr_swap_chain_resize_buffer); - NP_CHECK(gvr_swap_chain_resize_buffer, return false); - NP_LOAD(gGvrLibrary, gvr_buffer_spec_set_color_format); - NP_CHECK(gvr_buffer_spec_set_color_format, return false); - NP_LOAD(gGvrLibrary, gvr_buffer_spec_set_depth_stencil_format); - NP_CHECK(gvr_buffer_spec_set_depth_stencil_format, return false); - NP_LOAD(gGvrLibrary, gvr_swap_chain_create); - NP_CHECK(gvr_swap_chain_create, return false); - NP_LOAD(gGvrLibrary, gvr_frame_submit); - NP_CHECK(gvr_frame_submit, return false); - NP_LOAD(gGvrLibrary, gvr_get_head_space_from_start_space_rotation); - NP_CHECK(gvr_get_head_space_from_start_space_rotation, return false); - NP_LOAD(gGvrLibrary, gvr_get_time_point_now); - NP_CHECK(gvr_get_time_point_now, return false); - NP_LOAD(gGvrLibrary, gvr_frame_bind_buffer); - NP_CHECK(gvr_frame_bind_buffer, return false); - NP_LOAD(gGvrLibrary, gvr_frame_unbind); - NP_CHECK(gvr_frame_unbind, return false); - NP_LOAD(gGvrLibrary, gvr_buffer_viewport_get_source_uv); - NP_CHECK(gvr_buffer_viewport_get_source_uv, return false); - NP_LOAD(gGvrLibrary, gvr_buffer_spec_set_size); - NP_CHECK(gvr_buffer_spec_set_size, return false); - NP_LOAD(gGvrLibrary, gvr_buffer_spec_set_samples); - NP_CHECK(gvr_buffer_spec_set_samples, return false); - NP_LOAD(gGvrLibrary, gvr_get_eye_from_head_matrix); - NP_CHECK(gvr_get_eye_from_head_matrix, return false); - NP_LOAD(gGvrLibrary, gvr_buffer_viewport_get_source_fov); - NP_CHECK(gvr_buffer_viewport_get_source_fov, return false); - - NP_CALL(gvr_clear_error, gGvrContext); - NP_CALL(gvr_initialize_gl, gGvrContext); - if (NP_CALL(gvr_get_error, gGvrContext) != GVR_ERROR_NONE) return false; - - NP_CALL(gvr_clear_error, gGvrContext); - xnGvr_ViewportsList = NP_CALL(gvr_buffer_viewport_list_create, gGvrContext); - NP_CALL(gvr_get_recommended_buffer_viewports, gGvrContext, xnGvr_ViewportsList); - if (NP_CALL(gvr_get_error, gGvrContext) != GVR_ERROR_NONE) return false; - - NP_CALL(gvr_clear_error, gGvrContext); - xnGvr_LeftVieport = NP_CALL(gvr_buffer_viewport_create, gGvrContext); - xnGvr_RightVieport = NP_CALL(gvr_buffer_viewport_create, gGvrContext); - if (NP_CALL(gvr_get_error, gGvrContext) != GVR_ERROR_NONE) return false; - - NP_CALL(gvr_clear_error, gGvrContext); - NP_CALL(gvr_buffer_viewport_list_get_item, xnGvr_ViewportsList, 0, xnGvr_LeftVieport); - NP_CALL(gvr_buffer_viewport_list_get_item, xnGvr_ViewportsList, 1, xnGvr_RightVieport); - if (NP_CALL(gvr_get_error, gGvrContext) != GVR_ERROR_NONE) return false; - - NP_CALL(gvr_clear_error, gGvrContext); - auto bufferSpec = NP_CALL(gvr_buffer_spec_create, gGvrContext); - if (NP_CALL(gvr_get_error, gGvrContext) != GVR_ERROR_NONE) return false; - - NP_CALL(gvr_clear_error, gGvrContext); - NP_CALL(gvr_buffer_spec_set_size, bufferSpec, xnGvr_size); - if (NP_CALL(gvr_get_error, gGvrContext) != GVR_ERROR_NONE) return false; - - NP_CALL(gvr_clear_error, gGvrContext); - NP_CALL(gvr_buffer_spec_set_samples, bufferSpec, 1); - if (NP_CALL(gvr_get_error, gGvrContext) != GVR_ERROR_NONE) return false; - - NP_CALL(gvr_clear_error, gGvrContext); - NP_CALL(gvr_buffer_spec_set_color_format, bufferSpec, GVR_COLOR_FORMAT_RGBA_8888); - if (NP_CALL(gvr_get_error, gGvrContext) != GVR_ERROR_NONE) return false; - - NP_CALL(gvr_clear_error, gGvrContext); - NP_CALL(gvr_buffer_spec_set_depth_stencil_format, bufferSpec, GVR_DEPTH_STENCIL_FORMAT_NONE); - if (NP_CALL(gvr_get_error, gGvrContext) != GVR_ERROR_NONE) return false; - - NP_CALL(gvr_clear_error, gGvrContext); - const gvr_buffer_spec* specs[] = { bufferSpec }; - xnGvr_swap_chain = NP_CALL(gvr_swap_chain_create, gGvrContext, specs, 1); - if (NP_CALL(gvr_get_error, gGvrContext) != GVR_ERROR_NONE || xnGvr_swap_chain == NULL) return false; - - NP_CALL(gvr_buffer_spec_destroy, &bufferSpec); - - NP_CALL(gvr_clear_error, gGvrContext); - NP_CALL(gvr_swap_chain_resize_buffer, xnGvr_swap_chain, 0, xnGvr_size); - if (NP_CALL(gvr_get_error, gGvrContext)) return false; - - return true; - } - - void xnGvrGetPerspectiveMatrix(int eyeIndex, float near_clip, float far_clip, gvr_mat4f* outResult) - { -#ifdef IOS - //eyeIndex = eyeIndex == 0 ? 1 : 0; -#endif - - auto fov = NP_CALL(gvr_buffer_viewport_get_source_fov, eyeIndex == 0 ? xnGvr_LeftVieport : xnGvr_RightVieport); - float x_left = -tan(fov.left * M_PI / 180.0f) * near_clip; - float x_right = tan(fov.right * M_PI / 180.0f) * near_clip; - float y_bottom = -tan(fov.bottom * M_PI / 180.0f) * near_clip; - float y_top = tan(fov.top * M_PI / 180.0f) * near_clip; - - const auto X = (2 * near_clip) / (x_right - x_left); - const auto Y = (2 * near_clip) / (y_top - y_bottom); - const auto A = (x_right + x_left) / (x_right - x_left); - const auto B = (y_top + y_bottom) / (y_top - y_bottom); - const auto C = (near_clip + far_clip) / (near_clip - far_clip); - const auto D = (2 * near_clip * far_clip) / (near_clip - far_clip); - - for (auto i = 0; i < 4; ++i) - { - for (auto j = 0; j < 4; ++j) - { - outResult->m[i][j] = 0.0f; - } - } - - outResult->m[0][0] = X; - outResult->m[0][2] = A; - outResult->m[1][1] = Y; - outResult->m[1][2] = B; - outResult->m[2][2] = C; - outResult->m[2][3] = D; - outResult->m[3][2] = -1; - } - - void xnGvrGetHeadMatrix(float* outMatrix) - { - auto time = NP_CALL(gvr_get_time_point_now); - time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; - auto gvrMat4 = reinterpret_cast(outMatrix); - *gvrMat4 = NP_CALL(gvr_get_head_space_from_start_space_rotation, gGvrContext, time); - } - - void xnGvrGetEyeMatrix(int eyeIndex, float* outMatrix) - { -#ifdef IOS - //eyeIndex = eyeIndex == 0 ? 1 : 0; -#endif - - auto gvrMat4 = reinterpret_cast(outMatrix); - *gvrMat4 = NP_CALL(gvr_get_eye_from_head_matrix, gGvrContext, eyeIndex); - } - - void* xnGvrGetNextFrame() - { - NP_CALL(gvr_clear_error, gGvrContext); - auto frame = NP_CALL(gvr_swap_chain_acquire_frame, xnGvr_swap_chain); - auto err = NP_CALL(gvr_get_error, gGvrContext); - return err == GVR_ERROR_NONE ? frame : NULL; - } - - int xnGvrGetFBOIndex(gvr_frame* frame, int index) - { - return NP_CALL(gvr_frame_get_framebuffer_object, frame, index); - } - - npBool xnGvrSubmitFrame(gvr_frame* frame, float* headMatrix) - { - GLboolean masks[4]; - NP_CALL(glGetBooleanv, GL_COLOR_WRITEMASK, masks); - NP_CALL(glColorMask, true, true, true, true); // This was the super major headache and it's needed - - GLboolean scissor; - NP_CALL(glGetBooleanv, GL_SCISSOR_TEST, &scissor); - - GLboolean blend; - NP_CALL(glGetBooleanv, GL_BLEND, &blend); - - GLboolean cullFace; - NP_CALL(glGetBooleanv, GL_CULL_FACE, &cullFace); - - GLboolean depthTest; - NP_CALL(glGetBooleanv, GL_DEPTH_TEST, &depthTest); - - GLint eqRgb; - NP_CALL(glGetIntegerv, GL_BLEND_EQUATION_RGB, &eqRgb); - GLint eqAlpha; - NP_CALL(glGetIntegerv, GL_BLEND_EQUATION_ALPHA, &eqAlpha); - - GLint dstRgb; - NP_CALL(glGetIntegerv, GL_BLEND_DST_RGB, &dstRgb); - GLint dstAlpha; - NP_CALL(glGetIntegerv, GL_BLEND_DST_ALPHA, &dstAlpha); - GLint srcRgb; - NP_CALL(glGetIntegerv, GL_BLEND_SRC_RGB, &srcRgb); - GLint srcAlpha; - NP_CALL(glGetIntegerv, GL_BLEND_SRC_ALPHA, &srcAlpha); - - GLint viewport[4]; - NP_CALL(glGetIntegerv, GL_VIEWPORT, viewport); - - GLint index0Vert, index1Vert; - NP_CALL(glGetVertexAttribiv, 0, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &index0Vert); - NP_CALL(glGetVertexAttribiv, 1, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &index1Vert); - - GLint index0Size, index1Size; - NP_CALL(glGetVertexAttribiv, 0, GL_VERTEX_ATTRIB_ARRAY_SIZE, &index0Size); - NP_CALL(glGetVertexAttribiv, 1, GL_VERTEX_ATTRIB_ARRAY_SIZE, &index1Size); - - GLint index0Type, index1Type; - NP_CALL(glGetVertexAttribiv, 0, GL_VERTEX_ATTRIB_ARRAY_TYPE, &index0Type); - NP_CALL(glGetVertexAttribiv, 1, GL_VERTEX_ATTRIB_ARRAY_TYPE, &index1Type); - - GLint index0Normalized, index1Normalized; - NP_CALL(glGetVertexAttribiv, 0, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &index0Normalized); - NP_CALL(glGetVertexAttribiv, 1, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &index1Normalized); - - GLint index0Stride, index1Stride; - NP_CALL(glGetVertexAttribiv, 0, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &index0Stride); - NP_CALL(glGetVertexAttribiv, 1, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &index1Stride); - - GLvoid* index0Ptr; - GLvoid* index1Ptr; - NP_CALL(glGetVertexAttribPointerv, 0, GL_VERTEX_ATTRIB_ARRAY_POINTER, &index0Ptr); - NP_CALL(glGetVertexAttribPointerv, 1, GL_VERTEX_ATTRIB_ARRAY_POINTER, &index1Ptr); - - GLint indexBuffer; - NP_CALL(glGetIntegerv, GL_ELEMENT_ARRAY_BUFFER_BINDING, &indexBuffer); - - NP_CALL(gvr_clear_error, gGvrContext); - gvr_mat4f* gvrMat4 = reinterpret_cast(headMatrix); - NP_CALL(gvr_frame_submit, &frame, xnGvr_ViewportsList, *gvrMat4); - auto err = NP_CALL(gvr_get_error, gGvrContext); - - NP_CALL(glViewport, viewport[0], viewport[1], viewport[2], viewport[3]); - - NP_CALL(glColorMask, masks[0], masks[1], masks[2], masks[3]); - - if (scissor) - { - NP_CALL(glEnable, GL_SCISSOR_TEST); - } - - if(!blend) - { - NP_CALL(glDisable, GL_BLEND); - } - - if(cullFace) - { - NP_CALL(glEnable, GL_CULL_FACE); - } - - if(depthTest) - { - NP_CALL(glEnable, GL_DEPTH_TEST); - } - - NP_CALL(glBlendEquationSeparate, eqRgb, eqAlpha); - - NP_CALL(glBlendFuncSeparate, srcRgb, dstRgb, srcAlpha, dstAlpha); - - NP_CALL(glVertexAttribPointer, 0, index0Size, index0Type, index0Normalized, index0Stride, index0Ptr); - NP_CALL(glVertexAttribPointer, 1, index1Size, index1Type, index1Normalized, index1Stride, index1Ptr); - - if(!index0Vert) - { - NP_CALL(glDisableVertexAttribArray, 0); - } - - if (!index1Vert) - { - NP_CALL(glDisableVertexAttribArray, 1); - } - - NP_CALL(glBindBuffer, GL_ELEMENT_ARRAY_BUFFER, indexBuffer); - - return err == GVR_ERROR_NONE; - } -} - -#else - -#endif diff --git a/sources/engine/Stride.VirtualReality/GoogleVR/GoogleVR.cs b/sources/engine/Stride.VirtualReality/GoogleVR/GoogleVR.cs deleted file mode 100644 index 0b8ffd77c8..0000000000 --- a/sources/engine/Stride.VirtualReality/GoogleVR/GoogleVR.cs +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. - -#if DONT_BUILD_FOR_NOW && (STRIDE_PLATFORM_IOS || STRIDE_PLATFORM_ANDROID) - -using System; -using System.Runtime.InteropServices; -using System.Security; -using OpenTK.Graphics.ES20; -using Stride.Core.Mathematics; -using Stride.Graphics; - -#if STRIDE_PLATFORM_ANDROID -using Java.Lang; -using Android.App; -using Android.Views; -using Com.Google.VR.Ndk.Base; -using Stride.Games; -#endif - -namespace Stride.VirtualReality -{ - public static class GoogleVr - { - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnGvrStartup", CallingConvention = CallingConvention.Cdecl)] - private static extern int InternalStartup(IntPtr ctx); - -#if STRIDE_PLATFORM_ANDROID - - public static void Startup(Game game, Activity androidActivity) - { - game.WindowCreated += (sender1, args1) => - { - var androidWindow = (GameWindowAndroid)game.Window; - - // Setup VR layout - var layout = new GvrLayout(androidActivity); - if (layout.SetAsyncReprojectionEnabled(true)) - { - AndroidCompat.SetSustainedPerformanceMode(androidActivity, true); - } - AndroidCompat.SetVrModeEnabled(androidActivity, true); - - ((ViewGroup)androidWindow.StrideGameForm.Parent).RemoveView(androidWindow.StrideGameForm); - layout.SetPresentationView(androidWindow.StrideGameForm); - androidActivity.SetContentView(layout); - - // Init native, we need to reflect some methods that xamarin failed to wrap - var classGvrLayout = Class.ForName("com.google.vr.ndk.base.GvrLayout"); - var getGvrApiMethod = classGvrLayout.GetMethod("getGvrApi"); - var gvrApi = getGvrApiMethod.Invoke(layout); - var classGvrApi = Class.ForName("com.google.vr.ndk.base.GvrApi"); - var getNativeGvrContextMethod = classGvrApi.GetMethod("getNativeGvrContext"); - var nativeContextLong = (long)getNativeGvrContextMethod.Invoke(gvrApi); - var nativeCtx = new IntPtr(nativeContextLong); - - if (InternalStartup(nativeCtx) != 0) - { - throw new System.Exception("Failed to Startup Google VR SDK"); - } - }; - } - -#elif STRIDE_PLATFORM_IOS - - public static void Startup(Game game) - { - game.WindowCreated += (sender1, args1) => - { - var res = InternalStartup(IntPtr.Zero); - if (res != 0) - { - throw new Exception("Failed to init Google cardboad SDK."); - } - }; - } - -#endif - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnGvrGetMaxRenderSize", CallingConvention = CallingConvention.Cdecl)] - public static extern void GetMaxRenderSize(out int width, out int height); - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnGvrInit", CallingConvention = CallingConvention.Cdecl)] - public static extern bool Init(int width, int height); - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnGvrGetPerspectiveMatrix", CallingConvention = CallingConvention.Cdecl)] - public static extern void GetPerspectiveMatrix(int eyeIndex, float near, float far, out Matrix headMatrix); - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnGvrGetHeadMatrix", CallingConvention = CallingConvention.Cdecl)] - public static extern void GetHeadMatrix(out Matrix headMatrix); - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnGvrGetEyeMatrix", CallingConvention = CallingConvention.Cdecl)] - public static extern void GetEyeMatrix(int eyeIndex, out Matrix headMatrix); - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnGvrGetNextFrame", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr GetNextFrame(); - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnGvrGetFBOIndex", CallingConvention = CallingConvention.Cdecl)] - private static extern int GetFBOIndex(IntPtr frame, int index); - - public static void SubmitRenderTarget(GraphicsContext context, Texture renderTarget, IntPtr vrFrame, int index) - { - int currentFrameBuffer; - GL.GetInteger(GetPName.FramebufferBinding, out currentFrameBuffer); - - //TODO add proper destination values - GL.BindFramebuffer(FramebufferTarget.Framebuffer, GetFBOIndex(vrFrame, index)); - // The next call will write straight to the previously bound buffer - context.CommandList.CopyScaler2D(renderTarget, - new Rectangle(0, 0, renderTarget.Width, renderTarget.Height), - new Rectangle(0, 0, renderTarget.Width, renderTarget.Height) - ); - - GL.BindFramebuffer(FramebufferTarget.Framebuffer, currentFrameBuffer); - } - - [SuppressUnmanagedCodeSecurity] - [DllImport(NativeInvoke.Library, EntryPoint = "xnGvrSubmitFrame", CallingConvention = CallingConvention.Cdecl)] - private static extern bool InternalSubmitFrame(IntPtr frame, ref Matrix headMatrix); - - public static bool SubmitFrame(GraphicsDevice graphicsDevice, IntPtr frame, ref Matrix headMatrix) - { - int currentFrameBuffer; - GL.GetInteger(GetPName.FramebufferBinding, out currentFrameBuffer); - - GL.BindFramebuffer(FramebufferTarget.Framebuffer, graphicsDevice.FindOrCreateFBO(graphicsDevice.Presenter.BackBuffer)); - - var res = InternalSubmitFrame(frame, ref headMatrix); - - GL.BindFramebuffer(FramebufferTarget.Framebuffer, currentFrameBuffer); - - return res; - } - } -} - -#endif diff --git a/sources/engine/Stride.VirtualReality/GoogleVR/GoogleVrHmd.cs b/sources/engine/Stride.VirtualReality/GoogleVR/GoogleVrHmd.cs deleted file mode 100644 index 9c13ac4b97..0000000000 --- a/sources/engine/Stride.VirtualReality/GoogleVR/GoogleVrHmd.cs +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. - -#if DONT_BUILD_FOR_NOW && (STRIDE_PLATFORM_IOS || STRIDE_PLATFORM_ANDROID) - -using System; -#if STRIDE_PLATFORM_ANDROID -using Android.App; -#endif -using Stride.Core; -using Stride.Core.Mathematics; -using Stride.Engine; -using Stride.Games; -using Stride.Graphics; -using Stride.Rendering; -using Stride.Rendering.Composers; - -namespace Stride.VirtualReality -{ - internal class GoogleVrHmd : Hmd - { - private Matrix headMatrix; - - public GoogleVrHmd(IServiceRegistry registry) : base(registry) - { -#if STRIDE_PLATFORM_ANDROID - GoogleVr.Startup(Game, (Activity)PlatformAndroid.Context); -#else - GoogleVr.Startup(Game); -#endif - } - - public override void Initialize(Entity cameraRoot, CameraComponent leftCamera, CameraComponent rightCamera, bool requireMirror = false) - { - var size = RenderFrameSize; - if (!GoogleVr.Init(size.Width, size.Height)) - { - throw new Exception("Failed to Init Google VR SDK"); - } - - RenderFrameProvider = new DirectRenderFrameProvider(RenderFrame.FromTexture( - Texture.New2D(GraphicsDevice, size.Width, size.Height, PixelFormat.R8G8B8A8_UNorm_SRgb, TextureFlags.RenderTarget | TextureFlags.ShaderResource) - )); - - var compositor = (SceneGraphicsCompositorLayers)Game.SceneSystem.SceneInstance.RootScene.Settings.GraphicsCompositor; - compositor.Master.Add(new SceneDelegateRenderer((x, y) => - { - var frame = GoogleVr.GetNextFrame(); - GoogleVr.SubmitRenderTarget(x.GraphicsContext, RenderFrameProvider.RenderFrame.RenderTargets[0], frame, 0); - if (!GoogleVr.SubmitFrame(GraphicsDevice, frame, ref headMatrix)) - { - throw new Exception("Failed to SubmitFrame to Google VR SDK"); - } - })); - - leftCamera.UseCustomProjectionMatrix = true; - rightCamera.UseCustomProjectionMatrix = true; - leftCamera.UseCustomViewMatrix = true; - rightCamera.UseCustomViewMatrix = true; - leftCamera.NearClipPlane *= ViewScaling; - rightCamera.NearClipPlane *= ViewScaling; - - if (requireMirror) - { - MirrorTexture = RenderFrameProvider.RenderFrame.RenderTargets[0]; //we don't really have a mirror in this case but avoid crashes - } - - base.Initialize(cameraRoot, leftCamera, rightCamera, requireMirror); - } - - public override void Draw(GameTime gameTime) - { - GoogleVr.GetHeadMatrix(out headMatrix); - var headMatrixTr = headMatrix; - headMatrixTr.Transpose(); - - Matrix leftEyeMatrix, rightEyeMatrix; - GoogleVr.GetEyeMatrix(0, out leftEyeMatrix); - GoogleVr.GetEyeMatrix(1, out rightEyeMatrix); - - Matrix projLeft, projRight; - GoogleVr.GetPerspectiveMatrix(0, LeftCameraComponent.NearClipPlane, LeftCameraComponent.FarClipPlane, out projLeft); - GoogleVr.GetPerspectiveMatrix(1, LeftCameraComponent.NearClipPlane, LeftCameraComponent.FarClipPlane, out projRight); - -// var iosRotL = Matrix.RotationYawPitchRoll(0, 0, MathUtil.Pi); -// var iosRotR = Matrix.RotationYawPitchRoll(0, 0, MathUtil.Pi); -// projLeft *= iosRotL; -// projRight *= iosRotR; - - Vector3 scale, camPos; - Quaternion camRot; - - //have to make sure it's updated now - CameraRootEntity.Transform.UpdateWorldMatrix(); - CameraRootEntity.Transform.WorldMatrix.Decompose(out scale, out camRot, out camPos); - - LeftCameraComponent.ProjectionMatrix = projLeft; - - var pos = camPos + leftEyeMatrix.TranslationVector * ViewScaling; - var rotV = headMatrixTr * Matrix.Scaling(ViewScaling) * Matrix.RotationQuaternion(camRot); - var finalUp = Vector3.TransformCoordinate(new Vector3(0, 1, 0), rotV); - var finalForward = Vector3.TransformCoordinate(new Vector3(0, 0, -1), rotV); - var view = Matrix.LookAtRH(pos, pos + finalForward, finalUp); - LeftCameraComponent.ViewMatrix = view; - - RightCameraComponent.ProjectionMatrix = projRight; - - pos = camPos + rightEyeMatrix.TranslationVector * ViewScaling; - rotV = headMatrixTr * Matrix.Scaling(ViewScaling) * Matrix.RotationQuaternion(camRot); - finalUp = Vector3.TransformCoordinate(new Vector3(0, 1, 0), rotV); - finalForward = Vector3.TransformCoordinate(new Vector3(0, 0, -1), rotV); - view = Matrix.LookAtRH(pos, pos + finalForward, finalUp); - RightCameraComponent.ViewMatrix = view; - - base.Draw(gameTime); - } - - public override Size2 OptimalRenderFrameSize - { - get - { - int width, height; - GoogleVr.GetMaxRenderSize(out width, out height); - return new Size2(width, height); - } - } - - public override DirectRenderFrameProvider RenderFrameProvider { get; protected set; } - - public override Texture MirrorTexture { get; protected set; } - - public override float RenderFrameScaling { get; set; } = 0.5f; - - public override DeviceState State => DeviceState.Valid; - - public override bool CanInitialize => true; - } -} - -#endif diff --git a/sources/engine/Stride.VirtualReality/OpenVR/OpenVR.cs b/sources/engine/Stride.VirtualReality/OpenVR/OpenVR.cs index 16a3caadb1..83c964fe1c 100644 --- a/sources/engine/Stride.VirtualReality/OpenVR/OpenVR.cs +++ b/sources/engine/Stride.VirtualReality/OpenVR/OpenVR.cs @@ -226,7 +226,7 @@ public static bool Init() InitDone = true; - //this makes the camera behave like oculus rift default! + //set Universe to Seated by default Valve.VR.OpenVR.Compositor.SetTrackingSpace(ETrackingUniverseOrigin.TrackingUniverseSeated); return true; diff --git a/sources/engine/Stride.VirtualReality/OpenXR/OpenXRHmd.cs b/sources/engine/Stride.VirtualReality/OpenXR/OpenXRHmd.cs index 6bf6bf888c..d345d6b8c9 100644 --- a/sources/engine/Stride.VirtualReality/OpenXR/OpenXRHmd.cs +++ b/sources/engine/Stride.VirtualReality/OpenXR/OpenXRHmd.cs @@ -149,7 +149,6 @@ public override unsafe void Enable(GraphicsDevice device, GraphicsDeviceManager PrintApiLayers(); - Logger.Debug("Installing extensions"); var openXrExtensions = new List(); @@ -202,7 +201,7 @@ public override unsafe void Enable(GraphicsDevice device, GraphicsDeviceManager #if STRIDE_GRAPHICS_API_DIRECT3D11 if (!AvailableExtensions.Contains("XR_KHR_D3D11_enable")) { - throw new InvalidOperationException($"OpenXR error! Current implementation doesn't support directX 11"); + throw new InvalidOperationException($"OpenXR error! Current implementation doesn't support Direct3D 11"); } #endif @@ -268,7 +267,7 @@ public override unsafe void Enable(GraphicsDevice device, GraphicsDeviceManager var runtimeName = Marshal.PtrToStringAnsi(new System.IntPtr(properties.RuntimeName)); var runtimeVersion = ((Version)(Version64)properties.RuntimeVersion).ToString(3); - Console.WriteLine($"[INFO] Application: Using OpenXR Runtime \"{runtimeName}\" v{runtimeVersion}"); + Logger.Info($"Using OpenXR Runtime \"{runtimeName}\" v{runtimeVersion}"); // We're creating a head-mounted-display (HMD, i.e. a VR headset) example, so we ask for a runtime which // supports that form factor. The response we get is a ulong that is the System ID. diff --git a/sources/engine/Stride.VirtualReality/Stride.VirtualReality.csproj b/sources/engine/Stride.VirtualReality/Stride.VirtualReality.csproj index 2a255dbaea..207160a94a 100644 --- a/sources/engine/Stride.VirtualReality/Stride.VirtualReality.csproj +++ b/sources/engine/Stride.VirtualReality/Stride.VirtualReality.csproj @@ -1,4 +1,4 @@ - + true true @@ -14,15 +14,6 @@ * true - - - - - ..\..\..\deps\GoogleVR\lib\Android\GoogleVRJava.dll - - - - @@ -58,22 +49,10 @@ - - - + - - - _StrideIncludeExtraAssemblies;$(TargetsForTfmSpecificBuildOutput) - - - - - - - \ No newline at end of file diff --git a/sources/engine/Stride.VirtualReality/VRApi.cs b/sources/engine/Stride.VirtualReality/VRApi.cs index a47e556d5e..8b06dbe370 100644 --- a/sources/engine/Stride.VirtualReality/VRApi.cs +++ b/sources/engine/Stride.VirtualReality/VRApi.cs @@ -9,7 +9,5 @@ public enum VRApi WindowsMixedReality = 2, OpenXR = 3, Dummy = 100, - //Fove, - //Google, } } diff --git a/sources/engine/Stride.VirtualReality/VRDeviceSystem.cs b/sources/engine/Stride.VirtualReality/VRDeviceSystem.cs index d1ebc70552..b7a092c4c4 100644 --- a/sources/engine/Stride.VirtualReality/VRDeviceSystem.cs +++ b/sources/engine/Stride.VirtualReality/VRDeviceSystem.cs @@ -97,20 +97,6 @@ private void OnEnabledChanged(object sender, EventArgs eventArgs) #endif break; } - //case VRApi.Fove: - //{ - //#if STRIDE_GRAPHICS_API_DIRECT3D11 - // Device = new FoveHmd(); - //#endif - //break; - //} - //case VRApi.Google: - //{ - //#if STRIDE_PLATFORM_IOS || STRIDE_PLATFORM_ANDROID - // VRDevice = new GoogleVrHmd(); - //#endif - // break; - //} default: throw new ArgumentOutOfRangeException(); }