00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
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
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 void clearPorts ( void );
00135
00137
00141 static UInt32 registerExtension ( const Char8 *s );
00142 static void ignoreExtensions ( const Char8 *s );
00143
00144 static UInt32 registerFunction ( const Char8 *s, Int32 ext = -1,
00145 UInt32 version = 0xffff);
00146
00147 static void registerConstant ( GLenum val );
00148
00150
00154 static
00155 inline void setGLLibraryName (const Char8 *s );
00156
00157 inline UInt32 getGLVersion ( void );
00158
00159 static
00160 inline Int32 getExtensionId (const Char8 *s );
00161 inline bool hasExtension ( UInt32 id );
00162 bool hasExtension (const Char8 *s );
00163 static
00164 inline bool hasCommonExtension( UInt32 id );
00165 void *getFunction ( UInt32 id );
00166 void *getFunctionNoCheck( UInt32 id );
00167 void dumpExtensions ( void );
00168 GLExtensionFunction getFunctionByName (const Char8 *s );
00169 inline Real32 getConstantValue ( GLenum val );
00170 const Vec2f &getConstantValuev ( GLenum val );
00171
00172 static
00173 inline const std::vector<std::string> &getRegisteredExtensions(void);
00174 inline const std::vector<std::string> &getRegisteredFunctions (void);
00175 inline const std::vector<std::string> &getExtensions (void);
00176 inline const std::vector<std::string> &getIgnoredExtensions (void);
00177
00179
00183 static UInt32 registerGLObject (GLObjectFunctor functor,
00184 UInt32 num = 1);
00185
00187
00191 void validateGLObject (UInt32 id);
00192 void validateAllGLObjects(void);
00193
00194 inline void setGLObjectId (UInt32 id, UInt32 id2);
00195 inline UInt32 getGLObjectId (UInt32 id);
00196 static
00197 inline UInt32 getGLObjectsSize (void);
00198
00199 static void refreshGLObject (UInt32 id);
00200 static void refreshAllGLObjects (void);
00201 static void reinitializeGLObject(UInt32 id);
00202 static void reinitializeAllGLObjects(void);
00203 static void destroyGLObject (UInt32 id, UInt32 num = 1);
00204 static inline void unpackIdStatus (UInt32 idstatus, UInt32 &id,
00205 GLObjectStatusE &status);
00206
00208
00212 bool isResizePending( void );
00213
00214 virtual void resize (int width, int height);
00215 virtual void resizeGL (void);
00216
00217 void setSize (UInt16 width, UInt16 height);
00218
00220
00224 virtual void frameInit (void);
00225 virtual void frameExit (void);
00226
00227 virtual void draw ( DrawAction *action = NULL );
00228 virtual void drawAllViewports ( DrawAction *action = NULL );
00229
00230 virtual void render (RenderActionBase *action = NULL);
00231 virtual void renderAllViewports(RenderActionBase *action = NULL);
00232
00234
00238 virtual void init ( void ) = 0;
00239 virtual void activate ( void ) = 0;
00240 virtual void deactivate ( void ) = 0;
00241 virtual void swap ( void ) = 0;
00242
00244
00248 virtual void dump( UInt32 uiIndent = 0,
00249 const BitVector bvFlags = 0) const;
00250
00253
00254 protected:
00255
00259 Window(void);
00260 Window(const Window &source);
00261
00263
00267 virtual ~Window(void);
00268
00270
00274 virtual void setupGL(void);
00275
00277
00281 static void initRegisterGLObject (UInt32 id, UInt32 num);
00282
00283 static inline UInt32 packIdStatus (UInt32 id,
00284 GLObjectStatusE status);
00285
00286 void doInitRegisterGLObject(UInt32 id, UInt32 num);
00287
00290
00294 class GLObject;
00295
00296 friend class GLObject;
00297
00298 class GLObject {
00299
00300 public:
00301 GLObject(GLObjectFunctor funct);
00302
00303 GLObjectFunctor& getFunctor(void );
00304 void setFunctor(GLObjectFunctor funct);
00305
00306 UInt32 getLastValidate(void );
00307 void setLastValidate(UInt32 val);
00308
00309 UInt32 getRefCounter(void);
00310 UInt32 incRefCounter(void);
00311 UInt32 decRefCounter(void);
00312
00313 protected:
00314 GLObjectFunctor _functor;
00315 volatile UInt32 _refCounter;
00316 UInt32 _lastValidate;
00317 };
00318
00320
00324 #ifdef OSG_STL_HAS_HASH_MAP
00325 typedef
00326 OSG_STDEXTENSION_NAMESPACE::hash_map<
00327 GLenum,
00328 Vec2f> ConstHash;
00329 #else
00330 typedef
00331 std::map< GLenum, Vec2f > ConstHash;
00332 #endif
00333
00335
00336 private:
00337
00338 typedef WindowBase Inherited;
00339
00340 friend class FieldContainer;
00341 friend class WindowBase;
00342
00343 static std::vector<WindowPtr> _allWindows;
00344 static UInt32 _currentWindowId;
00345
00346 static void initMethod(void);
00347
00348 void onCreate (const Window *source = NULL);
00349 void onCreateAspect(const Window *aspect0,
00350 const Window *source = NULL);
00351
00352 void onDestroy(void);
00353
00354 static void staticAcquire(void);
00355 static void staticRelease(void);
00356
00357
00361 static Lock *_GLObjectLock;
00362 static Lock *_staticWindowLock;
00363 static std::vector<GLObject *> _glObjects;
00364 static const Char8 *_glLibraryName;
00365
00366 static std::vector<std::string> _registeredExtensions;
00367 static std::vector<std::string> _ignoredExtensions;
00368 static std::vector<bool > _commonExtensions;
00369 static std::vector<std::string> _registeredFunctions;
00370 static std::vector<Int32 > _registeredFunctionExts;
00371 static std::vector<UInt32 > _registeredFunctionVersions;
00372
00373 static std::vector<GLenum > _registeredConstants;
00374
00375 typedef std::pair<UInt32,UInt32> DestroyEntry;
00376 std::list<DestroyEntry > _glObjectDestroyList;
00377
00380
00384 std::vector<UInt32 > _lastValidate;
00385 std::vector<UInt32 > _ids;
00386
00387 UInt32 _glVersion;
00388 std::vector<std::string> _extensions;
00389 std::vector<bool > _availExtensions;
00390 std::vector<void *> _extFunctions;
00391 ConstHash _availConstants;
00392 UInt32 _numAvailConstants;
00393
00396 UInt32 _windowId;
00397
00398
00399
00400 Window& operator =(const Window &source);
00401 };
00402
00403
00404
00405
00406
00407 typedef Window *WindowP;
00408
00409 OSG_END_NAMESPACE
00410
00411 #include <OSGWindowBase.inl>
00412 #include <OSGWindow.inl>
00413
00414 #define OSGWINDOW_HEADER_CVSID "@(#)$Id:$"
00415
00416 #endif