Loading...
Searching...
No Matches

Class holding a valid drawing context. More...

#include <SFML/Window/Context.hpp>

Inheritance diagram for sf::Context:
sf::GlResource

Public Member Functions

 Context ()
 Default constructor.
 
 ~Context ()
 Destructor.
 
 Context (const Context &)=delete
 Deleted copy constructor.
 
Contextoperator= (const Context &)=delete
 Deleted copy assignment.
 
 Context (Context &&context) noexcept
 Move constructor.
 
Contextoperator= (Context &&context) noexcept
 Move assignment.
 
bool setActive (bool active)
 Activate or deactivate explicitly the context.
 
const ContextSettingsgetSettings () const
 Get the settings of the context.
 
 Context (const ContextSettings &settings, Vector2u size)
 Construct a in-memory context.
 

Static Public Member Functions

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.
 
static const ContextgetActiveContext ()
 Get the currently active context.
 
static std::uint64_t getActiveContextId ()
 Get the currently active context's ID.
 

Detailed Description

Class holding a valid drawing context.

If you need to make OpenGL calls without having an active window (like in a thread), you can use an instance of this class to get a valid context.

Having a valid context is necessary for every OpenGL call.

Note that a context is only active in its current thread, if you create a new thread it will have no valid context by default.

To use a sf::Context instance, just construct it and let it live as long as you need a valid context. No explicit activation is needed, all it has to do is to exist. Its destructor will take care of deactivating and freeing all the attached resources.

Usage example:

void threadFunction(void*)
{
sf::Context context;
// from now on, you have a valid context
// you can make OpenGL calls
glClear(GL_DEPTH_BUFFER_BIT);
}
// the context is automatically deactivated and destroyed
// by the sf::Context destructor
Class holding a valid drawing context.
Definition Context.hpp:58

Definition at line 57 of file Context.hpp.

Constructor & Destructor Documentation

◆ Context() [1/4]

sf::Context::Context ( )

Default constructor.

The constructor creates and activates the context

◆ ~Context()

sf::Context::~Context ( )

Destructor.

The destructor deactivates and destroys the context

◆ Context() [2/4]

sf::Context::Context ( const Context & )
delete

Deleted copy constructor.

◆ Context() [3/4]

sf::Context::Context ( Context && context)
noexcept

Move constructor.

◆ Context() [4/4]

sf::Context::Context ( const ContextSettings & settings,
Vector2u size )

Construct a in-memory context.

This constructor is for internal use, you don't need to bother with it.

Parameters
settingsCreation parameters
sizeBack buffer size

Member Function Documentation

◆ getActiveContext()

static const Context * sf::Context::getActiveContext ( )
staticnodiscard

Get the currently active context.

This function will only return sf::Context objects. Contexts created e.g. by RenderTargets or for internal use will not be returned by this function.

Returns
The currently active context or nullptr if none is active

◆ getActiveContextId()

static std::uint64_t sf::Context::getActiveContextId ( )
staticnodiscard

Get the currently active context's ID.

The context ID is used to identify contexts when managing unshareable OpenGL resources.

Returns
The active context's ID or 0 if no context is currently active

◆ getFunction()

static GlFunctionPointer sf::Context::getFunction ( const char * name)
staticnodiscard

Get the address of an OpenGL function.

On Windows when not using OpenGL ES, a context must be active for this function to succeed.

Parameters
nameName of the function to get the address of
Returns
Address of the OpenGL function, 0 on failure

◆ getSettings()

const ContextSettings & sf::Context::getSettings ( ) const
nodiscard

Get the settings of the context.

Note that these settings may be different than the ones passed to the constructor; they are indeed adjusted if the original settings are not directly supported by the system.

Returns
Structure containing the settings

◆ isExtensionAvailable()

static bool sf::Context::isExtensionAvailable ( std::string_view name)
staticnodiscard

Check whether a given OpenGL extension is available.

Parameters
nameName of the extension to check for
Returns
true if available, false if unavailable

◆ operator=() [1/2]

Context & sf::Context::operator= ( const Context & )
delete

Deleted copy assignment.

◆ operator=() [2/2]

Context & sf::Context::operator= ( Context && context)
noexcept

Move assignment.

◆ setActive()

bool sf::Context::setActive ( bool active)
nodiscard

Activate or deactivate explicitly the context.

Parameters
activetrue to activate, false to deactivate
Returns
true on success, false on failure

The documentation for this class was generated from the following file: