VTK  9.5.20250711
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
45#include "vtkRenderingVRModule.h" // For export macro
46#include "vtkSmartPointer.h" // for vtkSmartPointer
47#include "vtk_glad.h" // used for methods
48
49#include <vector> // ivars
50
51VTK_ABI_NAMESPACE_BEGIN
52class vtkCamera;
53class vtkMatrix4x4;
54class vtkVRModel;
55
56class VTKRENDERINGVR_EXPORT vtkVRRenderWindow : public vtkOpenGLRenderWindow
57{
58public:
59 enum
60 {
61 LeftEye = 0,
62 RightEye
63 };
64
66 void PrintSelf(ostream& os, vtkIndent indent) override;
67
73
75
78 GLuint GetLeftResolveBufferId() { return this->FramebufferDescs[LeftEye].ResolveFramebufferId; }
79 GLuint GetRightResolveBufferId() { return this->FramebufferDescs[RightEye].ResolveFramebufferId; }
80 void GetRenderBufferSize(int& width, int& height)
81 {
82 width = this->Size[0];
83 height = this->Size[1];
84 }
86
88
94
96
99 void SetModelForDeviceHandle(uint32_t handle, vtkVRModel* model);
101
103
111
113 /*
114 * This method gets a device handle for a given device. index is used to
115 * disambiguate when there are multiple device handles that map to a
116 * device.
117 */
118 uint32_t GetDeviceHandleForDevice(vtkEventDataDevice dev, uint32_t index = 0);
120
122 /*
123 * This method returns how many device handles map to a device.
124 */
127
129 /*
130 * This method adds a device handle if not already present. The second
131 * signature also sets the device associated with the device handle.
132 */
133 void AddDeviceHandle(uint32_t handle);
134 void AddDeviceHandle(uint32_t handle, vtkEventDataDevice device);
136
138 /*
139 * This method gets a device for a given device handle.
140 */
143
151 vtkEventDataDevice device, vtkMatrix4x4* deviceToWorldMatrix) override;
153 uint32_t handle, vtkMatrix4x4* deviceToWorldMatrix);
154
163
167 void AddRenderer(vtkRenderer*) override;
168
172 void MakeCurrent() override;
173
177 void ReleaseCurrent() override;
178
182 bool IsCurrent() override;
183
187 const char* ReportCapabilities() override { return "VR System"; }
188
192 vtkTypeBool IsDirect() override { return 1; }
193
199 vtkTypeBool GetEventPending() override { return 0; }
200
204 int* GetScreenSize() override;
205
207
214 void SetSize(int width, int height) override;
215 void SetSize(int a[2]) override { this->SetSize(a[0], a[1]); }
217
219
222 void* GetGenericDisplayId() override { return this->HelperWindow->GetGenericDisplayId(); }
223 void* GetGenericWindowId() override { return this->HelperWindow->GetGenericWindowId(); }
224 void* GetGenericParentId() override { return nullptr; }
225 void* GetGenericContext() override { return this->HelperWindow->GetGenericContext(); }
226 void* GetGenericDrawable() override { return this->HelperWindow->GetGenericDrawable(); }
228
232 int SupportsOpenGL() override { return 1; }
233
238 void Render() override;
239
241
244 vtkGetObjectMacro(HelperWindow, vtkOpenGLRenderWindow);
247
252
258
262 virtual void RenderModels() = 0;
263
265
268 vtkGetMacro(BaseStationVisibility, bool);
269 vtkSetMacro(BaseStationVisibility, bool);
270 vtkBooleanMacro(BaseStationVisibility, bool);
272
276 virtual void UpdateHMDMatrixPose(){};
277
282 vtkGetMacro(VRInitialized, bool);
283
284protected:
287
289 {
290 GLuint ResolveFramebufferId = 0;
291 GLuint ResolveColorTextureId = 0;
292 GLuint ResolveDepthTextureId = 0;
293 };
294
295 void CreateAWindow() override {}
296 void DestroyWindow() override {}
297
303 virtual bool GetSizeFromAPI() = 0;
304
305 virtual std::string GetWindowTitleFromAPI() { return "VTK - VR"; }
306
307 virtual bool CreateFramebuffers(uint32_t viewCount = 2) = 0;
308 virtual void RenderFramebuffer(FramebufferDesc& framebufferDesc) = 0;
309
310 bool VRInitialized = false;
311
312 // One per view (typically one per eye)
313 std::vector<FramebufferDesc> FramebufferDescs;
314
316 {
317 public:
321 uint32_t Index = 0;
322 };
323
324 std::map<uint32_t, DeviceData> DeviceHandleToDeviceDataMap;
325 uint32_t InvalidDeviceIndex = UINT32_MAX;
326
327 bool BaseStationVisibility = false;
328
330
331private:
332 vtkVRRenderWindow(const vtkVRRenderWindow&) = delete;
333 void operator=(const vtkVRRenderWindow&) = delete;
334};
335
336VTK_ABI_NAMESPACE_END
337#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:167
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 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 void UpdateHMDMatrixPose()
Update the HMD pose.
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.
std::vector< FramebufferDesc > FramebufferDescs
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
vtkEventDataDevice
platform-independent event data structures