13 #ifndef OGLPLUS_ERROR_1107121317_HPP
14 #define OGLPLUS_ERROR_1107121317_HPP
16 #include <oglplus/auxiliary/obj_desc.hpp>
23 #if OGLPLUS_CUSTOM_ERROR_HANDLING
27 #define OGLPLUS_ERROR_INFO_CONTEXT(CONTEXT, CLASS) \
28 static const char* _errinf_ctxt(void) \
32 static const char* _errinf_cls(void) \
37 #define OGLPLUS_ERROR_INFO_REUSE_CONTEXT(SOURCE) \
38 using SOURCE::_errinf_ctxt; \
39 using SOURCE::_errinf_cls;
43 #if OGLPLUS_ERROR_INFO_NO_GL_SYMBOL
44 #define OGLPLUS_ERROR_INFO_INIT_GLSYM(SYMBOL)
46 #define OGLPLUS_ERROR_INFO_INIT_GLSYM(SYMBOL) , SYMBOL
50 #if OGLPLUS_ERROR_INFO_NO_FILE
51 #define OGLPLUS_ERROR_INFO_INIT_FILE(FILEPATH)
53 #define OGLPLUS_ERROR_INFO_INIT_FILE(FILEPATH) , FILEPATH
57 #if OGLPLUS_ERROR_INFO_NO_FUNC
58 #define OGLPLUS_ERROR_INFO_INIT_FUNC(FUNC)
60 #define OGLPLUS_ERROR_INFO_INIT_FUNC(FUNC) , FUNC
64 #if OGLPLUS_ERROR_INFO_NO_LINE
65 #define OGLPLUS_ERROR_INFO_INIT_LINE(LINE)
67 #define OGLPLUS_ERROR_INFO_INIT_LINE(LINE) , LINE
71 #if OGLPLUS_ERROR_INFO_NO_CLASS_NAME
72 #define OGLPLUS_ERROR_INFO_INIT_CLS_NAME(NAME)
74 #define OGLPLUS_ERROR_INFO_INIT_CLS_NAME(NAME) , NAME
78 #if OGLPLUS_ERROR_INFO_NO_BIND_TARGET
79 #define OGLPLUS_ERROR_INFO_INIT_BIND_TGT(NAME)
81 #define OGLPLUS_ERROR_INFO_INIT_BIND_TGT(NAME) , NAME
85 #if OGLPLUS_ERROR_INFO_NO_OBJECT_DESC
86 #define OGLPLUS_ERROR_INFO_INIT_OBJ_DECS_FUNCS(GET, PURGE, NAME)
88 #define OGLPLUS_ERROR_INFO_INIT_OBJ_DECS_FUNCS(GET, PURGE, NAME) \
89 , GET, PURGE, GLuint(NAME)
93 #define OGLPLUS_ERROR_INFO(CONTEXT) \
95 sizeof(decltype(&gl ## CONTEXT)) \
96 OGLPLUS_ERROR_INFO_INIT_GLSYM(#CONTEXT) \
97 OGLPLUS_ERROR_INFO_INIT_FILE(__FILE__) \
98 OGLPLUS_ERROR_INFO_INIT_FUNC(__FUNCTION__) \
99 OGLPLUS_ERROR_INFO_INIT_LINE(__LINE__) \
100 OGLPLUS_ERROR_INFO_INIT_CLS_NAME("") \
101 OGLPLUS_ERROR_INFO_INIT_BIND_TGT(StrLit()) \
102 OGLPLUS_ERROR_INFO_INIT_OBJ_DECS_FUNCS(nullptr, nullptr, 0) \
105 #define OGLPLUS_LIMIT_ERROR_INFO(CONTEXT) \
107 sizeof(decltype(GL_ ## CONTEXT)) \
108 OGLPLUS_ERROR_INFO_INIT_GLSYM(#CONTEXT) \
109 OGLPLUS_ERROR_INFO_INIT_FILE(__FILE__) \
110 OGLPLUS_ERROR_INFO_INIT_FUNC(__FUNCTION__) \
111 OGLPLUS_ERROR_INFO_INIT_LINE(__LINE__) \
112 OGLPLUS_ERROR_INFO_INIT_CLS_NAME("") \
113 OGLPLUS_ERROR_INFO_INIT_BIND_TGT(StrLit()) \
114 OGLPLUS_ERROR_INFO_INIT_OBJ_DECS_FUNCS(nullptr, nullptr, 0) \
117 #define OGLPLUS_ERROR_INFO_AUTO_CTXT() \
120 OGLPLUS_ERROR_INFO_INIT_GLSYM(_errinf_ctxt()) \
121 OGLPLUS_ERROR_INFO_INIT_FILE(__FILE__) \
122 OGLPLUS_ERROR_INFO_INIT_FUNC(__FUNCTION__) \
123 OGLPLUS_ERROR_INFO_INIT_LINE(__LINE__) \
124 OGLPLUS_ERROR_INFO_INIT_CLS_NAME(_errinf_cls()) \
125 OGLPLUS_ERROR_INFO_INIT_BIND_TGT(StrLit()) \
126 OGLPLUS_ERROR_INFO_INIT_OBJ_DECS_FUNCS(nullptr, nullptr, 0) \
129 #define OGLPLUS_ERROR_INFO_STR(CONTEXT_STR) \
132 OGLPLUS_ERROR_INFO_INIT_GLSYM(CONTEXT_STR) \
133 OGLPLUS_ERROR_INFO_INIT_FILE(__FILE__) \
134 OGLPLUS_ERROR_INFO_INIT_FUNC(__FUNCTION__) \
135 OGLPLUS_ERROR_INFO_INIT_LINE(__LINE__) \
136 OGLPLUS_ERROR_INFO_INIT_CLS_NAME("") \
137 OGLPLUS_ERROR_INFO_INIT_BIND_TGT(StrLit()) \
138 OGLPLUS_ERROR_INFO_INIT_OBJ_DECS_FUNCS(nullptr, nullptr, 0) \
141 #define OGLPLUS_OBJECT_ERROR_INFO(CONTEXT, CLASS, TARGET_NAME, NAME) \
143 sizeof(decltype(&gl ## CONTEXT)) \
144 OGLPLUS_ERROR_INFO_INIT_GLSYM(#CONTEXT) \
145 OGLPLUS_ERROR_INFO_INIT_FILE(__FILE__) \
146 OGLPLUS_ERROR_INFO_INIT_FUNC(__FUNCTION__) \
147 OGLPLUS_ERROR_INFO_INIT_LINE(__LINE__) \
148 OGLPLUS_ERROR_INFO_INIT_CLS_NAME(#CLASS) \
149 OGLPLUS_ERROR_INFO_INIT_BIND_TGT(TARGET_NAME) \
150 OGLPLUS_ERROR_INFO_INIT_OBJ_DECS_FUNCS( \
151 &oglplus::aux::ObjectDescRegistry<CLASS##Ops>::_get_desc, \
152 &oglplus::aux::ObjectDescRegistry<CLASS##Ops>::_purge_archive,\
184 #if !OGLPLUS_ERROR_INFO_NO_GL_SYMBOL
188 #if !OGLPLUS_ERROR_INFO_NO_FILE
192 #if !OGLPLUS_ERROR_INFO_NO_FUNC
196 #if !OGLPLUS_ERROR_INFO_NO_LINE
197 const unsigned _line;
200 #if !OGLPLUS_ERROR_INFO_NO_CLASS_NAME
201 const char* _cls_name;
204 #if !OGLPLUS_ERROR_INFO_NO_BIND_TARGET
208 #if !OGLPLUS_ERROR_INFO_NO_OBJECT_DESC
209 const String& (*_get_obj_desc)(GLuint);
210 void (*_purge_archive)(void);
229 ,
const unsigned line
233 ,
const char* cls_name
241 ,
const String& (*get_obj_desc)(GLuint)
242 ,
void (*purge_archive)(
void)
247 #if !OGLPLUS_ERROR_INFO_NO_GL_SYMBOL
251 #if !OGLPLUS_ERROR_INFO_NO_FILE
255 #if !OGLPLUS_ERROR_INFO_NO_FUNC
259 #if !OGLPLUS_ERROR_INFO_NO_LINE
263 #if !OGLPLUS_ERROR_INFO_NO_CLASS_NAME
264 , _cls_name(cls_name)
267 #if !OGLPLUS_ERROR_INFO_NO_BIND_TARGET
268 , _bind_tgt(bind_tgt)
271 #if !OGLPLUS_ERROR_INFO_NO_OBJECT_DESC
272 , _get_obj_desc(get_obj_desc)
273 , _purge_archive(purge_archive)
274 , _obj_name(obj_name)
427 :
public std::runtime_error
433 #if !OGLPLUS_ERROR_NO_PROPERTIES
436 struct PropertyMapInit { };
444 #if !OGLPLUS_ERROR_NO_PROPERTIES
448 #if !OGLPLUS_ERROR_NO_PROPAGATION_INFO
457 bool assertion =
false
464 PropertyMapInit&& properties
467 inline ~
Error(
void) throw()
583 #if OGLPLUS_DOCUMENTATION_ONLY || OGLPLUS_ERROR_NO_PROPERTIES
599 #if OGLPLUS_DOCUMENTATION_ONLY || !OGLPLUS_ERROR_NO_PROPERTIES
600 template <
typename Key,
typename Value>
603 PropertyMapInit& properties,
608 properties[key] = value;
611 template <
typename Key,
typename Value>
618 #if OGLPLUS_DOCUMENTATION_ONLY || OGLPLUS_ERROR_NO_PROPAGATION_INFO
634 void Trace(
const ErrorInfo& info);
636 void Cleanup(
void)
const;
650 :
Error(code, desc, info,
true)
654 #if OGLPLUS_DOCUMENTATION_ONLY
681 :
Error(code, msg, info, true)
707 ):
Error(GL_INVALID_VALUE, msg, info)
743 Error::PropertyMapInit&& properties
744 ):
Error(code, msg, info, std::move(properties))
745 , _location(location)
758 #if OGLPLUS_DOCUMENTATION_ONLY || OGLPLUS_CUSTOM_ERROR_HANDLING
773 const char* _message;
850 Error::PropertyMapInit&& properties,
855 ): _error_code(error_code)
860 , _properties(std::move(properties))
861 , _assertion(assertion)
862 , _fatal_error(fatal_error)
863 , _build_error(build_error)
864 , _limit_error(limit_error)
879 bool _has_error_handler(
void);
907 #endif // OGLPLUS_CUSTOM_ERROR_HANDLING
909 template <
class Exception>
912 #if OGLPLUS_CUSTOM_ERROR_HANDLING
913 if(aux::_has_error_handler() && aux::_get_error_handler()(
915 GL_INVALID_OPERATION,
919 Error::PropertyMapInit(),
926 #endif // OGLPLUS_CUSTOM_ERROR_HANDLING
927 throw Exception(msg, info);
930 template <
class Exception,
typename FBStatus>
931 inline void HandleIncompleteFramebuffer(
933 const ErrorInfo& info
936 const GLchar* msg =
"Framebuffer is incomplete";
937 #if OGLPLUS_CUSTOM_ERROR_HANDLING
938 if(aux::_has_error_handler() && aux::_get_error_handler()(
940 GL_INVALID_FRAMEBUFFER_OPERATION,
944 Error::PropertyMapInit(),
951 #endif // OGLPLUS_CUSTOM_ERROR_HANDLING
952 throw Exception(status, msg, info);
955 void HandleShaderVariableError(
959 const ErrorInfo& info,
960 Error::PropertyMapInit&& properties
963 void HandleLimitError(GLuint value, GLuint limit,
const ErrorInfo& info);
965 #if !OGLPLUS_NO_VARIADIC_TEMPLATES && !OGLPLUS_NO_GLFUNC_CHECKS
966 void HandleMissingFunction(
const ErrorInfo& info);
967 #endif // OGLPLUS_NO_VARIADIC_TEMPLATES || OGLPLUS_NO_GLFUNC_CHECKS
972 const ErrorInfo& info,
973 Error::PropertyMapInit&& properties
976 void HandleError(GLenum code,
const ErrorInfo& info,
bool assertion);
978 #if OGLPLUS_DOCUMENTATION_ONLY
985 #define OGLPLUS_IS_ERROR(EXPRESSION)
988 #ifndef OGLPLUS_IS_ERROR
989 #define OGLPLUS_IS_ERROR(EXPRESSION) (EXPRESSION)
992 #if OGLPLUS_DOCUMENTATION_ONLY
997 #define OGLPLUS_CHECK(PARAM)
1000 #ifndef OGLPLUS_CHECK
1001 #define OGLPLUS_CHECK(PARAM) { \
1002 GLenum error_code = ::glGetError(); \
1003 if(error_code != GL_NO_ERROR) HandleError(error_code, PARAM, false); \
1007 #if OGLPLUS_DOCUMENTATION_ONLY
1013 #define OGLPLUS_VERIFY(PARAM)
1016 #ifndef OGLPLUS_VERIFY
1017 #if !OGPLUS_LOW_PROFILE
1018 #define OGLPLUS_VERIFY(PARAM) { \
1019 GLenum error_code = ::glGetError(); \
1020 if(error_code != GL_NO_ERROR) HandleError(error_code, PARAM, true); \
1023 #define OGLPLUS_VERIFY(PARAM)
1027 #define OGLPLUS_IGNORE(PARAM) ::glGetError();
1031 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
1032 #include <oglplus/error.ipp>
1035 #endif // include guard