fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Window / Base / OSGWindow.inl
blob556772eb0d243180d59907b24c19698e415b7573
1 /*---------------------------------------------------------------------------*\
2  *                                OpenSG                                     *
3  *                                                                           *
4  *                                                                           *
5  *                     Copyright 2000-2002 by OpenSG Forum                   *
6  *                                                                           *
7  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
8  *                                                                           *
9 \*---------------------------------------------------------------------------*/
10 /*---------------------------------------------------------------------------*\
11  *                                License                                    *
12  *                                                                           *
13  * This library is free software; you can redistribute it and/or modify it   *
14  * under the terms of the GNU Library General Public License as published    *
15  * by the Free Software Foundation, version 2.                               *
16  *                                                                           *
17  * This library is distributed in the hope that it will be useful, but       *
18  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
20  * Library General Public License for more details.                          *
21  *                                                                           *
22  * You should have received a copy of the GNU Library General Public         *
23  * License along with this library; if not, write to the Free Software       *
24  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
25  *                                                                           *
26 \*---------------------------------------------------------------------------*/
27 /*---------------------------------------------------------------------------*\
28  *                                Changes                                    *
29  *                                                                           *
30  *                                                                           *
31  *                                                                           *
32  *                                                                           *
33  *                                                                           *
34  *                                                                           *
35 \*---------------------------------------------------------------------------*/
37 OSG_BEGIN_NAMESPACE
39 /*------------------------------- size ----------------------------------*/
41 /*! Set the width and height of the Window. Only use if you really know what
42     you're doing. In most cases resize() is a better choice.
43  */
45 inline 
46 void Window::setSize(UInt16 width, UInt16 height)
48     setHeight(height);
49     setWidth(width);
52 /*! Check if the window has the indicated extension.
53     \warning No error checks are done on the passed index!
54  */
56 inline 
57 bool Window::hasExtension(UInt32 extId)
59     return (_availExtensions[extId] & !_sfIgnoreAllExtensions.getValue());
62 inline 
63 bool Window::hasExtOrVersion(UInt32 extId, 
64                              UInt32 uiGLVersion, 
65                              UInt32 uiGLESVersion)
67 #if defined(OSG_OGL_ES2)
68     return 
69         ((uiGLESVersion <= _glVersion) || 
70         (_availExtensions[extId] & !_sfIgnoreAllExtensions.getValue()));
71 #else
72     return 
73         ((uiGLVersion <= _glVersion) || 
74          (_availExtensions[extId] & !_sfIgnoreAllExtensions.getValue()));
75 #endif
78 /*! Check if the window has the indicated extension.
79     If extId is out of range, then automatically returns false.
80  */
81 inline 
82 bool Window::hasCommonExtension(UInt32 extId)
84     if(extId >= _commonExtensions.size())
85         return false;
87     return _commonExtensions[extId];
90 /*! Get the indicated extension function.
91     The id and the returned functions are checked for sanity and a warning is
92     issued if there are problems. Use getFunctionNoCheck if you're sure you
93     don't need them.
94  */
96 inline 
97 Window::GLExtensionFunction Window::getFunction(UInt32 funcId)
99     if(_sfIgnoreAllExtensions.getValue() == true)
100     {
101         return NULL;
102     }
104     if(funcId >= _extFunctions.size())
105     {
106         FINFO(("Window::getFunction: illegal id %d!\n", funcId));
107         return NULL;
108     }
110     if(_extFunctions[funcId] == NULL)
111     {
112         FINFO(("Window::getFunction: function \"%s\" is NULL!\n",
113                     _registeredFunctions[funcId].c_str()));
114         return NULL;
115     }
117     return _extFunctions[funcId];
120 /*! Get the indicated extension function.
121     \warning No error checks are done on the passed index nor on the returned
122     function!
123  */
125 inline 
126 Window::GLExtensionFunction Window::getFunctionNoCheck(UInt32 funcId)
128     if(_sfIgnoreAllExtensions.getValue() == true)
129         return NULL;
131     return _extFunctions[ funcId ];
134 /*! Return the value of the registered constant, Inf if not registered 
135     or no value received yet.
138 inline 
139 Real32 Window::getConstantValue(GLenum val)
141     return getConstantValuev(val)[0];
144 /*! Set the library name where to find OpenGL extension functions. This has
145     to be called before the first extension function is accessed, and it's
146     safe to call it before osgInit().
147  */
149 inline 
150 void Window::setGLLibraryName(const Char8 *s)
152     _glLibraryName = s;
155 /*! Return the version of OpenGL running in the Window in the form
156     0x&lt;major&gt;&lt;major&gt;&lt;minor&gt;&lt;minor&gt;, e.g. 0x0201 for 
157     version 2.1.
158  */
160 inline 
161 UInt32 Window::getGLVersion(void)
163     return _glVersion;
166 /*! Return the id of a registered extension. Return -1 if extension not
167     registered.
168  */
169 inline 
170 Int32 Window::getExtensionIdX(const Char8  *s)
172     std::vector<std::string>::iterator it;
174     it = std::find(_registeredExtensions.begin(),
175                    _registeredExtensions.end(),
176                     s);
178     if(it == _registeredExtensions.end())
179         return -1;
181     return Int32(it -_registeredExtensions.begin());
184 /*! Access the available extensions.
185  */
187 inline 
188 const std::vector<std::string> &Window::getExtensions(void)
190     return _extensions;
193 /*! Reutrn the list of registered extensions.
194  */
195 inline 
196 const std::vector<std::string> &Window::getRegisteredExtensions(void)
198     return _registeredExtensions;
201 /*! Access the registered functions.
202  */
203 inline 
204 const std::vector<std::string> &Window::getRegisteredFunctions(void)
206     return _registeredFunctions;
209 /*! Access the ignored extensions.
211 inline
212 const std::vector<std::string> &Window::getIgnoredExtensions(void)
214     return _ignoredExtensions;
217 inline 
218 void Window::setGLObjectId(UInt32 osgId, GLObjectId id2)
220     if(osgId < _ids.size())
221     {
222         _ids[osgId] = id2;
223     }
224     else
225     {
226         _ids.resize(_glObjects.size(), 0);
228         if(osgId < _ids.size())
229         {
230             _ids[osgId] = id2;
231         }
232         else
233         {
234             SWARNING << "Window::setGLObjectId: id (" 
235                      << osgId 
236                      << ") is not valid!" 
237                      << std::endl;
238         }
239     }
242 inline
243 Window::GLObjectId Window::getGLObjectId(UInt32 osgId)
245     if(osgId < _ids.size())
246         return _ids[osgId];
248     return 0;
251 inline 
252 void Window::setGLObjectInfo(UInt32 osgId, GLObjectId info)
254     if(osgId < _idInfo.size())
255     {
256         _idInfo[osgId] = info;
257     }
258     else
259     {
260         _idInfo.resize(_glObjects.size(), 0);
262         if(osgId < _idInfo.size())
263         {
264             _idInfo[osgId] = info;
265         }
266         else
267         {
268             SWARNING << "Window::setGLObjectId: id (" 
269                      << osgId 
270                      << ") is not valid!" 
271                      << std::endl;
272         }
273     }
276 inline
277 Window::GLObjectId Window::getGLObjectInfo(UInt32 osgId)
279     if(osgId < _idInfo.size())
280         return _idInfo[osgId];
282     return 0;
285 inline 
286 UInt32 Window::getGLObjectsSize(void)
288     return UInt32(_glObjects.size());
291 /* GLObject helper class */
293 inline 
294 Window::GLObject::GLObject(GLObjectFunctor        funct, 
295                            GLObjectDestroyFunctor destroy) :
296     _functor     (funct  ),
297     _destroy     (destroy),
298     _refCounter  (      0)
302 inline
303 void Window::GLObject::acquireLock(void)
305     if(! _GLObjectLock)
306     {
307         _GLObjectLock =
308             ThreadManager::the()->getLock("OSG::Window::_GLObjectLock", false);
309     }
311     _GLObjectLock->acquire();
314 inline
315 void Window::GLObject::releaseLock(void)
317     OSG_ASSERT(_GLObjectLock != NULL);
319     _GLObjectLock->release();
322 inline 
323 Window::GLObjectFunctor &Window::GLObject::getFunctor(void)
325     return _functor;
328 inline 
329 void Window::GLObject::setFunctor(GLObjectFunctor funct)
331     _functor = funct;
334 inline 
335 Window::GLObjectDestroyFunctor &Window::GLObject::getDestroyFunctor(void)
337     return _destroy;
340 inline 
341 void Window::GLObject::setDestroyFunctor(GLObjectDestroyFunctor funct)
343     _destroy = funct;
346 inline 
347 UInt32 Window::GLObject::getRefCounter(void)
349     return _refCounter;
352 inline 
353 UInt32 Window::GLObject::incRefCounter(void)
355     UInt32 val;
357     acquireLock();
359     val = _refCounter = _refCounter + 1;
361     releaseLock();
363     return val;
366 inline 
367 UInt32 Window::GLObject::decRefCounter(void)
369     UInt32 val;
371     acquireLock();
373     if(_refCounter)
374     {
375         val = _refCounter = _refCounter - 1;
376     }
377     else
378     {
379         val = 0;
380     }
382     releaseLock();
384     return val;
385 }    
387 inline
388 TraversalValidator *Window::getTravValidator(void)
390     return _pTravValidator;
393 inline
394 ShaderCache *Window::getShaderCache(void)
396     return _pShaderCache;
399 inline
400 void Window::setPartitionDrawMode(UInt32 uiMode)
402     if(0x0000 == (uiMode & PartitionDrawMask))
403     {
404         FWARNING(("Window: invalid draw mode\n"));
405         return;
406     }
408     editSField(DrawModeFieldMask);
410     _sfDrawMode.setValue(
411         (_sfDrawMode.getValue() & ~PartitionDrawMask) | 
412         (uiMode                 &  PartitionDrawMask) );
415 inline
416 void Window::setDrawerType(UInt32 uiDrawerType)
418     if(0x0000 == (uiDrawerType & DrawerMask))
419     {
420         FWARNING(("Window: invalid drawer type\n"));
421         return;
422     }
424     editSField(DrawModeFieldMask);
426     _sfDrawMode.setValue((_sfDrawMode.getValue() & ~DrawerMask) | 
427                          (uiDrawerType           &  DrawerMask) );
430 inline
431 UInt32 Window::getPartitionDrawMode(void) const
433     return _sfDrawMode.getValue() & PartitionDrawMask;
436 inline
437 UInt32 Window::getDrawerType(void) const
439     return _sfDrawMode.getValue() & DrawerMask;
442 inline
443 void DrawTask::setupContext(Window *pWindow)
447 inline
448 void DrawTask::finalizeContext(Window *pWindow)
452 OSG_END_NAMESPACE