VTK  9.3.20240424
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 "vtkDeprecation.h" // for deprecation
43#include "vtkEventData.h" // for enums
44#include "vtkNew.h" // for vtkNew
46#include "vtkRenderingVRModule.h" // For export macro
47#include "vtkSmartPointer.h" // for vtkSmartPointer
48#include "vtk_glew.h" // used for methods
49
50#include <vector> // ivars
51
52VTK_ABI_NAMESPACE_BEGIN
53class vtkCamera;
54class vtkMatrix4x4;
55class vtkVRModel;
56
57class VTKRENDERINGVR_EXPORT vtkVRRenderWindow : public vtkOpenGLRenderWindow
58{
59public:
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
95
97
100 void SetModelForDeviceHandle(uint32_t handle, vtkVRModel* model);
102
104
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 */
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 */
144
152 vtkEventDataDevice device, vtkMatrix4x4* deviceToWorldMatrix) override;
154 uint32_t handle, vtkMatrix4x4* deviceToWorldMatrix);
155
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);
248
253
259
263 virtual void RenderModels() = 0;
264
266
270 VTK_DEPRECATED_IN_9_4_0("Please use vtkVRCamera::SetTrackHMD() instead.")
271 vtkSetMacro(TrackHMD, bool);
272 VTK_DEPRECATED_IN_9_4_0("Please use vtkVRCamera::GetTrackHMD() instead.")
273 vtkGetMacro(TrackHMD, bool);
275
277
280 vtkGetMacro(BaseStationVisibility, bool);
281 vtkSetMacro(BaseStationVisibility, bool);
282 vtkBooleanMacro(BaseStationVisibility, bool);
284
288 virtual void UpdateHMDMatrixPose(){};
289
294 vtkGetMacro(VRInitialized, bool);
295
296protected:
299
301 {
302 GLuint ResolveFramebufferId = 0;
303 GLuint ResolveColorTextureId = 0;
304 GLuint ResolveDepthTextureId = 0;
305 };
306
307 void CreateAWindow() override {}
308 void DestroyWindow() override {}
309
315 virtual bool GetSizeFromAPI() = 0;
316
317 virtual std::string GetWindowTitleFromAPI() { return "VTK - VR"; }
318
319 virtual bool CreateFramebuffers(uint32_t viewCount = 2) = 0;
320 virtual void RenderFramebuffer(FramebufferDesc& framebufferDesc) = 0;
321
322 bool VRInitialized = false;
323
324 VTK_DEPRECATED_IN_9_4_0("Please use vtkVRCamera::TrackHMD instead.")
325 bool TrackHMD = true;
326
327 // One per view (typically one per eye)
328 std::vector<FramebufferDesc> FramebufferDescs;
329
331 {
332 public:
336 uint32_t Index = 0;
337 };
338
339 std::map<uint32_t, DeviceData> DeviceHandleToDeviceDataMap;
340 uint32_t InvalidDeviceIndex = UINT32_MAX;
341
342 bool BaseStationVisibility = false;
343
345
346private:
347 vtkVRRenderWindow(const vtkVRRenderWindow&) = delete;
348 void operator=(const vtkVRRenderWindow&) = delete;
349};
350
351VTK_ABI_NAMESPACE_END
352#endif
a virtual camera for 3D rendering
Definition vtkCamera.h:151
a simple class to control print indentation
Definition vtkIndent.h:108
represent and manipulate 4x4 transformation matrices
Allocate and hold a VTK object.
Definition vtkNew.h:160
OpenGL rendering window.
OpenGL state storage.
platform-independent render window interaction including picking and frame rate control.
abstract specification for renderers
Hold a reference to a vtkObjectBase instance.
VR camera.
Definition vtkVRCamera.h:23
VR device model.
Definition vtkVRModel.h:29
vtkNew< vtkMatrix4x4 > DeviceToPhysicalMatrix
vtkSmartPointer< vtkVRModel > Model
VR rendering window.
void Render() override
Overridden to not release resources that would interfere with an external application's rendering.
vtkVRModel * GetModelForDeviceHandle(uint32_t handle)
Get the VRModel corresponding to the device or device handle.
void AddDeviceHandle(uint32_t handle)
void CreateAWindow() override
Create a not-off-screen window.
void MakeCurrent() override
Make this windows OpenGL context the current context.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void ReleaseGraphicsResources(vtkWindow *) override
Free up any graphics resources associated with this window a value of nullptr means the context may a...
std::map< uint32_t, DeviceData > DeviceHandleToDeviceDataMap
const char * ReportCapabilities() override
Get report of capabilities for the render window.
virtual void RenderModels()=0
Render the controller and base station models.
void * GetGenericParentId() override
Implement required virtual functions.
vtkOpenGLRenderWindow * HelperWindow
void * GetGenericWindowId() override
Implement required virtual functions.
virtual bool GetDeviceToWorldMatrixForDeviceHandle(uint32_t handle, vtkMatrix4x4 *deviceToWorldMatrix)
uint32_t GetNumberOfDeviceHandlesForDevice(vtkEventDataDevice dev)
vtkVRModel * GetModelForDevice(vtkEventDataDevice idx)
Get the VRModel corresponding to the device or device handle.
~vtkVRRenderWindow() override
virtual bool GetSizeFromAPI()=0
Attempt to get the size of the display from the API and store it in this->Size.
int SupportsOpenGL() override
Does this render window support OpenGL? 0-false, 1-true.
vtkMatrix4x4 * GetDeviceToPhysicalMatrixForDeviceHandle(uint32_t handle)
Get the DeviceToPhysical matrix corresponding to the device or device handle.
void AddRenderer(vtkRenderer *) override
Add a renderer to the list of renderers.
GLuint GetLeftResolveBufferId()
Get the frame buffers used for rendering.
uint32_t GetDeviceHandleForDevice(vtkEventDataDevice dev, uint32_t index=0)
void SetSize(int width, int height) override
Set the size of the window in screen coordinates in pixels.
void * GetGenericDrawable() override
Implement required virtual functions.
virtual void RenderFramebuffer(FramebufferDesc &framebufferDesc)=0
vtkEventDataDevice GetDeviceForDeviceHandle(uint32_t handle)
void DestroyWindow() override
Destroy a not-off-screen window.
vtkOpenGLState * GetState() override
Get the state object used to keep track of OpenGL state.
void AddDeviceHandle(uint32_t handle, vtkEventDataDevice device)
void GetRenderBufferSize(int &width, int &height)
Get the frame buffers used for rendering.
bool IsCurrent() override
Tells if this window is the current OpenGL context for the calling thread.
GLuint GetRightResolveBufferId()
Get the frame buffers used for rendering.
bool GetDeviceToWorldMatrixForDevice(vtkEventDataDevice device, vtkMatrix4x4 *deviceToWorldMatrix) override
Store in deviceToWorldMatrix the matrix that goes from device coordinates to world coordinates.
vtkTypeBool GetEventPending() override
Check to see if a mouse button has been pressed or mouse wheel activated.
vtkTypeBool IsDirect() override
Is this render window using hardware acceleration? 0-false, 1-true.
int * GetScreenSize() override
Get the current size of the screen in pixels.
virtual void InitializeViewFromCamera(vtkCamera *cam)
Initialize the HMD to World setting and camera settings so that the VR world view most closely matche...
virtual bool CreateFramebuffers(uint32_t viewCount=2)=0
void * GetGenericContext() override
Implement required virtual functions.
void * GetGenericDisplayId() override
Implement required virtual functions.
vtkMatrix4x4 * GetDeviceToPhysicalMatrixForDevice(vtkEventDataDevice idx)
Get the DeviceToPhysical matrix corresponding to the device or device handle.
void SetHelperWindow(vtkOpenGLRenderWindow *val)
Set/Get the window to use for the openGL context.
void SetModelForDeviceHandle(uint32_t handle, vtkVRModel *model)
Set the VRModel corresponding to the device handle.
virtual std::string GetWindowTitleFromAPI()
void SetSize(int a[2]) override
Set the size of the window in screen coordinates in pixels.
vtkRenderWindowInteractor * MakeRenderWindowInteractor() override=0
Create an interactor to control renderers in this window.
void ReleaseCurrent() override
Release the current context.
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_DEPRECATED_IN_9_4_0(reason)
vtkEventDataDevice
platform-independent event data structures