| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  GLDebug.h
 | 
					
						
							|  |  |  | //  MNN
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Created by MNN on 2019/01/31.
 | 
					
						
							|  |  |  | //  Copyright © 2018, Alibaba Group Holding Limited
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef GLDEBUG_H
 | 
					
						
							|  |  |  | #define GLDEBUG_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <assert.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							| 
									
										
										
										
											2019-12-27 22:16:57 +08:00
										 |  |  | #include "core/Macro.h"
 | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define DEBUG_ON
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef DEBUG_ON
 | 
					
						
							|  |  |  | #ifdef GL_BUILD_FOR_ANDROID
 | 
					
						
							|  |  |  | #include <android/log.h>
 | 
					
						
							|  |  |  | #define GPPRINT(format, ...) __android_log_print(ANDROID_LOG_INFO, "MNNJNI", format, ##__VA_ARGS__)
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define GPPRINT(format, ...) printf(format, ##__VA_ARGS__)
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define CHECK_POINTER(x)          \
 | 
					
						
							|  |  |  |     {                             \ | 
					
						
							|  |  |  |         if (NULL == x) {          \ | 
					
						
							|  |  |  |             FUNC_PRINT_ALL(x, p); \ | 
					
						
							|  |  |  |             break;                \ | 
					
						
							|  |  |  |         }                         \ | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef GL_BUILD_FOR_ANDROID
 | 
					
						
							|  |  |  | #define GLASSERT(x) assert(x)
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define GLASSERT(x)               \
 | 
					
						
							|  |  |  |     {                             \ | 
					
						
							|  |  |  |         bool result = (x);        \ | 
					
						
							|  |  |  |         if (!(result))            \ | 
					
						
							|  |  |  |             FUNC_PRINT((result)); \ | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FUNC_PRINT(x)
 | 
					
						
							|  |  |  | #define FUNC_PRINT_ALL(x, type)
 | 
					
						
							|  |  |  | #define CHECK_POINTER(x)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GPASSERT(x) GLASSERT(x)
 | 
					
						
							| 
									
										
										
										
											2019-06-24 11:32:41 +08:00
										 |  |  |      | 
					
						
							|  |  |  | #ifdef OPEN_GL_CHECK_ERROR
 | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | #define OPENGL_CHECK_ERROR              \
 | 
					
						
							|  |  |  |     {                                   \ | 
					
						
							|  |  |  |         GLenum error = glGetError();    \ | 
					
						
							| 
									
										
										
										
											2019-06-24 11:32:41 +08:00
										 |  |  |         if (GL_NO_ERROR != error){       \ | 
					
						
							|  |  |  |         MNN_PRINT("File = %s Line = %d Func=%s\n", __FILE__, __LINE__, __FUNCTION__); \ | 
					
						
							|  |  |  |         FUNC_PRINT_ALL(error, 0x);  }\ | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  |         GLASSERT(GL_NO_ERROR == error); \ | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-24 11:32:41 +08:00
										 |  |  | #else
 | 
					
						
							|  |  |  | #define OPENGL_CHECK_ERROR
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | #define OPENGL_HAS_ERROR GL_NO_ERROR != glGetError()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void dump_stack(); | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |