Skip to main content

GLFWWindow Class

An OpenGL focused window implementation using GLFW. More...

Declaration

class helios::ext::glfw::window::GLFWWindow { ... }

Base class

classWindow

Abstract base class representing a generic window. More...

Public Constructors Index

GLFWWindow (const GLFWWindow &)=delete

Do not copy instances of GLFWWindow. More...

GLFWWindow (std::unique_ptr< helios::rendering::RenderTarget > renderTarget, const GLFWWindowConfig &cfg)

Constructs a new GLFWWindow based in the provided configuration. The underlying native window is not created until show() is called. More...

Public Destructor Index

~GLFWWindow () override

Destructor. Delegates to destroy(). More...

Public Operators Index

GLFWWindow &operator= (const GLFWWindow &)=delete

Public Member Functions Index

boolshow () noexcept override

Creates and displays the underlying native `GlFWwindow`. More...

voidswapBuffers () const noexcept override

Swaps the front and back buffers of the window. More...

voidpollEvents () const noexcept override

Processes all events in the underlying Window's EventQueue. More...

voidsetShouldClose (bool close) override

Sets the close flag of this window. More...

boolshouldClose () const override

Checks if the window has received a close request. More...

GLFWframebuffersizefunframeBufferSizeCallback () const noexcept

Returns the framebuffer resize callback function. More...

voidsetFrameBufferSizeCallback (GLFWframebuffersizefun framebufferSizeCallback) noexcept

Sets the callback function for framebuffer resize events. More...

GLFWwindow *nativeHandle () const noexcept

Returns the raw native GLFWwindow handle. More...

voiddestroy () const

Removed the underlying native handle of the GLFWwindow. More...

voidsetWindowUserPointer (std::unique_ptr< GLFWWindowUserPointer > windowUserPointer) noexcept

Sets the user-defined pointer for his GLFWWindow. More...

const GLFWWindowUserPointer &windowUserPointer () const noexcept

Returns a const reference to the `GLFWWindowUserPointer` managed by this class. More...

Private Member Attributes Index

GLFWwindow *nativeHandle_ = nullptr

The native GLFWwindow handle. More...

GLFWframebuffersizefunframeBufferSizeCallback_

C-style callback function for framebuffer resize events. This function pointer is passed to `glfwSetFramebufferSizeCallback`. More...

std::unique_ptr< GLFWWindowUserPointer >windowUserPointer_

A unique_ptr to the to an object holding user defined data for the native GLFWwindow. This information gets forwarded using `glfwSetWindowUserPointer`. More...

Description

An OpenGL focused window implementation using GLFW.

This class manages a `GLFWwindow` handle, providing methods for creation, display, event polling and resource cleanup.

Todo

add glfwSetWindowRefreshCallback

Definition at line 29 of file GLFWWindow.ixx.

Public Constructors

GLFWWindow()

helios::ext::glfw::window::GLFWWindow::GLFWWindow (const GLFWWindow &)
delete

Do not copy instances of GLFWWindow.

Definition at line 54 of file GLFWWindow.ixx.

Reference GLFWWindow.

Referenced by GLFWWindow and operator=.

GLFWWindow()

helios::ext::glfw::window::GLFWWindow::GLFWWindow (std::unique_ptr< helios::rendering::RenderTarget > renderTarget, const GLFWWindowConfig & cfg)
inline explicit

Constructs a new GLFWWindow based in the provided configuration. The underlying native window is not created until show() is called.

Parameters
cfg

A const ref to this window's configuration-

Definition at line 71 of file GLFWWindow.ixx.

71 explicit GLFWWindow(
72 std::unique_ptr<helios::rendering::RenderTarget> renderTarget,
73 const GLFWWindowConfig& cfg
74 ) :
75 Window(std::move(renderTarget), cfg),
76 frameBufferSizeCallback_(cfg.frameBufferSizeCallback) {
77 }

References frameBufferSizeCallback, helios::window::Window::renderTarget and helios::window::Window::Window.

Public Destructor

~GLFWWindow()

helios::ext::glfw::window::GLFWWindow::~GLFWWindow ()
inline

Destructor. Delegates to destroy().

Definition at line 60 of file GLFWWindow.ixx.

60 ~GLFWWindow() override {
61 destroy();
62 }

Reference destroy.

Public Operators

operator=()

