vtkIOSRenderWindow.h 10.4 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*=========================================================================

Program:   Visualization Toolkit
Module:    vtkIOSRenderWindow.h

Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/**
 * @class   vtkIOSRenderWindow
 * @brief   IOS OpenGL rendering window
 *
 *
 * vtkIOSRenderWindow is a concrete implementation of the abstract
 * class vtkOpenGLRenderWindow. It is only available on Mac OS X 10.6
 * and later.
 * To use this class, build VTK with VTK_USE_IOS turned ON (this is
 * the default).
 * This class can be used by 32 and 64 bit processes, and either in
 * garbage collected or reference counted modes. ARC is not supported.
 * vtkIOSRenderWindow uses Objective-C++, and the OpenGL and
 * IOS APIs. This class's default behaviour is to create an NSWindow and
 * a vtkIOSGLView which are used together to draw all VTK content.
 * If you already have an NSWindow and vtkIOSGLView and you want this
 * class to use them you must call both SetRootWindow() and SetWindowId(),
 * respectively, early on (before WindowInitialize() is executed).
 *
 * @sa
 * vtkOpenGLRenderWindow vtkIOSGLView
 *
 * @warning
 * This header must be in C++ only because it is included by .cxx files.
 * That means no Objective-C may be used. That's why some instance variables
 * are void* instead of what they really should be.
*/
Ken Martin's avatar
Ken Martin committed
42

43 44
#ifndef vtkIOSRenderWindow_h
#define vtkIOSRenderWindow_h
Ken Martin's avatar
Ken Martin committed
45 46 47 48 49 50 51 52 53 54 55

#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkOpenGLRenderWindow.h"

class VTKRENDERINGOPENGL2_EXPORT vtkIOSRenderWindow : public vtkOpenGLRenderWindow
{
public:
  static vtkIOSRenderWindow *New();
  vtkTypeMacro(vtkIOSRenderWindow,vtkOpenGLRenderWindow);
  void PrintSelf(ostream& os, vtkIndent indent);

56 57 58
  /**
   * Begin the rendering process.
   */
Ken Martin's avatar
Ken Martin committed
59 60
  virtual void Start();

61 62 63
  /**
   * Finish the rendering process.
   */
Ken Martin's avatar
Ken Martin committed
64 65
  virtual void Frame();

66 67 68
  /**
   * Specify various window parameters.
   */
Ken Martin's avatar
Ken Martin committed
69 70
  virtual void WindowConfigure();

71 72 73 74
  /**
   * Initialize the window for rendering.
   * virtual void WindowInitialize();
   */
Ken Martin's avatar
Ken Martin committed
75

76 77 78
  /**
   * Initialize the rendering window.
   */
Ken Martin's avatar
Ken Martin committed
79 80
  virtual void Initialize();

81 82 83 84 85 86
  /**
   * Change the window to fill the entire screen.  This is only partially
   * implemented for the vtkIOSRenderWindow.  It can only be called
   * before the window has been created, and it might not work on all
   * versions of OS X.
   */
Ken Martin's avatar
Ken Martin committed
87 88
  virtual void SetFullScreen(int);

89 90 91
  /**
   * Remap the window.  This is not implemented for the vtkIOSRenderWindow.
   */
Ken Martin's avatar
Ken Martin committed
92 93
  virtual void WindowRemap();

94 95 96 97
  /**
   * Set the preferred window size to full screen.  This is not implemented
   * for the vtkIOSRenderWindow.
   */
Ken Martin's avatar
Ken Martin committed
98 99
  virtual void PrefFullScreen();

100 101 102 103
  //@{
  /**
   * Set the size of the window in pixels.
   */
Ken Martin's avatar
Ken Martin committed
104 105
  virtual void SetSize(int a[2]);
  virtual void SetSize(int,int);
106
  //@}
Ken Martin's avatar
Ken Martin committed
107

108 109 110
  /**
   * Get the current size of the window in pixels.
   */
Ken Martin's avatar
Ken Martin committed
111 112
  virtual int *GetSize();

113 114 115 116
  //@{
  /**
   * Set the position of the window.
   */
Ken Martin's avatar
Ken Martin committed
117 118
  virtual void SetPosition(int a[2]);
  virtual void SetPosition(int,int);
119
  //@}
Ken Martin's avatar
Ken Martin committed
120

121 122 123
  /**
   * Get the current size of the screen in pixels.
   */
Ken Martin's avatar
Ken Martin committed
124 125
  virtual int *GetScreenSize();

126 127 128
  /**
   * Get the position in screen coordinates of the window.
   */
Ken Martin's avatar
Ken Martin committed
129 130
  virtual int *GetPosition();

131 132 133 134
  /**
   * Set the name of the window. This appears at the top of the window
   * normally.
   */
Ken Martin's avatar
Ken Martin committed
135 136 137
  virtual void SetWindowName(const char *);

