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__
25 // warning for truncation of template name for browse info
26 #pragma warning( disable : 4786)
28 #include "SkySingleton.hpp"
39 // ifdef to replace windows stuff for handles-JW
41 typedef HANDLE *PHANDLE;
42 #define DECLARE_HANDLE(n) typedef HANDLE n
44 DECLARE_HANDLE(HGLRC);
49 class SkyTextureState;
51 //! Graphics Context Singleton declaration.
52 /*! The Context must be created by calling GraphicsContext::Instantiate(). */
53 typedef SkySingleton<SkyContext> GraphicsContext;
55 //------------------------------------------------------------------------------
58 * @brief A manager / proxy for the state of OpenGL contexts.
60 * @todo <WRITE EXTENDED CLASS DESCRIPTION>
66 //------------------------------------------------------------------------------
69 * @brief Inherit this class and overide its methods to be notified of context events.
75 //! Handle a change in the dimensions of the graphics window.
76 virtual SKYRESULT GraphicsReshapeEvent() { return SKYRESULT_OK; }
80 * @enum SkyMessageType messages that the context can generate for it's listeners.
84 SKYCONTEXT_MESSAGE_RESHAPE,
85 SKYCONTEXT_MESSAGE_COUNT
90 SKYRESULT ProcessReshapeEvent(int iWidth, int iHeight);
91 SKYRESULT InitializeExtension(const char *pExtensionName);
93 //! Returns the current dimensions of the window.
94 void GetWindowSize(int &iWidth, int &iHeight) { iWidth = _iWidth; iHeight = _iHeight; }
96 SkyMaterial* GetCurrentMaterial();
97 SkyTextureState* GetCurrentTextureState();
99 SKYRESULT AddCurrentGLContext();
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);
107 protected: // methods
115 typedef std::map<HGLRC, SkyMaterial*> ContextMaterialMap;
116 typedef ContextMaterialMap::iterator ContextMaterialIterator;
117 typedef std::map<HGLRC, SkyTextureState*> ContextTextureStateMap;
118 typedef ContextTextureStateMap::iterator ContextTextureStateIterator;
120 ContextMaterialMap _currentMaterials;
121 ContextTextureStateMap _currentTextureState;
123 //------------------------------------------------------------------------------
124 // Messaging system to handle notification of mode changes
125 //------------------------------------------------------------------------------
126 typedef std::pair<int, Listener*> ListenerPair;
130 _ListenerPred(const Listener* l) { _l = l; }
131 bool operator()(const ListenerPair& pair) { return pair.second == _l; }
136 SKYRESULT _SendMessage(SkyMessageType msg);
137 std::list<ListenerPair> _listeners;
141 #endif //__SKYCONTEXT_HPP__