GLFWWindow & helios::ext::glfw::window::GLFWWindow::operator= (const GLFWWindow &)
delete

Definition at line 55 of file GLFWWindow.ixx.

Reference GLFWWindow.

Public Member Functions

destroy()

void helios::ext::glfw::window::GLFWWindow::destroy ()
inline

Removed the underlying native handle of the GLFWwindow.

See Also

https://www.glfw.org/docs/latest/group__window.html#gacdf43e51376051d2c091662e9fe3d7b2

Definition at line 204 of file GLFWWindow.ixx.

204 void destroy() const {
205 if (nativeHandle_) {
206 glfwDestroyWindow(nativeHandle_);
207 }
208 }

Referenced by ~GLFWWindow.

frameBufferSizeCallback()

GLFWframebuffersizefun helios::ext::glfw::window::GLFWWindow::frameBufferSizeCallback ()
inline nodiscard noexcept

Returns the framebuffer resize callback function.

Returns

the `GLFWframebuffersizefun` currently registered with this Window.

Definition at line 167 of file GLFWWindow.ixx.

167 [[nodiscard]] GLFWframebuffersizefun frameBufferSizeCallback() const noexcept {
168 return frameBufferSizeCallback_;
169 }

Referenced by GLFWWindow.

nativeHandle()

GLFWwindow * helios::ext::glfw::window::GLFWWindow::nativeHandle ()
inline nodiscard noexcept

Returns the raw native GLFWwindow handle.

This method should only be used in GLFW-related API parts, where underlying glfw-functions require the native window handle.

Returns

The `GLFWwindow*` handle, or a `nullptr` if not available.

Definition at line 194 of file GLFWWindow.ixx.

194 [[nodiscard]] GLFWwindow* nativeHandle() const noexcept {
195 return nativeHandle_;
196 }

pollEvents()

void helios::ext::glfw::window::GLFWWindow::pollEvents ()
inline noexcept virtual

Processes all events in the underlying Window's EventQueue.

This method should be called regularly in the main loop.

See Also

https://www.glfw.org/docs/latest/group__window.html#ga37bd57223967b4211d60ca1a0bf3c832

Definition at line 131 of file GLFWWindow.ixx.

131 void pollEvents() const noexcept override {
132 glfwPollEvents();
133 }

setFrameBufferSizeCallback()

void helios::ext::glfw::window::GLFWWindow::setFrameBufferSizeCallback (GLFWframebuffersizefun framebufferSizeCallback)
inline noexcept

Sets the callback function for framebuffer resize events.

Implementing APIs should consider this method as "package protected": It's purpose is to register a function that delegates the native event into the Application's EventQueue.

Parameters
framebufferSizeCallback

The `GLFWframebuffersizefun` to set.

Definition at line 181 of file GLFWWindow.ixx.

181 void setFrameBufferSizeCallback(GLFWframebuffersizefun framebufferSizeCallback) noexcept {
182 frameBufferSizeCallback_ = framebufferSizeCallback;
183 }

setShouldClose()

void helios::ext::glfw::window::GLFWWindow::setShouldClose (bool close)
inline virtual

Sets the close flag of this window.

Parameters
close

True to indicate this window should be closed, false otherwise.

See Also

shouldClose()

See Also

https://www.glfw.org/docs/latest/group__window.html#ga49c449dde2a6f87d996f4daaa09d6708

Definition at line 141 of file GLFWWindow.ixx.

141 void setShouldClose(bool close) override {
142 glfwSetWindowShouldClose(nativeHandle_, close);
143 }

setWindowUserPointer()

void helios::ext::glfw::window::GLFWWindow::setWindowUserPointer (std::unique_ptr< GLFWWindowUserPointer > windowUserPointer)
inline noexcept

Sets the user-defined pointer for his GLFWWindow.

This transfers ownership of the `GLFWWindowUserPointer`-object to this Window and additionally associates its raw pointer with this Window's native handle.

Parameters
windowUserPointer

A unique_ptr to the `GLFWWindowUserPointer` object. Ownership is transferred to this Window-instance.

Returns

Definition at line 222 of file GLFWWindow.ixx.

222 void setWindowUserPointer(std::unique_ptr<GLFWWindowUserPointer> windowUserPointer) noexcept {
223 windowUserPointer_ = std::move(windowUserPointer);
224 glfwSetWindowUserPointer(nativeHandle_, windowUserPointer_.get());
225 }

