ovr_sdk

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