liballofw
omnistereo.h
Go to the documentation of this file.
1 #ifndef ALLOFW_OMNISTEREO_H
2 #define ALLOFW_OMNISTEREO_H
3 
4 // Omnistereo Rendering.
5 #include "common.h"
6 #include "config.h"
7 #include "math/math.h"
8 #include "opengl.h"
9 
10 namespace allofw {
11 
13  typedef GLuint GLTextureID;
14 
16  class OmniStereo {
17  public:
19  typedef int StereoMode;
21  static const int kStereoMode_Mono = 0;
22  static const int kStereoMode_Left = 100;
23  static const int kStereoMode_Right = 101;
24  static const int kStereoMode_Active = 200;
25  static const int kStereoMode_Dual_LR = 300;
26  static const int kStereoMode_Dual_RL = 301;
27  static const int kStereoMode_Anaglyph_Red_Cyan = 400;
28 
29 
31  typedef int PanoramaMode;
33  static const int kPanoramaModeEquirectangular = 0;
34 
35 
37  typedef int Eye;
39  static const int kEye = 0;
40  static const int kEye_Left = 0;
41  static const int kEye_Right = 1;
42 
43 
45  typedef int CompositeMask;
47  static const int kCompositeMask_Scene = 1 << 0;
48  static const int kCompositeMask_Back = 1 << 1;
49  static const int kCompositeMask_Front = 1 << 2;
50  static const int kCompositeMask_Panorama = 1 << 3;
51  static const int kCompositeMask_Panorama_Equirectangular = 1 << 4;
52  static const int kCompositeMask_Panorama_Cubemap = 1 << 5;
53  static const int kCompositeMask_Panorama_Cubemap_YUV420P = 1 << 6;
54 
55 
56  // Stereo texture.
57  struct StereoTexture {
58  // In mono mode, we only use L.
59  union {
60  struct {
61  GLTextureID L;
62  GLTextureID R;
63  };
64  GLTextureID eyes[2];
65  };
66  StereoTexture() : L(0), R(0) { }
67  };
68 
70  class Delegate {
71  public:
73  struct CaptureInfo {
77  Eye eye;
82 
90  float near;
92  float far;
93 
96 
99  void setUniforms(GLuint program) const {
100  omnistereo->setUniforms(program, *this);
101  }
102  };
103 
105  virtual void onCaptureViewport(const CaptureInfo& info);
106 
107  virtual ~Delegate() { }
108  };
109 
112  virtual void setResolution(int size = 1024) = 0;
113 
116  virtual void setStereoMode(StereoMode stereo_mode) = 0;
117 
120  virtual void setPose(const Pose& pose) = 0;
124  virtual void setLens(float eye_separation = 0.0f, float sphere_radius = 1.0f) = 0;
128  virtual void setClipRange(float near, float far) = 0;
129 
132  virtual StereoTexture getCubemapTexture() = 0;
133 
137 
139  virtual void capture() = 0;
140 
142  struct CompositeInfo {
143  CompositeMask mask;
145  union {
147  StereoTexture panorama_planes[3];
148  };
149  CompositeInfo() : mask(kCompositeMask_Scene) { }
150  };
151 
155  virtual void composite(const Rectangle2i& viewport, const CompositeInfo& info = CompositeInfo()) = 0;
156 
160  virtual GLuint compositeCustomizeShader(const char* code) = 0;
161 
163  virtual void compositeRestoreShader() = 0;
164 
180  virtual const char* getShaderCode() = 0;
181 
185  virtual void setUniforms(GLuint program, const Delegate::CaptureInfo& info) = 0;
186 
189  virtual void setDelegate(Delegate* delegate) = 0;
190 
193  static OmniStereo* Create(Configuration* conf);
196  static void Destroy(OmniStereo* omnistereo);
197 
198  protected:
199  virtual ~OmniStereo();
200  };
201 
203  class WarpBlend {
204  public:
205 
207  struct WarpData {
212  };
213 
215  struct BlendData {
220  };
221 
223  struct ViewportInfo {
232  };
233 
235  virtual int getViewportCount() = 0;
236 
239  virtual ViewportInfo getViewport(int viewport_index) = 0;
240 
243  virtual BlendData getBlendData(int viewport_index) = 0;
244 
247  virtual WarpData getWarpData(int viewport_index) = 0;
248 
251  virtual GLTextureID getBlendTexture(int viewport_index) = 0;
252 
255  virtual GLTextureID getWarpTexture(int viewport_index) = 0;
256 
260  static WarpBlend* CreateEquirectangular(int width, int height);
261 
266  static WarpBlend* CreatePerspective(int width, int height, float fov);
267 
271  static WarpBlend* LoadAllosphereCalibration(const char* calibration_path, const char* hostname = nullptr);
272 
275  static void Destroy(WarpBlend* warpblend);
276 
277  protected:
278  virtual ~WarpBlend();
279  };
280 }
281 
282 #endif
static const int kCompositeMask_Back
Show the scene.
Definition: omnistereo.h:48
virtual void setDelegate(Delegate *delegate)=0
StereoTexture front
Definition: omnistereo.h:144
Quaternion viewport_rotation
Viewport pose.
Definition: omnistereo.h:84
static OmniStereo * Create(Configuration *conf)
Vector3f * data
3D positions for each pixel relative to the viewing center.
Definition: omnistereo.h:209
static const int kPanoramaModeEquirectangular
Definition: omnistereo.h:33
static const int kStereoMode_Dual_RL
Dual, left-right.
Definition: omnistereo.h:26
static const int kEye_Left
Single eye.
Definition: omnistereo.h:40
Size2i size
Width and height of the blend map.
Definition: omnistereo.h:219
float viewport_aspect
Viewport aspect ratio.
Definition: omnistereo.h:88
static const int kCompositeMask_Front
Show the back buffer.
Definition: omnistereo.h:49
CompositeMask mask
Definition: omnistereo.h:143
Capture info.
Definition: omnistereo.h:73
Pose pose
Current pose.
Definition: omnistereo.h:75
static const int kCompositeMask_Panorama_Cubemap_YUV420P
Panorama is cubemap.
Definition: omnistereo.h:53
CompositeInfo()
Definition: omnistereo.h:149
Panorama is cubemap.
Definition: omnistereo.h:57
static const int kEye_Right
Left eye.
Definition: omnistereo.h:41
Class for Omnistereo rendering.
Definition: omnistereo.h:16
static const int kStereoMode_Active
Only show right eye.
Definition: omnistereo.h:24
float sphere_radius
Sphere radius.
Definition: omnistereo.h:81
static void Destroy(OmniStereo *omnistereo)
float eye_separation
Eye separation.
Definition: omnistereo.h:79
Definition: allofw.h:12
virtual void setUniforms(GLuint program, const Delegate::CaptureInfo &info)=0
static const int kEye
Definition: omnistereo.h:39
virtual void setClipRange(float near, float far)=0
OmniStereo delegate class.
Definition: omnistereo.h:70
void setUniforms(GLuint program) const
Definition: omnistereo.h:99
static const int kCompositeMask_Panorama_Equirectangular
Show the panorama.
Definition: omnistereo.h:51
int PanoramaMode
Anaglyph, red/cyan.
Definition: omnistereo.h:32
Rectangle2 viewport
The viewport coordinates in screen pixels.
Definition: omnistereo.h:225
virtual void setPose(const Pose &pose)=0
virtual void capture()=0
Capture the scene.
virtual void setResolution(int size=1024)=0
int Eye
Equirectangular panorama mode.
Definition: omnistereo.h:38
bool enforce_aspect_ratio
Should OmniStereo maintain the viewport aspect ratio.
Definition: omnistereo.h:229
virtual StereoTexture getDepthCubemapTexture()=0
Vector4f * data
Alpha map in RGBA.
Definition: omnistereo.h:217
virtual StereoTexture getCubemapTexture()=0
YAML-based configuration reader.
Definition: config.h:12
Eye eye
Which eye.
Definition: omnistereo.h:77
virtual const char * getShaderCode()=0
Definition: geometry.h:16
static const int kCompositeMask_Panorama
Show the front buffer.
Definition: omnistereo.h:50
float near
Near clipping distance.
Definition: omnistereo.h:90
StereoTexture()
Definition: omnistereo.h:66
virtual void composite(const Rectangle2i &viewport, const CompositeInfo &info=CompositeInfo())=0
virtual void setStereoMode(StereoMode stereo_mode)=0
GLTextureID L
Definition: omnistereo.h:61
float far
Far clipping distance.
Definition: omnistereo.h:92
virtual void setLens(float eye_separation=0.0f, float sphere_radius=1.0f)=0
Viewport information.
Definition: omnistereo.h:223
Warp and blend information for a display configuration.
Definition: omnistereo.h:203
static const int kStereoMode_Mono
Definition: omnistereo.h:21
int CompositeMask
Right eye.
Definition: omnistereo.h:46
float viewport_fovy
Viewport fovy.
Definition: omnistereo.h:86
Warp map data.
Definition: omnistereo.h:207
Composite info structure.
Definition: omnistereo.h:142
static const int kCompositeMask_Scene
Definition: omnistereo.h:47
float aspect_ratio
Target aspect ratio of the viewport.
Definition: omnistereo.h:231
Definition: quaternion.h:9
Definition: vector.h:63
int StereoMode
Stereo mode.
Definition: omnistereo.h:20
Size2i screen_resolution
Target screen resolution (OmniStereo will determine the size of internal framebuffers based on this v...
Definition: omnistereo.h:227
Definition: vector.h:114
Size2i size
Width and height of the warp map.
Definition: omnistereo.h:211
static const int kCompositeMask_Panorama_Cubemap
Panorama is equirectangular.
Definition: omnistereo.h:52
virtual GLuint compositeCustomizeShader(const char *code)=0
static const int kStereoMode_Right
Only show left eye.
Definition: omnistereo.h:23
virtual ~OmniStereo()
OmniStereo * omnistereo
The OmniStereo object.
Definition: omnistereo.h:95
StereoTexture panorama
Definition: omnistereo.h:146
GLTextureID eyes[2]
Definition: omnistereo.h:64
Definition: pose.h:9
GLuint GLTextureID
OpenGL texture ID.
Definition: omnistereo.h:13
virtual void compositeRestoreShader()=0
Restore the composite shader to default.
GLTextureID R
Left eye texture.
Definition: omnistereo.h:62
Blend map data.
Definition: omnistereo.h:215
virtual ~Delegate()
Definition: omnistereo.h:107
static const int kStereoMode_Left
Mono.
Definition: omnistereo.h:22
static const int kStereoMode_Anaglyph_Red_Cyan
Dual, right-left.
Definition: omnistereo.h:27
static const int kStereoMode_Dual_LR
Active stereo.
Definition: omnistereo.h:25