1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkXOpenGLRenderWindow.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 /** 16 * @class vtkXOpenGLRenderWindow 17 * @brief OpenGL rendering window 18 * 19 * vtkXOpenGLRenderWindow is a concrete implementation of the abstract class 20 * vtkRenderWindow. vtkOpenGLRenderer interfaces to the OpenGL graphics 21 * library. Application programmers should normally use vtkRenderWindow 22 * instead of the OpenGL specific version. 23 */ 24 25 #ifndef vtkXOpenGLRenderWindow_h 26 #define vtkXOpenGLRenderWindow_h 27 28 #include "vtkRenderingOpenGL2Module.h" // For export macro 29 #include <stack> // for ivar 30 #include "vtkOpenGLRenderWindow.h" 31 #include <X11/Xlib.h> // Needed for X types used in the public interface 32 #include <X11/Xutil.h> // Needed for X types used in the public interface 33 34 class vtkIdList; 35 class vtkXOpenGLRenderWindowInternal; 36 37 class VTKRENDERINGOPENGL2_EXPORT vtkXOpenGLRenderWindow : public vtkOpenGLRenderWindow 38 { 39 public: 40 static vtkXOpenGLRenderWindow *New(); 41 vtkTypeMacro(vtkXOpenGLRenderWindow, vtkOpenGLRenderWindow); 42 void PrintSelf(ostream& os, vtkIndent indent) override; 43 44 /** 45 * Begin the rendering process. 46 */ 47 void Start() override; 48 49 /** 50 * End the rendering process and display the image. 51 */ 52 void Frame() override; 53 54 /** 55 * Initialize the window for rendering. 56 */ 57 virtual void WindowInitialize(); 58 59 /** 60 * Initialize the rendering window. This will setup all system-specific 61 * resources. This method and Finalize() must be symmetric and it 62 * should be possible to call them multiple times, even changing WindowId 63 * in-between. This is what WindowRemap does. 64 */ 65 void Initialize() override; 66 67 /** 68 * "Deinitialize" the rendering window. This will shutdown all system-specific 69 * resources. After having called this, it should be possible to destroy 70 * a window that was used for a SetWindowId() call without any ill effects. 71 */ 72 void Finalize() override; 73 74 /** 75 * Change the window to fill the entire screen. 76 */ 77 void SetFullScreen(vtkTypeBool) override; 78 79 /** 80 * Resize the window. 81 */ 82 void WindowRemap() override; 83 84 /** 85 * Set the preferred window size to full screen. 86 */ 87 virtual void PrefFullScreen(); 88 89 /** 90 * Specify the size of the rendering window in pixels. 91 */ 92 void SetSize(int,int) override; SetSize(int a[2])93 void SetSize(int a[2]) override { this->SetSize(a[0], a[1]); } 94 95 //@{ 96 /** 97 * Get the X properties of an ideal rendering window. 98 */ 99 virtual Colormap GetDesiredColormap(); 100 virtual Visual *GetDesiredVisual(); 101 virtual XVisualInfo *GetDesiredVisualInfo(); 102 virtual int GetDesiredDepth(); 103 //@} 104 105 /** 106 * Prescribe that the window be created in a stereo-capable mode. This 107 * method must be called before the window is realized. This method 108 * overrides the superclass method since this class can actually check 109 * whether the window has been realized yet. 110 */ 111 void SetStereoCapableWindow(vtkTypeBool capable) override; 112 113 /** 114 * Make this window the current OpenGL context. 115 */ 116 void MakeCurrent() override; 117 118 /** 119 * Tells if this window is the current OpenGL context for the calling thread. 120 */ 121 bool IsCurrent() override; 122 123 /** 124 * If called, allow MakeCurrent() to skip cache-check when called. 125 * MakeCurrent() reverts to original behavior of cache-checking 126 * on the next render. 127 */ 128 void SetForceMakeCurrent() override; 129 130 /** 131 * Get report of capabilities for the render window 132 */ 133 const char *ReportCapabilities() override; 134 135 /** 136 * Is this render window using hardware acceleration? 0-false, 1-true 137 */ 138 int IsDirect() override; 139 140 /** 141 * Xwindow get set functions 142 */ GetGenericDisplayId()143 void *GetGenericDisplayId() override 144 { 145 return this->GetDisplayId(); 146 } 147 148 void *GetGenericWindowId() override; GetGenericParentId()149 void *GetGenericParentId() override 150 { 151 return reinterpret_cast<void *>(this->ParentId); 152 } 153 154 void *GetGenericContext() override; GetGenericDrawable()155 void *GetGenericDrawable() override 156 { 157 return reinterpret_cast<void *>(this->WindowId); 158 } 159 160 /** 161 * Get the current size of the screen in pixels. 162 */ 163 int *GetScreenSize() VTK_SIZEHINT(2) override; 164 165 /** 166 * Get the position in screen coordinates (pixels) of the window. 167 */ 168 int *GetPosition() VTK_SIZEHINT(2) override; 169 170 /** 171 * Get this RenderWindow's X display id. 172 */ 173 Display *GetDisplayId(); 174 175 //@{ 176 /** 177 * Set the X display id for this RenderWindow to use to a pre-existing 178 * X display id. 179 */ 180 void SetDisplayId(Display *); 181 void SetDisplayId(void *) override; 182 //@} 183 184 /** 185 * Get this RenderWindow's parent X window id. 186 */ 187 Window GetParentId(); 188 189 //@{ 190 /** 191 * Sets the parent of the window that WILL BE created. 192 */ 193 void SetParentId(Window); 194 void SetParentId(void *) override; 195 //@} 196 197 /** 198 * Get this RenderWindow's X window id. 199 */ 200 Window GetWindowId(); 201 202 //@{ 203 /** 204 * Set this RenderWindow's X window id to a pre-existing window. 205 */ 206 void SetWindowId(Window); 207 void SetWindowId(void *) override; 208 //@} 209 210 /** 211 * Specify the X window id to use if a WindowRemap is done. 212 */ 213 void SetNextWindowId(Window); 214 215 /** 216 * Set the window id of the new window once a WindowRemap is done. 217 * This is the generic prototype as required by the vtkRenderWindow 218 * parent. 219 */ 220 void SetNextWindowId(void *) override; 221 222 /** 223 * Set name of rendering window. 224 */ 225 void SetWindowName(const char *) override; 226 227 /** 228 * Initialize the render window from the information associated 229 * with the currently activated OpenGL context. 230 */ 231 bool InitializeFromCurrentContext() override; 232 233 /** 234 * Does this platform support render window data sharing. 235 */ GetPlatformSupportsRenderWindowSharing()236 bool GetPlatformSupportsRenderWindowSharing() override { return true; }; 237 238 //@{ 239 /** 240 * Move the window to a new position on the display. 241 */ 242 void SetPosition(int,int) override; SetPosition(int a[2])243 void SetPosition(int a[2]) override { this->SetPosition(a[0], a[1]); } 244 //@} 245 246 //@{ 247 /** 248 * Hide or Show the mouse cursor, it is nice to be able to hide the 249 * default cursor if you want VTK to display a 3D cursor instead. 250 */ 251 void HideCursor() override; 252 void ShowCursor() override; 253 //@} 254 255 /** 256 * Change the shape of the cursor 257 */ 258 void SetCurrentCursor(int) override; 259 260 /** 261 * Check to see if a mouse button has been pressed or mouse wheel activated. 262 * All other events are ignored by this method. 263 * This is a useful check to abort a long render. 264 */ 265 int GetEventPending() override; 266 267 /** 268 * Set this RenderWindow's X window id to a pre-existing window. 269 */ 270 void SetWindowInfo(const char *info) override; 271 272 /** 273 * Set the window info that will be used after WindowRemap() 274 */ 275 void SetNextWindowInfo(const char *info) override; 276 277 /** 278 * Sets the X window id of the window that WILL BE created. 279 */ 280 void SetParentInfo(const char *info) override; 281 282 /** 283 * This computes the size of the render window 284 * before calling the supper classes render 285 */ 286 void Render() override; 287 288 /** 289 * Render without displaying the window. 290 */ 291 void SetOffScreenRendering(vtkTypeBool i) override; 292 293 //@{ 294 /** 295 * Ability to push and pop this window's context 296 * as the current context. The idea being to 297 * if needed make this window's context current 298 * and when done releasing resources restore 299 * the prior context 300 */ 301 void PushContext() override; 302 void PopContext() override; 303 //@} 304 305 /** 306 * Set the number of vertical syncs required between frames. 307 * A value of 0 means swap buffers as quickly as possible 308 * regardless of the vertical refresh. A value of 1 means swap 309 * buffers in sync with the vertical refresh to eliminate tearing. 310 * A value of -1 means use a value of 1 unless we missed a frame 311 * in which case swap immediately. Returns true if the call 312 * succeeded. 313 */ 314 bool SetSwapControl(int i) override; 315 316 protected: 317 vtkXOpenGLRenderWindow(); 318 ~vtkXOpenGLRenderWindow() override; 319 320 vtkXOpenGLRenderWindowInternal *Internal; 321 322 Window ParentId; 323 Window WindowId; 324 Window NextWindowId; 325 Display *DisplayId; 326 Colormap ColorMap; 327 int OwnWindow; 328 int OwnDisplay; 329 int ScreenSize[2]; 330 int CursorHidden; 331 int ForceMakeCurrent; 332 int UsingHardware; 333 334 std::stack<Display *> DisplayStack; 335 std::stack<Drawable> DrawableStack; 336 std::stack<void *> ContextStack; 337 338 // we must keep track of the cursors we are using 339 Cursor XCCrosshair; 340 Cursor XCArrow; 341 Cursor XCSizeAll; 342 Cursor XCSizeNS; 343 Cursor XCSizeWE; 344 Cursor XCSizeNE; 345 Cursor XCSizeNW; 346 Cursor XCSizeSE; 347 Cursor XCSizeSW; 348 Cursor XCHand; 349 350 351 void CreateAWindow() override; 352 void DestroyWindow() override; 353 void CreateOffScreenWindow(int width, int height); 354 void DestroyOffScreenWindow(); 355 void ResizeOffScreenWindow(int width, int height); 356 void CloseDisplay(); 357 358 359 private: 360 vtkXOpenGLRenderWindow(const vtkXOpenGLRenderWindow&) = delete; 361 void operator=(const vtkXOpenGLRenderWindow&) = delete; 362 }; 363 364 365 366 #endif 367