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
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.
18 * @file SkyContext.hpp
20 * Graphics Context Interface. Initializes GL extensions, etc.
22 #ifndef __SKYCONTEXT_HPP__
23 #define __SKYCONTEXT_HPP__
26 # include <simgear_config.h>
29 // warning for truncation of template name for browse info
30 // #pragma warning( disable : 4786)
31 #include "SkySingleton.hpp"
32 #include <simgear/compiler.h>
40 typedef HANDLE *PHANDLE;
41 #define DECLARE_HANDLE(n) typedef HANDLE n
42 DECLARE_HANDLE(HGLRC);
47 class SkyTextureState;
49 //! Graphics Context Singleton declaration.
50 /*! The Context must be created by calling GraphicsContext::Instantiate(). */
51 typedef SkySingleton<SkyContext> GraphicsContext;
53 //------------------------------------------------------------------------------
56 * @brief A manager / proxy for the state of OpenGL contexts.
58 * @todo <WRITE EXTENDED CLASS DESCRIPTION>
64 //------------------------------------------------------------------------------
67 * @brief Inherit this class and overide its methods to be notified of context events.
73 //! Handle a change in the dimensions of the graphics window.
74 virtual SKYRESULT GraphicsReshapeEvent() { return SKYRESULT_OK; }
78 * @enum SkyMessageType messages that the context can generate for it's listeners.
82 SKYCONTEXT_MESSAGE_RESHAPE,
83 SKYCONTEXT_MESSAGE_COUNT
88 SKYRESULT ProcessReshapeEvent(int iWidth, int iHeight);
89 SKYRESULT InitializeExtension(const char *pExtensionName);
91 //! Returns the current dimensions of the window.
92 void GetWindowSize(int &iWidth, int &iHeight) { iWidth = _iWidth; iHeight = _iHeight; }
94 SkyMaterial* GetCurrentMaterial();
95 SkyTextureState* GetCurrentTextureState();
97 SKYRESULT AddCurrentGLContext();
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);
105 protected: // methods
113 typedef std::map<HGLRC, SkyMaterial*> ContextMaterialMap;
114 typedef ContextMaterialMap::iterator ContextMaterialIterator;
115 typedef std::map<HGLRC, SkyTextureState*> ContextTextureStateMap;
116 typedef ContextTextureStateMap::iterator ContextTextureStateIterator;
118 ContextMaterialMap _currentMaterials;
119 ContextTextureStateMap _currentTextureState;
121 //------------------------------------------------------------------------------
122 // Messaging system to handle notification of mode changes
123 //------------------------------------------------------------------------------
124 typedef std::pair<int, Listener*> ListenerPair;
128 _ListenerPred(const Listener* l) { _l = l; }
129 bool operator()(const ListenerPair& pair) { return pair.second == _l; }
134 SKYRESULT _SendMessage(SkyMessageType msg);
135 std::list<ListenerPair> _listeners;
139 #endif //__SKYCONTEXT_HPP__