Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGWindow.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 
00040 #ifndef _OSGWINDOW_H_
00041 #define _OSGWINDOW_H_
00042 #ifdef __sgi
00043 #pragma once
00044 #endif
00045 
00046 #include <OSGConfig.h>
00047 
00048 #include <list>
00049 #include <utility>
00050 
00051 #ifdef OSG_STL_HAS_HASH_MAP
00052 #ifdef OSG_HASH_MAP_AS_EXT
00053 #include <ext/hash_map>
00054 #else
00055 #include <hash_map>
00056 #endif
00057 #else
00058 #include <map>
00059 #endif
00060 
00061 #include <OSGTypedFunctors.h>
00062 
00063 #include <OSGWindowBase.h>
00064 
00065 OSG_BEGIN_NAMESPACE
00066 
00067 class DrawAction;
00068 class RenderActionBase;
00069 
00073 class OSG_SYSTEMLIB_DLLMAPPING Window : public WindowBase
00074 {
00075     /*==========================  PUBLIC  =================================*/
00076   public:
00077 
00078     enum GLObjectStatusE 
00079     {
00080         notused      = 1, 
00081         initialize, 
00082         reinitialize, 
00083         initialized,
00084         needrefresh, 
00085         destroy, 
00086         finaldestroy 
00087     };
00088 
00089     enum { invalidExtensionID = 0x7fffffff, invalidFunctionID = 0x7fffffff };
00090 
00091     // max status value = 7, 3 bit shift is enough 
00092     enum { statusShift = 3, statusMask = 7 }; 
00093 
00094     static const Real32 unknownConstant;    
00095     
00096     typedef ArgsCollector<UInt32>                      GLObjectFunctorArgs;
00097 
00098     typedef TypedVoidFunctor2Base<PtrCallArg<Window> , 
00099                                   GLObjectFunctorArgs> GLObjectFunctor;
00100 
00101     typedef void (*GLExtensionFunction)(void);
00102 
00103     /*---------------------------------------------------------------------*/
00107     static const char *getClassname(void) { return "Window"; };
00108 
00110     /*---------------------------------------------------------------------*/
00114     virtual void changed(BitVector  whichField,
00115                          UInt32     origin   );
00116 
00118     /*---------------------------------------------------------------------*/
00122     void addPort      (const ViewportPtr &portP);
00123     void insertPort   (      UInt32       portIndex,
00124                        const ViewportPtr &portP);
00125 
00126     void replacePort  (      UInt32       portIndex,
00127                        const ViewportPtr &portP);
00128     void replacePortBy(const ViewportPtr &portP,
00129                        const ViewportPtr &newPortP);
00130 
00131     void subPort      (const ViewportPtr &portP);
00132     void subPort      (      UInt32       portIndex);
00133 
00134 
00136     /*---------------------------------------------------------------------*/
00140     static UInt32   registerExtension ( const Char8 *s   );
00141     static void     ignoreExtensions  ( const Char8 *s   );
00142 
00143     static UInt32   registerFunction  ( const Char8 *s,  Int32 ext = -1   );
00144 
00145     static void     registerConstant  (       GLenum val );
00146 
00148     /*---------------------------------------------------------------------*/
00152     static 
00153     inline void                 setGLLibraryName  (const Char8  *s   );
00154 
00155     static 
00156     inline Int32                getExtensionId    (const Char8  *s   );
00157     inline bool                 hasExtension      (      UInt32  id  );
00158            bool                 hasExtension      (const Char8  *s   );
00159     static 
00160     inline bool                 hasCommonExtension(      UInt32  id  );
00161            void                *getFunction       (      UInt32  id  );
00162            void                *getFunctionNoCheck(      UInt32  id  );
00163            void                 dumpExtensions    (      void        );
00164            GLExtensionFunction  getFunctionByName (const Char8  *s   );
00165     inline Real32               getConstantValue  (      GLenum  val );
00166            const  Vec2f        &getConstantValuev (      GLenum  val );    
00167     
00168     static  
00169     inline const std::vector<std::string> &getRegisteredExtensions(void);   
00170     inline const std::vector<std::string> &getRegisteredFunctions (void);   
00171     inline const std::vector<std::string> &getExtensions          (void);
00172     inline const std::vector<std::string> &getIgnoredExtensions   (void);
00173     
00175     /*---------------------------------------------------------------------*/
00179     static UInt32   registerGLObject  (GLObjectFunctor functor, 
00180                                        UInt32 num = 1);
00181 
00183     /*---------------------------------------------------------------------*/
00187     void            validateGLObject    (UInt32 id);
00188     void            validateAllGLObjects(void);
00189     GLObjectStatusE getGLObjectStatus   (UInt32 id);
00190     inline void     setGLObjectId       (UInt32 id, UInt32 id2);
00191     inline UInt32   getGLObjectId       (UInt32 id);
00192 
00193     static void     refreshGLObject     (UInt32 id);
00194     static void     reinitializeGLObject(UInt32 id);
00195     static void     destroyGLObject     (UInt32 id, UInt32 num = 1);
00196     static inline void unpackIdStatus   (UInt32 idstatus, UInt32 &id, 
00197                                                 GLObjectStatusE &status);
00198 
00200     /*---------------------------------------------------------------------*/
00204             bool isResizePending( void );
00205 
00206     virtual void resize         (int width, int height);
00207     virtual void resizeGL       (void);
00208 
00209             void setSize        (UInt16 width, UInt16 height);
00210 
00212     /*---------------------------------------------------------------------*/
00216     virtual void    frameInit        (void); 
00217     virtual void    frameExit        (void);
00218 
00219     virtual void    draw              ( DrawAction   *action = NULL );
00220     virtual void    drawAllViewports  ( DrawAction   *action = NULL );
00221 
00222     virtual void    render            (RenderActionBase *action = NULL);
00223     virtual void    renderAllViewports(RenderActionBase *action = NULL);
00224 
00226     /*---------------------------------------------------------------------*/
00230     virtual void init       ( void ) = 0;
00231     virtual void activate   ( void ) = 0;
00232     virtual void deactivate ( void ) = 0;
00233     virtual void swap       ( void ) = 0;
00234 
00236     /*---------------------------------------------------------------------*/
00240     virtual void dump(      UInt32    uiIndent = 0,
00241                       const BitVector bvFlags  = 0) const;
00242 
00245     /*=========================  PROTECTED  ===============================*/
00246   protected:
00247     /*---------------------------------------------------------------------*/
00251     Window(void);
00252     Window(const Window &source);
00253 
00255     /*---------------------------------------------------------------------*/
00259     virtual ~Window(void);
00260 
00262     /*---------------------------------------------------------------------*/
00266     virtual void setupGL(void);
00267 
00269     /*---------------------------------------------------------------------*/
00273     static        void   initRegisterGLObject  (UInt32 id, UInt32 num);
00274 
00275     static inline UInt32 packIdStatus          (UInt32 id, 
00276                                                 GLObjectStatusE status);
00277 
00278                   void   doInitRegisterGLObject(UInt32 id, UInt32 num);
00279 
00282     /*---------------------------------------------------------------------*/
00286     class GLObject;
00287 
00288     friend class GLObject;
00289 
00290     class GLObject {
00291 
00292       public:
00293         GLObject(GLObjectFunctor funct);
00294 
00295         GLObjectFunctor& getFunctor(void                 );
00296         void             setFunctor(GLObjectFunctor funct);
00297 
00298         UInt32 getLastValidate(void      );
00299         void   setLastValidate(UInt32 val);
00300 
00301         UInt32 getRefCounter(void);
00302         UInt32 incRefCounter(void);
00303         UInt32 decRefCounter(void);
00304  
00305       protected:
00306         GLObjectFunctor _functor;
00307         volatile UInt32 _refCounter;
00308                  UInt32 _lastValidate;
00309     };
00310 
00312     /*---------------------------------------------------------------------*/
00316 #ifdef OSG_STL_HAS_HASH_MAP
00317     typedef 
00318         OSG_STDEXTENSION_NAMESPACE::hash_map<
00319             GLenum,  
00320             Vec2f> ConstHash;
00321 #else
00322     typedef 
00323         std::map< GLenum,  Vec2f > ConstHash;
00324 #endif
00325 
00327     /*==========================  PRIVATE  ================================*/
00328   private:
00329 
00330     typedef WindowBase Inherited;
00331 
00332     friend class FieldContainer;
00333     friend class WindowBase;
00334 
00335     static std::vector<WindowPtr> _allWindows;
00336     static UInt32                 _currentWindowId;
00337 
00338     static void initMethod(void);
00339 
00340     void onCreate      (const Window *source = NULL);
00341     void onCreateAspect(const Window *aspect0,
00342                         const Window *source = NULL);
00343 
00344     void onDestroy(void);
00345 
00346     static void staticAcquire(void);
00347     static void staticRelease(void);
00348 
00349     /*---------------------------------------------------------------------*/
00353     static Lock                      *_GLObjectLock;
00354     static Lock                      *_staticWindowLock;
00355     static std::vector<GLObject  *>   _glObjects;
00356     static const Char8               *_glLibraryName;
00357 
00358     static std::vector<std::string>   _registeredExtensions;
00359     static std::vector<std::string>   _ignoredExtensions;
00360     static std::vector<bool       >   _commonExtensions;
00361     static std::vector<std::string>   _registeredFunctions;
00362     static std::vector<Int32      >   _registeredFunctionExts;
00363 
00364     static std::vector<GLenum     >   _registeredConstants;
00365 
00366     typedef std::pair<UInt32,UInt32>   DestroyEntry;
00367     std::list<DestroyEntry >  _glObjectDestroyList;
00368 
00371     /*---------------------------------------------------------------------*/
00375     std::vector<UInt32     > _lastValidate;
00376     std::vector<UInt32     > _ids;
00377 
00378     std::vector<std::string> _extensions;
00379     std::vector<bool       > _availExtensions;
00380     std::vector<void      *> _extFunctions;
00381     ConstHash                _availConstants;
00382     UInt32                   _numAvailConstants;
00383 
00386     UInt32                   _windowId;
00387 
00388     // prohibit default functions (move to 'public' if you need one)
00389 
00390     Window& operator =(const Window &source);
00391 };
00392 
00393 //---------------------------------------------------------------------------
00394 //   Exported Types
00395 //---------------------------------------------------------------------------
00396 
00397 typedef Window *WindowP;
00398 
00399 OSG_END_NAMESPACE
00400 
00401 #include <OSGWindowBase.inl>
00402 #include <OSGWindow.inl>
00403 
00404 #define OSGWINDOW_HEADER_CVSID "@(#)$Id:$"
00405 
00406 #endif /* _OSGWINDOW_H_ */

Generated on Thu Aug 25 04:12:11 2005 for OpenSG by  doxygen 1.4.3