VTK  9.7.1
vtkVRRenderWindow.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
39 #ifndef vtkVRRenderWindow_h
40 #define vtkVRRenderWindow_h
41 
42 #include "vtkEventData.h" // for enums
43 #include "vtkNew.h" // for vtkNew
44 #include "vtkOpenGLRenderWindow.h"
45 #include "vtkRenderingVRModule.h" // For export macro
46 #include "vtkSmartPointer.h" // for vtkSmartPointer
47 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
48 #include "vtk_glad.h" // used for methods
49 
50 #include <vector> // ivars
51 
52 VTK_ABI_NAMESPACE_BEGIN
53 class vtkCamera;
54 class vtkMatrix4x4;
55 class vtkVRModel;
56 
57 class VTKRENDERINGVR_EXPORT VTK_MARSHALAUTO vtkVRRenderWindow : public vtkOpenGLRenderWindow
58 {
59 public:
60  enum
61  {
62  LeftEye = 0,
63  RightEye
64  };
65 
67  void PrintSelf(ostream& os, vtkIndent indent) override;
68 
74 
76 
79  GLuint GetLeftResolveBufferId() { return this->FramebufferDescs[LeftEye].ResolveFramebufferId; }
80  GLuint GetRightResolveBufferId() { return this->FramebufferDescs[RightEye].ResolveFramebufferId; }
81  void GetRenderBufferSize(int& width, int& height)
82  {
83  width = this->Size[0];
84  height = this->Size[1];
85  }
87 
89 
92  vtkVRModel* GetModelForDevice(vtkEventDataDevice idx);
93  vtkVRModel* GetModelForDeviceHandle(uint32_t handle);
95 
97 
100  void SetModelForDeviceHandle(uint32_t handle, vtkVRModel* model);
102 
104 
109  vtkMatrix4x4* GetDeviceToPhysicalMatrixForDevice(vtkEventDataDevice idx);
110  vtkMatrix4x4* GetDeviceToPhysicalMatrixForDeviceHandle(uint32_t handle);
112 
114  /*
115  * This method gets a device handle for a given device. index is used to
116  * disambiguate when there are multiple device handles that map to a
117  * device.
118  */
119  uint32_t GetDeviceHandleForDevice(vtkEventDataDevice dev, uint32_t index = 0);
121 
123  /*
124  * This method returns how many device handles map to a device.
125  */
126  uint32_t GetNumberOfDeviceHandlesForDevice(vtkEventDataDevice dev);
128 
130  /*
131  * This method adds a device handle if not already present. The second
132  * signature also sets the device associated with the device handle.
133  */
134  void AddDeviceHandle(uint32_t handle);
135  void AddDeviceHandle(uint32_t handle, vtkEventDataDevice device);
137 
139  /*
140  * This method gets a device for a given device handle.
141  */
142  vtkEventDataDevice GetDeviceForDeviceHandle(uint32_t handle);
144 
152  vtkEventDataDevice device, vtkMatrix4x4* deviceToWorldMatrix) override;
153  virtual bool GetDeviceToWorldMatrixForDeviceHandle(
154  uint32_t handle, vtkMatrix4x4* deviceToWorldMatrix);
155 
163  virtual void InitializeViewFromCamera(vtkCamera* cam);
164 
168  void AddRenderer(vtkRenderer*) override;
169 
173  void MakeCurrent() override;
174 
178  void ReleaseCurrent() override;
179 
183  bool IsCurrent() override;
184 
188  const char* ReportCapabilities() override { return "VR System"; }
189 
193  vtkTypeBool IsDirect() override { return 1; }
194 
200  vtkTypeBool GetEventPending() override { return 0; }
201 
205  int* GetScreenSize() override;
206 
208 
215  void SetSize(int width, int height) override;
216  void SetSize(int a[2]) override { this->SetSize(a[0], a[1]); }
218 
220 
223  void* GetGenericDisplayId() override { return this->HelperWindow->GetGenericDisplayId(); }
224  void* GetGenericWindowId() override { return this->HelperWindow->GetGenericWindowId(); }
225  void* GetGenericParentId() override { return nullptr; }
226  void* GetGenericContext() override { return this->HelperWindow->GetGenericContext(); }
227  void* GetGenericDrawable() override { return this->HelperWindow->GetGenericDrawable(); }
229 
233  int SupportsOpenGL() override { return 1; }
234 
239  void Render() override;
240 
242 
245  vtkGetObjectMacro(HelperWindow, vtkOpenGLRenderWindow);
246  void SetHelperWindow(vtkOpenGLRenderWindow* val);
248 
252  vtkOpenGLState* GetState() override;
253 
258  void ReleaseGraphicsResources(vtkWindow*) override;
259 
263  virtual void RenderModels() = 0;
264 
266 
269  vtkGetMacro(BaseStationVisibility, bool);
270  vtkSetMacro(BaseStationVisibility, bool);
271  vtkBooleanMacro(BaseStationVisibility, bool);
273 
277  virtual void UpdateHMDMatrixPose() {};
278 
283  vtkGetMacro(VRInitialized, bool);
284 
285 protected:
287  ~vtkVRRenderWindow() override;
288 
290  {
291  GLuint ResolveFramebufferId = 0;
292  GLuint ResolveColorTextureId = 0;
293  GLuint ResolveDepthTextureId = 0;
294  };
295 
296  void CreateAWindow() override {}
297  void DestroyWindow() override {}
298 
304  virtual bool GetSizeFromAPI() = 0;
305 
306  virtual std::string GetWindowTitleFromAPI() { return "VTK - VR"; }
307 
308  virtual bool CreateFramebuffers(uint32_t viewCount = 2) = 0;
309  virtual void RenderFramebuffer(FramebufferDesc& framebufferDesc) = 0;
310 
311  bool VRInitialized = false;
312 
313  // One per view (typically one per eye)
314  std::vector<FramebufferDesc> FramebufferDescs;
315 
317  {
318  public:
322  uint32_t Index = 0;
323  };
324 
325  std::map<uint32_t, DeviceData> DeviceHandleToDeviceDataMap;
326  uint32_t InvalidDeviceIndex = UINT32_MAX;
327 
328  bool BaseStationVisibility = false;
329 
331 
332 private:
333  vtkVRRenderWindow(const vtkVRRenderWindow&) = delete;
334  void operator=(const vtkVRRenderWindow&) = delete;
335 };
336 
337 VTK_ABI_NAMESPACE_END
338 #endif
OpenGL rendering window.
void * GetGenericParentId() override
Implement required virtual functions.
void GetRenderBufferSize(int &width, int &height)
Get the frame buffers used for rendering.
virtual bool GetDeviceToWorldMatrixForDevice(vtkEventDataDevice device, vtkMatrix4x4 *deviceToWorldMatrix)
Store in deviceToWorldMatrix the matrix that goes from device coordinates to world coordinates...
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:31
void Render() override
Handle opengl specific code and calls superclass.
const char * ReportCapabilities() override
Get report of capabilities for the render window.
VR rendering window.
void DestroyWindow() override
Destroy a not-off-screen window.
abstract specification for renderers
Definition: vtkRenderer.h:63
virtual void AddRenderer(vtkRenderer *)
Add a renderer to the list of renderers.
virtual vtkRenderWindowInteractor * MakeRenderWindowInteractor()
Create an interactor to control renderers in this window.
virtual bool IsCurrent()
Tells if this window is the current graphics context for the calling thread.
int SupportsOpenGL() override
Does this render window support OpenGL? 0-false, 1-true.
GLuint GetRightResolveBufferId()
Get the frame buffers used for rendering.
void * GetGenericDisplayId() override
Implement required virtual functions.
int vtkTypeBool
Definition: vtkABI.h:64
VR device model.
Definition: vtkVRModel.h:29
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
void * GetGenericContext() override
Implement required virtual functions.
platform-independent render window interaction including picking and frame rate control.
vtkNew< vtkMatrix4x4 > DeviceToPhysicalMatrix
virtual void SetSize(int width, int height)
Set the size (width and height) of the rendering window in screen coordinates (in pixels)...
OpenGL state storage.
virtual std::string GetWindowTitleFromAPI()
void * GetGenericWindowId() override
Implement required virtual functions.
a simple class to control print indentation
Definition: vtkIndent.h:28
a virtual camera for 3D rendering
Definition: vtkCamera.h:41
virtual int * GetScreenSize()
Get the current size of the screen in pixels.
Definition: vtkWindow.h:110
void * GetGenericDrawable() override
Implement required virtual functions.
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:14
virtual void MakeCurrent()
Make the window current.
Definition: vtkWindow.h:255
std::vector< FramebufferDesc > FramebufferDescs
GLuint GetLeftResolveBufferId()
Get the frame buffers used for rendering.
virtual void ReleaseCurrent()
Release the current context.
Definition: vtkWindow.h:261
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTypeBool IsDirect() override
Is this render window using hardware acceleration? 0-false, 1-true.
void CreateAWindow() override
Create a not-off-screen window.
vtkOpenGLFramebufferObject * RenderFramebuffer
vtkSmartPointer< vtkVRModel > Model
std::map< uint32_t, DeviceData > DeviceHandleToDeviceDataMap
#define VTK_MARSHALAUTO
virtual vtkOpenGLState * GetState()
void SetSize(int a[2]) override
Set the size of the window in screen coordinates in pixels.
virtual void UpdateHMDMatrixPose()
Update the HMD pose.
int CreateFramebuffers(int width, int height)
Create the offScreen framebuffers or resize them if they are already created.
void ReleaseGraphicsResources(vtkWindow *) override
Free up any graphics resources associated with this window a value of NULL means the context may alre...
vtkTypeBool GetEventPending() override
Check to see if a mouse button has been pressed or mouse wheel activated.
vtkOpenGLRenderWindow * HelperWindow