1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkRenderWindow.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 vtkGenericOpenGLRenderWindow 17 * @brief platform independent render window 18 * 19 * 20 * vtkGenericOpenGLRenderWindow provides a skeleton for implementing a render window 21 * using one's own OpenGL context and drawable. 22 * To be effective, one must register an observer for WindowMakeCurrentEvent, 23 * WindowIsCurrentEvent and WindowFrameEvent. When this class sends a WindowIsCurrentEvent, 24 * the call data is an bool* which one can use to return whether the context is current. 25 */ 26 27 #ifndef vtkGenericOpenGLRenderWindow_h 28 #define vtkGenericOpenGLRenderWindow_h 29 30 #include "vtkOpenGLRenderWindow.h" 31 #include "vtkRenderingOpenGL2Module.h" // For export macro 32 33 class VTKRENDERINGOPENGL2_EXPORT vtkGenericOpenGLRenderWindow : public vtkOpenGLRenderWindow 34 { 35 public: 36 static vtkGenericOpenGLRenderWindow* New(); 37 vtkTypeMacro(vtkGenericOpenGLRenderWindow, vtkOpenGLRenderWindow); 38 void PrintSelf(ostream& os, vtkIndent indent) override; 39 40 protected: 41 vtkGenericOpenGLRenderWindow(); 42 ~vtkGenericOpenGLRenderWindow() override; 43 44 public: 45 //! Cleans up graphics resources allocated in the context for this VTK scene. 46 void Finalize() override; 47 48 //! flush the pending drawing operations 49 //! Class user may to watch for WindowFrameEvent and act on it 50 void Frame() override; 51 52 //! Makes the context current. It is the class user's 53 //! responsibility to watch for WindowMakeCurrentEvent and set it current. 54 void MakeCurrent() override; 55 56 //! Returns if the context is current. It is the class user's 57 //! responsibility to watch for WindowIsCurrentEvent and set the bool* flag 58 //! passed through the call data parameter. 59 bool IsCurrent() override; 60 61 //! Returns if OpenGL is supported. It is the class user's 62 //! responsibility to watch for WindowSupportsOpenGLEvent and set the int* flag 63 //! passed through the call data parameter. 64 int SupportsOpenGL() override; 65 66 //! Returns if the context is direct. It is the class user's 67 //! responsibility to watch for WindowIsDirectEvent and set the int* flag 68 //! passed through the call data parameter. 69 vtkTypeBool IsDirect() override; 70 71 // {@ 72 //! set the drawing buffers to use 73 void SetFrontLeftBuffer(unsigned int); 74 void SetFrontRightBuffer(unsigned int); 75 void SetBackLeftBuffer(unsigned int); 76 void SetBackRightBuffer(unsigned int); 77 // }@ 78 79 void SetOwnContext(vtkTypeBool); 80 81 //! no-op (for API compat with OpenGL1). PushState()82 void PushState() {} 83 //! no-op (for API compat with OpenGL1). PopState()84 void PopState() {} 85 86 // {@ 87 //! does nothing 88 void SetWindowId(void*) override; 89 void* GetGenericWindowId() override; 90 void SetDisplayId(void*) override; 91 void SetParentId(void*) override; 92 void* GetGenericDisplayId() override; 93 void* GetGenericParentId() override; 94 void* GetGenericContext() override; 95 void* GetGenericDrawable() override; 96 void SetWindowInfo(const char*) override; 97 void SetParentInfo(const char*) override; 98 int* GetScreenSize() VTK_SIZEHINT(2) override; 99 void HideCursor() override; 100 void ShowCursor() override; 101 void SetFullScreen(vtkTypeBool) override; 102 void WindowRemap() override; 103 vtkTypeBool GetEventPending() override; 104 void SetNextWindowId(void*) override; 105 void SetNextWindowInfo(const char*) override; 106 void CreateAWindow() override; 107 void DestroyWindow() override; 108 // }@ 109 110 ///@{ 111 /** 112 * Allow to update state within observer callback without changing 113 * data argument and MTime. 114 */ 115 void SetIsDirect(vtkTypeBool newValue); 116 void SetSupportsOpenGL(int newValue); 117 void SetIsCurrent(bool newValue); 118 ///@} 119 120 /** 121 * Override the Render method to do some state management. 122 * This method saves the OpenGL state before asking its child renderers to 123 * render their image. Once this is done, the OpenGL state is restored. 124 * \sa vtkOpenGLRenderWindow::SaveGLState() 125 * \sa vtkOpenGLRenderWindow::RestoreGLState() 126 */ 127 void Render() override; 128 129 /** 130 * Overridden to pass explicitly specified MaximumHardwareLineWidth, if any. 131 */ 132 float GetMaximumHardwareLineWidth() override; 133 134 ///@{ 135 /** 136 * Specify a non-zero line width to force the hardware line width determined 137 * by the window. 138 */ 139 vtkSetClampMacro(ForceMaximumHardwareLineWidth, float, 0, VTK_FLOAT_MAX); 140 vtkGetMacro(ForceMaximumHardwareLineWidth, float); 141 ///@} 142 143 ///@{ 144 /** 145 * Set this to true to indicate that the context is now ready. For backwards 146 * compatibility reasons, it's set to true by default. If set to false, the 147 * `Render` call will be skipped entirely. 148 */ 149 vtkSetMacro(ReadyForRendering, bool); 150 vtkGetMacro(ReadyForRendering, bool); 151 152 /** 153 * Set the size of the screen in pixels. 154 * An HDTV for example would be 1920 x 1080 pixels. 155 */ 156 vtkSetVector2Macro(ScreenSize, int); 157 158 /** 159 * Overridden to invoke vtkCommand::CursorChangedEvent 160 */ 161 void SetCurrentCursor(int cShape) override; 162 163 // since we are using an external context it must 164 // specify if the window is mapped or not. 165 vtkSetMacro(Mapped, vtkTypeBool); 166 167 /** 168 * Overridden to simply call `GetReadyForRendering` 169 */ 170 VTK_DEPRECATED_IN_9_1_0( 171 "Deprecated in 9.1 because no one knows what it's for and nothing uses it") 172 bool IsDrawable() override; 173 174 /** 175 * Initialize OpenGL for this window. 176 */ 177 void OpenGLInit() override; 178 179 protected: 180 /** 181 * Overridden to not attempt to read pixels if `this->ReadyForRendering` is 182 * false. In that case, this method will simply return `VTK_ERROR`. Otherwise, 183 * the superclass' implementation will be called. 184 */ 185 int ReadPixels( 186 const vtkRecti& rect, int front, int glFormat, int glType, void* data, int right) override; 187 188 int SetPixelData( 189 int x1, int y1, int x2, int y2, unsigned char* data, int front, int right) override; 190 int SetPixelData( 191 int x1, int y1, int x2, int y2, vtkUnsignedCharArray* data, int front, int right) override; 192 int SetRGBACharPixelData( 193 int x1, int y1, int x2, int y2, unsigned char* data, int front, int blend, int right) override; 194 int SetRGBACharPixelData(int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front, 195 int blend = 0, int right = 0) override; 196 197 int DirectStatus; 198 int SupportsOpenGLStatus; 199 bool CurrentStatus; 200 float ForceMaximumHardwareLineWidth; 201 bool ReadyForRendering; 202 203 private: 204 vtkGenericOpenGLRenderWindow(const vtkGenericOpenGLRenderWindow&) = delete; 205 void operator=(const vtkGenericOpenGLRenderWindow&) = delete; 206 }; 207 208 #endif 209