aboutsummaryrefslogtreecommitdiff
path: root/sp/src/public/sourcevr/isourcevirtualreality.h
blob: e22c67046500e391c453a47c930615491bc33223 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Contains the IHeadTrack interface, which is implemented in headtrack.dll
//
// $NoKeywords: $
//
//===========================================================================//

#ifndef ISOURCEVIRTUALREALITY_H
#define ISOURCEVIRTUALREALITY_H

#ifdef _WIN32
#pragma once
#endif

#include "tier1/interface.h"
#include "tier1/refcount.h"
#include "appframework/IAppSystem.h"
#include "mathlib/vmatrix.h"

//-----------------------------------------------------------------------------
// forward declarations
//-----------------------------------------------------------------------------
class ITexture;
class IMaterialSystem;

//-----------------------------------------------------------------------------
// important enumeration
//-----------------------------------------------------------------------------

struct VRRect_t
{
	int32 nX;
	int32 nY;
	int32 nWidth;
	int32 nHeight;
};


// NOTE NOTE NOTE!!!!  If you up this, grep for "NEW_INTERFACE" to see if there is anything
// waiting to be enabled during an interface revision.
#define SOURCE_VIRTUAL_REALITY_INTERFACE_VERSION "SourceVirtualReality001"

//-----------------------------------------------------------------------------
// The ISourceVirtualReality interface
//-----------------------------------------------------------------------------



abstract_class ISourceVirtualReality : public IAppSystem
{
public:
	virtual ~ISourceVirtualReality() {}

	// Placeholder for API revision
	virtual bool Connect( CreateInterfaceFn factory ) = 0;
	virtual void Disconnect() = 0;
	virtual void *QueryInterface( const char *pInterfaceName ) = 0;
	virtual InitReturnVal_t Init() = 0;
	virtual void Shutdown() = 0;

	// This enum is used to tell some of the other calls in this interface which eye
	// is being requested.
	enum VREye
	{
		VREye_Left = 0,
		VREye_Right
	};

	// Which texture is being requested in GetRenderTarget?
	enum EWhichRenderTarget
	{
		RT_Color = 0,
		RT_Depth,
	};


	// ----------------------------------------------------------------------
	// General utilities
	// ----------------------------------------------------------------------

	// Returns true if the game should run in VR mode
	virtual bool ShouldRunInVR() = 0;

	// Returns true if there is a compatible HMD connected 
	virtual bool IsHmdConnected() = 0;

	// The size and position of the viewport for the specified eye
	virtual void GetViewportBounds( VREye eEye, int *pnX, int *pnY, int *pnWidth, int *pnHeight ) = 0;

	// Performs the distortion post-processing.
	virtual bool DoDistortionProcessing ( VREye eEye ) = 0;

	// Composites the HUD directly onto the backbuffer / render target, including undistort.
	virtual bool CompositeHud ( VREye eEye, float ndcHudBounds[4], bool bDoUndistort, bool bBlackout, bool bTranslucent ) = 0;

	// ----------------------------------------------------------------------
	// Getting the current pose
	// ----------------------------------------------------------------------

	// returns the pose relative to the zero point
	virtual VMatrix GetMideyePose() = 0;

	// All-in-one interfaces (they call GetCameraPoseZeroFromCurrent)
	// Grabs the current tracking data and sets up state for the Override* calls.
	virtual bool SampleTrackingState ( float PlayerGameFov, float fPredictionSeconds ) = 0;

	// ----------------------------------------------------------------------
	// Information about the display
	// ----------------------------------------------------------------------

	// Passes back the bounds of the window that the game should create. This might
	// span two displays if we're dealing with a two-input display. Returns true
	// if the bounds were set.
	virtual bool GetDisplayBounds( VRRect_t *pRect ) = 0;

	// Computes and returns the projection matrix for the eye
	virtual bool GetEyeProjectionMatrix ( VMatrix *pResult, VREye, float zNear, float zFar, float fovScale ) = 0;

	// Returns the transform from the mid-eye to the specified eye. Multiply this by 
	// the tweaked (for mouse rotation and WASD translation) mideye position to get the
	// view matrix. This matrix takes the user's IPD into account.
	virtual VMatrix GetMidEyeFromEye( VREye eEye ) = 0;

	// returns the adapter index to use for VR mode
	virtual int GetVRModeAdapter() = 0;

	// ----------------------------------------------------------------------
	// Information about the tracker
	// ----------------------------------------------------------------------

	virtual bool WillDriftInYaw() = 0;

	// ----------------------------------------------------------------------
	// Methods about oversized offscreen rendering
	// ----------------------------------------------------------------------

	// Sets up the pre-distortion render targets.
	virtual void CreateRenderTargets( IMaterialSystem *pMaterialSystem ) = 0;
	virtual void ShutdownRenderTargets() = 0;

	// fetches the render target for the specified eye
	virtual ITexture *GetRenderTarget( VREye eEye, EWhichRenderTarget eWhich ) = 0;

	// Returns the (possibly overridden) framebuffer size for render target sizing.
	virtual void				GetRenderTargetFrameBufferDimensions( int & nWidth, int & nHeight ) = 0;

	// ----------------------------------------------------------------------
	// Enter/leave VR mode
	// ----------------------------------------------------------------------
	virtual bool Activate() = 0;
	virtual void Deactivate() = 0;
	
	virtual bool ShouldForceVRMode() = 0;
	virtual void SetShouldForceVRMode() = 0;

};



//-----------------------------------------------------------------------------

extern ISourceVirtualReality *g_pSourceVR;

inline bool UseVR()
{
	return g_pSourceVR != NULL && g_pSourceVR->ShouldRunInVR();
}

inline bool ShouldForceVRActive()
{
	return g_pSourceVR != NULL && g_pSourceVR->ShouldForceVRMode();
}

#endif // ISOURCEVIRTUALREALITY_H