OGLplus (0.52.0) a C++ wrapper for OpenGL

debug_output.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_OPT_DEBUG_OUTPUT_1209031534_HPP
14 #define OGLPLUS_OPT_DEBUG_OUTPUT_1209031534_HPP
15 
16 #include <oglplus/glfunc.hpp>
17 #include <oglplus/string/ref.hpp>
19 #include <oglplus/enumerations.hpp>
20 
21 #include <cassert>
22 #include <stack>
23 #include <functional>
24 #include <memory>
25 
26 namespace oglplus {
27 
29 
32 OGLPLUS_ENUM_CLASS_BEGIN(DebugOutputSeverity, GLenum)
33 #include <oglplus/enums/debug_output_severity.ipp>
34 OGLPLUS_ENUM_CLASS_END(DebugOutputSeverity)
35 
36 #if !OGLPLUS_NO_ENUM_VALUE_NAMES
37 #include <oglplus/enums/debug_output_severity_names.ipp>
38 #endif
39 
40 #if !OGLPLUS_ENUM_VALUE_RANGES
41 #include <oglplus/enums/debug_output_severity_range.ipp>
42 #endif
43 
44 
46 
49 OGLPLUS_ENUM_CLASS_BEGIN(DebugOutputSource, GLenum)
50 #include <oglplus/enums/debug_output_source.ipp>
51 OGLPLUS_ENUM_CLASS_END(DebugOutputSource)
52 
53 #if !OGLPLUS_NO_ENUM_VALUE_NAMES
54 #include <oglplus/enums/debug_output_source_names.ipp>
55 #endif
56 
57 #if !OGLPLUS_ENUM_VALUE_RANGES
58 #include <oglplus/enums/debug_output_source_range.ipp>
59 #endif
60 
62 
65 OGLPLUS_ENUM_CLASS_BEGIN(DebugOutputType, GLenum)
66 #include <oglplus/enums/debug_output_type.ipp>
67 OGLPLUS_ENUM_CLASS_END(DebugOutputType)
68 
69 #if !OGLPLUS_NO_ENUM_VALUE_NAMES
70 #include <oglplus/enums/debug_output_type_names.ipp>
71 #endif
72 
73 #if !OGLPLUS_ENUM_VALUE_RANGES
74 #include <oglplus/enums/debug_output_type_range.ipp>
75 #endif
76 
77 
78 #if OGLPLUS_DOCUMENTATION_ONLY || GL_VERSION_4_3
79 
81 
83 class Debug
84 {
85 public:
88 
91 
94 
95 
97 
101  static void MessageControl(
102  DebugOutputSource source,
103  DebugOutputType type,
104  DebugOutputSeverity severity,
105  bool enable
106  )
107  {
108  OGLPLUS_GLFUNC(DebugMessageControl)(
109  GLenum(source),
110  GLenum(type),
111  GLenum(severity),
112  0, nullptr,
113  enable ? GL_TRUE : GL_FALSE
114  );
115  OGLPLUS_VERIFY_SIMPLE(DebugMessageControl);
116  }
117 
120  {
121  DebugOutputSource source;
122  DebugOutputType type;
123  GLuint id;
124  DebugOutputSeverity severity;
125  GLsizei length;
126  const GLchar* message;
127  };
128 
130  typedef std::function<void (const CallbackData&)> Callback;
131 
133 
144  class LogSink
145  {
146  private:
147  static void GLAPIENTRY _gl_debug_proc(
148  GLenum source,
149  GLenum type,
150  GLuint id,
151  GLenum severity,
152  GLsizei length,
153  const GLchar* message,
154  const GLvoid* user_param
155  )
156  {
157  LogSink* self = (LogSink*)(user_param);
158  assert(self);
159  if(self->_callback)
160  {
161  CallbackData data;
162  data.source = DebugOutputSource(source);
163  data.type = DebugOutputType(type);
164  data.id = id;
165  data.severity = DebugOutputSeverity(severity);
166  data.length = length;
167  data.message = message;
168  self->_callback(data);
169  }
170  }
171 
172  Callback _callback;
173  GLDEBUGPROC _prev_callback;
174  void* _prev_context;
175  public:
177 
181  LogSink(Callback callback)
182  : _callback(callback)
183  , _prev_callback(nullptr)
184  , _prev_context(nullptr)
185  {
186  // get the previous callback
187  GLDEBUGPROC _tmp_callback = nullptr;
188  void** _tmp_ptr =
189  reinterpret_cast<void**>(&_tmp_callback);
190  OGLPLUS_GLFUNC(GetPointerv)(
191  GL_DEBUG_CALLBACK_FUNCTION,
192  _tmp_ptr
193  );
194  OGLPLUS_VERIFY_SIMPLE(GetPointerv);
195  _prev_callback = _tmp_callback;
196 
197  //get the previous context
198  OGLPLUS_GLFUNC(GetPointerv)(
199  GL_DEBUG_CALLBACK_USER_PARAM,
200  &_prev_context
201  );
202  OGLPLUS_VERIFY_SIMPLE(GetPointerv);
203 
204  OGLPLUS_GLFUNC(DebugMessageCallback)(
205  &LogSink::_gl_debug_proc,
206  static_cast<void*>(this)
207  );
208  OGLPLUS_VERIFY_SIMPLE(DebugMessageCallback);
209  }
210 
211 #if !OGLPLUS_NO_DELETED_FUNCTIONS
212  LogSink(const LogSink&) = delete;
214 #else
215  private:
216  LogSink(const LogSink&);
217  public:
218 #endif
219 
221 
225  ~LogSink(void)
226  {
227  OGLPLUS_GLFUNC(DebugMessageCallback)(
228  _prev_callback,
229  _prev_context
230  );
231  OGLPLUS_VERIFY_SIMPLE(DebugMessageCallback);
232  }
233  };
234 
236  class Group
237  {
238  public:
240 
245  DebugOutputSource source,
246  GLuint id,
247  const GLchar* message,
248  GLint length = -1
249  )
250  {
251  OGLPLUS_GLFUNC(PushDebugGroup)(
252  GLenum(source),
253  id,
254  length,
255  message
256  );
257  OGLPLUS_VERIFY_SIMPLE(PushDebugGroup);
258  }
259 
261 
268  DebugOutputSource source,
269  GLuint id,
270  StrCRef message
271  )
272  {
273  OGLPLUS_GLFUNC(PushDebugGroup)(
274  GLenum(source),
275  id,
276  message.size(),
277  message.begin()
278  );
279  OGLPLUS_VERIFY_SIMPLE(PushDebugGroup);
280  }
281 
283 
290  DebugOutputSource source,
291  GLuint id,
292  const String& message
293  )
294  {
295  OGLPLUS_GLFUNC(PushDebugGroup)(
296  GLenum(source),
297  id,
298  message.size(),
299  message.c_str()
300  );
301  OGLPLUS_VERIFY_SIMPLE(PushDebugGroup);
302  }
303 
304 #if !OGLPLUS_NO_DELETED_FUNCTIONS
305  Group(const Group&) = delete;
307 #else
308  private:
309  Group(const Group&);
310  public:
311 #endif
312 
317  ~Group(void)
318  {
319  OGLPLUS_GLFUNC(PopDebugGroup)();
320  OGLPLUS_VERIFY_SIMPLE(PopDebugGroup);
321  }
322  };
323 
325 
329  template <typename ObjTag>
330  static void ObjectLabel(
331  const ObjectName<ObjTag>& object,
332  StrCRef label
333  )
334  {
335  OGLPLUS_GLFUNC(ObjectLabel)(
336  GetGLName(object),
338  label.size(),
339  label.c_str()
340  );
341  OGLPLUS_VERIFY_SIMPLE(ObjectLabel);
342  }
343 
345 
351  static void Synchronous(bool enable)
352  {
353  if(enable)
354  {
355  OGLPLUS_GLFUNC(Enable)(
356  GL_DEBUG_OUTPUT_SYNCHRONOUS
357  );
358  OGLPLUS_VERIFY_SIMPLE(Enable);
359  }
360  else
361  {
362  OGLPLUS_GLFUNC(Disable)(
363  GL_DEBUG_OUTPUT_SYNCHRONOUS
364  );
365  OGLPLUS_VERIFY_SIMPLE(Disable);
366  }
367  }
368 
370 
374  static void InsertMessage(
375  DebugOutputSource source,
376  DebugOutputType type,
377  GLuint id,
378  DebugOutputSeverity severity,
379  const GLchar* buffer,
380  GLint length = -1
381  )
382  {
383  OGLPLUS_GLFUNC(DebugMessageInsert)(
384  GLenum(source),
385  GLenum(type),
386  id,
387  GLenum(severity),
388  length,
389  buffer
390  );
391  OGLPLUS_VERIFY_SIMPLE(DebugMessageInsert);
392  }
393 
395 
401  static void InsertMessage(
402  DebugOutputSource source,
403  DebugOutputType type,
404  GLuint id,
405  DebugOutputSeverity severity,
406  StrCRef message
407  )
408  {
409  OGLPLUS_GLFUNC(DebugMessageInsert)(
410  GLenum(source),
411  GLenum(type),
412  id,
413  GLenum(severity),
414  message.size(),
415  message.c_str()
416  );
417  OGLPLUS_VERIFY_SIMPLE(DebugMessageInsert);
418  }
419 
421 
427  static void InsertMessage(
428  DebugOutputSource source,
429  DebugOutputType type,
430  GLuint id,
431  DebugOutputSeverity severity,
432  const String& message
433  )
434  {
435  OGLPLUS_GLFUNC(DebugMessageInsert)(
436  GLenum(source),
437  GLenum(type),
438  id,
439  GLenum(severity),
440  message.size(),
441  message.c_str()
442  );
443  OGLPLUS_VERIFY_SIMPLE(DebugMessageInsert);
444  }
445 };
446 #endif
447 
448 } // namespace oglplus
449 
450 #endif // include guard
const Char * c_str(void) const
Returns the null-terminated c-string.
Definition: ref_tpl.hpp:200
Group(DebugOutputSource source, GLuint id, const String &message)
Pushes a debug group with the specified parameters.
Definition: debug_output.hpp:289
Pushes a group when constructed, pops in when destroyed.
Definition: debug_output.hpp:236
const_iterator begin(void) const
Returns iterator to the first character.
Definition: ref_tpl.hpp:170
Installs a custom callback processing the debug output.
Definition: debug_output.hpp:144
static void InsertMessage(DebugOutputSource source, DebugOutputType type, GLuint id, DebugOutputSeverity severity, const String &message)
Inserts a new message into the debug output.
Definition: debug_output.hpp:427
Group(DebugOutputSource source, GLuint id, StrCRef message)
Pushes a debug group with the specified parameters.
Definition: debug_output.hpp:267
Generic OpenGL object wrapper.
static void MessageControl(DebugOutputSource source, DebugOutputType type, DebugOutputSeverity severity, bool enable)
Enables/disables messages with specific parameters.
Definition: debug_output.hpp:101
Enumeration-related declarations.
static void Synchronous(bool enable)
Enables or disables synchronous debug output.
Definition: debug_output.hpp:351
std::function< void(const CallbackData &)> Callback
Type of a callback functor processing debug output.
Definition: debug_output.hpp:130
DebugOutputSeverity Severity
Debug output severity.
Definition: debug_output.hpp:87
DebugOutputSource
Debug output source enumeration.
Definition: debug_output.hpp:49
GLuint GetGLName(ObjectName< ObjTag > named)
Returns the GLuint OpenGL name assigned to named object.
Definition: name.hpp:38
String reference.
std::size_t size(void) const
Return the size (length) string.
Definition: ref_tpl.hpp:149
ObjectType
Enumeration of object types.
Definition: type.hpp:25
DebugOutputSource Source
Debug output source.
Definition: debug_output.hpp:90
static void ObjectLabel(const ObjectName< ObjTag > &object, StrCRef label)
Annotate object with the label with the specified length.
Definition: debug_output.hpp:330
static void InsertMessage(DebugOutputSource source, DebugOutputType type, GLuint id, DebugOutputSeverity severity, StrCRef message)
Inserts a new message into the debug output.
Definition: debug_output.hpp:401
String const reference wrapper template.
Definition: ref_tpl.hpp:72
Helper macro for optional checking of availability of GL function.
~LogSink(void)
Restores the previous callback and its context.
Definition: debug_output.hpp:225
DebugOutputSeverity
Debug output severity enumeration.
Definition: debug_output.hpp:32
Structure containing data passed to Callback functor.
Definition: debug_output.hpp:119
::std::basic_string< GLchar > String
String class.
Definition: def.hpp:36
LogSink(Callback callback)
Installs the callback and remembers the previous.
Definition: debug_output.hpp:181
DebugOutputType Type
Debug output type.
Definition: debug_output.hpp:93
DebugOutputType
Debug output type enumeration.
Definition: debug_output.hpp:65
static void InsertMessage(DebugOutputSource source, DebugOutputType type, GLuint id, DebugOutputSeverity severity, const GLchar *buffer, GLint length=-1)
Inserts a new message into the debug output.
Definition: debug_output.hpp:374
Wrapper for the GL debug output functionality.
Definition: debug_output.hpp:83
A common template for "named" objects like textures, buffers, etc.
Definition: fwd.hpp:136
Group(DebugOutputSource source, GLuint id, const GLchar *message, GLint length=-1)
Pushes a debug group with the specified parameters.
Definition: debug_output.hpp:244
~Group(void)
Pops a debug group with the specified parameters.
Definition: debug_output.hpp:317

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).