1 /*---------------------------------------------------------------------------*\
5 * Copyright 2000-2002 by OpenSG Forum *
7 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
9 \*---------------------------------------------------------------------------*/
10 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
26 \*---------------------------------------------------------------------------*/
27 /*---------------------------------------------------------------------------*\
35 \*---------------------------------------------------------------------------*/
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.
46 void Window::setSize(UInt16 width, UInt16 height)
52 /*! Check if the window has the indicated extension.
53 \warning No error checks are done on the passed index!
57 bool Window::hasExtension(UInt32 extId)
59 return (_availExtensions[extId] & !_sfIgnoreAllExtensions.getValue());
63 bool Window::hasExtOrVersion(UInt32 extId,
67 #if defined(OSG_OGL_ES2)
69 ((uiGLESVersion <= _glVersion) ||
70 (_availExtensions[extId] & !_sfIgnoreAllExtensions.getValue()));
73 ((uiGLVersion <= _glVersion) ||
74 (_availExtensions[extId] & !_sfIgnoreAllExtensions.getValue()));
78 /*! Check if the window has the indicated extension.
79 If extId is out of range, then automatically returns false.
82 bool Window::hasCommonExtension(UInt32 extId)
84 if(extId >= _commonExtensions.size())
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
97 Window::GLExtensionFunction Window::getFunction(UInt32 funcId)
99 if(_sfIgnoreAllExtensions.getValue() == true)
104 if(funcId >= _extFunctions.size())
106 FINFO(("Window::getFunction: illegal id %d!\n", funcId));
110 if(_extFunctions[funcId] == NULL)
112 FINFO(("Window::getFunction: function \"%s\" is NULL!\n",
113 _registeredFunctions[funcId].c_str()));
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
126 Window::GLExtensionFunction Window::getFunctionNoCheck(UInt32 funcId)
128 if(_sfIgnoreAllExtensions.getValue() == true)
131 return _extFunctions[ funcId ];
134 /*! Return the value of the registered constant, Inf if not registered
135 or no value received yet.
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().
150 void Window::setGLLibraryName(const Char8 *s)
155 /*! Return the version of OpenGL running in the Window in the form
156 0x<major><major><minor><minor>, e.g. 0x0201 for
161 UInt32 Window::getGLVersion(void)
166 /*! Return the id of a registered extension. Return -1 if extension not
170 Int32 Window::getExtensionIdX(const Char8 *s)
172 std::vector<std::string>::iterator it;
174 it = std::find(_registeredExtensions.begin(),
175 _registeredExtensions.end(),
178 if(it == _registeredExtensions.end())
181 return Int32(it -_registeredExtensions.begin());
184 /*! Access the available extensions.
188 const std::vector<std::string> &Window::getExtensions(void)
193 /*! Reutrn the list of registered extensions.
196 const std::vector<std::string> &Window::getRegisteredExtensions(void)
198 return _registeredExtensions;
201 /*! Access the registered functions.
204 const std::vector<std::string> &Window::getRegisteredFunctions(void)
206 return _registeredFunctions;
209 /*! Access the ignored extensions.
212 const std::vector<std::string> &Window::getIgnoredExtensions(void)
214 return _ignoredExtensions;
218 void Window::setGLObjectId(UInt32 osgId, GLObjectId id2)
220 if(osgId < _ids.size())
226 _ids.resize(_glObjects.size(), 0);
228 if(osgId < _ids.size())
234 SWARNING << "Window::setGLObjectId: id ("
243 Window::GLObjectId Window::getGLObjectId(UInt32 osgId)
245 if(osgId < _ids.size())
252 void Window::setGLObjectInfo(UInt32 osgId, GLObjectId info)
254 if(osgId < _idInfo.size())
256 _idInfo[osgId] = info;
260 _idInfo.resize(_glObjects.size(), 0);
262 if(osgId < _idInfo.size())
264 _idInfo[osgId] = info;
268 SWARNING << "Window::setGLObjectId: id ("
277 Window::GLObjectId Window::getGLObjectInfo(UInt32 osgId)
279 if(osgId < _idInfo.size())
280 return _idInfo[osgId];
286 UInt32 Window::getGLObjectsSize(void)
288 return UInt32(_glObjects.size());
291 /* GLObject helper class */
294 Window::GLObject::GLObject(GLObjectFunctor funct,
295 GLObjectDestroyFunctor destroy) :
303 void Window::GLObject::acquireLock(void)
308 ThreadManager::the()->getLock("OSG::Window::_GLObjectLock", false);
311 _GLObjectLock->acquire();
315 void Window::GLObject::releaseLock(void)
317 OSG_ASSERT(_GLObjectLock != NULL);
319 _GLObjectLock->release();
323 Window::GLObjectFunctor &Window::GLObject::getFunctor(void)
329 void Window::GLObject::setFunctor(GLObjectFunctor funct)
335 Window::GLObjectDestroyFunctor &Window::GLObject::getDestroyFunctor(void)
341 void Window::GLObject::setDestroyFunctor(GLObjectDestroyFunctor funct)
347 UInt32 Window::GLObject::getRefCounter(void)
353 UInt32 Window::GLObject::incRefCounter(void)
359 val = _refCounter = _refCounter + 1;
367 UInt32 Window::GLObject::decRefCounter(void)
375 val = _refCounter = _refCounter - 1;
388 TraversalValidator *Window::getTravValidator(void)
390 return _pTravValidator;
394 ShaderCache *Window::getShaderCache(void)
396 return _pShaderCache;
400 void Window::setPartitionDrawMode(UInt32 uiMode)
402 if(0x0000 == (uiMode & PartitionDrawMask))
404 FWARNING(("Window: invalid draw mode\n"));
408 editSField(DrawModeFieldMask);
410 _sfDrawMode.setValue(
411 (_sfDrawMode.getValue() & ~PartitionDrawMask) |
412 (uiMode & PartitionDrawMask) );
416 void Window::setDrawerType(UInt32 uiDrawerType)
418 if(0x0000 == (uiDrawerType & DrawerMask))
420 FWARNING(("Window: invalid drawer type\n"));
424 editSField(DrawModeFieldMask);
426 _sfDrawMode.setValue((_sfDrawMode.getValue() & ~DrawerMask) |
427 (uiDrawerType & DrawerMask) );
431 UInt32 Window::getPartitionDrawMode(void) const
433 return _sfDrawMode.getValue() & PartitionDrawMask;
437 UInt32 Window::getDrawerType(void) const
439 return _sfDrawMode.getValue() & DrawerMask;
443 void DrawTask::setupContext(Window *pWindow)
448 void DrawTask::finalizeContext(Window *pWindow)