Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
5.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Contains the IHeadTrack interface, which is implemented in headtrack.dll
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef ISOURCEVIRTUALREALITY_H
  9. #define ISOURCEVIRTUALREALITY_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "tier1/interface.h"
  14. #include "tier1/refcount.h"
  15. #include "appframework/IAppSystem.h"
  16. #include "mathlib/vmatrix.h"
  17. //-----------------------------------------------------------------------------
  18. // forward declarations
  19. //-----------------------------------------------------------------------------
  20. class ITexture;
  21. class IMaterialSystem;
  22. //-----------------------------------------------------------------------------
  23. // important enumeration
  24. //-----------------------------------------------------------------------------
  25. struct VRRect_t
  26. {
  27. int32 nX;
  28. int32 nY;
  29. int32 nWidth;
  30. int32 nHeight;
  31. };
  32. // NOTE NOTE NOTE!!!! If you up this, grep for "NEW_INTERFACE" to see if there is anything
  33. // waiting to be enabled during an interface revision.
  34. #define SOURCE_VIRTUAL_REALITY_INTERFACE_VERSION "SourceVirtualReality001"
  35. //-----------------------------------------------------------------------------
  36. // The ISourceVirtualReality interface
  37. //-----------------------------------------------------------------------------
  38. abstract_class ISourceVirtualReality : public IAppSystem
  39. {
  40. public:
  41. virtual ~ISourceVirtualReality() {}
  42. // Placeholder for API revision
  43. virtual bool Connect( CreateInterfaceFn factory ) = 0;
  44. virtual void Disconnect() = 0;
  45. virtual void *QueryInterface( const char *pInterfaceName ) = 0;
  46. virtual InitReturnVal_t Init() = 0;
  47. virtual void Shutdown() = 0;
  48. // This enum is used to tell some of the other calls in this interface which eye
  49. // is being requested.
  50. enum VREye
  51. {
  52. VREye_Left = 0,
  53. VREye_Right
  54. };
  55. // Which texture is being requested in GetRenderTarget?
  56. enum EWhichRenderTarget
  57. {
  58. RT_Color = 0,
  59. RT_Depth,
  60. };
  61. // ----------------------------------------------------------------------
  62. // General utilities
  63. // ----------------------------------------------------------------------
  64. // Returns true if the game should run in VR mode
  65. virtual bool ShouldRunInVR() = 0;
  66. // Returns true if there is a compatible HMD connected
  67. virtual bool IsHmdConnected() = 0;
  68. // The size and position of the viewport for the specified eye
  69. virtual void GetViewportBounds( VREye eEye, int *pnX, int *pnY, int *pnWidth, int *pnHeight ) = 0;
  70. // Performs the distortion post-processing.
  71. virtual bool DoDistortionProcessing ( VREye eEye ) = 0;
  72. // Composites the HUD directly onto the backbuffer / render target, including undistort.
  73. virtual bool CompositeHud ( VREye eEye, float ndcHudBounds[4], bool bDoUndistort, bool bBlackout, bool bTranslucent ) = 0;
  74. // ----------------------------------------------------------------------
  75. // Getting the current pose
  76. // ----------------------------------------------------------------------
  77. // returns the pose relative to the zero point
  78. virtual VMatrix GetMideyePose() = 0;
  79. // All-in-one interfaces (they call GetCameraPoseZeroFromCurrent)
  80. // Grabs the current tracking data and sets up state for the Override* calls.
  81. virtual bool SampleTrackingState ( float PlayerGameFov, float fPredictionSeconds ) = 0;
  82. // ----------------------------------------------------------------------
  83. // Information about the display
  84. // ----------------------------------------------------------------------
  85. // Passes back the bounds of the window that the game should create. This might
  86. // span two displays if we're dealing with a two-input display. Returns true
  87. // if the bounds were set.
  88. virtual bool GetDisplayBounds( VRRect_t *pRect ) = 0;
  89. // Computes and returns the projection matrix for the eye
  90. virtual bool GetEyeProjectionMatrix ( VMatrix *pResult, VREye, float zNear, float zFar, float fovScale ) = 0;
  91. // Returns the transform from the mid-eye to the specified eye. Multiply this by
  92. // the tweaked (for mouse rotation and WASD translation) mideye position to get the
  93. // view matrix. This matrix takes the user's IPD into account.
  94. virtual VMatrix GetMidEyeFromEye( VREye eEye ) = 0;
  95. // returns the adapter index to use for VR mode
  96. virtual int GetVRModeAdapter() = 0;
  97. // ----------------------------------------------------------------------
  98. // Information about the tracker
  99. // ----------------------------------------------------------------------
  100. virtual bool WillDriftInYaw() = 0;
  101. // ----------------------------------------------------------------------
  102. // Methods about oversized offscreen rendering
  103. // ----------------------------------------------------------------------
  104. // Sets up the pre-distortion render targets.
  105. virtual void CreateRenderTargets( IMaterialSystem *pMaterialSystem ) = 0;
  106. virtual void ShutdownRenderTargets() = 0;
  107. // fetches the render target for the specified eye
  108. virtual ITexture *GetRenderTarget( VREye eEye, EWhichRenderTarget eWhich ) = 0;
  109. // Returns the (possibly overridden) framebuffer size for render target sizing.
  110. virtual void GetRenderTargetFrameBufferDimensions( int & nWidth, int & nHeight ) = 0;
  111. // ----------------------------------------------------------------------
  112. // Enter/leave VR mode
  113. // ----------------------------------------------------------------------
  114. virtual bool Activate() = 0;
  115. virtual void Deactivate() = 0;
  116. virtual bool ShouldForceVRMode() = 0;
  117. virtual void SetShouldForceVRMode() = 0;
  118. };
  119. //-----------------------------------------------------------------------------
  120. extern ISourceVirtualReality *g_pSourceVR;
  121. inline bool UseVR()
  122. {
  123. return g_pSourceVR != NULL && g_pSourceVR->ShouldRunInVR();
  124. }
  125. inline bool ShouldForceVRActive()
  126. {
  127. return g_pSourceVR != NULL && g_pSourceVR->ShouldForceVRMode();
  128. }
  129. #endif // ISOURCEVIRTUALREALITY_H