  void SetNextWindowInfo(char *)
138
  {
Ken Martin's avatar
Ken Martin committed
139
      vtkWarningMacro("SetNextWindowInfo not implemented (WindowRemap not implemented).");
140
  }
Ken Martin's avatar
Ken Martin committed
141
  virtual void* GetGenericDrawable()
142
  {
Ken Martin's avatar
Ken Martin committed
143 144
      vtkWarningMacro("Method not implemented.");
      return 0;
145
  }
Ken Martin's avatar
Ken Martin committed
146
  virtual void SetDisplayId(void*)
147
  {
Ken Martin's avatar
Ken Martin committed
148
      vtkWarningMacro("Method not implemented.");
149
  }
Ken Martin's avatar
Ken Martin committed
150
  virtual void *GetGenericDisplayId()
151
  {
Ken Martin's avatar
Ken Martin committed
152 153
      vtkWarningMacro("Method not implemented.");
      return 0;
154
  }
Ken Martin's avatar
Ken Martin committed
155

156 157 158 159 160
  /**
   * Set this RenderWindow's window id to a pre-existing window.
   * The paramater is an ASCII string of a decimal number representing
   * a pointer to the window.
   */
Ken Martin's avatar
Ken Martin committed
161 162
  virtual void SetWindowInfo(char*);

163 164 165 166 167
  /**
   * See the documenation for SetParentId().  This method allows the ParentId
   * to be set as an ASCII string of a decimal number that is the memory
   * address of the parent UIView.
   */
Ken Martin's avatar
Ken Martin committed
168 169 170
  virtual void SetParentInfo(char*);

  void SetNextWindowId(void*)
171
  {
Ken Martin's avatar
Ken Martin committed
172
      vtkWarningMacro("SetNextWindowId not implemented (WindowRemap not implemented).");
173
  }
Ken Martin's avatar
Ken Martin committed
174

175 176 177 178
  /**
   * Initialize the render window from the information associated
   * with the currently activated OpenGL context.
   */
Ken Martin's avatar
Ken Martin committed
179 180
  virtual bool InitializeFromCurrentContext();

181 182 183
  /**
   * Update system if needed due to stereo rendering.
   */
Ken Martin's avatar
Ken Martin committed
184 185
  virtual void StereoUpdate();

186 187 188 189 190 191
  /**
   * Prescribe that the window be created in a stereo-capable mode. This
   * method must be called before the window is realized. This method
   * overrrides the superclass method since this class can actually check
   * whether the window has been realized yet.
   */
Ken Martin's avatar
Ken Martin committed
192 193
  virtual void SetStereoCapableWindow(int capable);

194 195 196
  /**
   * Make this windows OpenGL context the current context.
   */
Ken Martin's avatar
Ken Martin committed
197 198
  virtual void MakeCurrent();

199 200 201
  /**
   * Tells if this window is the current OpenGL context for the calling thread.
   */
Ken Martin's avatar
Ken Martin committed
202 203
  virtual bool IsCurrent();

204 205 206 207 208 209
  /**
   * Test if the window has a valid drawable. This is
   * currently only an issue on Mac OS X IOS where rendering
   * to an invalid drawable results in all OpenGL calls to fail
   * with "invalid framebuffer operation".
   */
Ken Martin's avatar
Ken Martin committed
210 211
  virtual bool IsDrawable();

212 213 214
  /**
   * Update this window's OpenGL context, e.g. when the window is resized.
   */
Ken Martin's avatar
Ken Martin committed
215 216
  void UpdateContext();

217 218 219
  /**
   * Get report of capabilities for the render window
   */
Ken Martin's avatar
Ken Martin committed
220 221
  const char *ReportCapabilities();

222 223 224
  /**
   * Does this render window support OpenGL? 0-false, 1-true
   */
Ken Martin's avatar
Ken Martin committed
225 226
  int SupportsOpenGL();

227 228 229
  /**
   * Is this render window using hardware acceleration? 0-false, 1-true
   */
Ken Martin's avatar
Ken Martin committed
230 231
  int IsDirect();

232 233 234 235 236
  /**
   * If called, allow MakeCurrent() to skip cache-check when called.
   * MakeCurrent() reverts to original behavior of cache-checking
   * on the next render.
   */
Ken Martin's avatar
Ken Martin committed
237 238
  virtual void SetForceMakeCurrent();

239 240 241 242
  /**
   * Check to see if an event is pending for this window.
   * This is a useful check to abort a long render.
   */
Ken Martin's avatar
Ken Martin committed
243 244
  virtual  int GetEventPending();

245 246 247 248
  //@{
  /**
   * Initialize OpenGL for this window.
   */
Ken Martin's avatar
Ken Martin committed
249 250 251
  virtual void SetupPalette(void *hDC);
  virtual void SetupPixelFormat(void *hDC, void *dwFlags, int debug,
                                int bpp=16, int zbpp=16);
252
  //@}
Ken Martin's avatar
Ken Martin committed
253

254 255 256
  /**
   * Clean up device contexts, rendering contexts, etc.
   */
Ken Martin's avatar
Ken Martin committed
257 258
  void Finalize();

259 260 261
  /**
   * Get the size of the depth buffer.
   */
Ken Martin's avatar
Ken Martin committed
262 263
  int GetDepthBufferSize();

264 265 266 267 268 269 270
  //@{
  /**
   * Hide or Show the mouse cursor, it is nice to be able to hide the
   * default cursor if you want VTK to display a 3D cursor instead.
   * Set cursor position in window (note that (0,0) is the lower left
   * corner).
   */
Ken Martin's avatar
Ken Martin committed
271 272 273
  virtual void HideCursor();
  virtual void ShowCursor();
  virtual void SetCursorPosition(int x, int y);
274
  //@}
Ken Martin's avatar
Ken Martin committed
275

276 277 278
  /**
   * Change the shape of the cursor.
   */
Ken Martin's avatar
Ken Martin committed
279 280
  virtual void SetCurrentCursor(int);

281 282 283 284
  /**
   * Get the WindowCreated flag. It is 1 if this object created an instance
   * of NSWindow, 0 otherwise.
   */
Ken Martin's avatar
Ken Martin committed
285 286
  virtual int GetWindowCreated();

287 288 289 290
  //@{
  /**
   * Accessors for the OpenGL context (Really an NSOpenGLContext*).
   */
Ken Martin's avatar
Ken Martin committed
291 292 293
  void SetContextId(void *);
  void *GetContextId();
  virtual void *GetGenericContext()   {return this->GetContextId();}
294 295 296 297 298 299 300 301 302 303 304 305
  //@}

