Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::render::opengl::Context Class Reference

OpenGL core profile context of a window, with every OpenGL function loaded. More...

#include <aegis2d/render/opengl/context.hpp>

Public Member Functions

 Context (const platform::Window &window, const ContextConfig &config={})
 Creates the context, makes it current and loads the OpenGL functions.
 
 Context (const Context &)=delete
 
Context & operator= (const Context &)=delete
 
 Context (Context &&other) noexcept
 Takes over the context of other, which must not be used afterwards.
 
Context & operator= (Context &&other) noexcept
 Destroys this context and takes over the context of other.
 
 ~Context ()
 Destroys the context.
 
void make_current ()
 Makes the context current on the calling thread.
 
void clear (Color color)
 Fills the whole framebuffer with one color.
 
void swap_buffers ()
 Shows the frame drawn since the previous call.
 
DebugOutput debug_output () const noexcept
 How OpenGL errors are reported for this context.
 
std::size_t check_errors ()
 Logs and clears the OpenGL errors recorded since the previous check.
 
Version version () const noexcept
 Version of the context actually created, as reported by the driver.
 
const DriverInfo & info () const noexcept
 Driver strings read when the context was created.
 

Static Public Member Functions

static Version required_version () noexcept
 Version the engine requires from the context.
 

Detailed Description

OpenGL core profile context of a window, with every OpenGL function loaded.

The context has the version the engine's OpenGL loader is generated for: 4.5, or 4.1 when AEGIS2D_MACOS_GL41 is on (the highest macOS supports). It is current on the creating thread once the constructor returns.

The OpenGL functions are process-wide: use one context, for one window. Destroy the context before its window.

Constructor & Destructor Documentation

◆ Context() [1/3]

aegis2d::render::opengl::Context::Context ( const platform::Window &  window,
const ContextConfig &  config = {} 
)
explicit

Creates the context, makes it current and loads the OpenGL functions.

Parameters
windowWindow created with platform::GraphicsApi::OpenGL.
configSwap behaviour of the context.
Exceptions
ContextErrorif the window is not an OpenGL window, or if the driver cannot give a context of the required version (macOS with the 4.5 build, Windows without a GPU driver, which only provides OpenGL 1.1).

◆ Context() [2/3]

aegis2d::render::opengl::Context::Context ( const Context &  )
delete

◆ Context() [3/3]

aegis2d::render::opengl::Context::Context ( Context &&  other)
noexcept

Takes over the context of other, which must not be used afterwards.

◆ ~Context()

aegis2d::render::opengl::Context::~Context ( )

Destroys the context.

Member Function Documentation

◆ check_errors()

std::size_t aegis2d::render::opengl::Context::check_errors ( )

Logs and clears the OpenGL errors recorded since the previous check.

Reads glGetError until no error is left, whatever debug_output() is. With DebugOutput::Callback, the driver has already logged each error, with more detail, when it happened.

Returns
Number of errors found.

◆ clear()

void aegis2d::render::opengl::Context::clear ( Color  color)

Fills the whole framebuffer with one color.

The viewport follows the window's pixel size, so a resized window is cleared entirely.

Parameters
colorColor to fill the framebuffer with.

◆ debug_output()

DebugOutput aegis2d::render::opengl::Context::debug_output ( ) const
noexcept

How OpenGL errors are reported for this context.

Returns
Off unless ContextConfig::debug was set; then Callback when the driver supports KHR_debug, Polling otherwise.

◆ info()

const DriverInfo & aegis2d::render::opengl::Context::info ( ) const
noexcept

Driver strings read when the context was created.

Returns
Vendor, renderer and version of the context.

◆ make_current()

void aegis2d::render::opengl::Context::make_current ( )

Makes the context current on the calling thread.

Exceptions
ContextErrorif SDL cannot make it current.

◆ operator=() [1/2]

Context & aegis2d::render::opengl::Context::operator= ( const Context &  )
delete

◆ operator=() [2/2]

Context & aegis2d::render::opengl::Context::operator= ( Context &&  other)
noexcept

Destroys this context and takes over the context of other.

Returns
This context.

◆ required_version()

static Version aegis2d::render::opengl::Context::required_version ( )
staticnoexcept

Version the engine requires from the context.

Returns
4.5, or 4.1 when built with AEGIS2D_MACOS_GL41.

◆ swap_buffers()

void aegis2d::render::opengl::Context::swap_buffers ( )

Shows the frame drawn since the previous call.

With DebugOutput::Polling, first logs the errors of the frame.

◆ version()

Version aegis2d::render::opengl::Context::version ( ) const
noexcept

Version of the context actually created, as reported by the driver.

Returns
At least required_version(); drivers may give a newer one.

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