OGLplus (0.52.0) a C++ wrapper for OpenGL

basic.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_ERROR_BASIC_1107121317_HPP
14 #define OGLPLUS_ERROR_BASIC_1107121317_HPP
15 
16 #include <oglplus/config/error.hpp>
17 #include <oglplus/error/code.hpp>
18 #include <oglplus/string/def.hpp>
19 #include <oglplus/string/ref.hpp>
20 #include <oglplus/string/empty.hpp>
21 #include <stdexcept>
22 #include <cassert>
23 
24 namespace oglplus {
25 
33 
43 class Error
44  : public std::runtime_error
45 {
46 private:
47  GLenum _code;
48 #if !OGLPLUS_ERROR_NO_FILE
49  const char* _file;
50 #endif
51 #if !OGLPLUS_ERROR_NO_FUNC
52  const char* _func;
53 #endif
54 #if !OGLPLUS_ERROR_NO_LINE
55  unsigned _line;
56 #endif
57 
58 #if !OGLPLUS_ERROR_NO_GL_LIB
59  const char* _gllib_name;
60 #endif
61 
62 #if !OGLPLUS_ERROR_NO_GL_FUNC
63  const char* _glfunc_name;
64 #endif
65 
66 #if !OGLPLUS_ERROR_NO_GL_SYMBOL
67  const char* _enumpar_name;
68  GLenum _enumpar;
69  GLint _index;
70 #endif
71 
72 public:
73  static const char* Message(GLenum);
74 
75  Error(const char* message);
76 
77  ~Error(void) throw() { }
78 
79  Error& NoInfo(void) { return *this; }
80 
81  Error& Code(GLenum code)
82  {
83  _code = code;
84  return *this;
85  }
86 
88  ErrorCode Code(void) const { return ErrorCode(_code); }
89 
90  Error& SourceFile(const char* file)
91  {
92 #if !OGLPLUS_ERROR_NO_FILE
93  _file = file;
94 #endif
95  (void)file;
96  return *this;
97  }
98 
100 
106  const char* SourceFile(void) const;
107 
108  Error& SourceFunc(const char* func)
109  {
110 #if !OGLPLUS_ERROR_NO_FUNC
111  _func = func;
112 #endif
113  (void)func;
114  return *this;
115  }
116 
118 
124  const char* SourceFunc(void) const;
125 
126  Error& SourceLine(unsigned line)
127  {
128 #if !OGLPLUS_ERROR_NO_LINE
129  _line = line;
130 #endif
131  (void)line;
132  return *this;
133  }
134 
136 
142  unsigned SourceLine(void) const;
143 
144  Error& GLLib(const char* lib_name)
145  {
146 #if !OGLPLUS_ERROR_NO_GL_LIB
147  _gllib_name = lib_name;
148 #endif
149  (void)lib_name;
150  return *this;
151  }
152 
153  const char* GLLib(void) const;
154 
155  Error& GLFunc(const char* func_name)
156  {
157 #if !OGLPLUS_ERROR_NO_GL_FUNC
158  _glfunc_name = func_name;
159 #endif
160  (void)func_name;
161  return *this;
162  }
163 
165 
173  const char* GLFunc(void) const;
174 
175  template <typename Enum_>
176  Error& EnumParam(Enum_ param)
177  {
178 #if !OGLPLUS_ERROR_NO_GL_SYMBOL
179  _enumpar = GLenum(param);
180  _enumpar_name = EnumValueName(param).c_str();
181 #endif
182  (void)param;
183  return *this;
184  }
185 
186  Error& EnumParam(GLenum param, const char* param_name)
187  {
188 #if !OGLPLUS_ERROR_NO_GL_SYMBOL
189  _enumpar = param;
190  _enumpar_name = param_name;
191 #endif
192  (void)param;
193  (void)param_name;
194  return *this;
195  }
196 
198 
206  GLenum EnumParam(void) const;
207 
209 
217  const char* EnumParamName(void) const;
218 
219  Error& Index(GLuint index)
220  {
221 #if !OGLPLUS_ERROR_NO_GL_SYMBOL
222  _index = GLint(index);
223 #endif
224  (void)index;
225  return *this;
226  }
227 
229 
239  GLint Index(void) const;
240 
242  virtual GLfloat Value(void) const { return GLfloat(0); }
243 
245  virtual GLfloat Limit(void) const { return GLfloat(0); }
246 
248  virtual GLenum BindTarget(void) const { return GLenum(0); }
249 
251  virtual const char* TargetName(void) const { return nullptr; }
252 
254 
257  virtual GLenum ObjectType(void) const { return GLenum(0); }
258 
260 
264  virtual const char* ObjectTypeName(void) const { return nullptr; }
265 
267 
271  virtual GLint ObjectName(void) const { return -1; }
272 
274 
278  virtual const std::string& ObjectDesc(void) const
279  {
280  return EmptyStdString();
281  }
282 
284 
288  virtual GLenum SubjectType(void) const { return GLenum(0); }
289 
291 
295  virtual const char* SubjectTypeName(void) const { return nullptr; }
296 
298 
302  virtual GLint SubjectName(void) const { return -1; }
303 
305 
309  virtual const std::string& SubjectDesc(void) const
310  {
311  return EmptyStdString();
312  }
313 
315 
320  virtual const char* Identifier(void) const { return nullptr; }
321 
323 
328  virtual const String& Log(void) const { return EmptyString(); }
329 };
330 
332 template <typename ErrorType>
333 inline void HandleError(ErrorType& error)
334 {
335  throw error;
336 }
337 
338 #define OGLPLUS_ERROR_CONTEXT(GLFUNC, CLASS) \
339  static const char* _errinf_glfn(void) \
340  { \
341  return #GLFUNC; \
342  } \
343  static const char* _errinf_cls(void) \
344  { \
345  return #CLASS; \
346  }
347 
348 #define OGLPLUS_ERROR_REUSE_CONTEXT(SOURCE) \
349  using SOURCE::_errinf_glfn; \
350  using SOURCE::_errinf_cls;
351 
352 // Macro for generic error handling
353 #define OGLPLUS_HANDLE_ERROR_IF(\
354  CONDITION,\
355  ERROR_CODE,\
356  MESSAGE,\
357  ERROR,\
358  ERROR_INFO\
359 )\
360 {\
361  GLenum error_code = ERROR_CODE;\
362  if(CONDITION)\
363  {\
364  ERROR error(MESSAGE);\
365  (void)error\
366  .ERROR_INFO\
367  .SourceFile(__FILE__)\
368  .SourceFunc(__FUNCTION__)\
369  .SourceLine(__LINE__)\
370  .Code(error_code);\
371  HandleError(error);\
372  }\
373 }
374 
375 #define OGLPLUS_GLFUNC_CHECK(FUNC_NAME, ERROR, ERROR_INFO)\
376  OGLPLUS_HANDLE_ERROR_IF(\
377  error_code != GL_NO_ERROR,\
378  glGetError(),\
379  ERROR::Message(error_code),\
380  ERROR,\
381  ERROR_INFO.GLFunc(FUNC_NAME)\
382  )
383 
384 #define OGLPLUS_CHECK(GLFUNC, ERROR, ERROR_INFO) \
385  OGLPLUS_GLFUNC_CHECK(#GLFUNC, ERROR, ERROR_INFO)
386 
387 #define OGLPLUS_CHECK_CTXT(ERROR, ERROR_INFO) \
388  OGLPLUS_GLFUNC_CHECK(_errinf_glfn(), ERROR, ERROR_INFO)
389 
390 #define OGLPLUS_CHECK_SIMPLE(GLFUNC) \
391  OGLPLUS_CHECK(GLFUNC, Error, NoInfo())
392 
393 #if !OGLPLUS_LOW_PROFILE
394 #define OGLPLUS_VERIFY(GLFUNC, ERROR, ERROR_INFO) \
395  OGLPLUS_CHECK(GLFUNC, ERROR, ERROR_INFO)
396 #else
397 #define OGLPLUS_VERIFY(GLFUNC, ERROR, ERROR_INFO)
398 #endif
399 
400 #define OGLPLUS_VERIFY_SIMPLE(GLFUNC) \
401  OGLPLUS_CHECK(GLFUNC, Error, NoInfo())
402 
403 #define OGLPLUS_IGNORE(PARAM) ::glGetError();
404 
405 } // namespace oglplus
406 
407 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
408 #include <oglplus/error/basic.ipp>
409 #endif
410 
411 #endif // include guard
Empty std::string.
virtual const char * TargetName(void) const
Returns the bind target name.
Definition: basic.hpp:251
const Char * c_str(void) const
Returns the null-terminated c-string.
Definition: ref_tpl.hpp:200
unsigned SourceLine(void) const
Returns the line of the source file where the error occured.
virtual GLenum SubjectType(void) const
Returns the subject type.
Definition: basic.hpp:288
virtual GLfloat Limit(void) const
Returns the limit value related to the error.
Definition: basic.hpp:245
virtual GLfloat Value(void) const
Returns the value parameter related to the error.
Definition: basic.hpp:242
StrCRef EnumValueName(Enum enum_value)
Returns the name of the GL enumerated value for an OGLplus enum value.
GLint Index(void) const
Returns the index parameter related to the error.
virtual const char * Identifier(void) const
Returns the identifier of a GPU program variable.
Definition: basic.hpp:320
virtual const char * SubjectTypeName(void) const
Returns the subject class name.
Definition: basic.hpp:295
void HandleError(ErrorType &error)
Generic error handling function.
Definition: basic.hpp:333
String type definition and related functions.
String reference.
GLenum EnumParam(void) const
Returns the value of the enumeration parameter related to the error.
virtual const char * ObjectTypeName(void) const
Returns the object type name.
Definition: basic.hpp:264
const char * GLFunc(void) const
Returns the name of the GL function related to the error.
const char * SourceFile(void) const
Returns the name of the source file where the error occured.
virtual const std::string & SubjectDesc(void) const
Returns the subject textual description.
Definition: basic.hpp:309
virtual GLenum BindTarget(void) const
Returns the bind target.
Definition: basic.hpp:248
virtual GLint SubjectName(void) const
Returns the subject GL name.
Definition: basic.hpp:302
const char * SourceFunc(void) const
Returns the name of the function where the error occured.
::std::basic_string< GLchar > String
String class.
Definition: def.hpp:36
virtual const String & Log(void) const
Returns a log string associated with the error.
Definition: basic.hpp:328
virtual const std::string & ObjectDesc(void) const
Returns the object instance description.
Definition: basic.hpp:278
ErrorCode Code(void) const
Returns the GL error code related to the error.
Definition: basic.hpp:88
Exception class for general OpenGL errors.
Definition: basic.hpp:43
Enumeration of error-codes.
ErrorCode
Error code enumeration.
Definition: code.hpp:27
virtual GLint ObjectName(void) const
Returns the object instance GL name.
Definition: basic.hpp:271
const char * EnumParamName(void) const
Returns the name of the enumeration parameter related to the error.
virtual GLenum ObjectType(void) const
Returns the object type.
Definition: basic.hpp:257

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