ovr_sdk

view 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 source
1 /************************************************************************************
3 Filename : CAPI_GL_DistortionRenderer.h
4 Content : Distortion renderer header for GL
5 Created : November 11, 2013
6 Authors : David Borel, Lee Cooper
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_GL_DistortionRenderer_h
28 #define OVR_CAPI_GL_DistortionRenderer_h
30 #include "../CAPI_DistortionRenderer.h"
32 #include "../../Kernel/OVR_Log.h"
33 #include "CAPI_GL_Util.h"
35 namespace OVR { namespace CAPI { namespace GL {
37 // ***** GL::DistortionRenderer
39 // Implementation of DistortionRenderer for GL.
41 class DistortionRenderer : public CAPI::DistortionRenderer
42 {
43 public:
44 DistortionRenderer(ovrHmd hmd,
45 FrameTimeManager& timeManager,
46 const HMDRenderState& renderState);
47 virtual ~DistortionRenderer();
50 // Creation function for the device.
51 static CAPI::DistortionRenderer* Create(ovrHmd hmd,
52 FrameTimeManager& timeManager,
53 const HMDRenderState& renderState);
56 // ***** Public DistortionRenderer interface
58 virtual bool Initialize(const ovrRenderAPIConfig* apiConfig) OVR_OVERRIDE;
60 virtual void SubmitEye(int eyeId, const ovrTexture* eyeTexture);
62 virtual void EndFrame(bool swapBuffers);
64 void WaitUntilGpuIdle();
66 // Similar to ovr_WaitTillTime but it also flushes GPU.
67 // Note, it exits when time expires, even if GPU is not in idle state yet.
68 double FlushGpuAndWaitTillTime(double absTime);
70 protected:
72 struct FOR_EACH_EYE
73 {
74 FOR_EACH_EYE() : numVerts(0), numIndices(0), texture(0), /*UVScaleOffset[],*/ TextureSize(0, 0), RenderViewport(0, 0, 0, 0) { }
76 int numVerts;
77 int numIndices;
79 GLuint texture;
81 ovrVector2f UVScaleOffset[2];
82 Sizei TextureSize;
83 Recti RenderViewport;
84 } eachEye[2];
86 Ptr<Texture> pOverdriveTextures[NumOverdriveTextures];
87 Ptr<Texture> OverdriveBackBufferTexture;
89 // GL context and utility variables.
90 RenderParams RParams;
91 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.
93 // Helpers
94 void initOverdrive();
95 void initBuffersAndShaders();
96 void initShaders();
97 void initFullscreenQuad();
98 void destroy();
100 void setViewport(const Recti& vp);
102 void renderDistortion(Texture* leftEyeTexture, Texture* rightEyeTexture);
104 void renderPrimitives(const ShaderFill* fill, Buffer* vertices, Buffer* indices,
105 int offset, int count,
106 PrimitiveType rprim, GLuint* vao, bool isDistortionMesh);
108 void createDrawQuad();
109 void renderLatencyQuad(unsigned char* latencyTesterDrawColor);
110 void renderLatencyPixel(unsigned char* latencyTesterPixelColor);
112 void renderEndFrame();
114 Ptr<Texture> pEyeTextures[2];
116 Ptr<Buffer> DistortionMeshVBs[2]; // one per-eye
117 Ptr<Buffer> DistortionMeshIBs[2]; // one per-eye
118 GLuint DistortionMeshVAOs[2]; // one per-eye
120 Ptr<ShaderSet> DistortionShader;
122 bool RotateCCW90;
124 struct StandardUniformData
125 {
126 Matrix4f Proj;
127 Matrix4f View;
128 } StdUniforms;
130 GLuint LatencyVAO;
131 Ptr<Buffer> LatencyTesterQuadVB;
132 Ptr<ShaderSet> SimpleQuadShader;
133 Ptr<ShaderSet> SimpleQuadGammaShader;
135 GLuint OverdriveFbo;
137 GLint SavedViewport[4];
138 GLfloat SavedClearColor[4];
139 GLint SavedDepthTest;
140 GLint SavedCullFace;
141 GLint SavedProgram;
142 GLint SavedActiveTexture;
143 GLint SavedBoundTexture;
144 GLint SavedVertexArray;
145 GLint SavedBoundFrameBuffer;
146 };
148 }}} // OVR::CAPI::GL
150 #endif // OVR_CAPI_GL_DistortionRenderer_h