Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CAPI_GL_DistortionRenderer.h
Go to the documentation of this file.
1 /************************************************************************************
2 
3 Filename : CAPI_GL_DistortionRenderer.h
4 Content : Distortion renderer header for GL
5 Created : November 11, 2013
6 Authors : David Borel, Lee Cooper
7 
8 Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved.
9 
10 Use of this software is subject to the terms of the Oculus Inc license
11 agreement provided at the time of installation or download, or which
12 otherwise accompanies this software in either electronic or hard copy form.
13 
14 ************************************************************************************/
15 
16 #ifndef OVR_CAPI_GL_DistortionRenderer_h
17 #define OVR_CAPI_GL_DistortionRenderer_h
18 
19 #include "../CAPI_DistortionRenderer.h"
20 
21 #include "../../Kernel/OVR_Log.h"
22 #include "CAPI_GL_Util.h"
23 
24 namespace OVR { namespace CAPI { namespace GL {
25 
26 // ***** GL::DistortionRenderer
27 
28 // Implementation of DistortionRenderer for GL.
29 
31 {
32 public:
34  FrameTimeManager& timeManager,
35  const HMDRenderState& renderState);
37 
38 
39  // Creation function for the device.
41  FrameTimeManager& timeManager,
42  const HMDRenderState& renderState);
43 
44 
45  // ***** Public DistortionRenderer interface
46 
47  virtual bool Initialize(const ovrRenderAPIConfig* apiConfig,
48  unsigned distortionCaps);
49 
50  virtual void SubmitEye(int eyeId, ovrTexture* eyeTexture);
51 
52  virtual void EndFrame(bool swapBuffers, unsigned char* latencyTesterDrawColor, unsigned char* latencyTester2DrawColor);
53 
54  void WaitUntilGpuIdle();
55 
56  // Similar to ovr_WaitTillTime but it also flushes GPU.
57  // Note, it exits when time expires, even if GPU is not in idle state yet.
58  double FlushGpuAndWaitTillTime(double absTime);
59 
60 protected:
61 
62 
64  {
65  public:
66  GraphicsState();
67  virtual void Save();
68  virtual void Restore();
69 
70  protected:
71  void ApplyBool(GLenum Name, GLint Value);
72 
73  public:
77 
78  GLint Viewport[4];
79  GLfloat ClearColor[4];
80  GLint DepthTest;
81  GLint CullFace;
82  GLint Program;
85  GLint VertexArray;
87 
88  GLint Blend;
89  GLint ColorWritemask[4];
90  GLint Dither;
91  GLint Fog;
92  GLint Lighting;
94  GLint RenderMode;
95  GLint SampleMask;
96  GLint ScissorTest;
97  GLfloat ZoomX;
98  GLfloat ZoomY;
99  };
100 
101  // TBD: Should we be using oe from RState instead?
102  unsigned DistortionCaps;
103 
105  {
107 
108 #if 0
109  IDirect3DVertexBuffer9 * dxVerts;
110  IDirect3DIndexBuffer9 * dxIndices;
111 #endif
112  int numVerts;
114 
115  GLuint texture;
116 
120  } eachEye[2];
121 
122  // GL context and utility variables.
124 
125  // Helpers
126  void initBuffersAndShaders();
127  void initShaders();
128  void initFullscreenQuad();
129  void destroy();
130 
131  void setViewport(const Recti& vp);
132 
133  void renderDistortion(Texture* leftEyeTexture, Texture* rightEyeTexture);
134 
135  void renderPrimitives(const ShaderFill* fill, Buffer* vertices, Buffer* indices,
136  int offset, int count,
137  PrimitiveType rprim, GLuint* vao, bool isDistortionMesh);
138 
139  void createDrawQuad();
140  void renderLatencyQuad(unsigned char* latencyTesterDrawColor);
141  void renderLatencyPixel(unsigned char* latencyTesterPixelColor);
142 
144 
145  Ptr<Buffer> DistortionMeshVBs[2]; // one per-eye
146  Ptr<Buffer> DistortionMeshIBs[2]; // one per-eye
147  GLuint DistortionMeshVAOs[2]; // one per-eye
148 
150 
152  {
155  } StdUniforms;
156 
157  GLuint LatencyVAO;
160 
163  GLuint CurrentFbo;
164 
165  GLint SavedViewport[4];
166  GLfloat SavedClearColor[4];
174 };
175 
176 }}} // OVR::CAPI::GL
177 
178 #endif // OVR_CAPI_GL_DistortionRenderer_h
virtual void SubmitEye(int eyeId, ovrTexture *eyeTexture)
struct OVR::CAPI::GL::DistortionRenderer::StandardUniformData StdUniforms
void renderDistortion(Texture *leftEyeTexture, Texture *rightEyeTexture)
static CAPI::DistortionRenderer * Create(ovrHmd hmd, FrameTimeManager &timeManager, const HMDRenderState &renderState)
void renderLatencyQuad(unsigned char *latencyTesterDrawColor)
void renderLatencyPixel(unsigned char *latencyTesterPixelColor)
virtual void EndFrame(bool swapBuffers, unsigned char *latencyTesterDrawColor, unsigned char *latencyTester2DrawColor)
DistortionRenderer(ovrHmd hmd, FrameTimeManager &timeManager, const HMDRenderState &renderState)
virtual bool Initialize(const ovrRenderAPIConfig *apiConfig, unsigned distortionCaps)
void renderPrimitives(const ShaderFill *fill, Buffer *vertices, Buffer *indices, int offset, int count, PrimitiveType rprim, GLuint *vao, bool isDistortionMesh)
struct OVR::CAPI::GL::DistortionRenderer::FOR_EACH_EYE eachEye[2]