|
|
|||
File indexing completed on 2026-06-02 08:58:14
0001 //////////////////////////////////////////////////////////// 0002 // 0003 // SFML - Simple and Fast Multimedia Library 0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) 0005 // 0006 // This software is provided 'as-is', without any express or implied warranty. 0007 // In no event will the authors be held liable for any damages arising from the use of this software. 0008 // 0009 // Permission is granted to anyone to use this software for any purpose, 0010 // including commercial applications, and to alter it and redistribute it freely, 0011 // subject to the following restrictions: 0012 // 0013 // 1. The origin of this software must not be misrepresented; 0014 // you must not claim that you wrote the original software. 0015 // If you use this software in a product, an acknowledgment 0016 // in the product documentation would be appreciated but is not required. 0017 // 0018 // 2. Altered source versions must be plainly marked as such, 0019 // and must not be misrepresented as being the original software. 0020 // 0021 // 3. This notice may not be removed or altered from any source distribution. 0022 // 0023 //////////////////////////////////////////////////////////// 0024 0025 #ifndef SFML_CONTEXT_HPP 0026 #define SFML_CONTEXT_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/Window/Export.hpp> 0032 #include <SFML/Window/GlResource.hpp> 0033 #include <SFML/Window/ContextSettings.hpp> 0034 #include <SFML/System/NonCopyable.hpp> 0035 0036 0037 namespace sf 0038 { 0039 namespace priv 0040 { 0041 class GlContext; 0042 } 0043 0044 typedef void (*GlFunctionPointer)(); 0045 0046 //////////////////////////////////////////////////////////// 0047 /// \brief Class holding a valid drawing context 0048 /// 0049 //////////////////////////////////////////////////////////// 0050 class SFML_WINDOW_API Context : GlResource, NonCopyable 0051 { 0052 public: 0053 0054 //////////////////////////////////////////////////////////// 0055 /// \brief Default constructor 0056 /// 0057 /// The constructor creates and activates the context 0058 /// 0059 //////////////////////////////////////////////////////////// 0060 Context(); 0061 0062 //////////////////////////////////////////////////////////// 0063 /// \brief Destructor 0064 /// 0065 /// The destructor deactivates and destroys the context 0066 /// 0067 //////////////////////////////////////////////////////////// 0068 ~Context(); 0069 0070 //////////////////////////////////////////////////////////// 0071 /// \brief Activate or deactivate explicitly the context 0072 /// 0073 /// \param active True to activate, false to deactivate 0074 /// 0075 /// \return True on success, false on failure 0076 /// 0077 //////////////////////////////////////////////////////////// 0078 bool setActive(bool active); 0079 0080 //////////////////////////////////////////////////////////// 0081 /// \brief Get the settings of the context 0082 /// 0083 /// Note that these settings may be different than the ones 0084 /// passed to the constructor; they are indeed adjusted if the 0085 /// original settings are not directly supported by the system. 0086 /// 0087 /// \return Structure containing the settings 0088 /// 0089 //////////////////////////////////////////////////////////// 0090 const ContextSettings& getSettings() const; 0091 0092 //////////////////////////////////////////////////////////// 0093 /// \brief Check whether a given OpenGL extension is available 0094 /// 0095 /// \param name Name of the extension to check for 0096 /// 0097 /// \return True if available, false if unavailable 0098 /// 0099 //////////////////////////////////////////////////////////// 0100 static bool isExtensionAvailable(const char* name); 0101 0102 //////////////////////////////////////////////////////////// 0103 /// \brief Get the address of an OpenGL function 0104 /// 0105 /// \param name Name of the function to get the address of 0106 /// 0107 /// \return Address of the OpenGL function, 0 on failure 0108 /// 0109 //////////////////////////////////////////////////////////// 0110 static GlFunctionPointer getFunction(const char* name); 0111 0112 //////////////////////////////////////////////////////////// 0113 /// \brief Get the currently active context 0114 /// 0115 /// This function will only return sf::Context objects. 0116 /// Contexts created e.g. by RenderTargets or for internal 0117 /// use will not be returned by this function. 0118 /// 0119 /// \return The currently active context or NULL if none is active 0120 /// 0121 //////////////////////////////////////////////////////////// 0122 static const Context* getActiveContext(); 0123 0124 //////////////////////////////////////////////////////////// 0125 /// \brief Get the currently active context's ID 0126 /// 0127 /// The context ID is used to identify contexts when 0128 /// managing unshareable OpenGL resources. 0129 /// 0130 /// \return The active context's ID or 0 if no context is currently active 0131 /// 0132 //////////////////////////////////////////////////////////// 0133 static Uint64 getActiveContextId(); 0134 0135 //////////////////////////////////////////////////////////// 0136 /// \brief Construct a in-memory context 0137 /// 0138 /// This constructor is for internal use, you don't need 0139 /// to bother with it. 0140 /// 0141 /// \param settings Creation parameters 0142 /// \param width Back buffer width 0143 /// \param height Back buffer height 0144 /// 0145 //////////////////////////////////////////////////////////// 0146 Context(const ContextSettings& settings, unsigned int width, unsigned int height); 0147 0148 private: 0149 0150 //////////////////////////////////////////////////////////// 0151 // Member data 0152 //////////////////////////////////////////////////////////// 0153 priv::GlContext* m_context; //!< Internal OpenGL context 0154 }; 0155 0156 } // namespace sf 0157 0158 0159 #endif // SFML_CONTEXT_HPP 0160 0161 //////////////////////////////////////////////////////////// 0162 /// \class sf::Context 0163 /// \ingroup window 0164 /// 0165 /// If you need to make OpenGL calls without having an 0166 /// active window (like in a thread), you can use an 0167 /// instance of this class to get a valid context. 0168 /// 0169 /// Having a valid context is necessary for *every* OpenGL call. 0170 /// 0171 /// Note that a context is only active in its current thread, 0172 /// if you create a new thread it will have no valid context 0173 /// by default. 0174 /// 0175 /// To use a sf::Context instance, just construct it and let it 0176 /// live as long as you need a valid context. No explicit activation 0177 /// is needed, all it has to do is to exist. Its destructor 0178 /// will take care of deactivating and freeing all the attached 0179 /// resources. 0180 /// 0181 /// Usage example: 0182 /// \code 0183 /// void threadFunction(void*) 0184 /// { 0185 /// sf::Context context; 0186 /// // from now on, you have a valid context 0187 /// 0188 /// // you can make OpenGL calls 0189 /// glClear(GL_DEPTH_BUFFER_BIT); 0190 /// } 0191 /// // the context is automatically deactivated and destroyed 0192 /// // by the sf::Context destructor 0193 /// \endcode 0194 /// 0195 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|