fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Window / Base / OSGWindow.h
blob59332400e374ac91c50d972b289f56f7bbd12c8e
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGWINDOW_H_
40 #define _OSGWINDOW_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include "OSGConfig.h"
47 #include <list>
48 #include <utility>
49 #include <boost/function.hpp>
51 #include "OSGDeprecatedCPP.h"
53 #include "OSGVector.h"
55 #include "OSGWindowBase.h"
56 #include "OSGWindowDrawTask.h"
57 #include "OSGWindowDrawThread.h"
58 #include "OSGDrawEnv.h"
60 OSG_BEGIN_NAMESPACE
62 class RenderActionBase;
63 class TraversalValidator;
64 class ShaderCache;
65 class PassiveViewport;
67 /*! \brief Window base class. See \ref PageSystemWindowWindow
68 for a description.
70 \ingroup GrpSystemWindowBase
71 \ingroup GrpLibOSGSystem
72 \includebasedoc
75 class OSG_SYSTEM_DLLMAPPING Window : public WindowBase
77 /*========================== PUBLIC =================================*/
79 public:
81 /**
82 * Enumeration values for the status of the GL objects. This is primarily
83 * used to signal the object's callback functions what to do. See \ref
84 * PageSystemOGLObjects for a description.
86 enum GLObjectStatusE
88 notused = 0x0001, /**< Object is not used at all right now. */
89 initialize = 0x0002, /**< Object is being initialized for the first time. */
90 reinitialize = 0x0003, /**< Object is being re-initialized (ie. significant change) */
91 initialized = 0x0004, /**< Object is initialized and valid. */
92 needrefresh = 0x0005, /**< Object is initialized but needs a refresh. */
93 destroy = 0x0006, /**< Object is to be destroyed (removed from context) */
94 finaldestroy = 0x0007 /**< Object has been removed from contexts, now release resources. */
97 enum
99 invalidExtensionID = 0x7fffffff,
100 invalidFunctionID = 0x7fffffff
103 enum
105 SequentialPartitionDraw = 0x000001,
106 ParallelPartitionDraw = 0x000002,
107 PartitionDrawMask = 0x0000FF,
109 StdDrawer = 0x000100,
110 ParallelDrawer = 0x000200,
111 DrawerMask = 0x00FF00,
113 ActiveContext = 0x010000,
114 ExternalContext = 0x020000,
115 PassiveContext = 0x040000,
116 ContextMask = 0xFF0000
119 static const Real32 unknownConstant;
121 /*! \} */
122 /*---------------------------------------------------------------------*/
123 /*! \name Typedefs */
124 /*! \{ */
126 typedef UIntPointer GLObjectId;
128 typedef boost::function<UInt32 (DrawEnv *,
129 UInt32,
130 GLObjectStatusE,
131 UInt64 )> GLObjectFunctor;
132 typedef boost::function<void (DrawEnv *,
133 UInt32,
134 GLObjectStatusE)> GLObjectDestroyFunctor;
136 typedef void (*GLExtensionFunction)(void);
138 typedef WindowDrawTask::GLInitFunctor GLInitFunctor;
140 /*---------------------------------------------------------------------*/
141 /*! \name Sync */
142 /*! \{ */
144 virtual void changed(ConstFieldMaskArg whichField,
145 UInt32 origin,
146 BitVector detail);
148 /*! \} */
149 /*---------------------------------------------------------------------*/
150 /*! \name Viewport handling */
151 /*! \{ */
153 /*! \} */
154 /*---------------------------------------------------------------------*/
155 /*! \name Extension registration
156 * See */
157 /*! \{ */
159 static UInt32 registerExtension(const Char8 *s );
160 static void ignoreExtensions (const Char8 *s );
162 static UInt32 registerFunction (const Char8 *s,
163 Int32 ext = -1,
164 UInt32 version = 0xffff);
166 static void registerConstant ( GLenum val );
168 /*! \} */
169 /*---------------------------------------------------------------------*/
170 /*! \name Extension handling */
171 /*! \{ */
173 static void setGLLibraryName (const Char8 *s );
175 UInt32 getGLVersion ( void );
177 static Int32 getExtensionIdX (const Char8 *s );
178 bool hasExtension ( UInt32 extId );
179 bool hasExtension (const Char8 *s );
180 static bool hasCommonExtension( UInt32 extId );
181 GLExtensionFunction getFunction ( UInt32 funcId);
182 GLExtensionFunction getFunctionNoCheck( UInt32 funcId);
183 void dumpExtensions ( void );
184 GLExtensionFunction getFunctionByName (const Char8 *s );
185 Real32 getConstantValue ( GLenum val );
186 const Vec2f &getConstantValuev ( GLenum val );
189 bool hasExtOrVersion (UInt32 extId,
190 UInt32 uiGLVersion = 0xFFFF,
191 UInt32 uiGLESVersion = 0xFFFF);
193 /*! \} */
194 /*---------------------------------------------------------------------*/
195 /*! \name Extension string handling */
196 /*! \{ */
198 static const std::vector<std::string> &getRegisteredExtensions(void);
199 const std::vector<std::string> &getRegisteredFunctions (void);
200 const std::vector<std::string> &getExtensions (void);
201 const std::vector<std::string> &getIgnoredExtensions (void);
203 /*! \} */
204 /*---------------------------------------------------------------------*/
205 /*! \name GL object registration */
206 /*! \{ */
208 static UInt32 registerGLObject(GLObjectFunctor functor,
209 GLObjectDestroyFunctor destroyFunctor,
210 UInt32 num = 1);
212 /*! \} */
213 /*---------------------------------------------------------------------*/
214 /*! \name GL object handling */
215 /*! \{ */
217 UInt32 validateGLObject (UInt32 osgId,
218 DrawEnv *pEnv,
219 UInt64 uiOptions = 0);
220 void validateAllGLObjects(void);
222 void setGLObjectId (UInt32 osgId,
223 GLObjectId id2 );
224 GLObjectId getGLObjectId (UInt32 osgId );
226 void setGLObjectInfo (UInt32 osgId,
227 GLObjectId infi );
228 GLObjectId getGLObjectInfo (UInt32 osgId );
230 /*! \} */
231 /*---------------------------------------------------------------------*/
232 /*! \name static GL object handling */
233 /*! \{ */
235 static UInt32 getGLObjectsSize (void );
237 static void refreshGLObject (UInt32 osgId );
238 static void refreshAllGLObjects (void );
240 static void reinitializeGLObject (UInt32 osgId );
241 static void reinitializeAllGLObjects(void );
243 static void destroyGLObject (UInt32 osgId,
244 UInt32 num = 1 );
246 /*! \} */
247 /*---------------------------------------------------------------------*/
248 /*! \name Size handling */
249 /*! \{ */
251 virtual void resize (int width,
252 int height );
254 void setSize (UInt16 width,
255 UInt16 height);
257 /*! \} */
258 /*---------------------------------------------------------------------*/
259 /*! \name Drawing */
260 /*! \{ */
262 virtual void render (RenderActionBase *action );
263 virtual void renderNoFinish(RenderActionBase *action );
264 virtual void frameFinish (bool bActivate = true);
265 virtual void runFrameExit (void );
267 /*! \} */
268 /*---------------------------------------------------------------------*/
269 /*! \name Window system implementation functions */
270 /*! \{ */
272 virtual void init(GLInitFunctor oFunc = GLInitFunctor());
274 /*! \} */
275 /*---------------------------------------------------------------------*/
276 /*! \name Sequential drawing */
277 /*! \{ */
279 virtual void activate (void );
280 virtual void deactivate (void );
281 virtual bool swap (void );
283 virtual void frameExit (void );
284 virtual void frameInit (void );
285 virtual void renderAllViewports(RenderActionBase *action);
287 virtual void terminate (void ) = 0;
289 /*! \} */
290 /*---------------------------------------------------------------------*/
291 /*! \name Sync */
292 /*! \{ */
294 void setPartitionDrawMode(UInt32 uiMode );
295 void setDrawerType (UInt32 uiDrawerType);
297 UInt32 getPartitionDrawMode(void ) const;
298 UInt32 getDrawerType (void ) const;
300 /*! \} */
301 /*---------------------------------------------------------------------*/
302 /*! \name Sync */
303 /*! \{ */
305 ShaderCache *getShaderCache (void );
306 TraversalValidator *getTravValidator(void );
308 static void requestStageRun (Int32 iStageId);
310 /*! \} */
311 /*---------------------------------------------------------------------*/
312 /*! \name Output */
313 /*! \{ */
315 virtual void resolveLinks(void);
317 /*! \} */
318 /*---------------------------------------------------------------------*/
319 /*! \name Output */
320 /*! \{ */
322 void queueTaskFromDrawer(DrawTask *pTask);
323 void queueTask (DrawTask *pTask);
324 static void queueGlobalTask (DrawTask *pTask);
327 void clearDrawTasks (void );
329 /*! \} */
330 /*---------------------------------------------------------------------*/
331 /*! \name Output */
332 /*! \{ */
334 virtual void submitTask (HardwareContextTask *pTask);
335 virtual void submitTaskAndWait(BlockingTask *pTask);
337 /*! \} */
338 /*---------------------------------------------------------------------*/
339 /*! \name Output */
340 /*! \{ */
342 virtual void dump ( UInt32 uiIndent = 0,
343 const BitVector bvFlags = 0) const;
345 static void staticDump(void );
347 /*! \} */
348 /*========================= PROTECTED ===============================*/
350 protected:
352 /*---------------------------------------------------------------------*/
353 /*! \name Constructors */
354 /*! \{ */
356 Window(void);
357 Window(const Window &source);
359 /*! \} */
360 /*---------------------------------------------------------------------*/
361 /*! \name Destructors */
362 /*! \{ */
364 virtual ~Window(void);
366 /*! \} */
367 /*---------------------------------------------------------------------*/
368 /*! \name GL setup handling */
369 /*! \{ */
371 virtual void setupGL(void);
373 /*! \} */
374 /*---------------------------------------------------------------------*/
375 /*! \name Init */
376 /*! \{ */
378 static void initMethod(InitPhase ePhase);
379 static bool cleanup (void );
381 /*! \} */
382 /*---------------------------------------------------------------------*/
383 /*! \name Window system implementation functions */
384 /*! \{ */
386 void validateAllGLObjects(DrawEnv *pEnv );
388 /*! \} */
389 /*---------------------------------------------------------------------*/
390 /*! \name Window system implementation functions */
391 /*! \{ */
393 virtual void doTerminate (void );
395 virtual void doActivate (void ) = 0;
396 virtual void doDeactivate (void ) = 0;
397 virtual bool doSwap (void ) = 0;
399 virtual void doFrameInit (bool reinitExtFuctions = false);
400 virtual void doFrameExit (void );
402 virtual void doRenderAllViewports(RenderActionBase *action );
404 virtual bool hasContext (void ) = 0;
406 /*! \} */
407 /*---------------------------------------------------------------------*/
408 /*! \name GL object handling */
409 /*! \{ */
411 void setupTasks(void);
413 /*! \} */
414 /*---------------------------------------------------------------------*/
415 /*! \name GL object handling */
416 /*! \{ */
418 static void doRefreshGLObject (UInt32 osgId );
419 static void doReinitializeGLObject(UInt32 osgId );
421 static void resetGLObjectStatus (UInt32 osgId, UInt32 num);
422 void doResetGLObjectStatus (UInt32 osgId, UInt32 num);
424 /*! \} */
425 /*---------------------------------------------------------------------*/
426 /*! \name GL object handling helper class */
427 /*! \{ */
429 class GLObject;
431 friend class GLObject;
433 /*! Used to keep track of the OpenGL objects registered with the system.
434 See \ref PageSystemOGLObjects for a description.
436 \nohierarchy
438 class GLObject
440 public:
442 GLObject(GLObjectFunctor funct,
443 GLObjectDestroyFunctor destroy);
445 void acquireLock(void);
446 void releaseLock(void);
448 GLObjectFunctor& getFunctor(void );
449 void setFunctor(GLObjectFunctor funct);
451 GLObjectDestroyFunctor& getDestroyFunctor(void );
452 void setDestroyFunctor(GLObjectDestroyFunctor funct);
454 UInt32 getRefCounter(void);
455 UInt32 incRefCounter(void);
456 UInt32 decRefCounter(void);
458 protected:
460 GLObjectFunctor _functor;
461 GLObjectDestroyFunctor _destroy;
462 volatile UInt32 _refCounter;
465 /*! \} */
466 /*---------------------------------------------------------------------*/
467 /*! \name MT Construction */
468 /*! \{ */
470 void onCreate (const Window *source = NULL);
472 void onCreateAspect (const Window *createAspect,
473 const Window *source = NULL);
475 void onDestroy ( UInt32 uiContainerId);
477 void onDestroyAspect( UInt32 uiContainerId,
478 UInt32 uiAspect );
480 static void staticAcquire (void );
481 static void staticRelease (void );
483 /*! \} */
484 /*---------------------------------------------------------------------*/
485 /*! \name Map for GL cvonstant handling */
486 /*! \{ */
488 typedef OSG_HASH_MAP(GLenum, Vec2f) ConstHash;
490 /*! \} */
491 /*---------------------------------------------------------------------*/
492 /*! \name Map for GL cvonstant handling */
493 /*! \{ */
495 void pushToDrawTasks(DrawTask * const value);
497 /*! \} */
498 /*---------------------------------------------------------------------*/
499 /*! \name GL object handling */
500 /*! \{ */
502 /*! \} */
503 /*========================== PRIVATE ================================*/
505 private:
507 typedef WindowBase Inherited;
509 typedef std::vector<WindowMTUncountedPtr> WindowStore;
511 friend class FieldContainer;
512 friend class WindowBase;
513 friend class DrawTask;
514 friend class WindowDrawTask;
515 friend class PassiveViewport;
517 static WindowStore _allWindows;
518 static Int32 _currentWindowId;
520 /*---------------------------------------------------------------------*/
521 /*! \name Static GL Object / Extension variables */
522 /*! \{ */
524 static LockRefPtr _GLObjectLock;
525 static LockRefPtr _staticWindowLock;
527 static std::vector<GLObject *> _glObjects;
528 static const Char8 *_glLibraryName;
531 * List of registered extension names. The index of the entry is the
532 * id/handle of the extention.
534 static std::vector<std::string> _registeredExtensions;
535 /** List of names of extensions to ignore. */
536 static std::vector<std::string> _ignoredExtensions;
537 static std::vector<bool > _commonExtensions; /**< ??? */
538 static std::vector<std::string> _registeredFunctions;
539 static std::vector<Int32 > _registeredFunctionExts;
540 static std::vector<UInt32 > _registeredFunctionVersions;
542 static std::vector<GLenum > _registeredConstants;
544 typedef std::pair<UInt32,UInt32> DestroyEntry;
546 std::list<DestroyEntry > _glObjectDestroyList;
548 /*! \} */
549 /*---------------------------------------------------------------------*/
550 /*! \name GL Object / Extension variables */
551 /*! \{ */
553 std::vector<UInt32 > _lastValidate;
554 std::vector<GLObjectId > _ids;
555 std::vector<GLObjectId > _idInfo;
557 UInt32 _glVersion;
558 std::vector<std::string > _extensions;
560 * List of whether extension can be used in current context. Indexed by
561 * extension id (registeredExtensions).
563 std::vector<bool > _availExtensions;
564 std::vector<GLExtensionFunction> _extFunctions;
566 ConstHash _availConstants;
568 Int32 _windowId;
569 TraversalValidator *_pTravValidator;
570 ShaderCache *_pShaderCache;
572 WindowDrawTaskRefPtr _pInitTask;
573 WindowDrawTaskRefPtr _pWaitTask;
574 WindowDrawTaskRefPtr _pSwapTask;
575 WindowDrawTaskRefPtr _pFrameInitTask;
576 WindowDrawTaskRefPtr _pFrameExitTask;
577 WindowDrawTaskRefPtr _pActivateTask;
578 WindowDrawTaskRefPtr _pDeactivateTask;
579 DrawTaskRefPtr _pGLFinishTask;
581 DrawEnv _oEnv;
583 /*! \} */
584 /*---------------------------------------------------------------------*/
586 // prohibit default functions (move to 'public' if you need one)
587 Window &operator =(const Window &source);
590 //---------------------------------------------------------------------------
591 // Exported Types
592 //---------------------------------------------------------------------------
594 typedef Window *WindowP;
596 OSG_END_NAMESPACE
598 #include "OSGWindowBase.inl"
599 #include "OSGWindow.inl"
601 #endif /* _OSGWINDOW_H_ */