ovr_sdk

view LibOVR/Src/CAPI/CAPI_DistortionRenderer.h @ 0:1b39a1b46319

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