gramods
SdlWindow.hh
1 
2 #ifndef GRAMODS_GRAPHICS_SDLWINDOW
3 #define GRAMODS_GRAPHICS_SDLWINDOW
4 
5 #include <gmCore/SdlContext.hh>
6 
7 #ifdef gramods_ENABLE_SDL2
8 
9 #include <gmGraphics/Window.hh>
10 
11 BEGIN_NAMESPACE_GMGRAPHICS;
12 
16 class SdlWindow
17  : public Window {
18 
19 public:
20 
21  SdlWindow();
22  ~SdlWindow();
23 
24  void initialize() override;
25 
30  void makeGLContextCurrent() override;
31 
36  gmCore::size2 getSize();
37 
41  void close() override;
42 
48  void setUseQuadBuffers(bool on) { gl_use_quad_buffers = on; }
49 
56  void setGLMajor(int v) { gl_major = v; }
57 
64  void setGLMinor(int v) { gl_minor = v; }
65 
72  void setGLProfile(std::string s) { gl_profile = s; }
73 
82  void setContext(std::shared_ptr<gmCore::SdlContext> ctx) { context = ctx; }
83 
88  void processEvents() override;
89 
94  bool isOpen() override;
95 
100  void swap() override;
101 
107  void traverse(Visitor *visitor) override;
108 
109  GM_OFI_DECLARE;
110 
111 private:
112 
113  bool processEvent(SDL_Event& event);
114 
115  bool alive;
116  SDL_Window* window;
117  SDL_GLContext gl_context;
118  static std::map<unsigned int, std::weak_ptr<SdlWindow>> sdl_windows;
119 
120  bool gl_use_quad_buffers = false;
121  int gl_major = -1;
122  int gl_minor = -1;
123  std::string gl_profile;
124 
125  std::shared_ptr<gmCore::SdlContext> context;
126 };
127 
128 END_NAMESPACE_GMGRAPHICS;
129 
130 #endif
131 #endif
An SDL window implementation.
Definition: SdlWindow.hh:17
void setUseQuadBuffers(bool on)
Sets if quad buffers should be requested for the GL context.
Definition: SdlWindow.hh:48
void setContext(std::shared_ptr< gmCore::SdlContext > ctx)
The SDL context.
Definition: SdlWindow.hh:82
void setGLMajor(int v)
Sets the major version to be requested for the GL context in this Window.
Definition: SdlWindow.hh:56
void setGLMinor(int v)
Sets the minor version to be requested for the GL context in this Window.
Definition: SdlWindow.hh:64
void setGLProfile(std::string s)
Sets the profile to be requested for the GL context in this Window.
Definition: SdlWindow.hh:72
The base of graphics Window implementations.
Definition: Window.hh:21
std::array< size_t, 2 > size2
Array of 2 size_t.
Definition: io_size.hh:9