vtkCarbonRenderWindow.h 8.3 KB
Newer Older
Yves Starreveld's avatar
Yves Starreveld committed
1
2
/*=========================================================================

3
4
Program:   Visualization Toolkit
Module:    vtkCarbonRenderWindow.h
Yves Starreveld's avatar
Yves Starreveld committed
5

6
7
8
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
Yves Starreveld's avatar
Yves Starreveld committed
9

10
11
12
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.
Yves Starreveld's avatar
Yves Starreveld committed
13
14
15

=========================================================================*/
// .NAME vtkCarbonRenderWindow - Carbon OpenGL rendering window
16
//
Yves Starreveld's avatar
Yves Starreveld committed
17
18
// .SECTION Description
// vtkCarbonRenderWindow is a concrete implementation of the abstract
19
20
21
22
23
24
25
26
27
28
29
// class vtkOpenGLRenderWindow. It is only available on Mac OS X 10.3
// and later.
// To use this class, build VTK with VTK_USE_CARBON turned ON.
// This class can be used only by 32 bit processes, as Carbon is
// unavailable in 64 bit. If you need 64 bit support, use
// vtkCocoaRenderWindow.
// vtkCarbonRenderWindow interfaces to the OpenGL graphics library using
// the Carbon AGL APIs.
//
// .SECTION See Also
// vtkOpenGLRenderWindow vtkCocoaRenderWindow
Yves Starreveld's avatar
Yves Starreveld committed
30

31
32
#ifndef vtkCarbonRenderWindow_h
#define vtkCarbonRenderWindow_h
Yves Starreveld's avatar
Yves Starreveld committed
33

34
#if defined(__LP64__) && __LP64__
35
36
37
38
  #error VTK_USE_CARBON cannot work in 64 bit; use VTK_USE_COCOA instead.
#endif
#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070)
  #error VTK_USE_CARBON cannot work with the OS X 10.7 SDK or later; use VTK_USE_COCOA instead.
39
40
#endif

41
#include "vtkRenderingOpenGLModule.h" // For export macro
Yves Starreveld's avatar
Yves Starreveld committed
42
#include "vtkOpenGLRenderWindow.h"
43

44
45
46
#include <Carbon/Carbon.h> // Carbon and Mac specific
#include <AGL/agl.h> // Carbon and Mac specific

Clinton Stimpson's avatar
   
Clinton Stimpson committed
47
48
49
class vtkCarbonRenderWindowInternal;


