1 | /****************************************************************************** |
---|
2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
3 | * |
---|
4 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
5 | * University of Illinois at Chicago |
---|
6 | * |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright |
---|
13 | * notice, this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above |
---|
15 | * copyright notice, this list of conditions and the following disclaimer |
---|
16 | * in the documentation and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the University of Illinois at Chicago nor |
---|
18 | * the names of its contributors may be used to endorse or promote |
---|
19 | * products derived from this software without specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
25 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | * |
---|
33 | * Direct questions, comments etc about SAGE to http://www.evl.uic.edu/cavern/forum/ |
---|
34 | * |
---|
35 | *****************************************************************************/ |
---|
36 | |
---|
37 | /*========================================================================= |
---|
38 | |
---|
39 | Program: Visualization Toolkit |
---|
40 | Module: $RCSfile: vtkXOpenGLOffScreenRenderWindow.cxx,v $ |
---|
41 | Language: C++ |
---|
42 | Date: $Date: 2003/03/26 14:04:59 $ |
---|
43 | Version: $Revision: 1.42 $ |
---|
44 | |
---|
45 | Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen |
---|
46 | All rights reserved. |
---|
47 | See Copyright.txt or http://www.kitware.com/Copyright.htm for details. |
---|
48 | |
---|
49 | This software is distributed WITHOUT ANY WARRANTY; without even |
---|
50 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
---|
51 | PURPOSE. See the above copyright notice for more information. |
---|
52 | |
---|
53 | =========================================================================*/ |
---|
54 | #include <GL/gl.h> |
---|
55 | #include "GL/glx.h" |
---|
56 | |
---|
57 | #include "vtkXOpenGLOffScreenRenderWindow.h" |
---|
58 | #include "vtk/vtkOpenGLRenderer.h" |
---|
59 | #include "vtk/vtkOpenGLProperty.h" |
---|
60 | #include "vtk/vtkOpenGLTexture.h" |
---|
61 | #include "vtk/vtkOpenGLCamera.h" |
---|
62 | #include "vtk/vtkOpenGLLight.h" |
---|
63 | #include "vtk/vtkOpenGLActor.h" |
---|
64 | #include "vtk/vtkOpenGLPolyDataMapper.h" |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | #include "vtk/vtkToolkits.h" |
---|
69 | |
---|
70 | #include "vtk/vtkCommand.h" |
---|
71 | #include "vtk/vtkIdList.h" |
---|
72 | #include "vtk/vtkObjectFactory.h" |
---|
73 | #include "vtk/vtkRendererCollection.h" |
---|
74 | |
---|
75 | #include <X11/Xlib.h> |
---|
76 | #include <X11/Xutil.h> |
---|
77 | #include <X11/cursorfont.h> |
---|
78 | |
---|
79 | class vtkXOpenGLOffScreenRenderWindow; |
---|
80 | class vtkRenderWindow; |
---|
81 | class vtkXOpenGLOffScreenRenderWindowInternal |
---|
82 | { |
---|
83 | friend class vtkXOpenGLOffScreenRenderWindow; |
---|
84 | private: |
---|
85 | vtkXOpenGLOffScreenRenderWindowInternal(vtkRenderWindow*); |
---|
86 | |
---|
87 | GLXContext ContextId; |
---|
88 | }; |
---|
89 | |
---|
90 | vtkXOpenGLOffScreenRenderWindowInternal::vtkXOpenGLOffScreenRenderWindowInternal( |
---|
91 | vtkRenderWindow * vtkNotUsed(rw)) |
---|
92 | { |
---|
93 | this->ContextId = NULL; |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | vtkCxxRevisionMacro(vtkXOpenGLOffScreenRenderWindow, "$Revision: 0.01 $"); |
---|
98 | vtkStandardNewMacro(vtkXOpenGLOffScreenRenderWindow); |
---|
99 | |
---|
100 | |
---|
101 | #define MAX_LIGHTS 8 |
---|
102 | |
---|
103 | |
---|
104 | XVisualInfo *vtkXOpenGLOffScreenRenderWindowTryForVisual(Display *DisplayId, |
---|
105 | int doublebuff, int stereo, |
---|
106 | int multisamples) |
---|
107 | { |
---|
108 | int index; |
---|
109 | static int attributes[50]; |
---|
110 | |
---|
111 | // setup the default stuff we ask for |
---|
112 | index = 0; |
---|
113 | attributes[index++] = GLX_RGBA; |
---|
114 | attributes[index++] = GLX_RED_SIZE; |
---|
115 | attributes[index++] = 1; |
---|
116 | attributes[index++] = GLX_GREEN_SIZE; |
---|
117 | attributes[index++] = 1; |
---|
118 | attributes[index++] = GLX_BLUE_SIZE; |
---|
119 | attributes[index++] = 1; |
---|
120 | attributes[index++] = GLX_DEPTH_SIZE; |
---|
121 | attributes[index++] = 1; |
---|
122 | if (doublebuff) |
---|
123 | { |
---|
124 | attributes[index++] = GLX_DOUBLEBUFFER; |
---|
125 | } |
---|
126 | if (stereo) |
---|
127 | { |
---|
128 | // also try for STEREO |
---|
129 | attributes[index++] = GLX_STEREO; |
---|
130 | } |
---|
131 | if (multisamples) |
---|
132 | { |
---|
133 | #ifdef GLX_SAMPLE_BUFFERS_SGIS |
---|
134 | attributes[index++] = GLX_SAMPLE_BUFFERS_SGIS; |
---|
135 | attributes[index++] = 1; |
---|
136 | attributes[index++] = GLX_SAMPLES_SGIS; |
---|
137 | attributes[index++] = multisamples; |
---|
138 | #endif |
---|
139 | } |
---|
140 | |
---|
141 | attributes[index++] = None; |
---|
142 | |
---|
143 | return glXChooseVisual(DisplayId, DefaultScreen(DisplayId), attributes ); |
---|
144 | } |
---|
145 | |
---|
146 | XVisualInfo *vtkXOpenGLOffScreenRenderWindow::GetDesiredVisualInfo() |
---|
147 | { |
---|
148 | XVisualInfo *v = NULL; |
---|
149 | int multi; |
---|
150 | int stereo = 0; |
---|
151 | |
---|
152 | // get the default display connection |
---|
153 | if (!this->DisplayId) |
---|
154 | { |
---|
155 | this->DisplayId = XOpenDisplay((char *)NULL); |
---|
156 | if (this->DisplayId == NULL) |
---|
157 | { |
---|
158 | vtkErrorMacro(<< "bad X server connection.\n"); |
---|
159 | } |
---|
160 | this->OwnDisplay = 1; |
---|
161 | } |
---|
162 | |
---|
163 | // try every possibility stoping when we find one that works |
---|
164 | for (stereo = this->StereoCapableWindow; !v && stereo >= 0; stereo--) |
---|
165 | { |
---|
166 | for (multi = this->MultiSamples; !v && multi >= 0; multi--) |
---|
167 | { |
---|
168 | if (v) |
---|
169 | { |
---|
170 | XFree(v); |
---|
171 | } |
---|
172 | v = vtkXOpenGLOffScreenRenderWindowTryForVisual(this->DisplayId, |
---|
173 | this->DoubleBuffer, |
---|
174 | stereo, multi); |
---|
175 | if (v && this->StereoCapableWindow && !stereo) |
---|
176 | { |
---|
177 | // requested a stereo capable window but we could not get one |
---|
178 | this->StereoCapableWindow = 0; |
---|
179 | } |
---|
180 | } |
---|
181 | } |
---|
182 | for (stereo = this->StereoCapableWindow; !v && stereo >= 0; stereo--) |
---|
183 | { |
---|
184 | for (multi = this->MultiSamples; !v && multi >= 0; multi--) |
---|
185 | { |
---|
186 | if (v) |
---|
187 | { |
---|
188 | XFree(v); |
---|
189 | } |
---|
190 | v = vtkXOpenGLOffScreenRenderWindowTryForVisual(this->DisplayId, |
---|
191 | !this->DoubleBuffer, |
---|
192 | stereo, multi); |
---|
193 | if (v) |
---|
194 | { |
---|
195 | this->DoubleBuffer = !this->DoubleBuffer; |
---|
196 | } |
---|
197 | if (v && this->StereoCapableWindow && !stereo) |
---|
198 | { |
---|
199 | // requested a stereo capable window but we could not get one |
---|
200 | this->StereoCapableWindow = 0; |
---|
201 | } |
---|
202 | } |
---|
203 | } |
---|
204 | if (!v) |
---|
205 | { |
---|
206 | vtkErrorMacro(<< "Could not find a decent visual\n"); |
---|
207 | } |
---|
208 | return ( v ); |
---|
209 | } |
---|
210 | |
---|
211 | vtkXOpenGLOffScreenRenderWindow::vtkXOpenGLOffScreenRenderWindow() |
---|
212 | { |
---|
213 | this->ParentId = (Window)NULL; |
---|
214 | this->ScreenSize[0] = 0; |
---|
215 | this->ScreenSize[1] = 0; |
---|
216 | this->OwnDisplay = 0; |
---|
217 | this->CursorHidden = 0; |
---|
218 | this->ForceMakeCurrent = 0; |
---|
219 | this->UsingHardware = 0; |
---|
220 | this->DisplayId = (Display *)NULL; |
---|
221 | this->WindowId = (Window)NULL; |
---|
222 | this->NextWindowId = (Window)NULL; |
---|
223 | this->ColorMap = (Colormap)0; |
---|
224 | this->OwnWindow = 0; |
---|
225 | |
---|
226 | this->Internal = new vtkXOpenGLOffScreenRenderWindowInternal(this); |
---|
227 | |
---|
228 | this->XCArrow = 0; |
---|
229 | this->XCSizeAll = 0; |
---|
230 | this->XCSizeNS = 0; |
---|
231 | this->XCSizeWE = 0; |
---|
232 | this->XCSizeNE = 0; |
---|
233 | this->XCSizeNW = 0; |
---|
234 | this->XCSizeSE = 0; |
---|
235 | this->XCSizeSW = 0; |
---|
236 | |
---|
237 | this->Capabilities = 0; |
---|
238 | } |
---|
239 | |
---|
240 | // free up memory & close the window |
---|
241 | vtkXOpenGLOffScreenRenderWindow::~vtkXOpenGLOffScreenRenderWindow() |
---|
242 | { |
---|
243 | GLuint id; |
---|
244 | short cur_light; |
---|
245 | vtkOpenGLRenderer *ren; |
---|
246 | |
---|
247 | // free the cursors |
---|
248 | if (this->DisplayId) |
---|
249 | { |
---|
250 | if (this->WindowId) |
---|
251 | { |
---|
252 | XUndefineCursor(this->DisplayId,this->WindowId); |
---|
253 | } |
---|
254 | if (this->XCArrow) |
---|
255 | { |
---|
256 | XFreeCursor(this->DisplayId,this->XCArrow); |
---|
257 | } |
---|
258 | if (this->XCSizeAll) |
---|
259 | { |
---|
260 | XFreeCursor(this->DisplayId,this->XCSizeAll); |
---|
261 | } |
---|
262 | if (this->XCSizeNS) |
---|
263 | { |
---|
264 | XFreeCursor(this->DisplayId,this->XCSizeNS); |
---|
265 | } |
---|
266 | if (this->XCSizeWE) |
---|
267 | { |
---|
268 | XFreeCursor(this->DisplayId,this->XCSizeWE); |
---|
269 | } |
---|
270 | if (this->XCSizeNE) |
---|
271 | { |
---|
272 | XFreeCursor(this->DisplayId,this->XCSizeNE); |
---|
273 | } |
---|
274 | if (this->XCSizeNW) |
---|
275 | { |
---|
276 | XFreeCursor(this->DisplayId,this->XCSizeNW); |
---|
277 | } |
---|
278 | if (this->XCSizeSE) |
---|
279 | { |
---|
280 | XFreeCursor(this->DisplayId,this->XCSizeSE); |
---|
281 | } |
---|
282 | if (this->XCSizeSW) |
---|
283 | { |
---|
284 | XFreeCursor(this->DisplayId,this->XCSizeSW); |
---|
285 | } |
---|
286 | } |
---|
287 | |
---|
288 | // make sure we have been initialized |
---|
289 | if (this->Internal->ContextId) |
---|
290 | { |
---|
291 | this->MakeCurrent(); |
---|
292 | |
---|
293 | /* first delete all the old lights */ |
---|
294 | for (cur_light = GL_LIGHT0; cur_light < GL_LIGHT0+MAX_LIGHTS; cur_light++) |
---|
295 | { |
---|
296 | glDisable((GLenum)cur_light); |
---|
297 | } |
---|
298 | |
---|
299 | /* now delete all textures */ |
---|
300 | glDisable(GL_TEXTURE_2D); |
---|
301 | for (int i = 1; i < this->TextureResourceIds->GetNumberOfIds(); i++) |
---|
302 | { |
---|
303 | id = (GLuint) this->TextureResourceIds->GetId(i); |
---|
304 | #ifdef GL_VERSION_1_1 |
---|
305 | if (glIsTexture(id)) |
---|
306 | { |
---|
307 | glDeleteTextures(1, &id); |
---|
308 | } |
---|
309 | #else |
---|
310 | if (glIsList(id)) |
---|
311 | { |
---|
312 | glDeleteLists(id,1); |
---|
313 | } |
---|
314 | #endif |
---|
315 | } |
---|
316 | |
---|
317 | // tell each of the renderers that this render window/graphics context |
---|
318 | // is being removed (the RendererCollection is removed by vtkRenderWindow's |
---|
319 | // destructor) |
---|
320 | this->Renderers->InitTraversal(); |
---|
321 | for ( ren = vtkOpenGLRenderer::SafeDownCast(this->Renderers->GetNextItemAsObject()); |
---|
322 | ren != NULL; |
---|
323 | ren = vtkOpenGLRenderer::SafeDownCast(this->Renderers->GetNextItemAsObject()) ) |
---|
324 | { |
---|
325 | ren->SetRenderWindow(NULL); |
---|
326 | } |
---|
327 | |
---|
328 | glFinish(); |
---|
329 | |
---|
330 | glXDestroyGLXPixmap(this->DisplayId,this->WindowId); |
---|
331 | XFreePixmap(this->DisplayId,this->pixmap); |
---|
332 | |
---|
333 | { |
---|
334 | glXDestroyContext( this->DisplayId, this->Internal->ContextId); |
---|
335 | this->Internal->ContextId = NULL; |
---|
336 | |
---|
337 | // then close the old window |
---|
338 | if (this->OwnWindow && this->DisplayId && this->WindowId) |
---|
339 | { |
---|
340 | XDestroyWindow(this->DisplayId,this->WindowId); |
---|
341 | this->WindowId = (Window)NULL; |
---|
342 | } |
---|
343 | } |
---|
344 | } |
---|
345 | |
---|
346 | if (this->DisplayId) |
---|
347 | { |
---|
348 | XSync(this->DisplayId,0); |
---|
349 | } |
---|
350 | // if we create the display, we'll delete it |
---|
351 | if (this->OwnDisplay && this->DisplayId) |
---|
352 | { |
---|
353 | XCloseDisplay(this->DisplayId); |
---|
354 | this->DisplayId = NULL; |
---|
355 | } |
---|
356 | delete this->Internal; |
---|
357 | delete[] this->Capabilities; |
---|
358 | } |
---|
359 | |
---|
360 | // End the rendering process and display the image. |
---|
361 | void vtkXOpenGLOffScreenRenderWindow::Frame(void) |
---|
362 | { |
---|
363 | this->MakeCurrent(); |
---|
364 | // glFlush(); |
---|
365 | // if (!this->AbortRender && this->DoubleBuffer && this->SwapBuffers) |
---|
366 | // { |
---|
367 | // glXSwapBuffers(this->DisplayId, this->WindowId); |
---|
368 | // vtkDebugMacro(<< " glXSwapBuffers\n"); |
---|
369 | // } |
---|
370 | } |
---|
371 | |
---|
372 | // |
---|
373 | // Set the variable that indicates that we want a stereo capable window |
---|
374 | // be created. This method can only be called before a window is realized. |
---|
375 | // |
---|
376 | void vtkXOpenGLOffScreenRenderWindow::SetStereoCapableWindow(int capable) |
---|
377 | { |
---|
378 | if (!this->WindowId) |
---|
379 | { |
---|
380 | vtkOpenGLRenderWindow::SetStereoCapableWindow(capable); |
---|
381 | } |
---|
382 | else |
---|
383 | { |
---|
384 | vtkWarningMacro(<< "Requesting a StereoCapableWindow must be performed " |
---|
385 | << "before the window is realized, i.e. before a render."); |
---|
386 | } |
---|
387 | } |
---|
388 | |
---|
389 | // Initialize the window for rendering. |
---|
390 | void vtkXOpenGLOffScreenRenderWindow::WindowInitialize (void) |
---|
391 | { |
---|
392 | XVisualInfo *v, matcher; |
---|
393 | int width = ((this->Size[0] > 0) ? this->Size[0] : 300); |
---|
394 | int height = ((this->Size[1] > 0) ? this->Size[1] : 300); |
---|
395 | |
---|
396 | // get the default display connection |
---|
397 | if (!this->DisplayId) |
---|
398 | { |
---|
399 | this->DisplayId = XOpenDisplay((char *)NULL); |
---|
400 | if (this->DisplayId == NULL) |
---|
401 | { |
---|
402 | vtkErrorMacro(<<"bad X server connection.\n"); |
---|
403 | } |
---|
404 | } |
---|
405 | |
---|
406 | // get visual info and set up pixmap buffer |
---|
407 | int attributeList[] = { GLX_RGBA, GLX_RED_SIZE, 1, |
---|
408 | GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, |
---|
409 | GLX_DEPTH_SIZE, 1, None }; |
---|
410 | printf("glxChooseVis DPY=%u SCRN=%u \n",(unsigned int)(this->DisplayId), |
---|
411 | DefaultScreen(this->DisplayId)); |
---|
412 | v = glXChooseVisual(this->DisplayId, |
---|
413 | DefaultScreen(this->DisplayId), |
---|
414 | attributeList); |
---|
415 | fprintf(stderr,"Visual selected.\n"); |
---|
416 | this->Internal->ContextId = glXCreateContext(this->DisplayId,v,0,GL_FALSE); |
---|
417 | /* create offscreen pixmap to render to (same depth as RootWindow) */ |
---|
418 | this->pixmap = XCreatePixmap(this->DisplayId, |
---|
419 | RootWindow(this->DisplayId,v->screen), |
---|
420 | width, |
---|
421 | height, |
---|
422 | v->depth); |
---|
423 | printf("Depth=%d\n",v->depth); |
---|
424 | this->WindowId= glXCreateGLXPixmap(this->DisplayId,v,this->pixmap); |
---|
425 | |
---|
426 | if (v) |
---|
427 | { |
---|
428 | XFree(v); |
---|
429 | } |
---|
430 | |
---|
431 | this->MakeCurrent(); |
---|
432 | vtkDebugMacro(<< " glMatrixMode ModelView\n"); |
---|
433 | glMatrixMode( GL_MODELVIEW ); |
---|
434 | vtkDebugMacro(<< " zbuffer enabled\n"); |
---|
435 | glDepthFunc( GL_LEQUAL ); |
---|
436 | glEnable( GL_DEPTH_TEST ); |
---|
437 | vtkDebugMacro(" texture stuff\n"); |
---|
438 | glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); |
---|
439 | // initialize blending for transparency |
---|
440 | vtkDebugMacro(<< " blend func stuff\n"); |
---|
441 | glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); |
---|
442 | glEnable(GL_BLEND); |
---|
443 | glEnable( GL_NORMALIZE ); |
---|
444 | glAlphaFunc(GL_GREATER,0); |
---|
445 | this->Mapped = 0; // if its mapped, then it trys windowgetattributes which fails! |
---|
446 | this->SwapBuffers = 0; |
---|
447 | this->DoubleBuffer = 0; |
---|
448 | } |
---|
449 | |
---|
450 | // Initialize the rendering window. |
---|
451 | void vtkXOpenGLOffScreenRenderWindow::Initialize (void) |
---|
452 | { |
---|
453 | // make sure we havent already been initialized |
---|
454 | if (this->Internal->ContextId) |
---|
455 | { |
---|
456 | return; |
---|
457 | } |
---|
458 | |
---|
459 | // now initialize the window |
---|
460 | this->WindowInitialize(); |
---|
461 | } |
---|
462 | |
---|
463 | // Change the window to fill the entire screen. |
---|
464 | void vtkXOpenGLOffScreenRenderWindow::SetFullScreen(int arg) |
---|
465 | { |
---|
466 | // Just Disable it |
---|
467 | return; |
---|
468 | } |
---|
469 | |
---|
470 | // Set the preferred window size to full screen. |
---|
471 | void vtkXOpenGLOffScreenRenderWindow::PrefFullScreen() |
---|
472 | { |
---|
473 | |
---|
474 | // limit the off screen size |
---|
475 | this->Size[0] = 1280; |
---|
476 | this->Size[1] = 1024; |
---|
477 | |
---|
478 | // don't show borders |
---|
479 | this->Borders = 0; |
---|
480 | } |
---|
481 | |
---|
482 | // Resize the window. |
---|
483 | void vtkXOpenGLOffScreenRenderWindow::WindowRemap() |
---|
484 | { |
---|
485 | short cur_light; |
---|
486 | |
---|
487 | /* first delete all the old lights */ |
---|
488 | for (cur_light = GL_LIGHT0; cur_light < GL_LIGHT0+MAX_LIGHTS; cur_light++) |
---|
489 | { |
---|
490 | glDisable((GLenum)cur_light); |
---|
491 | } |
---|
492 | { |
---|
493 | glXDestroyContext( this->DisplayId, this->Internal->ContextId); |
---|
494 | // then close the old window |
---|
495 | if (this->OwnWindow) |
---|
496 | { |
---|
497 | XDestroyWindow(this->DisplayId,this->WindowId); |
---|
498 | } |
---|
499 | } |
---|
500 | |
---|
501 | |
---|
502 | // set the default windowid |
---|
503 | this->WindowId = this->NextWindowId; |
---|
504 | this->NextWindowId = (Window)NULL; |
---|
505 | |
---|
506 | // configure the window |
---|
507 | this->WindowInitialize(); |
---|
508 | } |
---|
509 | |
---|
510 | // Begin the rendering process. |
---|
511 | void vtkXOpenGLOffScreenRenderWindow::Start(void) |
---|
512 | { |
---|
513 | // if the renderer has not been initialized, do so now |
---|
514 | if (!this->Internal->ContextId) |
---|
515 | { |
---|
516 | this->Initialize(); |
---|
517 | } |
---|
518 | |
---|
519 | // set the current window |
---|
520 | this->MakeCurrent(); |
---|
521 | } |
---|
522 | |
---|
523 | |
---|
524 | // Specify the size of the rendering window. |
---|
525 | void vtkXOpenGLOffScreenRenderWindow::SetSize(int x,int y) |
---|
526 | { |
---|
527 | if ((this->Size[0] != x)||(this->Size[1] != y)) |
---|
528 | { |
---|
529 | this->Modified(); |
---|
530 | this->Size[0] = x; |
---|
531 | this->Size[1] = y; |
---|
532 | } |
---|
533 | |
---|
534 | // if we arent mappen then just set the ivars |
---|
535 | if (!this->Mapped) |
---|
536 | { |
---|
537 | return; |
---|
538 | } |
---|
539 | |
---|
540 | XResizeWindow(this->DisplayId,this->WindowId,x,y); |
---|
541 | XSync(this->DisplayId,False); |
---|
542 | |
---|
543 | } |
---|
544 | |
---|
545 | |
---|
546 | |
---|
547 | int vtkXOpenGLOffScreenRenderWindow::GetDesiredDepth() |
---|
548 | { |
---|
549 | XVisualInfo *v; |
---|
550 | int depth = 0; |
---|
551 | |
---|
552 | // get the default visual to use |
---|
553 | v = this->GetDesiredVisualInfo(); |
---|
554 | |
---|
555 | if (v) |
---|
556 | { |
---|
557 | depth = v->depth; |
---|
558 | XFree(v); |
---|
559 | } |
---|
560 | |
---|
561 | return depth; |
---|
562 | } |
---|
563 | |
---|
564 | // Get a visual from the windowing system. |
---|
565 | Visual *vtkXOpenGLOffScreenRenderWindow::GetDesiredVisual () |
---|
566 | { |
---|
567 | XVisualInfo *v; |
---|
568 | Visual *vis=0; |
---|
569 | |
---|
570 | // get the default visual to use |
---|
571 | v = this->GetDesiredVisualInfo(); |
---|
572 | |
---|
573 | if (v) |
---|
574 | { |
---|
575 | vis = v->visual; |
---|
576 | XFree(v); |
---|
577 | } |
---|
578 | |
---|
579 | return vis; |
---|
580 | } |
---|
581 | |
---|
582 | |
---|
583 | // Get a colormap from the windowing system. |
---|
584 | Colormap vtkXOpenGLOffScreenRenderWindow::GetDesiredColormap () |
---|
585 | { |
---|
586 | XVisualInfo *v; |
---|
587 | |
---|
588 | if (this->ColorMap) return this->ColorMap; |
---|
589 | |
---|
590 | // get the default visual to use |
---|
591 | v = this->GetDesiredVisualInfo(); |
---|
592 | |
---|
593 | if (v) |
---|
594 | { |
---|
595 | this->ColorMap = XCreateColormap(this->DisplayId, |
---|
596 | RootWindow( this->DisplayId, v->screen), |
---|
597 | v->visual, AllocNone ); |
---|
598 | XFree(v); |
---|
599 | } |
---|
600 | |
---|
601 | return this->ColorMap; |
---|
602 | } |
---|
603 | |
---|
604 | void vtkXOpenGLOffScreenRenderWindow::PrintSelf(ostream& os, vtkIndent indent) |
---|
605 | { |
---|
606 | this->Superclass::PrintSelf(os,indent); |
---|
607 | |
---|
608 | os << indent << "ContextId: " << this->Internal->ContextId << "\n"; |
---|
609 | // #ifdef VTK_OPENGL_HAS_OSMESA |
---|
610 | // os << indent << "OffScreenContextId: " << this->Internal->OffScreenContextId << "\n"; |
---|
611 | // #endif |
---|
612 | os << indent << "Color Map: " << this->ColorMap << "\n"; |
---|
613 | os << indent << "Display Id: " << this->GetDisplayId() << "\n"; |
---|
614 | os << indent << "Next Window Id: " << this->NextWindowId << "\n"; |
---|
615 | os << indent << "Window Id: " << this->GetWindowId() << "\n"; |
---|
616 | } |
---|
617 | |
---|
618 | // the following can be useful for debugging XErrors |
---|
619 | // When uncommented (along with the lines in MakeCurrent) |
---|
620 | // it will cause a segfault upon an XError instead of |
---|
621 | // the normal XError handler |
---|
622 | // extern "C" {int vtkXError(Display *display, XErrorEvent *err) |
---|
623 | // { |
---|
624 | // // cause a segfault |
---|
625 | // *(float *)(0x01) = 1.0; |
---|
626 | // return 1; |
---|
627 | // }} |
---|
628 | |
---|
629 | void vtkXOpenGLOffScreenRenderWindow::MakeCurrent() |
---|
630 | { |
---|
631 | // when debugging XErrors uncomment the following lines |
---|
632 | // if (this->DisplayId) |
---|
633 | // { |
---|
634 | // XSynchronize(this->DisplayId,1); |
---|
635 | // } |
---|
636 | // XSetErrorHandler(vtkXError); |
---|
637 | |
---|
638 | { |
---|
639 | if (this->Internal->ContextId && ((this->Internal->ContextId != glXGetCurrentContext()) || this->ForceMakeCurrent)) |
---|
640 | { |
---|
641 | glXMakeCurrent(this->DisplayId,this->WindowId,this->Internal->ContextId); |
---|
642 | this->ForceMakeCurrent = 0; |
---|
643 | } |
---|
644 | } |
---|
645 | } |
---|
646 | |
---|
647 | void vtkXOpenGLOffScreenRenderWindow::SetForceMakeCurrent() |
---|
648 | { |
---|
649 | this->ForceMakeCurrent = 1; |
---|
650 | } |
---|
651 | |
---|
652 | int vtkXOpenGLOffScreenRenderWindowFoundMatch; |
---|
653 | |
---|
654 | extern "C" |
---|
655 | { |
---|
656 | Bool vtkXOpenGLOffScreenRenderWindowPredProc(Display *vtkNotUsed(disp), |
---|
657 | XEvent *event, |
---|
658 | char *arg) |
---|
659 | { |
---|
660 | Window win = (Window)arg; |
---|
661 | |
---|
662 | if (((reinterpret_cast<XAnyEvent *>(event))->window == win) && |
---|
663 | ((event->type == ButtonPress))) |
---|
664 | { |
---|
665 | vtkXOpenGLOffScreenRenderWindowFoundMatch = 1; |
---|
666 | } |
---|
667 | |
---|
668 | return 0; |
---|
669 | } |
---|
670 | } |
---|
671 | |
---|
672 | void *vtkXOpenGLOffScreenRenderWindow::GetGenericContext() |
---|
673 | { |
---|
674 | static GC gc = (GC) NULL; |
---|
675 | if (!gc) gc = XCreateGC(this->DisplayId, this->WindowId, 0, 0); |
---|
676 | return (void *) gc; |
---|
677 | } |
---|
678 | |
---|
679 | int vtkXOpenGLOffScreenRenderWindow::GetEventPending() |
---|
680 | { |
---|
681 | XEvent report; |
---|
682 | |
---|
683 | vtkXOpenGLOffScreenRenderWindowFoundMatch = 0; |
---|
684 | XCheckIfEvent(this->DisplayId, &report, vtkXOpenGLOffScreenRenderWindowPredProc, |
---|
685 | (char *)this->WindowId); |
---|
686 | return vtkXOpenGLOffScreenRenderWindowFoundMatch; |
---|
687 | } |
---|
688 | |
---|
689 | // Get the size of the screen in pixels |
---|
690 | int *vtkXOpenGLOffScreenRenderWindow::GetScreenSize() |
---|
691 | { |
---|
692 | // get the default display connection |
---|
693 | if (!this->DisplayId) |
---|
694 | { |
---|
695 | this->DisplayId = XOpenDisplay((char *)NULL); |
---|
696 | if (this->DisplayId == NULL) |
---|
697 | { |
---|
698 | vtkErrorMacro(<< "bad X server connection.\n"); |
---|
699 | } |
---|
700 | else |
---|
701 | { |
---|
702 | this->OwnDisplay = 1; |
---|
703 | } |
---|
704 | } |
---|
705 | |
---|
706 | this->ScreenSize[0] = |
---|
707 | DisplayWidth(this->DisplayId, DefaultScreen(this->DisplayId)); |
---|
708 | this->ScreenSize[1] = |
---|
709 | DisplayHeight(this->DisplayId, DefaultScreen(this->DisplayId)); |
---|
710 | |
---|
711 | return this->ScreenSize; |
---|
712 | } |
---|
713 | |
---|
714 | // Get this RenderWindow's X display id. |
---|
715 | Display *vtkXOpenGLOffScreenRenderWindow::GetDisplayId() |
---|
716 | { |
---|
717 | // get the default display connection |
---|
718 | if (!this->DisplayId) |
---|
719 | { |
---|
720 | this->DisplayId = XOpenDisplay((char *)NULL); |
---|
721 | if (this->DisplayId == NULL) |
---|
722 | { |
---|
723 | vtkErrorMacro(<< "bad X server connection.\n"); |
---|
724 | } |
---|
725 | this->OwnDisplay = 1; |
---|
726 | } |
---|
727 | vtkDebugMacro(<< "Returning DisplayId of " << (void *)this->DisplayId << "\n"); |
---|
728 | |
---|
729 | return this->DisplayId; |
---|
730 | } |
---|
731 | |
---|
732 | // Get this RenderWindow's parent X window id. |
---|
733 | Window vtkXOpenGLOffScreenRenderWindow::GetParentId() |
---|
734 | { |
---|
735 | vtkDebugMacro(<< "Returning ParentId of " << (void *)this->ParentId << "\n"); |
---|
736 | return this->ParentId; |
---|
737 | } |
---|
738 | |
---|
739 | // Get this RenderWindow's X window id. |
---|
740 | Window vtkXOpenGLOffScreenRenderWindow::GetWindowId() |
---|
741 | { |
---|
742 | vtkDebugMacro(<< "Returning WindowId of " << (void *)this->WindowId << "\n"); |
---|
743 | return this->WindowId; |
---|
744 | } |
---|
745 | |
---|
746 | // Sets the parent of the window that WILL BE created. |
---|
747 | void vtkXOpenGLOffScreenRenderWindow::SetParentId(Window arg) |
---|
748 | { |
---|
749 | // if (this->ParentId) |
---|
750 | // { |
---|
751 | // vtkErrorMacro("ParentId is already set."); |
---|
752 | // return; |
---|
753 | // } |
---|
754 | |
---|
755 | vtkDebugMacro(<< "Setting ParentId to " << (void *)arg << "\n"); |
---|
756 | |
---|
757 | this->ParentId = arg; |
---|
758 | } |
---|
759 | |
---|
760 | // Set this RenderWindow's X window id to a pre-existing window. |
---|
761 | void vtkXOpenGLOffScreenRenderWindow::SetWindowId(Window arg) |
---|
762 | { |
---|
763 | vtkDebugMacro(<< "Setting WindowId to " << (void *)arg << "\n"); |
---|
764 | |
---|
765 | this->WindowId = arg; |
---|
766 | |
---|
767 | if (this->CursorHidden) |
---|
768 | { |
---|
769 | this->CursorHidden = 0; |
---|
770 | this->HideCursor(); |
---|
771 | } |
---|
772 | } |
---|
773 | |
---|
774 | // Set this RenderWindow's X window id to a pre-existing window. |
---|
775 | void vtkXOpenGLOffScreenRenderWindow::SetWindowInfo(char *info) |
---|
776 | { |
---|
777 | int tmp; |
---|
778 | |
---|
779 | // get the default display connection |
---|
780 | if (!this->DisplayId) |
---|
781 | { |
---|
782 | this->DisplayId = XOpenDisplay((char *)NULL); |
---|
783 | if (this->DisplayId == NULL) |
---|
784 | { |
---|
785 | vtkErrorMacro(<< "bad X server connection.\n"); |
---|
786 | } |
---|
787 | else |
---|
788 | { |
---|
789 | this->OwnDisplay = 1; |
---|
790 | } |
---|
791 | } |
---|
792 | |
---|
793 | sscanf(info,"%i",&tmp); |
---|
794 | |
---|
795 | this->SetWindowId(tmp); |
---|
796 | } |
---|
797 | |
---|
798 | // Set this RenderWindow's X window id to a pre-existing window. |
---|
799 | void vtkXOpenGLOffScreenRenderWindow::SetNextWindowInfo(char *info) |
---|
800 | { |
---|
801 | int tmp; |
---|
802 | sscanf(info,"%i",&tmp); |
---|
803 | |
---|
804 | this->SetNextWindowId((Window)tmp); |
---|
805 | } |
---|
806 | |
---|
807 | // Sets the X window id of the window that WILL BE created. |
---|
808 | void vtkXOpenGLOffScreenRenderWindow::SetParentInfo(char *info) |
---|
809 | { |
---|
810 | int tmp; |
---|
811 | |
---|
812 | // get the default display connection |
---|
813 | if (!this->DisplayId) |
---|
814 | { |
---|
815 | this->DisplayId = XOpenDisplay((char *)NULL); |
---|
816 | if (this->DisplayId == NULL) |
---|
817 | { |
---|
818 | vtkErrorMacro(<< "bad X server connection.\n"); |
---|
819 | } |
---|
820 | else |
---|
821 | { |
---|
822 | this->OwnDisplay = 1; |
---|
823 | } |
---|
824 | } |
---|
825 | |
---|
826 | sscanf(info,"%i",&tmp); |
---|
827 | |
---|
828 | this->SetParentId(tmp); |
---|
829 | } |
---|
830 | |
---|
831 | void vtkXOpenGLOffScreenRenderWindow::SetWindowId(void *arg) |
---|
832 | { |
---|
833 | this->SetWindowId((Window)arg); |
---|
834 | } |
---|
835 | void vtkXOpenGLOffScreenRenderWindow::SetParentId(void *arg) |
---|
836 | { |
---|
837 | this->SetParentId((Window)arg); |
---|
838 | } |
---|
839 | |
---|
840 | const char* vtkXOpenGLOffScreenRenderWindow::ReportCapabilities() |
---|
841 | { |
---|
842 | MakeCurrent(); |
---|
843 | |
---|
844 | if (!this->DisplayId) |
---|
845 | { |
---|
846 | return "display id not set"; |
---|
847 | } |
---|
848 | |
---|
849 | int scrnum = DefaultScreen(this->DisplayId); |
---|
850 | const char *serverVendor = glXQueryServerString(this->DisplayId, scrnum, GLX_VENDOR); |
---|
851 | const char *serverVersion = glXQueryServerString(this->DisplayId, scrnum, GLX_VERSION); |
---|
852 | const char *serverExtensions = glXQueryServerString(this->DisplayId, scrnum, GLX_EXTENSIONS); |
---|
853 | const char *clientVendor = glXGetClientString(this->DisplayId, GLX_VENDOR); |
---|
854 | const char *clientVersion = glXGetClientString(this->DisplayId, GLX_VERSION); |
---|
855 | const char *clientExtensions = glXGetClientString(this->DisplayId, GLX_EXTENSIONS); |
---|
856 | const char *glxExtensions = glXQueryExtensionsString(this->DisplayId, scrnum); |
---|
857 | const char *glVendor = (const char *) glGetString(GL_VENDOR); |
---|
858 | const char *glRenderer = (const char *) glGetString(GL_RENDERER); |
---|
859 | const char *glVersion = (const char *) glGetString(GL_VERSION); |
---|
860 | const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS); |
---|
861 | |
---|
862 | ostrstream strm; |
---|
863 | strm << "server glx vendor string: " << serverVendor << endl; |
---|
864 | strm << "server glx version string: " << serverVersion << endl; |
---|
865 | strm << "server glx extensions: " << serverExtensions << endl; |
---|
866 | strm << "client glx vendor string: " << clientVendor << endl; |
---|
867 | strm << "client glx version string: " << clientVersion << endl; |
---|
868 | strm << "client glx extensions: " << clientExtensions << endl; |
---|
869 | strm << "glx extensions: " << glxExtensions << endl; |
---|
870 | strm << "OpenGL vendor string: " << glVendor << endl; |
---|
871 | strm << "OpenGL renderer string: " << glRenderer << endl; |
---|
872 | strm << "OpenGL version string: " << glVersion << endl; |
---|
873 | strm << "OpenGL extensions: " << glExtensions << endl; |
---|
874 | strm << "X Extensions: "; |
---|
875 | |
---|
876 | int n = 0; |
---|
877 | char **extlist = XListExtensions(this->DisplayId, &n); |
---|
878 | |
---|
879 | for (int i = 0; i < n; i++) |
---|
880 | { |
---|
881 | if (i != n-1) { |
---|
882 | strm << extlist[i] << ", "; |
---|
883 | } else { |
---|
884 | strm << extlist[i] << endl; |
---|
885 | } |
---|
886 | } |
---|
887 | strm << ends; |
---|
888 | delete[] this->Capabilities; |
---|
889 | this->Capabilities = strm.str(); |
---|
890 | return this->Capabilities; |
---|
891 | } |
---|
892 | |
---|
893 | int vtkXOpenGLOffScreenRenderWindow::SupportsOpenGL() |
---|
894 | { |
---|
895 | MakeCurrent(); |
---|
896 | if (!this->DisplayId) |
---|
897 | { |
---|
898 | return 0; |
---|
899 | } |
---|
900 | |
---|
901 | int value = 0; |
---|
902 | XVisualInfo *v = this->GetDesiredVisualInfo(); |
---|
903 | if (v) |
---|
904 | { |
---|
905 | glXGetConfig(this->DisplayId, v, GLX_USE_GL, &value); |
---|
906 | } |
---|
907 | |
---|
908 | return value; |
---|
909 | } |
---|
910 | |
---|
911 | |
---|
912 | int vtkXOpenGLOffScreenRenderWindow::IsDirect() |
---|
913 | { |
---|
914 | MakeCurrent(); |
---|
915 | if (!this->DisplayId || !this->Internal->ContextId) |
---|
916 | { |
---|
917 | return 0; |
---|
918 | } |
---|
919 | this->UsingHardware = glXIsDirect(this->DisplayId, |
---|
920 | this->Internal->ContextId) ? 1:0; |
---|
921 | return this->UsingHardware; |
---|
922 | } |
---|
923 | |
---|
924 | |
---|
925 | void vtkXOpenGLOffScreenRenderWindow::SetWindowName(const char * cname) |
---|
926 | { |
---|
927 | char *name = new char[ strlen(cname)+1 ]; |
---|
928 | strcpy(name, cname); |
---|
929 | XTextProperty win_name_text_prop; |
---|
930 | |
---|
931 | vtkOpenGLRenderWindow::SetWindowName( name ); |
---|
932 | |
---|
933 | if (this->Mapped) |
---|
934 | { |
---|
935 | if( XStringListToTextProperty( &name, 1, &win_name_text_prop ) == 0 ) |
---|
936 | { |
---|
937 | XFree (win_name_text_prop.value); |
---|
938 | vtkWarningMacro(<< "Can't rename window"); |
---|
939 | delete [] name; |
---|
940 | return; |
---|
941 | } |
---|
942 | |
---|
943 | XSetWMName( this->DisplayId, this->WindowId, &win_name_text_prop ); |
---|
944 | XSetWMIconName( this->DisplayId, this->WindowId, &win_name_text_prop ); |
---|
945 | XFree (win_name_text_prop.value); |
---|
946 | } |
---|
947 | delete [] name; |
---|
948 | } |
---|
949 | |
---|
950 | |
---|
951 | // Specify the X window id to use if a WindowRemap is done. |
---|
952 | void vtkXOpenGLOffScreenRenderWindow::SetNextWindowId(Window arg) |
---|
953 | { |
---|
954 | vtkDebugMacro(<< "Setting NextWindowId to " << (void *)arg << "\n"); |
---|
955 | |
---|
956 | this->NextWindowId = arg; |
---|
957 | } |
---|
958 | |
---|
959 | void vtkXOpenGLOffScreenRenderWindow::SetNextWindowId(void *arg) |
---|
960 | { |
---|
961 | this->SetNextWindowId((Window)arg); |
---|
962 | } |
---|
963 | |
---|
964 | |
---|
965 | // Set the X display id for this RenderWindow to use to a pre-existing |
---|
966 | // X display id. |
---|
967 | void vtkXOpenGLOffScreenRenderWindow::SetDisplayId(Display *arg) |
---|
968 | { |
---|
969 | vtkDebugMacro(<< "Setting DisplayId to " << (void *)arg << "\n"); |
---|
970 | |
---|
971 | this->DisplayId = arg; |
---|
972 | this->OwnDisplay = 0; |
---|
973 | |
---|
974 | } |
---|
975 | void vtkXOpenGLOffScreenRenderWindow::SetDisplayId(void *arg) |
---|
976 | { |
---|
977 | this->SetDisplayId((Display *)arg); |
---|
978 | this->OwnDisplay = 0; |
---|
979 | } |
---|
980 | |
---|
981 | void vtkXOpenGLOffScreenRenderWindow::Render() |
---|
982 | { |
---|
983 | XWindowAttributes attribs; |
---|
984 | |
---|
985 | // To avoid the expensive XGetWindowAttributes call, |
---|
986 | // compute size at the start of a render and use |
---|
987 | // the ivar other times. |
---|
988 | if (this->Mapped) |
---|
989 | { |
---|
990 | // Find the current window size |
---|
991 | XGetWindowAttributes(this->DisplayId, |
---|
992 | this->WindowId, &attribs); |
---|
993 | |
---|
994 | this->Size[0] = attribs.width; |
---|
995 | this->Size[1] = attribs.height; |
---|
996 | } |
---|
997 | |
---|
998 | // Now do the superclass stuff |
---|
999 | this->vtkOpenGLRenderWindow::Render(); |
---|
1000 | } |
---|
1001 | |
---|
1002 | //---------------------------------------------------------------------------- |
---|
1003 | void vtkXOpenGLOffScreenRenderWindow::HideCursor() |
---|
1004 | { |
---|
1005 | static char blankBits[] = { |
---|
1006 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
---|
1007 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
---|
1008 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
---|
1009 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
---|
1010 | |
---|
1011 | static XColor black = { 0, 0, 0, 0, 0, 0 }; |
---|
1012 | |
---|
1013 | if (!this->DisplayId || !this->WindowId) |
---|
1014 | { |
---|
1015 | this->CursorHidden = 1; |
---|
1016 | } |
---|
1017 | else if (!this->CursorHidden) |
---|
1018 | { |
---|
1019 | Pixmap blankPixmap = XCreateBitmapFromData(this->DisplayId, |
---|
1020 | this->WindowId, |
---|
1021 | blankBits, 16, 16); |
---|
1022 | |
---|
1023 | Cursor blankCursor = XCreatePixmapCursor(this->DisplayId, blankPixmap, |
---|
1024 | blankPixmap, &black, &black, |
---|
1025 | 7, 7); |
---|
1026 | |
---|
1027 | XDefineCursor(this->DisplayId, this->WindowId, blankCursor); |
---|
1028 | |
---|
1029 | XFreePixmap(this->DisplayId, blankPixmap); |
---|
1030 | |
---|
1031 | this->CursorHidden = 1; |
---|
1032 | } |
---|
1033 | } |
---|
1034 | |
---|
1035 | //---------------------------------------------------------------------------- |
---|
1036 | void vtkXOpenGLOffScreenRenderWindow::ShowCursor() |
---|
1037 | { |
---|
1038 | if (!this->DisplayId || !this->WindowId) |
---|
1039 | { |
---|
1040 | this->CursorHidden = 0; |
---|
1041 | } |
---|
1042 | else if (this->CursorHidden) |
---|
1043 | { |
---|
1044 | XUndefineCursor(this->DisplayId, this->WindowId); |
---|
1045 | this->CursorHidden = 0; |
---|
1046 | } |
---|
1047 | } |
---|
1048 | |
---|
1049 | |
---|
1050 | |
---|
1051 | // This probably has been moved to superclass. |
---|
1052 | void *vtkXOpenGLOffScreenRenderWindow::GetGenericWindowId() |
---|
1053 | { |
---|
1054 | return (void *)this->WindowId; |
---|
1055 | } |
---|
1056 | |
---|
1057 | void vtkXOpenGLOffScreenRenderWindow::SetCurrentCursor(int shape) |
---|
1058 | { |
---|
1059 | if ( this->InvokeEvent(vtkCommand::CursorChangedEvent,&shape) ) |
---|
1060 | { |
---|
1061 | return; |
---|
1062 | } |
---|
1063 | this->Superclass::SetCurrentCursor(shape); |
---|
1064 | if (!this->DisplayId || !this->WindowId) |
---|
1065 | { |
---|
1066 | return; |
---|
1067 | } |
---|
1068 | |
---|
1069 | if (shape == VTK_CURSOR_DEFAULT) |
---|
1070 | { |
---|
1071 | XUndefineCursor(this->DisplayId,this->WindowId); |
---|
1072 | return; |
---|
1073 | } |
---|
1074 | |
---|
1075 | switch (shape) |
---|
1076 | { |
---|
1077 | case VTK_CURSOR_ARROW: |
---|
1078 | if (!this->XCArrow) |
---|
1079 | { |
---|
1080 | this->XCArrow = XCreateFontCursor(this->DisplayId, XC_top_left_arrow); |
---|
1081 | } |
---|
1082 | XDefineCursor(this->DisplayId, this->WindowId, this->XCArrow); |
---|
1083 | break; |
---|
1084 | case VTK_CURSOR_SIZEALL: |
---|
1085 | if (!this->XCSizeAll) |
---|
1086 | { |
---|
1087 | this->XCSizeAll = XCreateFontCursor(this->DisplayId, XC_fleur); |
---|
1088 | } |
---|
1089 | XDefineCursor(this->DisplayId, this->WindowId, this->XCSizeAll); |
---|
1090 | break; |
---|
1091 | case VTK_CURSOR_SIZENS: |
---|
1092 | if (!this->XCSizeNS) |
---|
1093 | { |
---|
1094 | this->XCSizeNS = XCreateFontCursor(this->DisplayId, |
---|
1095 | XC_sb_v_double_arrow); |
---|
1096 | } |
---|
1097 | XDefineCursor(this->DisplayId, this->WindowId, this->XCSizeNS); |
---|
1098 | break; |
---|
1099 | case VTK_CURSOR_SIZEWE: |
---|
1100 | if (!this->XCSizeWE) |
---|
1101 | { |
---|
1102 | this->XCSizeWE = XCreateFontCursor(this->DisplayId, |
---|
1103 | XC_sb_h_double_arrow); |
---|
1104 | } |
---|
1105 | XDefineCursor(this->DisplayId, this->WindowId, this->XCSizeWE); |
---|
1106 | break; |
---|
1107 | case VTK_CURSOR_SIZENE: |
---|
1108 | if (!this->XCSizeNE) |
---|
1109 | { |
---|
1110 | this->XCSizeNE = XCreateFontCursor(this->DisplayId, |
---|
1111 | XC_top_right_corner); |
---|
1112 | } |
---|
1113 | XDefineCursor(this->DisplayId, this->WindowId, this->XCSizeNE); |
---|
1114 | break; |
---|
1115 | case VTK_CURSOR_SIZENW: |
---|
1116 | if (!this->XCSizeNW) |
---|
1117 | { |
---|
1118 | this->XCSizeNW = XCreateFontCursor(this->DisplayId, |
---|
1119 | XC_top_left_corner); |
---|
1120 | } |
---|
1121 | XDefineCursor(this->DisplayId, this->WindowId, this->XCSizeNW); |
---|
1122 | break; |
---|
1123 | case VTK_CURSOR_SIZESE: |
---|
1124 | if (!this->XCSizeSE) |
---|
1125 | { |
---|
1126 | this->XCSizeSE = XCreateFontCursor(this->DisplayId, |
---|
1127 | XC_bottom_right_corner); |
---|
1128 | } |
---|
1129 | XDefineCursor(this->DisplayId, this->WindowId, this->XCSizeSE); |
---|
1130 | break; |
---|
1131 | case VTK_CURSOR_SIZESW: |
---|
1132 | if (!this->XCSizeSW) |
---|
1133 | { |
---|
1134 | this->XCSizeSW = XCreateFontCursor(this->DisplayId, |
---|
1135 | XC_bottom_left_corner); |
---|
1136 | } |
---|
1137 | XDefineCursor(this->DisplayId, this->WindowId, this->XCSizeSW); |
---|
1138 | break; |
---|
1139 | } |
---|
1140 | } |
---|