OGLplus (0.52.0) a C++ wrapper for OpenGL

ARB_debug_output.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_EXT_ARB_DEBUG_OUTPUT_1203031902_HPP
14 #define OGLPLUS_EXT_ARB_DEBUG_OUTPUT_1203031902_HPP
15 
16 #include <oglplus/extension.hpp>
17 #include <oglplus/config/compiler.hpp>
18 #include <oglplus/string/ref.hpp>
19 #include <oglplus/string/def.hpp>
20 #include <oglplus/glfunc.hpp>
24 
25 #include <cassert>
26 #include <stack>
27 #include <functional>
28 #include <memory>
29 #include <unordered_set>
30 #include <iostream>
31 
32 namespace oglplus {
33 
34 #if OGLPLUS_DOCUMENTATION_ONLY || GL_ARB_debug_output
35 
37 
44 {
45 public:
46  OGLPLUS_EXTENSION_CLASS(ARB, debug_output)
47 
48 
49  static void Control(
50  DebugOutputARBSource source,
51  DebugOutputARBType type,
52  DebugOutputARBSeverity severity,
53  bool enable
54  )
55  {
56  OGLPLUS_GLFUNC(DebugMessageControlARB)(
57  GLenum(source),
58  GLenum(type),
59  GLenum(severity),
60  0, nullptr,
61  enable ? GL_TRUE : GL_FALSE
62  );
63  OGLPLUS_VERIFY_SIMPLE(DebugMessageControlARB);
64  }
65 
67  struct CallbackData
68  {
71 
74 
76  GLuint id;
77 
80 
82  GLsizei length;
83 
85  const GLchar* message;
86  };
87 
89 
95  typedef std::function<void (const CallbackData&)> Callback;
96 
98 
103  class LogSink
104  {
105  private:
106  static void GLAPIENTRY _gl_debug_proc(
107  GLenum source,
108  GLenum type,
109  GLuint id,
110  GLenum severity,
111  GLsizei length,
112  const GLchar* message,
113  GLvoid* user_param
114  )
115  {
116  LogSink* self = static_cast<LogSink*>(user_param);
117  assert(self);
118  if(self->_callback)
119  {
120  CallbackData data;
121  data.source = DebugOutputARBSource(source);
122  data.type = DebugOutputARBType(type);
123  data.id = id;
124  data.severity = DebugOutputARBSeverity(severity);
125  data.length = length;
126  data.message = message;
127  self->_callback(data);
128  }
129  }
130 
131  Callback _callback;
132  GLDEBUGPROCARB _prev_callback;
133  void* _prev_context;
134  public:
136  LogSink(Callback callback)
137  : _callback(callback)
138  , _prev_callback(nullptr)
139  , _prev_context(nullptr)
140  {
141  // get the previous callback
142  GLDEBUGPROCARB _tmp_callback = nullptr;
143  void** _tmp_ptr=reinterpret_cast<void**>(&_tmp_callback);
144  OGLPLUS_GLFUNC(GetPointerv)(
145  GL_DEBUG_CALLBACK_FUNCTION_ARB,
146  _tmp_ptr
147  );
148  OGLPLUS_IGNORE(GetPointerv);
149  _prev_callback = _tmp_callback;
150 
151  //get the previous context
152  OGLPLUS_GLFUNC(GetPointerv)(
153  GL_DEBUG_CALLBACK_USER_PARAM_ARB,
154  &_prev_context
155  );
156  OGLPLUS_IGNORE(GetPointerv);
157 
158  OGLPLUS_GLFUNC(DebugMessageCallbackARB)(
159  GLDEBUGPROCARB(&LogSink::_gl_debug_proc),
160  static_cast<void*>(this)
161  );
162  OGLPLUS_VERIFY_SIMPLE(DebugMessageCallbackARB);
163  }
164 
165 #if !OGLPLUS_NO_DELETED_FUNCTIONS
166  LogSink(const LogSink&) = delete;
168 #else
169  private:
170  LogSink(const LogSink&);
171  public:
172 #endif
173 
175  ~LogSink(void)
176  {
177  if(_prev_callback)
178  {
179  OGLPLUS_GLFUNC(DebugMessageCallbackARB)(
180  _prev_callback,
181  _prev_context
182  );
183  }
184  }
185  };
186 
188  static void Synchronous(bool enable)
189  {
190  if(enable)
191  {
192  OGLPLUS_GLFUNC(Enable)(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
193  OGLPLUS_VERIFY_SIMPLE(Enable);
194  }
195  else
196  {
197  OGLPLUS_GLFUNC(Disable)(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
198  OGLPLUS_VERIFY_SIMPLE(Disable);
199  }
200  }
201 
203  static void InsertMessage(
204  DebugOutputARBSource source,
205  DebugOutputARBType type,
206  GLuint id,
207  DebugOutputARBSeverity severity,
208  const GLchar* buffer,
209  GLint length = -1
210  )
211  {
212  OGLPLUS_GLFUNC(DebugMessageInsertARB)(
213  GLenum(source),
214  GLenum(type),
215  id,
216  GLenum(severity),
217  length,
218  buffer
219  );
220  OGLPLUS_VERIFY_SIMPLE(DebugMessageInsertARB);
221  }
222 
224  static void InsertMessage(
225  DebugOutputARBSource source,
226  DebugOutputARBType type,
227  GLuint id,
228  DebugOutputARBSeverity severity,
229  StrCRef message
230  )
231  {
232  OGLPLUS_GLFUNC(DebugMessageInsertARB)(
233  GLenum(source),
234  GLenum(type),
235  id,
236  GLenum(severity),
237  message.size(),
238  message.c_str()
239  );
240  OGLPLUS_VERIFY_SIMPLE(DebugMessageInsertARB);
241  }
242 };
243 
244 template <typename Essence>
245 class ARB_debug_output_CallbackWithEssence
246 {
247 private:
248  std::shared_ptr<Essence> essence;
249 public:
250  typedef typename ARB_debug_output::Callback Callback;
251 
252  ARB_debug_output_CallbackWithEssence(
253  typename Essence::CtrParam param
254  ): essence(std::make_shared<Essence>(param))
255  { }
256 
257  void operator()(const ARB_debug_output::CallbackData& data)
258  {
259  essence->Call(data);
260  }
261 
262  operator Callback (void) const
263  {
264  return Callback(*this);
265  }
266 };
267 
268 class ARB_debug_output_UniqueEssence
269 {
270 private:
271  typedef ARB_debug_output::Callback Callback;
272  Callback _callback;
273 
274  String buffer;
275  std::unordered_set<String> already_done;
276 
277  ARB_debug_output_UniqueEssence(const ARB_debug_output_UniqueEssence&);
278 public:
279  typedef const Callback& CtrParam;
280 
281  ARB_debug_output_UniqueEssence(const Callback& callback)
282  : _callback(callback)
283  { }
284 
285  void Call(const ARB_debug_output::CallbackData& data);
286 };
287 
288 #if OGLPLUS_DOCUMENTATION_ONLY
289 
298 {
299 public:
302 
304  operator ARB_debug_output::Callback (void) const;
305 };
306 #else
307 typedef ARB_debug_output_CallbackWithEssence<ARB_debug_output_UniqueEssence>
309 #endif
310 
311 
312 class ARB_debug_output_TreeEssence
313 {
314 private:
315  std::ostream& dbgout;
316 
317  ARB_debug_output_TreeEssence(const ARB_debug_output_TreeEssence&);
318 public:
319  typedef std::ostream& CtrParam;
320 
321  ARB_debug_output_TreeEssence(std::ostream& out);
322  ~ARB_debug_output_TreeEssence(void);
323 
324  void Call(const ARB_debug_output::CallbackData& data);
325 };
326 
327 #if OGLPLUS_DOCUMENTATION_ONLY
328 
336 {
337 public:
339  ARB_debug_output_Tree(std::ostream&);
340 
342  operator ARB_debug_output::Callback (void) const;
343 };
344 #else
345 typedef ARB_debug_output_CallbackWithEssence<ARB_debug_output_TreeEssence>
347 #endif
348 
349 
350 class ARB_debug_output_ToXMLEssence
351 {
352 private:
353  std::ostream& dbgout;
354 
355  ARB_debug_output_ToXMLEssence(const ARB_debug_output_ToXMLEssence&);
356 public:
357  typedef std::ostream& CtrParam;
358 
359  ARB_debug_output_ToXMLEssence(std::ostream& out);
360  ~ARB_debug_output_ToXMLEssence(void);
361 
362  void Call(const ARB_debug_output::CallbackData& data);
363 };
364 
365 #if OGLPLUS_DOCUMENTATION_ONLY
366 
373 {
374 public:
376  ARB_debug_output_ToXML(std::ostream&);
377 
379  operator ARB_debug_output::Callback (void) const;
380 };
381 #else
382 typedef ARB_debug_output_CallbackWithEssence<ARB_debug_output_ToXMLEssence>
384 #endif
385 
386 #endif // ARB_debug_output
387 
388 } // namespace oglplus
389 
390 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
391 #include <oglplus/ext/ARB_debug_output.ipp>
392 #endif // OGLPLUS_LINK_LIBRARY
393 
394 #endif // include guard
DebugOutputARBType type
The type of the debug message.
Definition: ARB_debug_output.hpp:73
The DebugOutputARBType enumeration.
const Char * c_str(void) const
Returns the null-terminated c-string.
Definition: ref_tpl.hpp:200
ARB_debug_output_Unique(ARB_debug_output::Callback)
Construction takes another callback implementation.
LogSink(Callback callback)
Installs the callback and remembers the previous.
Definition: ARB_debug_output.hpp:136
static void InsertMessage(DebugOutputARBSource source, DebugOutputARBType type, GLuint id, DebugOutputARBSeverity severity, StrCRef message)
Inserts a new message into the debug output.
Definition: ARB_debug_output.hpp:224
Wrapper for the ARB_debug_output extension.
Definition: ARB_debug_output.hpp:43
Installs a custom callback processing the debug output.
Definition: ARB_debug_output.hpp:103
Funcions and classes for handling and wrapping OpenGL extensions.
DebugOutputARBSource source
The source of the debug message.
Definition: ARB_debug_output.hpp:70
DebugOutputARBSeverity severity
The severity of the debug message.
Definition: ARB_debug_output.hpp:79
The DebugOutputARBSeverity enumeration.
~LogSink(void)
Restores the previous callback and its context.
Definition: ARB_debug_output.hpp:175
String type definition and related functions.
DebugOutputARBSeverity
Debug output severity enumeration.
Definition: severity.hpp:27
DebugOutputARBType
Debug output type enumeration.
Definition: type.hpp:27
ARB_debug_output_ToXML(std::ostream &)
Constructor takes a reference to standard output stream.
::std::basic_string< ALchar > String
String reference.
Filter for ARB_debug_output removing duplicate messages.
Definition: ARB_debug_output.hpp:297
The DebugOutputARBSource enumeration.
std::size_t size(void) const
Return the size (length) string.
Definition: ref_tpl.hpp:149
static void Control(DebugOutputARBSource source, DebugOutputARBType type, DebugOutputARBSeverity severity, bool enable)
Enables/disables messages with specific parameters.
Definition: ARB_debug_output.hpp:49
String const reference wrapper template.
Definition: ref_tpl.hpp:72
GLsizei length
The length of th debug message.
Definition: ARB_debug_output.hpp:82
Helper macro for optional checking of availability of GL function.
Filter for ARB_debug_output formatting the debug output into XML.
Definition: ARB_debug_output.hpp:372
DebugOutputARBSource
Debug output source enumeration.
Definition: source.hpp:27
Filter for ARB_debug_output printing a simple tree to a standard output.
Definition: ARB_debug_output.hpp:335
GLuint id
The id of the debug message.
Definition: ARB_debug_output.hpp:76
std::function< void(const CallbackData &)> Callback
Type of a callback functor processing debug output.
Definition: ARB_debug_output.hpp:95
Structure containing data passed to Callback functor.
Definition: ARB_debug_output.hpp:67
static void Synchronous(bool enable)
Enables or disables synchronous debug output.
Definition: ARB_debug_output.hpp:188
ARB_debug_output_Tree(std::ostream &)
Constructor takes a reference to standard output stream.
static void InsertMessage(DebugOutputARBSource source, DebugOutputARBType type, GLuint id, DebugOutputARBSeverity severity, const GLchar *buffer, GLint length=-1)
Inserts a new message into the debug output.
Definition: ARB_debug_output.hpp:203
const GLchar * message
The debug message.
Definition: ARB_debug_output.hpp:85

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