rev |
line source |
nuclear@0
|
1 /************************************************************************************
|
nuclear@0
|
2
|
nuclear@0
|
3 Filename : CAPI_DistortionRenderer.h
|
nuclear@0
|
4 Content : Abstract interface for platform-specific rendering of distortion
|
nuclear@0
|
5 Created : February 2, 2014
|
nuclear@0
|
6 Authors : Michael Antonov
|
nuclear@0
|
7
|
nuclear@0
|
8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
|
nuclear@0
|
9
|
nuclear@0
|
10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
|
nuclear@0
|
11 you may not use the Oculus VR Rift SDK except in compliance with the License,
|
nuclear@0
|
12 which is provided at the time of installation or download, or which
|
nuclear@0
|
13 otherwise accompanies this software in either electronic or hard copy form.
|
nuclear@0
|
14
|
nuclear@0
|
15 You may obtain a copy of the License at
|
nuclear@0
|
16
|
nuclear@0
|
17 http://www.oculusvr.com/licenses/LICENSE-3.2
|
nuclear@0
|
18
|
nuclear@0
|
19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
|
nuclear@0
|
20 distributed under the License is distributed on an "AS IS" BASIS,
|
nuclear@0
|
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
nuclear@0
|
22 See the License for the specific language governing permissions and
|
nuclear@0
|
23 limitations under the License.
|
nuclear@0
|
24
|
nuclear@0
|
25 ************************************************************************************/
|
nuclear@0
|
26
|
nuclear@0
|
27 #ifndef OVR_CAPI_DistortionRenderer_h
|
nuclear@0
|
28 #define OVR_CAPI_DistortionRenderer_h
|
nuclear@0
|
29
|
nuclear@0
|
30 #include "CAPI_HMDRenderState.h"
|
nuclear@0
|
31 #include "CAPI_FrameTimeManager.h"
|
nuclear@0
|
32
|
nuclear@0
|
33 typedef void (*PostDistortionCallback)(void* pRenderContext);
|
nuclear@0
|
34
|
nuclear@0
|
35 namespace OVR { namespace CAPI {
|
nuclear@0
|
36
|
nuclear@0
|
37 //-------------------------------------------------------------------------------------
|
nuclear@0
|
38 // ***** CAPI::DistortionRenderer
|
nuclear@0
|
39
|
nuclear@0
|
40 // DistortionRenderer implements rendering of distortion and other overlay elements
|
nuclear@0
|
41 // in platform-independent way.
|
nuclear@0
|
42 // Platform-specific renderer back ends for CAPI are derived from this class.
|
nuclear@0
|
43
|
nuclear@0
|
44 class DistortionRenderer : public RefCountBase<DistortionRenderer>
|
nuclear@0
|
45 {
|
nuclear@0
|
46 // Quiet assignment compiler warning.
|
nuclear@0
|
47 void operator = (const DistortionRenderer&) { }
|
nuclear@0
|
48 public:
|
nuclear@0
|
49
|
nuclear@0
|
50 DistortionRenderer(ovrRenderAPIType api, ovrHmd hmd,
|
nuclear@0
|
51 FrameTimeManager& timeManager,
|
nuclear@0
|
52 const HMDRenderState& renderState) :
|
nuclear@0
|
53 LastUsedOverdriveTextureIndex(-1),
|
nuclear@0
|
54 LatencyTestActive(false),
|
nuclear@0
|
55 LatencyTest2Active(false),
|
nuclear@0
|
56 RenderAPI(api),
|
nuclear@0
|
57 HMD(hmd),
|
nuclear@0
|
58 TimeManager(timeManager),
|
nuclear@0
|
59 RState(renderState),
|
nuclear@0
|
60 GfxState(),
|
nuclear@0
|
61 RegisteredPostDistortionCallback(NULL)
|
nuclear@0
|
62 {
|
nuclear@0
|
63 #ifdef OVR_OS_WIN32
|
nuclear@0
|
64 timer = CreateWaitableTimer(NULL, TRUE, NULL);
|
nuclear@0
|
65 OVR_ASSERT(timer != NULL);
|
nuclear@0
|
66 #endif
|
nuclear@0
|
67 }
|
nuclear@0
|
68 virtual ~DistortionRenderer()
|
nuclear@0
|
69 {
|
nuclear@0
|
70 }
|
nuclear@0
|
71
|
nuclear@0
|
72
|
nuclear@0
|
73 // Configures the Renderer based on externally passed API settings. Must be
|
nuclear@0
|
74 // called before use.
|
nuclear@0
|
75 // Under D3D, apiConfig includes D3D Device pointer, back buffer and other
|
nuclear@0
|
76 // needed structures.
|
nuclear@0
|
77 virtual bool Initialize(const ovrRenderAPIConfig* apiConfig) = 0;
|
nuclear@0
|
78
|
nuclear@0
|
79 // Submits one eye texture for rendering. This is in the separate method to
|
nuclear@0
|
80 // allow "submit as you render" scenarios on horizontal screens where one
|
nuclear@0
|
81 // eye can be scanned out before the other.
|
nuclear@0
|
82 virtual void SubmitEye(int eyeId, const ovrTexture* eyeTexture) = 0;
|
nuclear@0
|
83
|
nuclear@0
|
84 // Finish the frame, optionally swapping buffers.
|
nuclear@0
|
85 // Many implementations may actually apply the distortion here.
|
nuclear@0
|
86 virtual void EndFrame(bool swapBuffers) = 0;
|
nuclear@0
|
87
|
nuclear@0
|
88 void RegisterPostDistortionCallback(PostDistortionCallback postDistortionCallback)
|
nuclear@0
|
89 {
|
nuclear@0
|
90 RegisteredPostDistortionCallback = postDistortionCallback;
|
nuclear@0
|
91 }
|
nuclear@0
|
92
|
nuclear@0
|
93 // Stores the current graphics pipeline state so it can be restored later.
|
nuclear@0
|
94 void SaveGraphicsState() { if (GfxState && !(RState.DistortionCaps & ovrDistortionCap_NoRestore)) GfxState->Save(); }
|
nuclear@0
|
95
|
nuclear@0
|
96 // Restores the saved graphics pipeline state.
|
nuclear@0
|
97 void RestoreGraphicsState() { if (GfxState && !(RState.DistortionCaps & ovrDistortionCap_NoRestore)) GfxState->Restore(); }
|
nuclear@0
|
98
|
nuclear@0
|
99 // *** Creation Factory logic
|
nuclear@0
|
100
|
nuclear@0
|
101 ovrRenderAPIType GetRenderAPI() const { return RenderAPI; }
|
nuclear@0
|
102
|
nuclear@0
|
103 // Creation function for this interface, registered for API.
|
nuclear@0
|
104 typedef DistortionRenderer* (*CreateFunc)(ovrHmd hmd,
|
nuclear@0
|
105 FrameTimeManager &timeManager,
|
nuclear@0
|
106 const HMDRenderState& renderState);
|
nuclear@0
|
107
|
nuclear@0
|
108 static CreateFunc APICreateRegistry[ovrRenderAPI_Count];
|
nuclear@0
|
109
|
nuclear@0
|
110 // Color is expected to be 3 byte RGB
|
nuclear@0
|
111 void SetLatencyTestColor(unsigned char* color);
|
nuclear@0
|
112 void SetLatencyTest2Color(unsigned char* color);
|
nuclear@0
|
113
|
nuclear@0
|
114 protected:
|
nuclear@0
|
115 // Used for pixel luminance overdrive on DK2 displays
|
nuclear@0
|
116 // A copy of back buffer images will be ping ponged
|
nuclear@0
|
117 // TODO: figure out 0 dynamically based on DK2 latency?
|
nuclear@0
|
118 static const int NumOverdriveTextures = 2;
|
nuclear@0
|
119 int LastUsedOverdriveTextureIndex;
|
nuclear@0
|
120
|
nuclear@0
|
121 bool LatencyTestActive;
|
nuclear@0
|
122 unsigned char LatencyTestDrawColor[3];
|
nuclear@0
|
123 bool LatencyTest2Active;
|
nuclear@0
|
124 unsigned char LatencyTest2DrawColor[3];
|
nuclear@0
|
125
|
nuclear@0
|
126 bool IsOverdriveActive()
|
nuclear@0
|
127 {
|
nuclear@0
|
128 // doesn't make sense to use overdrive when vsync is disabled as we cannot guarantee
|
nuclear@0
|
129 // when the rendered frame will be displayed
|
nuclear@0
|
130 return LastUsedOverdriveTextureIndex >= 0 &&
|
nuclear@0
|
131 !((RState.EnabledHmdCaps & ovrHmdCap_NoVSync) > 0) &&
|
nuclear@0
|
132 (RState.DistortionCaps & ovrDistortionCap_Chromatic);
|
nuclear@0
|
133 }
|
nuclear@0
|
134
|
nuclear@0
|
135 void GetOverdriveScales(float& outRiseScale, float& outFallScale);
|
nuclear@0
|
136
|
nuclear@0
|
137 double WaitTillTime(double absTime);
|
nuclear@0
|
138
|
nuclear@0
|
139 #ifdef OVR_OS_WIN32
|
nuclear@0
|
140 HANDLE timer;
|
nuclear@0
|
141 LARGE_INTEGER waitableTimerInterval;
|
nuclear@0
|
142 #endif
|
nuclear@0
|
143
|
nuclear@0
|
144 class GraphicsState : public RefCountBase<GraphicsState>
|
nuclear@0
|
145 {
|
nuclear@0
|
146 public:
|
nuclear@0
|
147 GraphicsState() : IsValid(false) {}
|
nuclear@0
|
148 virtual ~GraphicsState() {}
|
nuclear@0
|
149 virtual void Save() = 0;
|
nuclear@0
|
150 virtual void Restore() = 0;
|
nuclear@0
|
151
|
nuclear@0
|
152 protected:
|
nuclear@0
|
153 bool IsValid;
|
nuclear@0
|
154 };
|
nuclear@0
|
155
|
nuclear@0
|
156 const ovrRenderAPIType RenderAPI;
|
nuclear@0
|
157 const ovrHmd HMD;
|
nuclear@0
|
158 FrameTimeManager& TimeManager;
|
nuclear@0
|
159 const HMDRenderState& RState;
|
nuclear@0
|
160 Ptr<GraphicsState> GfxState;
|
nuclear@0
|
161 PostDistortionCallback RegisteredPostDistortionCallback;
|
nuclear@0
|
162 };
|
nuclear@0
|
163
|
nuclear@0
|
164 }} // namespace OVR::CAPI
|
nuclear@0
|
165
|
nuclear@0
|
166
|
nuclear@0
|
167 #endif // OVR_CAPI_DistortionRenderer_h
|