]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/clouds3d/SkyContext.hpp
Clouds3D crashes because there is no Light
[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 #ifdef HAVE_CONFIG_H
26 #  include <simgear_config.h>
27 #endif
28
29 // warning for truncation of template name for browse info
30 // #pragma warning( disable : 4786)
31 #include "SkySingleton.hpp"
32 #include <simgear/compiler.h>
33 #include <list>
34 #include <map>
35 #include <algorithm>
36 #ifdef WIN32
37 # include "extgl.h"
38 #else
39 typedef void *HANDLE;
40 typedef HANDLE *PHANDLE;
41 #define DECLARE_HANDLE(n)  typedef HANDLE n
42 DECLARE_HANDLE(HGLRC);
43 #endif
44
45 class SkyContext;
46 class SkyMaterial;
47 class SkyTextureState;
48
49 //! Graphics Context Singleton declaration.
50 /*! The Context must be created by calling GraphicsContext::Instantiate(). */
51 typedef SkySingleton<SkyContext> GraphicsContext;
52
53 //------------------------------------------------------------------------------
54 /**
55  * @class SkyContext
56  * @brief A manager / proxy for the state of OpenGL contexts.
57  * 
58  * @todo <WRITE EXTENDED CLASS DESCRIPTION>
59  */
60 class SkyContext
61 {
62 public: // datatypes
63
64   //------------------------------------------------------------------------------
65   /**
66    * @class Listener
67    * @brief Inherit this class and overide its methods to be notified of context events.
68    */
69   class Listener
70         {
71         public:
72
73     //! Handle a change in the dimensions of the graphics window.
74                 virtual SKYRESULT GraphicsReshapeEvent()      { return SKYRESULT_OK; }
75         };
76
77   /**
78    * @enum SkyMessageType messages that the context can generate for it's listeners.
79    */
80         enum SkyMessageType
81         {
82                 SKYCONTEXT_MESSAGE_RESHAPE,
83           SKYCONTEXT_MESSAGE_COUNT
84         };
85
86 public: // methods
87
88   SKYRESULT        ProcessReshapeEvent(int iWidth, int iHeight);
89   SKYRESULT        InitializeExtension(const char *pExtensionName);
90
91   //! Returns the current dimensions of the window.
92   void             GetWindowSize(int &iWidth, int &iHeight) { iWidth = _iWidth; iHeight = _iHeight; }
93
94   SkyMaterial*     GetCurrentMaterial();
95   SkyTextureState* GetCurrentTextureState();
96
97   SKYRESULT        AddCurrentGLContext();
98
99   //------------------------------------------------------------------------------
100         // Register with the messaging system to handle notification of mode changes
101         //------------------------------------------------------------------------------
102         SKYRESULT        Register(Listener   *pListener, int priority = 0);
103         SKYRESULT        UnRegister(Listener *pLlistener);
104
105 protected: // methods
106         SkyContext();
107         ~SkyContext();
108
109 protected: // data
110         int _iWidth;
111   int _iHeight;
112
113   typedef std::map<HGLRC, SkyMaterial*>     ContextMaterialMap;
114   typedef ContextMaterialMap::iterator      ContextMaterialIterator;
115   typedef std::map<HGLRC, SkyTextureState*> ContextTextureStateMap;
116   typedef ContextTextureStateMap::iterator  ContextTextureStateIterator;
117
118   ContextMaterialMap      _currentMaterials;
119   ContextTextureStateMap  _currentTextureState;
120
121   //------------------------------------------------------------------------------
122         // Messaging system to handle notification of mode changes
123         //------------------------------------------------------------------------------
124         typedef std::pair<int, Listener*> ListenerPair;
125         class _ListenerPred
126         {
127         public:
128                 _ListenerPred(const Listener* l) { _l = l; }
129                 bool operator()(const ListenerPair& pair) { return pair.second == _l; }
130         protected:
131                 const Listener *_l;
132         };
133
134         SKYRESULT _SendMessage(SkyMessageType msg);
135         std::list<ListenerPair> _listeners;
136
137 };
138
139 #endif //__SKYCONTEXT_HPP__