Loading...
Searching...
No Matches
Context.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
31
33
35
36#include <memory>
37#include <string_view>
38
39#include <cstdint>
40
41
42namespace sf
43{
44namespace priv
45{
46class GlContext;
47}
48
49struct ContextSettings;
50
51using GlFunctionPointer = void (*)();
52
58{
59public:
67
75
80 Context(const Context&) = delete;
81
86 Context& operator=(const Context&) = delete;
87
92 Context(Context&& context) noexcept;
93
98 Context& operator=(Context&& context) noexcept;
99
108 [[nodiscard]] bool setActive(bool active);
109
120 [[nodiscard]] const ContextSettings& getSettings() const;
121
130 [[nodiscard]] static bool isExtensionAvailable(std::string_view name);
131
143 [[nodiscard]] static GlFunctionPointer getFunction(const char* name);
144
155 [[nodiscard]] static const Context* getActiveContext();
156
166 [[nodiscard]] static std::uint64_t getActiveContextId();
167
178 Context(const ContextSettings& settings, Vector2u size);
179
180private:
182 // Member data
184 std::unique_ptr<priv::GlContext> m_context;
185};
186
187} // namespace sf
188
189
#define SFML_WINDOW_API
Class holding a valid drawing context.
Definition Context.hpp:58
bool setActive(bool active)
Activate or deactivate explicitly the context.
Context & operator=(const Context &)=delete
Deleted copy assignment.
static const Context * getActiveContext()
Get the currently active context.
Context(const Context &)=delete
Deleted copy constructor.
const ContextSettings & getSettings() const
Get the settings of the context.
Context(const ContextSettings &settings, Vector2u size)
Construct a in-memory context.
~Context()
Destructor.
Context(Context &&context) noexcept
Move constructor.
static bool isExtensionAvailable(std::string_view name)
Check whether a given OpenGL extension is available.
static GlFunctionPointer getFunction(const char *name)
Get the address of an OpenGL function.
Context & operator=(Context &&context) noexcept
Move assignment.
Context()
Default constructor.
static std::uint64_t getActiveContextId()
Get the currently active context's ID.
Base class for classes that require an OpenGL context.
void(*)() GlFunctionPointer
Definition Context.hpp:51
Structure defining the settings of the OpenGL context attached to a window.