VolViz
A volume visualization tool
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
GLFW.h
Go to the documentation of this file.
1 #ifndef VolViz_GLFW_h
2 #define VolViz_GLFW_h
3 
4 // clang-format off
5 #ifndef XCODE_BUILD
6 # include "config.h"
7 #endif
8 // clang-format on
9 
10 #include "GLdefs.h"
11 
12 #include <GLFW/glfw3.h>
13 
14 #include <functional>
15 #include <string>
16 #include <vector>
17 
18 namespace VolViz {
19 namespace Private_ {
20 namespace GL {
21 
22 #pragma clang diagnostic push
23 #pragma clang diagnostic ignored "-Wpadded"
24 class GLFW {
26 public:
28  inline GLFW()
29  : GLFW("Volume Visualizer", VOLVIZ_DEFAULT_WINDOW_WIDTH,
30  VOLVIZ_DEFAULT_WINDOW_HEIGHT) {}
31 
32  GLFW(std::string title, std::size_t width, std::size_t height);
33  GLFW(GLFW const &) = delete;
34  GLFW(GLFW &&rhs);
35 
36  ~GLFW();
37 
39  void hide() noexcept;
41  void show() noexcept;
42 
44  bool isHidden() const noexcept;
45 
47  void makeCurrent() noexcept;
48 
50  void detachContext() noexcept;
51 
52  inline operator bool() const noexcept {
53  return !glfwWindowShouldClose(window);
54  }
55 
56  inline void swapBuffers() const noexcept { glfwSwapBuffers(window); }
57 
58  inline void waitEvents() const noexcept { glfwWaitEvents(); }
59 
60  inline void pollEvents() const noexcept { glfwPollEvents(); }
61 
62  bool supportsExtension(std::string name) const noexcept;
63 
64  inline decltype(auto) supportedExtensions() const noexcept {
65  return supportedExtensions_;
66  }
67 
69  std::size_t width() const noexcept;
71  std::size_t height() const noexcept;
72 
74  std::function<void(int, int, int, int)> keyInputHandler;
76  std::function<void(std::size_t, std::size_t)> windowResizeCallback;
78  std::function<void(double, double)> scrollWheelInputHandler;
80  std::function<void(int, int, int)> mouseButtonCallback;
82  std::function<void(double, double)> mouseMoveCallback;
83 
84 private:
85  GLFWwindow *window = nullptr;
86  std::vector<std::string> supportedExtensions_;
87 };
88 #pragma clang diagnostic pop
89 
90 } // namespace GL
91 } // namespace Private_
92 } // namespace VolViz
93 
94 #endif // VolViz_GLFW_h
void hide() noexcept
Hides the current window.
Definition: GLFW.cpp:111
GLsizei const GLchar *const * string
Definition: glad.h:2514
std::function< void(double, double)> mouseMoveCallback
mouse move callback
Definition: GLFW.h:82
void detachContext() noexcept
Detaches the context from the current thread.
Definition: GLFW.cpp:121
GLuint const GLchar * name
Definition: glad.h:2430
void show() noexcept
Unhides the current window.
Definition: GLFW.cpp:113
GLint GLsizei width
Definition: glad.h:2100
GLint GLsizei GLsizei height
Definition: glad.h:2100
std::size_t width() const noexcept
Returns the width of the window.
Definition: GLFW.cpp:123
void pollEvents() const noexcept
Definition: GLFW.h:60
void swapBuffers() const noexcept
Definition: GLFW.h:56
void waitEvents() const noexcept
Definition: GLFW.h:58
std::vector< std::string > supportedExtensions_
Definition: GLFW.h:86
std::function< void(int, int, int, int)> keyInputHandler
keyboard input handler
Definition: GLFW.h:74
bool isHidden() const noexcept
Returns true if the window is hidden.
Definition: GLFW.cpp:115
bool supportsExtension(std::string name) const noexcept
Definition: GLFW.cpp:137
GLFWwindow * window
Definition: GLFW.h:85
std::function< void(int, int, int)> mouseButtonCallback
mouse button callback
Definition: GLFW.h:80
GLFW()
Crates a GLFW context associated with a hidden window.
Definition: GLFW.h:28
void makeCurrent() noexcept
Makes the window's conext current.
Definition: GLFW.cpp:119
RAII wrapper for GLFW.
Definition: GLFW.h:25
std::function< void(double, double)> scrollWheelInputHandler
scroll wheel input handler
Definition: GLFW.h:78
~GLFW()
Definition: GLFW.cpp:106
std::function< void(std::size_t, std::size_t)> windowResizeCallback
window resize callback
Definition: GLFW.h:76
decltype(auto) supportedExtensions() const noexcept
Definition: GLFW.h:64