root/OpenSceneGraph/trunk/src/osgPlugins/cfg/RenderSurface.cpp @ 13041

Revision 13041, 14.6 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1/* -*-c++-*- Producer - Copyright (C) 2001-2004  Don Burns
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12 */
13
14#include <stdlib.h>
15#include <string.h>
16
17#include "RenderSurface.h"
18
19using namespace std;
20using namespace osgProducer;
21
22const std::string RenderSurface::defaultWindowName = std::string(" *** Producer::RenderSurface *** ");
23
24const unsigned int RenderSurface::UnknownDimension = 0xFFFFFFFF;
25const unsigned int RenderSurface::UnknownAmount = 0xFFFFFFFF;
26unsigned int RenderSurface::_numScreens = RenderSurface::UnknownAmount;
27
28bool RenderSurface::_shareAllGLContexts = false;
29//GLContext RenderSurface::_globallySharedGLContext  = 0L;
30
31void RenderSurface::shareAllGLContexts(bool flag)
32{
33    _shareAllGLContexts = flag;
34}
35
36bool RenderSurface::allGLContextsAreShared()
37{
38    return _shareAllGLContexts;
39}
40
41
42const std::string &RenderSurface::getDefaultWindowName()
43{
44    return defaultWindowName;
45}
46
47RenderSurface::RenderSurface( void )
48{
49    _drawableType    = DrawableType_Window;
50    _hostname        = "";
51    _displayNum     = 0;
52//     _screen          = 0;
53    _mayFullScreen   = true;
54    _isFullScreen    = true;
55
56    // This used to be #ifdefed for the X11 implementation
57    // but the code is pure C++ and should compile anywhere
58    // The _dislayNum variable is used by CGL as well.
59    char *envptr = getenv( "DISPLAY" );
60    if( envptr != NULL && *envptr != 0 )
61    {
62        size_t p0 = 0;
63        size_t p1 = string(envptr).find(":", p0);
64        _hostname = string(envptr).substr(p0,p1);
65        p0 = p1+1;
66        p1 = string(envptr).find(".", p0);
67
68        if( p1 > 0 )
69        {
70            _displayNum = atoi((string(envptr).substr(p0,p1)).c_str());
71            p0 = p1+1;
72            p1 = string(envptr).length() - p0;
73            if( p1 > 0 )
74                _screen = atoi((string(envptr).substr(p0,p1)).c_str());
75        }
76        else if( p1 < string(envptr).length() )
77        {
78            p1 = string(envptr).length();
79            _displayNum = atoi((string(envptr).substr(p0,p1)).c_str());
80            _screen = 0;
81        }
82    }
83
84    _windowLeft     = 0;
85    _windowRight    = 1;
86    _windowBottom   = 0;
87    _windowTop      = 1;
88    _windowX        = 0;
89    _windowY        = 0;
90    _windowWidth    = UnknownDimension;
91    _windowHeight   = UnknownDimension;
92    _screenWidth    = UnknownDimension;
93    _screenHeight   = UnknownDimension;
94    _customFullScreenOriginX = 0;
95    _customFullScreenOriginY = 0;
96    _customFullScreenWidth   = UnknownDimension;
97    _customFullScreenHeight  = UnknownDimension;
98    _useCustomFullScreen     = false;
99
100    _readDrawableRenderSurface = 0L;
101    _windowName      = defaultWindowName;
102    _realized        = false;
103    _useConfigEventThread = true;
104    _overrideRedirectFlag = false;
105
106    char *override_envptr = getenv( "PRODUCER_OVERRIDE_REDIRECT" );
107    if( override_envptr != NULL && *override_envptr != 0 )
108    {
109        if (strcmp(override_envptr,"true")==0 || strcmp(override_envptr,"True")==0 || strcmp(override_envptr,"TRUE")==0)
110        {
111            _overrideRedirectFlag = true;
112        }
113        else
114        {
115            _overrideRedirectFlag = false;
116        }
117    }
118
119    _decorations     = true;
120    _useCursorFlag   = true;
121
122
123
124
125    _useDefaultEsc = true;
126    _checkOwnEvents = true;
127    _inputRectangle.set( -1.0,  1.0, -1.0, 1.0 );
128    _bindInputRectangleToWindowSize = false;
129
130
131    _rtt_mode   = RenderToTextureMode_None;
132    //_rtt_mode   = RenderToRGBTexture;
133    _rtt_target = Texture2D;
134    _rtt_options = RenderToTextureOptions_Default;
135    _rtt_mipmap = 0;
136    _rtt_face = PositiveX;
137    _rtt_dirty_mipmap = true;
138    _rtt_dirty_face = true;
139
140
141#ifdef _WIN32_IMPLEMENTATION
142    _ownWindow = true;
143    _ownVisualChooser = true;
144    _ownVisualInfo = true;
145    _hinstance = NULL;
146    _glcontext = NULL;
147    _mx = 0;
148    _my = 0;
149    _mbutton = 0;
150#endif
151}
152
153RenderSurface::~RenderSurface( void )
154{
155#if 0
156     cancel();
157
158    _fini();
159
160    while (isRunning())
161    {
162        //std::cout << "waiting for RenderSurface to cancel"<<std::endl;
163        OpenThreads::Thread::YieldCurrentThread();
164    }
165
166    delete _threadReady;
167#endif
168}
169
170
171void RenderSurface::setDrawableType( RenderSurface::DrawableType drawableType )
172{
173    if( _realized )
174    {
175        std::cerr << "Warning: RenderSurface::setDrawableType() "
176                     "has no effect after RenderSurface has been realized\n";
177        return;
178    }
179    _drawableType = drawableType;
180}
181
182RenderSurface::DrawableType RenderSurface::getDrawableType()
183{
184    return _drawableType;
185}
186
187void RenderSurface::setReadDrawable( osgProducer::RenderSurface *rs )
188{
189    _readDrawableRenderSurface = rs;
190#if 0
191    if( _realized )
192        makeCurrent();
193#endif
194}
195
196#if 0
197void RenderSurface::setParentWindow( Window parent )
198{
199     _parent = parent;
200}
201
202Producer::Window RenderSurface::getParentWindow( void ) const
203{
204    return _parent;
205}
206#endif
207
208void RenderSurface::setWindowName( const std::string &name )
209{
210  //    _setWindowName( name );
211    _windowName = name;
212}
213
214const std::string &RenderSurface::getWindowName( void ) const
215{
216    return _windowName;
217}
218
219void RenderSurface::setHostName( const std::string &name )
220{
221    _hostname = name;
222}
223
224const std::string &RenderSurface::getHostName( void ) const
225{
226    return _hostname;
227}
228
229#if 0
230void RenderSurface::setDisplay( Display *dpy )
231{
232    _dpy = dpy;
233}
234
235Producer::Display *RenderSurface::getDisplay()
236{
237#ifdef WIN32
238    return &_hdc;
239#else
240    return _dpy;
241#endif
242}
243
244const Producer::Display *RenderSurface::getDisplay() const
245{
246#ifdef WIN32
247    return &_hdc;
248#else
249    return _dpy;
250#endif
251}
252#endif
253
254void RenderSurface::setDisplayNum( int num )
255{
256    _displayNum = num;
257}
258
259int  RenderSurface::getDisplayNum( void ) const
260{
261    return _displayNum;
262}
263
264void RenderSurface::setScreenNum( int num )
265{
266    _screen = num;
267}
268
269int  RenderSurface::getScreenNum( void ) const
270{
271    return _screen;
272}
273
274void RenderSurface::setWindowRectangle( int x, int y, unsigned int width, unsigned int height, bool resize)
275{
276    if( _useCustomFullScreen )
277    {
278        _windowX = x + _customFullScreenOriginX;
279        _windowY = y + _customFullScreenOriginY;
280    }
281    else
282    {
283        _windowX = x;
284        _windowY = y;
285    }
286    _windowWidth = width;
287    _windowHeight = height;
288#ifdef _OSX_AGL_IMPLEMENTATION
289    fullScreen(false);                  // STH: this may break other implementations, but it is necessary for OSX
290#else
291    _isFullScreen    = false;
292#endif
293#if 0
294    if( _realized && resize )
295        _resizeWindow();
296    else
297#endif
298        if( _bindInputRectangleToWindowSize == true )
299            _inputRectangle.set( 0.0, _windowWidth, 0.0, _windowHeight );
300}
301
302void RenderSurface::getWindowRectangle( int &x, int &y, unsigned int &width, unsigned int &height ) const
303{
304    if( _isFullScreen )
305    {
306        x = 0;
307        y = 0;
308        if( _useCustomFullScreen == true )
309        {
310            width  = _customFullScreenWidth;
311            height = _customFullScreenHeight;
312        }
313        else
314        {
315            width = _screenWidth;
316            height = _screenHeight;
317        }
318    }
319    else
320    {
321        x      = _windowX;
322        y      = _windowY;
323        width  = _windowWidth;
324        height = _windowHeight;
325    }
326}
327
328void RenderSurface::useDefaultFullScreenRectangle()
329{
330    _useCustomFullScreen = false;
331}
332
333void RenderSurface::setCustomFullScreenRectangle( int x, int y, unsigned int width, unsigned int height )
334{
335    _customFullScreenOriginX = x;
336    _customFullScreenOriginY = y;
337    _customFullScreenWidth   = width;
338    _customFullScreenHeight  = height;
339    _useCustomFullScreen     = true;
340
341    _windowX += _customFullScreenOriginX;
342    _windowY += _customFullScreenOriginY;
343}
344
345int RenderSurface::getWindowOriginX() const
346{
347    if( _isFullScreen )
348    {
349        if( _useCustomFullScreen == true )
350            return _customFullScreenOriginX;
351        else
352            return 0;
353    }
354    return _windowX;
355}
356
357int RenderSurface::getWindowOriginY() const
358{
359    if( _isFullScreen )
360    {
361        if( _useCustomFullScreen == true )
362            return _customFullScreenOriginY;
363        else
364            return 0;
365    }
366    return _windowY;
367}
368
369unsigned int RenderSurface::getWindowWidth() const
370{
371    if( _isFullScreen )
372    {
373        if( _useCustomFullScreen == true )
374            return _customFullScreenWidth;
375        else
376            return _screenWidth;
377    }
378    return _windowWidth;
379}
380
381unsigned int RenderSurface::getWindowHeight() const
382{
383    if( _isFullScreen )
384    {
385        if( _useCustomFullScreen == true )
386            return _customFullScreenHeight;
387        else
388            return _screenHeight;
389    }
390    return _windowHeight;
391}
392
393void RenderSurface::setInputRectangle( const InputRectangle &inputRectangle )
394{
395    _inputRectangle = inputRectangle;
396}
397
398const RenderSurface::InputRectangle &RenderSurface::getInputRectangle() const
399{
400    return _inputRectangle;
401}
402
403void RenderSurface::bindInputRectangleToWindowSize( bool flag)
404{
405    _bindInputRectangleToWindowSize = flag;
406    if( _bindInputRectangleToWindowSize == true )
407        _inputRectangle.set( 0.0, float(_windowWidth), 0.0, float(_windowHeight) );
408    else
409        _inputRectangle.set( -1.0,  1.0, -1.0, 1.0 );
410}
411
412
413void RenderSurface::useBorder( bool flag )
414{
415    _decorations = flag;
416#if 0
417    if( _realized )
418          _setBorder(_decorations);
419#endif
420}
421
422bool RenderSurface::usesBorder()
423{
424    return _decorations;
425}
426
427#if 0
428void RenderSurface::useCursor( bool flag )
429{
430     _useCursor(flag);
431}
432
433void RenderSurface::setCursor( Cursor cursor )
434{
435    _setCursor(cursor);
436}
437
438void RenderSurface::setCursorToDefault()
439{
440    _setCursorToDefault();
441}
442void RenderSurface::setWindow( const Window win )
443{
444    if( _realized )
445    {
446        std::cerr << "RenderSurface::setWindow() - cannot set window after RenderSurface has been realized\n";
447        return;
448    }
449    _win = win;
450#ifdef WIN32
451    _ownWindow = false;
452#endif
453}
454
455Producer::Window RenderSurface::getWindow( void ) const
456{
457    return _win;
458}
459
460GLContext RenderSurface::getGLContext( void) const
461{
462    return _glcontext;
463}
464
465void RenderSurface::setGLContext( GLContext glContext )
466{
467    if( _realized )
468    {
469        std::cerr << "RenderSurface::setGLContext() - Warning: Must be set before realize()." << std::endl;
470        return;
471    }
472
473    _glcontext = glContext;
474}
475
476
477bool RenderSurface::isRealized() const
478{
479    return _realized;
480}
481
482void RenderSurface::setVisualInfo( VisualInfo *vi )
483{
484    if( _realized )
485    {
486        std::cerr << "RenderSurface::setVisualInfo():Warning - has no effect after RenderSurface has been realized\n";
487        return;
488    }
489    _visualInfo = vi;
490#ifdef _WIN32_IMPLEMENTATION
491    _ownVisualInfo = false;
492#endif
493}
494
495VisualInfo *RenderSurface::getVisualInfo( void  )
496{
497    return _visualInfo;
498}
499
500const VisualInfo *RenderSurface::getVisualInfo( void  ) const
501{
502    return _visualInfo;
503}
504
505#endif
506
507void RenderSurface::setVisualChooser( VisualChooser *vc )
508{
509    if( _realized )
510    {
511        std::cerr << "RenderSurface::setVisualChooser():Warning - has no effect after RenderSurface has been realized\n";
512        return;
513    }
514    _visualChooser = vc;
515
516#ifdef _WIN32_IMPLEMENTATION
517    _ownVisualChooser = false;
518#endif
519}
520
521VisualChooser *RenderSurface::getVisualChooser( void )
522{
523    return _visualChooser.get();
524}
525
526const VisualChooser *RenderSurface::getVisualChooser( void ) const
527{
528    return _visualChooser.get();
529}
530
531
532#if 0
533void RenderSurface::getScreenSize( unsigned int &width, unsigned int &height )  const
534{
535    if( _realized )
536    {
537        if( _useCustomFullScreen == true )
538        {
539            width  = _customFullScreenWidth;
540            height = _customFullScreenHeight;
541        }
542        else
543        {
544            width  = _screenWidth;
545            height = _screenHeight;
546        }
547    }
548    else
549    {
550        _computeScreenSize(width, height);
551    }
552}
553#endif
554
555#if 0
556void  RenderSurface::useConfigEventThread( bool flag )
557{
558    if( _realized )
559    {
560        // This message is annoying.  Cameras that share a render surface will call this after the
561        // render surface has been realized, which is valid.
562        //std::cerr << "RenderSurface::useConfigEventThread():Warning - has no effect after RenderSurface has been realized\n";
563        return;
564    }
565    _useConfigEventThread = flag;
566}
567
568unsigned int RenderSurface::getRefreshRate() const
569{
570    if( !_realized ) return 0;
571    return _refreshRate;
572}
573
574void RenderSurface::addRealizeCallback( Callback *realizeCB )
575{
576    if( _realized )
577    {
578        std::cerr << "RenderSurface::addRealizeCallback() : Warning.  RenderSurface is already realized.  ignored.\n";
579            return;
580    }
581    _realizeCallbacks.push_back( realizeCB );
582}
583
584bool RenderSurface::waitForRealize()
585{
586    if( _realized ) return true;
587    while( _realized == false )
588        _realizeBlock->block();
589    return true;
590}
591
592void RenderSurface::positionPointer( int x, int y )
593{
594    _positionPointer(x,y);
595}
596
597void RenderSurface::initThreads()
598{
599    _initThreads();
600}
601#endif
602
603RenderSurface::RenderToTextureMode RenderSurface::getRenderToTextureMode() const
604{
605    return _rtt_mode;
606}
607
608
609void RenderSurface::setRenderToTextureMode(RenderToTextureMode mode)
610{
611    _rtt_mode = mode;
612}
613
614
615RenderSurface::RenderToTextureTarget RenderSurface::getRenderToTextureTarget() const
616{
617    return _rtt_target;
618}
619
620
621void RenderSurface::setRenderToTextureTarget(RenderToTextureTarget target)
622{
623    _rtt_target = target;
624}
625
626
627RenderSurface::RenderToTextureOptions RenderSurface::getRenderToTextureOptions() const
628{
629    return _rtt_options;
630}
631
632
633void RenderSurface::setRenderToTextureOptions(RenderToTextureOptions options)
634{
635    _rtt_options = options;
636}
637
638int RenderSurface::getRenderToTextureMipMapLevel() const
639{
640    return _rtt_mipmap;
641}
642
643
644void RenderSurface::setRenderToTextureMipMapLevel(int level)
645{
646    _rtt_mipmap = level;
647    _rtt_dirty_mipmap = true;
648}
649
650RenderSurface::CubeMapFace RenderSurface::getRenderToTextureFace() const
651{
652    return _rtt_face;
653}
654
655
656void RenderSurface::setRenderToTextureFace(CubeMapFace face)
657{
658    _rtt_face = face;
659    _rtt_dirty_face = true;
660}
661
662const std::vector<int> &RenderSurface::getPBufferUserAttributes() const
663{
664    return _user_pbattr;
665}
666
667std::vector<int> &RenderSurface::getPBufferUserAttributes()
668{
669    return _user_pbattr;
670}
671
672
673
674void RenderSurface::useOverrideRedirect(bool flag)
675{
676    _overrideRedirectFlag = flag;
677}
678
679bool RenderSurface::usesOverrideRedirect()
680{
681    return _overrideRedirectFlag;
682}
Note: See TracBrowser for help on using the browser.