1 #ifndef GLES_MACROS_H 2 #define GLES_MACROS_H 3 4 #if defined(__linux__) || defined(__APPLE__) 5 6 #include <mutex> 7 #include "base/PathUtils.h" 8 #include "base/MemoryTracker.h" 9 10 #if 0 11 12 #define MEM_TRACE_IF(condition, group) \ 13 if ((condition)) { \ 14 static std::once_flag once_flag; \ 15 const std::string func(__FUNCTION__); \ 16 std::call_once(once_flag, [&func]() { \ 17 if (android::base::MemoryTracker::get()) { \ 18 std::string baseName; \ 19 android::base::PathUtils::split(std::string(__FILE__), NULL, &baseName); \ 20 android::base::MemoryTracker::get()->addToGroup( \ 21 group, baseName.r() + ":" + func); \ 22 } \ 23 }); \ 24 } 25 #else 26 27 #define MEM_TRACE_IF(condition, group) 28 29 #endif 30 31 #else 32 // windows 33 #define MEM_TRACE_IF(condition, group) 34 #endif 35 36 #define MEM_TRACE(group) MEM_TRACE_IF(true, group) 37 38 39 #define GET_CTX() \ 40 MEM_TRACE_IF(strncmp(__FUNCTION__, "gl", 2) == 0, "EMUGL") \ 41 if (!s_eglIface) \ 42 return; \ 43 GLEScontext* ctx = s_eglIface->getGLESContext(); \ 44 if (!ctx) \ 45 return; 46 47 #define GET_CTX_CM() \ 48 MEM_TRACE_IF(strncmp(__FUNCTION__, "gl", 2) == 0, "EMUGL") \ 49 if (!s_eglIface) \ 50 return; \ 51 GLEScmContext* ctx = \ 52 static_cast<GLEScmContext*>(s_eglIface->getGLESContext()); \ 53 if (!ctx) \ 54 return; 55 56 #define GET_CTX_V2() \ 57 MEM_TRACE_IF(strncmp(__FUNCTION__, "gl", 2) == 0, "EMUGL") \ 58 if (!s_eglIface) \ 59 return; \ 60 GLESv2Context* ctx = \ 61 static_cast<GLESv2Context*>(s_eglIface->getGLESContext()); \ 62 if (!ctx) \ 63 return; 64 65 #define GET_CTX_RET(failure_ret) \ 66 MEM_TRACE_IF(strncmp(__FUNCTION__, "gl", 2) == 0, "EMUGL") \ 67 if (!s_eglIface) \ 68 return failure_ret; \ 69 GLEScontext* ctx = s_eglIface->getGLESContext(); \ 70 if (!ctx) \ 71 return failure_ret; 72 73 #define GET_CTX_CM_RET(failure_ret) \ 74 MEM_TRACE_IF(strncmp(__FUNCTION__, "gl", 2) == 0, "EMUGL") \ 75 if (!s_eglIface) \ 76 return failure_ret; \ 77 GLEScmContext* ctx = \ 78 static_cast<GLEScmContext*>(s_eglIface->getGLESContext()); \ 79 if (!ctx) \ 80 return failure_ret; 81 82 #define GET_CTX_V2_RET(failure_ret) \ 83 MEM_TRACE_IF(strncmp(__FUNCTION__, "gl", 2) == 0, "EMUGL") \ 84 if (!s_eglIface) \ 85 return failure_ret; \ 86 GLESv2Context* ctx = \ 87 static_cast<GLESv2Context*>(s_eglIface->getGLESContext()); \ 88 if (!ctx) \ 89 return failure_ret; 90 91 #define SET_ERROR_IF(condition,err) if((condition)) { \ 92 fprintf(stderr, "%s:%s:%d error 0x%x\n", __FILE__, __FUNCTION__, __LINE__, err); \ 93 ctx->setGLerror(err); \ 94 return; \ 95 } 96 97 98 #define RET_AND_SET_ERROR_IF(condition,err,ret) if((condition)) { \ 99 fprintf(stderr, "%s:%s:%d error 0x%x\n", __FILE__, __FUNCTION__, __LINE__, err); \ 100 ctx->setGLerror(err); \ 101 return ret; \ 102 } 103 104 #define SET_ERROR_IF_DISPATCHER_NOT_SUPPORT(func) \ 105 SET_ERROR_IF(!ctx->dispatcher().func, GL_INVALID_OPERATION) 106 107 #define RET_AND_SET_ERROR_IF_DISPATCHER_NOT_SUPPORT(func, ret) \ 108 RET_AND_SET_ERROR_IF(!ctx->dispatcher().func, GL_INVALID_OPERATION, ret) 109 110 // Define the following flag to work around cocos2d rendering bug 111 // BUG: 119568237 112 #define TOLERATE_PROGRAM_LINK_ERROR 1 113 114 #endif 115