50
class VTKRENDERINGOPENGL_EXPORT vtkCarbonRenderWindow : public vtkOpenGLRenderWindow
Yves Starreveld's avatar
Yves Starreveld committed
51
52
53
{
public:
  static vtkCarbonRenderWindow *New();
54
  vtkTypeMacro(vtkCarbonRenderWindow,vtkOpenGLRenderWindow);
Yves Starreveld's avatar
Yves Starreveld committed
55
56
57
58
  void PrintSelf(ostream& os, vtkIndent indent);

  // Description:
  // Begin the rendering process.
59
  void Start();
Yves Starreveld's avatar
Yves Starreveld committed
60
61
62

  // Description:
  // End the rendering process and display the image.
63
  void Frame();
Yves Starreveld's avatar
Yves Starreveld committed
64
65
66

  // Description:
  // Specify various window parameters.
67
  virtual void WindowConfigure();
Yves Starreveld's avatar
Yves Starreveld committed
68
69

  // Description:
Yves Starreveld's avatar
   
Yves Starreveld committed
70
  // Create the window.
71
  virtual void WindowInitialize();
Yves Starreveld's avatar
Yves Starreveld committed
72
73

  // Description:
Yves Starreveld's avatar
   
Yves Starreveld committed
74
75
76
77
  // Initialize the rendering window. This will setup all system-specific
  // resources. This method and Finalize() must be symmetric and it
  // should be possible to call them multiple times, even changing WindowId
  // in-between. This is what WindowRemap does.
78
  virtual void Initialize();
Yves Starreveld's avatar
Yves Starreveld committed
79

Yves Starreveld's avatar
   
Yves Starreveld committed
80
81
82
83
  // Description:
  // Finalize the rendering window. This will shutdown all system-specifc
  // resources. After having called this, it should be possible to destroy
  // a window that was used for a SetWindowId() call without any ill effects.
84
  virtual void Finalize();
Yves Starreveld's avatar
   
Yves Starreveld committed
85

Clinton Stimpson's avatar
   
Clinton Stimpson committed
86
87
88
89
  // Description:
  // Create a rendering area in memory.
  void SetOffScreenRendering(int);

Yves Starreveld's avatar
Yves Starreveld committed
90
91
92
93
94
95
  // Description:
  // Change the window to fill the entire screen.
  virtual void SetFullScreen(int);

  // Description:
  // Remap the window.
96
  virtual void WindowRemap();
Yves Starreveld's avatar
Yves Starreveld committed
97
98
99

  // Description:
  // Set the preferred window size to full screen.
100
  virtual void PrefFullScreen();
Yves Starreveld's avatar
Yves Starreveld committed
101
102

  // Description:
103
  // Set the size of the window in pixels.
104
  virtual void SetSize(int a[2]);
Yves Starreveld's avatar
Yves Starreveld committed
105
106
107
  virtual void SetSize(int,int);

  // Description:
108
  // Get the current size of the window in pixels.
Yves Starreveld's avatar
Yves Starreveld committed
109
110
  virtual int *GetSize();

111
112
  // Description:
  // Set the position of the window.
113
  virtual void SetPosition(int a[2]);
114
115
  virtual void SetPosition(int,int);

Yves Starreveld's avatar
Yves Starreveld committed
116
  // Description:
117
  // Get the current size of the screen in pixels.
Yves Starreveld's avatar
Yves Starreveld committed
118
119
120
121
122
123
124
125
126
  virtual int *GetScreenSize();

  // Description:
  // Get the position in screen coordinates of the window.
  virtual int *GetPosition();

  // Description:
  // Set the name of the window. This appears at the top of the window
  // normally.
127
  virtual void SetWindowName(const char *);
128

Yves Starreveld's avatar
Yves Starreveld committed
129
130
  // Description:
  // Set this RenderWindow's window id to a pre-existing window.
131
  void SetWindowInfo(char *);
Yves Starreveld's avatar
Yves Starreveld committed
132

133
  void SetNextWindowInfo(char *)
134
    {
Mathieu Malaterre's avatar
Mathieu Malaterre committed
135
      vtkWarningMacro("SetNextWindowInfo not implemented (WindowRemap not implemented).");
136
    }
137

Yves Starreveld's avatar
Yves Starreveld committed
138
  //BTX
Clinton Stimpson's avatar
   
Clinton Stimpson committed
139
140
141
142
143
144
  virtual void *GetGenericDisplayId() {return NULL;}
  virtual void *GetGenericWindowId()  {return (void *)this->WindowId;}
  virtual void *GetGenericParentId()  {return (void *)this->ParentId;}
  virtual AGLContext GetContextId();
  virtual void *GetGenericContext()  {return (void*)this->GetContextId();}
  virtual void SetDisplayId(void *) {}
145

Yves Starreveld's avatar
Yves Starreveld committed
146
147
  virtual void* GetGenericDrawable()
    {
148
      vtkWarningMacro("GetGenericDrawable Method not implemented.");
Yves Starreveld's avatar
Yves Starreveld committed
149
150
      return 0;
    }
151

Yves Starreveld's avatar
Yves Starreveld committed
152
153
  void SetParentInfo(char*)
    {
154
      vtkWarningMacro("SetParentInfo Method not implemented.");
Yves Starreveld's avatar
Yves Starreveld committed
155
156
157
    }

  // Description:
Clinton Stimpson's avatar
   
Clinton Stimpson committed
158
159
160
161
  // Get the HIView window pointer.
  virtual HIViewRef GetWindowId();
  // Set the HIView window pointer.
  void  SetWindowId(void *foo) {this->SetWindowId((HIViewRef)foo);};
Brad King's avatar
Brad King committed
162
  void SetNextWindowId(void*)
163
    {
164
      vtkWarningMacro("SetNextWindowId not implemented (WindowRemap not implemented).");
165
    }
166
167

  // Description:
Clinton Stimpson's avatar
   
Clinton Stimpson committed
168
169
170
  // Set the parent HIView.
  virtual void SetParentId(HIViewRef);
  void  SetParentId(void *foo) {this->SetParentId((HIViewRef)foo);};
171

Yves Starreveld's avatar
Yves Starreveld committed
172
  // Description:
Clinton Stimpson's avatar
   
Clinton Stimpson committed
173
174
  // Set the HIVIew pointer to a pre-existing window.
  virtual void SetWindowId(HIViewRef);
Yves Starreveld's avatar
Yves Starreveld committed
175

Clinton Stimpson's avatar
   
Clinton Stimpson committed
176
177
178
179
  // Description:
  // Set the root window id.  Use this when using non-HIView GUIs.
  void SetRootWindow(WindowPtr win);
  WindowPtr GetRootWindow();
Yves Starreveld's avatar
Yves Starreveld committed
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

  //ETX

  // supply base class virtual function
  vtkSetMacro(MultiSamples,int);
  vtkGetMacro(MultiSamples,int);

  // Description:
  // 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.
  virtual void SetStereoCapableWindow(int capable);

  // Description:
  // Make this windows OpenGL context the current context.
  void MakeCurrent();

198
199
200
  // Description:
  // Tells if this window is the current OpenGL context for the calling thread.
  virtual bool IsCurrent();
201

202
203
204
205
  // Description:
  // If called, allow MakeCurrent() to skip cache-check when called.
  // MakeCurrent() reverts to original behavior of cache-checking
  // on the next render.
206
  void SetForceMakeCurrent();
207

208
209
210
211
  // Description:
  // Is this render window using hardware acceleration? 0-false, 1-true.
  // Always true for Carbon.
  virtual int IsDirect();
212

Yves Starreveld's avatar
Yves Starreveld committed
213
214
215
216
217
218
219
220
221
222
223
224
225
226
  // Description:
  // Check to see if an event is pending for this window.
  // This is a useful check to abort a long render.
  virtual  int GetEventPending();

  // Description:
  // Get the size of the depth buffer.
  int GetDepthBufferSize();

  // Description:
  // 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.
  void HideCursor();
  void ShowCursor();
227

Yves Starreveld's avatar
Yves Starreveld committed
228
229
  void UpdateSizeAndPosition(int xPos, int yPos, int xSize, int ySize);

Clinton Stimpson's avatar
   
Clinton Stimpson committed
230
  // Description:
Clinton Stimpson's avatar
   
Clinton Stimpson committed
231
232
  // Fix the GL region.  The AGL_BUFFER_RECT and AGL_CLIP_REGION will be updated
  void UpdateGLRegion();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
233

234

Yves Starreveld's avatar
Yves Starreveld committed
235
236
237
238
protected:
  vtkCarbonRenderWindow();
  ~vtkCarbonRenderWindow();

Clinton Stimpson's avatar
   
Clinton Stimpson committed
239
240
  vtkCarbonRenderWindowInternal* Internal;

Yves Starreveld's avatar
Yves Starreveld committed
241
242
243
244
  int ApplicationInitialized; // Toolboxen initialized?
  GLint aglAttributes[64];    // input: pixel format attributes always required
                              //   (reset to what was actually allocated)
  AGLContext ContextId;
Clinton Stimpson's avatar
   
Clinton Stimpson committed
245
246
247
  HIViewRef WindowId;
  HIViewRef ParentId;
  WindowPtr RootWindow;
Yves Starreveld's avatar
Yves Starreveld committed
248
249
250
251
  int OwnWindow;
  int ScreenSize[2];

  int CursorHidden;
252
  int ForceMakeCurrent;
Yves Starreveld's avatar
Yves Starreveld committed
253

Clinton Stimpson's avatar
   
Clinton Stimpson committed
254

255
  // data and handlers to keep the GL view coincident with the HIView
Clinton Stimpson's avatar
   
Clinton Stimpson committed
256
257
  EventHandlerUPP RegionEventHandlerUPP;
  EventHandlerRef RegionEventHandler;
258
259
260
  static OSStatus RegionEventProcessor(EventHandlerCallRef er,
                                       EventRef event,
                                       void*);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
261

Yves Starreveld's avatar
Yves Starreveld committed
262
  void InitializeApplication();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
263

264
  void CreateAWindow();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
265
  void DestroyWindow();
266

Clinton Stimpson's avatar
   
Clinton Stimpson committed
267
268
269
270
  void CreateOffScreenWindow(int x, int y);
  void DestroyOffScreenWindow();
  void ResizeOffScreenWindow(int x, int y);

Yves Starreveld's avatar
Yves Starreveld committed
271
272
273
274
275
private:
  vtkCarbonRenderWindow(const vtkCarbonRenderWindow&);  // Not implemented.
  void operator=(const vtkCarbonRenderWindow&);  // Not implemented.
};

276
#endif