AnimEngine
All Classes Namespaces Functions
common.h
1 #pragma once
2 #ifndef KJY_OBJECT_ORIENTED_OPENGL_COMMON_H_
3 #define KJY_OBJECT_ORIENTED_OPENGL_COMMON_H_
4 
5 #include <assert.h>
6 
7 #define MAX(_A, _B) ((_A) > (_B) ? (_A) : (_B))
8 #define MIN(_A, _B) ((_A) < (_B) ? (_A) : (_B))
9 #define CLAMP(_A, _MIN, _MAX) ( _A > _MAX ? (_MAX) : (_A < _MIN ? (_MIN) : (_A) ) )
10 #define FNOT(_F) (1.0f - (_F))
11 
12 #ifndef STRIFY
13  #define _STRIFY(_PD) #_PD
14  #define STRIFY(_PD) _STRIFY(_PD)
15 #endif
16 
17 #define PING() {fprintf(stderr,"PING! (%d:%s)\n",__LINE__,__FILE__);}
18 
19 #define _GLERR_SWITCH \
20 switch(__glErr__){\
21  case 0x0500:\
22  fprintf(stderr, "'Invalid OpenGL enum was passed to function.\n'");\
23  break;\
24  case 0x0501:\
25  fprintf(stderr, "'Invalid value was passed to an OpenGL function.\n'");\
26  break;\
27  case 0x0502:\
28  fprintf(stderr, "'Invalid operation error, the OpenGL state conflicted with a command.\n'");\
29  break;\
30  case 0x0503:\
31  fprintf(stderr, "'OpenGL stack overflow.\n'");\
32  break;\
33  case 0x0504:\
34  fprintf(stderr, "'OpenGL stack underflow.\n'");\
35  break;\
36  case 0x0505:\
37  fprintf(stderr, "'OpenGL out of memory error!\n'");\
38  break;\
39  case 0x0506:\
40  fprintf(stderr, "'Invalid framebuffer operation!\n'");\
41  break;\
42  case 0x0507:\
43  fprintf(stderr, "'The OpenGL context was lost!\n'");\
44  break;\
45  \
46 }\
47 
48 #define ASSERT_NO_GLERR() {\
49  GLenum __glErr__ = glGetError();\
50  if(__glErr__ != GL_NO_ERROR){\
51  fprintf(stderr, "OpenGL Error caught on %s:%i\n", __FILE__, __LINE__);\
52  _GLERR_SWITCH\
53  assert(__glErr__ == GL_NO_ERROR);\
54  }\
55 }
56 
57 #define ASSERT_NO_GLERR_NOTE(_CALL) {\
58  GLenum __glErr__ = glGetError();\
59  if(__glErr__ != GL_NO_ERROR){\
60  fprintf(stderr, "OpenGL Error caught on %s:%i for call:\n", __FILE__, __LINE__);\
61  fprintf(stderr, " '%s'\n", "" STRIFY((_CALL)) "" );\
62  _GLERR_SWITCH\
63  assert(__glErr__ == GL_NO_ERROR);\
64  }\
65 }
66 
67 #define _CHECK_BEFORE() {\
68  GLenum __glErr__ = glGetError();\
69  if(__glErr__ != GL_NO_ERROR){\
70  fprintf(stderr, "OpenGL Error caught before %s:%i\n", __FILE__, __LINE__);\
71  _GLERR_SWITCH\
72  assert(__glErr__ == GL_NO_ERROR);\
73  }\
74 }
75 
76 #define CHECKED_GL_CALL(_CALL) _CHECK_BEFORE(); (_CALL); ASSERT_NO_GLERR_NOTE(_CALL)
77 
78 /* Check these calls only if the following flag is enabled */
79 #ifndef OOOGL_CONDITIONAL_CHECKS
80 #define CONDITIONALLY_CHECKED_GL_CALL(_CALL) (_CALL)
81 #define CONDITIONALLY_ASSERT_NO_GLERR() ((void)0)
82 #else
83 #define CONDITIONALLY_CHECKED_GL_CALL(_CALL) CHECKED_GL_CALL(_CALL)
84 #define CONDITIONALLY_ASSERT_NO_GLERR() ASSERT_NO_GLERR()
85 #endif
86 
87 
88 #ifndef BASETYPES
89  #define BASETYPES
90  typedef unsigned UINT;
91  typedef unsigned long ULONG;
92  typedef ULONG *PULONG;
93  typedef unsigned short USHORT;
94  typedef USHORT *PUSHORT;
95  typedef unsigned char UCHAR;
96  typedef UCHAR *PUCHAR;
97 #endif
98 
99 
100 #endif