ovr_sdk
diff LibOVR/Src/CAPI/GL/CAPI_GL_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/GL/CAPI_GL_DistortionRenderer.h Wed Jan 14 06:51:16 2015 +0200 1.3 @@ -0,0 +1,150 @@ 1.4 +/************************************************************************************ 1.5 + 1.6 +Filename : CAPI_GL_DistortionRenderer.h 1.7 +Content : Distortion renderer header for GL 1.8 +Created : November 11, 2013 1.9 +Authors : David Borel, Lee Cooper 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_GL_DistortionRenderer_h 1.31 +#define OVR_CAPI_GL_DistortionRenderer_h 1.32 + 1.33 +#include "../CAPI_DistortionRenderer.h" 1.34 + 1.35 +#include "../../Kernel/OVR_Log.h" 1.36 +#include "CAPI_GL_Util.h" 1.37 + 1.38 +namespace OVR { namespace CAPI { namespace GL { 1.39 + 1.40 +// ***** GL::DistortionRenderer 1.41 + 1.42 +// Implementation of DistortionRenderer for GL. 1.43 + 1.44 +class DistortionRenderer : public CAPI::DistortionRenderer 1.45 +{ 1.46 +public: 1.47 + DistortionRenderer(ovrHmd hmd, 1.48 + FrameTimeManager& timeManager, 1.49 + const HMDRenderState& renderState); 1.50 + virtual ~DistortionRenderer(); 1.51 + 1.52 + 1.53 + // Creation function for the device. 1.54 + static CAPI::DistortionRenderer* Create(ovrHmd hmd, 1.55 + FrameTimeManager& timeManager, 1.56 + const HMDRenderState& renderState); 1.57 + 1.58 + 1.59 + // ***** Public DistortionRenderer interface 1.60 + 1.61 + virtual bool Initialize(const ovrRenderAPIConfig* apiConfig) OVR_OVERRIDE; 1.62 + 1.63 + virtual void SubmitEye(int eyeId, const ovrTexture* eyeTexture); 1.64 + 1.65 + virtual void EndFrame(bool swapBuffers); 1.66 + 1.67 + void WaitUntilGpuIdle(); 1.68 + 1.69 + // Similar to ovr_WaitTillTime but it also flushes GPU. 1.70 + // Note, it exits when time expires, even if GPU is not in idle state yet. 1.71 + double FlushGpuAndWaitTillTime(double absTime); 1.72 + 1.73 +protected: 1.74 + 1.75 + struct FOR_EACH_EYE 1.76 + { 1.77 + FOR_EACH_EYE() : numVerts(0), numIndices(0), texture(0), /*UVScaleOffset[],*/ TextureSize(0, 0), RenderViewport(0, 0, 0, 0) { } 1.78 + 1.79 + int numVerts; 1.80 + int numIndices; 1.81 + 1.82 + GLuint texture; 1.83 + 1.84 + ovrVector2f UVScaleOffset[2]; 1.85 + Sizei TextureSize; 1.86 + Recti RenderViewport; 1.87 + } eachEye[2]; 1.88 + 1.89 + Ptr<Texture> pOverdriveTextures[NumOverdriveTextures]; 1.90 + Ptr<Texture> OverdriveBackBufferTexture; 1.91 + 1.92 + // GL context and utility variables. 1.93 + RenderParams RParams; 1.94 + Context distortionContext; // We are currently using this private OpenGL context instead of using the CAPI SaveGraphicsState/RestoreGraphicsState mechanism. To consider: Move this Context into SaveGraphicsState/RestoreGraphicState so there's consistency between DirectX and OpenGL. 1.95 + 1.96 + // Helpers 1.97 + void initOverdrive(); 1.98 + void initBuffersAndShaders(); 1.99 + void initShaders(); 1.100 + void initFullscreenQuad(); 1.101 + void destroy(); 1.102 + 1.103 + void setViewport(const Recti& vp); 1.104 + 1.105 + void renderDistortion(Texture* leftEyeTexture, Texture* rightEyeTexture); 1.106 + 1.107 + void renderPrimitives(const ShaderFill* fill, Buffer* vertices, Buffer* indices, 1.108 + int offset, int count, 1.109 + PrimitiveType rprim, GLuint* vao, bool isDistortionMesh); 1.110 + 1.111 + void createDrawQuad(); 1.112 + void renderLatencyQuad(unsigned char* latencyTesterDrawColor); 1.113 + void renderLatencyPixel(unsigned char* latencyTesterPixelColor); 1.114 + 1.115 + void renderEndFrame(); 1.116 + 1.117 + Ptr<Texture> pEyeTextures[2]; 1.118 + 1.119 + Ptr<Buffer> DistortionMeshVBs[2]; // one per-eye 1.120 + Ptr<Buffer> DistortionMeshIBs[2]; // one per-eye 1.121 + GLuint DistortionMeshVAOs[2]; // one per-eye 1.122 + 1.123 + Ptr<ShaderSet> DistortionShader; 1.124 + 1.125 + bool RotateCCW90; 1.126 + 1.127 + struct StandardUniformData 1.128 + { 1.129 + Matrix4f Proj; 1.130 + Matrix4f View; 1.131 + } StdUniforms; 1.132 + 1.133 + GLuint LatencyVAO; 1.134 + Ptr<Buffer> LatencyTesterQuadVB; 1.135 + Ptr<ShaderSet> SimpleQuadShader; 1.136 + Ptr<ShaderSet> SimpleQuadGammaShader; 1.137 + 1.138 + GLuint OverdriveFbo; 1.139 + 1.140 + GLint SavedViewport[4]; 1.141 + GLfloat SavedClearColor[4]; 1.142 + GLint SavedDepthTest; 1.143 + GLint SavedCullFace; 1.144 + GLint SavedProgram; 1.145 + GLint SavedActiveTexture; 1.146 + GLint SavedBoundTexture; 1.147 + GLint SavedVertexArray; 1.148 + GLint SavedBoundFrameBuffer; 1.149 +}; 1.150 + 1.151 +}}} // OVR::CAPI::GL 1.152 + 1.153 +#endif // OVR_CAPI_GL_DistortionRenderer_h