VTK
vtkOculusRenderWindow.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Visualization Toolkit
4 
5 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
6 All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
41 #ifndef vtkOculusRenderWindow_h
42 #define vtkOculusRenderWindow_h
43 
44 #include "vtkRenderingOculusModule.h" // For export macro
45 #include "vtkOpenGLRenderWindow.h"
46 
47 // Include the Oculus SDK
48 #include "OVR_CAPI_GL.h"
49 #include <SDL.h> // for ivars
50 #include <vector> // ivars
51 #include "vtkOpenGLHelper.h" // used for ivars
52 #include "vtk_glew.h" // used for methods
53 
54 class vtkOculusModel;
56 class vtkTransform;
57 
58 class VTKRENDERINGOCULUS_EXPORT vtkOculusRenderWindow : public vtkOpenGLRenderWindow
59 {
60 public:
61  static vtkOculusRenderWindow *New();
63  void PrintSelf(ostream& os, vtkIndent indent);
64 
68  virtual void Start(void);
69 
74  virtual void StereoUpdate();
75 
80  virtual void StereoMidpoint();
81 
86  virtual void StereoRenderComplete();
87 
91  void Frame(void);
92 
99  virtual void Initialize(void);
100 
106  virtual void Finalize(void);
107 
111  void MakeCurrent();
112 
116  virtual bool IsCurrent();
117 
121  const char *ReportCapabilities() { return "Oculus System";};
122 
126  int IsDirect() { return 1; };
127 
133  virtual int GetEventPending() { return 0;};
134 
138  void Clean();
139 
143  virtual int *GetScreenSize();
144 
146 
149  virtual void SetSize(int,int);
150  virtual void SetSize(int a[2]) {vtkOpenGLRenderWindow::SetSize(a);};
152 
154 
157  virtual void SetPosition(int,int);
158  virtual void SetPosition(int a[2]) {vtkOpenGLRenderWindow::SetPosition(a);};
160 
161  // implement required virtual functions
162  void SetWindowInfo(char *) {};
163  void SetNextWindowInfo(char *) {};
164  void SetParentInfo(char *) {};
165  virtual void *GetGenericDisplayId() {return (void *)this->ContextId;};
166  virtual void *GetGenericWindowId() {return (void *)this->WindowId;};
167  virtual void *GetGenericParentId() {return (void *)NULL;};
168  virtual void *GetGenericContext() {return (void *)this->ContextId;};
169  virtual void *GetGenericDrawable() {return (void *)this->WindowId;};
170  virtual void SetDisplayId(void *) {};
171  void SetWindowId(void *) {};
172  void SetParentId(void *) {};
173  void HideCursor() {};
174  void ShowCursor() {};
175  virtual void SetFullScreen(int) {};
176  virtual void WindowRemap(void) {};
177  virtual void SetNextWindowId(void *) {};
178 
180 
183  ovrSession GetSession() { return this->Session; };
184  ovrLayerEyeFov GetOVRLayer() { return this->OVRLayer; };
186 
190  void UpdateHMDMatrixPose();
191 
195  virtual int SupportsOpenGL() { return 1; };
196 
198 
202  { return this->LeftEyeDesc.m_nResolveFramebufferId; };
204  { return this->RightEyeDesc.m_nResolveFramebufferId; };
206 
211  void Render();
212 
213  ovrVector3f *GetHMDToEyeViewOffsets() {
214  return this->HMDToEyeViewOffsets; }
215 
216 protected:
219 
225 
226  virtual void CreateAWindow() {};
227  virtual void DestroyWindow() {};
228 
229  SDL_Window *WindowId;
230  SDL_GLContext ContextId;
231  ovrSession Session;
232  ovrHmdDesc HMD;
233  ovrLayerEyeFov OVRLayer;
234  ovrVector3f HMDToEyeViewOffsets[2];
235 
237  {
241  ovrTextureSwapChain TextureSwapChain;
242  };
245  bool CreateFrameBuffer(FramebufferDesc &framebufferDesc );
246 
247  // used in computing the pose
249 
250 private:
251  vtkOculusRenderWindow(const vtkOculusRenderWindow&); // Not implemented.
252  void operator=(const vtkOculusRenderWindow&); // Not implemented.
253 };
254 
255 
256 #endif
vtkOculusRenderWindow::SetPosition
virtual void SetPosition(int a[2])
Definition: vtkOculusRenderWindow.h:158
vtkOculusRenderWindow::GetGenericDisplayId
virtual void * GetGenericDisplayId()
Definition: vtkOculusRenderWindow.h:165
vtkOpenGLRenderWindow::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkRenderWindow::Start
virtual void Start()=0
Initialize the rendering process.
vtkOculusRenderWindow::Session
ovrSession Session
Definition: vtkOculusRenderWindow.h:231
vtkOculusRenderWindow::SetParentInfo
void SetParentInfo(char *)
Definition: vtkOculusRenderWindow.h:164
vtkOculusRenderWindow::SetDisplayId
virtual void SetDisplayId(void *)
Dummy stubs for vtkWindow API.
Definition: vtkOculusRenderWindow.h:170
vtkRenderWindow::StereoRenderComplete
virtual void StereoRenderComplete()
Handles work required once both views have been rendered when using stereo rendering.
vtkOculusRenderWindow::ShowCursor
void ShowCursor()
Definition: vtkOculusRenderWindow.h:174
vtkOculusRenderWindow::IsDirect
int IsDirect()
Is this render window using hardware acceleration? 0-false, 1-true.
Definition: vtkOculusRenderWindow.h:126
vtkOculusRenderWindow::FramebufferDesc::TextureSwapChain
ovrTextureSwapChain TextureSwapChain
Definition: vtkOculusRenderWindow.h:241
vtkOpenGLHelper.h
vtkOculusRenderWindow::RightEyeDesc
FramebufferDesc RightEyeDesc
Definition: vtkOculusRenderWindow.h:244
vtkOculusRenderWindow::GetGenericParentId
virtual void * GetGenericParentId()
Definition: vtkOculusRenderWindow.h:167
vtkOculusRenderWindow::FramebufferDesc::m_nResolveFramebufferId
GLuint m_nResolveFramebufferId
Definition: vtkOculusRenderWindow.h:239
vtkRenderWindow::Finalize
virtual void Finalize()=0
Finalize the rendering process.
vtkWindow::GetScreenSize
virtual int * GetScreenSize()=0
Get the current size of the screen in pixels.
vtkRenderWindow::IsCurrent
virtual bool IsCurrent()=0
Tells if this window is the current graphics context for the calling thread.
vtkOculusRenderWindow::FramebufferDesc::m_nDepthBufferId
GLuint m_nDepthBufferId
Definition: vtkOculusRenderWindow.h:238
vtkOculusRenderWindow::FramebufferDesc::RecommendedTexSize
ovrSizei RecommendedTexSize
Definition: vtkOculusRenderWindow.h:240
vtkTransform
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:60
vtkOculusRenderWindow::SetFullScreen
virtual void SetFullScreen(int)
Turn on/off rendering full screen window size.
Definition: vtkOculusRenderWindow.h:175
vtkOculusRenderWindow::CreateAWindow
virtual void CreateAWindow()
Create a not-off-screen window.
Definition: vtkOculusRenderWindow.h:226
vtkOculusRenderWindow::HMDTransform
vtkTransform * HMDTransform
Definition: vtkOculusRenderWindow.h:248
vtkOculusRenderWindow::ContextId
SDL_GLContext ContextId
Definition: vtkOculusRenderWindow.h:230
vtkRenderWindow::StereoMidpoint
virtual void StereoMidpoint()
Intermediate method performs operations required between the rendering of the left and right eye.
vtkOculusRenderWindow::GetGenericContext
virtual void * GetGenericContext()
Definition: vtkOculusRenderWindow.h:168
vtkOculusRenderWindow::SupportsOpenGL
virtual int SupportsOpenGL()
Does this render window support OpenGL? 0-false, 1-true.
Definition: vtkOculusRenderWindow.h:195
vtkOculusRenderWindow::GetGenericWindowId
virtual void * GetGenericWindowId()
Definition: vtkOculusRenderWindow.h:166
vtkRenderWindow::Render
virtual void Render()
Ask each renderer owned by this RenderWindow to render its image and synchronize this process.
vtkOculusRenderWindow::SetNextWindowInfo
void SetNextWindowInfo(char *)
Definition: vtkOculusRenderWindow.h:163
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkOculusRenderWindow::GetSession
ovrSession GetSession()
Get the system pointer.
Definition: vtkOculusRenderWindow.h:183
vtkOpenGLRenderWindow::StereoUpdate
virtual void StereoUpdate()
Update system if needed due to stereo rendering.
vtkOculusRenderWindow::OVRLayer
ovrLayerEyeFov OVRLayer
Definition: vtkOculusRenderWindow.h:233
vtkOpenGLVertexBufferObject
Definition: vtkOpenGLVertexBufferObject.h:36
vtkOculusRenderWindow::SetNextWindowId
virtual void SetNextWindowId(void *)
Definition: vtkOculusRenderWindow.h:177
vtkOculusRenderWindow::SetWindowId
void SetWindowId(void *)
Definition: vtkOculusRenderWindow.h:171
vtkOculusRenderWindow::SetSize
virtual void SetSize(int a[2])
Set the size of the window in screen coordinates in pixels.
Definition: vtkOculusRenderWindow.h:150
vtkOculusRenderWindow::HideCursor
void HideCursor()
Hide or Show the mouse cursor, it is nice to be able to hide the default cursor if you want VTK to di...
Definition: vtkOculusRenderWindow.h:173
vtkOculusRenderWindow::GetEventPending
virtual int GetEventPending()
Check to see if a mouse button has been pressed or mouse wheel activated.
Definition: vtkOculusRenderWindow.h:133
vtkOculusRenderWindow::GetGenericDrawable
virtual void * GetGenericDrawable()
Definition: vtkOculusRenderWindow.h:169
vtkOculusRenderWindow::WindowRemap
virtual void WindowRemap(void)
Remap the rendering window.
Definition: vtkOculusRenderWindow.h:176
vtkOculusRenderWindow::SetWindowInfo
void SetWindowInfo(char *)
Definition: vtkOculusRenderWindow.h:162
vtkOculusRenderWindow::SetParentId
void SetParentId(void *)
Definition: vtkOculusRenderWindow.h:172
vtkRenderWindow::MakeCurrent
virtual void MakeCurrent()=0
Attempt to make this window the current graphics context for the calling thread.
vtkOculusRenderWindow::ReportCapabilities
const char * ReportCapabilities()
Get report of capabilities for the render window.
Definition: vtkOculusRenderWindow.h:121
vtkOpenGLRenderWindow::ReleaseGraphicsResources
virtual void ReleaseGraphicsResources(vtkRenderWindow *)
Free up any graphics resources associated with this window a value of NULL means the context may alre...
vtkOpenGLRenderWindow::DestroyWindow
virtual void DestroyWindow()=0
Destroy a not-off-screen window.
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:41
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:86
vtkWindow::SetPosition
virtual void SetPosition(int, int)
vtkOculusRenderWindow::LeftEyeDesc
FramebufferDesc LeftEyeDesc
Definition: vtkOculusRenderWindow.h:243
vtkRenderWindow::Frame
virtual void Frame()=0
A termination method performed at the end of the rendering process to do things like swapping buffers...
vtkOculusRenderWindow::GetLeftResolveBufferId
GLuint GetLeftResolveBufferId()
Get the frame buffers used for rendering.
Definition: vtkOculusRenderWindow.h:201
vtkOculusRenderWindow::GetRightResolveBufferId
GLuint GetRightResolveBufferId()
Definition: vtkOculusRenderWindow.h:203
vtkRenderWindow::New
static vtkRenderWindow * New()
Construct an instance of vtkRenderWindow with its screen size set to 300x300, borders turned on,...
vtkOculusRenderWindow::GetOVRLayer
ovrLayerEyeFov GetOVRLayer()
Definition: vtkOculusRenderWindow.h:184
vtkOculusRenderWindow::GetHMDToEyeViewOffsets
ovrVector3f * GetHMDToEyeViewOffsets()
Definition: vtkOculusRenderWindow.h:213
vtkOpenGLRenderWindow::Initialize
virtual void Initialize(void)
Initialize the rendering window.
Definition: vtkOpenGLRenderWindow.h:344
vtkOculusRenderWindow::HMD
ovrHmdDesc HMD
Definition: vtkOculusRenderWindow.h:232
vtkOpenGLRenderWindow::SetSize
virtual void SetSize(int a[2])
Set the size of the window in screen coordinates in pixels.
vtkOculusRenderWindow::FramebufferDesc
Definition: vtkOculusRenderWindow.h:236
vtkOculusRenderWindow
Oculus rendering window.
Definition: vtkOculusRenderWindow.h:58