Macro.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /****************************************************************************
  2. Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #pragma once
  21. #include "platform/CCPlatformConfig.h"
  22. #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  23. #include <android/log.h>
  24. #endif
  25. #ifndef RENDERER_BEGIN
  26. #define RENDERER_BEGIN namespace cocos2d { namespace renderer {
  27. #endif // RENDERER_BEGIN
  28. #ifndef RENDERER_END
  29. #define RENDERER_END }}
  30. #endif // RENDERER_END
  31. //#ifndef DISALLOW_COPY_ASSIGN_AND_MOVE
  32. #define CC_DISALLOW_COPY_ASSIGN_AND_MOVE(type) \
  33. type(const type&) = delete; \
  34. type& operator =(const type&) = delete; \
  35. type(type &&) = delete; \
  36. type& operator =(const type &&) = delete;
  37. //#endif // DISALLOW_COPY_ASSIGN_AND_MOVE
  38. #define RENDERER_LOG_TAG "renderer"
  39. #define RENDERER_QUOTEME_(x) #x
  40. #define RENDERER_QUOTEME(x) RENDERER_QUOTEME_(x)
  41. #if defined(COCOS2D_DEBUG) && COCOS2D_DEBUG > 0
  42. #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  43. #define RENDERER_LOGV(fmt, ...) __android_log_print(ANDROID_LOG_VERBOSE, RENDERER_LOG_TAG, " (" RENDERER_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__)
  44. #else
  45. #define RENDERER_LOGV(fmt, ...) printf("V/" RENDERER_LOG_TAG " (" RENDERER_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__)
  46. #endif // (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  47. #else
  48. #define RENDERER_LOGV(fmt, ...) do {} while(false)
  49. #endif // defined(COCOS2D_DEBUG) && COCOS2D_DEBUG > 0
  50. #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  51. #define RENDERER_LOGD(fmt, ...) __android_log_print(ANDROID_LOG_DEBUG, RENDERER_LOG_TAG, " (" RENDERER_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__)
  52. #define RENDERER_LOGI(fmt, ...) __android_log_print(ANDROID_LOG_INFO, RENDERER_LOG_TAG, " (" RENDERER_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__)
  53. #define RENDERER_LOGW(fmt, ...) __android_log_print(ANDROID_LOG_WARN, RENDERER_LOG_TAG, " (" RENDERER_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__)
  54. #define RENDERER_LOGE(fmt, ...) __android_log_print(ANDROID_LOG_ERROR, RENDERER_LOG_TAG, " (" RENDERER_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__)
  55. #else
  56. #define RENDERER_LOGD(fmt, ...) printf("D/" RENDERER_LOG_TAG " (" RENDERER_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__)
  57. #define RENDERER_LOGI(fmt, ...) printf("I/" RENDERER_LOG_TAG " (" RENDERER_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__)
  58. #define RENDERER_LOGW(fmt, ...) printf("W/" RENDERER_LOG_TAG " (" RENDERER_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__)
  59. #define RENDERER_LOGE(fmt, ...) printf("E/" RENDERER_LOG_TAG " (" RENDERER_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__)
  60. #endif // (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  61. #define RENDERER_DEBUG 1 // REFINE: remove this
  62. #define RENDERER_SAFE_RELEASE(p) do { if((p) != nullptr) (p)->release(); } while(false)
  63. #define RENDERER_SAFE_RETAIN(p) do { if((p) != nullptr) (p)->retain(); } while(false)
  64. #define RENDERER_DEFINE_CREATE_METHOD_0(clsName, initMethod) \
  65. static clsName* create() \
  66. { \
  67. clsName* ret = new (std::nothrow) clsName(); \
  68. if (ret && ret->initMethod()) \
  69. { \
  70. ret->autorelease(); \
  71. return ret; \
  72. } \
  73. delete ret; \
  74. return nullptr; \
  75. }
  76. #define RENDERER_DEFINE_CREATE_METHOD_1(clsName, initMethod, arg0Type) \
  77. static clsName* create(arg0Type arg0) \
  78. { \
  79. clsName* ret = new (std::nothrow) clsName(); \
  80. if (ret && ret->initMethod(arg0)) \
  81. { \
  82. ret->autorelease(); \
  83. return ret; \
  84. } \
  85. delete ret; \
  86. return nullptr; \
  87. }
  88. #define RENDERER_DEFINE_CREATE_METHOD_2(clsName, initMethod, arg0Type, arg1Type) \
  89. static clsName* create(arg0Type arg0, arg1Type arg1) \
  90. { \
  91. clsName* ret = new (std::nothrow) clsName(); \
  92. if (ret && ret->initMethod(arg0, arg1)) \
  93. { \
  94. ret->autorelease(); \
  95. return ret; \
  96. } \
  97. delete ret; \
  98. return nullptr; \
  99. }
  100. #define RENDERER_DEFINE_CREATE_METHOD_3(clsName, initMethod, arg0Type, arg1Type, arg2Type) \
  101. static clsName* create(arg0Type arg0, arg1Type arg1, arg2Type arg2) \
  102. { \
  103. clsName* ret = new (std::nothrow) clsName(); \
  104. if (ret && ret->initMethod(arg0, arg1, arg2)) \
  105. { \
  106. ret->autorelease(); \
  107. return ret; \
  108. } \
  109. delete ret; \
  110. return nullptr; \
  111. }
  112. #define RENDERER_DEFINE_CREATE_METHOD_4(clsName, initMethod, arg0Type, arg1Type, arg2Type, arg3Type) \
  113. static clsName* create(arg0Type arg0, arg1Type arg1, arg2Type arg2, arg3Type arg3) \
  114. { \
  115. clsName* ret = new (std::nothrow) clsName(); \
  116. if (ret && ret->initMethod(arg0, arg1, arg2, arg3)) \
  117. { \
  118. ret->autorelease(); \
  119. return ret; \
  120. } \
  121. delete ret; \
  122. return nullptr; \
  123. }
  124. #define RENDERER_DEFINE_CREATE_METHOD_5(clsName, initMethod, arg0Type, arg1Type, arg2Type, arg3Type, arg4Type) \
  125. static clsName* create(arg0Type arg0, arg1Type arg1, arg2Type arg2, arg3Type arg3, arg4Type arg4) \
  126. { \
  127. clsName* ret = new (std::nothrow) clsName(); \
  128. if (ret && ret->initMethod(arg0, arg1, arg2, arg3, arg4)) \
  129. { \
  130. ret->autorelease(); \
  131. return ret; \
  132. } \
  133. delete ret; \
  134. return nullptr; \
  135. }
  136. #define RENDERER_DEFINE_CREATE_METHOD_6(clsName, initMethod, arg0Type, arg1Type, arg2Type, arg3Type, arg4Type, arg5Type) \
  137. static clsName* create(arg0Type arg0, arg1Type arg1, arg2Type arg2, arg3Type arg3, arg4Type arg4, arg5Type arg5) \
  138. { \
  139. clsName* ret = new (std::nothrow) clsName(); \
  140. if (ret && ret->initMethod(arg0, arg1, arg2, arg3, arg4, arg5)) \
  141. { \
  142. ret->autorelease(); \
  143. return ret; \
  144. } \
  145. delete ret; \
  146. return nullptr; \
  147. }
  148. // enum class to GLENUM
  149. #define ENUM_CLASS_TO_GLENUM(value) static_cast<GLenum>(value)
  150. #define _GL_CHECK(_call) \
  151. do { \
  152. _call; \
  153. GLenum gl_err = glGetError(); \
  154. if (0 != gl_err) \
  155. RENDERER_LOGE(#_call "; GL error 0x%x: %s:%s", gl_err, glEnumName(gl_err), __FUNCTION__); \
  156. } while(false)
  157. #if COCOS2D_DEBUG > 0
  158. # define GL_CHECK(_call) _GL_CHECK(_call)
  159. #else
  160. # define GL_CHECK(_call) _call
  161. #endif // BRENDERER_CONFIG_DEBUG
  162. #ifndef RENDERER_PI
  163. #define RENDERER_PI 3.1415926535897932385f
  164. #endif // RENDERER_PI