Reference windowUserPointer.

Referenced by helios::ext::glfw::app::GLFWFactory::makeOpenGLApp.

shouldClose()

bool helios::ext::glfw::window::GLFWWindow::shouldClose ()
inline nodiscard virtual

Checks if the window has received a close request.

Implementing APIs should consider this flag at regular intervals (e.g. each frame) to determine whether this window should be closed.

Returns

true if the window should be closed, otherwise false.

See Also

setShouldClose()

See Also

https://www.glfw.org/docs/latest/group__window.html#ga24e02fbfefbb81fc45320989f8140ab5

Definition at line 151 of file GLFWWindow.ixx.

151 [[nodiscard]] bool shouldClose() const override {
152 if (nativeHandle_ == nullptr) {
153 return true;
154 }
155 return glfwWindowShouldClose(nativeHandle_);
156 }

show()

bool helios::ext::glfw::window::GLFWWindow::show ()
inline noexcept virtual

Creates and displays the underlying native `GlFWwindow`.

This method initializes the native window. It does not set the current context, which is actually done by GLFWApplication::setCurrent().

See Also

https://www.glfw.org/docs/latest/group__window.html#ga3555a418df92ad53f917597fe2f64aeb

Definition at line 91 of file GLFWWindow.ixx.

91 bool show() noexcept override {
92 if (nativeHandle_ != nullptr) {
93 logger_.warn("Window already shown.");
94 return true;
95 }
96
97 logger_.info("Calling glfwCreateWindow().");
98 nativeHandle_ = glfwCreateWindow(
99 width_, height_, title_.c_str(), nullptr, nullptr);
100
101 if (aspectRatioDenom_ > 0 && aspectRatioNumer_ > 0) {
102 glfwSetWindowAspectRatio(nativeHandle_, aspectRatioNumer_, aspectRatioDenom_);
103 }
104
105 if (nativeHandle_ == nullptr) {
106 logger_.error("Failed to create GLFW window");
107 return false;
108 }
109
110 return true;
111 }

References helios::window::Window::aspectRatioDenom_, helios::window::Window::aspectRatioNumer_, helios::window::Window::height_, helios::window::Window::logger_, helios::window::Window::title_ and helios::window::Window::width_.

swapBuffers()

void helios::ext::glfw::window::GLFWWindow::swapBuffers ()
inline noexcept virtual

Swaps the front and back buffers of the window.

See Also

https://www.glfw.org/docs/latest/group__window.html#ga15a5a1ee5b3c2ca6b15ca209a12efd14

Definition at line 119 of file GLFWWindow.ixx.

119 void swapBuffers() const noexcept override {
120 glfwSwapBuffers(nativeHandle_);
121 }

windowUserPointer()

const GLFWWindowUserPointer & helios::ext::glfw::window::GLFWWindow::windowUserPointer ()
inline nodiscard noexcept

Returns a const reference to the `GLFWWindowUserPointer` managed by this class.

Returns

A const reference to this object's `GLFWWindowUserPointer`.

Definition at line 233 of file GLFWWindow.ixx.

233 [[nodiscard]] const GLFWWindowUserPointer& windowUserPointer() const noexcept {
234 return *windowUserPointer_;
235 }

Referenced by setWindowUserPointer.

Private Member Attributes

frameBufferSizeCallback_

GLFWframebuffersizefun helios::ext::glfw::window::GLFWWindow::frameBufferSizeCallback_

C-style callback function for framebuffer resize events. This function pointer is passed to `glfwSetFramebufferSizeCallback`.

Definition at line 42 of file GLFWWindow.ixx.

42 GLFWframebuffersizefun frameBufferSizeCallback_;

nativeHandle_

GLFWwindow* helios::ext::glfw::window::GLFWWindow::nativeHandle_ = nullptr

The native GLFWwindow handle.

Definition at line 35 of file GLFWWindow.ixx.

35 GLFWwindow* nativeHandle_ = nullptr;

windowUserPointer_

std::unique_ptr<GLFWWindowUserPointer> helios::ext::glfw::window::GLFWWindow::windowUserPointer_

A unique_ptr to the to an object holding user defined data for the native GLFWwindow. This information gets forwarded using `glfwSetWindowUserPointer`.

Definition at line 48 of file GLFWWindow.ixx.

48 std::unique_ptr<GLFWWindowUserPointer> windowUserPointer_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.