GLX/GteWindowSystem.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.1 (2016/07/01)
7 
8 #pragma once
9 
11 #include <memory>
12 
13 // Forward declarations to avoid name conflicts caused by #include-ing X11/Xlib.h.
14 struct _XDisplay;
15 struct __GLXcontextRec;
16 
17 namespace gte
18 {
19 
21 {
22 public:
23  // Construction and destruction. This is a singleton class.
24  ~WindowSystem ();
25  WindowSystem ();
26 
27  // Create and destroy windows. Derived classes may extend the inputs
28  // using a nested class derived from Window::Parameters
29  template <typename WindowType>
30  std::shared_ptr<WindowType> Create(typename WindowType::Parameters& parameters);
31 
32  // Creation of information used for a compute-shader-only GLXEngine.
33  bool Create(_XDisplay*& display, __GLXcontextRec*& context, unsigned long& window);
34 
35  template <typename WindowType>
36  void Destroy(std::shared_ptr<WindowType>& window);
37 
38  enum
39  {
40  DEFAULT_ACTION = 0,
41  NO_IDLE_LOOP = 1
42  };
43 
44  template <typename WindowType>
45  void MessagePump(std::shared_ptr<WindowType> const& window, unsigned int flags);
46 
47 private:
48  // Window creation and destruction.
49  void CreateFrom(Window::Parameters& parameters);
50 
51  char const* mDisplayName;
52  _XDisplay* mDisplay;
53  std::map<unsigned long, std::shared_ptr<Window>> mWindowMap;
54 };
55 
57 
58 template <typename WindowType>
59 std::shared_ptr<WindowType> WindowSystem::Create(typename WindowType::Parameters& parameters)
60 {
61  CreateFrom(parameters);
62  if (parameters.created)
63  {
64  std::shared_ptr<WindowType> window = std::make_shared<WindowType>(parameters);
65  mWindowMap[parameters.window] = window;
66  if (parameters.created)
67  {
68  return window;
69  }
70  Destroy(window);
71  }
72  // else: CreateFrom will report the problem via the logger system.
73  return nullptr;
74 }
75 
76 template <typename WindowType>
77 void WindowSystem::Destroy(std::shared_ptr<WindowType>& window)
78 {
79  if (window)
80  {
81  mWindowMap.erase(window->mWindow);
82  window->OnClose();
83  window = nullptr;
84  }
85 }
86 
87 template <typename WindowType>
88 void WindowSystem::MessagePump(std::shared_ptr<WindowType> const& window, unsigned int flags)
89 {
90  if (window)
91  {
92  window->ShowWindow();
93 
94  for (;;)
95  {
96  int result = window->ProcessedEvent();
97  if (result == Window::EVT_QUIT)
98  {
99  return;
100  }
101 
102  if (result == Window::EVT_NONE_PENDING)
103  {
104  if (!(flags & NO_IDLE_LOOP))
105  {
106  if (!window->IsMinimized())
107  {
108  window->OnIdle();
109  }
110  }
111  }
112  }
113  }
114 }
115 
116 }
void MessagePump(std::shared_ptr< WindowType > const &window, unsigned int flags)
std::shared_ptr< WindowType > Create(typename WindowType::Parameters &parameters)
GLbitfield flags
Definition: glcorearb.h:1591
std::map< unsigned long, std::shared_ptr< Window > > mWindowMap
void Destroy(std::shared_ptr< WindowType > &window)
char const * mDisplayName
GLuint64EXT * result
Definition: glext.h:10003
GTE_IMPEXP WindowSystem TheWindowSystem
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:02