  /**
   * Sets the NSWindow* associated with this vtkRenderWindow.
   * This class' default behaviour, that is, if you never call
   * SetWindowId()/SetRootWindow() is to create an NSWindow and a
   * vtkIOSGLView (UIView subclass) which are used together to draw
   * all vtk stuff into. If you already have an NSWindow and UIView and
   * you want this class to use them you must call both SetRootWindow()
   * and SetWindowId(), respectively, early on (before WindowInitialize()
   * is executed). In the case of Java, you should call only SetWindowId().
   */
Ken Martin's avatar
Ken Martin committed
306 307
  virtual void SetRootWindow(void *);

308 309 310
  /**
   * Returns the NSWindow* associated with this vtkRenderWindow.
   */
Ken Martin's avatar
Ken Martin committed
311 312
  virtual void *GetRootWindow();

313 314 315 316 317 318 319 320 321 322
  /**
   * Sets the UIView* associated with this vtkRenderWindow.
   * This class' default behaviour, that is, if you never call this
   * SetWindowId()/SetRootWindow() is to create an NSWindow and a
   * vtkIOSGLView (UIView subclass) which are used together to draw all
   * vtk stuff into. If you already have an NSWindow and UIView and you
   * want this class to use them you must call both SetRootWindow()
   * and SetWindowId(), respectively, early on (before WindowInitialize()
   * is executed). In the case of Java, you should call only SetWindowId().
   */
Ken Martin's avatar
Ken Martin committed
323 324
  virtual void SetWindowId(void *);

325 326 327
  /**
   * Returns the UIView* associated with this vtkRenderWindow.
   */
Ken Martin's avatar
Ken Martin committed
328 329 330
  virtual void *GetWindowId();
  virtual void *GetGenericWindowId() {return this->GetWindowId();}

331 332 333 334 335 336
  /**
   * Set the UIView* for the vtkRenderWindow to be parented within.  The
   * Position and Size of the RenderWindow will set the rectangle of the
   * UIView that the vtkRenderWindow will create within this parent.
   * If you set the WindowId, then this ParentId will be ignored.
   */
Ken Martin's avatar
Ken Martin committed
337 338
  virtual void SetParentId(void *UIView);

339 340 341 342 343
  /**
   * Get the parent UIView* for this vtkRenderWindow.  This method will
   * return "NULL" if the parent was not set with SetParentId() or
   * SetParentInfo().
   */
Ken Martin's avatar
Ken Martin committed
344 345 346
  virtual void *GetParentId();
  virtual void *GetGenericParentId() { return this->GetParentId(); }

347 348 349 350
  //@{
  /**
   * Accessors for the pixel format object (Really an NSOpenGLPixelFormat*).
   */
Ken Martin's avatar
Ken Martin committed
351 352
  void SetPixelFormat(void *pixelFormat);
  void *GetPixelFormat();
353
  //@}
Ken Martin's avatar
Ken Martin committed
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368

protected:
  vtkIOSRenderWindow();
  ~vtkIOSRenderWindow();

  void CreateGLContext();

  void CreateAWindow();
  void DestroyWindow();
  void DestroyOffScreenWindow();

  int OffScreenInitialized;
  int OnScreenInitialized;

private:
369
  vtkIOSRenderWindow(const vtkIOSRenderWindow&) VTK_DELETE_FUNCTION;
370
  void operator=(const vtkIOSRenderWindow&) VTK_DELETE_FUNCTION;
Ken Martin's avatar
Ken Martin committed
371 372 373 374 375 376 377 378 379 380 381

private:
  int      WindowCreated;
  int      ViewCreated;
  int      CursorHidden;

  int      ForceMakeCurrent;
  char     *Capabilities;
};

#endif