Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
graphicsmanagermacrodefs.h
Go to the documentation of this file.
1 
18 #ifndef ION_GFX_GRAPHICSMANAGERMACRODEFS_H_
19 #define ION_GFX_GRAPHICSMANAGERMACRODEFS_H_
20 
23 
24 #if defined(ION_ANALYTICS_ENABLED)
25 # define ION_PROFILE_GL_FUNC(name) \
26  ION_PROFILE_FUNCTION("ion::gfx::GraphicsManager::" #name)
27 #else
28 # define ION_PROFILE_GL_FUNC(name)
29 #endif
30 
31 #define ION_WRAP_NON_PROD_GL_FUNC(name, return_type, typed_args, args, trace) \
32  public: \
33  /* Invokes the wrapped function. */ \
34  return_type name typed_args { \
35  ION_PROFILE_GL_FUNC(name); \
36  DCHECK(name##_wrapper_.Get()); \
37  /* Don't trace calls to glGetError(). */ \
38  static const bool do_trace = strcmp(#name, "GetError") && \
39  strcmp(#name, "PushGroupMarker") && \
40  strcmp(#name, "PopGroupMarker"); \
41  if (tracing_ostream_ && do_trace) { \
42  *tracing_ostream_ << tracing_prefix_ << name##_wrapper_.GetFuncName() \
43  << "(" << trace << ")\n"; \
44  } \
45  if (is_error_checking_enabled_) { \
46  /* See ErrorChecker class doc for why it is needed here. */ \
47  std::ostringstream call; \
48  call << name##_wrapper_.GetFuncName() << "(" << trace << ")"; \
49  ErrorChecker error_checker(this, call.str()); \
50  return (*name##_wrapper_.Get())args; \
51  } else { \
52  return (*name##_wrapper_.Get())args; \
53  } \
54  }
55 
59 #define ION_WRAP_PROD_GL_FUNC(name, return_type, typed_args, args, trace) \
60  public: \
61  /* Invokes the wrapped function. */ \
62  return_type name typed_args { \
63  ION_PROFILE_GL_FUNC(name); \
64  return (*name ## _wrapper_.Get())args; \
65  }
66 
67 #define ION_DECLARE_GL_WRAPPER(group, name, return_type, typed_args, args) \
68  private: \
69  /* Typedef for a pointer to the function. */ \
70  typedef return_type(ION_APIENTRY* name ## _Type) typed_args; \
71  \
72  /* Wrapper class that initializes the pointer with a lookup. */ \
73  class name ## _Wrapper : public WrapperBase { \
74  public: \
75  name ## _Wrapper() : WrapperBase(#name, k ## group) {} \
76  name ## _Type Get() { return reinterpret_cast<name ## _Type>(ptr_); } \
77  }; \
78  \
79  /* Instance of the wrapper class. */ \
80  name ## _Wrapper name ## _wrapper_;
81 
82 #if ION_PRODUCTION
83 #define ION_WRAP_GL_FUNC(group, name, return_type, typed_args, args, trace) \
84  ION_WRAP_PROD_GL_FUNC(name, return_type, typed_args, args, trace) \
85  ION_DECLARE_GL_WRAPPER(group, name, return_type, typed_args, args)
86 #else
87 #define ION_WRAP_GL_FUNC(group, name, return_type, typed_args, args, trace) \
88  ION_WRAP_NON_PROD_GL_FUNC(name, return_type, typed_args, args, trace) \
89  ION_DECLARE_GL_WRAPPER(group, name, return_type, typed_args, args)
90 #endif
91 
93 #define ION_TRACE_ARG(name, type, arg) \
94  #arg << " = " << tracing_helper_.ToString(#type, arg)
95 
96 #endif // ION_GFX_GRAPHICSMANAGERMACRODEFS_H_