ovr_sdk

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LibOVR/Src/CAPI/CAPI_DistortionRenderer.h	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,167 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +Filename    :   CAPI_DistortionRenderer.h
     1.7 +Content     :   Abstract interface for platform-specific rendering of distortion
     1.8 +Created     :   February 2, 2014
     1.9 +Authors     :   Michael Antonov
    1.10 +
    1.11 +Copyright   :   Copyright 2014 Oculus VR, LLC All Rights reserved.
    1.12 +
    1.13 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 
    1.14 +you may not use the Oculus VR Rift SDK except in compliance with the License, 
    1.15 +which is provided at the time of installation or download, or which 
    1.16 +otherwise accompanies this software in either electronic or hard copy form.
    1.17 +
    1.18 +You may obtain a copy of the License at
    1.19 +
    1.20 +http://www.oculusvr.com/licenses/LICENSE-3.2 
    1.21 +
    1.22 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
    1.23 +distributed under the License is distributed on an "AS IS" BASIS,
    1.24 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.25 +See the License for the specific language governing permissions and
    1.26 +limitations under the License.
    1.27 +
    1.28 +************************************************************************************/
    1.29 +
    1.30 +#ifndef OVR_CAPI_DistortionRenderer_h
    1.31 +#define OVR_CAPI_DistortionRenderer_h
    1.32 +
    1.33 +#include "CAPI_HMDRenderState.h"
    1.34 +#include "CAPI_FrameTimeManager.h"
    1.35 +
    1.36 +typedef void (*PostDistortionCallback)(void* pRenderContext);
    1.37 +
    1.38 +namespace OVR { namespace CAPI {
    1.39 +
    1.40 +//-------------------------------------------------------------------------------------
    1.41 +// ***** CAPI::DistortionRenderer
    1.42 +
    1.43 +// DistortionRenderer implements rendering of distortion and other overlay elements
    1.44 +// in platform-independent way.
    1.45 +// Platform-specific renderer back ends for CAPI are derived from this class.
    1.46 +
    1.47 +class  DistortionRenderer : public RefCountBase<DistortionRenderer>
    1.48 +{
    1.49 +    // Quiet assignment compiler warning.
    1.50 +    void operator = (const DistortionRenderer&) { }
    1.51 +public:
    1.52 +    
    1.53 +    DistortionRenderer(ovrRenderAPIType api, ovrHmd hmd,
    1.54 +                       FrameTimeManager& timeManager,              
    1.55 +                       const HMDRenderState& renderState) :
    1.56 +		LastUsedOverdriveTextureIndex(-1),
    1.57 +        LatencyTestActive(false),
    1.58 +        LatencyTest2Active(false),
    1.59 +        RenderAPI(api),
    1.60 +        HMD(hmd),
    1.61 +        TimeManager(timeManager),
    1.62 +        RState(renderState),
    1.63 +        GfxState(),
    1.64 +        RegisteredPostDistortionCallback(NULL)
    1.65 +    {
    1.66 +#ifdef OVR_OS_WIN32
    1.67 +        timer = CreateWaitableTimer(NULL, TRUE, NULL);
    1.68 +        OVR_ASSERT(timer != NULL);
    1.69 +#endif
    1.70 +    }
    1.71 +    virtual ~DistortionRenderer()
    1.72 +    {
    1.73 +    }
    1.74 +    
    1.75 +
    1.76 +    // Configures the Renderer based on externally passed API settings. Must be
    1.77 +    // called before use.
    1.78 +    // Under D3D, apiConfig includes D3D Device pointer, back buffer and other
    1.79 +    // needed structures.
    1.80 +    virtual bool Initialize(const ovrRenderAPIConfig* apiConfig) = 0;
    1.81 +
    1.82 +    // Submits one eye texture for rendering. This is in the separate method to
    1.83 +    // allow "submit as you render" scenarios on horizontal screens where one
    1.84 +    // eye can be scanned out before the other.
    1.85 +    virtual void SubmitEye(int eyeId, const ovrTexture* eyeTexture) = 0;
    1.86 +
    1.87 +    // Finish the frame, optionally swapping buffers.
    1.88 +    // Many implementations may actually apply the distortion here.
    1.89 +    virtual void EndFrame(bool swapBuffers) = 0;
    1.90 +    
    1.91 +    void RegisterPostDistortionCallback(PostDistortionCallback postDistortionCallback)
    1.92 +    {
    1.93 +        RegisteredPostDistortionCallback = postDistortionCallback;
    1.94 +    }
    1.95 +
    1.96 +	// Stores the current graphics pipeline state so it can be restored later.
    1.97 +	void SaveGraphicsState() { if (GfxState && !(RState.DistortionCaps & ovrDistortionCap_NoRestore)) GfxState->Save(); }
    1.98 +
    1.99 +	// Restores the saved graphics pipeline state.
   1.100 +	void RestoreGraphicsState() { if (GfxState && !(RState.DistortionCaps & ovrDistortionCap_NoRestore)) GfxState->Restore(); }
   1.101 +
   1.102 +    // *** Creation Factory logic
   1.103 +    
   1.104 +    ovrRenderAPIType GetRenderAPI() const { return RenderAPI; }
   1.105 +
   1.106 +    // Creation function for this interface, registered for API.
   1.107 +    typedef DistortionRenderer* (*CreateFunc)(ovrHmd hmd,
   1.108 +                                              FrameTimeManager &timeManager,
   1.109 +                                              const HMDRenderState& renderState);
   1.110 +
   1.111 +    static CreateFunc APICreateRegistry[ovrRenderAPI_Count];
   1.112 +
   1.113 +    // Color is expected to be 3 byte RGB
   1.114 +    void SetLatencyTestColor(unsigned char* color);
   1.115 +    void SetLatencyTest2Color(unsigned char* color);
   1.116 +    
   1.117 +protected:
   1.118 +	// Used for pixel luminance overdrive on DK2 displays
   1.119 +	// A copy of back buffer images will be ping ponged
   1.120 +	// TODO: figure out 0 dynamically based on DK2 latency?
   1.121 +	static const int	NumOverdriveTextures = 2;
   1.122 +	int					LastUsedOverdriveTextureIndex;
   1.123 +
   1.124 +    bool                LatencyTestActive;
   1.125 +    unsigned char       LatencyTestDrawColor[3];
   1.126 +    bool                LatencyTest2Active;
   1.127 +    unsigned char       LatencyTest2DrawColor[3];
   1.128 +
   1.129 +    bool IsOverdriveActive()
   1.130 +	{
   1.131 +		// doesn't make sense to use overdrive when vsync is disabled as we cannot guarantee
   1.132 +		// when the rendered frame will be displayed
   1.133 +		return LastUsedOverdriveTextureIndex >= 0 &&
   1.134 +                !((RState.EnabledHmdCaps & ovrHmdCap_NoVSync) > 0) &&
   1.135 +                (RState.DistortionCaps & ovrDistortionCap_Chromatic);
   1.136 +	}
   1.137 +
   1.138 +    void GetOverdriveScales(float& outRiseScale, float& outFallScale);
   1.139 +
   1.140 +    double WaitTillTime(double absTime);
   1.141 +
   1.142 +#ifdef OVR_OS_WIN32
   1.143 +    HANDLE timer;
   1.144 +    LARGE_INTEGER waitableTimerInterval;
   1.145 +#endif
   1.146 +
   1.147 +    class GraphicsState : public RefCountBase<GraphicsState>
   1.148 +    {
   1.149 +    public:
   1.150 +        GraphicsState() : IsValid(false) {}
   1.151 +        virtual ~GraphicsState() {}
   1.152 +        virtual void Save() = 0;
   1.153 +        virtual void Restore() = 0;
   1.154 +        
   1.155 +    protected:
   1.156 +        bool IsValid;
   1.157 +    };
   1.158 +    
   1.159 +    const ovrRenderAPIType  RenderAPI;
   1.160 +    const ovrHmd            HMD;
   1.161 +    FrameTimeManager&       TimeManager;
   1.162 +    const HMDRenderState&   RState;
   1.163 +    Ptr<GraphicsState>      GfxState;
   1.164 +    PostDistortionCallback  RegisteredPostDistortionCallback;
   1.165 +};
   1.166 +
   1.167 +}} // namespace OVR::CAPI
   1.168 +
   1.169 +
   1.170 +#endif // OVR_CAPI_DistortionRenderer_h