OGLplus (0.52.0) a C++ wrapper for OpenGL

sync.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_SYNC_1107121519_HPP
14 #define OGLPLUS_SYNC_1107121519_HPP
15 
16 #include <oglplus/glfunc.hpp>
17 #include <oglplus/error/basic.hpp>
18 #include <oglplus/enumerations.hpp>
19 
20 namespace oglplus {
21 
22 // NOTE: Xlib.h defines this symbol
23 // using the preprocessor. To avoid any sort of
24 // problems here it is necessary to observe correct order
25 // of header includes or you gotta keep 'em separated
26 // (in different translation units)
27 #ifdef Status
28 #undef Status
29 #endif
30 
32 
37 OGLPLUS_ENUM_CLASS_BEGIN(SyncCondition, GLenum)
38 #include <oglplus/enums/sync_condition.ipp>
39 OGLPLUS_ENUM_CLASS_END(SyncCondition)
40 
41 #if !OGLPLUS_NO_ENUM_VALUE_NAMES
42 #include <oglplus/enums/sync_condition_names.ipp>
43 #endif
44 
45 #if !OGLPLUS_ENUM_VALUE_RANGES
46 #include <oglplus/enums/sync_condition_range.ipp>
47 #endif
48 
49 
51 
56 OGLPLUS_ENUM_CLASS_BEGIN(SyncType, GLenum)
57 #include <oglplus/enums/sync_type.ipp>
58 OGLPLUS_ENUM_CLASS_END(SyncType)
59 
60 #if !OGLPLUS_NO_ENUM_VALUE_NAMES
61 #include <oglplus/enums/sync_type_names.ipp>
62 #endif
63 
64 #if !OGLPLUS_ENUM_VALUE_RANGES
65 #include <oglplus/enums/sync_type_range.ipp>
66 #endif
67 
68 
70 
75 OGLPLUS_ENUM_CLASS_BEGIN(SyncStatus, GLenum)
76 #include <oglplus/enums/sync_status.ipp>
77 OGLPLUS_ENUM_CLASS_END(SyncStatus)
78 
79 #if !OGLPLUS_NO_ENUM_VALUE_NAMES
80 #include <oglplus/enums/sync_status_names.ipp>
81 #endif
82 
83 #if !OGLPLUS_ENUM_VALUE_RANGES
84 #include <oglplus/enums/sync_status_range.ipp>
85 #endif
86 
88 
93 OGLPLUS_ENUM_CLASS_BEGIN(SyncWaitResult, GLenum)
94 #include <oglplus/enums/sync_wait_result.ipp>
95 OGLPLUS_ENUM_CLASS_END(SyncWaitResult)
96 
97 #if !OGLPLUS_NO_ENUM_VALUE_NAMES
98 #include <oglplus/enums/sync_wait_result_names.ipp>
99 #endif
100 
101 #if !OGLPLUS_ENUM_VALUE_RANGES
102 #include <oglplus/enums/sync_wait_result_range.ipp>
103 #endif
104 
105 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_3_2 || GL_ARB_sync
106 
108 
112 class Sync
113 {
114 private:
115  GLsync _sync;
116 public:
118  struct Property
119  {
122 
124  typedef SyncType Type;
125 
128 
131  };
132 
134 
142  : _sync(OGLPLUS_GLFUNC(FenceSync)(GLenum(condition), 0))
143  {
144  OGLPLUS_CHECK_SIMPLE(FenceSync);
145  }
146 
147 #if !OGLPLUS_NO_DELETED_FUNCTIONS
148  Sync(const Sync&) = delete;
149 #else
150 private:
151  Sync(const Sync&);
152 public:
153 #endif
154 
156  Sync(Sync&& temp)
157  : _sync(temp._sync)
158  {
159  temp._sync = 0;
160  }
161 
162  ~Sync(void)
163  {
164  if(_sync != 0) OGLPLUS_GLFUNC(DeleteSync)(_sync);
165  }
166 
168 
174  bool Signaled(void) const
175  {
176  GLint result = 0;
177  OGLPLUS_GLFUNC(GetSynciv)(
178  _sync,
179  GL_SYNC_STATUS,
180  1,
181  nullptr,
182  &result
183  );
184  return result == GL_SIGNALED;
185  }
186 
188 
193  SyncType Type(void) const
194  {
195  GLint result = 0;
196  OGLPLUS_GLFUNC(GetSynciv)(
197  _sync,
198  GL_OBJECT_TYPE,
199  1,
200  nullptr,
201  &result
202  );
203  return SyncType(result);
204  }
205 
207 
213  {
214  GLint result = 0;
215  OGLPLUS_GLFUNC(GetSynciv)(
216  _sync,
217  GL_SYNC_CONDITION,
218  1,
219  nullptr,
220  &result
221  );
222  return SyncCondition(result);
223  }
224 
226 
231  SyncStatus Status(void) const
232  {
233  GLint result = 0;
234  OGLPLUS_GLFUNC(GetSynciv)(
235  _sync,
236  GL_SYNC_STATUS,
237  1,
238  nullptr,
239  &result
240  );
241  return SyncStatus(result);
242  }
243 
245 
249  SyncWaitResult ClientWait(GLuint64 timeout) const
250  {
251  GLenum result = OGLPLUS_GLFUNC(ClientWaitSync)(
252  _sync,
253  0,
254  timeout
255  );
256  OGLPLUS_VERIFY_SIMPLE(ClientWaitSync);
257  return SyncWaitResult(result);
258  }
259 
261 
265  void Wait(GLuint64 timeout = GL_TIMEOUT_IGNORED) const
266  {
267  OGLPLUS_GLFUNC(WaitSync)(_sync, 0, timeout);
268  OGLPLUS_VERIFY_SIMPLE(WaitSync);
269  }
270 };
271 
272 #endif // sync
273 
274 } // namespace oglplus
275 
276 #endif // include guard
bool Signaled(void) const
Returns true if this Sync object is in signaled status.
Definition: sync.hpp:174
Encapsulates sync object and fence functionality.
Definition: sync.hpp:112
SyncType Type
Synchronization object type.
Definition: sync.hpp:124
SyncType Type(void) const
Returns the type of this Sync object.
Definition: sync.hpp:193
SyncWaitResult
The wait result enumeration.
Definition: sync.hpp:93
SyncStatus Status(void) const
Returns the status of this Sync object.
Definition: sync.hpp:231
SyncWaitResult WaitResult
Synchronization wait result.
Definition: sync.hpp:130
Enumeration-related declarations.
SyncStatus
The synchronization object status enumeration.
Definition: sync.hpp:75
SyncWaitResult ClientWait(GLuint64 timeout) const
Wait for the condition to be satisfied.
Definition: sync.hpp:249
SyncCondition Condition
The synchronization condition.
Definition: sync.hpp:121
SyncCondition
The synchronization condition enumeration.
Definition: sync.hpp:37
Types related to Sync.
Definition: sync.hpp:118
SyncType
The synchronization object type enumeration.
Definition: sync.hpp:56
Sync(SyncCondition condition=SyncCondition::GPUCommandsComplete)
Creates a new sync object for the specified condition.
Definition: sync.hpp:141
Helper macro for optional checking of availability of GL function.
SyncCondition Condition(void) const
Returns the condition of this Sync object.
Definition: sync.hpp:212
Declaration of basic OGLplus' exceptions.
SyncStatus Status
Synchronization object status.
Definition: sync.hpp:127
Sync(Sync &&temp)
Sync objects are moveable.
Definition: sync.hpp:156
void Wait(GLuint64 timeout=GL_TIMEOUT_IGNORED) const
Wait for the condition to be satisfied.
Definition: sync.hpp:265

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).