]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/clouds3d/SkyContext.hpp
Tweak lib name.
[simgear.git] / simgear / scene / sky / clouds3d / SkyContext.hpp
1 //------------------------------------------------------------------------------
2 // File : SkyContext.hpp
3 //------------------------------------------------------------------------------
4 // SkyWorks : Copyright 2002 Mark J. Harris and
5 //                                              The University of North Carolina at Chapel Hill
6 //------------------------------------------------------------------------------
7 // Permission to use, copy, modify, distribute and sell this software and its 
8 // documentation for any purpose is hereby granted without fee, provided that 
9 // the above copyright notice appear in all copies and that both that copyright 
10 // notice and this permission notice appear in supporting documentation. 
11 // Binaries may be compiled with this software without any royalties or 
12 // restrictions. 
13 //
14 // The author(s) and The University of North Carolina at Chapel Hill make no 
15 // representations about the suitability of this software for any purpose. 
16 // It is provided "as is" without express or implied warranty.
17 /**
18  * @file SkyContext.hpp
19  * 
20  * Graphics Context Interface.  Initializes GL extensions, etc. 
21  */
22 #ifndef __SKYCONTEXT_HPP__
23 #define __SKYCONTEXT_HPP__
24
25 // warning for truncation of template name for browse info
26 #pragma warning( disable : 4786)
27
28 #include "SkySingleton.hpp"
29
30
31 #ifdef _WIN32
32 #include "extgl.h"
33 #endif
34
35 #include <list>
36 #include <map>
37 #include <algorithm>
38
39 //  ifdef to replace windows stuff for handles-JW
40 typedef void *HANDLE;
41 typedef HANDLE *PHANDLE;
42 #define DECLARE_HANDLE(n)  typedef HANDLE n
43
44 DECLARE_HANDLE(HGLRC);
45 // end of ifdef
46
47 class SkyContext;
48 class SkyMaterial;
49 class SkyTextureState;
50
51 //! Graphics Context Singleton declaration.
52 /*! The Context must be created by calling GraphicsContext::Instantiate(). */
53 typedef SkySingleton<SkyContext> GraphicsContext;
54
55 //------------------------------------------------------------------------------
56 /**
57  * @class SkyContext
58  * @brief A manager / proxy for the state of OpenGL contexts.
59  * 
60  * @todo <WRITE EXTENDED CLASS DESCRIPTION>
61  */
62 class SkyContext
63 {
64 public: // datatypes
65
66   //------------------------------------------------------------------------------
67   /**
68    * @class Listener
69    * @brief Inherit this class and overide its methods to be notified of context events.
70    */
71   class Listener
72         {
73         public:
74
75     //! Handle a change in the dimensions of the graphics window.
76                 virtual SKYRESULT GraphicsReshapeEvent()      { return SKYRESULT_OK; }
77         };
78
79   /**
80    * @enum SkyMessageType messages that the context can generate for it's listeners.
81    */
82         enum SkyMessageType
83         {
84                 SKYCONTEXT_MESSAGE_RESHAPE,
85           SKYCONTEXT_MESSAGE_COUNT
86         };
87
88 public: // methods
89
90   SKYRESULT        ProcessReshapeEvent(int iWidth, int iHeight);
91   SKYRESULT        InitializeExtension(const char *pExtensionName);
92
93   //! Returns the current dimensions of the window.
94   void             GetWindowSize(int &iWidth, int &iHeight) { iWidth = _iWidth; iHeight = _iHeight; }
95
96   SkyMaterial*     GetCurrentMaterial();
97   SkyTextureState* GetCurrentTextureState();
98
99   SKYRESULT        AddCurrentGLContext();
100
101   //------------------------------------------------------------------------------
102         // Register with the messaging system to handle notification of mode changes
103         //------------------------------------------------------------------------------
104         SKYRESULT        Register(Listener   *pListener, int priority = 0);
105         SKYRESULT        UnRegister(Listener *pLlistener);
106
107 protected: // methods
108         SkyContext();
109         ~SkyContext();
110
111 protected: // data
112         int _iWidth;
113   int _iHeight;
114
115   typedef std::map<HGLRC, SkyMaterial*>     ContextMaterialMap;
116   typedef ContextMaterialMap::iterator      ContextMaterialIterator;
117   typedef std::map<HGLRC, SkyTextureState*> ContextTextureStateMap;
118   typedef ContextTextureStateMap::iterator  ContextTextureStateIterator;
119
120   ContextMaterialMap      _currentMaterials;
121   ContextTextureStateMap  _currentTextureState;
122
123   //------------------------------------------------------------------------------
124         // Messaging system to handle notification of mode changes
125         //------------------------------------------------------------------------------
126         typedef std::pair<int, Listener*> ListenerPair;
127         class _ListenerPred
128         {
129         public:
130                 _ListenerPred(const Listener* l) { _l = l; }
131                 bool operator()(const ListenerPair& pair) { return pair.second == _l; }
132         protected:
133                 const Listener *_l;
134         };
135
136         SKYRESULT _SendMessage(SkyMessageType msg);
137         std::list<ListenerPair> _listeners;
138
139 };
140
141 #endif //__SKYCONTEXT_HPP__